@ipab/cli 0.1.0-rc.0 → 0.1.0-rc.1
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 +7 -1
- package/dist/app-authoring.d.ts +1 -2
- package/dist/app-authoring.d.ts.map +1 -1
- package/dist/app-authoring.js +8 -9
- package/dist/app-authoring.js.map +1 -1
- package/dist/app-definition.d.ts +0 -6
- package/dist/app-definition.d.ts.map +1 -1
- package/dist/app-definition.js +1 -7
- package/dist/app-definition.js.map +1 -1
- package/dist/app-templates.d.ts.map +1 -1
- package/dist/app-templates.js +8 -0
- package/dist/app-templates.js.map +1 -1
- package/dist/authoring.d.ts +5 -14
- package/dist/authoring.d.ts.map +1 -1
- package/dist/authoring.js +10 -39
- package/dist/authoring.js.map +1 -1
- 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 -10
- package/dist/builtins.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +124 -86
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +3 -3
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +15 -17
- package/dist/config.js.map +1 -1
- package/dist/context.d.ts +1 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +10 -0
- package/dist/context.js.map +1 -1
- package/dist/ipc.d.ts +2 -1
- package/dist/ipc.d.ts.map +1 -1
- package/dist/ipc.js +10 -1
- package/dist/ipc.js.map +1 -1
- package/dist/pins.d.ts +9 -9
- package/dist/pins.d.ts.map +1 -1
- package/dist/pins.js +10 -28
- package/dist/pins.js.map +1 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +1 -1
- package/dist/runtime.js.map +1 -1
- package/dist/source-bundle.d.ts +0 -1
- package/dist/source-bundle.d.ts.map +1 -1
- package/dist/source-bundle.js +0 -1
- package/dist/source-bundle.js.map +1 -1
- package/dist/state.d.ts +20 -10
- package/dist/state.d.ts.map +1 -1
- package/dist/state.js +27 -16
- package/dist/state.js.map +1 -1
- package/dist/template-definition.d.ts +0 -17
- package/dist/template-definition.d.ts.map +1 -1
- package/dist/template-definition.js +1 -10
- package/dist/template-definition.js.map +1 -1
- package/package.json +10 -10
- package/src/app-authoring.ts +15 -13
- package/src/app-definition.ts +1 -7
- package/src/app-templates.ts +13 -0
- package/src/authoring.ts +22 -55
- package/src/builtins.ts +5 -11
- package/src/cli.ts +152 -107
- package/src/config.ts +21 -20
- package/src/context.ts +10 -0
- package/src/ipc.ts +8 -0
- package/src/pins.ts +14 -28
- package/src/runtime.ts +1 -0
- package/src/source-bundle.ts +0 -1
- package/src/state.ts +40 -26
- package/src/template-definition.ts +1 -10
package/src/app-authoring.ts
CHANGED
|
@@ -41,28 +41,18 @@ export async function initApp(
|
|
|
41
41
|
parameters?: readonly string[];
|
|
42
42
|
} = {},
|
|
43
43
|
) {
|
|
44
|
-
if (
|
|
45
|
-
!/^[a-z0-9][a-z0-9._-]*$/.test(name) ||
|
|
46
|
-
name.length > 214 ||
|
|
47
|
-
["node_modules", "favicon.ico"].includes(name)
|
|
48
|
-
)
|
|
49
|
-
throw new HostError(
|
|
50
|
-
"App NAME must be an unscoped lowercase npm package name.",
|
|
51
|
-
);
|
|
52
44
|
const { files, cid: templateCid } = await appTemplate(
|
|
53
45
|
options.template ?? "node",
|
|
54
46
|
name,
|
|
55
47
|
options,
|
|
56
48
|
);
|
|
57
|
-
const schemaCid = (await builtinAppSchema()).cid.toString();
|
|
58
49
|
const root = await scaffoldFiles(directory, files, options);
|
|
59
50
|
return {
|
|
60
|
-
kind: "
|
|
51
|
+
kind: "project-init" as const,
|
|
61
52
|
directory: root,
|
|
62
53
|
name,
|
|
63
54
|
template: options.template ?? "node",
|
|
64
55
|
templateCid,
|
|
65
|
-
schemaCid,
|
|
66
56
|
files: [...files.keys()],
|
|
67
57
|
};
|
|
68
58
|
}
|
|
@@ -341,7 +331,7 @@ export async function buildApp(
|
|
|
341
331
|
const description = appDescription({
|
|
342
332
|
...defaults,
|
|
343
333
|
...overrides,
|
|
344
|
-
entry:
|
|
334
|
+
entry: "resources/app.cjs",
|
|
345
335
|
...(supportedSchemas ? { supportedSchemas: supportedSchemasPath } : {}),
|
|
346
336
|
});
|
|
347
337
|
if (description.icon !== undefined) {
|
|
@@ -515,7 +505,19 @@ export async function buildApp(
|
|
|
515
505
|
if (++resourceCount > 4096)
|
|
516
506
|
throw new HostError("App resource file count exceeds 4096.");
|
|
517
507
|
relativePath(path);
|
|
518
|
-
if (
|
|
508
|
+
if (
|
|
509
|
+
path
|
|
510
|
+
.split("/")
|
|
511
|
+
.some(
|
|
512
|
+
(part, index, parts) =>
|
|
513
|
+
part.startsWith(".") &&
|
|
514
|
+
!(
|
|
515
|
+
part === ".bundle.yaml" &&
|
|
516
|
+
index === parts.length - 1 &&
|
|
517
|
+
index > 0
|
|
518
|
+
),
|
|
519
|
+
)
|
|
520
|
+
)
|
|
519
521
|
throw new HostError("Hidden prebuilt resources are not supported.");
|
|
520
522
|
const bytes = await readBytes(inputTree, path, 16 * 1024 * 1024, options);
|
|
521
523
|
const target = join(bundleStage, "resources", ...path.split("/"));
|
package/src/app-definition.ts
CHANGED
|
@@ -14,12 +14,6 @@ export const appSchema = {
|
|
|
14
14
|
entry: {
|
|
15
15
|
path: "app.json",
|
|
16
16
|
contentType: "application/json",
|
|
17
|
-
defaultValue: {
|
|
18
|
-
name: "Untitled App",
|
|
19
|
-
version: "0.0.0",
|
|
20
|
-
description: "",
|
|
21
|
-
entry: "resources/app.cjs",
|
|
22
|
-
},
|
|
23
17
|
schema: {
|
|
24
18
|
$id: "urn:ipab:node-app.v1",
|
|
25
19
|
type: "object",
|
|
@@ -63,7 +57,7 @@ export const appSchema = {
|
|
|
63
57
|
|
|
64
58
|
// This is the canonical full definition, not a separate identity for the alias.
|
|
65
59
|
export const appSchemaCid = CID.parse(
|
|
66
|
-
"
|
|
60
|
+
"bafyreid3qonq3i2rjekgz7mtarpu4zbfmgg4uhtcjtpijdgrrhdke5opzq",
|
|
67
61
|
);
|
|
68
62
|
export const builtinTypes: ReadonlyMap<string, string> = new Map([
|
|
69
63
|
[appBuiltinAlias, appSchemaCid.toString()],
|
package/src/app-templates.ts
CHANGED
|
@@ -23,6 +23,17 @@ export const builtinTemplateNames = new Map([
|
|
|
23
23
|
["builtin:template.web-app", "web-app"],
|
|
24
24
|
] as const);
|
|
25
25
|
|
|
26
|
+
function appName(name: string) {
|
|
27
|
+
if (
|
|
28
|
+
!/^[a-z0-9][a-z0-9._-]*$/.test(name) ||
|
|
29
|
+
name.length > 214 ||
|
|
30
|
+
["node_modules", "favicon.ico"].includes(name)
|
|
31
|
+
)
|
|
32
|
+
throw new HostError(
|
|
33
|
+
"App NAME must be an unscoped lowercase npm package name.",
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
26
37
|
async function legacyTemplate(
|
|
27
38
|
selector: string,
|
|
28
39
|
name: string,
|
|
@@ -317,6 +328,7 @@ export async function appTemplate(
|
|
|
317
328
|
for (const [alias, name] of builtinTemplateNames)
|
|
318
329
|
if (selector === alias) selector = name;
|
|
319
330
|
if (selector === "node" || selector === "web-app") {
|
|
331
|
+
appName(name);
|
|
320
332
|
const loaded = await builtinTemplateSource(selector, options);
|
|
321
333
|
const parameters = [...(options.parameters ?? [])];
|
|
322
334
|
if (
|
|
@@ -360,6 +372,7 @@ export async function appTemplate(
|
|
|
360
372
|
}
|
|
361
373
|
}
|
|
362
374
|
if (legacy) {
|
|
375
|
+
appName(name);
|
|
363
376
|
if (options.parameters?.length)
|
|
364
377
|
throw new HostError(
|
|
365
378
|
"--param requires a Template Bundle, not a legacy mapping.",
|
package/src/authoring.ts
CHANGED
|
@@ -22,7 +22,6 @@ 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,
|
|
@@ -31,7 +30,11 @@ import {
|
|
|
31
30
|
parseBundleManifest,
|
|
32
31
|
ContentBundleError,
|
|
33
32
|
} from "@ipab/bundle";
|
|
34
|
-
import type {
|
|
33
|
+
import type {
|
|
34
|
+
EntryValidation,
|
|
35
|
+
OpenBundleOptions,
|
|
36
|
+
SchemaBlock,
|
|
37
|
+
} from "@ipab/bundle";
|
|
35
38
|
import {
|
|
36
39
|
encodeBundleCar,
|
|
37
40
|
encodeSchemaCar,
|
|
@@ -59,6 +62,7 @@ export interface BuildResult {
|
|
|
59
62
|
schemaCid: string;
|
|
60
63
|
output: string;
|
|
61
64
|
bytes: number;
|
|
65
|
+
validation?: EntryValidation | null;
|
|
62
66
|
}
|
|
63
67
|
export interface InspectResult {
|
|
64
68
|
kind: "content-bundle" | "bundle-schema";
|
|
@@ -68,15 +72,11 @@ export interface InspectResult {
|
|
|
68
72
|
name: string;
|
|
69
73
|
description: string;
|
|
70
74
|
entry: { path: string; contentType: string };
|
|
71
|
-
validation: {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
schemaCid: string;
|
|
77
|
-
name: string;
|
|
78
|
-
entry: { path: string; contentType: string };
|
|
79
|
-
files: string[];
|
|
75
|
+
validation: {
|
|
76
|
+
definition: "valid";
|
|
77
|
+
storage: "verified" | "not-applicable";
|
|
78
|
+
entry: EntryValidation | null;
|
|
79
|
+
};
|
|
80
80
|
}
|
|
81
81
|
export interface ImportResult {
|
|
82
82
|
kind: "bundle-import";
|
|
@@ -85,6 +85,7 @@ export interface ImportResult {
|
|
|
85
85
|
source: string;
|
|
86
86
|
blocks: number;
|
|
87
87
|
bytes: number;
|
|
88
|
+
validation: EntryValidation | null;
|
|
88
89
|
}
|
|
89
90
|
export function nodeError(error: unknown, code: string): boolean {
|
|
90
91
|
return error instanceof Error && "code" in error && error.code === code;
|
|
@@ -299,6 +300,7 @@ async function fromRoot(
|
|
|
299
300
|
});
|
|
300
301
|
return {
|
|
301
302
|
schema: bundle.schema,
|
|
303
|
+
validation: bundle.validation,
|
|
302
304
|
kind: "content-bundle" as const,
|
|
303
305
|
sourceKind,
|
|
304
306
|
cid: root.toString(),
|
|
@@ -334,7 +336,11 @@ export async function inspectBundle(
|
|
|
334
336
|
sourceKind: "directory",
|
|
335
337
|
cid: null,
|
|
336
338
|
...summary(encoded.schema),
|
|
337
|
-
validation: {
|
|
339
|
+
validation: {
|
|
340
|
+
definition: "valid",
|
|
341
|
+
storage: "verified",
|
|
342
|
+
entry: encoded.validation,
|
|
343
|
+
},
|
|
338
344
|
};
|
|
339
345
|
} finally {
|
|
340
346
|
await encoded.close();
|
|
@@ -347,8 +353,9 @@ export async function inspectBundle(
|
|
|
347
353
|
cid: loaded.cid,
|
|
348
354
|
...summary(loaded.schema),
|
|
349
355
|
validation: {
|
|
350
|
-
|
|
356
|
+
definition: "valid",
|
|
351
357
|
storage: loaded.kind === "content-bundle" ? "verified" : "not-applicable",
|
|
358
|
+
entry: loaded.kind === "content-bundle" ? loaded.validation : null,
|
|
352
359
|
},
|
|
353
360
|
};
|
|
354
361
|
}
|
|
@@ -378,6 +385,7 @@ export async function importBundle(
|
|
|
378
385
|
cid,
|
|
379
386
|
schemaCid: loaded.schema.cid.toString(),
|
|
380
387
|
source: path,
|
|
388
|
+
validation: loaded.kind === "content-bundle" ? loaded.validation : null,
|
|
381
389
|
blocks: car.blocks.size,
|
|
382
390
|
bytes: car.bytes,
|
|
383
391
|
};
|
|
@@ -490,54 +498,13 @@ export async function buildBundle(
|
|
|
490
498
|
cid: encoded.cid.toString(),
|
|
491
499
|
schemaCid: encoded.schema.cid.toString(),
|
|
492
500
|
output,
|
|
501
|
+
validation: encoded.validation,
|
|
493
502
|
};
|
|
494
503
|
return {
|
|
495
504
|
...result,
|
|
496
505
|
bytes: await writeCar(encoded, output, Boolean(options.replace), options),
|
|
497
506
|
};
|
|
498
507
|
}
|
|
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
508
|
export async function scaffoldFiles(
|
|
542
509
|
directory: string,
|
|
543
510
|
files: ReadonlyMap<string, string | Uint8Array>,
|
package/src/builtins.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { builtinAppSchema } from "./app-definition.js";
|
|
2
2
|
import {
|
|
3
3
|
builtinTemplateSchema,
|
|
4
|
-
templateBuiltinAlias,
|
|
5
4
|
templateSchema,
|
|
6
5
|
templateSchemaCid,
|
|
7
6
|
} from "./template-definition.js";
|
|
@@ -25,17 +24,12 @@ async function loadBuiltins(): Promise<{
|
|
|
25
24
|
builtin: true,
|
|
26
25
|
});
|
|
27
26
|
};
|
|
28
|
-
for (const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
]
|
|
27
|
+
for (const schema of [
|
|
28
|
+
await builtinAppSchema(),
|
|
29
|
+
await builtinTemplateSchema(),
|
|
30
|
+
]) {
|
|
32
31
|
const cid = schema.cid.toString();
|
|
33
32
|
blocks.set(cid, schema.bytes);
|
|
34
|
-
add(name, cid, {
|
|
35
|
-
kind: "schema",
|
|
36
|
-
typeName: schema.manifest.name,
|
|
37
|
-
schemaCid: cid,
|
|
38
|
-
});
|
|
39
33
|
}
|
|
40
34
|
for (const [name, selector] of builtinTemplateNames) {
|
|
41
35
|
const template = await builtinTemplateSource(selector);
|