@prisma/composer-cli 0.25.0-dev.5 → 0.26.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 (55) hide show
  1. package/dist/{result-D9vIrN7i.mjs → composer-config-CY9fET8H-KpGjlYgO.mjs} +89 -89
  2. package/dist/composer-config-CY9fET8H-KpGjlYgO.mjs.map +1 -0
  3. package/dist/{pipeline-DAYhea3J-uuBciVDS.mjs → container-transport-HcvNOGZL-CHqecFc7.mjs} +83 -71
  4. package/dist/container-transport-HcvNOGZL-CHqecFc7.mjs.map +1 -0
  5. package/dist/{execute-deploy-destroy-CF6DR7sA-jdelm-y5.mjs → execute-deploy-destroy-c0eko3AO-9npuGXd3.mjs} +70 -73
  6. package/dist/execute-deploy-destroy-c0eko3AO-9npuGXd3.mjs.map +1 -0
  7. package/dist/{execute-dev-DAIUT0es-DTdnJdOi.mjs → execute-dev-BICPaq1g-CSoZJuhB.mjs} +70 -9
  8. package/dist/execute-dev-BICPaq1g-CSoZJuhB.mjs.map +1 -0
  9. package/dist/{family-DB2Uf88c-DWEm0USb.d.mts → family-CgeZQdNg-gH8LuqqL.d.mts} +46 -140
  10. package/dist/family-CgeZQdNg-gH8LuqqL.d.mts.map +1 -0
  11. package/dist/family.d.mts +3 -28
  12. package/dist/family.d.mts.map +1 -1
  13. package/dist/family.mjs +12 -461
  14. package/dist/family.mjs.map +1 -1
  15. package/dist/{generate-dev-stack-CPpjJdTG-W0N0YgsI.mjs → generate-dev-stack-BUadNY_w-DF_lHVaP.mjs} +4 -4
  16. package/dist/{generate-dev-stack-CPpjJdTG-W0N0YgsI.mjs.map → generate-dev-stack-BUadNY_w-DF_lHVaP.mjs.map} +1 -1
  17. package/dist/run-alchemy-BEvB2sYQ-BgV2deuO.mjs +154 -0
  18. package/dist/run-alchemy-BEvB2sYQ-BgV2deuO.mjs.map +1 -0
  19. package/dist/testing.d.mts +10 -24
  20. package/dist/testing.d.mts.map +1 -1
  21. package/dist/testing.mjs +17 -46
  22. package/dist/testing.mjs.map +1 -1
  23. package/package.json +5 -8
  24. package/src/exports/testing.ts +2 -2
  25. package/dist/bin.mjs +0 -987
  26. package/dist/bin.mjs.map +0 -1
  27. package/dist/container-transport-HcvNOGZL-CIoZc7Rs.mjs +0 -34
  28. package/dist/container-transport-HcvNOGZL-CIoZc7Rs.mjs.map +0 -1
  29. package/dist/execute-deploy-destroy-CF6DR7sA-DGs5poBA.mjs +0 -556
  30. package/dist/execute-deploy-destroy-CF6DR7sA-DGs5poBA.mjs.map +0 -1
  31. package/dist/execute-deploy-destroy-CF6DR7sA-jdelm-y5.mjs.map +0 -1
  32. package/dist/execute-dev-DAIUT0es-CVW9TfgX.mjs +0 -2060
  33. package/dist/execute-dev-DAIUT0es-CVW9TfgX.mjs.map +0 -1
  34. package/dist/execute-dev-DAIUT0es-DTdnJdOi.mjs.map +0 -1
  35. package/dist/execute-log-PLs9-Qn3-BUBx5KmY.mjs +0 -155
  36. package/dist/execute-log-PLs9-Qn3-BUBx5KmY.mjs.map +0 -1
  37. package/dist/execute-log-PLs9-Qn3-D8DRuvDr.mjs +0 -154
  38. package/dist/execute-log-PLs9-Qn3-D8DRuvDr.mjs.map +0 -1
  39. package/dist/family-DB2Uf88c-DWEm0USb.d.mts.map +0 -1
  40. package/dist/local-target-B9cBl_6r.mjs +0 -68
  41. package/dist/local-target-B9cBl_6r.mjs.map +0 -1
  42. package/dist/local-target-P4-n1Ovh.mjs +0 -68
  43. package/dist/local-target-P4-n1Ovh.mjs.map +0 -1
  44. package/dist/pipeline-DAYhea3J-BEnHHWp8.mjs +0 -979
  45. package/dist/pipeline-DAYhea3J-BEnHHWp8.mjs.map +0 -1
  46. package/dist/pipeline-DAYhea3J-uuBciVDS.mjs.map +0 -1
  47. package/dist/result-D9vIrN7i.mjs.map +0 -1
  48. package/dist/result-SF9LFOuR.mjs +0 -461
  49. package/dist/result-SF9LFOuR.mjs.map +0 -1
  50. package/dist/run-alchemy-pANK8XNX-CqXC1tbs.mjs +0 -99
  51. package/dist/run-alchemy-pANK8XNX-CqXC1tbs.mjs.map +0 -1
  52. package/dist/run-alchemy-pANK8XNX-T_pHNDBo.mjs +0 -99
  53. package/dist/run-alchemy-pANK8XNX-T_pHNDBo.mjs.map +0 -1
  54. package/dist/shared-BAIiDgXa-DYP7EOSk.mjs +0 -33
  55. package/dist/shared-BAIiDgXa-DYP7EOSk.mjs.map +0 -1
@@ -1,979 +0,0 @@
1
- import { a as configFileMissing, c as CliStructuredError, i as checkComposerConfig, l as InternalError, u as blindCast } from "./result-D9vIrN7i.mjs";
2
- import * as mod from "node:module";
3
- import * as fs from "node:fs";
4
- import { existsSync } from "node:fs";
5
- import * as path from "node:path";
6
- import { fileURLToPath, pathToFileURL } from "node:url";
7
- //#region ../../0-framework/1-core/core/dist/graph-BfKAg2Ap.mjs
8
- /** The reserved name of a resource's single anonymous output port. Rejected as a user-declared port name (node.ts). */
9
- const RESOURCE_OUT_PORT = "$out";
10
- /**
11
- * Thrown by Load when the graph is malformed. Structured at origin
12
- * (base-type rule 6): one type-level code covers every raise site until a
13
- * finer per-site taxonomy is carved out. The `name` stays
14
- * `CliStructuredError` — structural recognition depends on it.
15
- */
16
- var LoadError = class extends CliStructuredError {
17
- constructor(message) {
18
- super("COMPOSE.GRAPH_INVALID", message);
19
- }
20
- };
21
- /**
22
- * Core model: node types and the factories that construct them, plain frozen
23
- * data objects. A node's `extension` + `type` form its deploy-time registry key (ADR-0017).
24
- */
25
- const NODE = Symbol.for("prisma:node");
26
- blindCast(Symbol.for("prisma:secret-need"));
27
- const SECRET_SOURCE = blindCast(Symbol.for("prisma:secret-source"));
28
- /** True if `value` is a secret source (an `envSecret` result or a forwarded ctx.secrets ref). */
29
- function isSecretSource(value) {
30
- return typeof value === "object" && value !== null && blindCast(value)[SECRET_SOURCE] === true;
31
- }
32
- blindCast(Symbol.for("prisma:provision-need"));
33
- const PARAM_SOURCE = blindCast(Symbol.for("prisma:param-source"));
34
- blindCast(Symbol.for("prisma:param-need"));
35
- /** True if `value` is a param source (an `envParam` result or a forwarded ctx.params ref). */
36
- function isParamSource(value) {
37
- return typeof value === "object" && value !== null && blindCast(value)[PARAM_SOURCE] === true;
38
- }
39
- /**
40
- * Core's grammar for every name that becomes a config-key segment —
41
- * addresses, input/param/secret names: ASCII letters and digits only.
42
- * Conservative by design so any target medium — POSIX env-var keys
43
- * included — can uppercase and "_"-join segments without escaping.
44
- */
45
- function isConfigKeySegment(name) {
46
- return /^[A-Za-z0-9]+$/.test(name);
47
- }
48
- /**
49
- * True if `value` was constructed by this module's factories. Checks the
50
- * brand only, never a prototype — a graph may mix nodes from a different
51
- * installed copy of core (dual-package hazard).
52
- */
53
- function isNode(value) {
54
- return typeof value === "object" && value !== null && value[NODE] === true;
55
- }
56
- /**
57
- * Stable topological sort: every edge's `from` precedes its `to` in the
58
- * result. Ties (nodes with no ordering constraint between them) keep their
59
- * relative order from `nodes` — so a graph already authored producer-first
60
- * comes out byte-identical to its pre-sort layout; only a graph that
61
- * genuinely needs reordering (e.g. a module wired via a forged ref pointing at a
62
- * not-yet-provisioned producer) actually moves. A Kahn's-algorithm variant
63
- * that always picks the ready node with the smallest original index. Edges
64
- * whose endpoint falls outside `nodes` (e.g. a service-root's input edges
65
- * targeting the root, which is appended separately) are ignored. Cycles
66
- * cannot reach here: `assertDependencyDag` already rejects them for
67
- * dependency edges, and input edges never cycle.
68
- */
69
- function topoSort(nodes, edges) {
70
- const byId = new Map(nodes.map((n) => [n.id, n]));
71
- const indexOf = new Map(nodes.map((n, i) => [n.id, i]));
72
- const indegree = new Map(nodes.map((n) => [n.id, 0]));
73
- const successors = /* @__PURE__ */ new Map();
74
- for (const edge of edges) {
75
- if (!byId.has(edge.from) || !byId.has(edge.to)) continue;
76
- const targets = successors.get(edge.from) ?? [];
77
- targets.push(edge.to);
78
- successors.set(edge.from, targets);
79
- indegree.set(edge.to, (indegree.get(edge.to) ?? 0) + 1);
80
- }
81
- const ready = new Set(nodes.filter((n) => indegree.get(n.id) === 0).map((n) => n.id));
82
- const order = [];
83
- while (ready.size > 0) {
84
- let next;
85
- let bestIndex = Number.POSITIVE_INFINITY;
86
- for (const id of ready) {
87
- const index = indexOf.get(id) ?? Number.POSITIVE_INFINITY;
88
- if (index < bestIndex) {
89
- bestIndex = index;
90
- next = id;
91
- }
92
- }
93
- if (next === void 0) break;
94
- ready.delete(next);
95
- order.push(next);
96
- for (const target of successors.get(next) ?? []) {
97
- const remaining = (indegree.get(target) ?? 0) - 1;
98
- indegree.set(target, remaining);
99
- if (remaining === 0) ready.add(target);
100
- }
101
- }
102
- 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.`);
103
- return order.map((id) => byId.get(id)).filter((n) => n !== void 0);
104
- }
105
- /**
106
- * The declared boundary ports of a module or service node at `id`: dep slots
107
- * as `in` ports (contractKind = the slot's `type`), exposed contracts as
108
- * `out` ports (contractKind = the contract's `kind`). A resource's one
109
- * `$out` port is recorded at its provision site instead (load-module.ts).
110
- */
111
- function boundaryPortsOf(id, node) {
112
- const ports = [];
113
- const slots = node.kind === "module" ? node.deps : node.inputs;
114
- for (const [name, slot] of Object.entries(slots)) {
115
- const type = typeof slot === "object" && slot !== null && "type" in slot && typeof slot.type === "string" ? slot.type : void 0;
116
- ports.push({
117
- node: id,
118
- direction: "in",
119
- name,
120
- contractKind: type
121
- });
122
- }
123
- for (const [name, contract] of Object.entries(node.expose ?? {})) {
124
- const kind = typeof contract === "object" && contract !== null && "kind" in contract && typeof contract.kind === "string" ? contract.kind : void 0;
125
- ports.push({
126
- node: id,
127
- direction: "out",
128
- name,
129
- contractKind: kind
130
- });
131
- }
132
- return ports;
133
- }
134
- function serviceInputs(service, serviceId) {
135
- if (typeof service.inputs !== "object" || service.inputs === null) throw new LoadError(`Service "${serviceId}" has no inputs map.`);
136
- const nodes = [];
137
- const edges = [];
138
- for (const [input, value] of Object.entries(service.inputs)) {
139
- const kind = isNode(value) ? value.kind : void 0;
140
- 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.`);
141
- if (kind !== "dependency") throw new LoadError(`Input "${input}" of "${serviceId}" is not a branded dependency end (construct it with the dependency() factory).`);
142
- if (value.type.length === 0) throw new LoadError(`Input "${input}" of "${serviceId}" has an empty node type.`);
143
- const id = `${serviceId}.${input}`;
144
- nodes.push({
145
- id,
146
- parent: serviceId,
147
- node: value
148
- });
149
- edges.push({
150
- from: id,
151
- to: serviceId,
152
- input,
153
- kind: "input"
154
- });
155
- }
156
- return {
157
- nodes,
158
- edges
159
- };
160
- }
161
- function loadService(root, rootId) {
162
- 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.`);
163
- 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).`);
164
- const rootGraphNode = {
165
- id: rootId,
166
- parent: void 0,
167
- node: root
168
- };
169
- const { nodes, edges } = serviceInputs(root, rootId);
170
- return {
171
- root: rootGraphNode,
172
- nodes: [...topoSort(nodes, edges), rootGraphNode],
173
- edges,
174
- ports: boundaryPortsOf(rootId, root),
175
- authoredEdges: [],
176
- inputBindings: [],
177
- params: []
178
- };
179
- }
180
- /**
181
- * Brands a ref-port with the AUTHORED endpoint it stands for — which port of
182
- * which node the author wired, before any forwarding chain resolves. Read
183
- * only by `authoredSourceOf`; `__providerId` keeps carrying the resolved
184
- * producer for the flat (post-dereference) edges.
185
- */
186
- const AUTHORED_PORT = Symbol("prisma:authored-port");
187
- /** The authored out-port brand carried by `ref`, if any. */
188
- function authoredPortOf(ref) {
189
- if (typeof ref !== "object" || ref === null) return void 0;
190
- const brand = blindCast(ref)[AUTHORED_PORT];
191
- if (typeof brand !== "object" || brand === null) return void 0;
192
- const { node, name } = blindCast(brand);
193
- return typeof node === "string" && typeof name === "string" ? {
194
- node,
195
- name
196
- } : void 0;
197
- }
198
- /**
199
- * Builds the ref a provision() call hands back: the id (so a producer with no
200
- * exposed ports — or an untyped slot — can still be wired wholesale) plus one
201
- * ref-port per exposed contract, each the contract's own runtime value (so
202
- * its `satisfies()` still works) tagged with the provider's id.
203
- */
204
- function refFor(id, service) {
205
- const ports = {};
206
- for (const [port, contract] of Object.entries(service.expose ?? {})) ports[port] = {
207
- ...contract,
208
- __providerId: id,
209
- [AUTHORED_PORT]: {
210
- node: id,
211
- name: port
212
- }
213
- };
214
- return blindCast({
215
- id,
216
- ...ports
217
- });
218
- }
219
- /**
220
- * The resource variant of refFor: a resource has exactly one port — the
221
- * contract it provides — flattened onto the ref itself, tagged with the
222
- * provider id. `id` and the authored brand are written last so a hostile
223
- * contract value cannot clobber them.
224
- */
225
- function refForResource(id, resource) {
226
- return blindCast({
227
- ...resource.provides,
228
- __providerId: id,
229
- id,
230
- [AUTHORED_PORT]: {
231
- node: id,
232
- name: RESOURCE_OUT_PORT
233
- }
234
- });
235
- }
236
- /** A wired value's producer id: a ref-port's `__providerId`, or a bare ref's `id`. */
237
- function producerIdOf(ref) {
238
- if (typeof ref !== "object" || ref === null) return void 0;
239
- if ("__providerId" in ref && typeof ref.__providerId === "string") return ref.__providerId;
240
- if ("id" in ref && typeof ref.id === "string") return ref.id;
241
- }
242
- /**
243
- * Brands each `ctx.inputs` entry with the input key it stands for (see
244
- * flatten): diagnostic only — usage attribution relies on the per-key object
245
- * identity the branding copy creates, never on reading this back.
246
- */
247
- const MODULE_INPUT_KEY = Symbol("prisma:module-input-key");
248
- /** Same per-key identity trick as MODULE_INPUT_KEY, for the parallel `ctx.secrets` forwarding channel. */
249
- const MODULE_SECRET_KEY = Symbol("prisma:module-secret-key");
250
- /** Same per-key identity trick as MODULE_INPUT_KEY, for the parallel `ctx.params` forwarding channel. */
251
- const MODULE_PARAM_KEY = Symbol("prisma:module-param-key");
252
- /** Whether `ref` carries a callable `satisfies` that accepts `required` truthily. */
253
- function satisfiesRequired(ref, required) {
254
- return typeof ref === "object" && ref !== null && "satisfies" in ref && typeof ref.satisfies === "function" && ref.satisfies(required);
255
- }
256
- /**
257
- * Checks one recorded `wiring` object against the Deps it was wired against:
258
- * every named input exists and is a dependency slot, every referenced
259
- * producer is a real (by-now-provisioned) address, and a wired ref whose
260
- * slot declares a required contract must satisfy() it — no producer-kind
261
- * branching, the contract alone determines validity, whether the producer is
262
- * a service port or a resource. Shared by both provisioned kinds so a
263
- * module-as-child gets exactly the checks a service gets, and run once per
264
- * entry against the one `byId` shared by the whole recursive flatten, so a
265
- * forwarded ref resolves through to its real producer address regardless of
266
- * which ancestor scope provisioned it.
267
- */
268
- function validateWiring(pending, byId) {
269
- const { deps, wiring, targetId, targetKind, enclosingModuleName } = pending;
270
- for (const [input, ref] of Object.entries(wiring)) {
271
- const declared = blindCast(deps[input]);
272
- 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}.`);
273
- const producerId = producerIdOf(ref);
274
- const producer = producerId !== void 0 ? byId.get(producerId) : void 0;
275
- 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}".`);
276
- const required = declared.required;
277
- if (required !== void 0 && !satisfiesRequired(ref, required)) throw new LoadError(`The deps for "${targetId}.${input}" do not satisfy the slot's required contract.`);
278
- }
279
- for (const [input, rawValue] of Object.entries(deps)) {
280
- const value = blindCast(rawValue);
281
- if (!isNode(value) || wiring[input] !== void 0) continue;
282
- if (value.kind === "dependency") throw new LoadError(`Dependency input "${input}" of provisioned ${targetKind} "${targetId}" is not wired to a producer (module "${enclosingModuleName}").`);
283
- }
284
- }
285
- /**
286
- * Flattens a value into itself plus every nested object/array member value —
287
- * identity fodder for the ctx.secrets/ctx.params usage marking, which must
288
- * see a forwarded source wherever it sits inside an input binding (ADR-0042).
289
- * A secret/param source is an opaque leaf: it is pushed (a forwarded ref IS
290
- * such a source, so identity-matching still needs it) but never descended
291
- * into, so a ref buried in an unrelated source's payload is not falsely seen
292
- * as used. `seen` guards object cycles so a self-referential binding cannot
293
- * recurse forever.
294
- */
295
- function deepValues(value, out, seen = /* @__PURE__ */ new WeakSet()) {
296
- out.push(value);
297
- if (typeof value !== "object" || value === null) return;
298
- if (isSecretSource(value) || isParamSource(value)) return;
299
- if (seen.has(value)) return;
300
- seen.add(value);
301
- const members = Array.isArray(value) ? value : Object.values(value);
302
- for (const member of members) deepValues(member, out, seen);
303
- }
304
- /** The (unvalidated) edges a `wiring` object implies — one dependency edge per entry; `validateWiring` does the real checking. */
305
- function wiringEdges(wiring, targetId) {
306
- return Object.entries(wiring).map(([input, ref]) => ({
307
- from: producerIdOf(ref) ?? "",
308
- to: targetId,
309
- input,
310
- kind: "dependency"
311
- }));
312
- }
313
- /**
314
- * Checks the secrets wired into one provisioned child MODULE: every declared
315
- * forwarding slot is bound to a real secret source (an `envSecret` or a
316
- * forwarded ctx.secrets ref), and no wired key names a slot the module
317
- * doesn't declare — the secret analog of `validateWiring`'s per-input checks,
318
- * but resolved inline (a source carries its own name, so no whole-graph pass
319
- * is needed).
320
- */
321
- function validateSecretBinding(child, id, secretWiring, enclosingModuleName) {
322
- const { kind } = child;
323
- for (const slot of Object.keys(child.secretSlots)) {
324
- const bound = secretWiring[slot];
325
- 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.`);
326
- 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.`);
327
- }
328
- 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}").`);
329
- }
330
- /**
331
- * Checks the params wired into a provisioned SERVICE: unlike a secret slot, a
332
- * declared param is never required to be bound here — it may fall back to its
333
- * own `default` (checked later, at `buildConfig`) — so this only rejects a
334
- * wired key that names something other than a real declared param.
335
- */
336
- function validateServiceParamBinding(child, id, paramWiring, enclosingModuleName) {
337
- 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}").`);
338
- }
339
- /**
340
- * Checks the params wired into a provisioned MODULE: every declared
341
- * param-forwarding slot must be bound to a real `ParamSource` — a slot has no
342
- * schema of its own, so (unlike a service param) it cannot fall back to a
343
- * literal or a default; the param analog of `validateSecretBinding`.
344
- */
345
- function validateParamNeedBinding(child, id, paramWiring, enclosingModuleName) {
346
- for (const slot of Object.keys(child.paramSlots)) {
347
- const bound = paramWiring[slot];
348
- 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.`);
349
- 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.`);
350
- }
351
- 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}").`);
352
- }
353
- /**
354
- * Recursively flattens one module's body into the shared graph state and
355
- * returns its resolved ModuleOutputs (one ref-port per expose key) for the
356
- * caller (the enclosing provision() call, or Load itself for the root) to
357
- * use. `address` is this module's OWN full address, or `undefined` for the root
358
- * scope — its direct children then get bare (unprefixed) addresses, keeping
359
- * a single-level module identical to before nesting existed. `wiring` supplies a
360
- * resolved producer ref-port for each of this module's OWN declared deps (empty
361
- * for the root, which may not declare any — see the root non-empty-deps
362
- * check in loadModule). `nodes`, `edges`, `pending`, and `byId` are shared
363
- * across the ENTIRE recursive flatten, not per scope — a nested module may
364
- * forward in a producer provisioned by an ancestor scope, and it is the
365
- * shared `byId` (keyed by full address) that lets that resolve.
366
- *
367
- * `selfId` is this module's own node id — the root's given id when `address`
368
- * is `undefined`, the full address otherwise. It anchors the authored view:
369
- * children carry it as their `parent`, and this module's own boundary ports
370
- * (and the authored edges touching them) are recorded against it.
371
- */
372
- function flatten(moduleNode, address, selfId, wiring, secretWiring, paramWiring, nodes, edges, pending, inputBindings, paramBindings, byId, ports, authoredEdges) {
373
- ports.push(...boundaryPortsOf(selfId, moduleNode));
374
- const localIds = /* @__PURE__ */ new Set();
375
- const used = /* @__PURE__ */ new Set();
376
- const usedSecrets = /* @__PURE__ */ new Set();
377
- const usedParams = /* @__PURE__ */ new Set();
378
- const ctxInputs = {};
379
- for (const key of Object.keys(moduleNode.deps)) {
380
- const wired = wiring[key];
381
- ctxInputs[key] = typeof wired === "object" && wired !== null ? {
382
- ...wired,
383
- [MODULE_INPUT_KEY]: key
384
- } : wired;
385
- }
386
- const markUsed = (values) => {
387
- for (const value of values) for (const key of Object.keys(ctxInputs)) if (value === ctxInputs[key]) used.add(key);
388
- };
389
- const authoredSourceOf = (value) => {
390
- for (const key of Object.keys(ctxInputs)) if (value === ctxInputs[key]) return {
391
- node: selfId,
392
- direction: "in",
393
- name: key
394
- };
395
- const brand = authoredPortOf(value);
396
- return brand === void 0 ? void 0 : {
397
- node: brand.node,
398
- direction: "out",
399
- name: brand.name
400
- };
401
- };
402
- /** Records the authored edge each wiring entry declares: source port → the target's own `in` port. */
403
- const recordAuthoredWiring = (targetId, targetWiring) => {
404
- for (const [input, ref] of Object.entries(targetWiring)) {
405
- const from = authoredSourceOf(ref);
406
- if (from !== void 0) authoredEdges.push({
407
- from,
408
- to: {
409
- node: targetId,
410
- direction: "in",
411
- name: input
412
- }
413
- });
414
- }
415
- };
416
- const ctxSecrets = {};
417
- for (const key of Object.keys(moduleNode.secretSlots)) {
418
- const bound = secretWiring[key];
419
- ctxSecrets[key] = typeof bound === "object" && bound !== null ? {
420
- ...bound,
421
- [MODULE_SECRET_KEY]: key
422
- } : bound;
423
- }
424
- const markSecretsUsed = (values) => {
425
- for (const value of values) for (const key of Object.keys(ctxSecrets)) if (value === ctxSecrets[key]) usedSecrets.add(key);
426
- };
427
- const ctxParams = {};
428
- for (const key of Object.keys(moduleNode.paramSlots)) {
429
- const bound = paramWiring[key];
430
- ctxParams[key] = typeof bound === "object" && bound !== null ? {
431
- ...bound,
432
- [MODULE_PARAM_KEY]: key
433
- } : bound;
434
- }
435
- const markParamsUsed = (values) => {
436
- for (const value of values) for (const key of Object.keys(ctxParams)) if (value === ctxParams[key]) usedParams.add(key);
437
- };
438
- const provision = (child, opts) => {
439
- const id = opts?.id ?? child.name;
440
- const provisionWiring = opts?.deps;
441
- const provisionSecrets = opts?.secrets;
442
- const provisionInput = opts?.input;
443
- const provisionParams = opts?.params;
444
- if (typeof id !== "string" || id.length === 0) throw new LoadError(`provision() requires a non-empty id (module "${moduleNode.name}").`);
445
- 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.)`);
446
- if (localIds.has(id)) throw new LoadError(`Duplicate provision id "${id}" in module "${moduleNode.name}".`);
447
- const untrusted = child;
448
- 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).`);
449
- localIds.add(id);
450
- const fullAddress = address === void 0 ? id : `${address}.${id}`;
451
- if (child.kind === "resource") {
452
- if (provisionWiring !== void 0) throw new LoadError(`provision("${id}") received deps for a resource — a resource has no dependency slots to satisfy.`);
453
- if (provisionSecrets !== void 0) throw new LoadError(`provision("${id}") received secrets for a resource — a resource has no secret slots to satisfy.`);
454
- if (provisionInput !== void 0) throw new LoadError(`provision("${id}") received an input binding for a resource — a resource declares no input schema.`);
455
- if (provisionParams !== void 0) throw new LoadError(`provision("${id}") received params for a resource — a resource has no params to satisfy.`);
456
- if (child.type.length === 0) throw new LoadError(`provision("${id}") received a resource with an empty node type.`);
457
- byId.set(fullAddress, child);
458
- nodes.push({
459
- id: fullAddress,
460
- parent: selfId,
461
- node: child
462
- });
463
- ports.push({
464
- node: fullAddress,
465
- direction: "out",
466
- name: RESOURCE_OUT_PORT,
467
- contractKind: child.provides.kind
468
- });
469
- return refForResource(fullAddress, child);
470
- }
471
- const localWiring = { ...provisionWiring ?? {} };
472
- markUsed(Object.values(localWiring));
473
- const localSecrets = { ...provisionSecrets ?? {} };
474
- markSecretsUsed(Object.values(localSecrets));
475
- const localParams = { ...provisionParams ?? {} };
476
- markParamsUsed(Object.values(localParams));
477
- if (child.kind === "service") {
478
- 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.`);
479
- 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.`);
480
- 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}").`);
481
- if (provisionInput !== void 0) {
482
- const leaves = [];
483
- deepValues(provisionInput, leaves);
484
- markSecretsUsed(leaves);
485
- markParamsUsed(leaves);
486
- inputBindings.push({
487
- serviceAddress: fullAddress,
488
- binding: blindCast(provisionInput)
489
- });
490
- }
491
- validateServiceParamBinding(child, id, localParams, moduleNode.name);
492
- for (const [slot, binding] of Object.entries(localParams)) paramBindings.push({
493
- serviceAddress: fullAddress,
494
- slot,
495
- binding
496
- });
497
- const inputs = serviceInputs(child, fullAddress);
498
- nodes.push(...inputs.nodes, {
499
- id: fullAddress,
500
- parent: selfId,
501
- node: child
502
- });
503
- edges.push(...inputs.edges, ...wiringEdges(localWiring, fullAddress));
504
- ports.push(...boundaryPortsOf(fullAddress, child));
505
- recordAuthoredWiring(fullAddress, localWiring);
506
- pending.push({
507
- deps: child.inputs,
508
- wiring: localWiring,
509
- targetId: fullAddress,
510
- targetKind: "service",
511
- enclosingModuleName: moduleNode.name
512
- });
513
- byId.set(fullAddress, child);
514
- return refFor(fullAddress, child);
515
- }
516
- 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.`);
517
- validateSecretBinding(child, id, localSecrets, moduleNode.name);
518
- validateParamNeedBinding(child, id, localParams, moduleNode.name);
519
- edges.push(...wiringEdges(localWiring, fullAddress));
520
- recordAuthoredWiring(fullAddress, localWiring);
521
- pending.push({
522
- deps: child.deps,
523
- wiring: localWiring,
524
- targetId: fullAddress,
525
- targetKind: "module",
526
- enclosingModuleName: moduleNode.name
527
- });
528
- const childOutputs = flatten(child, fullAddress, fullAddress, localWiring, localSecrets, localParams, nodes, edges, pending, inputBindings, paramBindings, byId, ports, authoredEdges);
529
- nodes.push({
530
- id: fullAddress,
531
- parent: selfId,
532
- node: child
533
- });
534
- byId.set(fullAddress, child);
535
- const brandedOutputs = {};
536
- for (const [key, value] of Object.entries(childOutputs)) brandedOutputs[key] = typeof value === "object" && value !== null ? {
537
- ...value,
538
- [AUTHORED_PORT]: {
539
- node: fullAddress,
540
- name: key
541
- }
542
- } : value;
543
- return blindCast({
544
- id: fullAddress,
545
- ...brandedOutputs
546
- });
547
- };
548
- const ctx = blindCast({
549
- inputs: ctxInputs,
550
- secrets: ctxSecrets,
551
- params: ctxParams,
552
- provision: blindCast(provision)
553
- });
554
- const outputs = blindCast(moduleNode.body(ctx) ?? {});
555
- markUsed(Object.values(outputs));
556
- 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.`);
557
- 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.`);
558
- 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.`);
559
- for (const [key, contract] of Object.entries(moduleNode.expose)) {
560
- const port = outputs[key];
561
- if (port === void 0) throw new LoadError(`Module "${moduleNode.name}" declares expose "${key}" but its body did not return a port for it.`);
562
- if (!satisfiesRequired(port, contract)) throw new LoadError(`Module "${moduleNode.name}"'s returned port for expose "${key}" does not satisfy its declared contract.`);
563
- const from = authoredSourceOf(port);
564
- if (from !== void 0) authoredEdges.push({
565
- from,
566
- to: {
567
- node: selfId,
568
- direction: "out",
569
- name: key
570
- }
571
- });
572
- }
573
- return outputs;
574
- }
575
- function loadModule(root, opts) {
576
- const rootId = opts?.id ?? root.name;
577
- const rootDepKeys = Object.keys(root.deps);
578
- if (rootDepKeys.length > 0) {
579
- const names = rootDepKeys.map((k) => `"${k}"`).join(", ");
580
- 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.`);
581
- }
582
- const rootSecretKeys = Object.keys(root.secretSlots);
583
- if (rootSecretKeys.length > 0) {
584
- const names = rootSecretKeys.map((k) => `"${k}"`).join(", ");
585
- 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.`);
586
- }
587
- const rootParamKeys = Object.keys(root.paramSlots);
588
- if (rootParamKeys.length > 0) {
589
- const names = rootParamKeys.map((k) => `"${k}"`).join(", ");
590
- 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.`);
591
- }
592
- const nodes = [];
593
- const edges = [];
594
- const pending = [];
595
- const inputBindings = [];
596
- const paramBindings = [];
597
- const byId = /* @__PURE__ */ new Map();
598
- const ports = [];
599
- const authoredEdges = [];
600
- flatten(root, void 0, rootId, {}, {}, {}, nodes, edges, pending, inputBindings, paramBindings, byId, ports, authoredEdges);
601
- for (const entry of pending) validateWiring(entry, byId);
602
- assertDependencyDag(edges);
603
- const rootGraphNode = {
604
- id: rootId,
605
- parent: void 0,
606
- node: root
607
- };
608
- return {
609
- root: rootGraphNode,
610
- nodes: [...topoSort(nodes, edges), rootGraphNode],
611
- edges,
612
- ports,
613
- authoredEdges,
614
- inputBindings,
615
- params: paramBindings
616
- };
617
- }
618
- /**
619
- * The dependency edges must form a DAG — a cycle means neither producer can
620
- * deploy first. Resources take no wiring, so only service/module-to-service/module
621
- * edges can ever participate in a cycle; no special-casing needed.
622
- */
623
- function assertDependencyDag(edges) {
624
- const adjacency = /* @__PURE__ */ new Map();
625
- for (const edge of edges) {
626
- if (edge.kind !== "dependency") continue;
627
- const targets = adjacency.get(edge.from) ?? [];
628
- targets.push(edge.to);
629
- adjacency.set(edge.from, targets);
630
- }
631
- const visiting = /* @__PURE__ */ new Set();
632
- const done = /* @__PURE__ */ new Set();
633
- const stack = [];
634
- const visit = (id) => {
635
- if (done.has(id)) return;
636
- if (visiting.has(id)) throw new LoadError(`Dependency cycle: ${[...stack.slice(stack.indexOf(id)), id].join(" → ")} — no deploy order exists.`);
637
- visiting.add(id);
638
- stack.push(id);
639
- for (const next of adjacency.get(id) ?? []) visit(next);
640
- stack.pop();
641
- visiting.delete(id);
642
- done.add(id);
643
- };
644
- for (const id of adjacency.keys()) visit(id);
645
- }
646
- /**
647
- * Builds the in-memory graph from a root node. A service root walks its own
648
- * `inputs`; a module root executes its body (wiring, not user code — the
649
- * designed exception to imports-run-nothing) and recursively flattens every
650
- * module it provisions into one graph of hierarchical addresses. A malformed
651
- * graph is a `LoadError` that names its fix; the individual validation rules
652
- * live with `loadService` / `loadModule` and are covered by name in the Load
653
- * tests. Executes nothing of the user's own code beyond module bodies.
654
- */
655
- function Load(root, opts) {
656
- if (!isNode(root)) throw new LoadError("Load expects a branded service or module node (construct it with the service()/module() factories).");
657
- if (root.kind === "module") return loadModule(root, opts);
658
- if (root.kind === "service") return loadService(root, opts?.id ?? "root");
659
- throw new LoadError("Load expects a service or module root (received another node kind).");
660
- }
661
- blindCast(Symbol.for("prisma:secret-box"));
662
- //#endregion
663
- //#region ../../0-framework/3-tooling/cli/dist/load-entry-BjRb7YB3.mjs
664
- /**
665
- * Synchronous Node resolve hook so that entry modules may import relative
666
- * files using the specifier forms TypeScript accepts by default —
667
- * extensionless `./service` and `./service.js` for a `.ts` source file —
668
- * without requiring `allowImportingTsExtensions` in every consumer's tsconfig.
669
- *
670
- * Resolution only; uses TypeScript's own documented mapping: for a specifier
671
- * Node could not resolve, strip any JS-family extension and probe the
672
- * corresponding TypeScript source; first candidate that exists on disk wins.
673
- * Format-specific rules: `.mjs` → `.mts`; `.cjs` → `.cts`; `.js` and
674
- * extensionless → `.ts`, `.mts`, `.tsx`, then `./index.ts`. Bare and package
675
- * specifiers are never touched. Existing `./x.ts` imports keep working —
676
- * Node resolves them before the hook fires (ADR-0005: no transform, no
677
- * guessing, deterministic TypeScript rule).
678
- *
679
- * Bun resolves `./x.js` and `./x` to `x.ts` natively, so the hook is a
680
- * no-op under Bun. Nothing is registered there.
681
- */
682
- let registered = false;
683
- /**
684
- * Registers the resolve hook once (idempotent). Call at the start of
685
- * `loadEntry` so every module in the entry graph benefits, including those
686
- * imported lazily after the entry itself loads.
687
- */
688
- function registerEntryResolution() {
689
- if (registered || typeof process.versions.bun === "string") return;
690
- if (typeof mod.registerHooks !== "function") return;
691
- registered = true;
692
- mod.registerHooks({ resolve(specifier, context, nextResolve) {
693
- try {
694
- return nextResolve(specifier, context);
695
- } catch (error) {
696
- if (!isRelativeSpecifier(specifier) || context.parentURL === void 0 || !isModuleNotFoundError(error)) throw error;
697
- for (const candidate of sourceCandidates(new URL(specifier, context.parentURL))) if (existsSync(fileURLToPath(candidate))) return nextResolve(candidate.href, context);
698
- throw error;
699
- }
700
- } });
701
- }
702
- /**
703
- * TypeScript's extension mapping: for a JS-family or extensionless URL,
704
- * produce the source candidates to probe. Format-specific: `.mjs` maps only
705
- * to `.mts`; `.cjs` maps only to `.cts`; `.js` and extensionless probe
706
- * `.ts`, `.mts`, `.tsx` (keeping `.tsx` so the JSX diagnostic fires), then
707
- * `./index.ts`.
708
- */
709
- function sourceCandidates(resolved) {
710
- const href = resolved.href;
711
- if (href.endsWith(".mjs")) {
712
- const base = href.slice(0, -4);
713
- return [new URL(`${base}.mts`)];
714
- }
715
- if (href.endsWith(".cjs")) {
716
- const base = href.slice(0, -4);
717
- return [new URL(`${base}.cts`)];
718
- }
719
- const base = href.endsWith(".js") ? href.slice(0, -3) : href;
720
- return [
721
- new URL(`${base}.ts`),
722
- new URL(`${base}.mts`),
723
- new URL(`${base}.tsx`),
724
- new URL(`${base}/index.ts`)
725
- ];
726
- }
727
- function isRelativeSpecifier(specifier) {
728
- return specifier.startsWith("./") || specifier.startsWith("../");
729
- }
730
- function isModuleNotFoundError(error) {
731
- if (!(error instanceof Error)) return false;
732
- if (!("code" in error)) return false;
733
- return error.code === "ERR_MODULE_NOT_FOUND";
734
- }
735
- /**
736
- * `loadEntry` imports a user's topology with the host runtime's own module
737
- * loader — under node (the CLI's shebang runtime), that loader strips
738
- * TypeScript types but has no JSX transform (ADR-0005: the framework
739
- * doesn't bundle or transform the app's code; deploy loading is no
740
- * exception). A `.tsx`/`.jsx` file anywhere in the topology's import graph
741
- * dies with node's raw `ERR_UNKNOWN_FILE_EXTENSION`, which names the file
742
- * but not the cause or the fix. This turns that one case into structured
743
- * error parts (summary/why/fix) that do — every other load failure (syntax
744
- * errors, missing files, non-JSX unknown extensions) is untouched.
745
- */
746
- const UNKNOWN_EXTENSION_CODE = "ERR_UNKNOWN_FILE_EXTENSION";
747
- const JSX_EXTENSIONS = [".tsx", ".jsx"];
748
- function errorCode(error) {
749
- return "code" in error && typeof error.code === "string" ? error.code : void 0;
750
- }
751
- function unknownExtensionPath(error) {
752
- if (!(error instanceof Error)) return void 0;
753
- if (errorCode(error) !== UNKNOWN_EXTENSION_CODE) return void 0;
754
- return /Unknown file extension "\.\w+" for (.+)$/.exec(error.message)?.[1];
755
- }
756
- /**
757
- * Returns structured error parts when `error` is node's
758
- * `ERR_UNKNOWN_FILE_EXTENSION` for a `.tsx`/`.jsx` file — `undefined` for
759
- * every other error (including unknown-extension failures for some other
760
- * extension), so the caller can fall through to its normal rethrow.
761
- */
762
- function explainJsxLoadError(error, entryPath) {
763
- const offendingPath = unknownExtensionPath(error);
764
- if (offendingPath === void 0) return void 0;
765
- if (!JSX_EXTENSIONS.some((ext) => offendingPath.endsWith(ext))) return void 0;
766
- return {
767
- summary: `"${offendingPath}" can't be loaded.`,
768
- 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.`,
769
- 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."
770
- };
771
- }
772
- /**
773
- * Pipeline step 1 (deploy-cli.md § The pipeline): import the entry module
774
- * (resolved against cwd) and require its default export to be a node — a
775
- * service or module, branded by core's factories. Whatever this module exports
776
- * IS the application; nothing else marks a root (ADR-0003).
777
- */
778
- async function loadEntry(entryArg, cwd) {
779
- registerEntryResolution();
780
- const resolvedPath = path.resolve(cwd, entryArg);
781
- let mod;
782
- try {
783
- mod = await import(pathToFileURL(resolvedPath).href);
784
- } catch (error) {
785
- const explained = explainJsxLoadError(error, resolvedPath);
786
- if (explained !== void 0) throw new CliStructuredError("COMPOSE.ENTRY_UNLOADABLE", explained.summary, {
787
- why: explained.why,
788
- fix: explained.fix,
789
- where: { path: resolvedPath },
790
- cause: error
791
- });
792
- throw new CliStructuredError("COMPOSE.ENTRY_UNLOADABLE", `Failed to import entry module "${resolvedPath}": ${error instanceof Error ? error.message : String(error)}`, {
793
- where: { path: resolvedPath },
794
- cause: error
795
- });
796
- }
797
- const root = blindCast(mod).default;
798
- 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).`, {
799
- fix: "Construct it with service() or module() from @prisma/composer.",
800
- where: { path: resolvedPath }
801
- });
802
- return {
803
- path: resolvedPath,
804
- root: blindCast(root)
805
- };
806
- }
807
- //#endregion
808
- //#region ../../0-framework/3-tooling/assemble/dist/index.mjs
809
- /**
810
- * A user-facing assembly failure, structured at origin (base-type rule 6):
811
- * a `CliStructuredError` whose code names which way assembly went wrong.
812
- * This package's second consumer is the programmatic deploy API, not just
813
- * the CLI — hosts branch on `error.code`, the CLI renders the envelope.
814
- */
815
- var AssembleError = class extends CliStructuredError {
816
- constructor(code, summary, options) {
817
- super(code, summary, options);
818
- }
819
- };
820
- /**
821
- * The registry route for one service's build: extension by
822
- * `build.extension`, node descriptor by `build.type`, kind must be "build".
823
- * The CLI's coverage validation reports the same misses earlier with the
824
- * config fix; these errors are the backstop for programmatic callers.
825
- */
826
- function buildDescriptorAssemble(config, node, address, cwd) {
827
- const { extension, type } = node.build;
828
- const extensionDescriptor = config.extensions.find((candidate) => candidate.id === extension);
829
- 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 `extensions` in the `composer` section of prisma.config.ts." });
830
- const nodeDescriptor = extensionDescriptor.nodes[type];
831
- 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(", ")}.` });
832
- 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." });
833
- return nodeDescriptor.assemble({
834
- build: node.build,
835
- address,
836
- cwd
837
- });
838
- }
839
- async function assembleServices(graph, config, cwd, run) {
840
- const runAssembler = run ?? ((node, address, nodeCwd) => buildDescriptorAssemble(config, node, address, nodeCwd));
841
- const serviceNodes = graph.nodes.filter((n) => n.node.kind === "service");
842
- if (serviceNodes.length === 0) throw new AssembleError("ASSEMBLE.SERVICE_MISSING", "The loaded graph has no service to assemble.");
843
- const bundles = {};
844
- for (const { id, node } of serviceNodes) try {
845
- bundles[id] = await runAssembler(node, id, cwd);
846
- } catch (error) {
847
- if (CliStructuredError.is(error)) throw error;
848
- throw new AssembleError("ASSEMBLE.BUILD_FAILED", error instanceof Error ? error.message : String(error), {
849
- meta: { address: id },
850
- cause: error
851
- });
852
- }
853
- return { bundles };
854
- }
855
- //#endregion
856
- //#region ../../0-framework/3-tooling/cli/dist/pipeline-DAYhea3J.mjs
857
- function lookup(extensions, extension, type, expectedKind, what) {
858
- const ext = extensions.get(extension);
859
- if (ext === void 0) throw new CliStructuredError("CONFIG.EXTENSION_MISSING", `No extension "${extension}" is configured (needed by ${what}).`, {
860
- fix: "Add it to `extensions` in the `composer` section of prisma.config.ts (import its /control entry and list its descriptor).",
861
- meta: {
862
- extension,
863
- type
864
- }
865
- });
866
- const descriptor = ext.nodes[type];
867
- if (descriptor === void 0) throw new CliStructuredError("CONFIG.DESCRIPTOR_MISSING", `Extension "${extension}" has no descriptor for node type "${type}" (needed by ${what}).`, {
868
- why: `Known types: ${Object.keys(ext.nodes).join(", ")}.`,
869
- meta: {
870
- extension,
871
- type
872
- }
873
- });
874
- 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: {
875
- extension,
876
- type,
877
- kind: descriptor.kind
878
- } });
879
- }
880
- /** Throws a structured CONFIG.* error on the first uncovered `(extension, type)`; silent when the config covers the whole graph. */
881
- function validateRegistryCoverage(graph, config) {
882
- const extensions = new Map(config.extensions.map((descriptor) => [descriptor.id, descriptor]));
883
- for (const { id, node } of graph.nodes) {
884
- if (node.kind === "resource") {
885
- lookup(extensions, node.extension, node.type, "resource", `resource node "${id}"`);
886
- continue;
887
- }
888
- if (node.kind !== "service") continue;
889
- lookup(extensions, node.extension, node.type, "service", `service node "${id}"`);
890
- lookup(extensions, node.build.extension, node.build.type, "build", `service node "${id}"'s build descriptor`);
891
- }
892
- }
893
- /**
894
- * The shared prefix of `deploy`/`destroy`/`dev` (deploy-cli.md § The
895
- * pipeline; local-dev spec § 6): entry load, Load,
896
- * registry coverage validation, name resolution, assemble. Deploy and dev
897
- * diverge after this — deploy resolves containers/preflight/stack file
898
- * against the hosted providers, dev against the local ones — so everything
899
- * up to and including assemble lives here once, consumed verbatim by both
900
- * `run()` (main.ts) and `runDev()` (dev/run-dev.ts), so the two pipelines
901
- * cannot drift.
902
- */
903
- function configError(findings, file) {
904
- const [first] = findings;
905
- return new CliStructuredError(first.code, first.summary, {
906
- ...first.why === void 0 ? {} : { why: first.why },
907
- fix: first.fix,
908
- where: { path: first.where ?? file },
909
- meta: {
910
- ...first.field === void 0 ? {} : { field: first.field },
911
- findings
912
- }
913
- });
914
- }
915
- /**
916
- * Refuses a caller's config with the same findings, in the same order, as the CLI's section validator.
917
- * The error is the first finding and carries all of them in `meta.findings`. Returns the config with `file` resolved against `cwd`.
918
- */
919
- function checkConfigSource(source, cwd) {
920
- const file = path.resolve(cwd, source.file);
921
- if (!fs.existsSync(file)) throw configError([configFileMissing(file)], file);
922
- const checked = checkComposerConfig(source.value, file);
923
- if (!checked.ok) throw configError(checked.findings, file);
924
- return {
925
- value: checked.value,
926
- file
927
- };
928
- }
929
- /**
930
- * The pipeline's front — entry load and name resolution —
931
- * WITHOUT Load, coverage, or assemble. `log` needs only who the app is (its
932
- * config and resolved name) to reach the already-running local instance; it
933
- * neither builds nor provisions, so it must not require the user's built
934
- * output the way the full pipeline does.
935
- */
936
- async function resolveAppIdentity(entry, overrideName, cwd, config) {
937
- const { value } = checkConfigSource(config, cwd);
938
- const entryModule = await loadEntry(entry, cwd);
939
- const name = overrideName ?? entryModule.root.name;
940
- if (name.length === 0) throw new CliStructuredError("COMPOSE.NAME_MISSING", "The root node has no name.", { fix: "Name it at authoring, or pass --name." });
941
- return {
942
- config: value,
943
- name
944
- };
945
- }
946
- /**
947
- * Runs entry load, Load, registry coverage, name resolution, and assemble — steps 1–5 of `run()`. `onAssembleError`, when
948
- * given, lets a caller decorate an assemble failure with command-specific
949
- * guidance (destroy's "build first" hint) without this shared step knowing
950
- * about any one command.
951
- */
952
- async function runPipeline(entry, overrideName, cwd, source, deps = {}, onAssembleError) {
953
- const configSource = checkConfigSource(source, cwd);
954
- const config = configSource.value;
955
- const entryModule = await loadEntry(entry, cwd);
956
- const graph = Load(entryModule.root);
957
- 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); })." });
958
- validateRegistryCoverage(graph, config);
959
- const name = overrideName ?? entryModule.root.name;
960
- if (name.length === 0) throw new CliStructuredError("COMPOSE.NAME_MISSING", "The root node has no name.", { fix: "Name it at authoring, or pass --name." });
961
- let assembled;
962
- try {
963
- assembled = await assembleServices(graph, config, cwd, deps.runAssembler);
964
- } catch (error) {
965
- if (onAssembleError !== void 0 && error instanceof Error) throw onAssembleError(error);
966
- throw error;
967
- }
968
- return {
969
- configSource,
970
- entryModule,
971
- graph,
972
- name,
973
- assembled
974
- };
975
- }
976
- //#endregion
977
- export { runPipeline as n, resolveAppIdentity as t };
978
-
979
- //# sourceMappingURL=pipeline-DAYhea3J-BEnHHWp8.mjs.map