@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/dist/swarm.js
CHANGED
|
@@ -3,7 +3,7 @@ import { lstat, mkdir, open } from "node:fs/promises";
|
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
4
|
import { join, resolve } from "node:path";
|
|
5
5
|
import { setTimeout as delay } from "node:timers/promises";
|
|
6
|
-
import { createHash, randomBytes } from "node:crypto";
|
|
6
|
+
import { createHash, randomBytes, randomUUID } from "node:crypto";
|
|
7
7
|
import { stringify } from "yaml";
|
|
8
8
|
import { CarBlockIterator } from "@ipld/car/iterator";
|
|
9
9
|
import * as dagCbor from "@ipld/dag-cbor";
|
|
@@ -12,7 +12,9 @@ import { CID } from "multiformats/cid";
|
|
|
12
12
|
import { sha256 } from "multiformats/hashes/sha2";
|
|
13
13
|
import { ContentBundleError, encodeSchema, openBundle, } from "@ipab/bundle";
|
|
14
14
|
import { encodeBundleCar, memoryTree, streamChunks, } from "@ipab/bundle-builder";
|
|
15
|
-
import { ContentError, GatewayReadError, IpfsStore } from "@ipab/ipfs-store";
|
|
15
|
+
import { ContentError, GatewayReadError, IpfsStore, } from "@ipab/ipfs-store";
|
|
16
|
+
import { Ownership } from "./history.js";
|
|
17
|
+
import { publicationSource } from "./publish-source.js";
|
|
16
18
|
import { ScopeClient, ScopeApiError, RESOURCE_ID_PATTERN, issueScopeCertificate, signScopeWriteReceipt, uniqueId, verifyScopeCertificate, valueCid, parseVariableUpdate, } from "@ipab/bundle/pointer/scope";
|
|
17
19
|
import { canonicalService, isCanonicalPublicKey, POINTER_ID_PATTERN, } from "@ipab/bundle/pointer/protocol";
|
|
18
20
|
import { importPrivateKeyPkcs8, importPublicKeyRaw, keyId, signEd25519, verifyEd25519, } from "@ipab/bundle/pointer/crypto";
|
|
@@ -2279,9 +2281,6 @@ export async function writeNamesHead(context, url, head, root, cid) {
|
|
|
2279
2281
|
catch (cause) {
|
|
2280
2282
|
throw new HostError(`Pivot replication failed; HEAD was not changed: ${message(cause)}`, 1, "PIVOT_PIN_FAILED", "publication");
|
|
2281
2283
|
}
|
|
2282
|
-
if (receipt === null) {
|
|
2283
|
-
return head.write(root, cid, idempotencyKey);
|
|
2284
|
-
}
|
|
2285
2284
|
return head.writeWithReceipt(receipt);
|
|
2286
2285
|
});
|
|
2287
2286
|
}
|
|
@@ -2292,22 +2291,18 @@ async function requestPivotWriteReceipt(context, url, root, ifCid, idempotencyKe
|
|
|
2292
2291
|
const members = await memberDirectory(context, url, config);
|
|
2293
2292
|
const pivots = members.filter(({ member, profile }) => memberIsPivot(config, member, profile));
|
|
2294
2293
|
if (!pivots.length)
|
|
2295
|
-
throw new HostError("No Pivot nodes are declared. Declare an
|
|
2294
|
+
throw new HostError("No Pivot nodes are declared. Declare an authorized Pivot with swarm profile --pivot true before publishing; HEAD was not changed.");
|
|
2295
|
+
const self = pivots.find(({ member }) => member.publicKey === record.account &&
|
|
2296
|
+
(record.account === config.owner ||
|
|
2297
|
+
record.secret?.certificate.body.write.includes(config.headId)));
|
|
2296
2298
|
const remote = pivots.filter(({ member }) => member.publicKey !== record.account);
|
|
2297
|
-
if (!remote.length)
|
|
2298
|
-
|
|
2299
|
-
members[0].member.publicKey === record.account &&
|
|
2300
|
-
record.account === config.owner) {
|
|
2301
|
-
context.diagnostic?.(`[${url}] Solo self-Pivot Swarm detected; publishing ${root} directly without remote Pivot receipt.`);
|
|
2302
|
-
return null;
|
|
2303
|
-
}
|
|
2304
|
-
throw new HostError("Publication requires an independent Pivot node. Declare another member with swarm profile --pivot true; HEAD was not changed.");
|
|
2305
|
-
}
|
|
2299
|
+
if (!self && !remote.length)
|
|
2300
|
+
throw new HostError("Publication requires an authorized Pivot. Ask the Owner to grant Pivot HEAD authority; HEAD was not changed.");
|
|
2306
2301
|
const authorized = remote.filter(({ member }) => member.publicKey === config.owner ||
|
|
2307
2302
|
(config.v === 3
|
|
2308
2303
|
? member.role === "pivot"
|
|
2309
2304
|
: member.pivotAuthority === true));
|
|
2310
|
-
const
|
|
2305
|
+
const remoteCandidates = authorized.length
|
|
2311
2306
|
? [
|
|
2312
2307
|
...authorized,
|
|
2313
2308
|
...remote.filter(({ member }) => member.publicKey !== config.owner &&
|
|
@@ -2315,6 +2310,7 @@ async function requestPivotWriteReceipt(context, url, root, ifCid, idempotencyKe
|
|
|
2315
2310
|
member.pivotAuthority === undefined),
|
|
2316
2311
|
]
|
|
2317
2312
|
: remote;
|
|
2313
|
+
const candidates = self ? [self, ...remoteCandidates] : remoteCandidates;
|
|
2318
2314
|
if (!context.requestPivotReceipt && !context.node)
|
|
2319
2315
|
throw new HostError("State pin requires an active publishing node.");
|
|
2320
2316
|
const c = coordinates(url);
|
|
@@ -2335,15 +2331,18 @@ async function requestPivotWriteReceipt(context, url, root, ifCid, idempotencyKe
|
|
|
2335
2331
|
const errors = [];
|
|
2336
2332
|
for (const pivot of candidates) {
|
|
2337
2333
|
try {
|
|
2338
|
-
const
|
|
2339
|
-
|
|
2340
|
-
|
|
2334
|
+
const local = pivot === self;
|
|
2335
|
+
const receipt = local
|
|
2336
|
+
? await handlePivotReceiptRequest(context, url, request, signal)
|
|
2337
|
+
: context.requestPivotReceipt
|
|
2338
|
+
? await context.requestPivotReceipt(pivot, request, signal)
|
|
2339
|
+
: await requestPivotReceiptOverP2p(context.node, pivot.member.peerId, pivot.profile.addresses, request, signal, context.fetch);
|
|
2341
2340
|
if (JSON.stringify(receipt.value) !== JSON.stringify({ root }) ||
|
|
2342
2341
|
receipt.ifCid !== ifCid ||
|
|
2343
2342
|
receipt.idempotencyKey !== idempotencyKey ||
|
|
2344
2343
|
receipt.subject !== pivot.member.publicKey)
|
|
2345
2344
|
throw new HostError(`Pivot ${pivot.member.publicKey} returned a receipt that does not match this publication.`);
|
|
2346
|
-
context.diagnostic?.(`[${url}] Received HEAD write receipt from Pivot ${pivot.profile.name} (${pivot.member.publicKey}).`);
|
|
2345
|
+
context.diagnostic?.(`[${url}] Received HEAD write receipt from ${local ? "local" : "remote"} Pivot ${pivot.profile.name} (${pivot.member.publicKey})${local ? "; no independent replica is confirmed" : ""}.`);
|
|
2347
2346
|
return receipt;
|
|
2348
2347
|
}
|
|
2349
2348
|
catch (cause) {
|
|
@@ -2352,7 +2351,7 @@ async function requestPivotWriteReceipt(context, url, root, ifCid, idempotencyKe
|
|
|
2352
2351
|
context.diagnostic?.(`[${url}] Pivot receipt request to ${pivot.member.publicKey} failed: ${detail}`);
|
|
2353
2352
|
}
|
|
2354
2353
|
}
|
|
2355
|
-
throw new HostError(`No authorized
|
|
2354
|
+
throw new HostError(`No authorized Pivot issued a HEAD write receipt for publication ${root} (${errors.join("; ")}); HEAD was not changed.`);
|
|
2356
2355
|
}
|
|
2357
2356
|
export async function handlePivotReceiptRequest(context, url, input, signal) {
|
|
2358
2357
|
rejectLocalSwarm(url, "Pivot receipt RPC");
|
|
@@ -2387,7 +2386,7 @@ export async function handlePivotReceiptRequest(context, url, input, signal) {
|
|
|
2387
2386
|
const source = context.store.withLocalSource(kuboSource(node, peers, context.diagnostic, context.env.IPAB_SWARM_DIAL_DEBUG === "1"));
|
|
2388
2387
|
try {
|
|
2389
2388
|
if (CID.parse(request.root).code === dagPb.code) {
|
|
2390
|
-
if (peers.length > 0)
|
|
2389
|
+
if (peers.length > 0 && member.peerId !== node.peerId)
|
|
2391
2390
|
await probePeer(node, member.peerId, peers, signal).catch(() => false);
|
|
2392
2391
|
await readSnapshot(source, request.root, url);
|
|
2393
2392
|
await pinPublication(source, [request.root], node, signal, context.fetch);
|
|
@@ -2796,7 +2795,7 @@ function parseArtifact(value) {
|
|
|
2796
2795
|
...(data.previous !== undefined ? { previous: data.previous } : {}),
|
|
2797
2796
|
};
|
|
2798
2797
|
}
|
|
2799
|
-
export async function jsonBundle(store, type, value) {
|
|
2798
|
+
export async function jsonBundle(store, type, value, operation) {
|
|
2800
2799
|
const encoded = await encodeBundleCar(memoryTree(new Map([
|
|
2801
2800
|
[
|
|
2802
2801
|
".bundle.yaml",
|
|
@@ -2811,8 +2810,23 @@ export async function jsonBundle(store, type, value) {
|
|
|
2811
2810
|
])));
|
|
2812
2811
|
try {
|
|
2813
2812
|
const iterator = await CarBlockIterator.fromIterable(streamChunks(encoded.stream));
|
|
2814
|
-
|
|
2815
|
-
|
|
2813
|
+
const blocks = [];
|
|
2814
|
+
for await (const block of iterator) {
|
|
2815
|
+
operation?.signal?.throwIfAborted();
|
|
2816
|
+
if (operation)
|
|
2817
|
+
blocks.push({ cid: block.cid, bytes: block.bytes });
|
|
2818
|
+
else
|
|
2819
|
+
await store.put(block.cid, block.bytes);
|
|
2820
|
+
}
|
|
2821
|
+
if (operation) {
|
|
2822
|
+
try {
|
|
2823
|
+
return await operation.owner.importBlocks(operation.session, blocks, encoded.cid, operation.signal ? { signal: operation.signal } : {});
|
|
2824
|
+
}
|
|
2825
|
+
catch (cause) {
|
|
2826
|
+
operation.recoveryRequired = true;
|
|
2827
|
+
throw cause;
|
|
2828
|
+
}
|
|
2829
|
+
}
|
|
2816
2830
|
return encoded.cid.toString();
|
|
2817
2831
|
}
|
|
2818
2832
|
finally {
|
|
@@ -4783,7 +4797,7 @@ export async function swarmMeta(context, header) {
|
|
|
4783
4797
|
return header.snapshot.stateBundle.meta;
|
|
4784
4798
|
const cid = header.snapshot.names.ipab;
|
|
4785
4799
|
if (!cid)
|
|
4786
|
-
throw new HostError('Swarm Meta Name "ipab" is missing. Create a new seeded Swarm
|
|
4800
|
+
throw new HostError('Swarm Meta Name "ipab" is missing. Create a new seeded v7 Swarm and explicitly transfer reviewed paths; legacy Swarms are never automatically upgraded.');
|
|
4787
4801
|
try {
|
|
4788
4802
|
const bundle = await openBundle(cid, {
|
|
4789
4803
|
resolveCid: (key) => context.store.block.get(key.toString()),
|
|
@@ -4794,7 +4808,7 @@ export async function swarmMeta(context, header) {
|
|
|
4794
4808
|
return parseSwarmMeta(await typedJson(context.store, cid.toString(), type));
|
|
4795
4809
|
}
|
|
4796
4810
|
catch (cause) {
|
|
4797
|
-
throw new HostError(`Invalid Swarm Meta at Name "ipab": ${message(cause)}.
|
|
4811
|
+
throw new HostError(`Invalid Swarm Meta at Name "ipab": ${message(cause)}. Legacy consumers require a direct typed Meta, not a versioned Artifact. Create a new seeded v7 Swarm and explicitly transfer reviewed paths; no builtin or legacy fallback is used.`);
|
|
4798
4812
|
}
|
|
4799
4813
|
}
|
|
4800
4814
|
function metaCid(snapshot) {
|
|
@@ -4818,7 +4832,7 @@ const swarmFs = createSwarmFs(swarmFsTransport);
|
|
|
4818
4832
|
function missingSkillPathError(snapshot) {
|
|
4819
4833
|
return new HostError(snapshot.stateBundle
|
|
4820
4834
|
? "This Swarm uses the earlier exact State Bundle type without skillPath. There is no in-place root-configuration migration command. Create a new seeded Swarm and explicitly republish reviewed Names. Publishing a user Name ipab never overrides root configuration; upgrades never rewrite it."
|
|
4821
|
-
:
|
|
4835
|
+
: "This Swarm uses the legacy exact Meta type without skillPath. Publish now creates an Artifact and cannot migrate direct Meta; create a new seeded v7 Swarm and explicitly transfer reviewed paths. Existing Meta is never overwritten automatically.");
|
|
4822
4836
|
}
|
|
4823
4837
|
function canonicalTypeSkillLeaf(name, leaf) {
|
|
4824
4838
|
try {
|
|
@@ -5413,31 +5427,34 @@ export async function swarmTemplates(context, configUrl, selector) {
|
|
|
5413
5427
|
export async function setSwarmTemplate(context, configUrl, selector, source, expect) {
|
|
5414
5428
|
templateName(selector);
|
|
5415
5429
|
await swarmFsTransport.pointer(context, configUrl);
|
|
5416
|
-
|
|
5417
|
-
|
|
5418
|
-
|
|
5419
|
-
|
|
5420
|
-
|
|
5421
|
-
|
|
5422
|
-
|
|
5423
|
-
|
|
5424
|
-
|
|
5425
|
-
|
|
5426
|
-
|
|
5427
|
-
name
|
|
5428
|
-
|
|
5429
|
-
|
|
5430
|
+
return withPublicationOperation(context, async (operation) => {
|
|
5431
|
+
const content = await templatePublicationSource(source, context.store, operation);
|
|
5432
|
+
const details = await inspectTemplate(context.store, content);
|
|
5433
|
+
let location;
|
|
5434
|
+
const targetCid = await publishContent(context, content, {
|
|
5435
|
+
swarm: configUrl,
|
|
5436
|
+
name: selector,
|
|
5437
|
+
operation,
|
|
5438
|
+
...(expect === undefined ? {} : { expect }),
|
|
5439
|
+
}, async (current) => {
|
|
5440
|
+
const meta = await swarmMeta(context, { snapshot: current });
|
|
5441
|
+
const name = formalName(`${meta.templatePath}/${selector}`);
|
|
5442
|
+
location = {
|
|
5443
|
+
name,
|
|
5444
|
+
templatePath: meta.templatePath,
|
|
5445
|
+
metaCid: metaCid(current),
|
|
5446
|
+
};
|
|
5447
|
+
return name;
|
|
5448
|
+
});
|
|
5449
|
+
return {
|
|
5450
|
+
swarm: configUrl,
|
|
5451
|
+
...location,
|
|
5452
|
+
selector,
|
|
5453
|
+
reference: formatNameReference(configUrl, location.name),
|
|
5454
|
+
targetCid,
|
|
5455
|
+
...details,
|
|
5430
5456
|
};
|
|
5431
|
-
return name;
|
|
5432
5457
|
});
|
|
5433
|
-
return {
|
|
5434
|
-
swarm: configUrl,
|
|
5435
|
-
...location,
|
|
5436
|
-
selector,
|
|
5437
|
-
reference: formatNameReference(configUrl, location.name),
|
|
5438
|
-
targetCid,
|
|
5439
|
-
...details,
|
|
5440
|
-
};
|
|
5441
5458
|
}
|
|
5442
5459
|
export async function removeSwarmTemplate(context, configUrl, selector, expect) {
|
|
5443
5460
|
templateName(selector);
|
|
@@ -5728,46 +5745,148 @@ export async function unpublish(context, options) {
|
|
|
5728
5745
|
return committed.result;
|
|
5729
5746
|
}
|
|
5730
5747
|
export async function publish(context, content, options) {
|
|
5731
|
-
|
|
5748
|
+
if (options.snapshot !== undefined)
|
|
5749
|
+
syntax("--snapshot was removed. For a direct binding use ipab fs set NAME --source SOURCE [--expect OLD_CID].");
|
|
5750
|
+
if (options.operation)
|
|
5751
|
+
return publishContent(context, content, {
|
|
5752
|
+
...options,
|
|
5753
|
+
operation: options.operation,
|
|
5754
|
+
});
|
|
5755
|
+
if (!options.swarm)
|
|
5756
|
+
throw new HostError("Publication requires a selected Swarm configuration URL or alias.");
|
|
5757
|
+
await swarmFsTransport.pointer(context, options.swarm);
|
|
5758
|
+
return withPublicationOperation(context, (operation) => publishContent(context, content, { ...options, operation }));
|
|
5759
|
+
}
|
|
5760
|
+
async function withPublicationOperation(context, action, signal) {
|
|
5761
|
+
const session = `publication:${randomUUID()}`;
|
|
5762
|
+
const state = context.state ?? new State(context.stateDir);
|
|
5763
|
+
let operation;
|
|
5764
|
+
let result;
|
|
5765
|
+
let cleanupError;
|
|
5766
|
+
let failed = false;
|
|
5767
|
+
try {
|
|
5768
|
+
const owner = await Ownership.create(state, context.store, session, session);
|
|
5769
|
+
operation = { owner, session, ...(signal ? { signal } : {}) };
|
|
5770
|
+
result = await action(operation);
|
|
5771
|
+
}
|
|
5772
|
+
catch (cause) {
|
|
5773
|
+
failed = true;
|
|
5774
|
+
throw cause;
|
|
5775
|
+
}
|
|
5776
|
+
finally {
|
|
5777
|
+
try {
|
|
5778
|
+
if (operation?.recoveryRequired) {
|
|
5779
|
+
const hold = state.hold(operation.owner.owner);
|
|
5780
|
+
if (hold)
|
|
5781
|
+
state.saveHold({ ...hold, pid: null });
|
|
5782
|
+
context.diagnostic?.(`Publication preparation failed; unfinished retention intent remains for recovery (${session}). HEAD was not submitted.`);
|
|
5783
|
+
}
|
|
5784
|
+
else {
|
|
5785
|
+
try {
|
|
5786
|
+
await operation?.owner.release();
|
|
5787
|
+
}
|
|
5788
|
+
catch (cause) {
|
|
5789
|
+
if (!failed)
|
|
5790
|
+
cleanupError = new HostError(`Binding completed as ${operation?.completedCid ?? "(unknown target)"}, but temporary ownership cleanup failed: ${message(cause)}. Durable ownership was not released; inspect the target before retry.`, 1, "OPERATION_FAILED", "publication");
|
|
5791
|
+
else
|
|
5792
|
+
context.diagnostic?.(`Temporary ownership cleanup also failed: ${message(cause)}.`);
|
|
5793
|
+
}
|
|
5794
|
+
}
|
|
5795
|
+
}
|
|
5796
|
+
finally {
|
|
5797
|
+
if (!context.state)
|
|
5798
|
+
state.close();
|
|
5799
|
+
}
|
|
5800
|
+
}
|
|
5801
|
+
if (cleanupError)
|
|
5802
|
+
throw cleanupError;
|
|
5803
|
+
return result;
|
|
5804
|
+
}
|
|
5805
|
+
async function retainPublicationRoots(operation, roots) {
|
|
5806
|
+
try {
|
|
5807
|
+
await operation.owner.retain(roots, operation.signal);
|
|
5808
|
+
}
|
|
5809
|
+
catch (cause) {
|
|
5810
|
+
operation.recoveryRequired = true;
|
|
5811
|
+
throw cause;
|
|
5812
|
+
}
|
|
5813
|
+
}
|
|
5814
|
+
export async function bindPublicationSource(context, input, options) {
|
|
5815
|
+
options.signal?.throwIfAborted();
|
|
5816
|
+
await swarmFsTransport.pointer(context, options.swarm);
|
|
5817
|
+
return withPublicationOperation(context, async (operation) => {
|
|
5818
|
+
const contentCid = await publicationSource(input, context.store, {
|
|
5819
|
+
owner: operation.owner,
|
|
5820
|
+
session: operation.session,
|
|
5821
|
+
options: options.signal ? { signal: options.signal } : {},
|
|
5822
|
+
onImportFailure: () => {
|
|
5823
|
+
operation.recoveryRequired = true;
|
|
5824
|
+
},
|
|
5825
|
+
});
|
|
5826
|
+
options.signal?.throwIfAborted();
|
|
5827
|
+
if (options.kind === "publish") {
|
|
5828
|
+
const cid = await publishContent(context, contentCid, {
|
|
5829
|
+
...options,
|
|
5830
|
+
operation,
|
|
5831
|
+
});
|
|
5832
|
+
return { cid, contentCid };
|
|
5833
|
+
}
|
|
5834
|
+
const roots = await dependencies(context.store, contentCid);
|
|
5835
|
+
await retainPublicationRoots(operation, [...roots]);
|
|
5836
|
+
options.signal?.throwIfAborted();
|
|
5837
|
+
const currentRoots = await currentDependencies(context.store, contentCid);
|
|
5838
|
+
await withStateAsync(context, (state) => pinCid(state, contentCid, context.store, [...currentRoots]));
|
|
5839
|
+
options.signal?.throwIfAborted();
|
|
5840
|
+
const result = await swarmFs.setSwarmFsPath(context, options.swarm, options.name, contentCid, {
|
|
5841
|
+
...(options.expect !== undefined ? { expect: options.expect } : {}),
|
|
5842
|
+
...(options.replace !== undefined
|
|
5843
|
+
? { replace: options.replace }
|
|
5844
|
+
: {}),
|
|
5845
|
+
...(options.signal ? { signal: options.signal } : {}),
|
|
5846
|
+
recursiveRoots: [...currentRoots],
|
|
5847
|
+
writeBlock: (cid, bytes) => context.store.stageBlock(operation.session, cid, bytes, options.signal ? { signal: options.signal } : {}),
|
|
5848
|
+
});
|
|
5849
|
+
operation.completedCid = result.cid;
|
|
5850
|
+
return result;
|
|
5851
|
+
}, options.signal);
|
|
5732
5852
|
}
|
|
5733
5853
|
async function publishContent(context, content, options, nameForSnapshot) {
|
|
5734
5854
|
if (!options.swarm)
|
|
5735
5855
|
throw new HostError("Publication requires a selected Swarm configuration URL or alias.");
|
|
5736
5856
|
await swarmFsTransport.pointer(context, options.swarm);
|
|
5857
|
+
const operation = options.operation;
|
|
5858
|
+
operation.signal?.throwIfAborted();
|
|
5737
5859
|
const roots = await dependencies(context.store, content);
|
|
5860
|
+
await retainPublicationRoots(operation, [...roots]);
|
|
5738
5861
|
const currentRoots = [...(await currentDependencies(context.store, content))];
|
|
5862
|
+
operation.signal?.throwIfAborted();
|
|
5739
5863
|
await withStateAsync(context, (state) => pinCid(state, content, context.store, currentRoots));
|
|
5740
5864
|
let name = formalName(options.name);
|
|
5741
5865
|
let resolvedName;
|
|
5742
|
-
if (options.snapshot && options.expect)
|
|
5743
|
-
throw new HostError("Snapshots cannot replace an occupied Name.");
|
|
5744
5866
|
const expected = options.expect
|
|
5745
5867
|
? CID.parse(options.expect).toV1().toString()
|
|
5746
5868
|
: undefined;
|
|
5747
5869
|
const contentBundle = await openBundle(CID.parse(content), {
|
|
5748
5870
|
resolveCid: (cid) => context.store.block.get(cid.toString()),
|
|
5749
5871
|
});
|
|
5750
|
-
const
|
|
5872
|
+
const migration = contentBundle.schemaKey === appSchemaCid.toString() ||
|
|
5751
5873
|
contentBundle.schemaKey === swarmMetaSchema.cid.toString() ||
|
|
5752
5874
|
contentBundle.schemaKey === legacySwarmMetaSchema.cid.toString();
|
|
5753
|
-
|
|
5754
|
-
|
|
5755
|
-
|
|
5756
|
-
|
|
5757
|
-
|
|
5758
|
-
|
|
5759
|
-
|
|
5875
|
+
if (migration)
|
|
5876
|
+
context.diagnostic?.("Publish now creates an Artifact version; target CID will differ from content CID. For a direct binding use ipab fs set NAME --source SOURCE [--expect OLD_CID].");
|
|
5877
|
+
const candidate = await jsonBundle(context.store, artifactType, {
|
|
5878
|
+
value: content,
|
|
5879
|
+
...(expected ? { previous: expected } : {}),
|
|
5880
|
+
timestamp: new Date().toISOString(),
|
|
5881
|
+
}, operation);
|
|
5760
5882
|
roots.add(candidate);
|
|
5761
|
-
|
|
5762
|
-
|
|
5763
|
-
: undefined;
|
|
5764
|
-
if (expectedDeps)
|
|
5765
|
-
for (const root of expectedDeps)
|
|
5766
|
-
roots.add(root);
|
|
5767
|
-
const retained = [candidate, ...(expectedDeps ?? [])];
|
|
5883
|
+
let previousPrepared = false;
|
|
5884
|
+
const retained = [candidate];
|
|
5768
5885
|
const committed = await swarmFs.commitSwarmPaths(context, options.swarm, {
|
|
5769
5886
|
allowLegacyNames: true,
|
|
5770
5887
|
refreshAfterCommit: true,
|
|
5888
|
+
...(operation.signal ? { signal: operation.signal } : {}),
|
|
5889
|
+
writeBlock: (cid, bytes) => context.store.stageBlock(operation.session, cid, bytes, operation.signal ? { signal: operation.signal } : {}),
|
|
5771
5890
|
plan: async (planCtx) => {
|
|
5772
5891
|
if (nameForSnapshot) {
|
|
5773
5892
|
name = await nameForSnapshot(planCtx.snapshot);
|
|
@@ -5779,6 +5898,20 @@ async function publishContent(context, content, options, nameForSnapshot) {
|
|
|
5779
5898
|
const existing = (await planCtx.resolve(name))?.toString();
|
|
5780
5899
|
if (existing !== expected)
|
|
5781
5900
|
throw new HostError(`Edit conflict for ${name}; content ${content} remains pinned. Occupied Names require --expect EXACT_OLD_CID (the old Artifact CID when applicable); inspect the current Name before retrying.`, 3, "EDIT_CONFLICT", "publication");
|
|
5901
|
+
if (expected && !previousPrepared) {
|
|
5902
|
+
let expectedDeps;
|
|
5903
|
+
try {
|
|
5904
|
+
expectedDeps = await dependencies(context.store, expected);
|
|
5905
|
+
}
|
|
5906
|
+
catch (cause) {
|
|
5907
|
+
throw new HostError(`Cannot retain the exact previous Bundle ${expected}: ${message(cause)}. Manage non-Bundle targets with ipab fs set.`, 1, "INVALID_PREVIOUS", "publication");
|
|
5908
|
+
}
|
|
5909
|
+
await retainPublicationRoots(operation, [...expectedDeps]);
|
|
5910
|
+
for (const root of expectedDeps)
|
|
5911
|
+
roots.add(root);
|
|
5912
|
+
retained.push(...expectedDeps);
|
|
5913
|
+
previousPrepared = true;
|
|
5914
|
+
}
|
|
5782
5915
|
return {
|
|
5783
5916
|
kind: "commit",
|
|
5784
5917
|
operations: [
|
|
@@ -5795,6 +5928,7 @@ async function publishContent(context, content, options, nameForSnapshot) {
|
|
|
5795
5928
|
headBusy: () => `HEAD is busy; candidate ${candidate} remains retained.`,
|
|
5796
5929
|
},
|
|
5797
5930
|
});
|
|
5931
|
+
operation.completedCid = committed.result;
|
|
5798
5932
|
return committed.result;
|
|
5799
5933
|
}
|
|
5800
5934
|
//# sourceMappingURL=swarm.js.map
|