@interop/did-cli 0.12.0 → 0.14.0
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/CHANGELOG.md +131 -6
- package/README.md +184 -18
- package/dist/commands/did/create.d.ts +22 -0
- package/dist/commands/did/create.d.ts.map +1 -1
- package/dist/commands/did/create.js +6 -27
- package/dist/commands/did/create.js.map +1 -1
- package/dist/commands/did/service.d.ts +19 -4
- package/dist/commands/did/service.d.ts.map +1 -1
- package/dist/commands/did/service.js +46 -45
- package/dist/commands/did/service.js.map +1 -1
- package/dist/commands/did/webvh-update.d.ts +72 -9
- package/dist/commands/did/webvh-update.d.ts.map +1 -1
- package/dist/commands/did/webvh-update.js +177 -61
- package/dist/commands/did/webvh-update.js.map +1 -1
- package/dist/commands/did.d.ts.map +1 -1
- package/dist/commands/did.js +10 -1
- package/dist/commands/did.js.map +1 -1
- package/dist/commands/key.d.ts +2 -16
- package/dist/commands/key.d.ts.map +1 -1
- package/dist/commands/key.js +64 -11
- package/dist/commands/key.js.map +1 -1
- package/dist/commands/was/request-grant.d.ts +37 -0
- package/dist/commands/was/request-grant.d.ts.map +1 -0
- package/dist/commands/was/request-grant.js +248 -0
- package/dist/commands/was/request-grant.js.map +1 -0
- package/dist/commands/was/resource.d.ts +21 -7
- package/dist/commands/was/resource.d.ts.map +1 -1
- package/dist/commands/was/resource.js +40 -15
- package/dist/commands/was/resource.js.map +1 -1
- package/dist/commands/was/shared.d.ts +43 -3
- package/dist/commands/was/shared.d.ts.map +1 -1
- package/dist/commands/was/shared.js +82 -4
- package/dist/commands/was/shared.js.map +1 -1
- package/dist/commands/was/shell/completer.d.ts +24 -0
- package/dist/commands/was/shell/completer.d.ts.map +1 -0
- package/dist/commands/was/shell/completer.js +99 -0
- package/dist/commands/was/shell/completer.js.map +1 -0
- package/dist/commands/was/shell/dispatcher.d.ts +27 -0
- package/dist/commands/was/shell/dispatcher.d.ts.map +1 -0
- package/dist/commands/was/shell/dispatcher.js +227 -0
- package/dist/commands/was/shell/dispatcher.js.map +1 -0
- package/dist/commands/was/shell/session.d.ts +37 -0
- package/dist/commands/was/shell/session.d.ts.map +1 -0
- package/dist/commands/was/shell/session.js +67 -0
- package/dist/commands/was/shell/session.js.map +1 -0
- package/dist/commands/was/shell/tokenize.d.ts +19 -0
- package/dist/commands/was/shell/tokenize.d.ts.map +1 -0
- package/dist/commands/was/shell/tokenize.js +77 -0
- package/dist/commands/was/shell/tokenize.js.map +1 -0
- package/dist/commands/was/shell.d.ts +30 -0
- package/dist/commands/was/shell.d.ts.map +1 -0
- package/dist/commands/was/shell.js +170 -0
- package/dist/commands/was/shell.js.map +1 -0
- package/dist/commands/was/tree.d.ts +6 -1
- package/dist/commands/was/tree.d.ts.map +1 -1
- package/dist/commands/was/tree.js +12 -5
- package/dist/commands/was/tree.js.map +1 -1
- package/dist/commands/was.d.ts.map +1 -1
- package/dist/commands/was.js +31 -1
- package/dist/commands/was.js.map +1 -1
- package/dist/keys/seed.d.ts +21 -0
- package/dist/keys/seed.d.ts.map +1 -0
- package/dist/keys/seed.js +41 -0
- package/dist/keys/seed.js.map +1 -0
- package/dist/keys/webvh-signer.d.ts +18 -13
- package/dist/keys/webvh-signer.d.ts.map +1 -1
- package/dist/keys/webvh-signer.js +5 -20
- package/dist/keys/webvh-signer.js.map +1 -1
- package/dist/meta.js +1 -1
- package/dist/meta.js.map +1 -1
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +57 -10
- package/dist/storage.js.map +1 -1
- package/dist/was/address.d.ts +24 -0
- package/dist/was/address.d.ts.map +1 -1
- package/dist/was/address.js +49 -3
- package/dist/was/address.js.map +1 -1
- package/dist/was/request-grant.d.ts +144 -0
- package/dist/was/request-grant.d.ts.map +1 -0
- package/dist/was/request-grant.js +249 -0
- package/dist/was/request-grant.js.map +1 -0
- package/package.json +22 -20
|
@@ -2,34 +2,49 @@
|
|
|
2
2
|
* `was resource` run functions: add (server-generated id), put (upsert at a
|
|
3
3
|
* known id), get (JSON or binary), list, delete, and the resource-metadata
|
|
4
4
|
* verbs `meta get` / `meta put`. Each addressing-capable verb accepts either
|
|
5
|
-
* a path or a `--capability` targeting the resource or its collection.
|
|
5
|
+
* a path or a `--capability` targeting the resource or its collection. A
|
|
6
|
+
* collection capability names its resource with `--resource <id>`, which is
|
|
7
|
+
* how a grant scoped to a whole collection is invoked at one resource.
|
|
6
8
|
*/
|
|
7
9
|
import { readFile } from 'node:fs/promises';
|
|
8
10
|
import { resolveCapabilityTarget } from '../../was/capability.js';
|
|
9
11
|
import { readPayload, writeResourceOutput } from '../../was/io.js';
|
|
10
|
-
import { assertOneAddressing, printResourceListing, reportDeleted, reportError, reportNotFound, resolveCollectionTarget, resolveResourceTarget, wasUrl } from './shared.js';
|
|
12
|
+
import { assertOneAddressing, printResourceListing, reportDeleted, reportError, reportNotFound, resolveCollectionTarget, resolveResourceTarget, wasUrl, withResourceId } from './shared.js';
|
|
11
13
|
/**
|
|
12
14
|
* Resolves a single resource handle and its URL from either a path address
|
|
13
|
-
* or a `--capability`
|
|
14
|
-
*
|
|
15
|
+
* or a `--capability` -- the shared addressing logic of the resource verbs
|
|
16
|
+
* that operate on one resource (`put`, `get`, `meta`).
|
|
17
|
+
*
|
|
18
|
+
* The capability may target the resource itself, or the collection holding
|
|
19
|
+
* it together with `--resource <id>`. The second form is what a grant scoped
|
|
20
|
+
* to a whole collection needs: the id is chosen by the caller (unlike `add`,
|
|
21
|
+
* where the server picks it), and the resource handle inherits the
|
|
22
|
+
* collection's bound capability, so the write is still an invocation of the
|
|
23
|
+
* received grant.
|
|
15
24
|
*
|
|
16
25
|
* @param options {object}
|
|
17
26
|
* @param [options.address] {string} The resource address.
|
|
18
27
|
* @param [options.capability] {string} A capability reference instead of
|
|
19
28
|
* a path.
|
|
29
|
+
* @param [options.resource] {string} The resource id beneath a collection
|
|
30
|
+
* capability.
|
|
20
31
|
* @param options.verb {string} The verb name, for the capability-depth
|
|
21
32
|
* error message.
|
|
22
33
|
* @param [options.server] {string} The server base URL.
|
|
23
34
|
* @param [options.did] {string} The signing DID or stored-DID handle.
|
|
24
35
|
* @returns {Promise<{resource: Resource, url: string}>}
|
|
25
36
|
*/
|
|
26
|
-
async function resolveResourceHandle({ address, capability, verb, server, did }) {
|
|
27
|
-
assertOneAddressing({ address, capability });
|
|
37
|
+
async function resolveResourceHandle({ address, capability, resource: resourceId, verb, server, did }) {
|
|
38
|
+
assertOneAddressing({ address, capability, resource: resourceId });
|
|
28
39
|
if (capability) {
|
|
29
|
-
const resolved =
|
|
40
|
+
const resolved = withResourceId({
|
|
41
|
+
resolved: await resolveCapabilityTarget({ ref: capability, did }),
|
|
42
|
+
resourceId
|
|
43
|
+
});
|
|
30
44
|
if (resolved.depth !== 'resource') {
|
|
31
45
|
throw new Error(`The capability targets a ${resolved.depth}; ` +
|
|
32
|
-
`${verb} needs a resource capability
|
|
46
|
+
`${verb} needs a resource capability, or a collection capability ` +
|
|
47
|
+
'with --resource <id>.');
|
|
33
48
|
}
|
|
34
49
|
return { resource: resolved.handle, url: resolved.url };
|
|
35
50
|
}
|
|
@@ -108,13 +123,15 @@ export async function runResourceAdd(options) {
|
|
|
108
123
|
}
|
|
109
124
|
/**
|
|
110
125
|
* Creates or replaces a resource at a known id (upsert) and prints
|
|
111
|
-
* `{ id, url }`. The resource comes from a path
|
|
112
|
-
* targeting one
|
|
126
|
+
* `{ id, url }`. The resource comes from a path, a `--capability`
|
|
127
|
+
* targeting one, or a collection `--capability` plus `--resource <id>`.
|
|
113
128
|
*
|
|
114
129
|
* @param options {object}
|
|
115
130
|
* @param [options.address] {string} The resource address.
|
|
116
131
|
* @param [options.capability] {string} A capability reference instead of
|
|
117
132
|
* a path.
|
|
133
|
+
* @param [options.resource] {string} The resource id beneath a collection
|
|
134
|
+
* capability.
|
|
118
135
|
* @param [options.file] {string} The payload file; stdin when omitted.
|
|
119
136
|
* @param [options.contentType] {string} Explicit payload content type.
|
|
120
137
|
* @param [options.server] {string} The server base URL.
|
|
@@ -145,13 +162,15 @@ export async function runResourcePut(options) {
|
|
|
145
162
|
}
|
|
146
163
|
/**
|
|
147
164
|
* Reads a resource: JSON pretty-printed to stdout, binary written raw
|
|
148
|
-
* (`--output` for files). The resource comes from a path
|
|
149
|
-
* `--capability`
|
|
165
|
+
* (`--output` for files). The resource comes from a path, a `--capability`
|
|
166
|
+
* targeting one, or a collection `--capability` plus `--resource <id>`.
|
|
150
167
|
*
|
|
151
168
|
* @param options {object}
|
|
152
169
|
* @param [options.address] {string} The resource address.
|
|
153
170
|
* @param [options.capability] {string} A capability reference instead of
|
|
154
171
|
* a path.
|
|
172
|
+
* @param [options.resource] {string} The resource id beneath a collection
|
|
173
|
+
* capability.
|
|
155
174
|
* @param [options.output] {string} The output file path; stdout when
|
|
156
175
|
* omitted.
|
|
157
176
|
* @param [options.server] {string} The server base URL.
|
|
@@ -178,12 +197,15 @@ export async function runResourceGet(options) {
|
|
|
178
197
|
/**
|
|
179
198
|
* Reads a resource's metadata object (server-managed `contentType` / `size` /
|
|
180
199
|
* timestamps plus the user-writable `custom`) and pretty-prints it. The
|
|
181
|
-
* resource comes from a path
|
|
200
|
+
* resource comes from a path, a `--capability` targeting one, or a
|
|
201
|
+
* collection `--capability` plus `--resource <id>`.
|
|
182
202
|
*
|
|
183
203
|
* @param options {object}
|
|
184
204
|
* @param [options.address] {string} The resource address.
|
|
185
205
|
* @param [options.capability] {string} A capability reference instead of
|
|
186
206
|
* a path.
|
|
207
|
+
* @param [options.resource] {string} The resource id beneath a collection
|
|
208
|
+
* capability.
|
|
187
209
|
* @param [options.server] {string} The server base URL.
|
|
188
210
|
* @param [options.did] {string} The signing DID or stored-DID handle.
|
|
189
211
|
* @returns {Promise<number>} The process exit code.
|
|
@@ -259,13 +281,16 @@ async function parseCustomJson(input) {
|
|
|
259
281
|
* Updates a resource's user-writable metadata and prints the resulting
|
|
260
282
|
* metadata. `--name`/`--tag` are read-modify-write sugar that preserve the
|
|
261
283
|
* other field; giving both, or `--json`, is a full `custom` replacement so
|
|
262
|
-
* any omitted property is cleared. The resource comes from a path
|
|
263
|
-
* `--capability` targeting one
|
|
284
|
+
* any omitted property is cleared. The resource comes from a path, a
|
|
285
|
+
* `--capability` targeting one, or a collection `--capability` plus
|
|
286
|
+
* `--resource <id>`.
|
|
264
287
|
*
|
|
265
288
|
* @param options {object}
|
|
266
289
|
* @param [options.address] {string} The resource address.
|
|
267
290
|
* @param [options.capability] {string} A capability reference instead of
|
|
268
291
|
* a path.
|
|
292
|
+
* @param [options.resource] {string} The resource id beneath a collection
|
|
293
|
+
* capability.
|
|
269
294
|
* @param [options.name] {string} The resource's display name.
|
|
270
295
|
* @param options.tag {string[]} Repeatable `key=value` tag pairs.
|
|
271
296
|
* @param [options.json] {string} Full `custom` JSON (inline or a file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource.js","sourceRoot":"","sources":["../../../src/commands/was/resource.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"resource.js","sourceRoot":"","sources":["../../../src/commands/was/resource.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAM3C,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAA;AACjE,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAClE,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,aAAa,EACb,WAAW,EACX,cAAc,EACd,uBAAuB,EACvB,qBAAqB,EACrB,MAAM,EACN,cAAc,EACf,MAAM,aAAa,CAAA;AAEpB;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,KAAK,UAAU,qBAAqB,CAAC,EACnC,OAAO,EACP,UAAU,EACV,QAAQ,EAAE,UAAU,EACpB,IAAI,EACJ,MAAM,EACN,GAAG,EAQJ;IACC,mBAAmB,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,QAA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vC;IACC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,qBAAqB,CAAC,OAAO,CAAC,CAAA;QACnD,MAAM,MAAM,CAAC,MAAM;aAChB,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC;aACrB,UAAU,CAAC,MAAM,CAAC,YAAY,CAAC;aAC/B,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC;aAC3B,MAAM,EAAE,CAAA;QACX,aAAa,CACX,MAAM,CAAC;YACL,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,YAAY,EAAE,MAAM,CAAC,YAAY;YACjC,UAAU,EAAE,MAAM,CAAC,UAAU;SAC9B,CAAC,CACH,CAAA;QACD,OAAO,CAAC,CAAA;IACV,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,WAAW,CAAC,EAAE,MAAM,EAAE,qBAAqB,EAAE,GAAG,EAAE,CAAC,CAAA;IAC5D,CAAC;AACH,CAAC"}
|
|
@@ -1,9 +1,27 @@
|
|
|
1
1
|
import { Option } from 'commander';
|
|
2
2
|
import { type Collection, type CollectionsList, type Resource, type CollectionResourcesList, type Space } from '@interop/was-client';
|
|
3
|
+
import type { ResolvedCapabilityTarget } from '../../was/capability.js';
|
|
3
4
|
import { type ResolvedWasTarget } from '../../was/client.js';
|
|
5
|
+
/**
|
|
6
|
+
* Installs (or clears) the exit reporter used by `runAndExit`. With a reporter
|
|
7
|
+
* set, `runAndExit` never touches `process.exit`; call with no argument to
|
|
8
|
+
* restore the default process-exiting behavior.
|
|
9
|
+
*
|
|
10
|
+
* @param [reporter] {(code: number) => void}
|
|
11
|
+
* @returns {void}
|
|
12
|
+
*/
|
|
13
|
+
export declare function setRunAndExitReporter(reporter?: (code: number) => void): void;
|
|
4
14
|
/**
|
|
5
15
|
* Awaits a command's run function and exits the process with its code when
|
|
6
|
-
* non-zero -- the shared tail of every `was` command action.
|
|
16
|
+
* non-zero -- the shared tail of every `was` command action. When an exit
|
|
17
|
+
* reporter is installed (the interactive shell), the code is handed to the
|
|
18
|
+
* reporter instead, so a command failure returns control to the REPL loop
|
|
19
|
+
* rather than exiting the process.
|
|
20
|
+
*
|
|
21
|
+
* A run function normally reports its own errors and returns a code; an
|
|
22
|
+
* error that escapes anyway is caught here and reported as a one-line
|
|
23
|
+
* message with exit code 1, instead of surfacing as an unhandled rejection
|
|
24
|
+
* with a raw stack trace (which would also bypass the shell's reporter).
|
|
7
25
|
*
|
|
8
26
|
* @param run {Promise<number>}
|
|
9
27
|
* @returns {Promise<void>}
|
|
@@ -20,20 +38,42 @@ export declare function runAndExit(run: Promise<number>): Promise<void>;
|
|
|
20
38
|
export declare function serverOption(): Option;
|
|
21
39
|
export declare function didOption(): Option;
|
|
22
40
|
export declare function capabilityOption(): Option;
|
|
41
|
+
export declare function resourceIdOption(): Option;
|
|
23
42
|
export declare function contentTypeOption(): Option;
|
|
24
43
|
/**
|
|
25
44
|
* Guards a run function against receiving both path- and capability-based
|
|
26
|
-
* addressing (or neither).
|
|
45
|
+
* addressing (or neither). `--resource <id>` is part of capability
|
|
46
|
+
* addressing -- it names a resource beneath a collection capability -- so it
|
|
47
|
+
* is rejected first when no capability anchors it, whether or not a path was
|
|
48
|
+
* also given.
|
|
27
49
|
*
|
|
28
50
|
* @param options {object}
|
|
29
51
|
* @param [options.address] {string}
|
|
30
52
|
* @param [options.capability] {string}
|
|
53
|
+
* @param [options.resource] {string} The `--resource` value.
|
|
31
54
|
* @returns {void}
|
|
32
55
|
*/
|
|
33
|
-
export declare function assertOneAddressing({ address, capability }: {
|
|
56
|
+
export declare function assertOneAddressing({ address, capability, resource }: {
|
|
34
57
|
address?: string;
|
|
35
58
|
capability?: string;
|
|
59
|
+
resource?: string;
|
|
36
60
|
}): void;
|
|
61
|
+
/**
|
|
62
|
+
* Applies `--resource <id>` to a resolved capability target, returning the
|
|
63
|
+
* target unchanged when no id was given. The id names a resource beneath a
|
|
64
|
+
* collection capability, and the resource handle hangs off that capability's
|
|
65
|
+
* collection handle, so it inherits the bound capability and the request
|
|
66
|
+
* stays an invocation of the received grant.
|
|
67
|
+
*
|
|
68
|
+
* @param options {object}
|
|
69
|
+
* @param options.resolved {ResolvedCapabilityTarget}
|
|
70
|
+
* @param [options.resourceId] {string} The `--resource` value.
|
|
71
|
+
* @returns {ResolvedCapabilityTarget}
|
|
72
|
+
*/
|
|
73
|
+
export declare function withResourceId({ resolved, resourceId }: {
|
|
74
|
+
resolved: ResolvedCapabilityTarget;
|
|
75
|
+
resourceId?: string;
|
|
76
|
+
}): ResolvedCapabilityTarget;
|
|
37
77
|
/**
|
|
38
78
|
* Builds the canonical URL of a space, collection, or resource on its
|
|
39
79
|
* server, for messages and output.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../../src/commands/was/shared.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAClC,OAAO,EAEL,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,QAAQ,EACb,KAAK,uBAAuB,EAC5B,KAAK,KAAK,EACX,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EAAoB,KAAK,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../../src/commands/was/shared.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAClC,OAAO,EAEL,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,QAAQ,EACb,KAAK,uBAAuB,EAC5B,KAAK,KAAK,EACX,MAAM,qBAAqB,CAAA;AAE5B,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAA;AACvE,OAAO,EAAoB,KAAK,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAW9E;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,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C,EAAE,MAAM,CAAA;CACb,GAAG,OAAO,CAAC,iBAAiB,GAAG;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC,CAK5E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CAAC,EACtC,OAAO,EACP,IAAI,EACJ,UAAU,EACX,EAAE;IACD,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB,GAAG;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAKtC;AA4CD;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,EACrC,OAAO,EACP,IAAI,EACJ,KAAK,EACN,EAAE;IACD,OAAO,EAAE,eAAe,CAAA;IACxB,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,GAAG,IAAI,CAYP;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,EACnC,OAAO,EACP,IAAI,EACJ,KAAK,EACN,EAAE;IACD,OAAO,EAAE,uBAAuB,CAAA;IAChC,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,GAAG,IAAI,CAYP;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,IAAI,CAO3D;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,iBAAiB,GAAG;IAC1D,MAAM,EAAE,KAAK,GAAG,UAAU,GAAG,QAAQ,CAAA;IACrC,GAAG,EAAE,MAAM,CAAA;CACZ,CAgBA"}
|
|
@@ -10,15 +10,52 @@ import { WasError } from '@interop/was-client';
|
|
|
10
10
|
import { parseWasAddress } from '../../was/address.js';
|
|
11
11
|
import { resolveWasTarget } from '../../was/client.js';
|
|
12
12
|
import { renderTable } from '../../table.js';
|
|
13
|
+
/**
|
|
14
|
+
* The active exit reporter, if any. When set (by the interactive shell),
|
|
15
|
+
* `runAndExit` reports the exit code through it instead of calling
|
|
16
|
+
* `process.exit`, keeping the tree shell-safe (no `runXxx` ever calls
|
|
17
|
+
* `process.exit`). Mirrors the `setWasClientFactory` seam convention.
|
|
18
|
+
*/
|
|
19
|
+
let exitReporter;
|
|
20
|
+
/**
|
|
21
|
+
* Installs (or clears) the exit reporter used by `runAndExit`. With a reporter
|
|
22
|
+
* set, `runAndExit` never touches `process.exit`; call with no argument to
|
|
23
|
+
* restore the default process-exiting behavior.
|
|
24
|
+
*
|
|
25
|
+
* @param [reporter] {(code: number) => void}
|
|
26
|
+
* @returns {void}
|
|
27
|
+
*/
|
|
28
|
+
export function setRunAndExitReporter(reporter) {
|
|
29
|
+
exitReporter = reporter;
|
|
30
|
+
}
|
|
13
31
|
/**
|
|
14
32
|
* Awaits a command's run function and exits the process with its code when
|
|
15
|
-
* non-zero -- the shared tail of every `was` command action.
|
|
33
|
+
* non-zero -- the shared tail of every `was` command action. When an exit
|
|
34
|
+
* reporter is installed (the interactive shell), the code is handed to the
|
|
35
|
+
* reporter instead, so a command failure returns control to the REPL loop
|
|
36
|
+
* rather than exiting the process.
|
|
37
|
+
*
|
|
38
|
+
* A run function normally reports its own errors and returns a code; an
|
|
39
|
+
* error that escapes anyway is caught here and reported as a one-line
|
|
40
|
+
* message with exit code 1, instead of surfacing as an unhandled rejection
|
|
41
|
+
* with a raw stack trace (which would also bypass the shell's reporter).
|
|
16
42
|
*
|
|
17
43
|
* @param run {Promise<number>}
|
|
18
44
|
* @returns {Promise<void>}
|
|
19
45
|
*/
|
|
20
46
|
export async function runAndExit(run) {
|
|
21
|
-
|
|
47
|
+
let code;
|
|
48
|
+
try {
|
|
49
|
+
code = await run;
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
console.error(err instanceof Error ? err.message : String(err));
|
|
53
|
+
code = 1;
|
|
54
|
+
}
|
|
55
|
+
if (exitReporter) {
|
|
56
|
+
exitReporter(code);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
22
59
|
if (code !== 0) {
|
|
23
60
|
process.exit(code);
|
|
24
61
|
}
|
|
@@ -41,19 +78,30 @@ export function capabilityOption() {
|
|
|
41
78
|
return new Option('--capability <ref>', 'a received capability (encoded string, JSON file, or stored zcap ' +
|
|
42
79
|
'id/handle) instead of a path');
|
|
43
80
|
}
|
|
81
|
+
export function resourceIdOption() {
|
|
82
|
+
return new Option('--resource <id>', 'the resource id to operate on beneath a collection --capability');
|
|
83
|
+
}
|
|
44
84
|
export function contentTypeOption() {
|
|
45
85
|
return new Option('--content-type <type>', 'send the payload as-is with this content type (skips JSON detection)');
|
|
46
86
|
}
|
|
47
87
|
/**
|
|
48
88
|
* Guards a run function against receiving both path- and capability-based
|
|
49
|
-
* addressing (or neither).
|
|
89
|
+
* addressing (or neither). `--resource <id>` is part of capability
|
|
90
|
+
* addressing -- it names a resource beneath a collection capability -- so it
|
|
91
|
+
* is rejected first when no capability anchors it, whether or not a path was
|
|
92
|
+
* also given.
|
|
50
93
|
*
|
|
51
94
|
* @param options {object}
|
|
52
95
|
* @param [options.address] {string}
|
|
53
96
|
* @param [options.capability] {string}
|
|
97
|
+
* @param [options.resource] {string} The `--resource` value.
|
|
54
98
|
* @returns {void}
|
|
55
99
|
*/
|
|
56
|
-
export function assertOneAddressing({ address, capability }) {
|
|
100
|
+
export function assertOneAddressing({ address, capability, resource }) {
|
|
101
|
+
if (resource !== undefined && !capability) {
|
|
102
|
+
throw new Error('--resource names a resource beneath a collection --capability; ' +
|
|
103
|
+
'a path already names one.');
|
|
104
|
+
}
|
|
57
105
|
if (address && capability) {
|
|
58
106
|
throw new Error('Provide either a path or --capability, not both.');
|
|
59
107
|
}
|
|
@@ -61,6 +109,36 @@ export function assertOneAddressing({ address, capability }) {
|
|
|
61
109
|
throw new Error('Provide a path or --capability.');
|
|
62
110
|
}
|
|
63
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* Applies `--resource <id>` to a resolved capability target, returning the
|
|
114
|
+
* target unchanged when no id was given. The id names a resource beneath a
|
|
115
|
+
* collection capability, and the resource handle hangs off that capability's
|
|
116
|
+
* collection handle, so it inherits the bound capability and the request
|
|
117
|
+
* stays an invocation of the received grant.
|
|
118
|
+
*
|
|
119
|
+
* @param options {object}
|
|
120
|
+
* @param options.resolved {ResolvedCapabilityTarget}
|
|
121
|
+
* @param [options.resourceId] {string} The `--resource` value.
|
|
122
|
+
* @returns {ResolvedCapabilityTarget}
|
|
123
|
+
*/
|
|
124
|
+
export function withResourceId({ resolved, resourceId }) {
|
|
125
|
+
if (resourceId === undefined) {
|
|
126
|
+
return resolved;
|
|
127
|
+
}
|
|
128
|
+
if (resolved.depth === 'resource') {
|
|
129
|
+
throw new Error('The capability already targets a resource; drop --resource.');
|
|
130
|
+
}
|
|
131
|
+
if (resolved.depth !== 'collection') {
|
|
132
|
+
throw new Error('--resource names a resource beneath a collection capability; ' +
|
|
133
|
+
`this one targets a ${resolved.depth}.`);
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
...resolved,
|
|
137
|
+
depth: 'resource',
|
|
138
|
+
handle: resolved.handle.resource(resourceId),
|
|
139
|
+
url: `${resolved.url.replace(/\/$/, '')}/${encodeURIComponent(resourceId)}`
|
|
140
|
+
};
|
|
141
|
+
}
|
|
64
142
|
/**
|
|
65
143
|
* Builds the canonical URL of a space, collection, or resource on its
|
|
66
144
|
* server, for messages and output.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/commands/was/shared.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAClC,OAAO,EACL,QAAQ,EAMT,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MAAM,CAAC,OAAO,CAAC,CAAA;IACjD,IAAI,MAAM,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;QACtC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,CAAA;IAC/B,CAAC;IACD,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,YAAY,CAAC,CAAA;IACxD,IAAI,MAAM,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;QACpC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,CAAA;IACpC,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,GAAG,EAAE,CAAA;AAChE,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tab-completion for the interactive shell's readline interface. Completes the
|
|
3
|
+
* first word (builtins plus top-level subcommand names and aliases), the
|
|
4
|
+
* subcommand after a command group (`space`, `collection`, `resource`,
|
|
5
|
+
* `resource-meta`, `policy`), and -- at the root working directory -- the first
|
|
6
|
+
* path segment of a path verb from the local space registry (handles and ids).
|
|
7
|
+
* Network-backed completion (collection/resource listings) is deferred.
|
|
8
|
+
*/
|
|
9
|
+
import type { Command } from 'commander';
|
|
10
|
+
import type { ShellSession } from './session.js';
|
|
11
|
+
/**
|
|
12
|
+
* Builds the readline completer function bound to the command tree and shell
|
|
13
|
+
* session.
|
|
14
|
+
*
|
|
15
|
+
* @param options {object}
|
|
16
|
+
* @param options.tree {Command} The `was` command tree.
|
|
17
|
+
* @param options.session {ShellSession}
|
|
18
|
+
* @returns {(line: string) => Promise<[string[], string]>}
|
|
19
|
+
*/
|
|
20
|
+
export declare function makeShellCompleter({ tree, session }: {
|
|
21
|
+
tree: Command;
|
|
22
|
+
session: ShellSession;
|
|
23
|
+
}): (line: string) => Promise<[string[], string]>;
|
|
24
|
+
//# sourceMappingURL=completer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"completer.d.ts","sourceRoot":"","sources":["../../../../src/commands/was/shell/completer.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAExC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAkFhD;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,IAAI,EACJ,OAAO,EACR,EAAE;IACD,IAAI,EAAE,OAAO,CAAA;IACb,OAAO,EAAE,YAAY,CAAA;CACtB,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,MAAM,CAAC,CAAC,CA6BhD"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { listSpaceRecords } from '../../../was/registry.js';
|
|
2
|
+
/** The shell builtins, offered as first-word completions. */
|
|
3
|
+
const BUILTINS = ['cd', 'use', 'pwd', 'connect', 'did', 'help', 'exit', 'quit'];
|
|
4
|
+
/** Top-level verbs that take a WAS path as their first positional argument. */
|
|
5
|
+
const PATH_VERBS = new Set([
|
|
6
|
+
'ls',
|
|
7
|
+
'get',
|
|
8
|
+
'put',
|
|
9
|
+
'rm',
|
|
10
|
+
'publish',
|
|
11
|
+
'unpublish',
|
|
12
|
+
'grant'
|
|
13
|
+
]);
|
|
14
|
+
/**
|
|
15
|
+
* Collects a command's own name plus its aliases.
|
|
16
|
+
*
|
|
17
|
+
* @param command {Command}
|
|
18
|
+
* @returns {string[]}
|
|
19
|
+
*/
|
|
20
|
+
function namesOf(command) {
|
|
21
|
+
return [command.name(), ...command.aliases()];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Finds a direct subcommand of a command by name or alias.
|
|
25
|
+
*
|
|
26
|
+
* @param options {object}
|
|
27
|
+
* @param options.parent {Command}
|
|
28
|
+
* @param options.name {string}
|
|
29
|
+
* @returns {Command | undefined}
|
|
30
|
+
*/
|
|
31
|
+
function findSubcommand({ parent, name }) {
|
|
32
|
+
return parent.commands.find(command => namesOf(command).includes(name));
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Narrows a candidate list to those starting with the word being edited,
|
|
36
|
+
* falling back to the full list when nothing matches (so a bare Tab lists
|
|
37
|
+
* everything).
|
|
38
|
+
*
|
|
39
|
+
* @param options {object}
|
|
40
|
+
* @param options.candidates {string[]}
|
|
41
|
+
* @param options.editing {string}
|
|
42
|
+
* @returns {string[]}
|
|
43
|
+
*/
|
|
44
|
+
function filterHits({ candidates, editing }) {
|
|
45
|
+
const hits = candidates.filter(candidate => candidate.startsWith(editing));
|
|
46
|
+
return hits.length > 0 ? hits : candidates;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Lists the registry space completions (handles and space ids).
|
|
50
|
+
*
|
|
51
|
+
* @returns {Promise<string[]>}
|
|
52
|
+
*/
|
|
53
|
+
async function spaceCompletions() {
|
|
54
|
+
const records = await listSpaceRecords();
|
|
55
|
+
const out = [];
|
|
56
|
+
for (const { record, meta } of records) {
|
|
57
|
+
if (meta?.handle) {
|
|
58
|
+
out.push(meta.handle);
|
|
59
|
+
}
|
|
60
|
+
out.push(record.id);
|
|
61
|
+
}
|
|
62
|
+
return out;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Builds the readline completer function bound to the command tree and shell
|
|
66
|
+
* session.
|
|
67
|
+
*
|
|
68
|
+
* @param options {object}
|
|
69
|
+
* @param options.tree {Command} The `was` command tree.
|
|
70
|
+
* @param options.session {ShellSession}
|
|
71
|
+
* @returns {(line: string) => Promise<[string[], string]>}
|
|
72
|
+
*/
|
|
73
|
+
export function makeShellCompleter({ tree, session }) {
|
|
74
|
+
return async function completer(line) {
|
|
75
|
+
const words = line.split(/\s+/);
|
|
76
|
+
const editing = words[words.length - 1] ?? '';
|
|
77
|
+
if (words.length <= 1) {
|
|
78
|
+
const candidates = [...BUILTINS, ...tree.commands.flatMap(namesOf)].sort();
|
|
79
|
+
return [filterHits({ candidates, editing }), editing];
|
|
80
|
+
}
|
|
81
|
+
const first = words[0];
|
|
82
|
+
if (words.length === 2) {
|
|
83
|
+
const group = findSubcommand({ parent: tree, name: first });
|
|
84
|
+
if (group && group.commands.length > 0) {
|
|
85
|
+
const candidates = group.commands.flatMap(namesOf).sort();
|
|
86
|
+
return [filterHits({ candidates, editing }), editing];
|
|
87
|
+
}
|
|
88
|
+
if (session.cwd.length === 0 && PATH_VERBS.has(first)) {
|
|
89
|
+
const candidates = (await spaceCompletions()).sort();
|
|
90
|
+
return [
|
|
91
|
+
candidates.filter(candidate => candidate.startsWith(editing)),
|
|
92
|
+
editing
|
|
93
|
+
];
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return [[], editing];
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=completer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"completer.js","sourceRoot":"","sources":["../../../../src/commands/was/shell/completer.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAG3D,6DAA6D;AAC7D,MAAM,QAAQ,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;AAE/E,+EAA+E;AAC/E,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC;IACzB,IAAI;IACJ,KAAK;IACL,KAAK;IACL,IAAI;IACJ,SAAS;IACT,WAAW;IACX,OAAO;CACR,CAAC,CAAA;AAEF;;;;;GAKG;AACH,SAAS,OAAO,CAAC,OAAgB;IAC/B,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAAA;AAC/C,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,cAAc,CAAC,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cher: tokenizes a line, handles the
|
|
3
|
+
* builtins (`cd`/`use`, `pwd`, `connect`, `did`, `help`, `exit`/`quit`, blank
|
|
4
|
+
* and `#`-comment lines, and a rejected nested `shell`), guards stdin-payload
|
|
5
|
+
* commands that would fight readline for stdin, then hands the rest to the
|
|
6
|
+
* shared command tree via `parseAsync`. Command errors are reported by the
|
|
7
|
+
* commands themselves (and swallowed as `CommanderError`s here), so a bad line
|
|
8
|
+
* never stops the loop.
|
|
9
|
+
*/
|
|
10
|
+
import { Command } from 'commander';
|
|
11
|
+
import { type ShellSession } from './session.js';
|
|
12
|
+
/**
|
|
13
|
+
* Builds the per-line dispatch function bound to the command tree. The
|
|
14
|
+
* returned function reports `'exit'` when the loop should stop.
|
|
15
|
+
*
|
|
16
|
+
* @param options {object}
|
|
17
|
+
* @param options.tree {Command}
|
|
18
|
+
* @returns {(options: {line: string, session: ShellSession, output: NodeJS.WritableStream}) => Promise<'exit' | void>}
|
|
19
|
+
*/
|
|
20
|
+
export declare function makeWasShellDispatcher({ tree }: {
|
|
21
|
+
tree: Command;
|
|
22
|
+
}): (options: {
|
|
23
|
+
line: string;
|
|
24
|
+
session: ShellSession;
|
|
25
|
+
output: NodeJS.WritableStream;
|
|
26
|
+
}) => Promise<'exit' | void>;
|
|
27
|
+
//# sourceMappingURL=dispatcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispatcher.d.ts","sourceRoot":"","sources":["../../../../src/commands/was/shell/dispatcher.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,OAAO,EAAkB,MAAM,WAAW,CAAA;AAEnD,OAAO,EAA+B,KAAK,YAAY,EAAE,MAAM,cAAc,CAAA;AAuK7E;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,EACrC,IAAI,EACL,EAAE;IACD,IAAI,EAAE,OAAO,CAAA;CACd,GAAG,CAAC,OAAO,EAAE;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,YAAY,CAAA;IACrB,MAAM,EAAE,MAAM,CAAC,cAAc,CAAA;CAC9B,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAgF3B"}
|