@ipab/cli 0.1.0-rc.0 → 0.1.0-rc.10
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 +230 -7
- package/dist/app-authoring.d.ts +16 -2
- package/dist/app-authoring.d.ts.map +1 -1
- package/dist/app-authoring.js +151 -66
- package/dist/app-authoring.js.map +1 -1
- package/dist/app-definition.d.ts +52 -63
- package/dist/app-definition.d.ts.map +1 -1
- package/dist/app-definition.js +33 -44
- package/dist/app-definition.js.map +1 -1
- package/dist/app-prebuild.d.ts +18 -0
- package/dist/app-prebuild.d.ts.map +1 -1
- package/dist/app-prebuild.js +46 -0
- package/dist/app-prebuild.js.map +1 -1
- package/dist/app-templates.d.ts +0 -1
- package/dist/app-templates.d.ts.map +1 -1
- package/dist/app-templates.js +15 -45
- package/dist/app-templates.js.map +1 -1
- package/dist/assembly.d.ts +7 -0
- package/dist/assembly.d.ts.map +1 -0
- package/dist/assembly.js +130 -0
- package/dist/assembly.js.map +1 -0
- package/dist/authoring.d.ts +8 -21
- package/dist/authoring.d.ts.map +1 -1
- package/dist/authoring.js +35 -54
- 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/builtins.d.ts.map +1 -1
- package/dist/builtins.js +5 -32
- package/dist/builtins.js.map +1 -1
- package/dist/bundled-skills.d.ts +14 -0
- package/dist/bundled-skills.d.ts.map +1 -0
- package/dist/bundled-skills.js +34 -0
- package/dist/bundled-skills.js.map +1 -0
- package/dist/cli.d.ts +8 -2
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +2009 -308
- package/dist/cli.js.map +1 -1
- package/dist/config-secret.d.ts +3 -0
- package/dist/config-secret.d.ts.map +1 -0
- package/dist/config-secret.js +12 -0
- package/dist/config-secret.js.map +1 -0
- package/dist/config.d.ts +9 -4
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +164 -23
- package/dist/config.js.map +1 -1
- package/dist/content-provider.d.ts +32 -0
- package/dist/content-provider.d.ts.map +1 -0
- package/dist/content-provider.js +222 -0
- package/dist/content-provider.js.map +1 -0
- package/dist/context-types.d.ts +12 -0
- package/dist/context-types.d.ts.map +1 -0
- package/dist/context-types.js +2 -0
- package/dist/context-types.js.map +1 -0
- package/dist/context.d.ts +26 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +56 -2
- package/dist/context.js.map +1 -1
- package/dist/daemon-ui.d.ts +93 -0
- package/dist/daemon-ui.d.ts.map +1 -0
- package/dist/daemon-ui.js +713 -0
- package/dist/daemon-ui.js.map +1 -0
- package/dist/daemon.d.ts +21 -0
- package/dist/daemon.d.ts.map +1 -0
- package/dist/daemon.js +317 -0
- package/dist/daemon.js.map +1 -0
- package/dist/doctor.d.ts +32 -0
- package/dist/doctor.d.ts.map +1 -0
- package/dist/doctor.js +684 -0
- package/dist/doctor.js.map +1 -0
- package/dist/errors.d.ts +1 -8
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +1 -20
- package/dist/errors.js.map +1 -1
- package/dist/get.d.ts +3 -0
- package/dist/get.d.ts.map +1 -0
- package/dist/get.js +80 -0
- package/dist/get.js.map +1 -0
- package/dist/history.d.ts.map +1 -1
- package/dist/history.js +6 -14
- package/dist/history.js.map +1 -1
- package/dist/host-error.d.ts +9 -0
- package/dist/host-error.d.ts.map +1 -0
- package/dist/host-error.js +21 -0
- package/dist/host-error.js.map +1 -0
- package/dist/identity.d.ts +16 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +119 -0
- package/dist/identity.js.map +1 -0
- package/dist/ipc.d.ts +5 -1
- package/dist/ipc.d.ts.map +1 -1
- package/dist/ipc.js +125 -4
- package/dist/ipc.js.map +1 -1
- package/dist/kubo-install.d.ts +26 -0
- package/dist/kubo-install.d.ts.map +1 -0
- package/dist/kubo-install.js +724 -0
- package/dist/kubo-install.js.map +1 -0
- package/dist/kubo-peering.d.ts +11 -0
- package/dist/kubo-peering.d.ts.map +1 -0
- package/dist/kubo-peering.js +93 -0
- package/dist/kubo-peering.js.map +1 -0
- package/dist/kubo-peers.d.ts +12 -0
- package/dist/kubo-peers.d.ts.map +1 -0
- package/dist/kubo-peers.js +119 -0
- package/dist/kubo-peers.js.map +1 -0
- package/dist/kubo-release.d.ts +22 -0
- package/dist/kubo-release.d.ts.map +1 -0
- package/dist/kubo-release.js +176 -0
- package/dist/kubo-release.js.map +1 -0
- package/dist/kubo-topology.d.ts +19 -0
- package/dist/kubo-topology.d.ts.map +1 -0
- package/dist/kubo-topology.js +113 -0
- package/dist/kubo-topology.js.map +1 -0
- package/dist/kubo.d.ts +85 -0
- package/dist/kubo.d.ts.map +1 -0
- package/dist/kubo.js +755 -0
- package/dist/kubo.js.map +1 -0
- package/dist/pins.d.ts +18 -20
- package/dist/pins.d.ts.map +1 -1
- package/dist/pins.js +146 -126
- package/dist/pins.js.map +1 -1
- package/dist/pivot-rpc.d.ts +62 -0
- package/dist/pivot-rpc.d.ts.map +1 -0
- package/dist/pivot-rpc.js +407 -0
- package/dist/pivot-rpc.js.map +1 -0
- package/dist/pivot-service.d.ts +16 -0
- package/dist/pivot-service.d.ts.map +1 -0
- package/dist/pivot-service.js +50 -0
- package/dist/pivot-service.js.map +1 -0
- package/dist/publish-source.d.ts +3 -0
- package/dist/publish-source.d.ts.map +1 -0
- package/dist/publish-source.js +85 -0
- package/dist/publish-source.js.map +1 -0
- package/dist/runtime.d.ts +2 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +9 -4
- package/dist/runtime.js.map +1 -1
- package/dist/search-index.d.ts +64 -0
- package/dist/search-index.d.ts.map +1 -0
- package/dist/search-index.js +409 -0
- package/dist/search-index.js.map +1 -0
- package/dist/search-service.d.ts +23 -0
- package/dist/search-service.d.ts.map +1 -0
- package/dist/search-service.js +116 -0
- package/dist/search-service.js.map +1 -0
- package/dist/skill-definition.d.ts +6 -0
- package/dist/skill-definition.d.ts.map +1 -0
- package/dist/skill-definition.js +38 -0
- package/dist/skill-definition.js.map +1 -0
- package/dist/skill-source.d.ts +9 -0
- package/dist/skill-source.d.ts.map +1 -0
- package/dist/skill-source.js +24 -0
- package/dist/skill-source.js.map +1 -0
- package/dist/skills.d.ts +104 -0
- package/dist/skills.d.ts.map +1 -0
- package/dist/skills.js +894 -0
- package/dist/skills.js.map +1 -0
- package/dist/source-bundle.d.ts +3 -9
- package/dist/source-bundle.d.ts.map +1 -1
- package/dist/source-bundle.js +17 -13
- package/dist/source-bundle.js.map +1 -1
- package/dist/space-path.d.ts +3 -0
- package/dist/space-path.d.ts.map +1 -0
- package/dist/space-path.js +17 -0
- package/dist/space-path.js.map +1 -0
- package/dist/space.d.ts +16 -4
- package/dist/space.d.ts.map +1 -1
- package/dist/space.js +170 -24
- package/dist/space.js.map +1 -1
- package/dist/state-storage-windows.d.ts +2 -0
- package/dist/state-storage-windows.d.ts.map +1 -0
- package/dist/state-storage-windows.js +114 -0
- package/dist/state-storage-windows.js.map +1 -0
- package/dist/state-storage.d.ts +5 -0
- package/dist/state-storage.d.ts.map +1 -0
- package/dist/state-storage.js +333 -0
- package/dist/state-storage.js.map +1 -0
- package/dist/state.d.ts +128 -16
- package/dist/state.d.ts.map +1 -1
- package/dist/state.js +506 -94
- package/dist/state.js.map +1 -1
- package/dist/swarm-envelope.d.ts +57 -0
- package/dist/swarm-envelope.d.ts.map +1 -0
- package/dist/swarm-envelope.js +299 -0
- package/dist/swarm-envelope.js.map +1 -0
- package/dist/swarm-files.d.ts +6 -0
- package/dist/swarm-files.d.ts.map +1 -0
- package/dist/swarm-files.js +116 -0
- package/dist/swarm-files.js.map +1 -0
- package/dist/swarm-meta.d.ts +15 -0
- package/dist/swarm-meta.d.ts.map +1 -0
- package/dist/swarm-meta.js +68 -0
- package/dist/swarm-meta.js.map +1 -0
- package/dist/swarm-observations.d.ts +40 -0
- package/dist/swarm-observations.d.ts.map +1 -0
- package/dist/swarm-observations.js +271 -0
- package/dist/swarm-observations.js.map +1 -0
- package/dist/swarm.d.ts +469 -0
- package/dist/swarm.d.ts.map +1 -0
- package/dist/swarm.js +4708 -0
- package/dist/swarm.js.map +1 -0
- package/dist/template-definition.d.ts +45 -67
- package/dist/template-definition.d.ts.map +1 -1
- package/dist/template-definition.js +35 -49
- package/dist/template-definition.js.map +1 -1
- package/dist/template-paths.d.ts +7 -0
- package/dist/template-paths.d.ts.map +1 -0
- package/dist/template-paths.js +23 -0
- package/dist/template-paths.js.map +1 -0
- package/dist/template-presentation.d.ts +20 -0
- package/dist/template-presentation.d.ts.map +1 -0
- package/dist/template-presentation.js +133 -0
- package/dist/template-presentation.js.map +1 -0
- package/dist/template-source.d.ts +4 -1
- package/dist/template-source.d.ts.map +1 -1
- package/dist/template-source.js +11 -4
- package/dist/template-source.js.map +1 -1
- package/dist/templates.d.ts +11 -0
- package/dist/templates.d.ts.map +1 -0
- package/dist/templates.js +53 -0
- package/dist/templates.js.map +1 -0
- package/dist/unixfs-tree.d.ts +67 -0
- package/dist/unixfs-tree.d.ts.map +1 -0
- package/dist/unixfs-tree.js +329 -0
- package/dist/unixfs-tree.js.map +1 -0
- package/package.json +18 -11
- package/src/app-authoring.ts +254 -88
- package/src/app-definition.ts +33 -45
- package/src/app-prebuild.ts +61 -0
- package/src/app-templates.ts +28 -71
- package/src/assembly.ts +185 -0
- package/src/authoring.ts +63 -72
- package/src/builtins.ts +7 -38
- package/src/bundled-skills.ts +60 -0
- package/src/cli.ts +2500 -376
- package/src/config-secret.ts +14 -0
- package/src/config.ts +215 -26
- package/src/content-provider.ts +299 -0
- package/src/context-types.ts +11 -0
- package/src/context.ts +100 -2
- package/src/daemon-ui.ts +812 -0
- package/src/daemon.ts +386 -0
- package/src/doctor.ts +1082 -0
- package/src/errors.ts +1 -25
- package/src/get.ts +90 -0
- package/src/history.ts +5 -15
- package/src/host-error.ts +26 -0
- package/src/identity.ts +175 -0
- package/src/ipc.ts +161 -4
- package/src/kubo-install.ts +936 -0
- package/src/kubo-peering.ts +126 -0
- package/src/kubo-peers.ts +144 -0
- package/src/kubo-release.ts +230 -0
- package/src/kubo-topology.ts +148 -0
- package/src/kubo.ts +1088 -0
- package/src/pins.ts +190 -142
- package/src/pivot-rpc.ts +601 -0
- package/src/pivot-service.ts +87 -0
- package/src/publish-source.ts +103 -0
- package/src/runtime.ts +16 -3
- package/src/search-index.ts +560 -0
- package/src/search-service.ts +152 -0
- package/src/skill-definition.ts +53 -0
- package/src/skill-source.ts +29 -0
- package/src/skills.ts +1236 -0
- package/src/source-bundle.ts +26 -14
- package/src/space-path.ts +30 -0
- package/src/space.ts +230 -42
- package/src/state-storage-windows.ts +134 -0
- package/src/state-storage.ts +378 -0
- package/src/state.ts +782 -116
- package/src/swarm-envelope.ts +461 -0
- package/src/swarm-files.ts +126 -0
- package/src/swarm-meta.ts +98 -0
- package/src/swarm-observations.ts +393 -0
- package/src/swarm.ts +7051 -0
- package/src/template-definition.ts +35 -49
- package/src/template-paths.ts +43 -0
- package/src/template-presentation.ts +151 -0
- package/src/template-source.ts +19 -5
- package/src/templates.ts +77 -0
- package/src/unixfs-tree.ts +401 -0
package/src/app-templates.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { fileURLToPath } from "node:url";
|
|
2
1
|
import { resolve } from "node:path";
|
|
3
|
-
import { lstat
|
|
2
|
+
import { lstat } from "node:fs/promises";
|
|
4
3
|
import { Liquid, type Template } from "liquidjs";
|
|
4
|
+
import { parseBundleManifest } from "@ipab/bundle";
|
|
5
5
|
import {
|
|
6
6
|
listTree,
|
|
7
7
|
readBytes,
|
|
8
8
|
type ReadonlyFileTree,
|
|
9
|
+
type TreeEntry,
|
|
9
10
|
} from "@ipab/bundle-builder";
|
|
10
11
|
import { filesystemTree } from "@ipab/bundle-builder/node";
|
|
11
12
|
import { HostError, object } from "./errors.js";
|
|
@@ -15,13 +16,20 @@ import {
|
|
|
15
16
|
templateDefinition,
|
|
16
17
|
templateParameters,
|
|
17
18
|
} from "./template-definition.js";
|
|
18
|
-
import {
|
|
19
|
+
import { templateSource } from "./template-source.js";
|
|
20
|
+
import { addTemplateOutputPath, templateOutputPath } from "./template-paths.js";
|
|
19
21
|
import { nodeError } from "./authoring.js";
|
|
20
22
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
function appName(name: string) {
|
|
24
|
+
if (
|
|
25
|
+
!/^[a-z0-9][a-z0-9._-]*$/.test(name) ||
|
|
26
|
+
name.length > 214 ||
|
|
27
|
+
["node_modules", "favicon.ico"].includes(name)
|
|
28
|
+
)
|
|
29
|
+
throw new HostError(
|
|
30
|
+
"App NAME must be an unscoped lowercase npm package name.",
|
|
31
|
+
);
|
|
32
|
+
}
|
|
25
33
|
|
|
26
34
|
async function legacyTemplate(
|
|
27
35
|
selector: string,
|
|
@@ -237,11 +245,18 @@ export async function renderTemplate(
|
|
|
237
245
|
options: AuthoringOptions & { parameters?: readonly string[] },
|
|
238
246
|
) {
|
|
239
247
|
const definition = templateDefinition(
|
|
240
|
-
await readBytes(
|
|
248
|
+
await readBytes(
|
|
249
|
+
tree,
|
|
250
|
+
parseBundleManifest(
|
|
251
|
+
await readBytes(tree, ".bundle.yaml", 1024 * 1024, options),
|
|
252
|
+
).entry,
|
|
253
|
+
64 * 1024,
|
|
254
|
+
options,
|
|
255
|
+
),
|
|
241
256
|
);
|
|
242
257
|
const values = templateParameters(definition, name, options.parameters);
|
|
243
258
|
const files = new Map<string, string | Uint8Array>();
|
|
244
|
-
const paths = new Map<string,
|
|
259
|
+
const paths = new Map<string, TreeEntry["kind"]>();
|
|
245
260
|
let count = 0,
|
|
246
261
|
total = 0;
|
|
247
262
|
const collect = async (directory: string, depth: number): Promise<void> => {
|
|
@@ -251,35 +266,8 @@ export async function renderTemplate(
|
|
|
251
266
|
if (++count > 256)
|
|
252
267
|
throw new HostError("Template exceeds 256 project paths.");
|
|
253
268
|
const source = `${directory}/${entry.name}`;
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
const rendered = entry.kind === "file" && original.endsWith(".liquid");
|
|
257
|
-
const target = relativePath(
|
|
258
|
-
rendered ? original.slice(0, -".liquid".length) : original,
|
|
259
|
-
);
|
|
260
|
-
if (
|
|
261
|
-
target
|
|
262
|
-
.split("/")
|
|
263
|
-
.some(
|
|
264
|
-
(part) =>
|
|
265
|
-
["node_modules", ".git", "dist"].includes(part.toLowerCase()) ||
|
|
266
|
-
/^(?:con|prn|aux|nul|com[0-9]|lpt[0-9])(?:\.|$)/i.test(part),
|
|
267
|
-
)
|
|
268
|
-
)
|
|
269
|
-
throw new HostError(`Unsafe template output path: ${target}.`);
|
|
270
|
-
const key = target.toLowerCase();
|
|
271
|
-
if (
|
|
272
|
-
paths.has(key) ||
|
|
273
|
-
[...paths].some(
|
|
274
|
-
([existing, kind]) =>
|
|
275
|
-
(kind === "file" && key.startsWith(`${existing}/`)) ||
|
|
276
|
-
(entry.kind === "file" && existing.startsWith(`${key}/`)),
|
|
277
|
-
)
|
|
278
|
-
)
|
|
279
|
-
throw new HostError(
|
|
280
|
-
`Duplicate or overlapping template output path: ${target}.`,
|
|
281
|
-
);
|
|
282
|
-
paths.set(key, entry.kind);
|
|
269
|
+
const { target, rendered } = templateOutputPath(source, entry.kind);
|
|
270
|
+
addTemplateOutputPath(paths, target, entry.kind);
|
|
283
271
|
if (entry.kind === "directory") {
|
|
284
272
|
await collect(source, depth + 1);
|
|
285
273
|
continue;
|
|
@@ -314,38 +302,6 @@ export async function appTemplate(
|
|
|
314
302
|
options: AuthoringOptions & { parameters?: readonly string[] },
|
|
315
303
|
): Promise<{ files: Map<string, string | Uint8Array>; cid: string | null }> {
|
|
316
304
|
options.signal?.throwIfAborted();
|
|
317
|
-
for (const [alias, name] of builtinTemplateNames)
|
|
318
|
-
if (selector === alias) selector = name;
|
|
319
|
-
if (selector === "node" || selector === "web-app") {
|
|
320
|
-
const loaded = await builtinTemplateSource(selector, options);
|
|
321
|
-
const parameters = [...(options.parameters ?? [])];
|
|
322
|
-
if (
|
|
323
|
-
selector === "web-app" &&
|
|
324
|
-
!parameters.some((value) => value.startsWith("webAppDependency="))
|
|
325
|
-
) {
|
|
326
|
-
const framework = object(
|
|
327
|
-
JSON.parse(
|
|
328
|
-
await readFile(
|
|
329
|
-
fileURLToPath(import.meta.resolve("@ipab/web-app/package.json")),
|
|
330
|
-
"utf8",
|
|
331
|
-
),
|
|
332
|
-
) as unknown,
|
|
333
|
-
"Web App framework package",
|
|
334
|
-
);
|
|
335
|
-
if (typeof framework.version !== "string" || !framework.version.trim())
|
|
336
|
-
throw new HostError(
|
|
337
|
-
"Web App framework package is missing its version.",
|
|
338
|
-
);
|
|
339
|
-
parameters.push(`webAppDependency=${framework.version}`);
|
|
340
|
-
}
|
|
341
|
-
return {
|
|
342
|
-
files: await renderTemplate(loaded.tree, name, {
|
|
343
|
-
...options,
|
|
344
|
-
parameters,
|
|
345
|
-
}),
|
|
346
|
-
cid: loaded.cid,
|
|
347
|
-
};
|
|
348
|
-
}
|
|
349
305
|
let legacy = false;
|
|
350
306
|
try {
|
|
351
307
|
await lstat(resolve(selector, ".bundle.yaml"));
|
|
@@ -360,6 +316,7 @@ export async function appTemplate(
|
|
|
360
316
|
}
|
|
361
317
|
}
|
|
362
318
|
if (legacy) {
|
|
319
|
+
appName(name);
|
|
363
320
|
if (options.parameters?.length)
|
|
364
321
|
throw new HostError(
|
|
365
322
|
"--param requires a Template Bundle, not a legacy mapping.",
|
|
@@ -375,7 +332,7 @@ export async function appTemplate(
|
|
|
375
332
|
} catch (error) {
|
|
376
333
|
if (nodeError(error, "ENOENT"))
|
|
377
334
|
throw new HostError(
|
|
378
|
-
`Unknown template "${selector}". Use
|
|
335
|
+
`Unknown template "${selector}". Use a Swarm template selector, valid Bundle directory, single-root CAR, exact CID or IPAB URI. Builtin templates and local aliases are unsupported.`,
|
|
379
336
|
);
|
|
380
337
|
throw error;
|
|
381
338
|
}
|
package/src/assembly.ts
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { lstat } from "node:fs/promises";
|
|
2
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
3
|
+
import { CID } from "multiformats/cid";
|
|
4
|
+
import { parseData, parseBundleManifest } from "@ipab/bundle";
|
|
5
|
+
import {
|
|
6
|
+
encodeBundleCar,
|
|
7
|
+
fileTree,
|
|
8
|
+
readBytes,
|
|
9
|
+
type FileReader,
|
|
10
|
+
} from "@ipab/bundle-builder";
|
|
11
|
+
import { filesystemTree } from "@ipab/bundle-builder/node";
|
|
12
|
+
import { HostError, object } from "./errors.js";
|
|
13
|
+
import { relativePath } from "./space.js";
|
|
14
|
+
import {
|
|
15
|
+
nodeError,
|
|
16
|
+
outputAvailable,
|
|
17
|
+
readCar,
|
|
18
|
+
writeCar,
|
|
19
|
+
type AuthoringOptions,
|
|
20
|
+
type BuildResult,
|
|
21
|
+
} from "./authoring.js";
|
|
22
|
+
|
|
23
|
+
function keys(value: Record<string, unknown>, allowed: string[]): void {
|
|
24
|
+
if (Object.keys(value).some((key) => !allowed.includes(key)))
|
|
25
|
+
throw new HostError(
|
|
26
|
+
"Unknown assembly recipe field. Legacy App ipab.yaml/ipab.json is not a generic assembly recipe; run project preparation separately.",
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function assembleBundle(
|
|
31
|
+
source = ".",
|
|
32
|
+
options: AuthoringOptions & {
|
|
33
|
+
output?: string;
|
|
34
|
+
outputDir?: string;
|
|
35
|
+
replace?: boolean;
|
|
36
|
+
} = {},
|
|
37
|
+
): Promise<BuildResult> {
|
|
38
|
+
const input = resolve(source);
|
|
39
|
+
const stat = await lstat(input);
|
|
40
|
+
if (stat.isSymbolicLink())
|
|
41
|
+
throw new HostError("Assembly input must not be a symlink.");
|
|
42
|
+
const recipePath = stat.isDirectory()
|
|
43
|
+
? join(input, "ipab.build.yaml")
|
|
44
|
+
: input;
|
|
45
|
+
const root = dirname(recipePath);
|
|
46
|
+
const tree = await filesystemTree(root);
|
|
47
|
+
let recipeBytes: Uint8Array;
|
|
48
|
+
try {
|
|
49
|
+
recipeBytes = await readBytes(
|
|
50
|
+
tree,
|
|
51
|
+
basename(recipePath),
|
|
52
|
+
64 * 1024,
|
|
53
|
+
options,
|
|
54
|
+
);
|
|
55
|
+
} catch (cause) {
|
|
56
|
+
if (stat.isDirectory()) {
|
|
57
|
+
for (const legacy of ["ipab.yaml", "ipab.json"]) {
|
|
58
|
+
try {
|
|
59
|
+
await lstat(join(root, legacy));
|
|
60
|
+
throw new HostError(
|
|
61
|
+
"Legacy App build configuration is unsupported by generic build. Run the project preparation script, then supply ipab.build.yaml.",
|
|
62
|
+
);
|
|
63
|
+
} catch (error) {
|
|
64
|
+
if (!nodeError(error, "ENOENT")) throw error;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
throw cause;
|
|
69
|
+
}
|
|
70
|
+
const recipe = object(
|
|
71
|
+
parseData(recipeBytes, "application/yaml"),
|
|
72
|
+
"assembly recipe",
|
|
73
|
+
);
|
|
74
|
+
keys(recipe, ["version", "files", "imports"]);
|
|
75
|
+
if (
|
|
76
|
+
recipe.version !== 1 ||
|
|
77
|
+
!Array.isArray(recipe.files) ||
|
|
78
|
+
!Array.isArray(recipe.imports ?? [])
|
|
79
|
+
)
|
|
80
|
+
throw new HostError(
|
|
81
|
+
"Assembly recipe requires version: 1, files: [{source,target}], and optional imports: [{cid,target}].",
|
|
82
|
+
);
|
|
83
|
+
const files = new Map<string, FileReader>();
|
|
84
|
+
const paths: string[] = [];
|
|
85
|
+
const claim = (target: string) => {
|
|
86
|
+
relativePath(target);
|
|
87
|
+
const key = target.toLowerCase();
|
|
88
|
+
if (
|
|
89
|
+
paths.some(
|
|
90
|
+
(previous) =>
|
|
91
|
+
previous === key ||
|
|
92
|
+
previous.startsWith(`${key}/`) ||
|
|
93
|
+
key.startsWith(`${previous}/`),
|
|
94
|
+
)
|
|
95
|
+
)
|
|
96
|
+
throw new HostError(`Assembly target collision: ${target}.`);
|
|
97
|
+
paths.push(key);
|
|
98
|
+
};
|
|
99
|
+
files.set(".bundle.yaml", () => tree.read(".bundle.yaml", options));
|
|
100
|
+
claim(".bundle.yaml");
|
|
101
|
+
const definition = parseBundleManifest(
|
|
102
|
+
await readBytes(tree, ".bundle.yaml", 1024 * 1024, options),
|
|
103
|
+
);
|
|
104
|
+
const inputs = new Set<string>([resolve(root, ".bundle.yaml"), recipePath]);
|
|
105
|
+
for (const item of recipe.files) {
|
|
106
|
+
const mapping = object(item, "file mapping");
|
|
107
|
+
keys(mapping, ["source", "target"]);
|
|
108
|
+
if (
|
|
109
|
+
typeof mapping.source !== "string" ||
|
|
110
|
+
typeof mapping.target !== "string"
|
|
111
|
+
)
|
|
112
|
+
throw new HostError(
|
|
113
|
+
"Recipe file mappings require source and target strings.",
|
|
114
|
+
);
|
|
115
|
+
relativePath(mapping.source);
|
|
116
|
+
claim(mapping.target);
|
|
117
|
+
inputs.add(resolve(root, ...mapping.source.split("/")));
|
|
118
|
+
const sourcePath = mapping.source;
|
|
119
|
+
files.set(mapping.target, () => tree.read(sourcePath, options));
|
|
120
|
+
}
|
|
121
|
+
// CID grafts are processed sequentially; keep at most one local CAR in memory.
|
|
122
|
+
let localCar:
|
|
123
|
+
{ path: string; data: Awaited<ReturnType<typeof readCar>> } | undefined;
|
|
124
|
+
const imports = ((recipe.imports as unknown[] | undefined) ?? []).map(
|
|
125
|
+
(item) => {
|
|
126
|
+
const mapping = object(item, "CID import");
|
|
127
|
+
keys(mapping, ["cid", "target", "car"]);
|
|
128
|
+
if (typeof mapping.cid !== "string" || typeof mapping.target !== "string")
|
|
129
|
+
throw new HostError("CID imports require cid and target strings.");
|
|
130
|
+
const cid = CID.parse(mapping.cid);
|
|
131
|
+
claim(mapping.target);
|
|
132
|
+
if (mapping.car !== undefined) {
|
|
133
|
+
if (typeof mapping.car !== "string")
|
|
134
|
+
throw new HostError("CID import car must be a relative file path.");
|
|
135
|
+
const path = resolve(root, relativePath(mapping.car));
|
|
136
|
+
inputs.add(path);
|
|
137
|
+
return {
|
|
138
|
+
path: mapping.target,
|
|
139
|
+
cid,
|
|
140
|
+
resolveCid: async (block: CID) => {
|
|
141
|
+
if (localCar?.path !== path)
|
|
142
|
+
localCar = { path, data: await readCar(path, options, root) };
|
|
143
|
+
if (!localCar.data.root.equals(cid))
|
|
144
|
+
throw new HostError(
|
|
145
|
+
"CID import does not match the local CAR root.",
|
|
146
|
+
);
|
|
147
|
+
return localCar.data.resolveCid(block);
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
if (!options.resolveCid)
|
|
152
|
+
throw new HostError("CID imports require a Store.");
|
|
153
|
+
return { path: mapping.target, cid, resolveCid: options.resolveCid };
|
|
154
|
+
},
|
|
155
|
+
);
|
|
156
|
+
if (
|
|
157
|
+
[definition.entry, definition.type].some(
|
|
158
|
+
(path) => !files.has(path) && !imports.some((item) => item.path === path),
|
|
159
|
+
)
|
|
160
|
+
)
|
|
161
|
+
throw new HostError(
|
|
162
|
+
"Recipe must explicitly select the Bundle entry and type files.",
|
|
163
|
+
);
|
|
164
|
+
const output = options.output
|
|
165
|
+
? resolve(options.output)
|
|
166
|
+
: join(root, options.outputDir ?? "dist", "bundle.car");
|
|
167
|
+
if ([...inputs].some((input) => input.toLowerCase() === output.toLowerCase()))
|
|
168
|
+
throw new HostError("CAR output cannot replace recipe or source inputs.");
|
|
169
|
+
await outputAvailable(output, Boolean(options.replace));
|
|
170
|
+
const encoded = await encodeBundleCar(fileTree(files), {
|
|
171
|
+
...options,
|
|
172
|
+
imports,
|
|
173
|
+
});
|
|
174
|
+
const result = {
|
|
175
|
+
kind: "content-bundle" as const,
|
|
176
|
+
cid: encoded.cid.toString(),
|
|
177
|
+
schemaCid: encoded.schema.cid.toString(),
|
|
178
|
+
output,
|
|
179
|
+
validation: encoded.validation,
|
|
180
|
+
};
|
|
181
|
+
return {
|
|
182
|
+
...result,
|
|
183
|
+
bytes: await writeCar(encoded, output, Boolean(options.replace), options),
|
|
184
|
+
};
|
|
185
|
+
}
|
package/src/authoring.ts
CHANGED
|
@@ -22,16 +22,21 @@ import { CarBlockIterator } from "@ipld/car/iterator";
|
|
|
22
22
|
import { CID } from "multiformats/cid";
|
|
23
23
|
import { sha256 } from "multiformats/hashes/sha2";
|
|
24
24
|
import ignore from "ignore";
|
|
25
|
-
import { stringify } from "yaml";
|
|
26
25
|
import {
|
|
27
26
|
bundleLimits,
|
|
28
27
|
encodeSchema,
|
|
29
28
|
openBundle,
|
|
30
29
|
openSchema,
|
|
31
30
|
parseBundleManifest,
|
|
31
|
+
parseBundleType,
|
|
32
32
|
ContentBundleError,
|
|
33
33
|
} from "@ipab/bundle";
|
|
34
|
-
import type {
|
|
34
|
+
import type {
|
|
35
|
+
EntryValidation,
|
|
36
|
+
OpenBundleOptions,
|
|
37
|
+
SchemaBlock,
|
|
38
|
+
BundleManifest,
|
|
39
|
+
} from "@ipab/bundle";
|
|
35
40
|
import {
|
|
36
41
|
encodeBundleCar,
|
|
37
42
|
encodeSchemaCar,
|
|
@@ -59,24 +64,20 @@ export interface BuildResult {
|
|
|
59
64
|
schemaCid: string;
|
|
60
65
|
output: string;
|
|
61
66
|
bytes: number;
|
|
67
|
+
validation?: EntryValidation | null;
|
|
62
68
|
}
|
|
63
69
|
export interface InspectResult {
|
|
64
70
|
kind: "content-bundle" | "bundle-schema";
|
|
65
71
|
sourceKind: "directory" | "definition" | "car" | "cid";
|
|
66
72
|
cid: string | null;
|
|
67
73
|
schemaCid: string;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
directory: string;
|
|
76
|
-
schemaCid: string;
|
|
77
|
-
name: string;
|
|
78
|
-
entry: { path: string; contentType: string };
|
|
79
|
-
files: string[];
|
|
74
|
+
manifest?: BundleManifest;
|
|
75
|
+
type: SchemaBlock["type"];
|
|
76
|
+
validation: {
|
|
77
|
+
definition: "valid";
|
|
78
|
+
storage: "verified" | "not-applicable";
|
|
79
|
+
entry: EntryValidation | null;
|
|
80
|
+
};
|
|
80
81
|
}
|
|
81
82
|
export interface ImportResult {
|
|
82
83
|
kind: "bundle-import";
|
|
@@ -85,6 +86,7 @@ export interface ImportResult {
|
|
|
85
86
|
source: string;
|
|
86
87
|
blocks: number;
|
|
87
88
|
bytes: number;
|
|
89
|
+
validation: EntryValidation | null;
|
|
88
90
|
}
|
|
89
91
|
export function nodeError(error: unknown, code: string): boolean {
|
|
90
92
|
return error instanceof Error && "code" in error && error.code === code;
|
|
@@ -109,7 +111,7 @@ async function localFile(
|
|
|
109
111
|
return readBytes(tree, basename(path), maximum, options);
|
|
110
112
|
}
|
|
111
113
|
async function definitionAt(path: string, options: AuthoringOptions) {
|
|
112
|
-
return
|
|
114
|
+
return parseBundleType(
|
|
113
115
|
await localFile(path, bundleLimits.parsingBytes, options),
|
|
114
116
|
);
|
|
115
117
|
}
|
|
@@ -159,16 +161,23 @@ export async function selectedTree(
|
|
|
159
161
|
pathKey(path).startsWith(`${pathKey(outputDir)}/`)),
|
|
160
162
|
) ||
|
|
161
163
|
matcher.ignores(directory ? `${path}/` : path);
|
|
162
|
-
for (const required of [".bundle.yaml", definition.entry.
|
|
164
|
+
for (const required of [".bundle.yaml", definition.entry, definition.type])
|
|
163
165
|
if (excluded(required, false))
|
|
164
166
|
throw new HostError(
|
|
165
167
|
`Required bundle file is excluded: ${required}. Fix .bundle-ignore or choose an output outside the entry tree.`,
|
|
166
168
|
);
|
|
167
169
|
return filesystemTree(root, { exclude: excluded });
|
|
168
170
|
}
|
|
169
|
-
export async function readCar(
|
|
170
|
-
|
|
171
|
-
|
|
171
|
+
export async function readCar(
|
|
172
|
+
path: string,
|
|
173
|
+
options: AuthoringOptions,
|
|
174
|
+
directory = dirname(path),
|
|
175
|
+
) {
|
|
176
|
+
const tree = await filesystemTree(directory);
|
|
177
|
+
const input = await tree.read(
|
|
178
|
+
relative(directory, path).split(sep).join("/"),
|
|
179
|
+
options,
|
|
180
|
+
);
|
|
172
181
|
const chunks = streamChunks(input, options);
|
|
173
182
|
let bytes = 0;
|
|
174
183
|
try {
|
|
@@ -299,18 +308,18 @@ async function fromRoot(
|
|
|
299
308
|
});
|
|
300
309
|
return {
|
|
301
310
|
schema: bundle.schema,
|
|
311
|
+
manifest: bundle.manifest,
|
|
312
|
+
validation: bundle.validation,
|
|
302
313
|
kind: "content-bundle" as const,
|
|
303
314
|
sourceKind,
|
|
304
315
|
cid: root.toString(),
|
|
305
316
|
};
|
|
306
317
|
}
|
|
307
|
-
function summary(schema: SchemaBlock) {
|
|
308
|
-
const { name, description, entry } = schema.manifest;
|
|
318
|
+
function summary(schema: SchemaBlock, manifest?: BundleManifest) {
|
|
309
319
|
return {
|
|
310
320
|
schemaCid: schema.cid.toString(),
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
entry: { path: entry.path, contentType: entry.contentType },
|
|
321
|
+
type: schema.type,
|
|
322
|
+
...(manifest ? { manifest } : {}),
|
|
314
323
|
};
|
|
315
324
|
}
|
|
316
325
|
export async function inspectBundle(
|
|
@@ -333,8 +342,12 @@ export async function inspectBundle(
|
|
|
333
342
|
kind: "content-bundle",
|
|
334
343
|
sourceKind: "directory",
|
|
335
344
|
cid: null,
|
|
336
|
-
...summary(encoded.schema),
|
|
337
|
-
validation: {
|
|
345
|
+
...summary(encoded.schema, encoded.manifest ?? undefined),
|
|
346
|
+
validation: {
|
|
347
|
+
definition: "valid",
|
|
348
|
+
storage: "verified",
|
|
349
|
+
entry: encoded.validation,
|
|
350
|
+
},
|
|
338
351
|
};
|
|
339
352
|
} finally {
|
|
340
353
|
await encoded.close();
|
|
@@ -345,10 +358,14 @@ export async function inspectBundle(
|
|
|
345
358
|
kind: loaded.kind,
|
|
346
359
|
sourceKind: loaded.sourceKind,
|
|
347
360
|
cid: loaded.cid,
|
|
348
|
-
...summary(
|
|
361
|
+
...summary(
|
|
362
|
+
loaded.schema,
|
|
363
|
+
"manifest" in loaded ? loaded.manifest : undefined,
|
|
364
|
+
),
|
|
349
365
|
validation: {
|
|
350
|
-
|
|
366
|
+
definition: "valid",
|
|
351
367
|
storage: loaded.kind === "content-bundle" ? "verified" : "not-applicable",
|
|
368
|
+
entry: loaded.kind === "content-bundle" ? loaded.validation : null,
|
|
352
369
|
},
|
|
353
370
|
};
|
|
354
371
|
}
|
|
@@ -378,6 +395,7 @@ export async function importBundle(
|
|
|
378
395
|
cid,
|
|
379
396
|
schemaCid: loaded.schema.cid.toString(),
|
|
380
397
|
source: path,
|
|
398
|
+
validation: loaded.kind === "content-bundle" ? loaded.validation : null,
|
|
381
399
|
blocks: car.blocks.size,
|
|
382
400
|
bytes: car.bytes,
|
|
383
401
|
};
|
|
@@ -458,14 +476,28 @@ export async function buildBundle(
|
|
|
458
476
|
const output = options.output
|
|
459
477
|
? resolve(options.output)
|
|
460
478
|
: join(outputDirectory, options.schemaOnly ? "schema.car" : "bundle.car");
|
|
461
|
-
const
|
|
479
|
+
const manifestPath = join(root, ".bundle.yaml");
|
|
480
|
+
const manifest =
|
|
481
|
+
!options.schemaOnly || (await existing(manifestPath))
|
|
482
|
+
? parseBundleManifest(
|
|
483
|
+
await localFile(manifestPath, bundleLimits.manifestBytes, options),
|
|
484
|
+
)
|
|
485
|
+
: undefined;
|
|
486
|
+
const definitionPath = stat.isDirectory()
|
|
487
|
+
? join(root, manifest?.type ?? ".bundle-type.yaml")
|
|
488
|
+
: path;
|
|
462
489
|
const definition = await definitionAt(definitionPath, options);
|
|
463
490
|
if (
|
|
464
491
|
[
|
|
465
492
|
definitionPath,
|
|
466
493
|
join(root, ".bundle.yaml"),
|
|
467
494
|
join(root, ".bundle-ignore"),
|
|
468
|
-
|
|
495
|
+
...(manifest
|
|
496
|
+
? [
|
|
497
|
+
resolve(root, ...manifest.entry.split("/")),
|
|
498
|
+
resolve(root, ...manifest.type.split("/")),
|
|
499
|
+
]
|
|
500
|
+
: []),
|
|
469
501
|
].some((input) => pathKey(output) === pathKey(input))
|
|
470
502
|
)
|
|
471
503
|
throw new HostError(
|
|
@@ -490,54 +522,13 @@ export async function buildBundle(
|
|
|
490
522
|
cid: encoded.cid.toString(),
|
|
491
523
|
schemaCid: encoded.schema.cid.toString(),
|
|
492
524
|
output,
|
|
525
|
+
validation: encoded.validation,
|
|
493
526
|
};
|
|
494
527
|
return {
|
|
495
528
|
...result,
|
|
496
529
|
bytes: await writeCar(encoded, output, Boolean(options.replace), options),
|
|
497
530
|
};
|
|
498
531
|
}
|
|
499
|
-
export async function initBundle(
|
|
500
|
-
source: string,
|
|
501
|
-
directory: string,
|
|
502
|
-
options: AuthoringOptions = {},
|
|
503
|
-
): Promise<InitResult> {
|
|
504
|
-
const loaded = await artifact(source, options);
|
|
505
|
-
if (loaded.kind !== "bundle-schema")
|
|
506
|
-
throw new HostError(
|
|
507
|
-
"Initialization requires a type definition, not a content bundle.",
|
|
508
|
-
);
|
|
509
|
-
const schema = loaded.schema;
|
|
510
|
-
const { entry } = schema.manifest;
|
|
511
|
-
if (ignore().add("/dist/").ignores(entry.path))
|
|
512
|
-
throw new HostError(
|
|
513
|
-
"Default entry conflicts with the generated /dist/ ignore rule.",
|
|
514
|
-
);
|
|
515
|
-
let value: string;
|
|
516
|
-
if (entry.contentType === "application/jsonl") {
|
|
517
|
-
if (!Array.isArray(entry.defaultValue))
|
|
518
|
-
throw new HostError("JSONL default must be an array.");
|
|
519
|
-
value = entry.defaultValue.map((item) => JSON.stringify(item)).join("\n");
|
|
520
|
-
if (value) value += "\n";
|
|
521
|
-
} else
|
|
522
|
-
value =
|
|
523
|
-
entry.contentType === "application/yaml"
|
|
524
|
-
? stringify(entry.defaultValue)
|
|
525
|
-
: `${JSON.stringify(entry.defaultValue, null, 2)}\n`;
|
|
526
|
-
const files = new Map([
|
|
527
|
-
[".bundle.yaml", stringify(schema.manifest)],
|
|
528
|
-
[".bundle-ignore", "/dist/\n"],
|
|
529
|
-
[entry.path, value],
|
|
530
|
-
]);
|
|
531
|
-
const root = await scaffoldFiles(directory, files, options);
|
|
532
|
-
return {
|
|
533
|
-
kind: "bundle-init",
|
|
534
|
-
directory: root,
|
|
535
|
-
schemaCid: schema.cid.toString(),
|
|
536
|
-
name: schema.manifest.name,
|
|
537
|
-
entry: { path: entry.path, contentType: entry.contentType },
|
|
538
|
-
files: [...files.keys()],
|
|
539
|
-
};
|
|
540
|
-
}
|
|
541
532
|
export async function scaffoldFiles(
|
|
542
533
|
directory: string,
|
|
543
534
|
files: ReadonlyMap<string, string | Uint8Array>,
|
package/src/builtins.ts
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
templateBuiltinAlias,
|
|
5
|
-
templateSchema,
|
|
6
|
-
templateSchemaCid,
|
|
7
|
-
} from "./template-definition.js";
|
|
8
|
-
import { builtinTemplateNames } from "./app-templates.js";
|
|
9
|
-
import { builtinTemplateSource } from "./template-source.js";
|
|
10
|
-
import type { NamedPin, PinMetadata } from "./state.js";
|
|
1
|
+
import { builtinAppSchema } from "./app-definition.js";
|
|
2
|
+
import { builtinTemplateSchema } from "./template-definition.js";
|
|
3
|
+
import type { NamedPin } from "./state.js";
|
|
11
4
|
|
|
12
5
|
async function loadBuiltins(): Promise<{
|
|
13
6
|
pins: readonly NamedPin[];
|
|
@@ -15,36 +8,12 @@ async function loadBuiltins(): Promise<{
|
|
|
15
8
|
}> {
|
|
16
9
|
const pins: NamedPin[] = [];
|
|
17
10
|
const blocks = new Map<string, Uint8Array>();
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
owner: name,
|
|
23
|
-
status: "ready",
|
|
24
|
-
metadata,
|
|
25
|
-
builtin: true,
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
for (const [name, schema] of [
|
|
29
|
-
[appBuiltinAlias, await builtinAppSchema()],
|
|
30
|
-
[templateBuiltinAlias, await builtinTemplateSchema()],
|
|
31
|
-
] as const) {
|
|
11
|
+
for (const schema of [
|
|
12
|
+
await builtinAppSchema(),
|
|
13
|
+
await builtinTemplateSchema(),
|
|
14
|
+
]) {
|
|
32
15
|
const cid = schema.cid.toString();
|
|
33
16
|
blocks.set(cid, schema.bytes);
|
|
34
|
-
add(name, cid, {
|
|
35
|
-
kind: "schema",
|
|
36
|
-
typeName: schema.manifest.name,
|
|
37
|
-
schemaCid: cid,
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
for (const [name, selector] of builtinTemplateNames) {
|
|
41
|
-
const template = await builtinTemplateSource(selector);
|
|
42
|
-
for (const [cid, bytes] of template.blocks) blocks.set(cid, bytes);
|
|
43
|
-
add(name, template.cid, {
|
|
44
|
-
kind: "bundle",
|
|
45
|
-
typeName: templateSchema.name,
|
|
46
|
-
schemaCid: templateSchemaCid.toString(),
|
|
47
|
-
});
|
|
48
17
|
}
|
|
49
18
|
return { pins, blocks };
|
|
50
19
|
}
|