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

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 (66) 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 +563 -289
  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/index.d.mts +152 -26
  14. package/dist/index.d.mts.map +1 -0
  15. package/dist/index.mjs +108 -43
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/{prisma-next-COrwlg3N.mjs → prisma-next-DlU01kXJ-2sP5mQb6.mjs} +3 -3
  18. package/dist/prisma-next-DlU01kXJ-2sP5mQb6.mjs.map +1 -0
  19. package/dist/prisma-next.d.mts +1 -2
  20. package/dist/prisma-next.d.mts.map +1 -0
  21. package/dist/prisma-next.mjs +1 -1
  22. package/dist/provisioned-edges-B_XS1Mz--NFJgcXK7.mjs +211 -0
  23. package/dist/provisioned-edges-B_XS1Mz--NFJgcXK7.mjs.map +1 -0
  24. package/dist/serializer-Cx5slrV4-xJfH6EWS.d.mts +36 -0
  25. package/dist/serializer-Cx5slrV4-xJfH6EWS.d.mts.map +1 -0
  26. package/dist/{serializer-C2CsA7xm-29Eg2Tjl.mjs → serializer-D8_84XWO-DA2B6YbX.mjs} +91 -7
  27. package/dist/serializer-D8_84XWO-DA2B6YbX.mjs.map +1 -0
  28. package/dist/storage/index.d.mts +56 -20
  29. package/dist/storage/index.d.mts.map +1 -0
  30. package/dist/storage/index.mjs +267 -44
  31. package/dist/storage/index.mjs.map +1 -1
  32. package/dist/storage/storage-entrypoint.mjs +7395 -53
  33. package/dist/storage/storage-entrypoint.mjs.map +1 -1
  34. package/dist/storage/storage-service.mjs +267 -44
  35. package/dist/storage/storage-service.mjs.map +1 -1
  36. package/dist/storage/testing.d.mts +7 -4
  37. package/dist/storage/testing.d.mts.map +1 -0
  38. package/dist/storage/testing.mjs.map +1 -1
  39. package/dist/streams/index.d.mts +222 -0
  40. package/dist/streams/index.d.mts.map +1 -0
  41. package/dist/streams/index.mjs +4170 -0
  42. package/dist/streams/index.mjs.map +1 -0
  43. package/dist/streams/streams-entrypoint.mjs +48207 -0
  44. package/dist/streams/streams-entrypoint.mjs.map +1 -0
  45. package/dist/streams/streams-service.mjs +923 -0
  46. package/dist/streams/streams-service.mjs.map +1 -0
  47. package/dist/streams/testing.d.mts +33 -0
  48. package/dist/streams/testing.d.mts.map +1 -0
  49. package/dist/streams/testing.mjs +31335 -0
  50. package/dist/streams/testing.mjs.map +1 -0
  51. package/dist/testing.d.mts +1 -2
  52. package/dist/testing.d.mts.map +1 -0
  53. package/dist/testing.mjs +1 -1
  54. package/dist/testing.mjs.map +1 -1
  55. package/package.json +29 -23
  56. package/src/exports/control.ts +1 -0
  57. package/src/exports/cron.ts +1 -0
  58. package/src/exports/index.ts +1 -0
  59. package/src/exports/prisma-next.ts +1 -0
  60. package/src/exports/storage-testing.ts +1 -0
  61. package/src/exports/storage.ts +1 -0
  62. package/src/exports/streams-testing.ts +1 -0
  63. package/src/exports/streams.ts +1 -0
  64. package/src/exports/testing.ts +1 -0
  65. package/dist/prisma-next-COrwlg3N.mjs.map +0 -1
  66. package/dist/serializer-C2CsA7xm-29Eg2Tjl.mjs.map +0 -1
@@ -42,6 +42,15 @@ function blindCast(input) {
42
42
  * data objects. A node's `extension` + `type` form its deploy-time registry key (ADR-0017).
43
43
  */
44
44
  const NODE = Symbol.for("prisma:node");
45
+ const PROVISION_NEED = blindCast(Symbol.for("prisma:provision-need"));
46
+ /** Builds an opaque provisioning need — the declaring package's own brand plus whatever payload its provisioner reads back. */
47
+ function provisionNeed(brand, payload) {
48
+ return blindCast(Object.freeze({
49
+ [PROVISION_NEED]: true,
50
+ brand,
51
+ payload
52
+ }));
53
+ }
45
54
  function requireType(type, factory) {
46
55
  if (typeof type !== "string" || type.length === 0) throw new Error(`${factory}() requires a non-empty node type.`);
47
56
  }
@@ -87,7 +96,7 @@ function service$1(def) {
87
96
  requireNoUnderscoreNames(Object.keys(def.inputs), "input", "service");
88
97
  requireNoUnderscoreNames(Object.keys(def.params), "param", "service");
89
98
  requireNoUnderscoreNames(Object.keys(def.secrets ?? {}), "secret", "service");
90
- for (const slot of Object.keys(def.secrets ?? {})) if (Object.hasOwn(def.params, slot)) throw new Error(`service() secret slot "${slot}" collides with a param of the same name — a secret slot and a service param derive the same config key (COMPOSE_<addr>_${slot.toUpperCase()}); rename one.`);
99
+ for (const slot of Object.keys(def.secrets ?? {})) if (Object.hasOwn(def.params, slot)) throw new Error(`service() secret slot "${slot}" collides with a param of the same name — a secret slot and a service param derive the same config key (COMPOSER_<addr>_${slot.toUpperCase()}); rename one.`);
91
100
  return Object.freeze({
92
101
  [NODE]: true,
93
102
  kind: "service",
@@ -171,7 +180,8 @@ function withFacets(schema, opts) {
171
180
  return {
172
181
  schema,
173
182
  ...opts.optional !== void 0 ? { optional: opts.optional } : {},
174
- ...opts.default !== void 0 ? { default: opts.default } : {}
183
+ ...opts.default !== void 0 ? { default: opts.default } : {},
184
+ ...opts.provision !== void 0 ? { provision: opts.provision } : {}
175
185
  };
176
186
  }
177
187
  /** A string-valued param. */
@@ -224,294 +234,9 @@ const nodeBuild = (opts) => ({
224
234
  extension: "@prisma/composer/node",
225
235
  type: "node",
226
236
  module: opts.module,
227
- entry: opts.entry
228
- });
229
- /**
230
- * Walks a node's own params, then each dependency input's connection params —
231
- * the same enumeration order `configOf` uses, but carrying the raw
232
- * `ConfigParam` (with its `serialize`/`deserialize`) instead of a pure-data
233
- * projection.
234
- */
235
- function paramEntries(node) {
236
- const entries = [];
237
- for (const [input, value] of Object.entries(node.inputs)) {
238
- if (typeof value !== "object" || value === null) continue;
239
- const params = blindCast(value).connection.params;
240
- for (const [name, param] of Object.entries(params)) entries.push({
241
- owner: { input },
242
- name,
243
- param
244
- });
245
- }
246
- for (const [name, param] of Object.entries(node.params)) entries.push({
247
- owner: "service",
248
- name,
249
- param
250
- });
251
- return entries;
252
- }
253
- const configKey = (address, d) => {
254
- const segments = address.split(".").filter((s) => s.length > 0);
255
- const owner = d.owner === "service" ? [] : [d.owner.input];
256
- return [
257
- "COMPOSE",
258
- ...segments,
259
- ...owner,
260
- d.name
261
- ].join("_").toUpperCase();
262
- };
263
- /**
264
- * Typed value → its stored string. Service-own literals are JSON-encoded; a
265
- * dependency-input value is a provisioning ref at deploy (and a resolved
266
- * string at boot) and passes through untouched — LANDMINE: JSON-encoding it
267
- * would break the ordering edge Alchemy resolves through it.
268
- */
269
- function encode(owner, value) {
270
- return owner === "service" ? JSON.stringify(value) : blindCast(value);
271
- }
272
- /** Reverses `encode`: JSON-parse a service-own value, take a dependency-input value raw. */
273
- function decode(owner, raw) {
274
- return owner === "service" ? JSON.parse(raw) : raw;
275
- }
276
- function coerce(raw, d, key) {
277
- if (!(raw !== void 0 && raw !== "")) {
278
- if (d.param.default !== void 0) return d.param.default;
279
- if (d.param.optional === true) return void 0;
280
- throw new Error(`missing required config param "${d.name}" (env ${key})`);
281
- }
282
- try {
283
- return standardValidateSync(d.param.schema, decode(d.owner, raw));
284
- } catch (cause) {
285
- const message = cause instanceof Error ? cause.message : String(cause);
286
- throw new Error(`invalid value for config param "${d.name}" (env ${key}): ${message}`);
287
- }
288
- }
289
- /**
290
- * Boot: read each declared param from env by its key, reverse the param's own
291
- * serialization (missing/invalid fails loudly), assemble the typed Config.
292
- * Secrets ride a separate channel (deserializeSecrets), not this one.
293
- */
294
- const deserialize = (node, address) => {
295
- const service = {};
296
- const inputs = {};
297
- for (const d of paramEntries(node)) {
298
- const key = configKey(address, d);
299
- const value = coerce(process.env[key], d, key);
300
- if (d.owner === "service") service[d.name] = value;
301
- else {
302
- let bucket = inputs[d.owner.input];
303
- if (bucket === void 0) {
304
- bucket = {};
305
- inputs[d.owner.input] = bucket;
306
- }
307
- bucket[d.name] = value;
308
- }
309
- }
310
- return {
311
- service,
312
- inputs
313
- };
314
- };
315
- /**
316
- * run()'s setup step: write the resolved config to the environment under
317
- * address-free keys (configKey("", d) + each serialize suffix), which load()
318
- * reads back with no address. Uses env, not a module variable, because a
319
- * framework may fork worker processes that inherit env but not memory.
320
- * Writes only these keys; nothing else is touched.
321
- */
322
- const stash = (node, config) => {
323
- for (const d of paramEntries(node)) {
324
- const value = d.owner === "service" ? config.service[d.name] : config.inputs[d.owner.input]?.[d.name];
325
- if (value === void 0) continue;
326
- process.env[configKey("", d)] = encode(d.owner, value);
327
- }
328
- };
329
- /** The pointer-row key for a secret slot: COMPOSE_<addr>_<slot> (secrets are service-level). */
330
- const secretKey = (address, slot) => configKey(address, {
331
- owner: "service",
332
- name: slot
333
- });
334
- /**
335
- * Boot: resolve every secret slot to its value by double-lookup — read the
336
- * pointer key (the platform NAME), then read that platform var. A missing
337
- * pointer or a missing/empty platform value is a loud failure naming both keys.
338
- * Returns a plain Record for core's `hydrateSecrets` to box.
339
- */
340
- const deserializeSecrets = (node, address) => {
341
- const values = {};
342
- for (const slot of Object.keys(node.secretSlots)) {
343
- const key = secretKey(address, slot);
344
- const name = process.env[key];
345
- if (name === void 0 || name === "") throw new Error(`missing secret pointer for slot "${slot}" (env ${key}) — the deploy did not write it.`);
346
- const value = process.env[name];
347
- if (value === void 0 || value === "") throw new Error(`secret "${slot}" is not provisioned (env ${key} → ${name}): the platform var "${name}" is unset or empty.`);
348
- values[slot] = value;
349
- }
350
- return values;
351
- };
352
- /**
353
- * run()'s setup step for secrets: re-emit each slot's pointer NAME under its
354
- * address-free key, so the address-free `deserializeSecrets` double-looks-up
355
- * identically. Never the value — the value stays only in the platform var.
356
- */
357
- const stashSecrets = (node, address) => {
358
- for (const slot of Object.keys(node.secretSlots)) {
359
- const name = process.env[secretKey(address, slot)];
360
- if (name === void 0) continue;
361
- process.env[secretKey("", slot)] = name;
362
- }
363
- };
364
- /** Synchronous Standard Schema validation — see the matching note in core's `config.ts`. */
365
- function standardValidateSync(schema, value) {
366
- const result = schema["~standard"].validate(value);
367
- if (result instanceof Promise) throw new Error("config param schema validation must be synchronous — async Standard Schema validators are not supported for config params");
368
- if (result.issues !== void 0) throw new Error(`config param validation failed: ${result.issues.map((issue) => issue.message).join("; ")}`);
369
- return result.value;
370
- }
371
- const reservedParams = { port: number$1({ default: 3e3 }) };
372
- /**
373
- * A Prisma Compute service — declarations only (deps + params + build + the
374
- * ports it exposes), no descriptor. `params` merges with the reserved
375
- * `ReservedParams` (`port`); a user param whose name collides with a reserved
376
- * one fails at authoring, the same way a colliding dependency name does.
377
- * Returns the extension's runnable/loadable node:
378
- * · run(address, boot) — the process controller: deserialize the platform
379
- * environment (keyed off `address`, the extension's ONE env read) into a
380
- * typed Config, re-emit it under address-free process-local stash keys,
381
- * then call boot() to start the app's entry.
382
- * · load() / config() — called from inside the app's entry: read the stash;
383
- * load() hydrates + memoizes the deps, config() returns the typed params.
384
- * Separate accessors so a dep and a param never share a namespace (ADR-0021).
385
- *
386
- * `service()`'s underlying node carries `extension: '@prisma/composer-prisma-cloud'` —
387
- * the control-plane registry key `prisma-composer deploy` resolves through the
388
- * app's `prisma-composer.config.ts` (ADR-0017). This module loads nothing at
389
- * deploy time; nodes are pure data.
390
- */
391
- const compute = (def) => {
392
- const userParams = def.params ?? blindCast({});
393
- for (const reserved of Object.keys(reservedParams)) {
394
- if (reserved in def.deps) throw new Error(`compute(): dependency "${reserved}" collides with the reserved service param of the same name — rename the dependency.`);
395
- if (reserved in userParams) throw new Error(`compute(): param "${reserved}" collides with the reserved service param of the same name — rename the param.`);
396
- }
397
- const params = blindCast({
398
- ...userParams,
399
- ...reservedParams
400
- });
401
- const node = service$1({
402
- name: def.name,
403
- extension: "@prisma/composer-prisma-cloud",
404
- type: "compute",
405
- inputs: def.deps,
406
- params,
407
- ...def.secrets !== void 0 ? { secrets: def.secrets } : {},
408
- build: def.build,
409
- ...def.expose !== void 0 ? { expose: def.expose } : {}
410
- });
411
- let resolved;
412
- let loadedDeps;
413
- let loadedParams;
414
- let loadedSecrets;
415
- function processConfig() {
416
- if (resolved === void 0) resolved = deserialize(node, "");
417
- return resolved;
418
- }
419
- const runnable = {
420
- ...node,
421
- async run(address, boot) {
422
- const config = deserialize(node, address);
423
- stash(node, config);
424
- stashSecrets(node, address);
425
- const port = config.service["port"];
426
- if (typeof port === "number") process.env["PORT"] = String(port);
427
- return boot();
428
- },
429
- load() {
430
- if (loadedDeps === void 0) loadedDeps = blindCast(hydrateSync(node, processConfig()));
431
- return loadedDeps;
432
- },
433
- config() {
434
- if (loadedParams === void 0) loadedParams = blindCast(processConfig().service);
435
- return loadedParams;
436
- },
437
- secrets() {
438
- if (loadedSecrets === void 0) loadedSecrets = blindCast(hydrateSecrets(node, deserializeSecrets(node, "")));
439
- return loadedSecrets;
440
- }
441
- };
442
- return Object.freeze(blindCast(runnable));
443
- };
444
- Object.freeze({
445
- kind: "postgres",
446
- __cmp: { url: "" },
447
- satisfies: (required) => required.kind === "postgres"
448
- });
449
- Object.freeze({
450
- kind: "credentials",
451
- __cmp: {
452
- accessKeyId: "",
453
- secretAccessKey: ""
454
- },
455
- satisfies: (required) => required.kind === "credentials"
237
+ entry: opts.entry,
238
+ ...opts.dir === void 0 ? {} : { dir: opts.dir }
456
239
  });
457
- async function standardValidate(schema, value) {
458
- const result = await schema["~standard"].validate(value);
459
- if (result.issues !== void 0) throw new Error(`Schema validation failed: ${result.issues.map((issue) => issue.message).join("; ")}`);
460
- return result.value;
461
- }
462
- /** `<base>/rpc/<method>`, preserving a base URL's own path (e.g. a mount point). */
463
- function methodUrl(base, method) {
464
- const normalizedBase = base.endsWith("/") ? base : `${base}/`;
465
- return new URL(`rpc/${method}`, normalizedBase).toString();
466
- }
467
- /** The server's `{ error }` body, if the response has one — undefined otherwise. */
468
- async function errorDetail(res) {
469
- try {
470
- const body = await res.json();
471
- return typeof body === "object" && body !== null && "error" in body ? String(body.error) : void 0;
472
- } catch {
473
- return;
474
- }
475
- }
476
- function makeClient(contract, url, opts) {
477
- const send = opts?.fetch ?? fetch;
478
- const client = {};
479
- for (const [method, schemas] of Object.entries(blindCast(contract.__cmp))) client[method] = async (input) => {
480
- const res = await send(new Request(methodUrl(url, method), {
481
- method: "POST",
482
- headers: { "content-type": "application/json" },
483
- body: JSON.stringify(input)
484
- }));
485
- if (!res.ok) {
486
- const detail = await errorDetail(res);
487
- throw new Error(`RPC call "${method}" failed: ${res.status} ${res.statusText}` + (detail !== void 0 ? ` — ${detail}` : ""));
488
- }
489
- return standardValidate(schemas.output, await res.json());
490
- };
491
- return blindCast(client);
492
- }
493
- function contract(fns) {
494
- const value = {
495
- kind: "rpc",
496
- __cmp: fns,
497
- satisfies: (required) => value === required
498
- };
499
- return Object.freeze(value);
500
- }
501
- function rpc(arg) {
502
- if (!isRpcContract(arg)) return arg;
503
- return dependency({
504
- type: "rpc",
505
- connection: {
506
- params: { url: string$1() },
507
- hydrate: ({ url }) => makeClient(arg, url)
508
- },
509
- required: arg
510
- });
511
- }
512
- function isRpcContract(value) {
513
- return typeof value === "object" && value !== null && "kind" in value && value.kind === "rpc" && "__cmp" in value && "satisfies" in value;
514
- }
515
240
  const liftArray = (data) => Array.isArray(data) ? data : [data];
516
241
  /**
517
242
  * Splits an array into two arrays based on the result of a predicate
@@ -7631,6 +7356,555 @@ ark.schema;
7631
7356
  ark.define;
7632
7357
  ark.declare;
7633
7358
  /**
7359
+ * Walks a node's own params, then each dependency input's connection params —
7360
+ * the same enumeration order `configOf` uses, but carrying the raw
7361
+ * `ConfigParam` (with its `serialize`/`deserialize`) instead of a pure-data
7362
+ * projection.
7363
+ */
7364
+ function paramEntries(node) {
7365
+ const entries = [];
7366
+ for (const [input, value] of Object.entries(node.inputs)) {
7367
+ if (typeof value !== "object" || value === null) continue;
7368
+ const params = blindCast(value).connection.params;
7369
+ for (const [name, param] of Object.entries(params)) entries.push({
7370
+ owner: { input },
7371
+ name,
7372
+ param
7373
+ });
7374
+ }
7375
+ for (const [name, param] of Object.entries(node.params)) entries.push({
7376
+ owner: "service",
7377
+ name,
7378
+ param
7379
+ });
7380
+ return entries;
7381
+ }
7382
+ const configKey = (address, d) => {
7383
+ const segments = address.split(".").filter((s) => s.length > 0);
7384
+ const owner = d.owner === "service" ? [] : [d.owner.input];
7385
+ return [
7386
+ "COMPOSER",
7387
+ ...segments,
7388
+ ...owner,
7389
+ d.name
7390
+ ].join("_").toUpperCase();
7391
+ };
7392
+ /**
7393
+ * Typed value → its stored string. Service-own literals are JSON-encoded; a
7394
+ * dependency-input value is a provisioning ref at deploy (and a resolved
7395
+ * string at boot) and passes through untouched — LANDMINE: JSON-encoding it
7396
+ * would break the ordering edge Alchemy resolves through it.
7397
+ */
7398
+ function encode(owner, value) {
7399
+ return owner === "service" ? JSON.stringify(value) : blindCast(value);
7400
+ }
7401
+ /** Reverses `encode`: JSON-parse a service-own value, take a dependency-input value raw. */
7402
+ function decode(owner, raw) {
7403
+ return owner === "service" ? JSON.parse(raw) : raw;
7404
+ }
7405
+ const PARAM_POINTER_PREFIX = "@composer-param-pointer:";
7406
+ /** True iff `raw` is a param pointer row (as opposed to a JSON-encoded literal). */
7407
+ const isParamPointerRow = (raw) => raw.startsWith(PARAM_POINTER_PREFIX);
7408
+ /** Reverses `encodeParamPointer`: the platform var NAME a pointer row points to. */
7409
+ const decodeParamPointer = (raw) => raw.slice(24);
7410
+ function coerce(raw, d, key) {
7411
+ if (!(raw !== void 0 && raw !== "")) {
7412
+ if (d.param.default !== void 0) return d.param.default;
7413
+ if (d.param.optional === true) return void 0;
7414
+ throw new Error(`missing required config param "${d.name}" (env ${key})`);
7415
+ }
7416
+ if (d.owner === "service" && isParamPointerRow(raw)) return coerceEnvSourcedParam(raw, d, key);
7417
+ try {
7418
+ return standardValidateSync(d.param.schema, decode(d.owner, raw));
7419
+ } catch (cause) {
7420
+ const message = cause instanceof Error ? cause.message : String(cause);
7421
+ throw new Error(`invalid value for config param "${d.name}" (env ${key}): ${message}`);
7422
+ }
7423
+ }
7424
+ /**
7425
+ * Boot resolution for an env-sourced param: double-lookup (pointer → platform
7426
+ * var), then the param's own schema on the raw string — no JSON decode, and
7427
+ * no redaction (it's config, not a secret). An UNSET platform var is a loud
7428
+ * boot failure naming both the param and the platform var; an EMPTY string is
7429
+ * not special-cased here — it reaches the schema like any other value, so it
7430
+ * passes iff the schema accepts it (deliberately unlike a literal param's own
7431
+ * ""-means-absent rule, and unlike a secret's non-empty requirement).
7432
+ */
7433
+ function coerceEnvSourcedParam(raw, d, key) {
7434
+ const platformVar = decodeParamPointer(raw);
7435
+ const value = process.env[platformVar];
7436
+ 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.`);
7437
+ try {
7438
+ return standardValidateSync(d.param.schema, value);
7439
+ } catch (cause) {
7440
+ const message = cause instanceof Error ? cause.message : String(cause);
7441
+ throw new Error(`invalid value for env-sourced config param "${d.name}" (env ${key} → ${platformVar}): ${message}`);
7442
+ }
7443
+ }
7444
+ /**
7445
+ * Boot: read each declared param from env by its key, reverse the param's own
7446
+ * serialization (missing/invalid fails loudly), assemble the typed Config.
7447
+ * Secrets ride a separate channel (deserializeSecrets), not this one.
7448
+ */
7449
+ const deserialize = (node, address) => {
7450
+ const service = {};
7451
+ const inputs = {};
7452
+ for (const d of paramEntries(node)) {
7453
+ const key = configKey(address, d);
7454
+ const value = coerce(process.env[key], d, key);
7455
+ if (d.owner === "service") service[d.name] = value;
7456
+ else {
7457
+ let bucket = inputs[d.owner.input];
7458
+ if (bucket === void 0) {
7459
+ bucket = {};
7460
+ inputs[d.owner.input] = bucket;
7461
+ }
7462
+ bucket[d.name] = value;
7463
+ }
7464
+ }
7465
+ return {
7466
+ service,
7467
+ inputs
7468
+ };
7469
+ };
7470
+ /**
7471
+ * run()'s setup step: write the resolved config to the environment under
7472
+ * address-free keys (configKey("", d) + each serialize suffix), which load()
7473
+ * reads back with no address. Uses env, not a module variable, because a
7474
+ * framework may fork worker processes that inherit env but not memory.
7475
+ * Writes only these keys; nothing else is touched.
7476
+ */
7477
+ const stash = (node, config) => {
7478
+ for (const d of paramEntries(node)) {
7479
+ const value = d.owner === "service" ? config.service[d.name] : config.inputs[d.owner.input]?.[d.name];
7480
+ if (value === void 0) continue;
7481
+ process.env[configKey("", d)] = encode(d.owner, value);
7482
+ }
7483
+ };
7484
+ /** The pointer-row key for a secret slot: COMPOSER_<addr>_<slot> (secrets are service-level). */
7485
+ const secretKey = (address, slot) => configKey(address, {
7486
+ owner: "service",
7487
+ name: slot
7488
+ });
7489
+ /**
7490
+ * Boot: resolve every secret slot to its value by double-lookup — read the
7491
+ * pointer key (the platform NAME), then read that platform var. A missing
7492
+ * pointer or a missing/empty platform value is a loud failure naming both keys.
7493
+ * Returns a plain Record for core's `hydrateSecrets` to box.
7494
+ */
7495
+ const deserializeSecrets = (node, address) => {
7496
+ const values = {};
7497
+ for (const slot of Object.keys(node.secretSlots)) {
7498
+ const key = secretKey(address, slot);
7499
+ const name = process.env[key];
7500
+ if (name === void 0 || name === "") throw new Error(`missing secret pointer for slot "${slot}" (env ${key}) — the deploy did not write it.`);
7501
+ const value = process.env[name];
7502
+ if (value === void 0 || value === "") throw new Error(`secret "${slot}" is not provisioned (env ${key} → ${name}): the platform var "${name}" is unset or empty.`);
7503
+ values[slot] = value;
7504
+ }
7505
+ return values;
7506
+ };
7507
+ /**
7508
+ * run()'s setup step for secrets: re-emit each slot's pointer NAME under its
7509
+ * address-free key, so the address-free `deserializeSecrets` double-looks-up
7510
+ * identically. Never the value — the value stays only in the platform var.
7511
+ */
7512
+ const stashSecrets = (node, address) => {
7513
+ for (const slot of Object.keys(node.secretSlots)) {
7514
+ const name = process.env[secretKey(address, slot)];
7515
+ if (name === void 0) continue;
7516
+ process.env[secretKey("", slot)] = name;
7517
+ }
7518
+ };
7519
+ /**
7520
+ * Boot: for each reserved provider param, read its address-scoped row through
7521
+ * the same `coerce` a declared param uses (JSON-decode, schema-validate), and
7522
+ * re-emit it address-free — `stash`'s counterpart for this separate
7523
+ * declaration space. A param is declared optional here unconditionally: an
7524
+ * absent row means "never provisioned" (local dev, tests, a provider with no
7525
+ * registered value for this deploy), never a boot failure, so nothing is
7526
+ * stashed and the runtime reader that owns this slot falls back to its own
7527
+ * pass-through behavior.
7528
+ */
7529
+ function stashProviderParams(entries, address) {
7530
+ for (const entry of entries) {
7531
+ const d = {
7532
+ owner: "service",
7533
+ name: entry.name,
7534
+ param: {
7535
+ schema: entry.schema,
7536
+ optional: true
7537
+ }
7538
+ };
7539
+ const key = configKey(address, d);
7540
+ const value = coerce(process.env[key], d, key);
7541
+ if (value === void 0) continue;
7542
+ process.env[configKey("", d)] = encode("service", value);
7543
+ }
7544
+ }
7545
+ /** The framework-resolved origin row: COMPOSER_<addr>_ORIGIN. Written per
7546
+ * compute service at serialize — the service's own provisioned endpoint URL,
7547
+ * riding the reserved-provider-param machinery (`origin-key.ts`'s
7548
+ * `ORIGIN_PARAM`); never a declared param, never in config(). A harness with
7549
+ * no deploy behind it supplies it by setting `COMPOSER_ORIGIN` to the
7550
+ * JSON-encoded origin URL — exactly how the existing entrypoint tests supply
7551
+ * their other `COMPOSER_*` rows. */
7552
+ const ORIGIN_KEY_NAME = "ORIGIN";
7553
+ /**
7554
+ * Reads this service's origin back out of the address-free stash
7555
+ * `stashProviderParams` wrote for the ORIGIN entry. `COMPOSER_ORIGIN` unset is
7556
+ * a loud failure — a deployed environment always writes it, so an unset row
7557
+ * means either a local harness that hasn't supplied it or a boot() called
7558
+ * before run().
7559
+ */
7560
+ function readOrigin() {
7561
+ const d = {
7562
+ owner: "service",
7563
+ name: ORIGIN_KEY_NAME,
7564
+ param: {
7565
+ schema: type("string"),
7566
+ optional: true
7567
+ }
7568
+ };
7569
+ const key = configKey("", d);
7570
+ const value = coerce(process.env[key], d, key);
7571
+ 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).");
7572
+ return blindCast(value);
7573
+ }
7574
+ /** Synchronous Standard Schema validation — see the matching note in core's `config.ts`. */
7575
+ function standardValidateSync(schema, value) {
7576
+ const result = schema["~standard"].validate(value);
7577
+ if (result instanceof Promise) throw new Error("config param schema validation must be synchronous — async Standard Schema validators are not supported for config params");
7578
+ if (result.issues !== void 0) throw new Error(`config param validation failed: ${result.issues.map((issue) => issue.message).join("; ")}`);
7579
+ return result.value;
7580
+ }
7581
+ /** Bounded jittered backoff for retrying a dropped call. `maxRetries` is retries after the first attempt. */
7582
+ const RETRY = {
7583
+ initialDelayMs: 250,
7584
+ multiplier: 2,
7585
+ maxDelayMs: 5e3,
7586
+ maxRetries: 5
7587
+ };
7588
+ const IDEMPOTENCY_KEY_HEADER$1 = "Idempotency-Key";
7589
+ function sleep(ms) {
7590
+ return new Promise((resolve) => setTimeout(resolve, ms));
7591
+ }
7592
+ /** Whether a non-OK response is safe to retry: 429 or any 5xx, never another 4xx. */
7593
+ function isRetryableStatus(status) {
7594
+ return status === 429 || status >= 500;
7595
+ }
7596
+ /** The server's `{ error }` body, if the response has one — undefined otherwise. */
7597
+ async function errorDetail(res) {
7598
+ try {
7599
+ const body = await res.json();
7600
+ return typeof body === "object" && body !== null && "error" in body ? String(body.error) : void 0;
7601
+ } catch {
7602
+ return;
7603
+ }
7604
+ }
7605
+ /** `<base>/rpc/<method>`, preserving a base URL's own path (e.g. a mount point). */
7606
+ function methodUrl(base, method) {
7607
+ const normalizedBase = base.endsWith("/") ? base : `${base}/`;
7608
+ return new URL(`rpc/${method}`, normalizedBase).toString();
7609
+ }
7610
+ /**
7611
+ * Sends one call over `send`, retrying a thrown error, 429, or 5xx with
7612
+ * full-jitter backoff. `buildRequest` runs per attempt but carries the same
7613
+ * idempotency key each time — only the transport call repeats, not the key.
7614
+ */
7615
+ async function callWithRetry(send, buildRequest, method) {
7616
+ let delay = RETRY.initialDelayMs;
7617
+ let retries = 0;
7618
+ for (;;) {
7619
+ let res;
7620
+ try {
7621
+ res = await send(buildRequest());
7622
+ } catch (err) {
7623
+ if (retries >= RETRY.maxRetries) throw err;
7624
+ retries += 1;
7625
+ await sleep(Math.random() * delay);
7626
+ delay = Math.min(delay * RETRY.multiplier, RETRY.maxDelayMs);
7627
+ continue;
7628
+ }
7629
+ if (res.ok) return res.json();
7630
+ if (!isRetryableStatus(res.status) || retries >= RETRY.maxRetries) {
7631
+ const detail = await errorDetail(res);
7632
+ throw new Error(`RPC call "${method}" failed: ${res.status} ${res.statusText}` + (detail !== void 0 ? ` — ${detail}` : ""));
7633
+ }
7634
+ retries += 1;
7635
+ await sleep(Math.random() * delay);
7636
+ delay = Math.min(delay * RETRY.multiplier, RETRY.maxDelayMs);
7637
+ }
7638
+ }
7639
+ function makeClient(contract, url, opts) {
7640
+ const send = opts?.fetch ?? fetch;
7641
+ const baseHeaders = { "content-type": "application/json" };
7642
+ if (opts?.serviceKey !== void 0) baseHeaders["Authorization"] = `Bearer ${opts.serviceKey}`;
7643
+ const client = {};
7644
+ for (const method of Object.keys(contract.__cmp)) client[method] = async (input) => {
7645
+ const idempotencyKey = crypto.randomUUID();
7646
+ const body = JSON.stringify(input);
7647
+ return callWithRetry(send, () => new Request(methodUrl(url, method), {
7648
+ method: "POST",
7649
+ headers: {
7650
+ ...baseHeaders,
7651
+ [IDEMPOTENCY_KEY_HEADER$1]: idempotencyKey
7652
+ },
7653
+ body
7654
+ }), method);
7655
+ };
7656
+ return blindCast(client);
7657
+ }
7658
+ function contract(fns) {
7659
+ const value = {
7660
+ kind: "rpc",
7661
+ __cmp: fns,
7662
+ satisfies: (required) => value === required
7663
+ };
7664
+ return Object.freeze(value);
7665
+ }
7666
+ /** ADR-0031's need brand for RPC's per-binding service key — the target registers a provisioner under this. */
7667
+ const RPC_PEER_KEY = Symbol.for("prisma:rpc/per-binding-key");
7668
+ /** The provisioning need `rpc()`'s `serviceKey` param declares (ADR-0030): a shared, unguessable value the target mints per consumer edge. */
7669
+ const perBindingToken = () => provisionNeed(RPC_PEER_KEY);
7670
+ function rpc(arg) {
7671
+ if (!isRpcContract(arg)) return arg;
7672
+ return dependency({
7673
+ type: "rpc",
7674
+ connection: {
7675
+ params: {
7676
+ url: string$1(),
7677
+ serviceKey: string$1({
7678
+ optional: true,
7679
+ provision: perBindingToken()
7680
+ })
7681
+ },
7682
+ hydrate: ({ url, serviceKey }) => makeClient(arg, url, { serviceKey })
7683
+ },
7684
+ required: arg
7685
+ });
7686
+ }
7687
+ function isRpcContract(value) {
7688
+ return typeof value === "object" && value !== null && "kind" in value && value.kind === "rpc" && "__cmp" in value && "satisfies" in value;
7689
+ }
7690
+ /**
7691
+ * The service's own origin as a reserved provider param (ADR-0031): the ONE
7692
+ * brand and the ONE entry — shared by control.ts (which registers the
7693
+ * deploy-side value function that resolves the provisioned service's
7694
+ * `endpointDomain` — see its `selfOriginValue`) and compute.ts (which
7695
+ * validates and stashes the row at boot through the generic
7696
+ * `stashProviderParams` loop), so writer and reader cannot drift.
7697
+ *
7698
+ * Unlike the key-minting brands (`service-keys.ts`, `streams-keys.ts`) this
7699
+ * brand has no provisioner and no consumer edges: the value derives from the
7700
+ * service's OWN provisioned attributes, so control.ts registers it as a
7701
+ * service-derived provider param (`descriptors/shared.ts`'s
7702
+ * `ServiceProviderParam`) and the descriptor writes it for EVERY compute
7703
+ * service, exposing or not.
7704
+ *
7705
+ * This module is reachable from the RUNTIME/authoring side — it must never
7706
+ * import `@internal/lowering` or `effect`, or those tokens leak into a user
7707
+ * service's bundle (the deploy-side value function lives in control.ts, the
7708
+ * control-plane-only entry).
7709
+ */
7710
+ /** ADR-0031's brand for the service's own origin — control.ts registers the deploy-side value function under this. */
7711
+ const SELF_ORIGIN = Symbol.for("prisma:self-origin");
7712
+ /**
7713
+ * The reserved provider param for the origin row: the var name is `ORIGIN`,
7714
+ * derived through `configKey` at both ends (`configKey(address, …)` at
7715
+ * deploy, `configKey('', …)` — `COMPOSER_ORIGIN` — at boot, where
7716
+ * `readOrigin` reads it back). `brand` is `SELF_ORIGIN` — control.ts looks
7717
+ * its deploy-side value function up by this field.
7718
+ */
7719
+ const ORIGIN_PARAM = {
7720
+ name: ORIGIN_KEY_NAME,
7721
+ schema: type("string"),
7722
+ brand: SELF_ORIGIN
7723
+ };
7724
+ /**
7725
+ * RPC's reserved provider param (ADR-0030/ADR-0031): the declaration —
7726
+ * name + schema + brand — for the accepted-keys set a provider stores, shared
7727
+ * by `control.ts` (which registers the deploy-side `value(refs)` that mints
7728
+ * and aggregates it — see its `rpcAcceptedKeysValue`) and `compute.ts` (which
7729
+ * validates and stashes it at boot), so writer and reader cannot drift.
7730
+ * Finding the edges themselves is `provisioned-edges.ts`'s generic,
7731
+ * brand-blind scan — RPC is not special-cased anywhere in this target.
7732
+ *
7733
+ * This module is reachable from the RUNTIME/authoring side — it must never
7734
+ * import `@internal/lowering` or `effect`, or those tokens leak into a user
7735
+ * service's bundle (the deploy-side `value(refs)` lives in control.ts, the
7736
+ * control-plane-only entry).
7737
+ */
7738
+ /**
7739
+ * The reserved provider param for RPC's accepted-keys set: the var name is
7740
+ * `RPC_ACCEPTED_KEYS`, derived through `configKey` at both ends
7741
+ * (`configKey(address, …)` at deploy, `configKey('', …)` at boot — the
7742
+ * address-free form is `@internal/service-rpc`'s `RPC_ACCEPTED_KEYS_ENV`). `brand` is
7743
+ * `RPC_PEER_KEY`, the same brand `perBindingToken()`'s need carries — control.ts
7744
+ * looks its `value(refs)` up by this field.
7745
+ */
7746
+ const RPC_ACCEPTED_KEYS_PARAM = {
7747
+ name: "RPC_ACCEPTED_KEYS",
7748
+ schema: type("string[]"),
7749
+ brand: RPC_PEER_KEY
7750
+ };
7751
+ /** ADR-0031's need brand for the streams module's bearer key — control.ts registers the provisioner under this. */
7752
+ const STREAMS_API_KEY = Symbol.for("prisma:streams/api-key");
7753
+ /**
7754
+ * The reserved provider param for the streams bearer key: the var name is
7755
+ * `STREAMS_API_KEY`. `brand` is `STREAMS_API_KEY` itself (the same symbol
7756
+ * `streamsApiKeyNeed()`'s need carries) — control.ts looks its `value(refs)`
7757
+ * up by this field.
7758
+ */
7759
+ const STREAMS_API_KEY_PARAM = {
7760
+ name: "STREAMS_API_KEY",
7761
+ schema: type("string"),
7762
+ brand: STREAMS_API_KEY
7763
+ };
7764
+ configKey("", {
7765
+ owner: "service",
7766
+ name: STREAMS_API_KEY_PARAM.name
7767
+ });
7768
+ /**
7769
+ * The list of provider-side reserved params the boot path validates and
7770
+ * stashes (ADR-0031): every brand's `{name, schema, brand}` declaration,
7771
+ * collected from that brand's own module (`service-keys.ts`,
7772
+ * `streams-keys.ts`, `origin-key.ts`) so `compute.ts` names no brand itself.
7773
+ *
7774
+ * This list exists separately from `control.ts`'s deploy-side registry
7775
+ * (`PROVIDER_PARAMS`) because `control.ts` is deploy-only code — it imports
7776
+ * `@internal/lowering` and `effect` to mint values — and a booted service
7777
+ * must never import it. This module is reachable from a user service's
7778
+ * bundle through `compute.ts`, so it must never import `@internal/lowering`,
7779
+ * `effect`, `alchemy`, or `control.ts`.
7780
+ *
7781
+ * This is the single source of which reserved provider params exist:
7782
+ * control.ts builds `PROVIDER_PARAMS` by mapping over this list and looking
7783
+ * up each entry's deploy-side value function (edge-derived `value(refs)` or
7784
+ * service-derived `valueForService(provisioned, address)`) by its `brand`,
7785
+ * throwing at module load if one is missing. Adding a brand means adding its
7786
+ * entry here, plus its deploy-side value function in control.ts — a brand
7787
+ * registered for deploy but absent here is no longer expressible, because
7788
+ * deploy no longer names its own param set independently.
7789
+ */
7790
+ const RESERVED_PROVIDER_PARAMS = [
7791
+ RPC_ACCEPTED_KEYS_PARAM,
7792
+ STREAMS_API_KEY_PARAM,
7793
+ ORIGIN_PARAM
7794
+ ];
7795
+ Object.freeze({
7796
+ kind: "s3",
7797
+ __cmp: {
7798
+ url: "",
7799
+ bucket: "",
7800
+ accessKeyId: "",
7801
+ secretAccessKey: ""
7802
+ },
7803
+ satisfies: (required) => required.kind === "s3"
7804
+ });
7805
+ const reservedParams = { port: number$1({ default: 3e3 }) };
7806
+ /**
7807
+ * A Prisma Compute service — declarations only (deps + params + build + the
7808
+ * ports it exposes), no descriptor. `params` merges with the reserved
7809
+ * `ReservedParams` (`port`); a user param whose name collides with a reserved
7810
+ * one fails at authoring, the same way a colliding dependency name does.
7811
+ *
7812
+ * · run(address, boot) — the process controller: deserialize the platform
7813
+ * environment (keyed off `address`, the extension's ONE env read) into a
7814
+ * typed Config, re-emit it under address-free process-local stash keys,
7815
+ * then call boot() to start the app's entry.
7816
+ * · load() / config() — called from inside the app's entry: read the stash;
7817
+ * load() hydrates + memoizes the deps, config() returns the typed params.
7818
+ * Separate accessors so a dep and a param never share a namespace (ADR-0021).
7819
+ * · origin() — this service's platform-assigned public origin, read from the
7820
+ * stash `run()` populates; memoized per process.
7821
+ *
7822
+ * The underlying node carries `extension: '@prisma/composer-prisma-cloud'` —
7823
+ * the control-plane registry key `prisma-composer deploy` resolves through the
7824
+ * app's `prisma-composer.config.ts` (ADR-0017). This module loads nothing at
7825
+ * deploy time; nodes are pure data until run() or load() is called.
7826
+ */
7827
+ var ComputeService = class {
7828
+ #resolved;
7829
+ #loadedDeps;
7830
+ #loadedParams;
7831
+ #loadedSecrets;
7832
+ #origin;
7833
+ constructor(node) {
7834
+ Object.assign(this, node);
7835
+ }
7836
+ #processConfig() {
7837
+ if (this.#resolved === void 0) this.#resolved = deserialize(this, "");
7838
+ return this.#resolved;
7839
+ }
7840
+ async run(address, boot) {
7841
+ const config = deserialize(this, address);
7842
+ stash(this, config);
7843
+ stashProviderParams(RESERVED_PROVIDER_PARAMS, address);
7844
+ stashSecrets(this, address);
7845
+ const port = config.service["port"];
7846
+ if (typeof port === "number") process.env["PORT"] = String(port);
7847
+ return boot();
7848
+ }
7849
+ load() {
7850
+ if (this.#loadedDeps === void 0) this.#loadedDeps = blindCast(hydrateSync(this, this.#processConfig()));
7851
+ return this.#loadedDeps;
7852
+ }
7853
+ config() {
7854
+ if (this.#loadedParams === void 0) this.#loadedParams = blindCast(this.#processConfig().service);
7855
+ return this.#loadedParams;
7856
+ }
7857
+ secrets() {
7858
+ if (this.#loadedSecrets === void 0) this.#loadedSecrets = blindCast(hydrateSecrets(this, deserializeSecrets(this, "")));
7859
+ return this.#loadedSecrets;
7860
+ }
7861
+ /** This service's platform-assigned public origin — read from the stash
7862
+ * run() populates and memoized per process. Throws if called before run()
7863
+ * has stashed it (readOrigin's pinned message). */
7864
+ origin() {
7865
+ this.#origin ??= readOrigin();
7866
+ return this.#origin;
7867
+ }
7868
+ };
7869
+ const compute = (def) => {
7870
+ const userParams = def.params ?? blindCast({});
7871
+ for (const reserved of Object.keys(reservedParams)) {
7872
+ if (reserved in def.deps) throw new Error(`compute(): dependency "${reserved}" collides with the reserved service param of the same name — rename the dependency.`);
7873
+ if (reserved in userParams) throw new Error(`compute(): param "${reserved}" collides with the reserved service param of the same name — rename the param.`);
7874
+ }
7875
+ 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.`);
7876
+ 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.`);
7877
+ const params = blindCast({
7878
+ ...userParams,
7879
+ ...reservedParams
7880
+ });
7881
+ const instance = new ComputeService(service$1({
7882
+ name: def.name,
7883
+ extension: "@prisma/composer-prisma-cloud",
7884
+ type: "compute",
7885
+ inputs: def.deps,
7886
+ params,
7887
+ ...def.secrets !== void 0 ? { secrets: def.secrets } : {},
7888
+ build: def.build,
7889
+ ...def.expose !== void 0 ? { expose: def.expose } : {}
7890
+ }));
7891
+ Object.freeze(instance);
7892
+ return instance;
7893
+ };
7894
+ Object.freeze({
7895
+ kind: "postgres",
7896
+ __cmp: { url: "" },
7897
+ satisfies: (required) => required.kind === "postgres"
7898
+ });
7899
+ Object.freeze({
7900
+ kind: "credentials",
7901
+ __cmp: {
7902
+ accessKeyId: "",
7903
+ secretAccessKey: ""
7904
+ },
7905
+ satisfies: (required) => required.kind === "credentials"
7906
+ });
7907
+ /**
7634
7908
  * The one call edge between the scheduler and the app's runner: `trigger(jobId)`.
7635
7909
  * The scheduler depends on it (`rpc(triggerContract)`); the runner exposes it
7636
7910
  * (`expose: { trigger: triggerContract }`). `jobId` travels as data through this