{"id":22100581,"url":"https://github.com/voxoco/durable-stream-client","last_synced_at":"2025-07-24T23:34:00.220Z","repository":{"id":58824655,"uuid":"532351146","full_name":"voxoco/durable-stream-client","owner":"voxoco","description":"Client NodeJS application for durable-stream","archived":false,"fork":false,"pushed_at":"2022-09-06T02:02:01.000Z","size":15,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-13T14:55:39.317Z","etag":null,"topics":["cloudflare-r2","cloudflare-workers","durable-objects","persistence","websocket"],"latest_commit_sha":null,"homepage":"https://voxo.co","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/voxoco.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}},"created_at":"2022-09-03T19:09:10.000Z","updated_at":"2024-07-29T13:58:30.000Z","dependencies_parsed_at":"2022-09-08T22:02:22.782Z","dependency_job_id":null,"html_url":"https://github.com/voxoco/durable-stream-client","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voxoco%2Fdurable-stream-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voxoco%2Fdurable-stream-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voxoco%2Fdurable-stream-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voxoco%2Fdurable-stream-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/voxoco","download_url":"https://codeload.github.com/voxoco/durable-stream-client/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227489203,"owners_count":17780529,"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-r2","cloudflare-workers","durable-objects","persistence","websocket"],"created_at":"2024-12-01T05:14:55.708Z","updated_at":"2024-12-01T05:14:56.539Z","avatar_url":"https://github.com/voxoco.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Durable Stream Client :electric_plug:\n\nA lightweight client for [Durable Stream](https://github.com/voxoco/durable-stream)\n\nThe client\n\n## Installation\n\n```bash\nnpm install durable-stream-client\n```\n\n## Feaures\n* Publish messages to a durable stream (to be propagated to other clients subscribed on the same subject)\n* Simple reconnect logic\n* Queues up messages while disconnected and sends them when reconnected (with a ~2 second timeout)\n* Subscribe to messages on a durable stream\n* Delete messages from a durable stream\n* Get/set the object state (a generic object we can set/get on the durable object)\n* Get metadata, get, put, delete objects in R2\n\n\n## Usage\n\n```js\n// Shim the websocket client for node\nglobalThis.WebSocket = require('websocket').w3cwebsocket;\n\nimport DurableStreamClient from 'durable-stream-client'\n\nconst client = new DurableStreamClient({\n  host: '\u003cworker-name\u003e.voxo.workers.dev', // defaults to localhost:8787\n  secure: true, // boolean required (if local set to false)\n  apiKey: 'my-api-key', // string required\n  subject: 'my-subject', // string required\n})\n\n// Initialize the client\nawait client.init();\n```\n\n## Primary Stream Methods\n\n```js\n// Get the current sequence number and general stream info\nconst info = await client.info();\nconsole.log(info);\n\nconst msg = {\n  test: 'value',\n  someData: 'some-data',\n}\n\n// Publish a message (can be a string or object)\nconst res = await client.publish(msg)\n// Returns a promise that resolves to the response from the server and includes the message id, sequence number etc..\n\n// Subscribe to messages\n// The first arg is the sequence number to start from (0 for all messages from the beginning of the stream)\nclient.subscribe(10000000019, async (msg, ack) =\u003e {\n  console.log(`Received message: ${JSON.stringify(msg)}`);\n  ack();\n  // Be sure to ack all messages!\n  // Acknowledging a message will remove it from the queue on the client and server\n})\n\n// Unsubscribe from messages\nawait client.unsubscribe();\n\n// Delete messages in the stream up to a sequence number\nawait client.delete(10000000019);\n\n// Get the object object state (just a generic object we can set/get on the durable object)\nconst state = await client.getState();\n\n// Set the object state\nawait client.putState({ some: 'data' });\n```\n\n## R2 Methods\n\n```js\n// Head object (get metadata)\nconst metadata = await client.headObject('/path/to/object.ext');\n\n// Get object\nconst object = await client.getObject('/path/to/object.ext');\n// Write the file to disk\nfs.writeFileSync('/local/path/file.ext', object);\n\n// Put object\n// Arg 1 = file path in R2\n// Arg 2 = local file path to upload\n\nconst res = await client.putObject('/path/to/object.ext', '/local/path/file.ext');\n\n// Delete object\nconst res = await client.deleteObject('/path/to/object.ext');\n```\n\n## \n\n## License\n\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvoxoco%2Fdurable-stream-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvoxoco%2Fdurable-stream-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvoxoco%2Fdurable-stream-client/lists"}