{"id":13726921,"url":"https://github.com/worker-tools/cloudflare-kv-storage","last_synced_at":"2025-05-08T07:39:43.299Z","repository":{"id":62422720,"uuid":"325471587","full_name":"worker-tools/cloudflare-kv-storage","owner":"worker-tools","description":"An implementation of the StorageArea interface using Cloudflare Worker's KV storage as a backing store","archived":false,"fork":false,"pushed_at":"2022-05-31T09:49:48.000Z","size":162,"stargazers_count":22,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-01T21:34:07.888Z","etag":null,"topics":["cloudflare","cloudflare-workers","cloudflare-workers-kv","kv-storage"],"latest_commit_sha":null,"homepage":"https://workers.tools/cloudflare-kv-storage","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/worker-tools.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-12-30T06:18:14.000Z","updated_at":"2024-09-28T08:01:28.000Z","dependencies_parsed_at":"2022-11-01T17:33:35.289Z","dependency_job_id":null,"html_url":"https://github.com/worker-tools/cloudflare-kv-storage","commit_stats":null,"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/worker-tools%2Fcloudflare-kv-storage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/worker-tools%2Fcloudflare-kv-storage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/worker-tools%2Fcloudflare-kv-storage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/worker-tools%2Fcloudflare-kv-storage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/worker-tools","download_url":"https://codeload.github.com/worker-tools/cloudflare-kv-storage/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253025283,"owners_count":21842404,"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":["cloudflare","cloudflare-workers","cloudflare-workers-kv","kv-storage"],"created_at":"2024-08-03T01:03:31.523Z","updated_at":"2025-05-08T07:39:43.281Z","avatar_url":"https://github.com/worker-tools.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# Cloudflare Storage Area\n\nAn implementation of the StorageArea ([1],[2],[3]) interface using [Cloudflare Worker's KV](https://developers.cloudflare.com/workers/runtime-apis/kv) \nstorage as a backing store.\n\nThe goal of this class is ease of use and compatibility with other Storage Area implementations, \nsuch as [`kv-storage-polyfill`](https://github.com/GoogleChromeLabs/kv-storage-polyfill).\n\nWhile work on [the specification](https://wicg.github.io/kv-storage/) itself has stopped, \nit's still a good interface for asynchronous data access that feels native to JavaScript.\n\n## Usage\n\n``` js\nimport { StorageArea } from '@worker-tools/cloudflare-kv-storage';\nconst storage = new StorageArea('foobar');\n```\n\nYou can now write cross-platform, cross-worker-env code:\n\n```js\nasync function myFunc(storage) {\n  await storage.set(['foo', 1], ['bar', 2], { expirationTtl: 5 * 60 });\n  await storage.get(['foo', 1]); // =\u003e ['bar', 2]\n}\n```\n\nNote that some of the underlying features of Cloudflare KV, such as [`expirationTtl`](https://developers.cloudflare.com/workers/runtime-apis/kv#expiring-keys), are still exposed via the optional options parameter. \nIf the underlying implementation isn't a ` CloudflareStorageArea`, the setting simply won't have any effect.\n\n## Prerequisites\nIn your `wrangler.toml`, make sure to provide a kv namespace binding and a default namespace for the this implementation.\n\n```toml\nkv_namespaces = [ \n  { binding = \"KV_NAMESPACE\", id = \"13c...\", preview_id = \"13c...\" }\n]\n\n[vars]\n  CF_STORAGE_AREA__DEFAULT_KV_NAMESPACE = \"KV_NAMESPACE\"\n```\n\n[1]: https://developers.google.com/web/updates/2019/03/kv-storage\n[2]: https://css-tricks.com/kv-storage/\n[3]: https://github.com/WICG/kv-storage\n\n## Features\n\nBeyond the cross-worker-env aspects of using StorageArea, CloudflareStorageArea provides a number of quality of life improvements over using Cloudflare's KV directly:\n\n* Support for multiple storage areas within a single KV binding\n* Wrapping and Unwrapping of many built-in types, such as `Map` and `Set` (structured clone algorithm)\n* Support for non-string keys and complex keys\n* Abstraction over KV pagination when listing keys\n\n## Disclaimers\n\nNote that efficiency is not a goal. Specifically, if you have sizable `ArrayBuffer`s,\nit's much better to use Cloudflare's KV directly.\n\n\u003cbr/\u003e\n\n--------\n\n\u003cbr/\u003e\n\n\u003cp align=\"center\"\u003e\u003ca href=\"https://workers.tools\"\u003e\u003cimg src=\"https://workers.tools/assets/img/logo.svg\" width=\"100\" height=\"100\" /\u003e\u003c/a\u003e\n\u003cp align=\"center\"\u003eThis module is part of the Worker Tools collection\u003cbr/\u003e⁕\n\n[Worker Tools](https://workers.tools) are a collection of TypeScript libraries for writing web servers in [Worker Runtimes](https://workers.js.org) such as Cloudflare Workers, Deno Deploy and Service Workers in the browser. \n\nIf you liked this module, you might also like:\n\n- 🧭 [__Worker Router__][router] --- Complete routing solution that works across CF Workers, Deno and Service Workers\n- 🔋 [__Worker Middleware__][middleware] --- A suite of standalone HTTP server-side middleware with TypeScript support\n- 📄 [__Worker HTML__][html] --- HTML templating and streaming response library\n- 📦 [__Storage Area__][kv-storage] --- Key-value store abstraction across [Cloudflare KV][cloudflare-kv-storage], [Deno][deno-kv-storage] and browsers.\n- 🆗 [__Response Creators__][response-creators] --- Factory functions for responses with pre-filled status and status text\n- 🎏 [__Stream Response__][stream-response] --- Use async generators to build streaming responses for SSE, etc...\n- 🥏 [__JSON Fetch__][json-fetch] --- Drop-in replacements for Fetch API classes with first class support for JSON.\n- 🦑 [__JSON Stream__][json-stream] --- Streaming JSON parser/stingifier with first class support for web streams.\n\nWorker Tools also includes a number of polyfills that help bridge the gap between Worker Runtimes:\n- ✏️ [__HTML Rewriter__][html-rewriter] --- Cloudflare's HTML Rewriter for use in Deno, browsers, etc...\n- 📍 [__Location Polyfill__][location-polyfill] --- A `Location` polyfill for Cloudflare Workers.\n- 🦕 [__Deno Fetch Event Adapter__][deno-fetch-event-adapter] --- Dispatches global `fetch` events using Deno’s native HTTP server.\n\n[router]: https://workers.tools/router\n[middleware]: https://workers.tools/middleware\n[html]: https://workers.tools/html\n[kv-storage]: https://workers.tools/kv-storage\n[cloudflare-kv-storage]: https://workers.tools/cloudflare-kv-storage\n[deno-kv-storage]: https://workers.tools/deno-kv-storage\n[kv-storage-polyfill]: https://workers.tools/kv-storage-polyfill\n[response-creators]: https://workers.tools/response-creators\n[stream-response]: https://workers.tools/stream-response\n[json-fetch]: https://workers.tools/json-fetch\n[json-stream]: https://workers.tools/json-stream\n[request-cookie-store]: https://workers.tools/request-cookie-store\n[extendable-promise]: https://workers.tools/extendable-promise\n[html-rewriter]: https://workers.tools/html-rewriter\n[location-polyfill]: https://workers.tools/location-polyfill\n[deno-fetch-event-adapter]: https://workers.tools/deno-fetch-event-adapter\n\nFore more visit [workers.tools](https://workers.tools).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fworker-tools%2Fcloudflare-kv-storage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fworker-tools%2Fcloudflare-kv-storage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fworker-tools%2Fcloudflare-kv-storage/lists"}