@acryldev/manifest 0.0.0-stage → 0.1.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.
@@ -0,0 +1,61 @@
1
+ import { existsSync, readFileSync, readdirSync } from "node:fs";
2
+ import { basename, join } from "node:path";
3
+ import { pathToFileURL } from "node:url";
4
+ //#region app-plugins.ts
5
+ /**
6
+ * The app's own plugins: the folders of `plugins/` that are not library copies (`plugins/library.json` lists those). A feature is one of them, and
7
+ * `blend.yaml` mounts it with a row of its own (`- id: notes` / `name: notes`), with no import in `src/app.ts`: a row whose name the static registry
8
+ * does not have resolves to the folder of that name here. So `blend.yaml` plus `plugins/` is the whole composition, and a version, a shared app or a
9
+ * blueprint made from the folder starts the same plugins.
10
+ */
11
+ /** The file a plugin folder starts from, in the order they are looked for. */
12
+ const PLUGIN_ENTRIES = [
13
+ "index.ts",
14
+ "index.js",
15
+ "index.mjs"
16
+ ];
17
+ /** A plugin's name: its folder's name and its Loader row id. */
18
+ const NAME = /^[a-z0-9][a-z0-9-]*$/;
19
+ /** The library copies a plugins folder holds (`library.json`, written by `acrylblends add`); absent or unreadable means none. */
20
+ function libraryCopies(dir) {
21
+ try {
22
+ const listed = JSON.parse(readFileSync(join(dir, "library.json"), "utf8")).plugins;
23
+ return new Set(Array.isArray(listed) ? listed.filter((name) => typeof name === "string") : []);
24
+ } catch {
25
+ return /* @__PURE__ */ new Set();
26
+ }
27
+ }
28
+ /** The entry file of a plugin folder, or undefined when it has none. */
29
+ function pluginEntry(dir) {
30
+ return PLUGIN_ENTRIES.map((file) => join(dir, file)).find((path) => existsSync(path));
31
+ }
32
+ /** The names of the app's own plugins in `dir` (the app's `plugins/`): folders with an entry file that are not library copies, sorted. */
33
+ function appPluginNames(dir) {
34
+ if (!existsSync(dir)) return [];
35
+ const library = libraryCopies(dir);
36
+ return readdirSync(dir, { withFileTypes: true }).filter((entry) => entry.isDirectory() && NAME.test(entry.name) && !library.has(entry.name) && pluginEntry(join(dir, entry.name)) !== void 0).map((entry) => entry.name).sort();
37
+ }
38
+ /**
39
+ * Import the app's own plugins `names` from `dir`, each checked to be a Cordis plugin whose `name` is its folder's.
40
+ * @throws an error that names the folder and the fix, for a folder that does not export a plugin.
41
+ */
42
+ async function loadAppPlugins(dir, names) {
43
+ const loaded = {};
44
+ for (const name of names) {
45
+ const entry = pluginEntry(join(dir, name));
46
+ if (entry === void 0) throw new Error(`plugins/${name} has no ${PLUGIN_ENTRIES.join(", ")}`);
47
+ const module = await import(pathToFileURL(entry).href);
48
+ const plugin = typeof module.apply === "function" ? module : module.default;
49
+ if (plugin === void 0 || typeof plugin.apply !== "function") throw new Error(`plugins/${name}/${basename(entry)} must export a Cordis plugin: export const name = '${name}' and export function apply(ctx) { ... }`);
50
+ if (plugin.name !== void 0 && plugin.name !== name) throw new Error(`plugins/${name} exports the plugin name "${String(plugin.name)}"; a plugin's name is its folder's, "${name}"`);
51
+ loaded[name] = {
52
+ ...plugin,
53
+ name
54
+ };
55
+ }
56
+ return loaded;
57
+ }
58
+ //#endregion
59
+ export { PLUGIN_ENTRIES, appPluginNames, libraryCopies, loadAppPlugins, pluginEntry };
60
+
61
+ //# sourceMappingURL=app-plugins.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-plugins.js","names":[],"sources":["../app-plugins.ts"],"sourcesContent":["/**\n * The app's own plugins: the folders of `plugins/` that are not library copies (`plugins/library.json` lists those). A feature is one of them, and\n * `blend.yaml` mounts it with a row of its own (`- id: notes` / `name: notes`), with no import in `src/app.ts`: a row whose name the static registry\n * does not have resolves to the folder of that name here. So `blend.yaml` plus `plugins/` is the whole composition, and a version, a shared app or a\n * blueprint made from the folder starts the same plugins.\n */\nimport { existsSync, readdirSync, readFileSync } from 'node:fs'\nimport { basename, join } from 'node:path'\nimport { pathToFileURL } from 'node:url'\n\n/** The file a plugin folder starts from, in the order they are looked for. */\nexport const PLUGIN_ENTRIES = ['index.ts', 'index.js', 'index.mjs'] as const\n/** A plugin's name: its folder's name and its Loader row id. */\nconst NAME = /^[a-z0-9][a-z0-9-]*$/\n\n/** The library copies a plugins folder holds (`library.json`, written by `acrylblends add`); absent or unreadable means none. */\nexport function libraryCopies(dir: string): ReadonlySet<string> {\n try {\n const listed = (\n JSON.parse(readFileSync(join(dir, 'library.json'), 'utf8')) as { plugins?: unknown }\n ).plugins\n return new Set(\n Array.isArray(listed)\n ? listed.filter((name): name is string => typeof name === 'string')\n : [],\n )\n } catch {\n return new Set()\n }\n}\n\n/** The entry file of a plugin folder, or undefined when it has none. */\nexport function pluginEntry(dir: string): string | undefined {\n return PLUGIN_ENTRIES.map((file) => join(dir, file)).find((path) => existsSync(path))\n}\n\n/** The names of the app's own plugins in `dir` (the app's `plugins/`): folders with an entry file that are not library copies, sorted. */\nexport function appPluginNames(dir: string): string[] {\n if (!existsSync(dir)) return []\n const library = libraryCopies(dir)\n return readdirSync(dir, { withFileTypes: true })\n .filter(\n (entry) =>\n entry.isDirectory() &&\n NAME.test(entry.name) &&\n !library.has(entry.name) &&\n pluginEntry(join(dir, entry.name)) !== undefined,\n )\n .map((entry) => entry.name)\n .sort()\n}\n\n/** A plugin module as a row mounts it. */\nexport interface AppPluginModule {\n readonly name: string\n readonly apply: (...args: never[]) => unknown\n}\n\n/**\n * Import the app's own plugins `names` from `dir`, each checked to be a Cordis plugin whose `name` is its folder's.\n * @throws an error that names the folder and the fix, for a folder that does not export a plugin.\n */\nexport async function loadAppPlugins(\n dir: string,\n names: readonly string[],\n): Promise<Record<string, AppPluginModule>> {\n const loaded: Record<string, AppPluginModule> = {}\n for (const name of names) {\n const entry = pluginEntry(join(dir, name))\n if (entry === undefined) throw new Error(`plugins/${name} has no ${PLUGIN_ENTRIES.join(', ')}`)\n const module = (await import(pathToFileURL(entry).href)) as Partial<AppPluginModule> & {\n default?: Partial<AppPluginModule>\n }\n const plugin = typeof module.apply === 'function' ? module : module.default\n if (plugin === undefined || typeof plugin.apply !== 'function')\n throw new Error(\n `plugins/${name}/${basename(entry)} must export a Cordis plugin: export const name = '${name}' and export function apply(ctx) { ... }`,\n )\n if (plugin.name !== undefined && plugin.name !== name)\n throw new Error(\n `plugins/${name} exports the plugin name \"${String(plugin.name)}\"; a plugin's name is its folder's, \"${name}\"`,\n )\n loaded[name] = { ...plugin, name } as AppPluginModule\n }\n return loaded\n}\n"],"mappings":";;;;;;;;;;;AAWA,MAAa,iBAAiB;CAAC;CAAY;CAAY;AAAW;;AAElE,MAAM,OAAO;;AAGb,SAAgB,cAAc,KAAkC;CAC9D,IAAI;EACF,MAAM,SACJ,KAAK,MAAM,aAAa,KAAK,KAAK,cAAc,GAAG,MAAM,CAAC,CAAC,CAC3D;EACF,OAAO,IAAI,IACT,MAAM,QAAQ,MAAM,IAChB,OAAO,QAAQ,SAAyB,OAAO,SAAS,QAAQ,IAChE,CAAC,CACP;CACF,QAAQ;EACN,uBAAO,IAAI,IAAI;CACjB;AACF;;AAGA,SAAgB,YAAY,KAAiC;CAC3D,OAAO,eAAe,KAAK,SAAS,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,SAAS,WAAW,IAAI,CAAC;AACtF;;AAGA,SAAgB,eAAe,KAAuB;CACpD,IAAI,CAAC,WAAW,GAAG,GAAG,OAAO,CAAC;CAC9B,MAAM,UAAU,cAAc,GAAG;CACjC,OAAO,YAAY,KAAK,EAAE,eAAe,KAAK,CAAC,CAAC,CAC7C,QACE,UACC,MAAM,YAAY,KAClB,KAAK,KAAK,MAAM,IAAI,KACpB,CAAC,QAAQ,IAAI,MAAM,IAAI,KACvB,YAAY,KAAK,KAAK,MAAM,IAAI,CAAC,MAAM,KAAA,CAC3C,CAAC,CACA,KAAK,UAAU,MAAM,IAAI,CAAC,CAC1B,KAAK;AACV;;;;;AAYA,eAAsB,eACpB,KACA,OAC0C;CAC1C,MAAM,SAA0C,CAAC;CACjD,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,QAAQ,YAAY,KAAK,KAAK,IAAI,CAAC;EACzC,IAAI,UAAU,KAAA,GAAW,MAAM,IAAI,MAAM,WAAW,KAAK,UAAU,eAAe,KAAK,IAAI,GAAG;EAC9F,MAAM,SAAU,MAAM,OAAO,cAAc,KAAK,CAAC,CAAC;EAGlD,MAAM,SAAS,OAAO,OAAO,UAAU,aAAa,SAAS,OAAO;EACpE,IAAI,WAAW,KAAA,KAAa,OAAO,OAAO,UAAU,YAClD,MAAM,IAAI,MACR,WAAW,KAAK,GAAG,SAAS,KAAK,EAAE,qDAAqD,KAAK,yCAC/F;EACF,IAAI,OAAO,SAAS,KAAA,KAAa,OAAO,SAAS,MAC/C,MAAM,IAAI,MACR,WAAW,KAAK,4BAA4B,OAAO,OAAO,IAAI,EAAE,uCAAuC,KAAK,EAC9G;EACF,OAAO,QAAQ;GAAE,GAAG;GAAQ;EAAK;CACnC;CACA,OAAO;AACT"}
package/lib/index.js ADDED
@@ -0,0 +1,408 @@
1
+ import { PLUGIN_ENTRIES, appPluginNames, libraryCopies, loadAppPlugins, pluginEntry } from "./app-plugins.js";
2
+ import { createHash } from "node:crypto";
3
+ import { existsSync, readFileSync } from "node:fs";
4
+ import { join } from "node:path";
5
+ import { parse } from "yaml";
6
+ //#region index.ts
7
+ /**
8
+ * The app manifest (`blend.yaml`): the app as data, in ACRYL's own Blend format (`blends.acryl.dev/v1alpha1`).
9
+ *
10
+ * Extracted from ACRYL Blends (`runtime/blends-core`). A manifest this plugin accepts is a valid ACRYL `blend.yaml`: a test checks
11
+ * the templates' manifests against ACRYL's JSON schema, so an app can move into ACRYL without conversion.
12
+ *
13
+ * - A **Blueprint** is a definition with ordered `spec.rows` (`id` is the slot, `name` the plugin it loads, optional `config` and
14
+ * `disabled`) and typed `spec.parameters` substituted into config as `{{parameters.name}}`.
15
+ * - A **Blend** is an instance of a Blueprint: it declares `spec.lineage` (which Blueprint, which version), and resolves over that
16
+ * parent. Its `spec.overrides` change inherited rows by id (a shallow merge: keys it sets win), and its own `spec.rows` are added
17
+ * after them. `spec.extends` names the parent explicitly (it must agree with the lineage). A parent resolves with its own defaults.
18
+ * - `planUpgrade` (upgrade.ts) answers the question ACRYL leaves open: when the Blueprint moves to a new version, what changed, and
19
+ * which of this Blend's overrides and rows it breaks.
20
+ *
21
+ * Problems are diagnostics with a code and a path, never a bare "invalid". The code an app can use stays in `src/app.ts` as a static
22
+ * registry of imports (so it type-checks); the manifest chooses, orders, configures and switches those plugins. A row may also name one of the
23
+ * app's own plugin folders (`plugins/<name>/`, app-plugins.ts): that is how a feature is mounted. Extensions are not listed here: they come and go
24
+ * while the app runs.
25
+ */
26
+ const API_VERSION = "blends.acryl.dev/v1alpha1";
27
+ /** The file name ACRYL uses for an app definition. */
28
+ const MANIFEST_FILE = "blend.yaml";
29
+ var ManifestError = class extends Error {
30
+ name = "ManifestError";
31
+ diagnostics;
32
+ constructor(source, diagnostics) {
33
+ super(`${source} is not a valid app manifest:\n${diagnostics.map((d) => ` ${d.path}: ${d.message} [${d.code}]`).join("\n")}`);
34
+ this.diagnostics = diagnostics;
35
+ }
36
+ };
37
+ const DEFINITION_ID = /^[a-z0-9]+(\.[a-z0-9-]+)+$/;
38
+ const ROW_ID = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
39
+ const SEMVER = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
40
+ const PARAMETER = /^[A-Za-z][A-Za-z0-9_-]*$/;
41
+ const TOKEN = /\{\{parameters\.([A-Za-z0-9_-]+)\}\}/g;
42
+ const WHOLE_TOKEN = /^\{\{parameters\.([A-Za-z0-9_-]+)\}\}$/;
43
+ const TOP_FIELDS = /* @__PURE__ */ new Set([
44
+ "apiVersion",
45
+ "kind",
46
+ "metadata",
47
+ "spec"
48
+ ]);
49
+ const METADATA_FIELDS = /* @__PURE__ */ new Set([
50
+ "id",
51
+ "name",
52
+ "version",
53
+ "category",
54
+ "description",
55
+ "license",
56
+ "visibility"
57
+ ]);
58
+ const SPEC_FIELDS = /* @__PURE__ */ new Set([
59
+ "runtime",
60
+ "extends",
61
+ "lineage",
62
+ "parameters",
63
+ "rows",
64
+ "overrides"
65
+ ]);
66
+ const ROW_FIELDS = /* @__PURE__ */ new Set([
67
+ "id",
68
+ "name",
69
+ "config",
70
+ "disabled"
71
+ ]);
72
+ const OVERRIDE_FIELDS = /* @__PURE__ */ new Set([
73
+ "id",
74
+ "name",
75
+ "config",
76
+ "disabled"
77
+ ]);
78
+ const LINEAGE_FIELDS = /* @__PURE__ */ new Set(["blueprint", "blueprintVersion"]);
79
+ const PARAMETER_FIELDS = /* @__PURE__ */ new Set(["type", "default"]);
80
+ const TYPES = /* @__PURE__ */ new Set([
81
+ "string",
82
+ "number",
83
+ "boolean"
84
+ ]);
85
+ const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
86
+ /** Every string inside a config value, with its path. Tokens are recognised in string values only. */
87
+ function walkStrings(value, path, visit) {
88
+ if (typeof value === "string") visit(value, path);
89
+ else if (Array.isArray(value)) for (const [index, item] of value.entries()) walkStrings(item, `${path}[${index}]`, visit);
90
+ else if (isObject(value)) for (const [key, item] of Object.entries(value)) walkStrings(item, `${path}.${key}`, visit);
91
+ }
92
+ /** The id of the definition a document resolves over: `extends`, else a Blend's lineage Blueprint. */
93
+ function parentIdOf(document) {
94
+ if (document.spec.extends !== void 0) return document.spec.extends;
95
+ return document.kind === "Blend" ? document.spec.lineage?.blueprint : void 0;
96
+ }
97
+ /**
98
+ * Validate one parsed document on its own (its parent is not read here; see `loadManifest`). An empty list means valid. `known` is
99
+ * the registry's names, so an unknown row `name` is reported here, before anything is mounted.
100
+ */
101
+ function validate(document, known) {
102
+ const problems = [];
103
+ const add = (code, path, message) => problems.push({
104
+ code,
105
+ path,
106
+ message
107
+ });
108
+ if (!isObject(document)) return [{
109
+ code: "schema-error",
110
+ path: "$",
111
+ message: "the manifest must be a map"
112
+ }];
113
+ for (const key of Object.keys(document)) if (!TOP_FIELDS.has(key)) add("schema-error", key, `unknown field '${key}'`);
114
+ if (document.apiVersion !== "blends.acryl.dev/v1alpha1") add("schema-error", "apiVersion", `must be '${API_VERSION}'`);
115
+ if (document.kind !== "Blueprint" && document.kind !== "Blend") add("schema-error", "kind", "must be 'Blueprint' or 'Blend'");
116
+ const metadata = document.metadata;
117
+ if (!isObject(metadata)) add("schema-error", "metadata", "missing required field metadata (id, name, version)");
118
+ else {
119
+ for (const key of Object.keys(metadata)) if (!METADATA_FIELDS.has(key)) add("schema-error", `metadata.${key}`, `unknown field '${key}'`);
120
+ if (typeof metadata.id !== "string" || !DEFINITION_ID.test(metadata.id)) add("schema-error", "metadata.id", "must be a dotted id such as 'acrylblends.my-app'");
121
+ if (typeof metadata.name !== "string" || metadata.name === "") add("schema-error", "metadata.name", "missing required field name");
122
+ if (typeof metadata.version !== "string" || !SEMVER.test(metadata.version)) add("schema-error", "metadata.version", "must be a semantic version such as 0.1.0");
123
+ if (metadata.visibility !== void 0 && metadata.visibility !== "private" && metadata.visibility !== "public") add("schema-error", "metadata.visibility", "must be 'private' or 'public'");
124
+ }
125
+ const spec = document.spec;
126
+ const declared = /* @__PURE__ */ new Map();
127
+ const used = /* @__PURE__ */ new Set();
128
+ const registry = known ? new Set(known) : void 0;
129
+ const ids = /* @__PURE__ */ new Set();
130
+ if (!isObject(spec)) {
131
+ add("schema-error", "spec", "missing required field spec (runtime)");
132
+ return problems;
133
+ }
134
+ for (const key of Object.keys(spec)) if (!SPEC_FIELDS.has(key)) add("schema-error", `spec.${key}`, `unknown field '${key}'`);
135
+ if (spec.runtime !== "cordis") add("schema-error", "spec.runtime", "must be 'cordis'");
136
+ const lineage = spec.lineage;
137
+ if (lineage !== void 0) if (!isObject(lineage)) add("schema-error", "spec.lineage", "must be { blueprint, blueprintVersion }");
138
+ else {
139
+ for (const key of Object.keys(lineage)) if (!LINEAGE_FIELDS.has(key)) add("schema-error", `spec.lineage.${key}`, `unknown field '${key}'`);
140
+ if (typeof lineage.blueprint !== "string" || !DEFINITION_ID.test(lineage.blueprint)) add("schema-error", "spec.lineage.blueprint", "must be a dotted Blueprint id");
141
+ if (typeof lineage.blueprintVersion !== "string" || !SEMVER.test(lineage.blueprintVersion)) add("schema-error", "spec.lineage.blueprintVersion", "must be a semantic version");
142
+ }
143
+ if (spec.extends !== void 0 && (typeof spec.extends !== "string" || !DEFINITION_ID.test(spec.extends))) add("schema-error", "spec.extends", "must be a dotted definition id");
144
+ if (document.kind === "Blend" && lineage === void 0) add("blend-without-lineage", "spec.lineage", "a Blend must declare spec.lineage (its Blueprint and version)");
145
+ if (document.kind === "Blueprint" && lineage !== void 0) add("blueprint-with-lineage", "spec.lineage", "a Blueprint must not declare spec.lineage; lineage belongs to Blends");
146
+ if (isObject(lineage) && spec.extends !== void 0 && spec.extends !== lineage.blueprint) add("lineage-extends-mismatch", "spec.extends", `extends '${String(spec.extends)}' must agree with lineage.blueprint '${String(lineage.blueprint)}'`);
147
+ const parameters = spec.parameters ?? {};
148
+ if (!isObject(parameters)) add("schema-error", "spec.parameters", "must be a map of name to { type, default }");
149
+ else for (const [name, declaration] of Object.entries(parameters)) {
150
+ const path = `spec.parameters.${name}`;
151
+ if (!PARAMETER.test(name)) add("schema-error", path, "a parameter name is letters, digits, _ and -");
152
+ if (!isObject(declaration) || !TYPES.has(declaration.type)) {
153
+ add("schema-error", `${path}.type`, "must be 'string', 'number' or 'boolean'");
154
+ continue;
155
+ }
156
+ for (const key of Object.keys(declaration)) if (!PARAMETER_FIELDS.has(key)) add("schema-error", `${path}.${key}`, `unknown field '${key}'`);
157
+ if (typeof declaration.default !== declaration.type) add("parameter-type-mismatch", `${path}.default`, `must be a ${declaration.type}`);
158
+ declared.set(name, declaration.type);
159
+ }
160
+ const checkTokens = (config, path) => {
161
+ walkStrings(config, path, (text, at) => {
162
+ for (const [, name] of text.matchAll(TOKEN)) {
163
+ used.add(name);
164
+ if (!declared.has(name)) add("dangling-parameter-reference", at, `refers to undeclared parameter '${name}'`);
165
+ }
166
+ });
167
+ };
168
+ const checkFlags = (entry, path, fields) => {
169
+ for (const key of Object.keys(entry)) if (!fields.has(key)) add("schema-error", `${path}.${key}`, `unknown field '${key}'`);
170
+ if (entry.disabled !== void 0 && typeof entry.disabled !== "boolean") add("schema-error", `${path}.disabled`, "must be true or false");
171
+ if (entry.config !== void 0 && !isObject(entry.config)) add("schema-error", `${path}.config`, "must be a map");
172
+ if (isObject(entry.config)) checkTokens(entry.config, `${path}.config`);
173
+ };
174
+ const checkName = (name, path) => {
175
+ if (registry && typeof name === "string" && !registry.has(name)) add("unknown-plugin", path, `no plugin '${name}' in the app's registry (known: ${[...registry].join(", ")})`);
176
+ };
177
+ const rows = spec.rows ?? [];
178
+ if (!Array.isArray(rows)) add("schema-error", "spec.rows", "must be a list of rows");
179
+ else for (const [index, row] of rows.entries()) {
180
+ const path = `spec.rows[${index}]`;
181
+ if (!isObject(row)) {
182
+ add("schema-error", path, "a row must be a map with an id and a name");
183
+ continue;
184
+ }
185
+ if (typeof row.id !== "string" || !ROW_ID.test(row.id)) {
186
+ add("schema-error", `${path}.id`, "must be lowercase letters, digits and dashes");
187
+ continue;
188
+ }
189
+ if (ids.has(row.id)) add("duplicate-row-id", `${path}.id`, `the id '${row.id}' is used twice`);
190
+ ids.add(row.id);
191
+ if (typeof row.name !== "string" || row.name === "") add("schema-error", `${path}.name`, "missing required field name (the plugin this row loads)");
192
+ else checkName(row.name, `${path}.name`);
193
+ checkFlags(row, path, ROW_FIELDS);
194
+ }
195
+ const overrides = spec.overrides ?? [];
196
+ if (!Array.isArray(overrides)) add("schema-error", "spec.overrides", "must be a list of overrides");
197
+ else {
198
+ const seen = /* @__PURE__ */ new Set();
199
+ for (const [index, entry] of overrides.entries()) {
200
+ const path = `spec.overrides[${index}]`;
201
+ if (!isObject(entry)) {
202
+ add("schema-error", path, "an override must be a map with an id");
203
+ continue;
204
+ }
205
+ if (typeof entry.id !== "string" || entry.id === "") {
206
+ add("schema-error", `${path}.id`, "missing required field id (the inherited row it changes)");
207
+ continue;
208
+ }
209
+ if (seen.has(entry.id)) add("duplicate-row-id", `${path}.id`, `the override id '${entry.id}' is used twice`);
210
+ seen.add(entry.id);
211
+ if (entry.name !== void 0) if (typeof entry.name !== "string" || entry.name === "") add("schema-error", `${path}.name`, "must be a plugin name");
212
+ else checkName(entry.name, `${path}.name`);
213
+ checkFlags(entry, path, OVERRIDE_FIELDS);
214
+ }
215
+ if (overrides.length > 0 && parentIdOf(document) === void 0) add("overrides-without-parent", "spec.overrides", "overrides need a parent: declare spec.extends, or make this a Blend with a lineage");
216
+ }
217
+ for (const name of declared.keys()) if (!used.has(name)) add("unused-parameter", `spec.parameters.${name}`, `'${name}' is declared but not used`);
218
+ return problems;
219
+ }
220
+ function substitute(value, values) {
221
+ if (typeof value === "string") {
222
+ const whole = WHOLE_TOKEN.exec(value);
223
+ if (whole) return values[whole[1]] ?? value;
224
+ return value.replace(TOKEN, (token, name) => name in values ? String(values[name]) : token);
225
+ }
226
+ if (Array.isArray(value)) return value.map((item) => substitute(item, values));
227
+ if (isObject(value)) return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, substitute(item, values)]));
228
+ return value;
229
+ }
230
+ function parseFile(file) {
231
+ if (!existsSync(file)) return [{
232
+ code: "parse-error",
233
+ path: "$",
234
+ message: `${file} does not exist`
235
+ }];
236
+ const text = readFileSync(file, "utf8");
237
+ try {
238
+ return {
239
+ text,
240
+ document: parse(text)
241
+ };
242
+ } catch (error) {
243
+ return [{
244
+ code: "parse-error",
245
+ path: "$",
246
+ message: error instanceof Error ? error.message : String(error)
247
+ }];
248
+ }
249
+ }
250
+ function collectValues(declarations, given, diagnostics) {
251
+ const values = {};
252
+ for (const [name, declaration] of Object.entries(declarations)) values[name] = declaration.default;
253
+ for (const [name, value] of Object.entries(given ?? {})) {
254
+ const declared = declarations[name];
255
+ if (!declared) diagnostics.push({
256
+ code: "parameter-override-unknown",
257
+ path: `spec.parameters.${name}`,
258
+ message: `no parameter '${name}' to set`
259
+ });
260
+ else if (typeof value !== declared.type) diagnostics.push({
261
+ code: "parameter-type-mismatch",
262
+ path: `spec.parameters.${name}`,
263
+ message: `must be a ${declared.type}`
264
+ });
265
+ else values[name] = value;
266
+ }
267
+ return values;
268
+ }
269
+ const substituted = (config, values) => config === void 0 ? {} : { config: substitute(config, values) };
270
+ /** A shallow per-key merge: keys the override sets win, keys it omits are inherited. The parent's row is never changed. */
271
+ function merged(row, entry, values) {
272
+ const config = entry.config === void 0 ? row.config : {
273
+ ...row.config,
274
+ ...substitute(entry.config, values)
275
+ };
276
+ const disabled = entry.disabled ?? row.disabled;
277
+ return {
278
+ id: row.id,
279
+ use: entry.name ?? row.use,
280
+ ...config === void 0 ? {} : { config },
281
+ ...disabled === void 0 ? {} : { disabled }
282
+ };
283
+ }
284
+ /**
285
+ * Resolve one document over its parent chain. Every problem is a diagnostic; nothing throws for invalid input. Rules (ACRYL's): the
286
+ * parent is `extends`, else a Blend's lineage Blueprint; a parent resolves with its own defaults; an override must name a row the
287
+ * resolved parent has; an own row must not reuse a parent row's id; a cycle or a missing parent is reported.
288
+ */
289
+ function resolveRows(document, options, chain, diagnostics, where = "") {
290
+ const at = (path) => `${where}${path}`;
291
+ const values = collectValues(document.spec.parameters ?? {}, options.values, diagnostics);
292
+ let inherited = [];
293
+ let parentResolved = parentIdOf(document) === void 0;
294
+ const parentId = parentIdOf(document);
295
+ const parentPath = document.spec.extends !== void 0 ? "spec.extends" : "spec.lineage.blueprint";
296
+ if (parentId !== void 0) if (chain.includes(parentId)) diagnostics.push({
297
+ code: "parent-cycle",
298
+ path: at(parentPath),
299
+ message: `parent '${parentId}' closes a cycle in the resolution chain`
300
+ });
301
+ else {
302
+ const file = options.getBlueprint?.(parentId);
303
+ const read = file === void 0 ? void 0 : parseFile(file);
304
+ if (read === void 0 || Array.isArray(read)) diagnostics.push({
305
+ code: "parent-not-supplied",
306
+ path: at(parentPath),
307
+ message: read === void 0 ? `parent '${parentId}' is not supplied (getBlueprint returned nothing)` : `parent '${parentId}': ${read[0]?.message}`
308
+ });
309
+ else {
310
+ const problems = validate(read.document);
311
+ if (problems.length > 0) for (const problem of problems) diagnostics.push({
312
+ ...problem,
313
+ path: `parent '${parentId}': ${problem.path}`
314
+ });
315
+ else {
316
+ inherited = resolveRows(read.document, options.getBlueprint ? { getBlueprint: options.getBlueprint } : {}, [...chain, parentId], diagnostics, `parent '${parentId}': `).rows;
317
+ parentResolved = !diagnostics.some((d) => d.path.startsWith(`parent '${parentId}'`));
318
+ }
319
+ }
320
+ }
321
+ const own = (document.spec.rows ?? []).map((row) => ({
322
+ id: row.id,
323
+ use: row.name,
324
+ ...substituted(row.config, values),
325
+ ...row.disabled === void 0 ? {} : { disabled: row.disabled }
326
+ }));
327
+ const parentIds = new Set(inherited.map((row) => row.id));
328
+ if (parentId !== void 0 && parentResolved) {
329
+ for (const [index, entry] of (document.spec.overrides ?? []).entries()) if (!parentIds.has(entry.id)) diagnostics.push({
330
+ code: "override-unknown-id",
331
+ path: at(`spec.overrides[${index}].id`),
332
+ message: `override targets row id '${entry.id}', which the resolved parent does not have`
333
+ });
334
+ for (const [index, row] of own.entries()) if (parentIds.has(row.id)) diagnostics.push({
335
+ code: "insert-id-collision",
336
+ path: at(`spec.rows[${index}].id`),
337
+ message: `row id '${row.id}' already exists in the resolved parent`
338
+ });
339
+ }
340
+ const overrideById = new Map((document.spec.overrides ?? []).map((entry) => [entry.id, entry]));
341
+ return {
342
+ rows: [...inherited.map((row) => overrideById.has(row.id) ? merged(row, overrideById.get(row.id), values) : row), ...own],
343
+ values
344
+ };
345
+ }
346
+ /**
347
+ * Read, validate and resolve a manifest. A Blend resolves over its Blueprint (`getBlueprint`). Throws a `ManifestError` with every
348
+ * diagnostic when anything is invalid.
349
+ */
350
+ function loadManifest(file, options = {}) {
351
+ const read = parseFile(file);
352
+ if (Array.isArray(read)) throw new ManifestError(file, read);
353
+ const diagnostics = validate(read.document, options.known);
354
+ if (diagnostics.some((d) => d.code === "schema-error" || d.code === "parse-error")) throw new ManifestError(file, diagnostics);
355
+ const raw = read.document;
356
+ const { rows, values } = resolveRows(raw, options, [raw.metadata.id], diagnostics);
357
+ if (options.known) {
358
+ const registry = new Set(options.known);
359
+ const own = new Set((raw.spec.rows ?? []).map((row) => row.id));
360
+ for (const row of rows) if (!own.has(row.id) && !registry.has(row.use)) diagnostics.push({
361
+ code: "unknown-plugin",
362
+ path: `resolved row '${row.id}'`,
363
+ message: `no plugin '${row.use}' in the app's registry (known: ${[...registry].join(", ")})`
364
+ });
365
+ }
366
+ if (diagnostics.length > 0) throw new ManifestError(file, diagnostics);
367
+ return {
368
+ ...raw,
369
+ plugins: rows,
370
+ values,
371
+ digest: createHash("sha256").update(read.text).digest("hex")
372
+ };
373
+ }
374
+ /**
375
+ * Mount the manifest's enabled rows in order, each with its config merged under `overrides[id]` (runtime values such as the port win),
376
+ * awaiting each one, because a fiber still waiting on an injected service reports done too early. Returns the fibers, in order.
377
+ */
378
+ async function compose(root, manifest, registry, overrides = {}) {
379
+ const fibers = [];
380
+ for (const row of manifest.plugins) {
381
+ if (row.disabled) continue;
382
+ const plugin = registry[row.use];
383
+ if (!plugin) throw new ManifestError("the manifest", [{
384
+ code: "unknown-plugin",
385
+ path: row.id,
386
+ message: `no plugin '${row.use}' in the registry`
387
+ }]);
388
+ const config = {
389
+ ...row.config ?? {},
390
+ ...overrides[row.id] ?? {}
391
+ };
392
+ const fiber = root.plugin(plugin, config);
393
+ fibers.push(fiber);
394
+ await fiber.await();
395
+ }
396
+ return fibers;
397
+ }
398
+ /** The usual place for Blueprints: a folder with one `<definition id>.yaml` per Blueprint (for example `blueprints/acme.shop.yaml`). */
399
+ function blueprintsIn(directory) {
400
+ return (id) => {
401
+ const file = join(directory, `${id}.yaml`);
402
+ return DEFINITION_ID.test(id) && existsSync(file) ? file : void 0;
403
+ };
404
+ }
405
+ //#endregion
406
+ export { API_VERSION, DEFINITION_ID, MANIFEST_FILE, ManifestError, PLUGIN_ENTRIES, SEMVER, appPluginNames, blueprintsIn, compose, libraryCopies, loadAppPlugins, loadManifest, parentIdOf, pluginEntry, resolveRows, validate };
407
+
408
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../index.ts"],"sourcesContent":["/**\n * The app manifest (`blend.yaml`): the app as data, in ACRYL's own Blend format (`blends.acryl.dev/v1alpha1`).\n *\n * Extracted from ACRYL Blends (`runtime/blends-core`). A manifest this plugin accepts is a valid ACRYL `blend.yaml`: a test checks\n * the templates' manifests against ACRYL's JSON schema, so an app can move into ACRYL without conversion.\n *\n * - A **Blueprint** is a definition with ordered `spec.rows` (`id` is the slot, `name` the plugin it loads, optional `config` and\n * `disabled`) and typed `spec.parameters` substituted into config as `{{parameters.name}}`.\n * - A **Blend** is an instance of a Blueprint: it declares `spec.lineage` (which Blueprint, which version), and resolves over that\n * parent. Its `spec.overrides` change inherited rows by id (a shallow merge: keys it sets win), and its own `spec.rows` are added\n * after them. `spec.extends` names the parent explicitly (it must agree with the lineage). A parent resolves with its own defaults.\n * - `planUpgrade` (upgrade.ts) answers the question ACRYL leaves open: when the Blueprint moves to a new version, what changed, and\n * which of this Blend's overrides and rows it breaks.\n *\n * Problems are diagnostics with a code and a path, never a bare \"invalid\". The code an app can use stays in `src/app.ts` as a static\n * registry of imports (so it type-checks); the manifest chooses, orders, configures and switches those plugins. A row may also name one of the\n * app's own plugin folders (`plugins/<name>/`, app-plugins.ts): that is how a feature is mounted. Extensions are not listed here: they come and go\n * while the app runs.\n */\nimport { createHash } from 'node:crypto'\nimport { existsSync, readFileSync } from 'node:fs'\nimport { join } from 'node:path'\nimport type { Context, Fiber } from '@deepseek-ai/cordis'\nimport { parse } from 'yaml'\n\nexport const API_VERSION = 'blends.acryl.dev/v1alpha1'\n/** The file name ACRYL uses for an app definition. */\nexport const MANIFEST_FILE = 'blend.yaml'\n\nexport type ParameterType = 'string' | 'number' | 'boolean'\nexport type ParameterValue = string | number | boolean\n\nexport interface ParameterDeclaration {\n readonly type: ParameterType\n readonly default: ParameterValue\n}\n\n/** A row as written in `spec.rows`. */\nexport interface BlendRow {\n readonly id: string\n readonly name: string\n readonly config?: Readonly<Record<string, unknown>>\n readonly disabled?: boolean\n}\n\n/** A change to an inherited row, by id. What it sets wins; what it omits is inherited. */\nexport interface OverrideEntry {\n readonly id: string\n readonly name?: string\n readonly config?: Readonly<Record<string, unknown>>\n readonly disabled?: boolean\n}\n\n/** A row as the app mounts it: `use` is the registry entry the row's `name` selects. */\nexport interface Row {\n readonly id: string\n readonly use: string\n readonly config?: Readonly<Record<string, unknown>>\n readonly disabled?: boolean\n}\n\nexport interface Metadata {\n readonly id: string\n readonly name: string\n readonly version: string\n readonly category?: string\n readonly description?: string\n readonly license?: string\n /** Anything but an explicit `public` is private: `save` never pushes a private app to a public remote. */\n readonly visibility?: 'private' | 'public'\n}\n\n/** Which Blueprint, at which version, a Blend was made from. */\nexport interface Lineage {\n readonly blueprint: string\n readonly blueprintVersion: string\n}\n\nexport interface Manifest {\n readonly apiVersion: typeof API_VERSION\n readonly kind: 'Blueprint' | 'Blend'\n readonly metadata: Metadata\n readonly spec: {\n readonly runtime: 'cordis'\n readonly extends?: string\n readonly lineage?: Lineage\n readonly parameters?: Readonly<Record<string, ParameterDeclaration>>\n readonly rows?: readonly BlendRow[]\n readonly overrides?: readonly OverrideEntry[]\n }\n}\n\nexport type DiagnosticCode =\n | 'parse-error'\n | 'schema-error'\n | 'duplicate-row-id'\n | 'unknown-plugin'\n | 'dangling-parameter-reference'\n | 'unused-parameter'\n | 'parameter-type-mismatch'\n | 'parameter-override-unknown'\n | 'blend-without-lineage'\n | 'blueprint-with-lineage'\n | 'lineage-extends-mismatch'\n | 'overrides-without-parent'\n | 'parent-not-supplied'\n | 'parent-cycle'\n | 'override-unknown-id'\n | 'insert-id-collision'\n\n/** Every problem names where it is, as a path into the document. */\nexport interface Diagnostic {\n readonly code: DiagnosticCode\n readonly path: string\n readonly message: string\n}\n\nexport class ManifestError extends Error {\n override name = 'ManifestError'\n readonly diagnostics: readonly Diagnostic[]\n constructor(source: string, diagnostics: readonly Diagnostic[]) {\n super(\n `${source} is not a valid app manifest:\\n${diagnostics.map((d) => ` ${d.path}: ${d.message} [${d.code}]`).join('\\n')}`,\n )\n this.diagnostics = diagnostics\n }\n}\n\nexport const DEFINITION_ID = /^[a-z0-9]+(\\.[a-z0-9-]+)+$/\nconst ROW_ID = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/\nexport const SEMVER =\n /^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$/\nconst PARAMETER = /^[A-Za-z][A-Za-z0-9_-]*$/\nconst TOKEN = /\\{\\{parameters\\.([A-Za-z0-9_-]+)\\}\\}/g\nconst WHOLE_TOKEN = /^\\{\\{parameters\\.([A-Za-z0-9_-]+)\\}\\}$/\nconst TOP_FIELDS = new Set(['apiVersion', 'kind', 'metadata', 'spec'])\nconst METADATA_FIELDS = new Set([\n 'id',\n 'name',\n 'version',\n 'category',\n 'description',\n 'license',\n 'visibility',\n])\nconst SPEC_FIELDS = new Set(['runtime', 'extends', 'lineage', 'parameters', 'rows', 'overrides'])\nconst ROW_FIELDS = new Set(['id', 'name', 'config', 'disabled'])\nconst OVERRIDE_FIELDS = new Set(['id', 'name', 'config', 'disabled'])\nconst LINEAGE_FIELDS = new Set(['blueprint', 'blueprintVersion'])\nconst PARAMETER_FIELDS = new Set(['type', 'default'])\nconst TYPES = new Set<ParameterType>(['string', 'number', 'boolean'])\n\nconst isObject = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value)\n\n/** Every string inside a config value, with its path. Tokens are recognised in string values only. */\nfunction walkStrings(\n value: unknown,\n path: string,\n visit: (text: string, path: string) => void,\n): void {\n if (typeof value === 'string') visit(value, path)\n else if (Array.isArray(value))\n for (const [index, item] of value.entries()) walkStrings(item, `${path}[${index}]`, visit)\n else if (isObject(value))\n for (const [key, item] of Object.entries(value)) walkStrings(item, `${path}.${key}`, visit)\n}\n\n/** The id of the definition a document resolves over: `extends`, else a Blend's lineage Blueprint. */\nexport function parentIdOf(document: Pick<Manifest, 'kind' | 'spec'>): string | undefined {\n if (document.spec.extends !== undefined) return document.spec.extends\n return document.kind === 'Blend' ? document.spec.lineage?.blueprint : undefined\n}\n\n/**\n * Validate one parsed document on its own (its parent is not read here; see `loadManifest`). An empty list means valid. `known` is\n * the registry's names, so an unknown row `name` is reported here, before anything is mounted.\n */\nexport function validate(document: unknown, known?: Iterable<string>): Diagnostic[] {\n const problems: Diagnostic[] = []\n const add = (code: DiagnosticCode, path: string, message: string) =>\n problems.push({ code, path, message })\n if (!isObject(document))\n return [{ code: 'schema-error', path: '$', message: 'the manifest must be a map' }]\n for (const key of Object.keys(document))\n if (!TOP_FIELDS.has(key)) add('schema-error', key, `unknown field '${key}'`)\n if (document.apiVersion !== API_VERSION)\n add('schema-error', 'apiVersion', `must be '${API_VERSION}'`)\n if (document.kind !== 'Blueprint' && document.kind !== 'Blend')\n add('schema-error', 'kind', \"must be 'Blueprint' or 'Blend'\")\n\n const metadata = document.metadata\n if (!isObject(metadata))\n add('schema-error', 'metadata', 'missing required field metadata (id, name, version)')\n else {\n for (const key of Object.keys(metadata))\n if (!METADATA_FIELDS.has(key))\n add('schema-error', `metadata.${key}`, `unknown field '${key}'`)\n if (typeof metadata.id !== 'string' || !DEFINITION_ID.test(metadata.id))\n add('schema-error', 'metadata.id', \"must be a dotted id such as 'acrylblends.my-app'\")\n if (typeof metadata.name !== 'string' || metadata.name === '')\n add('schema-error', 'metadata.name', 'missing required field name')\n if (typeof metadata.version !== 'string' || !SEMVER.test(metadata.version))\n add('schema-error', 'metadata.version', 'must be a semantic version such as 0.1.0')\n if (\n metadata.visibility !== undefined &&\n metadata.visibility !== 'private' &&\n metadata.visibility !== 'public'\n )\n add('schema-error', 'metadata.visibility', \"must be 'private' or 'public'\")\n }\n\n const spec = document.spec\n const declared = new Map<string, ParameterType>()\n const used = new Set<string>()\n const registry = known ? new Set(known) : undefined\n const ids = new Set<string>()\n if (!isObject(spec)) {\n add('schema-error', 'spec', 'missing required field spec (runtime)')\n return problems\n }\n for (const key of Object.keys(spec))\n if (!SPEC_FIELDS.has(key)) add('schema-error', `spec.${key}`, `unknown field '${key}'`)\n if (spec.runtime !== 'cordis') add('schema-error', 'spec.runtime', \"must be 'cordis'\")\n\n // Kind, lineage and extends agree with each other.\n const lineage = spec.lineage\n if (lineage !== undefined) {\n if (!isObject(lineage))\n add('schema-error', 'spec.lineage', 'must be { blueprint, blueprintVersion }')\n else {\n for (const key of Object.keys(lineage))\n if (!LINEAGE_FIELDS.has(key))\n add('schema-error', `spec.lineage.${key}`, `unknown field '${key}'`)\n if (typeof lineage.blueprint !== 'string' || !DEFINITION_ID.test(lineage.blueprint))\n add('schema-error', 'spec.lineage.blueprint', 'must be a dotted Blueprint id')\n if (typeof lineage.blueprintVersion !== 'string' || !SEMVER.test(lineage.blueprintVersion))\n add('schema-error', 'spec.lineage.blueprintVersion', 'must be a semantic version')\n }\n }\n if (\n spec.extends !== undefined &&\n (typeof spec.extends !== 'string' || !DEFINITION_ID.test(spec.extends))\n )\n add('schema-error', 'spec.extends', 'must be a dotted definition id')\n if (document.kind === 'Blend' && lineage === undefined)\n add(\n 'blend-without-lineage',\n 'spec.lineage',\n 'a Blend must declare spec.lineage (its Blueprint and version)',\n )\n if (document.kind === 'Blueprint' && lineage !== undefined)\n add(\n 'blueprint-with-lineage',\n 'spec.lineage',\n 'a Blueprint must not declare spec.lineage; lineage belongs to Blends',\n )\n if (isObject(lineage) && spec.extends !== undefined && spec.extends !== lineage.blueprint)\n add(\n 'lineage-extends-mismatch',\n 'spec.extends',\n `extends '${String(spec.extends)}' must agree with lineage.blueprint '${String(lineage.blueprint)}'`,\n )\n\n const parameters = spec.parameters ?? {}\n if (!isObject(parameters))\n add('schema-error', 'spec.parameters', 'must be a map of name to { type, default }')\n else {\n for (const [name, declaration] of Object.entries(parameters)) {\n const path = `spec.parameters.${name}`\n if (!PARAMETER.test(name))\n add('schema-error', path, 'a parameter name is letters, digits, _ and -')\n if (!isObject(declaration) || !TYPES.has(declaration.type as ParameterType)) {\n add('schema-error', `${path}.type`, \"must be 'string', 'number' or 'boolean'\")\n continue\n }\n for (const key of Object.keys(declaration))\n if (!PARAMETER_FIELDS.has(key))\n add('schema-error', `${path}.${key}`, `unknown field '${key}'`)\n if (typeof declaration.default !== declaration.type)\n add('parameter-type-mismatch', `${path}.default`, `must be a ${declaration.type}`)\n declared.set(name, declaration.type as ParameterType)\n }\n }\n\n const checkTokens = (config: unknown, path: string) => {\n walkStrings(config, path, (text, at) => {\n for (const [, name] of text.matchAll(TOKEN)) {\n used.add(name as string)\n if (!declared.has(name as string))\n add('dangling-parameter-reference', at, `refers to undeclared parameter '${name}'`)\n }\n })\n }\n const checkFlags = (entry: Record<string, unknown>, path: string, fields: Set<string>) => {\n for (const key of Object.keys(entry))\n if (!fields.has(key)) add('schema-error', `${path}.${key}`, `unknown field '${key}'`)\n if (entry.disabled !== undefined && typeof entry.disabled !== 'boolean')\n add('schema-error', `${path}.disabled`, 'must be true or false')\n if (entry.config !== undefined && !isObject(entry.config))\n add('schema-error', `${path}.config`, 'must be a map')\n if (isObject(entry.config)) checkTokens(entry.config, `${path}.config`)\n }\n const checkName = (name: unknown, path: string) => {\n if (registry && typeof name === 'string' && !registry.has(name))\n add(\n 'unknown-plugin',\n path,\n `no plugin '${name}' in the app's registry (known: ${[...registry].join(', ')})`,\n )\n }\n\n const rows = spec.rows ?? []\n if (!Array.isArray(rows)) add('schema-error', 'spec.rows', 'must be a list of rows')\n else {\n for (const [index, row] of (rows as unknown[]).entries()) {\n const path = `spec.rows[${index}]`\n if (!isObject(row)) {\n add('schema-error', path, 'a row must be a map with an id and a name')\n continue\n }\n if (typeof row.id !== 'string' || !ROW_ID.test(row.id)) {\n add('schema-error', `${path}.id`, 'must be lowercase letters, digits and dashes')\n continue\n }\n if (ids.has(row.id)) add('duplicate-row-id', `${path}.id`, `the id '${row.id}' is used twice`)\n ids.add(row.id)\n if (typeof row.name !== 'string' || row.name === '')\n add(\n 'schema-error',\n `${path}.name`,\n 'missing required field name (the plugin this row loads)',\n )\n else checkName(row.name, `${path}.name`)\n checkFlags(row, path, ROW_FIELDS)\n }\n }\n\n const overrides = spec.overrides ?? []\n if (!Array.isArray(overrides))\n add('schema-error', 'spec.overrides', 'must be a list of overrides')\n else {\n const seen = new Set<string>()\n for (const [index, entry] of (overrides as unknown[]).entries()) {\n const path = `spec.overrides[${index}]`\n if (!isObject(entry)) {\n add('schema-error', path, 'an override must be a map with an id')\n continue\n }\n if (typeof entry.id !== 'string' || entry.id === '') {\n add(\n 'schema-error',\n `${path}.id`,\n 'missing required field id (the inherited row it changes)',\n )\n continue\n }\n if (seen.has(entry.id))\n add('duplicate-row-id', `${path}.id`, `the override id '${entry.id}' is used twice`)\n seen.add(entry.id)\n if (entry.name !== undefined) {\n if (typeof entry.name !== 'string' || entry.name === '')\n add('schema-error', `${path}.name`, 'must be a plugin name')\n else checkName(entry.name, `${path}.name`)\n }\n checkFlags(entry, path, OVERRIDE_FIELDS)\n }\n if (overrides.length > 0 && parentIdOf(document as unknown as Manifest) === undefined)\n add(\n 'overrides-without-parent',\n 'spec.overrides',\n 'overrides need a parent: declare spec.extends, or make this a Blend with a lineage',\n )\n }\n for (const name of declared.keys())\n if (!used.has(name))\n add('unused-parameter', `spec.parameters.${name}`, `'${name}' is declared but not used`)\n return problems\n}\n\nfunction substitute(value: unknown, values: Readonly<Record<string, ParameterValue>>): unknown {\n if (typeof value === 'string') {\n const whole = WHOLE_TOKEN.exec(value)\n if (whole) return values[whole[1] as string] ?? value\n return value.replace(TOKEN, (token, name: string) =>\n name in values ? String(values[name]) : token,\n )\n }\n if (Array.isArray(value)) return value.map((item) => substitute(item, values))\n if (isObject(value))\n return Object.fromEntries(\n Object.entries(value).map(([key, item]) => [key, substitute(item, values)]),\n )\n return value\n}\n\n/** A manifest with its parameters resolved: every row's config has its tokens replaced, typed where a value is one whole token. */\nexport interface ResolvedManifest extends Manifest {\n /** The rows to mount, in order: the parent's rows (with overrides applied), then this document's own. `use` selects the registry entry. */\n readonly plugins: readonly Row[]\n readonly values: Readonly<Record<string, ParameterValue>>\n /** sha256 of the manifest file's bytes. */\n readonly digest: string\n}\n\nexport interface LoadOptions {\n readonly known?: Iterable<string>\n /** Values for the parameters of this document. A parent always resolves with its own defaults. */\n readonly values?: Readonly<Record<string, ParameterValue>>\n /** Where the parent Blueprint of a Blend lives: its file path by definition id, or undefined when it is not supplied. */\n readonly getBlueprint?: (id: string) => string | undefined\n}\n\nfunction parseFile(file: string): { text: string; document: unknown } | Diagnostic[] {\n if (!existsSync(file))\n return [{ code: 'parse-error', path: '$', message: `${file} does not exist` }]\n const text = readFileSync(file, 'utf8')\n try {\n return { text, document: parse(text) }\n } catch (error) {\n return [\n {\n code: 'parse-error',\n path: '$',\n message: error instanceof Error ? error.message : String(error),\n },\n ]\n }\n}\n\nfunction collectValues(\n declarations: Readonly<Record<string, ParameterDeclaration>>,\n given: Readonly<Record<string, ParameterValue>> | undefined,\n diagnostics: Diagnostic[],\n): Record<string, ParameterValue> {\n const values: Record<string, ParameterValue> = {}\n for (const [name, declaration] of Object.entries(declarations)) values[name] = declaration.default\n for (const [name, value] of Object.entries(given ?? {})) {\n const declared = declarations[name]\n if (!declared)\n diagnostics.push({\n code: 'parameter-override-unknown',\n path: `spec.parameters.${name}`,\n message: `no parameter '${name}' to set`,\n })\n else if (typeof value !== declared.type)\n diagnostics.push({\n code: 'parameter-type-mismatch',\n path: `spec.parameters.${name}`,\n message: `must be a ${declared.type}`,\n })\n else values[name] = value\n }\n return values\n}\n\nconst substituted = (\n config: Readonly<Record<string, unknown>> | undefined,\n values: Record<string, ParameterValue>,\n) => (config === undefined ? {} : { config: substitute(config, values) as Record<string, unknown> })\n\n/** A shallow per-key merge: keys the override sets win, keys it omits are inherited. The parent's row is never changed. */\nfunction merged(row: Row, entry: OverrideEntry, values: Record<string, ParameterValue>): Row {\n const config =\n entry.config === undefined\n ? row.config\n : { ...row.config, ...(substitute(entry.config, values) as Record<string, unknown>) }\n const disabled = entry.disabled ?? row.disabled\n return {\n id: row.id,\n use: entry.name ?? row.use,\n ...(config === undefined ? {} : { config }),\n ...(disabled === undefined ? {} : { disabled }),\n }\n}\n\n/**\n * Resolve one document over its parent chain. Every problem is a diagnostic; nothing throws for invalid input. Rules (ACRYL's): the\n * parent is `extends`, else a Blend's lineage Blueprint; a parent resolves with its own defaults; an override must name a row the\n * resolved parent has; an own row must not reuse a parent row's id; a cycle or a missing parent is reported.\n */\nexport function resolveRows(\n document: Manifest,\n options: Pick<LoadOptions, 'values' | 'getBlueprint'>,\n chain: readonly string[],\n diagnostics: Diagnostic[],\n where = '',\n): { rows: Row[]; values: Record<string, ParameterValue> } {\n const at = (path: string) => `${where}${path}`\n const values = collectValues(document.spec.parameters ?? {}, options.values, diagnostics)\n let inherited: Row[] = []\n // False when the parent could not be read or resolved: its problems are reported, and checks against its rows would only add noise.\n let parentResolved = parentIdOf(document) === undefined\n const parentId = parentIdOf(document)\n const parentPath = document.spec.extends !== undefined ? 'spec.extends' : 'spec.lineage.blueprint'\n if (parentId !== undefined) {\n if (chain.includes(parentId)) {\n diagnostics.push({\n code: 'parent-cycle',\n path: at(parentPath),\n message: `parent '${parentId}' closes a cycle in the resolution chain`,\n })\n } else {\n const file = options.getBlueprint?.(parentId)\n const read = file === undefined ? undefined : parseFile(file)\n if (read === undefined || Array.isArray(read)) {\n diagnostics.push({\n code: 'parent-not-supplied',\n path: at(parentPath),\n message:\n read === undefined\n ? `parent '${parentId}' is not supplied (getBlueprint returned nothing)`\n : `parent '${parentId}': ${read[0]?.message}`,\n })\n } else {\n const problems = validate(read.document)\n if (problems.length > 0) {\n for (const problem of problems)\n diagnostics.push({ ...problem, path: `parent '${parentId}': ${problem.path}` })\n } else {\n inherited = resolveRows(\n read.document as Manifest,\n options.getBlueprint ? { getBlueprint: options.getBlueprint } : {},\n [...chain, parentId],\n diagnostics,\n `parent '${parentId}': `,\n ).rows\n parentResolved = !diagnostics.some((d) => d.path.startsWith(`parent '${parentId}'`))\n }\n }\n }\n }\n const own: Row[] = (document.spec.rows ?? []).map((row) => ({\n id: row.id,\n use: row.name,\n ...substituted(row.config, values),\n ...(row.disabled === undefined ? {} : { disabled: row.disabled }),\n }))\n const parentIds = new Set(inherited.map((row) => row.id))\n if (parentId !== undefined && parentResolved) {\n for (const [index, entry] of (document.spec.overrides ?? []).entries())\n if (!parentIds.has(entry.id))\n diagnostics.push({\n code: 'override-unknown-id',\n path: at(`spec.overrides[${index}].id`),\n message: `override targets row id '${entry.id}', which the resolved parent does not have`,\n })\n for (const [index, row] of own.entries())\n if (parentIds.has(row.id))\n diagnostics.push({\n code: 'insert-id-collision',\n path: at(`spec.rows[${index}].id`),\n message: `row id '${row.id}' already exists in the resolved parent`,\n })\n }\n const overrideById = new Map((document.spec.overrides ?? []).map((entry) => [entry.id, entry]))\n const rows = [\n ...inherited.map((row) =>\n overrideById.has(row.id)\n ? merged(row, overrideById.get(row.id) as OverrideEntry, values)\n : row,\n ),\n ...own,\n ]\n return { rows, values }\n}\n\n/**\n * Read, validate and resolve a manifest. A Blend resolves over its Blueprint (`getBlueprint`). Throws a `ManifestError` with every\n * diagnostic when anything is invalid.\n */\nexport function loadManifest(file: string, options: LoadOptions = {}): ResolvedManifest {\n const read = parseFile(file)\n if (Array.isArray(read)) throw new ManifestError(file, read)\n const diagnostics = validate(read.document, options.known)\n if (diagnostics.some((d) => d.code === 'schema-error' || d.code === 'parse-error'))\n throw new ManifestError(file, diagnostics)\n const raw = read.document as Manifest\n const { rows, values } = resolveRows(raw, options, [raw.metadata.id], diagnostics)\n // A row inherited from a parent (or renamed by an override) can name a plugin this app does not have.\n if (options.known) {\n const registry = new Set(options.known)\n const own = new Set((raw.spec.rows ?? []).map((row) => row.id))\n for (const row of rows)\n if (!own.has(row.id) && !registry.has(row.use))\n diagnostics.push({\n code: 'unknown-plugin',\n path: `resolved row '${row.id}'`,\n message: `no plugin '${row.use}' in the app's registry (known: ${[...registry].join(', ')})`,\n })\n }\n if (diagnostics.length > 0) throw new ManifestError(file, diagnostics)\n return {\n ...raw,\n plugins: rows,\n values,\n digest: createHash('sha256').update(read.text).digest('hex'),\n }\n}\n\n/** What an app can mount: a Cordis plugin per name. */\nexport type Registry = Readonly<Record<string, unknown>>\n\n/**\n * Mount the manifest's enabled rows in order, each with its config merged under `overrides[id]` (runtime values such as the port win),\n * awaiting each one, because a fiber still waiting on an injected service reports done too early. Returns the fibers, in order.\n */\nexport async function compose(\n root: Context,\n manifest: Pick<ResolvedManifest, 'plugins'>,\n registry: Registry,\n overrides: Readonly<Record<string, Readonly<Record<string, unknown>>>> = {},\n): Promise<Fiber[]> {\n const fibers: Fiber[] = []\n for (const row of manifest.plugins) {\n if (row.disabled) continue\n const plugin = registry[row.use]\n if (!plugin)\n throw new ManifestError('the manifest', [\n { code: 'unknown-plugin', path: row.id, message: `no plugin '${row.use}' in the registry` },\n ])\n const config = { ...(row.config ?? {}), ...(overrides[row.id] ?? {}) }\n const fiber = root.plugin(plugin as Parameters<Context['plugin']>[0], config as never)\n fibers.push(fiber)\n await fiber.await()\n }\n return fibers\n}\n\n/** The usual place for Blueprints: a folder with one `<definition id>.yaml` per Blueprint (for example `blueprints/acme.shop.yaml`). */\nexport function blueprintsIn(directory: string): (id: string) => string | undefined {\n return (id) => {\n const file = join(directory, `${id}.yaml`)\n return DEFINITION_ID.test(id) && existsSync(file) ? file : undefined\n }\n}\n\nexport {\n type AppPluginModule,\n appPluginNames,\n libraryCopies,\n loadAppPlugins,\n PLUGIN_ENTRIES,\n pluginEntry,\n} from './app-plugins.ts'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,MAAa,cAAc;;AAE3B,MAAa,gBAAgB;AA0F7B,IAAa,gBAAb,cAAmC,MAAM;CACvC,OAAgB;CAChB;CACA,YAAY,QAAgB,aAAoC;EAC9D,MACE,GAAG,OAAO,iCAAiC,YAAY,KAAK,MAAM,KAAK,EAAE,KAAK,IAAI,EAAE,QAAQ,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,IAAI,GACtH;EACA,KAAK,cAAc;CACrB;AACF;AAEA,MAAa,gBAAgB;AAC7B,MAAM,SAAS;AACf,MAAa,SACX;AACF,MAAM,YAAY;AAClB,MAAM,QAAQ;AACd,MAAM,cAAc;AACpB,MAAM,6BAAa,IAAI,IAAI;CAAC;CAAc;CAAQ;CAAY;AAAM,CAAC;AACrE,MAAM,kCAAkB,IAAI,IAAI;CAC9B;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AACD,MAAM,8BAAc,IAAI,IAAI;CAAC;CAAW;CAAW;CAAW;CAAc;CAAQ;AAAW,CAAC;AAChG,MAAM,6BAAa,IAAI,IAAI;CAAC;CAAM;CAAQ;CAAU;AAAU,CAAC;AAC/D,MAAM,kCAAkB,IAAI,IAAI;CAAC;CAAM;CAAQ;CAAU;AAAU,CAAC;AACpE,MAAM,iCAAiB,IAAI,IAAI,CAAC,aAAa,kBAAkB,CAAC;AAChE,MAAM,mCAAmB,IAAI,IAAI,CAAC,QAAQ,SAAS,CAAC;AACpD,MAAM,wBAAQ,IAAI,IAAmB;CAAC;CAAU;CAAU;AAAS,CAAC;AAEpE,MAAM,YAAY,UAChB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;;AAGrE,SAAS,YACP,OACA,MACA,O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