brass-runtime 1.13.5 → 1.13.6

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/dist/index.cjs ADDED
@@ -0,0 +1,855 @@
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;
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+ var _chunkAC4RFFVXcjs = require('./chunk-AC4RFFVX.cjs');
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+ var _chunkKT4IKCIUcjs = require('./chunk-KT4IKCIU.cjs');
90
+
91
+ // src/core/types/cancel.ts
92
+ function makeCancelToken() {
93
+ let cancelled = false;
94
+ const listeners = /* @__PURE__ */ new Set();
95
+ const cancel = () => {
96
+ if (cancelled) return;
97
+ cancelled = true;
98
+ listeners.forEach((f) => f());
99
+ listeners.clear();
100
+ };
101
+ return {
102
+ isCancelled: () => cancelled,
103
+ onCancel: (f) => {
104
+ if (cancelled) {
105
+ try {
106
+ f();
107
+ } catch (e2) {
108
+ }
109
+ return () => {
110
+ };
111
+ }
112
+ listeners.add(f);
113
+ return () => {
114
+ listeners.delete(f);
115
+ };
116
+ },
117
+ cancel
118
+ };
119
+ }
120
+ function linkAbortController(token, ac) {
121
+ return token.onCancel(() => ac.abort());
122
+ }
123
+
124
+ // src/core/runtime/linkedQueue.ts
125
+ var LinkedQueue = (_class = class {constructor() { _class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this); }
126
+ __init() {this.head = null}
127
+ __init2() {this.tail = null}
128
+ __init3() {this.len = 0}
129
+ get length() {
130
+ return this.len;
131
+ }
132
+ isEmpty() {
133
+ return this.len === 0;
134
+ }
135
+ push(value) {
136
+ const node = { value, next: null, prev: this.tail, removed: false };
137
+ if (this.tail) this.tail.next = node;
138
+ else this.head = node;
139
+ this.tail = node;
140
+ this.len++;
141
+ return node;
142
+ }
143
+ shift() {
144
+ const h = this.head;
145
+ if (!h) return void 0;
146
+ this.unlink(h);
147
+ return h.value;
148
+ }
149
+ remove(node) {
150
+ if (node.removed) return;
151
+ this.unlink(node);
152
+ }
153
+ unlink(node) {
154
+ node.removed = true;
155
+ const { prev, next } = node;
156
+ if (prev) prev.next = next;
157
+ else this.head = next;
158
+ if (next) next.prev = prev;
159
+ else this.tail = prev;
160
+ node.next = null;
161
+ node.prev = null;
162
+ this.len--;
163
+ }
164
+ }, _class);
165
+
166
+ // src/core/stream/queue.ts
167
+ function bounded(capacity, strategy = "backpressure", options = {}) {
168
+ return _chunkKT4IKCIUcjs.asyncSync.call(void 0, () => makeQueue(capacity, strategy, options));
169
+ }
170
+ function makeQueue(capacity, strategy, options) {
171
+ const items = _chunkKT4IKCIUcjs.makeBoundedRingBuffer.call(void 0, capacity, capacity, options);
172
+ let closed = false;
173
+ const QueueClosedErr = { _tag: "QueueClosed" };
174
+ const offerWaiters = new LinkedQueue();
175
+ const takers = new LinkedQueue();
176
+ const shutdown = () => {
177
+ if (closed) return;
178
+ closed = true;
179
+ while (takers.length > 0) {
180
+ const t = takers.shift();
181
+ t({ _tag: "Failure", cause: { _tag: "Fail", error: QueueClosedErr } });
182
+ }
183
+ while (offerWaiters.length > 0) {
184
+ const w = offerWaiters.shift();
185
+ w.cb(false);
186
+ }
187
+ items.clear();
188
+ };
189
+ return {
190
+ size: () => items.length,
191
+ shutdown,
192
+ offer: (a) => _chunkKT4IKCIUcjs.async.call(void 0, (_env, cb) => {
193
+ if (closed) {
194
+ cb({ _tag: "Success", value: false });
195
+ return;
196
+ }
197
+ if (takers.length > 0) {
198
+ const t = takers.shift();
199
+ t({ _tag: "Success", value: a });
200
+ cb({ _tag: "Success", value: true });
201
+ return;
202
+ }
203
+ if (items.length < capacity) {
204
+ items.push(a);
205
+ cb({ _tag: "Success", value: true });
206
+ return;
207
+ }
208
+ if (strategy === "dropping") {
209
+ cb({ _tag: "Success", value: false });
210
+ return;
211
+ }
212
+ if (strategy === "sliding") {
213
+ items.shift();
214
+ items.push(a);
215
+ cb({ _tag: "Success", value: true });
216
+ return;
217
+ }
218
+ const node = offerWaiters.push({
219
+ a,
220
+ cb: (ok) => cb({ _tag: "Success", value: ok })
221
+ });
222
+ const canceler = () => {
223
+ offerWaiters.remove(node);
224
+ };
225
+ return canceler;
226
+ }),
227
+ take: () => _chunkKT4IKCIUcjs.async.call(void 0, (_env, cb) => {
228
+ if (items.length > 0) {
229
+ const a = items.shift();
230
+ cb({ _tag: "Success", value: a });
231
+ if (offerWaiters.length > 0 && items.length < capacity) {
232
+ const w = offerWaiters.shift();
233
+ items.push(w.a);
234
+ w.cb(true);
235
+ }
236
+ return;
237
+ }
238
+ if (offerWaiters.length > 0) {
239
+ const w = offerWaiters.shift();
240
+ w.cb(true);
241
+ cb({ _tag: "Success", value: w.a });
242
+ return;
243
+ }
244
+ if (closed) {
245
+ cb({ _tag: "Failure", cause: { _tag: "Fail", error: QueueClosedErr } });
246
+ return;
247
+ }
248
+ const node = takers.push(cb);
249
+ const canceler = () => {
250
+ takers.remove(node);
251
+ };
252
+ return canceler;
253
+ })
254
+ };
255
+ }
256
+
257
+ // src/core/stream/buffer.ts
258
+ var SIGNAL_END = { _tag: "End" };
259
+ function buffer(stream, capacity, strategy = "backpressure") {
260
+ let started = false;
261
+ let q = null;
262
+ let producer = null;
263
+ let upstream = stream;
264
+ const onUpstreamFailure = (opt) => _chunkKT4IKCIUcjs.asyncSucceed.call(void 0,
265
+ opt._tag === "None" ? SIGNAL_END : { _tag: "Fail", error: opt.value }
266
+ );
267
+ const onUpstreamSuccess = ([a, tail]) => _chunkKT4IKCIUcjs.asyncSync.call(void 0, () => {
268
+ upstream = tail;
269
+ return { _tag: "Elem", value: a };
270
+ });
271
+ const nextSignal = () => _chunkKT4IKCIUcjs.asyncFold.call(void 0,
272
+ _chunkAC4RFFVXcjs.uncons.call(void 0, upstream),
273
+ onUpstreamFailure,
274
+ onUpstreamSuccess
275
+ );
276
+ const start = (env) => _chunkKT4IKCIUcjs.asyncFlatMap.call(void 0, bounded(capacity, strategy), (_q) => {
277
+ q = _q;
278
+ let lastSig;
279
+ const afterOffer = () => {
280
+ if (lastSig._tag !== "Elem") {
281
+ return _chunkKT4IKCIUcjs.asyncSucceed.call(void 0, void 0);
282
+ }
283
+ return loop();
284
+ };
285
+ const onSignal = (sig) => {
286
+ lastSig = sig;
287
+ return _chunkKT4IKCIUcjs.asyncFlatMap.call(void 0, q.offer(sig), afterOffer);
288
+ };
289
+ const loop = () => _chunkKT4IKCIUcjs.asyncFlatMap.call(void 0, nextSignal(), onSignal);
290
+ producer = _chunkKT4IKCIUcjs.fork.call(void 0, loop(), env);
291
+ return _chunkKT4IKCIUcjs.asyncSucceed.call(void 0, void 0);
292
+ });
293
+ const pullDown = {
294
+ _tag: "Async",
295
+ register: (env, cb) => {
296
+ const go = () => {
297
+ if (!started) {
298
+ started = true;
299
+ _chunkKT4IKCIUcjs.unsafeGetCurrentRuntime.call(void 0, ).fork(start(env)).join(() => {
300
+ pullFromQueue(env, cb);
301
+ });
302
+ return;
303
+ }
304
+ pullFromQueue(env, cb);
305
+ };
306
+ go();
307
+ }
308
+ };
309
+ function pullFromQueue(env, cb) {
310
+ const takeEff = q.take();
311
+ _chunkKT4IKCIUcjs.unsafeGetCurrentRuntime.call(void 0, ).fork(takeEff).join((ex) => {
312
+ if (ex._tag !== "Success") return;
313
+ const sig = ex.value;
314
+ switch (sig._tag) {
315
+ case "Elem":
316
+ cb({ _tag: "Success", value: [sig.value, _chunkAC4RFFVXcjs.fromPull.call(void 0, pullDown)] });
317
+ return;
318
+ case "End":
319
+ _optionalChain([producer, 'optionalAccess', _ => _.interrupt, 'optionalCall', _2 => _2()]);
320
+ cb({ _tag: "Failure", cause: { _tag: "Fail", error: _chunkKT4IKCIUcjs.none } });
321
+ return;
322
+ case "Fail":
323
+ _optionalChain([producer, 'optionalAccess', _3 => _3.interrupt, 'optionalCall', _4 => _4()]);
324
+ cb({ _tag: "Failure", cause: { _tag: "Fail", error: _chunkKT4IKCIUcjs.some.call(void 0, sig.error) } });
325
+ return;
326
+ }
327
+ });
328
+ }
329
+ return _chunkAC4RFFVXcjs.fromPull.call(void 0, pullDown);
330
+ }
331
+
332
+ // src/core/stream/hub.ts
333
+ var toQueueStrategy = (s) => s === "BackPressure" ? "backpressure" : s === "Dropping" ? "dropping" : "sliding";
334
+ function makeHub(capacity, strategy = "BackPressure") {
335
+ const queues = /* @__PURE__ */ new Set();
336
+ let closed = false;
337
+ const publish = (a) => {
338
+ if (closed) return _chunkKT4IKCIUcjs.asyncSucceed.call(void 0, false);
339
+ const size = queues.size;
340
+ if (size === 0) return _chunkKT4IKCIUcjs.asyncSucceed.call(void 0, true);
341
+ if (size === 1) {
342
+ const q = queues.values().next().value;
343
+ return q.offer(a);
344
+ }
345
+ let eff = _chunkKT4IKCIUcjs.asyncSucceed.call(void 0, true);
346
+ for (const q of queues) {
347
+ eff = _chunkKT4IKCIUcjs.asyncFlatMap.call(void 0,
348
+ eff,
349
+ (okSoFar) => _chunkKT4IKCIUcjs.asyncFlatMap.call(void 0, q.offer(a), (ok) => _chunkKT4IKCIUcjs.asyncSucceed.call(void 0, okSoFar && ok))
350
+ );
351
+ }
352
+ return eff;
353
+ };
354
+ const publishAll = (as) => {
355
+ let eff = _chunkKT4IKCIUcjs.asyncSucceed.call(void 0, true);
356
+ const it = as[Symbol.iterator]();
357
+ while (true) {
358
+ const n = it.next();
359
+ if (n.done) break;
360
+ const a = n.value;
361
+ eff = _chunkKT4IKCIUcjs.asyncFlatMap.call(void 0,
362
+ eff,
363
+ (okSoFar) => _chunkKT4IKCIUcjs.asyncFlatMap.call(void 0, publish(a), (ok) => _chunkKT4IKCIUcjs.asyncSucceed.call(void 0, okSoFar && ok))
364
+ );
365
+ }
366
+ return eff;
367
+ };
368
+ const subscribe = () => {
369
+ if (closed) {
370
+ return _chunkKT4IKCIUcjs.asyncTotal.call(void 0, () => {
371
+ throw { _tag: "HubClosed" };
372
+ });
373
+ }
374
+ return _chunkKT4IKCIUcjs.asyncFlatMap.call(void 0,
375
+ bounded(capacity, toQueueStrategy(strategy)),
376
+ (q) => _chunkKT4IKCIUcjs.asyncSync.call(void 0, () => {
377
+ queues.add(q);
378
+ return {
379
+ ...q,
380
+ unsubscribe: () => {
381
+ if (!queues.has(q)) return;
382
+ queues.delete(q);
383
+ q.shutdown();
384
+ }
385
+ };
386
+ })
387
+ );
388
+ };
389
+ const shutdown = () => _chunkKT4IKCIUcjs.asyncSync.call(void 0, () => {
390
+ if (closed) return;
391
+ closed = true;
392
+ for (const q of queues) q.shutdown();
393
+ queues.clear();
394
+ });
395
+ return {
396
+ publish,
397
+ publishAll,
398
+ subscribe,
399
+ shutdown
400
+ };
401
+ }
402
+ var broadcast = makeHub;
403
+ function broadcastToHub(stream, hub) {
404
+ return _chunkAC4RFFVXcjs.foreachStream.call(void 0,
405
+ stream,
406
+ (a) => _chunkKT4IKCIUcjs.asyncFlatMap.call(void 0, hub.publish(a), () => _chunkKT4IKCIUcjs.asyncSucceed.call(void 0, void 0))
407
+ );
408
+ }
409
+ function fromHub(hub) {
410
+ return _chunkAC4RFFVXcjs.managedStream.call(void 0,
411
+ _chunkKT4IKCIUcjs.asyncFlatMap.call(void 0, hub.subscribe(), (sub) => {
412
+ const loop = _chunkAC4RFFVXcjs.fromPull.call(void 0,
413
+ _chunkKT4IKCIUcjs.asyncFlatMap.call(void 0,
414
+ _chunkKT4IKCIUcjs.asyncMapError.call(void 0, sub.take(), (_queueClosed) => _chunkKT4IKCIUcjs.none),
415
+ (a) => _chunkKT4IKCIUcjs.asyncSucceed.call(void 0, [a, loop])
416
+ )
417
+ );
418
+ return _chunkKT4IKCIUcjs.asyncSucceed.call(void 0, {
419
+ stream: loop,
420
+ release: (_exit) => _chunkKT4IKCIUcjs.asyncSync.call(void 0, () => sub.unsubscribe())
421
+ });
422
+ })
423
+ );
424
+ }
425
+
426
+ // src/core/stream/chunks.ts
427
+ var cachedWasmChunkCtor;
428
+ function resolveWasmChunkBuffer() {
429
+ if (cachedWasmChunkCtor !== void 0) return cachedWasmChunkCtor;
430
+ const mod = _chunkKT4IKCIUcjs.resolveWasmModule.call(void 0, );
431
+ cachedWasmChunkCtor = _nullishCoalesce(_optionalChain([mod, 'optionalAccess', _5 => _5.BrassWasmChunkBuffer]), () => ( null));
432
+ return cachedWasmChunkCtor;
433
+ }
434
+ var JsChunker = (_class2 = class {
435
+ constructor(maxChunkSize, fallbackUsed = false) {;_class2.prototype.__init4.call(this);_class2.prototype.__init5.call(this);_class2.prototype.__init6.call(this);_class2.prototype.__init7.call(this);_class2.prototype.__init8.call(this);
436
+ this.maxChunkSize = maxChunkSize;
437
+ this.fallbackUsed = fallbackUsed;
438
+ }
439
+
440
+
441
+ __init4() {this.engine = "js"}
442
+ __init5() {this.values = []}
443
+ __init6() {this.emittedChunks = 0}
444
+ __init7() {this.emittedItems = 0}
445
+ __init8() {this.flushes = 0}
446
+ get length() {
447
+ return this.values.length;
448
+ }
449
+ push(value) {
450
+ if (this.values.length >= this.maxChunkSize) return false;
451
+ this.values.push(value);
452
+ return true;
453
+ }
454
+ isFull() {
455
+ return this.values.length >= this.maxChunkSize;
456
+ }
457
+ isEmpty() {
458
+ return this.values.length === 0;
459
+ }
460
+ takeChunk() {
461
+ this.flushes += 1;
462
+ const chunk = this.values;
463
+ this.values = [];
464
+ if (chunk.length > 0) {
465
+ this.emittedChunks += 1;
466
+ this.emittedItems += chunk.length;
467
+ }
468
+ return chunk;
469
+ }
470
+ clear() {
471
+ this.values = [];
472
+ }
473
+ stats() {
474
+ return {
475
+ engine: "js",
476
+ fallbackUsed: this.fallbackUsed,
477
+ data: {
478
+ len: this.values.length,
479
+ maxChunkSize: this.maxChunkSize,
480
+ emittedChunks: this.emittedChunks,
481
+ emittedItems: this.emittedItems,
482
+ flushes: this.flushes
483
+ }
484
+ };
485
+ }
486
+ }, _class2);
487
+ var WasmChunker = (_class3 = class {
488
+ __init9() {this.engine = "wasm"}
489
+ __init10() {this.fallbackUsed = false}
490
+
491
+ constructor(maxChunkSize) {;_class3.prototype.__init9.call(this);_class3.prototype.__init10.call(this);
492
+ const Ctor = resolveWasmChunkBuffer();
493
+ if (!Ctor) {
494
+ throw new Error("brass-runtime wasm chunk buffer is not available. Run npm run build:wasm first.");
495
+ }
496
+ this.inner = new Ctor(maxChunkSize);
497
+ }
498
+ get length() {
499
+ return this.inner.len();
500
+ }
501
+ get maxChunkSize() {
502
+ return this.inner.max_chunk_size();
503
+ }
504
+ push(value) {
505
+ return this.inner.push(value);
506
+ }
507
+ isFull() {
508
+ return this.inner.is_full();
509
+ }
510
+ isEmpty() {
511
+ return this.inner.is_empty();
512
+ }
513
+ takeChunk() {
514
+ return Array.from(this.inner.take_chunk());
515
+ }
516
+ clear() {
517
+ this.inner.clear();
518
+ }
519
+ stats() {
520
+ return { engine: "wasm", fallbackUsed: false, data: JSON.parse(this.inner.stats_json()) };
521
+ }
522
+ }, _class3);
523
+ function makeStreamChunker(chunkSize, options = {}) {
524
+ const size = Math.max(1, chunkSize | 0);
525
+ const engine = _nullishCoalesce(options.engine, () => ( "auto"));
526
+ if (engine === "js") return new JsChunker(size, false);
527
+ if (engine === "wasm") return new WasmChunker(size);
528
+ return resolveWasmChunkBuffer() ? new WasmChunker(size) : new JsChunker(size, true);
529
+ }
530
+ function chunks(input, chunkSize, options = {}) {
531
+ const size = Math.max(1, chunkSize | 0);
532
+ const loop = (cur) => _chunkAC4RFFVXcjs.fromPull.call(void 0, fillChunk(cur, makeStreamChunker(size, options)));
533
+ const fillChunk = (cur, chunker) => _chunkKT4IKCIUcjs.asyncFold.call(void 0,
534
+ _chunkAC4RFFVXcjs.uncons.call(void 0, cur),
535
+ (opt) => {
536
+ if (opt._tag === "None" && !chunker.isEmpty()) {
537
+ return _chunkKT4IKCIUcjs.asyncSucceed.call(void 0, [chunker.takeChunk(), _chunkAC4RFFVXcjs.fromPull.call(void 0, _chunkKT4IKCIUcjs.asyncFail.call(void 0, _chunkKT4IKCIUcjs.none))]);
538
+ }
539
+ return _chunkKT4IKCIUcjs.asyncFail.call(void 0, opt);
540
+ },
541
+ ([a, tail]) => {
542
+ chunker.push(a);
543
+ if (chunker.isFull()) {
544
+ return _chunkKT4IKCIUcjs.asyncSucceed.call(void 0, [chunker.takeChunk(), loop(tail)]);
545
+ }
546
+ return fillChunk(tail, chunker);
547
+ }
548
+ );
549
+ return loop(input);
550
+ }
551
+ function mapChunks(input, chunkSize, f, options = {}) {
552
+ const pullOne = (pending, rest) => {
553
+ if (pending.length > 0) {
554
+ const [head, ...tail] = pending;
555
+ return _chunkAC4RFFVXcjs.fromPull.call(void 0, _chunkKT4IKCIUcjs.asyncSucceed.call(void 0, [head, pullOne(tail, rest)]));
556
+ }
557
+ return _chunkAC4RFFVXcjs.fromPull.call(void 0,
558
+ _chunkKT4IKCIUcjs.asyncFold.call(void 0,
559
+ _chunkAC4RFFVXcjs.uncons.call(void 0, rest),
560
+ (opt) => _chunkKT4IKCIUcjs.asyncFail.call(void 0, opt),
561
+ ([chunk, tail]) => {
562
+ const mapped = f(chunk);
563
+ return _chunkAC4RFFVXcjs.uncons.call(void 0, pullOne(mapped, tail));
564
+ }
565
+ )
566
+ );
567
+ };
568
+ return pullOne([], chunks(input, chunkSize, options));
569
+ }
570
+ function mapChunksEffect(chunkSize, f, options = {}) {
571
+ return ((input) => {
572
+ const chunked = chunks(input, chunkSize, options);
573
+ const pullOne = (pending, rest) => {
574
+ if (pending.length > 0) {
575
+ const [head, ...tail] = pending;
576
+ return _chunkAC4RFFVXcjs.fromPull.call(void 0, _chunkKT4IKCIUcjs.asyncSucceed.call(void 0, [head, pullOne(tail, rest)]));
577
+ }
578
+ return _chunkAC4RFFVXcjs.fromPull.call(void 0,
579
+ _chunkKT4IKCIUcjs.asyncFold.call(void 0,
580
+ _chunkKT4IKCIUcjs.asyncMapError.call(void 0, _chunkAC4RFFVXcjs.uncons.call(void 0, rest), (opt) => _chunkAC4RFFVXcjs.widenOpt.call(void 0, opt)),
581
+ (opt) => _chunkKT4IKCIUcjs.asyncFail.call(void 0, opt),
582
+ ([chunk, tail]) => _chunkKT4IKCIUcjs.asyncFold.call(void 0,
583
+ _chunkKT4IKCIUcjs.asyncMapError.call(void 0, f(chunk), (e) => ({ _tag: "Some", value: e })),
584
+ (opt) => _chunkKT4IKCIUcjs.asyncFail.call(void 0, opt),
585
+ (mapped) => _chunkAC4RFFVXcjs.uncons.call(void 0, pullOne(mapped, tail))
586
+ )
587
+ )
588
+ );
589
+ };
590
+ return pullOne([], chunked);
591
+ });
592
+ }
593
+
594
+ // src/core/stream/pipeline.ts
595
+ function via(stream, pipeline) {
596
+ return pipeline(stream);
597
+ }
598
+ function andThen(p1, p2) {
599
+ return ((input) => p2(p1(input)));
600
+ }
601
+ function compose(p2, p1) {
602
+ return andThen(p1, p2);
603
+ }
604
+ function identity() {
605
+ return ((input) => input);
606
+ }
607
+ function mapP(f) {
608
+ return ((input) => {
609
+ const onError = (opt) => _chunkKT4IKCIUcjs.asyncFail.call(void 0, opt);
610
+ const onSuccess = ([a, tail]) => _chunkKT4IKCIUcjs.asyncSucceed.call(void 0, [f(a), loop(tail)]);
611
+ const loop = (cur) => _chunkAC4RFFVXcjs.fromPull.call(void 0,
612
+ _chunkKT4IKCIUcjs.asyncFold.call(void 0, _chunkAC4RFFVXcjs.uncons.call(void 0, cur), onError, onSuccess)
613
+ );
614
+ return loop(input);
615
+ });
616
+ }
617
+ function filterP(pred) {
618
+ return ((input) => {
619
+ const onError = (opt) => _chunkKT4IKCIUcjs.asyncFail.call(void 0, opt);
620
+ const onSuccess = ([a, tail]) => pred(a) ? _chunkKT4IKCIUcjs.asyncSucceed.call(void 0, [a, loop(tail)]) : next(tail);
621
+ const next = (cur) => _chunkKT4IKCIUcjs.asyncFold.call(void 0, _chunkAC4RFFVXcjs.uncons.call(void 0, cur), onError, onSuccess);
622
+ const loop = (cur) => _chunkAC4RFFVXcjs.fromPull.call(void 0, next(cur));
623
+ return loop(input);
624
+ });
625
+ }
626
+ function filterMapP(f) {
627
+ return ((input) => {
628
+ const onError = (opt) => _chunkKT4IKCIUcjs.asyncFail.call(void 0, opt);
629
+ const next = (cur) => _chunkKT4IKCIUcjs.asyncFold.call(void 0,
630
+ _chunkAC4RFFVXcjs.uncons.call(void 0, cur),
631
+ onError,
632
+ ([a, tail]) => {
633
+ const ob = f(a);
634
+ return ob._tag === "Some" ? _chunkKT4IKCIUcjs.asyncSucceed.call(void 0, [ob.value, loop(tail)]) : next(tail);
635
+ }
636
+ );
637
+ const loop = (cur) => _chunkAC4RFFVXcjs.fromPull.call(void 0, next(cur));
638
+ return loop(input);
639
+ });
640
+ }
641
+ function takeP(n) {
642
+ const m = Math.max(0, n | 0);
643
+ return ((input) => {
644
+ const loop = (cur, remaining) => {
645
+ if (remaining <= 0) return _chunkAC4RFFVXcjs.emptyStream.call(void 0, );
646
+ return _chunkAC4RFFVXcjs.fromPull.call(void 0,
647
+ _chunkKT4IKCIUcjs.asyncFold.call(void 0,
648
+ _chunkAC4RFFVXcjs.uncons.call(void 0, cur),
649
+ (opt) => _chunkKT4IKCIUcjs.asyncFail.call(void 0, opt),
650
+ ([a, tail]) => _chunkKT4IKCIUcjs.asyncSucceed.call(void 0, [a, loop(tail, remaining - 1)])
651
+ )
652
+ );
653
+ };
654
+ return loop(input, m);
655
+ });
656
+ }
657
+ function dropP(n) {
658
+ const m = Math.max(0, n | 0);
659
+ return ((input) => {
660
+ const skip = (cur, remaining) => {
661
+ if (remaining <= 0) return cur;
662
+ return _chunkAC4RFFVXcjs.fromPull.call(void 0,
663
+ _chunkKT4IKCIUcjs.asyncFold.call(void 0,
664
+ _chunkAC4RFFVXcjs.uncons.call(void 0, cur),
665
+ (opt) => _chunkKT4IKCIUcjs.asyncFail.call(void 0, opt),
666
+ ([_a, tail]) => _chunkAC4RFFVXcjs.uncons.call(void 0, skip(tail, remaining - 1))
667
+ )
668
+ );
669
+ };
670
+ return skip(input, m);
671
+ });
672
+ }
673
+ function mapEffectP(f) {
674
+ return ((input) => {
675
+ const raiseToOpt = (fa) => _chunkKT4IKCIUcjs.asyncMapError.call(void 0, fa, (e) => _chunkKT4IKCIUcjs.some.call(void 0, e));
676
+ const loop = (cur) => _chunkAC4RFFVXcjs.fromPull.call(void 0,
677
+ _chunkKT4IKCIUcjs.asyncFold.call(void 0,
678
+ _chunkKT4IKCIUcjs.asyncMapError.call(void 0,
679
+ _chunkAC4RFFVXcjs.uncons.call(void 0, cur),
680
+ (opt) => _chunkAC4RFFVXcjs.widenOpt.call(void 0, opt)
681
+ ),
682
+ (opt) => _chunkKT4IKCIUcjs.asyncFail.call(void 0, opt),
683
+ ([a, tail]) => _chunkKT4IKCIUcjs.asyncFold.call(void 0,
684
+ raiseToOpt(f(a)),
685
+ // Async<Rp, ...>
686
+ (opt2) => _chunkKT4IKCIUcjs.asyncFail.call(void 0, opt2),
687
+ (b) => _chunkKT4IKCIUcjs.asyncSucceed.call(void 0, [b, loop(tail)])
688
+ )
689
+ )
690
+ );
691
+ return loop(input);
692
+ });
693
+ }
694
+ function tapEffectP(f) {
695
+ return mapEffectP((a) => _chunkKT4IKCIUcjs.asyncFlatMap.call(void 0, f(a), () => _chunkKT4IKCIUcjs.asyncSucceed.call(void 0, a)));
696
+ }
697
+ function chunksP(chunkSize, options = {}) {
698
+ return ((input) => chunks(input, chunkSize, options));
699
+ }
700
+ function mapChunksEffectP(chunkSize, f, options = {}) {
701
+ return mapChunksEffect(chunkSize, f, options);
702
+ }
703
+ function bufferP(capacity, strategy = "backpressure") {
704
+ return ((input) => buffer(input, capacity, strategy));
705
+ }
706
+ function groupedP(n) {
707
+ const size = Math.max(1, n | 0);
708
+ return ((input) => {
709
+ const gather = (cur, remaining, acc) => {
710
+ if (remaining <= 0) return _chunkKT4IKCIUcjs.asyncSucceed.call(void 0, { chunk: acc, rest: cur });
711
+ return _chunkKT4IKCIUcjs.asyncFold.call(void 0,
712
+ _chunkAC4RFFVXcjs.uncons.call(void 0, cur),
713
+ (opt) => {
714
+ if (opt._tag === "None") return _chunkKT4IKCIUcjs.asyncSucceed.call(void 0, { chunk: acc, rest: _chunkAC4RFFVXcjs.emptyStream.call(void 0, ) });
715
+ return _chunkKT4IKCIUcjs.asyncFail.call(void 0, opt);
716
+ },
717
+ ([a, tail]) => gather(tail, remaining - 1, [...acc, a])
718
+ );
719
+ };
720
+ const loop = (cur) => _chunkAC4RFFVXcjs.fromPull.call(void 0,
721
+ _chunkKT4IKCIUcjs.asyncFold.call(void 0,
722
+ _chunkAC4RFFVXcjs.uncons.call(void 0, cur),
723
+ (opt) => _chunkKT4IKCIUcjs.asyncFail.call(void 0, opt),
724
+ ([a, tail]) => _chunkKT4IKCIUcjs.asyncFlatMap.call(void 0,
725
+ gather(tail, size - 1, [a]),
726
+ ({ chunk, rest }) => _chunkKT4IKCIUcjs.asyncSucceed.call(void 0, [chunk, loop(rest)])
727
+ )
728
+ )
729
+ );
730
+ return loop(input);
731
+ });
732
+ }
733
+
734
+ // src/core/runtime/engineStats.ts
735
+ function engineStats(engine, data, fallbackUsed = false) {
736
+ return { engine, data, fallbackUsed };
737
+ }
738
+ function selectedEngineStats(requested, engine, data) {
739
+ return { requested, engine, data, fallbackUsed: requested === "auto" && engine !== "wasm" };
740
+ }
741
+
742
+
743
+
744
+
745
+
746
+
747
+
748
+
749
+
750
+
751
+
752
+
753
+
754
+
755
+
756
+
757
+
758
+
759
+
760
+
761
+
762
+
763
+
764
+
765
+
766
+
767
+
768
+
769
+
770
+
771
+
772
+
773
+
774
+
775
+
776
+
777
+
778
+
779
+
780
+
781
+
782
+
783
+
784
+
785
+
786
+
787
+
788
+
789
+
790
+
791
+
792
+
793
+
794
+
795
+
796
+
797
+
798
+
799
+
800
+
801
+
802
+
803
+
804
+
805
+
806
+
807
+
808
+
809
+
810
+
811
+
812
+
813
+
814
+
815
+
816
+
817
+
818
+
819
+
820
+
821
+
822
+
823
+
824
+
825
+
826
+
827
+
828
+
829
+
830
+
831
+
832
+
833
+
834
+
835
+
836
+
837
+
838
+
839
+
840
+
841
+
842
+
843
+
844
+
845
+
846
+
847
+
848
+
849
+
850
+
851
+
852
+
853
+
854
+
855
+ exports.Async = _chunkKT4IKCIUcjs.Async; exports.Cause = _chunkKT4IKCIUcjs.Cause; exports.DefaultHostExecutor = _chunkKT4IKCIUcjs.DefaultHostExecutor; exports.EngineFiberHandle = _chunkKT4IKCIUcjs.EngineFiberHandle; exports.Exit = _chunkKT4IKCIUcjs.Exit; exports.HostRegistry = _chunkKT4IKCIUcjs.HostRegistry; exports.JsFiberEngine = _chunkKT4IKCIUcjs.JsFiberEngine; exports.NoopHooks = _chunkKT4IKCIUcjs.NoopHooks; exports.ProgramBuilder = _chunkKT4IKCIUcjs.ProgramBuilder; exports.PushStatus = _chunkKT4IKCIUcjs.PushStatus; exports.ReferenceWasmBridge = _chunkKT4IKCIUcjs.ReferenceWasmBridge; exports.RingBuffer = _chunkKT4IKCIUcjs.RingBuffer; exports.Runtime = _chunkKT4IKCIUcjs.Runtime; exports.RuntimeFiber = _chunkKT4IKCIUcjs.RuntimeFiber; exports.Scheduler = _chunkKT4IKCIUcjs.Scheduler; exports.Scope = _chunkKT4IKCIUcjs.Scope; exports.WasmFiberEngine = _chunkKT4IKCIUcjs.WasmFiberEngine; exports.WasmFiberRegistryBridge = _chunkKT4IKCIUcjs.WasmFiberRegistryBridge; exports.WasmPackFiberBridge = _chunkKT4IKCIUcjs.WasmPackFiberBridge; exports.acquireRelease = _chunkKT4IKCIUcjs.acquireRelease; exports.andThen = andThen; exports.assertNever = _chunkAC4RFFVXcjs.assertNever; exports.async = _chunkKT4IKCIUcjs.async; exports.asyncCatchAll = _chunkKT4IKCIUcjs.asyncCatchAll; exports.asyncFail = _chunkKT4IKCIUcjs.asyncFail; exports.asyncFlatMap = _chunkKT4IKCIUcjs.asyncFlatMap; exports.asyncFold = _chunkKT4IKCIUcjs.asyncFold; exports.asyncInterruptible = _chunkKT4IKCIUcjs.asyncInterruptible; exports.asyncMap = _chunkKT4IKCIUcjs.asyncMap; exports.asyncMapError = _chunkKT4IKCIUcjs.asyncMapError; exports.asyncSucceed = _chunkKT4IKCIUcjs.asyncSucceed; exports.asyncSync = _chunkKT4IKCIUcjs.asyncSync; exports.asyncTotal = _chunkKT4IKCIUcjs.asyncTotal; exports.bounded = bounded; exports.broadcast = broadcast; exports.broadcastToHub = broadcastToHub; exports.buffer = buffer; exports.bufferP = bufferP; exports.catchAll = _chunkKT4IKCIUcjs.catchAll; exports.chunks = chunks; exports.chunksP = chunksP; exports.collectAllPar = _chunkKT4IKCIUcjs.collectAllPar; exports.collectStream = _chunkAC4RFFVXcjs.collectStream; exports.compose = compose; exports.concatStream = _chunkAC4RFFVXcjs.concatStream; exports.dropP = dropP; exports.emitStream = _chunkAC4RFFVXcjs.emitStream; exports.emptyStream = _chunkAC4RFFVXcjs.emptyStream; exports.end = _chunkKT4IKCIUcjs.end; exports.engineStats = engineStats; exports.fail = _chunkKT4IKCIUcjs.fail; exports.filterMapP = filterMapP; exports.filterP = filterP; exports.flatMap = _chunkKT4IKCIUcjs.flatMap; exports.flattenStream = _chunkAC4RFFVXcjs.flattenStream; exports.foreachStream = _chunkAC4RFFVXcjs.foreachStream; exports.fork = _chunkKT4IKCIUcjs.fork; exports.fromArray = _chunkAC4RFFVXcjs.fromArray; exports.fromHub = fromHub; exports.fromPromiseAbortable = _chunkKT4IKCIUcjs.fromPromiseAbortable; exports.fromPull = _chunkAC4RFFVXcjs.fromPull; exports.getBenchmarkBudget = _chunkKT4IKCIUcjs.getBenchmarkBudget; exports.getCurrentFiber = _chunkKT4IKCIUcjs.getCurrentFiber; exports.globalScheduler = _chunkKT4IKCIUcjs.globalScheduler; exports.groupedP = groupedP; exports.identity = identity; exports.linkAbortController = linkAbortController; exports.makeBoundedRingBuffer = _chunkKT4IKCIUcjs.makeBoundedRingBuffer; exports.makeCancelToken = makeCancelToken; exports.makeHub = makeHub; exports.makeStreamChunker = makeStreamChunker; exports.managedStream = _chunkAC4RFFVXcjs.managedStream; exports.map = _chunkKT4IKCIUcjs.map; exports.mapAsync = _chunkKT4IKCIUcjs.mapAsync; exports.mapChunks = mapChunks; exports.mapChunksEffect = mapChunksEffect; exports.mapChunksEffectP = mapChunksEffectP; exports.mapEffectP = mapEffectP; exports.mapError = _chunkKT4IKCIUcjs.mapError; exports.mapP = mapP; exports.mapStream = _chunkAC4RFFVXcjs.mapStream; exports.mapTryAsync = _chunkKT4IKCIUcjs.mapTryAsync; exports.merge = _chunkAC4RFFVXcjs.merge; exports.mergeStream = _chunkAC4RFFVXcjs.mergeStream; exports.none = _chunkKT4IKCIUcjs.none; exports.orElseOptional = _chunkKT4IKCIUcjs.orElseOptional; exports.race = _chunkKT4IKCIUcjs.race; exports.raceWith = _chunkKT4IKCIUcjs.raceWith; exports.rangeStream = _chunkAC4RFFVXcjs.rangeStream; exports.runtimeCapabilities = _chunkKT4IKCIUcjs.runtimeCapabilities; exports.selectedEngineStats = selectedEngineStats; exports.setBenchmarkBudget = _chunkKT4IKCIUcjs.setBenchmarkBudget; exports.some = _chunkKT4IKCIUcjs.some; exports.streamFromReadableStream = _chunkAC4RFFVXcjs.streamFromReadableStream; exports.succeed = _chunkKT4IKCIUcjs.succeed; exports.sync = _chunkKT4IKCIUcjs.sync; exports.takeP = takeP; exports.tapEffectP = tapEffectP; exports.toPromise = _chunkKT4IKCIUcjs.toPromise; exports.uncons = _chunkAC4RFFVXcjs.uncons; exports.unit = _chunkKT4IKCIUcjs.unit; exports.unsafeGetCurrentRuntime = _chunkKT4IKCIUcjs.unsafeGetCurrentRuntime; exports.unsafeRunAsync = _chunkKT4IKCIUcjs.unsafeRunAsync; exports.unsafeRunFoldWithEnv = _chunkKT4IKCIUcjs.unsafeRunFoldWithEnv; exports.unwrapScoped = _chunkAC4RFFVXcjs.unwrapScoped; exports.via = via; exports.widenOpt = _chunkAC4RFFVXcjs.widenOpt; exports.withAsyncPromise = _chunkKT4IKCIUcjs.withAsyncPromise; exports.withCurrentFiber = _chunkKT4IKCIUcjs.withCurrentFiber; exports.withScope = _chunkKT4IKCIUcjs.withScope; exports.withScopeAsync = _chunkKT4IKCIUcjs.withScopeAsync; exports.zip = _chunkAC4RFFVXcjs.zip; exports.zipPar = _chunkKT4IKCIUcjs.zipPar;