@prisma/composer 0.6.0-dev.7 → 0.6.0-dev.9

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 (97) hide show
  1. package/dist/{app-config-Cbv_lA38-BHJsd1DF.d.mts → app-config-CFsSXEVj-B242oUnm.d.mts} +4 -4
  2. package/dist/{app-config-Cbv_lA38-BHJsd1DF.d.mts.map → app-config-CFsSXEVj-B242oUnm.d.mts.map} +1 -1
  3. package/dist/bin.mjs +6 -91
  4. package/dist/bin.mjs.map +1 -1
  5. package/dist/cli-B3sWzFlb-CxEIzKsQ.mjs +401 -0
  6. package/dist/cli-B3sWzFlb-CxEIzKsQ.mjs.map +1 -0
  7. package/dist/config-ku5b_2YD.d.mts +1 -0
  8. package/dist/config.d.mts +2 -2
  9. package/dist/container-transport-DKmKg5JQ-BMRhx5w-.mjs +75 -0
  10. package/dist/container-transport-DKmKg5JQ-BMRhx5w-.mjs.map +1 -0
  11. package/dist/control.d.mts +216 -0
  12. package/dist/control.d.mts.map +1 -0
  13. package/dist/control.mjs +70 -0
  14. package/dist/control.mjs.map +1 -0
  15. package/dist/deploy-ku5b_2YD.d.mts +1 -0
  16. package/dist/deploy.d.mts +2 -2
  17. package/dist/deploy.mjs +312 -1
  18. package/dist/deploy.mjs.map +1 -0
  19. package/dist/deployment-summary-r47O6kFr-CcMYVOn5.mjs +70 -0
  20. package/dist/deployment-summary-r47O6kFr-CcMYVOn5.mjs.map +1 -0
  21. package/dist/{dist-BdvFDCLV.mjs → dist-C5rZnr4n.mjs} +2 -2
  22. package/dist/{dist-BdvFDCLV.mjs.map → dist-C5rZnr4n.mjs.map} +1 -1
  23. package/dist/emulator-retry-DGonap4g-S8BNrXFD.mjs +24 -0
  24. package/dist/emulator-retry-DGonap4g-S8BNrXFD.mjs.map +1 -0
  25. package/dist/errors-0e8IVwzi.mjs +88 -0
  26. package/dist/errors-0e8IVwzi.mjs.map +1 -0
  27. package/dist/execute-deploy-destroy-IT4vGkMc-YM1Cv6cu.mjs +306 -0
  28. package/dist/execute-deploy-destroy-IT4vGkMc-YM1Cv6cu.mjs.map +1 -0
  29. package/dist/execute-deploy-destroy-IT4vGkMc-oO8yjHPH.mjs +265 -0
  30. package/dist/execute-deploy-destroy-IT4vGkMc-oO8yjHPH.mjs.map +1 -0
  31. package/dist/execute-dev-DLYyduEM-88uyvrbj.mjs +2009 -0
  32. package/dist/execute-dev-DLYyduEM-88uyvrbj.mjs.map +1 -0
  33. package/dist/execute-dev-DLYyduEM-BuUGTm0g.mjs +2006 -0
  34. package/dist/execute-dev-DLYyduEM-BuUGTm0g.mjs.map +1 -0
  35. package/dist/execute-log-VIOL4DBz-DBPH8By4.mjs +157 -0
  36. package/dist/execute-log-VIOL4DBz-DBPH8By4.mjs.map +1 -0
  37. package/dist/execute-log-VIOL4DBz-DKodBrxS.mjs +155 -0
  38. package/dist/execute-log-VIOL4DBz-DKodBrxS.mjs.map +1 -0
  39. package/dist/{graph-DgbALPDo-BEHF94BN.mjs → graph-BJgUfGB0-kvgFzT4q.mjs} +13 -7
  40. package/dist/graph-BJgUfGB0-kvgFzT4q.mjs.map +1 -0
  41. package/dist/{graph-DDpXh7S8-b-93BcHn.d.mts → graph-DqklX5Sf-BNS2aO1j.d.mts} +3 -3
  42. package/dist/graph-DqklX5Sf-BNS2aO1j.d.mts.map +1 -0
  43. package/dist/{graph-types-C3FOaaXm-C6_rGzfn.d.mts → graph-types-N6brq1zY-1VMNwtkJ.d.mts} +88 -5
  44. package/dist/graph-types-N6brq1zY-1VMNwtkJ.d.mts.map +1 -0
  45. package/dist/{index-BQVrMGfe.d.mts → index-DryPyF9U.d.mts} +3 -3
  46. package/dist/{index-BQVrMGfe.d.mts.map → index-DryPyF9U.d.mts.map} +1 -1
  47. package/dist/index.d.mts +3 -3
  48. package/dist/index.mjs +2 -2
  49. package/dist/internal-error-BIc-ehme-Ck_lgxD_.mjs +18 -0
  50. package/dist/internal-error-BIc-ehme-Ck_lgxD_.mjs.map +1 -0
  51. package/dist/local-target-DnA2E8IN.mjs +47 -0
  52. package/dist/local-target-DnA2E8IN.mjs.map +1 -0
  53. package/dist/local-target-DuSyWeYc.mjs +68 -0
  54. package/dist/local-target-DuSyWeYc.mjs.map +1 -0
  55. package/dist/local-target.d.mts +1 -1
  56. package/dist/local-target.mjs +2 -46
  57. package/dist/{nextjs-DLyeRR7M-D47aMmfr.d.mts → nextjs-DLyeRR7M-DZODs9tk.d.mts} +3 -3
  58. package/dist/{nextjs-DLyeRR7M-D47aMmfr.d.mts.map → nextjs-DLyeRR7M-DZODs9tk.d.mts.map} +1 -1
  59. package/dist/nextjs-control.d.mts +4 -4
  60. package/dist/nextjs.d.mts +1 -1
  61. package/dist/node-control.d.mts +3 -3
  62. package/dist/node.d.mts +2 -2
  63. package/dist/pipeline-D3QoVzAB-Ci2aJ2mE.mjs +331 -0
  64. package/dist/pipeline-D3QoVzAB-Ci2aJ2mE.mjs.map +1 -0
  65. package/dist/pipeline-D3QoVzAB-D_ufjg3N.mjs +857 -0
  66. package/dist/pipeline-D3QoVzAB-D_ufjg3N.mjs.map +1 -0
  67. package/dist/render-error-DsPN5qfr-CkVGj9uP.mjs +30 -0
  68. package/dist/render-error-DsPN5qfr-CkVGj9uP.mjs.map +1 -0
  69. package/dist/report.d.mts +4 -3
  70. package/dist/report.d.mts.map +1 -1
  71. package/dist/report.mjs +4 -1
  72. package/dist/report.mjs.map +1 -1
  73. package/dist/result-CFqJKiqg.mjs +106 -0
  74. package/dist/result-CFqJKiqg.mjs.map +1 -0
  75. package/dist/result-CzGChwbZ.mjs +231 -0
  76. package/dist/result-CzGChwbZ.mjs.map +1 -0
  77. package/dist/run-alchemy-hghRtddF-CQHOzlrW.mjs +48 -0
  78. package/dist/run-alchemy-hghRtddF-CQHOzlrW.mjs.map +1 -0
  79. package/dist/service-rpc.d.mts +2 -2
  80. package/dist/service-rpc.mjs +2 -2
  81. package/dist/shared-CCaR42wo-BvegvmA_.mjs +265 -0
  82. package/dist/shared-CCaR42wo-BvegvmA_.mjs.map +1 -0
  83. package/dist/testing.d.mts +1 -1
  84. package/package.json +11 -10
  85. package/src/exports/control.ts +1 -0
  86. package/dist/cli-IDJ-0ZFU-Dz2KMWtU.mjs +0 -3269
  87. package/dist/cli-IDJ-0ZFU-Dz2KMWtU.mjs.map +0 -1
  88. package/dist/cli-error-HxLpXiUX-LVlg5SlD.mjs +0 -16
  89. package/dist/cli-error-HxLpXiUX-LVlg5SlD.mjs.map +0 -1
  90. package/dist/config-whuqZ5xT.d.mts +0 -1
  91. package/dist/deploy-C4DxNkJ9-D73lmBqy.mjs +0 -313
  92. package/dist/deploy-C4DxNkJ9-D73lmBqy.mjs.map +0 -1
  93. package/dist/deploy-whuqZ5xT.d.mts +0 -1
  94. package/dist/graph-DDpXh7S8-b-93BcHn.d.mts.map +0 -1
  95. package/dist/graph-DgbALPDo-BEHF94BN.mjs.map +0 -1
  96. package/dist/graph-types-C3FOaaXm-C6_rGzfn.d.mts.map +0 -1
  97. package/dist/local-target.mjs.map +0 -1
@@ -0,0 +1,857 @@
1
+ import { a as CliStructuredError, o as blindCast } from "./shared-CCaR42wo-BvegvmA_.mjs";
2
+ import { i as InternalError } from "./result-CFqJKiqg.mjs";
3
+ import * as fs from "node:fs";
4
+ import * as path from "node:path";
5
+ import { pathToFileURL } from "node:url";
6
+ import * as c12 from "c12";
7
+ //#region ../../0-framework/1-core/core/dist/graph-BJgUfGB0.mjs
8
+ /**
9
+ * Thrown by Load when the graph is malformed. Structured at origin
10
+ * (base-type rule 6): one type-level code covers every raise site until a
11
+ * finer per-site taxonomy is carved out. The `name` stays
12
+ * `CliStructuredError` — structural recognition depends on it.
13
+ */
14
+ var LoadError = class extends CliStructuredError {
15
+ constructor(message) {
16
+ super("COMPOSE.GRAPH_INVALID", message);
17
+ }
18
+ };
19
+ /**
20
+ * Core model: node types and the factories that construct them, plain frozen
21
+ * data objects. A node's `extension` + `type` form its deploy-time registry key (ADR-0017).
22
+ */
23
+ const NODE = Symbol.for("prisma:node");
24
+ blindCast(Symbol.for("prisma:secret-need"));
25
+ const SECRET_SOURCE = blindCast(Symbol.for("prisma:secret-source"));
26
+ /** True if `value` is a secret source (an `envSecret` result or a forwarded ctx.secrets ref). */
27
+ function isSecretSource(value) {
28
+ return typeof value === "object" && value !== null && blindCast(value)[SECRET_SOURCE] === true;
29
+ }
30
+ blindCast(Symbol.for("prisma:provision-need"));
31
+ const PARAM_SOURCE = blindCast(Symbol.for("prisma:param-source"));
32
+ blindCast(Symbol.for("prisma:param-need"));
33
+ /** True if `value` is a param source (an `envParam` result or a forwarded ctx.params ref). */
34
+ function isParamSource(value) {
35
+ return typeof value === "object" && value !== null && blindCast(value)[PARAM_SOURCE] === true;
36
+ }
37
+ /**
38
+ * Core's grammar for every name that becomes a config-key segment —
39
+ * addresses, input/param/secret names: ASCII letters and digits only.
40
+ * Conservative by design so any target medium — POSIX env-var keys
41
+ * included — can uppercase and "_"-join segments without escaping.
42
+ */
43
+ function isConfigKeySegment(name) {
44
+ return /^[A-Za-z0-9]+$/.test(name);
45
+ }
46
+ /**
47
+ * True if `value` was constructed by this module's factories. Checks the
48
+ * brand only, never a prototype — a graph may mix nodes from a different
49
+ * installed copy of core (dual-package hazard).
50
+ */
51
+ function isNode(value) {
52
+ return typeof value === "object" && value !== null && value[NODE] === true;
53
+ }
54
+ /**
55
+ * Stable topological sort: every edge's `from` precedes its `to` in the
56
+ * result. Ties (nodes with no ordering constraint between them) keep their
57
+ * relative order from `nodes` — so a graph already authored producer-first
58
+ * comes out byte-identical to its pre-sort layout; only a graph that
59
+ * genuinely needs reordering (e.g. a module wired via a forged ref pointing at a
60
+ * not-yet-provisioned producer) actually moves. A Kahn's-algorithm variant
61
+ * that always picks the ready node with the smallest original index. Edges
62
+ * whose endpoint falls outside `nodes` (e.g. a service-root's input edges
63
+ * targeting the root, which is appended separately) are ignored. Cycles
64
+ * cannot reach here: `assertDependencyDag` already rejects them for
65
+ * dependency edges, and input edges never cycle.
66
+ */
67
+ function topoSort(nodes, edges) {
68
+ const byId = new Map(nodes.map((n) => [n.id, n]));
69
+ const indexOf = new Map(nodes.map((n, i) => [n.id, i]));
70
+ const indegree = new Map(nodes.map((n) => [n.id, 0]));
71
+ const successors = /* @__PURE__ */ new Map();
72
+ for (const edge of edges) {
73
+ if (!byId.has(edge.from) || !byId.has(edge.to)) continue;
74
+ const targets = successors.get(edge.from) ?? [];
75
+ targets.push(edge.to);
76
+ successors.set(edge.from, targets);
77
+ indegree.set(edge.to, (indegree.get(edge.to) ?? 0) + 1);
78
+ }
79
+ const ready = new Set(nodes.filter((n) => indegree.get(n.id) === 0).map((n) => n.id));
80
+ const order = [];
81
+ while (ready.size > 0) {
82
+ let next;
83
+ let bestIndex = Number.POSITIVE_INFINITY;
84
+ for (const id of ready) {
85
+ const index = indexOf.get(id) ?? Number.POSITIVE_INFINITY;
86
+ if (index < bestIndex) {
87
+ bestIndex = index;
88
+ next = id;
89
+ }
90
+ }
91
+ if (next === void 0) break;
92
+ ready.delete(next);
93
+ order.push(next);
94
+ for (const target of successors.get(next) ?? []) {
95
+ const remaining = (indegree.get(target) ?? 0) - 1;
96
+ indegree.set(target, remaining);
97
+ if (remaining === 0) ready.add(target);
98
+ }
99
+ }
100
+ if (order.length !== nodes.length) throw new InternalError(`topological sort processed ${order.length} of ${nodes.length} nodes — the graph contains a cycle that slipped past the DAG validation.`);
101
+ return order.map((id) => byId.get(id)).filter((n) => n !== void 0);
102
+ }
103
+ function serviceInputs(service, serviceId) {
104
+ if (typeof service.inputs !== "object" || service.inputs === null) throw new LoadError(`Service "${serviceId}" has no inputs map.`);
105
+ const nodes = [];
106
+ const edges = [];
107
+ for (const [input, value] of Object.entries(service.inputs)) {
108
+ const kind = isNode(value) ? value.kind : void 0;
109
+ 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.`);
110
+ if (kind !== "dependency") throw new LoadError(`Input "${input}" of "${serviceId}" is not a branded dependency end (construct it with the dependency() factory).`);
111
+ if (value.type.length === 0) throw new LoadError(`Input "${input}" of "${serviceId}" has an empty node type.`);
112
+ const id = `${serviceId}.${input}`;
113
+ nodes.push({
114
+ id,
115
+ node: value
116
+ });
117
+ edges.push({
118
+ from: id,
119
+ to: serviceId,
120
+ input,
121
+ kind: "input"
122
+ });
123
+ }
124
+ return {
125
+ nodes,
126
+ edges
127
+ };
128
+ }
129
+ function loadService(root, rootId) {
130
+ 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.`);
131
+ 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).`);
132
+ const rootGraphNode = {
133
+ id: rootId,
134
+ node: root
135
+ };
136
+ const { nodes, edges } = serviceInputs(root, rootId);
137
+ return {
138
+ root: rootGraphNode,
139
+ nodes: [...topoSort(nodes, edges), rootGraphNode],
140
+ edges,
141
+ inputBindings: [],
142
+ params: []
143
+ };
144
+ }
145
+ /**
146
+ * Builds the ref a provision() call hands back: the id (so a producer with no
147
+ * exposed ports — or an untyped slot — can still be wired wholesale) plus one
148
+ * ref-port per exposed contract, each the contract's own runtime value (so
149
+ * its `satisfies()` still works) tagged with the provider's id.
150
+ */
151
+ function refFor(id, service) {
152
+ const ports = {};
153
+ for (const [port, contract] of Object.entries(service.expose ?? {})) ports[port] = {
154
+ ...contract,
155
+ __providerId: id
156
+ };
157
+ return blindCast({
158
+ id,
159
+ ...ports
160
+ });
161
+ }
162
+ /**
163
+ * The resource variant of refFor: a resource has exactly one port — the
164
+ * contract it provides — flattened onto the ref itself, tagged with the
165
+ * provider id. `id` is written last so a hostile contract value cannot
166
+ * clobber it.
167
+ */
168
+ function refForResource(id, resource) {
169
+ return blindCast({
170
+ ...resource.provides,
171
+ __providerId: id,
172
+ id
173
+ });
174
+ }
175
+ /** A wired value's producer id: a ref-port's `__providerId`, or a bare ref's `id`. */
176
+ function producerIdOf(ref) {
177
+ if (typeof ref !== "object" || ref === null) return void 0;
178
+ if ("__providerId" in ref && typeof ref.__providerId === "string") return ref.__providerId;
179
+ if ("id" in ref && typeof ref.id === "string") return ref.id;
180
+ }
181
+ /**
182
+ * Brands each `ctx.inputs` entry with the input key it stands for (see
183
+ * flatten): diagnostic only — usage attribution relies on the per-key object
184
+ * identity the branding copy creates, never on reading this back.
185
+ */
186
+ const MODULE_INPUT_KEY = Symbol("prisma:module-input-key");
187
+ /** Same per-key identity trick as MODULE_INPUT_KEY, for the parallel `ctx.secrets` forwarding channel. */
188
+ const MODULE_SECRET_KEY = Symbol("prisma:module-secret-key");
189
+ /** Same per-key identity trick as MODULE_INPUT_KEY, for the parallel `ctx.params` forwarding channel. */
190
+ const MODULE_PARAM_KEY = Symbol("prisma:module-param-key");
191
+ /** Whether `ref` carries a callable `satisfies` that accepts `required` truthily. */
192
+ function satisfiesRequired(ref, required) {
193
+ return typeof ref === "object" && ref !== null && "satisfies" in ref && typeof ref.satisfies === "function" && ref.satisfies(required);
194
+ }
195
+ /**
196
+ * Checks one recorded `wiring` object against the Deps it was wired against:
197
+ * every named input exists and is a dependency slot, every referenced
198
+ * producer is a real (by-now-provisioned) address, and a wired ref whose
199
+ * slot declares a required contract must satisfy() it — no producer-kind
200
+ * branching, the contract alone determines validity, whether the producer is
201
+ * a service port or a resource. Shared by both provisioned kinds so a
202
+ * module-as-child gets exactly the checks a service gets, and run once per
203
+ * entry against the one `byId` shared by the whole recursive flatten, so a
204
+ * forwarded ref resolves through to its real producer address regardless of
205
+ * which ancestor scope provisioned it.
206
+ */
207
+ function validateWiring(pending, byId) {
208
+ const { deps, wiring, targetId, targetKind, enclosingModuleName } = pending;
209
+ for (const [input, ref] of Object.entries(wiring)) {
210
+ const declared = blindCast(deps[input]);
211
+ if (declared === void 0 || !isNode(declared) || declared.kind !== "dependency") throw new LoadError(`The deps for "${targetId}" name "${input}", which is not a dependency slot of that ${targetKind}.`);
212
+ const producerId = producerIdOf(ref);
213
+ const producer = producerId !== void 0 ? byId.get(producerId) : void 0;
214
+ if (producerId === void 0 || producer === void 0) throw new LoadError(`The deps for "${targetId}.${input}" reference "${String(producerId)}", which is not provisioned in module "${enclosingModuleName}".`);
215
+ const required = declared.required;
216
+ if (required !== void 0 && !satisfiesRequired(ref, required)) throw new LoadError(`The deps for "${targetId}.${input}" do not satisfy the slot's required contract.`);
217
+ }
218
+ for (const [input, rawValue] of Object.entries(deps)) {
219
+ const value = blindCast(rawValue);
220
+ if (!isNode(value) || wiring[input] !== void 0) continue;
221
+ if (value.kind === "dependency") throw new LoadError(`Dependency input "${input}" of provisioned ${targetKind} "${targetId}" is not wired to a producer (module "${enclosingModuleName}").`);
222
+ }
223
+ }
224
+ /**
225
+ * Flattens a value into itself plus every nested object/array member value —
226
+ * identity fodder for the ctx.secrets/ctx.params usage marking, which must
227
+ * see a forwarded source wherever it sits inside an input binding (ADR-0042).
228
+ * A secret/param source is an opaque leaf: it is pushed (a forwarded ref IS
229
+ * such a source, so identity-matching still needs it) but never descended
230
+ * into, so a ref buried in an unrelated source's payload is not falsely seen
231
+ * as used. `seen` guards object cycles so a self-referential binding cannot
232
+ * recurse forever.
233
+ */
234
+ function deepValues(value, out, seen = /* @__PURE__ */ new WeakSet()) {
235
+ out.push(value);
236
+ if (typeof value !== "object" || value === null) return;
237
+ if (isSecretSource(value) || isParamSource(value)) return;
238
+ if (seen.has(value)) return;
239
+ seen.add(value);
240
+ const members = Array.isArray(value) ? value : Object.values(value);
241
+ for (const member of members) deepValues(member, out, seen);
242
+ }
243
+ /** The (unvalidated) edges a `wiring` object implies — one dependency edge per entry; `validateWiring` does the real checking. */
244
+ function wiringEdges(wiring, targetId) {
245
+ return Object.entries(wiring).map(([input, ref]) => ({
246
+ from: producerIdOf(ref) ?? "",
247
+ to: targetId,
248
+ input,
249
+ kind: "dependency"
250
+ }));
251
+ }
252
+ /**
253
+ * Checks the secrets wired into one provisioned child MODULE: every declared
254
+ * forwarding slot is bound to a real secret source (an `envSecret` or a
255
+ * forwarded ctx.secrets ref), and no wired key names a slot the module
256
+ * doesn't declare — the secret analog of `validateWiring`'s per-input checks,
257
+ * but resolved inline (a source carries its own name, so no whole-graph pass
258
+ * is needed).
259
+ */
260
+ function validateSecretBinding(child, id, secretWiring, enclosingModuleName) {
261
+ const { kind } = child;
262
+ for (const slot of Object.keys(child.secretSlots)) {
263
+ const bound = secretWiring[slot];
264
+ 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.`);
265
+ 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.`);
266
+ }
267
+ 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}").`);
268
+ }
269
+ /**
270
+ * Checks the params wired into a provisioned SERVICE: unlike a secret slot, a
271
+ * declared param is never required to be bound here — it may fall back to its
272
+ * own `default` (checked later, at `buildConfig`) — so this only rejects a
273
+ * wired key that names something other than a real declared param.
274
+ */
275
+ function validateServiceParamBinding(child, id, paramWiring, enclosingModuleName) {
276
+ for (const slot of Object.keys(paramWiring)) if (!Object.hasOwn(child.params, slot)) throw new LoadError(`The params for "${id}" name "${slot}", which is not a param of that service (module "${enclosingModuleName}").`);
277
+ }
278
+ /**
279
+ * Checks the params wired into a provisioned MODULE: every declared
280
+ * param-forwarding slot must be bound to a real `ParamSource` — a slot has no
281
+ * schema of its own, so (unlike a service param) it cannot fall back to a
282
+ * literal or a default; the param analog of `validateSecretBinding`.
283
+ */
284
+ function validateParamNeedBinding(child, id, paramWiring, enclosingModuleName) {
285
+ for (const slot of Object.keys(child.paramSlots)) {
286
+ const bound = paramWiring[slot];
287
+ 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.`);
288
+ 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.`);
289
+ }
290
+ 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}").`);
291
+ }
292
+ /**
293
+ * Recursively flattens one module's body into the shared graph state and
294
+ * returns its resolved ModuleOutputs (one ref-port per expose key) for the
295
+ * caller (the enclosing provision() call, or Load itself for the root) to
296
+ * use. `address` is this module's OWN full address, or `undefined` for the root
297
+ * scope — its direct children then get bare (unprefixed) addresses, keeping
298
+ * a single-level module identical to before nesting existed. `wiring` supplies a
299
+ * resolved producer ref-port for each of this module's OWN declared deps (empty
300
+ * for the root, which may not declare any — see the root non-empty-deps
301
+ * check in loadModule). `nodes`, `edges`, `pending`, and `byId` are shared
302
+ * across the ENTIRE recursive flatten, not per scope — a nested module may
303
+ * forward in a producer provisioned by an ancestor scope, and it is the
304
+ * shared `byId` (keyed by full address) that lets that resolve.
305
+ */
306
+ function flatten(moduleNode, address, wiring, secretWiring, paramWiring, nodes, edges, pending, inputBindings, paramBindings, byId) {
307
+ const localIds = /* @__PURE__ */ new Set();
308
+ const used = /* @__PURE__ */ new Set();
309
+ const usedSecrets = /* @__PURE__ */ new Set();
310
+ const usedParams = /* @__PURE__ */ new Set();
311
+ const ctxInputs = {};
312
+ for (const key of Object.keys(moduleNode.deps)) {
313
+ const wired = wiring[key];
314
+ ctxInputs[key] = typeof wired === "object" && wired !== null ? {
315
+ ...wired,
316
+ [MODULE_INPUT_KEY]: key
317
+ } : wired;
318
+ }
319
+ const markUsed = (values) => {
320
+ for (const value of values) for (const key of Object.keys(ctxInputs)) if (value === ctxInputs[key]) used.add(key);
321
+ };
322
+ const ctxSecrets = {};
323
+ for (const key of Object.keys(moduleNode.secretSlots)) {
324
+ const bound = secretWiring[key];
325
+ ctxSecrets[key] = typeof bound === "object" && bound !== null ? {
326
+ ...bound,
327
+ [MODULE_SECRET_KEY]: key
328
+ } : bound;
329
+ }
330
+ const markSecretsUsed = (values) => {
331
+ for (const value of values) for (const key of Object.keys(ctxSecrets)) if (value === ctxSecrets[key]) usedSecrets.add(key);
332
+ };
333
+ const ctxParams = {};
334
+ for (const key of Object.keys(moduleNode.paramSlots)) {
335
+ const bound = paramWiring[key];
336
+ ctxParams[key] = typeof bound === "object" && bound !== null ? {
337
+ ...bound,
338
+ [MODULE_PARAM_KEY]: key
339
+ } : bound;
340
+ }
341
+ const markParamsUsed = (values) => {
342
+ for (const value of values) for (const key of Object.keys(ctxParams)) if (value === ctxParams[key]) usedParams.add(key);
343
+ };
344
+ const provision = (child, opts) => {
345
+ const id = opts?.id ?? child.name;
346
+ const provisionWiring = opts?.deps;
347
+ const provisionSecrets = opts?.secrets;
348
+ const provisionInput = opts?.input;
349
+ const provisionParams = opts?.params;
350
+ if (typeof id !== "string" || id.length === 0) throw new LoadError(`provision() requires a non-empty id (module "${moduleNode.name}").`);
351
+ 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.)`);
352
+ if (localIds.has(id)) throw new LoadError(`Duplicate provision id "${id}" in module "${moduleNode.name}".`);
353
+ const untrusted = child;
354
+ if (!isNode(untrusted) || untrusted.kind !== "service" && untrusted.kind !== "resource" && untrusted.kind !== "module") throw new LoadError(`provision("${id}") expects a branded service, resource, or module node (construct it with the service()/resource()/module() factories or a pack's own).`);
355
+ localIds.add(id);
356
+ const fullAddress = address === void 0 ? id : `${address}.${id}`;
357
+ if (child.kind === "resource") {
358
+ if (provisionWiring !== void 0) throw new LoadError(`provision("${id}") received deps for a resource — a resource has no dependency slots to satisfy.`);
359
+ if (provisionSecrets !== void 0) throw new LoadError(`provision("${id}") received secrets for a resource — a resource has no secret slots to satisfy.`);
360
+ if (provisionInput !== void 0) throw new LoadError(`provision("${id}") received an input binding for a resource — a resource declares no input schema.`);
361
+ if (provisionParams !== void 0) throw new LoadError(`provision("${id}") received params for a resource — a resource has no params to satisfy.`);
362
+ if (child.type.length === 0) throw new LoadError(`provision("${id}") received a resource with an empty node type.`);
363
+ byId.set(fullAddress, child);
364
+ nodes.push({
365
+ id: fullAddress,
366
+ node: child
367
+ });
368
+ return refForResource(fullAddress, child);
369
+ }
370
+ const localWiring = { ...provisionWiring ?? {} };
371
+ markUsed(Object.values(localWiring));
372
+ const localSecrets = { ...provisionSecrets ?? {} };
373
+ markSecretsUsed(Object.values(localSecrets));
374
+ const localParams = { ...provisionParams ?? {} };
375
+ markParamsUsed(Object.values(localParams));
376
+ if (child.kind === "service") {
377
+ if (provisionSecrets !== void 0) throw new LoadError(`provision("${id}") received secrets for a service — a service takes its secrets as envSecret(...) leaves of its \`input\` binding (ADR-0042), not a secrets map.`);
378
+ if (child.inputSchema !== void 0 && provisionInput === void 0) throw new LoadError(`Input of provisioned service "${id}" is not bound (module "${moduleNode.name}") — the service declares an input schema; bind it with \`input: { … }\` on its provision() call.`);
379
+ if (child.inputSchema === void 0 && provisionInput !== void 0) throw new LoadError(`provision("${id}") received an input binding, but the service declares no input schema (module "${moduleNode.name}").`);
380
+ if (provisionInput !== void 0) {
381
+ const leaves = [];
382
+ deepValues(provisionInput, leaves);
383
+ markSecretsUsed(leaves);
384
+ markParamsUsed(leaves);
385
+ inputBindings.push({
386
+ serviceAddress: fullAddress,
387
+ binding: blindCast(provisionInput)
388
+ });
389
+ }
390
+ validateServiceParamBinding(child, id, localParams, moduleNode.name);
391
+ for (const [slot, binding] of Object.entries(localParams)) paramBindings.push({
392
+ serviceAddress: fullAddress,
393
+ slot,
394
+ binding
395
+ });
396
+ const inputs = serviceInputs(child, fullAddress);
397
+ nodes.push(...inputs.nodes, {
398
+ id: fullAddress,
399
+ node: child
400
+ });
401
+ edges.push(...inputs.edges, ...wiringEdges(localWiring, fullAddress));
402
+ pending.push({
403
+ deps: child.inputs,
404
+ wiring: localWiring,
405
+ targetId: fullAddress,
406
+ targetKind: "service",
407
+ enclosingModuleName: moduleNode.name
408
+ });
409
+ byId.set(fullAddress, child);
410
+ return refFor(fullAddress, child);
411
+ }
412
+ 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.`);
413
+ validateSecretBinding(child, id, localSecrets, moduleNode.name);
414
+ validateParamNeedBinding(child, id, localParams, moduleNode.name);
415
+ edges.push(...wiringEdges(localWiring, fullAddress));
416
+ pending.push({
417
+ deps: child.deps,
418
+ wiring: localWiring,
419
+ targetId: fullAddress,
420
+ targetKind: "module",
421
+ enclosingModuleName: moduleNode.name
422
+ });
423
+ const childOutputs = flatten(child, fullAddress, localWiring, localSecrets, localParams, nodes, edges, pending, inputBindings, paramBindings, byId);
424
+ nodes.push({
425
+ id: fullAddress,
426
+ node: child
427
+ });
428
+ byId.set(fullAddress, child);
429
+ return blindCast({
430
+ id: fullAddress,
431
+ ...childOutputs
432
+ });
433
+ };
434
+ const ctx = blindCast({
435
+ inputs: ctxInputs,
436
+ secrets: ctxSecrets,
437
+ params: ctxParams,
438
+ provision: blindCast(provision)
439
+ });
440
+ const outputs = blindCast(moduleNode.body(ctx) ?? {});
441
+ markUsed(Object.values(outputs));
442
+ 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.`);
443
+ 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.`);
444
+ 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.`);
445
+ for (const [key, contract] of Object.entries(moduleNode.expose)) {
446
+ const port = outputs[key];
447
+ if (port === void 0) throw new LoadError(`Module "${moduleNode.name}" declares expose "${key}" but its body did not return a port for it.`);
448
+ if (!satisfiesRequired(port, contract)) throw new LoadError(`Module "${moduleNode.name}"'s returned port for expose "${key}" does not satisfy its declared contract.`);
449
+ }
450
+ return outputs;
451
+ }
452
+ function loadModule(root, opts) {
453
+ const rootId = opts?.id ?? root.name;
454
+ const rootDepKeys = Object.keys(root.deps);
455
+ if (rootDepKeys.length > 0) {
456
+ const names = rootDepKeys.map((k) => `"${k}"`).join(", ");
457
+ 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.`);
458
+ }
459
+ const rootSecretKeys = Object.keys(root.secretSlots);
460
+ if (rootSecretKeys.length > 0) {
461
+ const names = rootSecretKeys.map((k) => `"${k}"`).join(", ");
462
+ throw new LoadError(`Module "${root.name}" declares secret${rootSecretKeys.length > 1 ? "s" : ""} ${names} but is being deployed as the root — a root has no enclosing scope to bind them; the root binds secrets with envSecret('NAME'), it does not declare secret slots of its own.`);
463
+ }
464
+ const rootParamKeys = Object.keys(root.paramSlots);
465
+ if (rootParamKeys.length > 0) {
466
+ const names = rootParamKeys.map((k) => `"${k}"`).join(", ");
467
+ throw new LoadError(`Module "${root.name}" declares param${rootParamKeys.length > 1 ? "s" : ""} ${names} but is being deployed as the root — a root has no enclosing scope to bind them; the root binds params directly on each provision() call, it does not declare param-forwarding slots of its own.`);
468
+ }
469
+ const nodes = [];
470
+ const edges = [];
471
+ const pending = [];
472
+ const inputBindings = [];
473
+ const paramBindings = [];
474
+ const byId = /* @__PURE__ */ new Map();
475
+ flatten(root, void 0, {}, {}, {}, nodes, edges, pending, inputBindings, paramBindings, byId);
476
+ for (const entry of pending) validateWiring(entry, byId);
477
+ assertDependencyDag(edges);
478
+ const rootGraphNode = {
479
+ id: rootId,
480
+ node: root
481
+ };
482
+ return {
483
+ root: rootGraphNode,
484
+ nodes: [...topoSort(nodes, edges), rootGraphNode],
485
+ edges,
486
+ inputBindings,
487
+ params: paramBindings
488
+ };
489
+ }
490
+ /**
491
+ * The dependency edges must form a DAG — a cycle means neither producer can
492
+ * deploy first. Resources take no wiring, so only service/module-to-service/module
493
+ * edges can ever participate in a cycle; no special-casing needed.
494
+ */
495
+ function assertDependencyDag(edges) {
496
+ const adjacency = /* @__PURE__ */ new Map();
497
+ for (const edge of edges) {
498
+ if (edge.kind !== "dependency") continue;
499
+ const targets = adjacency.get(edge.from) ?? [];
500
+ targets.push(edge.to);
501
+ adjacency.set(edge.from, targets);
502
+ }
503
+ const visiting = /* @__PURE__ */ new Set();
504
+ const done = /* @__PURE__ */ new Set();
505
+ const stack = [];
506
+ const visit = (id) => {
507
+ if (done.has(id)) return;
508
+ if (visiting.has(id)) throw new LoadError(`Dependency cycle: ${[...stack.slice(stack.indexOf(id)), id].join(" → ")} — no deploy order exists.`);
509
+ visiting.add(id);
510
+ stack.push(id);
511
+ for (const next of adjacency.get(id) ?? []) visit(next);
512
+ stack.pop();
513
+ visiting.delete(id);
514
+ done.add(id);
515
+ };
516
+ for (const id of adjacency.keys()) visit(id);
517
+ }
518
+ /**
519
+ * Builds the in-memory graph from a root node. A service root walks its own
520
+ * `inputs`; a module root executes its body (wiring, not user code — the
521
+ * designed exception to imports-run-nothing) and recursively flattens every
522
+ * module it provisions into one graph of hierarchical addresses. A malformed
523
+ * graph is a `LoadError` that names its fix; the individual validation rules
524
+ * live with `loadService` / `loadModule` and are covered by name in the Load
525
+ * tests. Executes nothing of the user's own code beyond module bodies.
526
+ */
527
+ function Load(root, opts) {
528
+ if (!isNode(root)) throw new LoadError("Load expects a branded service or module node (construct it with the service()/module() factories).");
529
+ if (root.kind === "module") return loadModule(root, opts);
530
+ if (root.kind === "service") return loadService(root, opts?.id ?? "root");
531
+ throw new LoadError("Load expects a service or module root (received another node kind).");
532
+ }
533
+ blindCast(Symbol.for("prisma:secret-box"));
534
+ //#endregion
535
+ //#region ../../0-framework/3-tooling/cli/dist/load-entry-ZpkCjTxj.mjs
536
+ /**
537
+ * `loadEntry` imports a user's topology with the host runtime's own module
538
+ * loader — under node (the CLI's shebang runtime), that loader strips
539
+ * TypeScript types but has no JSX transform (ADR-0005: the framework
540
+ * doesn't bundle or transform the app's code; deploy loading is no
541
+ * exception). A `.tsx`/`.jsx` file anywhere in the topology's import graph
542
+ * dies with node's raw `ERR_UNKNOWN_FILE_EXTENSION`, which names the file
543
+ * but not the cause or the fix. This turns that one case into structured
544
+ * error parts (summary/why/fix) that do — every other load failure (syntax
545
+ * errors, missing files, non-JSX unknown extensions) is untouched.
546
+ */
547
+ const UNKNOWN_EXTENSION_CODE = "ERR_UNKNOWN_FILE_EXTENSION";
548
+ const JSX_EXTENSIONS = [".tsx", ".jsx"];
549
+ function errorCode(error) {
550
+ return "code" in error && typeof error.code === "string" ? error.code : void 0;
551
+ }
552
+ function unknownExtensionPath(error) {
553
+ if (!(error instanceof Error)) return void 0;
554
+ if (errorCode(error) !== UNKNOWN_EXTENSION_CODE) return void 0;
555
+ return /Unknown file extension "\.\w+" for (.+)$/.exec(error.message)?.[1];
556
+ }
557
+ /**
558
+ * Returns structured error parts when `error` is node's
559
+ * `ERR_UNKNOWN_FILE_EXTENSION` for a `.tsx`/`.jsx` file — `undefined` for
560
+ * every other error (including unknown-extension failures for some other
561
+ * extension), so the caller can fall through to its normal rethrow.
562
+ */
563
+ function explainJsxLoadError(error, entryPath) {
564
+ const offendingPath = unknownExtensionPath(error);
565
+ if (offendingPath === void 0) return void 0;
566
+ if (!JSX_EXTENSIONS.some((ext) => offendingPath.endsWith(ext))) return void 0;
567
+ return {
568
+ summary: `"${offendingPath}" can't be loaded.`,
569
+ why: `deploy loads "${entryPath}"'s topology with node's own module loader, which strips TypeScript types but has no JSX transform — so a .tsx/.jsx file can't sit anywhere in that import graph.`,
570
+ fix: "Precompile that file in your own build (transform the JSX away, keep the real npm packages external) and import the compiled output instead of the raw .tsx/.jsx — see examples/email/scripts/build.ts in the prisma/composer repo for a worked example."
571
+ };
572
+ }
573
+ /**
574
+ * Pipeline step 1 (deploy-cli.md § The pipeline): import the entry module
575
+ * (resolved against cwd) and require its default export to be a node — a
576
+ * service or module, branded by core's factories. Whatever this module exports
577
+ * IS the application; nothing else marks a root (ADR-0003).
578
+ */
579
+ async function loadEntry(entryArg, cwd) {
580
+ const resolvedPath = path.resolve(cwd, entryArg);
581
+ let mod;
582
+ try {
583
+ mod = await import(pathToFileURL(resolvedPath).href);
584
+ } catch (error) {
585
+ const explained = explainJsxLoadError(error, resolvedPath);
586
+ if (explained !== void 0) throw new CliStructuredError("COMPOSE.ENTRY_UNLOADABLE", explained.summary, {
587
+ why: explained.why,
588
+ fix: explained.fix,
589
+ where: { path: resolvedPath },
590
+ cause: error
591
+ });
592
+ throw new CliStructuredError("COMPOSE.ENTRY_UNLOADABLE", `Failed to import entry module "${resolvedPath}": ${error instanceof Error ? error.message : String(error)}`, {
593
+ where: { path: resolvedPath },
594
+ cause: error
595
+ });
596
+ }
597
+ const root = blindCast(mod).default;
598
+ if (!isNode(root) || root.kind === "dependency" || root.kind === "resource") throw new CliStructuredError("COMPOSE.ENTRY_EXPORT_INVALID", `Entry module "${resolvedPath}" must default-export a node (a service or a module).`, {
599
+ fix: "Construct it with service() or module() from @prisma/composer.",
600
+ where: { path: resolvedPath }
601
+ });
602
+ return {
603
+ path: resolvedPath,
604
+ root: blindCast(root)
605
+ };
606
+ }
607
+ //#endregion
608
+ //#region ../../0-framework/3-tooling/assemble/dist/index.mjs
609
+ /**
610
+ * A user-facing assembly failure, structured at origin (base-type rule 6):
611
+ * a `CliStructuredError` whose code names which way assembly went wrong.
612
+ * This package's second consumer is the programmatic deploy API, not just
613
+ * the CLI — hosts branch on `error.code`, the CLI renders the envelope.
614
+ */
615
+ var AssembleError = class extends CliStructuredError {
616
+ constructor(code, summary, options) {
617
+ super(code, summary, options);
618
+ }
619
+ };
620
+ /**
621
+ * The registry route for one service's build: extension by
622
+ * `build.extension`, node descriptor by `build.type`, kind must be "build".
623
+ * The CLI's coverage validation reports the same misses earlier with the
624
+ * config fix; these errors are the backstop for programmatic callers.
625
+ */
626
+ function buildDescriptorAssemble(config, node, address, cwd) {
627
+ const { extension, type } = node.build;
628
+ const extensionDescriptor = config.extensions.find((candidate) => candidate.id === extension);
629
+ if (extensionDescriptor === void 0) throw new AssembleError("ASSEMBLE.EXTENSION_MISSING", `No extension "${extension}" is configured (needed by service "${node.name}"'s build).`, { fix: "Add it to prisma-composer.config.ts's `extensions`." });
630
+ const nodeDescriptor = extensionDescriptor.nodes[type];
631
+ if (nodeDescriptor === void 0) throw new AssembleError("ASSEMBLE.DESCRIPTOR_MISSING", `Extension "${extension}" has no descriptor for build type "${type}".`, { why: `Known types: ${Object.keys(extensionDescriptor.nodes).join(", ")}.` });
632
+ if (nodeDescriptor.kind !== "build") throw new AssembleError("ASSEMBLE.DESCRIPTOR_KIND_MISMATCH", `Extension "${extension}"'s descriptor for type "${type}" is a "${nodeDescriptor.kind}" descriptor.`, { why: "Assembling a service build needs a \"build\" descriptor." });
633
+ return nodeDescriptor.assemble({
634
+ build: node.build,
635
+ address,
636
+ cwd
637
+ });
638
+ }
639
+ async function assembleServices(graph, config, cwd, run) {
640
+ const runAssembler = run ?? ((node, address, nodeCwd) => buildDescriptorAssemble(config, node, address, nodeCwd));
641
+ const serviceNodes = graph.nodes.filter((n) => n.node.kind === "service");
642
+ if (serviceNodes.length === 0) throw new AssembleError("ASSEMBLE.SERVICE_MISSING", "The loaded graph has no service to assemble.");
643
+ const bundles = {};
644
+ for (const { id, node } of serviceNodes) try {
645
+ bundles[id] = await runAssembler(node, id, cwd);
646
+ } catch (error) {
647
+ if (CliStructuredError.is(error)) throw error;
648
+ throw new AssembleError("ASSEMBLE.BUILD_FAILED", error instanceof Error ? error.message : String(error), {
649
+ meta: { address: id },
650
+ cause: error
651
+ });
652
+ }
653
+ return { bundles };
654
+ }
655
+ //#endregion
656
+ //#region ../../0-framework/3-tooling/cli/dist/pipeline-D3QoVzAB.mjs
657
+ /**
658
+ * Pipeline step: find and load `prisma-composer.config.ts` (ADR-0017) — the ONE
659
+ * file that imports control-plane code. Discovery is the standard walk-up
660
+ * from the deploy entry's directory (mirrors prisma-next's config-loader);
661
+ * loading is c12 with that explicit path (rc/global/package.json lookups
662
+ * disabled), so the config file's own static imports resolve from the app
663
+ * root by whatever package manager runs — no specifier construction, no
664
+ * anchoring. The loaded shape is validated field-by-field with structured
665
+ * errors naming the field.
666
+ */
667
+ const CONFIG_FILENAME = "prisma-composer.config.ts";
668
+ /** Walks UP from the entry file's directory looking for the literal CONFIG_FILENAME; undefined when the walk hits the filesystem root. */
669
+ function findConfigPathForEntry(entryPath) {
670
+ let current = path.dirname(path.resolve(entryPath));
671
+ while (true) {
672
+ const candidate = path.join(current, CONFIG_FILENAME);
673
+ if (fs.existsSync(candidate)) return candidate;
674
+ const parent = path.dirname(current);
675
+ if (parent === current) return void 0;
676
+ current = parent;
677
+ }
678
+ }
679
+ function missingConfigError(entryPath) {
680
+ const searchedFrom = path.dirname(path.resolve(entryPath));
681
+ return new CliStructuredError("CONFIG.FILE_MISSING", `No ${CONFIG_FILENAME} found walking up from "${searchedFrom}".`, {
682
+ why: "The deploy needs the app's config file.",
683
+ fix: "Create one next to (or above) the entry, default-exporting defineConfig({ extensions: [...], state: ... }) from '@prisma/composer/config'.",
684
+ where: { path: searchedFrom }
685
+ });
686
+ }
687
+ function fieldError(field, requirement) {
688
+ return new CliStructuredError("CONFIG.FIELD_INVALID", `${CONFIG_FILENAME}: \`${field}\` ${requirement}.`, {
689
+ fix: "See defineConfig() in '@prisma/composer/config'.",
690
+ meta: { field }
691
+ });
692
+ }
693
+ function isRecord(value) {
694
+ return typeof value === "object" && value !== null;
695
+ }
696
+ /**
697
+ * Field-by-field validation of the loaded default export — deliberately no
698
+ * schema library: each check is a structured error naming the offending field.
699
+ * Returns the same object, typed.
700
+ */
701
+ function validateConfigShape(loaded, configPath) {
702
+ if (!isRecord(loaded) || Object.keys(loaded).length === 0) throw new CliStructuredError("CONFIG.EXPORT_INVALID", `"${configPath}" exported no config.`, {
703
+ fix: "It must default-export defineConfig({ extensions: [...], state: ... }) from '@prisma/composer/config'.",
704
+ where: { path: configPath }
705
+ });
706
+ const extensions = loaded["extensions"];
707
+ if (!Array.isArray(extensions)) throw fieldError("extensions", "must be an array");
708
+ const seen = /* @__PURE__ */ new Set();
709
+ for (const [index, entry] of extensions.entries()) {
710
+ if (!isRecord(entry)) throw fieldError(`extensions[${index}]`, "must be an extension descriptor object");
711
+ const id = entry["id"];
712
+ if (typeof id !== "string" || id.length === 0) throw fieldError(`extensions[${index}].id`, "must be a non-empty string (the extension package name)");
713
+ if (!isRecord(entry["nodes"])) throw fieldError(`extensions[${index}].nodes`, "must be an object (the node-ID → control registry)");
714
+ if (seen.has(id)) throw new CliStructuredError("CONFIG.EXTENSION_DUPLICATE", `${CONFIG_FILENAME}: extension "${id}" is listed more than once in \`extensions\`.`);
715
+ seen.add(id);
716
+ }
717
+ const state = loaded["state"];
718
+ if (!isRecord(state) || typeof state["extension"] !== "string" || typeof state["create"] !== "function") throw fieldError("state", "must be a state descriptor (e.g. prismaState())");
719
+ return blindCast(loaded);
720
+ }
721
+ /**
722
+ * Loads + validates the config at `configPath` via c12 (explicit file; rc /
723
+ * global-rc / package.json lookups disabled — discovery already happened in
724
+ * findConfigPathForEntry).
725
+ */
726
+ async function loadAppConfig(configPath) {
727
+ let result;
728
+ try {
729
+ result = await c12.loadConfig({
730
+ name: "prisma-composer",
731
+ configFile: configPath,
732
+ cwd: path.dirname(configPath),
733
+ rcFile: false,
734
+ globalRc: false,
735
+ packageJson: false
736
+ });
737
+ } catch (error) {
738
+ throw new CliStructuredError("CONFIG.EVALUATION_FAILED", `Evaluating "${configPath}" failed: ${error instanceof Error ? error.message : String(error)}`, {
739
+ where: { path: configPath },
740
+ cause: error
741
+ });
742
+ }
743
+ const loadedFile = result.configFile;
744
+ if (typeof loadedFile !== "string" || fs.realpathSync(loadedFile) !== fs.realpathSync(configPath)) throw new CliStructuredError("CONFIG.PATH_MISMATCH", `Config loading resolved "${String(loadedFile)}" instead of the discovered "${configPath}".`, {
745
+ why: "Refusing to deploy against a different file.",
746
+ where: { path: configPath }
747
+ });
748
+ return {
749
+ path: configPath,
750
+ config: validateConfigShape(result.config, configPath)
751
+ };
752
+ }
753
+ function lookup(extensions, extension, type, expectedKind, what) {
754
+ const ext = extensions.get(extension);
755
+ if (ext === void 0) throw new CliStructuredError("CONFIG.EXTENSION_MISSING", `No extension "${extension}" is configured (needed by ${what}).`, {
756
+ fix: `Add it to ${CONFIG_FILENAME}'s \`extensions\` (import its /control entry and list its descriptor).`,
757
+ meta: {
758
+ extension,
759
+ type
760
+ }
761
+ });
762
+ const descriptor = ext.nodes[type];
763
+ if (descriptor === void 0) throw new CliStructuredError("CONFIG.DESCRIPTOR_MISSING", `Extension "${extension}" has no descriptor for node type "${type}" (needed by ${what}).`, {
764
+ why: `Known types: ${Object.keys(ext.nodes).join(", ")}.`,
765
+ meta: {
766
+ extension,
767
+ type
768
+ }
769
+ });
770
+ if (descriptor.kind !== expectedKind) throw new CliStructuredError("CONFIG.DESCRIPTOR_KIND_MISMATCH", `Extension "${extension}"'s descriptor for node type "${type}" is a "${descriptor.kind}" descriptor — ${what} needs a "${expectedKind}" descriptor.`, { meta: {
771
+ extension,
772
+ type,
773
+ kind: descriptor.kind
774
+ } });
775
+ }
776
+ /** Throws a structured CONFIG.* error on the first uncovered `(extension, type)`; silent when the config covers the whole graph. */
777
+ function validateRegistryCoverage(graph, config) {
778
+ const extensions = new Map(config.extensions.map((descriptor) => [descriptor.id, descriptor]));
779
+ for (const { id, node } of graph.nodes) {
780
+ if (node.kind === "resource") {
781
+ lookup(extensions, node.extension, node.type, "resource", `resource node "${id}"`);
782
+ continue;
783
+ }
784
+ if (node.kind !== "service") continue;
785
+ lookup(extensions, node.extension, node.type, "service", `service node "${id}"`);
786
+ lookup(extensions, node.build.extension, node.build.type, "build", `service node "${id}"'s build descriptor`);
787
+ }
788
+ }
789
+ /**
790
+ * The shared prefix of `deploy`/`destroy`/`dev` (deploy-cli.md § The
791
+ * pipeline; local-dev spec § 6): config discovery/load, entry load, Load,
792
+ * registry coverage validation, name resolution, assemble. Deploy and dev
793
+ * diverge after this — deploy resolves containers/preflight/stack file
794
+ * against the hosted providers, dev against the local ones — so everything
795
+ * up to and including assemble lives here once, consumed verbatim by both
796
+ * `run()` (main.ts) and `runDev()` (dev/run-dev.ts), so the two pipelines
797
+ * cannot drift.
798
+ */
799
+ /**
800
+ * The pipeline's front — config discovery/load, entry load, name resolution —
801
+ * WITHOUT Load, coverage, or assemble. `log` needs only who the app is (its
802
+ * config and resolved name) to reach the already-running local instance; it
803
+ * neither builds nor provisions, so it must not require the user's built
804
+ * output the way the full pipeline does.
805
+ */
806
+ async function resolveAppIdentity(entry, overrideName, cwd, deps = {}) {
807
+ const resolvedEntryPath = path.resolve(cwd, entry);
808
+ const configPath = findConfigPathForEntry(resolvedEntryPath);
809
+ if (configPath === void 0) throw missingConfigError(resolvedEntryPath);
810
+ const config = deps.config ?? (await loadAppConfig(configPath)).config;
811
+ const entryModule = await loadEntry(entry, cwd);
812
+ const name = overrideName ?? entryModule.root.name;
813
+ if (name.length === 0) throw new CliStructuredError("COMPOSE.NAME_MISSING", "The root node has no name.", { fix: "Name it at authoring, or pass --name." });
814
+ return {
815
+ configPath,
816
+ config,
817
+ name
818
+ };
819
+ }
820
+ /**
821
+ * Runs config discovery/load, entry load, Load, registry coverage, name
822
+ * resolution, and assemble — steps 1–6 of `run()`. `onAssembleError`, when
823
+ * given, lets a caller decorate an assemble failure with command-specific
824
+ * guidance (destroy's "build first" hint) without this shared step knowing
825
+ * about any one command.
826
+ */
827
+ async function runPipeline(entry, overrideName, cwd, deps = {}, onAssembleError) {
828
+ const resolvedEntryPath = path.resolve(cwd, entry);
829
+ const configPath = findConfigPathForEntry(resolvedEntryPath);
830
+ if (configPath === void 0) throw missingConfigError(resolvedEntryPath);
831
+ const config = deps.config ?? (await loadAppConfig(configPath)).config;
832
+ const entryModule = await loadEntry(entry, cwd);
833
+ const graph = Load(entryModule.root);
834
+ 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); })." });
835
+ validateRegistryCoverage(graph, config);
836
+ const name = overrideName ?? entryModule.root.name;
837
+ if (name.length === 0) throw new CliStructuredError("COMPOSE.NAME_MISSING", "The root node has no name.", { fix: "Name it at authoring, or pass --name." });
838
+ let assembled;
839
+ try {
840
+ assembled = await assembleServices(graph, config, cwd, deps.runAssembler);
841
+ } catch (error) {
842
+ if (onAssembleError !== void 0 && error instanceof Error) throw onAssembleError(error);
843
+ throw error;
844
+ }
845
+ return {
846
+ configPath,
847
+ config,
848
+ entryModule,
849
+ graph,
850
+ name,
851
+ assembled
852
+ };
853
+ }
854
+ //#endregion
855
+ export { runPipeline as n, resolveAppIdentity as t };
856
+
857
+ //# sourceMappingURL=pipeline-D3QoVzAB-D_ufjg3N.mjs.map