clanka 0.7.3 → 0.7.5

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.
Files changed (50) hide show
  1. package/dist/Acp.d.ts +10 -0
  2. package/dist/Acp.d.ts.map +1 -1
  3. package/dist/Acp.js +1 -2
  4. package/dist/Acp.js.map +1 -1
  5. package/dist/AgentTools.d.ts.map +1 -1
  6. package/dist/AgentTools.js +1 -2
  7. package/dist/AgentTools.js.map +1 -1
  8. package/dist/GlobalWebSocket.d.ts +15 -0
  9. package/dist/GlobalWebSocket.d.ts.map +1 -0
  10. package/dist/GlobalWebSocket.js +26 -0
  11. package/dist/GlobalWebSocket.js.map +1 -0
  12. package/dist/WebToMarkdown.d.ts.map +1 -1
  13. package/dist/WebToMarkdown.js +8 -4
  14. package/dist/WebToMarkdown.js.map +1 -1
  15. package/dist/bin/Effect-DdkIoNCD.mjs +5058 -0
  16. package/dist/bin/Effect-DdkIoNCD.mjs.map +1 -0
  17. package/dist/bin/{McpClient-D6vFD-wP.mjs → McpClient-CJ0Vugoi.mjs} +582 -2896
  18. package/dist/bin/{McpClient-D6vFD-wP.mjs.map → McpClient-CJ0Vugoi.mjs.map} +1 -1
  19. package/dist/bin/OutputFormatter-DN8OGwuK.mjs +575 -0
  20. package/dist/bin/OutputFormatter-DN8OGwuK.mjs.map +1 -0
  21. package/dist/bin/Schema-BALIXGp7.mjs +5475 -0
  22. package/dist/bin/Schema-BALIXGp7.mjs.map +1 -0
  23. package/dist/bin/{SemanticSearch-D9iZ_Mi9.mjs → SemanticSearch-O6PZBRfd.mjs} +147 -1160
  24. package/dist/bin/{SemanticSearch-D9iZ_Mi9.mjs.map → SemanticSearch-O6PZBRfd.mjs.map} +1 -1
  25. package/dist/bin/Stream-B5ebASRi.mjs +2090 -0
  26. package/dist/bin/Stream-B5ebASRi.mjs.map +1 -0
  27. package/dist/bin/cli.mjs +9629 -41431
  28. package/dist/bin/cli.mjs.map +1 -1
  29. package/dist/bin/index.min-CI3qqohw.mjs +3300 -0
  30. package/dist/bin/index.min-CI3qqohw.mjs.map +1 -0
  31. package/dist/bin/turndown.cjs-usmCKZ4b.mjs +15195 -0
  32. package/dist/bin/turndown.cjs-usmCKZ4b.mjs.map +1 -0
  33. package/dist/cli.d.ts +1 -1
  34. package/dist/cli.js +10 -6
  35. package/dist/cli.js.map +1 -1
  36. package/dist/index.d.ts +4 -0
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +4 -0
  39. package/dist/index.js.map +1 -1
  40. package/package.json +2 -4
  41. package/src/Acp.ts +1 -2
  42. package/src/AgentTools.ts +3 -2
  43. package/src/GlobalWebSocket.ts +40 -0
  44. package/src/WebToMarkdown.ts +17 -7
  45. package/src/cli.ts +15 -6
  46. package/src/index.ts +5 -0
  47. package/dist/bin/Schema-D6y3R-At.mjs +0 -28728
  48. package/dist/bin/Schema-D6y3R-At.mjs.map +0 -1
  49. package/dist/bin/Undici-ChB4UBDa.mjs +0 -28
  50. package/dist/bin/Undici-ChB4UBDa.mjs.map +0 -1
@@ -0,0 +1,2090 @@
1
+ import { $r as exitVoid, A as ensuring$2, Ao as exitSucceed, As as identity, B as fnUntraced, Br as void_$2, C as catch_$2, Ci as suspend$3, Cn as isDoneCause, Co as Done, Ct as promise, Di as void_$1, Do as causeFail, Dr as interruptWith, Ds as constant, Dt as raceFirst, E as contextWith, Er as doneUnsafe, Es as constVoid, Et as provideService$2, Fr as interrupt$1, Fs as pipeArguments, G as forkIn, Gr as asSome, Gt as tap$1, H as forEach, I as flatMap$2, Ir as isExit, Ji as isArrayNonEmpty, K as forkScoped, Ki as fromIterable$1, Kr as callback$1, L as flatMapEager, Ln as findError, M as fail$3, N as failCause$2, Nn as die$2, Nr as fail$5, Nt as runForkWith, Oo as exitFail, Os as dual, Pa as get$1, Pn as done, Pr as failCause$3, Qr as exitInterrupt$1, Qt as uninterruptible, R as flatten$1, Ro as toJson, Rr as isSuccess, Rt as scopedWith, Si as succeedNone, Sn as filterDone, T as context, Ti as uninterruptibleMask, To as PipeInspectableProto, Tt as provideContext$2, U as forever, Ut as suspend$2, Vt as succeed$2, W as forkChild, Wr as andThen$1, Wt as sync, Xi as isReadonlyArrayNonEmpty, Y as gen, Yt as tryPromise, Z as interrupt$2, _r as forkUnsafe, _t as onExit$1, a as andThen, ai as fiberInterruptAs, an as whileLoop, bi as scopeFinalizerCountUnsafe, bn as catchDone, br as provide, c as as, ci as flatMap$3, da as isFailure, ea as map$3, ei as exitZipRight, fa as isSuccess$1, gr as close, gt as onError, hr as addFinalizerExit, ht as never, ii as fiberInterruptAllAs, in as when, j as exit, jo as withFiber$1, jr as makeUnsafe$3, ko as exitFailCause, lo as some, m as catchCause$1, ma as succeed$5, mi as makeLatchUnsafe, mr as addFinalizer, na as of, ni as fiberInterrupt, ns as hasProperty, oa as headUnsafe, oi as fiberJoin, on as withFiber, oo as none, ot as map$2, pi as makeLatch, pr as Scope, pt as matchCauseEffect, ri as fiberInterruptAll, rn as void_, sa as fail$4, si as fiberRunIn, t as acquireRelease, ti as fiberAwait, u as asVoid, ui as getCurrentFiber, un as yieldNow, vi as onExitPrimitive, vs as isString$1, wi as sync$1, wn as matchEffect, wr as _await, ws as constTrue, xi as succeed$4, xn as doneExitFromCause, yr as makeUnsafe$2, ys as isTagged, yt as onInterrupt, zr as succeed$3 } from "./Effect-DdkIoNCD.mjs";
2
+ //#region node_modules/.pnpm/effect@4.0.0-rc.115/node_modules/effect/dist/internal/count.js
3
+ const normalize = (n) => n > 0 ? Math.floor(n) : 0;
4
+ const normalizeNonEmpty = (n) => Math.max(1, normalize(n));
5
+ //#endregion
6
+ //#region node_modules/.pnpm/effect@4.0.0-rc.115/node_modules/effect/dist/Number.js
7
+ const Number$1 = globalThis.Number;
8
+ const nextPow2 = (n) => {
9
+ const nextPow = Math.ceil(Math.log(n) / Math.log(2));
10
+ return Math.max(Math.pow(2, nextPow), 2);
11
+ };
12
+ const parse = (s) => {
13
+ if (s === "NaN") return some(NaN);
14
+ if (s === "Infinity") return some(Infinity);
15
+ if (s === "-Infinity") return some(-Infinity);
16
+ if (s.trim() === "") return none();
17
+ const n = Number$1(s);
18
+ return Number$1.isNaN(n) ? none() : some(n);
19
+ };
20
+ const round = dual(2, (self, precision) => {
21
+ const factor = Math.pow(10, precision);
22
+ return Math.round(self * factor) / factor;
23
+ });
24
+ //#endregion
25
+ //#region node_modules/.pnpm/effect@4.0.0-rc.115/node_modules/effect/dist/String.js
26
+ const String = globalThis.String;
27
+ const isString = isString$1;
28
+ const toLowerCase = (self) => self.toLowerCase();
29
+ const camelToSnake = (self) => self.replace(/([A-Z])/g, "_$1").toLowerCase();
30
+ //#endregion
31
+ //#region node_modules/.pnpm/effect@4.0.0-rc.115/node_modules/effect/dist/Fiber.js
32
+ const await_ = fiberAwait;
33
+ const join = fiberJoin;
34
+ const interrupt = fiberInterrupt;
35
+ const interruptAs = fiberInterruptAs;
36
+ const interruptAll = fiberInterruptAll;
37
+ const interruptAllAs = fiberInterruptAllAs;
38
+ const getCurrent = getCurrentFiber;
39
+ const runIn = fiberRunIn;
40
+ //#endregion
41
+ //#region node_modules/.pnpm/effect@4.0.0-rc.115/node_modules/effect/dist/Latch.js
42
+ const makeUnsafe$1 = makeLatchUnsafe;
43
+ const make$5 = makeLatch;
44
+ //#endregion
45
+ //#region node_modules/.pnpm/effect@4.0.0-rc.115/node_modules/effect/dist/MutableRef.js
46
+ const TypeId$5 = "~effect/MutableRef";
47
+ const MutableRefProto = {
48
+ [TypeId$5]: TypeId$5,
49
+ ...PipeInspectableProto,
50
+ toJSON() {
51
+ return {
52
+ _id: "MutableRef",
53
+ current: toJson(this.current)
54
+ };
55
+ }
56
+ };
57
+ const make$4 = (value) => {
58
+ const ref = Object.create(MutableRefProto);
59
+ ref.current = value;
60
+ return ref;
61
+ };
62
+ const get = (self) => self.current;
63
+ const set = dual(2, (self, value) => {
64
+ self.current = value;
65
+ return self;
66
+ });
67
+ const update = dual(2, (self, f) => set(self, f(get(self))));
68
+ //#endregion
69
+ //#region node_modules/.pnpm/effect@4.0.0-rc.115/node_modules/effect/dist/MutableList.js
70
+ const Empty = Symbol.for("effect/MutableList/Empty");
71
+ const make$3 = () => ({
72
+ head: void 0,
73
+ tail: void 0,
74
+ length: 0
75
+ });
76
+ const emptyBucket = () => ({
77
+ array: [],
78
+ mutable: true,
79
+ offset: 0,
80
+ next: void 0
81
+ });
82
+ const append = (self, message) => {
83
+ if (!self.tail) self.head = self.tail = emptyBucket();
84
+ else if (!self.tail.mutable) {
85
+ self.tail.next = emptyBucket();
86
+ self.tail = self.tail.next;
87
+ }
88
+ self.tail.array.push(message);
89
+ self.length++;
90
+ };
91
+ const prepend = (self, message) => {
92
+ self.head = {
93
+ array: [message],
94
+ mutable: true,
95
+ offset: 0,
96
+ next: self.head
97
+ };
98
+ if (!self.tail) self.tail = self.head;
99
+ self.length++;
100
+ };
101
+ const appendAll = (self, messages) => appendAllUnsafe(self, fromIterable$1(messages), !Array.isArray(messages));
102
+ const appendAllUnsafe = (self, messages, mutable = false) => {
103
+ if (messages.length === 0) return 0;
104
+ const chunk = {
105
+ array: messages,
106
+ mutable,
107
+ offset: 0,
108
+ next: void 0
109
+ };
110
+ if (self.head) self.tail = self.tail.next = chunk;
111
+ else self.head = self.tail = chunk;
112
+ self.length += messages.length;
113
+ return messages.length;
114
+ };
115
+ const clear = (self) => {
116
+ self.head = self.tail = void 0;
117
+ self.length = 0;
118
+ };
119
+ const takeN = (self, n) => {
120
+ n = normalize(n);
121
+ if (n <= 0 || !self.head) return [];
122
+ n = Math.min(n, self.length);
123
+ if (n === self.length && self.head?.offset === 0 && !self.head.next) {
124
+ const array = self.head.array;
125
+ clear(self);
126
+ return array;
127
+ }
128
+ const array = new Array(n);
129
+ let index = 0;
130
+ let chunk = self.head;
131
+ while (chunk) {
132
+ while (chunk.offset < chunk.array.length) {
133
+ array[index++] = chunk.array[chunk.offset];
134
+ if (chunk.mutable) chunk.array[chunk.offset] = void 0;
135
+ chunk.offset++;
136
+ if (index === n) {
137
+ self.head = chunk;
138
+ self.length -= n;
139
+ if (self.length === 0) clear(self);
140
+ return array;
141
+ }
142
+ }
143
+ chunk = chunk.next;
144
+ }
145
+ clear(self);
146
+ return array;
147
+ };
148
+ const takeAll$2 = (self) => takeN(self, self.length);
149
+ const take$3 = (self) => {
150
+ if (!self.head) return Empty;
151
+ const message = self.head.array[self.head.offset];
152
+ if (self.head.mutable) self.head.array[self.head.offset] = void 0;
153
+ self.head.offset++;
154
+ self.length--;
155
+ if (self.head.offset === self.head.array.length) {
156
+ if (self.head.next) self.head = self.head.next;
157
+ else clear(self);
158
+ }
159
+ return message;
160
+ };
161
+ const filter$1 = (self, f) => {
162
+ const array = [];
163
+ let chunk = self.head;
164
+ while (chunk) {
165
+ for (let i = chunk.offset; i < chunk.array.length; i++) if (f(chunk.array[i], i)) array.push(chunk.array[i]);
166
+ chunk = chunk.next;
167
+ }
168
+ if (array.length === 0) {
169
+ clear(self);
170
+ return;
171
+ }
172
+ self.head = self.tail = {
173
+ array,
174
+ mutable: true,
175
+ offset: 0,
176
+ next: void 0
177
+ };
178
+ self.length = array.length;
179
+ };
180
+ const remove = (self, value) => filter$1(self, (v) => v !== value);
181
+ //#endregion
182
+ //#region node_modules/.pnpm/effect@4.0.0-rc.115/node_modules/effect/dist/PubSub.js
183
+ const TypeId$4 = "~effect/PubSub";
184
+ const SubscriptionTypeId = "~effect/PubSub/Subscription";
185
+ const make$2 = (options) => sync(() => makePubSubUnsafe(options.atomicPubSub(), new Map(), makeUnsafe$2(), makeUnsafe$1(false), make$4(false), options.strategy()));
186
+ const bounded$1 = (capacity) => make$2({
187
+ atomicPubSub: () => makeAtomicBounded(capacity),
188
+ strategy: () => new BackPressureStrategy()
189
+ });
190
+ const dropping = (capacity) => make$2({
191
+ atomicPubSub: () => makeAtomicBounded(capacity),
192
+ strategy: () => new DroppingStrategy()
193
+ });
194
+ const sliding = (capacity) => make$2({
195
+ atomicPubSub: () => makeAtomicBounded(capacity),
196
+ strategy: () => new SlidingStrategy()
197
+ });
198
+ const unbounded$1 = (options) => make$2({
199
+ atomicPubSub: () => makeAtomicUnbounded(options),
200
+ strategy: () => new DroppingStrategy()
201
+ });
202
+ const makeAtomicBounded = (capacity) => {
203
+ const options = typeof capacity === "number" ? { capacity } : capacity;
204
+ ensureCapacity(options.capacity);
205
+ const replayBuffer = options.replay && options.replay > 0 ? new ReplayBuffer(Math.ceil(options.replay)) : void 0;
206
+ if (options.capacity === 1) return new BoundedPubSubSingle(replayBuffer);
207
+ else if (nextPow2(options.capacity) === options.capacity) return new BoundedPubSubPow2(options.capacity, replayBuffer);
208
+ else return new BoundedPubSubArb(options.capacity, replayBuffer);
209
+ };
210
+ const makeAtomicUnbounded = (options) => {
211
+ const replay = options?.replay;
212
+ return new UnboundedPubSub(replay && replay > 0 ? new ReplayBuffer(Math.ceil(replay)) : void 0);
213
+ };
214
+ const shutdown$1 = (self) => uninterruptible(withFiber((fiber) => {
215
+ set(self.shutdownFlag, true);
216
+ return close(self.scope, interrupt$1(fiber.id)).pipe(andThen(self.strategy.shutdown), when(self.shutdownHook.open), asVoid);
217
+ }));
218
+ const publish = dual(2, (self, value) => suspend$2(() => {
219
+ if (self.shutdownFlag.current) return succeed$2(false);
220
+ if (self.pubsub.publish(value)) {
221
+ self.strategy.completeSubscribersUnsafe(self.pubsub, self.subscribers);
222
+ return succeed$2(true);
223
+ }
224
+ return self.strategy.handleSurplus(self.pubsub, self.subscribers, [value], self.shutdownFlag);
225
+ }));
226
+ const publishAll = dual(2, (self, elements) => suspend$2(() => {
227
+ if (self.shutdownFlag.current) return succeed$2(false);
228
+ const surplus = self.pubsub.publishAll(elements);
229
+ self.strategy.completeSubscribersUnsafe(self.pubsub, self.subscribers);
230
+ if (surplus.length === 0) return succeed$2(true);
231
+ return self.strategy.handleSurplus(self.pubsub, self.subscribers, surplus, self.shutdownFlag);
232
+ }));
233
+ const subscribe = (self) => uninterruptible(contextWith((services) => {
234
+ const localScope = get$1(services, Scope);
235
+ const scope = forkUnsafe(self.scope);
236
+ const subscription = makeSubscriptionUnsafe(self.pubsub, self.subscribers, self.strategy);
237
+ return addFinalizer(scope, unsubscribe(subscription)).pipe(andThen(addFinalizerExit(localScope, (exit) => close(scope, exit))), as(subscription));
238
+ }));
239
+ const unsubscribe = (self) => uninterruptible(withFiber((state) => {
240
+ set(self.shutdownFlag, true);
241
+ return forEach(takeAll$2(self.pollers), (d) => interruptWith(d, state.id), {
242
+ discard: true,
243
+ concurrency: "unbounded"
244
+ }).pipe(tap$1(() => sync(() => {
245
+ self.subscribers.delete(self.subscription);
246
+ self.subscription.unsubscribe();
247
+ self.replayWindow.close();
248
+ self.strategy.onPubSubEmptySpaceUnsafe(self.pubsub, self.subscribers);
249
+ })), when(self.shutdownHook.open), asVoid);
250
+ }));
251
+ const take$2 = (self) => suspend$2(() => {
252
+ if (self.shutdownFlag.current) return interrupt$2;
253
+ if (self.replayWindow.remaining > 0) {
254
+ const message = self.replayWindow.take();
255
+ return succeed$2(message);
256
+ }
257
+ const message = self.pollers.length === 0 ? self.subscription.poll() : Empty;
258
+ if (message === Empty) return pollForItem(self);
259
+ else {
260
+ self.strategy.onPubSubEmptySpaceUnsafe(self.pubsub, self.subscribers);
261
+ return succeed$2(message);
262
+ }
263
+ });
264
+ const takeAll$1 = (self) => suspend$2(function loop(value) {
265
+ if (self.shutdownFlag.current) return interrupt$2;
266
+ let as = self.pollers.length === 0 ? self.subscription.pollUpTo(Number.POSITIVE_INFINITY) : [];
267
+ if (value) as = value.concat(as);
268
+ self.strategy.onPubSubEmptySpaceUnsafe(self.pubsub, self.subscribers);
269
+ if (self.replayWindow.remaining > 0) return succeed$2(self.replayWindow.takeAll().concat(as));
270
+ else if (!isArrayNonEmpty(as)) return flatMap$2(pollForItem(self), (item) => loop([item]));
271
+ return succeed$2(as);
272
+ });
273
+ const pollForItem = (self) => {
274
+ const deferred = makeUnsafe$3();
275
+ let set = self.subscribers.get(self.subscription);
276
+ if (!set) {
277
+ set = new Set();
278
+ self.subscribers.set(self.subscription, set);
279
+ }
280
+ set.add(self.pollers);
281
+ append(self.pollers, deferred);
282
+ self.strategy.completePollersUnsafe(self.pubsub, self.subscribers, self.subscription, self.pollers);
283
+ return onInterrupt(_await(deferred), () => {
284
+ remove(self.pollers, deferred);
285
+ return void_;
286
+ });
287
+ };
288
+ const AbsentValue = Symbol.for("effect/PubSub/AbsentValue");
289
+ const addSubscribers = (subscribers, subscription, pollers) => {
290
+ if (!subscribers.has(subscription)) subscribers.set(subscription, new Set());
291
+ subscribers.get(subscription).add(pollers);
292
+ };
293
+ const removeSubscribers = (subscribers, subscription, pollers) => {
294
+ if (!subscribers.has(subscription)) return;
295
+ const set = subscribers.get(subscription);
296
+ set.delete(pollers);
297
+ if (set.size === 0) subscribers.delete(subscription);
298
+ };
299
+ const makeSubscriptionUnsafe = (pubsub, subscribers, strategy) => new SubscriptionImpl(pubsub, subscribers, pubsub.subscribe(), make$3(), makeUnsafe$1(false), make$4(false), strategy, pubsub.replayWindow());
300
+ var BoundedPubSubArb = class {
301
+ array;
302
+ replayIndices;
303
+ publisherIndex = 0;
304
+ subscribers;
305
+ subscriberCount = 0;
306
+ subscribersIndex = 0;
307
+ capacity;
308
+ replayBuffer;
309
+ constructor(capacity, replayBuffer) {
310
+ this.capacity = capacity;
311
+ this.replayBuffer = replayBuffer;
312
+ this.array = Array.from({ length: capacity });
313
+ this.replayIndices = replayBuffer ? Array.from({ length: capacity }) : [];
314
+ this.subscribers = Array.from({ length: capacity });
315
+ }
316
+ replayWindow() {
317
+ return this.replayBuffer ? new ReplayWindowImpl(this.replayBuffer) : emptyReplayWindow;
318
+ }
319
+ isEmpty() {
320
+ return this.publisherIndex === this.subscribersIndex;
321
+ }
322
+ isFull() {
323
+ return this.publisherIndex === this.subscribersIndex + this.capacity;
324
+ }
325
+ size() {
326
+ return this.publisherIndex - this.subscribersIndex;
327
+ }
328
+ publish(value) {
329
+ if (this.isFull()) return false;
330
+ const replayIndex = this.replayBuffer?.offer(value);
331
+ if (this.subscriberCount !== 0) {
332
+ const index = this.publisherIndex % this.capacity;
333
+ this.array[index] = value;
334
+ if (replayIndex !== void 0) this.replayIndices[index] = replayIndex;
335
+ this.subscribers[index] = this.subscriberCount;
336
+ this.publisherIndex += 1;
337
+ }
338
+ return true;
339
+ }
340
+ publishAll(elements) {
341
+ if (this.subscriberCount === 0) {
342
+ if (this.replayBuffer) this.replayBuffer.offerAll(elements);
343
+ return [];
344
+ }
345
+ const chunk = fromIterable$1(elements);
346
+ const n = chunk.length;
347
+ const size = this.publisherIndex - this.subscribersIndex;
348
+ const available = this.capacity - size;
349
+ const forPubSub = Math.min(n, available);
350
+ if (forPubSub === 0) return chunk;
351
+ let iteratorIndex = 0;
352
+ const publishAllIndex = this.publisherIndex + forPubSub;
353
+ while (this.publisherIndex !== publishAllIndex) {
354
+ const a = chunk[iteratorIndex++];
355
+ const index = this.publisherIndex % this.capacity;
356
+ this.array[index] = a;
357
+ const replayIndex = this.replayBuffer?.offer(a);
358
+ if (replayIndex !== void 0) this.replayIndices[index] = replayIndex;
359
+ this.subscribers[index] = this.subscriberCount;
360
+ this.publisherIndex += 1;
361
+ }
362
+ return chunk.slice(iteratorIndex);
363
+ }
364
+ slide() {
365
+ if (this.subscribersIndex !== this.publisherIndex) {
366
+ const index = this.subscribersIndex % this.capacity;
367
+ const value = this.array[index];
368
+ this.array[index] = AbsentValue;
369
+ this.subscribers[index] = 0;
370
+ this.subscribersIndex += 1;
371
+ this.replayBuffer?.slide(value, this.replayIndices[index]);
372
+ }
373
+ }
374
+ subscribe() {
375
+ this.subscriberCount += 1;
376
+ return new BoundedPubSubArbSubscription(this, this.publisherIndex, false);
377
+ }
378
+ };
379
+ var BoundedPubSubArbSubscription = class {
380
+ self;
381
+ subscriberIndex;
382
+ unsubscribed;
383
+ constructor(self, subscriberIndex, unsubscribed) {
384
+ this.self = self;
385
+ this.subscriberIndex = subscriberIndex;
386
+ this.unsubscribed = unsubscribed;
387
+ }
388
+ isEmpty() {
389
+ return this.unsubscribed || this.self.publisherIndex === this.subscriberIndex || this.self.publisherIndex === this.self.subscribersIndex;
390
+ }
391
+ size() {
392
+ if (this.unsubscribed) return 0;
393
+ return this.self.publisherIndex - Math.max(this.subscriberIndex, this.self.subscribersIndex);
394
+ }
395
+ poll() {
396
+ if (this.unsubscribed) return Empty;
397
+ this.subscriberIndex = Math.max(this.subscriberIndex, this.self.subscribersIndex);
398
+ if (this.subscriberIndex !== this.self.publisherIndex) {
399
+ const index = this.subscriberIndex % this.self.capacity;
400
+ const elem = this.self.array[index];
401
+ this.self.subscribers[index] -= 1;
402
+ if (this.self.subscribers[index] === 0) {
403
+ this.self.array[index] = AbsentValue;
404
+ this.self.subscribersIndex += 1;
405
+ }
406
+ this.subscriberIndex += 1;
407
+ return elem;
408
+ }
409
+ return Empty;
410
+ }
411
+ pollUpTo(n) {
412
+ n = normalize(n);
413
+ if (this.unsubscribed) return [];
414
+ this.subscriberIndex = Math.max(this.subscriberIndex, this.self.subscribersIndex);
415
+ const size = this.self.publisherIndex - this.subscriberIndex;
416
+ const toPoll = Math.min(n, size);
417
+ if (toPoll <= 0) return [];
418
+ const builder = [];
419
+ const pollUpToIndex = this.subscriberIndex + toPoll;
420
+ while (this.subscriberIndex !== pollUpToIndex) {
421
+ const index = this.subscriberIndex % this.self.capacity;
422
+ const a = this.self.array[index];
423
+ this.self.subscribers[index] -= 1;
424
+ if (this.self.subscribers[index] === 0) {
425
+ this.self.array[index] = AbsentValue;
426
+ this.self.subscribersIndex += 1;
427
+ }
428
+ builder.push(a);
429
+ this.subscriberIndex += 1;
430
+ }
431
+ return builder;
432
+ }
433
+ unsubscribe() {
434
+ if (!this.unsubscribed) {
435
+ this.unsubscribed = true;
436
+ this.self.subscriberCount -= 1;
437
+ this.subscriberIndex = Math.max(this.subscriberIndex, this.self.subscribersIndex);
438
+ while (this.subscriberIndex !== this.self.publisherIndex) {
439
+ const index = this.subscriberIndex % this.self.capacity;
440
+ this.self.subscribers[index] -= 1;
441
+ if (this.self.subscribers[index] === 0) {
442
+ this.self.array[index] = AbsentValue;
443
+ this.self.subscribersIndex += 1;
444
+ }
445
+ this.subscriberIndex += 1;
446
+ }
447
+ }
448
+ }
449
+ };
450
+ var BoundedPubSubPow2 = class {
451
+ array;
452
+ replayIndices;
453
+ mask;
454
+ publisherIndex = 0;
455
+ subscribers;
456
+ subscriberCount = 0;
457
+ subscribersIndex = 0;
458
+ capacity;
459
+ replayBuffer;
460
+ constructor(capacity, replayBuffer) {
461
+ this.capacity = capacity;
462
+ this.replayBuffer = replayBuffer;
463
+ this.array = Array.from({ length: capacity });
464
+ this.replayIndices = replayBuffer ? Array.from({ length: capacity }) : [];
465
+ this.mask = capacity - 1;
466
+ this.subscribers = Array.from({ length: capacity });
467
+ }
468
+ replayWindow() {
469
+ return this.replayBuffer ? new ReplayWindowImpl(this.replayBuffer) : emptyReplayWindow;
470
+ }
471
+ isEmpty() {
472
+ return this.publisherIndex === this.subscribersIndex;
473
+ }
474
+ isFull() {
475
+ return this.publisherIndex === this.subscribersIndex + this.capacity;
476
+ }
477
+ size() {
478
+ return this.publisherIndex - this.subscribersIndex;
479
+ }
480
+ publish(value) {
481
+ if (this.isFull()) return false;
482
+ const replayIndex = this.replayBuffer?.offer(value);
483
+ if (this.subscriberCount !== 0) {
484
+ const index = this.publisherIndex & this.mask;
485
+ this.array[index] = value;
486
+ if (replayIndex !== void 0) this.replayIndices[index] = replayIndex;
487
+ this.subscribers[index] = this.subscriberCount;
488
+ this.publisherIndex += 1;
489
+ }
490
+ return true;
491
+ }
492
+ publishAll(elements) {
493
+ if (this.subscriberCount === 0) {
494
+ if (this.replayBuffer) this.replayBuffer.offerAll(elements);
495
+ return [];
496
+ }
497
+ const chunk = fromIterable$1(elements);
498
+ const n = chunk.length;
499
+ const size = this.publisherIndex - this.subscribersIndex;
500
+ const available = this.capacity - size;
501
+ const forPubSub = Math.min(n, available);
502
+ if (forPubSub === 0) return chunk;
503
+ let iteratorIndex = 0;
504
+ const publishAllIndex = this.publisherIndex + forPubSub;
505
+ while (this.publisherIndex !== publishAllIndex) {
506
+ const elem = chunk[iteratorIndex++];
507
+ const index = this.publisherIndex & this.mask;
508
+ this.array[index] = elem;
509
+ const replayIndex = this.replayBuffer?.offer(elem);
510
+ if (replayIndex !== void 0) this.replayIndices[index] = replayIndex;
511
+ this.subscribers[index] = this.subscriberCount;
512
+ this.publisherIndex += 1;
513
+ }
514
+ return chunk.slice(iteratorIndex);
515
+ }
516
+ slide() {
517
+ if (this.subscribersIndex !== this.publisherIndex) {
518
+ const index = this.subscribersIndex & this.mask;
519
+ const value = this.array[index];
520
+ this.array[index] = AbsentValue;
521
+ this.subscribers[index] = 0;
522
+ this.subscribersIndex += 1;
523
+ this.replayBuffer?.slide(value, this.replayIndices[index]);
524
+ }
525
+ }
526
+ subscribe() {
527
+ this.subscriberCount += 1;
528
+ return new BoundedPubSubPow2Subscription(this, this.publisherIndex, false);
529
+ }
530
+ };
531
+ var BoundedPubSubPow2Subscription = class {
532
+ self;
533
+ subscriberIndex;
534
+ unsubscribed;
535
+ constructor(self, subscriberIndex, unsubscribed) {
536
+ this.self = self;
537
+ this.subscriberIndex = subscriberIndex;
538
+ this.unsubscribed = unsubscribed;
539
+ }
540
+ isEmpty() {
541
+ return this.unsubscribed || this.self.publisherIndex === this.subscriberIndex || this.self.publisherIndex === this.self.subscribersIndex;
542
+ }
543
+ size() {
544
+ if (this.unsubscribed) return 0;
545
+ return this.self.publisherIndex - Math.max(this.subscriberIndex, this.self.subscribersIndex);
546
+ }
547
+ poll() {
548
+ if (this.unsubscribed) return Empty;
549
+ this.subscriberIndex = Math.max(this.subscriberIndex, this.self.subscribersIndex);
550
+ if (this.subscriberIndex !== this.self.publisherIndex) {
551
+ const index = this.subscriberIndex & this.self.mask;
552
+ const elem = this.self.array[index];
553
+ this.self.subscribers[index] -= 1;
554
+ if (this.self.subscribers[index] === 0) {
555
+ this.self.array[index] = AbsentValue;
556
+ this.self.subscribersIndex += 1;
557
+ }
558
+ this.subscriberIndex += 1;
559
+ return elem;
560
+ }
561
+ return Empty;
562
+ }
563
+ pollUpTo(n) {
564
+ n = normalize(n);
565
+ if (this.unsubscribed) return [];
566
+ this.subscriberIndex = Math.max(this.subscriberIndex, this.self.subscribersIndex);
567
+ const size = this.self.publisherIndex - this.subscriberIndex;
568
+ const toPoll = Math.min(n, size);
569
+ if (toPoll <= 0) return [];
570
+ const builder = [];
571
+ const pollUpToIndex = this.subscriberIndex + toPoll;
572
+ while (this.subscriberIndex !== pollUpToIndex) {
573
+ const index = this.subscriberIndex & this.self.mask;
574
+ const elem = this.self.array[index];
575
+ this.self.subscribers[index] -= 1;
576
+ if (this.self.subscribers[index] === 0) {
577
+ this.self.array[index] = AbsentValue;
578
+ this.self.subscribersIndex += 1;
579
+ }
580
+ builder.push(elem);
581
+ this.subscriberIndex += 1;
582
+ }
583
+ return builder;
584
+ }
585
+ unsubscribe() {
586
+ if (!this.unsubscribed) {
587
+ this.unsubscribed = true;
588
+ this.self.subscriberCount -= 1;
589
+ this.subscriberIndex = Math.max(this.subscriberIndex, this.self.subscribersIndex);
590
+ while (this.subscriberIndex !== this.self.publisherIndex) {
591
+ const index = this.subscriberIndex & this.self.mask;
592
+ this.self.subscribers[index] -= 1;
593
+ if (this.self.subscribers[index] === 0) {
594
+ this.self.array[index] = AbsentValue;
595
+ this.self.subscribersIndex += 1;
596
+ }
597
+ this.subscriberIndex += 1;
598
+ }
599
+ }
600
+ }
601
+ };
602
+ var BoundedPubSubSingle = class {
603
+ publisherIndex = 0;
604
+ subscriberCount = 0;
605
+ subscribers = 0;
606
+ value = AbsentValue;
607
+ replayIndex = 0;
608
+ capacity = 1;
609
+ replayBuffer;
610
+ constructor(replayBuffer) {
611
+ this.replayBuffer = replayBuffer;
612
+ }
613
+ replayWindow() {
614
+ return this.replayBuffer ? new ReplayWindowImpl(this.replayBuffer) : emptyReplayWindow;
615
+ }
616
+ pipe() {
617
+ return pipeArguments(this, arguments);
618
+ }
619
+ isEmpty() {
620
+ return this.subscribers === 0;
621
+ }
622
+ isFull() {
623
+ return !this.isEmpty();
624
+ }
625
+ size() {
626
+ return this.isEmpty() ? 0 : 1;
627
+ }
628
+ publish(value) {
629
+ if (this.isFull()) return false;
630
+ const replayIndex = this.replayBuffer?.offer(value);
631
+ if (this.subscriberCount !== 0) {
632
+ this.value = value;
633
+ if (replayIndex !== void 0) this.replayIndex = replayIndex;
634
+ this.subscribers = this.subscriberCount;
635
+ this.publisherIndex += 1;
636
+ }
637
+ return true;
638
+ }
639
+ publishAll(elements) {
640
+ if (this.subscriberCount === 0) {
641
+ if (this.replayBuffer) this.replayBuffer.offerAll(elements);
642
+ return [];
643
+ }
644
+ const chunk = fromIterable$1(elements);
645
+ if (chunk.length === 0) return chunk;
646
+ if (this.publish(chunk[0])) return chunk.slice(1);
647
+ else return chunk;
648
+ }
649
+ slide() {
650
+ if (this.isFull()) {
651
+ const value = this.value;
652
+ this.subscribers = 0;
653
+ this.value = AbsentValue;
654
+ this.replayBuffer?.slide(value, this.replayIndex);
655
+ }
656
+ }
657
+ subscribe() {
658
+ this.subscriberCount += 1;
659
+ return new BoundedPubSubSingleSubscription(this, this.publisherIndex, false);
660
+ }
661
+ };
662
+ var BoundedPubSubSingleSubscription = class {
663
+ self;
664
+ subscriberIndex;
665
+ unsubscribed;
666
+ constructor(self, subscriberIndex, unsubscribed) {
667
+ this.self = self;
668
+ this.subscriberIndex = subscriberIndex;
669
+ this.unsubscribed = unsubscribed;
670
+ }
671
+ isEmpty() {
672
+ return this.unsubscribed || this.self.subscribers === 0 || this.subscriberIndex === this.self.publisherIndex;
673
+ }
674
+ size() {
675
+ return this.isEmpty() ? 0 : 1;
676
+ }
677
+ poll() {
678
+ if (this.isEmpty()) return Empty;
679
+ const elem = this.self.value;
680
+ this.self.subscribers -= 1;
681
+ if (this.self.subscribers === 0) this.self.value = AbsentValue;
682
+ this.subscriberIndex = this.self.publisherIndex;
683
+ return elem;
684
+ }
685
+ pollUpTo(n) {
686
+ if (normalize(n) < 1 || this.isEmpty()) return [];
687
+ return [this.poll()];
688
+ }
689
+ unsubscribe() {
690
+ if (!this.unsubscribed) {
691
+ this.unsubscribed = true;
692
+ this.self.subscriberCount -= 1;
693
+ if (this.self.subscribers !== 0 && this.subscriberIndex !== this.self.publisherIndex) {
694
+ this.self.subscribers -= 1;
695
+ if (this.self.subscribers === 0) this.self.value = AbsentValue;
696
+ }
697
+ }
698
+ }
699
+ };
700
+ var UnboundedPubSub = class {
701
+ publisherHead = {
702
+ value: AbsentValue,
703
+ replayIndex: void 0,
704
+ subscribers: 0,
705
+ next: null
706
+ };
707
+ publisherTail = this.publisherHead;
708
+ publisherIndex = 0;
709
+ subscribersIndex = 0;
710
+ capacity = Number.MAX_SAFE_INTEGER;
711
+ replayBuffer;
712
+ constructor(replayBuffer) {
713
+ this.replayBuffer = replayBuffer;
714
+ }
715
+ replayWindow() {
716
+ return this.replayBuffer ? new ReplayWindowImpl(this.replayBuffer) : emptyReplayWindow;
717
+ }
718
+ isEmpty() {
719
+ return this.publisherHead === this.publisherTail;
720
+ }
721
+ isFull() {
722
+ return false;
723
+ }
724
+ size() {
725
+ return this.publisherIndex - this.subscribersIndex;
726
+ }
727
+ publish(value) {
728
+ const replayIndex = this.replayBuffer?.offer(value);
729
+ const subscribers = this.publisherTail.subscribers;
730
+ if (subscribers !== 0) {
731
+ const node = {
732
+ value,
733
+ replayIndex,
734
+ subscribers,
735
+ next: null
736
+ };
737
+ this.publisherTail.next = node;
738
+ this.publisherTail = this.publisherTail.next;
739
+ this.publisherIndex += 1;
740
+ }
741
+ return true;
742
+ }
743
+ publishAll(elements) {
744
+ if (this.publisherTail.subscribers !== 0) for (const a of elements) this.publish(a);
745
+ else if (this.replayBuffer) this.replayBuffer.offerAll(elements);
746
+ return [];
747
+ }
748
+ slide() {
749
+ if (this.publisherHead !== this.publisherTail) {
750
+ const node = this.publisherHead.next;
751
+ const value = node.value;
752
+ this.publisherHead = this.publisherHead.next;
753
+ this.publisherHead.value = AbsentValue;
754
+ this.subscribersIndex += 1;
755
+ this.replayBuffer?.slide(value, node.replayIndex);
756
+ }
757
+ }
758
+ subscribe() {
759
+ this.publisherTail.subscribers += 1;
760
+ return new UnboundedPubSubSubscription(this, this.publisherTail, this.publisherIndex, false);
761
+ }
762
+ };
763
+ var UnboundedPubSubSubscription = class {
764
+ self;
765
+ subscriberHead;
766
+ subscriberIndex;
767
+ unsubscribed;
768
+ constructor(self, subscriberHead, subscriberIndex, unsubscribed) {
769
+ this.self = self;
770
+ this.subscriberHead = subscriberHead;
771
+ this.subscriberIndex = subscriberIndex;
772
+ this.unsubscribed = unsubscribed;
773
+ }
774
+ isEmpty() {
775
+ if (this.unsubscribed) return true;
776
+ let empty = true;
777
+ let loop = true;
778
+ while (loop) if (this.subscriberHead === this.self.publisherTail) loop = false;
779
+ else if (this.subscriberHead.next.value !== AbsentValue) {
780
+ empty = false;
781
+ loop = false;
782
+ } else {
783
+ this.subscriberHead = this.subscriberHead.next;
784
+ this.subscriberIndex += 1;
785
+ }
786
+ return empty;
787
+ }
788
+ size() {
789
+ if (this.unsubscribed) return 0;
790
+ return this.self.publisherIndex - Math.max(this.subscriberIndex, this.self.subscribersIndex);
791
+ }
792
+ poll() {
793
+ if (this.unsubscribed) return Empty;
794
+ let loop = true;
795
+ let polled = Empty;
796
+ while (loop) if (this.subscriberHead === this.self.publisherTail) loop = false;
797
+ else {
798
+ const elem = this.subscriberHead.next.value;
799
+ if (elem !== AbsentValue) {
800
+ polled = elem;
801
+ this.subscriberHead.subscribers -= 1;
802
+ if (this.subscriberHead.subscribers === 0) {
803
+ this.self.publisherHead = this.self.publisherHead.next;
804
+ this.self.publisherHead.value = AbsentValue;
805
+ this.self.subscribersIndex += 1;
806
+ }
807
+ loop = false;
808
+ }
809
+ this.subscriberHead = this.subscriberHead.next;
810
+ this.subscriberIndex += 1;
811
+ }
812
+ return polled;
813
+ }
814
+ pollUpTo(n) {
815
+ n = normalize(n);
816
+ const builder = [];
817
+ let i = 0;
818
+ while (i !== n) {
819
+ const a = this.poll();
820
+ if (a === Empty) i = n;
821
+ else {
822
+ builder.push(a);
823
+ i += 1;
824
+ }
825
+ }
826
+ return builder;
827
+ }
828
+ unsubscribe() {
829
+ if (!this.unsubscribed) {
830
+ this.unsubscribed = true;
831
+ this.self.publisherTail.subscribers -= 1;
832
+ while (this.subscriberHead !== this.self.publisherTail) {
833
+ if (this.subscriberHead.next.value !== AbsentValue) {
834
+ this.subscriberHead.subscribers -= 1;
835
+ if (this.subscriberHead.subscribers === 0) {
836
+ this.self.publisherHead = this.self.publisherHead.next;
837
+ this.self.publisherHead.value = AbsentValue;
838
+ this.self.subscribersIndex += 1;
839
+ }
840
+ }
841
+ this.subscriberHead = this.subscriberHead.next;
842
+ }
843
+ }
844
+ }
845
+ };
846
+ var SubscriptionImpl = class {
847
+ [SubscriptionTypeId] = { _A: identity };
848
+ pubsub;
849
+ subscribers;
850
+ subscription;
851
+ pollers;
852
+ shutdownHook;
853
+ shutdownFlag;
854
+ strategy;
855
+ replayWindow;
856
+ constructor(pubsub, subscribers, subscription, pollers, shutdownHook, shutdownFlag, strategy, replayWindow) {
857
+ this.pubsub = pubsub;
858
+ this.subscribers = subscribers;
859
+ this.subscription = subscription;
860
+ this.pollers = pollers;
861
+ this.shutdownHook = shutdownHook;
862
+ this.shutdownFlag = shutdownFlag;
863
+ this.strategy = strategy;
864
+ this.replayWindow = replayWindow;
865
+ }
866
+ pipe() {
867
+ return pipeArguments(this, arguments);
868
+ }
869
+ };
870
+ var PubSubImpl = class {
871
+ [TypeId$4] = { _A: identity };
872
+ pubsub;
873
+ subscribers;
874
+ scope;
875
+ shutdownHook;
876
+ shutdownFlag;
877
+ strategy;
878
+ constructor(pubsub, subscribers, scope, shutdownHook, shutdownFlag, strategy) {
879
+ this.pubsub = pubsub;
880
+ this.subscribers = subscribers;
881
+ this.scope = scope;
882
+ this.shutdownHook = shutdownHook;
883
+ this.shutdownFlag = shutdownFlag;
884
+ this.strategy = strategy;
885
+ }
886
+ pipe() {
887
+ return pipeArguments(this, arguments);
888
+ }
889
+ };
890
+ const makePubSubUnsafe = (pubsub, subscribers, scope, shutdownHook, shutdownFlag, strategy) => new PubSubImpl(pubsub, subscribers, scope, shutdownHook, shutdownFlag, strategy);
891
+ const ensureCapacity = (capacity) => {
892
+ if (capacity <= 0) throw new Error(`Cannot construct PubSub with capacity of ${capacity}`);
893
+ };
894
+ var BackPressureStrategy = class {
895
+ publishers = make$3();
896
+ get shutdown() {
897
+ return withFiber((fiber) => forEach(takeAll$2(this.publishers), ([_, deferred, last]) => last ? interruptWith(deferred, fiber.id) : void_, {
898
+ concurrency: "unbounded",
899
+ discard: true
900
+ }));
901
+ }
902
+ handleSurplus(pubsub, subscribers, elements, isShutdown) {
903
+ return suspend$2(() => {
904
+ const deferred = makeUnsafe$3();
905
+ this.offerUnsafe(elements, deferred);
906
+ this.onPubSubEmptySpaceUnsafe(pubsub, subscribers);
907
+ this.completeSubscribersUnsafe(pubsub, subscribers);
908
+ return (get(isShutdown) ? interrupt$2 : _await(deferred)).pipe(onInterrupt(() => {
909
+ this.removeUnsafe(deferred);
910
+ return void_;
911
+ }));
912
+ });
913
+ }
914
+ onPubSubEmptySpaceUnsafe(pubsub, subscribers) {
915
+ let keepPolling = true;
916
+ while (keepPolling && !pubsub.isFull()) {
917
+ const publisher = take$3(this.publishers);
918
+ if (publisher === Empty) keepPolling = false;
919
+ else {
920
+ const [value, deferred] = publisher;
921
+ const published = pubsub.publish(value);
922
+ if (published && publisher[2]) doneUnsafe(deferred, succeed$3(true));
923
+ else if (!published) prepend(this.publishers, publisher);
924
+ this.completeSubscribersUnsafe(pubsub, subscribers);
925
+ }
926
+ }
927
+ }
928
+ completePollersUnsafe(pubsub, subscribers, subscription, pollers) {
929
+ return strategyCompletePollersUnsafe(this, pubsub, subscribers, subscription, pollers);
930
+ }
931
+ completeSubscribersUnsafe(pubsub, subscribers) {
932
+ return strategyCompleteSubscribersUnsafe(this, pubsub, subscribers);
933
+ }
934
+ offerUnsafe(elements, deferred) {
935
+ const iterator = elements[Symbol.iterator]();
936
+ let next = iterator.next();
937
+ if (!next.done) while (1) {
938
+ const value = next.value;
939
+ next = iterator.next();
940
+ if (next.done) {
941
+ append(this.publishers, [
942
+ value,
943
+ deferred,
944
+ true
945
+ ]);
946
+ break;
947
+ }
948
+ append(this.publishers, [
949
+ value,
950
+ deferred,
951
+ false
952
+ ]);
953
+ }
954
+ }
955
+ removeUnsafe(deferred) {
956
+ filter$1(this.publishers, ([_, d]) => d !== deferred);
957
+ }
958
+ };
959
+ var DroppingStrategy = class {
960
+ get shutdown() {
961
+ return void_;
962
+ }
963
+ handleSurplus(_pubsub, _subscribers, _elements, _isShutdown) {
964
+ return succeed$2(false);
965
+ }
966
+ onPubSubEmptySpaceUnsafe(_pubsub, _subscribers) {}
967
+ completePollersUnsafe(pubsub, subscribers, subscription, pollers) {
968
+ return strategyCompletePollersUnsafe(this, pubsub, subscribers, subscription, pollers);
969
+ }
970
+ completeSubscribersUnsafe(pubsub, subscribers) {
971
+ return strategyCompleteSubscribersUnsafe(this, pubsub, subscribers);
972
+ }
973
+ };
974
+ var SlidingStrategy = class {
975
+ get shutdown() {
976
+ return void_;
977
+ }
978
+ handleSurplus(pubsub, subscribers, elements, _isShutdown) {
979
+ return sync(() => {
980
+ this.slidingPublishUnsafe(pubsub, elements);
981
+ this.completeSubscribersUnsafe(pubsub, subscribers);
982
+ return true;
983
+ });
984
+ }
985
+ onPubSubEmptySpaceUnsafe(_pubsub, _subscribers) {}
986
+ completePollersUnsafe(pubsub, subscribers, subscription, pollers) {
987
+ return strategyCompletePollersUnsafe(this, pubsub, subscribers, subscription, pollers);
988
+ }
989
+ completeSubscribersUnsafe(pubsub, subscribers) {
990
+ return strategyCompleteSubscribersUnsafe(this, pubsub, subscribers);
991
+ }
992
+ slidingPublishUnsafe(pubsub, elements) {
993
+ const it = elements[Symbol.iterator]();
994
+ let next = it.next();
995
+ if (!next.done && pubsub.capacity > 0) {
996
+ let a = next.value;
997
+ let loop = true;
998
+ while (loop) {
999
+ pubsub.slide();
1000
+ const pub = pubsub.publish(a);
1001
+ if (pub && (next = it.next()) && !next.done) a = next.value;
1002
+ else if (pub) loop = false;
1003
+ }
1004
+ }
1005
+ }
1006
+ };
1007
+ const strategyCompletePollersUnsafe = (strategy, pubsub, subscribers, subscription, pollers) => {
1008
+ let keepPolling = true;
1009
+ while (keepPolling && !subscription.isEmpty()) {
1010
+ const poller = take$3(pollers);
1011
+ if (poller === Empty) {
1012
+ removeSubscribers(subscribers, subscription, pollers);
1013
+ if (pollers.length === 0) keepPolling = false;
1014
+ else addSubscribers(subscribers, subscription, pollers);
1015
+ } else {
1016
+ const pollResult = subscription.poll();
1017
+ if (pollResult === Empty) prepend(pollers, poller);
1018
+ else {
1019
+ doneUnsafe(poller, succeed$3(pollResult));
1020
+ strategy.onPubSubEmptySpaceUnsafe(pubsub, subscribers);
1021
+ }
1022
+ }
1023
+ }
1024
+ };
1025
+ const strategyCompleteSubscribersUnsafe = (strategy, pubsub, subscribers) => {
1026
+ for (const [subscription, pollersSet] of subscribers) for (const pollers of pollersSet) strategy.completePollersUnsafe(pubsub, subscribers, subscription, pollers);
1027
+ };
1028
+ var ReplayBuffer = class {
1029
+ capacity;
1030
+ head = {
1031
+ value: AbsentValue,
1032
+ index: 0,
1033
+ next: null
1034
+ };
1035
+ tail = this.head;
1036
+ slideValues = [];
1037
+ size = 0;
1038
+ index = 0;
1039
+ publisherIndex = 0;
1040
+ constructor(capacity) {
1041
+ this.capacity = capacity;
1042
+ }
1043
+ slide(value, publisherIndex) {
1044
+ this.slideValues[this.index % this.capacity] = {
1045
+ value,
1046
+ index: publisherIndex
1047
+ };
1048
+ this.index++;
1049
+ }
1050
+ offer(a) {
1051
+ const index = this.publisherIndex++;
1052
+ this.tail.value = a;
1053
+ this.tail.index = index;
1054
+ this.tail.next = {
1055
+ value: AbsentValue,
1056
+ index: 0,
1057
+ next: null
1058
+ };
1059
+ this.tail = this.tail.next;
1060
+ if (this.size === this.capacity) this.head = this.head.next;
1061
+ else this.size += 1;
1062
+ return index;
1063
+ }
1064
+ offerAll(as) {
1065
+ for (const a of as) this.offer(a);
1066
+ }
1067
+ };
1068
+ var ReplayWindowImpl = class {
1069
+ buffer;
1070
+ values;
1071
+ index = 0;
1072
+ remaining;
1073
+ slideIndex;
1074
+ newestIndex = -1;
1075
+ constructor(buffer) {
1076
+ this.buffer = buffer;
1077
+ this.remaining = buffer.size;
1078
+ this.slideIndex = buffer.index;
1079
+ this.values = new Array(this.remaining);
1080
+ let node = buffer.head;
1081
+ for (let i = 0; i < this.remaining; i++) {
1082
+ this.values[i] = node.value;
1083
+ this.newestIndex = node.index;
1084
+ node = node.next;
1085
+ }
1086
+ }
1087
+ close() {
1088
+ this.values.length = 0;
1089
+ this.remaining = 0;
1090
+ }
1091
+ sync() {
1092
+ const slides = this.buffer.index - this.slideIndex;
1093
+ if (slides === 0 || this.remaining === 0) return;
1094
+ const count = Math.min(slides, this.buffer.capacity);
1095
+ const start = this.buffer.index - count;
1096
+ for (let i = 0; i < count; i++) {
1097
+ const entry = this.buffer.slideValues[(start + i) % this.buffer.capacity];
1098
+ if (entry.index > this.newestIndex) {
1099
+ this.index = (this.index + 1) % this.values.length;
1100
+ this.values[(this.index + this.remaining - 1) % this.values.length] = entry.value;
1101
+ this.newestIndex = entry.index;
1102
+ }
1103
+ }
1104
+ this.slideIndex = this.buffer.index;
1105
+ }
1106
+ take() {
1107
+ if (this.remaining === 0) return;
1108
+ this.sync();
1109
+ const value = this.values[this.index];
1110
+ this.values[this.index] = AbsentValue;
1111
+ this.index = (this.index + 1) % this.values.length;
1112
+ this.remaining--;
1113
+ if (this.remaining === 0) this.close();
1114
+ return value;
1115
+ }
1116
+ takeN(n) {
1117
+ n = normalize(n);
1118
+ const len = Math.min(n, this.remaining);
1119
+ const items = new Array(len);
1120
+ for (let i = 0; i < len; i++) items[i] = this.take();
1121
+ return items;
1122
+ }
1123
+ takeAll() {
1124
+ return this.takeN(this.remaining);
1125
+ }
1126
+ };
1127
+ const emptyReplayWindow = {
1128
+ remaining: 0,
1129
+ take: () => void 0,
1130
+ takeN: () => [],
1131
+ takeAll: () => [],
1132
+ close: () => void 0
1133
+ };
1134
+ //#endregion
1135
+ //#region node_modules/.pnpm/effect@4.0.0-rc.115/node_modules/effect/dist/Queue.js
1136
+ const TypeId$3 = "~effect/Queue";
1137
+ const EnqueueTypeId = "~effect/Queue/Enqueue";
1138
+ const DequeueTypeId = "~effect/Queue/Dequeue";
1139
+ const variance = {
1140
+ _A: identity,
1141
+ _E: identity
1142
+ };
1143
+ const QueueProto = {
1144
+ [TypeId$3]: variance,
1145
+ [EnqueueTypeId]: variance,
1146
+ [DequeueTypeId]: variance,
1147
+ ...PipeInspectableProto,
1148
+ toJSON() {
1149
+ return {
1150
+ _id: "effect/Queue",
1151
+ state: this.state._tag,
1152
+ size: sizeUnsafe(this)
1153
+ };
1154
+ }
1155
+ };
1156
+ const make$1 = (options) => withFiber$1((fiber) => {
1157
+ const self = Object.create(QueueProto);
1158
+ self.dispatcher = fiber.currentDispatcher;
1159
+ self.capacity = options?.capacity ?? Number.POSITIVE_INFINITY;
1160
+ self.strategy = options?.strategy ?? "suspend";
1161
+ self.messages = make$3();
1162
+ self.scheduleRunning = false;
1163
+ self.state = {
1164
+ _tag: "Open",
1165
+ takers: new Set(),
1166
+ offers: new Set(),
1167
+ awaiters: new Set()
1168
+ };
1169
+ return succeed$4(self);
1170
+ });
1171
+ const bounded = (capacity) => make$1({ capacity });
1172
+ const unbounded = () => make$1();
1173
+ const offer = (self, message) => suspend$3(() => {
1174
+ if (self.state._tag !== "Open") return exitFalse;
1175
+ else if (self.messages.length >= self.capacity) switch (self.strategy) {
1176
+ case "dropping": return exitFalse;
1177
+ case "suspend":
1178
+ if (self.capacity <= 0 && self.state.takers.size > 0) {
1179
+ append(self.messages, message);
1180
+ releaseTakers(self);
1181
+ return exitTrue;
1182
+ }
1183
+ return offerRemainingSingle(self, message);
1184
+ case "sliding":
1185
+ take$3(self.messages);
1186
+ append(self.messages, message);
1187
+ return exitTrue;
1188
+ }
1189
+ append(self.messages, message);
1190
+ scheduleReleaseTaker(self);
1191
+ return exitTrue;
1192
+ });
1193
+ const offerUnsafe = (self, message) => {
1194
+ if (self.state._tag !== "Open") return false;
1195
+ else if (self.messages.length >= self.capacity) {
1196
+ if (self.strategy === "sliding") {
1197
+ take$3(self.messages);
1198
+ append(self.messages, message);
1199
+ return true;
1200
+ } else if (self.capacity <= 0 && self.state.takers.size > 0) {
1201
+ append(self.messages, message);
1202
+ releaseTakers(self);
1203
+ return true;
1204
+ }
1205
+ return false;
1206
+ }
1207
+ append(self.messages, message);
1208
+ scheduleReleaseTaker(self);
1209
+ return true;
1210
+ };
1211
+ const offerAll = (self, messages) => suspend$3(() => {
1212
+ if (self.state._tag !== "Open") return succeed$4(fromIterable$1(messages));
1213
+ const remaining = offerAllUnsafe(self, messages);
1214
+ if (remaining.length === 0) return exitSucceed([]);
1215
+ else if (self.strategy === "dropping") return succeed$4(remaining);
1216
+ return offerRemainingArray(self, remaining);
1217
+ });
1218
+ const offerAllUnsafe = (self, messages) => {
1219
+ if (self.state._tag !== "Open") return fromIterable$1(messages);
1220
+ else if (self.capacity === Number.POSITIVE_INFINITY || self.strategy === "sliding") {
1221
+ appendAll(self.messages, messages);
1222
+ if (self.strategy === "sliding") takeN(self.messages, self.messages.length - self.capacity);
1223
+ scheduleReleaseTaker(self);
1224
+ return [];
1225
+ }
1226
+ const free = self.capacity <= 0 ? self.state.takers.size : self.capacity - self.messages.length;
1227
+ if (free === 0) return fromIterable$1(messages);
1228
+ const remaining = [];
1229
+ let i = 0;
1230
+ for (const message of messages) {
1231
+ if (i < free) append(self.messages, message);
1232
+ else remaining.push(message);
1233
+ i++;
1234
+ }
1235
+ scheduleReleaseTaker(self);
1236
+ return remaining;
1237
+ };
1238
+ const fail$2 = (self, error) => failCause$1(self, causeFail(error));
1239
+ const failCause$1 = dual(2, (self, cause) => sync$1(() => failCauseUnsafe(self, cause)));
1240
+ const failCauseUnsafe = (self, cause) => {
1241
+ if (self.state._tag !== "Open") return false;
1242
+ const exit = exitFailCause(cause);
1243
+ const fail = exitZipRight(exit, exitFailDone);
1244
+ if (self.state.offers.size === 0 && self.messages.length === 0) {
1245
+ finalize(self, fail);
1246
+ return true;
1247
+ }
1248
+ self.state = {
1249
+ ...self.state,
1250
+ _tag: "Closing",
1251
+ exit: fail
1252
+ };
1253
+ return true;
1254
+ };
1255
+ const end = (self) => failCause$1(self, causeFail(Done()));
1256
+ const endUnsafe = (self) => failCauseUnsafe(self, causeFail(Done()));
1257
+ const shutdown = (self) => sync$1(() => {
1258
+ if (self.state._tag === "Done") return true;
1259
+ clear(self.messages);
1260
+ const offers = self.state.offers;
1261
+ finalize(self, self.state._tag === "Open" ? exitInterrupt : self.state.exit);
1262
+ if (offers.size > 0) {
1263
+ for (const entry of offers) if (entry._tag === "Single") entry.resume(exitFalse);
1264
+ else entry.resume(exitSucceed(entry.remaining.slice(entry.offset)));
1265
+ offers.clear();
1266
+ }
1267
+ return true;
1268
+ });
1269
+ const takeAll = (self) => takeBetween(self, 1, Number.POSITIVE_INFINITY);
1270
+ const takeBetween = (self, min, max) => {
1271
+ min = normalize(min);
1272
+ max = normalize(max);
1273
+ return suspend$3(() => takeBetweenUnsafe(self, min, max) ?? andThen$1(awaitTake(self), takeBetween(self, 1, max)));
1274
+ };
1275
+ const take$1 = (self) => suspend$3(() => takeUnsafe(self) ?? andThen$1(awaitTake(self), take$1(self)));
1276
+ const poll = (self) => suspend$3(() => {
1277
+ const result = takeUnsafe(self);
1278
+ if (result === void 0) return succeed$4(none());
1279
+ if (result._tag === "Success") return succeed$4(some(result.value));
1280
+ return succeed$4(none());
1281
+ });
1282
+ const takeUnsafe = (self) => {
1283
+ if (self.state._tag === "Done") return self.state.exit;
1284
+ if (self.messages.length > 0) {
1285
+ const message = take$3(self.messages);
1286
+ releaseCapacity(self);
1287
+ return exitSucceed(message);
1288
+ } else if (self.capacity <= 0 && self.state.offers.size > 0) {
1289
+ const message = takeOfferUnsafe(self.state.offers);
1290
+ releaseCapacity(self);
1291
+ return exitSucceed(message);
1292
+ }
1293
+ };
1294
+ const sizeUnsafe = (self) => self.state._tag === "Done" ? 0 : self.messages.length;
1295
+ const exitFalse = exitSucceed(false);
1296
+ const exitTrue = exitSucceed(true);
1297
+ const exitFailDone = exitFail(Done());
1298
+ const exitInterrupt = exitInterrupt$1();
1299
+ const releaseTakers = (self) => {
1300
+ if (self.state._tag === "Done" || self.state.takers.size === 0) return;
1301
+ for (const taker of self.state.takers) {
1302
+ self.state.takers.delete(taker);
1303
+ taker(exitVoid);
1304
+ if (self.messages.length === 0) break;
1305
+ }
1306
+ };
1307
+ const scheduleReleaseTaker = (self) => {
1308
+ if (self.scheduleRunning || self.state._tag === "Done" || self.state.takers.size === 0) return;
1309
+ self.scheduleRunning = true;
1310
+ self.dispatcher.scheduleTask(() => {
1311
+ self.scheduleRunning = false;
1312
+ releaseTakers(self);
1313
+ }, 0);
1314
+ };
1315
+ const takeBetweenUnsafe = (self, min, max) => {
1316
+ if (self.state._tag === "Done") return self.state.exit;
1317
+ else if (max <= 0 || min <= 0) return exitSucceed([]);
1318
+ else if (self.capacity <= 0 && self.messages.length === 0 && self.state.offers.size > 0) {
1319
+ const messages = [takeOfferUnsafe(self.state.offers)];
1320
+ releaseCapacity(self);
1321
+ return exitSucceed(messages);
1322
+ }
1323
+ min = Math.min(min, self.capacity || 1);
1324
+ if (min <= self.messages.length) {
1325
+ const messages = takeN(self.messages, max);
1326
+ releaseCapacity(self);
1327
+ return exitSucceed(messages);
1328
+ }
1329
+ };
1330
+ const offerRemainingSingle = (self, message) => {
1331
+ return callback$1((resume) => {
1332
+ if (self.state._tag !== "Open") return resume(exitFalse);
1333
+ const entry = {
1334
+ _tag: "Single",
1335
+ message,
1336
+ resume
1337
+ };
1338
+ self.state.offers.add(entry);
1339
+ return sync$1(() => {
1340
+ if (self.state._tag === "Open") self.state.offers.delete(entry);
1341
+ });
1342
+ });
1343
+ };
1344
+ const offerRemainingArray = (self, remaining) => {
1345
+ return callback$1((resume) => {
1346
+ if (self.state._tag !== "Open") return resume(exitSucceed(remaining));
1347
+ const entry = {
1348
+ _tag: "Array",
1349
+ remaining,
1350
+ offset: 0,
1351
+ resume
1352
+ };
1353
+ self.state.offers.add(entry);
1354
+ return sync$1(() => {
1355
+ if (self.state._tag === "Open") self.state.offers.delete(entry);
1356
+ });
1357
+ });
1358
+ };
1359
+ const takeOfferUnsafe = (offers) => {
1360
+ const entry = offers.values().next().value;
1361
+ if (entry._tag === "Single") {
1362
+ offers.delete(entry);
1363
+ entry.resume(exitTrue);
1364
+ return entry.message;
1365
+ }
1366
+ const message = entry.remaining[entry.offset++];
1367
+ if (entry.offset === entry.remaining.length) {
1368
+ offers.delete(entry);
1369
+ entry.resume(exitSucceed([]));
1370
+ }
1371
+ return message;
1372
+ };
1373
+ const releaseCapacity = (self) => {
1374
+ if (self.state._tag === "Done") return isDoneCause(self.state.exit.cause);
1375
+ else if (self.state.offers.size === 0) {
1376
+ if (self.state._tag === "Closing" && self.messages.length === 0) {
1377
+ finalize(self, self.state.exit);
1378
+ return isDoneCause(self.state.exit.cause);
1379
+ }
1380
+ return false;
1381
+ }
1382
+ for (const entry of self.state.offers) {
1383
+ let n = self.capacity - self.messages.length;
1384
+ if (n <= 0) break;
1385
+ else if (entry._tag === "Single") {
1386
+ append(self.messages, entry.message);
1387
+ self.state.offers.delete(entry);
1388
+ entry.resume(exitTrue);
1389
+ } else {
1390
+ for (; entry.offset < entry.remaining.length; entry.offset++) {
1391
+ if (n === 0) return false;
1392
+ append(self.messages, entry.remaining[entry.offset]);
1393
+ n--;
1394
+ }
1395
+ self.state.offers.delete(entry);
1396
+ entry.resume(exitSucceed([]));
1397
+ }
1398
+ }
1399
+ return false;
1400
+ };
1401
+ const awaitTake = (self) => callback$1((resume) => {
1402
+ if (self.state._tag === "Done") return resume(self.state.exit);
1403
+ self.state.takers.add(resume);
1404
+ return sync$1(() => {
1405
+ if (self.state._tag !== "Done") self.state.takers.delete(resume);
1406
+ });
1407
+ });
1408
+ const finalize = (self, exit) => {
1409
+ if (self.state._tag === "Done") return;
1410
+ const openState = self.state;
1411
+ self.state = {
1412
+ _tag: "Done",
1413
+ exit
1414
+ };
1415
+ for (const taker of openState.takers) taker(exit);
1416
+ openState.takers.clear();
1417
+ for (const awaiter of openState.awaiters) awaiter(exit);
1418
+ openState.awaiters.clear();
1419
+ };
1420
+ //#endregion
1421
+ //#region node_modules/.pnpm/effect@4.0.0-rc.115/node_modules/effect/dist/Semaphore.js
1422
+ const makeUnsafe = (permits) => new SemaphoreImpl(permits);
1423
+ const waitForPermits = (self, n, effect) => callback$1((resume) => {
1424
+ if (self.free >= n) return resume(effect);
1425
+ const observer = () => {
1426
+ if (self.free < n) return;
1427
+ self.waiters.delete(observer);
1428
+ resume(effect);
1429
+ };
1430
+ self.waiters.add(observer);
1431
+ return sync$1(() => {
1432
+ self.waiters.delete(observer);
1433
+ });
1434
+ });
1435
+ var SemaphoreImpl = class {
1436
+ waiters = new Set();
1437
+ taken = 0;
1438
+ permits;
1439
+ constructor(permits) {
1440
+ this.permits = permits;
1441
+ }
1442
+ get free() {
1443
+ return this.permits - this.taken;
1444
+ }
1445
+ take(n) {
1446
+ const take = suspend$3(() => {
1447
+ if (this.free < n) return waitForPermits(this, n, take);
1448
+ this.taken += n;
1449
+ return succeed$4(n);
1450
+ });
1451
+ return take;
1452
+ }
1453
+ takeIfAvailable(n) {
1454
+ return suspend$3(() => {
1455
+ if (this.free < n) return succeed$4(false);
1456
+ this.taken += n;
1457
+ return succeed$4(true);
1458
+ });
1459
+ }
1460
+ releaseUnsafe(fiber, n) {
1461
+ this.taken -= n;
1462
+ if (this.waiters.size > 0) fiber.currentDispatcher.scheduleTask(() => {
1463
+ for (const observer of this.waiters) {
1464
+ if (this.free <= 0) break;
1465
+ observer();
1466
+ }
1467
+ }, 0);
1468
+ return this.free;
1469
+ }
1470
+ resize(permits) {
1471
+ return withFiber$1((fiber) => {
1472
+ this.permits = permits;
1473
+ if (this.free < 0) return void_$1;
1474
+ this.releaseUnsafe(fiber, 0);
1475
+ return void_$1;
1476
+ });
1477
+ }
1478
+ release(n) {
1479
+ return withFiber$1((fiber) => succeed$4(this.releaseUnsafe(fiber, n)));
1480
+ }
1481
+ get releaseAll() {
1482
+ return withFiber$1((fiber) => succeed$4(this.releaseUnsafe(fiber, this.taken)));
1483
+ }
1484
+ withPermits(n) {
1485
+ return (self) => uninterruptibleMask((restore) => {
1486
+ const acquire = suspend$3(() => {
1487
+ if (this.free < n) {
1488
+ const wait = waitForPermits(this, n, void_$1);
1489
+ return flatMap$3(restore(wait), () => acquire);
1490
+ }
1491
+ this.taken += n;
1492
+ return onExitPrimitive(restore(self), () => {
1493
+ this.releaseUnsafe(getCurrentFiber(), n);
1494
+ }, true);
1495
+ });
1496
+ return acquire;
1497
+ });
1498
+ }
1499
+ withPermit = this.withPermits(1);
1500
+ withPermitsIfAvailable(n) {
1501
+ return (self) => uninterruptibleMask((restore) => {
1502
+ if (this.free < n) return succeedNone;
1503
+ this.taken += n;
1504
+ return onExitPrimitive(restore(asSome(self)), () => {
1505
+ this.releaseUnsafe(getCurrentFiber(), n);
1506
+ }, true);
1507
+ });
1508
+ }
1509
+ };
1510
+ const make = (permits) => sync$1(() => new SemaphoreImpl(permits));
1511
+ //#endregion
1512
+ //#region node_modules/.pnpm/effect@4.0.0-rc.115/node_modules/effect/dist/Take.js
1513
+ const toPull = (take) => isExit(take) ? isSuccess(take) ? done(take.value) : take : succeed$2(take);
1514
+ //#endregion
1515
+ //#region node_modules/.pnpm/effect@4.0.0-rc.115/node_modules/effect/dist/Channel.js
1516
+ const TypeId$2 = "~effect/Channel";
1517
+ const isChannel = (u) => hasProperty(u, TypeId$2);
1518
+ const ChannelProto = {
1519
+ [TypeId$2]: {
1520
+ _Env: identity,
1521
+ _InErr: identity,
1522
+ _InElem: identity,
1523
+ _OutErr: identity,
1524
+ _OutElem: identity
1525
+ },
1526
+ pipe() {
1527
+ return pipeArguments(this, arguments);
1528
+ }
1529
+ };
1530
+ const fromTransform = (transform) => {
1531
+ const self = Object.create(ChannelProto);
1532
+ self.transform = (upstream, scope) => catchCause$1(transform(upstream, scope), (cause) => succeed$2(failCause$2(cause)));
1533
+ return self;
1534
+ };
1535
+ const transformPull$1 = (self, f) => fromTransform((upstream, scope) => flatMap$2(toTransform(self)(upstream, scope), (pull) => f(pull, scope)));
1536
+ const fromPull$1 = (effect) => fromTransform((_, __) => effect);
1537
+ const fromTransformBracket = (f) => fromTransform(fnUntraced(function* (upstream, scope) {
1538
+ const closableScope = forkUnsafe(scope);
1539
+ const onCause = (cause) => close(closableScope, doneExitFromCause(cause));
1540
+ const pull = yield* onError(f(upstream, scope, closableScope), onCause);
1541
+ return onError(pull, onCause);
1542
+ }));
1543
+ const toTransform = (channel) => channel.transform;
1544
+ const DefaultChunkSize = 4096;
1545
+ const asyncQueue = (scope, f, options) => make$1({
1546
+ capacity: options?.bufferSize,
1547
+ strategy: options?.strategy
1548
+ }).pipe(tap$1((queue) => addFinalizer(scope, shutdown(queue))), tap$1((queue) => forkIn(provide(f(queue), scope), scope)));
1549
+ const callbackArray = (f, options) => fromTransform((_, scope) => map$2(asyncQueue(scope, f, options), takeAll));
1550
+ const suspend$1 = (evaluate) => fromTransform((upstream, scope) => suspend$2(() => toTransform(evaluate())(upstream, scope)));
1551
+ const fromIteratorArray = (iterator, chunkSize = DefaultChunkSize) => {
1552
+ const size = normalizeNonEmpty(chunkSize);
1553
+ return fromPull$1(sync(() => {
1554
+ const iter = iterator();
1555
+ let done$14 = none();
1556
+ return suspend$2(() => {
1557
+ if (done$14._tag === "Some") return done(done$14.value);
1558
+ const buffer = [];
1559
+ while (buffer.length < size) {
1560
+ const state = iter.next();
1561
+ if (state.done) {
1562
+ if (buffer.length === 0) return done(state.value);
1563
+ done$14 = some(state.value);
1564
+ break;
1565
+ }
1566
+ buffer.push(state.value);
1567
+ }
1568
+ return succeed$2(buffer);
1569
+ });
1570
+ }));
1571
+ };
1572
+ const fromIterableArray = (iterable, chunkSize = DefaultChunkSize) => fromIteratorArray(() => iterable[Symbol.iterator](), chunkSize);
1573
+ const succeed$1 = (value) => fromEffect$1(succeed$2(value));
1574
+ const empty$1 = fromPull$1(succeed$2(done()));
1575
+ const fail$1 = (error) => fromPull$1(succeed$2(fail$3(error)));
1576
+ const failCause = (cause) => fromPull$1(failCause$2(cause));
1577
+ const die$1 = (defect) => failCause(die$2(defect));
1578
+ const fromEffect$1 = (effect) => fromPull$1(sync(() => {
1579
+ let done$15 = false;
1580
+ return suspend$2(() => {
1581
+ if (done$15) return done();
1582
+ done$15 = true;
1583
+ return effect;
1584
+ });
1585
+ }));
1586
+ const fromEffectTake = (effect) => fromPull$1(succeed$2(flatMap$2(effect, toPull)));
1587
+ const fromQueueArray = (queue) => fromPull$1(succeed$2(takeAll(queue)));
1588
+ const fromSubscriptionArray = (subscription) => fromPull$1(succeed$2(onInterrupt(takeAll$1(subscription), () => done())));
1589
+ const fromPubSubArray = (pubsub) => unwrap$1(map$2(subscribe(pubsub), fromSubscriptionArray));
1590
+ const fromPubSubTake$1 = (pubsub) => unwrap$1(map$2(subscribe(pubsub), (sub) => fromEffectTake(take$2(sub))));
1591
+ const fromReadableStream$1 = (options) => fromTransform((_, scope) => readableStreamToPullUnsafe({
1592
+ scope,
1593
+ readable: options.evaluate(),
1594
+ onError: options.onError,
1595
+ releaseLockOnEnd: options.releaseLockOnEnd
1596
+ }));
1597
+ const readableStreamToPullUnsafe = (options) => {
1598
+ const reader = options.readable.getReader();
1599
+ const exit = options.exit ?? make$4(void 0);
1600
+ const pull = suspend$2(() => {
1601
+ if (exit.current) return exit.current;
1602
+ return matchCauseEffect(tryPromise({
1603
+ try: () => reader.read(),
1604
+ catch: options.onError
1605
+ }), {
1606
+ onFailure: (cause) => exit.current ?? failCause$2(cause),
1607
+ onSuccess: ({ done: done$10, value }) => {
1608
+ if (exit.current) return exit.current;
1609
+ return done$10 ? done() : succeed$2(of(value));
1610
+ }
1611
+ });
1612
+ });
1613
+ return as(addFinalizer(options.scope, options.releaseLockOnEnd ? sync(() => reader.releaseLock()) : promise(() => reader.cancel().catch(constVoid))), pull);
1614
+ };
1615
+ const map$1 = dual(2, (self, f) => transformPull$1(self, (pull) => sync(() => {
1616
+ let i = 0;
1617
+ return map$2(pull, (o) => f(o, i++));
1618
+ })));
1619
+ const mapDone = dual(2, (self, f) => mapDoneEffect(self, (o) => succeed$2(f(o))));
1620
+ const mapDoneEffect = dual(2, (self, f) => transformPull$1(self, (pull) => succeed$2(catchDone(pull, (done$11) => flatMap$2(f(done$11), done)))));
1621
+ const concurrencyIsSequential = (concurrency) => concurrency === void 0 || concurrency !== "unbounded" && concurrency <= 1;
1622
+ const mapEffect$1 = dual((args) => isChannel(args[0]), (self, f, options) => concurrencyIsSequential(options?.concurrency) ? mapEffectSequential(self, f) : mapEffectConcurrent(self, f, options));
1623
+ const mapEffectSequential = (self, f) => fromTransform((upstream, scope) => {
1624
+ let i = 0;
1625
+ return map$2(toTransform(self)(upstream, scope), flatMap$2((o) => f(o, i++)));
1626
+ });
1627
+ const mapEffectConcurrent = (self, f, options) => fromTransformBracket(fnUntraced(function* (upstream, scope, forkedScope) {
1628
+ let i = 0;
1629
+ const pull = yield* toTransform(self)(upstream, scope);
1630
+ const concurrencyN = options.concurrency === "unbounded" ? Number.MAX_SAFE_INTEGER : options.concurrency;
1631
+ const queue = yield* bounded(0);
1632
+ yield* addFinalizer(forkedScope, shutdown(queue));
1633
+ const runFork = runForkWith(yield* context());
1634
+ const trackFiber = runIn(forkedScope);
1635
+ if (options.unordered) {
1636
+ const semaphore = makeUnsafe(concurrencyN);
1637
+ const release = constant(semaphore.release(1));
1638
+ const handle = matchCauseEffect({
1639
+ onFailure: (cause) => flatMap$2(failCause$1(queue, cause), release),
1640
+ onSuccess: (value) => flatMap$2(offer(queue, value), release)
1641
+ });
1642
+ yield* semaphore.take(1).pipe(flatMap$2(() => pull), flatMap$2((value) => {
1643
+ trackFiber(runFork(handle(f(value, i++))));
1644
+ return void_;
1645
+ }), forever({ disableYield: true }), catchCause$1((cause) => semaphore.withPermits(concurrencyN - 1)(failCause$1(queue, cause))), forkIn(forkedScope));
1646
+ } else {
1647
+ const effects = yield* bounded(concurrencyN - 2);
1648
+ yield* addFinalizer(forkedScope, shutdown(effects));
1649
+ yield* take$1(effects).pipe(flatten$1, flatMap$2((value) => offer(queue, value)), forever({ disableYield: true }), catchCause$1((cause) => failCause$1(queue, cause)), forkIn(forkedScope));
1650
+ let errorCause;
1651
+ const onExit = (exit) => {
1652
+ if (exit._tag === "Success") return;
1653
+ errorCause = exit.cause;
1654
+ failCauseUnsafe(queue, exit.cause);
1655
+ };
1656
+ yield* pull.pipe(flatMap$2((value) => {
1657
+ if (errorCause) return failCause$2(errorCause);
1658
+ const fiber = runFork(f(value, i++));
1659
+ trackFiber(fiber);
1660
+ fiber.addObserver(onExit);
1661
+ return offer(effects, join(fiber));
1662
+ }), forever({ disableYield: true }), catchCause$1((cause) => offer(effects, failCause$3(cause)).pipe(andThen(failCause$1(effects, cause)))), forkIn(forkedScope));
1663
+ }
1664
+ return take$1(queue);
1665
+ }));
1666
+ const flatMap$1 = dual((args) => isChannel(args[0]), (self, f, options) => concurrencyIsSequential(options?.concurrency) ? flatMapSequential(self, f) : flatMapConcurrent(self, f, options));
1667
+ const flatMapSequential = (self, f) => fromTransform((upstream, scope) => map$2(toTransform(self)(upstream, scope), (pull) => {
1668
+ let childPull;
1669
+ let childScope;
1670
+ const makePull = flatMap$2(pull, (value) => {
1671
+ childScope ??= forkUnsafe(scope);
1672
+ return flatMapEager(toTransform(f(value))(upstream, childScope), (pull) => {
1673
+ childPull = catchHalt(pull);
1674
+ return childPull;
1675
+ });
1676
+ });
1677
+ const catchHalt = catchDone((_) => {
1678
+ childPull = void 0;
1679
+ if (childScope.state._tag === "Open" && scopeFinalizerCountUnsafe(childScope) === 1) return makePull;
1680
+ const close$2 = close(childScope, void_$2);
1681
+ childScope = void 0;
1682
+ return flatMap$2(close$2, () => makePull);
1683
+ });
1684
+ return suspend$2(() => childPull ?? makePull);
1685
+ }));
1686
+ const flatMapConcurrent = (self, f, options) => self.pipe(map$1(f), mergeAll$1(options));
1687
+ const flattenArray = (self) => transformPull$1(self, (pull) => {
1688
+ let array;
1689
+ let index = 0;
1690
+ const pump = suspend$2(function loop() {
1691
+ if (array === void 0) return flatMap$2(pull, (array_) => {
1692
+ switch (array_.length) {
1693
+ case 0: return loop();
1694
+ case 1: return succeed$2(array_[0]);
1695
+ default:
1696
+ array = array_;
1697
+ return succeed$2(array_[index++]);
1698
+ }
1699
+ });
1700
+ const next = array[index++];
1701
+ if (index >= array.length) {
1702
+ array = void 0;
1703
+ index = 0;
1704
+ }
1705
+ return succeed$2(next);
1706
+ });
1707
+ return succeed$2(pump);
1708
+ });
1709
+ const filterArray = dual(2, (self, predicate) => transformPull$1(self, (pull) => succeed$2(flatMap$2(pull, function loop(arr) {
1710
+ const passes = [];
1711
+ for (let i = 0; i < arr.length; i++) if (predicate(arr[i])) passes.push(arr[i]);
1712
+ return isReadonlyArrayNonEmpty(passes) ? succeed$2(passes) : flatMap$2(pull, loop);
1713
+ }))));
1714
+ const filterMapArray = dual(2, (self, filter) => transformPull$1(self, (pull) => succeed$2(flatMap$2(pull, function loop(arr) {
1715
+ const passes = [];
1716
+ for (let i = 0; i < arr.length; i++) {
1717
+ const result = filter(arr[i]);
1718
+ if (isSuccess$1(result)) passes.push(result.success);
1719
+ }
1720
+ return isReadonlyArrayNonEmpty(passes) ? succeed$2(passes) : flatMap$2(pull, loop);
1721
+ }))));
1722
+ const catchCause = dual(2, (self, f) => fromTransform((upstream, scope) => {
1723
+ let forkedScope = forkUnsafe(scope);
1724
+ return map$2(toTransform(self)(upstream, forkedScope), (pull) => {
1725
+ let currentPull = pull.pipe(catchCause$1((cause) => {
1726
+ if (isDoneCause(cause)) return failCause$2(cause);
1727
+ const toClose = forkedScope;
1728
+ forkedScope = forkUnsafe(scope);
1729
+ return close(toClose, failCause$3(cause)).pipe(andThen(toTransform(f(cause))(upstream, forkedScope)), flatMap$2((childPull) => {
1730
+ currentPull = childPull;
1731
+ return childPull;
1732
+ }));
1733
+ }));
1734
+ return suspend$2(() => currentPull);
1735
+ });
1736
+ }));
1737
+ const catchCauseFilter = dual(3, (self, filter, f) => catchCause(self, (cause) => {
1738
+ const result = filter(cause);
1739
+ return isFailure(result) ? failCause(result.failure) : f(result.success, cause);
1740
+ }));
1741
+ const catch_$1 = dual(2, (self, f) => catchCauseFilter(self, findError, (e) => f(e)));
1742
+ const catchIf$1 = dual((args) => isChannel(args[0]), (self, predicate, f, orElse) => catch_$1(self, (err) => {
1743
+ return predicate(err) ? f(err) : orElse ? orElse(err) : fail$1(err);
1744
+ }));
1745
+ const catchFilter$1 = dual((args) => isChannel(args[0]), (self, filter, f, orElse) => catch_$1(self, (err) => {
1746
+ const result = filter(err);
1747
+ return isFailure(result) ? orElse ? orElse(result.failure) : fail$1(result.failure) : f(result.success);
1748
+ }));
1749
+ const catchReason$1 = dual((args) => isChannel(args[0]), (self, errorTag, reasonTag, f, orElse) => catch_$1(self, (error) => {
1750
+ if (isTagged(error, errorTag) && hasProperty(error, "reason")) {
1751
+ const reason = error.reason;
1752
+ if (isTagged(reason, reasonTag)) return f(reason, error);
1753
+ return orElse ? orElse(reason, error) : fail$1(error);
1754
+ }
1755
+ return fail$1(error);
1756
+ }));
1757
+ const mapError$1 = dual(2, (self, f) => catch_$1(self, (err) => fail$1(f(err))));
1758
+ const orDie$1 = (self) => catch_$1(self, die$1);
1759
+ const mergeAll$1 = dual(2, (channels, { bufferSize = 16, concurrency, switch: switch_ = false }) => fromTransformBracket(fnUntraced(function* (upstream, scope, forkedScope) {
1760
+ const concurrencyN = concurrency === "unbounded" ? Number.MAX_SAFE_INTEGER : Math.max(1, concurrency);
1761
+ const semaphore = switch_ ? void 0 : makeUnsafe(concurrencyN);
1762
+ const doneLatch = yield* make$5(true);
1763
+ const fibers = new Set();
1764
+ const queue = yield* bounded(bufferSize);
1765
+ yield* addFinalizer(forkedScope, shutdown(queue));
1766
+ const pull = yield* toTransform(channels)(upstream, scope);
1767
+ yield* gen(function* () {
1768
+ while (true) {
1769
+ let pullFiber;
1770
+ if (semaphore) {
1771
+ if (fibers.size < concurrencyN) yield* semaphore.take(1);
1772
+ else {
1773
+ pullFiber = yield* forkChild(pull);
1774
+ yield* raceFirst(semaphore.take(1), andThen(join(pullFiber), never));
1775
+ }
1776
+ }
1777
+ const channel = pullFiber === void 0 ? yield* pull : yield* join(pullFiber);
1778
+ const childScope = forkUnsafe(forkedScope);
1779
+ const childPull = yield* toTransform(channel)(upstream, childScope);
1780
+ while (fibers.size >= concurrencyN) {
1781
+ const fiber = headUnsafe(fibers);
1782
+ fibers.delete(fiber);
1783
+ if (fibers.size === 0) yield* doneLatch.open;
1784
+ yield* interrupt(fiber);
1785
+ }
1786
+ const fiber = yield* childPull.pipe(tap$1(() => yieldNow), flatMap$2((value) => offer(queue, value)), forever({ disableYield: true }), onError(fnUntraced(function* (cause) {
1787
+ const halt = filterDone(cause);
1788
+ yield* exit(close(childScope, !isFailure(halt) ? succeed$3(halt.success.value) : failCause$3(halt.failure)));
1789
+ if (!fibers.has(fiber)) return;
1790
+ fibers.delete(fiber);
1791
+ if (semaphore) yield* semaphore.release(1);
1792
+ if (fibers.size === 0) yield* doneLatch.open;
1793
+ if (isSuccess$1(halt)) return;
1794
+ return yield* failCause$1(queue, cause);
1795
+ })), forkChild);
1796
+ doneLatch.closeUnsafe();
1797
+ fibers.add(fiber);
1798
+ }
1799
+ }).pipe(catchCause$1((cause) => {
1800
+ const halt = filterDone(cause);
1801
+ if (isSuccess$1(halt)) return doneLatch.whenOpen(failCause$1(queue, cause));
1802
+ return failCause$1(queue, cause);
1803
+ }), forkIn(forkedScope));
1804
+ return take$1(queue);
1805
+ })));
1806
+ const merge$1 = dual((args) => isChannel(args[0]) && isChannel(args[1]), (left, right, options) => fromTransformBracket(fnUntraced(function* (upstream, _scope, forkedScope) {
1807
+ const strategy = options?.haltStrategy ?? "both";
1808
+ const queue = yield* bounded(0);
1809
+ yield* addFinalizer(forkedScope, shutdown(queue));
1810
+ let done = 0;
1811
+ function onExit(side, cause) {
1812
+ done++;
1813
+ if (!isDoneCause(cause)) return failCause$1(queue, cause);
1814
+ switch (strategy) {
1815
+ case "both": return done === 2 ? failCause$1(queue, cause) : void_;
1816
+ case "left":
1817
+ case "right": return side === strategy ? failCause$1(queue, cause) : void_;
1818
+ case "either": return failCause$1(queue, cause);
1819
+ }
1820
+ }
1821
+ const runSide = (side, channel, scope) => toTransform(channel)(upstream, scope).pipe(flatMap$2((pull) => pull.pipe(flatMap$2((value) => offer(queue, value)), forever)), onError((cause) => andThen(close(scope, doneExitFromCause(cause)), onExit(side, cause))), forkIn(forkedScope));
1822
+ yield* runSide("left", left, forkUnsafe(forkedScope));
1823
+ yield* runSide("right", right, forkUnsafe(forkedScope));
1824
+ return take$1(queue);
1825
+ })));
1826
+ const splitLines$1 = () => fromTransform((upstream, _scope) => sync(() => {
1827
+ let stringBuilder = "";
1828
+ let midCRLF = false;
1829
+ let done$12 = none();
1830
+ function splitLinesArray(chunk) {
1831
+ const chunkBuilder = [];
1832
+ function pushLine(segment) {
1833
+ if (stringBuilder.length === 0) chunkBuilder.push(segment);
1834
+ else {
1835
+ chunkBuilder.push(stringBuilder + segment);
1836
+ stringBuilder = "";
1837
+ }
1838
+ }
1839
+ for (let i = 0; i < chunk.length; i++) {
1840
+ const str = chunk[i];
1841
+ if (str.length !== 0) {
1842
+ let from = 0;
1843
+ let indexOfCR = str.indexOf("\r");
1844
+ let indexOfLF = str.indexOf("\n");
1845
+ if (midCRLF) {
1846
+ if (indexOfLF === 0) {
1847
+ from = 1;
1848
+ indexOfLF = str.indexOf("\n", from);
1849
+ }
1850
+ midCRLF = false;
1851
+ }
1852
+ while (indexOfCR !== -1 || indexOfLF !== -1) if (indexOfCR === -1 || indexOfLF !== -1 && indexOfLF < indexOfCR) {
1853
+ pushLine(str.substring(from, indexOfLF));
1854
+ from = indexOfLF + 1;
1855
+ indexOfLF = str.indexOf("\n", from);
1856
+ } else {
1857
+ pushLine(str.substring(from, indexOfCR));
1858
+ if (str.length === indexOfCR + 1) {
1859
+ midCRLF = true;
1860
+ from = str.length;
1861
+ indexOfCR = -1;
1862
+ } else {
1863
+ from = indexOfCR + (indexOfLF === indexOfCR + 1 ? 2 : 1);
1864
+ indexOfCR = str.indexOf("\r", from);
1865
+ indexOfLF = str.indexOf("\n", from);
1866
+ }
1867
+ }
1868
+ stringBuilder = stringBuilder + str.substring(from);
1869
+ }
1870
+ }
1871
+ return isReadonlyArrayNonEmpty(chunkBuilder) ? chunkBuilder : null;
1872
+ }
1873
+ const pullOrFlush = suspend$2(() => {
1874
+ if (done$12._tag === "Some") return done(done$12.value);
1875
+ return matchEffect(upstream, {
1876
+ onSuccess: loop,
1877
+ onFailure: failCause$2,
1878
+ onDone: (leftover) => {
1879
+ done$12 = some(leftover);
1880
+ if (stringBuilder.length > 0) {
1881
+ const last = stringBuilder;
1882
+ stringBuilder = "";
1883
+ midCRLF = false;
1884
+ return succeed$2([last]);
1885
+ }
1886
+ return done(leftover);
1887
+ }
1888
+ });
1889
+ });
1890
+ function loop(chunk) {
1891
+ const lines = splitLinesArray(chunk);
1892
+ return lines !== null ? succeed$2(lines) : pullOrFlush;
1893
+ }
1894
+ return pullOrFlush;
1895
+ }));
1896
+ const pipeTo = dual(2, (self, that) => fromTransform((upstream, scope) => flatMap$2(toTransform(self)(upstream, scope), (upstream) => toTransform(that)(upstream, scope))));
1897
+ const unwrap$1 = (channel) => fromTransform((upstream, scope) => {
1898
+ let pull;
1899
+ return succeed$2(suspend$2(() => {
1900
+ if (pull) return pull;
1901
+ return channel.pipe(provide(scope), flatMap$2((channel) => toTransform(channel)(upstream, scope)), flatMap$2((pull_) => pull = pull_));
1902
+ }));
1903
+ });
1904
+ const onExit = dual(2, (self, finalizer) => fromTransformBracket((upstream, scope, forkedScope) => addFinalizerExit(forkedScope, finalizer).pipe(andThen(toTransform(self)(upstream, scope)))));
1905
+ const onEnd$1 = dual(2, (self, onEnd) => transformPull$1(self, (pull) => succeed$2(catchDone(pull, (leftover) => flatMap$2(onEnd, () => done(leftover))))));
1906
+ const ensuring$1 = dual(2, (self, finalizer) => onExit(self, (_) => finalizer));
1907
+ const runWith = (self, f, onHalt) => suspend$2(() => {
1908
+ const scope = makeUnsafe$2();
1909
+ const makePull = toTransform(self)(done(), scope);
1910
+ return catchDone(flatMap$2(makePull, f), onHalt ? onHalt : succeed$2).pipe(onExit$1((exit) => close(scope, exit)));
1911
+ });
1912
+ const provideContext$1 = dual(2, (self, context) => fromTransform((upstream, scope) => map$2(provideContext$2(toTransform(self)(upstream, scope), context), provideContext$2(context))));
1913
+ 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))));
1914
+ const runDrain$1 = (self) => runWith(self, (pull) => forever(pull, { disableYield: true }));
1915
+ const runForEach$1 = dual(2, (self, f) => runWith(self, (pull) => forever(flatMap$2(pull, f), { disableYield: true })));
1916
+ const runFold$1 = dual(3, (self, initial, f) => suspend$2(() => {
1917
+ let state = initial();
1918
+ return runWith(self, (pull) => whileLoop({
1919
+ while: constTrue,
1920
+ body: () => pull,
1921
+ step: (value) => {
1922
+ state = f(state, value);
1923
+ }
1924
+ }), () => succeed$2(state));
1925
+ }));
1926
+ const toPullScoped = (self, scope) => toTransform(self)(done(), scope);
1927
+ const makePubSub = (options) => acquireRelease(options.capacity === "unbounded" ? unbounded$1(options) : options.strategy === "dropping" ? dropping(options) : options.strategy === "sliding" ? sliding(options) : bounded$1(options), shutdown$1);
1928
+ 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));
1929
+ const toPubSubTake$1 = dual(2, fnUntraced(function* (self, options) {
1930
+ const pubsub = yield* makePubSub(options);
1931
+ yield* runForEach$1(self, (value) => publish(pubsub, value)).pipe(onExit$1((exit) => publish(pubsub, exit)), forkScoped);
1932
+ return pubsub;
1933
+ }));
1934
+ //#endregion
1935
+ //#region node_modules/.pnpm/effect@4.0.0-rc.115/node_modules/effect/dist/internal/stream.js
1936
+ const TypeId$1 = "~effect/Stream";
1937
+ const streamVariance = {
1938
+ _R: identity,
1939
+ _E: identity,
1940
+ _A: identity
1941
+ };
1942
+ const Stream = function(channel) {
1943
+ this.channel = channel;
1944
+ };
1945
+ Stream.prototype = {
1946
+ [TypeId$1]: streamVariance,
1947
+ pipe() {
1948
+ return pipeArguments(this, arguments);
1949
+ }
1950
+ };
1951
+ const fromChannel$1 = (channel) => new Stream(channel);
1952
+ //#endregion
1953
+ //#region node_modules/.pnpm/effect@4.0.0-rc.115/node_modules/effect/dist/Stream.js
1954
+ const TypeId = "~effect/Stream";
1955
+ const isStream = (u) => hasProperty(u, TypeId);
1956
+ const fromChannel = fromChannel$1;
1957
+ const fromEffect = (effect) => fromChannel(fromEffect$1(map$2(effect, of)));
1958
+ const fromPull = (pull) => fromChannel(fromPull$1(pull));
1959
+ const transformPull = (self, f) => fromChannel(fromTransform((_, scope) => flatMap$2(toPullScoped(self.channel, scope), (pull) => f(pull, scope))));
1960
+ const toChannel = (stream) => stream.channel;
1961
+ const callback = (f, options) => fromChannel(callbackArray(f, options));
1962
+ const empty = fromChannel(empty$1);
1963
+ const succeed = (value) => fromChannel(succeed$1(of(value)));
1964
+ const suspend = (stream) => fromChannel(suspend$1(() => stream().channel));
1965
+ const fail = (error) => fromChannel(fail$1(error));
1966
+ const die = (defect) => fromChannel(die$1(defect));
1967
+ const fromIterable = (iterable, options) => Array.isArray(iterable) && options?.chunkSize === void 0 ? fromArray(iterable) : fromChannel(fromIterableArray(iterable, options?.chunkSize));
1968
+ const fromArray = (array) => isReadonlyArrayNonEmpty(array) ? fromChannel(succeed$1(array)) : empty;
1969
+ const fromArrayEffect = (effect) => unwrap(map$2(effect, fromArray));
1970
+ const fromQueue = (queue) => fromChannel(fromQueueArray(queue));
1971
+ const fromPubSub = (pubsub) => fromChannel(fromPubSubArray(pubsub));
1972
+ const fromPubSubTake = (pubsub) => fromChannel(fromPubSubTake$1(pubsub));
1973
+ const fromReadableStream = (options) => fromChannel(fromReadableStream$1(options));
1974
+ const unwrap = (effect) => fromChannel(unwrap$1(map$2(effect, toChannel)));
1975
+ const map = dual(2, (self, f) => suspend(() => {
1976
+ let i = 0;
1977
+ return fromChannel(map$1(self.channel, map$3((o) => f(o, i++))));
1978
+ }));
1979
+ const mapArray = dual(2, (self, f) => fromChannel(map$1(self.channel, f)));
1980
+ const mapEffect = dual((args) => isStream(args[0]), (self, f, options) => self.channel.pipe(flattenArray, mapEffect$1(f, options), map$1(of), fromChannel));
1981
+ const mapArrayEffect = dual(2, (self, f) => fromChannel(mapEffect$1(self.channel, f)));
1982
+ const tap = dual((args) => isStream(args[0]), (self, f, options) => mapEffect(self, (a) => as(f(a), a), options));
1983
+ const flatMap = dual((args) => isStream(args[0]), (self, f, options) => self.channel.pipe(flattenArray, flatMap$1((a) => f(a).channel, options), fromChannel));
1984
+ const flatten = dual((args) => isStream(args[0]), (self, options) => flatMap(self, identity, options));
1985
+ const flattenIterable = (self) => flatMap(self, fromIterable);
1986
+ const merge = dual((args) => isStream(args[0]) && isStream(args[1]), (self, that, options) => fromChannel(merge$1(toChannel(self), toChannel(that), options)));
1987
+ const mergeAll = dual(2, (streams, options) => flatten(fromIterable(streams), options));
1988
+ const filter = dual(2, (self, predicate) => fromChannel(filterArray(toChannel(self), predicate)));
1989
+ const filterMap = dual(2, (self, filter) => fromChannel(filterMapArray(toChannel(self), filter)));
1990
+ const catch_ = dual(2, (self, f) => fromChannel(catch_$1(self.channel, (error) => f(error).channel)));
1991
+ 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))));
1992
+ 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))));
1993
+ const catchTags = dual((args) => isStream(args[0]), (self, cases, orElse) => {
1994
+ let keys;
1995
+ return catchFilter(self, (e) => {
1996
+ keys ??= Object.keys(cases);
1997
+ return hasProperty(e, "_tag") && isString(e["_tag"]) && keys.includes(e["_tag"]) ? succeed$5(e) : fail$4(e);
1998
+ }, (e) => cases[e["_tag"]](e), orElse);
1999
+ });
2000
+ 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))));
2001
+ const mapError = dual(2, (self, f) => fromChannel(mapError$1(self.channel, f)));
2002
+ const orDie = (self) => fromChannel(orDie$1(self.channel));
2003
+ const take = dual(2, (self, n) => {
2004
+ const count = normalize(n);
2005
+ return count === 0 ? empty : takeUntil(self, (_, i) => i === count - 1);
2006
+ });
2007
+ const takeUntil = dual((args) => isStream(args[0]), (self, predicate, options) => transformPull(self, (pull, _scope) => sync(() => {
2008
+ let i = 0;
2009
+ let done$1 = false;
2010
+ return flatMap$2(suspend$2(() => done$1 ? done() : pull), (chunk) => {
2011
+ const index = chunk.findIndex((a) => predicate(a, i++));
2012
+ if (index >= 0) {
2013
+ done$1 = true;
2014
+ const arr = chunk.slice(0, options?.excludeLast ? index : index + 1);
2015
+ return isReadonlyArrayNonEmpty(arr) ? succeed$2(arr) : done();
2016
+ }
2017
+ return succeed$2(chunk);
2018
+ });
2019
+ })));
2020
+ const drop = dual(2, (self, n) => {
2021
+ const count = normalize(n);
2022
+ if (count === 0) return self;
2023
+ return transformPull(self, (pull, _scope) => sync(() => {
2024
+ let dropped = 0;
2025
+ const pump = pull.pipe(flatMap$2((chunk) => {
2026
+ if (dropped >= count) return succeed$2(chunk);
2027
+ dropped += chunk.length;
2028
+ if (dropped <= count) return pump;
2029
+ return succeed$2(chunk.slice(count - dropped));
2030
+ }));
2031
+ return pump;
2032
+ }));
2033
+ });
2034
+ const transduce = dual(2, (self, sink) => transformPull(self, (upstream, scope) => sync(() => {
2035
+ let done$6;
2036
+ let leftover;
2037
+ const upstreamWithLeftover = suspend$2(() => {
2038
+ if (leftover !== void 0) {
2039
+ const chunk = leftover;
2040
+ leftover = void 0;
2041
+ return succeed$2(chunk);
2042
+ }
2043
+ return upstream;
2044
+ }).pipe(catch_$2((error) => {
2045
+ done$6 = fail$5(error);
2046
+ return done();
2047
+ }));
2048
+ const pull = map$2(suspend$2(() => sink.transform(upstreamWithLeftover, scope)), ([value, leftover_]) => {
2049
+ leftover = leftover_;
2050
+ return of(value);
2051
+ });
2052
+ return suspend$2(() => done$6 ? done$6 : pull);
2053
+ })));
2054
+ const broadcast = dual(2, (self, options) => map$2(toPubSubTake(self, options), fromPubSubTake));
2055
+ const pipeThroughChannel = dual(2, (self, channel) => fromChannel(pipeTo(self.channel, channel)));
2056
+ const decodeText = dual((args) => isStream(args[0]), (self, options) => suspend(() => {
2057
+ const decoder = new TextDecoder(options?.encoding);
2058
+ return map(self, (chunk) => decoder.decode(chunk, { stream: true }));
2059
+ }));
2060
+ const splitLines = (self) => self.channel.pipe(pipeTo(splitLines$1()), fromChannel);
2061
+ const onEnd = dual(2, (self, onEnd) => fromChannel(onEnd$1(self.channel, onEnd)));
2062
+ const ensuring = dual(2, (self, finalizer) => fromChannel(ensuring$1(self.channel, finalizer)));
2063
+ const provideContext = dual(2, (self, context) => fromChannel(provideContext$1(self.channel, context)));
2064
+ const provideService = dual(3, (self, key, service) => fromChannel(provideService$1(self.channel, key, service)));
2065
+ const run = dual(2, (self, sink) => scopedWith((scope) => toPullScoped(self.channel, scope).pipe(flatMap$2((upstream) => sink.transform(upstream, scope)), map$2(([a]) => a))));
2066
+ const runCollect = (self) => runFold$1(self.channel, () => [], (acc, chunk) => {
2067
+ for (let i = 0; i < chunk.length; i++) acc.push(chunk[i]);
2068
+ return acc;
2069
+ });
2070
+ const runFold = dual(3, (self, initial, f) => runFold$1(self.channel, initial, (acc, arr) => {
2071
+ for (let i = 0; i < arr.length; i++) acc = f(acc, arr[i]);
2072
+ return acc;
2073
+ }));
2074
+ const runForEach = dual(2, (self, f) => runForEach$1(self.channel, (arr) => {
2075
+ let i = 0;
2076
+ return whileLoop({
2077
+ while: () => i < arr.length,
2078
+ body: () => f(arr[i++]),
2079
+ step: constVoid
2080
+ });
2081
+ }));
2082
+ const runForEachArray = dual(2, (self, f) => runForEach$1(self.channel, f));
2083
+ const runDrain = (self) => runDrain$1(self.channel);
2084
+ const mkString = (self) => runFold$1(self.channel, () => "", (acc, chunk) => acc + chunk.join(""));
2085
+ const runIntoPubSub = dual((args) => isStream(args[0]), (self, pubsub, options) => runIntoPubSubArray(self.channel, pubsub, options));
2086
+ const toPubSubTake = dual(2, (self, options) => toPubSubTake$1(self.channel, options));
2087
+ //#endregion
2088
+ export { transduce as $, mapEffect as A, interrupt as At, run as B, normalizeNonEmpty as Bt, fromPull as C, unbounded$1 as Ct, map as D, makeUnsafe$1 as Dt, isStream as E, update as Et, onEnd as F, runIn as Ft, runForEachArray as G, runDrain as H, orDie as I, camelToSnake as It, succeed as J, runIntoPubSub as K, pipeThroughChannel as L, toLowerCase as Lt, merge as M, interruptAllAs as Mt, mergeAll as N, interruptAs as Nt, mapArray as O, await_ as Ot, mkString as P, join as Pt, tap as Q, provideContext as R, parse as Rt, fromPubSub as S, unbounded as St, fromReadableStream as T, set as Tt, runFold as U, runCollect as V, runForEach as W, take as X, suspend as Y, takeUntil as Z, fromArray as _, offerAll as _t, catchTags as a, toTransform as at, fromEffect as b, poll as bt, die as c, makeUnsafe as ct, ensuring as d, endUnsafe as dt, unwrap as et, fail as f, fail$2 as ft, flattenIterable as g, offer as gt, flatMap as h, make$1 as ht, catchReason as i, pipeTo as it, mapError as j, interruptAll as jt, mapArrayEffect as k, getCurrent as kt, drop as l, bounded as lt, filterMap as m, failCauseUnsafe as mt, callback as n, map$1 as nt, catch_ as o, unwrap$1 as ot, filter as p, failCause$1 as pt, splitLines as q, catchIf as r, mapDone as rt, decodeText as s, make as st, broadcast as t, fromTransform as tt, empty as u, end as ut, fromArrayEffect as v, offerAllUnsafe as vt, fromQueue as w, make$4 as wt, fromIterable as x, take$1 as xt, fromChannel as y, offerUnsafe as yt, provideService as z, round as zt };
2089
+
2090
+ //# sourceMappingURL=Stream-B5ebASRi.mjs.map