brass-runtime 1.14.0 → 1.15.0

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/README.md +6 -3
  2. package/dist/agent/cli/main.cjs +44 -43
  3. package/dist/agent/cli/main.js +5 -4
  4. package/dist/agent/cli/main.mjs +5 -4
  5. package/dist/agent/index.cjs +4 -3
  6. package/dist/agent/index.d.ts +1 -1
  7. package/dist/agent/index.js +3 -2
  8. package/dist/agent/index.mjs +3 -2
  9. package/dist/{chunk-WJESVBWN.js → chunk-3QMOKAS5.js} +9 -7
  10. package/dist/{chunk-BMRF4FN6.js → chunk-4NHES7VK.mjs} +59 -237
  11. package/dist/chunk-AR22SXML.js +1043 -0
  12. package/dist/{chunk-4N2JEK4H.mjs → chunk-BDF4AMWX.mjs} +27 -151
  13. package/dist/chunk-BDYEENHT.js +224 -0
  14. package/dist/{chunk-JT7D6M5H.js → chunk-BMH5AV44.js} +27 -151
  15. package/dist/chunk-ELOOF35R.mjs +131 -0
  16. package/dist/chunk-JFPU5GQI.mjs +1043 -0
  17. package/dist/{chunk-MQF7HZ7Y.mjs → chunk-K6M7MDZ4.mjs} +9 -7
  18. package/dist/chunk-MS34J5LY.cjs +224 -0
  19. package/dist/{chunk-UWMMYKVK.mjs → chunk-PPUXIH5R.js} +59 -237
  20. package/dist/chunk-R3R2FVLG.cjs +131 -0
  21. package/dist/chunk-STVLQ3XD.cjs +489 -0
  22. package/dist/{chunk-BKBFSOGT.cjs → chunk-TGIFUAK4.cjs} +26 -150
  23. package/dist/chunk-TO7IKXYT.js +131 -0
  24. package/dist/chunk-UMAZLXAB.mjs +224 -0
  25. package/dist/{chunk-XTMZTVIT.cjs → chunk-VEZNF5GZ.cjs} +136 -134
  26. package/dist/chunk-XPZNXSVN.cjs +1043 -0
  27. package/dist/core/index.cjs +216 -0
  28. package/dist/core/index.d.ts +673 -0
  29. package/dist/core/index.js +216 -0
  30. package/dist/core/index.mjs +216 -0
  31. package/dist/{effect-DM56H743.d.ts → effect-CMOQKX8y.d.ts} +12 -11
  32. package/dist/http/index.cjs +2557 -235
  33. package/dist/http/index.d.ts +1514 -4
  34. package/dist/http/index.js +2549 -227
  35. package/dist/http/index.mjs +2549 -227
  36. package/dist/index.cjs +237 -1168
  37. package/dist/index.d.ts +7 -673
  38. package/dist/index.js +77 -1008
  39. package/dist/index.mjs +77 -1008
  40. package/dist/stream-FQm9h4Mg.d.ts +74 -0
  41. package/dist/tracing-DNT9jEbr.d.ts +106 -0
  42. package/package.json +11 -3
  43. package/dist/chunk-SKVY72E5.cjs +0 -667
  44. package/dist/stream-Oqe6WeLE.d.ts +0 -173
@@ -1,4 +1,11 @@
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; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10; var _class11; var _class12; var _class13; var _class14; var _class15; var _class16; var _class17;// src/core/types/asyncEffect.ts
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; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10; var _class11; var _class12; var _class13; var _class14; var _class15; var _class16; var _class17;var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined") return require.apply(this, arguments);
5
+ throw Error('Dynamic require of "' + x + '" is not supported');
6
+ });
7
+
8
+ // src/core/types/asyncEffect.ts
2
9
  var Async = {
3
10
  succeed: (value) => ({ _tag: "Succeed", value }),
4
11
  fail: (error) => ({ _tag: "Fail", error }),
@@ -6,21 +13,18 @@ var Async = {
6
13
  async: (register) => ({ _tag: "Async", register })
7
14
  };
8
15
  function asyncFold(fa, onFailure, onSuccess) {
9
- return { _tag: "Fold", first: fa, onFailure, onSuccess };
16
+ return {
17
+ _tag: "Fold",
18
+ first: fa,
19
+ onFailure,
20
+ onSuccess
21
+ };
10
22
  }
11
23
  function asyncCatchAll(fa, handler) {
12
- return asyncFold(
13
- fa,
14
- (e) => handler(e),
15
- (a) => asyncSucceed(a)
16
- );
24
+ return asyncFold(fa, handler, asyncSucceed);
17
25
  }
18
26
  function asyncMapError(fa, f) {
19
- return asyncFold(
20
- fa,
21
- (e) => asyncFail(f(e)),
22
- (a) => asyncSucceed(a)
23
- );
27
+ return asyncFold(fa, (e) => asyncFail(f(e)), asyncSucceed);
24
28
  }
25
29
  var SUCCEED_UNDEFINED = { _tag: "Succeed", value: void 0 };
26
30
  var SUCCEED_TRUE = { _tag: "Succeed", value: true };
@@ -43,7 +47,7 @@ var asyncSync = (thunk) => ({
43
47
  thunk
44
48
  });
45
49
  var asyncTotal = (thunk) => asyncSync(() => thunk());
46
- var async = (register) => ({
50
+ var asyncEffect = (register) => ({
47
51
  _tag: "Async",
48
52
  register
49
53
  });
@@ -64,7 +68,7 @@ function acquireRelease(acquire, release, scope) {
64
68
  });
65
69
  }
66
70
  function asyncInterruptible(register) {
67
- return async(register);
71
+ return asyncEffect(register);
68
72
  }
69
73
  var withAsyncPromise = (run) => (eff) => {
70
74
  const anyEff = eff;
@@ -101,18 +105,14 @@ var succeed = (value) => asyncSucceed(value);
101
105
  var fail = (error) => asyncFail(error);
102
106
  var sync = (thunk) => asyncSync((env) => thunk(env));
103
107
  var map = (fa, f) => asyncMap(fa, f);
104
- var flatMap = (fa, f) => asyncFlatMap(fa, (a) => f(a));
108
+ var flatMap = (fa, f) => asyncFlatMap(fa, f);
105
109
  var mapError = (fa, f) => asyncMapError(fa, f);
106
- var catchAll = (fa, handler) => asyncFold(
107
- fa,
108
- (e) => handler(e),
109
- (a) => asyncSucceed(a)
110
- );
110
+ var catchAll = (fa, handler) => asyncFold(fa, handler, asyncSucceed);
111
111
  function orElseOptional(fa, that) {
112
112
  return asyncFold(
113
113
  fa,
114
114
  (opt) => opt._tag === "Some" ? asyncFail(opt) : that(),
115
- (a) => asyncSucceed(a)
115
+ asyncSucceed
116
116
  );
117
117
  }
118
118
  var end = () => fail(none);
@@ -2797,7 +2797,7 @@ var Runtime = class _Runtime {
2797
2797
  });
2798
2798
  }
2799
2799
  delay(ms, eff) {
2800
- return async((_env, cb) => {
2800
+ return asyncEffect((_env, cb) => {
2801
2801
  const handle = setTimeout(() => {
2802
2802
  this.unsafeRunAsync(eff, cb);
2803
2803
  }, ms);
@@ -3517,7 +3517,7 @@ var JsFiberEngine = (_class16 = class {
3517
3517
  // src/core/runtime/scope.ts
3518
3518
  var nextScopeId = 1;
3519
3519
  function awaitAll(fibers) {
3520
- return async((_env, cb) => {
3520
+ return asyncEffect((_env, cb) => {
3521
3521
  let remaining = fibers.length;
3522
3522
  if (remaining === 0) {
3523
3523
  cb({ _tag: "Success", value: void 0 });
@@ -3628,7 +3628,7 @@ var Scope = (_class17 = class _Scope {
3628
3628
  closeAsync(exit = { _tag: "Success", value: void 0 }, opts = { awaitChildren: true }) {
3629
3629
  return asyncFlatMap(
3630
3630
  unit(),
3631
- () => async((env, cb) => {
3631
+ () => asyncEffect((env, cb) => {
3632
3632
  if (this.closed) {
3633
3633
  cb({ _tag: "Success", value: void 0 });
3634
3634
  return;
@@ -3663,7 +3663,7 @@ var Scope = (_class17 = class _Scope {
3663
3663
  }
3664
3664
  }, _class17);
3665
3665
  function withScopeAsync(runtime, f) {
3666
- return async((_env, cb) => {
3666
+ return asyncEffect((_env, cb) => {
3667
3667
  const scope = new Scope(runtime);
3668
3668
  let done = false;
3669
3669
  const completeAfterClose = (exit) => {
@@ -3690,130 +3690,6 @@ function withScope(runtime, f) {
3690
3690
  });
3691
3691
  }
3692
3692
 
3693
- // src/core/stream/structuredConcurrency.ts
3694
- function race(left, right, parentScope) {
3695
- return async((env, cb) => {
3696
- const scope = parentScope.subScope();
3697
- let done = false;
3698
- const onResult = (exit) => {
3699
- if (done) return;
3700
- done = true;
3701
- scope.close(exit);
3702
- cb(exit);
3703
- };
3704
- const fiberLeft = scope.fork(left);
3705
- const fiberRight = scope.fork(right);
3706
- fiberLeft.join(onResult);
3707
- fiberRight.join(onResult);
3708
- });
3709
- }
3710
- function zipPar(left, right, parentScope) {
3711
- return async((env, cb) => {
3712
- const scope = parentScope.subScope();
3713
- let leftExit = null;
3714
- let rightExit = null;
3715
- let done = false;
3716
- const checkDone = () => {
3717
- if (!leftExit || !rightExit || done) return;
3718
- done = true;
3719
- if (leftExit._tag === "Success" && rightExit._tag === "Success") {
3720
- scope.close({ _tag: "Success", value: void 0 });
3721
- cb({
3722
- _tag: "Success",
3723
- value: [leftExit.value, rightExit.value]
3724
- });
3725
- return;
3726
- }
3727
- let cause;
3728
- if (leftExit._tag === "Failure") {
3729
- cause = leftExit.cause;
3730
- } else if (rightExit._tag === "Failure") {
3731
- cause = rightExit.cause;
3732
- } else {
3733
- throw new Error("zipPar: unreachable state (no Failure exit)");
3734
- }
3735
- const errExit = {
3736
- _tag: "Failure",
3737
- cause
3738
- };
3739
- scope.close(errExit);
3740
- cb(errExit);
3741
- };
3742
- const f1 = scope.fork(left);
3743
- const f2 = scope.fork(right);
3744
- f1.join((exit) => {
3745
- leftExit = exit;
3746
- checkDone();
3747
- });
3748
- f2.join((exit) => {
3749
- rightExit = exit;
3750
- checkDone();
3751
- });
3752
- });
3753
- }
3754
- function collectAllPar(effects, parentScope) {
3755
- return async((env, cb) => {
3756
- const scope = parentScope.subScope();
3757
- const results = new Array(effects.length);
3758
- let completed = 0;
3759
- let done = false;
3760
- effects.forEach((eff, i) => {
3761
- const f = scope.fork(eff);
3762
- f.join((exit) => {
3763
- if (done) return;
3764
- if (exit._tag === "Failure") {
3765
- done = true;
3766
- const errExit = {
3767
- _tag: "Failure",
3768
- cause: exit.cause
3769
- };
3770
- scope.close(errExit);
3771
- cb(errExit);
3772
- return;
3773
- }
3774
- results[i] = exit.value;
3775
- completed++;
3776
- if (completed === effects.length) {
3777
- done = true;
3778
- const successExit = {
3779
- _tag: "Success",
3780
- value: results
3781
- };
3782
- scope.close({ _tag: "Success", value: void 0 });
3783
- cb(successExit);
3784
- }
3785
- });
3786
- });
3787
- });
3788
- }
3789
- function raceWith(left, right, parentScope, onLeft, onRight) {
3790
- return async((env, cb) => {
3791
- const scope = parentScope.subScope();
3792
- let done = false;
3793
- const fiberLeft = scope.fork(left);
3794
- const fiberRight = scope.fork(right);
3795
- const finish = (next) => {
3796
- scope.fork(next).join((exitNext) => {
3797
- scope.close(exitNext);
3798
- cb(exitNext);
3799
- });
3800
- };
3801
- fiberLeft.join((exitL) => {
3802
- if (done) return;
3803
- done = true;
3804
- finish(onLeft(exitL, fiberRight, scope));
3805
- });
3806
- fiberRight.join((exitR) => {
3807
- if (done) return;
3808
- done = true;
3809
- finish(onRight(exitR, fiberLeft, scope));
3810
- });
3811
- });
3812
- }
3813
-
3814
-
3815
-
3816
-
3817
3693
 
3818
3694
 
3819
3695
 
@@ -3894,4 +3770,4 @@ function raceWith(left, right, parentScope, onLeft, onRight) {
3894
3770
 
3895
3771
 
3896
3772
 
3897
- exports.Async = Async; exports.asyncFold = asyncFold; exports.asyncCatchAll = asyncCatchAll; exports.asyncMapError = asyncMapError; exports.unit = unit; exports.asyncSucceed = asyncSucceed; exports.asyncFail = asyncFail; exports.asyncSync = asyncSync; exports.asyncTotal = asyncTotal; exports.async = async; exports.asyncMap = asyncMap; exports.asyncFlatMap = asyncFlatMap; exports.acquireRelease = acquireRelease; exports.asyncInterruptible = asyncInterruptible; exports.withAsyncPromise = withAsyncPromise; exports.mapAsync = mapAsync; exports.mapTryAsync = mapTryAsync; exports.none = none; exports.some = some; exports.Cause = Cause; exports.Exit = Exit; exports.succeed = succeed; exports.fail = fail; exports.sync = sync; exports.map = map; exports.flatMap = flatMap; exports.mapError = mapError; exports.catchAll = catchAll; exports.orElseOptional = orElseOptional; exports.end = end; exports.PushStatus = PushStatus; exports.RingBuffer = RingBuffer; exports.resolveWasmModule = resolveWasmModule; exports.makeBoundedRingBuffer = makeBoundedRingBuffer; exports.sanitizeLaneKey = sanitizeLaneKey; exports.laneTag = laneTag; exports.inferCallerLaneFromStack = inferCallerLaneFromStack; exports.Scheduler = Scheduler; exports.globalScheduler = globalScheduler; exports.DefaultHostExecutor = DefaultHostExecutor; exports.JsFiberEngine = JsFiberEngine; exports.HostRegistry = HostRegistry; exports.ProgramBuilder = ProgramBuilder; exports.EngineFiberHandle = EngineFiberHandle; exports.ABI_VERSION = ABI_VERSION; exports.EVENT_WORDS = EVENT_WORDS; exports.NONE_U32 = NONE_U32; exports.OpcodeTagCode = OpcodeTagCode; exports.EventKindCode = EventKindCode; exports.encodeOpcodeProgram = encodeOpcodeProgram; exports.encodeOpcodeNodes = encodeOpcodeNodes; exports.decodeEvent = decodeEvent; exports.decodeEventBatch = decodeEventBatch; exports.WasmPackFiberBridge = WasmPackFiberBridge; exports.WasmFiberRegistryBridge = WasmFiberRegistryBridge; exports.makeFiberReadyQueue = makeFiberReadyQueue; exports.WasmFiberEngine = WasmFiberEngine; exports.runtimeCapabilities = runtimeCapabilities; exports.NoopHooks = NoopHooks; exports.Runtime = Runtime; exports.fork = fork; exports.runtimeForCaller = runtimeForCaller; exports.toPromiseByCaller = toPromiseByCaller; exports.unsafeRunAsync = unsafeRunAsync; exports.toPromise = toPromise; exports.abortablePromiseStats = abortablePromiseStats; exports.resetAbortablePromiseStats = resetAbortablePromiseStats; exports.fromPromiseAbortable = fromPromiseAbortable; exports.unsafeRunFoldWithEnv = unsafeRunFoldWithEnv; exports.setBenchmarkBudget = setBenchmarkBudget; exports.getBenchmarkBudget = getBenchmarkBudget; exports.RuntimeFiber = RuntimeFiber; exports.getCurrentFiber = getCurrentFiber; exports.unsafeGetCurrentRuntime = unsafeGetCurrentRuntime; exports.withCurrentFiber = withCurrentFiber; exports.Scope = Scope; exports.withScopeAsync = withScopeAsync; exports.withScope = withScope; exports.race = race; exports.zipPar = zipPar; exports.collectAllPar = collectAllPar; exports.raceWith = raceWith;
3773
+ exports.__require = __require; exports.Async = Async; exports.asyncFold = asyncFold; exports.asyncCatchAll = asyncCatchAll; exports.asyncMapError = asyncMapError; exports.unit = unit; exports.asyncSucceed = asyncSucceed; exports.asyncFail = asyncFail; exports.asyncSync = asyncSync; exports.asyncTotal = asyncTotal; exports.asyncEffect = asyncEffect; exports.asyncMap = asyncMap; exports.asyncFlatMap = asyncFlatMap; exports.acquireRelease = acquireRelease; exports.asyncInterruptible = asyncInterruptible; exports.withAsyncPromise = withAsyncPromise; exports.mapAsync = mapAsync; exports.mapTryAsync = mapTryAsync; exports.none = none; exports.some = some; exports.Cause = Cause; exports.Exit = Exit; exports.succeed = succeed; exports.fail = fail; exports.sync = sync; exports.map = map; exports.flatMap = flatMap; exports.mapError = mapError; exports.catchAll = catchAll; exports.orElseOptional = orElseOptional; exports.end = end; exports.PushStatus = PushStatus; exports.RingBuffer = RingBuffer; exports.resolveWasmModule = resolveWasmModule; exports.makeBoundedRingBuffer = makeBoundedRingBuffer; exports.sanitizeLaneKey = sanitizeLaneKey; exports.laneTag = laneTag; exports.inferCallerLaneFromStack = inferCallerLaneFromStack; exports.Scheduler = Scheduler; exports.globalScheduler = globalScheduler; exports.DefaultHostExecutor = DefaultHostExecutor; exports.JsFiberEngine = JsFiberEngine; exports.HostRegistry = HostRegistry; exports.ProgramBuilder = ProgramBuilder; exports.EngineFiberHandle = EngineFiberHandle; exports.ABI_VERSION = ABI_VERSION; exports.EVENT_WORDS = EVENT_WORDS; exports.NONE_U32 = NONE_U32; exports.OpcodeTagCode = OpcodeTagCode; exports.EventKindCode = EventKindCode; exports.encodeOpcodeProgram = encodeOpcodeProgram; exports.encodeOpcodeNodes = encodeOpcodeNodes; exports.decodeEvent = decodeEvent; exports.decodeEventBatch = decodeEventBatch; exports.WasmPackFiberBridge = WasmPackFiberBridge; exports.WasmFiberRegistryBridge = WasmFiberRegistryBridge; exports.makeFiberReadyQueue = makeFiberReadyQueue; exports.WasmFiberEngine = WasmFiberEngine; exports.runtimeCapabilities = runtimeCapabilities; exports.NoopHooks = NoopHooks; exports.Runtime = Runtime; exports.fork = fork; exports.runtimeForCaller = runtimeForCaller; exports.toPromiseByCaller = toPromiseByCaller; exports.unsafeRunAsync = unsafeRunAsync; exports.toPromise = toPromise; exports.abortablePromiseStats = abortablePromiseStats; exports.resetAbortablePromiseStats = resetAbortablePromiseStats; exports.fromPromiseAbortable = fromPromiseAbortable; exports.unsafeRunFoldWithEnv = unsafeRunFoldWithEnv; exports.setBenchmarkBudget = setBenchmarkBudget; exports.getBenchmarkBudget = getBenchmarkBudget; exports.RuntimeFiber = RuntimeFiber; exports.getCurrentFiber = getCurrentFiber; exports.unsafeGetCurrentRuntime = unsafeGetCurrentRuntime; exports.withCurrentFiber = withCurrentFiber; exports.Scope = Scope; exports.withScopeAsync = withScopeAsync; exports.withScope = withScope;
@@ -0,0 +1,131 @@
1
+ import {
2
+ asyncEffect
3
+ } from "./chunk-BMH5AV44.js";
4
+
5
+ // src/core/stream/structuredConcurrency.ts
6
+ function race(left, right, parentScope) {
7
+ return asyncEffect((env, cb) => {
8
+ const scope = parentScope.subScope();
9
+ let done = false;
10
+ const onResult = (exit) => {
11
+ if (done) return;
12
+ done = true;
13
+ scope.close(exit);
14
+ cb(exit);
15
+ };
16
+ const fiberLeft = scope.fork(left);
17
+ const fiberRight = scope.fork(right);
18
+ fiberLeft.join(onResult);
19
+ fiberRight.join(onResult);
20
+ });
21
+ }
22
+ function zipPar(left, right, parentScope) {
23
+ return asyncEffect((env, cb) => {
24
+ const scope = parentScope.subScope();
25
+ let leftExit = null;
26
+ let rightExit = null;
27
+ let done = false;
28
+ const checkDone = () => {
29
+ if (!leftExit || !rightExit || done) return;
30
+ done = true;
31
+ if (leftExit._tag === "Success" && rightExit._tag === "Success") {
32
+ scope.close({ _tag: "Success", value: void 0 });
33
+ cb({
34
+ _tag: "Success",
35
+ value: [leftExit.value, rightExit.value]
36
+ });
37
+ return;
38
+ }
39
+ let cause;
40
+ if (leftExit._tag === "Failure") {
41
+ cause = leftExit.cause;
42
+ } else if (rightExit._tag === "Failure") {
43
+ cause = rightExit.cause;
44
+ } else {
45
+ throw new Error("zipPar: unreachable state (no Failure exit)");
46
+ }
47
+ const errExit = {
48
+ _tag: "Failure",
49
+ cause
50
+ };
51
+ scope.close(errExit);
52
+ cb(errExit);
53
+ };
54
+ const f1 = scope.fork(left);
55
+ const f2 = scope.fork(right);
56
+ f1.join((exit) => {
57
+ leftExit = exit;
58
+ checkDone();
59
+ });
60
+ f2.join((exit) => {
61
+ rightExit = exit;
62
+ checkDone();
63
+ });
64
+ });
65
+ }
66
+ function collectAllPar(effects, parentScope) {
67
+ return asyncEffect((env, cb) => {
68
+ const scope = parentScope.subScope();
69
+ const results = new Array(effects.length);
70
+ let completed = 0;
71
+ let done = false;
72
+ effects.forEach((eff, i) => {
73
+ const f = scope.fork(eff);
74
+ f.join((exit) => {
75
+ if (done) return;
76
+ if (exit._tag === "Failure") {
77
+ done = true;
78
+ const errExit = {
79
+ _tag: "Failure",
80
+ cause: exit.cause
81
+ };
82
+ scope.close(errExit);
83
+ cb(errExit);
84
+ return;
85
+ }
86
+ results[i] = exit.value;
87
+ completed++;
88
+ if (completed === effects.length) {
89
+ done = true;
90
+ const successExit = {
91
+ _tag: "Success",
92
+ value: results
93
+ };
94
+ scope.close({ _tag: "Success", value: void 0 });
95
+ cb(successExit);
96
+ }
97
+ });
98
+ });
99
+ });
100
+ }
101
+ function raceWith(left, right, parentScope, onLeft, onRight) {
102
+ return asyncEffect((env, cb) => {
103
+ const scope = parentScope.subScope();
104
+ let done = false;
105
+ const fiberLeft = scope.fork(left);
106
+ const fiberRight = scope.fork(right);
107
+ const finish = (next) => {
108
+ scope.fork(next).join((exitNext) => {
109
+ scope.close(exitNext);
110
+ cb(exitNext);
111
+ });
112
+ };
113
+ fiberLeft.join((exitL) => {
114
+ if (done) return;
115
+ done = true;
116
+ finish(onLeft(exitL, fiberRight, scope));
117
+ });
118
+ fiberRight.join((exitR) => {
119
+ if (done) return;
120
+ done = true;
121
+ finish(onRight(exitR, fiberLeft, scope));
122
+ });
123
+ });
124
+ }
125
+
126
+ export {
127
+ race,
128
+ zipPar,
129
+ collectAllPar,
130
+ raceWith
131
+ };
@@ -0,0 +1,224 @@
1
+ import {
2
+ asyncEffect,
3
+ asyncFail,
4
+ asyncFlatMap,
5
+ asyncFold,
6
+ asyncSucceed,
7
+ unsafeGetCurrentRuntime
8
+ } from "./chunk-BDF4AMWX.mjs";
9
+
10
+ // src/core/runtime/combinators.ts
11
+ function sleep(ms) {
12
+ return asyncEffect((_env, cb) => {
13
+ const delay = Math.max(0, Math.floor(ms));
14
+ const id = setTimeout(() => cb({ _tag: "Success", value: void 0 }), delay);
15
+ return () => clearTimeout(id);
16
+ });
17
+ }
18
+ function timeout(effect, ms) {
19
+ return asyncEffect((env, cb) => {
20
+ let done = false;
21
+ let timerId;
22
+ let effectRunning = true;
23
+ timerId = setTimeout(() => {
24
+ if (done) return;
25
+ done = true;
26
+ effectRunning = false;
27
+ cb({
28
+ _tag: "Failure",
29
+ cause: { _tag: "Fail", error: { _tag: "TimeoutError", ms } }
30
+ });
31
+ }, Math.max(0, Math.floor(ms)));
32
+ const runtime = unsafeGetCurrentRuntime();
33
+ if (runtime) {
34
+ const fiber = runtime.fork(effect);
35
+ fiber.join((exit) => {
36
+ if (done) return;
37
+ done = true;
38
+ clearTimeout(timerId);
39
+ cb(exit);
40
+ });
41
+ return () => {
42
+ if (done) return;
43
+ done = true;
44
+ clearTimeout(timerId);
45
+ fiber.interrupt();
46
+ };
47
+ }
48
+ return () => {
49
+ if (done) return;
50
+ done = true;
51
+ clearTimeout(timerId);
52
+ };
53
+ });
54
+ }
55
+ function retry(effect, policy) {
56
+ const shouldRetry = policy.shouldRetry ?? (() => true);
57
+ const jitter = policy.jitter ?? "full";
58
+ const maxElapsedMs = policy.maxElapsedMs;
59
+ const computeDelay = (attempt) => {
60
+ const exp = policy.baseDelayMs * Math.pow(2, attempt);
61
+ const capped = Math.min(exp, policy.maxDelayMs);
62
+ if (jitter === "none") return capped;
63
+ return Math.floor(Math.random() * capped);
64
+ };
65
+ const loop = (attempt, startedAt) => asyncFold(
66
+ effect,
67
+ (error) => {
68
+ if (attempt >= policy.maxRetries) return asyncFail(error);
69
+ if (!shouldRetry(error, attempt)) return asyncFail(error);
70
+ if (maxElapsedMs !== void 0) {
71
+ const elapsed = performance.now() - startedAt;
72
+ if (elapsed >= maxElapsedMs) return asyncFail(error);
73
+ }
74
+ const delay = computeDelay(attempt);
75
+ return asyncFlatMap(sleep(delay), () => loop(attempt + 1, startedAt));
76
+ },
77
+ (value) => asyncSucceed(value)
78
+ );
79
+ return asyncFlatMap(
80
+ { _tag: "Sync", thunk: () => performance.now() },
81
+ (startedAt) => loop(0, startedAt)
82
+ );
83
+ }
84
+ function retryN(effect, n) {
85
+ return retry(effect, {
86
+ maxRetries: n,
87
+ baseDelayMs: 0,
88
+ maxDelayMs: 0,
89
+ jitter: "none"
90
+ });
91
+ }
92
+ function retryWithBackoff(effect, opts = {}) {
93
+ return retry(effect, {
94
+ maxRetries: opts.maxRetries ?? 3,
95
+ baseDelayMs: opts.baseDelayMs ?? 100,
96
+ maxDelayMs: opts.maxDelayMs ?? 1e4,
97
+ maxElapsedMs: opts.maxElapsedMs,
98
+ shouldRetry: opts.shouldRetry,
99
+ jitter: "full"
100
+ });
101
+ }
102
+
103
+ // src/core/runtime/circuitBreaker.ts
104
+ function makeCircuitBreaker(config = {}) {
105
+ const failureThreshold = config.failureThreshold ?? 5;
106
+ const resetTimeoutMs = config.resetTimeoutMs ?? 3e4;
107
+ const successThreshold = config.successThreshold ?? 1;
108
+ const isFailure = config.isFailure ?? (() => true);
109
+ const onStateChange = config.onStateChange;
110
+ let currentState = "closed";
111
+ let consecutiveFailures = 0;
112
+ let consecutiveSuccesses = 0;
113
+ let openedAt = 0;
114
+ let totalRequests = 0;
115
+ let totalFailures = 0;
116
+ let totalSuccesses = 0;
117
+ let totalRejected = 0;
118
+ let lastFailureTime = null;
119
+ let lastSuccessTime = null;
120
+ const transition = (to) => {
121
+ if (currentState === to) return;
122
+ const from = currentState;
123
+ currentState = to;
124
+ onStateChange?.(from, to);
125
+ };
126
+ const onSuccess = () => {
127
+ totalSuccesses++;
128
+ lastSuccessTime = Date.now();
129
+ consecutiveFailures = 0;
130
+ if (currentState === "half-open") {
131
+ consecutiveSuccesses++;
132
+ if (consecutiveSuccesses >= successThreshold) {
133
+ consecutiveSuccesses = 0;
134
+ transition("closed");
135
+ }
136
+ }
137
+ };
138
+ const onFailure = (error) => {
139
+ if (!isFailure(error)) {
140
+ onSuccess();
141
+ return;
142
+ }
143
+ totalFailures++;
144
+ lastFailureTime = Date.now();
145
+ consecutiveSuccesses = 0;
146
+ consecutiveFailures++;
147
+ if (currentState === "half-open") {
148
+ openedAt = Date.now();
149
+ transition("open");
150
+ } else if (currentState === "closed" && consecutiveFailures >= failureThreshold) {
151
+ openedAt = Date.now();
152
+ transition("open");
153
+ }
154
+ };
155
+ const shouldAllow = () => {
156
+ switch (currentState) {
157
+ case "closed":
158
+ return true;
159
+ case "open": {
160
+ const elapsed = Date.now() - openedAt;
161
+ if (elapsed >= resetTimeoutMs) {
162
+ transition("half-open");
163
+ return true;
164
+ }
165
+ return false;
166
+ }
167
+ case "half-open":
168
+ return true;
169
+ }
170
+ };
171
+ const protect = (effect) => {
172
+ totalRequests++;
173
+ if (!shouldAllow()) {
174
+ totalRejected++;
175
+ return asyncFail({
176
+ _tag: "CircuitBreakerOpen",
177
+ openSince: openedAt,
178
+ failures: consecutiveFailures
179
+ });
180
+ }
181
+ return asyncFold(
182
+ effect,
183
+ (error) => {
184
+ onFailure(error);
185
+ return asyncFail(error);
186
+ },
187
+ (value) => {
188
+ onSuccess();
189
+ return asyncSucceed(value);
190
+ }
191
+ );
192
+ };
193
+ const stats = () => ({
194
+ state: currentState,
195
+ failures: consecutiveFailures,
196
+ successes: consecutiveSuccesses,
197
+ totalRequests,
198
+ totalFailures,
199
+ totalSuccesses,
200
+ totalRejected,
201
+ lastFailureTime,
202
+ lastSuccessTime
203
+ });
204
+ const reset = () => {
205
+ consecutiveFailures = 0;
206
+ consecutiveSuccesses = 0;
207
+ transition("closed");
208
+ };
209
+ return {
210
+ state: () => currentState,
211
+ protect,
212
+ stats,
213
+ reset
214
+ };
215
+ }
216
+
217
+ export {
218
+ sleep,
219
+ timeout,
220
+ retry,
221
+ retryN,
222
+ retryWithBackoff,
223
+ makeCircuitBreaker
224
+ };