@prisma/composer-cli 0.35.0-dev.7 → 0.36.0-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{dev-current-DMzFQ3va-BFke9qY1.mjs → dev-current-Brb4qugP-BOI9FJdz.mjs} +5 -5
- package/dist/{dev-current-DMzFQ3va-BFke9qY1.mjs.map → dev-current-Brb4qugP-BOI9FJdz.mjs.map} +1 -1
- package/dist/{execute-deploy-destroy-C13H3wl--Bm77oUoX.mjs → execute-deploy-destroy-CNt-xpE7-CMQCNQpY.mjs} +7 -5
- package/dist/execute-deploy-destroy-CNt-xpE7-CMQCNQpY.mjs.map +1 -0
- package/dist/{execute-dev-C_SQ02a6-DWWK9eHb.mjs → execute-dev-BUk-XWBJ-DaB9ma8z.mjs} +7 -7
- package/dist/{execute-dev-C_SQ02a6-DWWK9eHb.mjs.map → execute-dev-BUk-XWBJ-DaB9ma8z.mjs.map} +1 -1
- package/dist/{execute-dev-current-BlIyvq-Q-C4sNMnwc.mjs → execute-dev-current-BdEqeKAB-xCBBITAB.mjs} +4 -4
- package/dist/{execute-dev-current-BlIyvq-Q-C4sNMnwc.mjs.map → execute-dev-current-BdEqeKAB-xCBBITAB.mjs.map} +1 -1
- package/dist/{family-B2JZ8O7U-UyY_0Kcx.d.mts → family-B2JZ8O7U-P_rOUr4w.d.mts} +68 -17
- package/dist/family-B2JZ8O7U-P_rOUr4w.d.mts.map +1 -0
- package/dist/family.d.mts +1 -1
- package/dist/family.mjs +2 -2
- package/dist/family.mjs.map +1 -1
- package/dist/{generate-dev-stack-C-1HoAgz-CqAVoJrq.mjs → generate-dev-stack-BkkU2HLE-Dek3CkAQ.mjs} +3 -2
- package/dist/generate-dev-stack-BkkU2HLE-Dek3CkAQ.mjs.map +1 -0
- package/dist/{list-deployed-BR2xnLVQ.mjs → list-deployed-GhPuf0RC.mjs} +3 -3
- package/dist/{list-deployed-BR2xnLVQ.mjs.map → list-deployed-GhPuf0RC.mjs.map} +1 -1
- package/dist/testing.d.mts +1 -1
- package/dist/testing.mjs +1 -1
- package/dist/testing.mjs.map +1 -1
- package/dist/{validate-environment-ymM9O00_-PUgv-1i7.mjs → validate-environment-CEhUSEg2-ExABehBM.mjs} +319 -54
- package/dist/validate-environment-CEhUSEg2-ExABehBM.mjs.map +1 -0
- package/package.json +7 -7
- package/dist/execute-deploy-destroy-C13H3wl--Bm77oUoX.mjs.map +0 -1
- package/dist/family-B2JZ8O7U-UyY_0Kcx.d.mts.map +0 -1
- package/dist/generate-dev-stack-C-1HoAgz-CqAVoJrq.mjs.map +0 -1
- package/dist/validate-environment-ymM9O00_-PUgv-1i7.mjs.map +0 -1
|
@@ -101,7 +101,7 @@ async function assembleServices(graph, config, cwd, run, onEvent, options = {})
|
|
|
101
101
|
};
|
|
102
102
|
}
|
|
103
103
|
//#endregion
|
|
104
|
-
//#region ../../0-framework/1-core/core/dist/graph-
|
|
104
|
+
//#region ../../0-framework/1-core/core/dist/graph-MGOZJdDt.mjs
|
|
105
105
|
/** The reserved name of a resource's single anonymous output port. Rejected as a user-declared port name (node.ts). */
|
|
106
106
|
const RESOURCE_OUT_PORT = "$out";
|
|
107
107
|
/**
|
|
@@ -111,8 +111,8 @@ const RESOURCE_OUT_PORT = "$out";
|
|
|
111
111
|
* `CliStructuredError` — structural recognition depends on it.
|
|
112
112
|
*/
|
|
113
113
|
var LoadError = class extends CliStructuredError {
|
|
114
|
-
constructor(message) {
|
|
115
|
-
super("COMPOSE.GRAPH_INVALID", message);
|
|
114
|
+
constructor(message, options) {
|
|
115
|
+
super("COMPOSE.GRAPH_INVALID", message, options);
|
|
116
116
|
}
|
|
117
117
|
};
|
|
118
118
|
/** The declared style of an untrusted contract value, or `undefined` when it declares none. */
|
|
@@ -120,6 +120,30 @@ function contractStyleOf(contract) {
|
|
|
120
120
|
if (typeof contract !== "object" || contract === null || !("style" in contract)) return void 0;
|
|
121
121
|
return contract.style === "request-response" || contract.style === "stream" ? contract.style : void 0;
|
|
122
122
|
}
|
|
123
|
+
const VALUE = blindCast(Symbol.for("prisma:value"));
|
|
124
|
+
const VALUE_ORIGIN = blindCast(Symbol.for("prisma:value-origin"));
|
|
125
|
+
/** True if `value` is a `Value` (checks the brand only, never a prototype). */
|
|
126
|
+
function isValue(value) {
|
|
127
|
+
return typeof value === "object" && value !== null && blindCast(value)[VALUE] === true;
|
|
128
|
+
}
|
|
129
|
+
/** True for an object whose prototype is `Object.prototype` or `null`: the only objects Load walks into. */
|
|
130
|
+
function isPlainObject(value) {
|
|
131
|
+
if (typeof value !== "object" || value === null) return false;
|
|
132
|
+
const prototype = Object.getPrototypeOf(value);
|
|
133
|
+
return prototype === Object.prototype || prototype === null;
|
|
134
|
+
}
|
|
135
|
+
/** Where Load gets `value`'s real value. Internal to core. */
|
|
136
|
+
function originOf(value) {
|
|
137
|
+
return value[VALUE_ORIGIN];
|
|
138
|
+
}
|
|
139
|
+
/** The one `environment` object every module body receives. */
|
|
140
|
+
const environmentFacts = Object.freeze({ name: Object.freeze({
|
|
141
|
+
[VALUE]: true,
|
|
142
|
+
[VALUE_ORIGIN]: Object.freeze({
|
|
143
|
+
kind: "environment",
|
|
144
|
+
fact: "name"
|
|
145
|
+
})
|
|
146
|
+
}) });
|
|
123
147
|
/**
|
|
124
148
|
* Core model: node types and the factories that construct them, plain frozen
|
|
125
149
|
* data objects. A node's `extension` + `type` form its deploy-time registry key (ADR-0017).
|
|
@@ -155,6 +179,10 @@ function isConfigKeySegment(name) {
|
|
|
155
179
|
function isNode(value) {
|
|
156
180
|
return typeof value === "object" && value !== null && value[NODE] === true;
|
|
157
181
|
}
|
|
182
|
+
/** A node's dependency slots. A resource node built by another installed copy of core may have no `inputs`; that means none. */
|
|
183
|
+
function slotsOf(node) {
|
|
184
|
+
return node.kind === "resource" ? node.inputs ?? {} : node.inputs;
|
|
185
|
+
}
|
|
158
186
|
/**
|
|
159
187
|
* Stable topological sort: every edge's `from` precedes its `to` in the
|
|
160
188
|
* result. Ties (nodes with no ordering constraint between them) keep their
|
|
@@ -205,15 +233,15 @@ function topoSort(nodes, edges) {
|
|
|
205
233
|
return order.map((id) => byId.get(id)).filter((n) => n !== void 0);
|
|
206
234
|
}
|
|
207
235
|
/**
|
|
208
|
-
* The declared boundary ports of a module or
|
|
209
|
-
* as `in` ports (contractKind = the slot's `type`), exposed
|
|
210
|
-
* `out` ports (contractKind = the contract's `kind`, style = its
|
|
211
|
-
* style). A resource's one
|
|
212
|
-
*
|
|
236
|
+
* The declared boundary ports of a module, service or resource node at `id`:
|
|
237
|
+
* dep slots as `in` ports (contractKind = the slot's `type`), exposed
|
|
238
|
+
* contracts as `out` ports (contractKind = the contract's `kind`, style = its
|
|
239
|
+
* declared style). A resource's one `$out` port is recorded at its provision
|
|
240
|
+
* site instead (load-module.ts).
|
|
213
241
|
*/
|
|
214
242
|
function boundaryPortsOf(id, node) {
|
|
215
243
|
const ports = [];
|
|
216
|
-
const slots = node.kind === "module" ? node.deps : node
|
|
244
|
+
const slots = node.kind === "module" ? node.deps : slotsOf(node);
|
|
217
245
|
for (const [name, slot] of Object.entries(slots)) {
|
|
218
246
|
const type = typeof slot === "object" && slot !== null && "type" in slot && typeof slot.type === "string" ? slot.type : void 0;
|
|
219
247
|
ports.push({
|
|
@@ -224,7 +252,8 @@ function boundaryPortsOf(id, node) {
|
|
|
224
252
|
style: void 0
|
|
225
253
|
});
|
|
226
254
|
}
|
|
227
|
-
|
|
255
|
+
const expose = node.kind === "resource" ? {} : node.expose ?? {};
|
|
256
|
+
for (const [name, contract] of Object.entries(expose)) {
|
|
228
257
|
const kind = typeof contract === "object" && contract !== null && "kind" in contract && typeof contract.kind === "string" ? contract.kind : void 0;
|
|
229
258
|
ports.push({
|
|
230
259
|
node: id,
|
|
@@ -236,24 +265,26 @@ function boundaryPortsOf(id, node) {
|
|
|
236
265
|
}
|
|
237
266
|
return ports;
|
|
238
267
|
}
|
|
239
|
-
|
|
240
|
-
|
|
268
|
+
/** A resource node built by another installed copy of core may have no `inputs`; it has no slots. */
|
|
269
|
+
function slotNodesAndEdges(node, nodeId) {
|
|
270
|
+
const inputs = slotsOf(node);
|
|
271
|
+
if (typeof inputs !== "object" || inputs === null) throw new LoadError(`Node "${nodeId}" has no inputs map.`);
|
|
241
272
|
const nodes = [];
|
|
242
273
|
const edges = [];
|
|
243
|
-
for (const [input, value] of Object.entries(
|
|
274
|
+
for (const [input, value] of Object.entries(inputs)) {
|
|
244
275
|
const kind = isNode(value) ? value.kind : void 0;
|
|
245
|
-
if (kind === "resource") throw new LoadError(`
|
|
246
|
-
if (kind !== "dependency") throw new LoadError(`
|
|
247
|
-
if (value.type.length === 0) throw new LoadError(`
|
|
248
|
-
const id = `${
|
|
276
|
+
if (kind === "resource") throw new LoadError(`Dependency "${input}" of "${nodeId}" is a resource node — a resource is provisioned by the composing module, never created for a service that mentions it. Declare the input as a dependency (the pack's dependency factory) and wire the module-provisioned resource's ref into it.`);
|
|
277
|
+
if (kind !== "dependency") throw new LoadError(`Dependency "${input}" of "${nodeId}" is not a branded dependency end (construct it with the dependency() factory).`);
|
|
278
|
+
if (value.type.length === 0) throw new LoadError(`Dependency "${input}" of "${nodeId}" has an empty node type.`);
|
|
279
|
+
const id = `${nodeId}.${input}`;
|
|
249
280
|
nodes.push({
|
|
250
281
|
id,
|
|
251
|
-
parent:
|
|
282
|
+
parent: nodeId,
|
|
252
283
|
node: value
|
|
253
284
|
});
|
|
254
285
|
edges.push({
|
|
255
286
|
from: id,
|
|
256
|
-
to:
|
|
287
|
+
to: nodeId,
|
|
257
288
|
input,
|
|
258
289
|
kind: "input"
|
|
259
290
|
});
|
|
@@ -264,14 +295,14 @@ function serviceInputs(service, serviceId) {
|
|
|
264
295
|
};
|
|
265
296
|
}
|
|
266
297
|
function loadService(root, rootId) {
|
|
267
|
-
for (const [input, value] of Object.entries(root.inputs)) if (isNode(value) && value.kind === "dependency") throw new LoadError(`Service "${rootId}" has an unwired dependency
|
|
298
|
+
for (const [input, value] of Object.entries(root.inputs)) if (isNode(value) && value.kind === "dependency") throw new LoadError(`Service "${rootId}" has an unwired dependency "${input}" — this service is composed by a module; deploy the module instead of loading "${rootId}" directly.`);
|
|
268
299
|
if (root.inputSchema !== void 0) throw new LoadError(`Service "${rootId}" declares an input schema but is being loaded directly — a lone service has no enclosing scope to bind its input. Compose it inside a module whose provision() call binds \`input: { … }\` (ADR-0042).`);
|
|
269
300
|
const rootGraphNode = {
|
|
270
301
|
id: rootId,
|
|
271
302
|
parent: void 0,
|
|
272
303
|
node: root
|
|
273
304
|
};
|
|
274
|
-
const { nodes, edges } =
|
|
305
|
+
const { nodes, edges } = slotNodesAndEdges(root, rootId);
|
|
275
306
|
return {
|
|
276
307
|
root: rootGraphNode,
|
|
277
308
|
nodes: [...topoSort(nodes, edges), rootGraphNode],
|
|
@@ -282,6 +313,178 @@ function loadService(root, rootId) {
|
|
|
282
313
|
params: []
|
|
283
314
|
};
|
|
284
315
|
}
|
|
316
|
+
function joinPath(path, key) {
|
|
317
|
+
return path === "" ? String(key) : `${path}.${key}`;
|
|
318
|
+
}
|
|
319
|
+
function describeSite(site) {
|
|
320
|
+
switch (site.kind) {
|
|
321
|
+
case "input": return site.path === "" ? `the input binding of service "${site.address}"` : `input key "${site.path}" of service "${site.address}"`;
|
|
322
|
+
case "param": return `param "${site.path}" of service "${site.address}"`;
|
|
323
|
+
case "props": return site.path === "" ? `the props of resource "${site.address}"` : `prop "${site.path}" of resource "${site.address}"`;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
function collect(value, site, found, seen) {
|
|
327
|
+
if (isValue(value)) {
|
|
328
|
+
found.push({
|
|
329
|
+
value,
|
|
330
|
+
site
|
|
331
|
+
});
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
if (isSecretSource(value) || isParamSource(value)) return;
|
|
335
|
+
if (!Array.isArray(value) && !isPlainObject(value)) return;
|
|
336
|
+
if (seen.has(value)) return;
|
|
337
|
+
seen.add(value);
|
|
338
|
+
const entries = Array.isArray(value) ? value.map((member, index) => [index, member]) : Object.entries(value);
|
|
339
|
+
for (const [key, member] of entries) {
|
|
340
|
+
const path = site.kind === "param" ? site.path : joinPath(site.path, key);
|
|
341
|
+
collect(member, {
|
|
342
|
+
...site,
|
|
343
|
+
path
|
|
344
|
+
}, found, seen);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
function describeNotPlain(value) {
|
|
348
|
+
switch (typeof value) {
|
|
349
|
+
case "function": return "a function";
|
|
350
|
+
case "symbol": return "a symbol";
|
|
351
|
+
case "bigint": return "a bigint";
|
|
352
|
+
case "number": return Number.isFinite(value) ? void 0 : "a non-finite number";
|
|
353
|
+
case "object": return value === null || Array.isArray(value) || isPlainObject(value) ? void 0 : "an object that is not plain data";
|
|
354
|
+
default: return;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
function isThenable(value) {
|
|
358
|
+
return typeof value === "object" && value !== null && "then" in value && typeof value.then === "function";
|
|
359
|
+
}
|
|
360
|
+
function checkResult(result, fnLabel) {
|
|
361
|
+
if (isThenable(result)) throw new LoadError(`${fnLabel} returned a Promise. resolve() runs synchronously at Load.`);
|
|
362
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
363
|
+
const walk = (value, path) => {
|
|
364
|
+
const atPath = path === "" ? "" : ` at "${path}"`;
|
|
365
|
+
if (value === void 0) throw new LoadError(`${fnLabel} returned undefined${atPath}. Return a result for every environment; Composer never picks a default.`);
|
|
366
|
+
if (isValue(value)) throw new LoadError(`${fnLabel} returned a value${atPath}, not a real value. List that value as a dependency; fn receives its real value.`);
|
|
367
|
+
if (isSecretSource(value) || isParamSource(value)) throw new LoadError(`${fnLabel} returned a secret or param source${atPath}. Bind envSecret() or envParam() directly; resolve() returns plain data.`);
|
|
368
|
+
const notPlain = describeNotPlain(value);
|
|
369
|
+
if (notPlain !== void 0) throw new LoadError(`${fnLabel} returned ${notPlain}${atPath}. resolve() returns plain data: strings, finite numbers, booleans, null, arrays and plain objects.`);
|
|
370
|
+
if (typeof value !== "object" || value === null || seen.has(value)) return;
|
|
371
|
+
seen.add(value);
|
|
372
|
+
const entries = Array.isArray(value) ? value.map((member, index) => [index, member]) : Object.entries(value);
|
|
373
|
+
for (const [key, member] of entries) walk(member, joinPath(path, key));
|
|
374
|
+
};
|
|
375
|
+
walk(result, "");
|
|
376
|
+
}
|
|
377
|
+
function substitute(value, results, inProgress) {
|
|
378
|
+
if (isValue(value)) return results.get(value);
|
|
379
|
+
if (isSecretSource(value) || isParamSource(value)) return value;
|
|
380
|
+
if (Array.isArray(value)) {
|
|
381
|
+
if (inProgress.has(value)) return value;
|
|
382
|
+
inProgress.add(value);
|
|
383
|
+
const rebuilt = value.map((member) => substitute(member, results, inProgress));
|
|
384
|
+
inProgress.delete(value);
|
|
385
|
+
return rebuilt.every((member, index) => member === value[index]) ? value : rebuilt;
|
|
386
|
+
}
|
|
387
|
+
if (isPlainObject(value)) {
|
|
388
|
+
if (inProgress.has(value)) return value;
|
|
389
|
+
inProgress.add(value);
|
|
390
|
+
const rebuilt = {};
|
|
391
|
+
let changed = false;
|
|
392
|
+
for (const [key, member] of Object.entries(value)) {
|
|
393
|
+
rebuilt[key] = substitute(member, results, inProgress);
|
|
394
|
+
if (rebuilt[key] !== member) changed = true;
|
|
395
|
+
}
|
|
396
|
+
inProgress.delete(value);
|
|
397
|
+
return changed ? rebuilt : value;
|
|
398
|
+
}
|
|
399
|
+
return value;
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Resolves every value the graph binds, dependency-first, once each, and
|
|
403
|
+
* returns each binding with its values replaced by their real values.
|
|
404
|
+
*/
|
|
405
|
+
function resolveValues(input) {
|
|
406
|
+
const { environment } = input;
|
|
407
|
+
const found = [];
|
|
408
|
+
for (const { serviceAddress, binding } of input.inputBindings) collect(binding, {
|
|
409
|
+
address: serviceAddress,
|
|
410
|
+
kind: "input",
|
|
411
|
+
path: ""
|
|
412
|
+
}, found, /* @__PURE__ */ new WeakSet());
|
|
413
|
+
for (const { serviceAddress, slot, binding } of input.params) collect(binding, {
|
|
414
|
+
address: serviceAddress,
|
|
415
|
+
kind: "param",
|
|
416
|
+
path: slot
|
|
417
|
+
}, found, /* @__PURE__ */ new WeakSet());
|
|
418
|
+
for (const [address, resource] of input.resources) {
|
|
419
|
+
const site = {
|
|
420
|
+
address,
|
|
421
|
+
kind: "props",
|
|
422
|
+
path: ""
|
|
423
|
+
};
|
|
424
|
+
collect(resource.props, site, found, /* @__PURE__ */ new WeakSet());
|
|
425
|
+
}
|
|
426
|
+
const results = /* @__PURE__ */ new Map();
|
|
427
|
+
const visiting = [];
|
|
428
|
+
const fnLabelFor = (site) => visiting.length === 1 ? `The resolve() function for ${describeSite(site)}` : `A resolve() function that ${describeSite(site)} depends on`;
|
|
429
|
+
const resolveOne = (value, site) => {
|
|
430
|
+
if (results.has(value)) return results.get(value);
|
|
431
|
+
if (visiting.includes(value)) throw new LoadError(`${describeSite(site)} depends on itself: a computed value's dependencies lead back to it. Remove the cycle.`);
|
|
432
|
+
visiting.push(value);
|
|
433
|
+
const origin = originOf(value);
|
|
434
|
+
let result;
|
|
435
|
+
switch (origin.kind) {
|
|
436
|
+
case "environment":
|
|
437
|
+
if (environment === void 0) throw new LoadError(`${describeSite(site)} depends on environment.name, but Load was given no environment. Pass { environment: { name } } to Load; the deploy and dev commands do.`);
|
|
438
|
+
result = environment[origin.fact];
|
|
439
|
+
break;
|
|
440
|
+
case "computed": {
|
|
441
|
+
const args = origin.dependencies.map((dependency) => resolveOne(dependency, site));
|
|
442
|
+
try {
|
|
443
|
+
result = origin.compute(args);
|
|
444
|
+
} catch (thrown) {
|
|
445
|
+
if (thrown instanceof LoadError) throw thrown;
|
|
446
|
+
const message = thrown instanceof Error ? thrown.message : String(thrown);
|
|
447
|
+
throw new LoadError(`${fnLabelFor(site)} threw: ${message}`, { cause: thrown });
|
|
448
|
+
}
|
|
449
|
+
checkResult(result, fnLabelFor(site));
|
|
450
|
+
break;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
visiting.pop();
|
|
454
|
+
results.set(value, result);
|
|
455
|
+
return result;
|
|
456
|
+
};
|
|
457
|
+
for (const { value, site } of found) resolveOne(value, site);
|
|
458
|
+
const authoredProps = new Map([...input.resources].map(([address, resource]) => [address, resource.props]));
|
|
459
|
+
if (found.length === 0) return {
|
|
460
|
+
inputBindings: input.inputBindings,
|
|
461
|
+
params: input.params,
|
|
462
|
+
resourceProps: authoredProps
|
|
463
|
+
};
|
|
464
|
+
const inProgress = /* @__PURE__ */ new WeakSet();
|
|
465
|
+
const resourceProps = /* @__PURE__ */ new Map();
|
|
466
|
+
for (const [address, props] of authoredProps) {
|
|
467
|
+
const substituted = substitute(props, results, inProgress);
|
|
468
|
+
resourceProps.set(address, substituted === props ? props : blindCast(substituted));
|
|
469
|
+
}
|
|
470
|
+
return {
|
|
471
|
+
resourceProps,
|
|
472
|
+
inputBindings: input.inputBindings.map((entry) => {
|
|
473
|
+
const binding = substitute(entry.binding, results, inProgress);
|
|
474
|
+
return binding === entry.binding ? entry : {
|
|
475
|
+
serviceAddress: entry.serviceAddress,
|
|
476
|
+
binding: blindCast(binding)
|
|
477
|
+
};
|
|
478
|
+
}),
|
|
479
|
+
params: input.params.map((entry) => {
|
|
480
|
+
const binding = substitute(entry.binding, results, inProgress);
|
|
481
|
+
return binding === entry.binding ? entry : {
|
|
482
|
+
...entry,
|
|
483
|
+
binding
|
|
484
|
+
};
|
|
485
|
+
})
|
|
486
|
+
};
|
|
487
|
+
}
|
|
285
488
|
/**
|
|
286
489
|
* Brands a ref-port with the AUTHORED endpoint it stands for — which port of
|
|
287
490
|
* which node the author wired, before any forwarding chain resolves. Read
|
|
@@ -322,14 +525,17 @@ function refFor(id, service) {
|
|
|
322
525
|
});
|
|
323
526
|
}
|
|
324
527
|
/**
|
|
325
|
-
* The resource variant of refFor: a resource has
|
|
528
|
+
* The resource variant of refFor: a resource has at most one port — the
|
|
326
529
|
* contract it provides — flattened onto the ref itself, tagged with the
|
|
327
530
|
* provider id. `id` and the authored brand are written last so a hostile
|
|
328
|
-
* contract value cannot clobber them.
|
|
531
|
+
* contract value cannot clobber them. A resource that exposes nothing gets
|
|
532
|
+
* only its id.
|
|
329
533
|
*/
|
|
330
534
|
function refForResource(id, resource) {
|
|
535
|
+
const provides = resource.provides;
|
|
536
|
+
if (provides === void 0) return { id };
|
|
331
537
|
return blindCast({
|
|
332
|
-
...
|
|
538
|
+
...provides,
|
|
333
539
|
__providerId: id,
|
|
334
540
|
id,
|
|
335
541
|
[AUTHORED_PORT]: {
|
|
@@ -345,7 +551,7 @@ function producerIdOf(ref) {
|
|
|
345
551
|
if ("id" in ref && typeof ref.id === "string") return ref.id;
|
|
346
552
|
}
|
|
347
553
|
/**
|
|
348
|
-
* Brands each `ctx.
|
|
554
|
+
* Brands each `ctx.deps` entry with the input key it stands for (see
|
|
349
555
|
* flatten): diagnostic only — usage attribution relies on the per-key object
|
|
350
556
|
* identity the branding copy creates, never on reading this back.
|
|
351
557
|
*/
|
|
@@ -384,7 +590,7 @@ function validateWiring(pending, byId) {
|
|
|
384
590
|
for (const [input, rawValue] of Object.entries(deps)) {
|
|
385
591
|
const value = blindCast(rawValue);
|
|
386
592
|
if (!isNode(value) || wiring[input] !== void 0) continue;
|
|
387
|
-
if (value.kind === "dependency") throw new LoadError(`Dependency
|
|
593
|
+
if (value.kind === "dependency") throw new LoadError(`Dependency "${input}" of provisioned ${targetKind} "${targetId}" is not wired to a producer (module "${enclosingModuleName}").`);
|
|
388
594
|
}
|
|
389
595
|
}
|
|
390
596
|
/**
|
|
@@ -423,11 +629,12 @@ function wiringEdges(wiring, targetId) {
|
|
|
423
629
|
* but resolved inline (a source carries its own name, so no whole-graph pass
|
|
424
630
|
* is needed).
|
|
425
631
|
*/
|
|
426
|
-
function validateSecretBinding(child, id, secretWiring, enclosingModuleName) {
|
|
632
|
+
function validateSecretBinding(child, id, address, secretWiring, enclosingModuleName) {
|
|
427
633
|
const { kind } = child;
|
|
428
634
|
for (const slot of Object.keys(child.secretSlots)) {
|
|
429
635
|
const bound = secretWiring[slot];
|
|
430
636
|
if (bound === void 0) throw new LoadError(`Secret slot "${slot}" of provisioned ${kind} "${id}" is not bound (module "${enclosingModuleName}") — bind it with envSecret('NAME') or forward ctx.secrets.`);
|
|
637
|
+
if (isValue(bound)) throw new LoadError(`The secrets for "${address}" bind "${slot}" to a value. A value is not a secret source; bind envSecret('NAME') or a forwarded ctx.secrets ref.`);
|
|
431
638
|
if (!isSecretSource(bound)) throw new LoadError(`Secret slot "${slot}" of "${id}" (module "${enclosingModuleName}") was wired with a non-secret value — use envSecret('NAME') or a forwarded ctx.secrets ref.`);
|
|
432
639
|
}
|
|
433
640
|
for (const slot of Object.keys(secretWiring)) if (!Object.hasOwn(child.secretSlots, slot)) throw new LoadError(`The secrets for "${id}" name "${slot}", which is not a secret slot of that ${kind} (module "${enclosingModuleName}").`);
|
|
@@ -447,10 +654,11 @@ function validateServiceParamBinding(child, id, paramWiring, enclosingModuleName
|
|
|
447
654
|
* schema of its own, so (unlike a service param) it cannot fall back to a
|
|
448
655
|
* literal or a default; the param analog of `validateSecretBinding`.
|
|
449
656
|
*/
|
|
450
|
-
function validateParamNeedBinding(child, id, paramWiring, enclosingModuleName) {
|
|
657
|
+
function validateParamNeedBinding(child, id, address, paramWiring, enclosingModuleName) {
|
|
451
658
|
for (const slot of Object.keys(child.paramSlots)) {
|
|
452
659
|
const bound = paramWiring[slot];
|
|
453
660
|
if (bound === void 0) throw new LoadError(`Param slot "${slot}" of provisioned module "${id}" is not bound (module "${enclosingModuleName}") — bind it with a param source (e.g. envParam('NAME')) or forward ctx.params.`);
|
|
661
|
+
if (isValue(bound)) throw new LoadError(`The params for "${address}" bind "${slot}" to a value. A module param slot takes a param source; bind envParam('NAME') or a forwarded ctx.params ref.`);
|
|
454
662
|
if (!isParamSource(bound)) throw new LoadError(`Param slot "${slot}" of "${id}" (module "${enclosingModuleName}") was wired with a non-source value — a module param-forwarding slot carries no schema to validate a literal against; use envParam('NAME') or a forwarded ctx.params ref.`);
|
|
455
663
|
}
|
|
456
664
|
for (const slot of Object.keys(paramWiring)) if (!Object.hasOwn(child.paramSlots, slot)) throw new LoadError(`The params for "${id}" name "${slot}", which is not a param slot of that module (module "${enclosingModuleName}").`);
|
|
@@ -473,7 +681,7 @@ function validateParamNeedBinding(child, id, paramWiring, enclosingModuleName) {
|
|
|
473
681
|
* children carry it as their `parent`, and this module's own boundary ports
|
|
474
682
|
* (and the authored edges touching them) are recorded against it.
|
|
475
683
|
*/
|
|
476
|
-
function flatten(moduleNode, selfId, wiring, secretWiring, paramWiring, nodes, edges, pending, inputBindings, paramBindings, byId, ports, authoredEdges) {
|
|
684
|
+
function flatten(moduleNode, selfId, wiring, secretWiring, paramWiring, nodes, edges, pending, inputBindings, paramBindings, byId, ports, authoredEdges, loading) {
|
|
477
685
|
ports.push(...boundaryPortsOf(selfId, moduleNode));
|
|
478
686
|
const localIds = /* @__PURE__ */ new Set();
|
|
479
687
|
const used = /* @__PURE__ */ new Set();
|
|
@@ -540,11 +748,13 @@ function flatten(moduleNode, selfId, wiring, secretWiring, paramWiring, nodes, e
|
|
|
540
748
|
for (const value of values) for (const key of Object.keys(ctxParams)) if (value === ctxParams[key]) usedParams.add(key);
|
|
541
749
|
};
|
|
542
750
|
const provision = (child, opts) => {
|
|
751
|
+
if (loading.sealed) throw new LoadError(`provision() was called after module "${moduleNode.name}" was loaded, from inside a resolve() function. resolve() computes values, never structure: the graph is the same whatever inputs Composer is given (ADR-0062). Provision the node in the module body and pass the value into it.`);
|
|
543
752
|
const id = opts?.id ?? child.name;
|
|
544
753
|
const provisionWiring = opts?.deps;
|
|
545
754
|
const provisionSecrets = opts?.secrets;
|
|
546
755
|
const provisionInput = opts?.input;
|
|
547
756
|
const provisionParams = opts?.params;
|
|
757
|
+
if (isValue(id)) throw new LoadError(`provision() received a value as its id (module "${moduleNode.name}"). A value can configure a node, never decide its address: the graph is the same whatever inputs Composer is given (ADR-0062).`);
|
|
548
758
|
if (typeof id !== "string" || id.length === 0) throw new LoadError(`provision() requires a non-empty id (module "${moduleNode.name}").`);
|
|
549
759
|
if (!isConfigKeySegment(id)) throw new LoadError(`provision() id "${id}" (module "${moduleNode.name}") must contain only ASCII letters and digits ([A-Za-z0-9]) — the id becomes an address segment, and addresses derive deterministic config keys (segments uppercased and joined with "_"). "${id}" would put "${id.toUpperCase()}" inside the derived key. ("_" collides with the key separator and "." with the address separator.)`);
|
|
550
760
|
if (localIds.has(id)) throw new LoadError(`Duplicate provision id "${id}" in module "${moduleNode.name}".`);
|
|
@@ -553,26 +763,41 @@ function flatten(moduleNode, selfId, wiring, secretWiring, paramWiring, nodes, e
|
|
|
553
763
|
localIds.add(id);
|
|
554
764
|
const fullAddress = `${selfId}.${id}`;
|
|
555
765
|
if (child.kind === "resource") {
|
|
556
|
-
if (provisionWiring !== void 0) throw new LoadError(`provision("${id}") received deps for a resource — a resource
|
|
766
|
+
if (provisionWiring !== void 0) throw new LoadError(`provision("${id}") received deps for a resource — a resource's slots are wired when it is constructed, not at provision().`);
|
|
557
767
|
if (provisionSecrets !== void 0) throw new LoadError(`provision("${id}") received secrets for a resource — a resource has no secret slots to satisfy.`);
|
|
558
768
|
if (provisionInput !== void 0) throw new LoadError(`provision("${id}") received an input binding for a resource — a resource declares no input schema.`);
|
|
559
769
|
if (provisionParams !== void 0) throw new LoadError(`provision("${id}") received params for a resource — a resource has no params to satisfy.`);
|
|
560
770
|
if (child.type.length === 0) throw new LoadError(`provision("${id}") received a resource with an empty node type.`);
|
|
771
|
+
const localWiring = { ...child.deps };
|
|
772
|
+
markUsed(Object.values(localWiring));
|
|
561
773
|
byId.set(fullAddress, child);
|
|
562
|
-
|
|
774
|
+
const slots = slotNodesAndEdges(child, fullAddress);
|
|
775
|
+
nodes.push(...slots.nodes, {
|
|
563
776
|
id: fullAddress,
|
|
564
777
|
parent: selfId,
|
|
565
778
|
node: child
|
|
566
779
|
});
|
|
567
|
-
|
|
780
|
+
edges.push(...slots.edges, ...wiringEdges(localWiring, fullAddress));
|
|
781
|
+
ports.push(...boundaryPortsOf(fullAddress, child));
|
|
782
|
+
const provides = child.provides;
|
|
783
|
+
if (provides !== void 0) ports.push({
|
|
568
784
|
node: fullAddress,
|
|
569
785
|
direction: "out",
|
|
570
786
|
name: RESOURCE_OUT_PORT,
|
|
571
|
-
contractKind:
|
|
572
|
-
style: contractStyleOf(
|
|
787
|
+
contractKind: provides.kind,
|
|
788
|
+
style: contractStyleOf(provides)
|
|
789
|
+
});
|
|
790
|
+
recordAuthoredWiring(fullAddress, localWiring);
|
|
791
|
+
pending.push({
|
|
792
|
+
deps: child.inputs ?? {},
|
|
793
|
+
wiring: localWiring,
|
|
794
|
+
targetId: fullAddress,
|
|
795
|
+
targetKind: "resource",
|
|
796
|
+
enclosingModuleName: moduleNode.name
|
|
573
797
|
});
|
|
574
798
|
return refForResource(fullAddress, child);
|
|
575
799
|
}
|
|
800
|
+
for (const [input, ref] of Object.entries(provisionWiring ?? {})) if (isValue(ref)) throw new LoadError(`The deps for "${fullAddress}.${input}" are bound to a value. A value can configure a node, never decide its edges: the graph is the same whatever inputs Composer is given (ADR-0062).`);
|
|
576
801
|
const localWiring = { ...provisionWiring ?? {} };
|
|
577
802
|
markUsed(Object.values(localWiring));
|
|
578
803
|
const localSecrets = { ...provisionSecrets ?? {} };
|
|
@@ -599,7 +824,7 @@ function flatten(moduleNode, selfId, wiring, secretWiring, paramWiring, nodes, e
|
|
|
599
824
|
slot,
|
|
600
825
|
binding
|
|
601
826
|
});
|
|
602
|
-
const inputs =
|
|
827
|
+
const inputs = slotNodesAndEdges(child, fullAddress);
|
|
603
828
|
nodes.push(...inputs.nodes, {
|
|
604
829
|
id: fullAddress,
|
|
605
830
|
parent: selfId,
|
|
@@ -619,8 +844,8 @@ function flatten(moduleNode, selfId, wiring, secretWiring, paramWiring, nodes, e
|
|
|
619
844
|
return refFor(fullAddress, child);
|
|
620
845
|
}
|
|
621
846
|
if (provisionInput !== void 0) throw new LoadError(`provision("${id}") received an input binding for a module — a module has no input schema; bind the input on the service that declares it.`);
|
|
622
|
-
validateSecretBinding(child, id, localSecrets, moduleNode.name);
|
|
623
|
-
validateParamNeedBinding(child, id, localParams, moduleNode.name);
|
|
847
|
+
validateSecretBinding(child, id, fullAddress, localSecrets, moduleNode.name);
|
|
848
|
+
validateParamNeedBinding(child, id, fullAddress, localParams, moduleNode.name);
|
|
624
849
|
edges.push(...wiringEdges(localWiring, fullAddress));
|
|
625
850
|
recordAuthoredWiring(fullAddress, localWiring);
|
|
626
851
|
pending.push({
|
|
@@ -630,7 +855,7 @@ function flatten(moduleNode, selfId, wiring, secretWiring, paramWiring, nodes, e
|
|
|
630
855
|
targetKind: "module",
|
|
631
856
|
enclosingModuleName: moduleNode.name
|
|
632
857
|
});
|
|
633
|
-
const childOutputs = flatten(child, fullAddress, localWiring, localSecrets, localParams, nodes, edges, pending, inputBindings, paramBindings, byId, ports, authoredEdges);
|
|
858
|
+
const childOutputs = flatten(child, fullAddress, localWiring, localSecrets, localParams, nodes, edges, pending, inputBindings, paramBindings, byId, ports, authoredEdges, loading);
|
|
634
859
|
nodes.push({
|
|
635
860
|
id: fullAddress,
|
|
636
861
|
parent: selfId,
|
|
@@ -651,14 +876,15 @@ function flatten(moduleNode, selfId, wiring, secretWiring, paramWiring, nodes, e
|
|
|
651
876
|
});
|
|
652
877
|
};
|
|
653
878
|
const ctx = blindCast({
|
|
654
|
-
|
|
879
|
+
deps: ctxInputs,
|
|
655
880
|
secrets: ctxSecrets,
|
|
656
881
|
params: ctxParams,
|
|
882
|
+
environment: environmentFacts,
|
|
657
883
|
provision: blindCast(provision)
|
|
658
884
|
});
|
|
659
885
|
const outputs = blindCast(moduleNode.body(ctx) ?? {});
|
|
660
886
|
markUsed(Object.values(outputs));
|
|
661
|
-
for (const key of Object.keys(moduleNode.deps)) if (!used.has(key)) throw new LoadError(`Module "${moduleNode.name}" declares
|
|
887
|
+
for (const key of Object.keys(moduleNode.deps)) if (!used.has(key)) throw new LoadError(`Module "${moduleNode.name}" declares dependency "${key}" but never forwards it into a provision nor returns it as an exposed interface.`);
|
|
662
888
|
for (const key of Object.keys(moduleNode.secretSlots)) if (!usedSecrets.has(key)) throw new LoadError(`Module "${moduleNode.name}" declares secret "${key}" but never forwards it into a provision.`);
|
|
663
889
|
for (const key of Object.keys(moduleNode.paramSlots)) if (!usedParams.has(key)) throw new LoadError(`Module "${moduleNode.name}" declares param "${key}" but never forwards it into a provision.`);
|
|
664
890
|
for (const [key, contract] of Object.entries(moduleNode.expose)) {
|
|
@@ -682,7 +908,7 @@ function loadModule(root, opts) {
|
|
|
682
908
|
const rootDepKeys = Object.keys(root.deps);
|
|
683
909
|
if (rootDepKeys.length > 0) {
|
|
684
910
|
const names = rootDepKeys.map((k) => `"${k}"`).join(", ");
|
|
685
|
-
throw new LoadError(`Module "${root.name}" declares
|
|
911
|
+
throw new LoadError(`Module "${root.name}" declares ${rootDepKeys.length > 1 ? "dependencies" : "dependency"} ${names} but is being deployed as the root — a root has no enclosing scope to wire them; compose "${root.name}" from another module that provisions and wires it instead.`);
|
|
686
912
|
}
|
|
687
913
|
const rootSecretKeys = Object.keys(root.secretSlots);
|
|
688
914
|
if (rootSecretKeys.length > 0) {
|
|
@@ -702,9 +928,30 @@ function loadModule(root, opts) {
|
|
|
702
928
|
const byId = /* @__PURE__ */ new Map();
|
|
703
929
|
const ports = [];
|
|
704
930
|
const authoredEdges = [];
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
931
|
+
const loading = { sealed: false };
|
|
932
|
+
try {
|
|
933
|
+
flatten(root, rootId, {}, {}, {}, nodes, edges, pending, inputBindings, paramBindings, byId, ports, authoredEdges, loading);
|
|
934
|
+
for (const entry of pending) validateWiring(entry, byId);
|
|
935
|
+
assertDependencyDag(edges);
|
|
936
|
+
} finally {
|
|
937
|
+
loading.sealed = true;
|
|
938
|
+
}
|
|
939
|
+
const resources = /* @__PURE__ */ new Map();
|
|
940
|
+
for (const [address, node] of byId) if (node.kind === "resource") resources.set(address, node);
|
|
941
|
+
const resolved = resolveValues({
|
|
942
|
+
environment: opts?.environment,
|
|
943
|
+
inputBindings,
|
|
944
|
+
params: paramBindings,
|
|
945
|
+
resources
|
|
946
|
+
});
|
|
947
|
+
const resolvedNodes = nodes.map((entry) => {
|
|
948
|
+
const props = resolved.resourceProps.get(entry.id);
|
|
949
|
+
if (entry.node.kind !== "resource" || props === void 0 || props === entry.node.props) return entry;
|
|
950
|
+
return {
|
|
951
|
+
...entry,
|
|
952
|
+
node: withResolvedProps(entry.node, props)
|
|
953
|
+
};
|
|
954
|
+
});
|
|
708
955
|
const rootGraphNode = {
|
|
709
956
|
id: rootId,
|
|
710
957
|
parent: void 0,
|
|
@@ -712,18 +959,32 @@ function loadModule(root, opts) {
|
|
|
712
959
|
};
|
|
713
960
|
return {
|
|
714
961
|
root: rootGraphNode,
|
|
715
|
-
nodes: [...topoSort(
|
|
962
|
+
nodes: [...topoSort(resolvedNodes, edges), rootGraphNode],
|
|
716
963
|
edges,
|
|
717
964
|
ports,
|
|
718
965
|
authoredEdges,
|
|
719
|
-
inputBindings,
|
|
720
|
-
params:
|
|
966
|
+
inputBindings: resolved.inputBindings,
|
|
967
|
+
params: resolved.params
|
|
721
968
|
};
|
|
722
969
|
}
|
|
723
970
|
/**
|
|
971
|
+
* A frozen copy of `node` holding `props`, keeping its prototype (a class built
|
|
972
|
+
* on `ResourceNodeBase` keeps its methods) and its own properties, the brand included.
|
|
973
|
+
*/
|
|
974
|
+
function withResolvedProps(node, props) {
|
|
975
|
+
return Object.freeze(Object.create(Object.getPrototypeOf(node), {
|
|
976
|
+
...Object.getOwnPropertyDescriptors(node),
|
|
977
|
+
props: {
|
|
978
|
+
value: Object.freeze(props),
|
|
979
|
+
enumerable: true,
|
|
980
|
+
writable: false,
|
|
981
|
+
configurable: false
|
|
982
|
+
}
|
|
983
|
+
}));
|
|
984
|
+
}
|
|
985
|
+
/**
|
|
724
986
|
* The dependency edges must form a DAG — a cycle means neither producer can
|
|
725
|
-
* deploy first.
|
|
726
|
-
* edges can ever participate in a cycle; no special-casing needed.
|
|
987
|
+
* deploy first. A resource with dependency slots can take part in a cycle too.
|
|
727
988
|
*/
|
|
728
989
|
function assertDependencyDag(edges) {
|
|
729
990
|
const adjacency = /* @__PURE__ */ new Map();
|
|
@@ -763,7 +1024,8 @@ function assertAppName(name) {
|
|
|
763
1024
|
* module it provisions into one graph of hierarchical addresses. A malformed
|
|
764
1025
|
* graph is a `LoadError` that names its fix; the individual validation rules
|
|
765
1026
|
* live with `loadService` / `loadModule` and are covered by name in the Load
|
|
766
|
-
* tests. Executes nothing of the user's own code beyond module bodies
|
|
1027
|
+
* tests. Executes nothing of the user's own code beyond module bodies and `resolve()`
|
|
1028
|
+
* functions.
|
|
767
1029
|
*/
|
|
768
1030
|
function Load(root, opts) {
|
|
769
1031
|
if (!isNode(root)) throw new LoadError("Load expects a branded service or module node (construct it with the service()/module() factories).");
|
|
@@ -776,7 +1038,7 @@ function Load(root, opts) {
|
|
|
776
1038
|
}
|
|
777
1039
|
blindCast(Symbol.for("prisma:secret-box"));
|
|
778
1040
|
//#endregion
|
|
779
|
-
//#region ../../0-framework/3-tooling/cli/dist/validate-environment-
|
|
1041
|
+
//#region ../../0-framework/3-tooling/cli/dist/validate-environment-CEhUSEg2.mjs
|
|
780
1042
|
/**
|
|
781
1043
|
* Synchronous Node resolve hook so that entry modules may import relative
|
|
782
1044
|
* files using the specifier forms TypeScript accepts by default —
|
|
@@ -1037,14 +1299,17 @@ async function resolveAppIdentity(entry, overrideName, cwd, config) {
|
|
|
1037
1299
|
* guidance (destroy's "build first" hint) without this shared step knowing
|
|
1038
1300
|
* about any one command.
|
|
1039
1301
|
*/
|
|
1040
|
-
async function runPipeline(entry, overrideName, cwd, source, deps = {}, onAssembleError) {
|
|
1302
|
+
async function runPipeline(entry, overrideName, environment, cwd, source, deps = {}, onAssembleError) {
|
|
1041
1303
|
const configSource = checkConfigSource(source, cwd);
|
|
1042
1304
|
const config = configSource.value;
|
|
1043
1305
|
const resolved = resolveEntryPath(entry, configSource, cwd);
|
|
1044
1306
|
const entryModule = await loadEntry(resolved.path, cwd, resolved.fix);
|
|
1045
1307
|
const name = overrideName ?? entryModule.root.name;
|
|
1046
1308
|
if (name.length === 0) throw new CliStructuredError("COMPOSE.NAME_MISSING", "The root node has no name.", { fix: "Name it at authoring, or pass --name." });
|
|
1047
|
-
const graph = Load(entryModule.root, {
|
|
1309
|
+
const graph = Load(entryModule.root, {
|
|
1310
|
+
id: name,
|
|
1311
|
+
environment: { name: environment }
|
|
1312
|
+
});
|
|
1048
1313
|
if (graph.root.node.kind !== "module") throw new CliStructuredError("COMPOSE.ROOT_NOT_MODULE", "The deploy root must be a module.", { fix: "Wrap your service, e.g. export default module('name', ({ provision }) => { provision(service); })." });
|
|
1049
1314
|
validateRegistryCoverage(graph, config);
|
|
1050
1315
|
deps.onEvent?.({ kind: "loaded" });
|
|
@@ -1075,4 +1340,4 @@ function validateEnvironmentName(environment, spawn = spawnSync) {
|
|
|
1075
1340
|
//#endregion
|
|
1076
1341
|
export { validateEnvironmentName as i, resolveAppIdentity as n, runPipeline as r, checkConfigSource as t };
|
|
1077
1342
|
|
|
1078
|
-
//# sourceMappingURL=validate-environment-
|
|
1343
|
+
//# sourceMappingURL=validate-environment-CEhUSEg2-ExABehBM.mjs.map
|