@powerhousedao/host-core 6.2.3-dev.100
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/LICENSE +661 -0
- package/dist/compound-DO_mvh0O.mjs +3296 -0
- package/dist/compound-DO_mvh0O.mjs.map +1 -0
- package/dist/compound-eW-6nGxK.d.mts +2509 -0
- package/dist/compound-eW-6nGxK.d.mts.map +1 -0
- package/dist/env-substitution-BXGohOGN.mjs +660 -0
- package/dist/env-substitution-BXGohOGN.mjs.map +1 -0
- package/dist/env-substitution-C_fVirPh.d.mts +17 -0
- package/dist/env-substitution-C_fVirPh.d.mts.map +1 -0
- package/dist/host-schemas-BM7F21lf.d.mts +2193 -0
- package/dist/host-schemas-BM7F21lf.d.mts.map +1 -0
- package/dist/index.d.mts +1304 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +1181 -0
- package/dist/index.mjs.map +1 -0
- package/dist/plugins-Uk84BRay.d.mts +182 -0
- package/dist/plugins-Uk84BRay.d.mts.map +1 -0
- package/dist/plugins.d.mts +3 -0
- package/dist/plugins.mjs +174 -0
- package/dist/plugins.mjs.map +1 -0
- package/dist/projection.d.mts +651 -0
- package/dist/projection.d.mts.map +1 -0
- package/dist/projection.mjs +1633 -0
- package/dist/projection.mjs.map +1 -0
- package/dist/runners/compound.d.mts +286 -0
- package/dist/runners/compound.d.mts.map +1 -0
- package/dist/runners/compound.mjs +42 -0
- package/dist/runners/compound.mjs.map +1 -0
- package/dist/schema.d.mts +146 -0
- package/dist/schema.d.mts.map +1 -0
- package/dist/schema.mjs +98 -0
- package/dist/schema.mjs.map +1 -0
- package/package.json +67 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compound-eW-6nGxK.d.mts","names":[],"sources":["../src/host-schemas.ts","../src/resolve/declared.ts","../src/runner-resolver.ts","../src/child-wrapper.ts","../src/runner-handle.ts","../src/compound.ts"],"mappings":";;;;;;;;;;;;;;;;cA2Ba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CYtD;EACR;EACA,QAAQ;EACR;EACA,MAAM;EACN;EACA,QAAQ;;;EAGR,SAAS;;UAiCM;;EAEf;;EAEA,cAAc;;;EAGd;;EAEA,QAAQ;;;EAGR,aAAa,OAAO;;;EAGpB;;EAEA,6BAA6B,OAAO;;UAkCrB;EACf,SAAS;;;EAGT,gBAAgB;;;;EAIhB,eAAe,iCAAiC;;iBAsB5B,YACpB,WAAW,gBACX,KAAK,eACL,SAAS,qBACR,QAAQ"}
|
|
@@ -0,0 +1,660 @@
|
|
|
1
|
+
import { pluginEntrySchema } from "./plugins.mjs";
|
|
2
|
+
import { TOKEN_ESCAPE_KEY, TOKEN_KEYS, concatTokenSchema, envTokenSchema, envTokenable, findToken, forbidRef, isToken, itemTokenSchema, keyTokenSchema, mapTokenSchema, outputTokenSchema, ref, switchboardOfDrive, tokenKeyOf, tokenSchema, tokenable } from "@powerhousedao/shared/host-tokens";
|
|
3
|
+
import { isOriginPlaceholderUrl } from "@powerhousedao/shared/connect/origin-placeholder";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
//#region src/drive-schema.ts
|
|
6
|
+
/**
|
|
7
|
+
* The schema half of drives.ts, zod only so `./schema` stays neutral.
|
|
8
|
+
* - slug: the SEEDING KEY (idempotence); id optional (stable identity).
|
|
9
|
+
* - preferredEditor: stored at header.meta.preferredEditor; Connect config's
|
|
10
|
+
* `app` is the legacy alias.
|
|
11
|
+
* - remote.url: a drive served elsewhere; local fields are ignored for it.
|
|
12
|
+
* Token-able (`$output` on a producer's `drives.<slug>.url`).
|
|
13
|
+
*/
|
|
14
|
+
function buildDriveDeclarationSchema(urlField) {
|
|
15
|
+
return z.strictObject({
|
|
16
|
+
slug: z.string().min(1),
|
|
17
|
+
id: z.string().min(1).optional(),
|
|
18
|
+
/** Derive the id from the project path, like generateProjectDriveId — the
|
|
19
|
+
* same ids classic `ph vetra` produces. `true` serves the drive under the
|
|
20
|
+
* hashed slug too (the vetra drive's slug IS its hashed id); `"id"` hashes
|
|
21
|
+
* only the id and keeps the declared slug (the classic Workflows drive:
|
|
22
|
+
* `/d/workflows`, id `workflows-<hash>`). */
|
|
23
|
+
projectHash: z.union([z.boolean(), z.literal("id")]).optional(),
|
|
24
|
+
/** What a missing drive is created as. Default powerhouse/document-drive. */
|
|
25
|
+
documentType: z.enum(["powerhouse/document-drive", "powerhouse/reactor-drive"]).optional(),
|
|
26
|
+
name: z.string().min(1).optional(),
|
|
27
|
+
icon: z.string().optional(),
|
|
28
|
+
preferredEditor: z.string().optional(),
|
|
29
|
+
sharingType: z.enum([
|
|
30
|
+
"public",
|
|
31
|
+
"private",
|
|
32
|
+
"shared"
|
|
33
|
+
]).optional(),
|
|
34
|
+
availableOffline: z.boolean().optional(),
|
|
35
|
+
remote: z.strictObject({ url: urlField(z.string().min(1)) }).optional()
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
const driveDeclarationSchema = buildDriveDeclarationSchema(tokenable);
|
|
39
|
+
const drivesSchema = z.array(driveDeclarationSchema);
|
|
40
|
+
/** The project-hashed drive id (`${slug}-${sha256(projectRoot)[0..8]}`) with
|
|
41
|
+
* the hash function injected, so neutral consumers (a browser monitor) can
|
|
42
|
+
* pass `crypto.subtle`-derived or precomputed hex. drives.ts binds it to
|
|
43
|
+
* node:crypto as `projectDriveId`. */
|
|
44
|
+
function projectDriveIdWith(sha256Hex, projectRoot, slug) {
|
|
45
|
+
return `${slug}-${sha256Hex(projectRoot).substring(0, 8)}`;
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/host-schemas.ts
|
|
49
|
+
/**
|
|
50
|
+
* The zod single source for host.js blocks (typed-host-configs G1). Every
|
|
51
|
+
* host type is z.input/z.output of these schemas; nothing is hand-mirrored.
|
|
52
|
+
* Top-level host objects and the `reactor` block are STRICT (a typo fails);
|
|
53
|
+
* `runner` stays loose until each runner declares its options (T2), and
|
|
54
|
+
* `config` is runner-defined.
|
|
55
|
+
*
|
|
56
|
+
* Token-able fields (typed-host-configs 3.5): `reactor.backends.*.remote.url`
|
|
57
|
+
* (required, a switchboard drive address), `reactor.drives` (whole list, e.g. `$map`),
|
|
58
|
+
* `reactor.drives[].remote.url` and `storage.dataDir` (`$env` only). Their z.input admits tokens, their z.output is the resolved type.
|
|
59
|
+
*/
|
|
60
|
+
/** A host's `name` keys its run record, `.ph/run/<name>.json`, so it must be
|
|
61
|
+
* one safe path segment. */
|
|
62
|
+
const HOST_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
63
|
+
const HOST_NAME_MAX_LENGTH = 128;
|
|
64
|
+
const HOST_NAME_MESSAGE = "A host name is used as a file name, so use only letters, digits, '.', '_' and '-', start with a letter or digit, and keep it to 128 characters.";
|
|
65
|
+
const hostNameSchema = z.string().min(1).max(128, HOST_NAME_MESSAGE).regex(HOST_NAME_PATTERN, HOST_NAME_MESSAGE);
|
|
66
|
+
/**
|
|
67
|
+
* A URL, or one written against the page origin (`${origin}/graphql`): the
|
|
68
|
+
* browser resolves the placeholder when it loads Connect's config, for a
|
|
69
|
+
* member whose own server proxies the switchboard's paths.
|
|
70
|
+
*/
|
|
71
|
+
const originOrUrlSchema = z.union([z.url(), z.string().refine(isOriginPlaceholderUrl, { message: "a URL, or ${origin}/<path> for a proxied sibling" })]);
|
|
72
|
+
const profileSchema = z.strictObject({
|
|
73
|
+
appId: z.string().min(1).optional(),
|
|
74
|
+
name: z.string().min(1).optional(),
|
|
75
|
+
description: z.string().optional(),
|
|
76
|
+
icon: z.string().optional()
|
|
77
|
+
});
|
|
78
|
+
const reactorProtocolSchema = z.strictObject({
|
|
79
|
+
featureFlags: z.strictObject({
|
|
80
|
+
documentDecisions: z.boolean().optional(),
|
|
81
|
+
authEnforcement: z.boolean().optional(),
|
|
82
|
+
authGroups: z.boolean().optional(),
|
|
83
|
+
authConditions: z.boolean().optional(),
|
|
84
|
+
undoV3: z.boolean().optional()
|
|
85
|
+
}).optional(),
|
|
86
|
+
createSignaturePolicy: z.enum(["legacy", "v2-required"]).optional(),
|
|
87
|
+
unsupportedStoredDocuments: z.enum(["refuse", "read-only"]).optional()
|
|
88
|
+
});
|
|
89
|
+
const runnerKindSchema = z.enum(["reactor", "compound"]);
|
|
90
|
+
const reactorBackendKindSchema = z.enum([
|
|
91
|
+
"in-process",
|
|
92
|
+
"worker",
|
|
93
|
+
"remote"
|
|
94
|
+
]);
|
|
95
|
+
const samePath = (a, b) => {
|
|
96
|
+
const norm = (p) => p.replace(/\\/g, "/").replace(/\/+$/, "").replace(/^\.\//, "");
|
|
97
|
+
return norm(a) === norm(b);
|
|
98
|
+
};
|
|
99
|
+
/** Compound wiring: the generic compound runner's `config` block.
|
|
100
|
+
* (`projectDrivesIntoConnect` and `drivesPublicBase` were removed in T3: a
|
|
101
|
+
* member consumes another member's drives through `$output` tokens.) */
|
|
102
|
+
const compoundWiringSchema = z.strictObject({
|
|
103
|
+
/** Member start order; must name declared children and agree with the
|
|
104
|
+
* output-token dependencies (resolve/plan.ts). Optional: without it the
|
|
105
|
+
* order is derived from the tokens. Unnamed members start after the named
|
|
106
|
+
* ones, in declaration order. */
|
|
107
|
+
startOrder: z.array(z.string().min(1)).optional(),
|
|
108
|
+
/** Write .ph/run/<host>.json (default true). */
|
|
109
|
+
runtimeRecord: z.boolean().optional(),
|
|
110
|
+
/** Patch the baked CSP for the runtime registry on a served Connect
|
|
111
|
+
* member (forwarded as `runner.cspRegistrySync` to every member whose
|
|
112
|
+
* runner is `@powerhousedao/ph-cli/runners/connect`). */
|
|
113
|
+
cspRegistrySync: z.boolean().optional()
|
|
114
|
+
});
|
|
115
|
+
/** `config.startOrder ⊆ keys(children)`, checked where both are visible.
|
|
116
|
+
* Apply it LAST (`.superRefine(refineStartOrder)`) to a runner's final host
|
|
117
|
+
* schema: zod refuses to `.extend()` a refined object. */
|
|
118
|
+
function refineStartOrder(host, ctx) {
|
|
119
|
+
const startOrder = host.config?.startOrder;
|
|
120
|
+
if (!Array.isArray(startOrder)) return;
|
|
121
|
+
const members = Object.keys(host.children);
|
|
122
|
+
startOrder.forEach((name, index) => {
|
|
123
|
+
if (startOrder.indexOf(name) !== index) {
|
|
124
|
+
ctx.addIssue({
|
|
125
|
+
code: "custom",
|
|
126
|
+
path: [
|
|
127
|
+
"config",
|
|
128
|
+
"startOrder",
|
|
129
|
+
index
|
|
130
|
+
],
|
|
131
|
+
message: `startOrder names "${String(name)}" twice; each member starts once.`
|
|
132
|
+
});
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (typeof name === "string" && members.includes(name)) return;
|
|
136
|
+
ctx.addIssue({
|
|
137
|
+
code: "custom",
|
|
138
|
+
path: [
|
|
139
|
+
"config",
|
|
140
|
+
"startOrder",
|
|
141
|
+
index
|
|
142
|
+
],
|
|
143
|
+
message: `startOrder names "${String(name)}", which is not a member. Members: ${members.join(", ") || "(none)"}.`
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
const ALLOW_TOKENS = {
|
|
148
|
+
any: tokenable,
|
|
149
|
+
env: envTokenable
|
|
150
|
+
};
|
|
151
|
+
const FORBID_TOKENS = {
|
|
152
|
+
any: (schema) => z.union([schema]),
|
|
153
|
+
env: (schema) => z.union([schema])
|
|
154
|
+
};
|
|
155
|
+
/** The replacement a non-drive `remote.url` message names. */
|
|
156
|
+
function useDriveUrl(host = "switchboard", member) {
|
|
157
|
+
return `remote: { url: ${host}.drives.<slug>.url } with ${host} from ../${host}/outputs.js, or remote: { url: { $output: { host: "${host}"${member ? `, member: "${member}"` : ""}, path: ["drives", "<slug>", "url"] } } }`;
|
|
158
|
+
}
|
|
159
|
+
/** The `$output` of a declared `remote.url` that reads `endpoints.graphql`. */
|
|
160
|
+
function endpointsGraphqlRef(url) {
|
|
161
|
+
if (typeof url !== "object" || url === null || !("$output" in url)) return;
|
|
162
|
+
const ref = url.$output;
|
|
163
|
+
if (typeof ref !== "object" || ref === null) return void 0;
|
|
164
|
+
const { host, member, path } = ref;
|
|
165
|
+
if (typeof host !== "string" || !Array.isArray(path)) return void 0;
|
|
166
|
+
if (path.join(".") !== "endpoints.graphql") return void 0;
|
|
167
|
+
return {
|
|
168
|
+
host,
|
|
169
|
+
...typeof member === "string" ? { member } : {}
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
/** The slug a drive link names: a `drives.<slug>.url` token's slug or a
|
|
173
|
+
* literal address's served slug; undefined when only runtime knows it. */
|
|
174
|
+
function linkedSlug(url) {
|
|
175
|
+
if (typeof url === "string") return switchboardOfDrive(url)?.slug;
|
|
176
|
+
const ref = typeof url === "object" && url !== null && "$output" in url ? url.$output : void 0;
|
|
177
|
+
const path = Array.isArray(ref?.path) ? ref.path : [];
|
|
178
|
+
return path.length === 3 && path[0] === "drives" && typeof path[1] === "string" && path[2] === "url" ? path[1] : void 0;
|
|
179
|
+
}
|
|
180
|
+
/** The drives a declared host names (home drives, `reactor.drives`, plugin
|
|
181
|
+
* `config.drive` links), or undefined when one is known only at runtime. */
|
|
182
|
+
function knownDriveSlugs(host) {
|
|
183
|
+
const reactor = host.reactor ?? {};
|
|
184
|
+
const slugs = [];
|
|
185
|
+
for (const backend of Object.values(reactor.backends ?? {})) {
|
|
186
|
+
if (backend.kind !== "remote") continue;
|
|
187
|
+
const slug = linkedSlug(backend.remote?.url);
|
|
188
|
+
if (slug === void 0) return void 0;
|
|
189
|
+
slugs.push(slug);
|
|
190
|
+
}
|
|
191
|
+
if (reactor.drives !== void 0) {
|
|
192
|
+
if (!Array.isArray(reactor.drives)) return void 0;
|
|
193
|
+
for (const drive of reactor.drives) if (typeof drive.slug === "string") slugs.push(drive.slug);
|
|
194
|
+
}
|
|
195
|
+
const plugins = Array.isArray(host.runner?.plugins) ? host.runner.plugins : [];
|
|
196
|
+
for (const entry of plugins) {
|
|
197
|
+
const config = typeof entry === "object" && entry !== null && "config" in entry ? entry.config : void 0;
|
|
198
|
+
if (typeof config !== "object" || config === null) continue;
|
|
199
|
+
if (!("drive" in config) || config.drive === void 0) continue;
|
|
200
|
+
const slug = linkedSlug(config.drive);
|
|
201
|
+
if (slug === void 0) return void 0;
|
|
202
|
+
slugs.push(slug);
|
|
203
|
+
}
|
|
204
|
+
for (const drive of connectDefaultDrives(host.config)) {
|
|
205
|
+
if (typeof drive !== "object" || drive === null || !("url" in drive)) continue;
|
|
206
|
+
const slug = linkedSlug(drive.url);
|
|
207
|
+
if (slug === void 0) return void 0;
|
|
208
|
+
slugs.push(slug);
|
|
209
|
+
}
|
|
210
|
+
return slugs;
|
|
211
|
+
}
|
|
212
|
+
/** A Connect host's `config.drives.defaultDrives`, unchecked. */
|
|
213
|
+
function connectDefaultDrives(config) {
|
|
214
|
+
const drives = typeof config === "object" && config !== null && "drives" in config ? config.drives : void 0;
|
|
215
|
+
const list = typeof drives === "object" && drives !== null && "defaultDrives" in drives ? drives.defaultDrives : void 0;
|
|
216
|
+
return Array.isArray(list) ? list : [];
|
|
217
|
+
}
|
|
218
|
+
/** Declared form, at host level so plugin drives are seen: a placement key
|
|
219
|
+
* must name a drive the host names, when every drive is knowable. A host
|
|
220
|
+
* with no remote backend is not checked: its plugins may contribute drives
|
|
221
|
+
* (a switchboard's workflows drive) that no field names. */
|
|
222
|
+
function refineDeclaredPlacementKeys(host, ctx) {
|
|
223
|
+
const placed = Object.keys(host.reactor?.placement?.drives ?? {});
|
|
224
|
+
if (placed.length === 0) return;
|
|
225
|
+
if (!Object.values(host.reactor?.backends ?? {}).some((b) => b.kind === "remote")) return;
|
|
226
|
+
const known = knownDriveSlugs(host);
|
|
227
|
+
if (!known) return;
|
|
228
|
+
const names = (slug, served) => served === slug || served.startsWith(`${slug}-`) && /^[0-9a-f]{8}$/.test(served.slice(slug.length + 1));
|
|
229
|
+
for (const slug of placed) {
|
|
230
|
+
if (known.some((served) => names(slug, served))) continue;
|
|
231
|
+
ctx.addIssue({
|
|
232
|
+
code: "custom",
|
|
233
|
+
path: [
|
|
234
|
+
"reactor",
|
|
235
|
+
"placement",
|
|
236
|
+
"drives",
|
|
237
|
+
slug
|
|
238
|
+
],
|
|
239
|
+
message: `placement.drives.${slug} names no drive this host links to or declares (${[...new Set(known)].join(", ") || "none"}).`
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
/** Resolved-form checks across backends, drives and placement: one base is
|
|
244
|
+
* one remote backend, and a drive placed on a remote is on its switchboard. */
|
|
245
|
+
function refineResolvedReactor(reactor, ctx) {
|
|
246
|
+
const backends = reactor.backends ?? {};
|
|
247
|
+
const baseOf = /* @__PURE__ */ new Map();
|
|
248
|
+
const byBase = /* @__PURE__ */ new Map();
|
|
249
|
+
const linked = /* @__PURE__ */ new Map();
|
|
250
|
+
const link = (slug, base) => linked.set(slug, (linked.get(slug) ?? /* @__PURE__ */ new Set()).add(base));
|
|
251
|
+
for (const [name, backend] of Object.entries(backends)) {
|
|
252
|
+
const url = backend.remote?.url;
|
|
253
|
+
if (backend.kind !== "remote" || typeof url !== "string") continue;
|
|
254
|
+
const home = switchboardOfDrive(url);
|
|
255
|
+
if (!home) continue;
|
|
256
|
+
baseOf.set(name, home.base);
|
|
257
|
+
link(home.slug, home.base);
|
|
258
|
+
const first = byBase.get(home.base);
|
|
259
|
+
if (first === void 0) {
|
|
260
|
+
byBase.set(home.base, name);
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
ctx.addIssue({
|
|
264
|
+
code: "custom",
|
|
265
|
+
path: [
|
|
266
|
+
"backends",
|
|
267
|
+
name,
|
|
268
|
+
"remote",
|
|
269
|
+
"url"
|
|
270
|
+
],
|
|
271
|
+
message: `backends "${first}" and "${name}" both open drives on the same switchboard (${home.base}). Keep "${first}", and list the second drive under reactor.drives with its remote.url instead.`
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
const kept = /* @__PURE__ */ new Set();
|
|
275
|
+
(Array.isArray(reactor.drives) ? reactor.drives : []).forEach((drive, index) => {
|
|
276
|
+
if (!drive.remote) {
|
|
277
|
+
kept.add(drive.slug);
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
const at = switchboardOfDrive(drive.remote.url);
|
|
281
|
+
if (at || drive.remote.url === "") {
|
|
282
|
+
if (at) link(drive.slug, at.base);
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
ctx.addIssue({
|
|
286
|
+
code: "custom",
|
|
287
|
+
path: [
|
|
288
|
+
"drives",
|
|
289
|
+
index,
|
|
290
|
+
"remote",
|
|
291
|
+
"url"
|
|
292
|
+
],
|
|
293
|
+
message: `remote.url must be a switchboard drive address (<switchboard>/d/<slug>), not ${drive.remote.url}: sync needs the drive. Use url: switchboard.drives.<slug>.url, or url: { $output: { host: "switchboard", path: ["drives", "<slug>", "url"] } }.`
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
const nameOf = (base) => byBase.get(base) ?? base;
|
|
297
|
+
for (const [slug, name] of Object.entries(reactor.placement?.drives ?? {})) {
|
|
298
|
+
const at = [
|
|
299
|
+
"placement",
|
|
300
|
+
"drives",
|
|
301
|
+
slug
|
|
302
|
+
];
|
|
303
|
+
const on = [...linked.get(slug) ?? []];
|
|
304
|
+
if (on.length > 0 && kept.has(slug)) {
|
|
305
|
+
ctx.addIssue({
|
|
306
|
+
code: "custom",
|
|
307
|
+
path: at,
|
|
308
|
+
message: `Drive "${slug}" is both this reactor's own drive and on ${on.map(nameOf).join(" and ")}. Rename one, or link only one.`
|
|
309
|
+
});
|
|
310
|
+
continue;
|
|
311
|
+
}
|
|
312
|
+
if (on.length > 1) {
|
|
313
|
+
ctx.addIssue({
|
|
314
|
+
code: "custom",
|
|
315
|
+
path: at,
|
|
316
|
+
message: `Drive "${slug}" is on both ${on.map(nameOf).join(" and ")}. Rename one, or link only one.`
|
|
317
|
+
});
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
const base = baseOf.get(name);
|
|
321
|
+
if (base === void 0) continue;
|
|
322
|
+
if (on.length === 0) {
|
|
323
|
+
if (!kept.has(slug)) continue;
|
|
324
|
+
ctx.addIssue({
|
|
325
|
+
code: "custom",
|
|
326
|
+
path: at,
|
|
327
|
+
message: `placement.drives.${slug} opens drive "${slug}" on "${name}", but this reactor keeps that drive itself. Only a drive on a switchboard can open there without a copy.`
|
|
328
|
+
});
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
if (on[0] === base) continue;
|
|
332
|
+
ctx.addIssue({
|
|
333
|
+
code: "custom",
|
|
334
|
+
path: at,
|
|
335
|
+
message: `placement.drives.${slug} opens drive "${slug}" on "${name}" (${base}), but the drive is on ${on[0]}. Place it on the backend for that switchboard.`
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
/** `remote` keys that tune a connection, so only a remote backend has them. */
|
|
340
|
+
const REMOTE_ONLY_KEYS = [
|
|
341
|
+
"requestTimeoutMs",
|
|
342
|
+
"breaker",
|
|
343
|
+
"realtime"
|
|
344
|
+
];
|
|
345
|
+
/**
|
|
346
|
+
* Builds the host schema set. "allow" (declared form) accepts `T | Token` in
|
|
347
|
+
* every token-able field; "forbid" (resolved form) accepts `T` only.
|
|
348
|
+
*/
|
|
349
|
+
function buildHostSchemas(tokenField) {
|
|
350
|
+
const resolved = tokenField === FORBID_TOKENS;
|
|
351
|
+
const reactorBackendSchema = z.strictObject({
|
|
352
|
+
kind: reactorBackendKindSchema,
|
|
353
|
+
storage: z.strictObject({
|
|
354
|
+
kind: z.enum([
|
|
355
|
+
"idb",
|
|
356
|
+
"memory",
|
|
357
|
+
"path",
|
|
358
|
+
"postgres"
|
|
359
|
+
]),
|
|
360
|
+
/** `"${userData}/…"` sugar or `{ $env: "NAME" }`. */
|
|
361
|
+
dataDir: tokenField.env(z.string()).optional(),
|
|
362
|
+
url: z.string().optional()
|
|
363
|
+
}).optional(),
|
|
364
|
+
readModel: z.strictObject({ url: z.string().optional() }).optional(),
|
|
365
|
+
packages: z.strictObject({
|
|
366
|
+
cdnUrl: z.string().optional(),
|
|
367
|
+
specs: z.array(z.string()).optional(),
|
|
368
|
+
/** on-demand model resolution (was DYNAMIC_MODEL_LOADING). */
|
|
369
|
+
dynamic: z.boolean().optional()
|
|
370
|
+
}).optional(),
|
|
371
|
+
remote: z.strictObject({
|
|
372
|
+
url: tokenField.any(originOrUrlSchema),
|
|
373
|
+
/** Give up on one request to this switchboard after this long. Default 30_000. */
|
|
374
|
+
requestTimeoutMs: z.number().int().positive().optional(),
|
|
375
|
+
/** After `failures` failed requests in a row, send nothing for
|
|
376
|
+
* `openMs`. Default { failures: 3, openMs: 30_000 }. `false`:
|
|
377
|
+
* never stop trying. */
|
|
378
|
+
breaker: z.union([z.literal(false), z.strictObject({
|
|
379
|
+
failures: z.number().int().min(1).optional(),
|
|
380
|
+
openMs: z.number().int().nonnegative().optional()
|
|
381
|
+
})]).optional(),
|
|
382
|
+
/** Live updates over a socket (the router's GraphQL
|
|
383
|
+
* subscriptions, not drive sync). Default true. */
|
|
384
|
+
realtime: z.boolean().optional()
|
|
385
|
+
}).optional()
|
|
386
|
+
}).superRefine((backend, ctx) => {
|
|
387
|
+
if (backend.kind === "remote" && !backend.remote) ctx.addIssue({
|
|
388
|
+
code: "custom",
|
|
389
|
+
path: ["remote", "url"],
|
|
390
|
+
message: `a "remote" backend needs remote.url, a switchboard drive address: ${useDriveUrl()}.`
|
|
391
|
+
});
|
|
392
|
+
if (backend.kind !== "remote" && backend.remote) for (const key of REMOTE_ONLY_KEYS) {
|
|
393
|
+
if (backend.remote[key] === void 0) continue;
|
|
394
|
+
ctx.addIssue({
|
|
395
|
+
code: "custom",
|
|
396
|
+
path: ["remote", key],
|
|
397
|
+
message: `remote.${key} applies only to a "remote" backend; this one is "${backend.kind}".`
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
const url = backend.remote?.url;
|
|
401
|
+
const graphqlRef = resolved ? void 0 : endpointsGraphqlRef(url);
|
|
402
|
+
if (graphqlRef) ctx.addIssue({
|
|
403
|
+
code: "custom",
|
|
404
|
+
path: ["remote", "url"],
|
|
405
|
+
message: `remote.url reads ${graphqlRef.host}'s endpoints.graphql; it must be a switchboard drive address (<switchboard>/d/<slug>): sync needs the drive. Use ${useDriveUrl(graphqlRef.host, graphqlRef.member)}.`
|
|
406
|
+
});
|
|
407
|
+
if (resolved && typeof url === "string" && !switchboardOfDrive(url)) ctx.addIssue({
|
|
408
|
+
code: "custom",
|
|
409
|
+
path: ["remote", "url"],
|
|
410
|
+
message: `remote.url must be a switchboard drive address (<switchboard>/d/<slug>), not ${url}: sync needs the drive. Use ${useDriveUrl()}.`
|
|
411
|
+
});
|
|
412
|
+
const store = backend.storage;
|
|
413
|
+
const storeDir = store?.kind === "path" ? store.dataDir : void 0;
|
|
414
|
+
const readModel = backend.readModel?.url;
|
|
415
|
+
if (typeof storeDir === "string" && readModel && samePath(storeDir, readModel)) ctx.addIssue({
|
|
416
|
+
code: "custom",
|
|
417
|
+
path: ["readModel", "url"],
|
|
418
|
+
message: `readModel.url must not be the reactor's storage dir (${readModel}): two PGlite instances on one data dir corrupt it. Omit readModel.url to get the classic <root>/.ph/read-storage next to the reactor store.`
|
|
419
|
+
});
|
|
420
|
+
});
|
|
421
|
+
const reactorSchema = z.strictObject({
|
|
422
|
+
backends: z.record(z.string(), reactorBackendSchema).optional(),
|
|
423
|
+
placement: z.strictObject({
|
|
424
|
+
primary: z.string().optional(),
|
|
425
|
+
/** Declared drive slug → backend name. A local backend keeps a
|
|
426
|
+
* synced copy; the drive's own remote backend opens it there with
|
|
427
|
+
* no copy. An unlisted drive keeps a synced copy. */
|
|
428
|
+
drives: z.record(z.string().min(1), z.string().min(1)).optional(),
|
|
429
|
+
/** The backend new drives (and documents outside a drive) are
|
|
430
|
+
* created on. A switchboard keeps no copy in this browser.
|
|
431
|
+
* Default: the browser reactor, else the only switchboard. */
|
|
432
|
+
newDrives: z.string().min(1).optional()
|
|
433
|
+
}).optional(),
|
|
434
|
+
router: z.strictObject({
|
|
435
|
+
/** Wait this long for a reactor to say whether it holds a
|
|
436
|
+
* document. 0: no bound. Default 3_000. */
|
|
437
|
+
probeTimeoutMs: z.number().int().nonnegative().optional(),
|
|
438
|
+
/** Look again after this long for a document found on a later
|
|
439
|
+
* backend. Default 30_000. */
|
|
440
|
+
provisionalRouteMs: z.number().int().nonnegative().optional()
|
|
441
|
+
}).optional(),
|
|
442
|
+
protocol: reactorProtocolSchema.optional(),
|
|
443
|
+
/** DEPRECATED (dies in R2): workflows become a listed plugin. */
|
|
444
|
+
workflows: z.boolean().optional(),
|
|
445
|
+
renown: z.strictObject({
|
|
446
|
+
url: z.string().optional(),
|
|
447
|
+
networkId: z.string().optional(),
|
|
448
|
+
chainId: z.number().int().optional()
|
|
449
|
+
}).optional(),
|
|
450
|
+
namespace: z.string().min(1).optional(),
|
|
451
|
+
drives: tokenField.any(z.array(buildDriveDeclarationSchema(tokenField.any))).optional()
|
|
452
|
+
}).superRefine((reactor, ctx) => {
|
|
453
|
+
const backends = reactor.backends ?? {};
|
|
454
|
+
for (const [slug, name] of Object.entries(reactor.placement?.drives ?? {})) {
|
|
455
|
+
if (Object.hasOwn(backends, name)) continue;
|
|
456
|
+
ctx.addIssue({
|
|
457
|
+
code: "custom",
|
|
458
|
+
path: [
|
|
459
|
+
"placement",
|
|
460
|
+
"drives",
|
|
461
|
+
slug
|
|
462
|
+
],
|
|
463
|
+
message: `placement.drives.${slug} names backend "${name}", which is not in backends (${Object.keys(backends).join(", ") || "none"}).`
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
const newDrives = reactor.placement?.newDrives;
|
|
467
|
+
if (newDrives !== void 0 && !Object.hasOwn(backends, newDrives)) ctx.addIssue({
|
|
468
|
+
code: "custom",
|
|
469
|
+
path: ["placement", "newDrives"],
|
|
470
|
+
message: `placement.newDrives names backend "${newDrives}", which is not in backends (${Object.keys(backends).join(", ") || "none"}).`
|
|
471
|
+
});
|
|
472
|
+
if (resolved) refineResolvedReactor(reactor, ctx);
|
|
473
|
+
});
|
|
474
|
+
/** Common runner options; runner modules extend it with their own. */
|
|
475
|
+
const runnerBaseSchema = z.looseObject({
|
|
476
|
+
module: z.string().min(1),
|
|
477
|
+
defaultVerb: z.string().min(1).optional(),
|
|
478
|
+
port: z.number().int().positive().optional(),
|
|
479
|
+
/** Bind address; each runner documents its default. */
|
|
480
|
+
host: z.string().min(1).optional(),
|
|
481
|
+
/** THE COMPOSITION: plugin entries; presence is activation. */
|
|
482
|
+
plugins: z.array(pluginEntrySchema).optional()
|
|
483
|
+
});
|
|
484
|
+
/** A compound member wrapper. Sections are FULL STATEMENTS except `runner`,
|
|
485
|
+
* which key-merges over the member's own. Plugins live in `runner.plugins`
|
|
486
|
+
* (as on a standalone host); there is no wrapper-level `plugins`. */
|
|
487
|
+
const childWrapperSchema = z.strictObject({
|
|
488
|
+
host: z.string().min(1),
|
|
489
|
+
runner: runnerBaseSchema.partial().extend({ port: z.number().int().min(0).max(65535).optional() }).optional(),
|
|
490
|
+
config: z.looseObject({}).optional(),
|
|
491
|
+
reactor: reactorSchema.optional()
|
|
492
|
+
});
|
|
493
|
+
const childrenSchema = z.record(z.string(), childWrapperSchema);
|
|
494
|
+
return {
|
|
495
|
+
reactorBackendSchema,
|
|
496
|
+
reactorSchema,
|
|
497
|
+
runnerBaseSchema,
|
|
498
|
+
childWrapperSchema,
|
|
499
|
+
childrenSchema,
|
|
500
|
+
reactorHostSchema: z.strictObject({
|
|
501
|
+
name: hostNameSchema,
|
|
502
|
+
runner: runnerBaseSchema,
|
|
503
|
+
config: z.looseObject({}).optional(),
|
|
504
|
+
profile: profileSchema.optional(),
|
|
505
|
+
reactor: reactorSchema.optional()
|
|
506
|
+
}),
|
|
507
|
+
compoundHostSchema: z.strictObject({
|
|
508
|
+
name: hostNameSchema,
|
|
509
|
+
runner: runnerBaseSchema,
|
|
510
|
+
children: childrenSchema,
|
|
511
|
+
config: z.looseObject({}).optional(),
|
|
512
|
+
profile: profileSchema.optional()
|
|
513
|
+
}),
|
|
514
|
+
/** This set's field wrapper, for a runner's OWN token-able fields inside
|
|
515
|
+
* `defineHostSchemas`: declared, `T | Token` in and `T` out; resolved,
|
|
516
|
+
* `T` only. Both modes share one static type. */
|
|
517
|
+
tokenable: tokenField.any,
|
|
518
|
+
/** As `tokenable`, but the only token accepted is `$env`. */
|
|
519
|
+
envTokenable: tokenField.env
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
/** The host schema set in declared ("allow": token-able fields take tokens)
|
|
523
|
+
* or resolved ("forbid") form. */
|
|
524
|
+
function makeHostSchemas(options) {
|
|
525
|
+
return buildHostSchemas(options.tokens === "allow" ? ALLOW_TOKENS : FORBID_TOKENS);
|
|
526
|
+
}
|
|
527
|
+
/** The issues a host-level refinement raises, outside a zod parse. */
|
|
528
|
+
function collectIssues(host, refine) {
|
|
529
|
+
if (typeof host !== "object" || host === null || !("reactor" in host)) return [];
|
|
530
|
+
const issues = [];
|
|
531
|
+
refine(host, { addIssue: (issue) => {
|
|
532
|
+
issues.push({
|
|
533
|
+
path: (issue.path ?? []).filter((part) => typeof part !== "symbol"),
|
|
534
|
+
message: issue.message ?? ""
|
|
535
|
+
});
|
|
536
|
+
} });
|
|
537
|
+
return issues;
|
|
538
|
+
}
|
|
539
|
+
/** withPlacementKeys' check, for a merged declared host parsed some other way. */
|
|
540
|
+
function placementKeyIssues(host) {
|
|
541
|
+
return collectIssues(host, refineDeclaredPlacementKeys);
|
|
542
|
+
}
|
|
543
|
+
const CONNECT_PRIMARY_MESSAGE = "Connect doesn't use placement.primary. To choose where new drives go, use placement.newDrives.";
|
|
544
|
+
/**
|
|
545
|
+
* A Connect host's placement rules, in either form. The router's primary is
|
|
546
|
+
* the browser reactor, else the `newDrives` switchboard, else the only one,
|
|
547
|
+
* so `placement.primary` means nothing here, and a Connect with several
|
|
548
|
+
* switchboards and no browser reactor must say where new drives go. Apply it
|
|
549
|
+
* last to the Connect runner's schema: `.superRefine(refineConnectReactor)`.
|
|
550
|
+
*/
|
|
551
|
+
function refineConnectReactor(host, ctx) {
|
|
552
|
+
const reactor = host.reactor;
|
|
553
|
+
if (!reactor) return;
|
|
554
|
+
if (reactor.placement?.primary !== void 0) ctx.addIssue({
|
|
555
|
+
code: "custom",
|
|
556
|
+
path: [
|
|
557
|
+
"reactor",
|
|
558
|
+
"placement",
|
|
559
|
+
"primary"
|
|
560
|
+
],
|
|
561
|
+
message: CONNECT_PRIMARY_MESSAGE
|
|
562
|
+
});
|
|
563
|
+
const backends = Object.entries(reactor.backends ?? {});
|
|
564
|
+
const remotes = backends.filter(([, backend]) => backend.kind === "remote").map(([name]) => name);
|
|
565
|
+
if (remotes.length > 1 && remotes.length === backends.length && reactor.placement?.newDrives === void 0) ctx.addIssue({
|
|
566
|
+
code: "custom",
|
|
567
|
+
path: [
|
|
568
|
+
"reactor",
|
|
569
|
+
"placement",
|
|
570
|
+
"newDrives"
|
|
571
|
+
],
|
|
572
|
+
message: `This Connect keeps no reactor in the browser and links ${remotes.length} switchboards (${remotes.join(", ")}). Set placement.newDrives to the one new drives are created on.`
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
/** refineConnectReactor's check, for a Connect host parsed some other way. */
|
|
576
|
+
function connectReactorIssues(host) {
|
|
577
|
+
return collectIssues(host, refineConnectReactor);
|
|
578
|
+
}
|
|
579
|
+
/** Adds the host-level placement key check to a runner's declared schema. */
|
|
580
|
+
function withPlacementKeys(schema) {
|
|
581
|
+
if (!(schema instanceof z.ZodType)) return schema;
|
|
582
|
+
return schema.superRefine((host, ctx) => {
|
|
583
|
+
if (typeof host === "object" && host !== null && "reactor" in host) refineDeclaredPlacementKeys(host, ctx);
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* One runner definition, two schemas (3.5): `build` runs over the DECLARED
|
|
588
|
+
* set (tokens allowed; its z.input types host files) and the RESOLVED set
|
|
589
|
+
* (no tokens; `validateHost` checks it before the verb). Export both, type
|
|
590
|
+
* the host as `z.input<typeof declaredHostSchema>`, refine last inside the
|
|
591
|
+
* builder (zod can't extend a refined object), and wrap the runner's own
|
|
592
|
+
* token-able fields with `s.tokenable` / `s.envTokenable`.
|
|
593
|
+
*/
|
|
594
|
+
function defineHostSchemas(build) {
|
|
595
|
+
return {
|
|
596
|
+
declaredHostSchema: withPlacementKeys(build(declaredSchemas)),
|
|
597
|
+
hostSchema: build(resolvedSchemas)
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
const declaredSchemas = makeHostSchemas({ tokens: "allow" });
|
|
601
|
+
const resolvedSchemas = makeHostSchemas({ tokens: "forbid" });
|
|
602
|
+
const declaredHostSchemas = declaredSchemas;
|
|
603
|
+
const reactorBackendSchema = resolvedSchemas.reactorBackendSchema;
|
|
604
|
+
const reactorSchema = resolvedSchemas.reactorSchema;
|
|
605
|
+
const runnerBaseSchema = resolvedSchemas.runnerBaseSchema;
|
|
606
|
+
const childWrapperSchema = resolvedSchemas.childWrapperSchema;
|
|
607
|
+
const childrenSchema = resolvedSchemas.childrenSchema;
|
|
608
|
+
const reactorHostSchema = resolvedSchemas.reactorHostSchema;
|
|
609
|
+
const compoundHostSchema = resolvedSchemas.compoundHostSchema;
|
|
610
|
+
/** The generic compound runner's host: the base with its wiring config. */
|
|
611
|
+
const genericCompound = defineHostSchemas((s) => s.compoundHostSchema.extend({ config: compoundWiringSchema.optional() }).superRefine(refineStartOrder));
|
|
612
|
+
const genericCompoundHostSchema = genericCompound.hostSchema;
|
|
613
|
+
const declaredGenericCompoundHostSchema = genericCompound.declaredHostSchema;
|
|
614
|
+
const SCHEMA_BASE = "https://powerhouse.inc/schemas";
|
|
615
|
+
/** One host schema as an editor JSON Schema with a stable `$id` — the
|
|
616
|
+
* per-runner emission helper (runner packages emit their own hostSchema). */
|
|
617
|
+
function emitHostJsonSchema(name, schema) {
|
|
618
|
+
return {
|
|
619
|
+
$id: `${SCHEMA_BASE}/${name}.schema.json`,
|
|
620
|
+
...z.toJSONSchema(schema, { io: "input" })
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
/** The emitted-schema set, keyed by published filename. Pure — the
|
|
624
|
+
* emit-schemas script writes these and the drift test re-derives them. */
|
|
625
|
+
function emittedHostSchemas() {
|
|
626
|
+
return {
|
|
627
|
+
"host-reactor.schema.json": emitHostJsonSchema("host-reactor", declaredSchemas.reactorHostSchema),
|
|
628
|
+
"host-compound.schema.json": emitHostJsonSchema("host-compound", declaredSchemas.compoundHostSchema)
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
//#endregion
|
|
632
|
+
//#region src/env-substitution.ts
|
|
633
|
+
/** The always-resolvable `$env` names (also the `"${name}"` sugar). */
|
|
634
|
+
const BUILTIN_ENV_NAMES = ["userData", "projectRoot"];
|
|
635
|
+
function isBuiltinEnvName(name) {
|
|
636
|
+
return BUILTIN_ENV_NAMES.includes(name);
|
|
637
|
+
}
|
|
638
|
+
const BUILTIN = new RegExp(`\\$\\{(${BUILTIN_ENV_NAMES.join("|")})\\}`, "g");
|
|
639
|
+
function substitute(text, env) {
|
|
640
|
+
return text.replace(BUILTIN, (match, name) => env[name] ?? match);
|
|
641
|
+
}
|
|
642
|
+
/** Deep-substitute the built-ins that `env` provides in every string; an
|
|
643
|
+
* absent built-in is left as written. The input is never mutated. */
|
|
644
|
+
function substituteBuiltinEnv(value, env) {
|
|
645
|
+
return substituteValue(value, env);
|
|
646
|
+
}
|
|
647
|
+
function substituteValue(value, env) {
|
|
648
|
+
if (typeof value === "string") return substitute(value, env);
|
|
649
|
+
if (Array.isArray(value)) return value.map((v) => substituteValue(v, env));
|
|
650
|
+
if (value !== null && typeof value === "object") {
|
|
651
|
+
const out = {};
|
|
652
|
+
for (const [k, v] of Object.entries(value)) out[k] = substituteValue(v, env);
|
|
653
|
+
return out;
|
|
654
|
+
}
|
|
655
|
+
return value;
|
|
656
|
+
}
|
|
657
|
+
//#endregion
|
|
658
|
+
export { runnerKindSchema as A, findToken as B, reactorBackendSchema as C, refineConnectReactor as D, reactorSchema as E, TOKEN_ESCAPE_KEY as F, mapTokenSchema as G, isToken as H, TOKEN_KEYS as I, tokenKeyOf as J, outputTokenSchema as K, concatTokenSchema as L, driveDeclarationSchema as M, drivesSchema as N, refineStartOrder as O, projectDriveIdWith as P, envTokenSchema as R, reactorBackendKindSchema as S, reactorProtocolSchema as T, itemTokenSchema as U, forbidRef as V, keyTokenSchema as W, tokenable as X, tokenSchema as Y, genericCompoundHostSchema as _, HOST_NAME_MESSAGE as a, placementKeyIssues as b, childrenSchema as c, connectReactorIssues as d, declaredGenericCompoundHostSchema as f, emittedHostSchemas as g, emitHostJsonSchema as h, HOST_NAME_MAX_LENGTH as i, buildDriveDeclarationSchema as j, runnerBaseSchema as k, compoundHostSchema as l, defineHostSchemas as m, substituteBuiltinEnv as n, HOST_NAME_PATTERN as o, declaredHostSchemas as p, ref as q, CONNECT_PRIMARY_MESSAGE as r, childWrapperSchema as s, isBuiltinEnvName as t, compoundWiringSchema as u, hostNameSchema as v, reactorHostSchema as w, profileSchema as x, makeHostSchemas as y, envTokenable as z };
|
|
659
|
+
|
|
660
|
+
//# sourceMappingURL=env-substitution-BXGohOGN.mjs.map
|