@durable-streams/cli 0.1.1 → 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/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,46 +1,62 @@
1
1
  {
2
2
  "name": "@durable-streams/cli",
3
3
  "description": "CLI tool for working with Durable Streams",
4
- "version": "0.1.1",
4
+ "version": "0.1.2",
5
5
  "author": "Durable Stream contributors",
6
- "license": "Apache-2.0",
7
- "repository": {
8
- "type": "git",
9
- "url": "git+https://github.com/durable-streams/durable-streams.git",
10
- "directory": "packages/cli"
11
- },
12
- "bugs": {
13
- "url": "https://github.com/durable-streams/durable-streams/issues"
14
- },
15
- "keywords": [
16
- "durable-streams",
17
- "streaming",
18
- "cli",
19
- "typescript"
20
- ],
21
6
  "bin": {
22
7
  "durable-stream": "./dist/index.js",
23
8
  "durable-stream-dev": "./bin/durable-stream-dev.mjs"
24
9
  },
10
+ "bugs": {
11
+ "url": "https://github.com/durable-streams/durable-streams/issues"
12
+ },
25
13
  "dependencies": {
26
- "@durable-streams/client": "0.1.1"
14
+ "@durable-streams/client": "0.1.2"
27
15
  },
28
16
  "devDependencies": {
29
17
  "@types/node": "^22.15.21",
30
18
  "tsdown": "^0.9.0",
31
19
  "tsx": "^4.19.2",
32
20
  "typescript": "^5.5.2",
33
- "@durable-streams/server": "0.1.1"
21
+ "@durable-streams/server": "0.1.2"
34
22
  },
35
23
  "engines": {
36
24
  "node": ">=18.0.0"
37
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
+ },
38
39
  "files": [
39
40
  "dist",
40
41
  "bin"
41
42
  ],
42
- "main": "./dist/index.js",
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,
43
58
  "type": "module",
59
+ "types": "./dist/index.d.ts",
44
60
  "scripts": {
45
61
  "build": "tsdown",
46
62
  "dev": "tsdown --watch",