{"id":19714400,"url":"https://github.com/peternaydenov/data-pool","last_synced_at":"2025-04-29T19:32:53.393Z","repository":{"id":65329917,"uuid":"562622199","full_name":"PeterNaydenov/data-pool","owner":"PeterNaydenov","description":"Data layer for node apps and single page applications","archived":false,"fork":false,"pushed_at":"2025-02-17T06:26:41.000Z","size":492,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-20T15:17:28.787Z","etag":null,"topics":["cache","data","store"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PeterNaydenov.png","metadata":{"files":{"readme":"README.md","changelog":"Changelog.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-11-06T22:18:20.000Z","updated_at":"2025-02-17T06:26:45.000Z","dependencies_parsed_at":"2023-01-22T05:40:39.569Z","dependency_job_id":"a48888b5-36a4-4412-9d44-cb1c57858f48","html_url":"https://github.com/PeterNaydenov/data-pool","commit_stats":{"total_commits":6,"total_committers":1,"mean_commits":6.0,"dds":0.0,"last_synced_commit":"50e359dd176ef01765b66ce2aa3adeb11b40dcc4"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PeterNaydenov%2Fdata-pool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PeterNaydenov%2Fdata-pool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PeterNaydenov%2Fdata-pool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PeterNaydenov%2Fdata-pool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PeterNaydenov","download_url":"https://codeload.github.com/PeterNaydenov/data-pool/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251569651,"owners_count":21610597,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cache","data","store"],"created_at":"2024-11-11T22:31:29.773Z","updated_at":"2025-04-29T19:32:50.898Z","avatar_url":"https://github.com/PeterNaydenov.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Data-pool (@peter.naydenov/data-pool)\n\n![version](https://img.shields.io/github/package-json/v/peterNaydenov/data-pool)\n![license](https://img.shields.io/github/license/peterNaydenov/data-pool)\n![GitHub issues](https://img.shields.io/github/issues/peterNaydenov/data-pool)\n![npm bundle size](https://img.shields.io/bundlephobia/minzip/%40peter.naydenov%2Fdata-pool)\n\n`Data-pool` is a data-layer for node apps and single page application (**SPA**). Data-pool will simplify data maintanance with :\n\n- Immutable data stores;\n- Caching data records from Api requests;\n- Optional TTL for each data record;\n- Optional update schedule for each data record;\n- A mechanism to fake Api request response;\n\n## Instalation\nInstall for node.js projects by writing in your terminal:\n\n```\nnpm i @peter.naydenov/data-pool\n```\nOnce it has been installed, it can be used by writing this line of JavaScript:\n\n```js\nimport dataPool from '@peter.naydenov/data-pool'\n```\n\nor \n\n```js\nconst dataPool = require ( '@peter.naydenov/data-pool' );\n```\n\n\n## How to use it\nCreate a `data-pool` instance:\n\n```js\nconst pool = dataPool ();\n```\nNow you are free to add and manipulate stores and data. For more details read the '**Methods**' section\n\n## Methods\n\n\n```js\n  set           : 'Create new record'\n, get           : 'Returns existing data, or requesting it from related API'\n, addApi        : 'Associate one or more APIs with data-pool'\n, removeApi     : 'Remove associated API. Single API only'\n, list          : 'List stores with data'\n, has           : 'Checks if store or store-key exist. Returns a boolean: true/false'\n, importStore   : 'Add data as a store' \n, exportStore   : 'Export store as a data'\n, on            : 'Watch for store changes' \n, setDummy      : 'Define dummy source-data for store-key. Should be a function that returns a promise.'\n, removeDummy   : 'Remove dummy source-data.'\n, setTTL        : 'Set a TTL for a store-key record.'\n, removeTTL     : 'Remove a ttl record'\n, setUpdate     : 'Set recurring updates for specific API related record'\n, removeUpdate  : 'Remove recurring updates requests'\n, setNoCache    : 'Specify store-key records that should not have cache'\n, removeNoCache : 'Remove no cache setting per store-key'\n```\n\n\n### pool.set\nCreates a new data record in data pool.\n```js\npool.set ( storeName, key, data )\n/**\n *  Arguments:\n *    - storeName: string(required). Name of the store;\n *    - key: string or tuple(required). \n *             if it's a string -\u003e data identifier\n *             if it's a tuple -\u003e first element is the data identifier, \n *                                second is the extension.\n *      Extension should be available because some Api calls can return different\n *      results and we want to keep instead of overwrite them. Example: \"getProduct\"\n *      method can return product specification but we have a lot of products. We want\n *      to keep them in data-pool as a separate objects.\n *    - data: Any(required). Provide any data that should be saved;\n * \n *   Returns: void\n * /\n\n```\n\nExample:\n\n```js\n pool.set ( 'demo', 'name', 'Peter' )\n /**\n  * 1: No store 'demo': \n  *  Will create store 'demo' and will set property 'name' to 'Peter'\n  * 2: There is store 'demo':\n  * Will create a property 'name' for store 'demo'\n  * 3: There is store 'demo' with a property 'name'\n  * Will overwrite the property 'name' with 'Peter'\n  * /\n // \n    \n```\n\n\n### pool.get\nReturns a requested store/key. If there is no value and there is associated Api, will send request to the Api. Dummy values per store/key will overwrite the Api if they exists.\n\n```js\npool.get ( storeName, key, ...other )\n/**\n *  Arguments:\n *     - storeName: string(required). Name of the store;\n *     - key: string or tuple(required). \n *             if it's a string -\u003e data identifier\n *             if it's a tuple -\u003e first element is the data identifier, \n *                                second is the extension.\n *   Returns: Any\u003cPromise\u003e\n * /\n\n```\n\nExample:\n\n```js\n  pool.get ( 'demo', 'name' )\n      .then ( r =\u003e {\n                // r = 'Peter'\n            })\n```\n\n### pool.addApi\nRegister api in data-pool as source of information. Api name will become a store name and api methods will become keys. Key as a tuple represents methods that can return more that one result and records will need specification. \nFor example - key:[ getProduct, 2443 ]. getProduct can return all items in the system, but extension specifies the exact product ID.\n\n```js\n pool.addApi ( apiList )\n /**\n  *  Arguments:\n  *  - apiList: object(required). List of Api that should work into data-pool\n  *  Returns: void\n  * /\n \n```\n\nExample:\n\n```js\n// we have api for users(userAPI) and api for products(productAPI)\npool.addApi ({ \n            user:userAPI, \n            product:productAPI \n        })\n\n// userApi has method 'getDetails'. Here is an example how we can call that method\npool.get ( 'user', 'getDetails' )\n    .then ( r =\u003e {\n                // r will contain result of userAPI.getDetails()\n        })\n\n```\n\n\n### pool.removeApi\nRemoves conection of data-pool to api. Removes all 'updates' related to these api methods.\n\n```js\n\npool.removeApi ( apiName )\n/**\n *  Arguments:\n *  - apiName - string(required). Api name that should be removed;\n *  Returns: void\n *\n * /\n\n````\n\nExample:\n\n```js\n  pool.removeApi ( 'user' )\n // Will remove association with userAPI from prev. example\n pool.get ( 'user', 'getDetails' )\n     .then ( r =\u003e {\n                    // Relation to the api is removed but store still exists!\n                    // 1. If store has record for 'user','getDetails' -\u003e will return the result\n                    // 2. If there is no record -\u003e will return null. \n                })\n```\n\n\n### pool.list\nReturns list of all existing stores.\n```js\npool.list ()\n/**\n *  no arguments\n *  Returns: string[]. \n * /\n```\nExample:\n```js\n// If we have association to userAPI and productAPI, and we have called once a\n// pool.get ( 'user','getDetails' )\nconst list = pool.list ()\n// list =\u003e [ 'user' ]\n```\nAccociation of the productAPI with data-pool will not create the store automatically. Store will be created when we have data for it.\n\n### pool.has\nCheck if store or store/key exists.\n\n```js\n  pool.has ( storeName, key )\n  /**\n   *  Arguments\n   *  - storeName - string(required). Name of the store.\n   *  - key: string or tuple(optional). \n   *             if it's a string -\u003e data identifier\n   *             if it's a tuple -\u003e first element is the data identifier, \n   *                                second is the extension.\n   *  Returns: boolean.\n   * /\n```\n\nExample:\n\n```js\n  const hasStore = pool.has ( 'user' )\n  // hasStore =\u003e true\n```\n\n\n### pool.importStore\nConverts a javascript object to data-pool store.\n\n```js\n pool.importStore ( storeName, data )\n /**\n  *   Arguments:\n  *     - storeName - string(required). Data will become a store\n  *     - data - object(required). Any data \n  * \n  *   Returns : void\n  * /\n```\n\nExample:\n\n```js\nconst data = {\n                name : 'Peter'\n              , age : 48\n            }\npool.importStore ( 'yo', data )\npool.get ( 'yo', 'name' )\n    .then ( r =\u003e {\n                // r === 'Peter'\n        })\n\n```\n\n\n### pool.exportStore\nReturns a store as a javascript object\n\n```js\npool.exportStore ( storeName )\n/**\n *  Arguments:\n *  - storeName - string(required). Name of the store for export\n *  Returns : object\n * /\n```\n\n\n### pool.on\nData-pool events are triggered on store's data changes.\n\n```js\npool.on ( nameOfStore, callback )\nfunction callback ( key, oldData, newData ) {\n                // ....\n        }\n/**\n *   Method 'on' Arguments\n *   - nameOfStore - string(required). Listen for changes in the specified store.\n *   - callback - function(required). Fn will be executed on every data field change;\n *   Returns : void\n * \n *  Callback Arguments:\n *   - key     -  Name of the changed field\n *   - oldData - field value at until now\n *   - newData - field upcoming value\n *  Returns : void\n * /\n```\n\n\n\n### pool.setDummy\nSet a dummy source of information for specific store/key. Used for testing and development purposes. If Api is not ready we can provide expected data as using a dummy function. To get back to real api call remove the dummy. Dummy will always overwrite default source of information.\n\n```js\npool.setDummy ( storeName, key, dummyFn )\n/**\n *  Arguments:\n *     - storeName: string(required). Name of the store;\n *     - key: string or tuple(required). \n *             if it's a string -\u003e data identifier\n *             if it's a tuple -\u003e first element is the data identifier, \n *                                second is the extension. \n *     - dummyFn: function. Function will be executed always when we have\n *                specified storeName/key. Function should return a promise.\n * \n *  Returns: void\n * /\n```\n\n\n### pool.removeDummy\nCancel dummy source of information.\n\n```js\npool.removeDummy ( storeName, key )\n/**\n *  Arguments:\n *     - storeName: string(required). Name of the store;\n *     - key: string or tuple(required). \n *             if it's a string -\u003e data identifier\n *             if it's a tuple -\u003e first element is the data identifier, \n *                                second is the extension. \n */\n```\n\n### pool.setTTL\nSet a 'time to live'(TTL) to specific store/key.\n\n```js\n pool.setTTL ( storeName, key, ttl )\n /**\n  *  Arguments: \n  *  - storeName : string(required). Name of the store;\n  *  - key: string(required). Data identifier\n  *  - ttl: number(required). Time to live in ms. \n  *  Returns: void\n  */ \n```\n\n### pool.removeTTL\nCancel TTL for specific store/key.\n\n```js\npool.removeTTL ( storeName, key )\n/**\n *  Arguments:\n *  - storeName: string(required). Name of the store;\n *  - key: string(required). Data identifier;\n *  Returns: void\n */\n```\n\n### pool.setUpdate\nSet interval to update record for api related stores.\n\n```js\npool.setUpdate ( storeName, key, interval )\n/**\n *  Arguments:\n *  - storeName: string(required). Name of the store;\n *  - key: string(required). Data identifier;\n *  - interval: number(required). Interval for next update in ms.\n *  Returns: void;\n */\n```\n\n### pool.removeUpdate\nCancel automatic update for api related stores.\n\n```js\npool.removeUpdate ( storeName, key )\n/**\n *  Arguments:\n *  - storeName: string(required). Name of the store;\n *  - key: string(required). Data identifier;\n *  Returns: void\n */\n```\n\n\n\n### pool.setNoCache\nUse '*setNoCache*' method with api related stores. Set `store-key` as no-cache and every data request will hit the api.\n\n```js\n pool.setNoCache ( storeName, key )\n /**\n  *  Arguments:\n  *  - storeName : string(required). Name of the store;\n  *  - key: string(required). Data identifier;\n  *  Returns: void\n  */\n```\n\n### pool.removeNoCache\nCancel no-cache request.\n\n```js\npool.removeNoCache ( storeName, key )\n/**\n * Arguments:\n *  - storeName: string(required). Name of the store;\n *  - key: string(required). Data identifier;\n *  Returns : void\n */\n```\n\n\n\n## Credits\n'@peter.naydenov/data-pool' was created and supported by Peter Naydenov.\n\n\n\n## License\n'@peter.naydenov/data-pool' is released under the MIT License.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeternaydenov%2Fdata-pool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeternaydenov%2Fdata-pool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeternaydenov%2Fdata-pool/lists"}