brass-runtime 1.14.0 → 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-WJESVBWN.js → chunk-3QMOKAS5.js} +9 -7
- package/dist/{chunk-BMRF4FN6.js → chunk-4NHES7VK.mjs} +59 -237
- package/dist/chunk-AR22SXML.js +1043 -0
- package/dist/{chunk-4N2JEK4H.mjs → chunk-BDF4AMWX.mjs} +27 -151
- package/dist/chunk-BDYEENHT.js +224 -0
- package/dist/{chunk-JT7D6M5H.js → chunk-BMH5AV44.js} +27 -151
- package/dist/chunk-ELOOF35R.mjs +131 -0
- package/dist/chunk-JFPU5GQI.mjs +1043 -0
- package/dist/{chunk-MQF7HZ7Y.mjs → chunk-K6M7MDZ4.mjs} +9 -7
- package/dist/chunk-MS34J5LY.cjs +224 -0
- package/dist/{chunk-UWMMYKVK.mjs → chunk-PPUXIH5R.js} +59 -237
- package/dist/chunk-R3R2FVLG.cjs +131 -0
- package/dist/chunk-STVLQ3XD.cjs +489 -0
- package/dist/{chunk-BKBFSOGT.cjs → chunk-TGIFUAK4.cjs} +26 -150
- package/dist/chunk-TO7IKXYT.js +131 -0
- package/dist/chunk-UMAZLXAB.mjs +224 -0
- package/dist/{chunk-XTMZTVIT.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-DM56H743.d.ts → effect-CMOQKX8y.d.ts} +12 -11
- package/dist/http/index.cjs +2557 -235
- package/dist/http/index.d.ts +1514 -4
- package/dist/http/index.js +2549 -227
- package/dist/http/index.mjs +2549 -227
- package/dist/index.cjs +237 -1168
- package/dist/index.d.ts +7 -673
- package/dist/index.js +77 -1008
- package/dist/index.mjs +77 -1008
- package/dist/stream-FQm9h4Mg.d.ts +74 -0
- package/dist/tracing-DNT9jEbr.d.ts +106 -0
- package/package.json +11 -3
- package/dist/chunk-SKVY72E5.cjs +0 -667
- package/dist/stream-Oqe6WeLE.d.ts +0 -173
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkTGIFUAK4cjs = require('./chunk-TGIFUAK4.cjs');
|
|
4
|
+
|
|
5
|
+
// src/core/stream/structuredConcurrency.ts
|
|
6
|
+
function race(left, right, parentScope) {
|
|
7
|
+
return _chunkTGIFUAK4cjs.asyncEffect.call(void 0, (env, cb) => {
|
|
8
|
+
const scope = parentScope.subScope();
|
|
9
|
+
let done = false;
|
|
10
|
+
const onResult = (exit) => {
|
|
11
|
+
if (done) return;
|
|
12
|
+
done = true;
|
|
13
|
+
scope.close(exit);
|
|
14
|
+
cb(exit);
|
|
15
|
+
};
|
|
16
|
+
const fiberLeft = scope.fork(left);
|
|
17
|
+
const fiberRight = scope.fork(right);
|
|
18
|
+
fiberLeft.join(onResult);
|
|
19
|
+
fiberRight.join(onResult);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function zipPar(left, right, parentScope) {
|
|
23
|
+
return _chunkTGIFUAK4cjs.asyncEffect.call(void 0, (env, cb) => {
|
|
24
|
+
const scope = parentScope.subScope();
|
|
25
|
+
let leftExit = null;
|
|
26
|
+
let rightExit = null;
|
|
27
|
+
let done = false;
|
|
28
|
+
const checkDone = () => {
|
|
29
|
+
if (!leftExit || !rightExit || done) return;
|
|
30
|
+
done = true;
|
|
31
|
+
if (leftExit._tag === "Success" && rightExit._tag === "Success") {
|
|
32
|
+
scope.close({ _tag: "Success", value: void 0 });
|
|
33
|
+
cb({
|
|
34
|
+
_tag: "Success",
|
|
35
|
+
value: [leftExit.value, rightExit.value]
|
|
36
|
+
});
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
let cause;
|
|
40
|
+
if (leftExit._tag === "Failure") {
|
|
41
|
+
cause = leftExit.cause;
|
|
42
|
+
} else if (rightExit._tag === "Failure") {
|
|
43
|
+
cause = rightExit.cause;
|
|
44
|
+
} else {
|
|
45
|
+
throw new Error("zipPar: unreachable state (no Failure exit)");
|
|
46
|
+
}
|
|
47
|
+
const errExit = {
|
|
48
|
+
_tag: "Failure",
|
|
49
|
+
cause
|
|
50
|
+
};
|
|
51
|
+
scope.close(errExit);
|
|
52
|
+
cb(errExit);
|
|
53
|
+
};
|
|
54
|
+
const f1 = scope.fork(left);
|
|
55
|
+
const f2 = scope.fork(right);
|
|
56
|
+
f1.join((exit) => {
|
|
57
|
+
leftExit = exit;
|
|
58
|
+
checkDone();
|
|
59
|
+
});
|
|
60
|
+
f2.join((exit) => {
|
|
61
|
+
rightExit = exit;
|
|
62
|
+
checkDone();
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function collectAllPar(effects, parentScope) {
|
|
67
|
+
return _chunkTGIFUAK4cjs.asyncEffect.call(void 0, (env, cb) => {
|
|
68
|
+
const scope = parentScope.subScope();
|
|
69
|
+
const results = new Array(effects.length);
|
|
70
|
+
let completed = 0;
|
|
71
|
+
let done = false;
|
|
72
|
+
effects.forEach((eff, i) => {
|
|
73
|
+
const f = scope.fork(eff);
|
|
74
|
+
f.join((exit) => {
|
|
75
|
+
if (done) return;
|
|
76
|
+
if (exit._tag === "Failure") {
|
|
77
|
+
done = true;
|
|
78
|
+
const errExit = {
|
|
79
|
+
_tag: "Failure",
|
|
80
|
+
cause: exit.cause
|
|
81
|
+
};
|
|
82
|
+
scope.close(errExit);
|
|
83
|
+
cb(errExit);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
results[i] = exit.value;
|
|
87
|
+
completed++;
|
|
88
|
+
if (completed === effects.length) {
|
|
89
|
+
done = true;
|
|
90
|
+
const successExit = {
|
|
91
|
+
_tag: "Success",
|
|
92
|
+
value: results
|
|
93
|
+
};
|
|
94
|
+
scope.close({ _tag: "Success", value: void 0 });
|
|
95
|
+
cb(successExit);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
function raceWith(left, right, parentScope, onLeft, onRight) {
|
|
102
|
+
return _chunkTGIFUAK4cjs.asyncEffect.call(void 0, (env, cb) => {
|
|
103
|
+
const scope = parentScope.subScope();
|
|
104
|
+
let done = false;
|
|
105
|
+
const fiberLeft = scope.fork(left);
|
|
106
|
+
const fiberRight = scope.fork(right);
|
|
107
|
+
const finish = (next) => {
|
|
108
|
+
scope.fork(next).join((exitNext) => {
|
|
109
|
+
scope.close(exitNext);
|
|
110
|
+
cb(exitNext);
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
fiberLeft.join((exitL) => {
|
|
114
|
+
if (done) return;
|
|
115
|
+
done = true;
|
|
116
|
+
finish(onLeft(exitL, fiberRight, scope));
|
|
117
|
+
});
|
|
118
|
+
fiberRight.join((exitR) => {
|
|
119
|
+
if (done) return;
|
|
120
|
+
done = true;
|
|
121
|
+
finish(onRight(exitR, fiberLeft, scope));
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
exports.race = race; exports.zipPar = zipPar; exports.collectAllPar = collectAllPar; exports.raceWith = raceWith;
|
|
@@ -0,0 +1,489 @@
|
|
|
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
|
+
var _chunkR3R2FVLGcjs = require('./chunk-R3R2FVLG.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
var _chunkTGIFUAK4cjs = require('./chunk-TGIFUAK4.cjs');
|
|
28
|
+
|
|
29
|
+
// src/core/stream/stream.ts
|
|
30
|
+
var widenOpt = (opt) => opt._tag === "None" ? _chunkTGIFUAK4cjs.none : _chunkTGIFUAK4cjs.some.call(void 0, opt.value);
|
|
31
|
+
var fromPull = (pull) => ({
|
|
32
|
+
_tag: "FromPull",
|
|
33
|
+
pull
|
|
34
|
+
});
|
|
35
|
+
var unwrapScoped = (acquire, release) => ({
|
|
36
|
+
_tag: "Scoped",
|
|
37
|
+
acquire,
|
|
38
|
+
release
|
|
39
|
+
});
|
|
40
|
+
var managedStream = (acquire) => ({
|
|
41
|
+
_tag: "Managed",
|
|
42
|
+
acquire
|
|
43
|
+
});
|
|
44
|
+
var mergeStream = (left, right, flip = true) => ({
|
|
45
|
+
_tag: "Merge",
|
|
46
|
+
left,
|
|
47
|
+
right,
|
|
48
|
+
flip
|
|
49
|
+
});
|
|
50
|
+
var EMPTY_STREAM = { _tag: "Empty" };
|
|
51
|
+
var emptyStream = () => EMPTY_STREAM;
|
|
52
|
+
var emitStream = (value) => ({
|
|
53
|
+
_tag: "Emit",
|
|
54
|
+
value
|
|
55
|
+
});
|
|
56
|
+
var concatStream = (left, right) => ({
|
|
57
|
+
_tag: "Concat",
|
|
58
|
+
left,
|
|
59
|
+
right
|
|
60
|
+
});
|
|
61
|
+
var flattenStream = (stream) => ({
|
|
62
|
+
_tag: "Flatten",
|
|
63
|
+
stream
|
|
64
|
+
});
|
|
65
|
+
function streamToRaceWithHandler(winnerSide, leftStream, rightStream, flip, id) {
|
|
66
|
+
return (exit, otherFiber, scope) => {
|
|
67
|
+
if (exit._tag === "Failure") {
|
|
68
|
+
}
|
|
69
|
+
if (exit._tag === "Success") {
|
|
70
|
+
}
|
|
71
|
+
if (exit._tag === "Success") {
|
|
72
|
+
const [a, tailWin] = exit.value;
|
|
73
|
+
otherFiber.interrupt();
|
|
74
|
+
const next = winnerSide === "L" ? fromPull(makeMergePull(tailWin, rightStream, !flip, id)) : fromPull(makeMergePull(leftStream, tailWin, !flip, id));
|
|
75
|
+
return _chunkTGIFUAK4cjs.asyncSucceed.call(void 0, [a, next]);
|
|
76
|
+
}
|
|
77
|
+
if (exit.cause._tag === "Interrupt") {
|
|
78
|
+
return _chunkTGIFUAK4cjs.asyncEffect.call(void 0, (_env, cb) => {
|
|
79
|
+
cb(_chunkTGIFUAK4cjs.Exit.failCause(_chunkTGIFUAK4cjs.Cause.interrupt()));
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
const opt = exit.cause.error;
|
|
83
|
+
if (opt._tag === "None") {
|
|
84
|
+
return winnerSide === "L" ? uncons(rightStream) : uncons(leftStream);
|
|
85
|
+
}
|
|
86
|
+
return _chunkTGIFUAK4cjs.asyncFail.call(void 0, opt);
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function makeMergePull(onLeft, onRight, flip, mergePullId) {
|
|
90
|
+
const id = ++mergePullId;
|
|
91
|
+
const onLeftHandler = streamToRaceWithHandler("L", onLeft, onRight, flip, id);
|
|
92
|
+
const onRightHandler = streamToRaceWithHandler("R", onLeft, onRight, flip, id);
|
|
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,
|
|
97
|
+
uncons(onLeft),
|
|
98
|
+
uncons(onRight),
|
|
99
|
+
scope,
|
|
100
|
+
onLeftHandler,
|
|
101
|
+
onRightHandler
|
|
102
|
+
);
|
|
103
|
+
scope.fork(handler).join((ex) => {
|
|
104
|
+
scope.close(ex);
|
|
105
|
+
cb(ex);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
function merge(left, right) {
|
|
110
|
+
return fromPull(makeMergePull(left, right, true, 0));
|
|
111
|
+
}
|
|
112
|
+
function uncons(self) {
|
|
113
|
+
switch (self._tag) {
|
|
114
|
+
case "Empty":
|
|
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
|
+
}
|
|
122
|
+
case "Emit":
|
|
123
|
+
return _chunkTGIFUAK4cjs.map.call(void 0,
|
|
124
|
+
_chunkTGIFUAK4cjs.mapError.call(void 0, self.value, (e) => _chunkTGIFUAK4cjs.some.call(void 0, e)),
|
|
125
|
+
(a) => [a, EMPTY_STREAM]
|
|
126
|
+
);
|
|
127
|
+
case "FromPull":
|
|
128
|
+
return self.pull;
|
|
129
|
+
case "Concat":
|
|
130
|
+
return _chunkTGIFUAK4cjs.orElseOptional.call(void 0,
|
|
131
|
+
_chunkTGIFUAK4cjs.map.call(void 0,
|
|
132
|
+
uncons(self.left),
|
|
133
|
+
([a, tail]) => [a, concatStream(tail, self.right)]
|
|
134
|
+
),
|
|
135
|
+
() => uncons(self.right)
|
|
136
|
+
);
|
|
137
|
+
case "Flatten":
|
|
138
|
+
return _chunkTGIFUAK4cjs.flatMap.call(void 0,
|
|
139
|
+
uncons(self.stream),
|
|
140
|
+
([head, tail]) => _chunkTGIFUAK4cjs.orElseOptional.call(void 0,
|
|
141
|
+
_chunkTGIFUAK4cjs.map.call(void 0,
|
|
142
|
+
uncons(head),
|
|
143
|
+
([a, as]) => [
|
|
144
|
+
a,
|
|
145
|
+
concatStream(as, flattenStream(tail))
|
|
146
|
+
]
|
|
147
|
+
),
|
|
148
|
+
() => uncons(flattenStream(tail))
|
|
149
|
+
)
|
|
150
|
+
);
|
|
151
|
+
case "Merge":
|
|
152
|
+
return makeMergePull(self.left, self.right, self.flip, 0);
|
|
153
|
+
case "Scoped":
|
|
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, );
|
|
158
|
+
_optionalChain([fiber, 'optionalAccess', _2 => _2.addFinalizer, 'call', _3 => _3((exit) => {
|
|
159
|
+
try {
|
|
160
|
+
scope.close(exit);
|
|
161
|
+
} catch (e3) {
|
|
162
|
+
}
|
|
163
|
+
})]);
|
|
164
|
+
const closeWith = (exit) => {
|
|
165
|
+
if (exit._tag === "Failure") {
|
|
166
|
+
const err = exit.cause.error;
|
|
167
|
+
if (err && typeof err === "object" && err._tag === "None") {
|
|
168
|
+
scope.close({ _tag: "Success", value: void 0 });
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
scope.close(exit);
|
|
173
|
+
};
|
|
174
|
+
const wrap = (s) => fromPull(
|
|
175
|
+
_chunkTGIFUAK4cjs.asyncEffect.call(void 0, (env2, cb2) => {
|
|
176
|
+
const pull = uncons(s);
|
|
177
|
+
_chunkTGIFUAK4cjs.unsafeRunFoldWithEnv.call(void 0,
|
|
178
|
+
pull,
|
|
179
|
+
env2,
|
|
180
|
+
(cause) => {
|
|
181
|
+
const ex = _chunkTGIFUAK4cjs.Exit.failCause(cause);
|
|
182
|
+
closeWith(ex);
|
|
183
|
+
cb2(ex);
|
|
184
|
+
},
|
|
185
|
+
([a, tail]) => {
|
|
186
|
+
cb2(_chunkTGIFUAK4cjs.Exit.succeed([a, wrap(tail)]));
|
|
187
|
+
}
|
|
188
|
+
);
|
|
189
|
+
})
|
|
190
|
+
);
|
|
191
|
+
scope.fork(self.acquire).join((ex) => {
|
|
192
|
+
if (ex._tag === "Failure") {
|
|
193
|
+
closeWith(ex);
|
|
194
|
+
cb({ _tag: "Failure", cause: { _tag: "Fail", error: _chunkTGIFUAK4cjs.some.call(void 0, ex.cause.error) } });
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
scope.addFinalizer((exit) => self.release(exit));
|
|
198
|
+
const inner = ex.value;
|
|
199
|
+
_chunkTGIFUAK4cjs.unsafeGetCurrentRuntime.call(void 0, ).fork(uncons(wrap(inner))).join(cb);
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
case "Managed":
|
|
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) => {
|
|
207
|
+
try {
|
|
208
|
+
scope.close(exit);
|
|
209
|
+
} catch (e4) {
|
|
210
|
+
}
|
|
211
|
+
})]);
|
|
212
|
+
const closeWith = (exit) => {
|
|
213
|
+
if (exit._tag === "Failure") {
|
|
214
|
+
const err = exit.cause.error;
|
|
215
|
+
if (err && typeof err === "object" && err._tag === "None") {
|
|
216
|
+
scope.close({ _tag: "Success", value: void 0 });
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
scope.close(exit);
|
|
221
|
+
};
|
|
222
|
+
scope.fork(self.acquire).join((ex) => {
|
|
223
|
+
if (ex._tag === "Failure") {
|
|
224
|
+
scope.close(ex);
|
|
225
|
+
cb({ _tag: "Failure", cause: { _tag: "Fail", error: _chunkTGIFUAK4cjs.some.call(void 0, ex.cause.error) } });
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
const { stream: inner, release } = ex.value;
|
|
229
|
+
scope.addFinalizer((exit) => release(exit));
|
|
230
|
+
const wrap = (s) => fromPull(
|
|
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);
|
|
237
|
+
closeWith(ex2);
|
|
238
|
+
cb2(ex2);
|
|
239
|
+
},
|
|
240
|
+
([a, tail]) => {
|
|
241
|
+
cb2(_chunkTGIFUAK4cjs.Exit.succeed([a, wrap(tail)]));
|
|
242
|
+
}
|
|
243
|
+
);
|
|
244
|
+
})
|
|
245
|
+
);
|
|
246
|
+
_chunkTGIFUAK4cjs.unsafeGetCurrentRuntime.call(void 0, ).fork(uncons(wrap(inner))).join(cb);
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
function assertNever(x, msg) {
|
|
252
|
+
throw new Error(_nullishCoalesce(msg, () => ( `Unexpected value: ${String(x)}`)));
|
|
253
|
+
}
|
|
254
|
+
function mapStream(self, f) {
|
|
255
|
+
switch (self._tag) {
|
|
256
|
+
case "Empty":
|
|
257
|
+
return emptyStream();
|
|
258
|
+
case "FromArray":
|
|
259
|
+
return { _tag: "FromArray", values: self.values.map(f) };
|
|
260
|
+
case "Emit":
|
|
261
|
+
return emitStream(_chunkTGIFUAK4cjs.map.call(void 0, self.value, f));
|
|
262
|
+
case "FromPull":
|
|
263
|
+
return fromPull(
|
|
264
|
+
_chunkTGIFUAK4cjs.map.call(void 0, self.pull, ([a, tail]) => [f(a), mapStream(tail, f)])
|
|
265
|
+
);
|
|
266
|
+
case "Concat":
|
|
267
|
+
return concatStream(mapStream(self.left, f), mapStream(self.right, f));
|
|
268
|
+
case "Flatten": {
|
|
269
|
+
const mappedOuter = mapStream(
|
|
270
|
+
self.stream,
|
|
271
|
+
(inner) => mapStream(inner, f)
|
|
272
|
+
);
|
|
273
|
+
return flattenStream(mappedOuter);
|
|
274
|
+
}
|
|
275
|
+
case "Merge":
|
|
276
|
+
return mergeStream(
|
|
277
|
+
mapStream(self.left, f),
|
|
278
|
+
mapStream(self.right, f),
|
|
279
|
+
self.flip
|
|
280
|
+
);
|
|
281
|
+
case "Scoped":
|
|
282
|
+
return unwrapScoped(
|
|
283
|
+
_chunkTGIFUAK4cjs.map.call(void 0, self.acquire, (s) => mapStream(s, f)),
|
|
284
|
+
self.release
|
|
285
|
+
);
|
|
286
|
+
case "Managed":
|
|
287
|
+
return managedStream(
|
|
288
|
+
_chunkTGIFUAK4cjs.map.call(void 0, self.acquire, ({ stream, release }) => ({
|
|
289
|
+
stream: mapStream(stream, f),
|
|
290
|
+
release
|
|
291
|
+
}))
|
|
292
|
+
);
|
|
293
|
+
default:
|
|
294
|
+
return assertNever(self);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
function rangeStream(start, end) {
|
|
298
|
+
const go = (i) => fromPull(
|
|
299
|
+
i > end ? _chunkTGIFUAK4cjs.asyncFail.call(void 0, _chunkTGIFUAK4cjs.none) : _chunkTGIFUAK4cjs.asyncSucceed.call(void 0, [i, go(i + 1)])
|
|
300
|
+
);
|
|
301
|
+
return go(start);
|
|
302
|
+
}
|
|
303
|
+
function zip(left, right) {
|
|
304
|
+
const pull = _chunkTGIFUAK4cjs.asyncFold.call(void 0,
|
|
305
|
+
_chunkTGIFUAK4cjs.asyncMapError.call(void 0, uncons(left), (opt) => widenOpt(opt)),
|
|
306
|
+
// si left termina o falla, el zip termina/falla igual
|
|
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, [
|
|
312
|
+
[a, b],
|
|
313
|
+
zip(tailL, tailR)
|
|
314
|
+
])
|
|
315
|
+
)
|
|
316
|
+
);
|
|
317
|
+
return fromPull(pull);
|
|
318
|
+
}
|
|
319
|
+
function foreachStream(stream, f) {
|
|
320
|
+
const loop = (cur) => _chunkTGIFUAK4cjs.asyncFold.call(void 0,
|
|
321
|
+
// uncons: Option<E> -> Option<E|E2>
|
|
322
|
+
_chunkTGIFUAK4cjs.asyncMapError.call(void 0, uncons(cur), (opt) => widenOpt(opt)),
|
|
323
|
+
(opt) => {
|
|
324
|
+
if (opt._tag === "None") return _chunkTGIFUAK4cjs.asyncSucceed.call(void 0, void 0);
|
|
325
|
+
return _chunkTGIFUAK4cjs.asyncFail.call(void 0, opt);
|
|
326
|
+
},
|
|
327
|
+
([a, tail]) => _chunkTGIFUAK4cjs.asyncFlatMap.call(void 0,
|
|
328
|
+
// f(a): E2 -> Option<E|E2>
|
|
329
|
+
_chunkTGIFUAK4cjs.asyncMapError.call(void 0, f(a), (e2) => _chunkTGIFUAK4cjs.some.call(void 0, e2)),
|
|
330
|
+
() => loop(tail)
|
|
331
|
+
)
|
|
332
|
+
);
|
|
333
|
+
return _chunkTGIFUAK4cjs.asyncFold.call(void 0,
|
|
334
|
+
loop(stream),
|
|
335
|
+
(opt) => {
|
|
336
|
+
if (opt._tag === "None") return _chunkTGIFUAK4cjs.asyncSucceed.call(void 0, void 0);
|
|
337
|
+
return _chunkTGIFUAK4cjs.asyncFail.call(void 0, opt.value);
|
|
338
|
+
},
|
|
339
|
+
() => _chunkTGIFUAK4cjs.asyncSucceed.call(void 0, void 0)
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
function fromArray(values) {
|
|
343
|
+
if (values.length === 0) return emptyStream();
|
|
344
|
+
return { _tag: "FromArray", values };
|
|
345
|
+
}
|
|
346
|
+
function collectStream(stream) {
|
|
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,
|
|
352
|
+
uncons(cur),
|
|
353
|
+
(opt) => {
|
|
354
|
+
if (opt._tag === "None") return _chunkTGIFUAK4cjs.succeed.call(void 0, acc);
|
|
355
|
+
return _chunkTGIFUAK4cjs.fail.call(void 0, opt);
|
|
356
|
+
},
|
|
357
|
+
([a, tail]) => {
|
|
358
|
+
acc.push(a);
|
|
359
|
+
return loop(tail, acc);
|
|
360
|
+
}
|
|
361
|
+
);
|
|
362
|
+
return _chunkTGIFUAK4cjs.mapError.call(void 0, loop(stream, []), (opt) => {
|
|
363
|
+
if (opt._tag === "Some") return opt.value;
|
|
364
|
+
throw new Error("unreachable: stream end handled as success");
|
|
365
|
+
});
|
|
366
|
+
}
|
|
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 } });
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
finish({
|
|
432
|
+
_tag: "Success",
|
|
433
|
+
value: [value, fromPull(pull)]
|
|
434
|
+
});
|
|
435
|
+
}).catch((e) => {
|
|
436
|
+
finish({ _tag: "Failure", cause: { _tag: "Fail", error: _chunkTGIFUAK4cjs.some.call(void 0, normalizeError(e)) } });
|
|
437
|
+
});
|
|
438
|
+
return () => {
|
|
439
|
+
cleanup();
|
|
440
|
+
try {
|
|
441
|
+
reader.cancel();
|
|
442
|
+
} catch (e6) {
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
});
|
|
446
|
+
return fromPull(pull);
|
|
447
|
+
}
|
|
448
|
+
function streamFromReadableStream(body, normalizeError, options = {}) {
|
|
449
|
+
if (!body) return emptyStream();
|
|
450
|
+
let reader;
|
|
451
|
+
return unwrapScoped(
|
|
452
|
+
// acquire: produce un ZStream
|
|
453
|
+
_chunkTGIFUAK4cjs.sync.call(void 0, () => {
|
|
454
|
+
reader = body.getReader();
|
|
455
|
+
return readerStream(reader, normalizeError, options.signal);
|
|
456
|
+
}),
|
|
457
|
+
// release: se corre en fin / error / interrupción
|
|
458
|
+
() => _chunkTGIFUAK4cjs.asyncSync.call(void 0, () => {
|
|
459
|
+
try {
|
|
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()]);
|
|
464
|
+
}
|
|
465
|
+
})
|
|
466
|
+
);
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
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;
|