@ipab/cli 0.1.0-rc.14 → 0.1.0-rc.16
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/authoring.d.ts +3 -1
- package/dist/authoring.d.ts.map +1 -1
- package/dist/authoring.js +14 -2
- package/dist/authoring.js.map +1 -1
- package/dist/builtins/skill.ipab.car +0 -0
- package/dist/builtins/template.bundle-viewer.car +0 -0
- package/dist/builtins/template.web-app.car +0 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +62 -45
- package/dist/cli.js.map +1 -1
- package/dist/daemon-api.d.ts.map +1 -1
- package/dist/daemon-api.js +59 -19
- package/dist/daemon-api.js.map +1 -1
- package/dist/daemon-client.d.ts +67 -20
- package/dist/daemon-client.d.ts.map +1 -1
- package/dist/daemon-client.js.map +1 -1
- package/dist/publish-source.d.ts +8 -1
- package/dist/publish-source.d.ts.map +1 -1
- package/dist/publish-source.js +71 -13
- package/dist/publish-source.js.map +1 -1
- package/dist/swarm-fs-core.d.ts +7 -2
- package/dist/swarm-fs-core.d.ts.map +1 -1
- package/dist/swarm-fs-core.js +30 -4
- package/dist/swarm-fs-core.js.map +1 -1
- package/dist/swarm.d.ts +21 -1
- package/dist/swarm.d.ts.map +1 -1
- package/dist/swarm.js +186 -49
- package/dist/swarm.js.map +1 -1
- package/dist/template-source.d.ts +1 -1
- package/dist/template-source.d.ts.map +1 -1
- package/dist/template-source.js +1 -6
- package/dist/template-source.js.map +1 -1
- package/dist/templates.d.ts +2 -1
- package/dist/templates.d.ts.map +1 -1
- package/dist/templates.js +11 -2
- package/dist/templates.js.map +1 -1
- package/dist/unixfs-tree.d.ts +1 -1
- package/dist/unixfs-tree.d.ts.map +1 -1
- package/dist/unixfs-tree.js +5 -2
- package/dist/unixfs-tree.js.map +1 -1
- package/package.json +3 -3
- package/src/authoring.ts +21 -9
- package/src/cli.ts +67 -49
- package/src/daemon-api.ts +74 -20
- package/src/daemon-client.ts +62 -22
- package/src/publish-source.ts +98 -12
- package/src/swarm-fs-core.ts +47 -3
- package/src/swarm.ts +281 -54
- package/src/template-source.ts +1 -6
- package/src/templates.ts +16 -1
- package/src/unixfs-tree.ts +3 -1
- package/dist/builtins/template.check.car +0 -0
package/src/publish-source.ts
CHANGED
|
@@ -6,21 +6,51 @@ import { encodeBundleCar, memoryTree, readBytes } from "@ipab/bundle-builder";
|
|
|
6
6
|
import { filesystemTree } from "@ipab/bundle-builder/node";
|
|
7
7
|
import { bundleLimits } from "@ipab/bundle";
|
|
8
8
|
import type { IpfsStore } from "@ipab/ipfs-store";
|
|
9
|
+
import type { IpfsReadOptions, StagedBlock } from "@ipab/ipfs-store";
|
|
10
|
+
import type { Ownership } from "./history.js";
|
|
9
11
|
import { HostError } from "./errors.js";
|
|
10
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
importBundle,
|
|
14
|
+
nodeError,
|
|
15
|
+
selectedTree,
|
|
16
|
+
snapshotLocalBundle,
|
|
17
|
+
} from "./authoring.js";
|
|
11
18
|
import { captureSource, sourceFingerprint } from "./source-bundle.js";
|
|
12
19
|
import { exactCid } from "./state.js";
|
|
13
20
|
|
|
14
21
|
export async function publicationSource(
|
|
15
22
|
input: string,
|
|
16
23
|
store: IpfsStore,
|
|
24
|
+
operation?: {
|
|
25
|
+
owner: Pick<Ownership, "retain" | "importBlocks">;
|
|
26
|
+
session: string;
|
|
27
|
+
options?: IpfsReadOptions;
|
|
28
|
+
onImportFailure?: () => void;
|
|
29
|
+
},
|
|
17
30
|
): Promise<string> {
|
|
31
|
+
const options = operation?.options ?? {};
|
|
32
|
+
options.signal?.throwIfAborted();
|
|
33
|
+
let inputCid: string | undefined;
|
|
18
34
|
try {
|
|
19
|
-
CID.parse(input);
|
|
20
|
-
return exactCid(input);
|
|
35
|
+
inputCid = exactCid(CID.parse(input).toString());
|
|
21
36
|
} catch {
|
|
22
37
|
// Non-CID inputs must be explicit existing local sources.
|
|
23
38
|
}
|
|
39
|
+
if (inputCid) {
|
|
40
|
+
if (operation) {
|
|
41
|
+
try {
|
|
42
|
+
await operation.owner.retain([inputCid], options.signal);
|
|
43
|
+
} catch (cause) {
|
|
44
|
+
operation.onImportFailure?.();
|
|
45
|
+
throw cause;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return inputCid;
|
|
49
|
+
}
|
|
50
|
+
if (/^[A-Za-z][A-Za-z0-9+.-]*:/.test(input) && !/^[A-Za-z]:[\\/]/.test(input))
|
|
51
|
+
throw new HostError(
|
|
52
|
+
"Publication SOURCE does not accept URIs; use an exact CID or an explicit local source.",
|
|
53
|
+
);
|
|
24
54
|
const path = resolve(input);
|
|
25
55
|
let stat;
|
|
26
56
|
try {
|
|
@@ -36,17 +66,44 @@ export async function publicationSource(
|
|
|
36
66
|
throw new HostError(
|
|
37
67
|
"Publication SOURCE must be a regular file or directory, never a symlink.",
|
|
38
68
|
);
|
|
39
|
-
if (stat.isFile() && extname(path).toLowerCase() === ".car")
|
|
40
|
-
|
|
69
|
+
if (stat.isFile() && extname(path).toLowerCase() === ".car") {
|
|
70
|
+
if (!operation)
|
|
71
|
+
return (await importBundle(path, () => Promise.resolve(store), options))
|
|
72
|
+
.cid;
|
|
73
|
+
try {
|
|
74
|
+
return await snapshotLocalBundle(
|
|
75
|
+
{ kind: "car", path },
|
|
76
|
+
operation.owner,
|
|
77
|
+
operation.session,
|
|
78
|
+
{
|
|
79
|
+
...options,
|
|
80
|
+
onImportFailure: operation.onImportFailure,
|
|
81
|
+
},
|
|
82
|
+
);
|
|
83
|
+
} catch (cause) {
|
|
84
|
+
options.signal?.throwIfAborted();
|
|
85
|
+
throw cause;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
41
88
|
let tree;
|
|
42
89
|
let snapshot: Map<string, Uint8Array> | undefined;
|
|
43
90
|
if (stat.isDirectory()) {
|
|
91
|
+
let hasManifest = false;
|
|
44
92
|
try {
|
|
45
93
|
await lstat(resolve(path, ".bundle.yaml"));
|
|
46
|
-
|
|
94
|
+
hasManifest = true;
|
|
47
95
|
} catch (cause) {
|
|
48
96
|
if (!nodeError(cause, "ENOENT")) throw cause;
|
|
49
|
-
|
|
97
|
+
}
|
|
98
|
+
if (hasManifest) {
|
|
99
|
+
tree = await selectedTree(
|
|
100
|
+
path,
|
|
101
|
+
undefined,
|
|
102
|
+
resolve(path, "dist"),
|
|
103
|
+
options,
|
|
104
|
+
);
|
|
105
|
+
} else {
|
|
106
|
+
snapshot = await captureSource(path, [], options);
|
|
50
107
|
tree = memoryTree(snapshot);
|
|
51
108
|
}
|
|
52
109
|
} else {
|
|
@@ -67,7 +124,7 @@ export async function publicationSource(
|
|
|
67
124
|
await filesystemTree(dirname(path)),
|
|
68
125
|
name,
|
|
69
126
|
bundleLimits.bytes,
|
|
70
|
-
|
|
127
|
+
options,
|
|
71
128
|
);
|
|
72
129
|
const bytes = (value: unknown) =>
|
|
73
130
|
new TextEncoder().encode(JSON.stringify(value));
|
|
@@ -82,20 +139,49 @@ export async function publicationSource(
|
|
|
82
139
|
]),
|
|
83
140
|
);
|
|
84
141
|
}
|
|
85
|
-
const encoded = await encodeBundleCar(tree);
|
|
142
|
+
const encoded = await encodeBundleCar(tree, options);
|
|
86
143
|
try {
|
|
144
|
+
const blocks: StagedBlock[] = [];
|
|
87
145
|
for await (const block of await CarBlockIterator.fromIterable(
|
|
88
146
|
encoded.stream,
|
|
89
|
-
))
|
|
90
|
-
|
|
147
|
+
)) {
|
|
148
|
+
options.signal?.throwIfAborted();
|
|
149
|
+
if (operation) blocks.push({ cid: block.cid, bytes: block.bytes });
|
|
150
|
+
else await store.put(block.cid, block.bytes);
|
|
151
|
+
}
|
|
91
152
|
if (
|
|
92
153
|
snapshot &&
|
|
93
154
|
sourceFingerprint(snapshot) !==
|
|
94
|
-
sourceFingerprint(await captureSource(path, []))
|
|
155
|
+
sourceFingerprint(await captureSource(path, [], options))
|
|
95
156
|
)
|
|
96
157
|
throw new HostError(
|
|
97
158
|
"Publication source changed while capturing its Bundle; retry.",
|
|
98
159
|
);
|
|
160
|
+
options.signal?.throwIfAborted();
|
|
161
|
+
if (operation) {
|
|
162
|
+
let cid: string;
|
|
163
|
+
try {
|
|
164
|
+
cid = await operation.owner.importBlocks(
|
|
165
|
+
operation.session,
|
|
166
|
+
blocks,
|
|
167
|
+
encoded.cid,
|
|
168
|
+
options,
|
|
169
|
+
);
|
|
170
|
+
} catch (cause) {
|
|
171
|
+
operation.onImportFailure?.();
|
|
172
|
+
throw cause;
|
|
173
|
+
}
|
|
174
|
+
options.signal?.throwIfAborted();
|
|
175
|
+
if (
|
|
176
|
+
snapshot &&
|
|
177
|
+
sourceFingerprint(snapshot) !==
|
|
178
|
+
sourceFingerprint(await captureSource(path, [], options))
|
|
179
|
+
)
|
|
180
|
+
throw new HostError(
|
|
181
|
+
"Publication source changed while capturing its Bundle; retry.",
|
|
182
|
+
);
|
|
183
|
+
return cid;
|
|
184
|
+
}
|
|
99
185
|
return encoded.cid.toString();
|
|
100
186
|
} finally {
|
|
101
187
|
await encoded.close();
|
package/src/swarm-fs-core.ts
CHANGED
|
@@ -141,13 +141,15 @@ export async function listSubtreeNames(
|
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
/**
|
|
144
|
-
* Returns
|
|
145
|
-
*
|
|
144
|
+
* Returns protected root metadata path prefixes for a v7 snapshot: the first
|
|
145
|
+
* segment of `.bundle.yaml`, `root.typeFile`, and `root.entryFile`. Returns an empty set
|
|
146
146
|
* for legacy (v2-v6) snapshots.
|
|
147
147
|
*/
|
|
148
148
|
export function protectedRootNames(snapshot: Snapshot): ReadonlySet<string> {
|
|
149
149
|
if (!isV7Snapshot(snapshot)) return new Set();
|
|
150
|
-
return
|
|
150
|
+
return new Set(
|
|
151
|
+
[...v7RootSkipFiles(snapshot)].map((path) => path.split("/")[0]!),
|
|
152
|
+
);
|
|
151
153
|
}
|
|
152
154
|
|
|
153
155
|
/**
|
|
@@ -284,6 +286,8 @@ export interface SwarmFsPlanContext {
|
|
|
284
286
|
}
|
|
285
287
|
|
|
286
288
|
export interface CommitSwarmPathsOptions<TResult> {
|
|
289
|
+
signal?: AbortSignal;
|
|
290
|
+
writeBlock?: (cid: CID, bytes: Uint8Array) => Promise<void>;
|
|
287
291
|
maxAttempts?: number;
|
|
288
292
|
allowLegacyNames?: boolean;
|
|
289
293
|
refreshAfterCommit?: boolean;
|
|
@@ -309,6 +313,9 @@ export interface CommitSwarmPathsResult<TResult> {
|
|
|
309
313
|
}
|
|
310
314
|
|
|
311
315
|
export interface SetSwarmFsPathOptions {
|
|
316
|
+
signal?: AbortSignal;
|
|
317
|
+
writeBlock?: (cid: CID, bytes: Uint8Array) => Promise<void>;
|
|
318
|
+
recursiveRoots?: readonly string[];
|
|
312
319
|
/** Expected current CIDv1 at path; mutually exclusive with replace. */
|
|
313
320
|
expect?: string;
|
|
314
321
|
/** Allow replacing an existing different CID; mutually exclusive with expect. */
|
|
@@ -1072,6 +1079,7 @@ export function createSwarmFs(transport: SwarmFsTransport): SwarmFs {
|
|
|
1072
1079
|
const head = await transport.pointer(context, configUrl);
|
|
1073
1080
|
|
|
1074
1081
|
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
1082
|
+
options.signal?.throwIfAborted();
|
|
1075
1083
|
const currentHead = await head.read();
|
|
1076
1084
|
const snapshot = await transport.readSnapshot(
|
|
1077
1085
|
context.store,
|
|
@@ -1100,6 +1108,7 @@ export function createSwarmFs(transport: SwarmFsTransport): SwarmFs {
|
|
|
1100
1108
|
};
|
|
1101
1109
|
|
|
1102
1110
|
const planned = await options.plan(planCtx);
|
|
1111
|
+
options.signal?.throwIfAborted();
|
|
1103
1112
|
if (planned.kind === "noop") {
|
|
1104
1113
|
return {
|
|
1105
1114
|
swarm: configUrl,
|
|
@@ -1142,6 +1151,7 @@ export function createSwarmFs(transport: SwarmFsTransport): SwarmFs {
|
|
|
1142
1151
|
context.store,
|
|
1143
1152
|
CID.parse(snapshot.stateBundle!.cid),
|
|
1144
1153
|
planned.operations,
|
|
1154
|
+
options.writeBlock,
|
|
1145
1155
|
);
|
|
1146
1156
|
if (!applied.changed) {
|
|
1147
1157
|
return {
|
|
@@ -1161,6 +1171,26 @@ export function createSwarmFs(transport: SwarmFsTransport): SwarmFs {
|
|
|
1161
1171
|
removedCids = applied.removedCids;
|
|
1162
1172
|
nextRoot = applied.newRootCid.toString();
|
|
1163
1173
|
|
|
1174
|
+
if (
|
|
1175
|
+
isLocal &&
|
|
1176
|
+
planned.retainedRecursive !== undefined &&
|
|
1177
|
+
context.store.supportsRetention
|
|
1178
|
+
) {
|
|
1179
|
+
const retained = [...new Set(planned.retainedRecursive)];
|
|
1180
|
+
const owner = `publication:${nextRoot}`;
|
|
1181
|
+
if (retained.length) {
|
|
1182
|
+
await context.store.retain(
|
|
1183
|
+
owner,
|
|
1184
|
+
retained,
|
|
1185
|
+
options.signal ? { signal: options.signal } : {},
|
|
1186
|
+
);
|
|
1187
|
+
}
|
|
1188
|
+
await context.store.confirmRetained(
|
|
1189
|
+
owner,
|
|
1190
|
+
retained,
|
|
1191
|
+
options.signal ? { signal: options.signal } : {},
|
|
1192
|
+
);
|
|
1193
|
+
}
|
|
1164
1194
|
if (!isLocal) {
|
|
1165
1195
|
const recursiveRoots = [
|
|
1166
1196
|
...new Set(planned.recursiveRoots ?? defaultSetRoots),
|
|
@@ -1179,6 +1209,7 @@ export function createSwarmFs(transport: SwarmFsTransport): SwarmFs {
|
|
|
1179
1209
|
? { authorizationToken: context.node!.auth }
|
|
1180
1210
|
: {}),
|
|
1181
1211
|
owner: `publication:${nextRoot}`,
|
|
1212
|
+
...(options.signal ? { signal: options.signal } : {}),
|
|
1182
1213
|
});
|
|
1183
1214
|
transport.invalidateSwarmHeader(context, configUrl);
|
|
1184
1215
|
}
|
|
@@ -1216,6 +1247,7 @@ export function createSwarmFs(transport: SwarmFsTransport): SwarmFs {
|
|
|
1216
1247
|
}
|
|
1217
1248
|
|
|
1218
1249
|
let written: Variable;
|
|
1250
|
+
options.signal?.throwIfAborted();
|
|
1219
1251
|
try {
|
|
1220
1252
|
written = await transport.writeNamesHead(
|
|
1221
1253
|
context,
|
|
@@ -1239,7 +1271,9 @@ export function createSwarmFs(transport: SwarmFsTransport): SwarmFs {
|
|
|
1239
1271
|
|
|
1240
1272
|
if (options.refreshAfterCommit !== false) {
|
|
1241
1273
|
try {
|
|
1274
|
+
options.signal?.throwIfAborted();
|
|
1242
1275
|
await transport.swarmHeader(context, configUrl, true);
|
|
1276
|
+
options.signal?.throwIfAborted();
|
|
1243
1277
|
} catch (cause) {
|
|
1244
1278
|
throw new HostError(
|
|
1245
1279
|
options.messages?.pinStale?.(cause, configUrl) ??
|
|
@@ -1312,6 +1346,8 @@ export function createSwarmFs(transport: SwarmFsTransport): SwarmFs {
|
|
|
1312
1346
|
configUrl,
|
|
1313
1347
|
{
|
|
1314
1348
|
allowLegacyNames: false,
|
|
1349
|
+
...(options?.signal ? { signal: options.signal } : {}),
|
|
1350
|
+
...(options?.writeBlock ? { writeBlock: options.writeBlock } : {}),
|
|
1315
1351
|
refreshAfterCommit: true,
|
|
1316
1352
|
plan: async (planCtx) => {
|
|
1317
1353
|
assertWritableSwarmFsPath(planCtx.snapshot, normalized);
|
|
@@ -1358,6 +1394,14 @@ export function createSwarmFs(transport: SwarmFsTransport): SwarmFs {
|
|
|
1358
1394
|
targetCid: CID.parse(canonicalTarget),
|
|
1359
1395
|
},
|
|
1360
1396
|
],
|
|
1397
|
+
...(options?.recursiveRoots
|
|
1398
|
+
? {
|
|
1399
|
+
recursiveRoots: [
|
|
1400
|
+
...new Set([canonicalTarget, ...options.recursiveRoots]),
|
|
1401
|
+
],
|
|
1402
|
+
retainedRecursive: planCtx.isLocal ? [] : [canonicalTarget],
|
|
1403
|
+
}
|
|
1404
|
+
: {}),
|
|
1361
1405
|
result: { previousCid: existing ?? null },
|
|
1362
1406
|
};
|
|
1363
1407
|
},
|