{"id":15044057,"url":"https://github.com/willin/remote-cloudflare-kv","last_synced_at":"2025-04-19T14:45:41.815Z","repository":{"id":170113260,"uuid":"646168628","full_name":"willin/remote-cloudflare-kv","owner":"willin","description":"A Remote Cloudflare KV API SDK for Vercel Edge Function, etc.","archived":false,"fork":false,"pushed_at":"2024-10-10T06:53:57.000Z","size":107,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-10T17:42:42.664Z","etag":null,"topics":["cloudflare","edge","kv","next","vercel","worker"],"latest_commit_sha":null,"homepage":"https://willin.wang/blog/remote-cloudflare-kv","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/willin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/funding.yml","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},"funding":{"github":"willin","custom":"https://afdian.com/@willin"}},"created_at":"2023-05-27T14:03:11.000Z","updated_at":"2025-03-12T06:58:47.000Z","dependencies_parsed_at":"2024-11-06T04:00:29.690Z","dependency_job_id":"3a5f5d55-286c-4fa1-abe5-697984dbd8cb","html_url":"https://github.com/willin/remote-cloudflare-kv","commit_stats":{"total_commits":6,"total_committers":3,"mean_commits":2.0,"dds":"0.33333333333333337","last_synced_commit":"b0d468a8f223910c3c9c4fe15239edb87c61a254"},"previous_names":["willin/remote-cloudflare-kv"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willin%2Fremote-cloudflare-kv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willin%2Fremote-cloudflare-kv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willin%2Fremote-cloudflare-kv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willin%2Fremote-cloudflare-kv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/willin","download_url":"https://codeload.github.com/willin/remote-cloudflare-kv/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248997451,"owners_count":21195879,"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","edge","kv","next","vercel","worker"],"created_at":"2024-09-24T20:50:00.730Z","updated_at":"2025-04-19T14:45:41.770Z","avatar_url":"https://github.com/willin.png","language":"TypeScript","funding_links":["https://github.com/sponsors/willin","https://afdian.com/@willin","https://paypal.me/willinwang"],"categories":[],"sub_categories":[],"readme":"# remote-cloudflare-kv\n\n[![npm](https://img.shields.io/npm/v/remote-cloudflare-kv.svg?style=plastic)](https://npmjs.org/package/remote-cloudflare-kv) [![npm](https://img.shields.io/npm/dm/remote-cloudflare-kv.svg?style=plastic)](https://npmjs.org/package/remote-cloudflare-kv) [![npm](https://img.shields.io/npm/dt/remote-cloudflare-kv.svg?style=plastic)](https://npmjs.org/package/remote-cloudflare-kv)\n\n## Setup\n\n```bash\nnpm install --save remote-cloudflare-kv\n# or\nyarn add remote-cloudflare-kv\n# or\npnpm install --save remote-cloudflare-kv\n```\n\n## Usage\n\n### Init\n\n```ts\nimport CloudflareKV from 'remote-cloudflare-kv';\n\nexport const NAMESPACE = new CloudflareKV({\n  account_id: process.env.CF_ACCOUNT_ID || '',\n  namespace_id: process.env.CF_NAMESPACE_ID || '',\n  // use bearer token\n  api_token: process.env.CF_API_TOKEN || '',\n  // or use email \u0026 api key\n  api_email: '',\n  api_key: ''\n});\n```\n\n### Writing key-value pairs\n\nTo create a new key-value pair, or to update the value for a particular key, call the put method on any namespace you have bound to your script. The basic form of this method looks like this:\n\n```ts\nawait NAMESPACE.put(key, value);\n// void\n```\n\nExpiring keys:\n\n```ts\nawait NAMESPACE.put(key, value, { expiration: secondsSinceEpoch });\n\nawait NAMESPACE.put(key, value, { expirationTtl: secondsFromNow });\n```\n\nMetadata:\n\n```ts\nawait NAMESPACE.put(key, value, {\n  metadata: { someMetadataKey: 'someMetadataValue' }\n});\n```\n\n### Get key-value pair\n\nTo get the value for a given key, you can call the get method on any namespace you have bound to your script:\n\n```ts\n// replace key \u0026 type\nconst result = await NAMESPACE.get('key', { type: 'json' });\nconsole.log(result);\n// {\"hello\": 1}\n```\n\nSupported types: `text`, `json`, `arrayBuffer`, `stream`.\n\nNormalises type, ignoring cacheTtl as there is only one \"edge location\": the user's computer\n\n### Get key-value pair with Metadata\n\nYou can get the metadata associated with a key-value pair alongside its value by calling the getWithMetadata method on a namespace you have bound in your script:\n\n```ts\nconst result = await NAMESPACE.getWithMetadata(key, { type: 'json' });\n//  {\"value\": {\"hello\": 1}, \"metadata\": {\"someKey\": \"someVal\"}}\n```\n\n### Deleting key-value pairs\n\nTo delete a key-value pair, call the delete method on any namespace you have bound to your script:\n\n```ts\nawait NAMESPACE.delete(key);\n// void\n```\n\n### Listing keys\n\nYou can use a list operation to see all of the keys that live in a given namespace.\n\n```ts\nconst result = await NAMESPACE.list();\nconsole.log(result);\n```\n\nMore detail:\n\nThe list method has this signature (in TypeScript):\n\n```ts\nawait NAMESPACE.list({ prefix: string, limit: number, cursor: string });\n```\n\nThe `list` method returns a promise which resolves with an object that looks like this:\n\n```json\n{\n  \"keys\": [\n    {\n      \"name\": \"foo\",\n      \"expiration\": 1234,\n      \"metadata\": { \"someMetadataKey\": \"someMetadataValue\" }\n    }\n  ],\n  \"list_complete\": false,\n  \"cursor\": \"6Ck1la0VxJ0djhidm1MdX2FyD\"\n}\n```\n\n## Refs\n\n- Runtime API: \u003chttps://developers.cloudflare.com/workers/runtime-apis/kv/\u003e\n- RESTful API: \u003chttps://developers.cloudflare.com/api/operations/workers-kv-namespace-list-namespaces\u003e\n\n## 赞助 Sponsor\n\n如果您对本项目感兴趣，可以通过以下方式支持我：\n\n- 关注我的 Github 账号：[@willin](https://github.com/willin) [![github](https://img.shields.io/github/followers/willin.svg?style=social\u0026label=Followers)](https://github.com/willin)\n- 参与 [爱发电](https://afdian.net/@willin) 计划\n- 支付宝或微信[扫码打赏](https://user-images.githubusercontent.com/1890238/89126156-0f3eeb80-d516-11ea-9046-5a3a5d59b86b.png)\n\nDonation ways:\n\n- Github: \u003chttps://github.com/sponsors/willin\u003e\n- Paypal: \u003chttps://paypal.me/willinwang\u003e\n- Alipay or Wechat Pay: [QRCode](https://user-images.githubusercontent.com/1890238/89126156-0f3eeb80-d516-11ea-9046-5a3a5d59b86b.png)\n\n## 许可证 License\n\nApache-2.0 \u0026copy; \u003chttps://willin.wang\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillin%2Fremote-cloudflare-kv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwillin%2Fremote-cloudflare-kv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillin%2Fremote-cloudflare-kv/lists"}