{"id":19257544,"url":"https://github.com/ericvera/getsetdel","last_synced_at":"2025-04-21T15:31:23.757Z","repository":{"id":260119743,"uuid":"876863606","full_name":"ericvera/getsetdel","owner":"ericvera","description":"Key-value store with a tiny metadata layer to support store management. Implemented in IndexedDB.","archived":false,"fork":false,"pushed_at":"2025-02-17T15:33:06.000Z","size":1925,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-28T19:16:27.872Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/ericvera.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2024-10-22T17:17:01.000Z","updated_at":"2025-02-17T15:33:01.000Z","dependencies_parsed_at":"2024-11-25T17:28:50.454Z","dependency_job_id":"7179a32b-b18b-434e-b9cf-a52d70be4bf8","html_url":"https://github.com/ericvera/getsetdel","commit_stats":null,"previous_names":["ericvera/getsetdel"],"tags_count":9,"template":false,"template_full_name":"ericvera/ts-lib-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericvera%2Fgetsetdel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericvera%2Fgetsetdel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericvera%2Fgetsetdel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericvera%2Fgetsetdel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ericvera","download_url":"https://codeload.github.com/ericvera/getsetdel/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250080628,"owners_count":21371541,"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":[],"created_at":"2024-11-09T19:10:35.244Z","updated_at":"2025-04-21T15:31:22.938Z","avatar_url":"https://github.com/ericvera.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# getsetdel\n\n**Key-value store implemented on top of IndexedDB with a small metadata layer to support store management.**\n\n[![github license](https://img.shields.io/github/license/ericvera/getsetdel.svg?style=flat-square)](https://github.com/ericvera/getsetdel/blob/master/LICENSE)\n[![npm version](https://img.shields.io/npm/v/getsetdel.svg?style=flat-square)](https://npmjs.org/package/getsetdel)\n\nFeatures:\n\n- Multiple named key-value stores\n- Built on top of IndexedDB (using [idb-keyval](https://www.npmjs.com/package/idb-keyval))\n- Keep track of created stores including a schema version and tags\n- Auto-clear data on version or tag changes\n- Support for custom store metadata\n- Query inventory of stores by name or tags\n\n## Design\n\nGetSetDel is a key-value store with an small inventory layer on top of it.\n\nIt choses clearing the store and hydrating it from scratch over dealing with complex data migrations. This is enabled by the inventory layer which keeps track of details that would invalidate the data (data/schema version or tags) as well as custom metadata that you may need (e.g. last sync timestamp) to keep the data up to date.\n\n### Storage Inventory Information\n\nWhen creating a store (via `createStore`), you can provide an optional `version` (which can be used to keep track of schema changes) and an optional array `tags` (e.g. 'public', 'private' data). At the same time we keep track of `creation` which contains the time when the current instance of the store was created.\n\n### Data Invalidation\n\nInstead of dealing with data migrations, we just get rid of all the data and start over. This happens in two ways:\n\n1. **During store creation (i.e. `createStore`):** At this time, if the data is invalidated, it is simply cleared (all data removed and inventory entry removed including all metadata).\n2. **During calls to all data access/modification methods (e.g. `get`, `set`, `del`, `entries`, etc.):** At this time, if the data is invalidated, it will throw a `GetSetDelResetError` exception which you can handle by clearing your state and starting over from `createStore`.\n\n### Alternatives\n\nIf you would like to manage all your stores yourself or if you only need a single store, I suggest you use [idb-keyval](https://www.npmjs.com/package/idb-keyval) instead of this. If you need more complex IndexedDB functionality, idb-keyval suggests [IDB](https://www.npmjs.com/package/idb).\n\n## Usage\n\n### Creating (initializing) a store\n\n```typescript\nimport { createStore } from 'getsetdel'\n\n// Option 1. Minimum required options\n// This will result in an IndexedDB databased named\n// 'getsetdel-store-name' with a store called 'store'\nconst storeToken = await createStore({\n  name: 'store-name',\n})\n\n// Option 2. Store with all the options (name is the only\n// required prop)\n// This will result in an IndexedDB databased named\n// 'getsetdel-all-options-store--0001' with a store called 'store'\nconst allOptionsStoreToken = await createStore({\n  name: 'all-options-store',\n  // In case you want to store data about a specific entity (this\n  // is behind the scenes just added to the IndexedDB name)\n  key: '0001',\n  // Data is cleared whenever createStore is called with different\n  // values on the following:\n  tags: ['private', 'other'],\n  version: 1,\n})\n```\n\n### Accessing/deleting data\n\n```typescript\nimport { createStore, del, set } from 'getsetdel'\n\nconst storeToken = await createStore({\n  name: 'store-name',\n})\n\n// To add data you can use set or setMany\nawait set(storeToken, 'key1', { some: 'data', here: true })\n\n// To get data you can use get, getMany (retrieve many keys\n// at once), or entries (returns key-value pairs for all\n// the entries in the store)\nconst key1Value = await get(storeToken, 'key1')\nconsole.log(key1Value)\n\n// To remove the data you can use del, delMany, or clear\n// to fully remove the data and the store entry in the\n// inventory.\nawait del(storeToken, 'key1')\n```\n\n### Metadata\n\n```typescript\n// Get the metadata\nconst metadata = await getMetadata(storeToken)\n\n// Set the metadata (This is a full overwrite and not\n// a merge)\nawait setMetadata(storeToken, {\n  ...metadata,\n  lastSync: Date.now(),\n})\n```\n\n### Reset handling\n\nGetSetDel provides a helper method to manage `GetSetDelResetError`.\n\n```typescript\nconst onStoreError = async () =\u003e {\n  // Do what you need to reset the state of your code and\n  // re-initialize the store by calling `createStore`\n}\n\n// When the `version` prop, `creation` timestamp, or `tags` change,\n// `onStoreError` is called. In the case of any other exception is thrown, the\n// exception is just re-thrown.\nawait set(storeToken, 'key', { data: 'hello' }).handleResetError(onStoreError)\n```\n\n### Query Inventory\n\nYou can query the inventory by `name` or `tags`.\n\nExample 1. Clear all the data tagged as `private` when a user logs out.\n\n```typescript\nconst privateStoreTokens = await queryInventory({\n  includesAnyTag: ['private'],\n})\n\nawait Promise.all(privateStoreTokens.map((token) =\u003e clear(token)))\n```\n\nExample 2. For clearing multiple stores called `todo-items` with `key` that matches project ids (e.g. `{ name: 'todo-items', key: 'projectid0001'}` and `{ name: 'todo-items', key: 'projectid0002'}`).\n\n```typescript\nconst privateStoreTokens = await queryInventory({\n  name: 'todo-items',\n})\n\nawait Promise.all(privateStoreTokens.map((token) =\u003e clear(token)))\n```\n\n# API Reference\n\nSee [docs](docs/README.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericvera%2Fgetsetdel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fericvera%2Fgetsetdel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericvera%2Fgetsetdel/lists"}