brass-runtime 1.13.2 → 1.13.3
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/agent/cli/main.js +2021 -15
- package/dist/agent/cli/main.mjs +2022 -0
- package/dist/agent/index.js +153 -1
- package/dist/agent/index.mjs +153 -0
- package/dist/chunk-3IF374MG.js +407 -0
- package/dist/chunk-6ECUD4N3.mjs +2879 -0
- package/dist/chunk-HRVX2IYW.js +2879 -0
- package/dist/chunk-QRPYH5J7.mjs +407 -0
- package/dist/chunk-T5XJDGTQ.mjs +2556 -0
- package/dist/chunk-TGOMLZ65.js +2556 -0
- package/dist/http/index.js +453 -1
- package/dist/http/index.mjs +453 -0
- package/dist/index.js +855 -1
- package/dist/index.mjs +855 -0
- package/package.json +3 -5
- package/dist/agent/cli/main.cjs +0 -16
- package/dist/agent/index.cjs +0 -1
- package/dist/chunk-6OUI6UGZ.cjs +0 -25
- package/dist/chunk-JAQUSSUV.js +0 -1
- package/dist/chunk-K47BP5A2.cjs +0 -2
- package/dist/chunk-LTHJNW5A.js +0 -2
- package/dist/chunk-W6TVAMYC.js +0 -25
- package/dist/chunk-XPOARCND.cjs +0 -1
- package/dist/http/index.cjs +0 -1
- package/dist/index.cjs +0 -1
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,855 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assertNever,
|
|
3
|
+
collectStream,
|
|
4
|
+
concatStream,
|
|
5
|
+
emitStream,
|
|
6
|
+
emptyStream,
|
|
7
|
+
flattenStream,
|
|
8
|
+
foreachStream,
|
|
9
|
+
fromArray,
|
|
10
|
+
fromPull,
|
|
11
|
+
managedStream,
|
|
12
|
+
mapStream,
|
|
13
|
+
merge,
|
|
14
|
+
mergeStream,
|
|
15
|
+
rangeStream,
|
|
16
|
+
streamFromReadableStream,
|
|
17
|
+
uncons,
|
|
18
|
+
unwrapScoped,
|
|
19
|
+
widenOpt,
|
|
20
|
+
zip
|
|
21
|
+
} from "./chunk-QRPYH5J7.mjs";
|
|
22
|
+
import {
|
|
23
|
+
Async,
|
|
24
|
+
Cause,
|
|
25
|
+
DefaultHostExecutor,
|
|
26
|
+
EngineFiberHandle,
|
|
27
|
+
Exit,
|
|
28
|
+
HostRegistry,
|
|
29
|
+
JsFiberEngine,
|
|
30
|
+
NoopHooks,
|
|
31
|
+
ProgramBuilder,
|
|
32
|
+
PushStatus,
|
|
33
|
+
ReferenceWasmBridge,
|
|
34
|
+
RingBuffer,
|
|
35
|
+
Runtime,
|
|
36
|
+
RuntimeFiber,
|
|
37
|
+
Scheduler,
|
|
38
|
+
Scope,
|
|
39
|
+
WasmFiberEngine,
|
|
40
|
+
WasmFiberRegistryBridge,
|
|
41
|
+
WasmPackFiberBridge,
|
|
42
|
+
acquireRelease,
|
|
43
|
+
async,
|
|
44
|
+
asyncCatchAll,
|
|
45
|
+
asyncFail,
|
|
46
|
+
asyncFlatMap,
|
|
47
|
+
asyncFold,
|
|
48
|
+
asyncInterruptible,
|
|
49
|
+
asyncMap,
|
|
50
|
+
asyncMapError,
|
|
51
|
+
asyncSucceed,
|
|
52
|
+
asyncSync,
|
|
53
|
+
asyncTotal,
|
|
54
|
+
catchAll,
|
|
55
|
+
collectAllPar,
|
|
56
|
+
end,
|
|
57
|
+
fail,
|
|
58
|
+
flatMap,
|
|
59
|
+
fork,
|
|
60
|
+
fromPromiseAbortable,
|
|
61
|
+
getBenchmarkBudget,
|
|
62
|
+
getCurrentFiber,
|
|
63
|
+
globalScheduler,
|
|
64
|
+
makeBoundedRingBuffer,
|
|
65
|
+
map,
|
|
66
|
+
mapAsync,
|
|
67
|
+
mapError,
|
|
68
|
+
mapTryAsync,
|
|
69
|
+
none,
|
|
70
|
+
orElseOptional,
|
|
71
|
+
race,
|
|
72
|
+
raceWith,
|
|
73
|
+
resolveWasmModule,
|
|
74
|
+
runtimeCapabilities,
|
|
75
|
+
setBenchmarkBudget,
|
|
76
|
+
some,
|
|
77
|
+
succeed,
|
|
78
|
+
sync,
|
|
79
|
+
toPromise,
|
|
80
|
+
unit,
|
|
81
|
+
unsafeGetCurrentRuntime,
|
|
82
|
+
unsafeRunAsync,
|
|
83
|
+
unsafeRunFoldWithEnv,
|
|
84
|
+
withAsyncPromise,
|
|
85
|
+
withCurrentFiber,
|
|
86
|
+
withScope,
|
|
87
|
+
withScopeAsync,
|
|
88
|
+
zipPar
|
|
89
|
+
} from "./chunk-T5XJDGTQ.mjs";
|
|
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 {
|
|
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 {
|
|
126
|
+
head = null;
|
|
127
|
+
tail = null;
|
|
128
|
+
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
|
+
};
|
|
165
|
+
|
|
166
|
+
// src/core/stream/queue.ts
|
|
167
|
+
function bounded(capacity, strategy = "backpressure", options = {}) {
|
|
168
|
+
return asyncSync(() => makeQueue(capacity, strategy, options));
|
|
169
|
+
}
|
|
170
|
+
function makeQueue(capacity, strategy, options) {
|
|
171
|
+
const items = makeBoundedRingBuffer(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) => async((_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: () => async((_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) => asyncSucceed(
|
|
265
|
+
opt._tag === "None" ? SIGNAL_END : { _tag: "Fail", error: opt.value }
|
|
266
|
+
);
|
|
267
|
+
const onUpstreamSuccess = ([a, tail]) => asyncSync(() => {
|
|
268
|
+
upstream = tail;
|
|
269
|
+
return { _tag: "Elem", value: a };
|
|
270
|
+
});
|
|
271
|
+
const nextSignal = () => asyncFold(
|
|
272
|
+
uncons(upstream),
|
|
273
|
+
onUpstreamFailure,
|
|
274
|
+
onUpstreamSuccess
|
|
275
|
+
);
|
|
276
|
+
const start = (env) => asyncFlatMap(bounded(capacity, strategy), (_q) => {
|
|
277
|
+
q = _q;
|
|
278
|
+
let lastSig;
|
|
279
|
+
const afterOffer = () => {
|
|
280
|
+
if (lastSig._tag !== "Elem") {
|
|
281
|
+
return asyncSucceed(void 0);
|
|
282
|
+
}
|
|
283
|
+
return loop();
|
|
284
|
+
};
|
|
285
|
+
const onSignal = (sig) => {
|
|
286
|
+
lastSig = sig;
|
|
287
|
+
return asyncFlatMap(q.offer(sig), afterOffer);
|
|
288
|
+
};
|
|
289
|
+
const loop = () => asyncFlatMap(nextSignal(), onSignal);
|
|
290
|
+
producer = fork(loop(), env);
|
|
291
|
+
return asyncSucceed(void 0);
|
|
292
|
+
});
|
|
293
|
+
const pullDown = {
|
|
294
|
+
_tag: "Async",
|
|
295
|
+
register: (env, cb) => {
|
|
296
|
+
const go = () => {
|
|
297
|
+
if (!started) {
|
|
298
|
+
started = true;
|
|
299
|
+
unsafeGetCurrentRuntime().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
|
+
unsafeGetCurrentRuntime().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, fromPull(pullDown)] });
|
|
317
|
+
return;
|
|
318
|
+
case "End":
|
|
319
|
+
producer?.interrupt?.();
|
|
320
|
+
cb({ _tag: "Failure", cause: { _tag: "Fail", error: none } });
|
|
321
|
+
return;
|
|
322
|
+
case "Fail":
|
|
323
|
+
producer?.interrupt?.();
|
|
324
|
+
cb({ _tag: "Failure", cause: { _tag: "Fail", error: some(sig.error) } });
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
return fromPull(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 asyncSucceed(false);
|
|
339
|
+
const size = queues.size;
|
|
340
|
+
if (size === 0) return asyncSucceed(true);
|
|
341
|
+
if (size === 1) {
|
|
342
|
+
const q = queues.values().next().value;
|
|
343
|
+
return q.offer(a);
|
|
344
|
+
}
|
|
345
|
+
let eff = asyncSucceed(true);
|
|
346
|
+
for (const q of queues) {
|
|
347
|
+
eff = asyncFlatMap(
|
|
348
|
+
eff,
|
|
349
|
+
(okSoFar) => asyncFlatMap(q.offer(a), (ok) => asyncSucceed(okSoFar && ok))
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
return eff;
|
|
353
|
+
};
|
|
354
|
+
const publishAll = (as) => {
|
|
355
|
+
let eff = asyncSucceed(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 = asyncFlatMap(
|
|
362
|
+
eff,
|
|
363
|
+
(okSoFar) => asyncFlatMap(publish(a), (ok) => asyncSucceed(okSoFar && ok))
|
|
364
|
+
);
|
|
365
|
+
}
|
|
366
|
+
return eff;
|
|
367
|
+
};
|
|
368
|
+
const subscribe = () => {
|
|
369
|
+
if (closed) {
|
|
370
|
+
return asyncTotal(() => {
|
|
371
|
+
throw { _tag: "HubClosed" };
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
return asyncFlatMap(
|
|
375
|
+
bounded(capacity, toQueueStrategy(strategy)),
|
|
376
|
+
(q) => asyncSync(() => {
|
|
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 = () => asyncSync(() => {
|
|
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 foreachStream(
|
|
405
|
+
stream,
|
|
406
|
+
(a) => asyncFlatMap(hub.publish(a), () => asyncSucceed(void 0))
|
|
407
|
+
);
|
|
408
|
+
}
|
|
409
|
+
function fromHub(hub) {
|
|
410
|
+
return managedStream(
|
|
411
|
+
asyncFlatMap(hub.subscribe(), (sub) => {
|
|
412
|
+
const loop = fromPull(
|
|
413
|
+
asyncFlatMap(
|
|
414
|
+
asyncMapError(sub.take(), (_queueClosed) => none),
|
|
415
|
+
(a) => asyncSucceed([a, loop])
|
|
416
|
+
)
|
|
417
|
+
);
|
|
418
|
+
return asyncSucceed({
|
|
419
|
+
stream: loop,
|
|
420
|
+
release: (_exit) => asyncSync(() => 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 = resolveWasmModule();
|
|
431
|
+
cachedWasmChunkCtor = mod?.BrassWasmChunkBuffer ?? null;
|
|
432
|
+
return cachedWasmChunkCtor;
|
|
433
|
+
}
|
|
434
|
+
var JsChunker = class {
|
|
435
|
+
constructor(maxChunkSize, fallbackUsed = false) {
|
|
436
|
+
this.maxChunkSize = maxChunkSize;
|
|
437
|
+
this.fallbackUsed = fallbackUsed;
|
|
438
|
+
}
|
|
439
|
+
maxChunkSize;
|
|
440
|
+
fallbackUsed;
|
|
441
|
+
engine = "js";
|
|
442
|
+
values = [];
|
|
443
|
+
emittedChunks = 0;
|
|
444
|
+
emittedItems = 0;
|
|
445
|
+
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
|
+
};
|
|
487
|
+
var WasmChunker = class {
|
|
488
|
+
engine = "wasm";
|
|
489
|
+
fallbackUsed = false;
|
|
490
|
+
inner;
|
|
491
|
+
constructor(maxChunkSize) {
|
|
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
|
+
};
|
|
523
|
+
function makeStreamChunker(chunkSize, options = {}) {
|
|
524
|
+
const size = Math.max(1, chunkSize | 0);
|
|
525
|
+
const engine = 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) => fromPull(fillChunk(cur, makeStreamChunker(size, options)));
|
|
533
|
+
const fillChunk = (cur, chunker) => asyncFold(
|
|
534
|
+
uncons(cur),
|
|
535
|
+
(opt) => {
|
|
536
|
+
if (opt._tag === "None" && !chunker.isEmpty()) {
|
|
537
|
+
return asyncSucceed([chunker.takeChunk(), fromPull(asyncFail(none))]);
|
|
538
|
+
}
|
|
539
|
+
return asyncFail(opt);
|
|
540
|
+
},
|
|
541
|
+
([a, tail]) => {
|
|
542
|
+
chunker.push(a);
|
|
543
|
+
if (chunker.isFull()) {
|
|
544
|
+
return asyncSucceed([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 fromPull(asyncSucceed([head, pullOne(tail, rest)]));
|
|
556
|
+
}
|
|
557
|
+
return fromPull(
|
|
558
|
+
asyncFold(
|
|
559
|
+
uncons(rest),
|
|
560
|
+
(opt) => asyncFail(opt),
|
|
561
|
+
([chunk, tail]) => {
|
|
562
|
+
const mapped = f(chunk);
|
|
563
|
+
return uncons(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 fromPull(asyncSucceed([head, pullOne(tail, rest)]));
|
|
577
|
+
}
|
|
578
|
+
return fromPull(
|
|
579
|
+
asyncFold(
|
|
580
|
+
asyncMapError(uncons(rest), (opt) => widenOpt(opt)),
|
|
581
|
+
(opt) => asyncFail(opt),
|
|
582
|
+
([chunk, tail]) => asyncFold(
|
|
583
|
+
asyncMapError(f(chunk), (e) => ({ _tag: "Some", value: e })),
|
|
584
|
+
(opt) => asyncFail(opt),
|
|
585
|
+
(mapped) => uncons(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) => asyncFail(opt);
|
|
610
|
+
const onSuccess = ([a, tail]) => asyncSucceed([f(a), loop(tail)]);
|
|
611
|
+
const loop = (cur) => fromPull(
|
|
612
|
+
asyncFold(uncons(cur), onError, onSuccess)
|
|
613
|
+
);
|
|
614
|
+
return loop(input);
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
function filterP(pred) {
|
|
618
|
+
return ((input) => {
|
|
619
|
+
const onError = (opt) => asyncFail(opt);
|
|
620
|
+
const onSuccess = ([a, tail]) => pred(a) ? asyncSucceed([a, loop(tail)]) : next(tail);
|
|
621
|
+
const next = (cur) => asyncFold(uncons(cur), onError, onSuccess);
|
|
622
|
+
const loop = (cur) => fromPull(next(cur));
|
|
623
|
+
return loop(input);
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
function filterMapP(f) {
|
|
627
|
+
return ((input) => {
|
|
628
|
+
const onError = (opt) => asyncFail(opt);
|
|
629
|
+
const next = (cur) => asyncFold(
|
|
630
|
+
uncons(cur),
|
|
631
|
+
onError,
|
|
632
|
+
([a, tail]) => {
|
|
633
|
+
const ob = f(a);
|
|
634
|
+
return ob._tag === "Some" ? asyncSucceed([ob.value, loop(tail)]) : next(tail);
|
|
635
|
+
}
|
|
636
|
+
);
|
|
637
|
+
const loop = (cur) => fromPull(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 emptyStream();
|
|
646
|
+
return fromPull(
|
|
647
|
+
asyncFold(
|
|
648
|
+
uncons(cur),
|
|
649
|
+
(opt) => asyncFail(opt),
|
|
650
|
+
([a, tail]) => asyncSucceed([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 fromPull(
|
|
663
|
+
asyncFold(
|
|
664
|
+
uncons(cur),
|
|
665
|
+
(opt) => asyncFail(opt),
|
|
666
|
+
([_a, tail]) => uncons(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) => asyncMapError(fa, (e) => some(e));
|
|
676
|
+
const loop = (cur) => fromPull(
|
|
677
|
+
asyncFold(
|
|
678
|
+
asyncMapError(
|
|
679
|
+
uncons(cur),
|
|
680
|
+
(opt) => widenOpt(opt)
|
|
681
|
+
),
|
|
682
|
+
(opt) => asyncFail(opt),
|
|
683
|
+
([a, tail]) => asyncFold(
|
|
684
|
+
raiseToOpt(f(a)),
|
|
685
|
+
// Async<Rp, ...>
|
|
686
|
+
(opt2) => asyncFail(opt2),
|
|
687
|
+
(b) => asyncSucceed([b, loop(tail)])
|
|
688
|
+
)
|
|
689
|
+
)
|
|
690
|
+
);
|
|
691
|
+
return loop(input);
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
function tapEffectP(f) {
|
|
695
|
+
return mapEffectP((a) => asyncFlatMap(f(a), () => asyncSucceed(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 asyncSucceed({ chunk: acc, rest: cur });
|
|
711
|
+
return asyncFold(
|
|
712
|
+
uncons(cur),
|
|
713
|
+
(opt) => {
|
|
714
|
+
if (opt._tag === "None") return asyncSucceed({ chunk: acc, rest: emptyStream() });
|
|
715
|
+
return asyncFail(opt);
|
|
716
|
+
},
|
|
717
|
+
([a, tail]) => gather(tail, remaining - 1, [...acc, a])
|
|
718
|
+
);
|
|
719
|
+
};
|
|
720
|
+
const loop = (cur) => fromPull(
|
|
721
|
+
asyncFold(
|
|
722
|
+
uncons(cur),
|
|
723
|
+
(opt) => asyncFail(opt),
|
|
724
|
+
([a, tail]) => asyncFlatMap(
|
|
725
|
+
gather(tail, size - 1, [a]),
|
|
726
|
+
({ chunk, rest }) => asyncSucceed([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
|
+
export {
|
|
742
|
+
Async,
|
|
743
|
+
Cause,
|
|
744
|
+
DefaultHostExecutor,
|
|
745
|
+
EngineFiberHandle,
|
|
746
|
+
Exit,
|
|
747
|
+
HostRegistry,
|
|
748
|
+
JsFiberEngine,
|
|
749
|
+
NoopHooks,
|
|
750
|
+
ProgramBuilder,
|
|
751
|
+
PushStatus,
|
|
752
|
+
ReferenceWasmBridge,
|
|
753
|
+
RingBuffer,
|
|
754
|
+
Runtime,
|
|
755
|
+
RuntimeFiber,
|
|
756
|
+
Scheduler,
|
|
757
|
+
Scope,
|
|
758
|
+
WasmFiberEngine,
|
|
759
|
+
WasmFiberRegistryBridge,
|
|
760
|
+
WasmPackFiberBridge,
|
|
761
|
+
acquireRelease,
|
|
762
|
+
andThen,
|
|
763
|
+
assertNever,
|
|
764
|
+
async,
|
|
765
|
+
asyncCatchAll,
|
|
766
|
+
asyncFail,
|
|
767
|
+
asyncFlatMap,
|
|
768
|
+
asyncFold,
|
|
769
|
+
asyncInterruptible,
|
|
770
|
+
asyncMap,
|
|
771
|
+
asyncMapError,
|
|
772
|
+
asyncSucceed,
|
|
773
|
+
asyncSync,
|
|
774
|
+
asyncTotal,
|
|
775
|
+
bounded,
|
|
776
|
+
broadcast,
|
|
777
|
+
broadcastToHub,
|
|
778
|
+
buffer,
|
|
779
|
+
bufferP,
|
|
780
|
+
catchAll,
|
|
781
|
+
chunks,
|
|
782
|
+
chunksP,
|
|
783
|
+
collectAllPar,
|
|
784
|
+
collectStream,
|
|
785
|
+
compose,
|
|
786
|
+
concatStream,
|
|
787
|
+
dropP,
|
|
788
|
+
emitStream,
|
|
789
|
+
emptyStream,
|
|
790
|
+
end,
|
|
791
|
+
engineStats,
|
|
792
|
+
fail,
|
|
793
|
+
filterMapP,
|
|
794
|
+
filterP,
|
|
795
|
+
flatMap,
|
|
796
|
+
flattenStream,
|
|
797
|
+
foreachStream,
|
|
798
|
+
fork,
|
|
799
|
+
fromArray,
|
|
800
|
+
fromHub,
|
|
801
|
+
fromPromiseAbortable,
|
|
802
|
+
fromPull,
|
|
803
|
+
getBenchmarkBudget,
|
|
804
|
+
getCurrentFiber,
|
|
805
|
+
globalScheduler,
|
|
806
|
+
groupedP,
|
|
807
|
+
identity,
|
|
808
|
+
linkAbortController,
|
|
809
|
+
makeBoundedRingBuffer,
|
|
810
|
+
makeCancelToken,
|
|
811
|
+
makeHub,
|
|
812
|
+
makeStreamChunker,
|
|
813
|
+
managedStream,
|
|
814
|
+
map,
|
|
815
|
+
mapAsync,
|
|
816
|
+
mapChunks,
|
|
817
|
+
mapChunksEffect,
|
|
818
|
+
mapChunksEffectP,
|
|
819
|
+
mapEffectP,
|
|
820
|
+
mapError,
|
|
821
|
+
mapP,
|
|
822
|
+
mapStream,
|
|
823
|
+
mapTryAsync,
|
|
824
|
+
merge,
|
|
825
|
+
mergeStream,
|
|
826
|
+
none,
|
|
827
|
+
orElseOptional,
|
|
828
|
+
race,
|
|
829
|
+
raceWith,
|
|
830
|
+
rangeStream,
|
|
831
|
+
runtimeCapabilities,
|
|
832
|
+
selectedEngineStats,
|
|
833
|
+
setBenchmarkBudget,
|
|
834
|
+
some,
|
|
835
|
+
streamFromReadableStream,
|
|
836
|
+
succeed,
|
|
837
|
+
sync,
|
|
838
|
+
takeP,
|
|
839
|
+
tapEffectP,
|
|
840
|
+
toPromise,
|
|
841
|
+
uncons,
|
|
842
|
+
unit,
|
|
843
|
+
unsafeGetCurrentRuntime,
|
|
844
|
+
unsafeRunAsync,
|
|
845
|
+
unsafeRunFoldWithEnv,
|
|
846
|
+
unwrapScoped,
|
|
847
|
+
via,
|
|
848
|
+
widenOpt,
|
|
849
|
+
withAsyncPromise,
|
|
850
|
+
withCurrentFiber,
|
|
851
|
+
withScope,
|
|
852
|
+
withScopeAsync,
|
|
853
|
+
zip,
|
|
854
|
+
zipPar
|
|
855
|
+
};
|