brass-runtime 1.13.8 → 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.
- package/README.md +6 -3
- package/dist/agent/cli/main.cjs +44 -43
- package/dist/agent/cli/main.js +5 -4
- package/dist/agent/cli/main.mjs +5 -4
- package/dist/agent/index.cjs +4 -3
- package/dist/agent/index.d.ts +1 -1
- package/dist/agent/index.js +3 -2
- package/dist/agent/index.mjs +3 -2
- package/dist/{chunk-3R7ZYRK2.mjs → chunk-3QMOKAS5.js} +9 -7
- package/dist/{chunk-ATHSSDUF.js → chunk-4NHES7VK.mjs} +113 -31
- package/dist/chunk-AR22SXML.js +1043 -0
- package/dist/chunk-BDF4AMWX.mjs +3773 -0
- package/dist/chunk-BDYEENHT.js +224 -0
- package/dist/chunk-BMH5AV44.js +3773 -0
- package/dist/chunk-ELOOF35R.mjs +131 -0
- package/dist/chunk-JFPU5GQI.mjs +1043 -0
- package/dist/{chunk-INZBKOHY.js → chunk-K6M7MDZ4.mjs} +9 -7
- package/dist/chunk-MS34J5LY.cjs +224 -0
- package/dist/{chunk-XNOTJSMZ.mjs → chunk-PPUXIH5R.js} +113 -31
- package/dist/chunk-R3R2FVLG.cjs +131 -0
- package/dist/{chunk-ZTDK2DLG.cjs → chunk-STVLQ3XD.cjs} +169 -87
- package/dist/chunk-TGIFUAK4.cjs +3773 -0
- package/dist/chunk-TO7IKXYT.js +131 -0
- package/dist/chunk-UMAZLXAB.mjs +224 -0
- package/dist/{chunk-XDINDYNA.cjs → chunk-VEZNF5GZ.cjs} +136 -134
- package/dist/chunk-XPZNXSVN.cjs +1043 -0
- package/dist/core/index.cjs +216 -0
- package/dist/core/index.d.ts +673 -0
- package/dist/core/index.js +216 -0
- package/dist/core/index.mjs +216 -0
- package/dist/{effect-ISvXPLgc.d.ts → effect-CMOQKX8y.d.ts} +202 -31
- package/dist/http/index.cjs +3177 -187
- package/dist/http/index.d.ts +1692 -9
- package/dist/http/index.js +3164 -174
- package/dist/http/index.mjs +3164 -174
- package/dist/index.cjs +936 -219
- package/dist/index.d.ts +313 -36
- package/dist/index.js +830 -113
- package/dist/index.mjs +830 -113
- package/dist/{stream-BvukHxCv.d.ts → stream-FQm9h4Mg.d.ts} +12 -4
- package/dist/tracing-DNT9jEbr.d.ts +106 -0
- package/package.json +11 -3
- package/wasm/pkg/brass_runtime_wasm_engine.d.ts +95 -16
- package/wasm/pkg/brass_runtime_wasm_engine.js +715 -15
- package/wasm/pkg/brass_runtime_wasm_engine_bg.wasm +0 -0
- package/wasm/pkg/brass_runtime_wasm_engine_bg.wasm.d.ts +78 -7
- package/dist/chunk-2P4PD6D7.cjs +0 -2557
- package/dist/chunk-7F2R7A2V.mjs +0 -2557
- package/dist/chunk-L6KKKM66.js +0 -2557
|
@@ -1,5 +1,6 @@
|
|
|
1
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; }
|
|
2
2
|
|
|
3
|
+
var _chunkR3R2FVLGcjs = require('./chunk-R3R2FVLG.cjs');
|
|
3
4
|
|
|
4
5
|
|
|
5
6
|
|
|
@@ -22,10 +23,11 @@
|
|
|
22
23
|
|
|
23
24
|
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
|
|
27
|
+
var _chunkTGIFUAK4cjs = require('./chunk-TGIFUAK4.cjs');
|
|
26
28
|
|
|
27
29
|
// src/core/stream/stream.ts
|
|
28
|
-
var widenOpt = (opt) => opt._tag === "None" ?
|
|
30
|
+
var widenOpt = (opt) => opt._tag === "None" ? _chunkTGIFUAK4cjs.none : _chunkTGIFUAK4cjs.some.call(void 0, opt.value);
|
|
29
31
|
var fromPull = (pull) => ({
|
|
30
32
|
_tag: "FromPull",
|
|
31
33
|
pull
|
|
@@ -70,28 +72,28 @@ function streamToRaceWithHandler(winnerSide, leftStream, rightStream, flip, id)
|
|
|
70
72
|
const [a, tailWin] = exit.value;
|
|
71
73
|
otherFiber.interrupt();
|
|
72
74
|
const next = winnerSide === "L" ? fromPull(makeMergePull(tailWin, rightStream, !flip, id)) : fromPull(makeMergePull(leftStream, tailWin, !flip, id));
|
|
73
|
-
return
|
|
75
|
+
return _chunkTGIFUAK4cjs.asyncSucceed.call(void 0, [a, next]);
|
|
74
76
|
}
|
|
75
77
|
if (exit.cause._tag === "Interrupt") {
|
|
76
|
-
return
|
|
77
|
-
cb(
|
|
78
|
+
return _chunkTGIFUAK4cjs.asyncEffect.call(void 0, (_env, cb) => {
|
|
79
|
+
cb(_chunkTGIFUAK4cjs.Exit.failCause(_chunkTGIFUAK4cjs.Cause.interrupt()));
|
|
78
80
|
});
|
|
79
81
|
}
|
|
80
82
|
const opt = exit.cause.error;
|
|
81
83
|
if (opt._tag === "None") {
|
|
82
84
|
return winnerSide === "L" ? uncons(rightStream) : uncons(leftStream);
|
|
83
85
|
}
|
|
84
|
-
return
|
|
86
|
+
return _chunkTGIFUAK4cjs.asyncFail.call(void 0, opt);
|
|
85
87
|
};
|
|
86
88
|
}
|
|
87
89
|
function makeMergePull(onLeft, onRight, flip, mergePullId) {
|
|
88
90
|
const id = ++mergePullId;
|
|
89
91
|
const onLeftHandler = streamToRaceWithHandler("L", onLeft, onRight, flip, id);
|
|
90
92
|
const onRightHandler = streamToRaceWithHandler("R", onLeft, onRight, flip, id);
|
|
91
|
-
return
|
|
92
|
-
const runtime =
|
|
93
|
-
const scope = new (0,
|
|
94
|
-
const handler =
|
|
93
|
+
return _chunkTGIFUAK4cjs.asyncEffect.call(void 0, (_env, cb) => {
|
|
94
|
+
const runtime = _chunkTGIFUAK4cjs.unsafeGetCurrentRuntime.call(void 0, );
|
|
95
|
+
const scope = new (0, _chunkTGIFUAK4cjs.Scope)(runtime);
|
|
96
|
+
const handler = _chunkR3R2FVLGcjs.raceWith.call(void 0,
|
|
95
97
|
uncons(onLeft),
|
|
96
98
|
uncons(onRight),
|
|
97
99
|
scope,
|
|
@@ -110,27 +112,33 @@ function merge(left, right) {
|
|
|
110
112
|
function uncons(self) {
|
|
111
113
|
switch (self._tag) {
|
|
112
114
|
case "Empty":
|
|
113
|
-
return
|
|
115
|
+
return _chunkTGIFUAK4cjs.fail.call(void 0, _chunkTGIFUAK4cjs.none);
|
|
116
|
+
case "FromArray": {
|
|
117
|
+
const arr = self.values;
|
|
118
|
+
if (arr.length === 0) return _chunkTGIFUAK4cjs.fail.call(void 0, _chunkTGIFUAK4cjs.none);
|
|
119
|
+
const tail = arr.length === 1 ? EMPTY_STREAM : { _tag: "FromArray", values: arr.slice(1) };
|
|
120
|
+
return _chunkTGIFUAK4cjs.succeed.call(void 0, [arr[0], tail]);
|
|
121
|
+
}
|
|
114
122
|
case "Emit":
|
|
115
|
-
return
|
|
116
|
-
|
|
123
|
+
return _chunkTGIFUAK4cjs.map.call(void 0,
|
|
124
|
+
_chunkTGIFUAK4cjs.mapError.call(void 0, self.value, (e) => _chunkTGIFUAK4cjs.some.call(void 0, e)),
|
|
117
125
|
(a) => [a, EMPTY_STREAM]
|
|
118
126
|
);
|
|
119
127
|
case "FromPull":
|
|
120
128
|
return self.pull;
|
|
121
129
|
case "Concat":
|
|
122
|
-
return
|
|
123
|
-
|
|
130
|
+
return _chunkTGIFUAK4cjs.orElseOptional.call(void 0,
|
|
131
|
+
_chunkTGIFUAK4cjs.map.call(void 0,
|
|
124
132
|
uncons(self.left),
|
|
125
133
|
([a, tail]) => [a, concatStream(tail, self.right)]
|
|
126
134
|
),
|
|
127
135
|
() => uncons(self.right)
|
|
128
136
|
);
|
|
129
137
|
case "Flatten":
|
|
130
|
-
return
|
|
138
|
+
return _chunkTGIFUAK4cjs.flatMap.call(void 0,
|
|
131
139
|
uncons(self.stream),
|
|
132
|
-
([head, tail]) =>
|
|
133
|
-
|
|
140
|
+
([head, tail]) => _chunkTGIFUAK4cjs.orElseOptional.call(void 0,
|
|
141
|
+
_chunkTGIFUAK4cjs.map.call(void 0,
|
|
134
142
|
uncons(head),
|
|
135
143
|
([a, as]) => [
|
|
136
144
|
a,
|
|
@@ -143,10 +151,10 @@ function uncons(self) {
|
|
|
143
151
|
case "Merge":
|
|
144
152
|
return makeMergePull(self.left, self.right, self.flip, 0);
|
|
145
153
|
case "Scoped":
|
|
146
|
-
return
|
|
147
|
-
const runtime =
|
|
148
|
-
const scope = new (0,
|
|
149
|
-
const fiber =
|
|
154
|
+
return _chunkTGIFUAK4cjs.asyncEffect.call(void 0, (env, cb) => {
|
|
155
|
+
const runtime = _chunkTGIFUAK4cjs.unsafeGetCurrentRuntime.call(void 0, );
|
|
156
|
+
const scope = new (0, _chunkTGIFUAK4cjs.Scope)(runtime);
|
|
157
|
+
const fiber = _chunkTGIFUAK4cjs.getCurrentFiber.call(void 0, );
|
|
150
158
|
_optionalChain([fiber, 'optionalAccess', _2 => _2.addFinalizer, 'call', _3 => _3((exit) => {
|
|
151
159
|
try {
|
|
152
160
|
scope.close(exit);
|
|
@@ -164,18 +172,18 @@ function uncons(self) {
|
|
|
164
172
|
scope.close(exit);
|
|
165
173
|
};
|
|
166
174
|
const wrap = (s) => fromPull(
|
|
167
|
-
|
|
175
|
+
_chunkTGIFUAK4cjs.asyncEffect.call(void 0, (env2, cb2) => {
|
|
168
176
|
const pull = uncons(s);
|
|
169
|
-
|
|
177
|
+
_chunkTGIFUAK4cjs.unsafeRunFoldWithEnv.call(void 0,
|
|
170
178
|
pull,
|
|
171
179
|
env2,
|
|
172
180
|
(cause) => {
|
|
173
|
-
const ex =
|
|
181
|
+
const ex = _chunkTGIFUAK4cjs.Exit.failCause(cause);
|
|
174
182
|
closeWith(ex);
|
|
175
183
|
cb2(ex);
|
|
176
184
|
},
|
|
177
185
|
([a, tail]) => {
|
|
178
|
-
cb2(
|
|
186
|
+
cb2(_chunkTGIFUAK4cjs.Exit.succeed([a, wrap(tail)]));
|
|
179
187
|
}
|
|
180
188
|
);
|
|
181
189
|
})
|
|
@@ -183,19 +191,19 @@ function uncons(self) {
|
|
|
183
191
|
scope.fork(self.acquire).join((ex) => {
|
|
184
192
|
if (ex._tag === "Failure") {
|
|
185
193
|
closeWith(ex);
|
|
186
|
-
cb({ _tag: "Failure", cause: { _tag: "Fail", error:
|
|
194
|
+
cb({ _tag: "Failure", cause: { _tag: "Fail", error: _chunkTGIFUAK4cjs.some.call(void 0, ex.cause.error) } });
|
|
187
195
|
return;
|
|
188
196
|
}
|
|
189
197
|
scope.addFinalizer((exit) => self.release(exit));
|
|
190
198
|
const inner = ex.value;
|
|
191
|
-
|
|
199
|
+
_chunkTGIFUAK4cjs.unsafeGetCurrentRuntime.call(void 0, ).fork(uncons(wrap(inner))).join(cb);
|
|
192
200
|
});
|
|
193
201
|
});
|
|
194
202
|
case "Managed":
|
|
195
|
-
return
|
|
196
|
-
const runtime =
|
|
197
|
-
const scope = new (0,
|
|
198
|
-
_optionalChain([
|
|
203
|
+
return _chunkTGIFUAK4cjs.asyncEffect.call(void 0, (env, cb) => {
|
|
204
|
+
const runtime = _chunkTGIFUAK4cjs.unsafeGetCurrentRuntime.call(void 0, );
|
|
205
|
+
const scope = new (0, _chunkTGIFUAK4cjs.Scope)(runtime);
|
|
206
|
+
_optionalChain([_chunkTGIFUAK4cjs.getCurrentFiber.call(void 0, ), 'optionalAccess', _4 => _4.addFinalizer, 'call', _5 => _5((exit) => {
|
|
199
207
|
try {
|
|
200
208
|
scope.close(exit);
|
|
201
209
|
} catch (e4) {
|
|
@@ -214,25 +222,28 @@ function uncons(self) {
|
|
|
214
222
|
scope.fork(self.acquire).join((ex) => {
|
|
215
223
|
if (ex._tag === "Failure") {
|
|
216
224
|
scope.close(ex);
|
|
217
|
-
cb({ _tag: "Failure", cause: { _tag: "Fail", error:
|
|
225
|
+
cb({ _tag: "Failure", cause: { _tag: "Fail", error: _chunkTGIFUAK4cjs.some.call(void 0, ex.cause.error) } });
|
|
218
226
|
return;
|
|
219
227
|
}
|
|
220
228
|
const { stream: inner, release } = ex.value;
|
|
221
229
|
scope.addFinalizer((exit) => release(exit));
|
|
222
230
|
const wrap = (s) => fromPull(
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
231
|
+
_chunkTGIFUAK4cjs.asyncEffect.call(void 0, (env2, cb2) => {
|
|
232
|
+
_chunkTGIFUAK4cjs.unsafeRunFoldWithEnv.call(void 0,
|
|
233
|
+
uncons(s),
|
|
234
|
+
env2,
|
|
235
|
+
(cause) => {
|
|
236
|
+
const ex2 = _chunkTGIFUAK4cjs.Exit.failCause(cause);
|
|
226
237
|
closeWith(ex2);
|
|
227
238
|
cb2(ex2);
|
|
228
|
-
|
|
239
|
+
},
|
|
240
|
+
([a, tail]) => {
|
|
241
|
+
cb2(_chunkTGIFUAK4cjs.Exit.succeed([a, wrap(tail)]));
|
|
229
242
|
}
|
|
230
|
-
|
|
231
|
-
cb2(_chunk2P4PD6D7cjs.Exit.succeed([a, wrap(tail)]));
|
|
232
|
-
});
|
|
243
|
+
);
|
|
233
244
|
})
|
|
234
245
|
);
|
|
235
|
-
|
|
246
|
+
_chunkTGIFUAK4cjs.unsafeGetCurrentRuntime.call(void 0, ).fork(uncons(wrap(inner))).join(cb);
|
|
236
247
|
});
|
|
237
248
|
});
|
|
238
249
|
}
|
|
@@ -244,11 +255,13 @@ function mapStream(self, f) {
|
|
|
244
255
|
switch (self._tag) {
|
|
245
256
|
case "Empty":
|
|
246
257
|
return emptyStream();
|
|
258
|
+
case "FromArray":
|
|
259
|
+
return { _tag: "FromArray", values: self.values.map(f) };
|
|
247
260
|
case "Emit":
|
|
248
|
-
return emitStream(
|
|
261
|
+
return emitStream(_chunkTGIFUAK4cjs.map.call(void 0, self.value, f));
|
|
249
262
|
case "FromPull":
|
|
250
263
|
return fromPull(
|
|
251
|
-
|
|
264
|
+
_chunkTGIFUAK4cjs.map.call(void 0, self.pull, ([a, tail]) => [f(a), mapStream(tail, f)])
|
|
252
265
|
);
|
|
253
266
|
case "Concat":
|
|
254
267
|
return concatStream(mapStream(self.left, f), mapStream(self.right, f));
|
|
@@ -267,12 +280,12 @@ function mapStream(self, f) {
|
|
|
267
280
|
);
|
|
268
281
|
case "Scoped":
|
|
269
282
|
return unwrapScoped(
|
|
270
|
-
|
|
283
|
+
_chunkTGIFUAK4cjs.map.call(void 0, self.acquire, (s) => mapStream(s, f)),
|
|
271
284
|
self.release
|
|
272
285
|
);
|
|
273
286
|
case "Managed":
|
|
274
287
|
return managedStream(
|
|
275
|
-
|
|
288
|
+
_chunkTGIFUAK4cjs.map.call(void 0, self.acquire, ({ stream, release }) => ({
|
|
276
289
|
stream: mapStream(stream, f),
|
|
277
290
|
release
|
|
278
291
|
}))
|
|
@@ -283,19 +296,19 @@ function mapStream(self, f) {
|
|
|
283
296
|
}
|
|
284
297
|
function rangeStream(start, end) {
|
|
285
298
|
const go = (i) => fromPull(
|
|
286
|
-
i > end ?
|
|
299
|
+
i > end ? _chunkTGIFUAK4cjs.asyncFail.call(void 0, _chunkTGIFUAK4cjs.none) : _chunkTGIFUAK4cjs.asyncSucceed.call(void 0, [i, go(i + 1)])
|
|
287
300
|
);
|
|
288
301
|
return go(start);
|
|
289
302
|
}
|
|
290
303
|
function zip(left, right) {
|
|
291
|
-
const pull =
|
|
292
|
-
|
|
304
|
+
const pull = _chunkTGIFUAK4cjs.asyncFold.call(void 0,
|
|
305
|
+
_chunkTGIFUAK4cjs.asyncMapError.call(void 0, uncons(left), (opt) => widenOpt(opt)),
|
|
293
306
|
// si left termina o falla, el zip termina/falla igual
|
|
294
|
-
(opt) =>
|
|
295
|
-
([a, tailL]) =>
|
|
296
|
-
|
|
297
|
-
(opt) =>
|
|
298
|
-
([b, tailR]) =>
|
|
307
|
+
(opt) => _chunkTGIFUAK4cjs.asyncFail.call(void 0, opt),
|
|
308
|
+
([a, tailL]) => _chunkTGIFUAK4cjs.asyncFold.call(void 0,
|
|
309
|
+
_chunkTGIFUAK4cjs.asyncMapError.call(void 0, uncons(right), (opt) => widenOpt(opt)),
|
|
310
|
+
(opt) => _chunkTGIFUAK4cjs.asyncFail.call(void 0, opt),
|
|
311
|
+
([b, tailR]) => _chunkTGIFUAK4cjs.asyncSucceed.call(void 0, [
|
|
299
312
|
[a, b],
|
|
300
313
|
zip(tailL, tailR)
|
|
301
314
|
])
|
|
@@ -304,81 +317,150 @@ function zip(left, right) {
|
|
|
304
317
|
return fromPull(pull);
|
|
305
318
|
}
|
|
306
319
|
function foreachStream(stream, f) {
|
|
307
|
-
const loop = (cur) =>
|
|
320
|
+
const loop = (cur) => _chunkTGIFUAK4cjs.asyncFold.call(void 0,
|
|
308
321
|
// uncons: Option<E> -> Option<E|E2>
|
|
309
|
-
|
|
322
|
+
_chunkTGIFUAK4cjs.asyncMapError.call(void 0, uncons(cur), (opt) => widenOpt(opt)),
|
|
310
323
|
(opt) => {
|
|
311
|
-
if (opt._tag === "None") return
|
|
312
|
-
return
|
|
324
|
+
if (opt._tag === "None") return _chunkTGIFUAK4cjs.asyncSucceed.call(void 0, void 0);
|
|
325
|
+
return _chunkTGIFUAK4cjs.asyncFail.call(void 0, opt);
|
|
313
326
|
},
|
|
314
|
-
([a, tail]) =>
|
|
327
|
+
([a, tail]) => _chunkTGIFUAK4cjs.asyncFlatMap.call(void 0,
|
|
315
328
|
// f(a): E2 -> Option<E|E2>
|
|
316
|
-
|
|
329
|
+
_chunkTGIFUAK4cjs.asyncMapError.call(void 0, f(a), (e2) => _chunkTGIFUAK4cjs.some.call(void 0, e2)),
|
|
317
330
|
() => loop(tail)
|
|
318
331
|
)
|
|
319
332
|
);
|
|
320
|
-
return
|
|
333
|
+
return _chunkTGIFUAK4cjs.asyncFold.call(void 0,
|
|
321
334
|
loop(stream),
|
|
322
335
|
(opt) => {
|
|
323
|
-
if (opt._tag === "None") return
|
|
324
|
-
return
|
|
336
|
+
if (opt._tag === "None") return _chunkTGIFUAK4cjs.asyncSucceed.call(void 0, void 0);
|
|
337
|
+
return _chunkTGIFUAK4cjs.asyncFail.call(void 0, opt.value);
|
|
325
338
|
},
|
|
326
|
-
() =>
|
|
339
|
+
() => _chunkTGIFUAK4cjs.asyncSucceed.call(void 0, void 0)
|
|
327
340
|
);
|
|
328
341
|
}
|
|
329
342
|
function fromArray(values) {
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
const head = emitStream(_chunk2P4PD6D7cjs.succeed.call(void 0, values[i]));
|
|
333
|
-
s = concatStream(head, s);
|
|
334
|
-
}
|
|
335
|
-
return s;
|
|
343
|
+
if (values.length === 0) return emptyStream();
|
|
344
|
+
return { _tag: "FromArray", values };
|
|
336
345
|
}
|
|
337
346
|
function collectStream(stream) {
|
|
338
|
-
const
|
|
347
|
+
const syncResult = drainStreamSyncFull(stream);
|
|
348
|
+
if (syncResult !== null) {
|
|
349
|
+
return _chunkTGIFUAK4cjs.asyncSucceed.call(void 0, syncResult);
|
|
350
|
+
}
|
|
351
|
+
const loop = (cur, acc) => _chunkTGIFUAK4cjs.asyncFold.call(void 0,
|
|
339
352
|
uncons(cur),
|
|
340
353
|
(opt) => {
|
|
341
|
-
if (opt._tag === "None") return
|
|
342
|
-
return
|
|
354
|
+
if (opt._tag === "None") return _chunkTGIFUAK4cjs.succeed.call(void 0, acc);
|
|
355
|
+
return _chunkTGIFUAK4cjs.fail.call(void 0, opt);
|
|
343
356
|
},
|
|
344
|
-
([a, tail]) =>
|
|
357
|
+
([a, tail]) => {
|
|
358
|
+
acc.push(a);
|
|
359
|
+
return loop(tail, acc);
|
|
360
|
+
}
|
|
345
361
|
);
|
|
346
|
-
return
|
|
362
|
+
return _chunkTGIFUAK4cjs.mapError.call(void 0, loop(stream, []), (opt) => {
|
|
347
363
|
if (opt._tag === "Some") return opt.value;
|
|
348
364
|
throw new Error("unreachable: stream end handled as success");
|
|
349
365
|
});
|
|
350
366
|
}
|
|
351
|
-
function
|
|
352
|
-
const
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
367
|
+
function drainStreamSyncFull(stream) {
|
|
368
|
+
const result = [];
|
|
369
|
+
let cur = stream;
|
|
370
|
+
while (true) {
|
|
371
|
+
switch (cur._tag) {
|
|
372
|
+
case "Empty":
|
|
373
|
+
return result;
|
|
374
|
+
case "FromArray": {
|
|
375
|
+
const arr = cur.values;
|
|
376
|
+
for (let i = 0; i < arr.length; i++) {
|
|
377
|
+
result.push(arr[i]);
|
|
378
|
+
}
|
|
379
|
+
return result;
|
|
380
|
+
}
|
|
381
|
+
case "Emit": {
|
|
382
|
+
const zio = cur.value;
|
|
383
|
+
if (zio._tag === "Succeed") {
|
|
384
|
+
result.push(zio.value);
|
|
385
|
+
return result;
|
|
386
|
+
}
|
|
387
|
+
return null;
|
|
388
|
+
}
|
|
389
|
+
case "Concat": {
|
|
390
|
+
const leftItems = drainStreamSyncFull(cur.left);
|
|
391
|
+
if (leftItems === null) return null;
|
|
392
|
+
for (let i = 0; i < leftItems.length; i++) {
|
|
393
|
+
result.push(leftItems[i]);
|
|
394
|
+
}
|
|
395
|
+
cur = cur.right;
|
|
396
|
+
break;
|
|
397
|
+
}
|
|
398
|
+
default:
|
|
399
|
+
return null;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
function readerStream(reader, normalizeError, signal) {
|
|
404
|
+
const pull = _chunkTGIFUAK4cjs.asyncEffect.call(void 0, (_, cb) => {
|
|
405
|
+
let done = false;
|
|
406
|
+
const cleanup = () => _optionalChain([signal, 'optionalAccess', _6 => _6.removeEventListener, 'call', _7 => _7("abort", abort)]);
|
|
407
|
+
const finish = (exit) => {
|
|
408
|
+
if (done) return;
|
|
409
|
+
done = true;
|
|
410
|
+
cleanup();
|
|
411
|
+
cb(exit);
|
|
412
|
+
};
|
|
413
|
+
const abort = () => {
|
|
414
|
+
try {
|
|
415
|
+
reader.cancel();
|
|
416
|
+
} catch (e5) {
|
|
417
|
+
}
|
|
418
|
+
const error = typeof DOMException === "function" ? new DOMException("aborted", "AbortError") : new Error("aborted");
|
|
419
|
+
finish({ _tag: "Failure", cause: { _tag: "Fail", error: _chunkTGIFUAK4cjs.some.call(void 0, normalizeError(error)) } });
|
|
420
|
+
};
|
|
421
|
+
if (_optionalChain([signal, 'optionalAccess', _8 => _8.aborted])) {
|
|
422
|
+
abort();
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
_optionalChain([signal, 'optionalAccess', _9 => _9.addEventListener, 'call', _10 => _10("abort", abort, { once: true })]);
|
|
426
|
+
reader.read().then(({ done: done2, value }) => {
|
|
427
|
+
if (done2) {
|
|
428
|
+
finish({ _tag: "Failure", cause: { _tag: "Fail", error: _chunkTGIFUAK4cjs.none } });
|
|
356
429
|
return;
|
|
357
430
|
}
|
|
358
|
-
|
|
431
|
+
finish({
|
|
359
432
|
_tag: "Success",
|
|
360
433
|
value: [value, fromPull(pull)]
|
|
361
434
|
});
|
|
362
435
|
}).catch((e) => {
|
|
363
|
-
|
|
436
|
+
finish({ _tag: "Failure", cause: { _tag: "Fail", error: _chunkTGIFUAK4cjs.some.call(void 0, normalizeError(e)) } });
|
|
364
437
|
});
|
|
438
|
+
return () => {
|
|
439
|
+
cleanup();
|
|
440
|
+
try {
|
|
441
|
+
reader.cancel();
|
|
442
|
+
} catch (e6) {
|
|
443
|
+
}
|
|
444
|
+
};
|
|
365
445
|
});
|
|
366
446
|
return fromPull(pull);
|
|
367
447
|
}
|
|
368
|
-
function streamFromReadableStream(body, normalizeError) {
|
|
448
|
+
function streamFromReadableStream(body, normalizeError, options = {}) {
|
|
369
449
|
if (!body) return emptyStream();
|
|
370
450
|
let reader;
|
|
371
451
|
return unwrapScoped(
|
|
372
452
|
// acquire: produce un ZStream
|
|
373
|
-
|
|
453
|
+
_chunkTGIFUAK4cjs.sync.call(void 0, () => {
|
|
374
454
|
reader = body.getReader();
|
|
375
|
-
return readerStream(reader, normalizeError);
|
|
455
|
+
return readerStream(reader, normalizeError, options.signal);
|
|
376
456
|
}),
|
|
377
457
|
// release: se corre en fin / error / interrupción
|
|
378
|
-
() =>
|
|
458
|
+
() => _chunkTGIFUAK4cjs.asyncSync.call(void 0, () => {
|
|
379
459
|
try {
|
|
380
|
-
_optionalChain([reader, 'optionalAccess',
|
|
381
|
-
} catch (
|
|
460
|
+
_optionalChain([reader, 'optionalAccess', _11 => _11.cancel, 'call', _12 => _12()]);
|
|
461
|
+
} catch (e7) {
|
|
462
|
+
} finally {
|
|
463
|
+
_optionalChain([options, 'access', _13 => _13.onRelease, 'optionalCall', _14 => _14()]);
|
|
382
464
|
}
|
|
383
465
|
})
|
|
384
466
|
);
|