@durable-streams/cli 0.1.1 → 0.1.3
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/README.md +19 -12
- package/dist/index.cjs +168 -0
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/package.json +36 -19
package/README.md
CHANGED
|
@@ -4,31 +4,38 @@ A command-line tool for interacting with durable streams.
|
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
|
-
###
|
|
7
|
+
### From npm
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
#
|
|
11
|
-
|
|
10
|
+
# Global installation
|
|
11
|
+
npm install -g @durable-streams/cli
|
|
12
12
|
|
|
13
|
-
#
|
|
14
|
-
|
|
13
|
+
# Or run directly with npx
|
|
14
|
+
npx @durable-streams/cli create my-stream
|
|
15
|
+
npx @durable-streams/cli read my-stream
|
|
15
16
|
```
|
|
16
17
|
|
|
17
|
-
###
|
|
18
|
-
|
|
19
|
-
For development, you can link the CLI globally with live TypeScript execution (no rebuild needed):
|
|
18
|
+
### From source (for development)
|
|
20
19
|
|
|
21
20
|
```bash
|
|
22
|
-
#
|
|
21
|
+
# Clone the repository
|
|
22
|
+
git clone https://github.com/durable-streams/durable-streams.git
|
|
23
|
+
cd durable-streams
|
|
24
|
+
|
|
25
|
+
# Install dependencies
|
|
26
|
+
pnpm install
|
|
27
|
+
|
|
28
|
+
# Build the CLI
|
|
29
|
+
pnpm build
|
|
30
|
+
|
|
31
|
+
# Link globally for development (uses tsx, no rebuild needed)
|
|
32
|
+
cd packages/cli
|
|
23
33
|
pnpm link:dev
|
|
24
34
|
|
|
25
35
|
# Now you can use durable-stream-dev anywhere
|
|
26
|
-
# Changes to src/index.ts are immediately available
|
|
27
36
|
durable-stream-dev create my-stream
|
|
28
37
|
```
|
|
29
38
|
|
|
30
|
-
This uses `tsx` to run the TypeScript source directly, so you see changes immediately without rebuilding.
|
|
31
|
-
|
|
32
39
|
## Quick Start
|
|
33
40
|
|
|
34
41
|
The easiest way to get started is to run the local development server and use the CLI:
|
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
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/package.json
CHANGED
|
@@ -1,46 +1,63 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@durable-streams/cli",
|
|
3
3
|
"description": "CLI tool for working with Durable Streams",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.3",
|
|
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": {
|
|
7
|
+
"cli": "./dist/index.js",
|
|
22
8
|
"durable-stream": "./dist/index.js",
|
|
23
9
|
"durable-stream-dev": "./bin/durable-stream-dev.mjs"
|
|
24
10
|
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/durable-streams/durable-streams/issues"
|
|
13
|
+
},
|
|
25
14
|
"dependencies": {
|
|
26
|
-
"@durable-streams/client": "0.1.
|
|
15
|
+
"@durable-streams/client": "0.1.2"
|
|
27
16
|
},
|
|
28
17
|
"devDependencies": {
|
|
29
18
|
"@types/node": "^22.15.21",
|
|
30
19
|
"tsdown": "^0.9.0",
|
|
31
20
|
"tsx": "^4.19.2",
|
|
32
21
|
"typescript": "^5.5.2",
|
|
33
|
-
"@durable-streams/server": "0.1.
|
|
22
|
+
"@durable-streams/server": "0.1.3"
|
|
34
23
|
},
|
|
35
24
|
"engines": {
|
|
36
25
|
"node": ">=18.0.0"
|
|
37
26
|
},
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"import": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"default": "./dist/index.js"
|
|
32
|
+
},
|
|
33
|
+
"require": {
|
|
34
|
+
"types": "./dist/index.d.cts",
|
|
35
|
+
"default": "./dist/index.cjs"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"./package.json": "./package.json"
|
|
39
|
+
},
|
|
38
40
|
"files": [
|
|
39
41
|
"dist",
|
|
40
42
|
"bin"
|
|
41
43
|
],
|
|
42
|
-
"
|
|
44
|
+
"keywords": [
|
|
45
|
+
"cli",
|
|
46
|
+
"durable-streams",
|
|
47
|
+
"streaming",
|
|
48
|
+
"typescript"
|
|
49
|
+
],
|
|
50
|
+
"license": "Apache-2.0",
|
|
51
|
+
"main": "./dist/index.cjs",
|
|
52
|
+
"module": "./dist/index.js",
|
|
53
|
+
"repository": {
|
|
54
|
+
"type": "git",
|
|
55
|
+
"url": "git+https://github.com/durable-streams/durable-streams.git",
|
|
56
|
+
"directory": "packages/cli"
|
|
57
|
+
},
|
|
58
|
+
"sideEffects": false,
|
|
43
59
|
"type": "module",
|
|
60
|
+
"types": "./dist/index.d.ts",
|
|
44
61
|
"scripts": {
|
|
45
62
|
"build": "tsdown",
|
|
46
63
|
"dev": "tsdown --watch",
|