@prisma/composer 0.35.0 → 0.36.0
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/app-config-CErnR6NK-D9NgSBH4.mjs +36 -0
- package/dist/app-config-CErnR6NK-D9NgSBH4.mjs.map +1 -0
- package/dist/{app-config-B_gQYj3K-DpMi9a4K.d.mts → app-config-DNnd7Zu--BQ1vHaMK.d.mts} +53 -31
- package/dist/app-config-DNnd7Zu--BQ1vHaMK.d.mts.map +1 -0
- package/dist/{config-CdxvLFzg.mjs → config-BFuriECI.mjs} +8 -5
- package/dist/config-BFuriECI.mjs.map +1 -0
- package/dist/config-RKyUvtGC.d.mts +1 -0
- package/dist/config.d.mts +3 -3
- package/dist/config.mjs +3 -3
- package/dist/control.d.mts +34 -26
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +20 -4
- package/dist/control.mjs.map +1 -1
- package/dist/deploy-RKyUvtGC.d.mts +1 -0
- package/dist/deploy.d.mts +3 -3
- package/dist/deploy.mjs +30 -15
- package/dist/deploy.mjs.map +1 -1
- package/dist/{deployment-summary-p88NV5m5-DTkPLzTp.d.mts → deployment-summary-p88NV5m5-SaPCCX2C.d.mts} +3 -3
- package/dist/{deployment-summary-p88NV5m5-DTkPLzTp.d.mts.map → deployment-summary-p88NV5m5-SaPCCX2C.d.mts.map} +1 -1
- package/dist/{dev-current-BB02pfSh-D-dYHs1q.mjs → dev-current-Brb4qugP-CG0_96FZ.mjs} +42 -8
- package/dist/dev-current-Brb4qugP-CG0_96FZ.mjs.map +1 -0
- package/dist/dev-environment-name-6eEr5PW8-CGk1ijP7.mjs +43 -0
- package/dist/dev-environment-name-6eEr5PW8-CGk1ijP7.mjs.map +1 -0
- package/dist/{dist-Xd2Pp_-u.mjs → dist-CZ_yEZ7F.mjs} +2 -2
- package/dist/dist-CZ_yEZ7F.mjs.map +1 -0
- package/dist/{execute-deploy-destroy-DwcoZIks-Cl-tWvo0.mjs → execute-deploy-destroy-CNt-xpE7-CYaa3sYk.mjs} +30 -35
- package/dist/execute-deploy-destroy-CNt-xpE7-CYaa3sYk.mjs.map +1 -0
- package/dist/{execute-dev-BHRWoEnd-D-YNpuEN.mjs → execute-dev-BUk-XWBJ-ZHX5A8cR.mjs} +60 -33
- package/dist/execute-dev-BUk-XWBJ-ZHX5A8cR.mjs.map +1 -0
- package/dist/{execute-dev-current-D4RkOtPA-CDBtbQUq.mjs → execute-dev-current-BdEqeKAB-BLUs2eQv.mjs} +71 -35
- package/dist/execute-dev-current-BdEqeKAB-BLUs2eQv.mjs.map +1 -0
- package/dist/{execute-log-DxjUaSwN-nVFDjZqy.mjs → execute-log-aiHhujIh-C_aXmb6j.mjs} +12 -8
- package/dist/execute-log-aiHhujIh-C_aXmb6j.mjs.map +1 -0
- package/dist/{graph-BmTgCiFm-qR5hnhOZ.d.mts → graph-BzTSXnoQ-BvGVq0bm.d.mts} +6 -7
- package/dist/graph-BzTSXnoQ-BvGVq0bm.d.mts.map +1 -0
- package/dist/{graph-D0ICjejE-CeQtHY5B.mjs → graph-MGOZJdDt-CyI8-9r7.mjs} +377 -58
- package/dist/graph-MGOZJdDt-CyI8-9r7.mjs.map +1 -0
- package/dist/{graph-types-Cegbwb_X-BU-H2pnt.d.mts → graph-types-DfsG9Rkg-D_ARjMo7.d.mts} +111 -25
- package/dist/graph-types-DfsG9Rkg-D_ARjMo7.d.mts.map +1 -0
- package/dist/http.d.mts +2 -2
- package/dist/http.mjs +2 -2
- package/dist/{index-B-9Dc0J7.d.mts → index-D89ftK2z.d.mts} +3 -3
- package/dist/{index-B-9Dc0J7.d.mts.map → index-D89ftK2z.d.mts.map} +1 -1
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +3 -3
- package/dist/{local-target-BUZG9uLx.mjs → local-target-DySKw61w.mjs} +2 -2
- package/dist/local-target-DySKw61w.mjs.map +1 -0
- package/dist/local-target.d.mts +2 -2
- package/dist/local-target.mjs +3 -3
- package/dist/{nextjs-DLyeRR7M-kVartQq-.d.mts → nextjs-DLyeRR7M-BeiYsLuZ.d.mts} +3 -3
- package/dist/{nextjs-DLyeRR7M-kVartQq-.d.mts.map → nextjs-DLyeRR7M-BeiYsLuZ.d.mts.map} +1 -1
- package/dist/nextjs-control.d.mts +4 -4
- package/dist/nextjs.d.mts +1 -1
- package/dist/node-control.d.mts +3 -3
- package/dist/node.d.mts +2 -2
- package/dist/report.d.mts +3 -3
- package/dist/{run-report-C2o98uD--AX8kpz4Q.mjs → run-report-CmBz2-xc-S50d4g5V.mjs} +5 -5
- package/dist/run-report-CmBz2-xc-S50d4g5V.mjs.map +1 -0
- package/dist/service-rpc.d.mts +2 -2
- package/dist/service-rpc.mjs +2 -2
- package/dist/testing.d.mts +1 -1
- package/dist/{pipeline-BmWt-Nhb-D9Eg14Sx.mjs → validate-environment-CEhUSEg2-DmAtiQhe.mjs} +20 -7
- package/dist/validate-environment-CEhUSEg2-DmAtiQhe.mjs.map +1 -0
- package/package.json +11 -11
- package/skills/prisma-composer-core-concepts/SKILL.md +84 -54
- package/dist/app-config-B_gQYj3K-DpMi9a4K.d.mts.map +0 -1
- package/dist/app-config-CGJHcFb--CIEFCG4V.mjs +0 -22
- package/dist/app-config-CGJHcFb--CIEFCG4V.mjs.map +0 -1
- package/dist/config-Bq3JlQ9_.d.mts +0 -1
- package/dist/config-CdxvLFzg.mjs.map +0 -1
- package/dist/deploy-Bq3JlQ9_.d.mts +0 -1
- package/dist/dev-current-BB02pfSh-D-dYHs1q.mjs.map +0 -1
- package/dist/dist-Xd2Pp_-u.mjs.map +0 -1
- package/dist/execute-deploy-destroy-DwcoZIks-Cl-tWvo0.mjs.map +0 -1
- package/dist/execute-dev-BHRWoEnd-D-YNpuEN.mjs.map +0 -1
- package/dist/execute-dev-current-D4RkOtPA-CDBtbQUq.mjs.map +0 -1
- package/dist/execute-log-DxjUaSwN-nVFDjZqy.mjs.map +0 -1
- package/dist/graph-BmTgCiFm-qR5hnhOZ.d.mts.map +0 -1
- package/dist/graph-D0ICjejE-CeQtHY5B.mjs.map +0 -1
- package/dist/graph-types-Cegbwb_X-BU-H2pnt.d.mts.map +0 -1
- package/dist/local-target-BUZG9uLx.mjs.map +0 -1
- package/dist/pipeline-BmWt-Nhb-D9Eg14Sx.mjs.map +0 -1
- package/dist/run-report-C2o98uD--AX8kpz4Q.mjs.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as blindCast } from "./casts-DpaahrlC-C5XMnP9S.mjs";
|
|
2
2
|
import { t as InternalError } from "./internal-error-Dfur7Zqt-D96dWHZK.mjs";
|
|
3
3
|
import { t as CliStructuredError } from "./errors-0e8IVwzi.mjs";
|
|
4
|
-
//#region ../../0-framework/1-core/core/dist/graph-
|
|
4
|
+
//#region ../../0-framework/1-core/core/dist/graph-MGOZJdDt.mjs
|
|
5
5
|
/** The reserved name of a resource's single anonymous output port. Rejected as a user-declared port name (node.ts). */
|
|
6
6
|
const RESOURCE_OUT_PORT = "$out";
|
|
7
7
|
/**
|
|
@@ -11,8 +11,8 @@ const RESOURCE_OUT_PORT = "$out";
|
|
|
11
11
|
* `CliStructuredError` — structural recognition depends on it.
|
|
12
12
|
*/
|
|
13
13
|
var LoadError = class extends CliStructuredError {
|
|
14
|
-
constructor(message) {
|
|
15
|
-
super("COMPOSE.GRAPH_INVALID", message);
|
|
14
|
+
constructor(message, options) {
|
|
15
|
+
super("COMPOSE.GRAPH_INVALID", message, options);
|
|
16
16
|
}
|
|
17
17
|
};
|
|
18
18
|
/** The declared style of an untrusted contract value, or `undefined` when it declares none. */
|
|
@@ -20,6 +20,53 @@ function contractStyleOf(contract) {
|
|
|
20
20
|
if (typeof contract !== "object" || contract === null || !("style" in contract)) return void 0;
|
|
21
21
|
return contract.style === "request-response" || contract.style === "stream" ? contract.style : void 0;
|
|
22
22
|
}
|
|
23
|
+
const VALUE = blindCast(Symbol.for("prisma:value"));
|
|
24
|
+
const VALUE_ORIGIN = blindCast(Symbol.for("prisma:value-origin"));
|
|
25
|
+
/**
|
|
26
|
+
* A value computed from other values. `fn` receives the dependencies' real
|
|
27
|
+
* values as one tuple, in order, and returns plain data. Load runs it after
|
|
28
|
+
* every module body, with `provision` disabled (ADR-0062). `fn` must be a pure
|
|
29
|
+
* function of its dependencies: a deploy runs it in two processes.
|
|
30
|
+
*/
|
|
31
|
+
function resolve(dependencies, fn) {
|
|
32
|
+
if (!Array.isArray(dependencies)) throw new Error("resolve() requires a tuple of values as its first argument.");
|
|
33
|
+
dependencies.forEach((dependency, index) => {
|
|
34
|
+
if (!isValue(dependency)) throw new Error(`resolve() dependency at index ${index} is not a value — list environment.name or another resolve() result.`);
|
|
35
|
+
});
|
|
36
|
+
if (typeof fn !== "function") throw new Error("resolve() requires a function as its second argument.");
|
|
37
|
+
const frozenDependencies = Object.freeze([...dependencies]);
|
|
38
|
+
const compute = blindCast(fn);
|
|
39
|
+
return Object.freeze({
|
|
40
|
+
[VALUE]: true,
|
|
41
|
+
[VALUE_ORIGIN]: Object.freeze({
|
|
42
|
+
kind: "computed",
|
|
43
|
+
dependencies: frozenDependencies,
|
|
44
|
+
compute
|
|
45
|
+
})
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/** True if `value` is a `Value` (checks the brand only, never a prototype). */
|
|
49
|
+
function isValue(value) {
|
|
50
|
+
return typeof value === "object" && value !== null && blindCast(value)[VALUE] === true;
|
|
51
|
+
}
|
|
52
|
+
/** True for an object whose prototype is `Object.prototype` or `null`: the only objects Load walks into. */
|
|
53
|
+
function isPlainObject(value) {
|
|
54
|
+
if (typeof value !== "object" || value === null) return false;
|
|
55
|
+
const prototype = Object.getPrototypeOf(value);
|
|
56
|
+
return prototype === Object.prototype || prototype === null;
|
|
57
|
+
}
|
|
58
|
+
/** Where Load gets `value`'s real value. Internal to core. */
|
|
59
|
+
function originOf(value) {
|
|
60
|
+
return value[VALUE_ORIGIN];
|
|
61
|
+
}
|
|
62
|
+
/** The one `environment` object every module body receives. */
|
|
63
|
+
const environmentFacts = Object.freeze({ name: Object.freeze({
|
|
64
|
+
[VALUE]: true,
|
|
65
|
+
[VALUE_ORIGIN]: Object.freeze({
|
|
66
|
+
kind: "environment",
|
|
67
|
+
fact: "name"
|
|
68
|
+
})
|
|
69
|
+
}) });
|
|
23
70
|
/**
|
|
24
71
|
* Core model: node types and the factories that construct them, plain frozen
|
|
25
72
|
* data objects. A node's `extension` + `type` form its deploy-time registry key (ADR-0017).
|
|
@@ -130,10 +177,38 @@ function freezeNode(node) {
|
|
|
130
177
|
Object.freeze(node);
|
|
131
178
|
return node;
|
|
132
179
|
}
|
|
180
|
+
/** The slots, wiring and configuration a resource may carry, checked once for `resource()` and `ResourceNodeBase`. */
|
|
181
|
+
function requireResourceWiring(def) {
|
|
182
|
+
const inputs = def.inputs ?? {};
|
|
183
|
+
const deps = def.deps ?? {};
|
|
184
|
+
requireConfigKeySegmentNames(Object.keys(inputs), "input", "resource");
|
|
185
|
+
for (const [input, slot] of Object.entries(inputs)) {
|
|
186
|
+
const declared = slot;
|
|
187
|
+
if (!isNode(declared) || declared.kind !== "dependency") throw new Error(`resource() dependency "${input}" is not a branded dependency end (construct it with the dependency() factory).`);
|
|
188
|
+
}
|
|
189
|
+
for (const input of Object.keys(inputs)) if (deps[input] === void 0) throw new Error(`resource() declares dependency "${input}" but its deps leave it unwired. A resource is wired when it is constructed.`);
|
|
190
|
+
for (const [input, producer] of Object.entries(deps)) {
|
|
191
|
+
if (!Object.hasOwn(inputs, input)) throw new Error(`resource() deps name "${input}", which is not a declared input.`);
|
|
192
|
+
if (isValue(producer)) throw new Error(`resource() deps wire "${input}" to a value. A value can configure a node, never decide its edges (ADR-0062).`);
|
|
193
|
+
}
|
|
194
|
+
if (def.props !== void 0 && !isPlainObject(def.props)) throw new Error("resource() props must be a plain object.");
|
|
195
|
+
}
|
|
196
|
+
/** A resource's routing `type`: its contract's `kind`, or the `type` named by a resource that offers nothing. */
|
|
197
|
+
function resourceType(def) {
|
|
198
|
+
const provides = def.provides;
|
|
199
|
+
if (provides === void 0) {
|
|
200
|
+
if (typeof def.type !== "string" || def.type.length === 0) throw new Error("resource() requires provides, the contract it offers, or type, for a resource that offers nothing.");
|
|
201
|
+
return def.type;
|
|
202
|
+
}
|
|
203
|
+
if (def.type !== void 0) throw new Error("resource() takes either provides or type, not both — type is the contract's kind when a contract is provided.");
|
|
204
|
+
if (typeof provides !== "object" || provides === null || !("kind" in provides) || typeof provides.kind !== "string" || provides.kind.length === 0 || !("satisfies" in provides) || typeof provides.satisfies !== "function") throw new Error("resource() requires `provides` — the Contract this resource offers (a non-empty `kind` plus its `satisfies()`).");
|
|
205
|
+
return provides.kind;
|
|
206
|
+
}
|
|
133
207
|
/**
|
|
134
208
|
* Everything `resource()` establishes, minus the freeze — an extension
|
|
135
209
|
* whose resource node carries extra fields extends this, assigns them, and
|
|
136
210
|
* calls `freezeNode(this)` as its constructor's last statement.
|
|
211
|
+
* A class built on this base must not use #private fields: Load copies a node whose props hold a value, and a copy carries own properties only.
|
|
137
212
|
*/
|
|
138
213
|
var ResourceNodeBase = class {
|
|
139
214
|
[NODE] = true;
|
|
@@ -142,15 +217,20 @@ var ResourceNodeBase = class {
|
|
|
142
217
|
extension;
|
|
143
218
|
type;
|
|
144
219
|
provides;
|
|
220
|
+
inputs;
|
|
221
|
+
deps;
|
|
222
|
+
props;
|
|
145
223
|
constructor(def) {
|
|
146
224
|
requireName(def.name, "resource");
|
|
147
225
|
requireExtension(def.extension, "resource");
|
|
148
|
-
|
|
149
|
-
|
|
226
|
+
this.type = resourceType(def);
|
|
227
|
+
requireResourceWiring(def);
|
|
150
228
|
this.name = def.name;
|
|
151
229
|
this.extension = def.extension;
|
|
152
|
-
this.
|
|
153
|
-
this.
|
|
230
|
+
this.provides = blindCast(def.provides);
|
|
231
|
+
this.inputs = blindCast(frozenShallowCopy(def.inputs ?? {}));
|
|
232
|
+
this.deps = blindCast(frozenShallowCopy(def.deps ?? {}));
|
|
233
|
+
this.props = blindCast(frozenShallowCopy(def.props ?? {}));
|
|
154
234
|
}
|
|
155
235
|
};
|
|
156
236
|
/** The core leaf: exactly the base, frozen. */
|
|
@@ -162,8 +242,9 @@ var FrozenResourceNode = class extends ResourceNodeBase {
|
|
|
162
242
|
};
|
|
163
243
|
/**
|
|
164
244
|
* Constructs a branded, frozen Resource node — an identity plus the Contract
|
|
165
|
-
* it provides; the routing `type` is the contract's `kind`.
|
|
166
|
-
*
|
|
245
|
+
* it provides; the routing `type` is the contract's `kind`. A resource that
|
|
246
|
+
* offers nothing omits `provides` and names its `type`. Pure — nothing is
|
|
247
|
+
* provisioned until a module provisions it.
|
|
167
248
|
*/
|
|
168
249
|
function resource(def) {
|
|
169
250
|
return new FrozenResourceNode(def);
|
|
@@ -252,6 +333,10 @@ function module(name, boundaryOrBody, maybeBody) {
|
|
|
252
333
|
function isNode(value) {
|
|
253
334
|
return typeof value === "object" && value !== null && value[NODE] === true;
|
|
254
335
|
}
|
|
336
|
+
/** A node's dependency slots. A resource node built by another installed copy of core may have no `inputs`; that means none. */
|
|
337
|
+
function slotsOf(node) {
|
|
338
|
+
return node.kind === "resource" ? node.inputs ?? {} : node.inputs;
|
|
339
|
+
}
|
|
255
340
|
/**
|
|
256
341
|
* Stable topological sort: every edge's `from` precedes its `to` in the
|
|
257
342
|
* result. Ties (nodes with no ordering constraint between them) keep their
|
|
@@ -302,15 +387,15 @@ function topoSort(nodes, edges) {
|
|
|
302
387
|
return order.map((id) => byId.get(id)).filter((n) => n !== void 0);
|
|
303
388
|
}
|
|
304
389
|
/**
|
|
305
|
-
* The declared boundary ports of a module or
|
|
306
|
-
* as `in` ports (contractKind = the slot's `type`), exposed
|
|
307
|
-
* `out` ports (contractKind = the contract's `kind`, style = its
|
|
308
|
-
* style). A resource's one
|
|
309
|
-
*
|
|
390
|
+
* The declared boundary ports of a module, service or resource node at `id`:
|
|
391
|
+
* dep slots as `in` ports (contractKind = the slot's `type`), exposed
|
|
392
|
+
* contracts as `out` ports (contractKind = the contract's `kind`, style = its
|
|
393
|
+
* declared style). A resource's one `$out` port is recorded at its provision
|
|
394
|
+
* site instead (load-module.ts).
|
|
310
395
|
*/
|
|
311
396
|
function boundaryPortsOf(id, node) {
|
|
312
397
|
const ports = [];
|
|
313
|
-
const slots = node.kind === "module" ? node.deps : node
|
|
398
|
+
const slots = node.kind === "module" ? node.deps : slotsOf(node);
|
|
314
399
|
for (const [name, slot] of Object.entries(slots)) {
|
|
315
400
|
const type = typeof slot === "object" && slot !== null && "type" in slot && typeof slot.type === "string" ? slot.type : void 0;
|
|
316
401
|
ports.push({
|
|
@@ -321,7 +406,8 @@ function boundaryPortsOf(id, node) {
|
|
|
321
406
|
style: void 0
|
|
322
407
|
});
|
|
323
408
|
}
|
|
324
|
-
|
|
409
|
+
const expose = node.kind === "resource" ? {} : node.expose ?? {};
|
|
410
|
+
for (const [name, contract] of Object.entries(expose)) {
|
|
325
411
|
const kind = typeof contract === "object" && contract !== null && "kind" in contract && typeof contract.kind === "string" ? contract.kind : void 0;
|
|
326
412
|
ports.push({
|
|
327
413
|
node: id,
|
|
@@ -333,24 +419,26 @@ function boundaryPortsOf(id, node) {
|
|
|
333
419
|
}
|
|
334
420
|
return ports;
|
|
335
421
|
}
|
|
336
|
-
|
|
337
|
-
|
|
422
|
+
/** A resource node built by another installed copy of core may have no `inputs`; it has no slots. */
|
|
423
|
+
function slotNodesAndEdges(node, nodeId) {
|
|
424
|
+
const inputs = slotsOf(node);
|
|
425
|
+
if (typeof inputs !== "object" || inputs === null) throw new LoadError(`Node "${nodeId}" has no inputs map.`);
|
|
338
426
|
const nodes = [];
|
|
339
427
|
const edges = [];
|
|
340
|
-
for (const [input, value] of Object.entries(
|
|
428
|
+
for (const [input, value] of Object.entries(inputs)) {
|
|
341
429
|
const kind = isNode(value) ? value.kind : void 0;
|
|
342
|
-
if (kind === "resource") throw new LoadError(`
|
|
343
|
-
if (kind !== "dependency") throw new LoadError(`
|
|
344
|
-
if (value.type.length === 0) throw new LoadError(`
|
|
345
|
-
const id = `${
|
|
430
|
+
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.`);
|
|
431
|
+
if (kind !== "dependency") throw new LoadError(`Dependency "${input}" of "${nodeId}" is not a branded dependency end (construct it with the dependency() factory).`);
|
|
432
|
+
if (value.type.length === 0) throw new LoadError(`Dependency "${input}" of "${nodeId}" has an empty node type.`);
|
|
433
|
+
const id = `${nodeId}.${input}`;
|
|
346
434
|
nodes.push({
|
|
347
435
|
id,
|
|
348
|
-
parent:
|
|
436
|
+
parent: nodeId,
|
|
349
437
|
node: value
|
|
350
438
|
});
|
|
351
439
|
edges.push({
|
|
352
440
|
from: id,
|
|
353
|
-
to:
|
|
441
|
+
to: nodeId,
|
|
354
442
|
input,
|
|
355
443
|
kind: "input"
|
|
356
444
|
});
|
|
@@ -361,14 +449,14 @@ function serviceInputs(service, serviceId) {
|
|
|
361
449
|
};
|
|
362
450
|
}
|
|
363
451
|
function loadService(root, rootId) {
|
|
364
|
-
for (const [input, value] of Object.entries(root.inputs)) if (isNode(value) && value.kind === "dependency") throw new LoadError(`Service "${rootId}" has an unwired dependency
|
|
452
|
+
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.`);
|
|
365
453
|
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).`);
|
|
366
454
|
const rootGraphNode = {
|
|
367
455
|
id: rootId,
|
|
368
456
|
parent: void 0,
|
|
369
457
|
node: root
|
|
370
458
|
};
|
|
371
|
-
const { nodes, edges } =
|
|
459
|
+
const { nodes, edges } = slotNodesAndEdges(root, rootId);
|
|
372
460
|
return {
|
|
373
461
|
root: rootGraphNode,
|
|
374
462
|
nodes: [...topoSort(nodes, edges), rootGraphNode],
|
|
@@ -379,6 +467,178 @@ function loadService(root, rootId) {
|
|
|
379
467
|
params: []
|
|
380
468
|
};
|
|
381
469
|
}
|
|
470
|
+
function joinPath(path, key) {
|
|
471
|
+
return path === "" ? String(key) : `${path}.${key}`;
|
|
472
|
+
}
|
|
473
|
+
function describeSite(site) {
|
|
474
|
+
switch (site.kind) {
|
|
475
|
+
case "input": return site.path === "" ? `the input binding of service "${site.address}"` : `input key "${site.path}" of service "${site.address}"`;
|
|
476
|
+
case "param": return `param "${site.path}" of service "${site.address}"`;
|
|
477
|
+
case "props": return site.path === "" ? `the props of resource "${site.address}"` : `prop "${site.path}" of resource "${site.address}"`;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
function collect(value, site, found, seen) {
|
|
481
|
+
if (isValue(value)) {
|
|
482
|
+
found.push({
|
|
483
|
+
value,
|
|
484
|
+
site
|
|
485
|
+
});
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
if (isSecretSource(value) || isParamSource(value)) return;
|
|
489
|
+
if (!Array.isArray(value) && !isPlainObject(value)) return;
|
|
490
|
+
if (seen.has(value)) return;
|
|
491
|
+
seen.add(value);
|
|
492
|
+
const entries = Array.isArray(value) ? value.map((member, index) => [index, member]) : Object.entries(value);
|
|
493
|
+
for (const [key, member] of entries) {
|
|
494
|
+
const path = site.kind === "param" ? site.path : joinPath(site.path, key);
|
|
495
|
+
collect(member, {
|
|
496
|
+
...site,
|
|
497
|
+
path
|
|
498
|
+
}, found, seen);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
function describeNotPlain(value) {
|
|
502
|
+
switch (typeof value) {
|
|
503
|
+
case "function": return "a function";
|
|
504
|
+
case "symbol": return "a symbol";
|
|
505
|
+
case "bigint": return "a bigint";
|
|
506
|
+
case "number": return Number.isFinite(value) ? void 0 : "a non-finite number";
|
|
507
|
+
case "object": return value === null || Array.isArray(value) || isPlainObject(value) ? void 0 : "an object that is not plain data";
|
|
508
|
+
default: return;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
function isThenable(value) {
|
|
512
|
+
return typeof value === "object" && value !== null && "then" in value && typeof value.then === "function";
|
|
513
|
+
}
|
|
514
|
+
function checkResult(result, fnLabel) {
|
|
515
|
+
if (isThenable(result)) throw new LoadError(`${fnLabel} returned a Promise. resolve() runs synchronously at Load.`);
|
|
516
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
517
|
+
const walk = (value, path) => {
|
|
518
|
+
const atPath = path === "" ? "" : ` at "${path}"`;
|
|
519
|
+
if (value === void 0) throw new LoadError(`${fnLabel} returned undefined${atPath}. Return a result for every environment; Composer never picks a default.`);
|
|
520
|
+
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.`);
|
|
521
|
+
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.`);
|
|
522
|
+
const notPlain = describeNotPlain(value);
|
|
523
|
+
if (notPlain !== void 0) throw new LoadError(`${fnLabel} returned ${notPlain}${atPath}. resolve() returns plain data: strings, finite numbers, booleans, null, arrays and plain objects.`);
|
|
524
|
+
if (typeof value !== "object" || value === null || seen.has(value)) return;
|
|
525
|
+
seen.add(value);
|
|
526
|
+
const entries = Array.isArray(value) ? value.map((member, index) => [index, member]) : Object.entries(value);
|
|
527
|
+
for (const [key, member] of entries) walk(member, joinPath(path, key));
|
|
528
|
+
};
|
|
529
|
+
walk(result, "");
|
|
530
|
+
}
|
|
531
|
+
function substitute(value, results, inProgress) {
|
|
532
|
+
if (isValue(value)) return results.get(value);
|
|
533
|
+
if (isSecretSource(value) || isParamSource(value)) return value;
|
|
534
|
+
if (Array.isArray(value)) {
|
|
535
|
+
if (inProgress.has(value)) return value;
|
|
536
|
+
inProgress.add(value);
|
|
537
|
+
const rebuilt = value.map((member) => substitute(member, results, inProgress));
|
|
538
|
+
inProgress.delete(value);
|
|
539
|
+
return rebuilt.every((member, index) => member === value[index]) ? value : rebuilt;
|
|
540
|
+
}
|
|
541
|
+
if (isPlainObject(value)) {
|
|
542
|
+
if (inProgress.has(value)) return value;
|
|
543
|
+
inProgress.add(value);
|
|
544
|
+
const rebuilt = {};
|
|
545
|
+
let changed = false;
|
|
546
|
+
for (const [key, member] of Object.entries(value)) {
|
|
547
|
+
rebuilt[key] = substitute(member, results, inProgress);
|
|
548
|
+
if (rebuilt[key] !== member) changed = true;
|
|
549
|
+
}
|
|
550
|
+
inProgress.delete(value);
|
|
551
|
+
return changed ? rebuilt : value;
|
|
552
|
+
}
|
|
553
|
+
return value;
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* Resolves every value the graph binds, dependency-first, once each, and
|
|
557
|
+
* returns each binding with its values replaced by their real values.
|
|
558
|
+
*/
|
|
559
|
+
function resolveValues(input) {
|
|
560
|
+
const { environment } = input;
|
|
561
|
+
const found = [];
|
|
562
|
+
for (const { serviceAddress, binding } of input.inputBindings) collect(binding, {
|
|
563
|
+
address: serviceAddress,
|
|
564
|
+
kind: "input",
|
|
565
|
+
path: ""
|
|
566
|
+
}, found, /* @__PURE__ */ new WeakSet());
|
|
567
|
+
for (const { serviceAddress, slot, binding } of input.params) collect(binding, {
|
|
568
|
+
address: serviceAddress,
|
|
569
|
+
kind: "param",
|
|
570
|
+
path: slot
|
|
571
|
+
}, found, /* @__PURE__ */ new WeakSet());
|
|
572
|
+
for (const [address, resource] of input.resources) {
|
|
573
|
+
const site = {
|
|
574
|
+
address,
|
|
575
|
+
kind: "props",
|
|
576
|
+
path: ""
|
|
577
|
+
};
|
|
578
|
+
collect(resource.props, site, found, /* @__PURE__ */ new WeakSet());
|
|
579
|
+
}
|
|
580
|
+
const results = /* @__PURE__ */ new Map();
|
|
581
|
+
const visiting = [];
|
|
582
|
+
const fnLabelFor = (site) => visiting.length === 1 ? `The resolve() function for ${describeSite(site)}` : `A resolve() function that ${describeSite(site)} depends on`;
|
|
583
|
+
const resolveOne = (value, site) => {
|
|
584
|
+
if (results.has(value)) return results.get(value);
|
|
585
|
+
if (visiting.includes(value)) throw new LoadError(`${describeSite(site)} depends on itself: a computed value's dependencies lead back to it. Remove the cycle.`);
|
|
586
|
+
visiting.push(value);
|
|
587
|
+
const origin = originOf(value);
|
|
588
|
+
let result;
|
|
589
|
+
switch (origin.kind) {
|
|
590
|
+
case "environment":
|
|
591
|
+
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.`);
|
|
592
|
+
result = environment[origin.fact];
|
|
593
|
+
break;
|
|
594
|
+
case "computed": {
|
|
595
|
+
const args = origin.dependencies.map((dependency) => resolveOne(dependency, site));
|
|
596
|
+
try {
|
|
597
|
+
result = origin.compute(args);
|
|
598
|
+
} catch (thrown) {
|
|
599
|
+
if (thrown instanceof LoadError) throw thrown;
|
|
600
|
+
const message = thrown instanceof Error ? thrown.message : String(thrown);
|
|
601
|
+
throw new LoadError(`${fnLabelFor(site)} threw: ${message}`, { cause: thrown });
|
|
602
|
+
}
|
|
603
|
+
checkResult(result, fnLabelFor(site));
|
|
604
|
+
break;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
visiting.pop();
|
|
608
|
+
results.set(value, result);
|
|
609
|
+
return result;
|
|
610
|
+
};
|
|
611
|
+
for (const { value, site } of found) resolveOne(value, site);
|
|
612
|
+
const authoredProps = new Map([...input.resources].map(([address, resource]) => [address, resource.props]));
|
|
613
|
+
if (found.length === 0) return {
|
|
614
|
+
inputBindings: input.inputBindings,
|
|
615
|
+
params: input.params,
|
|
616
|
+
resourceProps: authoredProps
|
|
617
|
+
};
|
|
618
|
+
const inProgress = /* @__PURE__ */ new WeakSet();
|
|
619
|
+
const resourceProps = /* @__PURE__ */ new Map();
|
|
620
|
+
for (const [address, props] of authoredProps) {
|
|
621
|
+
const substituted = substitute(props, results, inProgress);
|
|
622
|
+
resourceProps.set(address, substituted === props ? props : blindCast(substituted));
|
|
623
|
+
}
|
|
624
|
+
return {
|
|
625
|
+
resourceProps,
|
|
626
|
+
inputBindings: input.inputBindings.map((entry) => {
|
|
627
|
+
const binding = substitute(entry.binding, results, inProgress);
|
|
628
|
+
return binding === entry.binding ? entry : {
|
|
629
|
+
serviceAddress: entry.serviceAddress,
|
|
630
|
+
binding: blindCast(binding)
|
|
631
|
+
};
|
|
632
|
+
}),
|
|
633
|
+
params: input.params.map((entry) => {
|
|
634
|
+
const binding = substitute(entry.binding, results, inProgress);
|
|
635
|
+
return binding === entry.binding ? entry : {
|
|
636
|
+
...entry,
|
|
637
|
+
binding
|
|
638
|
+
};
|
|
639
|
+
})
|
|
640
|
+
};
|
|
641
|
+
}
|
|
382
642
|
/**
|
|
383
643
|
* Brands a ref-port with the AUTHORED endpoint it stands for — which port of
|
|
384
644
|
* which node the author wired, before any forwarding chain resolves. Read
|
|
@@ -419,14 +679,17 @@ function refFor(id, service) {
|
|
|
419
679
|
});
|
|
420
680
|
}
|
|
421
681
|
/**
|
|
422
|
-
* The resource variant of refFor: a resource has
|
|
682
|
+
* The resource variant of refFor: a resource has at most one port — the
|
|
423
683
|
* contract it provides — flattened onto the ref itself, tagged with the
|
|
424
684
|
* provider id. `id` and the authored brand are written last so a hostile
|
|
425
|
-
* contract value cannot clobber them.
|
|
685
|
+
* contract value cannot clobber them. A resource that exposes nothing gets
|
|
686
|
+
* only its id.
|
|
426
687
|
*/
|
|
427
688
|
function refForResource(id, resource) {
|
|
689
|
+
const provides = resource.provides;
|
|
690
|
+
if (provides === void 0) return { id };
|
|
428
691
|
return blindCast({
|
|
429
|
-
...
|
|
692
|
+
...provides,
|
|
430
693
|
__providerId: id,
|
|
431
694
|
id,
|
|
432
695
|
[AUTHORED_PORT]: {
|
|
@@ -442,7 +705,7 @@ function producerIdOf(ref) {
|
|
|
442
705
|
if ("id" in ref && typeof ref.id === "string") return ref.id;
|
|
443
706
|
}
|
|
444
707
|
/**
|
|
445
|
-
* Brands each `ctx.
|
|
708
|
+
* Brands each `ctx.deps` entry with the input key it stands for (see
|
|
446
709
|
* flatten): diagnostic only — usage attribution relies on the per-key object
|
|
447
710
|
* identity the branding copy creates, never on reading this back.
|
|
448
711
|
*/
|
|
@@ -481,7 +744,7 @@ function validateWiring(pending, byId) {
|
|
|
481
744
|
for (const [input, rawValue] of Object.entries(deps)) {
|
|
482
745
|
const value = blindCast(rawValue);
|
|
483
746
|
if (!isNode(value) || wiring[input] !== void 0) continue;
|
|
484
|
-
if (value.kind === "dependency") throw new LoadError(`Dependency
|
|
747
|
+
if (value.kind === "dependency") throw new LoadError(`Dependency "${input}" of provisioned ${targetKind} "${targetId}" is not wired to a producer (module "${enclosingModuleName}").`);
|
|
485
748
|
}
|
|
486
749
|
}
|
|
487
750
|
/**
|
|
@@ -520,11 +783,12 @@ function wiringEdges(wiring, targetId) {
|
|
|
520
783
|
* but resolved inline (a source carries its own name, so no whole-graph pass
|
|
521
784
|
* is needed).
|
|
522
785
|
*/
|
|
523
|
-
function validateSecretBinding(child, id, secretWiring, enclosingModuleName) {
|
|
786
|
+
function validateSecretBinding(child, id, address, secretWiring, enclosingModuleName) {
|
|
524
787
|
const { kind } = child;
|
|
525
788
|
for (const slot of Object.keys(child.secretSlots)) {
|
|
526
789
|
const bound = secretWiring[slot];
|
|
527
790
|
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.`);
|
|
791
|
+
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.`);
|
|
528
792
|
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.`);
|
|
529
793
|
}
|
|
530
794
|
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}").`);
|
|
@@ -544,10 +808,11 @@ function validateServiceParamBinding(child, id, paramWiring, enclosingModuleName
|
|
|
544
808
|
* schema of its own, so (unlike a service param) it cannot fall back to a
|
|
545
809
|
* literal or a default; the param analog of `validateSecretBinding`.
|
|
546
810
|
*/
|
|
547
|
-
function validateParamNeedBinding(child, id, paramWiring, enclosingModuleName) {
|
|
811
|
+
function validateParamNeedBinding(child, id, address, paramWiring, enclosingModuleName) {
|
|
548
812
|
for (const slot of Object.keys(child.paramSlots)) {
|
|
549
813
|
const bound = paramWiring[slot];
|
|
550
814
|
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.`);
|
|
815
|
+
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.`);
|
|
551
816
|
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.`);
|
|
552
817
|
}
|
|
553
818
|
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}").`);
|
|
@@ -570,7 +835,7 @@ function validateParamNeedBinding(child, id, paramWiring, enclosingModuleName) {
|
|
|
570
835
|
* children carry it as their `parent`, and this module's own boundary ports
|
|
571
836
|
* (and the authored edges touching them) are recorded against it.
|
|
572
837
|
*/
|
|
573
|
-
function flatten(moduleNode, selfId, wiring, secretWiring, paramWiring, nodes, edges, pending, inputBindings, paramBindings, byId, ports, authoredEdges) {
|
|
838
|
+
function flatten(moduleNode, selfId, wiring, secretWiring, paramWiring, nodes, edges, pending, inputBindings, paramBindings, byId, ports, authoredEdges, loading) {
|
|
574
839
|
ports.push(...boundaryPortsOf(selfId, moduleNode));
|
|
575
840
|
const localIds = /* @__PURE__ */ new Set();
|
|
576
841
|
const used = /* @__PURE__ */ new Set();
|
|
@@ -637,11 +902,13 @@ function flatten(moduleNode, selfId, wiring, secretWiring, paramWiring, nodes, e
|
|
|
637
902
|
for (const value of values) for (const key of Object.keys(ctxParams)) if (value === ctxParams[key]) usedParams.add(key);
|
|
638
903
|
};
|
|
639
904
|
const provision = (child, opts) => {
|
|
905
|
+
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.`);
|
|
640
906
|
const id = opts?.id ?? child.name;
|
|
641
907
|
const provisionWiring = opts?.deps;
|
|
642
908
|
const provisionSecrets = opts?.secrets;
|
|
643
909
|
const provisionInput = opts?.input;
|
|
644
910
|
const provisionParams = opts?.params;
|
|
911
|
+
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).`);
|
|
645
912
|
if (typeof id !== "string" || id.length === 0) throw new LoadError(`provision() requires a non-empty id (module "${moduleNode.name}").`);
|
|
646
913
|
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.)`);
|
|
647
914
|
if (localIds.has(id)) throw new LoadError(`Duplicate provision id "${id}" in module "${moduleNode.name}".`);
|
|
@@ -650,26 +917,41 @@ function flatten(moduleNode, selfId, wiring, secretWiring, paramWiring, nodes, e
|
|
|
650
917
|
localIds.add(id);
|
|
651
918
|
const fullAddress = `${selfId}.${id}`;
|
|
652
919
|
if (child.kind === "resource") {
|
|
653
|
-
if (provisionWiring !== void 0) throw new LoadError(`provision("${id}") received deps for a resource — a resource
|
|
920
|
+
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().`);
|
|
654
921
|
if (provisionSecrets !== void 0) throw new LoadError(`provision("${id}") received secrets for a resource — a resource has no secret slots to satisfy.`);
|
|
655
922
|
if (provisionInput !== void 0) throw new LoadError(`provision("${id}") received an input binding for a resource — a resource declares no input schema.`);
|
|
656
923
|
if (provisionParams !== void 0) throw new LoadError(`provision("${id}") received params for a resource — a resource has no params to satisfy.`);
|
|
657
924
|
if (child.type.length === 0) throw new LoadError(`provision("${id}") received a resource with an empty node type.`);
|
|
925
|
+
const localWiring = { ...child.deps };
|
|
926
|
+
markUsed(Object.values(localWiring));
|
|
658
927
|
byId.set(fullAddress, child);
|
|
659
|
-
|
|
928
|
+
const slots = slotNodesAndEdges(child, fullAddress);
|
|
929
|
+
nodes.push(...slots.nodes, {
|
|
660
930
|
id: fullAddress,
|
|
661
931
|
parent: selfId,
|
|
662
932
|
node: child
|
|
663
933
|
});
|
|
664
|
-
|
|
934
|
+
edges.push(...slots.edges, ...wiringEdges(localWiring, fullAddress));
|
|
935
|
+
ports.push(...boundaryPortsOf(fullAddress, child));
|
|
936
|
+
const provides = child.provides;
|
|
937
|
+
if (provides !== void 0) ports.push({
|
|
665
938
|
node: fullAddress,
|
|
666
939
|
direction: "out",
|
|
667
940
|
name: RESOURCE_OUT_PORT,
|
|
668
|
-
contractKind:
|
|
669
|
-
style: contractStyleOf(
|
|
941
|
+
contractKind: provides.kind,
|
|
942
|
+
style: contractStyleOf(provides)
|
|
943
|
+
});
|
|
944
|
+
recordAuthoredWiring(fullAddress, localWiring);
|
|
945
|
+
pending.push({
|
|
946
|
+
deps: child.inputs ?? {},
|
|
947
|
+
wiring: localWiring,
|
|
948
|
+
targetId: fullAddress,
|
|
949
|
+
targetKind: "resource",
|
|
950
|
+
enclosingModuleName: moduleNode.name
|
|
670
951
|
});
|
|
671
952
|
return refForResource(fullAddress, child);
|
|
672
953
|
}
|
|
954
|
+
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).`);
|
|
673
955
|
const localWiring = { ...provisionWiring ?? {} };
|
|
674
956
|
markUsed(Object.values(localWiring));
|
|
675
957
|
const localSecrets = { ...provisionSecrets ?? {} };
|
|
@@ -696,7 +978,7 @@ function flatten(moduleNode, selfId, wiring, secretWiring, paramWiring, nodes, e
|
|
|
696
978
|
slot,
|
|
697
979
|
binding
|
|
698
980
|
});
|
|
699
|
-
const inputs =
|
|
981
|
+
const inputs = slotNodesAndEdges(child, fullAddress);
|
|
700
982
|
nodes.push(...inputs.nodes, {
|
|
701
983
|
id: fullAddress,
|
|
702
984
|
parent: selfId,
|
|
@@ -716,8 +998,8 @@ function flatten(moduleNode, selfId, wiring, secretWiring, paramWiring, nodes, e
|
|
|
716
998
|
return refFor(fullAddress, child);
|
|
717
999
|
}
|
|
718
1000
|
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.`);
|
|
719
|
-
validateSecretBinding(child, id, localSecrets, moduleNode.name);
|
|
720
|
-
validateParamNeedBinding(child, id, localParams, moduleNode.name);
|
|
1001
|
+
validateSecretBinding(child, id, fullAddress, localSecrets, moduleNode.name);
|
|
1002
|
+
validateParamNeedBinding(child, id, fullAddress, localParams, moduleNode.name);
|
|
721
1003
|
edges.push(...wiringEdges(localWiring, fullAddress));
|
|
722
1004
|
recordAuthoredWiring(fullAddress, localWiring);
|
|
723
1005
|
pending.push({
|
|
@@ -727,7 +1009,7 @@ function flatten(moduleNode, selfId, wiring, secretWiring, paramWiring, nodes, e
|
|
|
727
1009
|
targetKind: "module",
|
|
728
1010
|
enclosingModuleName: moduleNode.name
|
|
729
1011
|
});
|
|
730
|
-
const childOutputs = flatten(child, fullAddress, localWiring, localSecrets, localParams, nodes, edges, pending, inputBindings, paramBindings, byId, ports, authoredEdges);
|
|
1012
|
+
const childOutputs = flatten(child, fullAddress, localWiring, localSecrets, localParams, nodes, edges, pending, inputBindings, paramBindings, byId, ports, authoredEdges, loading);
|
|
731
1013
|
nodes.push({
|
|
732
1014
|
id: fullAddress,
|
|
733
1015
|
parent: selfId,
|
|
@@ -748,14 +1030,15 @@ function flatten(moduleNode, selfId, wiring, secretWiring, paramWiring, nodes, e
|
|
|
748
1030
|
});
|
|
749
1031
|
};
|
|
750
1032
|
const ctx = blindCast({
|
|
751
|
-
|
|
1033
|
+
deps: ctxInputs,
|
|
752
1034
|
secrets: ctxSecrets,
|
|
753
1035
|
params: ctxParams,
|
|
1036
|
+
environment: environmentFacts,
|
|
754
1037
|
provision: blindCast(provision)
|
|
755
1038
|
});
|
|
756
1039
|
const outputs = blindCast(moduleNode.body(ctx) ?? {});
|
|
757
1040
|
markUsed(Object.values(outputs));
|
|
758
|
-
for (const key of Object.keys(moduleNode.deps)) if (!used.has(key)) throw new LoadError(`Module "${moduleNode.name}" declares
|
|
1041
|
+
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.`);
|
|
759
1042
|
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.`);
|
|
760
1043
|
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.`);
|
|
761
1044
|
for (const [key, contract] of Object.entries(moduleNode.expose)) {
|
|
@@ -779,7 +1062,7 @@ function loadModule(root, opts) {
|
|
|
779
1062
|
const rootDepKeys = Object.keys(root.deps);
|
|
780
1063
|
if (rootDepKeys.length > 0) {
|
|
781
1064
|
const names = rootDepKeys.map((k) => `"${k}"`).join(", ");
|
|
782
|
-
throw new LoadError(`Module "${root.name}" declares
|
|
1065
|
+
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.`);
|
|
783
1066
|
}
|
|
784
1067
|
const rootSecretKeys = Object.keys(root.secretSlots);
|
|
785
1068
|
if (rootSecretKeys.length > 0) {
|
|
@@ -799,9 +1082,30 @@ function loadModule(root, opts) {
|
|
|
799
1082
|
const byId = /* @__PURE__ */ new Map();
|
|
800
1083
|
const ports = [];
|
|
801
1084
|
const authoredEdges = [];
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
1085
|
+
const loading = { sealed: false };
|
|
1086
|
+
try {
|
|
1087
|
+
flatten(root, rootId, {}, {}, {}, nodes, edges, pending, inputBindings, paramBindings, byId, ports, authoredEdges, loading);
|
|
1088
|
+
for (const entry of pending) validateWiring(entry, byId);
|
|
1089
|
+
assertDependencyDag(edges);
|
|
1090
|
+
} finally {
|
|
1091
|
+
loading.sealed = true;
|
|
1092
|
+
}
|
|
1093
|
+
const resources = /* @__PURE__ */ new Map();
|
|
1094
|
+
for (const [address, node] of byId) if (node.kind === "resource") resources.set(address, node);
|
|
1095
|
+
const resolved = resolveValues({
|
|
1096
|
+
environment: opts?.environment,
|
|
1097
|
+
inputBindings,
|
|
1098
|
+
params: paramBindings,
|
|
1099
|
+
resources
|
|
1100
|
+
});
|
|
1101
|
+
const resolvedNodes = nodes.map((entry) => {
|
|
1102
|
+
const props = resolved.resourceProps.get(entry.id);
|
|
1103
|
+
if (entry.node.kind !== "resource" || props === void 0 || props === entry.node.props) return entry;
|
|
1104
|
+
return {
|
|
1105
|
+
...entry,
|
|
1106
|
+
node: withResolvedProps(entry.node, props)
|
|
1107
|
+
};
|
|
1108
|
+
});
|
|
805
1109
|
const rootGraphNode = {
|
|
806
1110
|
id: rootId,
|
|
807
1111
|
parent: void 0,
|
|
@@ -809,18 +1113,32 @@ function loadModule(root, opts) {
|
|
|
809
1113
|
};
|
|
810
1114
|
return {
|
|
811
1115
|
root: rootGraphNode,
|
|
812
|
-
nodes: [...topoSort(
|
|
1116
|
+
nodes: [...topoSort(resolvedNodes, edges), rootGraphNode],
|
|
813
1117
|
edges,
|
|
814
1118
|
ports,
|
|
815
1119
|
authoredEdges,
|
|
816
|
-
inputBindings,
|
|
817
|
-
params:
|
|
1120
|
+
inputBindings: resolved.inputBindings,
|
|
1121
|
+
params: resolved.params
|
|
818
1122
|
};
|
|
819
1123
|
}
|
|
820
1124
|
/**
|
|
1125
|
+
* A frozen copy of `node` holding `props`, keeping its prototype (a class built
|
|
1126
|
+
* on `ResourceNodeBase` keeps its methods) and its own properties, the brand included.
|
|
1127
|
+
*/
|
|
1128
|
+
function withResolvedProps(node, props) {
|
|
1129
|
+
return Object.freeze(Object.create(Object.getPrototypeOf(node), {
|
|
1130
|
+
...Object.getOwnPropertyDescriptors(node),
|
|
1131
|
+
props: {
|
|
1132
|
+
value: Object.freeze(props),
|
|
1133
|
+
enumerable: true,
|
|
1134
|
+
writable: false,
|
|
1135
|
+
configurable: false
|
|
1136
|
+
}
|
|
1137
|
+
}));
|
|
1138
|
+
}
|
|
1139
|
+
/**
|
|
821
1140
|
* The dependency edges must form a DAG — a cycle means neither producer can
|
|
822
|
-
* deploy first.
|
|
823
|
-
* edges can ever participate in a cycle; no special-casing needed.
|
|
1141
|
+
* deploy first. A resource with dependency slots can take part in a cycle too.
|
|
824
1142
|
*/
|
|
825
1143
|
function assertDependencyDag(edges) {
|
|
826
1144
|
const adjacency = /* @__PURE__ */ new Map();
|
|
@@ -860,7 +1178,8 @@ function assertAppName(name) {
|
|
|
860
1178
|
* module it provisions into one graph of hierarchical addresses. A malformed
|
|
861
1179
|
* graph is a `LoadError` that names its fix; the individual validation rules
|
|
862
1180
|
* live with `loadService` / `loadModule` and are covered by name in the Load
|
|
863
|
-
* tests. Executes nothing of the user's own code beyond module bodies
|
|
1181
|
+
* tests. Executes nothing of the user's own code beyond module bodies and `resolve()`
|
|
1182
|
+
* functions.
|
|
864
1183
|
*/
|
|
865
1184
|
function Load(root, opts) {
|
|
866
1185
|
if (!isNode(root)) throw new LoadError("Load expects a branded service or module node (construct it with the service()/module() factories).");
|
|
@@ -872,6 +1191,6 @@ function Load(root, opts) {
|
|
|
872
1191
|
throw new LoadError("Load expects a service or module root (received another node kind).");
|
|
873
1192
|
}
|
|
874
1193
|
//#endregion
|
|
875
|
-
export {
|
|
1194
|
+
export { slotsOf as S, resolve as _, assertAppName as a, secretSource as b, isNode as c, isSecretSource as d, isValue as f, provisionNeed as g, paramSource as h, ResourceNodeBase as i, isParamSource as l, paramNeed as m, LoadError as n, dependency as o, module as p, RESOURCE_OUT_PORT as r, freezeNode as s, Load as t, isProvisionNeed as u, resource as v, service as x, secret as y };
|
|
876
1195
|
|
|
877
|
-
//# sourceMappingURL=graph-
|
|
1196
|
+
//# sourceMappingURL=graph-MGOZJdDt-CyI8-9r7.mjs.map
|