@durable-streams/cli 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 durable-stream
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.cjs ADDED
@@ -0,0 +1,168 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ //#region rolldown:runtime
4
+ var __create = Object.create;
5
+ var __defProp = Object.defineProperty;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
12
+ key = keys[i];
13
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
21
+ value: mod,
22
+ enumerable: true
23
+ }) : target, mod));
24
+
25
+ //#endregion
26
+ const node_process = __toESM(require("node:process"));
27
+ const __durable_streams_client = __toESM(require("@durable-streams/client"));
28
+
29
+ //#region src/index.ts
30
+ const STREAM_URL = process.env.STREAM_URL || `http://localhost:4437`;
31
+ function printUsage() {
32
+ console.error(`
33
+ Usage:
34
+ durable-stream create <stream_id> Create a new stream
35
+ durable-stream write <stream_id> <content> Write content to a stream
36
+ cat file.txt | durable-stream write <stream_id> Write stdin to a stream
37
+ durable-stream read <stream_id> Follow a stream and write to stdout
38
+ durable-stream delete <stream_id> Delete a stream
39
+
40
+ Environment Variables:
41
+ STREAM_URL Base URL of the stream server (default: http://localhost:4437)
42
+ `);
43
+ }
44
+ async function createStream(streamId) {
45
+ const url = `${STREAM_URL}/v1/stream/${streamId}`;
46
+ try {
47
+ await __durable_streams_client.DurableStream.create({
48
+ url,
49
+ contentType: `application/octet-stream`
50
+ });
51
+ console.log(`Created stream: ${streamId}`);
52
+ } catch (error) {
53
+ if (error instanceof Error) node_process.stderr.write(`Error creating stream: ${error.message}\n`);
54
+ process.exit(1);
55
+ }
56
+ }
57
+ async function writeStream(streamId, content) {
58
+ const url = `${STREAM_URL}/v1/stream/${streamId}`;
59
+ try {
60
+ const stream = new __durable_streams_client.DurableStream({ url });
61
+ if (content) {
62
+ const processedContent = content.replace(/\\n/g, `\n`).replace(/\\t/g, `\t`).replace(/\\r/g, `\r`).replace(/\\\\/g, `\\`);
63
+ await stream.append(processedContent);
64
+ console.log(`Wrote ${processedContent.length} bytes to ${streamId}`);
65
+ } else {
66
+ const chunks = [];
67
+ node_process.stdin.on(`data`, (chunk) => {
68
+ chunks.push(chunk);
69
+ });
70
+ await new Promise((resolve, reject) => {
71
+ node_process.stdin.on(`end`, resolve);
72
+ node_process.stdin.on(`error`, reject);
73
+ });
74
+ const data = Buffer.concat(chunks);
75
+ await stream.append(data);
76
+ console.log(`Wrote ${data.length} bytes to ${streamId}`);
77
+ }
78
+ } catch (error) {
79
+ if (error instanceof Error) node_process.stderr.write(`Error writing to stream: ${error.message}\n`);
80
+ process.exit(1);
81
+ }
82
+ }
83
+ async function readStream(streamId) {
84
+ const url = `${STREAM_URL}/v1/stream/${streamId}`;
85
+ try {
86
+ const stream = new __durable_streams_client.DurableStream({ url });
87
+ const res = await stream.stream({ live: `auto` });
88
+ for await (const chunk of res.bodyStream()) if (chunk.length > 0) node_process.stdout.write(chunk);
89
+ } catch (error) {
90
+ if (error instanceof Error) node_process.stderr.write(`Error reading stream: ${error.message}\n`);
91
+ process.exit(1);
92
+ }
93
+ }
94
+ async function deleteStream(streamId) {
95
+ const url = `${STREAM_URL}/v1/stream/${streamId}`;
96
+ try {
97
+ const stream = new __durable_streams_client.DurableStream({ url });
98
+ await stream.delete();
99
+ console.log(`Deleted stream: ${streamId}`);
100
+ } catch (error) {
101
+ if (error instanceof Error) node_process.stderr.write(`Error deleting stream: ${error.message}\n`);
102
+ process.exit(1);
103
+ }
104
+ }
105
+ async function main() {
106
+ const args = process.argv.slice(2);
107
+ if (args.length < 1) {
108
+ printUsage();
109
+ process.exit(1);
110
+ }
111
+ const command = args[0];
112
+ switch (command) {
113
+ case `create`: {
114
+ if (args.length < 2) {
115
+ node_process.stderr.write(`Error: stream_id required\n`);
116
+ printUsage();
117
+ process.exit(1);
118
+ }
119
+ await createStream(args[1]);
120
+ break;
121
+ }
122
+ case `write`: {
123
+ if (args.length < 2) {
124
+ node_process.stderr.write(`Error: stream_id required\n`);
125
+ printUsage();
126
+ process.exit(1);
127
+ }
128
+ const streamId = args[1];
129
+ const content = args.slice(2).join(` `);
130
+ if (!node_process.stdin.isTTY) await writeStream(streamId);
131
+ else if (content) await writeStream(streamId, content);
132
+ else {
133
+ node_process.stderr.write(`Error: content required (provide as argument or pipe to stdin)\n`);
134
+ printUsage();
135
+ process.exit(1);
136
+ }
137
+ break;
138
+ }
139
+ case `read`: {
140
+ if (args.length < 2) {
141
+ node_process.stderr.write(`Error: stream_id required\n`);
142
+ printUsage();
143
+ process.exit(1);
144
+ }
145
+ await readStream(args[1]);
146
+ break;
147
+ }
148
+ case `delete`: {
149
+ if (args.length < 2) {
150
+ node_process.stderr.write(`Error: stream_id required\n`);
151
+ printUsage();
152
+ process.exit(1);
153
+ }
154
+ await deleteStream(args[1]);
155
+ break;
156
+ }
157
+ default:
158
+ node_process.stderr.write(`Error: unknown command '${command}'\n`);
159
+ printUsage();
160
+ process.exit(1);
161
+ }
162
+ }
163
+ main().catch((error) => {
164
+ node_process.stderr.write(`Fatal error: ${error.message}\n`);
165
+ process.exit(1);
166
+ });
167
+
168
+ //#endregion
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1 @@
1
+ export { };
package/package.json CHANGED
@@ -1,36 +1,66 @@
1
1
  {
2
2
  "name": "@durable-streams/cli",
3
- "version": "0.1.0",
4
3
  "description": "CLI tool for working with Durable Streams",
4
+ "version": "0.1.2",
5
5
  "author": "Durable Stream contributors",
6
- "license": "Apache-2.0",
7
- "type": "module",
8
6
  "bin": {
9
7
  "durable-stream": "./dist/index.js",
10
8
  "durable-stream-dev": "./bin/durable-stream-dev.mjs"
11
9
  },
12
- "main": "./dist/index.js",
13
- "files": [
14
- "dist",
15
- "bin"
16
- ],
17
- "scripts": {
18
- "build": "tsdown",
19
- "dev": "tsdown --watch",
20
- "start:dev": "tsx --watch example-server.ts",
21
- "link:dev": "pnpm link --global"
10
+ "bugs": {
11
+ "url": "https://github.com/durable-streams/durable-streams/issues"
22
12
  },
23
13
  "dependencies": {
24
- "@durable-streams/client": "workspace:*"
14
+ "@durable-streams/client": "0.1.2"
25
15
  },
26
16
  "devDependencies": {
27
- "@durable-streams/server": "workspace:*",
28
17
  "@types/node": "^22.15.21",
29
18
  "tsdown": "^0.9.0",
30
19
  "tsx": "^4.19.2",
31
- "typescript": "^5.5.2"
20
+ "typescript": "^5.5.2",
21
+ "@durable-streams/server": "0.1.2"
32
22
  },
33
23
  "engines": {
34
24
  "node": ">=18.0.0"
25
+ },
26
+ "exports": {
27
+ ".": {
28
+ "import": {
29
+ "types": "./dist/index.d.ts",
30
+ "default": "./dist/index.js"
31
+ },
32
+ "require": {
33
+ "types": "./dist/index.d.cts",
34
+ "default": "./dist/index.cjs"
35
+ }
36
+ },
37
+ "./package.json": "./package.json"
38
+ },
39
+ "files": [
40
+ "dist",
41
+ "bin"
42
+ ],
43
+ "keywords": [
44
+ "cli",
45
+ "durable-streams",
46
+ "streaming",
47
+ "typescript"
48
+ ],
49
+ "license": "Apache-2.0",
50
+ "main": "./dist/index.cjs",
51
+ "module": "./dist/index.js",
52
+ "repository": {
53
+ "type": "git",
54
+ "url": "git+https://github.com/durable-streams/durable-streams.git",
55
+ "directory": "packages/cli"
56
+ },
57
+ "sideEffects": false,
58
+ "type": "module",
59
+ "types": "./dist/index.d.ts",
60
+ "scripts": {
61
+ "build": "tsdown",
62
+ "dev": "tsdown --watch",
63
+ "link:dev": "pnpm link --global",
64
+ "start:dev": "tsx --watch example-server.ts"
35
65
  }
36
- }
66
+ }