brass-runtime 1.14.0 → 1.16.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.
- package/README.md +410 -135
- package/dist/agent/cli/main.cjs +49 -43
- package/dist/agent/cli/main.js +11 -5
- package/dist/agent/cli/main.mjs +11 -5
- package/dist/agent/index.cjs +8 -3
- package/dist/agent/index.d.ts +1 -1
- package/dist/agent/index.js +7 -2
- package/dist/agent/index.mjs +7 -2
- package/dist/{chunk-BMRF4FN6.js → chunk-2WC63LJK.mjs} +68 -242
- package/dist/chunk-3RG5ZIWI.js +10 -0
- package/dist/chunk-45F7OKGT.cjs +104 -0
- package/dist/chunk-5YOQOXEQ.cjs +2491 -0
- package/dist/chunk-7HUOJA4W.cjs +493 -0
- package/dist/{chunk-4N2JEK4H.mjs → chunk-7LVI2GIN.js} +252 -495
- package/dist/chunk-7TL2LHQJ.js +2491 -0
- package/dist/chunk-7V4KY4RL.mjs +104 -0
- package/dist/chunk-7XOPAB5Q.js +2143 -0
- package/dist/chunk-CCKHV5BT.mjs +193 -0
- package/dist/chunk-CY33PGEX.mjs +1110 -0
- package/dist/chunk-DJQ7OMMB.cjs +144 -0
- package/dist/chunk-F5EUMJL7.mjs +2143 -0
- package/dist/chunk-FM4W4QPL.js +193 -0
- package/dist/chunk-G3XGCZDQ.js +131 -0
- package/dist/{chunk-JT7D6M5H.js → chunk-G6IQOE4P.mjs} +252 -495
- package/dist/chunk-GOV47PPB.mjs +552 -0
- package/dist/chunk-H55LI6WY.js +93 -0
- package/dist/chunk-IJT6RRQ5.cjs +93 -0
- package/dist/chunk-J3H54ZRV.mjs +131 -0
- package/dist/chunk-JF4XXPZ5.cjs +552 -0
- package/dist/chunk-JNFRRJYH.cjs +2143 -0
- package/dist/chunk-JX3LZQJH.cjs +354 -0
- package/dist/chunk-K2T3DV26.mjs +93 -0
- package/dist/chunk-KCPT2D6G.js +552 -0
- package/dist/chunk-MWXMNYJS.cjs +1110 -0
- package/dist/{chunk-XTMZTVIT.cjs → chunk-N6VHMOWB.cjs} +140 -134
- package/dist/{chunk-WJESVBWN.js → chunk-NC5SDRYE.js} +16 -10
- package/dist/chunk-NOYZIMUJ.mjs +144 -0
- package/dist/chunk-NYL4D7SK.cjs +131 -0
- package/dist/chunk-OBGZSXTJ.cjs +10 -0
- package/dist/{chunk-UWMMYKVK.mjs → chunk-OOGJ73B6.js} +68 -242
- package/dist/chunk-PNVFW245.js +144 -0
- package/dist/chunk-PRWCB3QL.mjs +2491 -0
- package/dist/chunk-QY5FKYEQ.js +1110 -0
- package/dist/chunk-ROJC3NBJ.js +104 -0
- package/dist/chunk-SPUEME2B.cjs +343 -0
- package/dist/chunk-TDVMADDN.js +343 -0
- package/dist/chunk-TVN5I4U6.cjs +193 -0
- package/dist/chunk-U5KWK3PX.mjs +343 -0
- package/dist/chunk-VFIUZG7J.mjs +354 -0
- package/dist/{chunk-BKBFSOGT.cjs → chunk-WQ5QNU5R.cjs} +460 -703
- package/dist/chunk-XDZOO4L5.js +354 -0
- package/dist/chunk-Y6FXYEAI.mjs +10 -0
- package/dist/{chunk-MQF7HZ7Y.mjs → chunk-ZGLD4TVZ.mjs} +16 -10
- package/dist/client-CtFmoDvM.d.ts +645 -0
- package/dist/core/index.cjs +284 -0
- package/dist/core/index.d.ts +567 -0
- package/dist/core/index.js +284 -0
- package/dist/core/index.mjs +284 -0
- package/dist/{effect-DM56H743.d.ts → effect-CGNl5Rqp.d.ts} +118 -11
- package/dist/effectRunner-3ZHAD3LE.cjs +8 -0
- package/dist/effectRunner-A4CHJXJI.js +8 -0
- package/dist/effectRunner-OPUF6QRN.mjs +8 -0
- package/dist/http/index.cjs +4130 -890
- package/dist/http/index.d.ts +2289 -219
- package/dist/http/index.js +4116 -876
- package/dist/http/index.mjs +4116 -876
- package/dist/http/testing.cjs +159 -0
- package/dist/http/testing.d.ts +42 -0
- package/dist/http/testing.js +159 -0
- package/dist/http/testing.mjs +159 -0
- package/dist/index.cjs +305 -1168
- package/dist/index.d.ts +9 -701
- package/dist/index.js +176 -1039
- package/dist/index.mjs +176 -1039
- package/dist/observability/index.cjs +677 -0
- package/dist/observability/index.d.ts +79 -0
- package/dist/observability/index.js +677 -0
- package/dist/observability/index.mjs +677 -0
- package/dist/schedule-Fque9Abz.d.ts +70 -0
- package/dist/schema/index.cjs +25 -0
- package/dist/schema/index.d.ts +177 -0
- package/dist/schema/index.js +25 -0
- package/dist/schema/index.mjs +25 -0
- package/dist/server-C8hDXA74.d.ts +674 -0
- package/dist/stream-dvSs0QS5.d.ts +74 -0
- package/dist/tracer-B5tRH9H7.d.ts +230 -0
- package/dist/tracing-Dt9S_6V8.d.ts +148 -0
- package/package.json +37 -3
- package/dist/chunk-SKVY72E5.cjs +0 -667
- package/dist/stream-Oqe6WeLE.d.ts +0 -173
|
@@ -1,8 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
raceWith
|
|
3
|
+
} from "./chunk-J3H54ZRV.mjs";
|
|
4
|
+
import {
|
|
5
|
+
Scope
|
|
6
|
+
} from "./chunk-CCKHV5BT.mjs";
|
|
7
|
+
import {
|
|
8
|
+
getCurrentFiber,
|
|
9
|
+
unsafeGetCurrentRuntime,
|
|
10
|
+
unsafeRunFoldWithEnv
|
|
11
|
+
} from "./chunk-G6IQOE4P.mjs";
|
|
1
12
|
import {
|
|
2
13
|
Cause,
|
|
3
14
|
Exit,
|
|
4
|
-
|
|
5
|
-
async,
|
|
15
|
+
asyncEffect,
|
|
6
16
|
asyncFail,
|
|
7
17
|
asyncFlatMap,
|
|
8
18
|
asyncFold,
|
|
@@ -11,225 +21,14 @@ import {
|
|
|
11
21
|
asyncSync,
|
|
12
22
|
fail,
|
|
13
23
|
flatMap,
|
|
14
|
-
getCurrentFiber,
|
|
15
24
|
map,
|
|
16
25
|
mapError,
|
|
17
26
|
none,
|
|
18
27
|
orElseOptional,
|
|
19
|
-
raceWith,
|
|
20
28
|
some,
|
|
21
29
|
succeed,
|
|
22
|
-
sync
|
|
23
|
-
|
|
24
|
-
unsafeRunFoldWithEnv
|
|
25
|
-
} from "./chunk-JT7D6M5H.js";
|
|
26
|
-
|
|
27
|
-
// src/core/runtime/combinators.ts
|
|
28
|
-
function sleep(ms) {
|
|
29
|
-
return async((_env, cb) => {
|
|
30
|
-
const delay = Math.max(0, Math.floor(ms));
|
|
31
|
-
const id = setTimeout(() => cb({ _tag: "Success", value: void 0 }), delay);
|
|
32
|
-
return () => clearTimeout(id);
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
function timeout(effect, ms) {
|
|
36
|
-
return async((env, cb) => {
|
|
37
|
-
let done = false;
|
|
38
|
-
let timerId;
|
|
39
|
-
let effectRunning = true;
|
|
40
|
-
timerId = setTimeout(() => {
|
|
41
|
-
if (done) return;
|
|
42
|
-
done = true;
|
|
43
|
-
effectRunning = false;
|
|
44
|
-
cb({
|
|
45
|
-
_tag: "Failure",
|
|
46
|
-
cause: { _tag: "Fail", error: { _tag: "TimeoutError", ms } }
|
|
47
|
-
});
|
|
48
|
-
}, Math.max(0, Math.floor(ms)));
|
|
49
|
-
const runtime = unsafeGetCurrentRuntime();
|
|
50
|
-
if (runtime) {
|
|
51
|
-
const fiber = runtime.fork(effect);
|
|
52
|
-
fiber.join((exit) => {
|
|
53
|
-
if (done) return;
|
|
54
|
-
done = true;
|
|
55
|
-
clearTimeout(timerId);
|
|
56
|
-
cb(exit);
|
|
57
|
-
});
|
|
58
|
-
return () => {
|
|
59
|
-
if (done) return;
|
|
60
|
-
done = true;
|
|
61
|
-
clearTimeout(timerId);
|
|
62
|
-
fiber.interrupt();
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
return () => {
|
|
66
|
-
if (done) return;
|
|
67
|
-
done = true;
|
|
68
|
-
clearTimeout(timerId);
|
|
69
|
-
};
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
function retry(effect, policy) {
|
|
73
|
-
const shouldRetry = policy.shouldRetry ?? (() => true);
|
|
74
|
-
const jitter = policy.jitter ?? "full";
|
|
75
|
-
const maxElapsedMs = policy.maxElapsedMs;
|
|
76
|
-
const computeDelay = (attempt) => {
|
|
77
|
-
const exp = policy.baseDelayMs * Math.pow(2, attempt);
|
|
78
|
-
const capped = Math.min(exp, policy.maxDelayMs);
|
|
79
|
-
if (jitter === "none") return capped;
|
|
80
|
-
return Math.floor(Math.random() * capped);
|
|
81
|
-
};
|
|
82
|
-
const loop = (attempt, startedAt) => asyncFold(
|
|
83
|
-
effect,
|
|
84
|
-
(error) => {
|
|
85
|
-
if (attempt >= policy.maxRetries) return asyncFail(error);
|
|
86
|
-
if (!shouldRetry(error, attempt)) return asyncFail(error);
|
|
87
|
-
if (maxElapsedMs !== void 0) {
|
|
88
|
-
const elapsed = performance.now() - startedAt;
|
|
89
|
-
if (elapsed >= maxElapsedMs) return asyncFail(error);
|
|
90
|
-
}
|
|
91
|
-
const delay = computeDelay(attempt);
|
|
92
|
-
return asyncFlatMap(sleep(delay), () => loop(attempt + 1, startedAt));
|
|
93
|
-
},
|
|
94
|
-
(value) => asyncSucceed(value)
|
|
95
|
-
);
|
|
96
|
-
return asyncFlatMap(
|
|
97
|
-
{ _tag: "Sync", thunk: () => performance.now() },
|
|
98
|
-
(startedAt) => loop(0, startedAt)
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
function retryN(effect, n) {
|
|
102
|
-
return retry(effect, {
|
|
103
|
-
maxRetries: n,
|
|
104
|
-
baseDelayMs: 0,
|
|
105
|
-
maxDelayMs: 0,
|
|
106
|
-
jitter: "none"
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
function retryWithBackoff(effect, opts = {}) {
|
|
110
|
-
return retry(effect, {
|
|
111
|
-
maxRetries: opts.maxRetries ?? 3,
|
|
112
|
-
baseDelayMs: opts.baseDelayMs ?? 100,
|
|
113
|
-
maxDelayMs: opts.maxDelayMs ?? 1e4,
|
|
114
|
-
maxElapsedMs: opts.maxElapsedMs,
|
|
115
|
-
shouldRetry: opts.shouldRetry,
|
|
116
|
-
jitter: "full"
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// src/core/runtime/circuitBreaker.ts
|
|
121
|
-
function makeCircuitBreaker(config = {}) {
|
|
122
|
-
const failureThreshold = config.failureThreshold ?? 5;
|
|
123
|
-
const resetTimeoutMs = config.resetTimeoutMs ?? 3e4;
|
|
124
|
-
const successThreshold = config.successThreshold ?? 1;
|
|
125
|
-
const isFailure = config.isFailure ?? (() => true);
|
|
126
|
-
const onStateChange = config.onStateChange;
|
|
127
|
-
let currentState = "closed";
|
|
128
|
-
let consecutiveFailures = 0;
|
|
129
|
-
let consecutiveSuccesses = 0;
|
|
130
|
-
let openedAt = 0;
|
|
131
|
-
let totalRequests = 0;
|
|
132
|
-
let totalFailures = 0;
|
|
133
|
-
let totalSuccesses = 0;
|
|
134
|
-
let totalRejected = 0;
|
|
135
|
-
let lastFailureTime = null;
|
|
136
|
-
let lastSuccessTime = null;
|
|
137
|
-
const transition = (to) => {
|
|
138
|
-
if (currentState === to) return;
|
|
139
|
-
const from = currentState;
|
|
140
|
-
currentState = to;
|
|
141
|
-
onStateChange?.(from, to);
|
|
142
|
-
};
|
|
143
|
-
const onSuccess = () => {
|
|
144
|
-
totalSuccesses++;
|
|
145
|
-
lastSuccessTime = Date.now();
|
|
146
|
-
consecutiveFailures = 0;
|
|
147
|
-
if (currentState === "half-open") {
|
|
148
|
-
consecutiveSuccesses++;
|
|
149
|
-
if (consecutiveSuccesses >= successThreshold) {
|
|
150
|
-
consecutiveSuccesses = 0;
|
|
151
|
-
transition("closed");
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
const onFailure = (error) => {
|
|
156
|
-
if (!isFailure(error)) {
|
|
157
|
-
onSuccess();
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
totalFailures++;
|
|
161
|
-
lastFailureTime = Date.now();
|
|
162
|
-
consecutiveSuccesses = 0;
|
|
163
|
-
consecutiveFailures++;
|
|
164
|
-
if (currentState === "half-open") {
|
|
165
|
-
openedAt = Date.now();
|
|
166
|
-
transition("open");
|
|
167
|
-
} else if (currentState === "closed" && consecutiveFailures >= failureThreshold) {
|
|
168
|
-
openedAt = Date.now();
|
|
169
|
-
transition("open");
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
const shouldAllow = () => {
|
|
173
|
-
switch (currentState) {
|
|
174
|
-
case "closed":
|
|
175
|
-
return true;
|
|
176
|
-
case "open": {
|
|
177
|
-
const elapsed = Date.now() - openedAt;
|
|
178
|
-
if (elapsed >= resetTimeoutMs) {
|
|
179
|
-
transition("half-open");
|
|
180
|
-
return true;
|
|
181
|
-
}
|
|
182
|
-
return false;
|
|
183
|
-
}
|
|
184
|
-
case "half-open":
|
|
185
|
-
return true;
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
const protect = (effect) => {
|
|
189
|
-
totalRequests++;
|
|
190
|
-
if (!shouldAllow()) {
|
|
191
|
-
totalRejected++;
|
|
192
|
-
return asyncFail({
|
|
193
|
-
_tag: "CircuitBreakerOpen",
|
|
194
|
-
openSince: openedAt,
|
|
195
|
-
failures: consecutiveFailures
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
return asyncFold(
|
|
199
|
-
effect,
|
|
200
|
-
(error) => {
|
|
201
|
-
onFailure(error);
|
|
202
|
-
return asyncFail(error);
|
|
203
|
-
},
|
|
204
|
-
(value) => {
|
|
205
|
-
onSuccess();
|
|
206
|
-
return asyncSucceed(value);
|
|
207
|
-
}
|
|
208
|
-
);
|
|
209
|
-
};
|
|
210
|
-
const stats = () => ({
|
|
211
|
-
state: currentState,
|
|
212
|
-
failures: consecutiveFailures,
|
|
213
|
-
successes: consecutiveSuccesses,
|
|
214
|
-
totalRequests,
|
|
215
|
-
totalFailures,
|
|
216
|
-
totalSuccesses,
|
|
217
|
-
totalRejected,
|
|
218
|
-
lastFailureTime,
|
|
219
|
-
lastSuccessTime
|
|
220
|
-
});
|
|
221
|
-
const reset = () => {
|
|
222
|
-
consecutiveFailures = 0;
|
|
223
|
-
consecutiveSuccesses = 0;
|
|
224
|
-
transition("closed");
|
|
225
|
-
};
|
|
226
|
-
return {
|
|
227
|
-
state: () => currentState,
|
|
228
|
-
protect,
|
|
229
|
-
stats,
|
|
230
|
-
reset
|
|
231
|
-
};
|
|
232
|
-
}
|
|
30
|
+
sync
|
|
31
|
+
} from "./chunk-NOYZIMUJ.mjs";
|
|
233
32
|
|
|
234
33
|
// src/core/stream/stream.ts
|
|
235
34
|
var widenOpt = (opt) => opt._tag === "None" ? none : some(opt.value);
|
|
@@ -280,7 +79,7 @@ function streamToRaceWithHandler(winnerSide, leftStream, rightStream, flip, id)
|
|
|
280
79
|
return asyncSucceed([a, next]);
|
|
281
80
|
}
|
|
282
81
|
if (exit.cause._tag === "Interrupt") {
|
|
283
|
-
return
|
|
82
|
+
return asyncEffect((_env, cb) => {
|
|
284
83
|
cb(Exit.failCause(Cause.interrupt()));
|
|
285
84
|
});
|
|
286
85
|
}
|
|
@@ -295,7 +94,7 @@ function makeMergePull(onLeft, onRight, flip, mergePullId) {
|
|
|
295
94
|
const id = ++mergePullId;
|
|
296
95
|
const onLeftHandler = streamToRaceWithHandler("L", onLeft, onRight, flip, id);
|
|
297
96
|
const onRightHandler = streamToRaceWithHandler("R", onLeft, onRight, flip, id);
|
|
298
|
-
return
|
|
97
|
+
return asyncEffect((_env, cb) => {
|
|
299
98
|
const runtime = unsafeGetCurrentRuntime();
|
|
300
99
|
const scope = new Scope(runtime);
|
|
301
100
|
const handler = raceWith(
|
|
@@ -356,7 +155,7 @@ function uncons(self) {
|
|
|
356
155
|
case "Merge":
|
|
357
156
|
return makeMergePull(self.left, self.right, self.flip, 0);
|
|
358
157
|
case "Scoped":
|
|
359
|
-
return
|
|
158
|
+
return asyncEffect((env, cb) => {
|
|
360
159
|
const runtime = unsafeGetCurrentRuntime();
|
|
361
160
|
const scope = new Scope(runtime);
|
|
362
161
|
const fiber = getCurrentFiber();
|
|
@@ -377,7 +176,7 @@ function uncons(self) {
|
|
|
377
176
|
scope.close(exit);
|
|
378
177
|
};
|
|
379
178
|
const wrap = (s) => fromPull(
|
|
380
|
-
|
|
179
|
+
asyncEffect((env2, cb2) => {
|
|
381
180
|
const pull = uncons(s);
|
|
382
181
|
unsafeRunFoldWithEnv(
|
|
383
182
|
pull,
|
|
@@ -405,7 +204,7 @@ function uncons(self) {
|
|
|
405
204
|
});
|
|
406
205
|
});
|
|
407
206
|
case "Managed":
|
|
408
|
-
return
|
|
207
|
+
return asyncEffect((env, cb) => {
|
|
409
208
|
const runtime = unsafeGetCurrentRuntime();
|
|
410
209
|
const scope = new Scope(runtime);
|
|
411
210
|
getCurrentFiber()?.addFinalizer((exit) => {
|
|
@@ -433,16 +232,19 @@ function uncons(self) {
|
|
|
433
232
|
const { stream: inner, release } = ex.value;
|
|
434
233
|
scope.addFinalizer((exit) => release(exit));
|
|
435
234
|
const wrap = (s) => fromPull(
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
235
|
+
asyncEffect((env2, cb2) => {
|
|
236
|
+
unsafeRunFoldWithEnv(
|
|
237
|
+
uncons(s),
|
|
238
|
+
env2,
|
|
239
|
+
(cause) => {
|
|
240
|
+
const ex2 = Exit.failCause(cause);
|
|
439
241
|
closeWith(ex2);
|
|
440
242
|
cb2(ex2);
|
|
441
|
-
|
|
243
|
+
},
|
|
244
|
+
([a, tail]) => {
|
|
245
|
+
cb2(Exit.succeed([a, wrap(tail)]));
|
|
442
246
|
}
|
|
443
|
-
|
|
444
|
-
cb2(Exit.succeed([a, wrap(tail)]));
|
|
445
|
-
});
|
|
247
|
+
);
|
|
446
248
|
})
|
|
447
249
|
);
|
|
448
250
|
unsafeGetCurrentRuntime().fork(uncons(wrap(inner))).join(cb);
|
|
@@ -602,49 +404,73 @@ function drainStreamSyncFull(stream) {
|
|
|
602
404
|
}
|
|
603
405
|
}
|
|
604
406
|
}
|
|
605
|
-
function readerStream(reader, normalizeError) {
|
|
606
|
-
const pull =
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
407
|
+
function readerStream(reader, normalizeError, signal) {
|
|
408
|
+
const pull = asyncEffect((_, cb) => {
|
|
409
|
+
let done = false;
|
|
410
|
+
const cleanup = () => signal?.removeEventListener("abort", abort);
|
|
411
|
+
const finish = (exit) => {
|
|
412
|
+
if (done) return;
|
|
413
|
+
done = true;
|
|
414
|
+
cleanup();
|
|
415
|
+
cb(exit);
|
|
416
|
+
};
|
|
417
|
+
const abort = () => {
|
|
418
|
+
try {
|
|
419
|
+
reader.cancel();
|
|
420
|
+
} catch {
|
|
421
|
+
}
|
|
422
|
+
const error = typeof DOMException === "function" ? new DOMException("aborted", "AbortError") : new Error("aborted");
|
|
423
|
+
finish({ _tag: "Failure", cause: { _tag: "Fail", error: some(normalizeError(error)) } });
|
|
424
|
+
};
|
|
425
|
+
if (signal?.aborted) {
|
|
426
|
+
abort();
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
430
|
+
reader.read().then(({ done: done2, value }) => {
|
|
431
|
+
if (done2) {
|
|
432
|
+
finish({ _tag: "Failure", cause: { _tag: "Fail", error: none } });
|
|
610
433
|
return;
|
|
611
434
|
}
|
|
612
|
-
|
|
435
|
+
finish({
|
|
613
436
|
_tag: "Success",
|
|
614
437
|
value: [value, fromPull(pull)]
|
|
615
438
|
});
|
|
616
439
|
}).catch((e) => {
|
|
617
|
-
|
|
440
|
+
finish({ _tag: "Failure", cause: { _tag: "Fail", error: some(normalizeError(e)) } });
|
|
618
441
|
});
|
|
442
|
+
return () => {
|
|
443
|
+
cleanup();
|
|
444
|
+
try {
|
|
445
|
+
reader.cancel();
|
|
446
|
+
} catch {
|
|
447
|
+
}
|
|
448
|
+
};
|
|
619
449
|
});
|
|
620
450
|
return fromPull(pull);
|
|
621
451
|
}
|
|
622
|
-
function streamFromReadableStream(body, normalizeError) {
|
|
452
|
+
function streamFromReadableStream(body, normalizeError, options = {}) {
|
|
623
453
|
if (!body) return emptyStream();
|
|
624
454
|
let reader;
|
|
625
455
|
return unwrapScoped(
|
|
626
456
|
// acquire: produce un ZStream
|
|
627
457
|
sync(() => {
|
|
628
458
|
reader = body.getReader();
|
|
629
|
-
return readerStream(reader, normalizeError);
|
|
459
|
+
return readerStream(reader, normalizeError, options.signal);
|
|
630
460
|
}),
|
|
631
461
|
// release: se corre en fin / error / interrupción
|
|
632
462
|
() => asyncSync(() => {
|
|
633
463
|
try {
|
|
634
464
|
reader?.cancel();
|
|
635
465
|
} catch {
|
|
466
|
+
} finally {
|
|
467
|
+
options.onRelease?.();
|
|
636
468
|
}
|
|
637
469
|
})
|
|
638
470
|
);
|
|
639
471
|
}
|
|
640
472
|
|
|
641
473
|
export {
|
|
642
|
-
sleep,
|
|
643
|
-
timeout,
|
|
644
|
-
retry,
|
|
645
|
-
retryN,
|
|
646
|
-
retryWithBackoff,
|
|
647
|
-
makeCircuitBreaker,
|
|
648
474
|
widenOpt,
|
|
649
475
|
fromPull,
|
|
650
476
|
unwrapScoped,
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
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
|
+
export {
|
|
9
|
+
__require
|
|
10
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
|
+
|
|
3
|
+
var _chunkWQ5QNU5Rcjs = require('./chunk-WQ5QNU5R.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
var _chunkDJQ7OMMBcjs = require('./chunk-DJQ7OMMB.cjs');
|
|
11
|
+
|
|
12
|
+
// src/core/runtime/combinators.ts
|
|
13
|
+
function sleep(ms) {
|
|
14
|
+
return _chunkDJQ7OMMBcjs.asyncEffect.call(void 0, (_env, cb) => {
|
|
15
|
+
const delay = Math.max(0, Math.floor(ms));
|
|
16
|
+
const id = setTimeout(() => cb({ _tag: "Success", value: void 0 }), delay);
|
|
17
|
+
return () => clearTimeout(id);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function timeout(effect, ms) {
|
|
21
|
+
return _chunkDJQ7OMMBcjs.asyncEffect.call(void 0, (env, cb) => {
|
|
22
|
+
let done = false;
|
|
23
|
+
let timerId;
|
|
24
|
+
let effectRunning = true;
|
|
25
|
+
timerId = setTimeout(() => {
|
|
26
|
+
if (done) return;
|
|
27
|
+
done = true;
|
|
28
|
+
effectRunning = false;
|
|
29
|
+
cb({
|
|
30
|
+
_tag: "Failure",
|
|
31
|
+
cause: { _tag: "Fail", error: { _tag: "TimeoutError", ms } }
|
|
32
|
+
});
|
|
33
|
+
}, Math.max(0, Math.floor(ms)));
|
|
34
|
+
const runtime = _chunkWQ5QNU5Rcjs.unsafeGetCurrentRuntime.call(void 0, );
|
|
35
|
+
const fiber = runtime.fork(effect);
|
|
36
|
+
fiber.join((exit) => {
|
|
37
|
+
if (done) return;
|
|
38
|
+
done = true;
|
|
39
|
+
clearTimeout(timerId);
|
|
40
|
+
cb(exit);
|
|
41
|
+
});
|
|
42
|
+
return () => {
|
|
43
|
+
if (done) return;
|
|
44
|
+
done = true;
|
|
45
|
+
clearTimeout(timerId);
|
|
46
|
+
fiber.interrupt();
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
function retry(effect, policy) {
|
|
51
|
+
const shouldRetry = _nullishCoalesce(policy.shouldRetry, () => ( (() => true)));
|
|
52
|
+
const jitter = _nullishCoalesce(policy.jitter, () => ( "full"));
|
|
53
|
+
const maxElapsedMs = policy.maxElapsedMs;
|
|
54
|
+
const computeDelay = (attempt) => {
|
|
55
|
+
const exp = policy.baseDelayMs * Math.pow(2, attempt);
|
|
56
|
+
const capped = Math.min(exp, policy.maxDelayMs);
|
|
57
|
+
if (jitter === "none") return capped;
|
|
58
|
+
return Math.floor(Math.random() * capped);
|
|
59
|
+
};
|
|
60
|
+
const loop = (attempt, startedAt) => _chunkDJQ7OMMBcjs.asyncFold.call(void 0,
|
|
61
|
+
effect,
|
|
62
|
+
(error) => {
|
|
63
|
+
if (attempt >= policy.maxRetries) return _chunkDJQ7OMMBcjs.asyncFail.call(void 0, error);
|
|
64
|
+
if (!shouldRetry(error, attempt)) return _chunkDJQ7OMMBcjs.asyncFail.call(void 0, error);
|
|
65
|
+
if (maxElapsedMs !== void 0) {
|
|
66
|
+
const elapsed = performance.now() - startedAt;
|
|
67
|
+
if (elapsed >= maxElapsedMs) return _chunkDJQ7OMMBcjs.asyncFail.call(void 0, error);
|
|
68
|
+
}
|
|
69
|
+
const delay = computeDelay(attempt);
|
|
70
|
+
return _chunkDJQ7OMMBcjs.asyncFlatMap.call(void 0, sleep(delay), () => loop(attempt + 1, startedAt));
|
|
71
|
+
},
|
|
72
|
+
(value) => _chunkDJQ7OMMBcjs.asyncSucceed.call(void 0, value)
|
|
73
|
+
);
|
|
74
|
+
return _chunkDJQ7OMMBcjs.asyncFlatMap.call(void 0,
|
|
75
|
+
{ _tag: "Sync", thunk: () => performance.now() },
|
|
76
|
+
(startedAt) => loop(0, startedAt)
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
function retryN(effect, n) {
|
|
80
|
+
return retry(effect, {
|
|
81
|
+
maxRetries: n,
|
|
82
|
+
baseDelayMs: 0,
|
|
83
|
+
maxDelayMs: 0,
|
|
84
|
+
jitter: "none"
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
function retryWithBackoff(effect, opts = {}) {
|
|
88
|
+
return retry(effect, {
|
|
89
|
+
maxRetries: _nullishCoalesce(opts.maxRetries, () => ( 3)),
|
|
90
|
+
baseDelayMs: _nullishCoalesce(opts.baseDelayMs, () => ( 100)),
|
|
91
|
+
maxDelayMs: _nullishCoalesce(opts.maxDelayMs, () => ( 1e4)),
|
|
92
|
+
maxElapsedMs: opts.maxElapsedMs,
|
|
93
|
+
shouldRetry: opts.shouldRetry,
|
|
94
|
+
jitter: "full"
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
exports.sleep = sleep; exports.timeout = timeout; exports.retry = retry; exports.retryN = retryN; exports.retryWithBackoff = retryWithBackoff;
|