@prisma/composer-cli 0.35.0 → 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.
Files changed (49) hide show
  1. package/dist/app-config-CErnR6NK-6QjHJ7q5.mjs +32 -0
  2. package/dist/app-config-CErnR6NK-6QjHJ7q5.mjs.map +1 -0
  3. package/dist/{container-transport-HcvNOGZL-CIoZc7Rs.mjs → config-DiZaanS3.mjs} +32 -2
  4. package/dist/config-DiZaanS3.mjs.map +1 -0
  5. package/dist/{dev-current-BB02pfSh-vMKS1rYi.mjs → dev-current-Brb4qugP-BOI9FJdz.mjs} +44 -8
  6. package/dist/dev-current-Brb4qugP-BOI9FJdz.mjs.map +1 -0
  7. package/dist/dev-environment-name-6eEr5PW8-lIZmJjfr.mjs +71 -0
  8. package/dist/dev-environment-name-6eEr5PW8-lIZmJjfr.mjs.map +1 -0
  9. package/dist/dist-B9-nLeho.mjs.map +1 -1
  10. package/dist/{execute-deploy-destroy-DwcoZIks-CiW-dlB1.mjs → execute-deploy-destroy-CNt-xpE7-CMQCNQpY.mjs} +32 -56
  11. package/dist/execute-deploy-destroy-CNt-xpE7-CMQCNQpY.mjs.map +1 -0
  12. package/dist/{execute-dev-BHRWoEnd-DrGMSTD3.mjs → execute-dev-BUk-XWBJ-DaB9ma8z.mjs} +45 -23
  13. package/dist/execute-dev-BUk-XWBJ-DaB9ma8z.mjs.map +1 -0
  14. package/dist/{execute-dev-current-D4RkOtPA-BFoZ0cXm.mjs → execute-dev-current-BdEqeKAB-xCBBITAB.mjs} +70 -34
  15. package/dist/execute-dev-current-BdEqeKAB-xCBBITAB.mjs.map +1 -0
  16. package/dist/{family-xJ6y4fXc-CFBu6q4b.d.mts → family-B2JZ8O7U-P_rOUr4w.d.mts} +123 -52
  17. package/dist/family-B2JZ8O7U-P_rOUr4w.d.mts.map +1 -0
  18. package/dist/family.d.mts +3 -3
  19. package/dist/family.d.mts.map +1 -1
  20. package/dist/family.mjs +103 -47
  21. package/dist/family.mjs.map +1 -1
  22. package/dist/{generate-dev-stack-CfneNj97-Yx3Z2-9u.mjs → generate-dev-stack-BkkU2HLE-Dek3CkAQ.mjs} +18 -13
  23. package/dist/generate-dev-stack-BkkU2HLE-Dek3CkAQ.mjs.map +1 -0
  24. package/dist/{list-deployed-df3vxBbn.mjs → list-deployed-GhPuf0RC.mjs} +70 -44
  25. package/dist/list-deployed-GhPuf0RC.mjs.map +1 -0
  26. package/dist/testing.d.mts +3 -1
  27. package/dist/testing.d.mts.map +1 -1
  28. package/dist/testing.mjs +2 -1
  29. package/dist/testing.mjs.map +1 -1
  30. package/dist/{pipeline-BmWt-Nhb-Bos4TFXR.mjs → validate-environment-CEhUSEg2-ExABehBM.mjs} +330 -55
  31. package/dist/validate-environment-CEhUSEg2-ExABehBM.mjs.map +1 -0
  32. package/package.json +7 -7
  33. package/src/family/deploy-list.ts +17 -10
  34. package/src/family/deployed-nodes.ts +10 -10
  35. package/src/family/emulator-list.ts +7 -4
  36. package/src/family/list-deployed.ts +12 -12
  37. package/dist/container-transport-HcvNOGZL-CIoZc7Rs.mjs.map +0 -1
  38. package/dist/dev-current-BB02pfSh-vMKS1rYi.mjs.map +0 -1
  39. package/dist/execute-deploy-destroy-DwcoZIks-CiW-dlB1.mjs.map +0 -1
  40. package/dist/execute-dev-BHRWoEnd-DrGMSTD3.mjs.map +0 -1
  41. package/dist/execute-dev-current-D4RkOtPA-BFoZ0cXm.mjs.map +0 -1
  42. package/dist/family-xJ6y4fXc-CFBu6q4b.d.mts.map +0 -1
  43. package/dist/generate-dev-stack-CfneNj97-Yx3Z2-9u.mjs.map +0 -1
  44. package/dist/list-deployed-df3vxBbn.mjs.map +0 -1
  45. package/dist/local-target-CK8gvYV4.mjs +0 -48
  46. package/dist/local-target-CK8gvYV4.mjs.map +0 -1
  47. package/dist/pipeline-BmWt-Nhb-Bos4TFXR.mjs.map +0 -1
  48. package/dist/validate-stage-DxRW3MwT-DOWCXHa_.mjs +0 -13
  49. package/dist/validate-stage-DxRW3MwT-DOWCXHa_.mjs.map +0 -1
@@ -4,6 +4,7 @@ import * as fs from "node:fs";
4
4
  import { existsSync } from "node:fs";
5
5
  import * as path from "node:path";
6
6
  import { fileURLToPath, pathToFileURL } from "node:url";
7
+ import { spawnSync } from "node:child_process";
7
8
  //#region ../../0-framework/3-tooling/assemble/dist/index.mjs
8
9
  /**
9
10
  * A user-facing assembly failure, structured at origin (base-type rule 6):
@@ -100,7 +101,7 @@ async function assembleServices(graph, config, cwd, run, onEvent, options = {})
100
101
  };
101
102
  }
102
103
  //#endregion
103
- //#region ../../0-framework/1-core/core/dist/graph-D0ICjejE.mjs
104
+ //#region ../../0-framework/1-core/core/dist/graph-MGOZJdDt.mjs
104
105
  /** The reserved name of a resource's single anonymous output port. Rejected as a user-declared port name (node.ts). */
105
106
  const RESOURCE_OUT_PORT = "$out";
106
107
  /**
@@ -110,8 +111,8 @@ const RESOURCE_OUT_PORT = "$out";
110
111
  * `CliStructuredError` — structural recognition depends on it.
111
112
  */
112
113
  var LoadError = class extends CliStructuredError {
113
- constructor(message) {
114
- super("COMPOSE.GRAPH_INVALID", message);
114
+ constructor(message, options) {
115
+ super("COMPOSE.GRAPH_INVALID", message, options);
115
116
  }
116
117
  };
117
118
  /** The declared style of an untrusted contract value, or `undefined` when it declares none. */
@@ -119,6 +120,30 @@ function contractStyleOf(contract) {
119
120
  if (typeof contract !== "object" || contract === null || !("style" in contract)) return void 0;
120
121
  return contract.style === "request-response" || contract.style === "stream" ? contract.style : void 0;
121
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
+ }) });
122
147
  /**
123
148
  * Core model: node types and the factories that construct them, plain frozen
124
149
  * data objects. A node's `extension` + `type` form its deploy-time registry key (ADR-0017).
@@ -154,6 +179,10 @@ function isConfigKeySegment(name) {
154
179
  function isNode(value) {
155
180
  return typeof value === "object" && value !== null && value[NODE] === true;
156
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
+ }
157
186
  /**
158
187
  * Stable topological sort: every edge's `from` precedes its `to` in the
159
188
  * result. Ties (nodes with no ordering constraint between them) keep their
@@ -204,15 +233,15 @@ function topoSort(nodes, edges) {
204
233
  return order.map((id) => byId.get(id)).filter((n) => n !== void 0);
205
234
  }
206
235
  /**
207
- * The declared boundary ports of a module or service node at `id`: dep slots
208
- * as `in` ports (contractKind = the slot's `type`), exposed contracts as
209
- * `out` ports (contractKind = the contract's `kind`, style = its declared
210
- * style). A resource's one
211
- * `$out` port is recorded at its provision site instead (load-module.ts).
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).
212
241
  */
213
242
  function boundaryPortsOf(id, node) {
214
243
  const ports = [];
215
- const slots = node.kind === "module" ? node.deps : node.inputs;
244
+ const slots = node.kind === "module" ? node.deps : slotsOf(node);
216
245
  for (const [name, slot] of Object.entries(slots)) {
217
246
  const type = typeof slot === "object" && slot !== null && "type" in slot && typeof slot.type === "string" ? slot.type : void 0;
218
247
  ports.push({
@@ -223,7 +252,8 @@ function boundaryPortsOf(id, node) {
223
252
  style: void 0
224
253
  });
225
254
  }
226
- for (const [name, contract] of Object.entries(node.expose ?? {})) {
255
+ const expose = node.kind === "resource" ? {} : node.expose ?? {};
256
+ for (const [name, contract] of Object.entries(expose)) {
227
257
  const kind = typeof contract === "object" && contract !== null && "kind" in contract && typeof contract.kind === "string" ? contract.kind : void 0;
228
258
  ports.push({
229
259
  node: id,
@@ -235,24 +265,26 @@ function boundaryPortsOf(id, node) {
235
265
  }
236
266
  return ports;
237
267
  }
238
- function serviceInputs(service, serviceId) {
239
- if (typeof service.inputs !== "object" || service.inputs === null) throw new LoadError(`Service "${serviceId}" has no inputs map.`);
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.`);
240
272
  const nodes = [];
241
273
  const edges = [];
242
- for (const [input, value] of Object.entries(service.inputs)) {
274
+ for (const [input, value] of Object.entries(inputs)) {
243
275
  const kind = isNode(value) ? value.kind : void 0;
244
- if (kind === "resource") throw new LoadError(`Input "${input}" of "${serviceId}" 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.`);
245
- if (kind !== "dependency") throw new LoadError(`Input "${input}" of "${serviceId}" is not a branded dependency end (construct it with the dependency() factory).`);
246
- if (value.type.length === 0) throw new LoadError(`Input "${input}" of "${serviceId}" has an empty node type.`);
247
- const id = `${serviceId}.${input}`;
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}`;
248
280
  nodes.push({
249
281
  id,
250
- parent: serviceId,
282
+ parent: nodeId,
251
283
  node: value
252
284
  });
253
285
  edges.push({
254
286
  from: id,
255
- to: serviceId,
287
+ to: nodeId,
256
288
  input,
257
289
  kind: "input"
258
290
  });
@@ -263,14 +295,14 @@ function serviceInputs(service, serviceId) {
263
295
  };
264
296
  }
265
297
  function loadService(root, rootId) {
266
- 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 "${input}" — this service is composed by a module; deploy the module instead of loading "${rootId}" directly.`);
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.`);
267
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).`);
268
300
  const rootGraphNode = {
269
301
  id: rootId,
270
302
  parent: void 0,
271
303
  node: root
272
304
  };
273
- const { nodes, edges } = serviceInputs(root, rootId);
305
+ const { nodes, edges } = slotNodesAndEdges(root, rootId);
274
306
  return {
275
307
  root: rootGraphNode,
276
308
  nodes: [...topoSort(nodes, edges), rootGraphNode],
@@ -281,6 +313,178 @@ function loadService(root, rootId) {
281
313
  params: []
282
314
  };
283
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
+ }
284
488
  /**
285
489
  * Brands a ref-port with the AUTHORED endpoint it stands for — which port of
286
490
  * which node the author wired, before any forwarding chain resolves. Read
@@ -321,14 +525,17 @@ function refFor(id, service) {
321
525
  });
322
526
  }
323
527
  /**
324
- * The resource variant of refFor: a resource has exactly one port — the
528
+ * The resource variant of refFor: a resource has at most one port — the
325
529
  * contract it provides — flattened onto the ref itself, tagged with the
326
530
  * provider id. `id` and the authored brand are written last so a hostile
327
- * contract value cannot clobber them.
531
+ * contract value cannot clobber them. A resource that exposes nothing gets
532
+ * only its id.
328
533
  */
329
534
  function refForResource(id, resource) {
535
+ const provides = resource.provides;
536
+ if (provides === void 0) return { id };
330
537
  return blindCast({
331
- ...resource.provides,
538
+ ...provides,
332
539
  __providerId: id,
333
540
  id,
334
541
  [AUTHORED_PORT]: {
@@ -344,7 +551,7 @@ function producerIdOf(ref) {
344
551
  if ("id" in ref && typeof ref.id === "string") return ref.id;
345
552
  }
346
553
  /**
347
- * Brands each `ctx.inputs` entry with the input key it stands for (see
554
+ * Brands each `ctx.deps` entry with the input key it stands for (see
348
555
  * flatten): diagnostic only — usage attribution relies on the per-key object
349
556
  * identity the branding copy creates, never on reading this back.
350
557
  */
@@ -383,7 +590,7 @@ function validateWiring(pending, byId) {
383
590
  for (const [input, rawValue] of Object.entries(deps)) {
384
591
  const value = blindCast(rawValue);
385
592
  if (!isNode(value) || wiring[input] !== void 0) continue;
386
- if (value.kind === "dependency") throw new LoadError(`Dependency input "${input}" of provisioned ${targetKind} "${targetId}" is not wired to a producer (module "${enclosingModuleName}").`);
593
+ if (value.kind === "dependency") throw new LoadError(`Dependency "${input}" of provisioned ${targetKind} "${targetId}" is not wired to a producer (module "${enclosingModuleName}").`);
387
594
  }
388
595
  }
389
596
  /**
@@ -422,11 +629,12 @@ function wiringEdges(wiring, targetId) {
422
629
  * but resolved inline (a source carries its own name, so no whole-graph pass
423
630
  * is needed).
424
631
  */
425
- function validateSecretBinding(child, id, secretWiring, enclosingModuleName) {
632
+ function validateSecretBinding(child, id, address, secretWiring, enclosingModuleName) {
426
633
  const { kind } = child;
427
634
  for (const slot of Object.keys(child.secretSlots)) {
428
635
  const bound = secretWiring[slot];
429
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.`);
430
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.`);
431
639
  }
432
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}").`);
@@ -446,10 +654,11 @@ function validateServiceParamBinding(child, id, paramWiring, enclosingModuleName
446
654
  * schema of its own, so (unlike a service param) it cannot fall back to a
447
655
  * literal or a default; the param analog of `validateSecretBinding`.
448
656
  */
449
- function validateParamNeedBinding(child, id, paramWiring, enclosingModuleName) {
657
+ function validateParamNeedBinding(child, id, address, paramWiring, enclosingModuleName) {
450
658
  for (const slot of Object.keys(child.paramSlots)) {
451
659
  const bound = paramWiring[slot];
452
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.`);
453
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.`);
454
663
  }
455
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}").`);
@@ -472,7 +681,7 @@ function validateParamNeedBinding(child, id, paramWiring, enclosingModuleName) {
472
681
  * children carry it as their `parent`, and this module's own boundary ports
473
682
  * (and the authored edges touching them) are recorded against it.
474
683
  */
475
- 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) {
476
685
  ports.push(...boundaryPortsOf(selfId, moduleNode));
477
686
  const localIds = /* @__PURE__ */ new Set();
478
687
  const used = /* @__PURE__ */ new Set();
@@ -539,11 +748,13 @@ function flatten(moduleNode, selfId, wiring, secretWiring, paramWiring, nodes, e
539
748
  for (const value of values) for (const key of Object.keys(ctxParams)) if (value === ctxParams[key]) usedParams.add(key);
540
749
  };
541
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.`);
542
752
  const id = opts?.id ?? child.name;
543
753
  const provisionWiring = opts?.deps;
544
754
  const provisionSecrets = opts?.secrets;
545
755
  const provisionInput = opts?.input;
546
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).`);
547
758
  if (typeof id !== "string" || id.length === 0) throw new LoadError(`provision() requires a non-empty id (module "${moduleNode.name}").`);
548
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.)`);
549
760
  if (localIds.has(id)) throw new LoadError(`Duplicate provision id "${id}" in module "${moduleNode.name}".`);
@@ -552,26 +763,41 @@ function flatten(moduleNode, selfId, wiring, secretWiring, paramWiring, nodes, e
552
763
  localIds.add(id);
553
764
  const fullAddress = `${selfId}.${id}`;
554
765
  if (child.kind === "resource") {
555
- if (provisionWiring !== void 0) throw new LoadError(`provision("${id}") received deps for a resource — a resource has no dependency slots to satisfy.`);
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().`);
556
767
  if (provisionSecrets !== void 0) throw new LoadError(`provision("${id}") received secrets for a resource — a resource has no secret slots to satisfy.`);
557
768
  if (provisionInput !== void 0) throw new LoadError(`provision("${id}") received an input binding for a resource — a resource declares no input schema.`);
558
769
  if (provisionParams !== void 0) throw new LoadError(`provision("${id}") received params for a resource — a resource has no params to satisfy.`);
559
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));
560
773
  byId.set(fullAddress, child);
561
- nodes.push({
774
+ const slots = slotNodesAndEdges(child, fullAddress);
775
+ nodes.push(...slots.nodes, {
562
776
  id: fullAddress,
563
777
  parent: selfId,
564
778
  node: child
565
779
  });
566
- ports.push({
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({
567
784
  node: fullAddress,
568
785
  direction: "out",
569
786
  name: RESOURCE_OUT_PORT,
570
- contractKind: child.provides.kind,
571
- style: contractStyleOf(child.provides)
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
572
797
  });
573
798
  return refForResource(fullAddress, child);
574
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).`);
575
801
  const localWiring = { ...provisionWiring ?? {} };
576
802
  markUsed(Object.values(localWiring));
577
803
  const localSecrets = { ...provisionSecrets ?? {} };
@@ -598,7 +824,7 @@ function flatten(moduleNode, selfId, wiring, secretWiring, paramWiring, nodes, e
598
824
  slot,
599
825
  binding
600
826
  });
601
- const inputs = serviceInputs(child, fullAddress);
827
+ const inputs = slotNodesAndEdges(child, fullAddress);
602
828
  nodes.push(...inputs.nodes, {
603
829
  id: fullAddress,
604
830
  parent: selfId,
@@ -618,8 +844,8 @@ function flatten(moduleNode, selfId, wiring, secretWiring, paramWiring, nodes, e
618
844
  return refFor(fullAddress, child);
619
845
  }
620
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.`);
621
- validateSecretBinding(child, id, localSecrets, moduleNode.name);
622
- validateParamNeedBinding(child, id, localParams, moduleNode.name);
847
+ validateSecretBinding(child, id, fullAddress, localSecrets, moduleNode.name);
848
+ validateParamNeedBinding(child, id, fullAddress, localParams, moduleNode.name);
623
849
  edges.push(...wiringEdges(localWiring, fullAddress));
624
850
  recordAuthoredWiring(fullAddress, localWiring);
625
851
  pending.push({
@@ -629,7 +855,7 @@ function flatten(moduleNode, selfId, wiring, secretWiring, paramWiring, nodes, e
629
855
  targetKind: "module",
630
856
  enclosingModuleName: moduleNode.name
631
857
  });
632
- 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);
633
859
  nodes.push({
634
860
  id: fullAddress,
635
861
  parent: selfId,
@@ -650,14 +876,15 @@ function flatten(moduleNode, selfId, wiring, secretWiring, paramWiring, nodes, e
650
876
  });
651
877
  };
652
878
  const ctx = blindCast({
653
- inputs: ctxInputs,
879
+ deps: ctxInputs,
654
880
  secrets: ctxSecrets,
655
881
  params: ctxParams,
882
+ environment: environmentFacts,
656
883
  provision: blindCast(provision)
657
884
  });
658
885
  const outputs = blindCast(moduleNode.body(ctx) ?? {});
659
886
  markUsed(Object.values(outputs));
660
- for (const key of Object.keys(moduleNode.deps)) if (!used.has(key)) throw new LoadError(`Module "${moduleNode.name}" declares input "${key}" but never forwards it into a provision nor returns it as an output.`);
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.`);
661
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.`);
662
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.`);
663
890
  for (const [key, contract] of Object.entries(moduleNode.expose)) {
@@ -681,7 +908,7 @@ function loadModule(root, opts) {
681
908
  const rootDepKeys = Object.keys(root.deps);
682
909
  if (rootDepKeys.length > 0) {
683
910
  const names = rootDepKeys.map((k) => `"${k}"`).join(", ");
684
- throw new LoadError(`Module "${root.name}" declares input${rootDepKeys.length > 1 ? "s" : ""} ${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.`);
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.`);
685
912
  }
686
913
  const rootSecretKeys = Object.keys(root.secretSlots);
687
914
  if (rootSecretKeys.length > 0) {
@@ -701,9 +928,30 @@ function loadModule(root, opts) {
701
928
  const byId = /* @__PURE__ */ new Map();
702
929
  const ports = [];
703
930
  const authoredEdges = [];
704
- flatten(root, rootId, {}, {}, {}, nodes, edges, pending, inputBindings, paramBindings, byId, ports, authoredEdges);
705
- for (const entry of pending) validateWiring(entry, byId);
706
- assertDependencyDag(edges);
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
+ });
707
955
  const rootGraphNode = {
708
956
  id: rootId,
709
957
  parent: void 0,
@@ -711,18 +959,32 @@ function loadModule(root, opts) {
711
959
  };
712
960
  return {
713
961
  root: rootGraphNode,
714
- nodes: [...topoSort(nodes, edges), rootGraphNode],
962
+ nodes: [...topoSort(resolvedNodes, edges), rootGraphNode],
715
963
  edges,
716
964
  ports,
717
965
  authoredEdges,
718
- inputBindings,
719
- params: paramBindings
966
+ inputBindings: resolved.inputBindings,
967
+ params: resolved.params
720
968
  };
721
969
  }
722
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
+ /**
723
986
  * The dependency edges must form a DAG — a cycle means neither producer can
724
- * deploy first. Resources take no wiring, so only service/module-to-service/module
725
- * 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.
726
988
  */
727
989
  function assertDependencyDag(edges) {
728
990
  const adjacency = /* @__PURE__ */ new Map();
@@ -762,7 +1024,8 @@ function assertAppName(name) {
762
1024
  * module it provisions into one graph of hierarchical addresses. A malformed
763
1025
  * graph is a `LoadError` that names its fix; the individual validation rules
764
1026
  * live with `loadService` / `loadModule` and are covered by name in the Load
765
- * 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.
766
1029
  */
767
1030
  function Load(root, opts) {
768
1031
  if (!isNode(root)) throw new LoadError("Load expects a branded service or module node (construct it with the service()/module() factories).");
@@ -775,7 +1038,7 @@ function Load(root, opts) {
775
1038
  }
776
1039
  blindCast(Symbol.for("prisma:secret-box"));
777
1040
  //#endregion
778
- //#region ../../0-framework/3-tooling/cli/dist/pipeline-BmWt-Nhb.mjs
1041
+ //#region ../../0-framework/3-tooling/cli/dist/validate-environment-CEhUSEg2.mjs
779
1042
  /**
780
1043
  * Synchronous Node resolve hook so that entry modules may import relative
781
1044
  * files using the specifier forms TypeScript accepts by default —
@@ -1036,14 +1299,17 @@ async function resolveAppIdentity(entry, overrideName, cwd, config) {
1036
1299
  * guidance (destroy's "build first" hint) without this shared step knowing
1037
1300
  * about any one command.
1038
1301
  */
1039
- async function runPipeline(entry, overrideName, cwd, source, deps = {}, onAssembleError) {
1302
+ async function runPipeline(entry, overrideName, environment, cwd, source, deps = {}, onAssembleError) {
1040
1303
  const configSource = checkConfigSource(source, cwd);
1041
1304
  const config = configSource.value;
1042
1305
  const resolved = resolveEntryPath(entry, configSource, cwd);
1043
1306
  const entryModule = await loadEntry(resolved.path, cwd, resolved.fix);
1044
1307
  const name = overrideName ?? entryModule.root.name;
1045
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." });
1046
- const graph = Load(entryModule.root, { id: name });
1309
+ const graph = Load(entryModule.root, {
1310
+ id: name,
1311
+ environment: { name: environment }
1312
+ });
1047
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); })." });
1048
1314
  validateRegistryCoverage(graph, config);
1049
1315
  deps.onEvent?.({ kind: "loaded" });
@@ -1062,7 +1328,16 @@ async function runPipeline(entry, overrideName, cwd, source, deps = {}, onAssemb
1062
1328
  assembled
1063
1329
  };
1064
1330
  }
1331
+ /** Letters, digits, `-` and `_`, starting with a letter or digit: always a valid git ref, so no `git` is needed to check it. */
1332
+ const PLAIN_ENVIRONMENT_NAME = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
1333
+ /** An environment name must be a valid git ref (deploy-cli.md) — checked via `git check-ref-format`, never silently normalized. Runs before anything platform-specific. */
1334
+ function validateEnvironmentName(environment, spawn = spawnSync) {
1335
+ if (PLAIN_ENVIRONMENT_NAME.test(environment)) return;
1336
+ const result = spawn("git", ["check-ref-format", `refs/heads/${environment}`], { stdio: "ignore" });
1337
+ if (result.error) throw new CliStructuredError("DEPLOY.ENVIRONMENT_UNVALIDATABLE", `git is required to validate --environment "${environment}" (git check-ref-format): ${result.error.message}.`, { cause: result.error });
1338
+ if (result.status !== 0) throw new CliStructuredError("DEPLOY.ENVIRONMENT_INVALID", `Invalid --environment "${environment}": must be a valid git ref name (git check-ref-format rejected "refs/heads/${environment}").`);
1339
+ }
1065
1340
  //#endregion
1066
- export { resolveAppIdentity as n, runPipeline as r, checkConfigSource as t };
1341
+ export { validateEnvironmentName as i, resolveAppIdentity as n, runPipeline as r, checkConfigSource as t };
1067
1342
 
1068
- //# sourceMappingURL=pipeline-BmWt-Nhb-Bos4TFXR.mjs.map
1343
+ //# sourceMappingURL=validate-environment-CEhUSEg2-ExABehBM.mjs.map