@effect-ak/tg-bot 1.2.4 → 1.3.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/dist/index.cjs +396 -3971
- package/dist/index.d.ts +110 -81
- package/dist/index.js +391 -3955
- package/package.json +5 -10
- package/readme.md +34 -465
package/dist/index.cjs
CHANGED
|
@@ -20,3580 +20,47 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
-
BatchUpdateResult: () => BatchUpdateResult,
|
|
24
|
-
BotPollSettings: () => BotPollSettings,
|
|
25
|
-
BotPollSettingsTag: () => BotPollSettingsTag,
|
|
26
23
|
BotResponse: () => BotResponse,
|
|
27
|
-
|
|
28
|
-
BotTgClientTag: () => BotTgClientTag,
|
|
29
|
-
BotUpdateHandlersTag: () => BotUpdateHandlersTag,
|
|
30
|
-
HandleUpdateError: () => HandleUpdateError,
|
|
24
|
+
createBot: () => createBot,
|
|
31
25
|
createBotContext: () => createBotContext,
|
|
32
|
-
|
|
26
|
+
createWebhook: () => createWebhook,
|
|
33
27
|
defineBot: () => defineBot,
|
|
34
28
|
extractUpdate: () => extractUpdate,
|
|
35
|
-
|
|
36
|
-
handleOneByOne: () => handleOneByOne,
|
|
37
|
-
handleOneUpdate: () => handleOneUpdate,
|
|
38
|
-
handleUpdates: () => handleUpdates,
|
|
39
|
-
launchBot: () => launchBot,
|
|
40
|
-
runTgChatBot: () => runTgChatBot
|
|
29
|
+
runBot: () => runBot
|
|
41
30
|
});
|
|
42
31
|
module.exports = __toCommonJS(index_exports);
|
|
43
32
|
|
|
44
|
-
//
|
|
45
|
-
var
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (arity(arguments)) {
|
|
50
|
-
return body.apply(this, arguments);
|
|
51
|
-
}
|
|
52
|
-
return (self) => body(self, ...arguments);
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
switch (arity) {
|
|
56
|
-
case 0:
|
|
57
|
-
case 1:
|
|
58
|
-
throw new RangeError(`Invalid arity ${arity}`);
|
|
59
|
-
case 2:
|
|
60
|
-
return function(a, b) {
|
|
61
|
-
if (arguments.length >= 2) {
|
|
62
|
-
return body(a, b);
|
|
63
|
-
}
|
|
64
|
-
return function(self) {
|
|
65
|
-
return body(self, a);
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
case 3:
|
|
69
|
-
return function(a, b, c) {
|
|
70
|
-
if (arguments.length >= 3) {
|
|
71
|
-
return body(a, b, c);
|
|
72
|
-
}
|
|
73
|
-
return function(self) {
|
|
74
|
-
return body(self, a, b);
|
|
75
|
-
};
|
|
76
|
-
};
|
|
77
|
-
case 4:
|
|
78
|
-
return function(a, b, c, d) {
|
|
79
|
-
if (arguments.length >= 4) {
|
|
80
|
-
return body(a, b, c, d);
|
|
81
|
-
}
|
|
82
|
-
return function(self) {
|
|
83
|
-
return body(self, a, b, c);
|
|
84
|
-
};
|
|
85
|
-
};
|
|
86
|
-
case 5:
|
|
87
|
-
return function(a, b, c, d, e) {
|
|
88
|
-
if (arguments.length >= 5) {
|
|
89
|
-
return body(a, b, c, d, e);
|
|
90
|
-
}
|
|
91
|
-
return function(self) {
|
|
92
|
-
return body(self, a, b, c, d);
|
|
93
|
-
};
|
|
94
|
-
};
|
|
95
|
-
default:
|
|
96
|
-
return function() {
|
|
97
|
-
if (arguments.length >= arity) {
|
|
98
|
-
return body.apply(this, arguments);
|
|
99
|
-
}
|
|
100
|
-
const args2 = arguments;
|
|
101
|
-
return function(self) {
|
|
102
|
-
return body(self, ...args2);
|
|
103
|
-
};
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
var identity = (a) => a;
|
|
108
|
-
var constant = (value) => () => value;
|
|
109
|
-
var constTrue = /* @__PURE__ */ constant(true);
|
|
110
|
-
var constFalse = /* @__PURE__ */ constant(false);
|
|
111
|
-
var constUndefined = /* @__PURE__ */ constant(void 0);
|
|
112
|
-
var constVoid = constUndefined;
|
|
113
|
-
function pipe(a, ab, bc, cd, de, ef, fg, gh, hi) {
|
|
114
|
-
switch (arguments.length) {
|
|
115
|
-
case 1:
|
|
116
|
-
return a;
|
|
117
|
-
case 2:
|
|
118
|
-
return ab(a);
|
|
119
|
-
case 3:
|
|
120
|
-
return bc(ab(a));
|
|
121
|
-
case 4:
|
|
122
|
-
return cd(bc(ab(a)));
|
|
123
|
-
case 5:
|
|
124
|
-
return de(cd(bc(ab(a))));
|
|
125
|
-
case 6:
|
|
126
|
-
return ef(de(cd(bc(ab(a)))));
|
|
127
|
-
case 7:
|
|
128
|
-
return fg(ef(de(cd(bc(ab(a))))));
|
|
129
|
-
case 8:
|
|
130
|
-
return gh(fg(ef(de(cd(bc(ab(a)))))));
|
|
131
|
-
case 9:
|
|
132
|
-
return hi(gh(fg(ef(de(cd(bc(ab(a))))))));
|
|
133
|
-
default: {
|
|
134
|
-
let ret = arguments[0];
|
|
135
|
-
for (let i = 1; i < arguments.length; i++) {
|
|
136
|
-
ret = arguments[i](ret);
|
|
137
|
-
}
|
|
138
|
-
return ret;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// ../../node_modules/.pnpm/effect@3.19.13/node_modules/effect/dist/esm/Equivalence.js
|
|
144
|
-
var make = (isEquivalent) => (self, that) => self === that || isEquivalent(self, that);
|
|
145
|
-
|
|
146
|
-
// ../../node_modules/.pnpm/effect@3.19.13/node_modules/effect/dist/esm/GlobalValue.js
|
|
147
|
-
var globalStoreId = `effect/GlobalValue`;
|
|
148
|
-
var globalStore;
|
|
149
|
-
var globalValue = (id, compute) => {
|
|
150
|
-
if (!globalStore) {
|
|
151
|
-
globalThis[globalStoreId] ??= /* @__PURE__ */ new Map();
|
|
152
|
-
globalStore = globalThis[globalStoreId];
|
|
153
|
-
}
|
|
154
|
-
if (!globalStore.has(id)) {
|
|
155
|
-
globalStore.set(id, compute());
|
|
156
|
-
}
|
|
157
|
-
return globalStore.get(id);
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
// ../../node_modules/.pnpm/effect@3.19.13/node_modules/effect/dist/esm/Predicate.js
|
|
161
|
-
var isFunction2 = isFunction;
|
|
162
|
-
var isRecordOrArray = (input) => typeof input === "object" && input !== null;
|
|
163
|
-
var isObject = (input) => isRecordOrArray(input) || isFunction2(input);
|
|
164
|
-
var hasProperty = /* @__PURE__ */ dual(2, (self, property) => isObject(self) && property in self);
|
|
165
|
-
var isTagged = /* @__PURE__ */ dual(2, (self, tag) => hasProperty(self, "_tag") && self["_tag"] === tag);
|
|
166
|
-
|
|
167
|
-
// ../../node_modules/.pnpm/effect@3.19.13/node_modules/effect/dist/esm/internal/errors.js
|
|
168
|
-
var getBugErrorMessage = (message) => `BUG: ${message} - please report an issue at https://github.com/Effect-TS/effect/issues`;
|
|
169
|
-
|
|
170
|
-
// ../../node_modules/.pnpm/effect@3.19.13/node_modules/effect/dist/esm/Utils.js
|
|
171
|
-
var GenKindTypeId = /* @__PURE__ */ Symbol.for("effect/Gen/GenKind");
|
|
172
|
-
var GenKindImpl = class {
|
|
173
|
-
value;
|
|
174
|
-
constructor(value) {
|
|
175
|
-
this.value = value;
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* @since 2.0.0
|
|
179
|
-
*/
|
|
180
|
-
get _F() {
|
|
181
|
-
return identity;
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* @since 2.0.0
|
|
185
|
-
*/
|
|
186
|
-
get _R() {
|
|
187
|
-
return (_) => _;
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* @since 2.0.0
|
|
191
|
-
*/
|
|
192
|
-
get _O() {
|
|
193
|
-
return (_) => _;
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* @since 2.0.0
|
|
197
|
-
*/
|
|
198
|
-
get _E() {
|
|
199
|
-
return (_) => _;
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* @since 2.0.0
|
|
203
|
-
*/
|
|
204
|
-
[GenKindTypeId] = GenKindTypeId;
|
|
205
|
-
/**
|
|
206
|
-
* @since 2.0.0
|
|
207
|
-
*/
|
|
208
|
-
[Symbol.iterator]() {
|
|
209
|
-
return new SingleShotGen(this);
|
|
210
|
-
}
|
|
211
|
-
};
|
|
212
|
-
var SingleShotGen = class _SingleShotGen {
|
|
213
|
-
self;
|
|
214
|
-
called = false;
|
|
215
|
-
constructor(self) {
|
|
216
|
-
this.self = self;
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* @since 2.0.0
|
|
220
|
-
*/
|
|
221
|
-
next(a) {
|
|
222
|
-
return this.called ? {
|
|
223
|
-
value: a,
|
|
224
|
-
done: true
|
|
225
|
-
} : (this.called = true, {
|
|
226
|
-
value: this.self,
|
|
227
|
-
done: false
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* @since 2.0.0
|
|
232
|
-
*/
|
|
233
|
-
return(a) {
|
|
234
|
-
return {
|
|
235
|
-
value: a,
|
|
236
|
-
done: true
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* @since 2.0.0
|
|
241
|
-
*/
|
|
242
|
-
throw(e) {
|
|
243
|
-
throw e;
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* @since 2.0.0
|
|
247
|
-
*/
|
|
248
|
-
[Symbol.iterator]() {
|
|
249
|
-
return new _SingleShotGen(this.self);
|
|
250
|
-
}
|
|
251
|
-
};
|
|
252
|
-
var MUL_HI = 1481765933 >>> 0;
|
|
253
|
-
var MUL_LO = 1284865837 >>> 0;
|
|
254
|
-
var YieldWrapTypeId = /* @__PURE__ */ Symbol.for("effect/Utils/YieldWrap");
|
|
255
|
-
var YieldWrap = class {
|
|
256
|
-
/**
|
|
257
|
-
* @since 3.0.6
|
|
258
|
-
*/
|
|
259
|
-
#value;
|
|
260
|
-
constructor(value) {
|
|
261
|
-
this.#value = value;
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* @since 3.0.6
|
|
265
|
-
*/
|
|
266
|
-
[YieldWrapTypeId]() {
|
|
267
|
-
return this.#value;
|
|
268
|
-
}
|
|
269
|
-
};
|
|
270
|
-
function yieldWrapGet(self) {
|
|
271
|
-
if (typeof self === "object" && self !== null && YieldWrapTypeId in self) {
|
|
272
|
-
return self[YieldWrapTypeId]();
|
|
273
|
-
}
|
|
274
|
-
throw new Error(getBugErrorMessage("yieldWrapGet"));
|
|
275
|
-
}
|
|
276
|
-
var structuralRegionState = /* @__PURE__ */ globalValue("effect/Utils/isStructuralRegion", () => ({
|
|
277
|
-
enabled: false,
|
|
278
|
-
tester: void 0
|
|
279
|
-
}));
|
|
280
|
-
var standard = {
|
|
281
|
-
effect_internal_function: (body) => {
|
|
282
|
-
return body();
|
|
283
|
-
}
|
|
284
|
-
};
|
|
285
|
-
var forced = {
|
|
286
|
-
effect_internal_function: (body) => {
|
|
287
|
-
try {
|
|
288
|
-
return body();
|
|
289
|
-
} finally {
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
};
|
|
293
|
-
var isNotOptimizedAway = /* @__PURE__ */ standard.effect_internal_function(() => new Error().stack)?.includes("effect_internal_function") === true;
|
|
294
|
-
var internalCall = isNotOptimizedAway ? standard.effect_internal_function : forced.effect_internal_function;
|
|
295
|
-
var genConstructor = function* () {
|
|
296
|
-
}.constructor;
|
|
297
|
-
|
|
298
|
-
// ../../node_modules/.pnpm/effect@3.19.13/node_modules/effect/dist/esm/Hash.js
|
|
299
|
-
var randomHashCache = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/Hash/randomHashCache"), () => /* @__PURE__ */ new WeakMap());
|
|
300
|
-
var symbol = /* @__PURE__ */ Symbol.for("effect/Hash");
|
|
301
|
-
var hash = (self) => {
|
|
302
|
-
if (structuralRegionState.enabled === true) {
|
|
303
|
-
return 0;
|
|
304
|
-
}
|
|
305
|
-
switch (typeof self) {
|
|
306
|
-
case "number":
|
|
307
|
-
return number(self);
|
|
308
|
-
case "bigint":
|
|
309
|
-
return string(self.toString(10));
|
|
310
|
-
case "boolean":
|
|
311
|
-
return string(String(self));
|
|
312
|
-
case "symbol":
|
|
313
|
-
return string(String(self));
|
|
314
|
-
case "string":
|
|
315
|
-
return string(self);
|
|
316
|
-
case "undefined":
|
|
317
|
-
return string("undefined");
|
|
318
|
-
case "function":
|
|
319
|
-
case "object": {
|
|
320
|
-
if (self === null) {
|
|
321
|
-
return string("null");
|
|
322
|
-
} else if (self instanceof Date) {
|
|
323
|
-
if (Number.isNaN(self.getTime())) {
|
|
324
|
-
return string("Invalid Date");
|
|
325
|
-
}
|
|
326
|
-
return hash(self.toISOString());
|
|
327
|
-
} else if (self instanceof URL) {
|
|
328
|
-
return hash(self.href);
|
|
329
|
-
} else if (isHash(self)) {
|
|
330
|
-
return self[symbol]();
|
|
331
|
-
} else {
|
|
332
|
-
return random(self);
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
default:
|
|
336
|
-
throw new Error(`BUG: unhandled typeof ${typeof self} - please report an issue at https://github.com/Effect-TS/effect/issues`);
|
|
337
|
-
}
|
|
338
|
-
};
|
|
339
|
-
var random = (self) => {
|
|
340
|
-
if (!randomHashCache.has(self)) {
|
|
341
|
-
randomHashCache.set(self, number(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)));
|
|
342
|
-
}
|
|
343
|
-
return randomHashCache.get(self);
|
|
344
|
-
};
|
|
345
|
-
var combine = (b) => (self) => self * 53 ^ b;
|
|
346
|
-
var optimize = (n) => n & 3221225471 | n >>> 1 & 1073741824;
|
|
347
|
-
var isHash = (u) => hasProperty(u, symbol);
|
|
348
|
-
var number = (n) => {
|
|
349
|
-
if (n !== n || n === Infinity) {
|
|
350
|
-
return 0;
|
|
351
|
-
}
|
|
352
|
-
let h = n | 0;
|
|
353
|
-
if (h !== n) {
|
|
354
|
-
h ^= n * 4294967295;
|
|
355
|
-
}
|
|
356
|
-
while (n > 4294967295) {
|
|
357
|
-
h ^= n /= 4294967295;
|
|
358
|
-
}
|
|
359
|
-
return optimize(h);
|
|
360
|
-
};
|
|
361
|
-
var string = (str) => {
|
|
362
|
-
let h = 5381, i = str.length;
|
|
363
|
-
while (i) {
|
|
364
|
-
h = h * 33 ^ str.charCodeAt(--i);
|
|
365
|
-
}
|
|
366
|
-
return optimize(h);
|
|
367
|
-
};
|
|
368
|
-
var structureKeys = (o, keys2) => {
|
|
369
|
-
let h = 12289;
|
|
370
|
-
for (let i = 0; i < keys2.length; i++) {
|
|
371
|
-
h ^= pipe(string(keys2[i]), combine(hash(o[keys2[i]])));
|
|
372
|
-
}
|
|
373
|
-
return optimize(h);
|
|
374
|
-
};
|
|
375
|
-
var structure = (o) => structureKeys(o, Object.keys(o));
|
|
376
|
-
var array = (arr) => {
|
|
377
|
-
let h = 6151;
|
|
378
|
-
for (let i = 0; i < arr.length; i++) {
|
|
379
|
-
h = pipe(h, combine(hash(arr[i])));
|
|
380
|
-
}
|
|
381
|
-
return optimize(h);
|
|
382
|
-
};
|
|
383
|
-
var cached = function() {
|
|
384
|
-
if (arguments.length === 1) {
|
|
385
|
-
const self2 = arguments[0];
|
|
386
|
-
return function(hash3) {
|
|
387
|
-
Object.defineProperty(self2, symbol, {
|
|
388
|
-
value() {
|
|
389
|
-
return hash3;
|
|
390
|
-
},
|
|
391
|
-
enumerable: false
|
|
392
|
-
});
|
|
393
|
-
return hash3;
|
|
394
|
-
};
|
|
395
|
-
}
|
|
396
|
-
const self = arguments[0];
|
|
397
|
-
const hash2 = arguments[1];
|
|
398
|
-
Object.defineProperty(self, symbol, {
|
|
399
|
-
value() {
|
|
400
|
-
return hash2;
|
|
401
|
-
},
|
|
402
|
-
enumerable: false
|
|
403
|
-
});
|
|
404
|
-
return hash2;
|
|
405
|
-
};
|
|
406
|
-
|
|
407
|
-
// ../../node_modules/.pnpm/effect@3.19.13/node_modules/effect/dist/esm/Equal.js
|
|
408
|
-
var symbol2 = /* @__PURE__ */ Symbol.for("effect/Equal");
|
|
409
|
-
function equals() {
|
|
410
|
-
if (arguments.length === 1) {
|
|
411
|
-
return (self) => compareBoth(self, arguments[0]);
|
|
412
|
-
}
|
|
413
|
-
return compareBoth(arguments[0], arguments[1]);
|
|
414
|
-
}
|
|
415
|
-
function compareBoth(self, that) {
|
|
416
|
-
if (self === that) {
|
|
417
|
-
return true;
|
|
418
|
-
}
|
|
419
|
-
const selfType = typeof self;
|
|
420
|
-
if (selfType !== typeof that) {
|
|
421
|
-
return false;
|
|
422
|
-
}
|
|
423
|
-
if (selfType === "object" || selfType === "function") {
|
|
424
|
-
if (self !== null && that !== null) {
|
|
425
|
-
if (isEqual(self) && isEqual(that)) {
|
|
426
|
-
if (hash(self) === hash(that) && self[symbol2](that)) {
|
|
427
|
-
return true;
|
|
428
|
-
} else {
|
|
429
|
-
return structuralRegionState.enabled && structuralRegionState.tester ? structuralRegionState.tester(self, that) : false;
|
|
430
|
-
}
|
|
431
|
-
} else if (self instanceof Date && that instanceof Date) {
|
|
432
|
-
const t1 = self.getTime();
|
|
433
|
-
const t2 = that.getTime();
|
|
434
|
-
return t1 === t2 || Number.isNaN(t1) && Number.isNaN(t2);
|
|
435
|
-
} else if (self instanceof URL && that instanceof URL) {
|
|
436
|
-
return self.href === that.href;
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
if (structuralRegionState.enabled) {
|
|
440
|
-
if (Array.isArray(self) && Array.isArray(that)) {
|
|
441
|
-
return self.length === that.length && self.every((v, i) => compareBoth(v, that[i]));
|
|
442
|
-
}
|
|
443
|
-
if (Object.getPrototypeOf(self) === Object.prototype && Object.getPrototypeOf(self) === Object.prototype) {
|
|
444
|
-
const keysSelf = Object.keys(self);
|
|
445
|
-
const keysThat = Object.keys(that);
|
|
446
|
-
if (keysSelf.length === keysThat.length) {
|
|
447
|
-
for (const key of keysSelf) {
|
|
448
|
-
if (!(key in that && compareBoth(self[key], that[key]))) {
|
|
449
|
-
return structuralRegionState.tester ? structuralRegionState.tester(self, that) : false;
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
return true;
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
return structuralRegionState.tester ? structuralRegionState.tester(self, that) : false;
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
return structuralRegionState.enabled && structuralRegionState.tester ? structuralRegionState.tester(self, that) : false;
|
|
459
|
-
}
|
|
460
|
-
var isEqual = (u) => hasProperty(u, symbol2);
|
|
461
|
-
|
|
462
|
-
// ../../node_modules/.pnpm/effect@3.19.13/node_modules/effect/dist/esm/Inspectable.js
|
|
463
|
-
var NodeInspectSymbol = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
|
|
464
|
-
var toJSON = (x) => {
|
|
465
|
-
try {
|
|
466
|
-
if (hasProperty(x, "toJSON") && isFunction2(x["toJSON"]) && x["toJSON"].length === 0) {
|
|
467
|
-
return x.toJSON();
|
|
468
|
-
} else if (Array.isArray(x)) {
|
|
469
|
-
return x.map(toJSON);
|
|
470
|
-
}
|
|
471
|
-
} catch {
|
|
472
|
-
return {};
|
|
473
|
-
}
|
|
474
|
-
return redact(x);
|
|
475
|
-
};
|
|
476
|
-
var format = (x) => JSON.stringify(x, null, 2);
|
|
477
|
-
var BaseProto = {
|
|
478
|
-
toJSON() {
|
|
479
|
-
return toJSON(this);
|
|
480
|
-
},
|
|
481
|
-
[NodeInspectSymbol]() {
|
|
482
|
-
return this.toJSON();
|
|
483
|
-
},
|
|
484
|
-
toString() {
|
|
485
|
-
return format(this.toJSON());
|
|
486
|
-
}
|
|
487
|
-
};
|
|
488
|
-
var Class = class {
|
|
489
|
-
/**
|
|
490
|
-
* @since 2.0.0
|
|
491
|
-
*/
|
|
492
|
-
[NodeInspectSymbol]() {
|
|
493
|
-
return this.toJSON();
|
|
494
|
-
}
|
|
495
|
-
/**
|
|
496
|
-
* @since 2.0.0
|
|
497
|
-
*/
|
|
498
|
-
toString() {
|
|
499
|
-
return format(this.toJSON());
|
|
500
|
-
}
|
|
501
|
-
};
|
|
502
|
-
var toStringUnknown = (u, whitespace = 2) => {
|
|
503
|
-
if (typeof u === "string") {
|
|
504
|
-
return u;
|
|
505
|
-
}
|
|
506
|
-
try {
|
|
507
|
-
return typeof u === "object" ? stringifyCircular(u, whitespace) : String(u);
|
|
508
|
-
} catch {
|
|
509
|
-
return String(u);
|
|
510
|
-
}
|
|
511
|
-
};
|
|
512
|
-
var stringifyCircular = (obj, whitespace) => {
|
|
513
|
-
let cache = [];
|
|
514
|
-
const retVal = JSON.stringify(obj, (_key, value) => typeof value === "object" && value !== null ? cache.includes(value) ? void 0 : cache.push(value) && (redactableState.fiberRefs !== void 0 && isRedactable(value) ? value[symbolRedactable](redactableState.fiberRefs) : value) : value, whitespace);
|
|
515
|
-
cache = void 0;
|
|
516
|
-
return retVal;
|
|
517
|
-
};
|
|
518
|
-
var symbolRedactable = /* @__PURE__ */ Symbol.for("effect/Inspectable/Redactable");
|
|
519
|
-
var isRedactable = (u) => typeof u === "object" && u !== null && symbolRedactable in u;
|
|
520
|
-
var redactableState = /* @__PURE__ */ globalValue("effect/Inspectable/redactableState", () => ({
|
|
521
|
-
fiberRefs: void 0
|
|
522
|
-
}));
|
|
523
|
-
var redact = (u) => {
|
|
524
|
-
if (isRedactable(u) && redactableState.fiberRefs !== void 0) {
|
|
525
|
-
return u[symbolRedactable](redactableState.fiberRefs);
|
|
526
|
-
}
|
|
527
|
-
return u;
|
|
528
|
-
};
|
|
529
|
-
|
|
530
|
-
// ../../node_modules/.pnpm/effect@3.19.13/node_modules/effect/dist/esm/Pipeable.js
|
|
531
|
-
var pipeArguments = (self, args2) => {
|
|
532
|
-
switch (args2.length) {
|
|
533
|
-
case 0:
|
|
534
|
-
return self;
|
|
535
|
-
case 1:
|
|
536
|
-
return args2[0](self);
|
|
537
|
-
case 2:
|
|
538
|
-
return args2[1](args2[0](self));
|
|
539
|
-
case 3:
|
|
540
|
-
return args2[2](args2[1](args2[0](self)));
|
|
541
|
-
case 4:
|
|
542
|
-
return args2[3](args2[2](args2[1](args2[0](self))));
|
|
543
|
-
case 5:
|
|
544
|
-
return args2[4](args2[3](args2[2](args2[1](args2[0](self)))));
|
|
545
|
-
case 6:
|
|
546
|
-
return args2[5](args2[4](args2[3](args2[2](args2[1](args2[0](self))))));
|
|
547
|
-
case 7:
|
|
548
|
-
return args2[6](args2[5](args2[4](args2[3](args2[2](args2[1](args2[0](self)))))));
|
|
549
|
-
case 8:
|
|
550
|
-
return args2[7](args2[6](args2[5](args2[4](args2[3](args2[2](args2[1](args2[0](self))))))));
|
|
551
|
-
case 9:
|
|
552
|
-
return args2[8](args2[7](args2[6](args2[5](args2[4](args2[3](args2[2](args2[1](args2[0](self)))))))));
|
|
553
|
-
default: {
|
|
554
|
-
let ret = self;
|
|
555
|
-
for (let i = 0, len = args2.length; i < len; i++) {
|
|
556
|
-
ret = args2[i](ret);
|
|
557
|
-
}
|
|
558
|
-
return ret;
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
};
|
|
562
|
-
|
|
563
|
-
// ../../node_modules/.pnpm/effect@3.19.13/node_modules/effect/dist/esm/internal/opCodes/effect.js
|
|
564
|
-
var OP_COMMIT = "Commit";
|
|
565
|
-
var OP_FAILURE = "Failure";
|
|
566
|
-
var OP_WITH_RUNTIME = "WithRuntime";
|
|
567
|
-
|
|
568
|
-
// ../../node_modules/.pnpm/effect@3.19.13/node_modules/effect/dist/esm/internal/version.js
|
|
569
|
-
var moduleVersion = "3.19.13";
|
|
570
|
-
var getCurrentVersion = () => moduleVersion;
|
|
571
|
-
|
|
572
|
-
// ../../node_modules/.pnpm/effect@3.19.13/node_modules/effect/dist/esm/internal/effectable.js
|
|
573
|
-
var EffectTypeId = /* @__PURE__ */ Symbol.for("effect/Effect");
|
|
574
|
-
var StreamTypeId = /* @__PURE__ */ Symbol.for("effect/Stream");
|
|
575
|
-
var SinkTypeId = /* @__PURE__ */ Symbol.for("effect/Sink");
|
|
576
|
-
var ChannelTypeId = /* @__PURE__ */ Symbol.for("effect/Channel");
|
|
577
|
-
var effectVariance = {
|
|
578
|
-
/* c8 ignore next */
|
|
579
|
-
_R: (_) => _,
|
|
580
|
-
/* c8 ignore next */
|
|
581
|
-
_E: (_) => _,
|
|
582
|
-
/* c8 ignore next */
|
|
583
|
-
_A: (_) => _,
|
|
584
|
-
_V: /* @__PURE__ */ getCurrentVersion()
|
|
585
|
-
};
|
|
586
|
-
var sinkVariance = {
|
|
587
|
-
/* c8 ignore next */
|
|
588
|
-
_A: (_) => _,
|
|
589
|
-
/* c8 ignore next */
|
|
590
|
-
_In: (_) => _,
|
|
591
|
-
/* c8 ignore next */
|
|
592
|
-
_L: (_) => _,
|
|
593
|
-
/* c8 ignore next */
|
|
594
|
-
_E: (_) => _,
|
|
595
|
-
/* c8 ignore next */
|
|
596
|
-
_R: (_) => _
|
|
597
|
-
};
|
|
598
|
-
var channelVariance = {
|
|
599
|
-
/* c8 ignore next */
|
|
600
|
-
_Env: (_) => _,
|
|
601
|
-
/* c8 ignore next */
|
|
602
|
-
_InErr: (_) => _,
|
|
603
|
-
/* c8 ignore next */
|
|
604
|
-
_InElem: (_) => _,
|
|
605
|
-
/* c8 ignore next */
|
|
606
|
-
_InDone: (_) => _,
|
|
607
|
-
/* c8 ignore next */
|
|
608
|
-
_OutErr: (_) => _,
|
|
609
|
-
/* c8 ignore next */
|
|
610
|
-
_OutElem: (_) => _,
|
|
611
|
-
/* c8 ignore next */
|
|
612
|
-
_OutDone: (_) => _
|
|
613
|
-
};
|
|
614
|
-
var EffectPrototype = {
|
|
615
|
-
[EffectTypeId]: effectVariance,
|
|
616
|
-
[StreamTypeId]: effectVariance,
|
|
617
|
-
[SinkTypeId]: sinkVariance,
|
|
618
|
-
[ChannelTypeId]: channelVariance,
|
|
619
|
-
[symbol2](that) {
|
|
620
|
-
return this === that;
|
|
621
|
-
},
|
|
622
|
-
[symbol]() {
|
|
623
|
-
return cached(this, random(this));
|
|
624
|
-
},
|
|
625
|
-
[Symbol.iterator]() {
|
|
626
|
-
return new SingleShotGen(new YieldWrap(this));
|
|
627
|
-
},
|
|
628
|
-
pipe() {
|
|
629
|
-
return pipeArguments(this, arguments);
|
|
630
|
-
}
|
|
631
|
-
};
|
|
632
|
-
var StructuralPrototype = {
|
|
633
|
-
[symbol]() {
|
|
634
|
-
return cached(this, structure(this));
|
|
635
|
-
},
|
|
636
|
-
[symbol2](that) {
|
|
637
|
-
const selfKeys = Object.keys(this);
|
|
638
|
-
const thatKeys = Object.keys(that);
|
|
639
|
-
if (selfKeys.length !== thatKeys.length) {
|
|
640
|
-
return false;
|
|
641
|
-
}
|
|
642
|
-
for (const key of selfKeys) {
|
|
643
|
-
if (!(key in that && equals(this[key], that[key]))) {
|
|
644
|
-
return false;
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
|
-
return true;
|
|
648
|
-
}
|
|
649
|
-
};
|
|
650
|
-
var CommitPrototype = {
|
|
651
|
-
...EffectPrototype,
|
|
652
|
-
_op: OP_COMMIT
|
|
653
|
-
};
|
|
654
|
-
var StructuralCommitPrototype = {
|
|
655
|
-
...CommitPrototype,
|
|
656
|
-
...StructuralPrototype
|
|
657
|
-
};
|
|
658
|
-
|
|
659
|
-
// ../../node_modules/.pnpm/effect@3.19.13/node_modules/effect/dist/esm/internal/option.js
|
|
660
|
-
var TypeId = /* @__PURE__ */ Symbol.for("effect/Option");
|
|
661
|
-
var CommonProto = {
|
|
662
|
-
...EffectPrototype,
|
|
663
|
-
[TypeId]: {
|
|
664
|
-
_A: (_) => _
|
|
665
|
-
},
|
|
666
|
-
[NodeInspectSymbol]() {
|
|
667
|
-
return this.toJSON();
|
|
668
|
-
},
|
|
669
|
-
toString() {
|
|
670
|
-
return format(this.toJSON());
|
|
671
|
-
}
|
|
672
|
-
};
|
|
673
|
-
var SomeProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(CommonProto), {
|
|
674
|
-
_tag: "Some",
|
|
675
|
-
_op: "Some",
|
|
676
|
-
[symbol2](that) {
|
|
677
|
-
return isOption(that) && isSome(that) && equals(this.value, that.value);
|
|
678
|
-
},
|
|
679
|
-
[symbol]() {
|
|
680
|
-
return cached(this, combine(hash(this._tag))(hash(this.value)));
|
|
681
|
-
},
|
|
682
|
-
toJSON() {
|
|
683
|
-
return {
|
|
684
|
-
_id: "Option",
|
|
685
|
-
_tag: this._tag,
|
|
686
|
-
value: toJSON(this.value)
|
|
687
|
-
};
|
|
688
|
-
}
|
|
689
|
-
});
|
|
690
|
-
var NoneHash = /* @__PURE__ */ hash("None");
|
|
691
|
-
var NoneProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(CommonProto), {
|
|
692
|
-
_tag: "None",
|
|
693
|
-
_op: "None",
|
|
694
|
-
[symbol2](that) {
|
|
695
|
-
return isOption(that) && isNone(that);
|
|
696
|
-
},
|
|
697
|
-
[symbol]() {
|
|
698
|
-
return NoneHash;
|
|
699
|
-
},
|
|
700
|
-
toJSON() {
|
|
701
|
-
return {
|
|
702
|
-
_id: "Option",
|
|
703
|
-
_tag: this._tag
|
|
704
|
-
};
|
|
705
|
-
}
|
|
706
|
-
});
|
|
707
|
-
var isOption = (input) => hasProperty(input, TypeId);
|
|
708
|
-
var isNone = (fa) => fa._tag === "None";
|
|
709
|
-
var isSome = (fa) => fa._tag === "Some";
|
|
710
|
-
var none = /* @__PURE__ */ Object.create(NoneProto);
|
|
711
|
-
var some = (value) => {
|
|
712
|
-
const a = Object.create(SomeProto);
|
|
713
|
-
a.value = value;
|
|
714
|
-
return a;
|
|
715
|
-
};
|
|
716
|
-
|
|
717
|
-
// ../../node_modules/.pnpm/effect@3.19.13/node_modules/effect/dist/esm/internal/either.js
|
|
718
|
-
var TypeId2 = /* @__PURE__ */ Symbol.for("effect/Either");
|
|
719
|
-
var CommonProto2 = {
|
|
720
|
-
...EffectPrototype,
|
|
721
|
-
[TypeId2]: {
|
|
722
|
-
_R: (_) => _
|
|
723
|
-
},
|
|
724
|
-
[NodeInspectSymbol]() {
|
|
725
|
-
return this.toJSON();
|
|
726
|
-
},
|
|
727
|
-
toString() {
|
|
728
|
-
return format(this.toJSON());
|
|
729
|
-
}
|
|
730
|
-
};
|
|
731
|
-
var RightProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(CommonProto2), {
|
|
732
|
-
_tag: "Right",
|
|
733
|
-
_op: "Right",
|
|
734
|
-
[symbol2](that) {
|
|
735
|
-
return isEither(that) && isRight(that) && equals(this.right, that.right);
|
|
736
|
-
},
|
|
737
|
-
[symbol]() {
|
|
738
|
-
return combine(hash(this._tag))(hash(this.right));
|
|
739
|
-
},
|
|
740
|
-
toJSON() {
|
|
741
|
-
return {
|
|
742
|
-
_id: "Either",
|
|
743
|
-
_tag: this._tag,
|
|
744
|
-
right: toJSON(this.right)
|
|
745
|
-
};
|
|
746
|
-
}
|
|
747
|
-
});
|
|
748
|
-
var LeftProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(CommonProto2), {
|
|
749
|
-
_tag: "Left",
|
|
750
|
-
_op: "Left",
|
|
751
|
-
[symbol2](that) {
|
|
752
|
-
return isEither(that) && isLeft(that) && equals(this.left, that.left);
|
|
753
|
-
},
|
|
754
|
-
[symbol]() {
|
|
755
|
-
return combine(hash(this._tag))(hash(this.left));
|
|
756
|
-
},
|
|
757
|
-
toJSON() {
|
|
758
|
-
return {
|
|
759
|
-
_id: "Either",
|
|
760
|
-
_tag: this._tag,
|
|
761
|
-
left: toJSON(this.left)
|
|
762
|
-
};
|
|
763
|
-
}
|
|
764
|
-
});
|
|
765
|
-
var isEither = (input) => hasProperty(input, TypeId2);
|
|
766
|
-
var isLeft = (ma) => ma._tag === "Left";
|
|
767
|
-
var isRight = (ma) => ma._tag === "Right";
|
|
768
|
-
var left = (left3) => {
|
|
769
|
-
const a = Object.create(LeftProto);
|
|
770
|
-
a.left = left3;
|
|
771
|
-
return a;
|
|
772
|
-
};
|
|
773
|
-
var right = (right3) => {
|
|
774
|
-
const a = Object.create(RightProto);
|
|
775
|
-
a.right = right3;
|
|
776
|
-
return a;
|
|
777
|
-
};
|
|
778
|
-
|
|
779
|
-
// ../../node_modules/.pnpm/effect@3.19.13/node_modules/effect/dist/esm/Either.js
|
|
780
|
-
var right2 = right;
|
|
781
|
-
var left2 = left;
|
|
782
|
-
|
|
783
|
-
// ../../node_modules/.pnpm/effect@3.19.13/node_modules/effect/dist/esm/Option.js
|
|
784
|
-
var none2 = () => none;
|
|
785
|
-
var some2 = some;
|
|
786
|
-
var isNone2 = isNone;
|
|
787
|
-
var isSome2 = isSome;
|
|
788
|
-
var getOrElse = /* @__PURE__ */ dual(2, (self, onNone) => isNone2(self) ? onNone() : self.value);
|
|
789
|
-
var getOrUndefined = /* @__PURE__ */ getOrElse(constUndefined);
|
|
790
|
-
|
|
791
|
-
// ../../node_modules/.pnpm/effect@3.19.13/node_modules/effect/dist/esm/Array.js
|
|
792
|
-
var fromIterable = (collection) => Array.isArray(collection) ? collection : Array.from(collection);
|
|
793
|
-
var isArray = Array.isArray;
|
|
794
|
-
var reverse = (self) => Array.from(self).reverse();
|
|
795
|
-
var reduce = /* @__PURE__ */ dual(3, (self, b, f) => fromIterable(self).reduce((b2, a, i) => f(b2, a, i), b));
|
|
796
|
-
|
|
797
|
-
// ../../node_modules/.pnpm/effect@3.19.13/node_modules/effect/dist/esm/Chunk.js
|
|
798
|
-
var TypeId3 = /* @__PURE__ */ Symbol.for("effect/Chunk");
|
|
799
|
-
function copy(src, srcPos, dest, destPos, len) {
|
|
800
|
-
for (let i = srcPos; i < Math.min(src.length, srcPos + len); i++) {
|
|
801
|
-
dest[destPos + i - srcPos] = src[i];
|
|
802
|
-
}
|
|
803
|
-
return dest;
|
|
804
|
-
}
|
|
805
|
-
var emptyArray = [];
|
|
806
|
-
var getEquivalence = (isEquivalent) => make((self, that) => self.length === that.length && toReadonlyArray(self).every((value, i) => isEquivalent(value, unsafeGet(that, i))));
|
|
807
|
-
var _equivalence = /* @__PURE__ */ getEquivalence(equals);
|
|
808
|
-
var ChunkProto = {
|
|
809
|
-
[TypeId3]: {
|
|
810
|
-
_A: (_) => _
|
|
811
|
-
},
|
|
812
|
-
toString() {
|
|
813
|
-
return format(this.toJSON());
|
|
814
|
-
},
|
|
815
|
-
toJSON() {
|
|
816
|
-
return {
|
|
817
|
-
_id: "Chunk",
|
|
818
|
-
values: toReadonlyArray(this).map(toJSON)
|
|
819
|
-
};
|
|
820
|
-
},
|
|
821
|
-
[NodeInspectSymbol]() {
|
|
822
|
-
return this.toJSON();
|
|
823
|
-
},
|
|
824
|
-
[symbol2](that) {
|
|
825
|
-
return isChunk(that) && _equivalence(this, that);
|
|
826
|
-
},
|
|
827
|
-
[symbol]() {
|
|
828
|
-
return cached(this, array(toReadonlyArray(this)));
|
|
829
|
-
},
|
|
830
|
-
[Symbol.iterator]() {
|
|
831
|
-
switch (this.backing._tag) {
|
|
832
|
-
case "IArray": {
|
|
833
|
-
return this.backing.array[Symbol.iterator]();
|
|
834
|
-
}
|
|
835
|
-
case "IEmpty": {
|
|
836
|
-
return emptyArray[Symbol.iterator]();
|
|
837
|
-
}
|
|
838
|
-
default: {
|
|
839
|
-
return toReadonlyArray(this)[Symbol.iterator]();
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
},
|
|
843
|
-
pipe() {
|
|
844
|
-
return pipeArguments(this, arguments);
|
|
845
|
-
}
|
|
846
|
-
};
|
|
847
|
-
var makeChunk = (backing) => {
|
|
848
|
-
const chunk = Object.create(ChunkProto);
|
|
849
|
-
chunk.backing = backing;
|
|
850
|
-
switch (backing._tag) {
|
|
851
|
-
case "IEmpty": {
|
|
852
|
-
chunk.length = 0;
|
|
853
|
-
chunk.depth = 0;
|
|
854
|
-
chunk.left = chunk;
|
|
855
|
-
chunk.right = chunk;
|
|
856
|
-
break;
|
|
857
|
-
}
|
|
858
|
-
case "IConcat": {
|
|
859
|
-
chunk.length = backing.left.length + backing.right.length;
|
|
860
|
-
chunk.depth = 1 + Math.max(backing.left.depth, backing.right.depth);
|
|
861
|
-
chunk.left = backing.left;
|
|
862
|
-
chunk.right = backing.right;
|
|
863
|
-
break;
|
|
864
|
-
}
|
|
865
|
-
case "IArray": {
|
|
866
|
-
chunk.length = backing.array.length;
|
|
867
|
-
chunk.depth = 0;
|
|
868
|
-
chunk.left = _empty;
|
|
869
|
-
chunk.right = _empty;
|
|
870
|
-
break;
|
|
871
|
-
}
|
|
872
|
-
case "ISingleton": {
|
|
873
|
-
chunk.length = 1;
|
|
874
|
-
chunk.depth = 0;
|
|
875
|
-
chunk.left = _empty;
|
|
876
|
-
chunk.right = _empty;
|
|
877
|
-
break;
|
|
878
|
-
}
|
|
879
|
-
case "ISlice": {
|
|
880
|
-
chunk.length = backing.length;
|
|
881
|
-
chunk.depth = backing.chunk.depth + 1;
|
|
882
|
-
chunk.left = _empty;
|
|
883
|
-
chunk.right = _empty;
|
|
884
|
-
break;
|
|
885
|
-
}
|
|
886
|
-
}
|
|
887
|
-
return chunk;
|
|
888
|
-
};
|
|
889
|
-
var isChunk = (u) => hasProperty(u, TypeId3);
|
|
890
|
-
var _empty = /* @__PURE__ */ makeChunk({
|
|
891
|
-
_tag: "IEmpty"
|
|
892
|
-
});
|
|
893
|
-
var empty = () => _empty;
|
|
894
|
-
var make2 = (...as2) => unsafeFromNonEmptyArray(as2);
|
|
895
|
-
var of = (a) => makeChunk({
|
|
896
|
-
_tag: "ISingleton",
|
|
897
|
-
a
|
|
898
|
-
});
|
|
899
|
-
var fromIterable2 = (self) => isChunk(self) ? self : unsafeFromArray(fromIterable(self));
|
|
900
|
-
var copyToArray = (self, array2, initial) => {
|
|
901
|
-
switch (self.backing._tag) {
|
|
902
|
-
case "IArray": {
|
|
903
|
-
copy(self.backing.array, 0, array2, initial, self.length);
|
|
904
|
-
break;
|
|
905
|
-
}
|
|
906
|
-
case "IConcat": {
|
|
907
|
-
copyToArray(self.left, array2, initial);
|
|
908
|
-
copyToArray(self.right, array2, initial + self.left.length);
|
|
909
|
-
break;
|
|
910
|
-
}
|
|
911
|
-
case "ISingleton": {
|
|
912
|
-
array2[initial] = self.backing.a;
|
|
913
|
-
break;
|
|
914
|
-
}
|
|
915
|
-
case "ISlice": {
|
|
916
|
-
let i = 0;
|
|
917
|
-
let j = initial;
|
|
918
|
-
while (i < self.length) {
|
|
919
|
-
array2[j] = unsafeGet(self, i);
|
|
920
|
-
i += 1;
|
|
921
|
-
j += 1;
|
|
922
|
-
}
|
|
923
|
-
break;
|
|
924
|
-
}
|
|
925
|
-
}
|
|
926
|
-
};
|
|
927
|
-
var toReadonlyArray_ = (self) => {
|
|
928
|
-
switch (self.backing._tag) {
|
|
929
|
-
case "IEmpty": {
|
|
930
|
-
return emptyArray;
|
|
931
|
-
}
|
|
932
|
-
case "IArray": {
|
|
933
|
-
return self.backing.array;
|
|
934
|
-
}
|
|
935
|
-
default: {
|
|
936
|
-
const arr = new Array(self.length);
|
|
937
|
-
copyToArray(self, arr, 0);
|
|
938
|
-
self.backing = {
|
|
939
|
-
_tag: "IArray",
|
|
940
|
-
array: arr
|
|
941
|
-
};
|
|
942
|
-
self.left = _empty;
|
|
943
|
-
self.right = _empty;
|
|
944
|
-
self.depth = 0;
|
|
945
|
-
return arr;
|
|
946
|
-
}
|
|
947
|
-
}
|
|
948
|
-
};
|
|
949
|
-
var toReadonlyArray = toReadonlyArray_;
|
|
950
|
-
var reverseChunk = (self) => {
|
|
951
|
-
switch (self.backing._tag) {
|
|
952
|
-
case "IEmpty":
|
|
953
|
-
case "ISingleton":
|
|
954
|
-
return self;
|
|
955
|
-
case "IArray": {
|
|
956
|
-
return makeChunk({
|
|
957
|
-
_tag: "IArray",
|
|
958
|
-
array: reverse(self.backing.array)
|
|
959
|
-
});
|
|
960
|
-
}
|
|
961
|
-
case "IConcat": {
|
|
962
|
-
return makeChunk({
|
|
963
|
-
_tag: "IConcat",
|
|
964
|
-
left: reverse2(self.backing.right),
|
|
965
|
-
right: reverse2(self.backing.left)
|
|
966
|
-
});
|
|
967
|
-
}
|
|
968
|
-
case "ISlice":
|
|
969
|
-
return unsafeFromArray(reverse(toReadonlyArray(self)));
|
|
970
|
-
}
|
|
971
|
-
};
|
|
972
|
-
var reverse2 = reverseChunk;
|
|
973
|
-
var unsafeFromArray = (self) => self.length === 0 ? empty() : self.length === 1 ? of(self[0]) : makeChunk({
|
|
974
|
-
_tag: "IArray",
|
|
975
|
-
array: self
|
|
976
|
-
});
|
|
977
|
-
var unsafeFromNonEmptyArray = (self) => unsafeFromArray(self);
|
|
978
|
-
var unsafeGet = /* @__PURE__ */ dual(2, (self, index) => {
|
|
979
|
-
switch (self.backing._tag) {
|
|
980
|
-
case "IEmpty": {
|
|
981
|
-
throw new Error(`Index out of bounds`);
|
|
982
|
-
}
|
|
983
|
-
case "ISingleton": {
|
|
984
|
-
if (index !== 0) {
|
|
985
|
-
throw new Error(`Index out of bounds`);
|
|
986
|
-
}
|
|
987
|
-
return self.backing.a;
|
|
988
|
-
}
|
|
989
|
-
case "IArray": {
|
|
990
|
-
if (index >= self.length || index < 0) {
|
|
991
|
-
throw new Error(`Index out of bounds`);
|
|
992
|
-
}
|
|
993
|
-
return self.backing.array[index];
|
|
994
|
-
}
|
|
995
|
-
case "IConcat": {
|
|
996
|
-
return index < self.left.length ? unsafeGet(self.left, index) : unsafeGet(self.right, index - self.left.length);
|
|
997
|
-
}
|
|
998
|
-
case "ISlice": {
|
|
999
|
-
return unsafeGet(self.backing.chunk, index + self.backing.offset);
|
|
1000
|
-
}
|
|
1001
|
-
}
|
|
1002
|
-
});
|
|
1003
|
-
var prepend = /* @__PURE__ */ dual(2, (self, elem) => appendAll(of(elem), self));
|
|
1004
|
-
var appendAll = /* @__PURE__ */ dual(2, (self, that) => {
|
|
1005
|
-
if (self.backing._tag === "IEmpty") {
|
|
1006
|
-
return that;
|
|
1007
|
-
}
|
|
1008
|
-
if (that.backing._tag === "IEmpty") {
|
|
1009
|
-
return self;
|
|
1010
|
-
}
|
|
1011
|
-
const diff = that.depth - self.depth;
|
|
1012
|
-
if (Math.abs(diff) <= 1) {
|
|
1013
|
-
return makeChunk({
|
|
1014
|
-
_tag: "IConcat",
|
|
1015
|
-
left: self,
|
|
1016
|
-
right: that
|
|
1017
|
-
});
|
|
1018
|
-
} else if (diff < -1) {
|
|
1019
|
-
if (self.left.depth >= self.right.depth) {
|
|
1020
|
-
const nr = appendAll(self.right, that);
|
|
1021
|
-
return makeChunk({
|
|
1022
|
-
_tag: "IConcat",
|
|
1023
|
-
left: self.left,
|
|
1024
|
-
right: nr
|
|
1025
|
-
});
|
|
1026
|
-
} else {
|
|
1027
|
-
const nrr = appendAll(self.right.right, that);
|
|
1028
|
-
if (nrr.depth === self.depth - 3) {
|
|
1029
|
-
const nr = makeChunk({
|
|
1030
|
-
_tag: "IConcat",
|
|
1031
|
-
left: self.right.left,
|
|
1032
|
-
right: nrr
|
|
1033
|
-
});
|
|
1034
|
-
return makeChunk({
|
|
1035
|
-
_tag: "IConcat",
|
|
1036
|
-
left: self.left,
|
|
1037
|
-
right: nr
|
|
1038
|
-
});
|
|
1039
|
-
} else {
|
|
1040
|
-
const nl = makeChunk({
|
|
1041
|
-
_tag: "IConcat",
|
|
1042
|
-
left: self.left,
|
|
1043
|
-
right: self.right.left
|
|
1044
|
-
});
|
|
1045
|
-
return makeChunk({
|
|
1046
|
-
_tag: "IConcat",
|
|
1047
|
-
left: nl,
|
|
1048
|
-
right: nrr
|
|
1049
|
-
});
|
|
1050
|
-
}
|
|
1051
|
-
}
|
|
1052
|
-
} else {
|
|
1053
|
-
if (that.right.depth >= that.left.depth) {
|
|
1054
|
-
const nl = appendAll(self, that.left);
|
|
1055
|
-
return makeChunk({
|
|
1056
|
-
_tag: "IConcat",
|
|
1057
|
-
left: nl,
|
|
1058
|
-
right: that.right
|
|
1059
|
-
});
|
|
1060
|
-
} else {
|
|
1061
|
-
const nll = appendAll(self, that.left.left);
|
|
1062
|
-
if (nll.depth === that.depth - 3) {
|
|
1063
|
-
const nl = makeChunk({
|
|
1064
|
-
_tag: "IConcat",
|
|
1065
|
-
left: nll,
|
|
1066
|
-
right: that.left.right
|
|
1067
|
-
});
|
|
1068
|
-
return makeChunk({
|
|
1069
|
-
_tag: "IConcat",
|
|
1070
|
-
left: nl,
|
|
1071
|
-
right: that.right
|
|
1072
|
-
});
|
|
1073
|
-
} else {
|
|
1074
|
-
const nr = makeChunk({
|
|
1075
|
-
_tag: "IConcat",
|
|
1076
|
-
left: that.left.right,
|
|
1077
|
-
right: that.right
|
|
1078
|
-
});
|
|
1079
|
-
return makeChunk({
|
|
1080
|
-
_tag: "IConcat",
|
|
1081
|
-
left: nll,
|
|
1082
|
-
right: nr
|
|
1083
|
-
});
|
|
1084
|
-
}
|
|
1085
|
-
}
|
|
1086
|
-
}
|
|
1087
|
-
});
|
|
1088
|
-
var isEmpty = (self) => self.length === 0;
|
|
1089
|
-
var isNonEmpty = (self) => self.length > 0;
|
|
1090
|
-
var unsafeHead = (self) => unsafeGet(self, 0);
|
|
1091
|
-
var headNonEmpty = unsafeHead;
|
|
1092
|
-
|
|
1093
|
-
// ../../node_modules/.pnpm/effect@3.19.13/node_modules/effect/dist/esm/internal/context.js
|
|
1094
|
-
var TagTypeId = /* @__PURE__ */ Symbol.for("effect/Context/Tag");
|
|
1095
|
-
var ReferenceTypeId = /* @__PURE__ */ Symbol.for("effect/Context/Reference");
|
|
1096
|
-
var STMSymbolKey = "effect/STM";
|
|
1097
|
-
var STMTypeId = /* @__PURE__ */ Symbol.for(STMSymbolKey);
|
|
1098
|
-
var TagProto = {
|
|
1099
|
-
...EffectPrototype,
|
|
1100
|
-
_op: "Tag",
|
|
1101
|
-
[STMTypeId]: effectVariance,
|
|
1102
|
-
[TagTypeId]: {
|
|
1103
|
-
_Service: (_) => _,
|
|
1104
|
-
_Identifier: (_) => _
|
|
1105
|
-
},
|
|
1106
|
-
toString() {
|
|
1107
|
-
return format(this.toJSON());
|
|
1108
|
-
},
|
|
1109
|
-
toJSON() {
|
|
1110
|
-
return {
|
|
1111
|
-
_id: "Tag",
|
|
1112
|
-
key: this.key,
|
|
1113
|
-
stack: this.stack
|
|
1114
|
-
};
|
|
1115
|
-
},
|
|
1116
|
-
[NodeInspectSymbol]() {
|
|
1117
|
-
return this.toJSON();
|
|
1118
|
-
},
|
|
1119
|
-
of(self) {
|
|
1120
|
-
return self;
|
|
1121
|
-
},
|
|
1122
|
-
context(self) {
|
|
1123
|
-
return make3(this, self);
|
|
1124
|
-
}
|
|
1125
|
-
};
|
|
1126
|
-
var ReferenceProto = {
|
|
1127
|
-
...TagProto,
|
|
1128
|
-
[ReferenceTypeId]: ReferenceTypeId
|
|
1129
|
-
};
|
|
1130
|
-
var Tag = (id) => () => {
|
|
1131
|
-
const limit = Error.stackTraceLimit;
|
|
1132
|
-
Error.stackTraceLimit = 2;
|
|
1133
|
-
const creationError = new Error();
|
|
1134
|
-
Error.stackTraceLimit = limit;
|
|
1135
|
-
function TagClass() {
|
|
1136
|
-
}
|
|
1137
|
-
Object.setPrototypeOf(TagClass, TagProto);
|
|
1138
|
-
TagClass.key = id;
|
|
1139
|
-
Object.defineProperty(TagClass, "stack", {
|
|
1140
|
-
get() {
|
|
1141
|
-
return creationError.stack;
|
|
1142
|
-
}
|
|
1143
|
-
});
|
|
1144
|
-
return TagClass;
|
|
1145
|
-
};
|
|
1146
|
-
var Reference = () => (id, options) => {
|
|
1147
|
-
const limit = Error.stackTraceLimit;
|
|
1148
|
-
Error.stackTraceLimit = 2;
|
|
1149
|
-
const creationError = new Error();
|
|
1150
|
-
Error.stackTraceLimit = limit;
|
|
1151
|
-
function ReferenceClass() {
|
|
1152
|
-
}
|
|
1153
|
-
Object.setPrototypeOf(ReferenceClass, ReferenceProto);
|
|
1154
|
-
ReferenceClass.key = id;
|
|
1155
|
-
ReferenceClass.defaultValue = options.defaultValue;
|
|
1156
|
-
Object.defineProperty(ReferenceClass, "stack", {
|
|
1157
|
-
get() {
|
|
1158
|
-
return creationError.stack;
|
|
1159
|
-
}
|
|
1160
|
-
});
|
|
1161
|
-
return ReferenceClass;
|
|
1162
|
-
};
|
|
1163
|
-
var TypeId4 = /* @__PURE__ */ Symbol.for("effect/Context");
|
|
1164
|
-
var ContextProto = {
|
|
1165
|
-
[TypeId4]: {
|
|
1166
|
-
_Services: (_) => _
|
|
1167
|
-
},
|
|
1168
|
-
[symbol2](that) {
|
|
1169
|
-
if (isContext(that)) {
|
|
1170
|
-
if (this.unsafeMap.size === that.unsafeMap.size) {
|
|
1171
|
-
for (const k of this.unsafeMap.keys()) {
|
|
1172
|
-
if (!that.unsafeMap.has(k) || !equals(this.unsafeMap.get(k), that.unsafeMap.get(k))) {
|
|
1173
|
-
return false;
|
|
1174
|
-
}
|
|
1175
|
-
}
|
|
1176
|
-
return true;
|
|
1177
|
-
}
|
|
1178
|
-
}
|
|
1179
|
-
return false;
|
|
1180
|
-
},
|
|
1181
|
-
[symbol]() {
|
|
1182
|
-
return cached(this, number(this.unsafeMap.size));
|
|
1183
|
-
},
|
|
1184
|
-
pipe() {
|
|
1185
|
-
return pipeArguments(this, arguments);
|
|
1186
|
-
},
|
|
1187
|
-
toString() {
|
|
1188
|
-
return format(this.toJSON());
|
|
1189
|
-
},
|
|
1190
|
-
toJSON() {
|
|
1191
|
-
return {
|
|
1192
|
-
_id: "Context",
|
|
1193
|
-
services: Array.from(this.unsafeMap).map(toJSON)
|
|
1194
|
-
};
|
|
1195
|
-
},
|
|
1196
|
-
[NodeInspectSymbol]() {
|
|
1197
|
-
return this.toJSON();
|
|
1198
|
-
}
|
|
1199
|
-
};
|
|
1200
|
-
var makeContext = (unsafeMap) => {
|
|
1201
|
-
const context = Object.create(ContextProto);
|
|
1202
|
-
context.unsafeMap = unsafeMap;
|
|
1203
|
-
return context;
|
|
1204
|
-
};
|
|
1205
|
-
var serviceNotFoundError = (tag) => {
|
|
1206
|
-
const error = new Error(`Service not found${tag.key ? `: ${String(tag.key)}` : ""}`);
|
|
1207
|
-
if (tag.stack) {
|
|
1208
|
-
const lines = tag.stack.split("\n");
|
|
1209
|
-
if (lines.length > 2) {
|
|
1210
|
-
const afterAt = lines[2].match(/at (.*)/);
|
|
1211
|
-
if (afterAt) {
|
|
1212
|
-
error.message = error.message + ` (defined at ${afterAt[1]})`;
|
|
1213
|
-
}
|
|
1214
|
-
}
|
|
1215
|
-
}
|
|
1216
|
-
if (error.stack) {
|
|
1217
|
-
const lines = error.stack.split("\n");
|
|
1218
|
-
lines.splice(1, 3);
|
|
1219
|
-
error.stack = lines.join("\n");
|
|
1220
|
-
}
|
|
1221
|
-
return error;
|
|
1222
|
-
};
|
|
1223
|
-
var isContext = (u) => hasProperty(u, TypeId4);
|
|
1224
|
-
var make3 = (tag, service2) => makeContext(/* @__PURE__ */ new Map([[tag.key, service2]]));
|
|
1225
|
-
var add = /* @__PURE__ */ dual(3, (self, tag, service2) => {
|
|
1226
|
-
const map7 = new Map(self.unsafeMap);
|
|
1227
|
-
map7.set(tag.key, service2);
|
|
1228
|
-
return makeContext(map7);
|
|
1229
|
-
});
|
|
1230
|
-
var defaultValueCache = /* @__PURE__ */ globalValue("effect/Context/defaultValueCache", () => /* @__PURE__ */ new Map());
|
|
1231
|
-
var getDefaultValue = (tag) => {
|
|
1232
|
-
if (defaultValueCache.has(tag.key)) {
|
|
1233
|
-
return defaultValueCache.get(tag.key);
|
|
1234
|
-
}
|
|
1235
|
-
const value = tag.defaultValue();
|
|
1236
|
-
defaultValueCache.set(tag.key, value);
|
|
1237
|
-
return value;
|
|
1238
|
-
};
|
|
1239
|
-
var unsafeGetReference = (self, tag) => {
|
|
1240
|
-
return self.unsafeMap.has(tag.key) ? self.unsafeMap.get(tag.key) : getDefaultValue(tag);
|
|
1241
|
-
};
|
|
1242
|
-
var unsafeGet2 = /* @__PURE__ */ dual(2, (self, tag) => {
|
|
1243
|
-
if (!self.unsafeMap.has(tag.key)) {
|
|
1244
|
-
if (ReferenceTypeId in tag) return getDefaultValue(tag);
|
|
1245
|
-
throw serviceNotFoundError(tag);
|
|
1246
|
-
}
|
|
1247
|
-
return self.unsafeMap.get(tag.key);
|
|
1248
|
-
});
|
|
1249
|
-
var merge = /* @__PURE__ */ dual(2, (self, that) => {
|
|
1250
|
-
const map7 = new Map(self.unsafeMap);
|
|
1251
|
-
for (const [tag, s] of that.unsafeMap) {
|
|
1252
|
-
map7.set(tag, s);
|
|
1253
|
-
}
|
|
1254
|
-
return makeContext(map7);
|
|
1255
|
-
});
|
|
1256
|
-
|
|
1257
|
-
// ../../node_modules/.pnpm/effect@3.19.13/node_modules/effect/dist/esm/Context.js
|
|
1258
|
-
var make4 = make3;
|
|
1259
|
-
var add2 = add;
|
|
1260
|
-
var unsafeGet3 = unsafeGet2;
|
|
1261
|
-
var merge2 = merge;
|
|
1262
|
-
var Tag2 = Tag;
|
|
1263
|
-
var Reference2 = Reference;
|
|
1264
|
-
|
|
1265
|
-
// ../../node_modules/.pnpm/effect@3.19.13/node_modules/effect/dist/esm/internal/hashMap/config.js
|
|
1266
|
-
var SIZE = 5;
|
|
1267
|
-
var BUCKET_SIZE = /* @__PURE__ */ Math.pow(2, SIZE);
|
|
1268
|
-
var MASK = BUCKET_SIZE - 1;
|
|
1269
|
-
var MAX_INDEX_NODE = BUCKET_SIZE / 2;
|
|
1270
|
-
var MIN_ARRAY_NODE = BUCKET_SIZE / 4;
|
|
1271
|
-
|
|
1272
|
-
// ../../node_modules/.pnpm/effect@3.19.13/node_modules/effect/dist/esm/internal/hashMap/bitwise.js
|
|
1273
|
-
function popcount(x) {
|
|
1274
|
-
x -= x >> 1 & 1431655765;
|
|
1275
|
-
x = (x & 858993459) + (x >> 2 & 858993459);
|
|
1276
|
-
x = x + (x >> 4) & 252645135;
|
|
1277
|
-
x += x >> 8;
|
|
1278
|
-
x += x >> 16;
|
|
1279
|
-
return x & 127;
|
|
1280
|
-
}
|
|
1281
|
-
function hashFragment(shift, h) {
|
|
1282
|
-
return h >>> shift & MASK;
|
|
1283
|
-
}
|
|
1284
|
-
function toBitmap(x) {
|
|
1285
|
-
return 1 << x;
|
|
1286
|
-
}
|
|
1287
|
-
function fromBitmap(bitmap, bit) {
|
|
1288
|
-
return popcount(bitmap & bit - 1);
|
|
1289
|
-
}
|
|
1290
|
-
|
|
1291
|
-
// ../../node_modules/.pnpm/effect@3.19.13/node_modules/effect/dist/esm/internal/stack.js
|
|
1292
|
-
var make5 = (value, previous) => ({
|
|
1293
|
-
value,
|
|
1294
|
-
previous
|
|
1295
|
-
});
|
|
1296
|
-
|
|
1297
|
-
// ../../node_modules/.pnpm/effect@3.19.13/node_modules/effect/dist/esm/internal/hashMap/array.js
|
|
1298
|
-
function arrayUpdate(mutate2, at, v, arr) {
|
|
1299
|
-
let out = arr;
|
|
1300
|
-
if (!mutate2) {
|
|
1301
|
-
const len = arr.length;
|
|
1302
|
-
out = new Array(len);
|
|
1303
|
-
for (let i = 0; i < len; ++i) out[i] = arr[i];
|
|
1304
|
-
}
|
|
1305
|
-
out[at] = v;
|
|
1306
|
-
return out;
|
|
1307
|
-
}
|
|
1308
|
-
function arraySpliceOut(mutate2, at, arr) {
|
|
1309
|
-
const newLen = arr.length - 1;
|
|
1310
|
-
let i = 0;
|
|
1311
|
-
let g = 0;
|
|
1312
|
-
let out = arr;
|
|
1313
|
-
if (mutate2) {
|
|
1314
|
-
i = g = at;
|
|
1315
|
-
} else {
|
|
1316
|
-
out = new Array(newLen);
|
|
1317
|
-
while (i < at) out[g++] = arr[i++];
|
|
1318
|
-
}
|
|
1319
|
-
++i;
|
|
1320
|
-
while (i <= newLen) out[g++] = arr[i++];
|
|
1321
|
-
if (mutate2) {
|
|
1322
|
-
out.length = newLen;
|
|
1323
|
-
}
|
|
1324
|
-
return out;
|
|
1325
|
-
}
|
|
1326
|
-
function arraySpliceIn(mutate2, at, v, arr) {
|
|
1327
|
-
const len = arr.length;
|
|
1328
|
-
if (mutate2) {
|
|
1329
|
-
let i2 = len;
|
|
1330
|
-
while (i2 >= at) arr[i2--] = arr[i2];
|
|
1331
|
-
arr[at] = v;
|
|
1332
|
-
return arr;
|
|
1333
|
-
}
|
|
1334
|
-
let i = 0, g = 0;
|
|
1335
|
-
const out = new Array(len + 1);
|
|
1336
|
-
while (i < at) out[g++] = arr[i++];
|
|
1337
|
-
out[at] = v;
|
|
1338
|
-
while (i < len) out[++g] = arr[i++];
|
|
1339
|
-
return out;
|
|
1340
|
-
}
|
|
1341
|
-
|
|
1342
|
-
// ../../node_modules/.pnpm/effect@3.19.13/node_modules/effect/dist/esm/internal/hashMap/node.js
|
|
1343
|
-
var EmptyNode = class _EmptyNode {
|
|
1344
|
-
_tag = "EmptyNode";
|
|
1345
|
-
modify(edit, _shift, f, hash2, key, size4) {
|
|
1346
|
-
const v = f(none2());
|
|
1347
|
-
if (isNone2(v)) return new _EmptyNode();
|
|
1348
|
-
++size4.value;
|
|
1349
|
-
return new LeafNode(edit, hash2, key, v);
|
|
1350
|
-
}
|
|
1351
|
-
};
|
|
1352
|
-
function isEmptyNode(a) {
|
|
1353
|
-
return isTagged(a, "EmptyNode");
|
|
1354
|
-
}
|
|
1355
|
-
function isLeafNode(node) {
|
|
1356
|
-
return isEmptyNode(node) || node._tag === "LeafNode" || node._tag === "CollisionNode";
|
|
1357
|
-
}
|
|
1358
|
-
function canEditNode(node, edit) {
|
|
1359
|
-
return isEmptyNode(node) ? false : edit === node.edit;
|
|
1360
|
-
}
|
|
1361
|
-
var LeafNode = class _LeafNode {
|
|
1362
|
-
edit;
|
|
1363
|
-
hash;
|
|
1364
|
-
key;
|
|
1365
|
-
value;
|
|
1366
|
-
_tag = "LeafNode";
|
|
1367
|
-
constructor(edit, hash2, key, value) {
|
|
1368
|
-
this.edit = edit;
|
|
1369
|
-
this.hash = hash2;
|
|
1370
|
-
this.key = key;
|
|
1371
|
-
this.value = value;
|
|
1372
|
-
}
|
|
1373
|
-
modify(edit, shift, f, hash2, key, size4) {
|
|
1374
|
-
if (equals(key, this.key)) {
|
|
1375
|
-
const v2 = f(this.value);
|
|
1376
|
-
if (v2 === this.value) return this;
|
|
1377
|
-
else if (isNone2(v2)) {
|
|
1378
|
-
--size4.value;
|
|
1379
|
-
return new EmptyNode();
|
|
1380
|
-
}
|
|
1381
|
-
if (canEditNode(this, edit)) {
|
|
1382
|
-
this.value = v2;
|
|
1383
|
-
return this;
|
|
1384
|
-
}
|
|
1385
|
-
return new _LeafNode(edit, hash2, key, v2);
|
|
1386
|
-
}
|
|
1387
|
-
const v = f(none2());
|
|
1388
|
-
if (isNone2(v)) return this;
|
|
1389
|
-
++size4.value;
|
|
1390
|
-
return mergeLeaves(edit, shift, this.hash, this, hash2, new _LeafNode(edit, hash2, key, v));
|
|
1391
|
-
}
|
|
1392
|
-
};
|
|
1393
|
-
var CollisionNode = class _CollisionNode {
|
|
1394
|
-
edit;
|
|
1395
|
-
hash;
|
|
1396
|
-
children;
|
|
1397
|
-
_tag = "CollisionNode";
|
|
1398
|
-
constructor(edit, hash2, children) {
|
|
1399
|
-
this.edit = edit;
|
|
1400
|
-
this.hash = hash2;
|
|
1401
|
-
this.children = children;
|
|
1402
|
-
}
|
|
1403
|
-
modify(edit, shift, f, hash2, key, size4) {
|
|
1404
|
-
if (hash2 === this.hash) {
|
|
1405
|
-
const canEdit = canEditNode(this, edit);
|
|
1406
|
-
const list = this.updateCollisionList(canEdit, edit, this.hash, this.children, f, key, size4);
|
|
1407
|
-
if (list === this.children) return this;
|
|
1408
|
-
return list.length > 1 ? new _CollisionNode(edit, this.hash, list) : list[0];
|
|
1409
|
-
}
|
|
1410
|
-
const v = f(none2());
|
|
1411
|
-
if (isNone2(v)) return this;
|
|
1412
|
-
++size4.value;
|
|
1413
|
-
return mergeLeaves(edit, shift, this.hash, this, hash2, new LeafNode(edit, hash2, key, v));
|
|
1414
|
-
}
|
|
1415
|
-
updateCollisionList(mutate2, edit, hash2, list, f, key, size4) {
|
|
1416
|
-
const len = list.length;
|
|
1417
|
-
for (let i = 0; i < len; ++i) {
|
|
1418
|
-
const child = list[i];
|
|
1419
|
-
if ("key" in child && equals(key, child.key)) {
|
|
1420
|
-
const value = child.value;
|
|
1421
|
-
const newValue2 = f(value);
|
|
1422
|
-
if (newValue2 === value) return list;
|
|
1423
|
-
if (isNone2(newValue2)) {
|
|
1424
|
-
--size4.value;
|
|
1425
|
-
return arraySpliceOut(mutate2, i, list);
|
|
1426
|
-
}
|
|
1427
|
-
return arrayUpdate(mutate2, i, new LeafNode(edit, hash2, key, newValue2), list);
|
|
1428
|
-
}
|
|
1429
|
-
}
|
|
1430
|
-
const newValue = f(none2());
|
|
1431
|
-
if (isNone2(newValue)) return list;
|
|
1432
|
-
++size4.value;
|
|
1433
|
-
return arrayUpdate(mutate2, len, new LeafNode(edit, hash2, key, newValue), list);
|
|
1434
|
-
}
|
|
1435
|
-
};
|
|
1436
|
-
var IndexedNode = class _IndexedNode {
|
|
1437
|
-
edit;
|
|
1438
|
-
mask;
|
|
1439
|
-
children;
|
|
1440
|
-
_tag = "IndexedNode";
|
|
1441
|
-
constructor(edit, mask, children) {
|
|
1442
|
-
this.edit = edit;
|
|
1443
|
-
this.mask = mask;
|
|
1444
|
-
this.children = children;
|
|
1445
|
-
}
|
|
1446
|
-
modify(edit, shift, f, hash2, key, size4) {
|
|
1447
|
-
const mask = this.mask;
|
|
1448
|
-
const children = this.children;
|
|
1449
|
-
const frag = hashFragment(shift, hash2);
|
|
1450
|
-
const bit = toBitmap(frag);
|
|
1451
|
-
const indx = fromBitmap(mask, bit);
|
|
1452
|
-
const exists = mask & bit;
|
|
1453
|
-
const canEdit = canEditNode(this, edit);
|
|
1454
|
-
if (!exists) {
|
|
1455
|
-
const _newChild = new EmptyNode().modify(edit, shift + SIZE, f, hash2, key, size4);
|
|
1456
|
-
if (!_newChild) return this;
|
|
1457
|
-
return children.length >= MAX_INDEX_NODE ? expand(edit, frag, _newChild, mask, children) : new _IndexedNode(edit, mask | bit, arraySpliceIn(canEdit, indx, _newChild, children));
|
|
1458
|
-
}
|
|
1459
|
-
const current = children[indx];
|
|
1460
|
-
const child = current.modify(edit, shift + SIZE, f, hash2, key, size4);
|
|
1461
|
-
if (current === child) return this;
|
|
1462
|
-
let bitmap = mask;
|
|
1463
|
-
let newChildren;
|
|
1464
|
-
if (isEmptyNode(child)) {
|
|
1465
|
-
bitmap &= ~bit;
|
|
1466
|
-
if (!bitmap) return new EmptyNode();
|
|
1467
|
-
if (children.length <= 2 && isLeafNode(children[indx ^ 1])) {
|
|
1468
|
-
return children[indx ^ 1];
|
|
1469
|
-
}
|
|
1470
|
-
newChildren = arraySpliceOut(canEdit, indx, children);
|
|
1471
|
-
} else {
|
|
1472
|
-
newChildren = arrayUpdate(canEdit, indx, child, children);
|
|
1473
|
-
}
|
|
1474
|
-
if (canEdit) {
|
|
1475
|
-
this.mask = bitmap;
|
|
1476
|
-
this.children = newChildren;
|
|
1477
|
-
return this;
|
|
1478
|
-
}
|
|
1479
|
-
return new _IndexedNode(edit, bitmap, newChildren);
|
|
1480
|
-
}
|
|
1481
|
-
};
|
|
1482
|
-
var ArrayNode = class _ArrayNode {
|
|
1483
|
-
edit;
|
|
1484
|
-
size;
|
|
1485
|
-
children;
|
|
1486
|
-
_tag = "ArrayNode";
|
|
1487
|
-
constructor(edit, size4, children) {
|
|
1488
|
-
this.edit = edit;
|
|
1489
|
-
this.size = size4;
|
|
1490
|
-
this.children = children;
|
|
1491
|
-
}
|
|
1492
|
-
modify(edit, shift, f, hash2, key, size4) {
|
|
1493
|
-
let count = this.size;
|
|
1494
|
-
const children = this.children;
|
|
1495
|
-
const frag = hashFragment(shift, hash2);
|
|
1496
|
-
const child = children[frag];
|
|
1497
|
-
const newChild = (child || new EmptyNode()).modify(edit, shift + SIZE, f, hash2, key, size4);
|
|
1498
|
-
if (child === newChild) return this;
|
|
1499
|
-
const canEdit = canEditNode(this, edit);
|
|
1500
|
-
let newChildren;
|
|
1501
|
-
if (isEmptyNode(child) && !isEmptyNode(newChild)) {
|
|
1502
|
-
++count;
|
|
1503
|
-
newChildren = arrayUpdate(canEdit, frag, newChild, children);
|
|
1504
|
-
} else if (!isEmptyNode(child) && isEmptyNode(newChild)) {
|
|
1505
|
-
--count;
|
|
1506
|
-
if (count <= MIN_ARRAY_NODE) {
|
|
1507
|
-
return pack(edit, count, frag, children);
|
|
1508
|
-
}
|
|
1509
|
-
newChildren = arrayUpdate(canEdit, frag, new EmptyNode(), children);
|
|
1510
|
-
} else {
|
|
1511
|
-
newChildren = arrayUpdate(canEdit, frag, newChild, children);
|
|
1512
|
-
}
|
|
1513
|
-
if (canEdit) {
|
|
1514
|
-
this.size = count;
|
|
1515
|
-
this.children = newChildren;
|
|
1516
|
-
return this;
|
|
1517
|
-
}
|
|
1518
|
-
return new _ArrayNode(edit, count, newChildren);
|
|
1519
|
-
}
|
|
1520
|
-
};
|
|
1521
|
-
function pack(edit, count, removed, elements) {
|
|
1522
|
-
const children = new Array(count - 1);
|
|
1523
|
-
let g = 0;
|
|
1524
|
-
let bitmap = 0;
|
|
1525
|
-
for (let i = 0, len = elements.length; i < len; ++i) {
|
|
1526
|
-
if (i !== removed) {
|
|
1527
|
-
const elem = elements[i];
|
|
1528
|
-
if (elem && !isEmptyNode(elem)) {
|
|
1529
|
-
children[g++] = elem;
|
|
1530
|
-
bitmap |= 1 << i;
|
|
1531
|
-
}
|
|
1532
|
-
}
|
|
1533
|
-
}
|
|
1534
|
-
return new IndexedNode(edit, bitmap, children);
|
|
1535
|
-
}
|
|
1536
|
-
function expand(edit, frag, child, bitmap, subNodes) {
|
|
1537
|
-
const arr = [];
|
|
1538
|
-
let bit = bitmap;
|
|
1539
|
-
let count = 0;
|
|
1540
|
-
for (let i = 0; bit; ++i) {
|
|
1541
|
-
if (bit & 1) arr[i] = subNodes[count++];
|
|
1542
|
-
bit >>>= 1;
|
|
1543
|
-
}
|
|
1544
|
-
arr[frag] = child;
|
|
1545
|
-
return new ArrayNode(edit, count + 1, arr);
|
|
1546
|
-
}
|
|
1547
|
-
function mergeLeavesInner(edit, shift, h1, n1, h2, n2) {
|
|
1548
|
-
if (h1 === h2) return new CollisionNode(edit, h1, [n2, n1]);
|
|
1549
|
-
const subH1 = hashFragment(shift, h1);
|
|
1550
|
-
const subH2 = hashFragment(shift, h2);
|
|
1551
|
-
if (subH1 === subH2) {
|
|
1552
|
-
return (child) => new IndexedNode(edit, toBitmap(subH1) | toBitmap(subH2), [child]);
|
|
1553
|
-
} else {
|
|
1554
|
-
const children = subH1 < subH2 ? [n1, n2] : [n2, n1];
|
|
1555
|
-
return new IndexedNode(edit, toBitmap(subH1) | toBitmap(subH2), children);
|
|
1556
|
-
}
|
|
1557
|
-
}
|
|
1558
|
-
function mergeLeaves(edit, shift, h1, n1, h2, n2) {
|
|
1559
|
-
let stack = void 0;
|
|
1560
|
-
let currentShift = shift;
|
|
1561
|
-
while (true) {
|
|
1562
|
-
const res = mergeLeavesInner(edit, currentShift, h1, n1, h2, n2);
|
|
1563
|
-
if (typeof res === "function") {
|
|
1564
|
-
stack = make5(res, stack);
|
|
1565
|
-
currentShift = currentShift + SIZE;
|
|
1566
|
-
} else {
|
|
1567
|
-
let final = res;
|
|
1568
|
-
while (stack != null) {
|
|
1569
|
-
final = stack.value(final);
|
|
1570
|
-
stack = stack.previous;
|
|
1571
|
-
}
|
|
1572
|
-
return final;
|
|
1573
|
-
}
|
|
1574
|
-
}
|
|
1575
|
-
}
|
|
1576
|
-
|
|
1577
|
-
// ../../node_modules/.pnpm/effect@3.19.13/node_modules/effect/dist/esm/internal/hashMap.js
|
|
1578
|
-
var HashMapSymbolKey = "effect/HashMap";
|
|
1579
|
-
var HashMapTypeId = /* @__PURE__ */ Symbol.for(HashMapSymbolKey);
|
|
1580
|
-
var HashMapProto = {
|
|
1581
|
-
[HashMapTypeId]: HashMapTypeId,
|
|
1582
|
-
[Symbol.iterator]() {
|
|
1583
|
-
return new HashMapIterator(this, (k, v) => [k, v]);
|
|
1584
|
-
},
|
|
1585
|
-
[symbol]() {
|
|
1586
|
-
let hash2 = hash(HashMapSymbolKey);
|
|
1587
|
-
for (const item of this) {
|
|
1588
|
-
hash2 ^= pipe(hash(item[0]), combine(hash(item[1])));
|
|
1589
|
-
}
|
|
1590
|
-
return cached(this, hash2);
|
|
1591
|
-
},
|
|
1592
|
-
[symbol2](that) {
|
|
1593
|
-
if (isHashMap(that)) {
|
|
1594
|
-
if (that._size !== this._size) {
|
|
1595
|
-
return false;
|
|
1596
|
-
}
|
|
1597
|
-
for (const item of this) {
|
|
1598
|
-
const elem = pipe(that, getHash(item[0], hash(item[0])));
|
|
1599
|
-
if (isNone2(elem)) {
|
|
1600
|
-
return false;
|
|
1601
|
-
} else {
|
|
1602
|
-
if (!equals(item[1], elem.value)) {
|
|
1603
|
-
return false;
|
|
1604
|
-
}
|
|
1605
|
-
}
|
|
1606
|
-
}
|
|
1607
|
-
return true;
|
|
1608
|
-
}
|
|
1609
|
-
return false;
|
|
1610
|
-
},
|
|
1611
|
-
toString() {
|
|
1612
|
-
return format(this.toJSON());
|
|
1613
|
-
},
|
|
1614
|
-
toJSON() {
|
|
1615
|
-
return {
|
|
1616
|
-
_id: "HashMap",
|
|
1617
|
-
values: Array.from(this).map(toJSON)
|
|
1618
|
-
};
|
|
1619
|
-
},
|
|
1620
|
-
[NodeInspectSymbol]() {
|
|
1621
|
-
return this.toJSON();
|
|
1622
|
-
},
|
|
1623
|
-
pipe() {
|
|
1624
|
-
return pipeArguments(this, arguments);
|
|
1625
|
-
}
|
|
1626
|
-
};
|
|
1627
|
-
var makeImpl = (editable, edit, root, size4) => {
|
|
1628
|
-
const map7 = Object.create(HashMapProto);
|
|
1629
|
-
map7._editable = editable;
|
|
1630
|
-
map7._edit = edit;
|
|
1631
|
-
map7._root = root;
|
|
1632
|
-
map7._size = size4;
|
|
1633
|
-
return map7;
|
|
1634
|
-
};
|
|
1635
|
-
var HashMapIterator = class _HashMapIterator {
|
|
1636
|
-
map;
|
|
1637
|
-
f;
|
|
1638
|
-
v;
|
|
1639
|
-
constructor(map7, f) {
|
|
1640
|
-
this.map = map7;
|
|
1641
|
-
this.f = f;
|
|
1642
|
-
this.v = visitLazy(this.map._root, this.f, void 0);
|
|
1643
|
-
}
|
|
1644
|
-
next() {
|
|
1645
|
-
if (isNone2(this.v)) {
|
|
1646
|
-
return {
|
|
1647
|
-
done: true,
|
|
1648
|
-
value: void 0
|
|
1649
|
-
};
|
|
1650
|
-
}
|
|
1651
|
-
const v0 = this.v.value;
|
|
1652
|
-
this.v = applyCont(v0.cont);
|
|
1653
|
-
return {
|
|
1654
|
-
done: false,
|
|
1655
|
-
value: v0.value
|
|
1656
|
-
};
|
|
1657
|
-
}
|
|
1658
|
-
[Symbol.iterator]() {
|
|
1659
|
-
return new _HashMapIterator(this.map, this.f);
|
|
1660
|
-
}
|
|
1661
|
-
};
|
|
1662
|
-
var applyCont = (cont) => cont ? visitLazyChildren(cont[0], cont[1], cont[2], cont[3], cont[4]) : none2();
|
|
1663
|
-
var visitLazy = (node, f, cont = void 0) => {
|
|
1664
|
-
switch (node._tag) {
|
|
1665
|
-
case "LeafNode": {
|
|
1666
|
-
if (isSome2(node.value)) {
|
|
1667
|
-
return some2({
|
|
1668
|
-
value: f(node.key, node.value.value),
|
|
1669
|
-
cont
|
|
1670
|
-
});
|
|
1671
|
-
}
|
|
1672
|
-
return applyCont(cont);
|
|
1673
|
-
}
|
|
1674
|
-
case "CollisionNode":
|
|
1675
|
-
case "ArrayNode":
|
|
1676
|
-
case "IndexedNode": {
|
|
1677
|
-
const children = node.children;
|
|
1678
|
-
return visitLazyChildren(children.length, children, 0, f, cont);
|
|
1679
|
-
}
|
|
1680
|
-
default: {
|
|
1681
|
-
return applyCont(cont);
|
|
1682
|
-
}
|
|
1683
|
-
}
|
|
1684
|
-
};
|
|
1685
|
-
var visitLazyChildren = (len, children, i, f, cont) => {
|
|
1686
|
-
while (i < len) {
|
|
1687
|
-
const child = children[i++];
|
|
1688
|
-
if (child && !isEmptyNode(child)) {
|
|
1689
|
-
return visitLazy(child, f, [len, children, i, f, cont]);
|
|
1690
|
-
}
|
|
1691
|
-
}
|
|
1692
|
-
return applyCont(cont);
|
|
1693
|
-
};
|
|
1694
|
-
var _empty2 = /* @__PURE__ */ makeImpl(false, 0, /* @__PURE__ */ new EmptyNode(), 0);
|
|
1695
|
-
var empty3 = () => _empty2;
|
|
1696
|
-
var isHashMap = (u) => hasProperty(u, HashMapTypeId);
|
|
1697
|
-
var getHash = /* @__PURE__ */ dual(3, (self, key, hash2) => {
|
|
1698
|
-
let node = self._root;
|
|
1699
|
-
let shift = 0;
|
|
1700
|
-
while (true) {
|
|
1701
|
-
switch (node._tag) {
|
|
1702
|
-
case "LeafNode": {
|
|
1703
|
-
return equals(key, node.key) ? node.value : none2();
|
|
1704
|
-
}
|
|
1705
|
-
case "CollisionNode": {
|
|
1706
|
-
if (hash2 === node.hash) {
|
|
1707
|
-
const children = node.children;
|
|
1708
|
-
for (let i = 0, len = children.length; i < len; ++i) {
|
|
1709
|
-
const child = children[i];
|
|
1710
|
-
if ("key" in child && equals(key, child.key)) {
|
|
1711
|
-
return child.value;
|
|
1712
|
-
}
|
|
1713
|
-
}
|
|
1714
|
-
}
|
|
1715
|
-
return none2();
|
|
1716
|
-
}
|
|
1717
|
-
case "IndexedNode": {
|
|
1718
|
-
const frag = hashFragment(shift, hash2);
|
|
1719
|
-
const bit = toBitmap(frag);
|
|
1720
|
-
if (node.mask & bit) {
|
|
1721
|
-
node = node.children[fromBitmap(node.mask, bit)];
|
|
1722
|
-
shift += SIZE;
|
|
1723
|
-
break;
|
|
1724
|
-
}
|
|
1725
|
-
return none2();
|
|
1726
|
-
}
|
|
1727
|
-
case "ArrayNode": {
|
|
1728
|
-
node = node.children[hashFragment(shift, hash2)];
|
|
1729
|
-
if (node) {
|
|
1730
|
-
shift += SIZE;
|
|
1731
|
-
break;
|
|
1732
|
-
}
|
|
1733
|
-
return none2();
|
|
1734
|
-
}
|
|
1735
|
-
default:
|
|
1736
|
-
return none2();
|
|
1737
|
-
}
|
|
1738
|
-
}
|
|
1739
|
-
});
|
|
1740
|
-
var set = /* @__PURE__ */ dual(3, (self, key, value) => modifyAt(self, key, () => some2(value)));
|
|
1741
|
-
var setTree = /* @__PURE__ */ dual(3, (self, newRoot, newSize) => {
|
|
1742
|
-
if (self._editable) {
|
|
1743
|
-
;
|
|
1744
|
-
self._root = newRoot;
|
|
1745
|
-
self._size = newSize;
|
|
1746
|
-
return self;
|
|
1747
|
-
}
|
|
1748
|
-
return newRoot === self._root ? self : makeImpl(self._editable, self._edit, newRoot, newSize);
|
|
1749
|
-
});
|
|
1750
|
-
var keys = (self) => new HashMapIterator(self, (key) => key);
|
|
1751
|
-
var size = (self) => self._size;
|
|
1752
|
-
var beginMutation = (self) => makeImpl(true, self._edit + 1, self._root, self._size);
|
|
1753
|
-
var modifyAt = /* @__PURE__ */ dual(3, (self, key, f) => modifyHash(self, key, hash(key), f));
|
|
1754
|
-
var modifyHash = /* @__PURE__ */ dual(4, (self, key, hash2, f) => {
|
|
1755
|
-
const size4 = {
|
|
1756
|
-
value: self._size
|
|
1757
|
-
};
|
|
1758
|
-
const newRoot = self._root.modify(self._editable ? self._edit : NaN, 0, f, hash2, key, size4);
|
|
1759
|
-
return pipe(self, setTree(newRoot, size4.value));
|
|
1760
|
-
});
|
|
1761
|
-
var forEach = /* @__PURE__ */ dual(2, (self, f) => reduce2(self, void 0, (_, value, key) => f(value, key)));
|
|
1762
|
-
var reduce2 = /* @__PURE__ */ dual(3, (self, zero, f) => {
|
|
1763
|
-
const root = self._root;
|
|
1764
|
-
if (root._tag === "LeafNode") {
|
|
1765
|
-
return isSome2(root.value) ? f(zero, root.value.value, root.key) : zero;
|
|
1766
|
-
}
|
|
1767
|
-
if (root._tag === "EmptyNode") {
|
|
1768
|
-
return zero;
|
|
1769
|
-
}
|
|
1770
|
-
const toVisit = [root.children];
|
|
1771
|
-
let children;
|
|
1772
|
-
while (children = toVisit.pop()) {
|
|
1773
|
-
for (let i = 0, len = children.length; i < len; ) {
|
|
1774
|
-
const child = children[i++];
|
|
1775
|
-
if (child && !isEmptyNode(child)) {
|
|
1776
|
-
if (child._tag === "LeafNode") {
|
|
1777
|
-
if (isSome2(child.value)) {
|
|
1778
|
-
zero = f(zero, child.value.value, child.key);
|
|
1779
|
-
}
|
|
1780
|
-
} else {
|
|
1781
|
-
toVisit.push(child.children);
|
|
1782
|
-
}
|
|
1783
|
-
}
|
|
1784
|
-
}
|
|
1785
|
-
}
|
|
1786
|
-
return zero;
|
|
1787
|
-
});
|
|
1788
|
-
|
|
1789
|
-
// ../../node_modules/.pnpm/effect@3.19.13/node_modules/effect/dist/esm/internal/hashSet.js
|
|
1790
|
-
var HashSetSymbolKey = "effect/HashSet";
|
|
1791
|
-
var HashSetTypeId = /* @__PURE__ */ Symbol.for(HashSetSymbolKey);
|
|
1792
|
-
var HashSetProto = {
|
|
1793
|
-
[HashSetTypeId]: HashSetTypeId,
|
|
1794
|
-
[Symbol.iterator]() {
|
|
1795
|
-
return keys(this._keyMap);
|
|
1796
|
-
},
|
|
1797
|
-
[symbol]() {
|
|
1798
|
-
return cached(this, combine(hash(this._keyMap))(hash(HashSetSymbolKey)));
|
|
1799
|
-
},
|
|
1800
|
-
[symbol2](that) {
|
|
1801
|
-
if (isHashSet(that)) {
|
|
1802
|
-
return size(this._keyMap) === size(that._keyMap) && equals(this._keyMap, that._keyMap);
|
|
1803
|
-
}
|
|
1804
|
-
return false;
|
|
1805
|
-
},
|
|
1806
|
-
toString() {
|
|
1807
|
-
return format(this.toJSON());
|
|
1808
|
-
},
|
|
1809
|
-
toJSON() {
|
|
1810
|
-
return {
|
|
1811
|
-
_id: "HashSet",
|
|
1812
|
-
values: Array.from(this).map(toJSON)
|
|
1813
|
-
};
|
|
1814
|
-
},
|
|
1815
|
-
[NodeInspectSymbol]() {
|
|
1816
|
-
return this.toJSON();
|
|
1817
|
-
},
|
|
1818
|
-
pipe() {
|
|
1819
|
-
return pipeArguments(this, arguments);
|
|
1820
|
-
}
|
|
1821
|
-
};
|
|
1822
|
-
var makeImpl2 = (keyMap) => {
|
|
1823
|
-
const set2 = Object.create(HashSetProto);
|
|
1824
|
-
set2._keyMap = keyMap;
|
|
1825
|
-
return set2;
|
|
1826
|
-
};
|
|
1827
|
-
var isHashSet = (u) => hasProperty(u, HashSetTypeId);
|
|
1828
|
-
var _empty3 = /* @__PURE__ */ makeImpl2(/* @__PURE__ */ empty3());
|
|
1829
|
-
var empty4 = () => _empty3;
|
|
1830
|
-
var size2 = (self) => size(self._keyMap);
|
|
1831
|
-
var beginMutation2 = (self) => makeImpl2(beginMutation(self._keyMap));
|
|
1832
|
-
var endMutation = (self) => {
|
|
1833
|
-
;
|
|
1834
|
-
self._keyMap._editable = false;
|
|
1835
|
-
return self;
|
|
1836
|
-
};
|
|
1837
|
-
var mutate = /* @__PURE__ */ dual(2, (self, f) => {
|
|
1838
|
-
const transient = beginMutation2(self);
|
|
1839
|
-
f(transient);
|
|
1840
|
-
return endMutation(transient);
|
|
1841
|
-
});
|
|
1842
|
-
var add3 = /* @__PURE__ */ dual(2, (self, value) => self._keyMap._editable ? (set(value, true)(self._keyMap), self) : makeImpl2(set(value, true)(self._keyMap)));
|
|
1843
|
-
var union2 = /* @__PURE__ */ dual(2, (self, that) => mutate(empty4(), (set2) => {
|
|
1844
|
-
forEach2(self, (value) => add3(set2, value));
|
|
1845
|
-
for (const value of that) {
|
|
1846
|
-
add3(set2, value);
|
|
1847
|
-
}
|
|
1848
|
-
}));
|
|
1849
|
-
var forEach2 = /* @__PURE__ */ dual(2, (self, f) => forEach(self._keyMap, (_, k) => f(k)));
|
|
1850
|
-
|
|
1851
|
-
// ../../node_modules/.pnpm/effect@3.19.13/node_modules/effect/dist/esm/HashSet.js
|
|
1852
|
-
var empty5 = empty4;
|
|
1853
|
-
var size3 = size2;
|
|
1854
|
-
var add4 = add3;
|
|
1855
|
-
var union3 = union2;
|
|
1856
|
-
|
|
1857
|
-
// ../../node_modules/.pnpm/effect@3.19.13/node_modules/effect/dist/esm/internal/data.js
|
|
1858
|
-
var ArrayProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(Array.prototype), {
|
|
1859
|
-
[symbol]() {
|
|
1860
|
-
return cached(this, array(this));
|
|
1861
|
-
},
|
|
1862
|
-
[symbol2](that) {
|
|
1863
|
-
if (Array.isArray(that) && this.length === that.length) {
|
|
1864
|
-
return this.every((v, i) => equals(v, that[i]));
|
|
1865
|
-
} else {
|
|
1866
|
-
return false;
|
|
1867
|
-
}
|
|
1868
|
-
}
|
|
1869
|
-
});
|
|
1870
|
-
var Structural = /* @__PURE__ */ function() {
|
|
1871
|
-
function Structural2(args2) {
|
|
1872
|
-
if (args2) {
|
|
1873
|
-
Object.assign(this, args2);
|
|
1874
|
-
}
|
|
1875
|
-
}
|
|
1876
|
-
Structural2.prototype = StructuralPrototype;
|
|
1877
|
-
return Structural2;
|
|
1878
|
-
}();
|
|
1879
|
-
|
|
1880
|
-
// ../../node_modules/.pnpm/effect@3.19.13/node_modules/effect/dist/esm/internal/opCodes/cause.js
|
|
1881
|
-
var OP_DIE = "Die";
|
|
1882
|
-
var OP_EMPTY = "Empty";
|
|
1883
|
-
var OP_FAIL = "Fail";
|
|
1884
|
-
var OP_INTERRUPT = "Interrupt";
|
|
1885
|
-
var OP_PARALLEL = "Parallel";
|
|
1886
|
-
var OP_SEQUENTIAL = "Sequential";
|
|
1887
|
-
|
|
1888
|
-
// ../../node_modules/.pnpm/effect@3.19.13/node_modules/effect/dist/esm/internal/cause.js
|
|
1889
|
-
var CauseSymbolKey = "effect/Cause";
|
|
1890
|
-
var CauseTypeId = /* @__PURE__ */ Symbol.for(CauseSymbolKey);
|
|
1891
|
-
var variance = {
|
|
1892
|
-
/* c8 ignore next */
|
|
1893
|
-
_E: (_) => _
|
|
1894
|
-
};
|
|
1895
|
-
var proto = {
|
|
1896
|
-
[CauseTypeId]: variance,
|
|
1897
|
-
[symbol]() {
|
|
1898
|
-
return pipe(hash(CauseSymbolKey), combine(hash(flattenCause(this))), cached(this));
|
|
1899
|
-
},
|
|
1900
|
-
[symbol2](that) {
|
|
1901
|
-
return isCause(that) && causeEquals(this, that);
|
|
1902
|
-
},
|
|
1903
|
-
pipe() {
|
|
1904
|
-
return pipeArguments(this, arguments);
|
|
1905
|
-
},
|
|
1906
|
-
toJSON() {
|
|
1907
|
-
switch (this._tag) {
|
|
1908
|
-
case "Empty":
|
|
1909
|
-
return {
|
|
1910
|
-
_id: "Cause",
|
|
1911
|
-
_tag: this._tag
|
|
1912
|
-
};
|
|
1913
|
-
case "Die":
|
|
1914
|
-
return {
|
|
1915
|
-
_id: "Cause",
|
|
1916
|
-
_tag: this._tag,
|
|
1917
|
-
defect: toJSON(this.defect)
|
|
1918
|
-
};
|
|
1919
|
-
case "Interrupt":
|
|
1920
|
-
return {
|
|
1921
|
-
_id: "Cause",
|
|
1922
|
-
_tag: this._tag,
|
|
1923
|
-
fiberId: this.fiberId.toJSON()
|
|
1924
|
-
};
|
|
1925
|
-
case "Fail":
|
|
1926
|
-
return {
|
|
1927
|
-
_id: "Cause",
|
|
1928
|
-
_tag: this._tag,
|
|
1929
|
-
failure: toJSON(this.error)
|
|
1930
|
-
};
|
|
1931
|
-
case "Sequential":
|
|
1932
|
-
case "Parallel":
|
|
1933
|
-
return {
|
|
1934
|
-
_id: "Cause",
|
|
1935
|
-
_tag: this._tag,
|
|
1936
|
-
left: toJSON(this.left),
|
|
1937
|
-
right: toJSON(this.right)
|
|
1938
|
-
};
|
|
1939
|
-
}
|
|
1940
|
-
},
|
|
1941
|
-
toString() {
|
|
1942
|
-
return pretty(this);
|
|
1943
|
-
},
|
|
1944
|
-
[NodeInspectSymbol]() {
|
|
1945
|
-
return this.toJSON();
|
|
1946
|
-
}
|
|
1947
|
-
};
|
|
1948
|
-
var fail = (error) => {
|
|
1949
|
-
const o = Object.create(proto);
|
|
1950
|
-
o._tag = OP_FAIL;
|
|
1951
|
-
o.error = error;
|
|
1952
|
-
return o;
|
|
1953
|
-
};
|
|
1954
|
-
var parallel = (left3, right3) => {
|
|
1955
|
-
const o = Object.create(proto);
|
|
1956
|
-
o._tag = OP_PARALLEL;
|
|
1957
|
-
o.left = left3;
|
|
1958
|
-
o.right = right3;
|
|
1959
|
-
return o;
|
|
1960
|
-
};
|
|
1961
|
-
var sequential = (left3, right3) => {
|
|
1962
|
-
const o = Object.create(proto);
|
|
1963
|
-
o._tag = OP_SEQUENTIAL;
|
|
1964
|
-
o.left = left3;
|
|
1965
|
-
o.right = right3;
|
|
1966
|
-
return o;
|
|
1967
|
-
};
|
|
1968
|
-
var isCause = (u) => hasProperty(u, CauseTypeId);
|
|
1969
|
-
var isInterruptedOnly = (self) => reduceWithContext(void 0, IsInterruptedOnlyCauseReducer)(self);
|
|
1970
|
-
var causeEquals = (left3, right3) => {
|
|
1971
|
-
let leftStack = of(left3);
|
|
1972
|
-
let rightStack = of(right3);
|
|
1973
|
-
while (isNonEmpty(leftStack) && isNonEmpty(rightStack)) {
|
|
1974
|
-
const [leftParallel, leftSequential] = pipe(headNonEmpty(leftStack), reduce4([empty5(), empty()], ([parallel2, sequential2], cause) => {
|
|
1975
|
-
const [par, seq] = evaluateCause(cause);
|
|
1976
|
-
return some2([pipe(parallel2, union3(par)), pipe(sequential2, appendAll(seq))]);
|
|
1977
|
-
}));
|
|
1978
|
-
const [rightParallel, rightSequential] = pipe(headNonEmpty(rightStack), reduce4([empty5(), empty()], ([parallel2, sequential2], cause) => {
|
|
1979
|
-
const [par, seq] = evaluateCause(cause);
|
|
1980
|
-
return some2([pipe(parallel2, union3(par)), pipe(sequential2, appendAll(seq))]);
|
|
1981
|
-
}));
|
|
1982
|
-
if (!equals(leftParallel, rightParallel)) {
|
|
1983
|
-
return false;
|
|
1984
|
-
}
|
|
1985
|
-
leftStack = leftSequential;
|
|
1986
|
-
rightStack = rightSequential;
|
|
1987
|
-
}
|
|
1988
|
-
return true;
|
|
1989
|
-
};
|
|
1990
|
-
var flattenCause = (cause) => {
|
|
1991
|
-
return flattenCauseLoop(of(cause), empty());
|
|
1992
|
-
};
|
|
1993
|
-
var flattenCauseLoop = (causes, flattened) => {
|
|
1994
|
-
while (1) {
|
|
1995
|
-
const [parallel2, sequential2] = pipe(causes, reduce([empty5(), empty()], ([parallel3, sequential3], cause) => {
|
|
1996
|
-
const [par, seq] = evaluateCause(cause);
|
|
1997
|
-
return [pipe(parallel3, union3(par)), pipe(sequential3, appendAll(seq))];
|
|
1998
|
-
}));
|
|
1999
|
-
const updated = size3(parallel2) > 0 ? pipe(flattened, prepend(parallel2)) : flattened;
|
|
2000
|
-
if (isEmpty(sequential2)) {
|
|
2001
|
-
return reverse2(updated);
|
|
2002
|
-
}
|
|
2003
|
-
causes = sequential2;
|
|
2004
|
-
flattened = updated;
|
|
2005
|
-
}
|
|
2006
|
-
throw new Error(getBugErrorMessage("Cause.flattenCauseLoop"));
|
|
2007
|
-
};
|
|
2008
|
-
var evaluateCause = (self) => {
|
|
2009
|
-
let cause = self;
|
|
2010
|
-
const stack = [];
|
|
2011
|
-
let _parallel = empty5();
|
|
2012
|
-
let _sequential = empty();
|
|
2013
|
-
while (cause !== void 0) {
|
|
2014
|
-
switch (cause._tag) {
|
|
2015
|
-
case OP_EMPTY: {
|
|
2016
|
-
if (stack.length === 0) {
|
|
2017
|
-
return [_parallel, _sequential];
|
|
2018
|
-
}
|
|
2019
|
-
cause = stack.pop();
|
|
2020
|
-
break;
|
|
2021
|
-
}
|
|
2022
|
-
case OP_FAIL: {
|
|
2023
|
-
_parallel = add4(_parallel, make2(cause._tag, cause.error));
|
|
2024
|
-
if (stack.length === 0) {
|
|
2025
|
-
return [_parallel, _sequential];
|
|
2026
|
-
}
|
|
2027
|
-
cause = stack.pop();
|
|
2028
|
-
break;
|
|
2029
|
-
}
|
|
2030
|
-
case OP_DIE: {
|
|
2031
|
-
_parallel = add4(_parallel, make2(cause._tag, cause.defect));
|
|
2032
|
-
if (stack.length === 0) {
|
|
2033
|
-
return [_parallel, _sequential];
|
|
2034
|
-
}
|
|
2035
|
-
cause = stack.pop();
|
|
2036
|
-
break;
|
|
2037
|
-
}
|
|
2038
|
-
case OP_INTERRUPT: {
|
|
2039
|
-
_parallel = add4(_parallel, make2(cause._tag, cause.fiberId));
|
|
2040
|
-
if (stack.length === 0) {
|
|
2041
|
-
return [_parallel, _sequential];
|
|
2042
|
-
}
|
|
2043
|
-
cause = stack.pop();
|
|
2044
|
-
break;
|
|
2045
|
-
}
|
|
2046
|
-
case OP_SEQUENTIAL: {
|
|
2047
|
-
switch (cause.left._tag) {
|
|
2048
|
-
case OP_EMPTY: {
|
|
2049
|
-
cause = cause.right;
|
|
2050
|
-
break;
|
|
2051
|
-
}
|
|
2052
|
-
case OP_SEQUENTIAL: {
|
|
2053
|
-
cause = sequential(cause.left.left, sequential(cause.left.right, cause.right));
|
|
2054
|
-
break;
|
|
2055
|
-
}
|
|
2056
|
-
case OP_PARALLEL: {
|
|
2057
|
-
cause = parallel(sequential(cause.left.left, cause.right), sequential(cause.left.right, cause.right));
|
|
2058
|
-
break;
|
|
2059
|
-
}
|
|
2060
|
-
default: {
|
|
2061
|
-
_sequential = prepend(_sequential, cause.right);
|
|
2062
|
-
cause = cause.left;
|
|
2063
|
-
break;
|
|
2064
|
-
}
|
|
2065
|
-
}
|
|
2066
|
-
break;
|
|
2067
|
-
}
|
|
2068
|
-
case OP_PARALLEL: {
|
|
2069
|
-
stack.push(cause.right);
|
|
2070
|
-
cause = cause.left;
|
|
2071
|
-
break;
|
|
2072
|
-
}
|
|
2073
|
-
}
|
|
2074
|
-
}
|
|
2075
|
-
throw new Error(getBugErrorMessage("Cause.evaluateCauseLoop"));
|
|
2076
|
-
};
|
|
2077
|
-
var IsInterruptedOnlyCauseReducer = {
|
|
2078
|
-
emptyCase: constTrue,
|
|
2079
|
-
failCase: constFalse,
|
|
2080
|
-
dieCase: constFalse,
|
|
2081
|
-
interruptCase: constTrue,
|
|
2082
|
-
sequentialCase: (_, left3, right3) => left3 && right3,
|
|
2083
|
-
parallelCase: (_, left3, right3) => left3 && right3
|
|
2084
|
-
};
|
|
2085
|
-
var OP_SEQUENTIAL_CASE = "SequentialCase";
|
|
2086
|
-
var OP_PARALLEL_CASE = "ParallelCase";
|
|
2087
|
-
var reduce4 = /* @__PURE__ */ dual(3, (self, zero, pf) => {
|
|
2088
|
-
let accumulator = zero;
|
|
2089
|
-
let cause = self;
|
|
2090
|
-
const causes = [];
|
|
2091
|
-
while (cause !== void 0) {
|
|
2092
|
-
const option = pf(accumulator, cause);
|
|
2093
|
-
accumulator = isSome2(option) ? option.value : accumulator;
|
|
2094
|
-
switch (cause._tag) {
|
|
2095
|
-
case OP_SEQUENTIAL: {
|
|
2096
|
-
causes.push(cause.right);
|
|
2097
|
-
cause = cause.left;
|
|
2098
|
-
break;
|
|
2099
|
-
}
|
|
2100
|
-
case OP_PARALLEL: {
|
|
2101
|
-
causes.push(cause.right);
|
|
2102
|
-
cause = cause.left;
|
|
2103
|
-
break;
|
|
2104
|
-
}
|
|
2105
|
-
default: {
|
|
2106
|
-
cause = void 0;
|
|
2107
|
-
break;
|
|
2108
|
-
}
|
|
2109
|
-
}
|
|
2110
|
-
if (cause === void 0 && causes.length > 0) {
|
|
2111
|
-
cause = causes.pop();
|
|
2112
|
-
}
|
|
2113
|
-
}
|
|
2114
|
-
return accumulator;
|
|
2115
|
-
});
|
|
2116
|
-
var reduceWithContext = /* @__PURE__ */ dual(3, (self, context, reducer) => {
|
|
2117
|
-
const input = [self];
|
|
2118
|
-
const output = [];
|
|
2119
|
-
while (input.length > 0) {
|
|
2120
|
-
const cause = input.pop();
|
|
2121
|
-
switch (cause._tag) {
|
|
2122
|
-
case OP_EMPTY: {
|
|
2123
|
-
output.push(right2(reducer.emptyCase(context)));
|
|
2124
|
-
break;
|
|
2125
|
-
}
|
|
2126
|
-
case OP_FAIL: {
|
|
2127
|
-
output.push(right2(reducer.failCase(context, cause.error)));
|
|
2128
|
-
break;
|
|
2129
|
-
}
|
|
2130
|
-
case OP_DIE: {
|
|
2131
|
-
output.push(right2(reducer.dieCase(context, cause.defect)));
|
|
2132
|
-
break;
|
|
2133
|
-
}
|
|
2134
|
-
case OP_INTERRUPT: {
|
|
2135
|
-
output.push(right2(reducer.interruptCase(context, cause.fiberId)));
|
|
2136
|
-
break;
|
|
2137
|
-
}
|
|
2138
|
-
case OP_SEQUENTIAL: {
|
|
2139
|
-
input.push(cause.right);
|
|
2140
|
-
input.push(cause.left);
|
|
2141
|
-
output.push(left2({
|
|
2142
|
-
_tag: OP_SEQUENTIAL_CASE
|
|
2143
|
-
}));
|
|
2144
|
-
break;
|
|
2145
|
-
}
|
|
2146
|
-
case OP_PARALLEL: {
|
|
2147
|
-
input.push(cause.right);
|
|
2148
|
-
input.push(cause.left);
|
|
2149
|
-
output.push(left2({
|
|
2150
|
-
_tag: OP_PARALLEL_CASE
|
|
2151
|
-
}));
|
|
2152
|
-
break;
|
|
2153
|
-
}
|
|
2154
|
-
}
|
|
2155
|
-
}
|
|
2156
|
-
const accumulator = [];
|
|
2157
|
-
while (output.length > 0) {
|
|
2158
|
-
const either = output.pop();
|
|
2159
|
-
switch (either._tag) {
|
|
2160
|
-
case "Left": {
|
|
2161
|
-
switch (either.left._tag) {
|
|
2162
|
-
case OP_SEQUENTIAL_CASE: {
|
|
2163
|
-
const left3 = accumulator.pop();
|
|
2164
|
-
const right3 = accumulator.pop();
|
|
2165
|
-
const value = reducer.sequentialCase(context, left3, right3);
|
|
2166
|
-
accumulator.push(value);
|
|
2167
|
-
break;
|
|
2168
|
-
}
|
|
2169
|
-
case OP_PARALLEL_CASE: {
|
|
2170
|
-
const left3 = accumulator.pop();
|
|
2171
|
-
const right3 = accumulator.pop();
|
|
2172
|
-
const value = reducer.parallelCase(context, left3, right3);
|
|
2173
|
-
accumulator.push(value);
|
|
2174
|
-
break;
|
|
2175
|
-
}
|
|
2176
|
-
}
|
|
2177
|
-
break;
|
|
2178
|
-
}
|
|
2179
|
-
case "Right": {
|
|
2180
|
-
accumulator.push(either.right);
|
|
2181
|
-
break;
|
|
2182
|
-
}
|
|
2183
|
-
}
|
|
2184
|
-
}
|
|
2185
|
-
if (accumulator.length === 0) {
|
|
2186
|
-
throw new Error("BUG: Cause.reduceWithContext - please report an issue at https://github.com/Effect-TS/effect/issues");
|
|
2187
|
-
}
|
|
2188
|
-
return accumulator.pop();
|
|
2189
|
-
});
|
|
2190
|
-
var pretty = (cause, options) => {
|
|
2191
|
-
if (isInterruptedOnly(cause)) {
|
|
2192
|
-
return "All fibers interrupted without errors.";
|
|
2193
|
-
}
|
|
2194
|
-
return prettyErrors(cause).map(function(e) {
|
|
2195
|
-
if (options?.renderErrorCause !== true || e.cause === void 0) {
|
|
2196
|
-
return e.stack;
|
|
2197
|
-
}
|
|
2198
|
-
return `${e.stack} {
|
|
2199
|
-
${renderErrorCause(e.cause, " ")}
|
|
2200
|
-
}`;
|
|
2201
|
-
}).join("\n");
|
|
2202
|
-
};
|
|
2203
|
-
var renderErrorCause = (cause, prefix) => {
|
|
2204
|
-
const lines = cause.stack.split("\n");
|
|
2205
|
-
let stack = `${prefix}[cause]: ${lines[0]}`;
|
|
2206
|
-
for (let i = 1, len = lines.length; i < len; i++) {
|
|
2207
|
-
stack += `
|
|
2208
|
-
${prefix}${lines[i]}`;
|
|
2209
|
-
}
|
|
2210
|
-
if (cause.cause) {
|
|
2211
|
-
stack += ` {
|
|
2212
|
-
${renderErrorCause(cause.cause, `${prefix} `)}
|
|
2213
|
-
${prefix}}`;
|
|
2214
|
-
}
|
|
2215
|
-
return stack;
|
|
2216
|
-
};
|
|
2217
|
-
var PrettyError = class _PrettyError extends globalThis.Error {
|
|
2218
|
-
span = void 0;
|
|
2219
|
-
constructor(originalError) {
|
|
2220
|
-
const originalErrorIsObject = typeof originalError === "object" && originalError !== null;
|
|
2221
|
-
const prevLimit = Error.stackTraceLimit;
|
|
2222
|
-
Error.stackTraceLimit = 1;
|
|
2223
|
-
super(prettyErrorMessage(originalError), originalErrorIsObject && "cause" in originalError && typeof originalError.cause !== "undefined" ? {
|
|
2224
|
-
cause: new _PrettyError(originalError.cause)
|
|
2225
|
-
} : void 0);
|
|
2226
|
-
if (this.message === "") {
|
|
2227
|
-
this.message = "An error has occurred";
|
|
2228
|
-
}
|
|
2229
|
-
Error.stackTraceLimit = prevLimit;
|
|
2230
|
-
this.name = originalError instanceof Error ? originalError.name : "Error";
|
|
2231
|
-
if (originalErrorIsObject) {
|
|
2232
|
-
if (spanSymbol in originalError) {
|
|
2233
|
-
this.span = originalError[spanSymbol];
|
|
2234
|
-
}
|
|
2235
|
-
Object.keys(originalError).forEach((key) => {
|
|
2236
|
-
if (!(key in this)) {
|
|
2237
|
-
this[key] = originalError[key];
|
|
2238
|
-
}
|
|
2239
|
-
});
|
|
2240
|
-
}
|
|
2241
|
-
this.stack = prettyErrorStack(`${this.name}: ${this.message}`, originalError instanceof Error && originalError.stack ? originalError.stack : "", this.span);
|
|
2242
|
-
}
|
|
2243
|
-
};
|
|
2244
|
-
var prettyErrorMessage = (u) => {
|
|
2245
|
-
if (typeof u === "string") {
|
|
2246
|
-
return u;
|
|
2247
|
-
}
|
|
2248
|
-
if (typeof u === "object" && u !== null && u instanceof Error) {
|
|
2249
|
-
return u.message;
|
|
2250
|
-
}
|
|
2251
|
-
try {
|
|
2252
|
-
if (hasProperty(u, "toString") && isFunction2(u["toString"]) && u["toString"] !== Object.prototype.toString && u["toString"] !== globalThis.Array.prototype.toString) {
|
|
2253
|
-
return u["toString"]();
|
|
2254
|
-
}
|
|
2255
|
-
} catch {
|
|
2256
|
-
}
|
|
2257
|
-
return stringifyCircular(u);
|
|
2258
|
-
};
|
|
2259
|
-
var locationRegex = /\((.*)\)/g;
|
|
2260
|
-
var spanToTrace = /* @__PURE__ */ globalValue("effect/Tracer/spanToTrace", () => /* @__PURE__ */ new WeakMap());
|
|
2261
|
-
var prettyErrorStack = (message, stack, span) => {
|
|
2262
|
-
const out = [message];
|
|
2263
|
-
const lines = stack.startsWith(message) ? stack.slice(message.length).split("\n") : stack.split("\n");
|
|
2264
|
-
for (let i = 1; i < lines.length; i++) {
|
|
2265
|
-
if (lines[i].includes(" at new BaseEffectError") || lines[i].includes(" at new YieldableError")) {
|
|
2266
|
-
i++;
|
|
2267
|
-
continue;
|
|
2268
|
-
}
|
|
2269
|
-
if (lines[i].includes("Generator.next")) {
|
|
2270
|
-
break;
|
|
2271
|
-
}
|
|
2272
|
-
if (lines[i].includes("effect_internal_function")) {
|
|
2273
|
-
break;
|
|
2274
|
-
}
|
|
2275
|
-
out.push(lines[i].replace(/at .*effect_instruction_i.*\((.*)\)/, "at $1").replace(/EffectPrimitive\.\w+/, "<anonymous>"));
|
|
2276
|
-
}
|
|
2277
|
-
if (span) {
|
|
2278
|
-
let current = span;
|
|
2279
|
-
let i = 0;
|
|
2280
|
-
while (current && current._tag === "Span" && i < 10) {
|
|
2281
|
-
const stackFn = spanToTrace.get(current);
|
|
2282
|
-
if (typeof stackFn === "function") {
|
|
2283
|
-
const stack2 = stackFn();
|
|
2284
|
-
if (typeof stack2 === "string") {
|
|
2285
|
-
const locationMatchAll = stack2.matchAll(locationRegex);
|
|
2286
|
-
let match2 = false;
|
|
2287
|
-
for (const [, location] of locationMatchAll) {
|
|
2288
|
-
match2 = true;
|
|
2289
|
-
out.push(` at ${current.name} (${location})`);
|
|
2290
|
-
}
|
|
2291
|
-
if (!match2) {
|
|
2292
|
-
out.push(` at ${current.name} (${stack2.replace(/^at /, "")})`);
|
|
2293
|
-
}
|
|
2294
|
-
} else {
|
|
2295
|
-
out.push(` at ${current.name}`);
|
|
2296
|
-
}
|
|
2297
|
-
} else {
|
|
2298
|
-
out.push(` at ${current.name}`);
|
|
2299
|
-
}
|
|
2300
|
-
current = getOrUndefined(current.parent);
|
|
2301
|
-
i++;
|
|
2302
|
-
}
|
|
2303
|
-
}
|
|
2304
|
-
return out.join("\n");
|
|
2305
|
-
};
|
|
2306
|
-
var spanSymbol = /* @__PURE__ */ Symbol.for("effect/SpanAnnotation");
|
|
2307
|
-
var prettyErrors = (cause) => reduceWithContext(cause, void 0, {
|
|
2308
|
-
emptyCase: () => [],
|
|
2309
|
-
dieCase: (_, unknownError) => {
|
|
2310
|
-
return [new PrettyError(unknownError)];
|
|
2311
|
-
},
|
|
2312
|
-
failCase: (_, error) => {
|
|
2313
|
-
return [new PrettyError(error)];
|
|
2314
|
-
},
|
|
2315
|
-
interruptCase: () => [],
|
|
2316
|
-
parallelCase: (_, l, r) => [...l, ...r],
|
|
2317
|
-
sequentialCase: (_, l, r) => [...l, ...r]
|
|
2318
|
-
});
|
|
2319
|
-
|
|
2320
|
-
// ../../node_modules/.pnpm/effect@3.19.13/node_modules/effect/dist/esm/internal/singleShotGen.js
|
|
2321
|
-
var SingleShotGen2 = class _SingleShotGen {
|
|
2322
|
-
self;
|
|
2323
|
-
called = false;
|
|
2324
|
-
constructor(self) {
|
|
2325
|
-
this.self = self;
|
|
2326
|
-
}
|
|
2327
|
-
next(a) {
|
|
2328
|
-
return this.called ? {
|
|
2329
|
-
value: a,
|
|
2330
|
-
done: true
|
|
2331
|
-
} : (this.called = true, {
|
|
2332
|
-
value: this.self,
|
|
2333
|
-
done: false
|
|
2334
|
-
});
|
|
2335
|
-
}
|
|
2336
|
-
return(a) {
|
|
2337
|
-
return {
|
|
2338
|
-
value: a,
|
|
2339
|
-
done: true
|
|
2340
|
-
};
|
|
2341
|
-
}
|
|
2342
|
-
throw(e) {
|
|
2343
|
-
throw e;
|
|
2344
|
-
}
|
|
2345
|
-
[Symbol.iterator]() {
|
|
2346
|
-
return new _SingleShotGen(this.self);
|
|
2347
|
-
}
|
|
2348
|
-
};
|
|
2349
|
-
|
|
2350
|
-
// ../../node_modules/.pnpm/effect@3.19.13/node_modules/effect/dist/esm/internal/core.js
|
|
2351
|
-
var EffectTypeId2 = /* @__PURE__ */ Symbol.for("effect/Effect");
|
|
2352
|
-
var EffectPrimitive = class {
|
|
2353
|
-
_op;
|
|
2354
|
-
effect_instruction_i0 = void 0;
|
|
2355
|
-
effect_instruction_i1 = void 0;
|
|
2356
|
-
effect_instruction_i2 = void 0;
|
|
2357
|
-
trace = void 0;
|
|
2358
|
-
[EffectTypeId2] = effectVariance;
|
|
2359
|
-
constructor(_op) {
|
|
2360
|
-
this._op = _op;
|
|
2361
|
-
}
|
|
2362
|
-
[symbol2](that) {
|
|
2363
|
-
return this === that;
|
|
2364
|
-
}
|
|
2365
|
-
[symbol]() {
|
|
2366
|
-
return cached(this, random(this));
|
|
2367
|
-
}
|
|
2368
|
-
pipe() {
|
|
2369
|
-
return pipeArguments(this, arguments);
|
|
2370
|
-
}
|
|
2371
|
-
toJSON() {
|
|
2372
|
-
return {
|
|
2373
|
-
_id: "Effect",
|
|
2374
|
-
_op: this._op,
|
|
2375
|
-
effect_instruction_i0: toJSON(this.effect_instruction_i0),
|
|
2376
|
-
effect_instruction_i1: toJSON(this.effect_instruction_i1),
|
|
2377
|
-
effect_instruction_i2: toJSON(this.effect_instruction_i2)
|
|
2378
|
-
};
|
|
2379
|
-
}
|
|
2380
|
-
toString() {
|
|
2381
|
-
return format(this.toJSON());
|
|
2382
|
-
}
|
|
2383
|
-
[NodeInspectSymbol]() {
|
|
2384
|
-
return this.toJSON();
|
|
2385
|
-
}
|
|
2386
|
-
[Symbol.iterator]() {
|
|
2387
|
-
return new SingleShotGen2(new YieldWrap(this));
|
|
2388
|
-
}
|
|
2389
|
-
};
|
|
2390
|
-
var EffectPrimitiveFailure = class {
|
|
2391
|
-
_op;
|
|
2392
|
-
effect_instruction_i0 = void 0;
|
|
2393
|
-
effect_instruction_i1 = void 0;
|
|
2394
|
-
effect_instruction_i2 = void 0;
|
|
2395
|
-
trace = void 0;
|
|
2396
|
-
[EffectTypeId2] = effectVariance;
|
|
2397
|
-
constructor(_op) {
|
|
2398
|
-
this._op = _op;
|
|
2399
|
-
this._tag = _op;
|
|
2400
|
-
}
|
|
2401
|
-
[symbol2](that) {
|
|
2402
|
-
return exitIsExit(that) && that._op === "Failure" && // @ts-expect-error
|
|
2403
|
-
equals(this.effect_instruction_i0, that.effect_instruction_i0);
|
|
2404
|
-
}
|
|
2405
|
-
[symbol]() {
|
|
2406
|
-
return pipe(
|
|
2407
|
-
// @ts-expect-error
|
|
2408
|
-
string(this._tag),
|
|
2409
|
-
// @ts-expect-error
|
|
2410
|
-
combine(hash(this.effect_instruction_i0)),
|
|
2411
|
-
cached(this)
|
|
2412
|
-
);
|
|
2413
|
-
}
|
|
2414
|
-
get cause() {
|
|
2415
|
-
return this.effect_instruction_i0;
|
|
2416
|
-
}
|
|
2417
|
-
pipe() {
|
|
2418
|
-
return pipeArguments(this, arguments);
|
|
2419
|
-
}
|
|
2420
|
-
toJSON() {
|
|
2421
|
-
return {
|
|
2422
|
-
_id: "Exit",
|
|
2423
|
-
_tag: this._op,
|
|
2424
|
-
cause: this.cause.toJSON()
|
|
2425
|
-
};
|
|
2426
|
-
}
|
|
2427
|
-
toString() {
|
|
2428
|
-
return format(this.toJSON());
|
|
2429
|
-
}
|
|
2430
|
-
[NodeInspectSymbol]() {
|
|
2431
|
-
return this.toJSON();
|
|
2432
|
-
}
|
|
2433
|
-
[Symbol.iterator]() {
|
|
2434
|
-
return new SingleShotGen2(new YieldWrap(this));
|
|
2435
|
-
}
|
|
2436
|
-
};
|
|
2437
|
-
var EffectPrimitiveSuccess = class {
|
|
2438
|
-
_op;
|
|
2439
|
-
effect_instruction_i0 = void 0;
|
|
2440
|
-
effect_instruction_i1 = void 0;
|
|
2441
|
-
effect_instruction_i2 = void 0;
|
|
2442
|
-
trace = void 0;
|
|
2443
|
-
[EffectTypeId2] = effectVariance;
|
|
2444
|
-
constructor(_op) {
|
|
2445
|
-
this._op = _op;
|
|
2446
|
-
this._tag = _op;
|
|
2447
|
-
}
|
|
2448
|
-
[symbol2](that) {
|
|
2449
|
-
return exitIsExit(that) && that._op === "Success" && // @ts-expect-error
|
|
2450
|
-
equals(this.effect_instruction_i0, that.effect_instruction_i0);
|
|
2451
|
-
}
|
|
2452
|
-
[symbol]() {
|
|
2453
|
-
return pipe(
|
|
2454
|
-
// @ts-expect-error
|
|
2455
|
-
string(this._tag),
|
|
2456
|
-
// @ts-expect-error
|
|
2457
|
-
combine(hash(this.effect_instruction_i0)),
|
|
2458
|
-
cached(this)
|
|
2459
|
-
);
|
|
2460
|
-
}
|
|
2461
|
-
get value() {
|
|
2462
|
-
return this.effect_instruction_i0;
|
|
2463
|
-
}
|
|
2464
|
-
pipe() {
|
|
2465
|
-
return pipeArguments(this, arguments);
|
|
2466
|
-
}
|
|
2467
|
-
toJSON() {
|
|
2468
|
-
return {
|
|
2469
|
-
_id: "Exit",
|
|
2470
|
-
_tag: this._op,
|
|
2471
|
-
value: toJSON(this.value)
|
|
2472
|
-
};
|
|
2473
|
-
}
|
|
2474
|
-
toString() {
|
|
2475
|
-
return format(this.toJSON());
|
|
2476
|
-
}
|
|
2477
|
-
[NodeInspectSymbol]() {
|
|
2478
|
-
return this.toJSON();
|
|
2479
|
-
}
|
|
2480
|
-
[Symbol.iterator]() {
|
|
2481
|
-
return new SingleShotGen2(new YieldWrap(this));
|
|
2482
|
-
}
|
|
2483
|
-
};
|
|
2484
|
-
var isEffect = (u) => hasProperty(u, EffectTypeId2);
|
|
2485
|
-
var withFiberRuntime = (withRuntime) => {
|
|
2486
|
-
const effect = new EffectPrimitive(OP_WITH_RUNTIME);
|
|
2487
|
-
effect.effect_instruction_i0 = withRuntime;
|
|
2488
|
-
return effect;
|
|
2489
|
-
};
|
|
2490
|
-
var originalSymbol = /* @__PURE__ */ Symbol.for("effect/OriginalAnnotation");
|
|
2491
|
-
var capture = (obj, span) => {
|
|
2492
|
-
if (isSome2(span)) {
|
|
2493
|
-
return new Proxy(obj, {
|
|
2494
|
-
has(target, p) {
|
|
2495
|
-
return p === spanSymbol || p === originalSymbol || p in target;
|
|
2496
|
-
},
|
|
2497
|
-
get(target, p) {
|
|
2498
|
-
if (p === spanSymbol) {
|
|
2499
|
-
return span.value;
|
|
2500
|
-
}
|
|
2501
|
-
if (p === originalSymbol) {
|
|
2502
|
-
return obj;
|
|
2503
|
-
}
|
|
2504
|
-
return target[p];
|
|
2505
|
-
}
|
|
2506
|
-
});
|
|
2507
|
-
}
|
|
2508
|
-
return obj;
|
|
2509
|
-
};
|
|
2510
|
-
var fail2 = (error) => isObject(error) && !(spanSymbol in error) ? withFiberRuntime((fiber) => failCause(fail(capture(error, currentSpanFromFiber(fiber))))) : failCause(fail(error));
|
|
2511
|
-
var failCause = (cause) => {
|
|
2512
|
-
const effect = new EffectPrimitiveFailure(OP_FAILURE);
|
|
2513
|
-
effect.effect_instruction_i0 = cause;
|
|
2514
|
-
return effect;
|
|
2515
|
-
};
|
|
2516
|
-
var logLevelAll = {
|
|
2517
|
-
_tag: "All",
|
|
2518
|
-
syslog: 0,
|
|
2519
|
-
label: "ALL",
|
|
2520
|
-
ordinal: Number.MIN_SAFE_INTEGER,
|
|
2521
|
-
pipe() {
|
|
2522
|
-
return pipeArguments(this, arguments);
|
|
2523
|
-
}
|
|
2524
|
-
};
|
|
2525
|
-
var logLevelNone = {
|
|
2526
|
-
_tag: "None",
|
|
2527
|
-
syslog: 7,
|
|
2528
|
-
label: "OFF",
|
|
2529
|
-
ordinal: Number.MAX_SAFE_INTEGER,
|
|
2530
|
-
pipe() {
|
|
2531
|
-
return pipeArguments(this, arguments);
|
|
2532
|
-
}
|
|
2533
|
-
};
|
|
2534
|
-
var RequestResolverSymbolKey = "effect/RequestResolver";
|
|
2535
|
-
var RequestResolverTypeId = /* @__PURE__ */ Symbol.for(RequestResolverSymbolKey);
|
|
2536
|
-
var requestResolverVariance = {
|
|
2537
|
-
/* c8 ignore next */
|
|
2538
|
-
_A: (_) => _,
|
|
2539
|
-
/* c8 ignore next */
|
|
2540
|
-
_R: (_) => _
|
|
2541
|
-
};
|
|
2542
|
-
var RequestResolverImpl = class _RequestResolverImpl {
|
|
2543
|
-
runAll;
|
|
2544
|
-
target;
|
|
2545
|
-
[RequestResolverTypeId] = requestResolverVariance;
|
|
2546
|
-
constructor(runAll, target) {
|
|
2547
|
-
this.runAll = runAll;
|
|
2548
|
-
this.target = target;
|
|
2549
|
-
}
|
|
2550
|
-
[symbol]() {
|
|
2551
|
-
return cached(this, this.target ? hash(this.target) : random(this));
|
|
2552
|
-
}
|
|
2553
|
-
[symbol2](that) {
|
|
2554
|
-
return this.target ? isRequestResolver(that) && equals(this.target, that.target) : this === that;
|
|
2555
|
-
}
|
|
2556
|
-
identified(...ids) {
|
|
2557
|
-
return new _RequestResolverImpl(this.runAll, fromIterable2(ids));
|
|
2558
|
-
}
|
|
2559
|
-
pipe() {
|
|
2560
|
-
return pipeArguments(this, arguments);
|
|
2561
|
-
}
|
|
2562
|
-
};
|
|
2563
|
-
var isRequestResolver = (u) => hasProperty(u, RequestResolverTypeId);
|
|
2564
|
-
var YieldableError = /* @__PURE__ */ function() {
|
|
2565
|
-
class YieldableError2 extends globalThis.Error {
|
|
2566
|
-
commit() {
|
|
2567
|
-
return fail2(this);
|
|
2568
|
-
}
|
|
2569
|
-
toJSON() {
|
|
2570
|
-
const obj = {
|
|
2571
|
-
...this
|
|
2572
|
-
};
|
|
2573
|
-
if (this.message) obj.message = this.message;
|
|
2574
|
-
if (this.cause) obj.cause = this.cause;
|
|
2575
|
-
return obj;
|
|
2576
|
-
}
|
|
2577
|
-
[NodeInspectSymbol]() {
|
|
2578
|
-
if (this.toString !== globalThis.Error.prototype.toString) {
|
|
2579
|
-
return this.stack ? `${this.toString()}
|
|
2580
|
-
${this.stack.split("\n").slice(1).join("\n")}` : this.toString();
|
|
2581
|
-
} else if ("Bun" in globalThis) {
|
|
2582
|
-
return pretty(fail(this), {
|
|
2583
|
-
renderErrorCause: true
|
|
2584
|
-
});
|
|
2585
|
-
}
|
|
2586
|
-
return this;
|
|
2587
|
-
}
|
|
2588
|
-
}
|
|
2589
|
-
Object.assign(YieldableError2.prototype, StructuralCommitPrototype);
|
|
2590
|
-
return YieldableError2;
|
|
2591
|
-
}();
|
|
2592
|
-
var makeException = (proto2, tag) => {
|
|
2593
|
-
class Base2 extends YieldableError {
|
|
2594
|
-
_tag = tag;
|
|
2595
|
-
}
|
|
2596
|
-
Object.assign(Base2.prototype, proto2);
|
|
2597
|
-
Base2.prototype.name = tag;
|
|
2598
|
-
return Base2;
|
|
2599
|
-
};
|
|
2600
|
-
var RuntimeExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/RuntimeException");
|
|
2601
|
-
var RuntimeException = /* @__PURE__ */ makeException({
|
|
2602
|
-
[RuntimeExceptionTypeId]: RuntimeExceptionTypeId
|
|
2603
|
-
}, "RuntimeException");
|
|
2604
|
-
var InterruptedExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/InterruptedException");
|
|
2605
|
-
var InterruptedException = /* @__PURE__ */ makeException({
|
|
2606
|
-
[InterruptedExceptionTypeId]: InterruptedExceptionTypeId
|
|
2607
|
-
}, "InterruptedException");
|
|
2608
|
-
var IllegalArgumentExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/IllegalArgument");
|
|
2609
|
-
var IllegalArgumentException = /* @__PURE__ */ makeException({
|
|
2610
|
-
[IllegalArgumentExceptionTypeId]: IllegalArgumentExceptionTypeId
|
|
2611
|
-
}, "IllegalArgumentException");
|
|
2612
|
-
var NoSuchElementExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/NoSuchElement");
|
|
2613
|
-
var NoSuchElementException = /* @__PURE__ */ makeException({
|
|
2614
|
-
[NoSuchElementExceptionTypeId]: NoSuchElementExceptionTypeId
|
|
2615
|
-
}, "NoSuchElementException");
|
|
2616
|
-
var InvalidPubSubCapacityExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/InvalidPubSubCapacityException");
|
|
2617
|
-
var InvalidPubSubCapacityException = /* @__PURE__ */ makeException({
|
|
2618
|
-
[InvalidPubSubCapacityExceptionTypeId]: InvalidPubSubCapacityExceptionTypeId
|
|
2619
|
-
}, "InvalidPubSubCapacityException");
|
|
2620
|
-
var ExceededCapacityExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/ExceededCapacityException");
|
|
2621
|
-
var ExceededCapacityException = /* @__PURE__ */ makeException({
|
|
2622
|
-
[ExceededCapacityExceptionTypeId]: ExceededCapacityExceptionTypeId
|
|
2623
|
-
}, "ExceededCapacityException");
|
|
2624
|
-
var TimeoutExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/Timeout");
|
|
2625
|
-
var TimeoutException = /* @__PURE__ */ makeException({
|
|
2626
|
-
[TimeoutExceptionTypeId]: TimeoutExceptionTypeId
|
|
2627
|
-
}, "TimeoutException");
|
|
2628
|
-
var exitIsExit = (u) => isEffect(u) && "_tag" in u && (u._tag === "Success" || u._tag === "Failure");
|
|
2629
|
-
var currentSpanFromFiber = (fiber) => {
|
|
2630
|
-
const span = fiber.currentSpan;
|
|
2631
|
-
return span !== void 0 && span._tag === "Span" ? some2(span) : none2();
|
|
2632
|
-
};
|
|
2633
|
-
|
|
2634
|
-
// ../../node_modules/.pnpm/effect@3.19.13/node_modules/effect/dist/esm/Data.js
|
|
2635
|
-
var Class2 = Structural;
|
|
2636
|
-
var TaggedClass = (tag) => {
|
|
2637
|
-
class Base2 extends Class2 {
|
|
2638
|
-
_tag = tag;
|
|
2639
|
-
}
|
|
2640
|
-
return Base2;
|
|
2641
|
-
};
|
|
2642
|
-
var Error2 = /* @__PURE__ */ function() {
|
|
2643
|
-
const plainArgsSymbol = /* @__PURE__ */ Symbol.for("effect/Data/Error/plainArgs");
|
|
2644
|
-
const O = {
|
|
2645
|
-
BaseEffectError: class extends YieldableError {
|
|
2646
|
-
constructor(args2) {
|
|
2647
|
-
super(args2?.message, args2?.cause ? {
|
|
2648
|
-
cause: args2.cause
|
|
2649
|
-
} : void 0);
|
|
2650
|
-
if (args2) {
|
|
2651
|
-
Object.assign(this, args2);
|
|
2652
|
-
Object.defineProperty(this, plainArgsSymbol, {
|
|
2653
|
-
value: args2,
|
|
2654
|
-
enumerable: false
|
|
2655
|
-
});
|
|
2656
|
-
}
|
|
2657
|
-
}
|
|
2658
|
-
toJSON() {
|
|
2659
|
-
return {
|
|
2660
|
-
...this[plainArgsSymbol],
|
|
2661
|
-
...this
|
|
2662
|
-
};
|
|
2663
|
-
}
|
|
2664
|
-
}
|
|
2665
|
-
};
|
|
2666
|
-
return O.BaseEffectError;
|
|
2667
|
-
}();
|
|
2668
|
-
var TaggedError = (tag) => {
|
|
2669
|
-
const O = {
|
|
2670
|
-
BaseEffectError: class extends Error2 {
|
|
2671
|
-
_tag = tag;
|
|
2672
|
-
}
|
|
2673
|
-
};
|
|
2674
|
-
O.BaseEffectError.prototype.name = tag;
|
|
2675
|
-
return O.BaseEffectError;
|
|
2676
|
-
};
|
|
2677
|
-
|
|
2678
|
-
// src/internal/bot-response.ts
|
|
2679
|
-
var BotResponse = class _BotResponse extends TaggedClass("BotResponse") {
|
|
2680
|
-
static make(result) {
|
|
2681
|
-
return new _BotResponse({ response: result });
|
|
2682
|
-
}
|
|
2683
|
-
static ignore = new _BotResponse({});
|
|
2684
|
-
};
|
|
2685
|
-
|
|
2686
|
-
// src/internal/bot-context.ts
|
|
2687
|
-
var extractCommand = (update) => {
|
|
2688
|
-
if (typeof update !== "object" || update === null) return void 0;
|
|
2689
|
-
const u = update;
|
|
2690
|
-
if (!u.entities || !u.text) return void 0;
|
|
2691
|
-
const entity = u.entities.find((e) => e.type === "bot_command");
|
|
2692
|
-
if (!entity) return void 0;
|
|
2693
|
-
return u.text.slice(entity.offset, entity.offset + entity.length);
|
|
2694
|
-
};
|
|
2695
|
-
var createBotContext = (update) => {
|
|
2696
|
-
const command = extractCommand(update);
|
|
2697
|
-
return {
|
|
2698
|
-
command,
|
|
2699
|
-
reply: (text, options) => BotResponse.make({ type: "message", text, ...options }),
|
|
2700
|
-
replyWithDocument: (document, options) => BotResponse.make({ type: "document", document, ...options }),
|
|
2701
|
-
replyWithPhoto: (photo, options) => BotResponse.make({ type: "photo", photo, ...options }),
|
|
2702
|
-
ignore: BotResponse.ignore
|
|
2703
|
-
};
|
|
2704
|
-
};
|
|
2705
|
-
|
|
2706
|
-
// ../../node_modules/.pnpm/effect@3.19.13/node_modules/effect/dist/esm/Effectable.js
|
|
2707
|
-
var EffectPrototype2 = EffectPrototype;
|
|
2708
|
-
|
|
2709
|
-
// ../../node_modules/.pnpm/effect@3.19.13/node_modules/effect/dist/esm/Micro.js
|
|
2710
|
-
var TypeId5 = /* @__PURE__ */ Symbol.for("effect/Micro");
|
|
2711
|
-
var MicroExitTypeId = /* @__PURE__ */ Symbol.for("effect/Micro/MicroExit");
|
|
2712
|
-
var isMicro = (u) => typeof u === "object" && u !== null && TypeId5 in u;
|
|
2713
|
-
var MicroCauseTypeId = /* @__PURE__ */ Symbol.for("effect/Micro/MicroCause");
|
|
2714
|
-
var microCauseVariance = {
|
|
2715
|
-
_E: identity
|
|
2716
|
-
};
|
|
2717
|
-
var MicroCauseImpl = class extends globalThis.Error {
|
|
2718
|
-
_tag;
|
|
2719
|
-
traces;
|
|
2720
|
-
[MicroCauseTypeId];
|
|
2721
|
-
constructor(_tag, originalError, traces) {
|
|
2722
|
-
const causeName = `MicroCause.${_tag}`;
|
|
2723
|
-
let name;
|
|
2724
|
-
let message;
|
|
2725
|
-
let stack;
|
|
2726
|
-
if (originalError instanceof globalThis.Error) {
|
|
2727
|
-
name = `(${causeName}) ${originalError.name}`;
|
|
2728
|
-
message = originalError.message;
|
|
2729
|
-
const messageLines = message.split("\n").length;
|
|
2730
|
-
stack = originalError.stack ? `(${causeName}) ${originalError.stack.split("\n").slice(0, messageLines + 3).join("\n")}` : `${name}: ${message}`;
|
|
2731
|
-
} else {
|
|
2732
|
-
name = causeName;
|
|
2733
|
-
message = toStringUnknown(originalError, 0);
|
|
2734
|
-
stack = `${name}: ${message}`;
|
|
2735
|
-
}
|
|
2736
|
-
if (traces.length > 0) {
|
|
2737
|
-
stack += `
|
|
2738
|
-
${traces.join("\n ")}`;
|
|
2739
|
-
}
|
|
2740
|
-
super(message);
|
|
2741
|
-
this._tag = _tag;
|
|
2742
|
-
this.traces = traces;
|
|
2743
|
-
this[MicroCauseTypeId] = microCauseVariance;
|
|
2744
|
-
this.name = name;
|
|
2745
|
-
this.stack = stack;
|
|
2746
|
-
}
|
|
2747
|
-
pipe() {
|
|
2748
|
-
return pipeArguments(this, arguments);
|
|
2749
|
-
}
|
|
2750
|
-
toString() {
|
|
2751
|
-
return this.stack;
|
|
2752
|
-
}
|
|
2753
|
-
[NodeInspectSymbol]() {
|
|
2754
|
-
return this.stack;
|
|
2755
|
-
}
|
|
2756
|
-
};
|
|
2757
|
-
var Fail = class extends MicroCauseImpl {
|
|
2758
|
-
error;
|
|
2759
|
-
constructor(error, traces = []) {
|
|
2760
|
-
super("Fail", error, traces);
|
|
2761
|
-
this.error = error;
|
|
2762
|
-
}
|
|
2763
|
-
};
|
|
2764
|
-
var causeFail = (error, traces = []) => new Fail(error, traces);
|
|
2765
|
-
var Die = class extends MicroCauseImpl {
|
|
2766
|
-
defect;
|
|
2767
|
-
constructor(defect, traces = []) {
|
|
2768
|
-
super("Die", defect, traces);
|
|
2769
|
-
this.defect = defect;
|
|
2770
|
-
}
|
|
2771
|
-
};
|
|
2772
|
-
var causeDie = (defect, traces = []) => new Die(defect, traces);
|
|
2773
|
-
var Interrupt = class extends MicroCauseImpl {
|
|
2774
|
-
constructor(traces = []) {
|
|
2775
|
-
super("Interrupt", "interrupted", traces);
|
|
2776
|
-
}
|
|
2777
|
-
};
|
|
2778
|
-
var causeInterrupt = (traces = []) => new Interrupt(traces);
|
|
2779
|
-
var causeIsFail = (self) => self._tag === "Fail";
|
|
2780
|
-
var causeIsInterrupt = (self) => self._tag === "Interrupt";
|
|
2781
|
-
var MicroFiberTypeId = /* @__PURE__ */ Symbol.for("effect/Micro/MicroFiber");
|
|
2782
|
-
var fiberVariance = {
|
|
2783
|
-
_A: identity,
|
|
2784
|
-
_E: identity
|
|
2785
|
-
};
|
|
2786
|
-
var MicroFiberImpl = class {
|
|
2787
|
-
context;
|
|
2788
|
-
interruptible;
|
|
2789
|
-
[MicroFiberTypeId];
|
|
2790
|
-
_stack = [];
|
|
2791
|
-
_observers = [];
|
|
2792
|
-
_exit;
|
|
2793
|
-
_children;
|
|
2794
|
-
currentOpCount = 0;
|
|
2795
|
-
constructor(context, interruptible2 = true) {
|
|
2796
|
-
this.context = context;
|
|
2797
|
-
this.interruptible = interruptible2;
|
|
2798
|
-
this[MicroFiberTypeId] = fiberVariance;
|
|
2799
|
-
}
|
|
2800
|
-
getRef(ref) {
|
|
2801
|
-
return unsafeGetReference(this.context, ref);
|
|
2802
|
-
}
|
|
2803
|
-
addObserver(cb) {
|
|
2804
|
-
if (this._exit) {
|
|
2805
|
-
cb(this._exit);
|
|
2806
|
-
return constVoid;
|
|
2807
|
-
}
|
|
2808
|
-
this._observers.push(cb);
|
|
2809
|
-
return () => {
|
|
2810
|
-
const index = this._observers.indexOf(cb);
|
|
2811
|
-
if (index >= 0) {
|
|
2812
|
-
this._observers.splice(index, 1);
|
|
2813
|
-
}
|
|
2814
|
-
};
|
|
2815
|
-
}
|
|
2816
|
-
_interrupted = false;
|
|
2817
|
-
unsafeInterrupt() {
|
|
2818
|
-
if (this._exit) {
|
|
2819
|
-
return;
|
|
2820
|
-
}
|
|
2821
|
-
this._interrupted = true;
|
|
2822
|
-
if (this.interruptible) {
|
|
2823
|
-
this.evaluate(exitInterrupt);
|
|
2824
|
-
}
|
|
2825
|
-
}
|
|
2826
|
-
unsafePoll() {
|
|
2827
|
-
return this._exit;
|
|
2828
|
-
}
|
|
2829
|
-
evaluate(effect) {
|
|
2830
|
-
if (this._exit) {
|
|
2831
|
-
return;
|
|
2832
|
-
} else if (this._yielded !== void 0) {
|
|
2833
|
-
const yielded = this._yielded;
|
|
2834
|
-
this._yielded = void 0;
|
|
2835
|
-
yielded();
|
|
2836
|
-
}
|
|
2837
|
-
const exit2 = this.runLoop(effect);
|
|
2838
|
-
if (exit2 === Yield) {
|
|
2839
|
-
return;
|
|
2840
|
-
}
|
|
2841
|
-
const interruptChildren = fiberMiddleware.interruptChildren && fiberMiddleware.interruptChildren(this);
|
|
2842
|
-
if (interruptChildren !== void 0) {
|
|
2843
|
-
return this.evaluate(flatMap3(interruptChildren, () => exit2));
|
|
2844
|
-
}
|
|
2845
|
-
this._exit = exit2;
|
|
2846
|
-
for (let i = 0; i < this._observers.length; i++) {
|
|
2847
|
-
this._observers[i](exit2);
|
|
2848
|
-
}
|
|
2849
|
-
this._observers.length = 0;
|
|
2850
|
-
}
|
|
2851
|
-
runLoop(effect) {
|
|
2852
|
-
let yielding = false;
|
|
2853
|
-
let current = effect;
|
|
2854
|
-
this.currentOpCount = 0;
|
|
2855
|
-
try {
|
|
2856
|
-
while (true) {
|
|
2857
|
-
this.currentOpCount++;
|
|
2858
|
-
if (!yielding && this.getRef(CurrentScheduler).shouldYield(this)) {
|
|
2859
|
-
yielding = true;
|
|
2860
|
-
const prev = current;
|
|
2861
|
-
current = flatMap3(yieldNow, () => prev);
|
|
2862
|
-
}
|
|
2863
|
-
current = current[evaluate](this);
|
|
2864
|
-
if (current === Yield) {
|
|
2865
|
-
const yielded = this._yielded;
|
|
2866
|
-
if (MicroExitTypeId in yielded) {
|
|
2867
|
-
this._yielded = void 0;
|
|
2868
|
-
return yielded;
|
|
2869
|
-
}
|
|
2870
|
-
return Yield;
|
|
2871
|
-
}
|
|
2872
|
-
}
|
|
2873
|
-
} catch (error) {
|
|
2874
|
-
if (!hasProperty(current, evaluate)) {
|
|
2875
|
-
return exitDie(`MicroFiber.runLoop: Not a valid effect: ${String(current)}`);
|
|
2876
|
-
}
|
|
2877
|
-
return exitDie(error);
|
|
2878
|
-
}
|
|
2879
|
-
}
|
|
2880
|
-
getCont(symbol3) {
|
|
2881
|
-
while (true) {
|
|
2882
|
-
const op = this._stack.pop();
|
|
2883
|
-
if (!op) return void 0;
|
|
2884
|
-
const cont = op[ensureCont] && op[ensureCont](this);
|
|
2885
|
-
if (cont) return {
|
|
2886
|
-
[symbol3]: cont
|
|
2887
|
-
};
|
|
2888
|
-
if (op[symbol3]) return op;
|
|
2889
|
-
}
|
|
2890
|
-
}
|
|
2891
|
-
// cancel the yielded operation, or for the yielded exit value
|
|
2892
|
-
_yielded = void 0;
|
|
2893
|
-
yieldWith(value) {
|
|
2894
|
-
this._yielded = value;
|
|
2895
|
-
return Yield;
|
|
2896
|
-
}
|
|
2897
|
-
children() {
|
|
2898
|
-
return this._children ??= /* @__PURE__ */ new Set();
|
|
2899
|
-
}
|
|
2900
|
-
};
|
|
2901
|
-
var fiberMiddleware = /* @__PURE__ */ globalValue("effect/Micro/fiberMiddleware", () => ({
|
|
2902
|
-
interruptChildren: void 0
|
|
2903
|
-
}));
|
|
2904
|
-
var fiberAwait = (self) => async((resume) => sync(self.addObserver((exit2) => resume(succeed(exit2)))));
|
|
2905
|
-
var fiberInterrupt = (self) => suspend(() => {
|
|
2906
|
-
self.unsafeInterrupt();
|
|
2907
|
-
return asVoid(fiberAwait(self));
|
|
2908
|
-
});
|
|
2909
|
-
var fiberInterruptAll = (fibers) => suspend(() => {
|
|
2910
|
-
for (const fiber of fibers) fiber.unsafeInterrupt();
|
|
2911
|
-
const iter = fibers[Symbol.iterator]();
|
|
2912
|
-
const wait = suspend(() => {
|
|
2913
|
-
let result = iter.next();
|
|
2914
|
-
while (!result.done) {
|
|
2915
|
-
if (result.value.unsafePoll()) {
|
|
2916
|
-
result = iter.next();
|
|
2917
|
-
continue;
|
|
2918
|
-
}
|
|
2919
|
-
const fiber = result.value;
|
|
2920
|
-
return async((resume) => {
|
|
2921
|
-
fiber.addObserver((_) => {
|
|
2922
|
-
resume(wait);
|
|
2923
|
-
});
|
|
2924
|
-
});
|
|
2925
|
-
}
|
|
2926
|
-
return exitVoid;
|
|
2927
|
-
});
|
|
2928
|
-
return wait;
|
|
2929
|
-
});
|
|
2930
|
-
var identifier = /* @__PURE__ */ Symbol.for("effect/Micro/identifier");
|
|
2931
|
-
var args = /* @__PURE__ */ Symbol.for("effect/Micro/args");
|
|
2932
|
-
var evaluate = /* @__PURE__ */ Symbol.for("effect/Micro/evaluate");
|
|
2933
|
-
var successCont = /* @__PURE__ */ Symbol.for("effect/Micro/successCont");
|
|
2934
|
-
var failureCont = /* @__PURE__ */ Symbol.for("effect/Micro/failureCont");
|
|
2935
|
-
var ensureCont = /* @__PURE__ */ Symbol.for("effect/Micro/ensureCont");
|
|
2936
|
-
var Yield = /* @__PURE__ */ Symbol.for("effect/Micro/Yield");
|
|
2937
|
-
var microVariance = {
|
|
2938
|
-
_A: identity,
|
|
2939
|
-
_E: identity,
|
|
2940
|
-
_R: identity
|
|
2941
|
-
};
|
|
2942
|
-
var MicroProto = {
|
|
2943
|
-
...EffectPrototype2,
|
|
2944
|
-
_op: "Micro",
|
|
2945
|
-
[TypeId5]: microVariance,
|
|
2946
|
-
pipe() {
|
|
2947
|
-
return pipeArguments(this, arguments);
|
|
2948
|
-
},
|
|
2949
|
-
[Symbol.iterator]() {
|
|
2950
|
-
return new SingleShotGen(new YieldWrap(this));
|
|
2951
|
-
},
|
|
2952
|
-
toJSON() {
|
|
2953
|
-
return {
|
|
2954
|
-
_id: "Micro",
|
|
2955
|
-
op: this[identifier],
|
|
2956
|
-
...args in this ? {
|
|
2957
|
-
args: this[args]
|
|
2958
|
-
} : void 0
|
|
2959
|
-
};
|
|
2960
|
-
},
|
|
2961
|
-
toString() {
|
|
2962
|
-
return format(this);
|
|
2963
|
-
},
|
|
2964
|
-
[NodeInspectSymbol]() {
|
|
2965
|
-
return format(this);
|
|
2966
|
-
}
|
|
2967
|
-
};
|
|
2968
|
-
function defaultEvaluate(_fiber) {
|
|
2969
|
-
return exitDie(`Micro.evaluate: Not implemented`);
|
|
2970
|
-
}
|
|
2971
|
-
var makePrimitiveProto = (options) => ({
|
|
2972
|
-
...MicroProto,
|
|
2973
|
-
[identifier]: options.op,
|
|
2974
|
-
[evaluate]: options.eval ?? defaultEvaluate,
|
|
2975
|
-
[successCont]: options.contA,
|
|
2976
|
-
[failureCont]: options.contE,
|
|
2977
|
-
[ensureCont]: options.ensure
|
|
2978
|
-
});
|
|
2979
|
-
var makePrimitive = (options) => {
|
|
2980
|
-
const Proto = makePrimitiveProto(options);
|
|
2981
|
-
return function() {
|
|
2982
|
-
const self = Object.create(Proto);
|
|
2983
|
-
self[args] = options.single === false ? arguments : arguments[0];
|
|
2984
|
-
return self;
|
|
2985
|
-
};
|
|
2986
|
-
};
|
|
2987
|
-
var makeExit = (options) => {
|
|
2988
|
-
const Proto = {
|
|
2989
|
-
...makePrimitiveProto(options),
|
|
2990
|
-
[MicroExitTypeId]: MicroExitTypeId,
|
|
2991
|
-
_tag: options.op,
|
|
2992
|
-
get [options.prop]() {
|
|
2993
|
-
return this[args];
|
|
2994
|
-
},
|
|
2995
|
-
toJSON() {
|
|
2996
|
-
return {
|
|
2997
|
-
_id: "MicroExit",
|
|
2998
|
-
_tag: options.op,
|
|
2999
|
-
[options.prop]: this[args]
|
|
3000
|
-
};
|
|
3001
|
-
},
|
|
3002
|
-
[symbol2](that) {
|
|
3003
|
-
return isMicroExit(that) && that._tag === options.op && equals(this[args], that[args]);
|
|
3004
|
-
},
|
|
3005
|
-
[symbol]() {
|
|
3006
|
-
return cached(this, combine(string(options.op))(hash(this[args])));
|
|
3007
|
-
}
|
|
3008
|
-
};
|
|
3009
|
-
return function(value) {
|
|
3010
|
-
const self = Object.create(Proto);
|
|
3011
|
-
self[args] = value;
|
|
3012
|
-
self[successCont] = void 0;
|
|
3013
|
-
self[failureCont] = void 0;
|
|
3014
|
-
self[ensureCont] = void 0;
|
|
3015
|
-
return self;
|
|
3016
|
-
};
|
|
3017
|
-
};
|
|
3018
|
-
var succeed = /* @__PURE__ */ makeExit({
|
|
3019
|
-
op: "Success",
|
|
3020
|
-
prop: "value",
|
|
3021
|
-
eval(fiber) {
|
|
3022
|
-
const cont = fiber.getCont(successCont);
|
|
3023
|
-
return cont ? cont[successCont](this[args], fiber) : fiber.yieldWith(this);
|
|
3024
|
-
}
|
|
3025
|
-
});
|
|
3026
|
-
var failCause2 = /* @__PURE__ */ makeExit({
|
|
3027
|
-
op: "Failure",
|
|
3028
|
-
prop: "cause",
|
|
3029
|
-
eval(fiber) {
|
|
3030
|
-
let cont = fiber.getCont(failureCont);
|
|
3031
|
-
while (causeIsInterrupt(this[args]) && cont && fiber.interruptible) {
|
|
3032
|
-
cont = fiber.getCont(failureCont);
|
|
3033
|
-
}
|
|
3034
|
-
return cont ? cont[failureCont](this[args], fiber) : fiber.yieldWith(this);
|
|
3035
|
-
}
|
|
3036
|
-
});
|
|
3037
|
-
var fail3 = (error) => failCause2(causeFail(error));
|
|
3038
|
-
var sync = /* @__PURE__ */ makePrimitive({
|
|
3039
|
-
op: "Sync",
|
|
3040
|
-
eval(fiber) {
|
|
3041
|
-
const value = this[args]();
|
|
3042
|
-
const cont = fiber.getCont(successCont);
|
|
3043
|
-
return cont ? cont[successCont](value, fiber) : fiber.yieldWith(exitSucceed(value));
|
|
3044
|
-
}
|
|
3045
|
-
});
|
|
3046
|
-
var suspend = /* @__PURE__ */ makePrimitive({
|
|
3047
|
-
op: "Suspend",
|
|
3048
|
-
eval(_fiber) {
|
|
3049
|
-
return this[args]();
|
|
3050
|
-
}
|
|
3051
|
-
});
|
|
3052
|
-
var yieldNowWith = /* @__PURE__ */ makePrimitive({
|
|
3053
|
-
op: "Yield",
|
|
3054
|
-
eval(fiber) {
|
|
3055
|
-
let resumed = false;
|
|
3056
|
-
fiber.getRef(CurrentScheduler).scheduleTask(() => {
|
|
3057
|
-
if (resumed) return;
|
|
3058
|
-
fiber.evaluate(exitVoid);
|
|
3059
|
-
}, this[args] ?? 0);
|
|
3060
|
-
return fiber.yieldWith(() => {
|
|
3061
|
-
resumed = true;
|
|
3062
|
-
});
|
|
3063
|
-
}
|
|
3064
|
-
});
|
|
3065
|
-
var yieldNow = /* @__PURE__ */ yieldNowWith(0);
|
|
3066
|
-
var void_ = /* @__PURE__ */ succeed(void 0);
|
|
3067
|
-
var try_ = (options) => suspend(() => {
|
|
3068
|
-
try {
|
|
3069
|
-
return succeed(options.try());
|
|
3070
|
-
} catch (err) {
|
|
3071
|
-
return fail3(options.catch(err));
|
|
3072
|
-
}
|
|
3073
|
-
});
|
|
3074
|
-
var tryPromise = (options) => asyncOptions(function(resume, signal) {
|
|
3075
|
-
try {
|
|
3076
|
-
options.try(signal).then((a) => resume(succeed(a)), (e) => resume(fail3(options.catch(e))));
|
|
3077
|
-
} catch (err) {
|
|
3078
|
-
resume(fail3(options.catch(err)));
|
|
3079
|
-
}
|
|
3080
|
-
}, options.try.length !== 0);
|
|
3081
|
-
var withMicroFiber = /* @__PURE__ */ makePrimitive({
|
|
3082
|
-
op: "WithMicroFiber",
|
|
3083
|
-
eval(fiber) {
|
|
3084
|
-
return this[args](fiber);
|
|
3085
|
-
}
|
|
3086
|
-
});
|
|
3087
|
-
var asyncOptions = /* @__PURE__ */ makePrimitive({
|
|
3088
|
-
op: "Async",
|
|
3089
|
-
single: false,
|
|
3090
|
-
eval(fiber) {
|
|
3091
|
-
const register = this[args][0];
|
|
3092
|
-
let resumed = false;
|
|
3093
|
-
let yielded = false;
|
|
3094
|
-
const controller = this[args][1] ? new AbortController() : void 0;
|
|
3095
|
-
const onCancel = register((effect) => {
|
|
3096
|
-
if (resumed) return;
|
|
3097
|
-
resumed = true;
|
|
3098
|
-
if (yielded) {
|
|
3099
|
-
fiber.evaluate(effect);
|
|
3100
|
-
} else {
|
|
3101
|
-
yielded = effect;
|
|
3102
|
-
}
|
|
3103
|
-
}, controller?.signal);
|
|
3104
|
-
if (yielded !== false) return yielded;
|
|
3105
|
-
yielded = true;
|
|
3106
|
-
fiber._yielded = () => {
|
|
3107
|
-
resumed = true;
|
|
3108
|
-
};
|
|
3109
|
-
if (controller === void 0 && onCancel === void 0) {
|
|
3110
|
-
return Yield;
|
|
3111
|
-
}
|
|
3112
|
-
fiber._stack.push(asyncFinalizer(() => {
|
|
3113
|
-
resumed = true;
|
|
3114
|
-
controller?.abort();
|
|
3115
|
-
return onCancel ?? exitVoid;
|
|
3116
|
-
}));
|
|
3117
|
-
return Yield;
|
|
3118
|
-
}
|
|
3119
|
-
});
|
|
3120
|
-
var asyncFinalizer = /* @__PURE__ */ makePrimitive({
|
|
3121
|
-
op: "AsyncFinalizer",
|
|
3122
|
-
ensure(fiber) {
|
|
3123
|
-
if (fiber.interruptible) {
|
|
3124
|
-
fiber.interruptible = false;
|
|
3125
|
-
fiber._stack.push(setInterruptible(true));
|
|
3126
|
-
}
|
|
3127
|
-
},
|
|
3128
|
-
contE(cause, _fiber) {
|
|
3129
|
-
return causeIsInterrupt(cause) ? flatMap3(this[args](), () => failCause2(cause)) : failCause2(cause);
|
|
3130
|
-
}
|
|
3131
|
-
});
|
|
3132
|
-
var async = (register) => asyncOptions(register, register.length >= 2);
|
|
3133
|
-
var gen = (...args2) => suspend(() => fromIterator(args2.length === 1 ? args2[0]() : args2[1].call(args2[0])));
|
|
3134
|
-
var fromIterator = /* @__PURE__ */ makePrimitive({
|
|
3135
|
-
op: "Iterator",
|
|
3136
|
-
contA(value, fiber) {
|
|
3137
|
-
const state = this[args].next(value);
|
|
3138
|
-
if (state.done) return succeed(state.value);
|
|
3139
|
-
fiber._stack.push(this);
|
|
3140
|
-
return yieldWrapGet(state.value);
|
|
3141
|
-
},
|
|
3142
|
-
eval(fiber) {
|
|
3143
|
-
return this[successCont](void 0, fiber);
|
|
3144
|
-
}
|
|
3145
|
-
});
|
|
3146
|
-
var as = /* @__PURE__ */ dual(2, (self, value) => map6(self, (_) => value));
|
|
3147
|
-
var andThen = /* @__PURE__ */ dual(2, (self, f) => flatMap3(self, (a) => {
|
|
3148
|
-
const value = isMicro(f) ? f : typeof f === "function" ? f(a) : f;
|
|
3149
|
-
return isMicro(value) ? value : succeed(value);
|
|
3150
|
-
}));
|
|
3151
|
-
var tap = /* @__PURE__ */ dual(2, (self, f) => flatMap3(self, (a) => {
|
|
3152
|
-
const value = isMicro(f) ? f : typeof f === "function" ? f(a) : f;
|
|
3153
|
-
return isMicro(value) ? as(value, a) : succeed(a);
|
|
3154
|
-
}));
|
|
3155
|
-
var asVoid = (self) => flatMap3(self, (_) => exitVoid);
|
|
3156
|
-
var exit = (self) => matchCause(self, {
|
|
3157
|
-
onFailure: exitFailCause,
|
|
3158
|
-
onSuccess: exitSucceed
|
|
3159
|
-
});
|
|
3160
|
-
var flatMap3 = /* @__PURE__ */ dual(2, (self, f) => {
|
|
3161
|
-
const onSuccess = Object.create(OnSuccessProto);
|
|
3162
|
-
onSuccess[args] = self;
|
|
3163
|
-
onSuccess[successCont] = f;
|
|
3164
|
-
return onSuccess;
|
|
3165
|
-
});
|
|
3166
|
-
var OnSuccessProto = /* @__PURE__ */ makePrimitiveProto({
|
|
3167
|
-
op: "OnSuccess",
|
|
3168
|
-
eval(fiber) {
|
|
3169
|
-
fiber._stack.push(this);
|
|
3170
|
-
return this[args];
|
|
3171
|
-
}
|
|
3172
|
-
});
|
|
3173
|
-
var map6 = /* @__PURE__ */ dual(2, (self, f) => flatMap3(self, (a) => succeed(f(a))));
|
|
3174
|
-
var isMicroExit = (u) => hasProperty(u, MicroExitTypeId);
|
|
3175
|
-
var exitSucceed = succeed;
|
|
3176
|
-
var exitFailCause = failCause2;
|
|
3177
|
-
var exitInterrupt = /* @__PURE__ */ exitFailCause(/* @__PURE__ */ causeInterrupt());
|
|
3178
|
-
var exitDie = (defect) => exitFailCause(causeDie(defect));
|
|
3179
|
-
var exitVoid = /* @__PURE__ */ exitSucceed(void 0);
|
|
3180
|
-
var exitVoidAll = (exits) => {
|
|
3181
|
-
for (const exit2 of exits) {
|
|
3182
|
-
if (exit2._tag === "Failure") {
|
|
3183
|
-
return exit2;
|
|
3184
|
-
}
|
|
3185
|
-
}
|
|
3186
|
-
return exitVoid;
|
|
3187
|
-
};
|
|
3188
|
-
var setImmediate = "setImmediate" in globalThis ? globalThis.setImmediate : (f) => setTimeout(f, 0);
|
|
3189
|
-
var MicroSchedulerDefault = class {
|
|
3190
|
-
tasks = [];
|
|
3191
|
-
running = false;
|
|
3192
|
-
/**
|
|
3193
|
-
* @since 3.5.9
|
|
3194
|
-
*/
|
|
3195
|
-
scheduleTask(task, _priority) {
|
|
3196
|
-
this.tasks.push(task);
|
|
3197
|
-
if (!this.running) {
|
|
3198
|
-
this.running = true;
|
|
3199
|
-
setImmediate(this.afterScheduled);
|
|
3200
|
-
}
|
|
3201
|
-
}
|
|
3202
|
-
/**
|
|
3203
|
-
* @since 3.5.9
|
|
3204
|
-
*/
|
|
3205
|
-
afterScheduled = () => {
|
|
3206
|
-
this.running = false;
|
|
3207
|
-
this.runTasks();
|
|
3208
|
-
};
|
|
3209
|
-
/**
|
|
3210
|
-
* @since 3.5.9
|
|
3211
|
-
*/
|
|
3212
|
-
runTasks() {
|
|
3213
|
-
const tasks = this.tasks;
|
|
3214
|
-
this.tasks = [];
|
|
3215
|
-
for (let i = 0, len = tasks.length; i < len; i++) {
|
|
3216
|
-
tasks[i]();
|
|
3217
|
-
}
|
|
3218
|
-
}
|
|
3219
|
-
/**
|
|
3220
|
-
* @since 3.5.9
|
|
3221
|
-
*/
|
|
3222
|
-
shouldYield(fiber) {
|
|
3223
|
-
return fiber.currentOpCount >= fiber.getRef(MaxOpsBeforeYield);
|
|
3224
|
-
}
|
|
3225
|
-
/**
|
|
3226
|
-
* @since 3.5.9
|
|
3227
|
-
*/
|
|
3228
|
-
flush() {
|
|
3229
|
-
while (this.tasks.length > 0) {
|
|
3230
|
-
this.runTasks();
|
|
3231
|
-
}
|
|
3232
|
-
}
|
|
3233
|
-
};
|
|
3234
|
-
var service = (tag) => withMicroFiber((fiber) => succeed(unsafeGet3(fiber.context, tag)));
|
|
3235
|
-
var updateContext = /* @__PURE__ */ dual(2, (self, f) => withMicroFiber((fiber) => {
|
|
3236
|
-
const prev = fiber.context;
|
|
3237
|
-
fiber.context = f(prev);
|
|
3238
|
-
return onExit(self, () => {
|
|
3239
|
-
fiber.context = prev;
|
|
3240
|
-
return void_;
|
|
3241
|
-
});
|
|
3242
|
-
}));
|
|
3243
|
-
var provideContext = /* @__PURE__ */ dual(2, (self, provided) => updateContext(self, merge2(provided)));
|
|
3244
|
-
var provideService = /* @__PURE__ */ dual(3, (self, tag, service2) => updateContext(self, add2(tag, service2)));
|
|
3245
|
-
var MaxOpsBeforeYield = class extends (/* @__PURE__ */ Reference2()("effect/Micro/currentMaxOpsBeforeYield", {
|
|
3246
|
-
defaultValue: () => 2048
|
|
3247
|
-
})) {
|
|
3248
|
-
};
|
|
3249
|
-
var CurrentConcurrency = class extends (/* @__PURE__ */ Reference2()("effect/Micro/currentConcurrency", {
|
|
3250
|
-
defaultValue: () => "unbounded"
|
|
3251
|
-
})) {
|
|
3252
|
-
};
|
|
3253
|
-
var CurrentScheduler = class extends (/* @__PURE__ */ Reference2()("effect/Micro/currentScheduler", {
|
|
3254
|
-
defaultValue: () => new MicroSchedulerDefault()
|
|
3255
|
-
})) {
|
|
3256
|
-
};
|
|
3257
|
-
var repeatExit = /* @__PURE__ */ dual(2, (self, options) => suspend(() => {
|
|
3258
|
-
const startedAt = options.schedule ? Date.now() : 0;
|
|
3259
|
-
let attempt = 0;
|
|
3260
|
-
const loop = flatMap3(exit(self), (exit2) => {
|
|
3261
|
-
if (options.while !== void 0 && !options.while(exit2)) {
|
|
3262
|
-
return exit2;
|
|
3263
|
-
} else if (options.times !== void 0 && attempt >= options.times) {
|
|
3264
|
-
return exit2;
|
|
3265
|
-
}
|
|
3266
|
-
attempt++;
|
|
3267
|
-
let delayEffect = yieldNow;
|
|
3268
|
-
if (options.schedule !== void 0) {
|
|
3269
|
-
const elapsed = Date.now() - startedAt;
|
|
3270
|
-
const duration = options.schedule(attempt, elapsed);
|
|
3271
|
-
if (isNone2(duration)) {
|
|
3272
|
-
return exit2;
|
|
3273
|
-
}
|
|
3274
|
-
delayEffect = sleep(duration.value);
|
|
3275
|
-
}
|
|
3276
|
-
return flatMap3(delayEffect, () => loop);
|
|
3277
|
-
});
|
|
3278
|
-
return loop;
|
|
3279
|
-
}));
|
|
3280
|
-
var repeat = /* @__PURE__ */ dual((args2) => isMicro(args2[0]), (self, options) => repeatExit(self, {
|
|
3281
|
-
...options,
|
|
3282
|
-
while: (exit2) => exit2._tag === "Success" && (options?.while === void 0 || options.while(exit2.value))
|
|
3283
|
-
}));
|
|
3284
|
-
var catchAllCause = /* @__PURE__ */ dual(2, (self, f) => {
|
|
3285
|
-
const onFailure = Object.create(OnFailureProto);
|
|
3286
|
-
onFailure[args] = self;
|
|
3287
|
-
onFailure[failureCont] = f;
|
|
3288
|
-
return onFailure;
|
|
3289
|
-
});
|
|
3290
|
-
var OnFailureProto = /* @__PURE__ */ makePrimitiveProto({
|
|
3291
|
-
op: "OnFailure",
|
|
3292
|
-
eval(fiber) {
|
|
3293
|
-
fiber._stack.push(this);
|
|
3294
|
-
return this[args];
|
|
33
|
+
// src/types.ts
|
|
34
|
+
var BotResponse = class _BotResponse {
|
|
35
|
+
response;
|
|
36
|
+
constructor(response) {
|
|
37
|
+
this.response = response;
|
|
3295
38
|
}
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
var catchAll = /* @__PURE__ */ dual(2, (self, f) => catchCauseIf(self, causeIsFail, (cause) => f(cause.error)));
|
|
3299
|
-
var matchCauseEffect = /* @__PURE__ */ dual(2, (self, options) => {
|
|
3300
|
-
const primitive = Object.create(OnSuccessAndFailureProto);
|
|
3301
|
-
primitive[args] = self;
|
|
3302
|
-
primitive[successCont] = options.onSuccess;
|
|
3303
|
-
primitive[failureCont] = options.onFailure;
|
|
3304
|
-
return primitive;
|
|
3305
|
-
});
|
|
3306
|
-
var OnSuccessAndFailureProto = /* @__PURE__ */ makePrimitiveProto({
|
|
3307
|
-
op: "OnSuccessAndFailure",
|
|
3308
|
-
eval(fiber) {
|
|
3309
|
-
fiber._stack.push(this);
|
|
3310
|
-
return this[args];
|
|
3311
|
-
}
|
|
3312
|
-
});
|
|
3313
|
-
var matchCause = /* @__PURE__ */ dual(2, (self, options) => matchCauseEffect(self, {
|
|
3314
|
-
onFailure: (cause) => sync(() => options.onFailure(cause)),
|
|
3315
|
-
onSuccess: (value) => sync(() => options.onSuccess(value))
|
|
3316
|
-
}));
|
|
3317
|
-
var sleep = (millis) => async((resume) => {
|
|
3318
|
-
const timeout = setTimeout(() => {
|
|
3319
|
-
resume(void_);
|
|
3320
|
-
}, millis);
|
|
3321
|
-
return sync(() => {
|
|
3322
|
-
clearTimeout(timeout);
|
|
3323
|
-
});
|
|
3324
|
-
});
|
|
3325
|
-
var delay = /* @__PURE__ */ dual(2, (self, millis) => andThen(sleep(millis), self));
|
|
3326
|
-
var MicroScopeTypeId = /* @__PURE__ */ Symbol.for("effect/Micro/MicroScope");
|
|
3327
|
-
var MicroScopeImpl = class _MicroScopeImpl {
|
|
3328
|
-
[MicroScopeTypeId];
|
|
3329
|
-
state = {
|
|
3330
|
-
_tag: "Open",
|
|
3331
|
-
finalizers: /* @__PURE__ */ new Set()
|
|
3332
|
-
};
|
|
3333
|
-
constructor() {
|
|
3334
|
-
this[MicroScopeTypeId] = MicroScopeTypeId;
|
|
3335
|
-
}
|
|
3336
|
-
unsafeAddFinalizer(finalizer) {
|
|
3337
|
-
if (this.state._tag === "Open") {
|
|
3338
|
-
this.state.finalizers.add(finalizer);
|
|
3339
|
-
}
|
|
3340
|
-
}
|
|
3341
|
-
addFinalizer(finalizer) {
|
|
3342
|
-
return suspend(() => {
|
|
3343
|
-
if (this.state._tag === "Open") {
|
|
3344
|
-
this.state.finalizers.add(finalizer);
|
|
3345
|
-
return void_;
|
|
3346
|
-
}
|
|
3347
|
-
return finalizer(this.state.exit);
|
|
3348
|
-
});
|
|
3349
|
-
}
|
|
3350
|
-
unsafeRemoveFinalizer(finalizer) {
|
|
3351
|
-
if (this.state._tag === "Open") {
|
|
3352
|
-
this.state.finalizers.delete(finalizer);
|
|
3353
|
-
}
|
|
3354
|
-
}
|
|
3355
|
-
close(microExit) {
|
|
3356
|
-
return suspend(() => {
|
|
3357
|
-
if (this.state._tag === "Open") {
|
|
3358
|
-
const finalizers = Array.from(this.state.finalizers).reverse();
|
|
3359
|
-
this.state = {
|
|
3360
|
-
_tag: "Closed",
|
|
3361
|
-
exit: microExit
|
|
3362
|
-
};
|
|
3363
|
-
return flatMap3(forEach3(finalizers, (finalizer) => exit(finalizer(microExit))), exitVoidAll);
|
|
3364
|
-
}
|
|
3365
|
-
return void_;
|
|
3366
|
-
});
|
|
3367
|
-
}
|
|
3368
|
-
get fork() {
|
|
3369
|
-
return sync(() => {
|
|
3370
|
-
const newScope = new _MicroScopeImpl();
|
|
3371
|
-
if (this.state._tag === "Closed") {
|
|
3372
|
-
newScope.state = this.state;
|
|
3373
|
-
return newScope;
|
|
3374
|
-
}
|
|
3375
|
-
function fin(exit2) {
|
|
3376
|
-
return newScope.close(exit2);
|
|
3377
|
-
}
|
|
3378
|
-
this.state.finalizers.add(fin);
|
|
3379
|
-
newScope.unsafeAddFinalizer((_) => sync(() => this.unsafeRemoveFinalizer(fin)));
|
|
3380
|
-
return newScope;
|
|
3381
|
-
});
|
|
3382
|
-
}
|
|
3383
|
-
};
|
|
3384
|
-
var onExit = /* @__PURE__ */ dual(2, (self, f) => uninterruptibleMask((restore) => matchCauseEffect(restore(self), {
|
|
3385
|
-
onFailure: (cause) => flatMap3(f(exitFailCause(cause)), () => failCause2(cause)),
|
|
3386
|
-
onSuccess: (a) => flatMap3(f(exitSucceed(a)), () => succeed(a))
|
|
3387
|
-
})));
|
|
3388
|
-
var setInterruptible = /* @__PURE__ */ makePrimitive({
|
|
3389
|
-
op: "SetInterruptible",
|
|
3390
|
-
ensure(fiber) {
|
|
3391
|
-
fiber.interruptible = this[args];
|
|
3392
|
-
if (fiber._interrupted && fiber.interruptible) {
|
|
3393
|
-
return () => exitInterrupt;
|
|
3394
|
-
}
|
|
3395
|
-
}
|
|
3396
|
-
});
|
|
3397
|
-
var interruptible = (self) => withMicroFiber((fiber) => {
|
|
3398
|
-
if (fiber.interruptible) return self;
|
|
3399
|
-
fiber.interruptible = true;
|
|
3400
|
-
fiber._stack.push(setInterruptible(false));
|
|
3401
|
-
if (fiber._interrupted) return exitInterrupt;
|
|
3402
|
-
return self;
|
|
3403
|
-
});
|
|
3404
|
-
var uninterruptibleMask = (f) => withMicroFiber((fiber) => {
|
|
3405
|
-
if (!fiber.interruptible) return f(identity);
|
|
3406
|
-
fiber.interruptible = false;
|
|
3407
|
-
fiber._stack.push(setInterruptible(true));
|
|
3408
|
-
return f(interruptible);
|
|
3409
|
-
});
|
|
3410
|
-
var whileLoop = /* @__PURE__ */ makePrimitive({
|
|
3411
|
-
op: "While",
|
|
3412
|
-
contA(value, fiber) {
|
|
3413
|
-
this[args].step(value);
|
|
3414
|
-
if (this[args].while()) {
|
|
3415
|
-
fiber._stack.push(this);
|
|
3416
|
-
return this[args].body();
|
|
3417
|
-
}
|
|
3418
|
-
return exitVoid;
|
|
3419
|
-
},
|
|
3420
|
-
eval(fiber) {
|
|
3421
|
-
if (this[args].while()) {
|
|
3422
|
-
fiber._stack.push(this);
|
|
3423
|
-
return this[args].body();
|
|
3424
|
-
}
|
|
3425
|
-
return exitVoid;
|
|
3426
|
-
}
|
|
3427
|
-
});
|
|
3428
|
-
var forEach3 = (iterable, f, options) => withMicroFiber((parent) => {
|
|
3429
|
-
const concurrencyOption = options?.concurrency === "inherit" ? parent.getRef(CurrentConcurrency) : options?.concurrency ?? 1;
|
|
3430
|
-
const concurrency = concurrencyOption === "unbounded" ? Number.POSITIVE_INFINITY : Math.max(1, concurrencyOption);
|
|
3431
|
-
const items = fromIterable(iterable);
|
|
3432
|
-
let length = items.length;
|
|
3433
|
-
if (length === 0) {
|
|
3434
|
-
return options?.discard ? void_ : succeed([]);
|
|
3435
|
-
}
|
|
3436
|
-
const out = options?.discard ? void 0 : new Array(length);
|
|
3437
|
-
let index = 0;
|
|
3438
|
-
if (concurrency === 1) {
|
|
3439
|
-
return as(whileLoop({
|
|
3440
|
-
while: () => index < items.length,
|
|
3441
|
-
body: () => f(items[index], index),
|
|
3442
|
-
step: out ? (b) => out[index++] = b : (_) => index++
|
|
3443
|
-
}), out);
|
|
3444
|
-
}
|
|
3445
|
-
return async((resume) => {
|
|
3446
|
-
const fibers = /* @__PURE__ */ new Set();
|
|
3447
|
-
let result = void 0;
|
|
3448
|
-
let inProgress = 0;
|
|
3449
|
-
let doneCount = 0;
|
|
3450
|
-
let pumping = false;
|
|
3451
|
-
let interrupted = false;
|
|
3452
|
-
function pump() {
|
|
3453
|
-
pumping = true;
|
|
3454
|
-
while (inProgress < concurrency && index < length) {
|
|
3455
|
-
const currentIndex = index;
|
|
3456
|
-
const item = items[currentIndex];
|
|
3457
|
-
index++;
|
|
3458
|
-
inProgress++;
|
|
3459
|
-
try {
|
|
3460
|
-
const child = unsafeFork(parent, f(item, currentIndex), true, true);
|
|
3461
|
-
fibers.add(child);
|
|
3462
|
-
child.addObserver((exit2) => {
|
|
3463
|
-
fibers.delete(child);
|
|
3464
|
-
if (interrupted) {
|
|
3465
|
-
return;
|
|
3466
|
-
} else if (exit2._tag === "Failure") {
|
|
3467
|
-
if (result === void 0) {
|
|
3468
|
-
result = exit2;
|
|
3469
|
-
length = index;
|
|
3470
|
-
fibers.forEach((fiber) => fiber.unsafeInterrupt());
|
|
3471
|
-
}
|
|
3472
|
-
} else if (out !== void 0) {
|
|
3473
|
-
out[currentIndex] = exit2.value;
|
|
3474
|
-
}
|
|
3475
|
-
doneCount++;
|
|
3476
|
-
inProgress--;
|
|
3477
|
-
if (doneCount === length) {
|
|
3478
|
-
resume(result ?? succeed(out));
|
|
3479
|
-
} else if (!pumping && inProgress < concurrency) {
|
|
3480
|
-
pump();
|
|
3481
|
-
}
|
|
3482
|
-
});
|
|
3483
|
-
} catch (err) {
|
|
3484
|
-
result = exitDie(err);
|
|
3485
|
-
length = index;
|
|
3486
|
-
fibers.forEach((fiber) => fiber.unsafeInterrupt());
|
|
3487
|
-
}
|
|
3488
|
-
}
|
|
3489
|
-
pumping = false;
|
|
3490
|
-
}
|
|
3491
|
-
pump();
|
|
3492
|
-
return suspend(() => {
|
|
3493
|
-
interrupted = true;
|
|
3494
|
-
index = length;
|
|
3495
|
-
return fiberInterruptAll(fibers);
|
|
3496
|
-
});
|
|
3497
|
-
});
|
|
3498
|
-
});
|
|
3499
|
-
var unsafeFork = (parent, effect, immediate = false, daemon = false) => {
|
|
3500
|
-
const child = new MicroFiberImpl(parent.context, parent.interruptible);
|
|
3501
|
-
if (!daemon) {
|
|
3502
|
-
parent.children().add(child);
|
|
3503
|
-
child.addObserver(() => parent.children().delete(child));
|
|
3504
|
-
}
|
|
3505
|
-
if (immediate) {
|
|
3506
|
-
child.evaluate(effect);
|
|
3507
|
-
} else {
|
|
3508
|
-
parent.getRef(CurrentScheduler).scheduleTask(() => child.evaluate(effect), 0);
|
|
3509
|
-
}
|
|
3510
|
-
return child;
|
|
3511
|
-
};
|
|
3512
|
-
var forkDaemon = (self) => withMicroFiber((fiber) => succeed(unsafeFork(fiber, self, false, true)));
|
|
3513
|
-
var runFork = (effect, options) => {
|
|
3514
|
-
const fiber = new MicroFiberImpl(CurrentScheduler.context(options?.scheduler ?? new MicroSchedulerDefault()));
|
|
3515
|
-
fiber.evaluate(effect);
|
|
3516
|
-
if (options?.signal) {
|
|
3517
|
-
if (options.signal.aborted) {
|
|
3518
|
-
fiber.unsafeInterrupt();
|
|
3519
|
-
} else {
|
|
3520
|
-
const abort = () => fiber.unsafeInterrupt();
|
|
3521
|
-
options.signal.addEventListener("abort", abort, {
|
|
3522
|
-
once: true
|
|
3523
|
-
});
|
|
3524
|
-
fiber.addObserver(() => options.signal.removeEventListener("abort", abort));
|
|
3525
|
-
}
|
|
3526
|
-
}
|
|
3527
|
-
return fiber;
|
|
3528
|
-
};
|
|
3529
|
-
var runPromiseExit = (effect, options) => new Promise((resolve, _reject) => {
|
|
3530
|
-
const handle = runFork(effect, options);
|
|
3531
|
-
handle.addObserver(resolve);
|
|
3532
|
-
});
|
|
3533
|
-
var runPromise = (effect, options) => runPromiseExit(effect, options).then((exit2) => {
|
|
3534
|
-
if (exit2._tag === "Failure") {
|
|
3535
|
-
throw exit2.cause;
|
|
39
|
+
static make(result) {
|
|
40
|
+
return new _BotResponse(result);
|
|
3536
41
|
}
|
|
3537
|
-
|
|
3538
|
-
});
|
|
3539
|
-
|
|
3540
|
-
// src/internal/handle-update.ts
|
|
3541
|
-
var import_tg_bot_client = require("@effect-ak/tg-bot-client");
|
|
3542
|
-
|
|
3543
|
-
// src/internal/poll-settings.ts
|
|
3544
|
-
var BotUpdateHandlersTag = class extends Tag2("BotUpdateHandlers")() {
|
|
42
|
+
static ignore = new _BotResponse();
|
|
3545
43
|
};
|
|
3546
|
-
var
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
let log_level = input.log_level ?? "info";
|
|
3554
|
-
let on_error = input.on_error;
|
|
3555
|
-
if (batch_size < 10 || batch_size > 100) {
|
|
3556
|
-
console.warn("Wrong batch_size, must be in [10..100], using 10 instead");
|
|
3557
|
-
batch_size = 10;
|
|
3558
|
-
}
|
|
3559
|
-
if (poll_timeout < 2 || poll_timeout > 120) {
|
|
3560
|
-
console.warn("Wrong poll_timeout, must be in [2..120], using 20 instead");
|
|
3561
|
-
poll_timeout = 20;
|
|
3562
|
-
}
|
|
3563
|
-
if (max_empty_responses && max_empty_responses < 2) {
|
|
3564
|
-
console.warn(
|
|
3565
|
-
"Wrong max_empty_responses, must be in [2..infinity], using infinity"
|
|
3566
|
-
);
|
|
3567
|
-
max_empty_responses = void 0;
|
|
3568
|
-
}
|
|
3569
|
-
if (!log_level) {
|
|
3570
|
-
log_level = "info";
|
|
3571
|
-
}
|
|
3572
|
-
if (!on_error) {
|
|
3573
|
-
on_error = "stop";
|
|
3574
|
-
}
|
|
3575
|
-
const config = new _BotPollSettings({
|
|
3576
|
-
batch_size,
|
|
3577
|
-
poll_timeout,
|
|
3578
|
-
max_empty_responses,
|
|
3579
|
-
log_level,
|
|
3580
|
-
on_error
|
|
3581
|
-
});
|
|
3582
|
-
console.log("bot poll settings", config);
|
|
3583
|
-
return config;
|
|
3584
|
-
}
|
|
44
|
+
var extractCommand = (update) => {
|
|
45
|
+
if (typeof update !== "object" || update === null) return void 0;
|
|
46
|
+
const u = update;
|
|
47
|
+
if (!u.entities || !u.text) return void 0;
|
|
48
|
+
const entity = u.entities.find((e) => e.type === "bot_command");
|
|
49
|
+
if (!entity) return void 0;
|
|
50
|
+
return u.text.slice(entity.offset, entity.offset + entity.length);
|
|
3585
51
|
};
|
|
3586
|
-
var
|
|
3587
|
-
|
|
3588
|
-
{
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
}
|
|
3592
|
-
|
|
3593
|
-
|
|
52
|
+
var createBotContext = (update) => {
|
|
53
|
+
const command = extractCommand(update);
|
|
54
|
+
return {
|
|
55
|
+
command,
|
|
56
|
+
reply: (text, options) => BotResponse.make({ type: "message", text, ...options }),
|
|
57
|
+
replyWithDocument: (document, options) => BotResponse.make({ type: "document", document, ...options }),
|
|
58
|
+
replyWithPhoto: (photo, options) => BotResponse.make({ type: "photo", photo, ...options }),
|
|
59
|
+
ignore: BotResponse.ignore
|
|
60
|
+
};
|
|
3594
61
|
};
|
|
3595
62
|
|
|
3596
|
-
// src/
|
|
63
|
+
// src/bot-processor.ts
|
|
3597
64
|
var isGuardedHandler = (handler) => typeof handler === "object" && handler !== null && "handle" in handler;
|
|
3598
65
|
var executeSingleGuard = async (guard, update, ctx) => {
|
|
3599
66
|
const input = { update, ctx };
|
|
@@ -3610,454 +77,296 @@ var executeGuards = async (guards, update, ctx) => {
|
|
|
3610
77
|
}
|
|
3611
78
|
return BotResponse.ignore;
|
|
3612
79
|
};
|
|
3613
|
-
var executeHandler = (handler, update, ctx) => {
|
|
80
|
+
var executeHandler = async (handler, update, ctx) => {
|
|
3614
81
|
if (typeof handler === "function") {
|
|
3615
|
-
return handler(update);
|
|
82
|
+
return await handler(update);
|
|
3616
83
|
}
|
|
3617
84
|
if (Array.isArray(handler)) {
|
|
3618
|
-
return executeGuards(handler, update, ctx);
|
|
85
|
+
return await executeGuards(handler, update, ctx);
|
|
3619
86
|
}
|
|
3620
87
|
if (isGuardedHandler(handler)) {
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
);
|
|
88
|
+
const result = await executeSingleGuard(handler, update, ctx);
|
|
89
|
+
return result ?? BotResponse.ignore;
|
|
3624
90
|
}
|
|
3625
91
|
return BotResponse.ignore;
|
|
3626
92
|
};
|
|
3627
93
|
var extractUpdate = (input) => {
|
|
3628
94
|
for (const [field, value] of Object.entries(input)) {
|
|
3629
|
-
if (field
|
|
3630
|
-
|
|
3631
|
-
}
|
|
3632
|
-
return {
|
|
3633
|
-
type: field,
|
|
3634
|
-
...value
|
|
3635
|
-
};
|
|
95
|
+
if (field === "update_id") continue;
|
|
96
|
+
return { type: field, ...value };
|
|
3636
97
|
}
|
|
3637
|
-
return;
|
|
3638
|
-
};
|
|
3639
|
-
var BatchUpdateResult = class extends Class2 {
|
|
98
|
+
return void 0;
|
|
3640
99
|
};
|
|
3641
|
-
var handleUpdates = (updates
|
|
3642
|
-
|
|
3643
|
-
|
|
3644
|
-
if (updateHandler.type == "single") {
|
|
3645
|
-
return yield* handleOneByOne(updates, updateHandler, pollSettings);
|
|
3646
|
-
} else {
|
|
3647
|
-
return yield* handleEntireBatch(updates, updateHandler);
|
|
100
|
+
var handleUpdates = async (updates, behavior, client, settings, log, onHandleResult) => {
|
|
101
|
+
if (behavior.type === "single") {
|
|
102
|
+
return handleOneByOne(updates, behavior, client, settings, log, onHandleResult);
|
|
3648
103
|
}
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
try: () => result,
|
|
3658
|
-
catch: identity
|
|
3659
|
-
});
|
|
3660
|
-
} else {
|
|
3661
|
-
return succeed(result);
|
|
3662
|
-
}
|
|
3663
|
-
}),
|
|
3664
|
-
andThen(
|
|
3665
|
-
(doNext) => new BatchUpdateResult({
|
|
3666
|
-
hasErrors: !doNext,
|
|
3667
|
-
updates
|
|
3668
|
-
})
|
|
3669
|
-
),
|
|
3670
|
-
catchAll((error) => {
|
|
3671
|
-
console.warn("handle batch error", {
|
|
104
|
+
return handleEntireBatch(updates, behavior, log);
|
|
105
|
+
};
|
|
106
|
+
var handleEntireBatch = async (updates, handlers, log) => {
|
|
107
|
+
try {
|
|
108
|
+
const doNext = await handlers.on_batch(updates);
|
|
109
|
+
return { hasErrors: !doNext, updates };
|
|
110
|
+
} catch (error) {
|
|
111
|
+
log.warn("handle batch error", {
|
|
3672
112
|
errorMessage: error instanceof Error ? error.message : void 0,
|
|
3673
113
|
updates: updates.map((_) => Object.keys(_).at(1)),
|
|
3674
114
|
error
|
|
3675
115
|
});
|
|
3676
|
-
return
|
|
3677
|
-
new BatchUpdateResult({
|
|
3678
|
-
hasErrors: true,
|
|
3679
|
-
updates
|
|
3680
|
-
})
|
|
3681
|
-
);
|
|
3682
|
-
})
|
|
3683
|
-
);
|
|
3684
|
-
var HandleUpdateError = class extends TaggedError("HandleUpdateError") {
|
|
3685
|
-
logInfo() {
|
|
3686
|
-
return {
|
|
3687
|
-
updateId: this.update.update_id,
|
|
3688
|
-
updateKey: Object.keys(this.update).at(1),
|
|
3689
|
-
name: this._tag,
|
|
3690
|
-
...this.cause instanceof Error && { error: this.cause.message }
|
|
3691
|
-
};
|
|
116
|
+
return { hasErrors: true, updates };
|
|
3692
117
|
}
|
|
3693
118
|
};
|
|
3694
|
-
var handleOneByOne = (updates, handlers,
|
|
3695
|
-
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
return succeed(error);
|
|
3704
|
-
})
|
|
3705
|
-
),
|
|
3706
|
-
{
|
|
3707
|
-
concurrency: 10
|
|
119
|
+
var handleOneByOne = async (updates, handlers, client, settings, log, onHandleResult) => {
|
|
120
|
+
const results = await Promise.allSettled(
|
|
121
|
+
updates.map((update) => handleOneUpdate(update, handlers, client, settings, log, onHandleResult))
|
|
122
|
+
);
|
|
123
|
+
const hasErrors = results.some(
|
|
124
|
+
(r) => r.status === "rejected" || r.status === "fulfilled" && r.value !== void 0
|
|
125
|
+
);
|
|
126
|
+
if (settings.log_level === "debug") {
|
|
127
|
+
log.debug("handle batch result", results);
|
|
3708
128
|
}
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
console.debug("handle batch result", batchResult);
|
|
3713
|
-
}
|
|
3714
|
-
return new BatchUpdateResult({
|
|
3715
|
-
hasErrors: !batchResult.every((error) => error == null),
|
|
3716
|
-
updates
|
|
3717
|
-
});
|
|
3718
|
-
})
|
|
3719
|
-
);
|
|
3720
|
-
var handleOneUpdate = (updateObject, handlers) => gen(function* () {
|
|
129
|
+
return { hasErrors, updates };
|
|
130
|
+
};
|
|
131
|
+
var handleOneUpdate = async (updateObject, handlers, client, settings, log, onHandleResult) => {
|
|
3721
132
|
const update = extractUpdate(updateObject);
|
|
3722
133
|
if (!update) {
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
|
|
3728
|
-
);
|
|
134
|
+
log.warn("update handle error", {
|
|
135
|
+
updateId: updateObject.update_id,
|
|
136
|
+
name: "UnknownUpdate"
|
|
137
|
+
});
|
|
138
|
+
return "UnknownUpdate";
|
|
3729
139
|
}
|
|
3730
140
|
const handler = handlers[`on_${update.type}`];
|
|
3731
141
|
if (!handler) {
|
|
3732
|
-
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
);
|
|
3738
|
-
}
|
|
3739
|
-
if (update.type == "message" && "text" in update) {
|
|
3740
|
-
console.info("Got a new text message", {
|
|
3741
|
-
chatId: update.chat.id,
|
|
3742
|
-
chatType: update.chat.type,
|
|
3743
|
-
message: `${update.text.slice(0, 5)}...`
|
|
142
|
+
onHandleResult?.({
|
|
143
|
+
update: updateObject,
|
|
144
|
+
updateType: update.type,
|
|
145
|
+
status: "no_handler",
|
|
146
|
+
duration: 0
|
|
3744
147
|
});
|
|
148
|
+
return "HandlerNotDefined";
|
|
3745
149
|
}
|
|
3746
150
|
const ctx = createBotContext(update);
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
151
|
+
const startTime = performance.now();
|
|
152
|
+
let handleResult;
|
|
153
|
+
let hasError = false;
|
|
154
|
+
let errorMessage;
|
|
155
|
+
try {
|
|
156
|
+
handleResult = await executeHandler(handler, update, ctx);
|
|
157
|
+
} catch (error) {
|
|
158
|
+
hasError = true;
|
|
159
|
+
errorMessage = error instanceof Error ? error.message : String(error);
|
|
160
|
+
const errorInfo = {
|
|
161
|
+
updateId: updateObject.update_id,
|
|
162
|
+
updateKey: Object.keys(updateObject).at(1),
|
|
3751
163
|
name: "BotHandlerError",
|
|
164
|
+
...error instanceof Error && { error: error.message }
|
|
165
|
+
};
|
|
166
|
+
log.warn("error", errorInfo);
|
|
167
|
+
handleResult = BotResponse.make({
|
|
168
|
+
type: "message",
|
|
169
|
+
text: `Some internal error has happened (BotHandlerError) while handling this message`,
|
|
170
|
+
message_effect_id: "\u{1F4A9}",
|
|
171
|
+
...updateObject.message?.message_id ? { reply_parameters: { message_id: updateObject.message.message_id } } : void 0
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
const duration = Math.round(performance.now() - startTime);
|
|
175
|
+
if (!handleResult) {
|
|
176
|
+
if (settings.log_level === "debug") {
|
|
177
|
+
log.debug(`Bot response is undefined for update #${updateObject.update_id}`);
|
|
178
|
+
}
|
|
179
|
+
onHandleResult?.({
|
|
3752
180
|
update: updateObject,
|
|
3753
|
-
|
|
3754
|
-
|
|
3755
|
-
|
|
3756
|
-
|
|
3757
|
-
|
|
3758
|
-
return tryPromise({
|
|
3759
|
-
try: () => handleResult2,
|
|
3760
|
-
catch: (error) => new HandleUpdateError({
|
|
3761
|
-
name: "BotHandlerError",
|
|
3762
|
-
update: updateObject,
|
|
3763
|
-
cause: error
|
|
3764
|
-
})
|
|
3765
|
-
});
|
|
3766
|
-
}
|
|
3767
|
-
return succeed(handleResult2);
|
|
3768
|
-
}),
|
|
3769
|
-
catchAll((error) => {
|
|
3770
|
-
handleUpdateError = error;
|
|
3771
|
-
console.warn("error", error.logInfo());
|
|
3772
|
-
return succeed(
|
|
3773
|
-
BotResponse.make({
|
|
3774
|
-
type: "message",
|
|
3775
|
-
text: `Some internal error has happend(${error.name}) while handling this message`,
|
|
3776
|
-
message_effect_id: import_tg_bot_client.MESSAGE_EFFECTS["\u{1F4A9}"],
|
|
3777
|
-
...updateObject.message?.message_id ? {
|
|
3778
|
-
reply_parameters: {
|
|
3779
|
-
message_id: updateObject.message?.message_id
|
|
3780
|
-
}
|
|
3781
|
-
} : void 0
|
|
3782
|
-
})
|
|
3783
|
-
);
|
|
3784
|
-
})
|
|
3785
|
-
);
|
|
3786
|
-
const pollSettings = yield* service(BotPollSettingsTag);
|
|
3787
|
-
if (!handleResult && pollSettings.log_level == "debug") {
|
|
3788
|
-
console.log(
|
|
3789
|
-
`Bot response is undefined for update with ID #${updateObject.update_id}.`
|
|
3790
|
-
);
|
|
3791
|
-
return;
|
|
181
|
+
updateType: update.type,
|
|
182
|
+
status: "ignored",
|
|
183
|
+
duration
|
|
184
|
+
});
|
|
185
|
+
return void 0;
|
|
3792
186
|
}
|
|
3793
187
|
if ("chat" in update && handleResult.response) {
|
|
3794
|
-
const client = yield* service(BotTgClientTag);
|
|
3795
188
|
const responsePayload = handleResult.response;
|
|
3796
|
-
const
|
|
3797
|
-
|
|
3798
|
-
|
|
3799
|
-
chat_id: update.chat.id
|
|
3800
|
-
}),
|
|
3801
|
-
catch: (error) => error
|
|
189
|
+
const result = await client.execute(`send_${responsePayload.type}`, {
|
|
190
|
+
...responsePayload,
|
|
191
|
+
chat_id: update.chat.id
|
|
3802
192
|
});
|
|
3803
|
-
if (
|
|
3804
|
-
|
|
3805
|
-
}
|
|
3806
|
-
|
|
3807
|
-
|
|
3808
|
-
}
|
|
3809
|
-
|
|
3810
|
-
|
|
3811
|
-
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
|
|
3818
|
-
};
|
|
3819
|
-
const fetchUpdates = _fetchUpdates(state).pipe(
|
|
3820
|
-
tap((updates) => {
|
|
3821
|
-
const id = updates.map((_) => _.update_id).sort().at(-1);
|
|
3822
|
-
console.log("updating last update id", id);
|
|
3823
|
-
state.lastUpdateId = id ? id + 1 : void 0;
|
|
3824
|
-
console.log(state);
|
|
3825
|
-
})
|
|
3826
|
-
);
|
|
3827
|
-
const commit = _commitLastBatch(state);
|
|
3828
|
-
return {
|
|
3829
|
-
state,
|
|
3830
|
-
fetchUpdates,
|
|
3831
|
-
commit
|
|
3832
|
-
};
|
|
3833
|
-
}
|
|
3834
|
-
}
|
|
3835
|
-
) {
|
|
3836
|
-
};
|
|
3837
|
-
var FetchUpdatesError = class extends TaggedError("FetchUpdatesError") {
|
|
193
|
+
if (!result.ok) {
|
|
194
|
+
log.warn("failed to send response", result.error);
|
|
195
|
+
} else if (settings.log_level === "debug") {
|
|
196
|
+
log.debug("bot response", result.data);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
onHandleResult?.({
|
|
200
|
+
update: updateObject,
|
|
201
|
+
updateType: update.type,
|
|
202
|
+
status: hasError ? "error" : handleResult.response ? "handled" : "ignored",
|
|
203
|
+
...handleResult.response ? { responseType: handleResult.response.type } : {},
|
|
204
|
+
...errorMessage ? { error: errorMessage } : {},
|
|
205
|
+
duration
|
|
206
|
+
});
|
|
207
|
+
return void 0;
|
|
3838
208
|
};
|
|
3839
|
-
|
|
3840
|
-
|
|
3841
|
-
|
|
3842
|
-
|
|
3843
|
-
|
|
3844
|
-
|
|
3845
|
-
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
}
|
|
3858
|
-
if (
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
return updates;
|
|
3862
|
-
} else {
|
|
3863
|
-
pollState.emptyResponses += 1;
|
|
3864
|
-
return [];
|
|
3865
|
-
}
|
|
3866
|
-
});
|
|
3867
|
-
var _commitLastBatch = (pollState) => gen(function* () {
|
|
3868
|
-
console.log("commit", { pollState });
|
|
3869
|
-
if (pollState.lastUpdateId) {
|
|
3870
|
-
const client = yield* service(BotTgClientTag);
|
|
3871
|
-
const offset = pollState.lastUpdateId;
|
|
3872
|
-
return yield* tryPromise({
|
|
3873
|
-
try: () => client.execute("get_updates", {
|
|
3874
|
-
offset,
|
|
3875
|
-
limit: 0
|
|
3876
|
-
}),
|
|
3877
|
-
catch: (error) => error
|
|
3878
|
-
}).pipe(
|
|
3879
|
-
andThen(
|
|
3880
|
-
andThen(service(BotPollSettingsTag), (pollSettings) => {
|
|
3881
|
-
if (pollSettings.log_level == "debug") {
|
|
3882
|
-
console.debug("committed offset", pollState);
|
|
3883
|
-
}
|
|
3884
|
-
})
|
|
3885
|
-
)
|
|
3886
|
-
);
|
|
3887
|
-
} else {
|
|
3888
|
-
return yield* fail3(
|
|
3889
|
-
new FetchUpdatesError({
|
|
3890
|
-
name: "NoUpdatesToCommit"
|
|
3891
|
-
})
|
|
209
|
+
|
|
210
|
+
// src/run.ts
|
|
211
|
+
var import_tg_bot_client = require("@effect-ak/tg-bot-client");
|
|
212
|
+
|
|
213
|
+
// src/polling.ts
|
|
214
|
+
function makePollSettings(input, log) {
|
|
215
|
+
let batch_size = input.batch_size ?? 10;
|
|
216
|
+
let poll_timeout = input.poll_timeout ?? 10;
|
|
217
|
+
let max_empty_responses = input.max_empty_responses;
|
|
218
|
+
let log_level = input.log_level ?? "info";
|
|
219
|
+
let on_error = input.on_error ?? "stop";
|
|
220
|
+
if (batch_size < 10 || batch_size > 100) {
|
|
221
|
+
log.warn("Wrong batch_size, must be in [10..100], using 10 instead");
|
|
222
|
+
batch_size = 10;
|
|
223
|
+
}
|
|
224
|
+
if (poll_timeout < 2 || poll_timeout > 120) {
|
|
225
|
+
log.warn("Wrong poll_timeout, must be in [2..120], using 20 instead");
|
|
226
|
+
poll_timeout = 20;
|
|
227
|
+
}
|
|
228
|
+
if (max_empty_responses && max_empty_responses < 2) {
|
|
229
|
+
log.warn(
|
|
230
|
+
"Wrong max_empty_responses, must be in [2..infinity], using infinity"
|
|
3892
231
|
);
|
|
232
|
+
max_empty_responses = void 0;
|
|
233
|
+
}
|
|
234
|
+
const settings = {
|
|
235
|
+
batch_size,
|
|
236
|
+
poll_timeout,
|
|
237
|
+
max_empty_responses,
|
|
238
|
+
log_level,
|
|
239
|
+
on_error
|
|
240
|
+
};
|
|
241
|
+
log.debug("bot poll settings", settings);
|
|
242
|
+
return settings;
|
|
243
|
+
}
|
|
244
|
+
var UpdateFetcher = class {
|
|
245
|
+
constructor(client, settings) {
|
|
246
|
+
this.client = client;
|
|
247
|
+
this.settings = settings;
|
|
248
|
+
}
|
|
249
|
+
lastUpdateId;
|
|
250
|
+
emptyResponses = 0;
|
|
251
|
+
async fetchUpdates() {
|
|
252
|
+
if (this.settings.max_empty_responses && this.emptyResponses >= this.settings.max_empty_responses) {
|
|
253
|
+
throw new Error("TooManyEmptyResponses");
|
|
254
|
+
}
|
|
255
|
+
if (this.settings.log_level === "debug") {
|
|
256
|
+
console.debug("getting updates", {
|
|
257
|
+
lastUpdateId: this.lastUpdateId,
|
|
258
|
+
emptyResponses: this.emptyResponses
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
const result = await this.client.execute("get_updates", {
|
|
262
|
+
timeout: this.settings.poll_timeout,
|
|
263
|
+
...this.lastUpdateId ? { offset: this.lastUpdateId } : void 0
|
|
264
|
+
});
|
|
265
|
+
if (!result.ok) {
|
|
266
|
+
throw new Error(`Failed to fetch updates: ${result.error._tag}`);
|
|
267
|
+
}
|
|
268
|
+
const sorted = result.data.sort((a, b) => a.update_id - b.update_id);
|
|
269
|
+
if (sorted.length > 0) {
|
|
270
|
+
const lastId = sorted[sorted.length - 1].update_id;
|
|
271
|
+
if (this.settings.log_level === "debug") {
|
|
272
|
+
console.debug("updating last update id", lastId);
|
|
273
|
+
}
|
|
274
|
+
this.lastUpdateId = lastId + 1;
|
|
275
|
+
this.emptyResponses = 0;
|
|
276
|
+
} else {
|
|
277
|
+
this.emptyResponses += 1;
|
|
278
|
+
}
|
|
279
|
+
return sorted;
|
|
3893
280
|
}
|
|
3894
|
-
|
|
3895
|
-
|
|
3896
|
-
|
|
3897
|
-
|
|
3898
|
-
|
|
3899
|
-
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
|
|
3903
|
-
|
|
3904
|
-
};
|
|
3905
|
-
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
-
runBotInBackground,
|
|
3909
|
-
getFiber
|
|
3910
|
-
};
|
|
281
|
+
async commit() {
|
|
282
|
+
if (!this.lastUpdateId) return;
|
|
283
|
+
if (this.settings.log_level === "debug") {
|
|
284
|
+
console.debug("committing offset", this.lastUpdateId);
|
|
285
|
+
}
|
|
286
|
+
const result = await this.client.execute("get_updates", {
|
|
287
|
+
offset: this.lastUpdateId,
|
|
288
|
+
limit: 0
|
|
289
|
+
});
|
|
290
|
+
if (!result.ok) {
|
|
291
|
+
throw new Error(`Failed to commit offset: ${result.error._tag}`);
|
|
292
|
+
}
|
|
293
|
+
if (this.settings.log_level === "debug") {
|
|
294
|
+
console.debug("committed offset", this.lastUpdateId);
|
|
3911
295
|
}
|
|
3912
296
|
}
|
|
3913
|
-
) {
|
|
3914
297
|
};
|
|
3915
|
-
var _runBotDaemon = (state) => gen(function* () {
|
|
3916
|
-
console.log("running telegram chat bot");
|
|
3917
|
-
const fetchService = yield* service(BotFetchUpdatesService);
|
|
3918
|
-
const settings = yield* service(BotPollSettingsTag);
|
|
3919
|
-
const continueOnError = (hasError) => {
|
|
3920
|
-
if (settings.on_error == "continue") return true;
|
|
3921
|
-
return !hasError;
|
|
3922
|
-
};
|
|
3923
|
-
const startFiber = delay(1e3)(
|
|
3924
|
-
fetchService.fetchUpdates.pipe(
|
|
3925
|
-
andThen(handleUpdates),
|
|
3926
|
-
tap((result) => {
|
|
3927
|
-
const hasUpdates = result.updates.length > 0;
|
|
3928
|
-
return hasUpdates && continueOnError(result.hasErrors) ? fetchService.commit : void_;
|
|
3929
|
-
})
|
|
3930
|
-
)
|
|
3931
|
-
).pipe(
|
|
3932
|
-
repeat({
|
|
3933
|
-
while: (_) => continueOnError(_.hasErrors)
|
|
3934
|
-
}),
|
|
3935
|
-
forkDaemon,
|
|
3936
|
-
tap(
|
|
3937
|
-
(fiber) => fiber.addObserver((exit2) => {
|
|
3938
|
-
console.log("bot's fiber has been closed", exit2);
|
|
3939
|
-
})
|
|
3940
|
-
)
|
|
3941
|
-
);
|
|
3942
|
-
if (state.fiber) {
|
|
3943
|
-
console.log("killing previous bot's fiber");
|
|
3944
|
-
yield* fiberInterrupt(state.fiber);
|
|
3945
|
-
}
|
|
3946
|
-
state.fiber = yield* startFiber;
|
|
3947
|
-
console.log("Fetching bot updates via long polling...");
|
|
3948
|
-
});
|
|
3949
298
|
|
|
3950
|
-
// src/
|
|
3951
|
-
var
|
|
3952
|
-
|
|
299
|
+
// src/run.ts
|
|
300
|
+
var consoleLogger = {
|
|
301
|
+
debug: (msg, data) => console.debug(msg, ...data !== void 0 ? [data] : []),
|
|
302
|
+
info: (msg, data) => console.log(msg, ...data !== void 0 ? [data] : []),
|
|
303
|
+
warn: (msg, data) => console.warn(msg, ...data !== void 0 ? [data] : []),
|
|
304
|
+
error: (msg, data) => console.error(msg, ...data !== void 0 ? [data] : [])
|
|
305
|
+
};
|
|
306
|
+
var delay = (ms) => new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
307
|
+
var extractBehavior = (input) => {
|
|
3953
308
|
if (input.mode === "batch") {
|
|
3954
309
|
return { type: "batch", on_batch: input.on_batch };
|
|
3955
310
|
}
|
|
3956
|
-
const { bot_token, mode, poll, ...handlers } = input;
|
|
311
|
+
const { bot_token, mode, poll, onUpdate: _, onHandleResult: __, logger: ___, ...handlers } = input;
|
|
3957
312
|
return { type: "single", ...handlers };
|
|
3958
313
|
};
|
|
3959
|
-
var
|
|
3960
|
-
const
|
|
3961
|
-
const
|
|
3962
|
-
const
|
|
3963
|
-
const
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
|
|
3976
|
-
|
|
314
|
+
var runBot = async (input) => {
|
|
315
|
+
const log = input.logger ?? consoleLogger;
|
|
316
|
+
const settings = makePollSettings(input.poll ?? {}, log);
|
|
317
|
+
const client = (0, import_tg_bot_client.makeTgBotClient)({ bot_token: input.bot_token });
|
|
318
|
+
const fetcher = new UpdateFetcher(client, settings);
|
|
319
|
+
let behavior = extractBehavior(input);
|
|
320
|
+
const abortController = new AbortController();
|
|
321
|
+
const poll = async () => {
|
|
322
|
+
if (settings.log_level === "debug") {
|
|
323
|
+
log.debug("running telegram chat bot");
|
|
324
|
+
log.debug("Fetching bot updates via long polling...");
|
|
325
|
+
}
|
|
326
|
+
while (!abortController.signal.aborted) {
|
|
327
|
+
try {
|
|
328
|
+
const updates = await fetcher.fetchUpdates();
|
|
329
|
+
if (input.onUpdate) {
|
|
330
|
+
for (const u of updates) input.onUpdate(u);
|
|
331
|
+
}
|
|
332
|
+
const result = await handleUpdates(updates, behavior, client, settings, log, input.onHandleResult);
|
|
333
|
+
if (updates.length > 0 && !result.hasErrors) {
|
|
334
|
+
await fetcher.commit();
|
|
335
|
+
}
|
|
336
|
+
if (result.hasErrors && settings.on_error === "stop") {
|
|
337
|
+
log.warn("stopping bot due to error (on_error=stop)");
|
|
338
|
+
break;
|
|
339
|
+
}
|
|
340
|
+
} catch (error) {
|
|
341
|
+
log.error("polling error", error instanceof Error ? error.message : error);
|
|
342
|
+
if (settings.on_error === "stop") break;
|
|
343
|
+
}
|
|
344
|
+
await delay(1e3);
|
|
345
|
+
}
|
|
346
|
+
if (settings.log_level === "debug") {
|
|
347
|
+
log.debug("bot polling stopped");
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
poll();
|
|
3977
351
|
return {
|
|
3978
|
-
|
|
3979
|
-
|
|
352
|
+
stop: () => abortController.abort(),
|
|
353
|
+
reload: (newBehavior) => {
|
|
354
|
+
behavior = newBehavior;
|
|
355
|
+
}
|
|
3980
356
|
};
|
|
3981
|
-
}
|
|
3982
|
-
|
|
3983
|
-
// src/run.ts
|
|
3984
|
-
var runTgChatBot = (input) => launchBot(input).pipe(runPromise);
|
|
357
|
+
};
|
|
3985
358
|
var defineBot = (input) => {
|
|
3986
|
-
if (Object.keys(input).length
|
|
359
|
+
if (Object.keys(input).length === 0)
|
|
3987
360
|
console.warn("No handlers are defined for bot");
|
|
3988
361
|
return input;
|
|
3989
362
|
};
|
|
3990
|
-
|
|
3991
|
-
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
const input = { update, ctx };
|
|
3996
|
-
if (guard.match) {
|
|
3997
|
-
const matched = await guard.match(input);
|
|
3998
|
-
if (!matched) return null;
|
|
3999
|
-
}
|
|
4000
|
-
return await guard.handle(input);
|
|
4001
|
-
};
|
|
4002
|
-
var executeGuards2 = async (guards, update, ctx) => {
|
|
4003
|
-
for (const guard of guards) {
|
|
4004
|
-
const result = await executeSingleGuard2(guard, update, ctx);
|
|
4005
|
-
if (result !== null) return result;
|
|
4006
|
-
}
|
|
4007
|
-
return BotResponse.ignore;
|
|
4008
|
-
};
|
|
4009
|
-
var executeHandler2 = async (handler, update, ctx) => {
|
|
4010
|
-
if (typeof handler === "function") {
|
|
4011
|
-
return await handler(update);
|
|
4012
|
-
}
|
|
4013
|
-
if (Array.isArray(handler)) {
|
|
4014
|
-
return await executeGuards2(handler, update, ctx);
|
|
4015
|
-
}
|
|
4016
|
-
if (isGuardedHandler2(handler)) {
|
|
4017
|
-
const result = await executeSingleGuard2(handler, update, ctx);
|
|
4018
|
-
return result ?? BotResponse.ignore;
|
|
4019
|
-
}
|
|
4020
|
-
return BotResponse.ignore;
|
|
4021
|
-
};
|
|
4022
|
-
var extractUpdate2 = (input) => {
|
|
4023
|
-
for (const [field, value] of Object.entries(input)) {
|
|
4024
|
-
if (field === "update_id") continue;
|
|
4025
|
-
return { type: field, ...value };
|
|
4026
|
-
}
|
|
4027
|
-
return void 0;
|
|
4028
|
-
};
|
|
4029
|
-
var processUpdate = async (updateObject, handlers, client) => {
|
|
4030
|
-
const update = extractUpdate2(updateObject);
|
|
4031
|
-
if (!update) {
|
|
4032
|
-
console.warn("Unknown update format", updateObject);
|
|
4033
|
-
return;
|
|
4034
|
-
}
|
|
4035
|
-
const handlerKey = `on_${update.type}`;
|
|
4036
|
-
const handler = handlers[handlerKey];
|
|
4037
|
-
if (!handler) {
|
|
4038
|
-
return;
|
|
4039
|
-
}
|
|
4040
|
-
const ctx = createBotContext(update);
|
|
4041
|
-
try {
|
|
4042
|
-
const result = await executeHandler2(handler, update, ctx);
|
|
4043
|
-
if (result.response && "chat" in update) {
|
|
4044
|
-
const responsePayload = result.response;
|
|
4045
|
-
await client.execute(`send_${responsePayload.type}`, {
|
|
4046
|
-
...responsePayload,
|
|
4047
|
-
chat_id: update.chat.id
|
|
4048
|
-
});
|
|
4049
|
-
}
|
|
4050
|
-
} catch (error) {
|
|
4051
|
-
console.error("Error handling update", {
|
|
4052
|
-
updateId: updateObject.update_id,
|
|
4053
|
-
error: error instanceof Error ? error.message : error
|
|
4054
|
-
});
|
|
4055
|
-
}
|
|
4056
|
-
};
|
|
4057
|
-
var createWebhookHandler = (config) => {
|
|
4058
|
-
const client = (0, import_tg_bot_client3.makeTgBotClient)({ bot_token: config.bot_token });
|
|
363
|
+
var createWebhook = (config) => {
|
|
364
|
+
const { bot_token, onHandleResult, logger, ...handlers } = config;
|
|
365
|
+
const log = logger ?? consoleLogger;
|
|
366
|
+
const client = (0, import_tg_bot_client.makeTgBotClient)({ bot_token });
|
|
367
|
+
const settings = makePollSettings({}, log);
|
|
4059
368
|
const handleUpdate = async (update) => {
|
|
4060
|
-
await
|
|
369
|
+
await handleUpdates([update], { type: "single", ...handlers }, client, settings, log, onHandleResult);
|
|
4061
370
|
};
|
|
4062
371
|
const handler = async (request) => {
|
|
4063
372
|
try {
|
|
@@ -4065,31 +374,147 @@ var createWebhookHandler = (config) => {
|
|
|
4065
374
|
await handleUpdate(update);
|
|
4066
375
|
return new Response("ok", { status: 200 });
|
|
4067
376
|
} catch (error) {
|
|
4068
|
-
|
|
377
|
+
log.error("Webhook error", error);
|
|
4069
378
|
return new Response("error", { status: 500 });
|
|
4070
379
|
}
|
|
4071
380
|
};
|
|
4072
381
|
handler.handleUpdate = handleUpdate;
|
|
4073
382
|
return handler;
|
|
4074
383
|
};
|
|
384
|
+
|
|
385
|
+
// src/bot-builder.ts
|
|
386
|
+
function makeMessageHelpers() {
|
|
387
|
+
return {
|
|
388
|
+
command: (cmd, handler) => ({
|
|
389
|
+
match: ({ ctx }) => ctx.command === cmd,
|
|
390
|
+
handle: handler
|
|
391
|
+
}),
|
|
392
|
+
text: (handler) => ({
|
|
393
|
+
match: ({ update }) => !!update.text,
|
|
394
|
+
handle: handler
|
|
395
|
+
}),
|
|
396
|
+
photo: (handler) => ({
|
|
397
|
+
match: ({ update }) => !!update.photo,
|
|
398
|
+
handle: handler
|
|
399
|
+
}),
|
|
400
|
+
document: (handler) => ({
|
|
401
|
+
match: ({ update }) => !!update.document,
|
|
402
|
+
handle: handler
|
|
403
|
+
}),
|
|
404
|
+
sticker: (handler) => ({
|
|
405
|
+
match: ({ update }) => !!update.sticker,
|
|
406
|
+
handle: handler
|
|
407
|
+
}),
|
|
408
|
+
fallback: (handler) => ({ handle: handler })
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
function makeCallbackQueryHelpers() {
|
|
412
|
+
return {
|
|
413
|
+
data: (pattern, handler) => ({
|
|
414
|
+
match: ({ update }) => typeof pattern === "string" ? update.data === pattern : pattern.test(update.data ?? ""),
|
|
415
|
+
handle: handler
|
|
416
|
+
}),
|
|
417
|
+
fallback: (handler) => ({ handle: handler })
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
function makeInlineQueryHelpers() {
|
|
421
|
+
return {
|
|
422
|
+
query: (pattern, handler) => ({
|
|
423
|
+
match: ({ update }) => typeof pattern === "string" ? update.query === pattern : pattern.test(update.query),
|
|
424
|
+
handle: handler
|
|
425
|
+
}),
|
|
426
|
+
fallback: (handler) => ({ handle: handler })
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
function makeGenericHelpers() {
|
|
430
|
+
return {
|
|
431
|
+
fallback: (handler) => ({ handle: handler })
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
function resolve(makeHelpers, input) {
|
|
435
|
+
if (typeof input === "function") {
|
|
436
|
+
return input(makeHelpers());
|
|
437
|
+
}
|
|
438
|
+
return input;
|
|
439
|
+
}
|
|
440
|
+
function createBot() {
|
|
441
|
+
const handlers = /* @__PURE__ */ new Map();
|
|
442
|
+
function register(type, guards) {
|
|
443
|
+
const existing = handlers.get(type) ?? [];
|
|
444
|
+
handlers.set(type, [...existing, ...guards]);
|
|
445
|
+
}
|
|
446
|
+
function collectHandlers() {
|
|
447
|
+
const result = {};
|
|
448
|
+
for (const [type, guards] of handlers) {
|
|
449
|
+
result[`on_${type}`] = guards;
|
|
450
|
+
}
|
|
451
|
+
return result;
|
|
452
|
+
}
|
|
453
|
+
const bot = {
|
|
454
|
+
onMessage(input) {
|
|
455
|
+
register("message", resolve(makeMessageHelpers, input));
|
|
456
|
+
return bot;
|
|
457
|
+
},
|
|
458
|
+
onEditedMessage(input) {
|
|
459
|
+
register("edited_message", resolve(makeGenericHelpers, input));
|
|
460
|
+
return bot;
|
|
461
|
+
},
|
|
462
|
+
onChannelPost(input) {
|
|
463
|
+
register("channel_post", resolve(makeGenericHelpers, input));
|
|
464
|
+
return bot;
|
|
465
|
+
},
|
|
466
|
+
onEditedChannelPost(input) {
|
|
467
|
+
register("edited_channel_post", resolve(makeGenericHelpers, input));
|
|
468
|
+
return bot;
|
|
469
|
+
},
|
|
470
|
+
onBusinessMessage(input) {
|
|
471
|
+
register("business_message", resolve(makeGenericHelpers, input));
|
|
472
|
+
return bot;
|
|
473
|
+
},
|
|
474
|
+
onEditedBusinessMessage(input) {
|
|
475
|
+
register("edited_business_message", resolve(makeGenericHelpers, input));
|
|
476
|
+
return bot;
|
|
477
|
+
},
|
|
478
|
+
onCallbackQuery(input) {
|
|
479
|
+
register("callback_query", resolve(makeCallbackQueryHelpers, input));
|
|
480
|
+
return bot;
|
|
481
|
+
},
|
|
482
|
+
onInlineQuery(input) {
|
|
483
|
+
register("inline_query", resolve(makeInlineQueryHelpers, input));
|
|
484
|
+
return bot;
|
|
485
|
+
},
|
|
486
|
+
on(type, input) {
|
|
487
|
+
register(type, resolve(makeGenericHelpers, input));
|
|
488
|
+
return bot;
|
|
489
|
+
},
|
|
490
|
+
async run(config) {
|
|
491
|
+
const collected = collectHandlers();
|
|
492
|
+
if (handlers.size === 0) {
|
|
493
|
+
console.warn("No handlers are defined for bot");
|
|
494
|
+
}
|
|
495
|
+
return runBot({
|
|
496
|
+
...config,
|
|
497
|
+
mode: "single",
|
|
498
|
+
...collected
|
|
499
|
+
});
|
|
500
|
+
},
|
|
501
|
+
webhook(config) {
|
|
502
|
+
const collected = collectHandlers();
|
|
503
|
+
return createWebhook({
|
|
504
|
+
...config,
|
|
505
|
+
...collected
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
return bot;
|
|
510
|
+
}
|
|
4075
511
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4076
512
|
0 && (module.exports = {
|
|
4077
|
-
BatchUpdateResult,
|
|
4078
|
-
BotPollSettings,
|
|
4079
|
-
BotPollSettingsTag,
|
|
4080
513
|
BotResponse,
|
|
4081
|
-
|
|
4082
|
-
BotTgClientTag,
|
|
4083
|
-
BotUpdateHandlersTag,
|
|
4084
|
-
HandleUpdateError,
|
|
514
|
+
createBot,
|
|
4085
515
|
createBotContext,
|
|
4086
|
-
|
|
516
|
+
createWebhook,
|
|
4087
517
|
defineBot,
|
|
4088
518
|
extractUpdate,
|
|
4089
|
-
|
|
4090
|
-
handleOneByOne,
|
|
4091
|
-
handleOneUpdate,
|
|
4092
|
-
handleUpdates,
|
|
4093
|
-
launchBot,
|
|
4094
|
-
runTgChatBot
|
|
519
|
+
runBot
|
|
4095
520
|
});
|