@ipab/cli 0.1.0-rc.14 → 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 +186 -49
- 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 +281 -54
- package/src/templates.ts +16 -1
- package/src/unixfs-tree.ts +3 -1
package/src/swarm.ts
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";
|
|
@@ -21,7 +21,14 @@ import {
|
|
|
21
21
|
memoryTree,
|
|
22
22
|
streamChunks,
|
|
23
23
|
} from "@ipab/bundle-builder";
|
|
24
|
-
import {
|
|
24
|
+
import {
|
|
25
|
+
ContentError,
|
|
26
|
+
GatewayReadError,
|
|
27
|
+
IpfsStore,
|
|
28
|
+
type StagedBlock,
|
|
29
|
+
} from "@ipab/ipfs-store";
|
|
30
|
+
import { Ownership } from "./history.js";
|
|
31
|
+
import { publicationSource } from "./publish-source.js";
|
|
25
32
|
import {
|
|
26
33
|
ScopeClient,
|
|
27
34
|
ScopeApiError,
|
|
@@ -4179,6 +4186,7 @@ export async function jsonBundle(
|
|
|
4179
4186
|
store: IpfsStore,
|
|
4180
4187
|
type: BundleType,
|
|
4181
4188
|
value: unknown,
|
|
4189
|
+
operation?: PublicationOperation,
|
|
4182
4190
|
): Promise<string> {
|
|
4183
4191
|
const encoded = await encodeBundleCar(
|
|
4184
4192
|
memoryTree(
|
|
@@ -4202,7 +4210,25 @@ export async function jsonBundle(
|
|
|
4202
4210
|
const iterator = await CarBlockIterator.fromIterable(
|
|
4203
4211
|
streamChunks(encoded.stream),
|
|
4204
4212
|
);
|
|
4205
|
-
|
|
4213
|
+
const blocks: StagedBlock[] = [];
|
|
4214
|
+
for await (const block of iterator) {
|
|
4215
|
+
operation?.signal?.throwIfAborted();
|
|
4216
|
+
if (operation) blocks.push({ cid: block.cid, bytes: block.bytes });
|
|
4217
|
+
else await store.put(block.cid, block.bytes);
|
|
4218
|
+
}
|
|
4219
|
+
if (operation) {
|
|
4220
|
+
try {
|
|
4221
|
+
return await operation.owner.importBlocks(
|
|
4222
|
+
operation.session,
|
|
4223
|
+
blocks,
|
|
4224
|
+
encoded.cid,
|
|
4225
|
+
operation.signal ? { signal: operation.signal } : {},
|
|
4226
|
+
);
|
|
4227
|
+
} catch (cause) {
|
|
4228
|
+
operation.recoveryRequired = true;
|
|
4229
|
+
throw cause;
|
|
4230
|
+
}
|
|
4231
|
+
}
|
|
4206
4232
|
return encoded.cid.toString();
|
|
4207
4233
|
} finally {
|
|
4208
4234
|
await encoded.close();
|
|
@@ -7030,7 +7056,7 @@ export async function swarmMeta(
|
|
|
7030
7056
|
const cid = header.snapshot.names.ipab;
|
|
7031
7057
|
if (!cid)
|
|
7032
7058
|
throw new HostError(
|
|
7033
|
-
'Swarm Meta Name "ipab" is missing. Create a new seeded Swarm
|
|
7059
|
+
'Swarm Meta Name "ipab" is missing. Create a new seeded v7 Swarm and explicitly transfer reviewed paths; legacy Swarms are never automatically upgraded.',
|
|
7034
7060
|
);
|
|
7035
7061
|
try {
|
|
7036
7062
|
const bundle = await openBundle(cid, {
|
|
@@ -7043,7 +7069,7 @@ export async function swarmMeta(
|
|
|
7043
7069
|
return parseSwarmMeta(await typedJson(context.store, cid.toString(), type));
|
|
7044
7070
|
} catch (cause) {
|
|
7045
7071
|
throw new HostError(
|
|
7046
|
-
`Invalid Swarm Meta at Name "ipab": ${message(cause)}.
|
|
7072
|
+
`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.`,
|
|
7047
7073
|
);
|
|
7048
7074
|
}
|
|
7049
7075
|
}
|
|
@@ -7146,7 +7172,7 @@ function missingSkillPathError(snapshot: Snapshot): HostError {
|
|
|
7146
7172
|
return new HostError(
|
|
7147
7173
|
snapshot.stateBundle
|
|
7148
7174
|
? "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."
|
|
7149
|
-
:
|
|
7175
|
+
: "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.",
|
|
7150
7176
|
);
|
|
7151
7177
|
}
|
|
7152
7178
|
|
|
@@ -7951,37 +7977,44 @@ export async function setSwarmTemplate(
|
|
|
7951
7977
|
) {
|
|
7952
7978
|
templateName(selector);
|
|
7953
7979
|
await swarmFsTransport.pointer(context, configUrl);
|
|
7954
|
-
|
|
7955
|
-
|
|
7956
|
-
|
|
7957
|
-
|
|
7958
|
-
|
|
7959
|
-
|
|
7960
|
-
content
|
|
7961
|
-
|
|
7980
|
+
return withPublicationOperation(context, async (operation) => {
|
|
7981
|
+
const content = await templatePublicationSource(
|
|
7982
|
+
source,
|
|
7983
|
+
context.store,
|
|
7984
|
+
operation,
|
|
7985
|
+
);
|
|
7986
|
+
const details = await inspectTemplate(context.store, content);
|
|
7987
|
+
let location:
|
|
7988
|
+
{ name: string; templatePath: string; metaCid: string } | undefined;
|
|
7989
|
+
const targetCid = await publishContent(
|
|
7990
|
+
context,
|
|
7991
|
+
content,
|
|
7992
|
+
{
|
|
7993
|
+
swarm: configUrl,
|
|
7994
|
+
name: selector,
|
|
7995
|
+
operation,
|
|
7996
|
+
...(expect === undefined ? {} : { expect }),
|
|
7997
|
+
},
|
|
7998
|
+
async (current) => {
|
|
7999
|
+
const meta = await swarmMeta(context, { snapshot: current });
|
|
8000
|
+
const name = formalName(`${meta.templatePath}/${selector}`);
|
|
8001
|
+
location = {
|
|
8002
|
+
name,
|
|
8003
|
+
templatePath: meta.templatePath,
|
|
8004
|
+
metaCid: metaCid(current),
|
|
8005
|
+
};
|
|
8006
|
+
return name;
|
|
8007
|
+
},
|
|
8008
|
+
);
|
|
8009
|
+
return {
|
|
7962
8010
|
swarm: configUrl,
|
|
7963
|
-
|
|
7964
|
-
|
|
7965
|
-
|
|
7966
|
-
|
|
7967
|
-
|
|
7968
|
-
|
|
7969
|
-
|
|
7970
|
-
name,
|
|
7971
|
-
templatePath: meta.templatePath,
|
|
7972
|
-
metaCid: metaCid(current),
|
|
7973
|
-
};
|
|
7974
|
-
return name;
|
|
7975
|
-
},
|
|
7976
|
-
);
|
|
7977
|
-
return {
|
|
7978
|
-
swarm: configUrl,
|
|
7979
|
-
...location!,
|
|
7980
|
-
selector,
|
|
7981
|
-
reference: formatNameReference(configUrl, location!.name),
|
|
7982
|
-
targetCid,
|
|
7983
|
-
...details,
|
|
7984
|
-
};
|
|
8011
|
+
...location!,
|
|
8012
|
+
selector,
|
|
8013
|
+
reference: formatNameReference(configUrl, location!.name),
|
|
8014
|
+
targetCid,
|
|
8015
|
+
...details,
|
|
8016
|
+
};
|
|
8017
|
+
});
|
|
7985
8018
|
}
|
|
7986
8019
|
export async function removeSwarmTemplate(
|
|
7987
8020
|
context: SwarmContext,
|
|
@@ -8405,10 +8438,173 @@ export async function publish(
|
|
|
8405
8438
|
name: string;
|
|
8406
8439
|
expect?: string;
|
|
8407
8440
|
snapshot?: boolean;
|
|
8441
|
+
operation?: PublicationOperation;
|
|
8408
8442
|
},
|
|
8409
8443
|
): Promise<string> {
|
|
8410
|
-
|
|
8444
|
+
if (options.snapshot !== undefined)
|
|
8445
|
+
syntax(
|
|
8446
|
+
"--snapshot was removed. For a direct binding use ipab fs set NAME --source SOURCE [--expect OLD_CID].",
|
|
8447
|
+
);
|
|
8448
|
+
if (options.operation)
|
|
8449
|
+
return publishContent(context, content, {
|
|
8450
|
+
...options,
|
|
8451
|
+
operation: options.operation,
|
|
8452
|
+
});
|
|
8453
|
+
if (!options.swarm)
|
|
8454
|
+
throw new HostError(
|
|
8455
|
+
"Publication requires a selected Swarm configuration URL or alias.",
|
|
8456
|
+
);
|
|
8457
|
+
await swarmFsTransport.pointer(context, options.swarm);
|
|
8458
|
+
return withPublicationOperation(context, (operation) =>
|
|
8459
|
+
publishContent(context, content, { ...options, operation }),
|
|
8460
|
+
);
|
|
8411
8461
|
}
|
|
8462
|
+
|
|
8463
|
+
export interface PublicationOperation {
|
|
8464
|
+
owner: Ownership;
|
|
8465
|
+
session: string;
|
|
8466
|
+
signal?: AbortSignal;
|
|
8467
|
+
recoveryRequired?: boolean;
|
|
8468
|
+
completedCid?: string;
|
|
8469
|
+
}
|
|
8470
|
+
|
|
8471
|
+
async function withPublicationOperation<T>(
|
|
8472
|
+
context: SwarmContext,
|
|
8473
|
+
action: (operation: PublicationOperation) => Promise<T>,
|
|
8474
|
+
signal?: AbortSignal,
|
|
8475
|
+
): Promise<T> {
|
|
8476
|
+
const session = `publication:${randomUUID()}`;
|
|
8477
|
+
const state = context.state ?? new State(context.stateDir);
|
|
8478
|
+
let operation: PublicationOperation | undefined;
|
|
8479
|
+
let result: T;
|
|
8480
|
+
let cleanupError: HostError | undefined;
|
|
8481
|
+
let failed = false;
|
|
8482
|
+
try {
|
|
8483
|
+
const owner = await Ownership.create(
|
|
8484
|
+
state,
|
|
8485
|
+
context.store,
|
|
8486
|
+
session,
|
|
8487
|
+
session,
|
|
8488
|
+
);
|
|
8489
|
+
operation = { owner, session, ...(signal ? { signal } : {}) };
|
|
8490
|
+
result = await action(operation);
|
|
8491
|
+
} catch (cause) {
|
|
8492
|
+
failed = true;
|
|
8493
|
+
throw cause;
|
|
8494
|
+
} finally {
|
|
8495
|
+
try {
|
|
8496
|
+
if (operation?.recoveryRequired) {
|
|
8497
|
+
const hold = state.hold(operation.owner.owner);
|
|
8498
|
+
if (hold) state.saveHold({ ...hold, pid: null });
|
|
8499
|
+
context.diagnostic?.(
|
|
8500
|
+
`Publication preparation failed; unfinished retention intent remains for recovery (${session}). HEAD was not submitted.`,
|
|
8501
|
+
);
|
|
8502
|
+
} else {
|
|
8503
|
+
try {
|
|
8504
|
+
await operation?.owner.release();
|
|
8505
|
+
} catch (cause) {
|
|
8506
|
+
if (!failed)
|
|
8507
|
+
cleanupError = new HostError(
|
|
8508
|
+
`Binding completed as ${operation?.completedCid ?? "(unknown target)"}, but temporary ownership cleanup failed: ${message(cause)}. Durable ownership was not released; inspect the target before retry.`,
|
|
8509
|
+
1,
|
|
8510
|
+
"OPERATION_FAILED",
|
|
8511
|
+
"publication",
|
|
8512
|
+
);
|
|
8513
|
+
else
|
|
8514
|
+
context.diagnostic?.(
|
|
8515
|
+
`Temporary ownership cleanup also failed: ${message(cause)}.`,
|
|
8516
|
+
);
|
|
8517
|
+
}
|
|
8518
|
+
}
|
|
8519
|
+
} finally {
|
|
8520
|
+
if (!context.state) state.close();
|
|
8521
|
+
}
|
|
8522
|
+
}
|
|
8523
|
+
if (cleanupError) throw cleanupError;
|
|
8524
|
+
return result;
|
|
8525
|
+
}
|
|
8526
|
+
|
|
8527
|
+
async function retainPublicationRoots(
|
|
8528
|
+
operation: PublicationOperation,
|
|
8529
|
+
roots: string[],
|
|
8530
|
+
) {
|
|
8531
|
+
try {
|
|
8532
|
+
await operation.owner.retain(roots, operation.signal);
|
|
8533
|
+
} catch (cause) {
|
|
8534
|
+
operation.recoveryRequired = true;
|
|
8535
|
+
throw cause;
|
|
8536
|
+
}
|
|
8537
|
+
}
|
|
8538
|
+
|
|
8539
|
+
export async function bindPublicationSource(
|
|
8540
|
+
context: SwarmContext,
|
|
8541
|
+
input: string,
|
|
8542
|
+
options: {
|
|
8543
|
+
swarm: string;
|
|
8544
|
+
name: string;
|
|
8545
|
+
kind: "fs" | "publish";
|
|
8546
|
+
expect?: string;
|
|
8547
|
+
replace?: boolean;
|
|
8548
|
+
signal?: AbortSignal;
|
|
8549
|
+
},
|
|
8550
|
+
) {
|
|
8551
|
+
options.signal?.throwIfAborted();
|
|
8552
|
+
await swarmFsTransport.pointer(context, options.swarm);
|
|
8553
|
+
return withPublicationOperation(
|
|
8554
|
+
context,
|
|
8555
|
+
async (operation) => {
|
|
8556
|
+
const contentCid = await publicationSource(input, context.store, {
|
|
8557
|
+
owner: operation.owner,
|
|
8558
|
+
session: operation.session,
|
|
8559
|
+
options: options.signal ? { signal: options.signal } : {},
|
|
8560
|
+
onImportFailure: () => {
|
|
8561
|
+
operation.recoveryRequired = true;
|
|
8562
|
+
},
|
|
8563
|
+
});
|
|
8564
|
+
options.signal?.throwIfAborted();
|
|
8565
|
+
if (options.kind === "publish") {
|
|
8566
|
+
const cid = await publishContent(context, contentCid, {
|
|
8567
|
+
...options,
|
|
8568
|
+
operation,
|
|
8569
|
+
});
|
|
8570
|
+
return { cid, contentCid };
|
|
8571
|
+
}
|
|
8572
|
+
const roots = await dependencies(context.store, contentCid);
|
|
8573
|
+
await retainPublicationRoots(operation, [...roots]);
|
|
8574
|
+
options.signal?.throwIfAborted();
|
|
8575
|
+
const currentRoots = await currentDependencies(context.store, contentCid);
|
|
8576
|
+
await withStateAsync(context, (state) =>
|
|
8577
|
+
pinCid(state, contentCid, context.store, [...currentRoots]),
|
|
8578
|
+
);
|
|
8579
|
+
options.signal?.throwIfAborted();
|
|
8580
|
+
const result = await swarmFs.setSwarmFsPath(
|
|
8581
|
+
context,
|
|
8582
|
+
options.swarm,
|
|
8583
|
+
options.name,
|
|
8584
|
+
contentCid,
|
|
8585
|
+
{
|
|
8586
|
+
...(options.expect !== undefined ? { expect: options.expect } : {}),
|
|
8587
|
+
...(options.replace !== undefined
|
|
8588
|
+
? { replace: options.replace }
|
|
8589
|
+
: {}),
|
|
8590
|
+
...(options.signal ? { signal: options.signal } : {}),
|
|
8591
|
+
recursiveRoots: [...currentRoots],
|
|
8592
|
+
writeBlock: (cid, bytes) =>
|
|
8593
|
+
context.store.stageBlock(
|
|
8594
|
+
operation.session,
|
|
8595
|
+
cid,
|
|
8596
|
+
bytes,
|
|
8597
|
+
options.signal ? { signal: options.signal } : {},
|
|
8598
|
+
),
|
|
8599
|
+
},
|
|
8600
|
+
);
|
|
8601
|
+
operation.completedCid = result.cid;
|
|
8602
|
+
return result;
|
|
8603
|
+
},
|
|
8604
|
+
options.signal,
|
|
8605
|
+
);
|
|
8606
|
+
}
|
|
8607
|
+
|
|
8412
8608
|
async function publishContent(
|
|
8413
8609
|
context: SwarmContext,
|
|
8414
8610
|
content: string,
|
|
@@ -8416,7 +8612,7 @@ async function publishContent(
|
|
|
8416
8612
|
swarm?: string;
|
|
8417
8613
|
name: string;
|
|
8418
8614
|
expect?: string;
|
|
8419
|
-
|
|
8615
|
+
operation: PublicationOperation;
|
|
8420
8616
|
},
|
|
8421
8617
|
nameForSnapshot?: (current: Snapshot) => Promise<string>,
|
|
8422
8618
|
): Promise<string> {
|
|
@@ -8425,42 +8621,55 @@ async function publishContent(
|
|
|
8425
8621
|
"Publication requires a selected Swarm configuration URL or alias.",
|
|
8426
8622
|
);
|
|
8427
8623
|
await swarmFsTransport.pointer(context, options.swarm);
|
|
8624
|
+
const operation = options.operation;
|
|
8625
|
+
operation.signal?.throwIfAborted();
|
|
8428
8626
|
const roots = await dependencies(context.store, content);
|
|
8627
|
+
await retainPublicationRoots(operation, [...roots]);
|
|
8429
8628
|
const currentRoots = [...(await currentDependencies(context.store, content))];
|
|
8629
|
+
operation.signal?.throwIfAborted();
|
|
8430
8630
|
await withStateAsync(context, (state) =>
|
|
8431
8631
|
pinCid(state, content, context.store, currentRoots),
|
|
8432
8632
|
);
|
|
8433
8633
|
let name = formalName(options.name);
|
|
8434
8634
|
let resolvedName: string | undefined;
|
|
8435
|
-
if (options.snapshot && options.expect)
|
|
8436
|
-
throw new HostError("Snapshots cannot replace an occupied Name.");
|
|
8437
8635
|
const expected = options.expect
|
|
8438
8636
|
? CID.parse(options.expect).toV1().toString()
|
|
8439
8637
|
: undefined;
|
|
8440
8638
|
const contentBundle = await openBundle(CID.parse(content), {
|
|
8441
8639
|
resolveCid: (cid) => context.store.block.get(cid.toString()),
|
|
8442
8640
|
});
|
|
8443
|
-
const
|
|
8641
|
+
const migration =
|
|
8444
8642
|
contentBundle.schemaKey === appSchemaCid.toString() ||
|
|
8445
8643
|
contentBundle.schemaKey === swarmMetaSchema.cid.toString() ||
|
|
8446
8644
|
contentBundle.schemaKey === legacySwarmMetaSchema.cid.toString();
|
|
8447
|
-
|
|
8448
|
-
|
|
8449
|
-
|
|
8450
|
-
|
|
8451
|
-
|
|
8452
|
-
|
|
8453
|
-
|
|
8454
|
-
|
|
8645
|
+
if (migration)
|
|
8646
|
+
context.diagnostic?.(
|
|
8647
|
+
"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].",
|
|
8648
|
+
);
|
|
8649
|
+
const candidate = await jsonBundle(
|
|
8650
|
+
context.store,
|
|
8651
|
+
artifactType,
|
|
8652
|
+
{
|
|
8653
|
+
value: content,
|
|
8654
|
+
...(expected ? { previous: expected } : {}),
|
|
8655
|
+
timestamp: new Date().toISOString(),
|
|
8656
|
+
},
|
|
8657
|
+
operation,
|
|
8658
|
+
);
|
|
8455
8659
|
roots.add(candidate);
|
|
8456
|
-
|
|
8457
|
-
|
|
8458
|
-
: undefined;
|
|
8459
|
-
if (expectedDeps) for (const root of expectedDeps) roots.add(root);
|
|
8460
|
-
const retained = [candidate, ...(expectedDeps ?? [])];
|
|
8660
|
+
let previousPrepared = false;
|
|
8661
|
+
const retained = [candidate];
|
|
8461
8662
|
const committed = await swarmFs.commitSwarmPaths(context, options.swarm, {
|
|
8462
8663
|
allowLegacyNames: true,
|
|
8463
8664
|
refreshAfterCommit: true,
|
|
8665
|
+
...(operation.signal ? { signal: operation.signal } : {}),
|
|
8666
|
+
writeBlock: (cid, bytes) =>
|
|
8667
|
+
context.store.stageBlock(
|
|
8668
|
+
operation.session,
|
|
8669
|
+
cid,
|
|
8670
|
+
bytes,
|
|
8671
|
+
operation.signal ? { signal: operation.signal } : {},
|
|
8672
|
+
),
|
|
8464
8673
|
plan: async (planCtx) => {
|
|
8465
8674
|
if (nameForSnapshot) {
|
|
8466
8675
|
name = await nameForSnapshot(planCtx.snapshot);
|
|
@@ -8482,6 +8691,23 @@ async function publishContent(
|
|
|
8482
8691
|
"EDIT_CONFLICT",
|
|
8483
8692
|
"publication",
|
|
8484
8693
|
);
|
|
8694
|
+
if (expected && !previousPrepared) {
|
|
8695
|
+
let expectedDeps: Set<string>;
|
|
8696
|
+
try {
|
|
8697
|
+
expectedDeps = await dependencies(context.store, expected);
|
|
8698
|
+
} catch (cause) {
|
|
8699
|
+
throw new HostError(
|
|
8700
|
+
`Cannot retain the exact previous Bundle ${expected}: ${message(cause)}. Manage non-Bundle targets with ipab fs set.`,
|
|
8701
|
+
1,
|
|
8702
|
+
"INVALID_PREVIOUS",
|
|
8703
|
+
"publication",
|
|
8704
|
+
);
|
|
8705
|
+
}
|
|
8706
|
+
await retainPublicationRoots(operation, [...expectedDeps]);
|
|
8707
|
+
for (const root of expectedDeps) roots.add(root);
|
|
8708
|
+
retained.push(...expectedDeps);
|
|
8709
|
+
previousPrepared = true;
|
|
8710
|
+
}
|
|
8485
8711
|
return {
|
|
8486
8712
|
kind: "commit",
|
|
8487
8713
|
operations: [
|
|
@@ -8500,5 +8726,6 @@ async function publishContent(
|
|
|
8500
8726
|
headBusy: () => `HEAD is busy; candidate ${candidate} remains retained.`,
|
|
8501
8727
|
},
|
|
8502
8728
|
});
|
|
8729
|
+
operation.completedCid = committed.result;
|
|
8503
8730
|
return committed.result;
|
|
8504
8731
|
}
|
package/src/templates.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { bundleLimits, openBundle } from "@ipab/bundle";
|
|
|
5
5
|
import type { IpfsStore } from "@ipab/ipfs-store";
|
|
6
6
|
import { HostError } from "./errors.js";
|
|
7
7
|
import { publicationSource } from "./publish-source.js";
|
|
8
|
+
import type { PublicationOperation } from "./swarm.js";
|
|
8
9
|
import { bytes } from "./space.js";
|
|
9
10
|
import {
|
|
10
11
|
templateDefinition,
|
|
@@ -38,6 +39,7 @@ export async function inspectTemplate(store: IpfsStore, cid: string) {
|
|
|
38
39
|
export async function templatePublicationSource(
|
|
39
40
|
input: string,
|
|
40
41
|
store: IpfsStore,
|
|
42
|
+
operation?: PublicationOperation,
|
|
41
43
|
) {
|
|
42
44
|
let cid: CID | undefined;
|
|
43
45
|
try {
|
|
@@ -71,7 +73,20 @@ export async function templatePublicationSource(
|
|
|
71
73
|
);
|
|
72
74
|
}
|
|
73
75
|
}
|
|
74
|
-
const content = await publicationSource(
|
|
76
|
+
const content = await publicationSource(
|
|
77
|
+
input,
|
|
78
|
+
store,
|
|
79
|
+
operation
|
|
80
|
+
? {
|
|
81
|
+
owner: operation.owner,
|
|
82
|
+
session: operation.session,
|
|
83
|
+
options: operation.signal ? { signal: operation.signal } : {},
|
|
84
|
+
onImportFailure: () => {
|
|
85
|
+
operation.recoveryRequired = true;
|
|
86
|
+
},
|
|
87
|
+
}
|
|
88
|
+
: undefined,
|
|
89
|
+
);
|
|
75
90
|
await inspectTemplate(store, content);
|
|
76
91
|
return content;
|
|
77
92
|
}
|
package/src/unixfs-tree.ts
CHANGED
|
@@ -183,6 +183,7 @@ export async function applyUnixfsMutations(
|
|
|
183
183
|
store: IpfsStore,
|
|
184
184
|
rootCid: CID,
|
|
185
185
|
mutations: readonly UnixfsMutation[],
|
|
186
|
+
writeBlock?: (cid: CID, bytes: Uint8Array) => Promise<void>,
|
|
186
187
|
): Promise<ApplyUnixfsMutationsResult> {
|
|
187
188
|
const canonicalRoot = rootCid.toV1();
|
|
188
189
|
if (mutations.length === 0) {
|
|
@@ -385,7 +386,8 @@ export async function applyUnixfsMutations(
|
|
|
385
386
|
|
|
386
387
|
const encoded = await encodeUnixfsDirectory(node.links.values());
|
|
387
388
|
if (!node.originalCid || !encoded.cid.equals(node.originalCid)) {
|
|
388
|
-
await
|
|
389
|
+
if (writeBlock) await writeBlock(encoded.cid, encoded.bytes);
|
|
390
|
+
else await store.put(encoded.cid, encoded.bytes);
|
|
389
391
|
node.newlyWritten = true;
|
|
390
392
|
node.encodedCid = encoded.cid;
|
|
391
393
|
} else {
|