@ipab/cli 0.1.0-rc.10 → 0.1.0-rc.12
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/README.md +24 -11
- package/dist/authoring.d.ts +7 -0
- package/dist/authoring.d.ts.map +1 -1
- package/dist/authoring.js +85 -5
- 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.check.car +0 -0
- package/dist/builtins/template.node.car +0 -0
- package/dist/builtins/template.web-app.car +0 -0
- package/dist/bundled-skills.d.ts +1 -1
- package/dist/cli.d.ts +2 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +904 -183
- package/dist/cli.js.map +1 -1
- package/dist/config-secret.js +1 -1
- package/dist/config-secret.js.map +1 -1
- package/dist/config.d.ts +4 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +17 -2
- package/dist/config.js.map +1 -1
- package/dist/daemon-ui.d.ts +1 -0
- package/dist/daemon-ui.d.ts.map +1 -1
- package/dist/daemon-ui.js +2 -0
- package/dist/daemon-ui.js.map +1 -1
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +7 -3
- package/dist/doctor.js.map +1 -1
- package/dist/get.d.ts.map +1 -1
- package/dist/get.js +1 -1
- package/dist/get.js.map +1 -1
- package/dist/history.d.ts +3 -1
- package/dist/history.d.ts.map +1 -1
- package/dist/history.js +16 -1
- package/dist/history.js.map +1 -1
- package/dist/kubo-topology.d.ts +2 -0
- package/dist/kubo-topology.d.ts.map +1 -1
- package/dist/kubo-topology.js +17 -20
- package/dist/kubo-topology.js.map +1 -1
- package/dist/kubo.d.ts +5 -3
- package/dist/kubo.d.ts.map +1 -1
- package/dist/kubo.js +83 -13
- package/dist/kubo.js.map +1 -1
- package/dist/name-reference.d.ts +8 -0
- package/dist/name-reference.d.ts.map +1 -0
- package/dist/name-reference.js +63 -0
- package/dist/name-reference.js.map +1 -0
- package/dist/pivot-rpc.d.ts +37 -2
- package/dist/pivot-rpc.d.ts.map +1 -1
- package/dist/pivot-rpc.js +188 -8
- package/dist/pivot-rpc.js.map +1 -1
- package/dist/search-index.d.ts.map +1 -1
- package/dist/search-index.js +1 -0
- package/dist/search-index.js.map +1 -1
- package/dist/skill-definition.d.ts +9 -0
- package/dist/skill-definition.d.ts.map +1 -1
- package/dist/skill-definition.js +26 -2
- package/dist/skill-definition.js.map +1 -1
- package/dist/skill-source.d.ts +1 -0
- package/dist/skill-source.d.ts.map +1 -1
- package/dist/skill-source.js +10 -4
- package/dist/skill-source.js.map +1 -1
- package/dist/skills.d.ts +9 -3
- package/dist/skills.d.ts.map +1 -1
- package/dist/skills.js +31 -2
- package/dist/skills.js.map +1 -1
- package/dist/state.d.ts +20 -0
- package/dist/state.d.ts.map +1 -1
- package/dist/state.js +87 -3
- package/dist/state.js.map +1 -1
- package/dist/swarm-fs-core.d.ts +217 -0
- package/dist/swarm-fs-core.d.ts.map +1 -0
- package/dist/swarm-fs-core.js +885 -0
- package/dist/swarm-fs-core.js.map +1 -0
- package/dist/swarm-fs-path.d.ts +17 -0
- package/dist/swarm-fs-path.d.ts.map +1 -0
- package/dist/swarm-fs-path.js +46 -0
- package/dist/swarm-fs-path.js.map +1 -0
- package/dist/swarm-fs.d.ts +9 -0
- package/dist/swarm-fs.d.ts.map +1 -0
- package/dist/swarm-fs.js +21 -0
- package/dist/swarm-fs.js.map +1 -0
- package/dist/swarm-observations.d.ts +6 -0
- package/dist/swarm-observations.d.ts.map +1 -1
- package/dist/swarm-observations.js +28 -8
- package/dist/swarm-observations.js.map +1 -1
- package/dist/swarm.d.ts +192 -17
- package/dist/swarm.d.ts.map +1 -1
- package/dist/swarm.js +1360 -442
- package/dist/swarm.js.map +1 -1
- package/dist/unixfs-tree.d.ts +55 -0
- package/dist/unixfs-tree.d.ts.map +1 -1
- package/dist/unixfs-tree.js +361 -2
- package/dist/unixfs-tree.js.map +1 -1
- package/package.json +5 -5
- package/src/authoring.ts +125 -8
- package/src/cli.ts +1215 -281
- package/src/config-secret.ts +1 -1
- package/src/config.ts +20 -2
- package/src/daemon-ui.ts +3 -0
- package/src/doctor.ts +12 -2
- package/src/get.ts +2 -1
- package/src/history.ts +26 -1
- package/src/kubo-topology.ts +25 -22
- package/src/kubo.ts +127 -9
- package/src/name-reference.ts +91 -0
- package/src/pivot-rpc.ts +272 -14
- package/src/search-index.ts +1 -0
- package/src/skill-definition.ts +45 -3
- package/src/skill-source.ts +10 -4
- package/src/skills.ts +43 -2
- package/src/state.ts +117 -2
- package/src/swarm-fs-core.ts +1461 -0
- package/src/swarm-fs-path.ts +68 -0
- package/src/swarm-fs.ts +104 -0
- package/src/swarm-observations.ts +40 -14
- package/src/swarm.ts +1950 -727
- package/src/unixfs-tree.ts +447 -2
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { syntax } from "./host-error.js";
|
|
2
|
+
|
|
3
|
+
export interface NormalizedFsPath {
|
|
4
|
+
/** Normalized relative path; empty string for root "/". */
|
|
5
|
+
path: string;
|
|
6
|
+
/** Path segments; empty array for root "/". */
|
|
7
|
+
segments: string[];
|
|
8
|
+
/** True when the normalized path is root "/". */
|
|
9
|
+
isRoot: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// eslint-disable-next-line no-control-regex
|
|
13
|
+
const FORBIDDEN_PATH_CHARS = /[\\:%*?"<>|\u0000-\u001f\u007f]/;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Normalizes a Swarm UnixFS path and rejects unsafe or invalid syntax with
|
|
17
|
+
* exitCode 2 / INVALID_ARGUMENT.
|
|
18
|
+
*/
|
|
19
|
+
export function normalizeSwarmFsPath(
|
|
20
|
+
input: string | undefined,
|
|
21
|
+
options?: { allowRoot?: boolean; allowTrailingSlash?: boolean },
|
|
22
|
+
): NormalizedFsPath {
|
|
23
|
+
const allowRoot = options?.allowRoot ?? false;
|
|
24
|
+
const allowTrailingSlash = options?.allowTrailingSlash ?? false;
|
|
25
|
+
|
|
26
|
+
if (input === undefined || input === "") {
|
|
27
|
+
if (allowRoot) return { path: "", segments: [], isRoot: true };
|
|
28
|
+
syntax("Path must not be empty.");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (input.length > 1024)
|
|
32
|
+
syntax("Path exceeds maximum length of 1024 characters.");
|
|
33
|
+
|
|
34
|
+
if (FORBIDDEN_PATH_CHARS.test(input))
|
|
35
|
+
syntax(`Path "${input}" contains forbidden characters.`);
|
|
36
|
+
|
|
37
|
+
if (input.includes("//"))
|
|
38
|
+
syntax(`Path "${input}" must not contain consecutive slashes.`);
|
|
39
|
+
|
|
40
|
+
if (input === "/" || input === ".") {
|
|
41
|
+
if (allowRoot) return { path: "", segments: [], isRoot: true };
|
|
42
|
+
syntax("Root path is not allowed for this operation.");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
let normalized = input.startsWith("/") ? input.slice(1) : input;
|
|
46
|
+
|
|
47
|
+
if (normalized.endsWith("/")) {
|
|
48
|
+
if (!allowTrailingSlash)
|
|
49
|
+
syntax(`Trailing slash is not allowed in path "${input}".`);
|
|
50
|
+
normalized = normalized.slice(0, -1);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const segments = normalized.split("/");
|
|
54
|
+
for (const segment of segments) {
|
|
55
|
+
if (!segment || segment === "." || segment === "..")
|
|
56
|
+
syntax(`Path "${input}" contains an invalid segment "${segment}".`);
|
|
57
|
+
if (segment.endsWith(".") || segment.endsWith(" "))
|
|
58
|
+
syntax(
|
|
59
|
+
`Path "${input}" segment "${segment}" must not end with a dot or space.`,
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
path: segments.join("/"),
|
|
65
|
+
segments,
|
|
66
|
+
isRoot: false,
|
|
67
|
+
};
|
|
68
|
+
}
|
package/src/swarm-fs.ts
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assertWritableSwarmFsPath,
|
|
3
|
+
createSwarmFs,
|
|
4
|
+
isV7Snapshot,
|
|
5
|
+
listSubtreeNames,
|
|
6
|
+
normalizeSwarmFsPath,
|
|
7
|
+
protectedRootNames,
|
|
8
|
+
resolveSnapshotName,
|
|
9
|
+
v7RootSkipFiles,
|
|
10
|
+
type BoundHead,
|
|
11
|
+
type CommitSwarmPathsOptions,
|
|
12
|
+
type CommitSwarmPathsResult,
|
|
13
|
+
type NormalizedFsPath,
|
|
14
|
+
type ReadSwarmSnapshotOptions,
|
|
15
|
+
type RemoveSwarmFsPathOptions,
|
|
16
|
+
type RemoveSwarmFsPathResult,
|
|
17
|
+
type SetSwarmFsPathOptions,
|
|
18
|
+
type SetSwarmFsPathResult,
|
|
19
|
+
type SwarmFs,
|
|
20
|
+
type SwarmFsListEntry,
|
|
21
|
+
type SwarmFsListResult,
|
|
22
|
+
type SwarmFsMutationPlan,
|
|
23
|
+
type SwarmFsNodeKind,
|
|
24
|
+
type SwarmFsNoopPlan,
|
|
25
|
+
type SwarmFsPlan,
|
|
26
|
+
type SwarmFsPlanContext,
|
|
27
|
+
type SwarmFsSnapshotContext,
|
|
28
|
+
type SwarmFsStatResult,
|
|
29
|
+
type SwarmFsTransport,
|
|
30
|
+
type SwarmReadMode,
|
|
31
|
+
} from "./swarm-fs-core.js";
|
|
32
|
+
import {
|
|
33
|
+
invalidateSwarmHeader,
|
|
34
|
+
lazyPrivateSource,
|
|
35
|
+
localHeader,
|
|
36
|
+
missingContent,
|
|
37
|
+
pointer,
|
|
38
|
+
prepareNamesPublication,
|
|
39
|
+
readSnapshot,
|
|
40
|
+
swarmHeader,
|
|
41
|
+
writeNamesHead,
|
|
42
|
+
} from "./swarm.js";
|
|
43
|
+
|
|
44
|
+
export {
|
|
45
|
+
assertWritableSwarmFsPath,
|
|
46
|
+
createSwarmFs,
|
|
47
|
+
isV7Snapshot,
|
|
48
|
+
listSubtreeNames,
|
|
49
|
+
normalizeSwarmFsPath,
|
|
50
|
+
protectedRootNames,
|
|
51
|
+
resolveSnapshotName,
|
|
52
|
+
v7RootSkipFiles,
|
|
53
|
+
type BoundHead,
|
|
54
|
+
type CommitSwarmPathsOptions,
|
|
55
|
+
type CommitSwarmPathsResult,
|
|
56
|
+
type NormalizedFsPath,
|
|
57
|
+
type ReadSwarmSnapshotOptions,
|
|
58
|
+
type RemoveSwarmFsPathOptions,
|
|
59
|
+
type RemoveSwarmFsPathResult,
|
|
60
|
+
type SetSwarmFsPathOptions,
|
|
61
|
+
type SetSwarmFsPathResult,
|
|
62
|
+
type SwarmFs,
|
|
63
|
+
type SwarmFsListEntry,
|
|
64
|
+
type SwarmFsListResult,
|
|
65
|
+
type SwarmFsMutationPlan,
|
|
66
|
+
type SwarmFsNodeKind,
|
|
67
|
+
type SwarmFsNoopPlan,
|
|
68
|
+
type SwarmFsPlan,
|
|
69
|
+
type SwarmFsPlanContext,
|
|
70
|
+
type SwarmFsSnapshotContext,
|
|
71
|
+
type SwarmFsStatResult,
|
|
72
|
+
type SwarmFsTransport,
|
|
73
|
+
type SwarmReadMode,
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const defaultSwarmFs = createSwarmFs({
|
|
77
|
+
pointer,
|
|
78
|
+
writeNamesHead,
|
|
79
|
+
readSnapshot,
|
|
80
|
+
swarmHeader,
|
|
81
|
+
localHeader,
|
|
82
|
+
lazyPrivateSource,
|
|
83
|
+
invalidateSwarmHeader,
|
|
84
|
+
prepareNamesPublication,
|
|
85
|
+
missingContent,
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
export const readSwarmFsSnapshot: SwarmFs["readSwarmFsSnapshot"] = (...args) =>
|
|
89
|
+
defaultSwarmFs.readSwarmFsSnapshot(...args);
|
|
90
|
+
|
|
91
|
+
export const statSwarmFsPath: SwarmFs["statSwarmFsPath"] = (...args) =>
|
|
92
|
+
defaultSwarmFs.statSwarmFsPath(...args);
|
|
93
|
+
|
|
94
|
+
export const listSwarmFsPath: SwarmFs["listSwarmFsPath"] = (...args) =>
|
|
95
|
+
defaultSwarmFs.listSwarmFsPath(...args);
|
|
96
|
+
|
|
97
|
+
export const commitSwarmPaths: SwarmFs["commitSwarmPaths"] = (...args) =>
|
|
98
|
+
defaultSwarmFs.commitSwarmPaths(...args);
|
|
99
|
+
|
|
100
|
+
export const setSwarmFsPath: SwarmFs["setSwarmFsPath"] = (...args) =>
|
|
101
|
+
defaultSwarmFs.setSwarmFsPath(...args);
|
|
102
|
+
|
|
103
|
+
export const removeSwarmFsPath: SwarmFs["removeSwarmFsPath"] = (...args) =>
|
|
104
|
+
defaultSwarmFs.removeSwarmFsPath(...args);
|
|
@@ -6,6 +6,7 @@ import { nodeRecord, validateAddress, type PeerConnection } from "./kubo.js";
|
|
|
6
6
|
import { isCanonicalPublicKey } from "@ipab/bundle/pointer/protocol";
|
|
7
7
|
import type { PivotCandidate } from "./kubo-topology.js";
|
|
8
8
|
import type { Organization } from "./swarm.js";
|
|
9
|
+
import { parsePivotStatus, type PivotStatus } from "./pivot-rpc.js";
|
|
9
10
|
|
|
10
11
|
export type PivotLocalStatus =
|
|
11
12
|
"selected" | "cooldown" | "unknown" | "self" | "candidate";
|
|
@@ -25,6 +26,14 @@ export interface NetworkingSnapshot {
|
|
|
25
26
|
topology: string | null;
|
|
26
27
|
pivots: PivotObservation[];
|
|
27
28
|
account?: string;
|
|
29
|
+
readiness?: Record<
|
|
30
|
+
string,
|
|
31
|
+
{
|
|
32
|
+
observedAt: number;
|
|
33
|
+
status: PivotStatus | null;
|
|
34
|
+
error: string | null;
|
|
35
|
+
}
|
|
36
|
+
>;
|
|
28
37
|
connections?: {
|
|
29
38
|
observedAt: number | null;
|
|
30
39
|
error: string | null;
|
|
@@ -96,6 +105,7 @@ const timestamp = (value: unknown): value is number =>
|
|
|
96
105
|
const nullableError = (value: unknown): value is string | null =>
|
|
97
106
|
value === null || (typeof value === "string" && value.length <= 2048);
|
|
98
107
|
function sameAddresses(value: unknown, expected: readonly string[]): boolean {
|
|
108
|
+
if (value === null || value === undefined) return expected.length === 0;
|
|
99
109
|
if (!Array.isArray(value)) return false;
|
|
100
110
|
const addresses = value as unknown[];
|
|
101
111
|
return (
|
|
@@ -172,6 +182,33 @@ function parseSnapshot(input: unknown): NetworkingSnapshot {
|
|
|
172
182
|
throw new HostError("Duplicate local Pivot observation.");
|
|
173
183
|
if (data.account !== undefined && !isCanonicalPublicKey(data.account))
|
|
174
184
|
throw new HostError("Invalid observation account.");
|
|
185
|
+
let readiness: NetworkingSnapshot["readiness"];
|
|
186
|
+
if (data.readiness !== undefined) {
|
|
187
|
+
const saved = object(data.readiness, "Pivot readiness observations");
|
|
188
|
+
if (Object.keys(saved).length > 256)
|
|
189
|
+
throw new HostError("Too many Pivot readiness observations.");
|
|
190
|
+
readiness = Object.fromEntries(
|
|
191
|
+
Object.entries(saved).map(([peerId, input]) => {
|
|
192
|
+
const entry = object(input, "Pivot readiness observation");
|
|
193
|
+
if (
|
|
194
|
+
!/^[A-Za-z0-9]{32,128}$/.test(peerId) ||
|
|
195
|
+
!timestamp(entry.observedAt) ||
|
|
196
|
+
entry.observedAt > updatedAt ||
|
|
197
|
+
!nullableError(entry.error)
|
|
198
|
+
)
|
|
199
|
+
throw new HostError("Invalid Pivot readiness observation.");
|
|
200
|
+
return [
|
|
201
|
+
peerId,
|
|
202
|
+
{
|
|
203
|
+
observedAt: entry.observedAt,
|
|
204
|
+
status:
|
|
205
|
+
entry.status === null ? null : parsePivotStatus(entry.status),
|
|
206
|
+
error: entry.error,
|
|
207
|
+
},
|
|
208
|
+
];
|
|
209
|
+
}),
|
|
210
|
+
);
|
|
211
|
+
}
|
|
175
212
|
let connections: NetworkingSnapshot["connections"];
|
|
176
213
|
if (data.connections !== undefined) {
|
|
177
214
|
const saved = object(data.connections, "connection observation");
|
|
@@ -220,6 +257,7 @@ function parseSnapshot(input: unknown): NetworkingSnapshot {
|
|
|
220
257
|
pivots,
|
|
221
258
|
...(typeof data.account === "string" ? { account: data.account } : {}),
|
|
222
259
|
...(connections ? { connections } : {}),
|
|
260
|
+
...(readiness ? { readiness } : {}),
|
|
223
261
|
};
|
|
224
262
|
}
|
|
225
263
|
export async function networkingAccount(
|
|
@@ -325,25 +363,13 @@ export async function readNetworkingSnapshot(
|
|
|
325
363
|
);
|
|
326
364
|
const selected = snapshot.pivots.filter((pivot) => pivot.selected);
|
|
327
365
|
const bootstrap = selected.flatMap(({ addresses }) => addresses).sort();
|
|
328
|
-
const relays = selected
|
|
329
|
-
.flatMap(({ addresses }) => (addresses[0] ? [addresses[0]] : []))
|
|
330
|
-
.sort();
|
|
331
|
-
const swarm = object(
|
|
332
|
-
config?.Swarm ?? {},
|
|
333
|
-
"local Kubo Swarm configuration",
|
|
334
|
-
);
|
|
335
|
-
const relayClient = object(
|
|
336
|
-
swarm.RelayClient ?? {},
|
|
337
|
-
"local Kubo relay configuration",
|
|
338
|
-
);
|
|
339
366
|
if (
|
|
340
367
|
!config ||
|
|
341
368
|
object(config.Identity, "local Kubo identity").PeerID !== peerId ||
|
|
342
|
-
!sameAddresses(config.Bootstrap, bootstrap)
|
|
343
|
-
!sameAddresses(relayClient.StaticRelays, relays)
|
|
369
|
+
!sameAddresses(config.Bootstrap, bootstrap)
|
|
344
370
|
)
|
|
345
371
|
topologyError =
|
|
346
|
-
"Current Bootstrap
|
|
372
|
+
"Current Bootstrap differs from the observed applied selection.";
|
|
347
373
|
}
|
|
348
374
|
} else topologyError = "No existing managed node.";
|
|
349
375
|
return {
|