@prisma/composer-prisma-cloud 0.1.0-dev.1 → 0.1.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 (44) hide show
  1. package/dist/control.d.mts +44 -4
  2. package/dist/control.mjs +155 -37
  3. package/dist/control.mjs.map +1 -1
  4. package/dist/cron/index.mjs +73 -8
  5. package/dist/cron/index.mjs.map +1 -1
  6. package/dist/cron/scheduler-entrypoint.mjs +158 -93
  7. package/dist/cron/scheduler-entrypoint.mjs.map +1 -1
  8. package/dist/cron/scheduler-service.mjs +73 -8
  9. package/dist/cron/scheduler-service.mjs.map +1 -1
  10. package/dist/index.d.mts +34 -15
  11. package/dist/index.mjs +4 -5
  12. package/dist/index.mjs.map +1 -1
  13. package/dist/{prisma-next-COrwlg3N.mjs → prisma-next-qPB8_Az6.mjs} +2 -2
  14. package/dist/prisma-next-qPB8_Az6.mjs.map +1 -0
  15. package/dist/prisma-next.d.mts +1 -1
  16. package/dist/prisma-next.mjs +1 -1
  17. package/dist/{param-DB0B8m15-IvzNq9BM.mjs → provisioned-edges-DIQAR4q4-Bn9op-JG.mjs} +87 -28
  18. package/dist/provisioned-edges-DIQAR4q4-Bn9op-JG.mjs.map +1 -0
  19. package/dist/{serializer-DAEWRfnm-D3GW9dOZ.mjs → serializer-CX4VYdf_-KKGoAxfx.mjs} +29 -3
  20. package/dist/{serializer-DAEWRfnm-D3GW9dOZ.mjs.map → serializer-CX4VYdf_-KKGoAxfx.mjs.map} +1 -1
  21. package/dist/serializer-Cx5slrV4-xJfH6EWS.d.mts +36 -0
  22. package/dist/storage/index.d.mts +11 -11
  23. package/dist/storage/index.mjs +74 -8
  24. package/dist/storage/index.mjs.map +1 -1
  25. package/dist/storage/storage-entrypoint.mjs +7197 -12
  26. package/dist/storage/storage-entrypoint.mjs.map +1 -1
  27. package/dist/storage/storage-service.mjs +74 -8
  28. package/dist/storage/storage-service.mjs.map +1 -1
  29. package/dist/storage/testing.mjs.map +1 -1
  30. package/dist/streams/index.d.mts +224 -22
  31. package/dist/streams/index.mjs +3637 -37
  32. package/dist/streams/index.mjs.map +1 -1
  33. package/dist/streams/streams-entrypoint.mjs +7731 -221
  34. package/dist/streams/streams-entrypoint.mjs.map +1 -1
  35. package/dist/streams/streams-service.mjs +400 -21
  36. package/dist/streams/streams-service.mjs.map +1 -1
  37. package/dist/streams/testing.d.mts +1 -1
  38. package/dist/streams/testing.mjs.map +1 -1
  39. package/dist/testing.d.mts +1 -1
  40. package/dist/testing.mjs +1 -1
  41. package/dist/testing.mjs.map +1 -1
  42. package/package.json +14 -14
  43. package/dist/param-DB0B8m15-IvzNq9BM.mjs.map +0 -1
  44. package/dist/prisma-next-COrwlg3N.mjs.map +0 -1
@@ -1,6 +1,7 @@
1
- import { dependency, hydrateSecrets, hydrateSync, number, resource, secret, service, string } from "@prisma/composer";
1
+ import { dependency, hydrateSecrets, hydrateSync, number, provisionNeed, resource, service, string } from "@prisma/composer";
2
2
  import { blindCast } from "@prisma/composer/casts";
3
- import "@prisma/composer/rpc";
3
+ import { RPC_PEER_KEY } from "@prisma/composer/service-rpc";
4
+ import { type } from "arktype";
4
5
  import node from "@prisma/composer/node";
5
6
  blindCast(Symbol.for("prisma:prisma-cloud-secret-source"));
6
7
  /**
@@ -164,6 +165,32 @@ const stashSecrets = (node, address) => {
164
165
  process.env[secretKey("", slot)] = name;
165
166
  }
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
+ }
167
194
  /** Synchronous Standard Schema validation — see the matching note in core's `config.ts`. */
168
195
  function standardValidateSync(schema, value) {
169
196
  const result = schema["~standard"].validate(value);
@@ -172,12 +199,60 @@ function standardValidateSync(schema, value) {
172
199
  return result.value;
173
200
  }
174
201
  //#endregion
175
- //#region ../../1-prisma-cloud/1-extensions/target/dist/param-DB0B8m15.mjs
176
- /** The reserved accepted-keys env var: COMPOSER_<addr>_RPC_ACCEPTED_KEYS ("" ↦ @internal/rpc's RPC_ACCEPTED_KEYS_ENV). */
177
- const serviceKeyEnvName = (address) => configKey(address, {
202
+ //#region ../../1-prisma-cloud/1-extensions/target/dist/provisioned-edges-DIQAR4q4.mjs
203
+ /**
204
+ * RPC's reserved provider param (ADR-0030/ADR-0031): the declaration
205
+ * name + schema + brand — for the accepted-keys set a provider stores, shared
206
+ * by `control.ts` (which registers the deploy-side `value(refs)` that mints
207
+ * and aggregates it — see its `rpcAcceptedKeysValue`) and `compute.ts` (which
208
+ * validates and stashes it at boot), so writer and reader cannot drift.
209
+ * Finding the edges themselves is `provisioned-edges.ts`'s generic,
210
+ * brand-blind scan — RPC is not special-cased anywhere in this target.
211
+ *
212
+ * This module is reachable from the RUNTIME/authoring side — it must never
213
+ * import `@internal/lowering` or `effect`, or those tokens leak into a user
214
+ * service's bundle (the deploy-side `value(refs)` lives in control.ts, the
215
+ * control-plane-only entry).
216
+ */
217
+ /**
218
+ * The reserved provider param for RPC's accepted-keys set: the var name is
219
+ * `RPC_ACCEPTED_KEYS`, derived through `configKey` at both ends
220
+ * (`configKey(address, …)` at deploy, `configKey('', …)` at boot — the
221
+ * address-free form is `@internal/service-rpc`'s `RPC_ACCEPTED_KEYS_ENV`). `brand` is
222
+ * `RPC_PEER_KEY`, the same brand `perBindingToken()`'s need carries — control.ts
223
+ * looks its `value(refs)` up by this field.
224
+ */
225
+ const RPC_ACCEPTED_KEYS_PARAM = {
226
+ name: "RPC_ACCEPTED_KEYS",
227
+ schema: type("string[]"),
228
+ brand: RPC_PEER_KEY
229
+ };
230
+ /** ADR-0031's need brand for the streams module's bearer key — control.ts registers the provisioner under this. */
231
+ const STREAMS_API_KEY = Symbol.for("prisma:streams/api-key");
232
+ /**
233
+ * The provisioning need `durableStreams()`'s `apiKey` param declares: an
234
+ * unguessable value the target mints ONCE PER PROVIDER (not per edge) —
235
+ * `@prisma/streams-server` authenticates a single `API_KEY`, so every
236
+ * consumer of one streams module must present the same value. Per-provider
237
+ * cardinality is provisioner policy (ADR-0031), invisible to core.
238
+ */
239
+ const streamsApiKeyNeed = () => provisionNeed(STREAMS_API_KEY);
240
+ /**
241
+ * The reserved provider param for the streams bearer key: the var name is
242
+ * `STREAMS_API_KEY`. `brand` is `STREAMS_API_KEY` itself (the same symbol
243
+ * `streamsApiKeyNeed()`'s need carries) — control.ts looks its `value(refs)`
244
+ * up by this field.
245
+ */
246
+ const STREAMS_API_KEY_PARAM = {
247
+ name: "STREAMS_API_KEY",
248
+ schema: type("string"),
249
+ brand: STREAMS_API_KEY
250
+ };
251
+ configKey("", {
178
252
  owner: "service",
179
- name: "RPC_ACCEPTED_KEYS"
253
+ name: STREAMS_API_KEY_PARAM.name
180
254
  });
255
+ const RESERVED_PROVIDER_PARAMS = [RPC_ACCEPTED_KEYS_PARAM, STREAMS_API_KEY_PARAM];
181
256
  blindCast(Symbol.for("prisma:prisma-cloud-param-source"));
182
257
  //#endregion
183
258
  //#region ../../1-prisma-cloud/1-extensions/target/dist/index.mjs
@@ -234,9 +309,8 @@ const compute = (def) => {
234
309
  async run(address, boot) {
235
310
  const config = deserialize(node, address);
236
311
  stash(node, config);
312
+ stashProviderParams(RESERVED_PROVIDER_PARAMS, address);
237
313
  stashSecrets(node, address);
238
- const accepted = process.env[serviceKeyEnvName(address)];
239
- if (accepted !== void 0) process.env[serviceKeyEnvName("")] = accepted;
240
314
  const port = config.service["port"];
241
315
  if (typeof port === "number") process.env["PORT"] = String(port);
242
316
  return boot();
@@ -334,7 +408,7 @@ function s3StoreService(def) {
334
408
  }));
335
409
  }
336
410
  //#endregion
337
- //#region ../../1-prisma-cloud/2-shared-modules/storage/dist/storage-service-DSaZsAC4.mjs
411
+ //#region ../../1-prisma-cloud/2-shared-modules/storage/dist/storage-service-BQdOiMsW.mjs
338
412
  const s3Contract = Object.freeze({
339
413
  kind: "s3",
340
414
  __cmp: {
@@ -390,31 +464,336 @@ function storageService(opts) {
390
464
  });
391
465
  }
392
466
  storageService({ bucket: "storage" });
393
- //#endregion
394
- //#region ../../1-prisma-cloud/2-shared-modules/streams/dist/streams-service-Dx0z-whA.mjs
395
- const streamsContract = Object.freeze({
467
+ var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
468
+ var require_reusify = /* @__PURE__ */ __commonJSMin(((exports, module) => {
469
+ function reusify(Constructor) {
470
+ var head = new Constructor();
471
+ var tail = head;
472
+ function get() {
473
+ var current = head;
474
+ if (current.next) head = current.next;
475
+ else {
476
+ head = new Constructor();
477
+ tail = head;
478
+ }
479
+ current.next = null;
480
+ return current;
481
+ }
482
+ function release(obj) {
483
+ tail.next = obj;
484
+ tail = obj;
485
+ }
486
+ return {
487
+ get,
488
+ release
489
+ };
490
+ }
491
+ module.exports = reusify;
492
+ }));
493
+ (/* @__PURE__ */ __commonJSMin(((exports, module) => {
494
+ var reusify = require_reusify();
495
+ function fastqueue(context, worker, _concurrency) {
496
+ if (typeof context === "function") {
497
+ _concurrency = worker;
498
+ worker = context;
499
+ context = null;
500
+ }
501
+ if (!(_concurrency >= 1)) throw new Error("fastqueue concurrency must be equal to or greater than 1");
502
+ var cache = reusify(Task);
503
+ var queueHead = null;
504
+ var queueTail = null;
505
+ var _running = 0;
506
+ var errorHandler = null;
507
+ var self = {
508
+ push,
509
+ drain: noop,
510
+ saturated: noop,
511
+ pause,
512
+ paused: false,
513
+ get concurrency() {
514
+ return _concurrency;
515
+ },
516
+ set concurrency(value) {
517
+ if (!(value >= 1)) throw new Error("fastqueue concurrency must be equal to or greater than 1");
518
+ _concurrency = value;
519
+ if (self.paused) return;
520
+ for (; queueHead && _running < _concurrency;) {
521
+ _running++;
522
+ release();
523
+ }
524
+ },
525
+ running,
526
+ resume,
527
+ idle,
528
+ length,
529
+ getQueue,
530
+ unshift,
531
+ empty: noop,
532
+ kill,
533
+ killAndDrain,
534
+ error,
535
+ abort
536
+ };
537
+ return self;
538
+ function running() {
539
+ return _running;
540
+ }
541
+ function pause() {
542
+ self.paused = true;
543
+ }
544
+ function length() {
545
+ var current = queueHead;
546
+ var counter = 0;
547
+ while (current) {
548
+ current = current.next;
549
+ counter++;
550
+ }
551
+ return counter;
552
+ }
553
+ function getQueue() {
554
+ var current = queueHead;
555
+ var tasks = [];
556
+ while (current) {
557
+ tasks.push(current.value);
558
+ current = current.next;
559
+ }
560
+ return tasks;
561
+ }
562
+ function resume() {
563
+ if (!self.paused) return;
564
+ self.paused = false;
565
+ if (queueHead === null) {
566
+ _running++;
567
+ release();
568
+ return;
569
+ }
570
+ for (; queueHead && _running < _concurrency;) {
571
+ _running++;
572
+ release();
573
+ }
574
+ }
575
+ function idle() {
576
+ return _running === 0 && self.length() === 0;
577
+ }
578
+ function push(value, done) {
579
+ var current = cache.get();
580
+ current.context = context;
581
+ current.release = release;
582
+ current.value = value;
583
+ current.callback = done || noop;
584
+ current.errorHandler = errorHandler;
585
+ if (_running >= _concurrency || self.paused) if (queueTail) {
586
+ queueTail.next = current;
587
+ queueTail = current;
588
+ } else {
589
+ queueHead = current;
590
+ queueTail = current;
591
+ self.saturated();
592
+ }
593
+ else {
594
+ _running++;
595
+ worker.call(context, current.value, current.worked);
596
+ }
597
+ }
598
+ function unshift(value, done) {
599
+ var current = cache.get();
600
+ current.context = context;
601
+ current.release = release;
602
+ current.value = value;
603
+ current.callback = done || noop;
604
+ current.errorHandler = errorHandler;
605
+ if (_running >= _concurrency || self.paused) if (queueHead) {
606
+ current.next = queueHead;
607
+ queueHead = current;
608
+ } else {
609
+ queueHead = current;
610
+ queueTail = current;
611
+ self.saturated();
612
+ }
613
+ else {
614
+ _running++;
615
+ worker.call(context, current.value, current.worked);
616
+ }
617
+ }
618
+ function release(holder) {
619
+ if (holder) cache.release(holder);
620
+ var next = queueHead;
621
+ if (next && _running <= _concurrency) if (!self.paused) {
622
+ if (queueTail === queueHead) queueTail = null;
623
+ queueHead = next.next;
624
+ next.next = null;
625
+ worker.call(context, next.value, next.worked);
626
+ if (queueTail === null) self.empty();
627
+ } else _running--;
628
+ else if (--_running === 0) self.drain();
629
+ }
630
+ function kill() {
631
+ queueHead = null;
632
+ queueTail = null;
633
+ self.drain = noop;
634
+ }
635
+ function killAndDrain() {
636
+ queueHead = null;
637
+ queueTail = null;
638
+ self.drain();
639
+ self.drain = noop;
640
+ }
641
+ function abort() {
642
+ var current = queueHead;
643
+ queueHead = null;
644
+ queueTail = null;
645
+ while (current) {
646
+ var next = current.next;
647
+ var callback = current.callback;
648
+ var errorHandler = current.errorHandler;
649
+ var val = current.value;
650
+ var context = current.context;
651
+ current.value = null;
652
+ current.callback = noop;
653
+ current.errorHandler = null;
654
+ if (errorHandler) errorHandler(/* @__PURE__ */ new Error("abort"), val);
655
+ callback.call(context, /* @__PURE__ */ new Error("abort"));
656
+ current.release(current);
657
+ current = next;
658
+ }
659
+ self.drain = noop;
660
+ }
661
+ function error(handler) {
662
+ errorHandler = handler;
663
+ }
664
+ }
665
+ function noop() {}
666
+ function Task() {
667
+ this.value = null;
668
+ this.callback = noop;
669
+ this.next = null;
670
+ this.release = noop;
671
+ this.context = null;
672
+ this.errorHandler = null;
673
+ var self = this;
674
+ this.worked = function worked(err, result) {
675
+ var callback = self.callback;
676
+ var errorHandler = self.errorHandler;
677
+ var val = self.value;
678
+ self.value = null;
679
+ self.callback = noop;
680
+ if (self.errorHandler) errorHandler(err, val);
681
+ callback.call(self.context, err, result);
682
+ self.release(self);
683
+ };
684
+ }
685
+ function queueAsPromised(context, worker, _concurrency) {
686
+ if (typeof context === "function") {
687
+ _concurrency = worker;
688
+ worker = context;
689
+ context = null;
690
+ }
691
+ function asyncWrapper(arg, cb) {
692
+ worker.call(this, arg).then(function(res) {
693
+ cb(null, res);
694
+ }, cb);
695
+ }
696
+ var queue = fastqueue(context, asyncWrapper, _concurrency);
697
+ var pushCb = queue.push;
698
+ var unshiftCb = queue.unshift;
699
+ queue.push = push;
700
+ queue.unshift = unshift;
701
+ queue.drained = drained;
702
+ return queue;
703
+ function push(value) {
704
+ var p = new Promise(function(resolve, reject) {
705
+ pushCb(value, function(err, result) {
706
+ if (err) {
707
+ reject(err);
708
+ return;
709
+ }
710
+ resolve(result);
711
+ });
712
+ });
713
+ p.catch(noop);
714
+ return p;
715
+ }
716
+ function unshift(value) {
717
+ var p = new Promise(function(resolve, reject) {
718
+ unshiftCb(value, function(err, result) {
719
+ if (err) {
720
+ reject(err);
721
+ return;
722
+ }
723
+ resolve(result);
724
+ });
725
+ });
726
+ p.catch(noop);
727
+ return p;
728
+ }
729
+ function drained() {
730
+ return new Promise(function(resolve) {
731
+ process.nextTick(function() {
732
+ if (queue.idle()) resolve();
733
+ else {
734
+ var previousDrain = queue.drain;
735
+ queue.drain = function() {
736
+ if (typeof previousDrain === "function") previousDrain();
737
+ resolve();
738
+ queue.drain = previousDrain;
739
+ };
740
+ }
741
+ });
742
+ });
743
+ }
744
+ }
745
+ module.exports = fastqueue;
746
+ module.exports.promise = queueAsPromised;
747
+ })))();
748
+ /**
749
+ * Default backoff options.
750
+ */
751
+ const BackoffDefaults = {
752
+ initialDelay: 100,
753
+ maxDelay: 6e4,
754
+ multiplier: 1.3,
755
+ maxRetries: Infinity
756
+ };
757
+ ({ ...BackoffDefaults });
758
+ ({ ...BackoffDefaults });
759
+ /**
760
+ * The `streams()` module's own exposed port: a general streams provider,
761
+ * satisfied by kind alone — the `postgresContract` pattern. The module
762
+ * cannot know its eventual consumers' stream names (different consumers of
763
+ * one module each name their own), and the server genuinely serves any
764
+ * stream, so what a consumer requires of its provider is only "is a streams
765
+ * provider". That is exactly what this wide type says, and the empty def
766
+ * map is a legitimate `StreamDefs` value — a placeholder nobody reads, like
767
+ * postgres's `{ url: '' }`. Consumers keep their literal handle typing from
768
+ * `durableStreams(contract)`'s generic parameter, which is independent of
769
+ * the wiring-compatibility type here.
770
+ */
771
+ const streamsProviderContract = Object.freeze({
396
772
  kind: "streams",
397
- __cmp: { url: "" },
773
+ __cmp: {},
398
774
  satisfies: (required) => required.kind === "streams"
399
775
  });
776
+ string(), string({ provision: streamsApiKeyNeed() });
400
777
  /**
401
- * The streams service node: a plain `compute` service (no lowering extension
402
- * the contract binding is `{ url }`, which compute's deploy outputs already
403
- * carry). It declares the `store` dependency (`s3()`, the storage module's
404
- * port), the `apiKey` secret slot, and the `streams` expose. The deploy
405
- * bootstrap runs the default-exported bare node; the real wiring arrives
406
- * through serialized config at runtime exactly like `storage-service.ts`.
778
+ * The streams service node: a plain `compute` service the contract binding's
779
+ * `url` is a producer output compute's deploy already carries, and its
780
+ * `apiKey` is minted by the target's registered provisioner (ADR-0031), so
781
+ * nothing is left for a bespoke lowering to extend. It declares the `store`
782
+ * dependency (`s3()`, the storage module's port) and the `streams` expose; the
783
+ * bearer key reaches this service through the target's reserved provider
784
+ * param, not through a dependency. The deploy bootstrap runs the
785
+ * default-exported bare node; the real wiring arrives through serialized
786
+ * config at runtime — exactly like `storage-service.ts`.
407
787
  */
408
788
  function streamsService() {
409
789
  return compute({
410
790
  name: "streams",
411
791
  deps: { store: s3() },
412
- secrets: { apiKey: secret() },
413
792
  build: node({
414
793
  module: new URL("./streams-service.mjs", import.meta.url).href,
415
794
  entry: "./streams-entrypoint.mjs"
416
795
  }),
417
- expose: { streams: streamsContract }
796
+ expose: { streams: streamsProviderContract }
418
797
  });
419
798
  }
420
799
  var streams_service_default = streamsService();