@ipab/cli 0.1.0-rc.13 → 0.1.0-rc.15
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/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 +203 -69
- package/dist/swarm.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 +1 -1
- 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 +310 -87
- package/src/templates.ts +16 -1
- package/src/unixfs-tree.ts +3 -1
package/src/daemon-api.ts
CHANGED
|
@@ -63,9 +63,13 @@ import {
|
|
|
63
63
|
} from "./history.js";
|
|
64
64
|
import { ContextHandler } from "./ipc.js";
|
|
65
65
|
import { logFiles } from "./logs.js";
|
|
66
|
-
import {
|
|
66
|
+
import {
|
|
67
|
+
formalName,
|
|
68
|
+
parseNameReference,
|
|
69
|
+
templateName,
|
|
70
|
+
} from "./name-reference.js";
|
|
71
|
+
import { normalizeSwarmFsPath } from "./swarm-fs-core.js";
|
|
67
72
|
import { pinDetails, unpin } from "./pins.js";
|
|
68
|
-
import { publicationSource } from "./publish-source.js";
|
|
69
73
|
import {
|
|
70
74
|
listSwarmFsPath,
|
|
71
75
|
removeSwarmFsPath,
|
|
@@ -76,13 +80,13 @@ import {
|
|
|
76
80
|
accountProfile,
|
|
77
81
|
approveMembership,
|
|
78
82
|
artifactValue,
|
|
83
|
+
bindPublicationSource,
|
|
79
84
|
createSwarm,
|
|
80
85
|
exportRequest,
|
|
81
86
|
grantPivotAuthority,
|
|
82
87
|
inspectSwarmStatus,
|
|
83
88
|
pinNameSubscription,
|
|
84
89
|
pinReference,
|
|
85
|
-
publish,
|
|
86
90
|
removeMember,
|
|
87
91
|
removeSwarmAssociation,
|
|
88
92
|
removeSwarmSkill,
|
|
@@ -1030,8 +1034,8 @@ export class DaemonService {
|
|
|
1030
1034
|
return {
|
|
1031
1035
|
pattern: "/v1/swarms/fs/set",
|
|
1032
1036
|
params: {},
|
|
1033
|
-
handler: ({ body, diagnostic }) =>
|
|
1034
|
-
this.handleSwarmFsSet(body, diagnostic),
|
|
1037
|
+
handler: ({ body, signal, diagnostic }) =>
|
|
1038
|
+
this.handleSwarmFsSet(body, diagnostic, signal),
|
|
1035
1039
|
};
|
|
1036
1040
|
}
|
|
1037
1041
|
if (method === "POST" && pathname === "/v1/swarms/fs/rm") {
|
|
@@ -1982,27 +1986,63 @@ export class DaemonService {
|
|
|
1982
1986
|
private async handleSwarmFsSet(
|
|
1983
1987
|
body: Record<string, unknown>,
|
|
1984
1988
|
diagnostic: (text: string, progress?: boolean) => void,
|
|
1989
|
+
signal: AbortSignal,
|
|
1985
1990
|
): Promise<unknown> {
|
|
1991
|
+
if (Object.hasOwn(body, "snapshot"))
|
|
1992
|
+
syntax(
|
|
1993
|
+
"--snapshot was removed. For a direct binding use ipab fs set NAME --source SOURCE [--expect OLD_CID].",
|
|
1994
|
+
);
|
|
1995
|
+
const kind = body.kind === undefined ? "fs" : requireString(body, "kind");
|
|
1996
|
+
if (!["fs", "publish", "template", "register", "skill"].includes(kind))
|
|
1997
|
+
syntax(`Unknown binding kind "${kind}".`);
|
|
1998
|
+
if (kind === "fs") {
|
|
1999
|
+
if (Object.hasOwn(body, "cid") === Object.hasOwn(body, "source"))
|
|
2000
|
+
syntax("fs set requires exactly one cid or source.");
|
|
2001
|
+
if (optionalBoolean(body, "wrapArtifact"))
|
|
2002
|
+
syntax("Raw FS does not wrap Artifacts; use publish for a version.");
|
|
2003
|
+
normalizeSwarmFsPath(requireString(body, "path"));
|
|
2004
|
+
if (Object.hasOwn(body, "source")) requireString(body, "source");
|
|
2005
|
+
else exactCid(requireString(body, "cid"));
|
|
2006
|
+
const expect = optionalString(body, "expect");
|
|
2007
|
+
if (expect !== undefined) exactCid(expect);
|
|
2008
|
+
if (expect !== undefined && optionalBoolean(body, "replace"))
|
|
2009
|
+
syntax("Options expect and replace are mutually exclusive.");
|
|
2010
|
+
}
|
|
2011
|
+
if (kind === "publish") {
|
|
2012
|
+
if (
|
|
2013
|
+
[
|
|
2014
|
+
"replace",
|
|
2015
|
+
"cid",
|
|
2016
|
+
"path",
|
|
2017
|
+
"wrapArtifact",
|
|
2018
|
+
"validator",
|
|
2019
|
+
"versioned",
|
|
2020
|
+
].some((field) => Object.hasOwn(body, field))
|
|
2021
|
+
)
|
|
2022
|
+
syntax(
|
|
2023
|
+
"Publish accepts name, source and an exact expect baseline; raw/replacement/version flags are not supported.",
|
|
2024
|
+
);
|
|
2025
|
+
formalName(requireString(body, "name"));
|
|
2026
|
+
requireString(body, "source");
|
|
2027
|
+
const expect = optionalString(body, "expect");
|
|
2028
|
+
if (expect !== undefined) exactCid(expect);
|
|
2029
|
+
}
|
|
1986
2030
|
const swarm = requireSwarmParam(body);
|
|
1987
2031
|
const url = this.state.resolveSwarm(swarm);
|
|
1988
|
-
const kind = optionalString(body, "kind") ?? "fs";
|
|
1989
2032
|
|
|
1990
2033
|
if (kind === "publish") {
|
|
1991
2034
|
const name = requireString(body, "name");
|
|
1992
2035
|
const source = requireString(body, "source");
|
|
1993
2036
|
const expect = optionalString(body, "expect");
|
|
1994
|
-
const snapshot = optionalBoolean(body, "snapshot") ?? false;
|
|
1995
2037
|
return this.mutex.run(`swarm-fs:${url}`, () =>
|
|
1996
2038
|
this.withSwarmContext(async (ctx) => {
|
|
1997
|
-
|
|
1998
|
-
const contentCid = await publicationSource(source, store);
|
|
1999
|
-
const cid = await publish(ctx, contentCid, {
|
|
2039
|
+
return bindPublicationSource(ctx, source, {
|
|
2000
2040
|
swarm: url,
|
|
2001
2041
|
name,
|
|
2042
|
+
kind: "publish",
|
|
2002
2043
|
...(expect !== undefined ? { expect } : {}),
|
|
2003
|
-
|
|
2044
|
+
signal,
|
|
2004
2045
|
});
|
|
2005
|
-
return { cid, contentCid };
|
|
2006
2046
|
}, diagnostic),
|
|
2007
2047
|
);
|
|
2008
2048
|
}
|
|
@@ -2192,15 +2232,35 @@ export class DaemonService {
|
|
|
2192
2232
|
}
|
|
2193
2233
|
|
|
2194
2234
|
const path = requireString(body, "path");
|
|
2195
|
-
const cid = exactCid(requireString(body, "cid"));
|
|
2196
2235
|
const expect = optionalString(body, "expect");
|
|
2197
2236
|
const replace = optionalBoolean(body, "replace");
|
|
2198
2237
|
const validator = optionalString(body, "validator");
|
|
2199
|
-
const wrapArtifact = optionalBoolean(body, "wrapArtifact") ?? false;
|
|
2200
2238
|
|
|
2201
2239
|
if (expect !== undefined && replace) {
|
|
2202
2240
|
syntax("Options expect and replace are mutually exclusive.");
|
|
2203
2241
|
}
|
|
2242
|
+
if (Object.hasOwn(body, "source")) {
|
|
2243
|
+
const source = requireString(body, "source");
|
|
2244
|
+
if (validator !== undefined)
|
|
2245
|
+
syntax(
|
|
2246
|
+
"Source bindings validate a Content Bundle; validator is only supported with cid.",
|
|
2247
|
+
);
|
|
2248
|
+
return this.mutex.run(`swarm-fs:${url}`, () =>
|
|
2249
|
+
this.withSwarmContext(
|
|
2250
|
+
(ctx) =>
|
|
2251
|
+
bindPublicationSource(ctx, source, {
|
|
2252
|
+
kind: "fs",
|
|
2253
|
+
swarm: url,
|
|
2254
|
+
name: path,
|
|
2255
|
+
...(expect !== undefined ? { expect: exactCid(expect) } : {}),
|
|
2256
|
+
...(replace !== undefined ? { replace } : {}),
|
|
2257
|
+
signal,
|
|
2258
|
+
}),
|
|
2259
|
+
diagnostic,
|
|
2260
|
+
),
|
|
2261
|
+
);
|
|
2262
|
+
}
|
|
2263
|
+
const cid = exactCid(requireString(body, "cid"));
|
|
2204
2264
|
|
|
2205
2265
|
if (validator === "template") {
|
|
2206
2266
|
const store = await this.getStore();
|
|
@@ -2227,12 +2287,6 @@ export class DaemonService {
|
|
|
2227
2287
|
syntax(`Unknown validator "${validator}".`);
|
|
2228
2288
|
}
|
|
2229
2289
|
|
|
2230
|
-
// If wrapArtifact is requested, validate the target exists as a block/bundle before committing.
|
|
2231
|
-
if (wrapArtifact) {
|
|
2232
|
-
const store = await this.getStore();
|
|
2233
|
-
await store.block.get(cid);
|
|
2234
|
-
}
|
|
2235
|
-
|
|
2236
2290
|
return this.mutex.run(`swarm-fs:${url}`, () =>
|
|
2237
2291
|
this.withSwarmContext(
|
|
2238
2292
|
(ctx) =>
|
package/src/daemon-client.ts
CHANGED
|
@@ -24,6 +24,65 @@ import type {
|
|
|
24
24
|
SwarmFsListResult,
|
|
25
25
|
SwarmFsStatResult,
|
|
26
26
|
} from "./swarm-fs-core.js";
|
|
27
|
+
import type { Association } from "./state.js";
|
|
28
|
+
import type { setSwarmSkill, setSwarmTemplate } from "./swarm.js";
|
|
29
|
+
|
|
30
|
+
type FsBinding = {
|
|
31
|
+
kind?: "fs";
|
|
32
|
+
swarm: string;
|
|
33
|
+
path: string;
|
|
34
|
+
expect?: string | undefined;
|
|
35
|
+
replace?: boolean | undefined;
|
|
36
|
+
} & (
|
|
37
|
+
| { cid: string; source?: never; validator?: "template" | "app" | "bundle" }
|
|
38
|
+
| { source: string; cid?: never; validator?: never }
|
|
39
|
+
);
|
|
40
|
+
export type BindingRequest =
|
|
41
|
+
| FsBinding
|
|
42
|
+
| {
|
|
43
|
+
kind: "publish";
|
|
44
|
+
swarm: string;
|
|
45
|
+
name: string;
|
|
46
|
+
source: string;
|
|
47
|
+
expect?: string | undefined;
|
|
48
|
+
}
|
|
49
|
+
| {
|
|
50
|
+
kind: "template";
|
|
51
|
+
swarm: string;
|
|
52
|
+
name: string;
|
|
53
|
+
source: string;
|
|
54
|
+
expect?: string | undefined;
|
|
55
|
+
}
|
|
56
|
+
| ({
|
|
57
|
+
kind: "register";
|
|
58
|
+
swarm: string;
|
|
59
|
+
schema: string;
|
|
60
|
+
app: string;
|
|
61
|
+
argv?: string[];
|
|
62
|
+
replace?: boolean;
|
|
63
|
+
} & ({ swarms?: never } | { swarms: [string, ...string[]] }))
|
|
64
|
+
| {
|
|
65
|
+
kind: "skill";
|
|
66
|
+
swarm: string;
|
|
67
|
+
skill: string;
|
|
68
|
+
global?: boolean;
|
|
69
|
+
types?: string[];
|
|
70
|
+
replace?: boolean;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export type BindingResult<T extends BindingRequest> = T extends {
|
|
74
|
+
kind: "publish";
|
|
75
|
+
}
|
|
76
|
+
? { cid: string; contentCid: string }
|
|
77
|
+
: T extends { kind: "template" }
|
|
78
|
+
? Awaited<ReturnType<typeof setSwarmTemplate>>
|
|
79
|
+
: T extends { kind: "register"; swarms: string[] }
|
|
80
|
+
? { associations: Association[] }
|
|
81
|
+
: T extends { kind: "register" }
|
|
82
|
+
? Association
|
|
83
|
+
: T extends { kind: "skill" }
|
|
84
|
+
? Awaited<ReturnType<typeof setSwarmSkill>>
|
|
85
|
+
: SetSwarmFsPathResult;
|
|
27
86
|
|
|
28
87
|
export interface DaemonClientOptions {
|
|
29
88
|
stateDir: string;
|
|
@@ -654,30 +713,11 @@ export class DaemonClient {
|
|
|
654
713
|
options,
|
|
655
714
|
),
|
|
656
715
|
|
|
657
|
-
fsSet: (
|
|
658
|
-
params:
|
|
659
|
-
swarm: string;
|
|
660
|
-
swarms?: string[] | undefined;
|
|
661
|
-
kind?: "fs" | "publish" | "template" | "register" | "skill";
|
|
662
|
-
path?: string | undefined;
|
|
663
|
-
cid?: string | undefined;
|
|
664
|
-
name?: string | undefined;
|
|
665
|
-
source?: string | undefined;
|
|
666
|
-
expect?: string | undefined;
|
|
667
|
-
replace?: boolean | undefined;
|
|
668
|
-
snapshot?: boolean | undefined;
|
|
669
|
-
wrapArtifact?: boolean | undefined;
|
|
670
|
-
validator?: "template" | "app" | "bundle" | undefined;
|
|
671
|
-
schema?: string | undefined;
|
|
672
|
-
app?: string | undefined;
|
|
673
|
-
argv?: string[] | undefined;
|
|
674
|
-
skill?: string | undefined;
|
|
675
|
-
global?: boolean | undefined;
|
|
676
|
-
types?: string[] | undefined;
|
|
677
|
-
},
|
|
716
|
+
fsSet: <T extends BindingRequest>(
|
|
717
|
+
params: T,
|
|
678
718
|
options?: DaemonRequestOptions,
|
|
679
719
|
) =>
|
|
680
|
-
this.request<
|
|
720
|
+
this.request<BindingResult<T>>(
|
|
681
721
|
"POST",
|
|
682
722
|
"/v1/swarms/fs/set",
|
|
683
723
|
params,
|
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
|
},
|