@prisma/composer-prisma-cloud 0.1.0 → 0.2.0-dev.10

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 (80) hide show
  1. package/dist/control.d.mts +79 -36
  2. package/dist/control.d.mts.map +1 -0
  3. package/dist/control.mjs +1074 -330
  4. package/dist/control.mjs.map +1 -1
  5. package/dist/cron/index.d.mts +63 -10
  6. package/dist/cron/index.d.mts.map +1 -0
  7. package/dist/cron/index.mjs +255 -42
  8. package/dist/cron/index.mjs.map +1 -1
  9. package/dist/cron/scheduler-entrypoint.mjs +578 -300
  10. package/dist/cron/scheduler-entrypoint.mjs.map +1 -1
  11. package/dist/cron/scheduler-service.mjs +255 -42
  12. package/dist/cron/scheduler-service.mjs.map +1 -1
  13. package/dist/email/email-entrypoint.mjs +19738 -0
  14. package/dist/email/email-entrypoint.mjs.map +1 -0
  15. package/dist/email/email-service.mjs +566 -0
  16. package/dist/email/email-service.mjs.map +1 -0
  17. package/dist/email/index.d.mts +282 -0
  18. package/dist/email/index.d.mts.map +1 -0
  19. package/dist/email/index.mjs +653 -0
  20. package/dist/email/index.mjs.map +1 -0
  21. package/dist/email/testing.d.mts +22 -0
  22. package/dist/email/testing.d.mts.map +1 -0
  23. package/dist/email/testing.mjs +1321 -0
  24. package/dist/email/testing.mjs.map +1 -0
  25. package/dist/index.d.mts +152 -26
  26. package/dist/index.d.mts.map +1 -0
  27. package/dist/index.mjs +108 -43
  28. package/dist/index.mjs.map +1 -1
  29. package/dist/{prisma-next-COrwlg3N.mjs → prisma-next-BvBwGCIt-CSauMX4l.mjs} +20 -4
  30. package/dist/prisma-next-BvBwGCIt-CSauMX4l.mjs.map +1 -0
  31. package/dist/prisma-next.d.mts +14 -6
  32. package/dist/prisma-next.d.mts.map +1 -0
  33. package/dist/prisma-next.mjs +1 -1
  34. package/dist/provisioned-edges-B_XS1Mz--NFJgcXK7.mjs +211 -0
  35. package/dist/provisioned-edges-B_XS1Mz--NFJgcXK7.mjs.map +1 -0
  36. package/dist/serializer-Cx5slrV4-xJfH6EWS.d.mts +36 -0
  37. package/dist/serializer-Cx5slrV4-xJfH6EWS.d.mts.map +1 -0
  38. package/dist/{serializer-C2CsA7xm-29Eg2Tjl.mjs → serializer-D8_84XWO-DA2B6YbX.mjs} +91 -7
  39. package/dist/serializer-D8_84XWO-DA2B6YbX.mjs.map +1 -0
  40. package/dist/storage/index.d.mts +56 -20
  41. package/dist/storage/index.d.mts.map +1 -0
  42. package/dist/storage/index.mjs +267 -44
  43. package/dist/storage/index.mjs.map +1 -1
  44. package/dist/storage/storage-entrypoint.mjs +7501 -155
  45. package/dist/storage/storage-entrypoint.mjs.map +1 -1
  46. package/dist/storage/storage-service.mjs +267 -44
  47. package/dist/storage/storage-service.mjs.map +1 -1
  48. package/dist/storage/testing.d.mts +7 -4
  49. package/dist/storage/testing.d.mts.map +1 -0
  50. package/dist/storage/testing.mjs.map +1 -1
  51. package/dist/streams/index.d.mts +222 -0
  52. package/dist/streams/index.d.mts.map +1 -0
  53. package/dist/streams/index.mjs +4170 -0
  54. package/dist/streams/index.mjs.map +1 -0
  55. package/dist/streams/streams-entrypoint.mjs +48211 -0
  56. package/dist/streams/streams-entrypoint.mjs.map +1 -0
  57. package/dist/streams/streams-service.mjs +923 -0
  58. package/dist/streams/streams-service.mjs.map +1 -0
  59. package/dist/streams/testing.d.mts +33 -0
  60. package/dist/streams/testing.d.mts.map +1 -0
  61. package/dist/streams/testing.mjs +31335 -0
  62. package/dist/streams/testing.mjs.map +1 -0
  63. package/dist/testing.d.mts +1 -2
  64. package/dist/testing.d.mts.map +1 -0
  65. package/dist/testing.mjs +1 -1
  66. package/dist/testing.mjs.map +1 -1
  67. package/package.json +35 -23
  68. package/src/exports/control.ts +1 -0
  69. package/src/exports/cron.ts +1 -0
  70. package/src/exports/email-testing.ts +1 -0
  71. package/src/exports/email.ts +1 -0
  72. package/src/exports/index.ts +1 -0
  73. package/src/exports/prisma-next.ts +1 -0
  74. package/src/exports/storage-testing.ts +1 -0
  75. package/src/exports/storage.ts +1 -0
  76. package/src/exports/streams-testing.ts +1 -0
  77. package/src/exports/streams.ts +1 -0
  78. package/src/exports/testing.ts +1 -0
  79. package/dist/prisma-next-COrwlg3N.mjs.map +0 -1
  80. package/dist/serializer-C2CsA7xm-29Eg2Tjl.mjs.map +0 -1
@@ -0,0 +1,923 @@
1
+ import { dependency, hydrateSecrets, hydrateSync, number, provisionNeed, resource, service, string } from "@prisma/composer";
2
+ import { blindCast } from "@prisma/composer/casts";
3
+ import { type } from "arktype";
4
+ import { RPC_PEER_KEY } from "@prisma/composer/service-rpc";
5
+ import node from "@prisma/composer/node";
6
+ blindCast(Symbol.for("prisma:prisma-cloud-secret-source"));
7
+ /**
8
+ * Walks a node's own params, then each dependency input's connection params —
9
+ * the same enumeration order `configOf` uses, but carrying the raw
10
+ * `ConfigParam` (with its `serialize`/`deserialize`) instead of a pure-data
11
+ * projection.
12
+ */
13
+ function paramEntries(node) {
14
+ const entries = [];
15
+ for (const [input, value] of Object.entries(node.inputs)) {
16
+ if (typeof value !== "object" || value === null) continue;
17
+ const params = blindCast(value).connection.params;
18
+ for (const [name, param] of Object.entries(params)) entries.push({
19
+ owner: { input },
20
+ name,
21
+ param
22
+ });
23
+ }
24
+ for (const [name, param] of Object.entries(node.params)) entries.push({
25
+ owner: "service",
26
+ name,
27
+ param
28
+ });
29
+ return entries;
30
+ }
31
+ const configKey = (address, d) => {
32
+ const segments = address.split(".").filter((s) => s.length > 0);
33
+ const owner = d.owner === "service" ? [] : [d.owner.input];
34
+ return [
35
+ "COMPOSER",
36
+ ...segments,
37
+ ...owner,
38
+ d.name
39
+ ].join("_").toUpperCase();
40
+ };
41
+ /**
42
+ * Typed value → its stored string. Service-own literals are JSON-encoded; a
43
+ * dependency-input value is a provisioning ref at deploy (and a resolved
44
+ * string at boot) and passes through untouched — LANDMINE: JSON-encoding it
45
+ * would break the ordering edge Alchemy resolves through it.
46
+ */
47
+ function encode(owner, value) {
48
+ return owner === "service" ? JSON.stringify(value) : blindCast(value);
49
+ }
50
+ /** Reverses `encode`: JSON-parse a service-own value, take a dependency-input value raw. */
51
+ function decode(owner, raw) {
52
+ return owner === "service" ? JSON.parse(raw) : raw;
53
+ }
54
+ const PARAM_POINTER_PREFIX = "@composer-param-pointer:";
55
+ /** True iff `raw` is a param pointer row (as opposed to a JSON-encoded literal). */
56
+ const isParamPointerRow = (raw) => raw.startsWith(PARAM_POINTER_PREFIX);
57
+ /** Reverses `encodeParamPointer`: the platform var NAME a pointer row points to. */
58
+ const decodeParamPointer = (raw) => raw.slice(24);
59
+ function coerce(raw, d, key) {
60
+ if (!(raw !== void 0 && raw !== "")) {
61
+ if (d.param.default !== void 0) return d.param.default;
62
+ if (d.param.optional === true) return void 0;
63
+ throw new Error(`missing required config param "${d.name}" (env ${key})`);
64
+ }
65
+ if (d.owner === "service" && isParamPointerRow(raw)) return coerceEnvSourcedParam(raw, d, key);
66
+ try {
67
+ return standardValidateSync(d.param.schema, decode(d.owner, raw));
68
+ } catch (cause) {
69
+ const message = cause instanceof Error ? cause.message : String(cause);
70
+ throw new Error(`invalid value for config param "${d.name}" (env ${key}): ${message}`);
71
+ }
72
+ }
73
+ /**
74
+ * Boot resolution for an env-sourced param: double-lookup (pointer → platform
75
+ * var), then the param's own schema on the raw string — no JSON decode, and
76
+ * no redaction (it's config, not a secret). An UNSET platform var is a loud
77
+ * boot failure naming both the param and the platform var; an EMPTY string is
78
+ * not special-cased here — it reaches the schema like any other value, so it
79
+ * passes iff the schema accepts it (deliberately unlike a literal param's own
80
+ * ""-means-absent rule, and unlike a secret's non-empty requirement).
81
+ */
82
+ function coerceEnvSourcedParam(raw, d, key) {
83
+ const platformVar = decodeParamPointer(raw);
84
+ const value = process.env[platformVar];
85
+ if (value === void 0) throw new Error(`env-sourced config param "${d.name}" (env ${key} → ${platformVar}) is unset: the platform variable "${platformVar}" was not injected — the deploy did not provision it.`);
86
+ try {
87
+ return standardValidateSync(d.param.schema, value);
88
+ } catch (cause) {
89
+ const message = cause instanceof Error ? cause.message : String(cause);
90
+ throw new Error(`invalid value for env-sourced config param "${d.name}" (env ${key} → ${platformVar}): ${message}`);
91
+ }
92
+ }
93
+ /**
94
+ * Boot: read each declared param from env by its key, reverse the param's own
95
+ * serialization (missing/invalid fails loudly), assemble the typed Config.
96
+ * Secrets ride a separate channel (deserializeSecrets), not this one.
97
+ */
98
+ const deserialize = (node, address) => {
99
+ const service = {};
100
+ const inputs = {};
101
+ for (const d of paramEntries(node)) {
102
+ const key = configKey(address, d);
103
+ const value = coerce(process.env[key], d, key);
104
+ if (d.owner === "service") service[d.name] = value;
105
+ else {
106
+ let bucket = inputs[d.owner.input];
107
+ if (bucket === void 0) {
108
+ bucket = {};
109
+ inputs[d.owner.input] = bucket;
110
+ }
111
+ bucket[d.name] = value;
112
+ }
113
+ }
114
+ return {
115
+ service,
116
+ inputs
117
+ };
118
+ };
119
+ /**
120
+ * run()'s setup step: write the resolved config to the environment under
121
+ * address-free keys (configKey("", d) + each serialize suffix), which load()
122
+ * reads back with no address. Uses env, not a module variable, because a
123
+ * framework may fork worker processes that inherit env but not memory.
124
+ * Writes only these keys; nothing else is touched.
125
+ */
126
+ const stash = (node, config) => {
127
+ for (const d of paramEntries(node)) {
128
+ const value = d.owner === "service" ? config.service[d.name] : config.inputs[d.owner.input]?.[d.name];
129
+ if (value === void 0) continue;
130
+ process.env[configKey("", d)] = encode(d.owner, value);
131
+ }
132
+ };
133
+ /** The pointer-row key for a secret slot: COMPOSER_<addr>_<slot> (secrets are service-level). */
134
+ const secretKey = (address, slot) => configKey(address, {
135
+ owner: "service",
136
+ name: slot
137
+ });
138
+ /**
139
+ * Boot: resolve every secret slot to its value by double-lookup — read the
140
+ * pointer key (the platform NAME), then read that platform var. A missing
141
+ * pointer or a missing/empty platform value is a loud failure naming both keys.
142
+ * Returns a plain Record for core's `hydrateSecrets` to box.
143
+ */
144
+ const deserializeSecrets = (node, address) => {
145
+ const values = {};
146
+ for (const slot of Object.keys(node.secretSlots)) {
147
+ const key = secretKey(address, slot);
148
+ const name = process.env[key];
149
+ if (name === void 0 || name === "") throw new Error(`missing secret pointer for slot "${slot}" (env ${key}) — the deploy did not write it.`);
150
+ const value = process.env[name];
151
+ if (value === void 0 || value === "") throw new Error(`secret "${slot}" is not provisioned (env ${key} → ${name}): the platform var "${name}" is unset or empty.`);
152
+ values[slot] = value;
153
+ }
154
+ return values;
155
+ };
156
+ /**
157
+ * run()'s setup step for secrets: re-emit each slot's pointer NAME under its
158
+ * address-free key, so the address-free `deserializeSecrets` double-looks-up
159
+ * identically. Never the value — the value stays only in the platform var.
160
+ */
161
+ const stashSecrets = (node, address) => {
162
+ for (const slot of Object.keys(node.secretSlots)) {
163
+ const name = process.env[secretKey(address, slot)];
164
+ if (name === void 0) continue;
165
+ process.env[secretKey("", slot)] = name;
166
+ }
167
+ };
168
+ /**
169
+ * Boot: for each reserved provider param, read its address-scoped row through
170
+ * the same `coerce` a declared param uses (JSON-decode, schema-validate), and
171
+ * re-emit it address-free — `stash`'s counterpart for this separate
172
+ * declaration space. A param is declared optional here unconditionally: an
173
+ * absent row means "never provisioned" (local dev, tests, a provider with no
174
+ * registered value for this deploy), never a boot failure, so nothing is
175
+ * stashed and the runtime reader that owns this slot falls back to its own
176
+ * pass-through behavior.
177
+ */
178
+ function stashProviderParams(entries, address) {
179
+ for (const entry of entries) {
180
+ const d = {
181
+ owner: "service",
182
+ name: entry.name,
183
+ param: {
184
+ schema: entry.schema,
185
+ optional: true
186
+ }
187
+ };
188
+ const key = configKey(address, d);
189
+ const value = coerce(process.env[key], d, key);
190
+ if (value === void 0) continue;
191
+ process.env[configKey("", d)] = encode("service", value);
192
+ }
193
+ }
194
+ /** The framework-resolved origin row: COMPOSER_<addr>_ORIGIN. Written per
195
+ * compute service at serialize — the service's own provisioned endpoint URL,
196
+ * riding the reserved-provider-param machinery (`origin-key.ts`'s
197
+ * `ORIGIN_PARAM`); never a declared param, never in config(). A harness with
198
+ * no deploy behind it supplies it by setting `COMPOSER_ORIGIN` to the
199
+ * JSON-encoded origin URL — exactly how the existing entrypoint tests supply
200
+ * their other `COMPOSER_*` rows. */
201
+ const ORIGIN_KEY_NAME = "ORIGIN";
202
+ /**
203
+ * Reads this service's origin back out of the address-free stash
204
+ * `stashProviderParams` wrote for the ORIGIN entry. `COMPOSER_ORIGIN` unset is
205
+ * a loud failure — a deployed environment always writes it, so an unset row
206
+ * means either a local harness that hasn't supplied it or a boot() called
207
+ * before run().
208
+ */
209
+ function readOrigin() {
210
+ const d = {
211
+ owner: "service",
212
+ name: ORIGIN_KEY_NAME,
213
+ param: {
214
+ schema: type("string"),
215
+ optional: true
216
+ }
217
+ };
218
+ const key = configKey("", d);
219
+ const value = coerce(process.env[key], d, key);
220
+ if (value === void 0) throw new Error("this service's origin is not available (env COMPOSER_ORIGIN is unset) — a deployed environment writes it automatically; a local harness must supply it like any other config value (set COMPOSER_ORIGIN to the JSON-encoded origin URL).");
221
+ return blindCast(value);
222
+ }
223
+ /** Synchronous Standard Schema validation — see the matching note in core's `config.ts`. */
224
+ function standardValidateSync(schema, value) {
225
+ const result = schema["~standard"].validate(value);
226
+ if (result instanceof Promise) throw new Error("config param schema validation must be synchronous — async Standard Schema validators are not supported for config params");
227
+ if (result.issues !== void 0) throw new Error(`config param validation failed: ${result.issues.map((issue) => issue.message).join("; ")}`);
228
+ return result.value;
229
+ }
230
+ //#endregion
231
+ //#region ../../1-prisma-cloud/1-extensions/target/dist/provisioned-edges-B_XS1Mz-.mjs
232
+ /**
233
+ * The service's own origin as a reserved provider param (ADR-0031): the ONE
234
+ * brand and the ONE entry — shared by control.ts (which registers the
235
+ * deploy-side value function that resolves the provisioned service's
236
+ * `endpointDomain` — see its `selfOriginValue`) and compute.ts (which
237
+ * validates and stashes the row at boot through the generic
238
+ * `stashProviderParams` loop), so writer and reader cannot drift.
239
+ *
240
+ * Unlike the key-minting brands (`service-keys.ts`, `streams-keys.ts`) this
241
+ * brand has no provisioner and no consumer edges: the value derives from the
242
+ * service's OWN provisioned attributes, so control.ts registers it as a
243
+ * service-derived provider param (`descriptors/shared.ts`'s
244
+ * `ServiceProviderParam`) and the descriptor writes it for EVERY compute
245
+ * service, exposing or not.
246
+ *
247
+ * This module is reachable from the RUNTIME/authoring side — it must never
248
+ * import `@internal/lowering` or `effect`, or those tokens leak into a user
249
+ * service's bundle (the deploy-side value function lives in control.ts, the
250
+ * control-plane-only entry).
251
+ */
252
+ /** ADR-0031's brand for the service's own origin — control.ts registers the deploy-side value function under this. */
253
+ const SELF_ORIGIN = Symbol.for("prisma:self-origin");
254
+ /**
255
+ * The reserved provider param for the origin row: the var name is `ORIGIN`,
256
+ * derived through `configKey` at both ends (`configKey(address, …)` at
257
+ * deploy, `configKey('', …)` — `COMPOSER_ORIGIN` — at boot, where
258
+ * `readOrigin` reads it back). `brand` is `SELF_ORIGIN` — control.ts looks
259
+ * its deploy-side value function up by this field.
260
+ */
261
+ const ORIGIN_PARAM = {
262
+ name: ORIGIN_KEY_NAME,
263
+ schema: type("string"),
264
+ brand: SELF_ORIGIN
265
+ };
266
+ /**
267
+ * RPC's reserved provider param (ADR-0030/ADR-0031): the declaration —
268
+ * name + schema + brand — for the accepted-keys set a provider stores, shared
269
+ * by `control.ts` (which registers the deploy-side `value(refs)` that mints
270
+ * and aggregates it — see its `rpcAcceptedKeysValue`) and `compute.ts` (which
271
+ * validates and stashes it at boot), so writer and reader cannot drift.
272
+ * Finding the edges themselves is `provisioned-edges.ts`'s generic,
273
+ * brand-blind scan — RPC is not special-cased anywhere in this target.
274
+ *
275
+ * This module is reachable from the RUNTIME/authoring side — it must never
276
+ * import `@internal/lowering` or `effect`, or those tokens leak into a user
277
+ * service's bundle (the deploy-side `value(refs)` lives in control.ts, the
278
+ * control-plane-only entry).
279
+ */
280
+ /**
281
+ * The reserved provider param for RPC's accepted-keys set: the var name is
282
+ * `RPC_ACCEPTED_KEYS`, derived through `configKey` at both ends
283
+ * (`configKey(address, …)` at deploy, `configKey('', …)` at boot — the
284
+ * address-free form is `@internal/service-rpc`'s `RPC_ACCEPTED_KEYS_ENV`). `brand` is
285
+ * `RPC_PEER_KEY`, the same brand `perBindingToken()`'s need carries — control.ts
286
+ * looks its `value(refs)` up by this field.
287
+ */
288
+ const RPC_ACCEPTED_KEYS_PARAM = {
289
+ name: "RPC_ACCEPTED_KEYS",
290
+ schema: type("string[]"),
291
+ brand: RPC_PEER_KEY
292
+ };
293
+ /** ADR-0031's need brand for the streams module's bearer key — control.ts registers the provisioner under this. */
294
+ const STREAMS_API_KEY = Symbol.for("prisma:streams/api-key");
295
+ /**
296
+ * The provisioning need `durableStreams()`'s `apiKey` param declares: an
297
+ * unguessable value the target mints ONCE PER PROVIDER (not per edge) —
298
+ * `@prisma/streams-server` authenticates a single `API_KEY`, so every
299
+ * consumer of one streams module must present the same value. Per-provider
300
+ * cardinality is provisioner policy (ADR-0031), invisible to core.
301
+ */
302
+ const streamsApiKeyNeed = () => provisionNeed(STREAMS_API_KEY);
303
+ /**
304
+ * The reserved provider param for the streams bearer key: the var name is
305
+ * `STREAMS_API_KEY`. `brand` is `STREAMS_API_KEY` itself (the same symbol
306
+ * `streamsApiKeyNeed()`'s need carries) — control.ts looks its `value(refs)`
307
+ * up by this field.
308
+ */
309
+ const STREAMS_API_KEY_PARAM = {
310
+ name: "STREAMS_API_KEY",
311
+ schema: type("string"),
312
+ brand: STREAMS_API_KEY
313
+ };
314
+ configKey("", {
315
+ owner: "service",
316
+ name: STREAMS_API_KEY_PARAM.name
317
+ });
318
+ /**
319
+ * The list of provider-side reserved params the boot path validates and
320
+ * stashes (ADR-0031): every brand's `{name, schema, brand}` declaration,
321
+ * collected from that brand's own module (`service-keys.ts`,
322
+ * `streams-keys.ts`, `origin-key.ts`) so `compute.ts` names no brand itself.
323
+ *
324
+ * This list exists separately from `control.ts`'s deploy-side registry
325
+ * (`PROVIDER_PARAMS`) because `control.ts` is deploy-only code — it imports
326
+ * `@internal/lowering` and `effect` to mint values — and a booted service
327
+ * must never import it. This module is reachable from a user service's
328
+ * bundle through `compute.ts`, so it must never import `@internal/lowering`,
329
+ * `effect`, `alchemy`, or `control.ts`.
330
+ *
331
+ * This is the single source of which reserved provider params exist:
332
+ * control.ts builds `PROVIDER_PARAMS` by mapping over this list and looking
333
+ * up each entry's deploy-side value function (edge-derived `value(refs)` or
334
+ * service-derived `valueForService(provisioned, address)`) by its `brand`,
335
+ * throwing at module load if one is missing. Adding a brand means adding its
336
+ * entry here, plus its deploy-side value function in control.ts — a brand
337
+ * registered for deploy but absent here is no longer expressible, because
338
+ * deploy no longer names its own param set independently.
339
+ */
340
+ const RESERVED_PROVIDER_PARAMS = [
341
+ RPC_ACCEPTED_KEYS_PARAM,
342
+ STREAMS_API_KEY_PARAM,
343
+ ORIGIN_PARAM
344
+ ];
345
+ blindCast(Symbol.for("prisma:prisma-cloud-param-source"));
346
+ Object.freeze({
347
+ kind: "s3",
348
+ __cmp: {
349
+ url: "",
350
+ bucket: "",
351
+ accessKeyId: "",
352
+ secretAccessKey: ""
353
+ },
354
+ satisfies: (required) => required.kind === "s3"
355
+ });
356
+ const reservedParams = { port: number({ default: 3e3 }) };
357
+ /**
358
+ * A Prisma Compute service — declarations only (deps + params + build + the
359
+ * ports it exposes), no descriptor. `params` merges with the reserved
360
+ * `ReservedParams` (`port`); a user param whose name collides with a reserved
361
+ * one fails at authoring, the same way a colliding dependency name does.
362
+ *
363
+ * · run(address, boot) — the process controller: deserialize the platform
364
+ * environment (keyed off `address`, the extension's ONE env read) into a
365
+ * typed Config, re-emit it under address-free process-local stash keys,
366
+ * then call boot() to start the app's entry.
367
+ * · load() / config() — called from inside the app's entry: read the stash;
368
+ * load() hydrates + memoizes the deps, config() returns the typed params.
369
+ * Separate accessors so a dep and a param never share a namespace (ADR-0021).
370
+ * · origin() — this service's platform-assigned public origin, read from the
371
+ * stash `run()` populates; memoized per process.
372
+ *
373
+ * The underlying node carries `extension: '@prisma/composer-prisma-cloud'` —
374
+ * the control-plane registry key `prisma-composer deploy` resolves through the
375
+ * app's `prisma-composer.config.ts` (ADR-0017). This module loads nothing at
376
+ * deploy time; nodes are pure data until run() or load() is called.
377
+ */
378
+ var ComputeService = class {
379
+ #resolved;
380
+ #loadedDeps;
381
+ #loadedParams;
382
+ #loadedSecrets;
383
+ #origin;
384
+ constructor(node) {
385
+ Object.assign(this, node);
386
+ }
387
+ #processConfig() {
388
+ if (this.#resolved === void 0) this.#resolved = deserialize(this, "");
389
+ return this.#resolved;
390
+ }
391
+ async run(address, boot) {
392
+ const config = deserialize(this, address);
393
+ stash(this, config);
394
+ stashProviderParams(RESERVED_PROVIDER_PARAMS, address);
395
+ stashSecrets(this, address);
396
+ const port = config.service["port"];
397
+ if (typeof port === "number") process.env["PORT"] = String(port);
398
+ return boot();
399
+ }
400
+ load() {
401
+ if (this.#loadedDeps === void 0) this.#loadedDeps = blindCast(hydrateSync(this, this.#processConfig()));
402
+ return this.#loadedDeps;
403
+ }
404
+ config() {
405
+ if (this.#loadedParams === void 0) this.#loadedParams = blindCast(this.#processConfig().service);
406
+ return this.#loadedParams;
407
+ }
408
+ secrets() {
409
+ if (this.#loadedSecrets === void 0) this.#loadedSecrets = blindCast(hydrateSecrets(this, deserializeSecrets(this, "")));
410
+ return this.#loadedSecrets;
411
+ }
412
+ /** This service's platform-assigned public origin — read from the stash
413
+ * run() populates and memoized per process. Throws if called before run()
414
+ * has stashed it (readOrigin's pinned message). */
415
+ origin() {
416
+ this.#origin ??= readOrigin();
417
+ return this.#origin;
418
+ }
419
+ };
420
+ const compute = (def) => {
421
+ const userParams = def.params ?? blindCast({});
422
+ for (const reserved of Object.keys(reservedParams)) {
423
+ if (reserved in def.deps) throw new Error(`compute(): dependency "${reserved}" collides with the reserved service param of the same name — rename the dependency.`);
424
+ if (reserved in userParams) throw new Error(`compute(): param "${reserved}" collides with the reserved service param of the same name — rename the param.`);
425
+ }
426
+ for (const name of Object.keys(userParams)) if (name.toUpperCase() === "ORIGIN") throw new Error(`compute(): param "${name}" collides with the framework-written origin row — rename the param.`);
427
+ for (const name of Object.keys(def.secrets ?? {})) if (name.toUpperCase() === "ORIGIN") throw new Error(`compute(): secret "${name}" collides with the framework-written origin row — rename the secret.`);
428
+ const params = blindCast({
429
+ ...userParams,
430
+ ...reservedParams
431
+ });
432
+ const instance = new ComputeService(service({
433
+ name: def.name,
434
+ extension: "@prisma/composer-prisma-cloud",
435
+ type: "compute",
436
+ inputs: def.deps,
437
+ params,
438
+ ...def.secrets !== void 0 ? { secrets: def.secrets } : {},
439
+ build: def.build,
440
+ ...def.expose !== void 0 ? { expose: def.expose } : {}
441
+ }));
442
+ Object.freeze(instance);
443
+ return instance;
444
+ };
445
+ /**
446
+ * The contract a Postgres provides — and the contract its consumers require.
447
+ * `satisfies` compares KIND, not identity: an extension module can be duplicated
448
+ * across a workspace (same rationale as the Symbol.for node brand), and every
449
+ * duplicate's contract must still satisfy. `__cmp` is the connection config a
450
+ * postgres offers; core never inspects it.
451
+ */
452
+ const postgresContract = Object.freeze({
453
+ kind: "postgres",
454
+ __cmp: { url: "" },
455
+ satisfies: (required) => required.kind === "postgres"
456
+ });
457
+ function postgres(opts) {
458
+ if (opts?.name !== void 0) return resource({
459
+ name: opts.name,
460
+ extension: "@prisma/composer-prisma-cloud",
461
+ provides: postgresContract
462
+ });
463
+ return dependency({
464
+ type: "postgres",
465
+ connection: {
466
+ params: { url: string() },
467
+ hydrate: (v) => v
468
+ },
469
+ required: postgresContract
470
+ });
471
+ }
472
+ /**
473
+ * The contract the `s3-credentials` resource provides — a minted SigV4 key
474
+ * pair. `satisfies` compares KIND only (mirrors `postgresContract`); `__cmp` is
475
+ * the config the resource offers, which core never inspects.
476
+ */
477
+ const credentialsContract = Object.freeze({
478
+ kind: "credentials",
479
+ __cmp: {
480
+ accessKeyId: "",
481
+ secretAccessKey: ""
482
+ },
483
+ satisfies: (required) => required.kind === "credentials"
484
+ });
485
+ function s3Credentials(opts) {
486
+ if (opts?.name !== void 0) return resource({
487
+ name: opts.name,
488
+ extension: "@prisma/composer-prisma-cloud",
489
+ provides: credentialsContract
490
+ });
491
+ return dependency({
492
+ type: "credentials",
493
+ connection: {
494
+ params: {
495
+ accessKeyId: string(),
496
+ secretAccessKey: string()
497
+ },
498
+ hydrate: (v) => v
499
+ },
500
+ required: credentialsContract
501
+ });
502
+ }
503
+ /**
504
+ * The storage service authoring factory — a `compute` service routed to the
505
+ * `s3-store` lowering instead of `compute`'s. It is exactly `compute`'s
506
+ * runnable (run/load/config, deps, params, build, expose) with the routing
507
+ * `type` overridden to `'s3-store'`: nothing at runtime keys off `type` (the
508
+ * serializer keys off the deployment address and each param's owner/name, and
509
+ * `load`/`config` off deps/params), so only the deploy-time descriptor lookup
510
+ * sees the override and routes to the extended-output lowering (§ 5). The
511
+ * return type is compute's exactly (including the reserved `port` param). The
512
+ * storage module (D4b) calls this with its `db`/`credentials` deps, a `bucket`
513
+ * param, and `expose: { store: s3Contract }`.
514
+ *
515
+ * `compute()`'s result is a `ComputeService` instance — its run/load/config/
516
+ * secrets/origin methods live on the class prototype, not as the instance's
517
+ * own properties, so a plain object spread (`{ ...node }`) would silently
518
+ * drop them. Building a fresh `ComputeService` from the same data fields
519
+ * (which `{ ...node }` DOES copy — they're the node's own enumerable
520
+ * properties) with `type` overridden keeps every method intact.
521
+ */
522
+ function s3StoreService(def) {
523
+ const instance = new ComputeService({
524
+ ...compute(def),
525
+ type: "s3-store"
526
+ });
527
+ Object.freeze(instance);
528
+ return instance;
529
+ }
530
+ //#endregion
531
+ //#region ../../1-prisma-cloud/2-shared-modules/storage/dist/storage-service-DSaZsAC4.mjs
532
+ const s3Contract = Object.freeze({
533
+ kind: "s3",
534
+ __cmp: {
535
+ url: "",
536
+ bucket: "",
537
+ accessKeyId: "",
538
+ secretAccessKey: ""
539
+ },
540
+ satisfies: (required) => required.kind === "s3"
541
+ });
542
+ /**
543
+ * A consumer's dependency on an S3-compatible store. No `region` in the
544
+ * binding — the server accepts whatever region string the client signed.
545
+ */
546
+ function s3() {
547
+ return dependency({
548
+ type: "s3",
549
+ connection: {
550
+ params: {
551
+ url: string(),
552
+ bucket: string(),
553
+ accessKeyId: string(),
554
+ secretAccessKey: string()
555
+ },
556
+ hydrate: (v) => v
557
+ },
558
+ required: s3Contract
559
+ });
560
+ }
561
+ /**
562
+ * The storage service node (like cron's `scheduler.ts` + `scheduler-service.ts`
563
+ * combined): `storageService` builds the `s3-store` service — a Postgres `db`
564
+ * dependency, a minted `credentials` dependency, a `bucket` param, and the
565
+ * `store` port exposing `s3Contract`. The deploy bootstrap runs the
566
+ * default-exported bare node (`main.run(address, boot)`); the real bucket comes
567
+ * from serialized config at runtime, so the default's `bucket` is only a
568
+ * placeholder — exactly like `scheduler-service.ts` default-exports
569
+ * `cronScheduler({ jobs: [] })`.
570
+ */
571
+ function storageService(opts) {
572
+ return s3StoreService({
573
+ name: "storage",
574
+ deps: {
575
+ db: postgres(),
576
+ credentials: s3Credentials()
577
+ },
578
+ params: { bucket: string({ default: opts.bucket }) },
579
+ build: node({
580
+ module: new URL("./storage-service.mjs", import.meta.url).href,
581
+ entry: "./storage-entrypoint.mjs"
582
+ }),
583
+ expose: { store: s3Contract }
584
+ });
585
+ }
586
+ storageService({ bucket: "storage" });
587
+ var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
588
+ var require_reusify = /* @__PURE__ */ __commonJSMin(((exports, module) => {
589
+ function reusify(Constructor) {
590
+ var head = new Constructor();
591
+ var tail = head;
592
+ function get() {
593
+ var current = head;
594
+ if (current.next) head = current.next;
595
+ else {
596
+ head = new Constructor();
597
+ tail = head;
598
+ }
599
+ current.next = null;
600
+ return current;
601
+ }
602
+ function release(obj) {
603
+ tail.next = obj;
604
+ tail = obj;
605
+ }
606
+ return {
607
+ get,
608
+ release
609
+ };
610
+ }
611
+ module.exports = reusify;
612
+ }));
613
+ (/* @__PURE__ */ __commonJSMin(((exports, module) => {
614
+ var reusify = require_reusify();
615
+ function fastqueue(context, worker, _concurrency) {
616
+ if (typeof context === "function") {
617
+ _concurrency = worker;
618
+ worker = context;
619
+ context = null;
620
+ }
621
+ if (!(_concurrency >= 1)) throw new Error("fastqueue concurrency must be equal to or greater than 1");
622
+ var cache = reusify(Task);
623
+ var queueHead = null;
624
+ var queueTail = null;
625
+ var _running = 0;
626
+ var errorHandler = null;
627
+ var self = {
628
+ push,
629
+ drain: noop,
630
+ saturated: noop,
631
+ pause,
632
+ paused: false,
633
+ get concurrency() {
634
+ return _concurrency;
635
+ },
636
+ set concurrency(value) {
637
+ if (!(value >= 1)) throw new Error("fastqueue concurrency must be equal to or greater than 1");
638
+ _concurrency = value;
639
+ if (self.paused) return;
640
+ for (; queueHead && _running < _concurrency;) {
641
+ _running++;
642
+ release();
643
+ }
644
+ },
645
+ running,
646
+ resume,
647
+ idle,
648
+ length,
649
+ getQueue,
650
+ unshift,
651
+ empty: noop,
652
+ kill,
653
+ killAndDrain,
654
+ error,
655
+ abort
656
+ };
657
+ return self;
658
+ function running() {
659
+ return _running;
660
+ }
661
+ function pause() {
662
+ self.paused = true;
663
+ }
664
+ function length() {
665
+ var current = queueHead;
666
+ var counter = 0;
667
+ while (current) {
668
+ current = current.next;
669
+ counter++;
670
+ }
671
+ return counter;
672
+ }
673
+ function getQueue() {
674
+ var current = queueHead;
675
+ var tasks = [];
676
+ while (current) {
677
+ tasks.push(current.value);
678
+ current = current.next;
679
+ }
680
+ return tasks;
681
+ }
682
+ function resume() {
683
+ if (!self.paused) return;
684
+ self.paused = false;
685
+ if (queueHead === null) {
686
+ _running++;
687
+ release();
688
+ return;
689
+ }
690
+ for (; queueHead && _running < _concurrency;) {
691
+ _running++;
692
+ release();
693
+ }
694
+ }
695
+ function idle() {
696
+ return _running === 0 && self.length() === 0;
697
+ }
698
+ function push(value, done) {
699
+ var current = cache.get();
700
+ current.context = context;
701
+ current.release = release;
702
+ current.value = value;
703
+ current.callback = done || noop;
704
+ current.errorHandler = errorHandler;
705
+ if (_running >= _concurrency || self.paused) if (queueTail) {
706
+ queueTail.next = current;
707
+ queueTail = current;
708
+ } else {
709
+ queueHead = current;
710
+ queueTail = current;
711
+ self.saturated();
712
+ }
713
+ else {
714
+ _running++;
715
+ worker.call(context, current.value, current.worked);
716
+ }
717
+ }
718
+ function unshift(value, done) {
719
+ var current = cache.get();
720
+ current.context = context;
721
+ current.release = release;
722
+ current.value = value;
723
+ current.callback = done || noop;
724
+ current.errorHandler = errorHandler;
725
+ if (_running >= _concurrency || self.paused) if (queueHead) {
726
+ current.next = queueHead;
727
+ queueHead = current;
728
+ } else {
729
+ queueHead = current;
730
+ queueTail = current;
731
+ self.saturated();
732
+ }
733
+ else {
734
+ _running++;
735
+ worker.call(context, current.value, current.worked);
736
+ }
737
+ }
738
+ function release(holder) {
739
+ if (holder) cache.release(holder);
740
+ var next = queueHead;
741
+ if (next && _running <= _concurrency) if (!self.paused) {
742
+ if (queueTail === queueHead) queueTail = null;
743
+ queueHead = next.next;
744
+ next.next = null;
745
+ worker.call(context, next.value, next.worked);
746
+ if (queueTail === null) self.empty();
747
+ } else _running--;
748
+ else if (--_running === 0) self.drain();
749
+ }
750
+ function kill() {
751
+ queueHead = null;
752
+ queueTail = null;
753
+ self.drain = noop;
754
+ }
755
+ function killAndDrain() {
756
+ queueHead = null;
757
+ queueTail = null;
758
+ self.drain();
759
+ self.drain = noop;
760
+ }
761
+ function abort() {
762
+ var current = queueHead;
763
+ queueHead = null;
764
+ queueTail = null;
765
+ while (current) {
766
+ var next = current.next;
767
+ var callback = current.callback;
768
+ var errorHandler = current.errorHandler;
769
+ var val = current.value;
770
+ var context = current.context;
771
+ current.value = null;
772
+ current.callback = noop;
773
+ current.errorHandler = null;
774
+ if (errorHandler) errorHandler(/* @__PURE__ */ new Error("abort"), val);
775
+ callback.call(context, /* @__PURE__ */ new Error("abort"));
776
+ current.release(current);
777
+ current = next;
778
+ }
779
+ self.drain = noop;
780
+ }
781
+ function error(handler) {
782
+ errorHandler = handler;
783
+ }
784
+ }
785
+ function noop() {}
786
+ function Task() {
787
+ this.value = null;
788
+ this.callback = noop;
789
+ this.next = null;
790
+ this.release = noop;
791
+ this.context = null;
792
+ this.errorHandler = null;
793
+ var self = this;
794
+ this.worked = function worked(err, result) {
795
+ var callback = self.callback;
796
+ var errorHandler = self.errorHandler;
797
+ var val = self.value;
798
+ self.value = null;
799
+ self.callback = noop;
800
+ if (self.errorHandler) errorHandler(err, val);
801
+ callback.call(self.context, err, result);
802
+ self.release(self);
803
+ };
804
+ }
805
+ function queueAsPromised(context, worker, _concurrency) {
806
+ if (typeof context === "function") {
807
+ _concurrency = worker;
808
+ worker = context;
809
+ context = null;
810
+ }
811
+ function asyncWrapper(arg, cb) {
812
+ worker.call(this, arg).then(function(res) {
813
+ cb(null, res);
814
+ }, cb);
815
+ }
816
+ var queue = fastqueue(context, asyncWrapper, _concurrency);
817
+ var pushCb = queue.push;
818
+ var unshiftCb = queue.unshift;
819
+ queue.push = push;
820
+ queue.unshift = unshift;
821
+ queue.drained = drained;
822
+ return queue;
823
+ function push(value) {
824
+ var p = new Promise(function(resolve, reject) {
825
+ pushCb(value, function(err, result) {
826
+ if (err) {
827
+ reject(err);
828
+ return;
829
+ }
830
+ resolve(result);
831
+ });
832
+ });
833
+ p.catch(noop);
834
+ return p;
835
+ }
836
+ function unshift(value) {
837
+ var p = new Promise(function(resolve, reject) {
838
+ unshiftCb(value, function(err, result) {
839
+ if (err) {
840
+ reject(err);
841
+ return;
842
+ }
843
+ resolve(result);
844
+ });
845
+ });
846
+ p.catch(noop);
847
+ return p;
848
+ }
849
+ function drained() {
850
+ return new Promise(function(resolve) {
851
+ process.nextTick(function() {
852
+ if (queue.idle()) resolve();
853
+ else {
854
+ var previousDrain = queue.drain;
855
+ queue.drain = function() {
856
+ if (typeof previousDrain === "function") previousDrain();
857
+ resolve();
858
+ queue.drain = previousDrain;
859
+ };
860
+ }
861
+ });
862
+ });
863
+ }
864
+ }
865
+ module.exports = fastqueue;
866
+ module.exports.promise = queueAsPromised;
867
+ })))();
868
+ /**
869
+ * Default backoff options.
870
+ */
871
+ const BackoffDefaults = {
872
+ initialDelay: 100,
873
+ maxDelay: 6e4,
874
+ multiplier: 1.3,
875
+ maxRetries: Infinity
876
+ };
877
+ ({ ...BackoffDefaults });
878
+ ({ ...BackoffDefaults });
879
+ /**
880
+ * The `streams()` module's own exposed port: a general streams provider,
881
+ * satisfied by kind alone — the `postgresContract` pattern. The module
882
+ * cannot know its eventual consumers' stream names (different consumers of
883
+ * one module each name their own), and the server genuinely serves any
884
+ * stream, so what a consumer requires of its provider is only "is a streams
885
+ * provider". That is exactly what this wide type says, and the empty def
886
+ * map is a legitimate `StreamDefs` value — a placeholder nobody reads, like
887
+ * postgres's `{ url: '' }`. Consumers keep their literal handle typing from
888
+ * `durableStreams(contract)`'s generic parameter, which is independent of
889
+ * the wiring-compatibility type here.
890
+ */
891
+ const streamsProviderContract = Object.freeze({
892
+ kind: "streams",
893
+ __cmp: {},
894
+ satisfies: (required) => required.kind === "streams"
895
+ });
896
+ string(), string({ provision: streamsApiKeyNeed() });
897
+ /**
898
+ * The streams service node: a plain `compute` service — the contract binding's
899
+ * `url` is a producer output compute's deploy already carries, and its
900
+ * `apiKey` is minted by the target's registered provisioner (ADR-0031), so
901
+ * nothing is left for a bespoke lowering to extend. It declares the `store`
902
+ * dependency (`s3()`, the storage module's port) and the `streams` expose; the
903
+ * bearer key reaches this service through the target's reserved provider
904
+ * param, not through a dependency. The deploy bootstrap runs the
905
+ * default-exported bare node; the real wiring arrives through serialized
906
+ * config at runtime — exactly like `storage-service.ts`.
907
+ */
908
+ function streamsService() {
909
+ return compute({
910
+ name: "streams",
911
+ deps: { store: s3() },
912
+ build: node({
913
+ module: new URL("./streams-service.mjs", import.meta.url).href,
914
+ entry: "./streams-entrypoint.mjs"
915
+ }),
916
+ expose: { streams: streamsProviderContract }
917
+ });
918
+ }
919
+ var streams_service_default = streamsService();
920
+ //#endregion
921
+ export { streams_service_default as default, streamsService };
922
+
923
+ //# sourceMappingURL=streams-service.mjs.map