@orchagent/cli 0.3.118 → 0.3.119
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/commands/storage.js +52 -20
- package/package.json +1 -1
package/dist/commands/storage.js
CHANGED
|
@@ -98,29 +98,61 @@ function formatBytes(bytes) {
|
|
|
98
98
|
return `${(bytes / 1024).toFixed(1)} KB`;
|
|
99
99
|
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
100
100
|
}
|
|
101
|
+
async function readStdin() {
|
|
102
|
+
if (process.stdin.isTTY) {
|
|
103
|
+
throw new errors_1.CliError('No JSON value provided.\n\n' +
|
|
104
|
+
'Usage:\n' +
|
|
105
|
+
' orch storage set <ns> <key> \'{"k":"v"}\' Inline JSON\n' +
|
|
106
|
+
' orch storage set <ns> <key> @file.json Read from file\n' +
|
|
107
|
+
' echo \'{"k":"v"}\' | orch storage set <ns> <key> - Read from stdin\n' +
|
|
108
|
+
' cat data.json | orch storage set <ns> <key> Pipe (implicit stdin)');
|
|
109
|
+
}
|
|
110
|
+
const chunks = [];
|
|
111
|
+
for await (const chunk of process.stdin) {
|
|
112
|
+
chunks.push(Buffer.from(chunk));
|
|
113
|
+
}
|
|
114
|
+
if (!chunks.length) {
|
|
115
|
+
throw new errors_1.CliError('No data received on stdin.');
|
|
116
|
+
}
|
|
117
|
+
return Buffer.concat(chunks).toString('utf8');
|
|
118
|
+
}
|
|
101
119
|
async function parseJsonArg(arg) {
|
|
102
|
-
|
|
103
|
-
if (arg
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
120
|
+
let raw;
|
|
121
|
+
if (!arg || arg === '-') {
|
|
122
|
+
// Read from stdin
|
|
123
|
+
raw = await readStdin();
|
|
124
|
+
}
|
|
125
|
+
else if (arg.startsWith('@')) {
|
|
126
|
+
// Support @file.json and @- syntax
|
|
127
|
+
const source = arg.slice(1);
|
|
128
|
+
if (source === '-') {
|
|
129
|
+
raw = await readStdin();
|
|
109
130
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
131
|
+
else {
|
|
132
|
+
const fs = await Promise.resolve().then(() => __importStar(require('fs/promises')));
|
|
133
|
+
try {
|
|
134
|
+
raw = await fs.readFile(source, 'utf-8');
|
|
135
|
+
}
|
|
136
|
+
catch (err) {
|
|
137
|
+
if (err.code === 'ENOENT') {
|
|
138
|
+
throw new errors_1.CliError(`File not found: ${source}`);
|
|
139
|
+
}
|
|
140
|
+
throw new errors_1.CliError(`Failed to read ${source}: ${err.message}`);
|
|
113
141
|
}
|
|
114
|
-
throw new errors_1.CliError(`Invalid JSON in ${filePath}: ${err.message}`);
|
|
115
142
|
}
|
|
116
143
|
}
|
|
144
|
+
else {
|
|
145
|
+
raw = arg;
|
|
146
|
+
}
|
|
117
147
|
try {
|
|
118
|
-
return JSON.parse(
|
|
148
|
+
return JSON.parse(raw);
|
|
119
149
|
}
|
|
120
150
|
catch {
|
|
121
151
|
throw new errors_1.CliError('Invalid JSON value.\n\n' +
|
|
122
|
-
'Pass valid JSON
|
|
123
|
-
'
|
|
152
|
+
'Pass valid JSON, @file.json, or pipe via stdin:\n' +
|
|
153
|
+
' orch storage set signals 2026-03-05 \'{"pending": []}\'\n' +
|
|
154
|
+
' orch storage set signals 2026-03-05 @data.json\n' +
|
|
155
|
+
' echo \'{"pending": []}\' | orch storage set signals 2026-03-05 -');
|
|
124
156
|
}
|
|
125
157
|
}
|
|
126
158
|
// ============================================
|
|
@@ -220,10 +252,10 @@ function registerStorageCommand(program) {
|
|
|
220
252
|
chalk_1.default.gray(`updated: ${formatDate(result.updated_at)} by ${result.updated_by}\n\n`));
|
|
221
253
|
process.stdout.write(JSON.stringify(result.value, null, 2) + '\n');
|
|
222
254
|
});
|
|
223
|
-
// orch storage set <namespace> <key>
|
|
255
|
+
// orch storage set <namespace> <key> [value]
|
|
224
256
|
storage
|
|
225
|
-
.command('set <namespace> <key>
|
|
226
|
-
.description('Create or update a document (JSON string
|
|
257
|
+
.command('set <namespace> <key> [value]')
|
|
258
|
+
.description('Create or update a document (JSON string, @file.json, or - for stdin)')
|
|
227
259
|
.option('--workspace <slug>', 'Workspace slug (default: current workspace)')
|
|
228
260
|
.option('--version <n>', 'Expected version for compare-and-swap (CAS)')
|
|
229
261
|
.action(async (namespace, key, value, options) => {
|
|
@@ -251,10 +283,10 @@ function registerStorageCommand(program) {
|
|
|
251
283
|
` ${namespace}/${key} ` +
|
|
252
284
|
chalk_1.default.gray(`v${result.version} (${formatBytes(result.size_bytes)})\n`));
|
|
253
285
|
});
|
|
254
|
-
// orch storage patch <namespace> <key>
|
|
286
|
+
// orch storage patch <namespace> <key> [value]
|
|
255
287
|
storage
|
|
256
|
-
.command('patch <namespace> <key>
|
|
257
|
-
.description('Merge-patch a document (
|
|
288
|
+
.command('patch <namespace> <key> [value]')
|
|
289
|
+
.description('Merge-patch a document (JSON string, @file.json, or - for stdin)')
|
|
258
290
|
.option('--workspace <slug>', 'Workspace slug (default: current workspace)')
|
|
259
291
|
.action(async (namespace, key, value, options) => {
|
|
260
292
|
const config = await (0, config_1.getResolvedConfig)();
|
package/package.json
CHANGED