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.
@@ -1,31 +1,31 @@
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
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
- var _chunkTGOMLZ65js = require('./chunk-TGOMLZ65.js');
1
+ import {
2
+ Cause,
3
+ Exit,
4
+ Scope,
5
+ async,
6
+ asyncFail,
7
+ asyncFlatMap,
8
+ asyncFold,
9
+ asyncMapError,
10
+ asyncSucceed,
11
+ asyncSync,
12
+ fail,
13
+ flatMap,
14
+ getCurrentFiber,
15
+ map,
16
+ mapError,
17
+ none,
18
+ orElseOptional,
19
+ raceWith,
20
+ some,
21
+ succeed,
22
+ sync,
23
+ unsafeGetCurrentRuntime,
24
+ unsafeRunFoldWithEnv
25
+ } from "./chunk-TGOMLZ65.js";
26
26
 
27
27
  // src/core/stream/stream.ts
28
- var widenOpt = (opt) => opt._tag === "None" ? _chunkTGOMLZ65js.none : _chunkTGOMLZ65js.some.call(void 0, opt.value);
28
+ var widenOpt = (opt) => opt._tag === "None" ? none : some(opt.value);
29
29
  var fromPull = (pull) => ({
30
30
  _tag: "FromPull",
31
31
  pull
@@ -70,28 +70,28 @@ function streamToRaceWithHandler(winnerSide, leftStream, rightStream, flip, id)
70
70
  const [a, tailWin] = exit.value;
71
71
  otherFiber.interrupt();
72
72
  const next = winnerSide === "L" ? fromPull(makeMergePull(tailWin, rightStream, !flip, id)) : fromPull(makeMergePull(leftStream, tailWin, !flip, id));
73
- return _chunkTGOMLZ65js.asyncSucceed.call(void 0, [a, next]);
73
+ return asyncSucceed([a, next]);
74
74
  }
75
75
  if (exit.cause._tag === "Interrupt") {
76
- return _chunkTGOMLZ65js.async.call(void 0, (_env, cb) => {
77
- cb(_chunkTGOMLZ65js.Exit.failCause(_chunkTGOMLZ65js.Cause.interrupt()));
76
+ return async((_env, cb) => {
77
+ cb(Exit.failCause(Cause.interrupt()));
78
78
  });
79
79
  }
80
80
  const opt = exit.cause.error;
81
81
  if (opt._tag === "None") {
82
82
  return winnerSide === "L" ? uncons(rightStream) : uncons(leftStream);
83
83
  }
84
- return _chunkTGOMLZ65js.asyncFail.call(void 0, opt);
84
+ return asyncFail(opt);
85
85
  };
86
86
  }
87
87
  function makeMergePull(onLeft, onRight, flip, mergePullId) {
88
88
  const id = ++mergePullId;
89
89
  const onLeftHandler = streamToRaceWithHandler("L", onLeft, onRight, flip, id);
90
90
  const onRightHandler = streamToRaceWithHandler("R", onLeft, onRight, flip, id);
91
- return _chunkTGOMLZ65js.async.call(void 0, (_env, cb) => {
92
- const runtime = _chunkTGOMLZ65js.unsafeGetCurrentRuntime.call(void 0, );
93
- const scope = new (0, _chunkTGOMLZ65js.Scope)(runtime);
94
- const handler = _chunkTGOMLZ65js.raceWith.call(void 0,
91
+ return async((_env, cb) => {
92
+ const runtime = unsafeGetCurrentRuntime();
93
+ const scope = new Scope(runtime);
94
+ const handler = raceWith(
95
95
  uncons(onLeft),
96
96
  uncons(onRight),
97
97
  scope,
@@ -110,27 +110,27 @@ function merge(left, right) {
110
110
  function uncons(self) {
111
111
  switch (self._tag) {
112
112
  case "Empty":
113
- return _chunkTGOMLZ65js.fail.call(void 0, _chunkTGOMLZ65js.none);
113
+ return fail(none);
114
114
  case "Emit":
115
- return _chunkTGOMLZ65js.map.call(void 0,
116
- _chunkTGOMLZ65js.mapError.call(void 0, self.value, (e) => _chunkTGOMLZ65js.some.call(void 0, e)),
115
+ return map(
116
+ mapError(self.value, (e) => some(e)),
117
117
  (a) => [a, EMPTY_STREAM]
118
118
  );
119
119
  case "FromPull":
120
120
  return self.pull;
121
121
  case "Concat":
122
- return _chunkTGOMLZ65js.orElseOptional.call(void 0,
123
- _chunkTGOMLZ65js.map.call(void 0,
122
+ return orElseOptional(
123
+ map(
124
124
  uncons(self.left),
125
125
  ([a, tail]) => [a, concatStream(tail, self.right)]
126
126
  ),
127
127
  () => uncons(self.right)
128
128
  );
129
129
  case "Flatten":
130
- return _chunkTGOMLZ65js.flatMap.call(void 0,
130
+ return flatMap(
131
131
  uncons(self.stream),
132
- ([head, tail]) => _chunkTGOMLZ65js.orElseOptional.call(void 0,
133
- _chunkTGOMLZ65js.map.call(void 0,
132
+ ([head, tail]) => orElseOptional(
133
+ map(
134
134
  uncons(head),
135
135
  ([a, as]) => [
136
136
  a,
@@ -143,16 +143,16 @@ function uncons(self) {
143
143
  case "Merge":
144
144
  return makeMergePull(self.left, self.right, self.flip, 0);
145
145
  case "Scoped":
146
- return _chunkTGOMLZ65js.async.call(void 0, (env, cb) => {
147
- const runtime = _chunkTGOMLZ65js.unsafeGetCurrentRuntime.call(void 0, );
148
- const scope = new (0, _chunkTGOMLZ65js.Scope)(runtime);
149
- const fiber = _chunkTGOMLZ65js.getCurrentFiber.call(void 0, );
150
- _optionalChain([fiber, 'optionalAccess', _2 => _2.addFinalizer, 'call', _3 => _3((exit) => {
146
+ return async((env, cb) => {
147
+ const runtime = unsafeGetCurrentRuntime();
148
+ const scope = new Scope(runtime);
149
+ const fiber = getCurrentFiber();
150
+ fiber?.addFinalizer((exit) => {
151
151
  try {
152
152
  scope.close(exit);
153
- } catch (e3) {
153
+ } catch {
154
154
  }
155
- })]);
155
+ });
156
156
  const closeWith = (exit) => {
157
157
  if (exit._tag === "Failure") {
158
158
  const err = exit.cause.error;
@@ -164,18 +164,18 @@ function uncons(self) {
164
164
  scope.close(exit);
165
165
  };
166
166
  const wrap = (s) => fromPull(
167
- _chunkTGOMLZ65js.async.call(void 0, (env2, cb2) => {
167
+ async((env2, cb2) => {
168
168
  const pull = uncons(s);
169
- _chunkTGOMLZ65js.unsafeRunFoldWithEnv.call(void 0,
169
+ unsafeRunFoldWithEnv(
170
170
  pull,
171
171
  env2,
172
172
  (cause) => {
173
- const ex = _chunkTGOMLZ65js.Exit.failCause(cause);
173
+ const ex = Exit.failCause(cause);
174
174
  closeWith(ex);
175
175
  cb2(ex);
176
176
  },
177
177
  ([a, tail]) => {
178
- cb2(_chunkTGOMLZ65js.Exit.succeed([a, wrap(tail)]));
178
+ cb2(Exit.succeed([a, wrap(tail)]));
179
179
  }
180
180
  );
181
181
  })
@@ -183,24 +183,24 @@ function uncons(self) {
183
183
  scope.fork(self.acquire).join((ex) => {
184
184
  if (ex._tag === "Failure") {
185
185
  closeWith(ex);
186
- cb({ _tag: "Failure", cause: { _tag: "Fail", error: _chunkTGOMLZ65js.some.call(void 0, ex.cause.error) } });
186
+ cb({ _tag: "Failure", cause: { _tag: "Fail", error: some(ex.cause.error) } });
187
187
  return;
188
188
  }
189
189
  scope.addFinalizer((exit) => self.release(exit));
190
190
  const inner = ex.value;
191
- _chunkTGOMLZ65js.unsafeGetCurrentRuntime.call(void 0, ).fork(uncons(wrap(inner))).join(cb);
191
+ unsafeGetCurrentRuntime().fork(uncons(wrap(inner))).join(cb);
192
192
  });
193
193
  });
194
194
  case "Managed":
195
- return _chunkTGOMLZ65js.async.call(void 0, (env, cb) => {
196
- const runtime = _chunkTGOMLZ65js.unsafeGetCurrentRuntime.call(void 0, );
197
- const scope = new (0, _chunkTGOMLZ65js.Scope)(runtime);
198
- _optionalChain([_chunkTGOMLZ65js.getCurrentFiber.call(void 0, ), 'optionalAccess', _4 => _4.addFinalizer, 'call', _5 => _5((exit) => {
195
+ return async((env, cb) => {
196
+ const runtime = unsafeGetCurrentRuntime();
197
+ const scope = new Scope(runtime);
198
+ getCurrentFiber()?.addFinalizer((exit) => {
199
199
  try {
200
200
  scope.close(exit);
201
- } catch (e4) {
201
+ } catch {
202
202
  }
203
- })]);
203
+ });
204
204
  const closeWith = (exit) => {
205
205
  if (exit._tag === "Failure") {
206
206
  const err = exit.cause.error;
@@ -214,13 +214,13 @@ function uncons(self) {
214
214
  scope.fork(self.acquire).join((ex) => {
215
215
  if (ex._tag === "Failure") {
216
216
  scope.close(ex);
217
- cb({ _tag: "Failure", cause: { _tag: "Fail", error: _chunkTGOMLZ65js.some.call(void 0, ex.cause.error) } });
217
+ cb({ _tag: "Failure", cause: { _tag: "Fail", error: some(ex.cause.error) } });
218
218
  return;
219
219
  }
220
220
  const { stream: inner, release } = ex.value;
221
221
  scope.addFinalizer((exit) => release(exit));
222
222
  const wrap = (s) => fromPull(
223
- _chunkTGOMLZ65js.async.call(void 0, (env2, cb2) => {
223
+ async((env2, cb2) => {
224
224
  uncons(s)(env2, (ex2) => {
225
225
  if (ex2._tag === "Failure") {
226
226
  closeWith(ex2);
@@ -228,27 +228,27 @@ function uncons(self) {
228
228
  return;
229
229
  }
230
230
  const [a, tail] = ex2.value;
231
- cb2(_chunkTGOMLZ65js.Exit.succeed([a, wrap(tail)]));
231
+ cb2(Exit.succeed([a, wrap(tail)]));
232
232
  });
233
233
  })
234
234
  );
235
- _chunkTGOMLZ65js.unsafeGetCurrentRuntime.call(void 0, ).fork(uncons(wrap(inner))).join(cb);
235
+ unsafeGetCurrentRuntime().fork(uncons(wrap(inner))).join(cb);
236
236
  });
237
237
  });
238
238
  }
239
239
  }
240
240
  function assertNever(x, msg) {
241
- throw new Error(_nullishCoalesce(msg, () => ( `Unexpected value: ${String(x)}`)));
241
+ throw new Error(msg ?? `Unexpected value: ${String(x)}`);
242
242
  }
243
243
  function mapStream(self, f) {
244
244
  switch (self._tag) {
245
245
  case "Empty":
246
246
  return emptyStream();
247
247
  case "Emit":
248
- return emitStream(_chunkTGOMLZ65js.map.call(void 0, self.value, f));
248
+ return emitStream(map(self.value, f));
249
249
  case "FromPull":
250
250
  return fromPull(
251
- _chunkTGOMLZ65js.map.call(void 0, self.pull, ([a, tail]) => [f(a), mapStream(tail, f)])
251
+ map(self.pull, ([a, tail]) => [f(a), mapStream(tail, f)])
252
252
  );
253
253
  case "Concat":
254
254
  return concatStream(mapStream(self.left, f), mapStream(self.right, f));
@@ -267,12 +267,12 @@ function mapStream(self, f) {
267
267
  );
268
268
  case "Scoped":
269
269
  return unwrapScoped(
270
- _chunkTGOMLZ65js.map.call(void 0, self.acquire, (s) => mapStream(s, f)),
270
+ map(self.acquire, (s) => mapStream(s, f)),
271
271
  self.release
272
272
  );
273
273
  case "Managed":
274
274
  return managedStream(
275
- _chunkTGOMLZ65js.map.call(void 0, self.acquire, ({ stream, release }) => ({
275
+ map(self.acquire, ({ stream, release }) => ({
276
276
  stream: mapStream(stream, f),
277
277
  release
278
278
  }))
@@ -283,19 +283,19 @@ function mapStream(self, f) {
283
283
  }
284
284
  function rangeStream(start, end) {
285
285
  const go = (i) => fromPull(
286
- i > end ? _chunkTGOMLZ65js.asyncFail.call(void 0, _chunkTGOMLZ65js.none) : _chunkTGOMLZ65js.asyncSucceed.call(void 0, [i, go(i + 1)])
286
+ i > end ? asyncFail(none) : asyncSucceed([i, go(i + 1)])
287
287
  );
288
288
  return go(start);
289
289
  }
290
290
  function zip(left, right) {
291
- const pull = _chunkTGOMLZ65js.asyncFold.call(void 0,
292
- _chunkTGOMLZ65js.asyncMapError.call(void 0, uncons(left), (opt) => widenOpt(opt)),
291
+ const pull = asyncFold(
292
+ asyncMapError(uncons(left), (opt) => widenOpt(opt)),
293
293
  // si left termina o falla, el zip termina/falla igual
294
- (opt) => _chunkTGOMLZ65js.asyncFail.call(void 0, opt),
295
- ([a, tailL]) => _chunkTGOMLZ65js.asyncFold.call(void 0,
296
- _chunkTGOMLZ65js.asyncMapError.call(void 0, uncons(right), (opt) => widenOpt(opt)),
297
- (opt) => _chunkTGOMLZ65js.asyncFail.call(void 0, opt),
298
- ([b, tailR]) => _chunkTGOMLZ65js.asyncSucceed.call(void 0, [
294
+ (opt) => asyncFail(opt),
295
+ ([a, tailL]) => asyncFold(
296
+ asyncMapError(uncons(right), (opt) => widenOpt(opt)),
297
+ (opt) => asyncFail(opt),
298
+ ([b, tailR]) => asyncSucceed([
299
299
  [a, b],
300
300
  zip(tailL, tailR)
301
301
  ])
@@ -304,55 +304,55 @@ function zip(left, right) {
304
304
  return fromPull(pull);
305
305
  }
306
306
  function foreachStream(stream, f) {
307
- const loop = (cur) => _chunkTGOMLZ65js.asyncFold.call(void 0,
307
+ const loop = (cur) => asyncFold(
308
308
  // uncons: Option<E> -> Option<E|E2>
309
- _chunkTGOMLZ65js.asyncMapError.call(void 0, uncons(cur), (opt) => widenOpt(opt)),
309
+ asyncMapError(uncons(cur), (opt) => widenOpt(opt)),
310
310
  (opt) => {
311
- if (opt._tag === "None") return _chunkTGOMLZ65js.asyncSucceed.call(void 0, void 0);
312
- return _chunkTGOMLZ65js.asyncFail.call(void 0, opt);
311
+ if (opt._tag === "None") return asyncSucceed(void 0);
312
+ return asyncFail(opt);
313
313
  },
314
- ([a, tail]) => _chunkTGOMLZ65js.asyncFlatMap.call(void 0,
314
+ ([a, tail]) => asyncFlatMap(
315
315
  // f(a): E2 -> Option<E|E2>
316
- _chunkTGOMLZ65js.asyncMapError.call(void 0, f(a), (e2) => _chunkTGOMLZ65js.some.call(void 0, e2)),
316
+ asyncMapError(f(a), (e2) => some(e2)),
317
317
  () => loop(tail)
318
318
  )
319
319
  );
320
- return _chunkTGOMLZ65js.asyncFold.call(void 0,
320
+ return asyncFold(
321
321
  loop(stream),
322
322
  (opt) => {
323
- if (opt._tag === "None") return _chunkTGOMLZ65js.asyncSucceed.call(void 0, void 0);
324
- return _chunkTGOMLZ65js.asyncFail.call(void 0, opt.value);
323
+ if (opt._tag === "None") return asyncSucceed(void 0);
324
+ return asyncFail(opt.value);
325
325
  },
326
- () => _chunkTGOMLZ65js.asyncSucceed.call(void 0, void 0)
326
+ () => asyncSucceed(void 0)
327
327
  );
328
328
  }
329
329
  function fromArray(values) {
330
330
  let s = emptyStream();
331
331
  for (let i = values.length - 1; i >= 0; i--) {
332
- const head = emitStream(_chunkTGOMLZ65js.succeed.call(void 0, values[i]));
332
+ const head = emitStream(succeed(values[i]));
333
333
  s = concatStream(head, s);
334
334
  }
335
335
  return s;
336
336
  }
337
337
  function collectStream(stream) {
338
- const loop = (cur, acc) => _chunkTGOMLZ65js.asyncFold.call(void 0,
338
+ const loop = (cur, acc) => asyncFold(
339
339
  uncons(cur),
340
340
  (opt) => {
341
- if (opt._tag === "None") return _chunkTGOMLZ65js.succeed.call(void 0, acc);
342
- return _chunkTGOMLZ65js.fail.call(void 0, opt);
341
+ if (opt._tag === "None") return succeed(acc);
342
+ return fail(opt);
343
343
  },
344
344
  ([a, tail]) => loop(tail, [...acc, a])
345
345
  );
346
- return _chunkTGOMLZ65js.mapError.call(void 0, loop(stream, []), (opt) => {
346
+ return mapError(loop(stream, []), (opt) => {
347
347
  if (opt._tag === "Some") return opt.value;
348
348
  throw new Error("unreachable: stream end handled as success");
349
349
  });
350
350
  }
351
351
  function readerStream(reader, normalizeError) {
352
- const pull = _chunkTGOMLZ65js.async.call(void 0, (_, cb) => {
352
+ const pull = async((_, cb) => {
353
353
  reader.read().then(({ done, value }) => {
354
354
  if (done) {
355
- cb({ _tag: "Failure", cause: { _tag: "Fail", error: _chunkTGOMLZ65js.none } });
355
+ cb({ _tag: "Failure", cause: { _tag: "Fail", error: none } });
356
356
  return;
357
357
  }
358
358
  cb({
@@ -360,7 +360,7 @@ function readerStream(reader, normalizeError) {
360
360
  value: [value, fromPull(pull)]
361
361
  });
362
362
  }).catch((e) => {
363
- cb({ _tag: "Failure", cause: { _tag: "Fail", error: _chunkTGOMLZ65js.some.call(void 0, normalizeError(e)) } });
363
+ cb({ _tag: "Failure", cause: { _tag: "Fail", error: some(normalizeError(e)) } });
364
364
  });
365
365
  });
366
366
  return fromPull(pull);
@@ -370,38 +370,38 @@ function streamFromReadableStream(body, normalizeError) {
370
370
  let reader;
371
371
  return unwrapScoped(
372
372
  // acquire: produce un ZStream
373
- _chunkTGOMLZ65js.sync.call(void 0, () => {
373
+ sync(() => {
374
374
  reader = body.getReader();
375
375
  return readerStream(reader, normalizeError);
376
376
  }),
377
377
  // release: se corre en fin / error / interrupción
378
- () => _chunkTGOMLZ65js.asyncSync.call(void 0, () => {
378
+ () => asyncSync(() => {
379
379
  try {
380
- _optionalChain([reader, 'optionalAccess', _6 => _6.cancel, 'call', _7 => _7()]);
381
- } catch (e5) {
380
+ reader?.cancel();
381
+ } catch {
382
382
  }
383
383
  })
384
384
  );
385
385
  }
386
386
 
387
-
388
-
389
-
390
-
391
-
392
-
393
-
394
-
395
-
396
-
397
-
398
-
399
-
400
-
401
-
402
-
403
-
404
-
405
-
406
-
407
- exports.widenOpt = widenOpt; exports.fromPull = fromPull; exports.unwrapScoped = unwrapScoped; exports.managedStream = managedStream; exports.mergeStream = mergeStream; exports.emptyStream = emptyStream; exports.emitStream = emitStream; exports.concatStream = concatStream; exports.flattenStream = flattenStream; exports.merge = merge; exports.uncons = uncons; exports.assertNever = assertNever; exports.mapStream = mapStream; exports.rangeStream = rangeStream; exports.zip = zip; exports.foreachStream = foreachStream; exports.fromArray = fromArray; exports.collectStream = collectStream; exports.streamFromReadableStream = streamFromReadableStream;
387
+ export {
388
+ widenOpt,
389
+ fromPull,
390
+ unwrapScoped,
391
+ managedStream,
392
+ mergeStream,
393
+ emptyStream,
394
+ emitStream,
395
+ concatStream,
396
+ flattenStream,
397
+ merge,
398
+ uncons,
399
+ assertNever,
400
+ mapStream,
401
+ rangeStream,
402
+ zip,
403
+ foreachStream,
404
+ fromArray,
405
+ collectStream,
406
+ streamFromReadableStream
407
+ };