clanka 0.26.0 → 0.27.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 +2 -3
- package/dist/Acp.test.js +2 -3
- package/dist/Acp.test.js.map +1 -1
- package/dist/AcpImage.test.js +0 -1
- package/dist/AcpImage.test.js.map +1 -1
- package/dist/Agent.d.ts.map +1 -1
- package/dist/Agent.js +7 -7
- package/dist/Agent.js.map +1 -1
- package/dist/Agent.test.js +7 -7
- package/dist/Agent.test.js.map +1 -1
- package/dist/AgentBashJobs.test.js +7 -7
- package/dist/AgentBashJobs.test.js.map +1 -1
- package/dist/AgentCallerConfig.test.js +0 -1
- package/dist/AgentCallerConfig.test.js.map +1 -1
- package/dist/AgentExecutor.d.ts +2 -3
- package/dist/AgentExecutor.d.ts.map +1 -1
- package/dist/AgentExecutor.js +4 -13
- package/dist/AgentExecutor.js.map +1 -1
- package/dist/AgentExecutor.test.js +20 -20
- package/dist/AgentExecutor.test.js.map +1 -1
- package/dist/AgentImage.test.js +1 -2
- package/dist/AgentImage.test.js.map +1 -1
- package/dist/AgentSkills.test.js +0 -2
- package/dist/AgentSkills.test.js.map +1 -1
- package/dist/AgentSubagents.test.js +57 -29
- package/dist/AgentSubagents.test.js.map +1 -1
- package/dist/AgentTools.d.ts +6 -238
- package/dist/AgentTools.d.ts.map +1 -1
- package/dist/AgentTools.js +11 -39
- package/dist/AgentTools.js.map +1 -1
- package/dist/ClaudeAgent.test.js +0 -1
- package/dist/ClaudeAgent.test.js.map +1 -1
- package/dist/ScriptFormatting.d.ts +5 -0
- package/dist/ScriptFormatting.d.ts.map +1 -1
- package/dist/ScriptFormatting.js +255 -53
- package/dist/ScriptFormatting.js.map +1 -1
- package/dist/ScriptFormatting.test.js +16 -0
- package/dist/ScriptFormatting.test.js.map +1 -1
- package/dist/bin/{Latch-DOdbsGMQ.mjs → Latch-BE6_TYRL.mjs} +1 -1
- package/dist/bin/{McpClient-B-FFG6Pg.mjs → McpClient-DCt4v5W5.mjs} +2 -2
- package/dist/bin/{OutputFormatter-DhhP2i-7.mjs → OutputFormatter-DaFv_C_I.mjs} +2 -3
- package/dist/bin/{Schema-CFdSO6iH.mjs → Schema-B3MiG1aD.mjs} +204 -568
- package/dist/bin/cli.mjs +5106 -2479
- package/dist/bin/{upgrade-C4aOEWJH.mjs → upgrade-WqgIU_21.mjs} +3 -3
- package/dist/cli.js +2 -25
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +0 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -7
- package/src/Acp.test.ts +2 -3
- package/src/AcpImage.test.ts +0 -1
- package/src/Agent.test.ts +10 -7
- package/src/Agent.ts +8 -10
- package/src/AgentBashJobs.test.ts +9 -9
- package/src/AgentCallerConfig.test.ts +0 -1
- package/src/AgentExecutor.test.ts +20 -20
- package/src/AgentExecutor.ts +4 -16
- package/src/AgentImage.test.ts +1 -2
- package/src/AgentSkills.test.ts +0 -2
- package/src/AgentSubagents.test.ts +77 -34
- package/src/AgentTools.ts +19 -51
- package/src/ClaudeAgent.test.ts +0 -1
- package/src/ScriptFormatting.test.ts +20 -0
- package/src/ScriptFormatting.ts +234 -47
- package/src/cli.ts +1 -56
- package/src/index.ts +0 -10
- package/dist/ChunkRepo.d.ts +0 -173
- package/dist/ChunkRepo.d.ts.map +0 -1
- package/dist/ChunkRepo.js +0 -168
- package/dist/ChunkRepo.js.map +0 -1
- package/dist/ChunkRepo.test.d.ts +0 -2
- package/dist/ChunkRepo.test.d.ts.map +0 -1
- package/dist/ChunkRepo.test.js +0 -63
- package/dist/ChunkRepo.test.js.map +0 -1
- package/dist/CodeChunker.d.ts +0 -84
- package/dist/CodeChunker.d.ts.map +0 -1
- package/dist/CodeChunker.js +0 -658
- package/dist/CodeChunker.js.map +0 -1
- package/dist/CodeChunker.test.d.ts +0 -2
- package/dist/CodeChunker.test.d.ts.map +0 -1
- package/dist/CodeChunker.test.js +0 -434
- package/dist/CodeChunker.test.js.map +0 -1
- package/dist/SemanticSearch/Service.d.ts +0 -31
- package/dist/SemanticSearch/Service.d.ts.map +0 -1
- package/dist/SemanticSearch/Service.js +0 -29
- package/dist/SemanticSearch/Service.js.map +0 -1
- package/dist/SemanticSearch.d.ts +0 -34
- package/dist/SemanticSearch.d.ts.map +0 -1
- package/dist/SemanticSearch.js +0 -171
- package/dist/SemanticSearch.js.map +0 -1
- package/dist/SemanticSearch.test.d.ts +0 -2
- package/dist/SemanticSearch.test.d.ts.map +0 -1
- package/dist/SemanticSearch.test.js +0 -34
- package/dist/SemanticSearch.test.js.map +0 -1
- package/dist/Sqlite.d.ts +0 -15
- package/dist/Sqlite.d.ts.map +0 -1
- package/dist/Sqlite.js +0 -44
- package/dist/Sqlite.js.map +0 -1
- package/dist/bin/AiError-DBaKz35C.mjs +0 -2723
- package/dist/bin/SemanticSearch-C3a7LAQr.mjs +0 -2558
- package/src/ChunkRepo.test.ts +0 -89
- package/src/ChunkRepo.ts +0 -260
- package/src/CodeChunker.test.ts +0 -493
- package/src/CodeChunker.ts +0 -1018
- package/src/SemanticSearch/Service.ts +0 -50
- package/src/SemanticSearch.test.ts +0 -51
- package/src/SemanticSearch.ts +0 -282
- package/src/Sqlite.ts +0 -60
|
@@ -1,2723 +0,0 @@
|
|
|
1
|
-
import { $c as suspend$3, $i as gen, $l as format, $u as causeFail, Aa as provideService$2, Ad as isString$1, Ai as contextWith, B as String$1, Bc as findRecoverableError, Bi as flatMap$2, Bo as catchDone, Bu as none, Ca as onInterrupt, Cl as fromIterable$1, Da as promise, Dc as callback$2, Ec as asSome, El as isArrayNonEmpty, Fc as fiberInterrupt, Fd as constTrue, Fi as exit, Gi as forEach, Gs as addFinalizerExit, H as Struct, Hi as flatten$2, Hl as fail$4, Ho as filterDone, I as Record, Ic as fiberInterruptAll, Ii as fail$3, Ja as succeedNone$1, Jc as onExitUnsafe, Js as forkUnsafe, Ki as forever, Kl as isFailure, Ko as nextPow2, Ks as close, L as Redacted, Lc as fiberInterruptAllAs, Ld as constVoid, Li as failCause$3, Lu as isSome, Ma as raceFirst, Mc as exitVoid, Mi as die$3, Ml as map$3, Nc as exitZipRight, Oi as catch_$2, Ol as isReadonlyArrayNonEmpty, Pc as fiberAwait, Pi as ensuring$2, Pl as of, Qa as tap$1, Qc as succeedNone, Ql as normalizeNonEmpty, Qo as Done$1, Qu as args, Ra as runForkWith, Rc as fiberJoin, Rd as constant, Ru as map$4, Sa as onExitPrimitive$1, Sn as withDecodingDefault, T as MutableJson, Tc as andThen$1, Ts as squash, Ua as scopedWith, Uc as getCurrentFiber, Uo as isDoneCause, Us as Scope, Uu as some, Vc as flatMap$3, Vd as identity, Vi as flatMapEager, Vl as headUnsafe, Vo as doneExitFromCause, Wd as pipeArguments, Wi as fnUntraced, Wo as matchEffect, Ws as addFinalizer, Xa as suspend$2, Xc as scopeAddFinalizer, Xi as forkScoped, Xs as makeUnsafe$1, Xu as Done, Ya as succeedSome, Yc as scope, Yi as forkIn, Yl as succeed$5, Za as sync, Zc as succeed$4, Zl as normalize, Zs as provide, Zu as PipeInspectableProto, _a as matchCauseEffect, _c as isExit$1, _i as callback$1, _s as isDone, ad as makePrimitive, ai as acquireRelease, b as Int, ba as onError, bc as succeed$2, da as map$2, dc as asVoidAll, ds as fromReasons, ed as evaluate, el as sync$1, eo as tapError$2, fc as die$4, fi as as, fn as optional, fo as void_, g as Error$1, gc as interrupt$1, hn as tag, ho as withFiber, hs as isCause, hu as get$1, ic as interruptWith, id as isExit, io as tryPromise, it as Unknown, j as NullOr, jc as exitInterrupt$1, jd as isTagged, jl as lastNonEmpty, ka as provideContext$2, ki as context, l as DateTimeUtc, lc as makeUnsafe$2, li as andThen, m as Duration, ma as mapError$2, mc as failCause$4, mi as asVoid, mo as whileLoop, mu as empty$2, n as ArraySchema, na as interrupt$2, nc as doneUnsafe, nd as exitFailCause, oa as logError, od as withFiber$1, os as die$2, p as Defect, pc as fail$5, pd as toJson, po as when, ps as hasInterruptsOnly, qa as succeed$3, qc as onExitPrimitive, qi as forkChild, ql as isSuccess$1, rd as exitSucceed, rl as void_$1, rt as Union, so as uninterruptible, ss as done, ta as ignoreCause, td as exitFail, tl as uninterruptibleMask, vc as isFailure$1, vi as catchCause$2, w as Literals, xa as onExit$2, xc as void_$2, xd as hasProperty, xn as withConstructorDefault, ya as never, yc as isSuccess, yo as yieldNow, za as runPromiseWith, zc as fiberRunIn, zd as dual } from "./Schema-CFdSO6iH.mjs";
|
|
2
|
-
import { n as makeUnsafe$3, t as make$6 } from "./Latch-DOdbsGMQ.mjs";
|
|
3
|
-
// node_modules/.pnpm/effect@4.1.3/node_modules/effect/dist/String.js
|
|
4
|
-
const String = globalThis.String;
|
|
5
|
-
const isString = isString$1;
|
|
6
|
-
const toLowerCase = (self) => self.toLowerCase();
|
|
7
|
-
const camelToSnake = (self) => self.replace(/([A-Z])/g, "_$1").toLowerCase();
|
|
8
|
-
// node_modules/.pnpm/effect@4.1.3/node_modules/effect/dist/Fiber.js
|
|
9
|
-
const await_ = fiberAwait;
|
|
10
|
-
const join = fiberJoin;
|
|
11
|
-
const interrupt = fiberInterrupt;
|
|
12
|
-
const interruptAll = fiberInterruptAll;
|
|
13
|
-
const interruptAllAs = fiberInterruptAllAs;
|
|
14
|
-
const getCurrent = getCurrentFiber;
|
|
15
|
-
const runIn = fiberRunIn;
|
|
16
|
-
// node_modules/.pnpm/effect@4.1.3/node_modules/effect/dist/MutableRef.js
|
|
17
|
-
const TypeId$6 = "~effect/MutableRef";
|
|
18
|
-
const MutableRefProto = {
|
|
19
|
-
[TypeId$6]: TypeId$6,
|
|
20
|
-
...PipeInspectableProto,
|
|
21
|
-
toJSON() {
|
|
22
|
-
return {
|
|
23
|
-
_id: "MutableRef",
|
|
24
|
-
current: toJson(this.current)
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
const make$5 = (value) => {
|
|
29
|
-
const ref = Object.create(MutableRefProto);
|
|
30
|
-
ref.current = value;
|
|
31
|
-
return ref;
|
|
32
|
-
};
|
|
33
|
-
const get = (self) => self.current;
|
|
34
|
-
const set = dual(2, (self, value) => {
|
|
35
|
-
self.current = value;
|
|
36
|
-
return self;
|
|
37
|
-
});
|
|
38
|
-
const update = dual(2, (self, f) => set(self, f(get(self))));
|
|
39
|
-
// node_modules/.pnpm/effect@4.1.3/node_modules/effect/dist/MutableList.js
|
|
40
|
-
const Empty = Symbol.for("effect/MutableList/Empty");
|
|
41
|
-
const make$4 = () => ({
|
|
42
|
-
head: void 0,
|
|
43
|
-
tail: void 0,
|
|
44
|
-
length: 0
|
|
45
|
-
});
|
|
46
|
-
const compactHead = (self) => {
|
|
47
|
-
const head = self.head;
|
|
48
|
-
if (head.offset >= 1024 && head === self.tail && head.mutable && (head.array.length - head.offset) * 8 <= head.offset) self.head = self.tail = {
|
|
49
|
-
array: head.array.slice(head.offset),
|
|
50
|
-
mutable: true,
|
|
51
|
-
offset: 0,
|
|
52
|
-
next: void 0
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
const emptyBucket = () => ({
|
|
56
|
-
array: [],
|
|
57
|
-
mutable: true,
|
|
58
|
-
offset: 0,
|
|
59
|
-
next: void 0
|
|
60
|
-
});
|
|
61
|
-
const append = (self, message) => {
|
|
62
|
-
if (!self.tail) self.head = self.tail = emptyBucket();
|
|
63
|
-
else if (!self.tail.mutable) {
|
|
64
|
-
self.tail.next = emptyBucket();
|
|
65
|
-
self.tail = self.tail.next;
|
|
66
|
-
}
|
|
67
|
-
self.tail.array.push(message);
|
|
68
|
-
self.length++;
|
|
69
|
-
};
|
|
70
|
-
const prepend = (self, message) => {
|
|
71
|
-
self.head = {
|
|
72
|
-
array: [message],
|
|
73
|
-
mutable: true,
|
|
74
|
-
offset: 0,
|
|
75
|
-
next: self.head
|
|
76
|
-
};
|
|
77
|
-
if (!self.tail) self.tail = self.head;
|
|
78
|
-
self.length++;
|
|
79
|
-
};
|
|
80
|
-
const appendAll = (self, messages) => appendAllUnsafe(self, Array.from(messages), true);
|
|
81
|
-
const appendAllUnsafe = (self, messages, mutable = false) => {
|
|
82
|
-
if (messages.length === 0) return 0;
|
|
83
|
-
const chunk = {
|
|
84
|
-
array: messages,
|
|
85
|
-
mutable,
|
|
86
|
-
offset: 0,
|
|
87
|
-
next: void 0
|
|
88
|
-
};
|
|
89
|
-
if (self.head) self.tail = self.tail.next = chunk;
|
|
90
|
-
else self.head = self.tail = chunk;
|
|
91
|
-
self.length += messages.length;
|
|
92
|
-
return messages.length;
|
|
93
|
-
};
|
|
94
|
-
const clear = (self) => {
|
|
95
|
-
self.head = self.tail = void 0;
|
|
96
|
-
self.length = 0;
|
|
97
|
-
};
|
|
98
|
-
const takeN = (self, n) => {
|
|
99
|
-
n = normalize(n);
|
|
100
|
-
if (n <= 0 || !self.head) return [];
|
|
101
|
-
n = Math.min(n, self.length);
|
|
102
|
-
if (n === self.length && self.head?.offset === 0 && !self.head.next) {
|
|
103
|
-
const array = self.head.array;
|
|
104
|
-
clear(self);
|
|
105
|
-
return array;
|
|
106
|
-
}
|
|
107
|
-
const array = new Array(n);
|
|
108
|
-
let index = 0;
|
|
109
|
-
let chunk = self.head;
|
|
110
|
-
while (chunk) {
|
|
111
|
-
while (chunk.offset < chunk.array.length) {
|
|
112
|
-
array[index++] = chunk.array[chunk.offset];
|
|
113
|
-
if (chunk.mutable) chunk.array[chunk.offset] = void 0;
|
|
114
|
-
chunk.offset++;
|
|
115
|
-
if (index === n) {
|
|
116
|
-
self.head = chunk.offset === chunk.array.length && chunk.next ? chunk.next : chunk;
|
|
117
|
-
self.length -= n;
|
|
118
|
-
if (self.length === 0) clear(self);
|
|
119
|
-
else compactHead(self);
|
|
120
|
-
return array;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
chunk = chunk.next;
|
|
124
|
-
}
|
|
125
|
-
clear(self);
|
|
126
|
-
return array;
|
|
127
|
-
};
|
|
128
|
-
const takeNVoid = (self, n) => {
|
|
129
|
-
n = normalize(n);
|
|
130
|
-
if (n <= 0 || !self.head) return;
|
|
131
|
-
n = Math.min(n, self.length);
|
|
132
|
-
if (n === self.length && self.head?.offset === 0 && !self.head.next) {
|
|
133
|
-
clear(self);
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
let count = 0;
|
|
137
|
-
let chunk = self.head;
|
|
138
|
-
while (chunk) {
|
|
139
|
-
const size = chunk.array.length - chunk.offset;
|
|
140
|
-
if (count + size > n) {
|
|
141
|
-
chunk.offset += n - count;
|
|
142
|
-
self.head = chunk;
|
|
143
|
-
self.length -= n;
|
|
144
|
-
compactHead(self);
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
count += size;
|
|
148
|
-
chunk = chunk.next;
|
|
149
|
-
}
|
|
150
|
-
clear(self);
|
|
151
|
-
};
|
|
152
|
-
const takeAll$2 = (self) => takeN(self, self.length);
|
|
153
|
-
const take$3 = (self) => {
|
|
154
|
-
if (!self.head) return Empty;
|
|
155
|
-
const message = self.head.array[self.head.offset];
|
|
156
|
-
if (self.head.mutable) self.head.array[self.head.offset] = void 0;
|
|
157
|
-
self.head.offset++;
|
|
158
|
-
self.length--;
|
|
159
|
-
if (self.head.offset === self.head.array.length) {
|
|
160
|
-
if (self.head.next) self.head = self.head.next;
|
|
161
|
-
else clear(self);
|
|
162
|
-
} else compactHead(self);
|
|
163
|
-
return message;
|
|
164
|
-
};
|
|
165
|
-
const filter$1 = (self, f) => {
|
|
166
|
-
const array = [];
|
|
167
|
-
let chunk = self.head;
|
|
168
|
-
let index = 0;
|
|
169
|
-
while (chunk) {
|
|
170
|
-
for (let i = chunk.offset; i < chunk.array.length; i++) if (f(chunk.array[i], index++)) array.push(chunk.array[i]);
|
|
171
|
-
chunk = chunk.next;
|
|
172
|
-
}
|
|
173
|
-
if (array.length === 0) {
|
|
174
|
-
clear(self);
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
self.head = self.tail = {
|
|
178
|
-
array,
|
|
179
|
-
mutable: true,
|
|
180
|
-
offset: 0,
|
|
181
|
-
next: void 0
|
|
182
|
-
};
|
|
183
|
-
self.length = array.length;
|
|
184
|
-
};
|
|
185
|
-
const remove = (self, value) => filter$1(self, (v) => v !== value);
|
|
186
|
-
// node_modules/.pnpm/effect@4.1.3/node_modules/effect/dist/PubSub.js
|
|
187
|
-
const TypeId$5 = "~effect/PubSub";
|
|
188
|
-
const SubscriptionTypeId = "~effect/PubSub/Subscription";
|
|
189
|
-
const make$3 = (options) => sync(() => makePubSubUnsafe(options.atomicPubSub(), new Map(), makeUnsafe$1(), makeUnsafe$3(false), make$5(false), options.strategy(), make$5(none())));
|
|
190
|
-
const bounded$1 = (capacity) => make$3({
|
|
191
|
-
atomicPubSub: () => makeAtomicBounded(capacity),
|
|
192
|
-
strategy: () => new BackPressureStrategy()
|
|
193
|
-
});
|
|
194
|
-
const dropping = (capacity) => make$3({
|
|
195
|
-
atomicPubSub: () => makeAtomicBounded(capacity),
|
|
196
|
-
strategy: () => new DroppingStrategy()
|
|
197
|
-
});
|
|
198
|
-
const sliding$1 = (capacity) => make$3({
|
|
199
|
-
atomicPubSub: () => makeAtomicBounded(capacity),
|
|
200
|
-
strategy: () => new SlidingStrategy()
|
|
201
|
-
});
|
|
202
|
-
const unbounded$1 = (options) => make$3({
|
|
203
|
-
atomicPubSub: () => makeAtomicUnbounded(options),
|
|
204
|
-
strategy: () => new DroppingStrategy()
|
|
205
|
-
});
|
|
206
|
-
const makeAtomicBounded = (capacity) => {
|
|
207
|
-
const options = typeof capacity === "number" ? { capacity } : capacity;
|
|
208
|
-
ensureCapacity(options.capacity);
|
|
209
|
-
if (options.capacity === Infinity) return makeAtomicUnbounded(options);
|
|
210
|
-
const replayBuffer = options.replay && options.replay > 0 ? new ReplayBuffer(Math.ceil(options.replay)) : void 0;
|
|
211
|
-
if (options.capacity === 1) return new BoundedPubSubSingle(replayBuffer);
|
|
212
|
-
else if (nextPow2(options.capacity) === options.capacity) return new BoundedPubSubPow2(options.capacity, replayBuffer);
|
|
213
|
-
else return new BoundedPubSubArb(options.capacity, replayBuffer);
|
|
214
|
-
};
|
|
215
|
-
const makeAtomicUnbounded = (options) => {
|
|
216
|
-
const replay = options?.replay;
|
|
217
|
-
return new UnboundedPubSub(replay && replay > 0 ? new ReplayBuffer(Math.ceil(replay)) : void 0);
|
|
218
|
-
};
|
|
219
|
-
const shutdown$1 = (self) => uninterruptible(withFiber((fiber) => {
|
|
220
|
-
set(self.shutdownFlag, true);
|
|
221
|
-
return close(self.scope, interrupt$1(fiber.id)).pipe(andThen(self.strategy.shutdown), when(self.shutdownHook.open), asVoid);
|
|
222
|
-
}));
|
|
223
|
-
const end$1 = dual(2, (self, value) => sync(() => endUnsafe$1(self, value)));
|
|
224
|
-
const endUnsafe$1 = dual(2, (self, value) => {
|
|
225
|
-
if (self.shutdownFlag.current || isSome(self.ended.current)) return false;
|
|
226
|
-
set(self.ended, some(value));
|
|
227
|
-
if (self.strategy instanceof BackPressureStrategy) {
|
|
228
|
-
for (const [_, deferred, last] of takeAll$2(self.strategy.publishers)) if (last) doneUnsafe(deferred, succeed$2(false));
|
|
229
|
-
}
|
|
230
|
-
const exit = succeed$2(value);
|
|
231
|
-
for (const pollersSet of self.subscribers.values()) for (const pollers of pollersSet) {
|
|
232
|
-
let poller;
|
|
233
|
-
while ((poller = take$3(pollers)) !== Empty) doneUnsafe(poller, exit);
|
|
234
|
-
}
|
|
235
|
-
self.subscribers.clear();
|
|
236
|
-
return true;
|
|
237
|
-
});
|
|
238
|
-
const publish = dual(2, (self, value) => suspend$2(() => {
|
|
239
|
-
if (self.shutdownFlag.current || isSome(self.ended.current)) return succeed$3(false);
|
|
240
|
-
if (self.pubsub.publish(value)) {
|
|
241
|
-
self.strategy.completeSubscribersUnsafe(self.pubsub, self.subscribers);
|
|
242
|
-
return succeed$3(true);
|
|
243
|
-
}
|
|
244
|
-
return self.strategy.handleSurplus(self.pubsub, self.subscribers, [value], self.shutdownFlag, self.ended);
|
|
245
|
-
}));
|
|
246
|
-
const publishAll = dual(2, (self, elements) => suspend$2(() => {
|
|
247
|
-
if (self.shutdownFlag.current || isSome(self.ended.current)) return succeed$3(false);
|
|
248
|
-
const surplus = self.pubsub.publishAll(elements);
|
|
249
|
-
self.strategy.completeSubscribersUnsafe(self.pubsub, self.subscribers);
|
|
250
|
-
if (surplus.length === 0) return succeed$3(true);
|
|
251
|
-
return self.strategy.handleSurplus(self.pubsub, self.subscribers, surplus, self.shutdownFlag, self.ended);
|
|
252
|
-
}));
|
|
253
|
-
const subscribe = (self) => uninterruptible(contextWith((services) => {
|
|
254
|
-
const localScope = get$1(services, Scope);
|
|
255
|
-
const scope = forkUnsafe(self.scope);
|
|
256
|
-
const subscription = makeSubscriptionUnsafe(self.pubsub, self.subscribers, self.strategy, self.ended);
|
|
257
|
-
return addFinalizer(scope, unsubscribe(subscription)).pipe(andThen(addFinalizerExit(localScope, (exit) => close(scope, exit))), as(subscription));
|
|
258
|
-
}));
|
|
259
|
-
const unsubscribe = (self) => uninterruptible(withFiber((state) => {
|
|
260
|
-
set(self.shutdownFlag, true);
|
|
261
|
-
return forEach(takeAll$2(self.pollers), (d) => interruptWith(d, state.id), {
|
|
262
|
-
discard: true,
|
|
263
|
-
concurrency: "unbounded"
|
|
264
|
-
}).pipe(tap$1(() => sync(() => {
|
|
265
|
-
self.subscribers.delete(self.subscription);
|
|
266
|
-
self.subscription.unsubscribe();
|
|
267
|
-
self.replayWindow.close();
|
|
268
|
-
self.strategy.onPubSubEmptySpaceUnsafe(self.pubsub, self.subscribers);
|
|
269
|
-
})), when(self.shutdownHook.open), asVoid);
|
|
270
|
-
}));
|
|
271
|
-
const take$2 = (self) => suspend$2(() => {
|
|
272
|
-
if (self.shutdownFlag.current) return interrupt$2;
|
|
273
|
-
if (self.replayWindow.remaining > 0) {
|
|
274
|
-
const message = self.replayWindow.take();
|
|
275
|
-
return succeed$3(message);
|
|
276
|
-
}
|
|
277
|
-
const message = self.pollers.length === 0 ? self.subscription.poll() : Empty;
|
|
278
|
-
if (message === Empty) return pollForItem(self);
|
|
279
|
-
else {
|
|
280
|
-
self.strategy.onPubSubEmptySpaceUnsafe(self.pubsub, self.subscribers);
|
|
281
|
-
return succeed$3(message);
|
|
282
|
-
}
|
|
283
|
-
});
|
|
284
|
-
const takeAll$1 = (self) => suspend$2(function loop(value) {
|
|
285
|
-
if (self.shutdownFlag.current) return interrupt$2;
|
|
286
|
-
let as = self.pollers.length === 0 ? self.subscription.pollUpTo(Number.POSITIVE_INFINITY) : [];
|
|
287
|
-
if (value) as = value.concat(as);
|
|
288
|
-
self.strategy.onPubSubEmptySpaceUnsafe(self.pubsub, self.subscribers);
|
|
289
|
-
if (self.replayWindow.remaining > 0) return succeed$3(self.replayWindow.takeAll().concat(as));
|
|
290
|
-
else if (!isArrayNonEmpty(as)) return flatMap$2(pollForItem(self), (item) => loop([item]));
|
|
291
|
-
return succeed$3(as);
|
|
292
|
-
});
|
|
293
|
-
const pollForItem = (self) => callback$1((resume) => {
|
|
294
|
-
if (self.shutdownFlag.current) return resume(interrupt$2);
|
|
295
|
-
if (isSome(self.ended.current)) {
|
|
296
|
-
const message = self.pollers.length === 0 ? self.subscription.poll() : Empty;
|
|
297
|
-
if (message !== Empty) {
|
|
298
|
-
self.strategy.onPubSubEmptySpaceUnsafe(self.pubsub, self.subscribers);
|
|
299
|
-
return resume(succeed$3(message));
|
|
300
|
-
}
|
|
301
|
-
return resume(succeed$3(self.ended.current.value));
|
|
302
|
-
}
|
|
303
|
-
const deferred = makeUnsafe$2();
|
|
304
|
-
let set = self.subscribers.get(self.subscription);
|
|
305
|
-
if (!set) {
|
|
306
|
-
set = new Set();
|
|
307
|
-
self.subscribers.set(self.subscription, set);
|
|
308
|
-
}
|
|
309
|
-
set.add(self.pollers);
|
|
310
|
-
append(self.pollers, deferred);
|
|
311
|
-
self.strategy.completePollersUnsafe(self.pubsub, self.subscribers, self.subscription, self.pollers);
|
|
312
|
-
if (deferred.effect) return resume(deferred.effect);
|
|
313
|
-
deferred.resumes = [resume];
|
|
314
|
-
return sync(() => remove(self.pollers, deferred));
|
|
315
|
-
});
|
|
316
|
-
const AbsentValue = Symbol.for("effect/PubSub/AbsentValue");
|
|
317
|
-
const addSubscribers = (subscribers, subscription, pollers) => {
|
|
318
|
-
if (!subscribers.has(subscription)) subscribers.set(subscription, new Set());
|
|
319
|
-
subscribers.get(subscription).add(pollers);
|
|
320
|
-
};
|
|
321
|
-
const removeSubscribers = (subscribers, subscription, pollers) => {
|
|
322
|
-
if (!subscribers.has(subscription)) return;
|
|
323
|
-
const set = subscribers.get(subscription);
|
|
324
|
-
set.delete(pollers);
|
|
325
|
-
if (set.size === 0) subscribers.delete(subscription);
|
|
326
|
-
};
|
|
327
|
-
const makeSubscriptionUnsafe = (pubsub, subscribers, strategy, ended) => new SubscriptionImpl(pubsub, subscribers, pubsub.subscribe(), make$4(), makeUnsafe$3(false), make$5(false), strategy, pubsub.replayWindow(), ended);
|
|
328
|
-
var BoundedPubSubArb = class {
|
|
329
|
-
array;
|
|
330
|
-
replayIndices;
|
|
331
|
-
publisherIndex = 0;
|
|
332
|
-
subscribers;
|
|
333
|
-
subscriberCount = 0;
|
|
334
|
-
subscribersIndex = 0;
|
|
335
|
-
capacity;
|
|
336
|
-
replayBuffer;
|
|
337
|
-
constructor(capacity, replayBuffer) {
|
|
338
|
-
this.capacity = capacity;
|
|
339
|
-
this.replayBuffer = replayBuffer;
|
|
340
|
-
this.array = Array.from({ length: capacity });
|
|
341
|
-
this.replayIndices = replayBuffer ? Array.from({ length: capacity }) : [];
|
|
342
|
-
this.subscribers = Array.from({ length: capacity });
|
|
343
|
-
}
|
|
344
|
-
replayWindow() {
|
|
345
|
-
return this.replayBuffer ? new ReplayWindowImpl(this.replayBuffer) : emptyReplayWindow;
|
|
346
|
-
}
|
|
347
|
-
isEmpty() {
|
|
348
|
-
return this.publisherIndex === this.subscribersIndex;
|
|
349
|
-
}
|
|
350
|
-
isFull() {
|
|
351
|
-
return this.publisherIndex === this.subscribersIndex + this.capacity;
|
|
352
|
-
}
|
|
353
|
-
size() {
|
|
354
|
-
return this.publisherIndex - this.subscribersIndex;
|
|
355
|
-
}
|
|
356
|
-
publish(value) {
|
|
357
|
-
if (this.isFull()) return false;
|
|
358
|
-
const replayIndex = this.replayBuffer?.offer(value);
|
|
359
|
-
if (this.subscriberCount !== 0) {
|
|
360
|
-
const index = this.publisherIndex % this.capacity;
|
|
361
|
-
this.array[index] = value;
|
|
362
|
-
if (replayIndex !== void 0) this.replayIndices[index] = replayIndex;
|
|
363
|
-
this.subscribers[index] = this.subscriberCount;
|
|
364
|
-
this.publisherIndex += 1;
|
|
365
|
-
}
|
|
366
|
-
return true;
|
|
367
|
-
}
|
|
368
|
-
publishAll(elements) {
|
|
369
|
-
if (this.subscriberCount === 0) {
|
|
370
|
-
if (this.replayBuffer) this.replayBuffer.offerAll(elements);
|
|
371
|
-
return [];
|
|
372
|
-
}
|
|
373
|
-
const chunk = fromIterable$1(elements);
|
|
374
|
-
const n = chunk.length;
|
|
375
|
-
const size = this.publisherIndex - this.subscribersIndex;
|
|
376
|
-
const available = this.capacity - size;
|
|
377
|
-
const forPubSub = Math.min(n, available);
|
|
378
|
-
if (forPubSub === 0) return chunk;
|
|
379
|
-
let iteratorIndex = 0;
|
|
380
|
-
const publishAllIndex = this.publisherIndex + forPubSub;
|
|
381
|
-
while (this.publisherIndex !== publishAllIndex) {
|
|
382
|
-
const a = chunk[iteratorIndex++];
|
|
383
|
-
const index = this.publisherIndex % this.capacity;
|
|
384
|
-
this.array[index] = a;
|
|
385
|
-
const replayIndex = this.replayBuffer?.offer(a);
|
|
386
|
-
if (replayIndex !== void 0) this.replayIndices[index] = replayIndex;
|
|
387
|
-
this.subscribers[index] = this.subscriberCount;
|
|
388
|
-
this.publisherIndex += 1;
|
|
389
|
-
}
|
|
390
|
-
return chunk.slice(iteratorIndex);
|
|
391
|
-
}
|
|
392
|
-
slide() {
|
|
393
|
-
if (this.subscribersIndex !== this.publisherIndex) {
|
|
394
|
-
const index = this.subscribersIndex % this.capacity;
|
|
395
|
-
const value = this.array[index];
|
|
396
|
-
this.array[index] = AbsentValue;
|
|
397
|
-
this.subscribers[index] = 0;
|
|
398
|
-
this.subscribersIndex += 1;
|
|
399
|
-
this.replayBuffer?.slide(value, this.replayIndices[index]);
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
subscribe() {
|
|
403
|
-
this.subscriberCount += 1;
|
|
404
|
-
return new BoundedPubSubArbSubscription(this, this.publisherIndex, false);
|
|
405
|
-
}
|
|
406
|
-
};
|
|
407
|
-
var BoundedPubSubArbSubscription = class {
|
|
408
|
-
self;
|
|
409
|
-
subscriberIndex;
|
|
410
|
-
unsubscribed;
|
|
411
|
-
constructor(self, subscriberIndex, unsubscribed) {
|
|
412
|
-
this.self = self;
|
|
413
|
-
this.subscriberIndex = subscriberIndex;
|
|
414
|
-
this.unsubscribed = unsubscribed;
|
|
415
|
-
}
|
|
416
|
-
isEmpty() {
|
|
417
|
-
return this.unsubscribed || this.self.publisherIndex === this.subscriberIndex || this.self.publisherIndex === this.self.subscribersIndex;
|
|
418
|
-
}
|
|
419
|
-
size() {
|
|
420
|
-
if (this.unsubscribed) return 0;
|
|
421
|
-
return this.self.publisherIndex - Math.max(this.subscriberIndex, this.self.subscribersIndex);
|
|
422
|
-
}
|
|
423
|
-
poll() {
|
|
424
|
-
if (this.unsubscribed) return Empty;
|
|
425
|
-
this.subscriberIndex = Math.max(this.subscriberIndex, this.self.subscribersIndex);
|
|
426
|
-
if (this.subscriberIndex !== this.self.publisherIndex) {
|
|
427
|
-
const index = this.subscriberIndex % this.self.capacity;
|
|
428
|
-
const elem = this.self.array[index];
|
|
429
|
-
this.self.subscribers[index] -= 1;
|
|
430
|
-
if (this.self.subscribers[index] === 0) {
|
|
431
|
-
this.self.array[index] = AbsentValue;
|
|
432
|
-
this.self.subscribersIndex += 1;
|
|
433
|
-
}
|
|
434
|
-
this.subscriberIndex += 1;
|
|
435
|
-
return elem;
|
|
436
|
-
}
|
|
437
|
-
return Empty;
|
|
438
|
-
}
|
|
439
|
-
pollUpTo(n) {
|
|
440
|
-
n = normalize(n);
|
|
441
|
-
if (this.unsubscribed) return [];
|
|
442
|
-
this.subscriberIndex = Math.max(this.subscriberIndex, this.self.subscribersIndex);
|
|
443
|
-
const size = this.self.publisherIndex - this.subscriberIndex;
|
|
444
|
-
const toPoll = Math.min(n, size);
|
|
445
|
-
if (toPoll <= 0) return [];
|
|
446
|
-
const builder = [];
|
|
447
|
-
const pollUpToIndex = this.subscriberIndex + toPoll;
|
|
448
|
-
while (this.subscriberIndex !== pollUpToIndex) {
|
|
449
|
-
const index = this.subscriberIndex % this.self.capacity;
|
|
450
|
-
const a = this.self.array[index];
|
|
451
|
-
this.self.subscribers[index] -= 1;
|
|
452
|
-
if (this.self.subscribers[index] === 0) {
|
|
453
|
-
this.self.array[index] = AbsentValue;
|
|
454
|
-
this.self.subscribersIndex += 1;
|
|
455
|
-
}
|
|
456
|
-
builder.push(a);
|
|
457
|
-
this.subscriberIndex += 1;
|
|
458
|
-
}
|
|
459
|
-
return builder;
|
|
460
|
-
}
|
|
461
|
-
unsubscribe() {
|
|
462
|
-
if (!this.unsubscribed) {
|
|
463
|
-
this.unsubscribed = true;
|
|
464
|
-
this.self.subscriberCount -= 1;
|
|
465
|
-
this.subscriberIndex = Math.max(this.subscriberIndex, this.self.subscribersIndex);
|
|
466
|
-
while (this.subscriberIndex !== this.self.publisherIndex) {
|
|
467
|
-
const index = this.subscriberIndex % this.self.capacity;
|
|
468
|
-
this.self.subscribers[index] -= 1;
|
|
469
|
-
if (this.self.subscribers[index] === 0) {
|
|
470
|
-
this.self.array[index] = AbsentValue;
|
|
471
|
-
this.self.subscribersIndex += 1;
|
|
472
|
-
}
|
|
473
|
-
this.subscriberIndex += 1;
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
};
|
|
478
|
-
var BoundedPubSubPow2 = class {
|
|
479
|
-
array;
|
|
480
|
-
replayIndices;
|
|
481
|
-
mask;
|
|
482
|
-
publisherIndex = 0;
|
|
483
|
-
subscribers;
|
|
484
|
-
subscriberCount = 0;
|
|
485
|
-
subscribersIndex = 0;
|
|
486
|
-
capacity;
|
|
487
|
-
replayBuffer;
|
|
488
|
-
constructor(capacity, replayBuffer) {
|
|
489
|
-
this.capacity = capacity;
|
|
490
|
-
this.replayBuffer = replayBuffer;
|
|
491
|
-
this.array = Array.from({ length: capacity });
|
|
492
|
-
this.replayIndices = replayBuffer ? Array.from({ length: capacity }) : [];
|
|
493
|
-
this.mask = capacity - 1;
|
|
494
|
-
this.subscribers = Array.from({ length: capacity });
|
|
495
|
-
}
|
|
496
|
-
replayWindow() {
|
|
497
|
-
return this.replayBuffer ? new ReplayWindowImpl(this.replayBuffer) : emptyReplayWindow;
|
|
498
|
-
}
|
|
499
|
-
isEmpty() {
|
|
500
|
-
return this.publisherIndex === this.subscribersIndex;
|
|
501
|
-
}
|
|
502
|
-
isFull() {
|
|
503
|
-
return this.publisherIndex === this.subscribersIndex + this.capacity;
|
|
504
|
-
}
|
|
505
|
-
size() {
|
|
506
|
-
return this.publisherIndex - this.subscribersIndex;
|
|
507
|
-
}
|
|
508
|
-
publish(value) {
|
|
509
|
-
if (this.isFull()) return false;
|
|
510
|
-
const replayIndex = this.replayBuffer?.offer(value);
|
|
511
|
-
if (this.subscriberCount !== 0) {
|
|
512
|
-
const index = this.publisherIndex & this.mask;
|
|
513
|
-
this.array[index] = value;
|
|
514
|
-
if (replayIndex !== void 0) this.replayIndices[index] = replayIndex;
|
|
515
|
-
this.subscribers[index] = this.subscriberCount;
|
|
516
|
-
this.publisherIndex += 1;
|
|
517
|
-
}
|
|
518
|
-
return true;
|
|
519
|
-
}
|
|
520
|
-
publishAll(elements) {
|
|
521
|
-
if (this.subscriberCount === 0) {
|
|
522
|
-
if (this.replayBuffer) this.replayBuffer.offerAll(elements);
|
|
523
|
-
return [];
|
|
524
|
-
}
|
|
525
|
-
const chunk = fromIterable$1(elements);
|
|
526
|
-
const n = chunk.length;
|
|
527
|
-
const size = this.publisherIndex - this.subscribersIndex;
|
|
528
|
-
const available = this.capacity - size;
|
|
529
|
-
const forPubSub = Math.min(n, available);
|
|
530
|
-
if (forPubSub === 0) return chunk;
|
|
531
|
-
let iteratorIndex = 0;
|
|
532
|
-
const publishAllIndex = this.publisherIndex + forPubSub;
|
|
533
|
-
while (this.publisherIndex !== publishAllIndex) {
|
|
534
|
-
const elem = chunk[iteratorIndex++];
|
|
535
|
-
const index = this.publisherIndex & this.mask;
|
|
536
|
-
this.array[index] = elem;
|
|
537
|
-
const replayIndex = this.replayBuffer?.offer(elem);
|
|
538
|
-
if (replayIndex !== void 0) this.replayIndices[index] = replayIndex;
|
|
539
|
-
this.subscribers[index] = this.subscriberCount;
|
|
540
|
-
this.publisherIndex += 1;
|
|
541
|
-
}
|
|
542
|
-
return chunk.slice(iteratorIndex);
|
|
543
|
-
}
|
|
544
|
-
slide() {
|
|
545
|
-
if (this.subscribersIndex !== this.publisherIndex) {
|
|
546
|
-
const index = this.subscribersIndex & this.mask;
|
|
547
|
-
const value = this.array[index];
|
|
548
|
-
this.array[index] = AbsentValue;
|
|
549
|
-
this.subscribers[index] = 0;
|
|
550
|
-
this.subscribersIndex += 1;
|
|
551
|
-
this.replayBuffer?.slide(value, this.replayIndices[index]);
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
subscribe() {
|
|
555
|
-
this.subscriberCount += 1;
|
|
556
|
-
return new BoundedPubSubPow2Subscription(this, this.publisherIndex, false);
|
|
557
|
-
}
|
|
558
|
-
};
|
|
559
|
-
var BoundedPubSubPow2Subscription = class {
|
|
560
|
-
self;
|
|
561
|
-
subscriberIndex;
|
|
562
|
-
unsubscribed;
|
|
563
|
-
constructor(self, subscriberIndex, unsubscribed) {
|
|
564
|
-
this.self = self;
|
|
565
|
-
this.subscriberIndex = subscriberIndex;
|
|
566
|
-
this.unsubscribed = unsubscribed;
|
|
567
|
-
}
|
|
568
|
-
isEmpty() {
|
|
569
|
-
return this.unsubscribed || this.self.publisherIndex === this.subscriberIndex || this.self.publisherIndex === this.self.subscribersIndex;
|
|
570
|
-
}
|
|
571
|
-
size() {
|
|
572
|
-
if (this.unsubscribed) return 0;
|
|
573
|
-
return this.self.publisherIndex - Math.max(this.subscriberIndex, this.self.subscribersIndex);
|
|
574
|
-
}
|
|
575
|
-
poll() {
|
|
576
|
-
if (this.unsubscribed) return Empty;
|
|
577
|
-
this.subscriberIndex = Math.max(this.subscriberIndex, this.self.subscribersIndex);
|
|
578
|
-
if (this.subscriberIndex !== this.self.publisherIndex) {
|
|
579
|
-
const index = this.subscriberIndex & this.self.mask;
|
|
580
|
-
const elem = this.self.array[index];
|
|
581
|
-
this.self.subscribers[index] -= 1;
|
|
582
|
-
if (this.self.subscribers[index] === 0) {
|
|
583
|
-
this.self.array[index] = AbsentValue;
|
|
584
|
-
this.self.subscribersIndex += 1;
|
|
585
|
-
}
|
|
586
|
-
this.subscriberIndex += 1;
|
|
587
|
-
return elem;
|
|
588
|
-
}
|
|
589
|
-
return Empty;
|
|
590
|
-
}
|
|
591
|
-
pollUpTo(n) {
|
|
592
|
-
n = normalize(n);
|
|
593
|
-
if (this.unsubscribed) return [];
|
|
594
|
-
this.subscriberIndex = Math.max(this.subscriberIndex, this.self.subscribersIndex);
|
|
595
|
-
const size = this.self.publisherIndex - this.subscriberIndex;
|
|
596
|
-
const toPoll = Math.min(n, size);
|
|
597
|
-
if (toPoll <= 0) return [];
|
|
598
|
-
const builder = [];
|
|
599
|
-
const pollUpToIndex = this.subscriberIndex + toPoll;
|
|
600
|
-
while (this.subscriberIndex !== pollUpToIndex) {
|
|
601
|
-
const index = this.subscriberIndex & this.self.mask;
|
|
602
|
-
const elem = this.self.array[index];
|
|
603
|
-
this.self.subscribers[index] -= 1;
|
|
604
|
-
if (this.self.subscribers[index] === 0) {
|
|
605
|
-
this.self.array[index] = AbsentValue;
|
|
606
|
-
this.self.subscribersIndex += 1;
|
|
607
|
-
}
|
|
608
|
-
builder.push(elem);
|
|
609
|
-
this.subscriberIndex += 1;
|
|
610
|
-
}
|
|
611
|
-
return builder;
|
|
612
|
-
}
|
|
613
|
-
unsubscribe() {
|
|
614
|
-
if (!this.unsubscribed) {
|
|
615
|
-
this.unsubscribed = true;
|
|
616
|
-
this.self.subscriberCount -= 1;
|
|
617
|
-
this.subscriberIndex = Math.max(this.subscriberIndex, this.self.subscribersIndex);
|
|
618
|
-
while (this.subscriberIndex !== this.self.publisherIndex) {
|
|
619
|
-
const index = this.subscriberIndex & this.self.mask;
|
|
620
|
-
this.self.subscribers[index] -= 1;
|
|
621
|
-
if (this.self.subscribers[index] === 0) {
|
|
622
|
-
this.self.array[index] = AbsentValue;
|
|
623
|
-
this.self.subscribersIndex += 1;
|
|
624
|
-
}
|
|
625
|
-
this.subscriberIndex += 1;
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
};
|
|
630
|
-
var BoundedPubSubSingle = class {
|
|
631
|
-
publisherIndex = 0;
|
|
632
|
-
subscriberCount = 0;
|
|
633
|
-
subscribers = 0;
|
|
634
|
-
value = AbsentValue;
|
|
635
|
-
replayIndex = 0;
|
|
636
|
-
capacity = 1;
|
|
637
|
-
replayBuffer;
|
|
638
|
-
constructor(replayBuffer) {
|
|
639
|
-
this.replayBuffer = replayBuffer;
|
|
640
|
-
}
|
|
641
|
-
replayWindow() {
|
|
642
|
-
return this.replayBuffer ? new ReplayWindowImpl(this.replayBuffer) : emptyReplayWindow;
|
|
643
|
-
}
|
|
644
|
-
pipe() {
|
|
645
|
-
return pipeArguments(this, arguments);
|
|
646
|
-
}
|
|
647
|
-
isEmpty() {
|
|
648
|
-
return this.subscribers === 0;
|
|
649
|
-
}
|
|
650
|
-
isFull() {
|
|
651
|
-
return !this.isEmpty();
|
|
652
|
-
}
|
|
653
|
-
size() {
|
|
654
|
-
return this.isEmpty() ? 0 : 1;
|
|
655
|
-
}
|
|
656
|
-
publish(value) {
|
|
657
|
-
if (this.isFull()) return false;
|
|
658
|
-
const replayIndex = this.replayBuffer?.offer(value);
|
|
659
|
-
if (this.subscriberCount !== 0) {
|
|
660
|
-
this.value = value;
|
|
661
|
-
if (replayIndex !== void 0) this.replayIndex = replayIndex;
|
|
662
|
-
this.subscribers = this.subscriberCount;
|
|
663
|
-
this.publisherIndex += 1;
|
|
664
|
-
}
|
|
665
|
-
return true;
|
|
666
|
-
}
|
|
667
|
-
publishAll(elements) {
|
|
668
|
-
if (this.subscriberCount === 0) {
|
|
669
|
-
if (this.replayBuffer) this.replayBuffer.offerAll(elements);
|
|
670
|
-
return [];
|
|
671
|
-
}
|
|
672
|
-
const chunk = fromIterable$1(elements);
|
|
673
|
-
if (chunk.length === 0) return chunk;
|
|
674
|
-
if (this.publish(chunk[0])) return chunk.slice(1);
|
|
675
|
-
else return chunk;
|
|
676
|
-
}
|
|
677
|
-
slide() {
|
|
678
|
-
if (this.isFull()) {
|
|
679
|
-
const value = this.value;
|
|
680
|
-
this.subscribers = 0;
|
|
681
|
-
this.value = AbsentValue;
|
|
682
|
-
this.replayBuffer?.slide(value, this.replayIndex);
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
subscribe() {
|
|
686
|
-
this.subscriberCount += 1;
|
|
687
|
-
return new BoundedPubSubSingleSubscription(this, this.publisherIndex, false);
|
|
688
|
-
}
|
|
689
|
-
};
|
|
690
|
-
var BoundedPubSubSingleSubscription = class {
|
|
691
|
-
self;
|
|
692
|
-
subscriberIndex;
|
|
693
|
-
unsubscribed;
|
|
694
|
-
constructor(self, subscriberIndex, unsubscribed) {
|
|
695
|
-
this.self = self;
|
|
696
|
-
this.subscriberIndex = subscriberIndex;
|
|
697
|
-
this.unsubscribed = unsubscribed;
|
|
698
|
-
}
|
|
699
|
-
isEmpty() {
|
|
700
|
-
return this.unsubscribed || this.self.subscribers === 0 || this.subscriberIndex === this.self.publisherIndex;
|
|
701
|
-
}
|
|
702
|
-
size() {
|
|
703
|
-
return this.isEmpty() ? 0 : 1;
|
|
704
|
-
}
|
|
705
|
-
poll() {
|
|
706
|
-
if (this.isEmpty()) return Empty;
|
|
707
|
-
const elem = this.self.value;
|
|
708
|
-
this.self.subscribers -= 1;
|
|
709
|
-
if (this.self.subscribers === 0) this.self.value = AbsentValue;
|
|
710
|
-
this.subscriberIndex = this.self.publisherIndex;
|
|
711
|
-
return elem;
|
|
712
|
-
}
|
|
713
|
-
pollUpTo(n) {
|
|
714
|
-
if (normalize(n) < 1 || this.isEmpty()) return [];
|
|
715
|
-
return [this.poll()];
|
|
716
|
-
}
|
|
717
|
-
unsubscribe() {
|
|
718
|
-
if (!this.unsubscribed) {
|
|
719
|
-
this.unsubscribed = true;
|
|
720
|
-
this.self.subscriberCount -= 1;
|
|
721
|
-
if (this.self.subscribers !== 0 && this.subscriberIndex !== this.self.publisherIndex) {
|
|
722
|
-
this.self.subscribers -= 1;
|
|
723
|
-
if (this.self.subscribers === 0) this.self.value = AbsentValue;
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
|
-
};
|
|
728
|
-
var UnboundedPubSub = class {
|
|
729
|
-
publisherHead = {
|
|
730
|
-
value: AbsentValue,
|
|
731
|
-
replayIndex: void 0,
|
|
732
|
-
subscribers: 0,
|
|
733
|
-
next: null
|
|
734
|
-
};
|
|
735
|
-
publisherTail = this.publisherHead;
|
|
736
|
-
publisherIndex = 0;
|
|
737
|
-
subscribersIndex = 0;
|
|
738
|
-
capacity = Number.MAX_SAFE_INTEGER;
|
|
739
|
-
replayBuffer;
|
|
740
|
-
constructor(replayBuffer) {
|
|
741
|
-
this.replayBuffer = replayBuffer;
|
|
742
|
-
}
|
|
743
|
-
replayWindow() {
|
|
744
|
-
return this.replayBuffer ? new ReplayWindowImpl(this.replayBuffer) : emptyReplayWindow;
|
|
745
|
-
}
|
|
746
|
-
isEmpty() {
|
|
747
|
-
return this.publisherHead === this.publisherTail;
|
|
748
|
-
}
|
|
749
|
-
isFull() {
|
|
750
|
-
return false;
|
|
751
|
-
}
|
|
752
|
-
size() {
|
|
753
|
-
return this.publisherIndex - this.subscribersIndex;
|
|
754
|
-
}
|
|
755
|
-
publish(value) {
|
|
756
|
-
const replayIndex = this.replayBuffer?.offer(value);
|
|
757
|
-
const subscribers = this.publisherTail.subscribers;
|
|
758
|
-
if (subscribers !== 0) {
|
|
759
|
-
const node = {
|
|
760
|
-
value,
|
|
761
|
-
replayIndex,
|
|
762
|
-
subscribers,
|
|
763
|
-
next: null
|
|
764
|
-
};
|
|
765
|
-
this.publisherTail.next = node;
|
|
766
|
-
this.publisherTail = this.publisherTail.next;
|
|
767
|
-
this.publisherIndex += 1;
|
|
768
|
-
}
|
|
769
|
-
return true;
|
|
770
|
-
}
|
|
771
|
-
publishAll(elements) {
|
|
772
|
-
if (this.publisherTail.subscribers !== 0) for (const a of elements) this.publish(a);
|
|
773
|
-
else if (this.replayBuffer) this.replayBuffer.offerAll(elements);
|
|
774
|
-
return [];
|
|
775
|
-
}
|
|
776
|
-
slide() {
|
|
777
|
-
if (this.publisherHead !== this.publisherTail) {
|
|
778
|
-
const node = this.publisherHead.next;
|
|
779
|
-
const value = node.value;
|
|
780
|
-
this.publisherHead = this.publisherHead.next;
|
|
781
|
-
this.publisherHead.value = AbsentValue;
|
|
782
|
-
this.subscribersIndex += 1;
|
|
783
|
-
this.replayBuffer?.slide(value, node.replayIndex);
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
subscribe() {
|
|
787
|
-
this.publisherTail.subscribers += 1;
|
|
788
|
-
return new UnboundedPubSubSubscription(this, this.publisherTail, this.publisherIndex, false);
|
|
789
|
-
}
|
|
790
|
-
};
|
|
791
|
-
var UnboundedPubSubSubscription = class {
|
|
792
|
-
self;
|
|
793
|
-
subscriberHead;
|
|
794
|
-
subscriberIndex;
|
|
795
|
-
unsubscribed;
|
|
796
|
-
constructor(self, subscriberHead, subscriberIndex, unsubscribed) {
|
|
797
|
-
this.self = self;
|
|
798
|
-
this.subscriberHead = subscriberHead;
|
|
799
|
-
this.subscriberIndex = subscriberIndex;
|
|
800
|
-
this.unsubscribed = unsubscribed;
|
|
801
|
-
}
|
|
802
|
-
isEmpty() {
|
|
803
|
-
if (this.unsubscribed) return true;
|
|
804
|
-
let empty = true;
|
|
805
|
-
let loop = true;
|
|
806
|
-
while (loop) if (this.subscriberHead === this.self.publisherTail) loop = false;
|
|
807
|
-
else if (this.subscriberHead.next.value !== AbsentValue) {
|
|
808
|
-
empty = false;
|
|
809
|
-
loop = false;
|
|
810
|
-
} else {
|
|
811
|
-
this.subscriberHead = this.subscriberHead.next;
|
|
812
|
-
this.subscriberIndex += 1;
|
|
813
|
-
}
|
|
814
|
-
return empty;
|
|
815
|
-
}
|
|
816
|
-
size() {
|
|
817
|
-
if (this.unsubscribed) return 0;
|
|
818
|
-
return this.self.publisherIndex - Math.max(this.subscriberIndex, this.self.subscribersIndex);
|
|
819
|
-
}
|
|
820
|
-
poll() {
|
|
821
|
-
if (this.unsubscribed) return Empty;
|
|
822
|
-
let loop = true;
|
|
823
|
-
let polled = Empty;
|
|
824
|
-
while (loop) if (this.subscriberHead === this.self.publisherTail) loop = false;
|
|
825
|
-
else {
|
|
826
|
-
const elem = this.subscriberHead.next.value;
|
|
827
|
-
if (elem !== AbsentValue) {
|
|
828
|
-
polled = elem;
|
|
829
|
-
this.subscriberHead.subscribers -= 1;
|
|
830
|
-
if (this.subscriberHead.subscribers === 0) {
|
|
831
|
-
this.self.publisherHead = this.self.publisherHead.next;
|
|
832
|
-
this.self.publisherHead.value = AbsentValue;
|
|
833
|
-
this.self.subscribersIndex += 1;
|
|
834
|
-
}
|
|
835
|
-
loop = false;
|
|
836
|
-
}
|
|
837
|
-
this.subscriberHead = this.subscriberHead.next;
|
|
838
|
-
this.subscriberIndex += 1;
|
|
839
|
-
}
|
|
840
|
-
return polled;
|
|
841
|
-
}
|
|
842
|
-
pollUpTo(n) {
|
|
843
|
-
n = normalize(n);
|
|
844
|
-
const builder = [];
|
|
845
|
-
let i = 0;
|
|
846
|
-
while (i !== n) {
|
|
847
|
-
const a = this.poll();
|
|
848
|
-
if (a === Empty) i = n;
|
|
849
|
-
else {
|
|
850
|
-
builder.push(a);
|
|
851
|
-
i += 1;
|
|
852
|
-
}
|
|
853
|
-
}
|
|
854
|
-
return builder;
|
|
855
|
-
}
|
|
856
|
-
unsubscribe() {
|
|
857
|
-
if (!this.unsubscribed) {
|
|
858
|
-
this.unsubscribed = true;
|
|
859
|
-
this.self.publisherTail.subscribers -= 1;
|
|
860
|
-
while (this.subscriberHead !== this.self.publisherTail) {
|
|
861
|
-
if (this.subscriberHead.next.value !== AbsentValue) {
|
|
862
|
-
this.subscriberHead.subscribers -= 1;
|
|
863
|
-
if (this.subscriberHead.subscribers === 0) {
|
|
864
|
-
this.self.publisherHead = this.self.publisherHead.next;
|
|
865
|
-
this.self.publisherHead.value = AbsentValue;
|
|
866
|
-
this.self.subscribersIndex += 1;
|
|
867
|
-
}
|
|
868
|
-
}
|
|
869
|
-
this.subscriberHead = this.subscriberHead.next;
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
};
|
|
874
|
-
var SubscriptionImpl = class {
|
|
875
|
-
[SubscriptionTypeId] = { _A: identity };
|
|
876
|
-
pubsub;
|
|
877
|
-
subscribers;
|
|
878
|
-
subscription;
|
|
879
|
-
pollers;
|
|
880
|
-
shutdownHook;
|
|
881
|
-
shutdownFlag;
|
|
882
|
-
strategy;
|
|
883
|
-
replayWindow;
|
|
884
|
-
ended;
|
|
885
|
-
constructor(pubsub, subscribers, subscription, pollers, shutdownHook, shutdownFlag, strategy, replayWindow, ended) {
|
|
886
|
-
this.pubsub = pubsub;
|
|
887
|
-
this.subscribers = subscribers;
|
|
888
|
-
this.subscription = subscription;
|
|
889
|
-
this.pollers = pollers;
|
|
890
|
-
this.shutdownHook = shutdownHook;
|
|
891
|
-
this.shutdownFlag = shutdownFlag;
|
|
892
|
-
this.strategy = strategy;
|
|
893
|
-
this.replayWindow = replayWindow;
|
|
894
|
-
this.ended = ended;
|
|
895
|
-
}
|
|
896
|
-
pipe() {
|
|
897
|
-
return pipeArguments(this, arguments);
|
|
898
|
-
}
|
|
899
|
-
};
|
|
900
|
-
var PubSubImpl = class {
|
|
901
|
-
[TypeId$5] = { _A: identity };
|
|
902
|
-
pubsub;
|
|
903
|
-
subscribers;
|
|
904
|
-
scope;
|
|
905
|
-
shutdownHook;
|
|
906
|
-
shutdownFlag;
|
|
907
|
-
strategy;
|
|
908
|
-
ended;
|
|
909
|
-
constructor(pubsub, subscribers, scope, shutdownHook, shutdownFlag, strategy, ended) {
|
|
910
|
-
this.pubsub = pubsub;
|
|
911
|
-
this.subscribers = subscribers;
|
|
912
|
-
this.scope = scope;
|
|
913
|
-
this.shutdownHook = shutdownHook;
|
|
914
|
-
this.shutdownFlag = shutdownFlag;
|
|
915
|
-
this.strategy = strategy;
|
|
916
|
-
this.ended = ended;
|
|
917
|
-
}
|
|
918
|
-
pipe() {
|
|
919
|
-
return pipeArguments(this, arguments);
|
|
920
|
-
}
|
|
921
|
-
};
|
|
922
|
-
const makePubSubUnsafe = (pubsub, subscribers, scope, shutdownHook, shutdownFlag, strategy, ended) => new PubSubImpl(pubsub, subscribers, scope, shutdownHook, shutdownFlag, strategy, ended);
|
|
923
|
-
const ensureCapacity = (capacity) => {
|
|
924
|
-
if (capacity <= 0 || capacity !== Infinity && !Number.isInteger(capacity)) throw new Error(`Cannot construct PubSub with capacity of ${capacity}`);
|
|
925
|
-
};
|
|
926
|
-
var BackPressureStrategy = class {
|
|
927
|
-
publishers = make$4();
|
|
928
|
-
get shutdown() {
|
|
929
|
-
return withFiber((fiber) => forEach(takeAll$2(this.publishers), ([_, deferred, last]) => last ? interruptWith(deferred, fiber.id) : void_, {
|
|
930
|
-
concurrency: "unbounded",
|
|
931
|
-
discard: true
|
|
932
|
-
}));
|
|
933
|
-
}
|
|
934
|
-
handleSurplus(pubsub, subscribers, elements, isShutdown, ended) {
|
|
935
|
-
return callback$1((resume) => {
|
|
936
|
-
if (isSome(ended.current)) return resume(succeed$3(false));
|
|
937
|
-
const deferred = makeUnsafe$2();
|
|
938
|
-
this.offerUnsafe(elements, deferred);
|
|
939
|
-
this.onPubSubEmptySpaceUnsafe(pubsub, subscribers);
|
|
940
|
-
this.completeSubscribersUnsafe(pubsub, subscribers);
|
|
941
|
-
if (get(isShutdown)) {
|
|
942
|
-
this.removeUnsafe(deferred);
|
|
943
|
-
return resume(interrupt$2);
|
|
944
|
-
}
|
|
945
|
-
if (deferred.effect) return resume(deferred.effect);
|
|
946
|
-
deferred.resumes = [resume];
|
|
947
|
-
return sync(() => this.removeUnsafe(deferred));
|
|
948
|
-
});
|
|
949
|
-
}
|
|
950
|
-
onPubSubEmptySpaceUnsafe(pubsub, subscribers) {
|
|
951
|
-
let keepPolling = true;
|
|
952
|
-
while (keepPolling && !pubsub.isFull()) {
|
|
953
|
-
const publisher = take$3(this.publishers);
|
|
954
|
-
if (publisher === Empty) keepPolling = false;
|
|
955
|
-
else {
|
|
956
|
-
const [value, deferred, last] = publisher;
|
|
957
|
-
const published = pubsub.publish(value);
|
|
958
|
-
if (!published) prepend(this.publishers, publisher);
|
|
959
|
-
this.completeSubscribersUnsafe(pubsub, subscribers);
|
|
960
|
-
if (published && last) doneUnsafe(deferred, succeed$2(true));
|
|
961
|
-
}
|
|
962
|
-
}
|
|
963
|
-
}
|
|
964
|
-
completePollersUnsafe(pubsub, subscribers, subscription, pollers) {
|
|
965
|
-
return strategyCompletePollersUnsafe(this, pubsub, subscribers, subscription, pollers);
|
|
966
|
-
}
|
|
967
|
-
completeSubscribersUnsafe(pubsub, subscribers) {
|
|
968
|
-
return strategyCompleteSubscribersUnsafe(this, pubsub, subscribers);
|
|
969
|
-
}
|
|
970
|
-
offerUnsafe(elements, deferred) {
|
|
971
|
-
const iterator = elements[Symbol.iterator]();
|
|
972
|
-
let next = iterator.next();
|
|
973
|
-
if (!next.done) while (1) {
|
|
974
|
-
const value = next.value;
|
|
975
|
-
next = iterator.next();
|
|
976
|
-
if (next.done) {
|
|
977
|
-
append(this.publishers, [
|
|
978
|
-
value,
|
|
979
|
-
deferred,
|
|
980
|
-
true
|
|
981
|
-
]);
|
|
982
|
-
break;
|
|
983
|
-
}
|
|
984
|
-
append(this.publishers, [
|
|
985
|
-
value,
|
|
986
|
-
deferred,
|
|
987
|
-
false
|
|
988
|
-
]);
|
|
989
|
-
}
|
|
990
|
-
}
|
|
991
|
-
removeUnsafe(deferred) {
|
|
992
|
-
filter$1(this.publishers, ([_, d]) => d !== deferred);
|
|
993
|
-
}
|
|
994
|
-
};
|
|
995
|
-
var DroppingStrategy = class {
|
|
996
|
-
get shutdown() {
|
|
997
|
-
return void_;
|
|
998
|
-
}
|
|
999
|
-
handleSurplus(_pubsub, _subscribers, _elements, _isShutdown) {
|
|
1000
|
-
return succeed$3(false);
|
|
1001
|
-
}
|
|
1002
|
-
onPubSubEmptySpaceUnsafe(_pubsub, _subscribers) {}
|
|
1003
|
-
completePollersUnsafe(pubsub, subscribers, subscription, pollers) {
|
|
1004
|
-
return strategyCompletePollersUnsafe(this, pubsub, subscribers, subscription, pollers);
|
|
1005
|
-
}
|
|
1006
|
-
completeSubscribersUnsafe(pubsub, subscribers) {
|
|
1007
|
-
return strategyCompleteSubscribersUnsafe(this, pubsub, subscribers);
|
|
1008
|
-
}
|
|
1009
|
-
};
|
|
1010
|
-
var SlidingStrategy = class {
|
|
1011
|
-
get shutdown() {
|
|
1012
|
-
return void_;
|
|
1013
|
-
}
|
|
1014
|
-
handleSurplus(pubsub, subscribers, elements, _isShutdown, ended) {
|
|
1015
|
-
return sync(() => {
|
|
1016
|
-
if (isSome(ended.current)) return false;
|
|
1017
|
-
this.slidingPublishUnsafe(pubsub, elements);
|
|
1018
|
-
this.completeSubscribersUnsafe(pubsub, subscribers);
|
|
1019
|
-
return true;
|
|
1020
|
-
});
|
|
1021
|
-
}
|
|
1022
|
-
onPubSubEmptySpaceUnsafe(_pubsub, _subscribers) {}
|
|
1023
|
-
completePollersUnsafe(pubsub, subscribers, subscription, pollers) {
|
|
1024
|
-
return strategyCompletePollersUnsafe(this, pubsub, subscribers, subscription, pollers);
|
|
1025
|
-
}
|
|
1026
|
-
completeSubscribersUnsafe(pubsub, subscribers) {
|
|
1027
|
-
return strategyCompleteSubscribersUnsafe(this, pubsub, subscribers);
|
|
1028
|
-
}
|
|
1029
|
-
slidingPublishUnsafe(pubsub, elements) {
|
|
1030
|
-
const it = elements[Symbol.iterator]();
|
|
1031
|
-
let next = it.next();
|
|
1032
|
-
if (!next.done && pubsub.capacity > 0) {
|
|
1033
|
-
let a = next.value;
|
|
1034
|
-
let loop = true;
|
|
1035
|
-
while (loop) {
|
|
1036
|
-
pubsub.slide();
|
|
1037
|
-
const pub = pubsub.publish(a);
|
|
1038
|
-
if (pub && (next = it.next()) && !next.done) a = next.value;
|
|
1039
|
-
else if (pub) loop = false;
|
|
1040
|
-
}
|
|
1041
|
-
}
|
|
1042
|
-
}
|
|
1043
|
-
};
|
|
1044
|
-
const strategyCompletePollersUnsafe = (strategy, pubsub, subscribers, subscription, pollers) => {
|
|
1045
|
-
let keepPolling = true;
|
|
1046
|
-
while (keepPolling && !subscription.isEmpty()) {
|
|
1047
|
-
const poller = take$3(pollers);
|
|
1048
|
-
if (poller === Empty) {
|
|
1049
|
-
removeSubscribers(subscribers, subscription, pollers);
|
|
1050
|
-
if (pollers.length === 0) keepPolling = false;
|
|
1051
|
-
else addSubscribers(subscribers, subscription, pollers);
|
|
1052
|
-
} else {
|
|
1053
|
-
const pollResult = subscription.poll();
|
|
1054
|
-
if (pollResult === Empty) prepend(pollers, poller);
|
|
1055
|
-
else {
|
|
1056
|
-
doneUnsafe(poller, succeed$2(pollResult));
|
|
1057
|
-
strategy.onPubSubEmptySpaceUnsafe(pubsub, subscribers);
|
|
1058
|
-
}
|
|
1059
|
-
}
|
|
1060
|
-
}
|
|
1061
|
-
};
|
|
1062
|
-
const strategyCompleteSubscribersUnsafe = (strategy, pubsub, subscribers) => {
|
|
1063
|
-
for (const [subscription, pollersSet] of subscribers) for (const pollers of pollersSet) strategy.completePollersUnsafe(pubsub, subscribers, subscription, pollers);
|
|
1064
|
-
};
|
|
1065
|
-
var ReplayBuffer = class {
|
|
1066
|
-
capacity;
|
|
1067
|
-
head = {
|
|
1068
|
-
value: AbsentValue,
|
|
1069
|
-
index: 0,
|
|
1070
|
-
next: null
|
|
1071
|
-
};
|
|
1072
|
-
tail = this.head;
|
|
1073
|
-
slideValues = [];
|
|
1074
|
-
size = 0;
|
|
1075
|
-
index = 0;
|
|
1076
|
-
publisherIndex = 0;
|
|
1077
|
-
constructor(capacity) {
|
|
1078
|
-
this.capacity = capacity;
|
|
1079
|
-
}
|
|
1080
|
-
slide(value, publisherIndex) {
|
|
1081
|
-
this.slideValues[this.index % this.capacity] = {
|
|
1082
|
-
value,
|
|
1083
|
-
index: publisherIndex
|
|
1084
|
-
};
|
|
1085
|
-
this.index++;
|
|
1086
|
-
}
|
|
1087
|
-
offer(a) {
|
|
1088
|
-
const index = this.publisherIndex++;
|
|
1089
|
-
this.tail.value = a;
|
|
1090
|
-
this.tail.index = index;
|
|
1091
|
-
this.tail.next = {
|
|
1092
|
-
value: AbsentValue,
|
|
1093
|
-
index: 0,
|
|
1094
|
-
next: null
|
|
1095
|
-
};
|
|
1096
|
-
this.tail = this.tail.next;
|
|
1097
|
-
if (this.size === this.capacity) {
|
|
1098
|
-
const dropped = this.head;
|
|
1099
|
-
this.head = dropped.next;
|
|
1100
|
-
dropped.next = null;
|
|
1101
|
-
dropped.value = AbsentValue;
|
|
1102
|
-
} else this.size += 1;
|
|
1103
|
-
return index;
|
|
1104
|
-
}
|
|
1105
|
-
offerAll(as) {
|
|
1106
|
-
for (const a of as) this.offer(a);
|
|
1107
|
-
}
|
|
1108
|
-
};
|
|
1109
|
-
var ReplayWindowImpl = class {
|
|
1110
|
-
buffer;
|
|
1111
|
-
values;
|
|
1112
|
-
index = 0;
|
|
1113
|
-
remaining;
|
|
1114
|
-
slideIndex;
|
|
1115
|
-
newestIndex = -1;
|
|
1116
|
-
constructor(buffer) {
|
|
1117
|
-
this.buffer = buffer;
|
|
1118
|
-
this.remaining = buffer.size;
|
|
1119
|
-
this.slideIndex = buffer.index;
|
|
1120
|
-
this.values = new Array(this.remaining);
|
|
1121
|
-
let node = buffer.head;
|
|
1122
|
-
for (let i = 0; i < this.remaining; i++) {
|
|
1123
|
-
this.values[i] = node.value;
|
|
1124
|
-
this.newestIndex = node.index;
|
|
1125
|
-
node = node.next;
|
|
1126
|
-
}
|
|
1127
|
-
}
|
|
1128
|
-
close() {
|
|
1129
|
-
this.values.length = 0;
|
|
1130
|
-
this.remaining = 0;
|
|
1131
|
-
}
|
|
1132
|
-
sync() {
|
|
1133
|
-
const slides = this.buffer.index - this.slideIndex;
|
|
1134
|
-
if (slides === 0 || this.remaining === 0) return;
|
|
1135
|
-
const count = Math.min(slides, this.buffer.capacity);
|
|
1136
|
-
const start = this.buffer.index - count;
|
|
1137
|
-
for (let i = 0; i < count; i++) {
|
|
1138
|
-
const entry = this.buffer.slideValues[(start + i) % this.buffer.capacity];
|
|
1139
|
-
if (entry.index > this.newestIndex) {
|
|
1140
|
-
this.index = (this.index + 1) % this.values.length;
|
|
1141
|
-
this.values[(this.index + this.remaining - 1) % this.values.length] = entry.value;
|
|
1142
|
-
this.newestIndex = entry.index;
|
|
1143
|
-
}
|
|
1144
|
-
}
|
|
1145
|
-
this.slideIndex = this.buffer.index;
|
|
1146
|
-
}
|
|
1147
|
-
take() {
|
|
1148
|
-
if (this.remaining === 0) return;
|
|
1149
|
-
this.sync();
|
|
1150
|
-
const value = this.values[this.index];
|
|
1151
|
-
this.values[this.index] = AbsentValue;
|
|
1152
|
-
this.index = (this.index + 1) % this.values.length;
|
|
1153
|
-
this.remaining--;
|
|
1154
|
-
if (this.remaining === 0) this.close();
|
|
1155
|
-
return value;
|
|
1156
|
-
}
|
|
1157
|
-
takeN(n) {
|
|
1158
|
-
n = normalize(n);
|
|
1159
|
-
const len = Math.min(n, this.remaining);
|
|
1160
|
-
const items = new Array(len);
|
|
1161
|
-
for (let i = 0; i < len; i++) items[i] = this.take();
|
|
1162
|
-
return items;
|
|
1163
|
-
}
|
|
1164
|
-
takeAll() {
|
|
1165
|
-
return this.takeN(this.remaining);
|
|
1166
|
-
}
|
|
1167
|
-
};
|
|
1168
|
-
const emptyReplayWindow = {
|
|
1169
|
-
remaining: 0,
|
|
1170
|
-
take: () => void 0,
|
|
1171
|
-
takeN: () => [],
|
|
1172
|
-
takeAll: () => [],
|
|
1173
|
-
close: () => void 0
|
|
1174
|
-
};
|
|
1175
|
-
// node_modules/.pnpm/effect@4.1.3/node_modules/effect/dist/Queue.js
|
|
1176
|
-
const TypeId$4 = "~effect/Queue";
|
|
1177
|
-
const EnqueueTypeId = "~effect/Queue/Enqueue";
|
|
1178
|
-
const DequeueTypeId = "~effect/Queue/Dequeue";
|
|
1179
|
-
const variance = {
|
|
1180
|
-
_A: identity,
|
|
1181
|
-
_E: identity
|
|
1182
|
-
};
|
|
1183
|
-
const QueueProto = {
|
|
1184
|
-
[TypeId$4]: variance,
|
|
1185
|
-
[EnqueueTypeId]: variance,
|
|
1186
|
-
[DequeueTypeId]: variance,
|
|
1187
|
-
...PipeInspectableProto,
|
|
1188
|
-
toJSON() {
|
|
1189
|
-
return {
|
|
1190
|
-
_id: "effect/Queue",
|
|
1191
|
-
state: this.state._tag,
|
|
1192
|
-
size: sizeUnsafe(this)
|
|
1193
|
-
};
|
|
1194
|
-
}
|
|
1195
|
-
};
|
|
1196
|
-
const make$2 = (options) => withFiber$1((fiber) => {
|
|
1197
|
-
const self = Object.create(QueueProto);
|
|
1198
|
-
self.dispatcher = fiber.currentDispatcher;
|
|
1199
|
-
self.capacity = options?.capacity ?? Number.POSITIVE_INFINITY;
|
|
1200
|
-
self.strategy = options?.strategy ?? "suspend";
|
|
1201
|
-
self.messages = make$4();
|
|
1202
|
-
self.scheduleRunning = false;
|
|
1203
|
-
self.state = {
|
|
1204
|
-
_tag: "Open",
|
|
1205
|
-
takers: new Set(),
|
|
1206
|
-
offers: new Set(),
|
|
1207
|
-
awaiters: new Set()
|
|
1208
|
-
};
|
|
1209
|
-
return succeed$4(self);
|
|
1210
|
-
});
|
|
1211
|
-
const bounded = (capacity) => make$2({ capacity });
|
|
1212
|
-
const sliding = (capacity) => make$2({
|
|
1213
|
-
capacity,
|
|
1214
|
-
strategy: "sliding"
|
|
1215
|
-
});
|
|
1216
|
-
const unbounded = () => make$2();
|
|
1217
|
-
const offer = dual(2, (self, message) => suspend$3(() => offerUnsafe(self, message) ? exitTrue : self.state._tag === "Open" && self.strategy === "suspend" ? offerOrWait(self, message) : exitFalse));
|
|
1218
|
-
const offerUnsafe = (self, message) => {
|
|
1219
|
-
if (self.state._tag !== "Open") return false;
|
|
1220
|
-
else if (self.messages.length >= self.capacity) {
|
|
1221
|
-
if (self.capacity <= 0 && self.state.takers.size > (self.strategy === "sliding" ? 0 : self.messages.length)) {
|
|
1222
|
-
append(self.messages, message);
|
|
1223
|
-
if (self.strategy === "sliding") takeNVoid(self.messages, self.messages.length - self.state.takers.size);
|
|
1224
|
-
releaseTakers(self);
|
|
1225
|
-
return true;
|
|
1226
|
-
} else if (self.strategy === "sliding") {
|
|
1227
|
-
if (self.capacity > 0) {
|
|
1228
|
-
take$3(self.messages);
|
|
1229
|
-
append(self.messages, message);
|
|
1230
|
-
}
|
|
1231
|
-
return true;
|
|
1232
|
-
}
|
|
1233
|
-
return false;
|
|
1234
|
-
}
|
|
1235
|
-
append(self.messages, message);
|
|
1236
|
-
scheduleReleaseTaker(self);
|
|
1237
|
-
return true;
|
|
1238
|
-
};
|
|
1239
|
-
const offerAll = dual(2, (self, messages) => callback$2((resume) => {
|
|
1240
|
-
const remaining = offerAllUnsafe(self, messages);
|
|
1241
|
-
if (remaining.length === 0 || self.strategy === "dropping") return resume(exitSucceed(remaining));
|
|
1242
|
-
return waitToOffer(self, {
|
|
1243
|
-
_tag: "Array",
|
|
1244
|
-
remaining,
|
|
1245
|
-
offset: 0,
|
|
1246
|
-
resume
|
|
1247
|
-
});
|
|
1248
|
-
}));
|
|
1249
|
-
const offerAllUnsafe = (self, messages) => {
|
|
1250
|
-
if (self.state._tag !== "Open") return fromIterable$1(messages);
|
|
1251
|
-
else if (self.capacity === Number.POSITIVE_INFINITY || self.strategy === "sliding") {
|
|
1252
|
-
appendAll(self.messages, messages);
|
|
1253
|
-
if (self.strategy === "sliding") {
|
|
1254
|
-
const capacity = self.capacity <= 0 ? self.state.takers.size : self.capacity;
|
|
1255
|
-
takeNVoid(self.messages, self.messages.length - capacity);
|
|
1256
|
-
}
|
|
1257
|
-
scheduleReleaseTaker(self);
|
|
1258
|
-
return [];
|
|
1259
|
-
}
|
|
1260
|
-
const free = (self.capacity <= 0 ? self.state.takers.size : self.capacity) - self.messages.length;
|
|
1261
|
-
if (free <= 0) return fromIterable$1(messages);
|
|
1262
|
-
const remaining = [];
|
|
1263
|
-
let i = 0;
|
|
1264
|
-
for (const message of messages) {
|
|
1265
|
-
if (i < free) append(self.messages, message);
|
|
1266
|
-
else remaining.push(message);
|
|
1267
|
-
i++;
|
|
1268
|
-
}
|
|
1269
|
-
scheduleReleaseTaker(self);
|
|
1270
|
-
return remaining;
|
|
1271
|
-
};
|
|
1272
|
-
const fail$2 = dual(2, (self, error) => failCause$2(self, causeFail(error)));
|
|
1273
|
-
const failCause$2 = dual(2, (self, cause) => sync$1(() => failCauseUnsafe(self, cause)));
|
|
1274
|
-
const failCauseUnsafe = (self, cause) => {
|
|
1275
|
-
if (self.state._tag !== "Open") return false;
|
|
1276
|
-
const exit = exitFailCause(cause);
|
|
1277
|
-
const fail = exitZipRight(exit, exitFailDone);
|
|
1278
|
-
if (self.state.offers.size === 0 && self.messages.length === 0) {
|
|
1279
|
-
finalize(self, fail);
|
|
1280
|
-
return true;
|
|
1281
|
-
}
|
|
1282
|
-
self.state = {
|
|
1283
|
-
...self.state,
|
|
1284
|
-
_tag: "Closing",
|
|
1285
|
-
exit: fail
|
|
1286
|
-
};
|
|
1287
|
-
scheduleReleaseTaker(self);
|
|
1288
|
-
return true;
|
|
1289
|
-
};
|
|
1290
|
-
const end = (self) => failCause$2(self, causeFail(Done()));
|
|
1291
|
-
const endUnsafe = (self) => failCauseUnsafe(self, causeFail(Done()));
|
|
1292
|
-
const shutdown = (self) => sync$1(() => shutdownUnsafe(self));
|
|
1293
|
-
const shutdownUnsafe = (self) => {
|
|
1294
|
-
if (self.state._tag === "Done") return false;
|
|
1295
|
-
clear(self.messages);
|
|
1296
|
-
const offers = self.state.offers;
|
|
1297
|
-
finalize(self, self.state._tag === "Open" ? exitInterrupt : self.state.exit);
|
|
1298
|
-
for (const entry of offers) resumeUnoffered(entry);
|
|
1299
|
-
return true;
|
|
1300
|
-
};
|
|
1301
|
-
const takeAll = (self) => takeBetween(self, 1, Number.POSITIVE_INFINITY);
|
|
1302
|
-
const takeBetween = dual(3, (self, min, max) => {
|
|
1303
|
-
min = normalize(min);
|
|
1304
|
-
max = normalize(max);
|
|
1305
|
-
return suspendTake(() => takeBetweenUnsafe(self, min, max) ?? andThen$1(awaitTake(self, () => canTake(self, min)), takeBetween(self, min, max)));
|
|
1306
|
-
});
|
|
1307
|
-
const take$1 = (self) => suspendTake(() => takeUnsafe(self) ?? andThen$1(awaitTake(self, () => canTake(self, 1)), take$1(self)));
|
|
1308
|
-
const poll = (self) => suspendTake(() => {
|
|
1309
|
-
const result = takeUnsafe(self);
|
|
1310
|
-
if (result === void 0) return succeed$4(none());
|
|
1311
|
-
if (result._tag === "Success") return succeed$4(some(result.value));
|
|
1312
|
-
return succeed$4(none());
|
|
1313
|
-
});
|
|
1314
|
-
const takeUnsafe = (self) => {
|
|
1315
|
-
if (self.state._tag === "Done") return self.state.exit;
|
|
1316
|
-
if (self.messages.length > 0) {
|
|
1317
|
-
const message = take$3(self.messages);
|
|
1318
|
-
releaseCapacity(self);
|
|
1319
|
-
return exitSucceed(message);
|
|
1320
|
-
} else if (self.capacity <= 0 && self.state.offers.size > 0) {
|
|
1321
|
-
const message = takeOfferUnsafe(self.state.offers);
|
|
1322
|
-
releaseCapacity(self);
|
|
1323
|
-
return exitSucceed(message);
|
|
1324
|
-
}
|
|
1325
|
-
};
|
|
1326
|
-
const sizeUnsafe = (self) => self.state._tag === "Done" ? 0 : self.messages.length;
|
|
1327
|
-
const exitFalse = exitSucceed(false);
|
|
1328
|
-
const exitTrue = exitSucceed(true);
|
|
1329
|
-
const exitFailDone = exitFail(Done());
|
|
1330
|
-
const exitInterrupt = exitInterrupt$1();
|
|
1331
|
-
const releaseTakers = (self) => {
|
|
1332
|
-
if (self.state._tag === "Done" || self.state.takers.size === 0) return;
|
|
1333
|
-
for (const taker of self.state.takers) {
|
|
1334
|
-
if (!taker.ready()) continue;
|
|
1335
|
-
self.state.takers.delete(taker);
|
|
1336
|
-
taker.resume(exitVoid);
|
|
1337
|
-
if (self.messages.length === 0) break;
|
|
1338
|
-
}
|
|
1339
|
-
};
|
|
1340
|
-
const scheduleReleaseTaker = (self) => {
|
|
1341
|
-
if (self.scheduleRunning || self.state._tag === "Done" || self.state.takers.size === 0) return;
|
|
1342
|
-
self.scheduleRunning = true;
|
|
1343
|
-
self.dispatcher.scheduleTask(() => {
|
|
1344
|
-
self.scheduleRunning = false;
|
|
1345
|
-
releaseTakers(self);
|
|
1346
|
-
}, 0);
|
|
1347
|
-
};
|
|
1348
|
-
const takeBetweenUnsafe = (self, min, max) => {
|
|
1349
|
-
if (self.state._tag === "Done") return self.state.exit;
|
|
1350
|
-
else if (max <= 0 || min <= 0) return exitSucceed([]);
|
|
1351
|
-
else if (!canTake(self, min)) return;
|
|
1352
|
-
const messages = self.messages.length > 0 ? takeN(self.messages, max) : [takeOfferUnsafe(self.state.offers)];
|
|
1353
|
-
releaseCapacity(self);
|
|
1354
|
-
return exitSucceed(messages);
|
|
1355
|
-
};
|
|
1356
|
-
const suspendTake = makePrimitive({
|
|
1357
|
-
op: "QueueTake",
|
|
1358
|
-
[evaluate](fiber) {
|
|
1359
|
-
const effect = this[args]();
|
|
1360
|
-
return isExit(effect) ? effect[evaluate](fiber) : effect;
|
|
1361
|
-
}
|
|
1362
|
-
});
|
|
1363
|
-
const canTake = (self, min) => self.messages.length >= (self.state._tag === "Closing" ? 1 : Math.min(min, self.capacity || 1)) || self.capacity <= 0 && self.state._tag !== "Done" && self.state.offers.size > 0;
|
|
1364
|
-
const awaitTake = (self, ready) => callback$2((resume) => {
|
|
1365
|
-
if (self.state._tag === "Done") return resume(self.state.exit);
|
|
1366
|
-
if (ready()) return resume(exitVoid);
|
|
1367
|
-
const taker = {
|
|
1368
|
-
ready,
|
|
1369
|
-
resume
|
|
1370
|
-
};
|
|
1371
|
-
self.state.takers.add(taker);
|
|
1372
|
-
return sync$1(() => {
|
|
1373
|
-
if (self.state._tag !== "Done") self.state.takers.delete(taker);
|
|
1374
|
-
});
|
|
1375
|
-
});
|
|
1376
|
-
const offerOrWait = (self, message) => callback$2((resume) => offerUnsafe(self, message) ? resume(exitTrue) : waitToOffer(self, {
|
|
1377
|
-
_tag: "Single",
|
|
1378
|
-
message,
|
|
1379
|
-
resume
|
|
1380
|
-
}));
|
|
1381
|
-
const waitToOffer = (self, entry) => {
|
|
1382
|
-
if (self.state._tag !== "Open") return resumeUnoffered(entry);
|
|
1383
|
-
const offers = self.state.offers;
|
|
1384
|
-
offers.add(entry);
|
|
1385
|
-
return sync$1(() => {
|
|
1386
|
-
if (self.state._tag === "Done") return;
|
|
1387
|
-
offers.delete(entry);
|
|
1388
|
-
if (self.state._tag === "Closing" && offers.size === 0 && self.messages.length === 0) finalize(self, self.state.exit);
|
|
1389
|
-
});
|
|
1390
|
-
};
|
|
1391
|
-
const resumeUnoffered = (entry) => entry._tag === "Single" ? entry.resume(exitFalse) : entry.resume(exitSucceed(entry.remaining.slice(entry.offset)));
|
|
1392
|
-
const takeOfferUnsafe = (offers) => {
|
|
1393
|
-
const entry = offers.values().next().value;
|
|
1394
|
-
if (entry._tag === "Single") {
|
|
1395
|
-
offers.delete(entry);
|
|
1396
|
-
entry.resume(exitTrue);
|
|
1397
|
-
return entry.message;
|
|
1398
|
-
}
|
|
1399
|
-
const message = entry.remaining[entry.offset++];
|
|
1400
|
-
if (entry.offset === entry.remaining.length) {
|
|
1401
|
-
offers.delete(entry);
|
|
1402
|
-
entry.resume(exitSucceed([]));
|
|
1403
|
-
}
|
|
1404
|
-
return message;
|
|
1405
|
-
};
|
|
1406
|
-
const releaseCapacity = (self) => {
|
|
1407
|
-
if (self.state._tag === "Done") return isDoneCause(self.state.exit.cause);
|
|
1408
|
-
else if (self.state.offers.size === 0) {
|
|
1409
|
-
if (self.state._tag === "Closing" && self.messages.length === 0) {
|
|
1410
|
-
finalize(self, self.state.exit);
|
|
1411
|
-
return isDoneCause(self.state.exit.cause);
|
|
1412
|
-
}
|
|
1413
|
-
return false;
|
|
1414
|
-
}
|
|
1415
|
-
for (const entry of self.state.offers) {
|
|
1416
|
-
let n = self.capacity - self.messages.length;
|
|
1417
|
-
if (n <= 0) break;
|
|
1418
|
-
else if (entry._tag === "Single") {
|
|
1419
|
-
append(self.messages, entry.message);
|
|
1420
|
-
self.state.offers.delete(entry);
|
|
1421
|
-
entry.resume(exitTrue);
|
|
1422
|
-
} else {
|
|
1423
|
-
for (; entry.offset < entry.remaining.length; entry.offset++) {
|
|
1424
|
-
if (n === 0) return false;
|
|
1425
|
-
append(self.messages, entry.remaining[entry.offset]);
|
|
1426
|
-
n--;
|
|
1427
|
-
}
|
|
1428
|
-
self.state.offers.delete(entry);
|
|
1429
|
-
entry.resume(exitSucceed([]));
|
|
1430
|
-
}
|
|
1431
|
-
const state = self.state;
|
|
1432
|
-
if (state._tag === "Done") return isDoneCause(state.exit.cause);
|
|
1433
|
-
}
|
|
1434
|
-
return false;
|
|
1435
|
-
};
|
|
1436
|
-
const finalize = (self, exit) => {
|
|
1437
|
-
if (self.state._tag === "Done") return;
|
|
1438
|
-
const openState = self.state;
|
|
1439
|
-
self.state = {
|
|
1440
|
-
_tag: "Done",
|
|
1441
|
-
exit
|
|
1442
|
-
};
|
|
1443
|
-
for (const taker of openState.takers) taker.resume(exit);
|
|
1444
|
-
openState.takers.clear();
|
|
1445
|
-
for (const awaiter of openState.awaiters) awaiter(exit);
|
|
1446
|
-
openState.awaiters.clear();
|
|
1447
|
-
};
|
|
1448
|
-
// node_modules/.pnpm/effect@4.1.3/node_modules/effect/dist/Semaphore.js
|
|
1449
|
-
const makeUnsafe = (permits) => new SemaphoreImpl(permits);
|
|
1450
|
-
const firstAvailableWaiter = (self) => {
|
|
1451
|
-
for (const waiter of self.waiters) if (waiter.permits <= self.free) return waiter;
|
|
1452
|
-
};
|
|
1453
|
-
const takePermits = (self, n, onAcquire, restore = identity) => withFiber$1((fiber) => {
|
|
1454
|
-
if (self.free >= n && firstAvailableWaiter(self) === void 0) {
|
|
1455
|
-
self.taken += n;
|
|
1456
|
-
return onAcquire();
|
|
1457
|
-
}
|
|
1458
|
-
const waiter = {
|
|
1459
|
-
permits: n,
|
|
1460
|
-
resume: void 0
|
|
1461
|
-
};
|
|
1462
|
-
const remove = () => {
|
|
1463
|
-
if (self.waiters.delete(waiter)) self.releaseUnsafe(fiber, 0);
|
|
1464
|
-
};
|
|
1465
|
-
self.waiters.add(waiter);
|
|
1466
|
-
onExitUnsafe(fiber, remove);
|
|
1467
|
-
const wait = restore(callback$2((resume) => {
|
|
1468
|
-
if (firstAvailableWaiter(self) === waiter) resume(void_$1);
|
|
1469
|
-
else waiter.resume = resume;
|
|
1470
|
-
}));
|
|
1471
|
-
const loop = flatMap$3(wait, () => {
|
|
1472
|
-
if (firstAvailableWaiter(self) !== waiter) return loop;
|
|
1473
|
-
self.taken += n;
|
|
1474
|
-
remove();
|
|
1475
|
-
return onAcquire();
|
|
1476
|
-
});
|
|
1477
|
-
return loop;
|
|
1478
|
-
});
|
|
1479
|
-
var SemaphoreImpl = class {
|
|
1480
|
-
waiters = new Set();
|
|
1481
|
-
taken = 0;
|
|
1482
|
-
permits;
|
|
1483
|
-
constructor(permits) {
|
|
1484
|
-
this.permits = permits;
|
|
1485
|
-
}
|
|
1486
|
-
get free() {
|
|
1487
|
-
return this.permits - this.taken;
|
|
1488
|
-
}
|
|
1489
|
-
take(n) {
|
|
1490
|
-
return takePermits(this, n, () => succeed$4(n));
|
|
1491
|
-
}
|
|
1492
|
-
takeScoped(n) {
|
|
1493
|
-
return uninterruptibleMask((restore) => flatMap$3(scope, (scope) => takePermits(this, n, () => scopeAddFinalizer(scope, this.release(n)), restore)));
|
|
1494
|
-
}
|
|
1495
|
-
takeIfAvailable(n) {
|
|
1496
|
-
return suspend$3(() => {
|
|
1497
|
-
if (this.free < n) return succeed$4(false);
|
|
1498
|
-
this.taken += n;
|
|
1499
|
-
return succeed$4(true);
|
|
1500
|
-
});
|
|
1501
|
-
}
|
|
1502
|
-
releaseUnsafe(fiber, n) {
|
|
1503
|
-
this.taken -= n;
|
|
1504
|
-
if (this.waiters.size > 0) fiber.currentDispatcher.scheduleTask(() => {
|
|
1505
|
-
let remaining = this.free;
|
|
1506
|
-
for (const waiter of Array.from(this.waiters)) {
|
|
1507
|
-
if (!this.waiters.has(waiter) || waiter.permits > remaining) continue;
|
|
1508
|
-
remaining -= waiter.permits;
|
|
1509
|
-
const resume = waiter.resume;
|
|
1510
|
-
waiter.resume = void 0;
|
|
1511
|
-
resume?.(void_$1);
|
|
1512
|
-
}
|
|
1513
|
-
}, 0);
|
|
1514
|
-
return this.free;
|
|
1515
|
-
}
|
|
1516
|
-
resize(permits) {
|
|
1517
|
-
return withFiber$1((fiber) => {
|
|
1518
|
-
this.permits = permits;
|
|
1519
|
-
if (this.free < 0) return void_$1;
|
|
1520
|
-
this.releaseUnsafe(fiber, 0);
|
|
1521
|
-
return void_$1;
|
|
1522
|
-
});
|
|
1523
|
-
}
|
|
1524
|
-
release(n) {
|
|
1525
|
-
return withFiber$1((fiber) => succeed$4(this.releaseUnsafe(fiber, n)));
|
|
1526
|
-
}
|
|
1527
|
-
get releaseAll() {
|
|
1528
|
-
return withFiber$1((fiber) => succeed$4(this.releaseUnsafe(fiber, this.taken)));
|
|
1529
|
-
}
|
|
1530
|
-
withPermits(n) {
|
|
1531
|
-
return (self) => uninterruptibleMask((restore) => takePermits(this, n, () => onExitPrimitive(restore(self), () => {
|
|
1532
|
-
this.releaseUnsafe(getCurrentFiber(), n);
|
|
1533
|
-
}, true), restore));
|
|
1534
|
-
}
|
|
1535
|
-
withPermit = this.withPermits(1);
|
|
1536
|
-
withPermitsIfAvailable(n) {
|
|
1537
|
-
return (self) => uninterruptibleMask((restore) => {
|
|
1538
|
-
if (this.free < n) return succeedNone;
|
|
1539
|
-
this.taken += n;
|
|
1540
|
-
return onExitPrimitive(restore(asSome(self)), () => {
|
|
1541
|
-
this.releaseUnsafe(getCurrentFiber(), n);
|
|
1542
|
-
}, true);
|
|
1543
|
-
});
|
|
1544
|
-
}
|
|
1545
|
-
};
|
|
1546
|
-
const make$1 = (permits) => sync$1(() => new SemaphoreImpl(permits));
|
|
1547
|
-
// node_modules/.pnpm/effect@4.1.3/node_modules/effect/dist/Take.js
|
|
1548
|
-
const toPull = (take) => isExit$1(take) ? isSuccess(take) ? done(take.value) : take : succeed$3(take);
|
|
1549
|
-
// node_modules/.pnpm/effect@4.1.3/node_modules/effect/dist/Channel.js
|
|
1550
|
-
const TypeId$3 = "~effect/Channel";
|
|
1551
|
-
const isChannel = (u) => hasProperty(u, TypeId$3);
|
|
1552
|
-
const ChannelProto = {
|
|
1553
|
-
[TypeId$3]: {
|
|
1554
|
-
_Env: identity,
|
|
1555
|
-
_InErr: identity,
|
|
1556
|
-
_InElem: identity,
|
|
1557
|
-
_OutErr: identity,
|
|
1558
|
-
_OutElem: identity
|
|
1559
|
-
},
|
|
1560
|
-
pipe() {
|
|
1561
|
-
return pipeArguments(this, arguments);
|
|
1562
|
-
}
|
|
1563
|
-
};
|
|
1564
|
-
const fromTransform = (transform) => {
|
|
1565
|
-
const self = Object.create(ChannelProto);
|
|
1566
|
-
self.transform = (upstream, scope) => catchCause$2(transform(upstream, scope), (cause) => succeed$3(failCause$3(cause)));
|
|
1567
|
-
return self;
|
|
1568
|
-
};
|
|
1569
|
-
const transformPull$1 = (self, f) => fromTransform((upstream, scope) => flatMap$2(toTransform(self)(upstream, scope), (pull) => f(pull, scope)));
|
|
1570
|
-
const fromPull$1 = (effect) => fromTransform((_, __) => effect);
|
|
1571
|
-
const fromTransformBracket = (f) => fromTransform(fnUntraced(function* (upstream, scope) {
|
|
1572
|
-
const closableScope = forkUnsafe(scope);
|
|
1573
|
-
const onCause = (cause) => close(closableScope, doneExitFromCause(cause));
|
|
1574
|
-
const pull = yield* onError(f(upstream, scope, closableScope), onCause);
|
|
1575
|
-
return onError(pull, onCause);
|
|
1576
|
-
}));
|
|
1577
|
-
const toTransform = (channel) => channel.transform;
|
|
1578
|
-
const DefaultChunkSize = 4096;
|
|
1579
|
-
const asyncQueue = (scope, f, options) => make$2({
|
|
1580
|
-
capacity: options?.bufferSize,
|
|
1581
|
-
strategy: options?.strategy
|
|
1582
|
-
}).pipe(tap$1((queue) => addFinalizer(scope, shutdown(queue))), tap$1((queue) => provide(f(queue), scope).pipe(catchCause$2((cause) => failCause$2(queue, cause)), forkIn(scope, { startImmediately: true }))));
|
|
1583
|
-
const callbackArray = (f, options) => fromTransform((_, scope) => map$2(asyncQueue(scope, f, options), takeAll));
|
|
1584
|
-
const suspend$1 = (evaluate) => fromTransform((upstream, scope) => suspend$2(() => toTransform(evaluate())(upstream, scope)));
|
|
1585
|
-
const fromIterator = (iterator) => fromPull$1(sync(() => {
|
|
1586
|
-
const iter = iterator();
|
|
1587
|
-
return suspend$2(() => {
|
|
1588
|
-
const state = iter.next();
|
|
1589
|
-
return state.done ? done(state.value) : succeed$3(state.value);
|
|
1590
|
-
});
|
|
1591
|
-
}));
|
|
1592
|
-
const fromIteratorArray = (iterator, chunkSize = DefaultChunkSize) => {
|
|
1593
|
-
const size = normalizeNonEmpty(chunkSize);
|
|
1594
|
-
return fromPull$1(sync(() => {
|
|
1595
|
-
const iter = iterator();
|
|
1596
|
-
let done$8 = none();
|
|
1597
|
-
return suspend$2(() => {
|
|
1598
|
-
if (done$8._tag === "Some") return done(done$8.value);
|
|
1599
|
-
const buffer = [];
|
|
1600
|
-
while (buffer.length < size) {
|
|
1601
|
-
const state = iter.next();
|
|
1602
|
-
if (state.done) {
|
|
1603
|
-
if (buffer.length === 0) return done(state.value);
|
|
1604
|
-
done$8 = some(state.value);
|
|
1605
|
-
break;
|
|
1606
|
-
}
|
|
1607
|
-
buffer.push(state.value);
|
|
1608
|
-
}
|
|
1609
|
-
return succeed$3(buffer);
|
|
1610
|
-
});
|
|
1611
|
-
}));
|
|
1612
|
-
};
|
|
1613
|
-
const fromIterableArray = (iterable, chunkSize = DefaultChunkSize) => fromIteratorArray(() => iterable[Symbol.iterator](), chunkSize);
|
|
1614
|
-
const succeed$1 = (value) => fromEffect$1(succeed$3(value));
|
|
1615
|
-
const empty$1 = fromPull$1(succeed$3(done()));
|
|
1616
|
-
const fail$1 = (error) => fromPull$1(succeed$3(fail$3(error)));
|
|
1617
|
-
const failCause$1 = (cause) => fromPull$1(failCause$3(cause));
|
|
1618
|
-
const die$1 = (defect) => failCause$1(die$2(defect));
|
|
1619
|
-
const fromEffect$1 = (effect) => fromPull$1(sync(() => {
|
|
1620
|
-
let done$9 = false;
|
|
1621
|
-
return suspend$2(() => {
|
|
1622
|
-
if (done$9) return done();
|
|
1623
|
-
done$9 = true;
|
|
1624
|
-
return effect;
|
|
1625
|
-
});
|
|
1626
|
-
}));
|
|
1627
|
-
const fromEffectDrain = (effect) => fromPull$1(flatMap$2(effect, () => done()));
|
|
1628
|
-
const fromEffectTake = (effect) => fromPull$1(succeed$3(flatMap$2(effect, toPull)));
|
|
1629
|
-
const fromQueueArray = (queue) => fromPull$1(succeed$3(takeAll(queue)));
|
|
1630
|
-
const fromSubscriptionArray = (subscription) => fromPull$1(succeed$3(onInterrupt(takeAll$1(subscription), () => done())));
|
|
1631
|
-
const fromPubSubArray = (pubsub) => unwrap$1(map$2(subscribe(pubsub), fromSubscriptionArray));
|
|
1632
|
-
const fromPubSubTake$1 = (pubsub) => unwrap$1(map$2(subscribe(pubsub), (sub) => fromEffectTake(take$2(sub))));
|
|
1633
|
-
const fromReadableStream$1 = (options) => fromTransform((_, scope) => readableStreamToPullUnsafe({
|
|
1634
|
-
scope,
|
|
1635
|
-
readable: options.evaluate(),
|
|
1636
|
-
onError: options.onError,
|
|
1637
|
-
releaseLockOnEnd: options.releaseLockOnEnd
|
|
1638
|
-
}));
|
|
1639
|
-
const readableStreamToPullUnsafe = (options) => {
|
|
1640
|
-
const reader = options.readable.getReader();
|
|
1641
|
-
const exit = options.exit ?? make$5(void 0);
|
|
1642
|
-
const pull = suspend$2(() => {
|
|
1643
|
-
if (exit.current) return exit.current;
|
|
1644
|
-
return matchCauseEffect(tryPromise({
|
|
1645
|
-
try: () => reader.read(),
|
|
1646
|
-
catch: options.onError
|
|
1647
|
-
}), {
|
|
1648
|
-
onFailure: (cause) => exit.current ?? failCause$3(cause),
|
|
1649
|
-
onSuccess: ({ done: done$11, value }) => {
|
|
1650
|
-
if (exit.current) return exit.current;
|
|
1651
|
-
return done$11 ? done() : succeed$3(of(value));
|
|
1652
|
-
}
|
|
1653
|
-
});
|
|
1654
|
-
});
|
|
1655
|
-
return as(addFinalizer(options.scope, options.releaseLockOnEnd ? sync(() => reader.releaseLock()) : promise(() => reader.cancel().catch((error) => reader.closed.then(() => Promise.reject(error), constVoid))).pipe(ensuring$2(sync(() => reader.releaseLock())))), pull);
|
|
1656
|
-
};
|
|
1657
|
-
const fromAsyncIterable$1 = (iterable, onError) => fromTransform(fnUntraced(function* (_, scope) {
|
|
1658
|
-
const iter = iterable[Symbol.asyncIterator]();
|
|
1659
|
-
let pulling = false;
|
|
1660
|
-
if (iter.return) yield* addFinalizer(scope, suspend$2(() => pulling ? sync(() => void iter.return().catch(constVoid)) : promise(() => iter.return())));
|
|
1661
|
-
return flatMap$2(tryPromise({
|
|
1662
|
-
try: () => {
|
|
1663
|
-
const promise = iter.next();
|
|
1664
|
-
pulling = true;
|
|
1665
|
-
return promise.finally(() => {
|
|
1666
|
-
pulling = false;
|
|
1667
|
-
});
|
|
1668
|
-
},
|
|
1669
|
-
catch: onError
|
|
1670
|
-
}), (result) => result.done ? done(result.value) : succeed$3(result.value));
|
|
1671
|
-
}));
|
|
1672
|
-
const fromAsyncIterableArray = (iterable, onError) => map$1(fromAsyncIterable$1(iterable, onError), of);
|
|
1673
|
-
const map$1 = dual(2, (self, f) => transformPull$1(self, (pull) => sync(() => {
|
|
1674
|
-
let i = 0;
|
|
1675
|
-
return map$2(pull, (o) => f(o, i++));
|
|
1676
|
-
})));
|
|
1677
|
-
const mapDone = dual(2, (self, f) => mapDoneEffect(self, (o) => succeed$3(f(o))));
|
|
1678
|
-
const mapDoneEffect = dual(2, (self, f) => transformPull$1(self, (pull) => succeed$3(catchDone(pull, (done$12) => flatMap$2(f(done$12), done)))));
|
|
1679
|
-
const concurrencyIsSequential = (concurrency) => concurrency === void 0 || concurrency !== "unbounded" && concurrency <= 1;
|
|
1680
|
-
const mapEffect$1 = dual((args) => isChannel(args[0]), (self, f, options) => concurrencyIsSequential(options?.concurrency) ? mapEffectSequential(self, f) : mapEffectConcurrent(self, f, options));
|
|
1681
|
-
const mapEffectSequential = (self, f) => fromTransform((upstream, scope) => {
|
|
1682
|
-
let i = 0;
|
|
1683
|
-
return map$2(toTransform(self)(upstream, scope), flatMap$2((o) => f(o, i++)));
|
|
1684
|
-
});
|
|
1685
|
-
const mapEffectConcurrent = (self, f, options) => fromTransformBracket(fnUntraced(function* (upstream, scope, forkedScope) {
|
|
1686
|
-
let i = 0;
|
|
1687
|
-
const pull = yield* toTransform(self)(upstream, scope);
|
|
1688
|
-
const concurrencyN = options.concurrency === "unbounded" ? Number.MAX_SAFE_INTEGER : Math.min(options.concurrency, Number.MAX_SAFE_INTEGER);
|
|
1689
|
-
const queue = yield* bounded(0);
|
|
1690
|
-
yield* addFinalizer(forkedScope, shutdown(queue));
|
|
1691
|
-
const runFork = runForkWith(yield* context());
|
|
1692
|
-
const trackFiber = runIn(forkedScope);
|
|
1693
|
-
if (options.unordered) {
|
|
1694
|
-
const semaphore = makeUnsafe(concurrencyN);
|
|
1695
|
-
const release = constant(semaphore.release(1));
|
|
1696
|
-
const handle = matchCauseEffect({
|
|
1697
|
-
onFailure: (cause) => flatMap$2(failCause$2(queue, cause), release),
|
|
1698
|
-
onSuccess: (value) => flatMap$2(offer(queue, value), release)
|
|
1699
|
-
});
|
|
1700
|
-
yield* semaphore.take(1).pipe(flatMap$2(() => pull), flatMap$2((value) => {
|
|
1701
|
-
const index = i++;
|
|
1702
|
-
trackFiber(runFork(handle(suspend$2(() => f(value, index)))));
|
|
1703
|
-
return void_;
|
|
1704
|
-
}), forever({ disableYield: true }), catchCause$2((cause) => semaphore.withPermits(concurrencyN - 1)(failCause$2(queue, cause))), forkIn(forkedScope));
|
|
1705
|
-
} else {
|
|
1706
|
-
const effects = yield* bounded(concurrencyN - 2);
|
|
1707
|
-
yield* addFinalizer(forkedScope, shutdown(effects));
|
|
1708
|
-
yield* take$1(effects).pipe(flatten$2, flatMap$2((value) => offer(queue, value)), forever({ disableYield: true }), catchCause$2((cause) => failCause$2(queue, cause)), forkIn(forkedScope));
|
|
1709
|
-
let errorCause;
|
|
1710
|
-
const onExit = (exit) => {
|
|
1711
|
-
if (exit._tag === "Success") return;
|
|
1712
|
-
errorCause = exit.cause;
|
|
1713
|
-
failCauseUnsafe(queue, exit.cause);
|
|
1714
|
-
};
|
|
1715
|
-
yield* pull.pipe(flatMap$2((value) => {
|
|
1716
|
-
if (errorCause) return failCause$3(errorCause);
|
|
1717
|
-
const index = i++;
|
|
1718
|
-
const fiber = runFork(suspend$2(() => f(value, index)));
|
|
1719
|
-
trackFiber(fiber);
|
|
1720
|
-
fiber.addObserver(onExit);
|
|
1721
|
-
return offer(effects, join(fiber));
|
|
1722
|
-
}), forever({ disableYield: true }), catchCause$2((cause) => offer(effects, failCause$4(cause)).pipe(andThen(failCause$2(effects, cause)))), forkIn(forkedScope));
|
|
1723
|
-
}
|
|
1724
|
-
return take$1(queue);
|
|
1725
|
-
}));
|
|
1726
|
-
const flatMap$1 = dual((args) => isChannel(args[0]), (self, f, options) => concurrencyIsSequential(options?.concurrency) ? flatMapSequential(self, f) : flatMapConcurrent(self, f, options));
|
|
1727
|
-
const flatMapSequential = (self, f) => fromTransform((upstream, scope) => map$2(toTransform(self)(upstream, scope), (pull) => {
|
|
1728
|
-
let childPull;
|
|
1729
|
-
let childScope;
|
|
1730
|
-
const makePull = flatMap$2(pull, (value) => {
|
|
1731
|
-
childScope ??= forkUnsafe(scope);
|
|
1732
|
-
return flatMapEager(toTransform(f(value))(upstream, childScope), (pull) => {
|
|
1733
|
-
childPull = catchHalt(pull);
|
|
1734
|
-
return childPull;
|
|
1735
|
-
});
|
|
1736
|
-
});
|
|
1737
|
-
const catchHalt = catchDone((_) => {
|
|
1738
|
-
childPull = void 0;
|
|
1739
|
-
if (childScope.state._tag === "Empty") return makePull;
|
|
1740
|
-
const close$2 = close(childScope, void_$2);
|
|
1741
|
-
childScope = void 0;
|
|
1742
|
-
return flatMap$2(close$2, () => makePull);
|
|
1743
|
-
});
|
|
1744
|
-
return suspend$2(() => childPull ?? makePull);
|
|
1745
|
-
}));
|
|
1746
|
-
const flatMapConcurrent = (self, f, options) => self.pipe(map$1(f), mergeAll$1(options));
|
|
1747
|
-
const flatten$1 = (channels) => flatMap$1(channels, identity);
|
|
1748
|
-
const flattenArray$1 = (self) => transformPull$1(self, (pull) => {
|
|
1749
|
-
let array;
|
|
1750
|
-
let index = 0;
|
|
1751
|
-
const pump = suspend$2(function loop() {
|
|
1752
|
-
if (array === void 0) return flatMap$2(pull, (array_) => {
|
|
1753
|
-
switch (array_.length) {
|
|
1754
|
-
case 0: return loop();
|
|
1755
|
-
case 1: return succeed$3(array_[0]);
|
|
1756
|
-
default:
|
|
1757
|
-
array = array_;
|
|
1758
|
-
return succeed$3(array_[index++]);
|
|
1759
|
-
}
|
|
1760
|
-
});
|
|
1761
|
-
const next = array[index++];
|
|
1762
|
-
if (index >= array.length) {
|
|
1763
|
-
array = void 0;
|
|
1764
|
-
index = 0;
|
|
1765
|
-
}
|
|
1766
|
-
return succeed$3(next);
|
|
1767
|
-
});
|
|
1768
|
-
return succeed$3(pump);
|
|
1769
|
-
});
|
|
1770
|
-
const filterArray = dual(2, (self, predicate) => transformPull$1(self, (pull) => succeed$3(flatMap$2(pull, function loop(arr) {
|
|
1771
|
-
const passes = [];
|
|
1772
|
-
for (let i = 0; i < arr.length; i++) if (predicate(arr[i])) passes.push(arr[i]);
|
|
1773
|
-
return isReadonlyArrayNonEmpty(passes) ? succeed$3(passes) : flatMap$2(pull, loop);
|
|
1774
|
-
}))));
|
|
1775
|
-
const filterMapArray = dual(2, (self, filter) => transformPull$1(self, (pull) => succeed$3(flatMap$2(pull, function loop(arr) {
|
|
1776
|
-
const passes = [];
|
|
1777
|
-
for (let i = 0; i < arr.length; i++) {
|
|
1778
|
-
const result = filter(arr[i]);
|
|
1779
|
-
if (isSuccess$1(result)) passes.push(result.success);
|
|
1780
|
-
}
|
|
1781
|
-
return isReadonlyArrayNonEmpty(passes) ? succeed$3(passes) : flatMap$2(pull, loop);
|
|
1782
|
-
}))));
|
|
1783
|
-
const catchCause$1 = dual(2, (self, f) => fromTransform((upstream, scope) => {
|
|
1784
|
-
let forkedScope = forkUnsafe(scope);
|
|
1785
|
-
return map$2(toTransform(self)(upstream, forkedScope), (pull) => {
|
|
1786
|
-
let currentPull = pull.pipe(catchCause$2((cause) => {
|
|
1787
|
-
if (isDoneCause(cause)) return failCause$3(cause);
|
|
1788
|
-
const toClose = forkedScope;
|
|
1789
|
-
forkedScope = forkUnsafe(scope);
|
|
1790
|
-
return close(toClose, failCause$4(cause)).pipe(andThen(toTransform(f(cause))(upstream, forkedScope)), flatMap$2((childPull) => {
|
|
1791
|
-
currentPull = childPull;
|
|
1792
|
-
return childPull;
|
|
1793
|
-
}));
|
|
1794
|
-
}));
|
|
1795
|
-
return suspend$2(() => currentPull);
|
|
1796
|
-
});
|
|
1797
|
-
}));
|
|
1798
|
-
const catchCauseFilter = dual(3, (self, filter, f) => catchCause$1(self, (cause) => {
|
|
1799
|
-
const result = filter(cause);
|
|
1800
|
-
return isFailure(result) ? failCause$1(result.failure) : f(result.success, cause);
|
|
1801
|
-
}));
|
|
1802
|
-
const catch_$1 = dual(2, (self, f) => catchCauseFilter(self, findRecoverableError, (e) => f(e)));
|
|
1803
|
-
const tapError$1 = dual(2, (self, f) => transformPull$1(self, (pull) => succeed$3(tapError$2(pull, (err) => isDone(err) ? void_ : asVoid(f(err))))));
|
|
1804
|
-
const catchIf$1 = dual((args) => isChannel(args[0]), (self, predicate, f, orElse) => catch_$1(self, (err) => {
|
|
1805
|
-
return predicate(err) ? f(err) : orElse ? orElse(err) : fail$1(err);
|
|
1806
|
-
}));
|
|
1807
|
-
const catchFilter$1 = dual((args) => isChannel(args[0]), (self, filter, f, orElse) => catch_$1(self, (err) => {
|
|
1808
|
-
const result = filter(err);
|
|
1809
|
-
return isFailure(result) ? orElse ? orElse(result.failure) : fail$1(result.failure) : f(result.success);
|
|
1810
|
-
}));
|
|
1811
|
-
const catchReason$1 = dual((args) => isChannel(args[0]), (self, errorTag, reasonTag, f, orElse) => catch_$1(self, (error) => {
|
|
1812
|
-
if (isTagged(error, errorTag) && hasProperty(error, "reason")) {
|
|
1813
|
-
const reason = error.reason;
|
|
1814
|
-
if (isTagged(reason, reasonTag)) return f(reason, error);
|
|
1815
|
-
return orElse ? orElse(reason, error) : fail$1(error);
|
|
1816
|
-
}
|
|
1817
|
-
return fail$1(error);
|
|
1818
|
-
}));
|
|
1819
|
-
const mapError$1 = dual(2, (self, f) => transformPull$1(self, (pull) => succeed$3(mapError$2(pull, (err) => isDone(err) ? err : f(err)))));
|
|
1820
|
-
const orDie$1 = (self) => catch_$1(self, die$1);
|
|
1821
|
-
const mergeAll$1 = dual(2, (channels, { bufferSize = 16, concurrency, switch: switch_ = false }) => fromTransformBracket(fnUntraced(function* (upstream, scope, forkedScope) {
|
|
1822
|
-
const concurrencyN = concurrency === "unbounded" ? Number.MAX_SAFE_INTEGER : Math.max(1, concurrency);
|
|
1823
|
-
const semaphore = switch_ ? void 0 : makeUnsafe(concurrencyN);
|
|
1824
|
-
const doneLatch = yield* make$6(true);
|
|
1825
|
-
const fibers = new Map();
|
|
1826
|
-
const queue = yield* bounded(bufferSize);
|
|
1827
|
-
yield* addFinalizer(forkedScope, shutdown(queue));
|
|
1828
|
-
const pull = yield* toTransform(channels)(upstream, scope);
|
|
1829
|
-
yield* gen(function* () {
|
|
1830
|
-
while (true) {
|
|
1831
|
-
let pullFiber;
|
|
1832
|
-
if (semaphore) {
|
|
1833
|
-
if (fibers.size < concurrencyN) yield* semaphore.take(1);
|
|
1834
|
-
else {
|
|
1835
|
-
pullFiber = yield* forkChild(pull);
|
|
1836
|
-
yield* raceFirst(semaphore.take(1), andThen(join(pullFiber), never));
|
|
1837
|
-
}
|
|
1838
|
-
}
|
|
1839
|
-
const channel = pullFiber === void 0 ? yield* pull : yield* join(pullFiber);
|
|
1840
|
-
const childScope = forkUnsafe(forkedScope);
|
|
1841
|
-
const childPull = yield* toTransform(channel)(upstream, childScope);
|
|
1842
|
-
while (fibers.size >= concurrencyN) {
|
|
1843
|
-
const [fiber, fiberScope] = headUnsafe(fibers);
|
|
1844
|
-
fibers.delete(fiber);
|
|
1845
|
-
if (fibers.size === 0) yield* doneLatch.open;
|
|
1846
|
-
yield* interrupt(fiber);
|
|
1847
|
-
yield* ignoreCause(close(fiberScope, interrupt$1()));
|
|
1848
|
-
}
|
|
1849
|
-
const fiber = yield* childPull.pipe(tap$1(() => yieldNow), flatMap$2((value) => offer(queue, value)), forever({ disableYield: true }), onError(fnUntraced(function* (cause) {
|
|
1850
|
-
const exit$1 = doneExitFromCause(cause);
|
|
1851
|
-
const closeExit = yield* exit(close(childScope, exit$1));
|
|
1852
|
-
if (!fibers.has(fiber)) return;
|
|
1853
|
-
const failure = asVoidAll([exit$1, closeExit]);
|
|
1854
|
-
if (isFailure$1(failure)) yield* failCause$2(queue, failure.cause);
|
|
1855
|
-
fibers.delete(fiber);
|
|
1856
|
-
if (semaphore) yield* semaphore.release(1);
|
|
1857
|
-
if (fibers.size === 0) yield* doneLatch.open;
|
|
1858
|
-
})), forkChild);
|
|
1859
|
-
doneLatch.closeUnsafe();
|
|
1860
|
-
fibers.set(fiber, childScope);
|
|
1861
|
-
}
|
|
1862
|
-
}).pipe(catchCause$2((cause) => {
|
|
1863
|
-
const halt = filterDone(cause);
|
|
1864
|
-
if (isSuccess$1(halt)) return doneLatch.whenOpen(failCause$2(queue, cause));
|
|
1865
|
-
return failCause$2(queue, cause);
|
|
1866
|
-
}), forkIn(forkedScope));
|
|
1867
|
-
return take$1(queue);
|
|
1868
|
-
})));
|
|
1869
|
-
const merge$1 = dual((args) => isChannel(args[0]) && isChannel(args[1]), (left, right, options) => fromTransformBracket(fnUntraced(function* (upstream, _scope, forkedScope) {
|
|
1870
|
-
const strategy = options?.haltStrategy ?? "both";
|
|
1871
|
-
const queue = yield* bounded(0);
|
|
1872
|
-
yield* addFinalizer(forkedScope, shutdown(queue));
|
|
1873
|
-
let done = 0;
|
|
1874
|
-
function onExit(side, cause) {
|
|
1875
|
-
done++;
|
|
1876
|
-
if (!isDoneCause(cause)) return failCause$2(queue, cause);
|
|
1877
|
-
switch (strategy) {
|
|
1878
|
-
case "both": return done === 2 ? failCause$2(queue, cause) : void_;
|
|
1879
|
-
case "left":
|
|
1880
|
-
case "right": return side === strategy ? failCause$2(queue, cause) : void_;
|
|
1881
|
-
case "either": return failCause$2(queue, cause);
|
|
1882
|
-
}
|
|
1883
|
-
}
|
|
1884
|
-
const runSide = (side, channel, scope) => toTransform(channel)(upstream, scope).pipe(flatMap$2((pull) => pull.pipe(flatMap$2((value) => offer(queue, value)), forever)), onError((cause) => onExitPrimitive$1(doneExitFromCause(cause), (exit) => close(scope, exit)).pipe(matchCauseEffect({
|
|
1885
|
-
onFailure: (cause) => onExit(side, cause),
|
|
1886
|
-
onSuccess: () => onExit(side, cause)
|
|
1887
|
-
}))), forkIn(forkedScope));
|
|
1888
|
-
yield* runSide("left", left, forkUnsafe(forkedScope));
|
|
1889
|
-
yield* runSide("right", right, forkUnsafe(forkedScope));
|
|
1890
|
-
return take$1(queue);
|
|
1891
|
-
})));
|
|
1892
|
-
const mergeEffect$1 = dual(2, (self, effect) => merge$1(self, fromEffectDrain(effect), { haltStrategy: "left" }));
|
|
1893
|
-
const splitLines$1 = () => fromTransform((upstream, _scope) => sync(() => {
|
|
1894
|
-
let stringBuilder = "";
|
|
1895
|
-
let midCRLF = false;
|
|
1896
|
-
let done$10 = none();
|
|
1897
|
-
function splitLinesArray(chunk) {
|
|
1898
|
-
const chunkBuilder = [];
|
|
1899
|
-
function pushLine(segment) {
|
|
1900
|
-
if (stringBuilder.length === 0) chunkBuilder.push(segment);
|
|
1901
|
-
else {
|
|
1902
|
-
chunkBuilder.push(stringBuilder + segment);
|
|
1903
|
-
stringBuilder = "";
|
|
1904
|
-
}
|
|
1905
|
-
}
|
|
1906
|
-
for (let i = 0; i < chunk.length; i++) {
|
|
1907
|
-
const str = chunk[i];
|
|
1908
|
-
if (str.length !== 0) {
|
|
1909
|
-
let from = 0;
|
|
1910
|
-
let indexOfCR = str.indexOf("\r");
|
|
1911
|
-
let indexOfLF = str.indexOf("\n");
|
|
1912
|
-
if (midCRLF) {
|
|
1913
|
-
if (indexOfLF === 0) {
|
|
1914
|
-
from = 1;
|
|
1915
|
-
indexOfLF = str.indexOf("\n", from);
|
|
1916
|
-
}
|
|
1917
|
-
midCRLF = false;
|
|
1918
|
-
}
|
|
1919
|
-
while (indexOfCR !== -1 || indexOfLF !== -1) if (indexOfCR === -1 || indexOfLF !== -1 && indexOfLF < indexOfCR) {
|
|
1920
|
-
pushLine(str.substring(from, indexOfLF));
|
|
1921
|
-
from = indexOfLF + 1;
|
|
1922
|
-
indexOfLF = str.indexOf("\n", from);
|
|
1923
|
-
} else {
|
|
1924
|
-
pushLine(str.substring(from, indexOfCR));
|
|
1925
|
-
if (str.length === indexOfCR + 1) {
|
|
1926
|
-
midCRLF = true;
|
|
1927
|
-
from = str.length;
|
|
1928
|
-
indexOfCR = -1;
|
|
1929
|
-
} else {
|
|
1930
|
-
from = indexOfCR + (indexOfLF === indexOfCR + 1 ? 2 : 1);
|
|
1931
|
-
indexOfCR = str.indexOf("\r", from);
|
|
1932
|
-
indexOfLF = str.indexOf("\n", from);
|
|
1933
|
-
}
|
|
1934
|
-
}
|
|
1935
|
-
stringBuilder = stringBuilder + str.substring(from);
|
|
1936
|
-
}
|
|
1937
|
-
}
|
|
1938
|
-
return isReadonlyArrayNonEmpty(chunkBuilder) ? chunkBuilder : null;
|
|
1939
|
-
}
|
|
1940
|
-
const pullOrFlush = suspend$2(() => {
|
|
1941
|
-
if (done$10._tag === "Some") return done(done$10.value);
|
|
1942
|
-
return matchEffect(upstream, {
|
|
1943
|
-
onSuccess: loop,
|
|
1944
|
-
onFailure: failCause$3,
|
|
1945
|
-
onDone: (leftover) => {
|
|
1946
|
-
done$10 = some(leftover);
|
|
1947
|
-
if (stringBuilder.length > 0) {
|
|
1948
|
-
const last = stringBuilder;
|
|
1949
|
-
stringBuilder = "";
|
|
1950
|
-
midCRLF = false;
|
|
1951
|
-
return succeed$3([last]);
|
|
1952
|
-
}
|
|
1953
|
-
return done(leftover);
|
|
1954
|
-
}
|
|
1955
|
-
});
|
|
1956
|
-
});
|
|
1957
|
-
function loop(chunk) {
|
|
1958
|
-
const lines = splitLinesArray(chunk);
|
|
1959
|
-
return lines !== null ? succeed$3(lines) : pullOrFlush;
|
|
1960
|
-
}
|
|
1961
|
-
return pullOrFlush;
|
|
1962
|
-
}));
|
|
1963
|
-
const decodeText$1 = (encoding, options) => fromTransform((upstream, _scope) => sync(() => {
|
|
1964
|
-
const decoder = new TextDecoder(encoding, options);
|
|
1965
|
-
const streamOptions = { stream: true };
|
|
1966
|
-
let pull = upstream.pipe(map$2(map$3((bytes) => decoder.decode(bytes, streamOptions))), catchDone((leftover) => {
|
|
1967
|
-
pull = done(leftover);
|
|
1968
|
-
const last = decoder.decode();
|
|
1969
|
-
return last.length > 0 ? succeed$3(of(last)) : pull;
|
|
1970
|
-
}));
|
|
1971
|
-
return suspend$2(() => pull);
|
|
1972
|
-
}));
|
|
1973
|
-
const pipeTo = dual(2, (self, that) => fromTransform((upstream, scope) => flatMap$2(toTransform(self)(upstream, scope), (upstream) => toTransform(that)(upstream, scope))));
|
|
1974
|
-
const isUpstreamFailure = (reason) => reason._tag === "Die" && isDone(reason.defect) && isCause(reason.defect.value);
|
|
1975
|
-
const hasUpstreamFailure = (cause) => cause.reasons.some(isUpstreamFailure);
|
|
1976
|
-
const upstreamFailureToDefect = (pull) => catchCause$2(pull, (cause) => isDoneCause(cause) ? failCause$3(cause) : die$3(Done$1(cause)));
|
|
1977
|
-
const unwrapUpstreamFailure = (cause) => hasUpstreamFailure(cause) ? fromReasons(cause.reasons.flatMap((reason) => isUpstreamFailure(reason) ? reason.defect.value.reasons : [reason])) : cause;
|
|
1978
|
-
const restoreUpstreamFailure = (effect) => catchCause$2(effect, (cause) => failCause$3(unwrapUpstreamFailure(cause)));
|
|
1979
|
-
const unwrap$1 = (channel) => fromTransform((upstream, scope) => {
|
|
1980
|
-
let pull;
|
|
1981
|
-
return succeed$3(suspend$2(() => {
|
|
1982
|
-
if (pull) return pull;
|
|
1983
|
-
return channel.pipe(provide(scope), flatMap$2((channel) => toTransform(channel)(upstream, scope)), flatMap$2((pull_) => pull = pull_));
|
|
1984
|
-
}));
|
|
1985
|
-
});
|
|
1986
|
-
const scoped$1 = (self) => fromTransformBracket((upstream, scope, forkedScope) => map$2(provide(toTransform(self)(upstream, scope), forkedScope), provide(forkedScope)));
|
|
1987
|
-
const onExit$1 = dual(2, (self, finalizer) => fromTransformBracket((upstream, scope, forkedScope) => addFinalizerExit(forkedScope, finalizer).pipe(andThen(toTransform(self)(upstream, scope)))));
|
|
1988
|
-
const ensuring$1 = dual(2, (self, finalizer) => onExit$1(self, (_) => finalizer));
|
|
1989
|
-
const runWith = (self, f, onHalt) => suspend$2(() => {
|
|
1990
|
-
const scope = makeUnsafe$1();
|
|
1991
|
-
const makePull = toTransform(self)(done(), scope);
|
|
1992
|
-
return catchDone(flatMap$2(makePull, f), onHalt ? onHalt : succeed$3).pipe(onExit$2((exit) => close(scope, exit)));
|
|
1993
|
-
});
|
|
1994
|
-
const provideContext$1 = dual(2, (self, context) => fromTransform((upstream, scope) => map$2(provideContext$2(toTransform(self)(upstream, scope), context), provideContext$2(context))));
|
|
1995
|
-
const provideService$1 = dual(3, (self, key, service) => fromTransform((upstream, scope) => map$2(provideService$2(toTransform(self)(upstream, scope), key, service), provideService$2(key, service))));
|
|
1996
|
-
const runDrain$1 = (self) => runWith(self, (pull) => forever(pull, { disableYield: true }));
|
|
1997
|
-
const runForEach$1 = dual(2, (self, f) => runWith(self, (pull) => forever(flatMap$2(pull, f), { disableYield: true })));
|
|
1998
|
-
const runLast$1 = (self) => suspend$2(() => {
|
|
1999
|
-
const absent = Symbol();
|
|
2000
|
-
let last = absent;
|
|
2001
|
-
return runWith(self, (pull) => forever(flatMap$2(pull, (item) => {
|
|
2002
|
-
last = item;
|
|
2003
|
-
return void_;
|
|
2004
|
-
}), { disableYield: true }), () => last === absent ? succeedNone$1 : succeedSome(last));
|
|
2005
|
-
});
|
|
2006
|
-
const runFold$1 = dual(3, (self, initial, f) => suspend$2(() => {
|
|
2007
|
-
let state = initial();
|
|
2008
|
-
return runWith(self, (pull) => whileLoop({
|
|
2009
|
-
while: constTrue,
|
|
2010
|
-
body: () => pull,
|
|
2011
|
-
step: (value) => {
|
|
2012
|
-
state = f(state, value);
|
|
2013
|
-
}
|
|
2014
|
-
}), () => succeed$3(state));
|
|
2015
|
-
}));
|
|
2016
|
-
const toPullScoped = (self, scope) => toTransform(self)(done(), scope);
|
|
2017
|
-
const makePubSub = (options) => acquireRelease(options.capacity === "unbounded" ? unbounded$1(options) : options.strategy === "dropping" ? dropping(options) : options.strategy === "sliding" ? sliding$1(options) : bounded$1(options), shutdown$1);
|
|
2018
|
-
const runIntoPubSubArray = dual((args) => isChannel(args[0]), (self, pubsub, options) => runForEach$1(self, (value) => publishAll(pubsub, value)).pipe(options?.shutdownOnEnd === true ? ensuring$2(shutdown$1(pubsub)) : identity));
|
|
2019
|
-
const toPubSubTake$1 = dual(2, fnUntraced(function* (self, options) {
|
|
2020
|
-
const pubsub = yield* makePubSub(options);
|
|
2021
|
-
yield* runForEach$1(self, (value) => publish(pubsub, value)).pipe(onExit$2((exit) => end$1(pubsub, exit)), forkScoped);
|
|
2022
|
-
return pubsub;
|
|
2023
|
-
}));
|
|
2024
|
-
// node_modules/.pnpm/effect@4.1.3/node_modules/effect/dist/internal/stream.js
|
|
2025
|
-
const TypeId$2 = "~effect/Stream";
|
|
2026
|
-
const streamVariance = {
|
|
2027
|
-
_R: identity,
|
|
2028
|
-
_E: identity,
|
|
2029
|
-
_A: identity
|
|
2030
|
-
};
|
|
2031
|
-
const Stream = function(channel) {
|
|
2032
|
-
this.channel = channel;
|
|
2033
|
-
};
|
|
2034
|
-
Stream.prototype = {
|
|
2035
|
-
[TypeId$2]: streamVariance,
|
|
2036
|
-
pipe() {
|
|
2037
|
-
return pipeArguments(this, arguments);
|
|
2038
|
-
}
|
|
2039
|
-
};
|
|
2040
|
-
const fromChannel$1 = (channel) => new Stream(channel);
|
|
2041
|
-
// node_modules/.pnpm/effect@4.1.3/node_modules/effect/dist/Stream.js
|
|
2042
|
-
const TypeId$1 = "~effect/Stream";
|
|
2043
|
-
const isStream = (u) => hasProperty(u, TypeId$1);
|
|
2044
|
-
const fromChannel = fromChannel$1;
|
|
2045
|
-
const fromEffect = (effect) => fromChannel(fromEffect$1(map$2(effect, of)));
|
|
2046
|
-
const fromPull = (pull) => fromChannel(fromPull$1(pull));
|
|
2047
|
-
const transformPull = (self, f) => fromChannel(fromTransform((_, scope) => flatMap$2(toPullScoped(self.channel, scope), (pull) => f(pull, scope))));
|
|
2048
|
-
const toChannel = (stream) => stream.channel;
|
|
2049
|
-
const callback = (f, options) => fromChannel(callbackArray(f, options));
|
|
2050
|
-
const empty = fromChannel(empty$1);
|
|
2051
|
-
const succeed = (value) => fromChannel(succeed$1(of(value)));
|
|
2052
|
-
const suspend = (stream) => {
|
|
2053
|
-
const suspended = fromChannel(suspend$1(() => stream().channel));
|
|
2054
|
-
suspendedStreams.set(suspended, stream);
|
|
2055
|
-
return suspended;
|
|
2056
|
-
};
|
|
2057
|
-
const suspendedStreams = new WeakMap();
|
|
2058
|
-
const fail = (error) => fromChannel(fail$1(error));
|
|
2059
|
-
const failCause = (cause) => fromChannel(failCause$1(cause));
|
|
2060
|
-
const die = (defect) => fromChannel(die$1(defect));
|
|
2061
|
-
const fromIterable = (iterable, options) => Array.isArray(iterable) && options?.chunkSize === void 0 ? fromArray(iterable) : fromChannel(fromIterableArray(iterable, options?.chunkSize));
|
|
2062
|
-
const fromArray = (array) => isReadonlyArrayNonEmpty(array) ? fromChannel(succeed$1(array)) : empty;
|
|
2063
|
-
const fromArrayEffect = (effect) => unwrap(map$2(effect, fromArray));
|
|
2064
|
-
const fromQueue = (queue) => fromChannel(fromQueueArray(queue));
|
|
2065
|
-
const fromPubSub = (pubsub) => fromChannel(fromPubSubArray(pubsub));
|
|
2066
|
-
const fromPubSubTake = (pubsub) => fromChannel(fromPubSubTake$1(pubsub));
|
|
2067
|
-
const fromReadableStream = (options) => fromChannel(fromReadableStream$1(options));
|
|
2068
|
-
const fromAsyncIterable = (iterable, onError) => fromChannel(fromAsyncIterableArray(iterable, onError));
|
|
2069
|
-
const unwrap = (effect) => fromChannel(unwrap$1(map$2(effect, toChannel)));
|
|
2070
|
-
const scoped = (self) => fromChannel(scoped$1(self.channel));
|
|
2071
|
-
const map = dual(2, (self, f) => suspend(() => {
|
|
2072
|
-
let i = 0;
|
|
2073
|
-
return fromChannel(map$1(self.channel, map$3((o) => f(o, i++))));
|
|
2074
|
-
}));
|
|
2075
|
-
const mapArray = dual(2, (self, f) => fromChannel(map$1(self.channel, f)));
|
|
2076
|
-
const mapEffect = dual((args) => isStream(args[0]), (self, f, options) => self.channel.pipe(flattenArray$1, mapEffect$1(f, options), map$1(of), fromChannel));
|
|
2077
|
-
const mapArrayEffect = dual(2, (self, f) => fromChannel(mapEffect$1(self.channel, f)));
|
|
2078
|
-
const tap = dual((args) => isStream(args[0]), (self, f, options) => mapEffect(self, (a) => as(f(a), a), options));
|
|
2079
|
-
const flatMap = dual((args) => isStream(args[0]), (self, f, options) => self.channel.pipe(flattenArray$1, flatMap$1((a) => f(a).channel, options), fromChannel));
|
|
2080
|
-
const flatten = dual((args) => isStream(args[0]), (self, options) => flatMap(self, identity, options));
|
|
2081
|
-
const flattenArray = (self) => fromChannel(flattenArray$1(self.channel));
|
|
2082
|
-
const drainFork = dual(2, (self, that) => mergeEffect(self, runDrain(that)));
|
|
2083
|
-
const flattenIterable = (self) => flatMap(self, fromIterable);
|
|
2084
|
-
const concat = dual(2, (self, that) => {
|
|
2085
|
-
const stream = fromChannel(flatten$1(fromIterator(() => concatChannels(self, that))));
|
|
2086
|
-
concatParts.set(stream, [self, that]);
|
|
2087
|
-
return stream;
|
|
2088
|
-
});
|
|
2089
|
-
const concatParts = new WeakMap();
|
|
2090
|
-
function* concatChannels(self, that) {
|
|
2091
|
-
const stack = [that, self];
|
|
2092
|
-
while (stack.length > 0) {
|
|
2093
|
-
const stream = stack.pop();
|
|
2094
|
-
const parts = concatParts.get(stream);
|
|
2095
|
-
if (parts !== void 0) {
|
|
2096
|
-
stack.push(parts[1], parts[0]);
|
|
2097
|
-
continue;
|
|
2098
|
-
}
|
|
2099
|
-
const evaluate = suspendedStreams.get(stream);
|
|
2100
|
-
if (evaluate === void 0) {
|
|
2101
|
-
yield stream.channel;
|
|
2102
|
-
continue;
|
|
2103
|
-
}
|
|
2104
|
-
try {
|
|
2105
|
-
stack.push(evaluate());
|
|
2106
|
-
} catch (defect) {
|
|
2107
|
-
stack.push(die(defect));
|
|
2108
|
-
}
|
|
2109
|
-
yield empty$1;
|
|
2110
|
-
}
|
|
2111
|
-
}
|
|
2112
|
-
const merge = dual((args) => isStream(args[0]) && isStream(args[1]), (self, that, options) => fromChannel(merge$1(toChannel(self), toChannel(that), options)));
|
|
2113
|
-
const mergeEffect = dual(2, (self, effect) => self.channel.pipe(mergeEffect$1(effect), fromChannel));
|
|
2114
|
-
const mergeAll = dual(2, (streams, options) => flatten(fromIterable(streams), options));
|
|
2115
|
-
const filter = dual(2, (self, predicate) => fromChannel(filterArray(toChannel(self), predicate)));
|
|
2116
|
-
const filterMap = dual(2, (self, filter) => fromChannel(filterMapArray(toChannel(self), filter)));
|
|
2117
|
-
const catchCause = dual(2, (self, f) => self.channel.pipe(catchCause$1((cause) => f(cause).channel), fromChannel));
|
|
2118
|
-
const catch_ = dual(2, (self, f) => fromChannel(catch_$1(self.channel, (error) => f(error).channel)));
|
|
2119
|
-
const tapError = dual(2, (self, f) => self.channel.pipe(tapError$1(f), fromChannel));
|
|
2120
|
-
const catchIf = dual((args) => isStream(args[0]), (self, predicate, f, orElse) => fromChannel(catchIf$1(toChannel(self), predicate, (e) => f(e).channel, orElse && ((e) => orElse(e).channel))));
|
|
2121
|
-
const catchFilter = dual((args) => isStream(args[0]), (self, filter, f, orElse) => fromChannel(catchFilter$1(toChannel(self), filter, (e) => f(e).channel, orElse && ((e) => orElse(e).channel))));
|
|
2122
|
-
const catchTags = dual((args) => isStream(args[0]), (self, cases, orElse) => {
|
|
2123
|
-
let keys;
|
|
2124
|
-
return catchFilter(self, (e) => {
|
|
2125
|
-
keys ??= Object.keys(cases);
|
|
2126
|
-
return hasProperty(e, "_tag") && isString(e["_tag"]) && keys.includes(e["_tag"]) ? succeed$5(e) : fail$4(e);
|
|
2127
|
-
}, (e) => cases[e["_tag"]](e), orElse);
|
|
2128
|
-
});
|
|
2129
|
-
const catchReason = dual((args) => isStream(args[0]), (self, errorTag, reasonTag, f, orElse) => fromChannel(catchReason$1(toChannel(self), errorTag, reasonTag, (reason, error) => f(reason, error).channel, orElse && ((reason, error) => orElse(reason, error).channel))));
|
|
2130
|
-
const mapError = dual(2, (self, f) => fromChannel(mapError$1(self.channel, f)));
|
|
2131
|
-
const orDie = (self) => fromChannel(orDie$1(self.channel));
|
|
2132
|
-
const take = dual(2, (self, n) => {
|
|
2133
|
-
const count = normalize(n);
|
|
2134
|
-
return count === 0 ? empty : takeUntil(self, (_, i) => i === count - 1);
|
|
2135
|
-
});
|
|
2136
|
-
const takeUntil = dual((args) => isStream(args[0]), (self, predicate, options) => transformPull(self, (pull, _scope) => sync(() => {
|
|
2137
|
-
let i = 0;
|
|
2138
|
-
let done$6 = false;
|
|
2139
|
-
return flatMap$2(suspend$2(() => done$6 ? done() : pull), (chunk) => {
|
|
2140
|
-
const index = chunk.findIndex((a) => predicate(a, i++));
|
|
2141
|
-
if (index >= 0) {
|
|
2142
|
-
done$6 = true;
|
|
2143
|
-
const arr = chunk.slice(0, options?.excludeLast ? index : index + 1);
|
|
2144
|
-
return isReadonlyArrayNonEmpty(arr) ? succeed$3(arr) : done();
|
|
2145
|
-
}
|
|
2146
|
-
return succeed$3(chunk);
|
|
2147
|
-
});
|
|
2148
|
-
})));
|
|
2149
|
-
const takeWhile = dual(2, (self, predicate) => transformPull(self, (pull, _scope) => sync(() => {
|
|
2150
|
-
let i = 0;
|
|
2151
|
-
let done$7 = false;
|
|
2152
|
-
const pump = flatMap$2(suspend$2(() => done$7 ? done() : pull), (chunk) => {
|
|
2153
|
-
const out = [];
|
|
2154
|
-
for (let j = 0; j < chunk.length; j++) {
|
|
2155
|
-
if (!predicate(chunk[j], i++)) {
|
|
2156
|
-
done$7 = true;
|
|
2157
|
-
break;
|
|
2158
|
-
}
|
|
2159
|
-
out.push(chunk[j]);
|
|
2160
|
-
}
|
|
2161
|
-
return isReadonlyArrayNonEmpty(out) ? succeed$3(out) : done$7 ? done() : pump;
|
|
2162
|
-
});
|
|
2163
|
-
return pump;
|
|
2164
|
-
})));
|
|
2165
|
-
const drop = dual(2, (self, n) => {
|
|
2166
|
-
const count = normalize(n);
|
|
2167
|
-
if (count === 0) return self;
|
|
2168
|
-
return transformPull(self, (pull, _scope) => sync(() => {
|
|
2169
|
-
let dropped = 0;
|
|
2170
|
-
const pump = pull.pipe(flatMap$2((chunk) => {
|
|
2171
|
-
if (dropped >= count) return succeed$3(chunk);
|
|
2172
|
-
dropped += chunk.length;
|
|
2173
|
-
if (dropped <= count) return pump;
|
|
2174
|
-
return succeed$3(chunk.slice(count - dropped));
|
|
2175
|
-
}));
|
|
2176
|
-
return pump;
|
|
2177
|
-
}));
|
|
2178
|
-
});
|
|
2179
|
-
const transduce = dual(2, (self, sink) => transformPull(self, (upstream, scope) => sync(() => {
|
|
2180
|
-
let done$3;
|
|
2181
|
-
let leftover;
|
|
2182
|
-
const upstreamWithLeftover = suspend$2(() => {
|
|
2183
|
-
if (leftover !== void 0) {
|
|
2184
|
-
const chunk = leftover;
|
|
2185
|
-
leftover = void 0;
|
|
2186
|
-
return succeed$3(chunk);
|
|
2187
|
-
}
|
|
2188
|
-
return upstream;
|
|
2189
|
-
}).pipe(catch_$2((error) => {
|
|
2190
|
-
done$3 = fail$5(error);
|
|
2191
|
-
return done();
|
|
2192
|
-
}));
|
|
2193
|
-
const pull = map$2(suspend$2(() => sink.transform(upstreamWithLeftover, scope)), ([value, leftover_]) => {
|
|
2194
|
-
leftover = leftover_;
|
|
2195
|
-
return of(value);
|
|
2196
|
-
});
|
|
2197
|
-
return suspend$2(() => done$3 ? done$3 : pull);
|
|
2198
|
-
})));
|
|
2199
|
-
const broadcast = dual(2, (self, options) => map$2(toPubSubTake(self, options), fromPubSubTake));
|
|
2200
|
-
const pipeThroughChannel = dual(2, (self, channel) => fromChannel(pipeTo(self.channel, channel)));
|
|
2201
|
-
const decodeText = dual((args) => isStream(args[0]), (self, options) => self.channel.pipe(pipeTo(decodeText$1(options?.encoding)), fromChannel));
|
|
2202
|
-
const splitLines = (self) => self.channel.pipe(pipeTo(splitLines$1()), fromChannel);
|
|
2203
|
-
const onExit = dual(2, (self, finalizer) => fromChannel(onExit$1(self.channel, finalizer)));
|
|
2204
|
-
const ensuring = dual(2, (self, finalizer) => fromChannel(ensuring$1(self.channel, finalizer)));
|
|
2205
|
-
const provideContext = dual(2, (self, context) => fromChannel(provideContext$1(self.channel, context)));
|
|
2206
|
-
const provideService = dual(3, (self, key, service) => fromChannel(provideService$1(self.channel, key, service)));
|
|
2207
|
-
const run = dual(2, (self, sink) => scopedWith((scope) => toPullScoped(self.channel, scope).pipe(flatMap$2((upstream) => runSink(sink, upstream, scope)), map$2(([a]) => a))));
|
|
2208
|
-
const runSink = (sink, upstream, scope) => restoreUpstreamFailure(sink.transform(upstreamFailureToDefect(upstream), scope));
|
|
2209
|
-
const runCollect = (self) => runFold$1(self.channel, () => [], (acc, chunk) => {
|
|
2210
|
-
for (let i = 0; i < chunk.length; i++) acc.push(chunk[i]);
|
|
2211
|
-
return acc;
|
|
2212
|
-
});
|
|
2213
|
-
const runFold = dual(3, (self, initial, f) => runFold$1(self.channel, initial, (acc, arr) => {
|
|
2214
|
-
for (let i = 0; i < arr.length; i++) acc = f(acc, arr[i]);
|
|
2215
|
-
return acc;
|
|
2216
|
-
}));
|
|
2217
|
-
const runLast = (self) => map$2(runLast$1(self.channel), map$4(lastNonEmpty));
|
|
2218
|
-
const runForEach = dual(2, (self, f) => runForEach$1(self.channel, (arr) => {
|
|
2219
|
-
let i = 0;
|
|
2220
|
-
return whileLoop({
|
|
2221
|
-
while: () => i < arr.length,
|
|
2222
|
-
body: () => f(arr[i++]),
|
|
2223
|
-
step: constVoid
|
|
2224
|
-
});
|
|
2225
|
-
}));
|
|
2226
|
-
const runForEachArray = dual(2, (self, f) => runForEach$1(self.channel, f));
|
|
2227
|
-
const runDrain = (self) => runDrain$1(self.channel);
|
|
2228
|
-
const mkString = (self) => runFold$1(self.channel, () => "", (acc, chunk) => acc + chunk.join(""));
|
|
2229
|
-
const toAsyncIterableWith = dual(2, (self, context) => ({ [Symbol.asyncIterator]() {
|
|
2230
|
-
const runPromise = runPromiseWith(context);
|
|
2231
|
-
const runFork = runForkWith(context);
|
|
2232
|
-
const scope = makeUnsafe$1();
|
|
2233
|
-
let pull;
|
|
2234
|
-
let currentIter;
|
|
2235
|
-
let currentFiber;
|
|
2236
|
-
let closePromise;
|
|
2237
|
-
const close$1 = (exit) => {
|
|
2238
|
-
if (closePromise) return closePromise;
|
|
2239
|
-
const fiber = currentFiber;
|
|
2240
|
-
closePromise = runPromise(as(andThen(fiber ? interrupt(fiber) : void_, close(scope, exit)), {
|
|
2241
|
-
done: true,
|
|
2242
|
-
value: void 0
|
|
2243
|
-
}));
|
|
2244
|
-
return closePromise;
|
|
2245
|
-
};
|
|
2246
|
-
const closeAndReportError = async (exit) => {
|
|
2247
|
-
try {
|
|
2248
|
-
await close$1(exit);
|
|
2249
|
-
} catch (error) {
|
|
2250
|
-
await runPromise(logError("Suppressed error while closing Stream async iterator", error));
|
|
2251
|
-
}
|
|
2252
|
-
};
|
|
2253
|
-
return {
|
|
2254
|
-
async next() {
|
|
2255
|
-
if (closePromise) return closePromise;
|
|
2256
|
-
if (currentIter) {
|
|
2257
|
-
const next = currentIter.next();
|
|
2258
|
-
if (!next.done) return next;
|
|
2259
|
-
currentIter = void 0;
|
|
2260
|
-
}
|
|
2261
|
-
const fiber = runFork(pull ?? flatMap$2(toPullScoped(self.channel, scope), (nextPull) => {
|
|
2262
|
-
pull = nextPull;
|
|
2263
|
-
return nextPull;
|
|
2264
|
-
}));
|
|
2265
|
-
currentFiber = fiber;
|
|
2266
|
-
const exit = await runPromise(await_(fiber));
|
|
2267
|
-
if (currentFiber === fiber) currentFiber = void 0;
|
|
2268
|
-
if (isSuccess(exit)) {
|
|
2269
|
-
currentIter = exit.value[Symbol.iterator]();
|
|
2270
|
-
return currentIter.next();
|
|
2271
|
-
} else if (isDoneCause(exit.cause)) return close$1(void_$2);
|
|
2272
|
-
if (closePromise && hasInterruptsOnly(exit.cause)) return closePromise;
|
|
2273
|
-
await closeAndReportError(exit);
|
|
2274
|
-
throw squash(exit.cause);
|
|
2275
|
-
},
|
|
2276
|
-
return() {
|
|
2277
|
-
return close$1(void_$2);
|
|
2278
|
-
},
|
|
2279
|
-
async throw(error) {
|
|
2280
|
-
await closeAndReportError(die$4(error));
|
|
2281
|
-
throw error;
|
|
2282
|
-
}
|
|
2283
|
-
};
|
|
2284
|
-
} }));
|
|
2285
|
-
const toAsyncIterable = (self) => toAsyncIterableWith(self, empty$2());
|
|
2286
|
-
const runIntoPubSub = dual((args) => isStream(args[0]), (self, pubsub, options) => runIntoPubSubArray(self.channel, pubsub, options));
|
|
2287
|
-
const toPubSubTake = dual(2, (self, options) => toPubSubTake$1(self.channel, options));
|
|
2288
|
-
// node_modules/.pnpm/effect@4.1.3/node_modules/effect/dist/ai/AiError.js
|
|
2289
|
-
const HttpResponseDetails = Struct({
|
|
2290
|
-
status: Int,
|
|
2291
|
-
headers: Record(String$1, Union([String$1, Redacted(String$1)]))
|
|
2292
|
-
}).annotate({ identifier: "HttpResponseDetails" });
|
|
2293
|
-
const ReasonTypeId = "~effect/ai/AiError/Reason";
|
|
2294
|
-
const providerMetadataWithDefaults = () => ProviderMetadata.pipe(withConstructorDefault(succeed$3({})), withDecodingDefault(succeed$3({})));
|
|
2295
|
-
var NetworkError = class NetworkError extends Error$1("effect/ai/AiError/NetworkError")({
|
|
2296
|
-
_tag: tag("NetworkError"),
|
|
2297
|
-
reason: Literals([
|
|
2298
|
-
"TransportError",
|
|
2299
|
-
"EncodeError",
|
|
2300
|
-
"InvalidUrlError"
|
|
2301
|
-
]),
|
|
2302
|
-
method: String$1,
|
|
2303
|
-
url: String$1,
|
|
2304
|
-
description: optional(String$1),
|
|
2305
|
-
cause: optional(Defect())
|
|
2306
|
-
}) {
|
|
2307
|
-
[ReasonTypeId] = ReasonTypeId;
|
|
2308
|
-
get isRetryable() {
|
|
2309
|
-
return this.reason === "TransportError";
|
|
2310
|
-
}
|
|
2311
|
-
static fromRequestError(error) {
|
|
2312
|
-
return new NetworkError({
|
|
2313
|
-
description: error.description,
|
|
2314
|
-
reason: error._tag,
|
|
2315
|
-
method: error.request.method,
|
|
2316
|
-
url: error.request.url
|
|
2317
|
-
});
|
|
2318
|
-
}
|
|
2319
|
-
static fromHttpClientError(error) {
|
|
2320
|
-
return new NetworkError({
|
|
2321
|
-
description: error.reason.description,
|
|
2322
|
-
reason: error.reason._tag,
|
|
2323
|
-
method: error.reason.request.method,
|
|
2324
|
-
url: error.reason.request.url,
|
|
2325
|
-
cause: error
|
|
2326
|
-
});
|
|
2327
|
-
}
|
|
2328
|
-
get message() {
|
|
2329
|
-
const methodAndUrl = `${this.method} ${this.url}`;
|
|
2330
|
-
let baseMessage = this.description ? `${this.reason}: ${this.description}` : `${this.reason}: A network error occurred.`;
|
|
2331
|
-
baseMessage += ` (${methodAndUrl})`;
|
|
2332
|
-
let suggestion = "";
|
|
2333
|
-
switch (this.reason) {
|
|
2334
|
-
case "EncodeError":
|
|
2335
|
-
suggestion += "Check that the request body data is properly formatted and matches the expected content type.";
|
|
2336
|
-
break;
|
|
2337
|
-
case "InvalidUrlError":
|
|
2338
|
-
suggestion += "Verify that the URL format is correct and that all required parameters have been provided.";
|
|
2339
|
-
suggestion += " Check for any special characters that may need encoding.";
|
|
2340
|
-
break;
|
|
2341
|
-
case "TransportError": suggestion += "Check your network connection and verify that the requested URL is accessible.";
|
|
2342
|
-
}
|
|
2343
|
-
baseMessage += `\n\n${suggestion}`;
|
|
2344
|
-
return baseMessage;
|
|
2345
|
-
}
|
|
2346
|
-
};
|
|
2347
|
-
const ProviderMetadata = Record(String$1, NullOr(MutableJson));
|
|
2348
|
-
const UsageInfo = Struct({
|
|
2349
|
-
promptTokens: optional(Int),
|
|
2350
|
-
completionTokens: optional(Int),
|
|
2351
|
-
totalTokens: optional(Int)
|
|
2352
|
-
}).annotate({ identifier: "UsageInfo" });
|
|
2353
|
-
const HttpContext = Struct({
|
|
2354
|
-
response: optional(HttpResponseDetails),
|
|
2355
|
-
body: optional(String$1)
|
|
2356
|
-
}).annotate({ identifier: "HttpContext" });
|
|
2357
|
-
const buildErrorDescription = (params) => {
|
|
2358
|
-
const parts = [];
|
|
2359
|
-
if (params.message) parts.push(params.message);
|
|
2360
|
-
else parts.push(`HTTP ${params.status}`);
|
|
2361
|
-
parts.push(`(${params.method} ${params.url})`);
|
|
2362
|
-
if (params.errorCode) parts.push(`[code: ${params.errorCode}]`);
|
|
2363
|
-
else if (params.errorType) parts.push(`[type: ${params.errorType}]`);
|
|
2364
|
-
if (params.requestId) parts.push(`[requestId: ${params.requestId}]`);
|
|
2365
|
-
if (!params.message && params.body) {
|
|
2366
|
-
const truncated = params.body.length > 200 ? params.body.slice(0, 200) + "..." : params.body;
|
|
2367
|
-
parts.push(`Response: ${truncated}`);
|
|
2368
|
-
}
|
|
2369
|
-
return parts.join(" ");
|
|
2370
|
-
};
|
|
2371
|
-
var RateLimitError = class extends Error$1("effect/ai/AiError/RateLimitError")({
|
|
2372
|
-
_tag: tag("RateLimitError"),
|
|
2373
|
-
retryAfter: optional(Duration),
|
|
2374
|
-
metadata: providerMetadataWithDefaults(),
|
|
2375
|
-
http: optional(HttpContext)
|
|
2376
|
-
}) {
|
|
2377
|
-
[ReasonTypeId] = ReasonTypeId;
|
|
2378
|
-
get isRetryable() {
|
|
2379
|
-
return true;
|
|
2380
|
-
}
|
|
2381
|
-
get message() {
|
|
2382
|
-
let msg = "Rate limit exceeded";
|
|
2383
|
-
if (this.retryAfter) msg += `. Retry after ${format(this.retryAfter)}`;
|
|
2384
|
-
return msg;
|
|
2385
|
-
}
|
|
2386
|
-
};
|
|
2387
|
-
var QuotaExhaustedError = class extends Error$1("effect/ai/AiError/QuotaExhaustedError")({
|
|
2388
|
-
_tag: tag("QuotaExhaustedError"),
|
|
2389
|
-
resetAt: optional(DateTimeUtc),
|
|
2390
|
-
metadata: providerMetadataWithDefaults(),
|
|
2391
|
-
http: optional(HttpContext)
|
|
2392
|
-
}) {
|
|
2393
|
-
[ReasonTypeId] = ReasonTypeId;
|
|
2394
|
-
get isRetryable() {
|
|
2395
|
-
return false;
|
|
2396
|
-
}
|
|
2397
|
-
get message() {
|
|
2398
|
-
let msg = "Quota exhausted";
|
|
2399
|
-
if (this.resetAt) msg += `. Resets at ${this.resetAt}`;
|
|
2400
|
-
return `${msg}. Check your account billing and usage limits.`;
|
|
2401
|
-
}
|
|
2402
|
-
};
|
|
2403
|
-
var AuthenticationError = class extends Error$1("effect/ai/AiError/AuthenticationError")({
|
|
2404
|
-
_tag: tag("AuthenticationError"),
|
|
2405
|
-
kind: Literals([
|
|
2406
|
-
"InvalidKey",
|
|
2407
|
-
"ExpiredKey",
|
|
2408
|
-
"MissingKey",
|
|
2409
|
-
"InsufficientPermissions",
|
|
2410
|
-
"Unknown"
|
|
2411
|
-
]),
|
|
2412
|
-
description: optional(String$1),
|
|
2413
|
-
metadata: providerMetadataWithDefaults(),
|
|
2414
|
-
http: optional(HttpContext)
|
|
2415
|
-
}) {
|
|
2416
|
-
[ReasonTypeId] = ReasonTypeId;
|
|
2417
|
-
get isRetryable() {
|
|
2418
|
-
return false;
|
|
2419
|
-
}
|
|
2420
|
-
get message() {
|
|
2421
|
-
let msg = `${this.kind}: ${{
|
|
2422
|
-
InvalidKey: "Verify your API key is correct",
|
|
2423
|
-
ExpiredKey: "Your API key has expired. Generate a new one",
|
|
2424
|
-
MissingKey: "No API key provided. Set the appropriate environment variable",
|
|
2425
|
-
InsufficientPermissions: "Your API key lacks required permissions",
|
|
2426
|
-
Unknown: "Authentication failed. Check your credentials"
|
|
2427
|
-
}[this.kind]}`;
|
|
2428
|
-
if (this.description) msg += `. ${this.description}`;
|
|
2429
|
-
return msg;
|
|
2430
|
-
}
|
|
2431
|
-
};
|
|
2432
|
-
var ContentPolicyError = class extends Error$1("effect/ai/AiError/ContentPolicyError")({
|
|
2433
|
-
_tag: tag("ContentPolicyError"),
|
|
2434
|
-
description: String$1,
|
|
2435
|
-
metadata: providerMetadataWithDefaults(),
|
|
2436
|
-
http: optional(HttpContext)
|
|
2437
|
-
}) {
|
|
2438
|
-
[ReasonTypeId] = ReasonTypeId;
|
|
2439
|
-
get isRetryable() {
|
|
2440
|
-
return false;
|
|
2441
|
-
}
|
|
2442
|
-
get message() {
|
|
2443
|
-
return `Content policy violation: ${this.description}`;
|
|
2444
|
-
}
|
|
2445
|
-
};
|
|
2446
|
-
var InvalidRequestError = class extends Error$1("effect/ai/AiError/InvalidRequestError")({
|
|
2447
|
-
_tag: tag("InvalidRequestError"),
|
|
2448
|
-
parameter: optional(String$1),
|
|
2449
|
-
constraint: optional(String$1),
|
|
2450
|
-
description: optional(String$1),
|
|
2451
|
-
metadata: providerMetadataWithDefaults(),
|
|
2452
|
-
http: optional(HttpContext)
|
|
2453
|
-
}) {
|
|
2454
|
-
[ReasonTypeId] = ReasonTypeId;
|
|
2455
|
-
get isRetryable() {
|
|
2456
|
-
return false;
|
|
2457
|
-
}
|
|
2458
|
-
get message() {
|
|
2459
|
-
let msg = "Invalid request";
|
|
2460
|
-
if (this.parameter) msg += `: parameter '${this.parameter}'`;
|
|
2461
|
-
if (this.constraint) msg += ` ${this.constraint}`;
|
|
2462
|
-
if (this.description) msg += `. ${this.description}`;
|
|
2463
|
-
return msg;
|
|
2464
|
-
}
|
|
2465
|
-
};
|
|
2466
|
-
var InternalProviderError = class extends Error$1("effect/ai/AiError/InternalProviderError")({
|
|
2467
|
-
_tag: tag("InternalProviderError"),
|
|
2468
|
-
description: String$1,
|
|
2469
|
-
metadata: providerMetadataWithDefaults(),
|
|
2470
|
-
http: optional(HttpContext)
|
|
2471
|
-
}) {
|
|
2472
|
-
[ReasonTypeId] = ReasonTypeId;
|
|
2473
|
-
get isRetryable() {
|
|
2474
|
-
return true;
|
|
2475
|
-
}
|
|
2476
|
-
get message() {
|
|
2477
|
-
return `Internal provider error: ${this.description}`;
|
|
2478
|
-
}
|
|
2479
|
-
};
|
|
2480
|
-
var InvalidResponseError = class InvalidResponseError extends Error$1("effect/ai/AiError/InvalidResponseError")({
|
|
2481
|
-
_tag: tag("InvalidResponseError"),
|
|
2482
|
-
description: String$1,
|
|
2483
|
-
metadata: providerMetadataWithDefaults(),
|
|
2484
|
-
http: optional(HttpContext)
|
|
2485
|
-
}) {
|
|
2486
|
-
[ReasonTypeId] = ReasonTypeId;
|
|
2487
|
-
get isRetryable() {
|
|
2488
|
-
return false;
|
|
2489
|
-
}
|
|
2490
|
-
static fromSchemaError(error) {
|
|
2491
|
-
return new InvalidResponseError({ description: error.message });
|
|
2492
|
-
}
|
|
2493
|
-
get message() {
|
|
2494
|
-
return `Invalid response: ${this.description}`;
|
|
2495
|
-
}
|
|
2496
|
-
};
|
|
2497
|
-
var InvalidOutputError = class InvalidOutputError extends Error$1("effect/ai/AiError/InvalidOutputError")({
|
|
2498
|
-
_tag: tag("InvalidOutputError"),
|
|
2499
|
-
description: String$1,
|
|
2500
|
-
metadata: providerMetadataWithDefaults(),
|
|
2501
|
-
usage: optional(UsageInfo)
|
|
2502
|
-
}) {
|
|
2503
|
-
[ReasonTypeId] = ReasonTypeId;
|
|
2504
|
-
get isRetryable() {
|
|
2505
|
-
return true;
|
|
2506
|
-
}
|
|
2507
|
-
static fromSchemaError(error) {
|
|
2508
|
-
return new InvalidOutputError({ description: error.message });
|
|
2509
|
-
}
|
|
2510
|
-
get message() {
|
|
2511
|
-
return `Invalid output: ${this.description}`;
|
|
2512
|
-
}
|
|
2513
|
-
};
|
|
2514
|
-
var StructuredOutputError = class StructuredOutputError extends Error$1("effect/ai/AiError/StructuredOutputError")({
|
|
2515
|
-
_tag: tag("StructuredOutputError"),
|
|
2516
|
-
description: String$1,
|
|
2517
|
-
responseText: String$1,
|
|
2518
|
-
metadata: providerMetadataWithDefaults(),
|
|
2519
|
-
usage: optional(UsageInfo)
|
|
2520
|
-
}) {
|
|
2521
|
-
[ReasonTypeId] = ReasonTypeId;
|
|
2522
|
-
get isRetryable() {
|
|
2523
|
-
return true;
|
|
2524
|
-
}
|
|
2525
|
-
static fromSchemaError(error, responseText) {
|
|
2526
|
-
return new StructuredOutputError({
|
|
2527
|
-
description: error.message,
|
|
2528
|
-
responseText
|
|
2529
|
-
});
|
|
2530
|
-
}
|
|
2531
|
-
get message() {
|
|
2532
|
-
return `Structured output validation failed: ${this.description}`;
|
|
2533
|
-
}
|
|
2534
|
-
};
|
|
2535
|
-
var UnsupportedSchemaError = class extends Error$1("effect/ai/AiError/UnsupportedSchemaError")({
|
|
2536
|
-
_tag: tag("UnsupportedSchemaError"),
|
|
2537
|
-
description: String$1,
|
|
2538
|
-
metadata: providerMetadataWithDefaults()
|
|
2539
|
-
}) {
|
|
2540
|
-
[ReasonTypeId] = ReasonTypeId;
|
|
2541
|
-
get isRetryable() {
|
|
2542
|
-
return false;
|
|
2543
|
-
}
|
|
2544
|
-
get message() {
|
|
2545
|
-
return `Unsupported schema: ${this.description}`;
|
|
2546
|
-
}
|
|
2547
|
-
};
|
|
2548
|
-
var UnknownError = class extends Error$1("effect/ai/AiError/UnknownError")({
|
|
2549
|
-
_tag: tag("UnknownError"),
|
|
2550
|
-
description: optional(String$1),
|
|
2551
|
-
metadata: providerMetadataWithDefaults(),
|
|
2552
|
-
http: optional(HttpContext)
|
|
2553
|
-
}) {
|
|
2554
|
-
[ReasonTypeId] = ReasonTypeId;
|
|
2555
|
-
get isRetryable() {
|
|
2556
|
-
return false;
|
|
2557
|
-
}
|
|
2558
|
-
get message() {
|
|
2559
|
-
return this.description ?? "Unknown error";
|
|
2560
|
-
}
|
|
2561
|
-
};
|
|
2562
|
-
var ToolNotFoundError = class extends Error$1("effect/ai/AiError/ToolNotFoundError")({
|
|
2563
|
-
_tag: tag("ToolNotFoundError"),
|
|
2564
|
-
toolName: String$1,
|
|
2565
|
-
availableTools: ArraySchema(String$1)
|
|
2566
|
-
}) {
|
|
2567
|
-
[ReasonTypeId] = ReasonTypeId;
|
|
2568
|
-
get isRetryable() {
|
|
2569
|
-
return true;
|
|
2570
|
-
}
|
|
2571
|
-
get message() {
|
|
2572
|
-
const availableTools = this.availableTools.length > 0 ? this.availableTools.join(", ") : "none";
|
|
2573
|
-
return `Tool '${this.toolName}' not found. Available tools: ${availableTools}`;
|
|
2574
|
-
}
|
|
2575
|
-
};
|
|
2576
|
-
var ToolParameterValidationError = class extends Error$1("effect/ai/AiError/ToolParameterValidationError")({
|
|
2577
|
-
_tag: tag("ToolParameterValidationError"),
|
|
2578
|
-
toolName: String$1,
|
|
2579
|
-
description: String$1
|
|
2580
|
-
}) {
|
|
2581
|
-
[ReasonTypeId] = ReasonTypeId;
|
|
2582
|
-
get isRetryable() {
|
|
2583
|
-
return true;
|
|
2584
|
-
}
|
|
2585
|
-
get message() {
|
|
2586
|
-
return `Invalid parameters for tool '${this.toolName}': ${this.description}`;
|
|
2587
|
-
}
|
|
2588
|
-
};
|
|
2589
|
-
var InvalidToolResultError = class extends Error$1("effect/ai/AiError/InvalidToolResultError")({
|
|
2590
|
-
_tag: tag("InvalidToolResultError"),
|
|
2591
|
-
toolName: String$1,
|
|
2592
|
-
description: String$1
|
|
2593
|
-
}) {
|
|
2594
|
-
[ReasonTypeId] = ReasonTypeId;
|
|
2595
|
-
get isRetryable() {
|
|
2596
|
-
return false;
|
|
2597
|
-
}
|
|
2598
|
-
get message() {
|
|
2599
|
-
return `Tool '${this.toolName}' returned invalid result: ${this.description}`;
|
|
2600
|
-
}
|
|
2601
|
-
};
|
|
2602
|
-
var ToolResultEncodingError = class extends Error$1("effect/ai/AiError/ToolResultEncodingError")({
|
|
2603
|
-
_tag: tag("ToolResultEncodingError"),
|
|
2604
|
-
toolName: String$1,
|
|
2605
|
-
toolResult: Unknown,
|
|
2606
|
-
description: String$1
|
|
2607
|
-
}) {
|
|
2608
|
-
[ReasonTypeId] = ReasonTypeId;
|
|
2609
|
-
get isRetryable() {
|
|
2610
|
-
return false;
|
|
2611
|
-
}
|
|
2612
|
-
get message() {
|
|
2613
|
-
return `Failed to encode result for tool '${this.toolName}': ${this.description}`;
|
|
2614
|
-
}
|
|
2615
|
-
};
|
|
2616
|
-
var ToolConfigurationError = class extends Error$1("effect/ai/AiError/ToolConfigurationError")({
|
|
2617
|
-
_tag: tag("ToolConfigurationError"),
|
|
2618
|
-
toolName: String$1,
|
|
2619
|
-
description: String$1
|
|
2620
|
-
}) {
|
|
2621
|
-
[ReasonTypeId] = ReasonTypeId;
|
|
2622
|
-
get isRetryable() {
|
|
2623
|
-
return false;
|
|
2624
|
-
}
|
|
2625
|
-
get message() {
|
|
2626
|
-
return `Invalid configuration for tool '${this.toolName}': ${this.description}`;
|
|
2627
|
-
}
|
|
2628
|
-
};
|
|
2629
|
-
var ToolkitRequiredError = class extends Error$1("effect/ai/AiError/ToolkitRequiredError")({
|
|
2630
|
-
_tag: tag("ToolkitRequiredError"),
|
|
2631
|
-
pendingApprovals: ArraySchema(String$1),
|
|
2632
|
-
description: optional(String$1)
|
|
2633
|
-
}) {
|
|
2634
|
-
[ReasonTypeId] = ReasonTypeId;
|
|
2635
|
-
get isRetryable() {
|
|
2636
|
-
return false;
|
|
2637
|
-
}
|
|
2638
|
-
get message() {
|
|
2639
|
-
return `Toolkit required to resolve pending tool approvals: ${this.pendingApprovals.join(", ")}`;
|
|
2640
|
-
}
|
|
2641
|
-
};
|
|
2642
|
-
var InvalidUserInputError = class extends Error$1("effect/ai/AiError/InvalidUserInputError")({
|
|
2643
|
-
_tag: tag("InvalidUserInputError"),
|
|
2644
|
-
description: String$1
|
|
2645
|
-
}) {
|
|
2646
|
-
[ReasonTypeId] = ReasonTypeId;
|
|
2647
|
-
get isRetryable() {
|
|
2648
|
-
return false;
|
|
2649
|
-
}
|
|
2650
|
-
get message() {
|
|
2651
|
-
return `Invalid user input: ${this.description}`;
|
|
2652
|
-
}
|
|
2653
|
-
};
|
|
2654
|
-
const AiErrorReason = Union([
|
|
2655
|
-
RateLimitError,
|
|
2656
|
-
QuotaExhaustedError,
|
|
2657
|
-
AuthenticationError,
|
|
2658
|
-
ContentPolicyError,
|
|
2659
|
-
InvalidRequestError,
|
|
2660
|
-
InvalidResponseError,
|
|
2661
|
-
InternalProviderError,
|
|
2662
|
-
NetworkError,
|
|
2663
|
-
InvalidOutputError,
|
|
2664
|
-
StructuredOutputError,
|
|
2665
|
-
UnsupportedSchemaError,
|
|
2666
|
-
UnknownError,
|
|
2667
|
-
ToolNotFoundError,
|
|
2668
|
-
ToolParameterValidationError,
|
|
2669
|
-
InvalidToolResultError,
|
|
2670
|
-
ToolResultEncodingError,
|
|
2671
|
-
ToolConfigurationError,
|
|
2672
|
-
ToolkitRequiredError,
|
|
2673
|
-
InvalidUserInputError
|
|
2674
|
-
]);
|
|
2675
|
-
const TypeId = "~effect/ai/AiError";
|
|
2676
|
-
var AiError = class extends Error$1("effect/ai/AiError/AiError")({
|
|
2677
|
-
_tag: tag("AiError"),
|
|
2678
|
-
module: String$1,
|
|
2679
|
-
method: String$1,
|
|
2680
|
-
reason: AiErrorReason
|
|
2681
|
-
}) {
|
|
2682
|
-
[TypeId] = TypeId;
|
|
2683
|
-
cause = this.reason;
|
|
2684
|
-
get isRetryable() {
|
|
2685
|
-
return this.reason.isRetryable;
|
|
2686
|
-
}
|
|
2687
|
-
get retryAfter() {
|
|
2688
|
-
return "retryAfter" in this.reason ? this.reason.retryAfter : void 0;
|
|
2689
|
-
}
|
|
2690
|
-
get message() {
|
|
2691
|
-
return `${this.module}.${this.method}: ${this.reason.message}`;
|
|
2692
|
-
}
|
|
2693
|
-
};
|
|
2694
|
-
const isAiError = (u) => hasProperty(u, TypeId);
|
|
2695
|
-
const isAiErrorReason = (u) => hasProperty(u, ReasonTypeId);
|
|
2696
|
-
const make = (params) => new AiError(params);
|
|
2697
|
-
const reasonFromHttpStatus = (params) => {
|
|
2698
|
-
const { status, http, metadata, description } = params;
|
|
2699
|
-
const common = {
|
|
2700
|
-
http,
|
|
2701
|
-
...metadata ? { metadata } : void 0,
|
|
2702
|
-
...description ? { description } : void 0
|
|
2703
|
-
};
|
|
2704
|
-
switch (status) {
|
|
2705
|
-
case 400: return new InvalidRequestError(common);
|
|
2706
|
-
case 401: return new AuthenticationError({
|
|
2707
|
-
kind: "InvalidKey",
|
|
2708
|
-
...common
|
|
2709
|
-
});
|
|
2710
|
-
case 403: return new AuthenticationError({
|
|
2711
|
-
kind: "InsufficientPermissions",
|
|
2712
|
-
...common
|
|
2713
|
-
});
|
|
2714
|
-
case 429: return new RateLimitError(common);
|
|
2715
|
-
default:
|
|
2716
|
-
if (status >= 500) return new InternalProviderError({
|
|
2717
|
-
description: "Server error",
|
|
2718
|
-
...common
|
|
2719
|
-
});
|
|
2720
|
-
return new UnknownError(common);
|
|
2721
|
-
}
|
|
2722
|
-
};
|
|
2723
|
-
export { fromPubSub as $, offerUnsafe as $t, catchTags as A, takeUntil as At, failCause as B, unwrap$1 as Bt, make as C, runIntoPubSub as Ct, catchCause as D, succeed as Dt, callback as E, splitLines as Et, drainFork as F, transduce as Ft, flattenArray as G, endUnsafe as Gt, filterMap as H, makeUnsafe as Ht, drop as I, unwrap as It, fromArrayEffect as J, failCauseUnsafe as Jt, flattenIterable as K, fail$2 as Kt, empty as L, fromTransform as Lt, concat as M, tap as Mt, decodeText as N, tapError as Nt, catchIf as O, suspend as Ot, die as P, toAsyncIterable as Pt, fromIterable as Q, offerAllUnsafe as Qt, ensuring as R, mapDone as Rt, isAiErrorReason as S, runForEachArray as St, broadcast as T, scoped as Tt, flatMap as U, bounded as Ut, filter as V, make$1 as Vt, flatten as W, end as Wt, fromChannel as X, offer as Xt, fromAsyncIterable as Y, make$2 as Yt, fromEffect as Z, offerAll as Zt, ToolkitRequiredError as _, toLowerCase as _n, run as _t, InvalidOutputError as a, unbounded$1 as an, mapArray as at, buildErrorDescription as b, runFold as bt, InvalidToolResultError as c, update as cn, mapError as ct, RateLimitError as d, interrupt as dn, mkString as dt, poll as en, fromPull as et, StructuredOutputError as f, interruptAll as fn, onExit as ft, ToolResultEncodingError as g, camelToSnake as gn, provideService as gt, ToolParameterValidationError as h, runIn as hn, provideContext as ht, InternalProviderError as i, unbounded as in, map as it, catch_ as j, takeWhile as jt, catchReason as k, take as kt, NetworkError as l, await_ as ln, merge as lt, ToolNotFoundError as m, join as mn, pipeThroughChannel as mt, AuthenticationError as n, sliding as nn, fromReadableStream as nt, InvalidRequestError as o, make$5 as on, mapArrayEffect as ot, ToolConfigurationError as p, interruptAllAs as pn, orDie as pt, fromArray as q, failCause$2 as qt, HttpResponseDetails as r, take$1 as rn, isStream as rt, InvalidResponseError as s, set as sn, mapEffect as st, AiError as t, shutdownUnsafe as tn, fromQueue as tt, QuotaExhaustedError as u, getCurrent as un, mergeAll as ut, UnknownError as v, runCollect as vt, reasonFromHttpStatus as w, runLast as wt, isAiError as x, runForEach as xt, UnsupportedSchemaError as y, runDrain as yt, fail as z, toTransform as zt };
|