brass-runtime 1.17.0 → 1.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/README.md +36 -3
  2. package/dist/agent/cli/main.cjs +31 -32
  3. package/dist/agent/cli/main.js +3 -4
  4. package/dist/agent/cli/main.mjs +3 -4
  5. package/dist/agent/index.cjs +4 -5
  6. package/dist/agent/index.d.ts +1 -1
  7. package/dist/agent/index.js +3 -4
  8. package/dist/agent/index.mjs +3 -4
  9. package/dist/{chunk-7X3K5RMS.js → chunk-22HZQG5F.js} +9 -11
  10. package/dist/{chunk-GLE2WY7Z.cjs → chunk-2JHJ4YHS.cjs} +417 -124
  11. package/dist/{chunk-Q2I37RP3.cjs → chunk-2OW6IFY2.cjs} +44 -323
  12. package/dist/{chunk-7ZPEZ57L.cjs → chunk-5LC7V2OZ.cjs} +18 -20
  13. package/dist/{chunk-AGR5B2BC.cjs → chunk-5RZ7YITF.cjs} +564 -12
  14. package/dist/{chunk-DNFJLJMW.mjs → chunk-6MLAZPBL.mjs} +48 -24
  15. package/dist/{chunk-EJ6BPYVR.mjs → chunk-6V2AWT4R.mjs} +1 -1
  16. package/dist/{chunk-3AYM6WPJ.js → chunk-7DU7IQHK.js} +20 -299
  17. package/dist/{chunk-SK7UZRNI.mjs → chunk-7GBJYOX7.mjs} +528 -23
  18. package/dist/chunk-7TKI527D.cjs +123 -0
  19. package/dist/{chunk-52OB2ROS.js → chunk-7VQLEN37.js} +2 -4
  20. package/dist/{chunk-KH4SYAOS.mjs → chunk-B5FKOLTB.mjs} +20 -299
  21. package/dist/{chunk-FHQGHPMO.mjs → chunk-BC6Q6BCO.mjs} +2 -4
  22. package/dist/{chunk-4P2HHGAX.mjs → chunk-COOW7BJX.mjs} +32 -11
  23. package/dist/{chunk-2HQTDLHF.mjs → chunk-EEN5OTCR.mjs} +555 -3
  24. package/dist/{chunk-KZJQ723N.cjs → chunk-EICAJDNX.cjs} +13 -15
  25. package/dist/chunk-ELIECDYN.cjs +33 -0
  26. package/dist/{chunk-GYM3LLGS.mjs → chunk-H626ZTDZ.mjs} +399 -106
  27. package/dist/{chunk-C3MDXTRZ.js → chunk-HCJ4S3YB.js} +48 -24
  28. package/dist/{chunk-7JIJOVCT.js → chunk-IPSMXUWA.js} +2 -4
  29. package/dist/{chunk-4ROBZFL6.cjs → chunk-J6DUHITE.cjs} +6 -8
  30. package/dist/{chunk-6RY2FFN4.mjs → chunk-JWIEMBE6.mjs} +9 -11
  31. package/dist/{chunk-PD4EJTQC.cjs → chunk-KNTJ7FQB.cjs} +5 -5
  32. package/dist/chunk-KTGDLBLD.mjs +123 -0
  33. package/dist/chunk-LSYQ3C2M.js +33 -0
  34. package/dist/{chunk-RKGKFN2A.js → chunk-OW5VHAOE.js} +1 -1
  35. package/dist/{chunk-EOC4UHBS.mjs → chunk-RBHNOKH4.mjs} +2 -2
  36. package/dist/{chunk-6IXXWIUM.js → chunk-S4HXADU4.js} +555 -3
  37. package/dist/{chunk-FH2X7BVP.js → chunk-TTSPIU3U.js} +399 -106
  38. package/dist/{chunk-5QC7LRZ3.js → chunk-UAKAF32U.js} +2 -2
  39. package/dist/{chunk-CZIVE6NT.cjs → chunk-UUMKZJRJ.cjs} +48 -24
  40. package/dist/{chunk-MBEJI5HF.mjs → chunk-WCBNXPN6.mjs} +2 -4
  41. package/dist/{chunk-52PPNNI4.cjs → chunk-WGE2FEZE.cjs} +2 -2
  42. package/dist/{chunk-WBGRHGBP.cjs → chunk-WI7GZF3B.cjs} +114 -93
  43. package/dist/chunk-WUDHOZIH.js +6234 -0
  44. package/dist/{chunk-F6XWZQY4.cjs → chunk-WVSZOPGQ.cjs} +583 -78
  45. package/dist/chunk-XPIMJQYS.cjs +6234 -0
  46. package/dist/{chunk-VWIPB6I5.js → chunk-YGR2IN4R.js} +528 -23
  47. package/dist/chunk-YM3EDNYD.js +123 -0
  48. package/dist/chunk-YWLLH27R.mjs +33 -0
  49. package/dist/{chunk-BKK77SBA.js → chunk-YZ5LQ32F.js} +32 -11
  50. package/dist/chunk-Z3ZZMQUZ.mjs +6234 -0
  51. package/dist/core/index.cjs +37 -9
  52. package/dist/core/index.d.ts +19 -152
  53. package/dist/core/index.js +86 -58
  54. package/dist/core/index.mjs +86 -58
  55. package/dist/defaultClient-Cid0JoUR.d.ts +1648 -0
  56. package/dist/{effect-DIUHZ9IN.d.ts → effect-DnGUuhw6.d.ts} +22 -1
  57. package/dist/http/index.cjs +206 -59
  58. package/dist/http/index.d.ts +55 -819
  59. package/dist/http/index.js +220 -73
  60. package/dist/http/index.mjs +220 -73
  61. package/dist/http/testing.cjs +31 -10
  62. package/dist/http/testing.d.ts +16 -5
  63. package/dist/http/testing.js +29 -8
  64. package/dist/http/testing.mjs +29 -8
  65. package/dist/index.cjs +116 -88
  66. package/dist/index.d.ts +9 -8
  67. package/dist/index.js +87 -59
  68. package/dist/index.mjs +87 -59
  69. package/dist/{schedule-CK3Ml_7p.d.ts → layer-D2LFcBVx.d.ts} +176 -2
  70. package/dist/observability/index.cjs +20 -7
  71. package/dist/observability/index.d.ts +32 -8
  72. package/dist/observability/index.js +19 -6
  73. package/dist/observability/index.mjs +19 -6
  74. package/dist/perf/cli.cjs +26 -28
  75. package/dist/perf/cli.js +11 -13
  76. package/dist/perf/cli.mjs +11 -13
  77. package/dist/perf/index.cjs +13 -15
  78. package/dist/perf/index.js +11 -13
  79. package/dist/perf/index.mjs +11 -13
  80. package/dist/schema/index.cjs +2 -2
  81. package/dist/schema/index.js +1 -1
  82. package/dist/schema/index.mjs +1 -1
  83. package/dist/{server-D6JZ15_e.d.ts → server-Bf1zNYZk.d.ts} +5 -5
  84. package/dist/{stream-B4oK9JFP.d.ts → stream-I7bkvF7a.d.ts} +1 -1
  85. package/dist/{tracer-Hwt1cl7h.d.ts → tracer-DF83nLn6.d.ts} +2 -2
  86. package/dist/{tracing-DqbTKGcf.d.ts → tracing-CWV4gT0u.d.ts} +1 -1
  87. package/docs/README.md +2 -0
  88. package/docs/ai/PUBLIC_API.md +28 -7
  89. package/docs/articles/brass-runtime-http-observability.md +467 -0
  90. package/docs/frameworks/angular.md +51 -0
  91. package/docs/frameworks/express.md +58 -0
  92. package/docs/frameworks/fastify.md +49 -0
  93. package/docs/frameworks/nestjs.md +53 -0
  94. package/docs/frameworks/nextjs.md +55 -0
  95. package/docs/frameworks/react.md +44 -0
  96. package/docs/frameworks/vanilla.md +56 -0
  97. package/docs/guides/layers.md +130 -0
  98. package/docs/http-recipes.md +31 -1
  99. package/docs/http.md +50 -1
  100. package/docs/observability.md +132 -0
  101. package/docs/performance-profiler.md +6 -2
  102. package/docs/recipes/layers.md +46 -2
  103. package/docs/recipes/testing.md +25 -0
  104. package/package.json +6 -2
  105. package/dist/chunk-3LOYJFRR.cjs +0 -300
  106. package/dist/chunk-3Y2RIUMM.js +0 -300
  107. package/dist/chunk-5EC274J5.cjs +0 -2874
  108. package/dist/chunk-5VRJNBLZ.mjs +0 -2874
  109. package/dist/chunk-62AZW6UT.cjs +0 -313
  110. package/dist/chunk-74ZTY6CP.js +0 -2871
  111. package/dist/chunk-7CMJS3QE.mjs +0 -2871
  112. package/dist/chunk-A2OM6NEH.mjs +0 -194
  113. package/dist/chunk-B33ICAKP.js +0 -313
  114. package/dist/chunk-JF5WGYJJ.cjs +0 -194
  115. package/dist/chunk-KN32XNTH.mjs +0 -313
  116. package/dist/chunk-KQLYONSE.cjs +0 -2871
  117. package/dist/chunk-L2SYFEBS.js +0 -194
  118. package/dist/chunk-MIIYDLGM.js +0 -2874
  119. package/dist/chunk-PWC3RBQE.mjs +0 -300
  120. package/dist/client-CZHU674n.d.ts +0 -820
@@ -1,8 +1,13 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;
2
+
3
+
4
+
5
+
6
+ var _chunk2JHJ4YHScjs = require('./chunk-2JHJ4YHS.cjs');
7
+
2
8
 
3
9
 
4
10
 
5
- var _chunkGLE2WY7Zcjs = require('./chunk-GLE2WY7Z.cjs');
6
11
 
7
12
 
8
13
 
@@ -15,14 +20,14 @@ var _chunkMVGUEJ5Zcjs = require('./chunk-MVGUEJ5Z.cjs');
15
20
  // src/core/runtime/combinators.ts
16
21
  function sleep(ms) {
17
22
  return _chunkMVGUEJ5Zcjs.asyncEffect.call(void 0, (env, cb) => {
18
- const clock = _chunkGLE2WY7Zcjs.runtimeClockFromEnv.call(void 0, env);
23
+ const clock = _chunk2JHJ4YHScjs.runtimeClockFromEnv.call(void 0, env);
19
24
  const id = clock.setTimeout(() => cb({ _tag: "Success", value: void 0 }), ms);
20
25
  return () => clock.clearTimeout(id);
21
26
  });
22
27
  }
23
28
  function timeout(effect, ms) {
24
29
  return _chunkMVGUEJ5Zcjs.asyncEffect.call(void 0, (env, cb) => {
25
- const clock = _chunkGLE2WY7Zcjs.runtimeClockFromEnv.call(void 0, env);
30
+ const clock = _chunk2JHJ4YHScjs.runtimeClockFromEnv.call(void 0, env);
26
31
  let done = false;
27
32
  let timerId;
28
33
  let fiber;
@@ -35,7 +40,7 @@ function timeout(effect, ms) {
35
40
  cause: { _tag: "Fail", error: { _tag: "TimeoutError", ms } }
36
41
  });
37
42
  }, ms);
38
- const runtime = _chunkGLE2WY7Zcjs.unsafeGetCurrentRuntime.call(void 0, );
43
+ const runtime = _chunk2JHJ4YHScjs.unsafeGetCurrentRuntime.call(void 0, );
39
44
  fiber = runtime.fork(effect);
40
45
  fiber.join((exit) => {
41
46
  if (done) return;
@@ -77,7 +82,7 @@ function retry(effect, policy) {
77
82
  );
78
83
  return _chunkMVGUEJ5Zcjs.asyncFlatMap.call(void 0,
79
84
  { _tag: "Sync", thunk: (env) => {
80
- const clock = _chunkGLE2WY7Zcjs.runtimeClockFromEnv.call(void 0, env);
85
+ const clock = _chunk2JHJ4YHScjs.runtimeClockFromEnv.call(void 0, env);
81
86
  return { clock, startedAt: clock.now() };
82
87
  } },
83
88
  ({ clock, startedAt }) => loop(0, startedAt, clock)
@@ -102,6 +107,174 @@ function retryWithBackoff(effect, opts = {}) {
102
107
  });
103
108
  }
104
109
 
110
+ // src/core/runtime/resource.ts
111
+ function bracket(acquire, use, release) {
112
+ return _chunkMVGUEJ5Zcjs.asyncEffect.call(void 0, (env, cb) => {
113
+ const runtime = _chunk2JHJ4YHScjs.unsafeGetCurrentRuntime.call(void 0, );
114
+ const scope = new (0, _chunk2JHJ4YHScjs.Scope)(runtime);
115
+ const acquireFiber = scope.fork(acquire);
116
+ acquireFiber.join((acquireExit) => {
117
+ if (acquireExit._tag === "Failure") {
118
+ scope.close(acquireExit);
119
+ cb(acquireExit);
120
+ return;
121
+ }
122
+ const resource2 = acquireExit.value;
123
+ const useFiber = scope.fork(use(resource2));
124
+ useFiber.join((useExit) => {
125
+ const releaseEffect = safeRelease(release, resource2, useExit);
126
+ const releaseFiber = runtime.fork(releaseEffect);
127
+ releaseFiber.join(() => {
128
+ scope.close(useExit);
129
+ cb(useExit);
130
+ });
131
+ });
132
+ });
133
+ return () => {
134
+ scope.close(_chunkMVGUEJ5Zcjs.Exit.failCause(_chunkMVGUEJ5Zcjs.Cause.interrupt()));
135
+ };
136
+ });
137
+ }
138
+ function safeRelease(release, resource2, exit) {
139
+ return _chunkMVGUEJ5Zcjs.asyncFold.call(void 0,
140
+ (() => {
141
+ try {
142
+ return release(resource2, exit);
143
+ } catch (e) {
144
+ return _chunkMVGUEJ5Zcjs.unit.call(void 0, );
145
+ }
146
+ })(),
147
+ () => _chunkMVGUEJ5Zcjs.unit.call(void 0, ),
148
+ () => _chunkMVGUEJ5Zcjs.unit.call(void 0, )
149
+ );
150
+ }
151
+ function ensuring(effect, finalizer) {
152
+ return _chunkMVGUEJ5Zcjs.asyncEffect.call(void 0, (env, cb) => {
153
+ const runtime = _chunk2JHJ4YHScjs.unsafeGetCurrentRuntime.call(void 0, );
154
+ const fiber = runtime.fork(effect);
155
+ fiber.join((exit) => {
156
+ const fin = _chunkMVGUEJ5Zcjs.asyncFold.call(void 0,
157
+ (() => {
158
+ try {
159
+ return finalizer(exit);
160
+ } catch (e2) {
161
+ return _chunkMVGUEJ5Zcjs.unit.call(void 0, );
162
+ }
163
+ })(),
164
+ () => _chunkMVGUEJ5Zcjs.unit.call(void 0, ),
165
+ () => _chunkMVGUEJ5Zcjs.unit.call(void 0, )
166
+ );
167
+ runtime.fork(fin).join(() => {
168
+ cb(exit);
169
+ });
170
+ });
171
+ return () => {
172
+ fiber.interrupt();
173
+ };
174
+ });
175
+ }
176
+ function resource(acquire, release) {
177
+ return makeResourceFromUse((body) => bracket(acquire, body, release));
178
+ }
179
+ var makeResource = resource;
180
+ function resourceSucceed(value) {
181
+ return makeResourceFromUse((body) => body(value));
182
+ }
183
+ function resourceFromManaged(m) {
184
+ return makeResourceFromUse((body) => useManaged(m, body));
185
+ }
186
+ function useResource(res, body) {
187
+ return res.use(body);
188
+ }
189
+ function resourceAll(resources) {
190
+ const build = (index) => {
191
+ if (index >= resources.length) return resourceSucceed([]);
192
+ return resources[index].flatMap(
193
+ (head) => build(index + 1).map((tail) => [head, ...tail])
194
+ );
195
+ };
196
+ return build(0).map((values) => values);
197
+ }
198
+ var Resource = Object.freeze({
199
+ make: resource,
200
+ succeed: resourceSucceed,
201
+ fromManaged: resourceFromManaged,
202
+ all: resourceAll,
203
+ use: useResource
204
+ });
205
+ function makeResourceFromUse(use) {
206
+ const self = {
207
+ _tag: "Resource",
208
+ use,
209
+ map: (f) => makeResourceFromUse((body) => self.use((a) => body(f(a)))),
210
+ flatMap: (f) => makeResourceFromUse((body) => self.use((a) => f(a).use(body))),
211
+ zip: (that) => self.flatMap((a) => that.map((b) => [a, b]))
212
+ };
213
+ return self;
214
+ }
215
+ function managed(acquire, release) {
216
+ return {
217
+ _tag: "Managed",
218
+ acquire,
219
+ release: (resource2, exit) => release(resource2, exit)
220
+ };
221
+ }
222
+ function useManaged(m, body) {
223
+ return bracket(m.acquire, body, m.release);
224
+ }
225
+ function managedAll(manageds) {
226
+ const acquire = _chunkMVGUEJ5Zcjs.asyncEffect.call(void 0, (env, cb) => {
227
+ const runtime = _chunk2JHJ4YHScjs.unsafeGetCurrentRuntime.call(void 0, );
228
+ const resources = [];
229
+ let i = 0;
230
+ const acquireNext = () => {
231
+ if (i >= manageds.length) {
232
+ cb({ _tag: "Success", value: resources });
233
+ return;
234
+ }
235
+ const m = manageds[i];
236
+ const fiber = runtime.fork(m.acquire);
237
+ fiber.join((exit) => {
238
+ if (exit._tag === "Failure") {
239
+ releaseAcquired(runtime, manageds, resources, exit).then(() => {
240
+ cb(exit);
241
+ });
242
+ return;
243
+ }
244
+ resources.push(exit.value);
245
+ i++;
246
+ acquireNext();
247
+ });
248
+ };
249
+ acquireNext();
250
+ });
251
+ const release = (resources, exit) => {
252
+ return _chunkMVGUEJ5Zcjs.asyncEffect.call(void 0, (_env, cb) => {
253
+ const runtime = _chunk2JHJ4YHScjs.unsafeGetCurrentRuntime.call(void 0, );
254
+ releaseAcquired(runtime, manageds, resources, exit).then(() => {
255
+ cb({ _tag: "Success", value: void 0 });
256
+ });
257
+ });
258
+ };
259
+ return { _tag: "Managed", acquire, release };
260
+ }
261
+ async function releaseAcquired(runtime, manageds, resources, exit) {
262
+ for (let i = resources.length - 1; i >= 0; i--) {
263
+ try {
264
+ const m = manageds[i];
265
+ await new Promise((resolve) => {
266
+ const releaseEff = _chunkMVGUEJ5Zcjs.asyncFold.call(void 0,
267
+ m.release(resources[i], exit),
268
+ () => _chunkMVGUEJ5Zcjs.unit.call(void 0, ),
269
+ () => _chunkMVGUEJ5Zcjs.unit.call(void 0, )
270
+ );
271
+ runtime.fork(releaseEff).join(() => resolve());
272
+ });
273
+ } catch (e3) {
274
+ }
275
+ }
276
+ }
277
+
105
278
  // src/core/runtime/schedule.ts
106
279
  function recurs(n) {
107
280
  return {
@@ -420,7 +593,7 @@ function union(left, right) {
420
593
  };
421
594
  }
422
595
  function makeScheduleDriver(schedule, options = {}) {
423
- const clock = _nullishCoalesce(options.clock, () => ( _chunkGLE2WY7Zcjs.liveClock));
596
+ const clock = _nullishCoalesce(options.clock, () => ( _chunk2JHJ4YHScjs.liveClock));
424
597
  let startedAtMs = _nullishCoalesce(options.startedAtMs, () => ( clock.now()));
425
598
  let attempt = 0;
426
599
  let lastDecision;
@@ -488,7 +661,7 @@ function runSchedule(schedule, inputs, options = {}) {
488
661
  function driverFromRuntime(schedule, options = {}) {
489
662
  return _chunkMVGUEJ5Zcjs.Async.sync((env) => makeScheduleDriver(schedule, {
490
663
  ...options,
491
- clock: _nullishCoalesce(options.clock, () => ( _chunkGLE2WY7Zcjs.runtimeClockFromEnv.call(void 0, env)))
664
+ clock: _nullishCoalesce(options.clock, () => ( _chunk2JHJ4YHScjs.runtimeClockFromEnv.call(void 0, env)))
492
665
  }));
493
666
  }
494
667
  function retryWithSchedule(effect, schedule, options = {}) {
@@ -546,7 +719,7 @@ function normalizeCap(ms) {
546
719
  return normalizeDelay(ms);
547
720
  }
548
721
  function defaultClock() {
549
- return _chunkGLE2WY7Zcjs.liveClock.now();
722
+ return _chunk2JHJ4YHScjs.liveClock.now();
550
723
  }
551
724
  function nowFromContext(context) {
552
725
  return _nullishCoalesce(_optionalChain([context, 'optionalAccess', _4 => _4.clock, 'access', _5 => _5.now, 'call', _6 => _6()]), () => ( defaultClock()));
@@ -578,7 +751,7 @@ function wallClockNow() {
578
751
  function safeObserve(observer, event) {
579
752
  try {
580
753
  observer(event);
581
- } catch (e) {
754
+ } catch (e4) {
582
755
  }
583
756
  }
584
757
  function observeDriverDecision(event, options) {
@@ -596,7 +769,7 @@ function observeDriverDecision(event, options) {
596
769
  ...options.captureInput ? { input: event.input } : {},
597
770
  ...options.captureOutput ? { output: event.output } : {}
598
771
  }, _nullishCoalesce(options.emitContext, () => ( {})));
599
- } catch (e2) {
772
+ } catch (e5) {
600
773
  }
601
774
  }
602
775
  var Schedule = Object.freeze({
@@ -636,6 +809,385 @@ var Schedule = Object.freeze({
636
809
  poll: repeatWithSchedule
637
810
  });
638
811
 
812
+ // src/core/runtime/layer.ts
813
+ var MissingLayerServiceError = (_class = class extends Error {
814
+ __init() {this._tag = "MissingLayerService"}
815
+
816
+ constructor(serviceName) {
817
+ super(`Missing layer service '${serviceName}'. Add a layer that provides this ServiceTag or pass a LayerContext containing it.`);_class.prototype.__init.call(this);;
818
+ this.name = "MissingLayerServiceError";
819
+ this.serviceName = serviceName;
820
+ }
821
+ }, _class);
822
+ function formatLayerError(error) {
823
+ if (error instanceof MissingLayerServiceError) return error.message;
824
+ if (isObjectRecord(error) && error._tag === "MissingLayerService" && typeof error.serviceName === "string") {
825
+ return `Missing layer service '${error.serviceName}'. Add the provider layer before using the service.`;
826
+ }
827
+ return error instanceof Error ? error.message : String(error);
828
+ }
829
+ function makeServiceTag(name) {
830
+ return {
831
+ _tag: "ServiceTag",
832
+ key: Symbol(name),
833
+ name
834
+ };
835
+ }
836
+ var serviceTag = makeServiceTag;
837
+ var defineService = makeServiceTag;
838
+ var LayerContext = class _LayerContext {
839
+
840
+ constructor(entries) {
841
+ if (entries instanceof Map) {
842
+ this.services = new Map(entries);
843
+ return;
844
+ }
845
+ this.services = /* @__PURE__ */ new Map();
846
+ if (!entries) return;
847
+ for (const [tag, service] of entries) this.services.set(tag.key, service);
848
+ }
849
+ static empty() {
850
+ return new _LayerContext();
851
+ }
852
+ get(tag) {
853
+ return this.services.get(tag.key);
854
+ }
855
+ unsafeGet(tag) {
856
+ if (!this.services.has(tag.key)) {
857
+ throw new MissingLayerServiceError(tag.name);
858
+ }
859
+ return this.services.get(tag.key);
860
+ }
861
+ has(tag) {
862
+ return this.services.has(tag.key);
863
+ }
864
+ add(tag, service) {
865
+ const next = new Map(this.services);
866
+ next.set(tag.key, service);
867
+ return new _LayerContext(next);
868
+ }
869
+ merge(other) {
870
+ const next = new Map(this.services);
871
+ for (const [key, service] of other.services) next.set(key, service);
872
+ return new _LayerContext(next);
873
+ }
874
+ size() {
875
+ return this.services.size;
876
+ }
877
+ };
878
+ function makeLayerScope() {
879
+ const cache = /* @__PURE__ */ new WeakMap();
880
+ const finalizers = [];
881
+ let closed = false;
882
+ const scope = {
883
+ get: (l, deps) => {
884
+ if (closed) return _chunkMVGUEJ5Zcjs.asyncFail.call(void 0, new Error("LayerScope is closed"));
885
+ if (cache.has(l)) return _chunkMVGUEJ5Zcjs.asyncSucceed.call(void 0, cache.get(l));
886
+ const built = l.buildScoped ? l.buildScoped(deps, scope) : _chunkMVGUEJ5Zcjs.asyncFlatMap.call(void 0,
887
+ l.build(deps),
888
+ ({ service, release }) => _chunkMVGUEJ5Zcjs.asyncFlatMap.call(void 0, scope.addFinalizer(release), () => _chunkMVGUEJ5Zcjs.asyncSucceed.call(void 0, service))
889
+ );
890
+ return _chunkMVGUEJ5Zcjs.asyncFlatMap.call(void 0,
891
+ built,
892
+ (service) => _chunkMVGUEJ5Zcjs.asyncSync.call(void 0, () => {
893
+ cache.set(l, service);
894
+ return service;
895
+ })
896
+ );
897
+ },
898
+ close: () => {
899
+ if (closed) return _chunkMVGUEJ5Zcjs.unit.call(void 0, );
900
+ closed = true;
901
+ return releaseAll(finalizers);
902
+ },
903
+ size: () => finalizers.length,
904
+ addFinalizer: (release) => _chunkMVGUEJ5Zcjs.asyncSync.call(void 0, () => {
905
+ if (!closed) finalizers.push(release);
906
+ })
907
+ };
908
+ return scope;
909
+ }
910
+ function releaseAll(finalizers) {
911
+ const next = finalizers.pop();
912
+ if (!next) return _chunkMVGUEJ5Zcjs.unit.call(void 0, );
913
+ return _chunkMVGUEJ5Zcjs.asyncFold.call(void 0,
914
+ next(),
915
+ () => releaseAll(finalizers),
916
+ () => releaseAll(finalizers)
917
+ );
918
+ }
919
+ function mergeServices(a, b) {
920
+ if (a instanceof LayerContext && b instanceof LayerContext) {
921
+ return a.merge(b);
922
+ }
923
+ if (isObjectRecord(a) && isObjectRecord(b)) {
924
+ return { ...a, ...b };
925
+ }
926
+ return Object.assign({}, a, b);
927
+ }
928
+ function isObjectRecord(value) {
929
+ return typeof value === "object" && value !== null;
930
+ }
931
+ function layer(acquire, release) {
932
+ return {
933
+ _tag: "Layer",
934
+ build: (_deps) => _chunkMVGUEJ5Zcjs.asyncFlatMap.call(void 0, acquire(), (service) => _chunkMVGUEJ5Zcjs.asyncSucceed.call(void 0, {
935
+ service,
936
+ release: release ? () => release(service) : () => _chunkMVGUEJ5Zcjs.unit.call(void 0, )
937
+ }))
938
+ };
939
+ }
940
+ function layerValue(tag, value) {
941
+ return layerEffect(tag, () => _chunkMVGUEJ5Zcjs.asyncSucceed.call(void 0, value));
942
+ }
943
+ var makeTestLayer = layerValue;
944
+ function makeTestLayers(...providers) {
945
+ return {
946
+ _tag: "Layer",
947
+ build: (deps = LayerContext.empty()) => _chunkMVGUEJ5Zcjs.asyncSucceed.call(void 0, {
948
+ service: providers.reduce(
949
+ (context, [tag, service]) => context.add(tag, service),
950
+ deps
951
+ ),
952
+ release: () => _chunkMVGUEJ5Zcjs.unit.call(void 0, )
953
+ })
954
+ };
955
+ }
956
+ function layerEffect(tag, acquire, release) {
957
+ return {
958
+ _tag: "Layer",
959
+ build: (deps = LayerContext.empty()) => _chunkMVGUEJ5Zcjs.asyncFlatMap.call(void 0, acquire(deps), (service) => _chunkMVGUEJ5Zcjs.asyncSucceed.call(void 0, {
960
+ service: deps.add(tag, service),
961
+ release: release ? () => release(service) : () => _chunkMVGUEJ5Zcjs.unit.call(void 0, )
962
+ }))
963
+ };
964
+ }
965
+ var layerFromContext = layerEffect;
966
+ var defineLayer = layerEffect;
967
+ function getService(tag) {
968
+ return _chunkMVGUEJ5Zcjs.asyncSync.call(void 0, (context) => context.unsafeGet(tag));
969
+ }
970
+ function getServices(tags) {
971
+ return _chunkMVGUEJ5Zcjs.asyncSync.call(void 0, (context) => readServices(context, tags));
972
+ }
973
+ function useService(tag, use) {
974
+ return (context) => {
975
+ let service;
976
+ try {
977
+ service = context.unsafeGet(tag);
978
+ } catch (error) {
979
+ return _chunkMVGUEJ5Zcjs.asyncFail.call(void 0, error);
980
+ }
981
+ return use(service);
982
+ };
983
+ }
984
+ function useServices(tags, use) {
985
+ return (context) => {
986
+ let services;
987
+ try {
988
+ services = readServices(context, tags);
989
+ } catch (error) {
990
+ return _chunkMVGUEJ5Zcjs.asyncFail.call(void 0, error);
991
+ }
992
+ return use(services);
993
+ };
994
+ }
995
+ function readServices(context, tags) {
996
+ const services = {};
997
+ for (const key of Object.keys(tags)) {
998
+ services[key] = context.unsafeGet(tags[key]);
999
+ }
1000
+ return services;
1001
+ }
1002
+ function layerFrom() {
1003
+ return (acquire, release) => ({
1004
+ _tag: "Layer",
1005
+ build: (deps) => _chunkMVGUEJ5Zcjs.asyncFlatMap.call(void 0, acquire(deps), (service) => _chunkMVGUEJ5Zcjs.asyncSucceed.call(void 0, {
1006
+ service,
1007
+ release: release ? () => release(service) : () => _chunkMVGUEJ5Zcjs.unit.call(void 0, )
1008
+ }))
1009
+ });
1010
+ }
1011
+ function layerSucceed(value) {
1012
+ return {
1013
+ _tag: "Layer",
1014
+ build: () => _chunkMVGUEJ5Zcjs.asyncSucceed.call(void 0, { service: value, release: () => _chunkMVGUEJ5Zcjs.unit.call(void 0, ) })
1015
+ };
1016
+ }
1017
+ function layerFail(error) {
1018
+ return {
1019
+ _tag: "Layer",
1020
+ build: () => _chunkMVGUEJ5Zcjs.asyncFail.call(void 0, error)
1021
+ };
1022
+ }
1023
+ function compose(from, to) {
1024
+ return {
1025
+ _tag: "Layer",
1026
+ buildScoped: (deps, scope) => _chunkMVGUEJ5Zcjs.asyncFlatMap.call(void 0,
1027
+ scope.get(from, deps),
1028
+ (mid) => scope.get(to, mid)
1029
+ ),
1030
+ build: (deps) => _chunkMVGUEJ5Zcjs.asyncFlatMap.call(void 0,
1031
+ from.build(deps),
1032
+ ({ service: mid, release: releaseMid }) => _chunkMVGUEJ5Zcjs.asyncFold.call(void 0,
1033
+ to.build(mid),
1034
+ (error) => _chunkMVGUEJ5Zcjs.asyncFlatMap.call(void 0, releaseMid(), () => _chunkMVGUEJ5Zcjs.asyncFail.call(void 0, error)),
1035
+ ({ service: out, release: releaseOut }) => _chunkMVGUEJ5Zcjs.asyncSucceed.call(void 0, {
1036
+ service: out,
1037
+ release: () => _chunkMVGUEJ5Zcjs.asyncFlatMap.call(void 0, releaseOut(), () => releaseMid())
1038
+ })
1039
+ )
1040
+ )
1041
+ };
1042
+ }
1043
+ function composeAll(...layers) {
1044
+ return layers.slice(1).reduce(
1045
+ (acc, next) => compose(acc, next),
1046
+ layers[0]
1047
+ );
1048
+ }
1049
+ function merge(left, right) {
1050
+ return {
1051
+ _tag: "Layer",
1052
+ buildScoped: (deps, scope) => _chunkMVGUEJ5Zcjs.asyncFlatMap.call(void 0,
1053
+ scope.get(left, deps),
1054
+ (a) => _chunkMVGUEJ5Zcjs.asyncFlatMap.call(void 0,
1055
+ scope.get(right, deps),
1056
+ (b) => _chunkMVGUEJ5Zcjs.asyncSucceed.call(void 0, mergeServices(a, b))
1057
+ )
1058
+ ),
1059
+ build: (deps) => _chunkMVGUEJ5Zcjs.asyncFlatMap.call(void 0,
1060
+ left.build(deps),
1061
+ ({ service: a, release: releaseA }) => _chunkMVGUEJ5Zcjs.asyncFold.call(void 0,
1062
+ right.build(deps),
1063
+ (error) => _chunkMVGUEJ5Zcjs.asyncFlatMap.call(void 0, releaseA(), () => _chunkMVGUEJ5Zcjs.asyncFail.call(void 0, error)),
1064
+ ({ service: b, release: releaseB }) => _chunkMVGUEJ5Zcjs.asyncSucceed.call(void 0, {
1065
+ service: mergeServices(a, b),
1066
+ release: () => _chunkMVGUEJ5Zcjs.asyncFlatMap.call(void 0, releaseB(), () => releaseA())
1067
+ })
1068
+ )
1069
+ )
1070
+ };
1071
+ }
1072
+ function mergeAll(...layers) {
1073
+ return layers.slice(1).reduce(
1074
+ (acc, next) => merge(acc, next),
1075
+ layers[0]
1076
+ );
1077
+ }
1078
+ function mapLayer(l, f) {
1079
+ return {
1080
+ _tag: "Layer",
1081
+ buildScoped: (deps, scope) => _chunkMVGUEJ5Zcjs.asyncFlatMap.call(void 0,
1082
+ scope.get(l, deps),
1083
+ (service) => _chunkMVGUEJ5Zcjs.asyncSucceed.call(void 0, f(service))
1084
+ ),
1085
+ build: (deps) => _chunkMVGUEJ5Zcjs.asyncFlatMap.call(void 0,
1086
+ l.build(deps),
1087
+ ({ service, release }) => _chunkMVGUEJ5Zcjs.asyncSucceed.call(void 0, { service: f(service), release })
1088
+ )
1089
+ };
1090
+ }
1091
+ function buildLayer(l, deps) {
1092
+ const scope = makeLayerScope();
1093
+ return _chunkMVGUEJ5Zcjs.asyncFold.call(void 0,
1094
+ scope.get(l, deps),
1095
+ (error) => _chunkMVGUEJ5Zcjs.asyncFlatMap.call(void 0, scope.close(), () => _chunkMVGUEJ5Zcjs.asyncFail.call(void 0, error)),
1096
+ (service) => _chunkMVGUEJ5Zcjs.asyncSucceed.call(void 0, {
1097
+ service,
1098
+ scope,
1099
+ close: scope.close,
1100
+ use: (body) => body(service)
1101
+ })
1102
+ );
1103
+ }
1104
+ function provideLayer(l, use, deps) {
1105
+ return _chunkMVGUEJ5Zcjs.asyncFlatMap.call(void 0,
1106
+ buildLayer(l, _nullishCoalesce(deps, () => ( {}))),
1107
+ ({ service, close }) => ensuring(
1108
+ use(service),
1109
+ () => close()
1110
+ )
1111
+ );
1112
+ }
1113
+ function provideLayerContext(l, use, deps = LayerContext.empty()) {
1114
+ return provideLayer(l, use, deps);
1115
+ }
1116
+ var provide = provideLayer;
1117
+ var provideContext = provideLayerContext;
1118
+ var Layer = Object.freeze({
1119
+ make: layer,
1120
+ from: layerFrom,
1121
+ succeed: layerSucceed,
1122
+ fail: layerFail,
1123
+ value: layerValue,
1124
+ test: makeTestLayer,
1125
+ tests: makeTestLayers,
1126
+ effect: layerEffect,
1127
+ define: defineLayer,
1128
+ fromContext: layerFromContext,
1129
+ compose,
1130
+ composeAll,
1131
+ merge,
1132
+ all: mergeAll,
1133
+ mergeAll,
1134
+ map: mapLayer,
1135
+ provide: provideLayer,
1136
+ provideContext: provideLayerContext,
1137
+ build: buildLayer,
1138
+ scope: makeLayerScope,
1139
+ context: LayerContext.empty,
1140
+ tag: makeServiceTag,
1141
+ service: getService,
1142
+ services: getServices,
1143
+ use: useService,
1144
+ useAll: useServices
1145
+ });
1146
+
1147
+
1148
+
1149
+
1150
+
1151
+
1152
+
1153
+
1154
+
1155
+
1156
+
1157
+
1158
+
1159
+
1160
+
1161
+
1162
+
1163
+
1164
+
1165
+
1166
+
1167
+
1168
+
1169
+
1170
+
1171
+
1172
+
1173
+
1174
+
1175
+
1176
+
1177
+
1178
+
1179
+
1180
+
1181
+
1182
+
1183
+
1184
+
1185
+
1186
+
1187
+
1188
+
1189
+
1190
+
639
1191
 
640
1192
 
641
1193
 
@@ -680,4 +1232,4 @@ var Schedule = Object.freeze({
680
1232
 
681
1233
 
682
1234
 
683
- exports.sleep = sleep; exports.timeout = timeout; exports.retry = retry; exports.retryN = retryN; exports.retryWithBackoff = retryWithBackoff; exports.recurs = recurs; exports.forever = forever; exports.never = never; exports.once = once; exports.fixed = fixed; exports.spaced = spaced; exports.exponential = exponential; exports.linear = linear; exports.fibonacci = fibonacci; exports.jittered = jittered; exports.elapsed = elapsed; exports.whileInput = whileInput; exports.untilInput = untilInput; exports.take = take; exports.map = map; exports.contramap = contramap; exports.jitteredSchedule = jitteredSchedule; exports.jitter = jitter; exports.windowed = windowed; exports.maxDelay = maxDelay; exports.maxElapsed = maxElapsed; exports.upTo = upTo; exports.whileOutput = whileOutput; exports.untilOutput = untilOutput; exports.named = named; exports.tapDecision = tapDecision; exports.andThen = andThen; exports.intersect = intersect; exports.union = union; exports.makeScheduleDriver = makeScheduleDriver; exports.scheduleDriver = scheduleDriver; exports.runSchedule = runSchedule; exports.retryWithSchedule = retryWithSchedule; exports.retry2 = retry2; exports.repeatWithSchedule = repeatWithSchedule; exports.repeat = repeat; exports.poll = poll; exports.Schedule = Schedule;
1235
+ exports.sleep = sleep; exports.timeout = timeout; exports.retry = retry; exports.retryN = retryN; exports.retryWithBackoff = retryWithBackoff; exports.bracket = bracket; exports.ensuring = ensuring; exports.resource = resource; exports.makeResource = makeResource; exports.resourceSucceed = resourceSucceed; exports.resourceFromManaged = resourceFromManaged; exports.useResource = useResource; exports.resourceAll = resourceAll; exports.Resource = Resource; exports.managed = managed; exports.useManaged = useManaged; exports.managedAll = managedAll; exports.recurs = recurs; exports.forever = forever; exports.never = never; exports.once = once; exports.fixed = fixed; exports.spaced = spaced; exports.exponential = exponential; exports.linear = linear; exports.fibonacci = fibonacci; exports.jittered = jittered; exports.elapsed = elapsed; exports.whileInput = whileInput; exports.untilInput = untilInput; exports.take = take; exports.map = map; exports.contramap = contramap; exports.jitteredSchedule = jitteredSchedule; exports.jitter = jitter; exports.windowed = windowed; exports.maxDelay = maxDelay; exports.maxElapsed = maxElapsed; exports.upTo = upTo; exports.whileOutput = whileOutput; exports.untilOutput = untilOutput; exports.named = named; exports.tapDecision = tapDecision; exports.andThen = andThen; exports.intersect = intersect; exports.union = union; exports.makeScheduleDriver = makeScheduleDriver; exports.scheduleDriver = scheduleDriver; exports.runSchedule = runSchedule; exports.retryWithSchedule = retryWithSchedule; exports.retry2 = retry2; exports.repeatWithSchedule = repeatWithSchedule; exports.repeat = repeat; exports.poll = poll; exports.Schedule = Schedule; exports.MissingLayerServiceError = MissingLayerServiceError; exports.formatLayerError = formatLayerError; exports.makeServiceTag = makeServiceTag; exports.serviceTag = serviceTag; exports.defineService = defineService; exports.LayerContext = LayerContext; exports.makeLayerScope = makeLayerScope; exports.layer = layer; exports.layerValue = layerValue; exports.makeTestLayer = makeTestLayer; exports.makeTestLayers = makeTestLayers; exports.layerEffect = layerEffect; exports.layerFromContext = layerFromContext; exports.defineLayer = defineLayer; exports.getService = getService; exports.getServices = getServices; exports.useService = useService; exports.useServices = useServices; exports.layerFrom = layerFrom; exports.layerSucceed = layerSucceed; exports.layerFail = layerFail; exports.compose = compose; exports.composeAll = composeAll; exports.merge = merge; exports.mergeAll = mergeAll; exports.mapLayer = mapLayer; exports.buildLayer = buildLayer; exports.provideLayer = provideLayer; exports.provideLayerContext = provideLayerContext; exports.provide = provide; exports.provideContext = provideContext; exports.Layer = Layer;