pullfrog 0.1.29 → 0.1.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/dist/agents/claudePretoolGate.d.ts +5 -1
  2. package/dist/agents/opencodePlugin.d.ts +2 -2
  3. package/dist/agents/postRun.d.ts +8 -31
  4. package/dist/agents/shared.d.ts +6 -0
  5. package/dist/agents/subagentToolGates.d.ts +22 -40
  6. package/dist/cli.mjs +63989 -59666
  7. package/dist/external.d.ts +45 -2
  8. package/dist/index.js +62509 -58186
  9. package/dist/internal/index.d.ts +2 -2
  10. package/dist/internal.js +99 -33
  11. package/dist/mcp/checkSuite.d.ts +3 -1
  12. package/dist/mcp/checkout.d.ts +4 -2
  13. package/dist/mcp/comment.d.ts +12 -4
  14. package/dist/mcp/commitInfo.d.ts +3 -1
  15. package/dist/mcp/dependencies.d.ts +6 -2
  16. package/dist/mcp/git.d.ts +32 -6
  17. package/dist/mcp/issue.d.ts +26 -1
  18. package/dist/mcp/issueComments.d.ts +3 -1
  19. package/dist/mcp/issueEvents.d.ts +3 -1
  20. package/dist/mcp/issueInfo.d.ts +3 -1
  21. package/dist/mcp/labels.d.ts +16 -1
  22. package/dist/mcp/output.d.ts +6 -2
  23. package/dist/mcp/pr.d.ts +19 -2
  24. package/dist/mcp/prInfo.d.ts +3 -1
  25. package/dist/mcp/resolveRepoCtx.d.ts +34 -0
  26. package/dist/mcp/review.d.ts +9 -3
  27. package/dist/mcp/reviewComments.d.ts +9 -3
  28. package/dist/mcp/selectMode.d.ts +3 -1
  29. package/dist/mcp/server.d.ts +7 -1
  30. package/dist/mcp/shared.d.ts +18 -1
  31. package/dist/mcp/shell.d.ts +6 -2
  32. package/dist/mcp/upload.d.ts +3 -1
  33. package/dist/mcp/xrepo.d.ts +15 -0
  34. package/dist/models.d.ts +58 -5
  35. package/dist/modes.d.ts +1 -1
  36. package/dist/toolState.d.ts +66 -16
  37. package/dist/utils/apiCommit.d.ts +40 -0
  38. package/dist/utils/apiKeys.d.ts +19 -0
  39. package/dist/utils/buildPullfrogFooter.d.ts +27 -0
  40. package/dist/utils/claudeSubscription.d.ts +30 -0
  41. package/dist/utils/errorReport.d.ts +2 -2
  42. package/dist/utils/github.d.ts +28 -2
  43. package/dist/utils/instructions.d.ts +11 -0
  44. package/dist/utils/isTransientNetworkError.d.ts +10 -0
  45. package/dist/utils/learnings.d.ts +14 -0
  46. package/dist/utils/modelAccess.d.ts +64 -0
  47. package/dist/utils/openCodeModels.d.ts +2 -2
  48. package/dist/utils/payload.d.ts +16 -0
  49. package/dist/utils/proxy.d.ts +3 -5
  50. package/dist/utils/runContext.d.ts +4 -0
  51. package/dist/utils/runContextData.d.ts +10 -0
  52. package/dist/utils/runErrorRenderer.d.ts +2 -2
  53. package/dist/utils/setup.d.ts +18 -3
  54. package/dist/utils/token.d.ts +22 -3
  55. package/dist/yes/index.d.ts +32 -0
  56. package/dist/yes/standard-schema.d.ts +117 -0
  57. package/dist/yes.js +1244 -0
  58. package/package.json +19 -10
  59. package/dist/utils/byokFallback.d.ts +0 -44
  60. package/dist/utils/retry.d.ts +0 -13
package/dist/yes.js ADDED
@@ -0,0 +1,1244 @@
1
+ import { createRequire as __createRequire } from 'module'; import { fileURLToPath as __fileURLToPath } from 'url'; import { dirname as __dirnameFn } from 'path'; const require = __createRequire(import.meta.url); const __filename = __fileURLToPath(import.meta.url); const __dirname = __dirnameFn(__filename);
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
9
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
10
+ }) : x)(function(x) {
11
+ if (typeof require !== "undefined") return require.apply(this, arguments);
12
+ throw Error('Dynamic require of "' + x + '" is not supported');
13
+ });
14
+ var __commonJS = (cb, mod) => function __require2() {
15
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
16
+ };
17
+ var __copyProps = (to, from, except, desc) => {
18
+ if (from && typeof from === "object" || typeof from === "function") {
19
+ for (let key of __getOwnPropNames(from))
20
+ if (!__hasOwnProp.call(to, key) && key !== except)
21
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
22
+ }
23
+ return to;
24
+ };
25
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
26
+ // If the importer is in node compatibility mode or this is not an ESM
27
+ // file that has been converted to a CommonJS file using a Babel-
28
+ // compatible transform (i.e. "__esModule" has not been set), then set
29
+ // "default" to the CommonJS "module.exports" for node compatibility.
30
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
31
+ mod
32
+ ));
33
+
34
+ // node_modules/.pnpm/object-hash@3.0.0/node_modules/object-hash/index.js
35
+ var require_object_hash = __commonJS({
36
+ "node_modules/.pnpm/object-hash@3.0.0/node_modules/object-hash/index.js"(exports, module) {
37
+ "use strict";
38
+ var crypto = __require("crypto");
39
+ exports = module.exports = objectHash;
40
+ function objectHash(object, options) {
41
+ options = applyDefaults(object, options);
42
+ return hash2(object, options);
43
+ }
44
+ exports.sha1 = function(object) {
45
+ return objectHash(object);
46
+ };
47
+ exports.keys = function(object) {
48
+ return objectHash(object, { excludeValues: true, algorithm: "sha1", encoding: "hex" });
49
+ };
50
+ exports.MD5 = function(object) {
51
+ return objectHash(object, { algorithm: "md5", encoding: "hex" });
52
+ };
53
+ exports.keysMD5 = function(object) {
54
+ return objectHash(object, { algorithm: "md5", encoding: "hex", excludeValues: true });
55
+ };
56
+ var hashes = crypto.getHashes ? crypto.getHashes().slice() : ["sha1", "md5"];
57
+ hashes.push("passthrough");
58
+ var encodings = ["buffer", "hex", "binary", "base64"];
59
+ function applyDefaults(object, sourceOptions) {
60
+ sourceOptions = sourceOptions || {};
61
+ var options = {};
62
+ options.algorithm = sourceOptions.algorithm || "sha1";
63
+ options.encoding = sourceOptions.encoding || "hex";
64
+ options.excludeValues = sourceOptions.excludeValues ? true : false;
65
+ options.algorithm = options.algorithm.toLowerCase();
66
+ options.encoding = options.encoding.toLowerCase();
67
+ options.ignoreUnknown = sourceOptions.ignoreUnknown !== true ? false : true;
68
+ options.respectType = sourceOptions.respectType === false ? false : true;
69
+ options.respectFunctionNames = sourceOptions.respectFunctionNames === false ? false : true;
70
+ options.respectFunctionProperties = sourceOptions.respectFunctionProperties === false ? false : true;
71
+ options.unorderedArrays = sourceOptions.unorderedArrays !== true ? false : true;
72
+ options.unorderedSets = sourceOptions.unorderedSets === false ? false : true;
73
+ options.unorderedObjects = sourceOptions.unorderedObjects === false ? false : true;
74
+ options.replacer = sourceOptions.replacer || void 0;
75
+ options.excludeKeys = sourceOptions.excludeKeys || void 0;
76
+ if (typeof object === "undefined") {
77
+ throw new Error("Object argument required.");
78
+ }
79
+ for (var i = 0; i < hashes.length; ++i) {
80
+ if (hashes[i].toLowerCase() === options.algorithm.toLowerCase()) {
81
+ options.algorithm = hashes[i];
82
+ }
83
+ }
84
+ if (hashes.indexOf(options.algorithm) === -1) {
85
+ throw new Error('Algorithm "' + options.algorithm + '" not supported. supported values: ' + hashes.join(", "));
86
+ }
87
+ if (encodings.indexOf(options.encoding) === -1 && options.algorithm !== "passthrough") {
88
+ throw new Error('Encoding "' + options.encoding + '" not supported. supported values: ' + encodings.join(", "));
89
+ }
90
+ return options;
91
+ }
92
+ function isNativeFunction(f) {
93
+ if (typeof f !== "function") {
94
+ return false;
95
+ }
96
+ var exp = /^function\s+\w*\s*\(\s*\)\s*{\s+\[native code\]\s+}$/i;
97
+ return exp.exec(Function.prototype.toString.call(f)) != null;
98
+ }
99
+ function hash2(object, options) {
100
+ var hashingStream;
101
+ if (options.algorithm !== "passthrough") {
102
+ hashingStream = crypto.createHash(options.algorithm);
103
+ } else {
104
+ hashingStream = new PassThrough();
105
+ }
106
+ if (typeof hashingStream.write === "undefined") {
107
+ hashingStream.write = hashingStream.update;
108
+ hashingStream.end = hashingStream.update;
109
+ }
110
+ var hasher = typeHasher(options, hashingStream);
111
+ hasher.dispatch(object);
112
+ if (!hashingStream.update) {
113
+ hashingStream.end("");
114
+ }
115
+ if (hashingStream.digest) {
116
+ return hashingStream.digest(options.encoding === "buffer" ? void 0 : options.encoding);
117
+ }
118
+ var buf = hashingStream.read();
119
+ if (options.encoding === "buffer") {
120
+ return buf;
121
+ }
122
+ return buf.toString(options.encoding);
123
+ }
124
+ exports.writeToStream = function(object, options, stream) {
125
+ if (typeof stream === "undefined") {
126
+ stream = options;
127
+ options = {};
128
+ }
129
+ options = applyDefaults(object, options);
130
+ return typeHasher(options, stream).dispatch(object);
131
+ };
132
+ function typeHasher(options, writeTo, context) {
133
+ context = context || [];
134
+ var write = function(str) {
135
+ if (writeTo.update) {
136
+ return writeTo.update(str, "utf8");
137
+ } else {
138
+ return writeTo.write(str, "utf8");
139
+ }
140
+ };
141
+ return {
142
+ dispatch: function(value) {
143
+ if (options.replacer) {
144
+ value = options.replacer(value);
145
+ }
146
+ var type = typeof value;
147
+ if (value === null) {
148
+ type = "null";
149
+ }
150
+ return this["_" + type](value);
151
+ },
152
+ _object: function(object) {
153
+ var pattern = /\[object (.*)\]/i;
154
+ var objString = Object.prototype.toString.call(object);
155
+ var objType = pattern.exec(objString);
156
+ if (!objType) {
157
+ objType = "unknown:[" + objString + "]";
158
+ } else {
159
+ objType = objType[1];
160
+ }
161
+ objType = objType.toLowerCase();
162
+ var objectNumber = null;
163
+ if ((objectNumber = context.indexOf(object)) >= 0) {
164
+ return this.dispatch("[CIRCULAR:" + objectNumber + "]");
165
+ } else {
166
+ context.push(object);
167
+ }
168
+ if (typeof Buffer !== "undefined" && Buffer.isBuffer && Buffer.isBuffer(object)) {
169
+ write("buffer:");
170
+ return write(object);
171
+ }
172
+ if (objType !== "object" && objType !== "function" && objType !== "asyncfunction") {
173
+ if (this["_" + objType]) {
174
+ this["_" + objType](object);
175
+ } else if (options.ignoreUnknown) {
176
+ return write("[" + objType + "]");
177
+ } else {
178
+ throw new Error('Unknown object type "' + objType + '"');
179
+ }
180
+ } else {
181
+ var keys = Object.keys(object);
182
+ if (options.unorderedObjects) {
183
+ keys = keys.sort();
184
+ }
185
+ if (options.respectType !== false && !isNativeFunction(object)) {
186
+ keys.splice(0, 0, "prototype", "__proto__", "constructor");
187
+ }
188
+ if (options.excludeKeys) {
189
+ keys = keys.filter(function(key) {
190
+ return !options.excludeKeys(key);
191
+ });
192
+ }
193
+ write("object:" + keys.length + ":");
194
+ var self = this;
195
+ return keys.forEach(function(key) {
196
+ self.dispatch(key);
197
+ write(":");
198
+ if (!options.excludeValues) {
199
+ self.dispatch(object[key]);
200
+ }
201
+ write(",");
202
+ });
203
+ }
204
+ },
205
+ _array: function(arr, unordered) {
206
+ unordered = typeof unordered !== "undefined" ? unordered : options.unorderedArrays !== false;
207
+ var self = this;
208
+ write("array:" + arr.length + ":");
209
+ if (!unordered || arr.length <= 1) {
210
+ return arr.forEach(function(entry) {
211
+ return self.dispatch(entry);
212
+ });
213
+ }
214
+ var contextAdditions = [];
215
+ var entries = arr.map(function(entry) {
216
+ var strm = new PassThrough();
217
+ var localContext = context.slice();
218
+ var hasher = typeHasher(options, strm, localContext);
219
+ hasher.dispatch(entry);
220
+ contextAdditions = contextAdditions.concat(localContext.slice(context.length));
221
+ return strm.read().toString();
222
+ });
223
+ context = context.concat(contextAdditions);
224
+ entries.sort();
225
+ return this._array(entries, false);
226
+ },
227
+ _date: function(date) {
228
+ return write("date:" + date.toJSON());
229
+ },
230
+ _symbol: function(sym) {
231
+ return write("symbol:" + sym.toString());
232
+ },
233
+ _error: function(err) {
234
+ return write("error:" + err.toString());
235
+ },
236
+ _boolean: function(bool) {
237
+ return write("bool:" + bool.toString());
238
+ },
239
+ _string: function(string) {
240
+ write("string:" + string.length + ":");
241
+ write(string.toString());
242
+ },
243
+ _function: function(fn) {
244
+ write("fn:");
245
+ if (isNativeFunction(fn)) {
246
+ this.dispatch("[native]");
247
+ } else {
248
+ this.dispatch(fn.toString());
249
+ }
250
+ if (options.respectFunctionNames !== false) {
251
+ this.dispatch("function-name:" + String(fn.name));
252
+ }
253
+ if (options.respectFunctionProperties) {
254
+ this._object(fn);
255
+ }
256
+ },
257
+ _number: function(number) {
258
+ return write("number:" + number.toString());
259
+ },
260
+ _xml: function(xml) {
261
+ return write("xml:" + xml.toString());
262
+ },
263
+ _null: function() {
264
+ return write("Null");
265
+ },
266
+ _undefined: function() {
267
+ return write("Undefined");
268
+ },
269
+ _regexp: function(regex) {
270
+ return write("regex:" + regex.toString());
271
+ },
272
+ _uint8array: function(arr) {
273
+ write("uint8array:");
274
+ return this.dispatch(Array.prototype.slice.call(arr));
275
+ },
276
+ _uint8clampedarray: function(arr) {
277
+ write("uint8clampedarray:");
278
+ return this.dispatch(Array.prototype.slice.call(arr));
279
+ },
280
+ _int8array: function(arr) {
281
+ write("int8array:");
282
+ return this.dispatch(Array.prototype.slice.call(arr));
283
+ },
284
+ _uint16array: function(arr) {
285
+ write("uint16array:");
286
+ return this.dispatch(Array.prototype.slice.call(arr));
287
+ },
288
+ _int16array: function(arr) {
289
+ write("int16array:");
290
+ return this.dispatch(Array.prototype.slice.call(arr));
291
+ },
292
+ _uint32array: function(arr) {
293
+ write("uint32array:");
294
+ return this.dispatch(Array.prototype.slice.call(arr));
295
+ },
296
+ _int32array: function(arr) {
297
+ write("int32array:");
298
+ return this.dispatch(Array.prototype.slice.call(arr));
299
+ },
300
+ _float32array: function(arr) {
301
+ write("float32array:");
302
+ return this.dispatch(Array.prototype.slice.call(arr));
303
+ },
304
+ _float64array: function(arr) {
305
+ write("float64array:");
306
+ return this.dispatch(Array.prototype.slice.call(arr));
307
+ },
308
+ _arraybuffer: function(arr) {
309
+ write("arraybuffer:");
310
+ return this.dispatch(new Uint8Array(arr));
311
+ },
312
+ _url: function(url) {
313
+ return write("url:" + url.toString(), "utf8");
314
+ },
315
+ _map: function(map) {
316
+ write("map:");
317
+ var arr = Array.from(map);
318
+ return this._array(arr, options.unorderedSets !== false);
319
+ },
320
+ _set: function(set) {
321
+ write("set:");
322
+ var arr = Array.from(set);
323
+ return this._array(arr, options.unorderedSets !== false);
324
+ },
325
+ _file: function(file) {
326
+ write("file:");
327
+ return this.dispatch([file.name, file.size, file.type, file.lastModfied]);
328
+ },
329
+ _blob: function() {
330
+ if (options.ignoreUnknown) {
331
+ return write("[blob]");
332
+ }
333
+ throw Error('Hashing Blob objects is currently not supported\n(see https://github.com/puleos/object-hash/issues/26)\nUse "options.replacer" or "options.ignoreUnknown"\n');
334
+ },
335
+ _domwindow: function() {
336
+ return write("domwindow");
337
+ },
338
+ _bigint: function(number) {
339
+ return write("bigint:" + number.toString());
340
+ },
341
+ /* Node.js standard native objects */
342
+ _process: function() {
343
+ return write("process");
344
+ },
345
+ _timer: function() {
346
+ return write("timer");
347
+ },
348
+ _pipe: function() {
349
+ return write("pipe");
350
+ },
351
+ _tcp: function() {
352
+ return write("tcp");
353
+ },
354
+ _udp: function() {
355
+ return write("udp");
356
+ },
357
+ _tty: function() {
358
+ return write("tty");
359
+ },
360
+ _statwatcher: function() {
361
+ return write("statwatcher");
362
+ },
363
+ _securecontext: function() {
364
+ return write("securecontext");
365
+ },
366
+ _connection: function() {
367
+ return write("connection");
368
+ },
369
+ _zlib: function() {
370
+ return write("zlib");
371
+ },
372
+ _context: function() {
373
+ return write("context");
374
+ },
375
+ _nodescript: function() {
376
+ return write("nodescript");
377
+ },
378
+ _httpparser: function() {
379
+ return write("httpparser");
380
+ },
381
+ _dataview: function() {
382
+ return write("dataview");
383
+ },
384
+ _signal: function() {
385
+ return write("signal");
386
+ },
387
+ _fsevent: function() {
388
+ return write("fsevent");
389
+ },
390
+ _tlswrap: function() {
391
+ return write("tlswrap");
392
+ }
393
+ };
394
+ }
395
+ function PassThrough() {
396
+ return {
397
+ buf: "",
398
+ write: function(b) {
399
+ this.buf += b;
400
+ },
401
+ end: function(b) {
402
+ this.buf += b;
403
+ },
404
+ read: function() {
405
+ return this.buf;
406
+ }
407
+ };
408
+ }
409
+ }
410
+ });
411
+
412
+ // yes/index.ts
413
+ import { performance as performance2 } from "node:perf_hooks";
414
+ import { setTimeout as sleep } from "node:timers/promises";
415
+
416
+ // node_modules/.pnpm/lru-cache@11.3.6/node_modules/lru-cache/dist/esm/node/index.min.js
417
+ import { tracingChannel as I, channel as G } from "node:diagnostics_channel";
418
+ var S = G("lru-cache:metrics");
419
+ var W = I("lru-cache");
420
+ var C = typeof performance == "object" && performance && typeof performance.now == "function" ? performance : Date;
421
+ var D = () => S.hasSubscribers || W.hasSubscribers;
422
+ var U = /* @__PURE__ */ new Set();
423
+ var L = typeof process == "object" && process ? process : {};
424
+ var P = (u3, e, t, i) => {
425
+ typeof L.emitWarning == "function" ? L.emitWarning(u3, e, t, i) : console.error(`[${t}] ${e}: ${u3}`);
426
+ };
427
+ var H = (u3) => !U.has(u3);
428
+ var X = Symbol("type");
429
+ var F = (u3) => !!u3 && u3 === Math.floor(u3) && u3 > 0 && isFinite(u3);
430
+ var j = (u3) => F(u3) ? u3 <= Math.pow(2, 8) ? Uint8Array : u3 <= Math.pow(2, 16) ? Uint16Array : u3 <= Math.pow(2, 32) ? Uint32Array : u3 <= Number.MAX_SAFE_INTEGER ? O : null : null;
431
+ var O = class extends Array {
432
+ constructor(e) {
433
+ super(e), this.fill(0);
434
+ }
435
+ };
436
+ var R = class u {
437
+ heap;
438
+ length;
439
+ static #o = false;
440
+ static create(e) {
441
+ let t = j(e);
442
+ if (!t) return [];
443
+ u.#o = true;
444
+ let i = new u(e, t);
445
+ return u.#o = false, i;
446
+ }
447
+ constructor(e, t) {
448
+ if (!u.#o) throw new TypeError("instantiate Stack using Stack.create(n)");
449
+ this.heap = new t(e), this.length = 0;
450
+ }
451
+ push(e) {
452
+ this.heap[this.length++] = e;
453
+ }
454
+ pop() {
455
+ return this.heap[--this.length];
456
+ }
457
+ };
458
+ var M = class u2 {
459
+ #o;
460
+ #u;
461
+ #w;
462
+ #x;
463
+ #S;
464
+ #M;
465
+ #U;
466
+ #m;
467
+ get perf() {
468
+ return this.#m;
469
+ }
470
+ ttl;
471
+ ttlResolution;
472
+ ttlAutopurge;
473
+ updateAgeOnGet;
474
+ updateAgeOnHas;
475
+ allowStale;
476
+ noDisposeOnSet;
477
+ noUpdateTTL;
478
+ maxEntrySize;
479
+ sizeCalculation;
480
+ noDeleteOnFetchRejection;
481
+ noDeleteOnStaleGet;
482
+ allowStaleOnFetchAbort;
483
+ allowStaleOnFetchRejection;
484
+ ignoreFetchAbort;
485
+ #n;
486
+ #b;
487
+ #s;
488
+ #i;
489
+ #t;
490
+ #a;
491
+ #c;
492
+ #l;
493
+ #h;
494
+ #y;
495
+ #r;
496
+ #_;
497
+ #F;
498
+ #d;
499
+ #g;
500
+ #T;
501
+ #W;
502
+ #f;
503
+ #j;
504
+ static unsafeExposeInternals(e) {
505
+ return { starts: e.#F, ttls: e.#d, autopurgeTimers: e.#g, sizes: e.#_, keyMap: e.#s, keyList: e.#i, valList: e.#t, next: e.#a, prev: e.#c, get head() {
506
+ return e.#l;
507
+ }, get tail() {
508
+ return e.#h;
509
+ }, free: e.#y, isBackgroundFetch: (t) => e.#e(t), backgroundFetch: (t, i, s, n) => e.#P(t, i, s, n), moveToTail: (t) => e.#L(t), indexes: (t) => e.#A(t), rindexes: (t) => e.#z(t), isStale: (t) => e.#p(t) };
510
+ }
511
+ get max() {
512
+ return this.#o;
513
+ }
514
+ get maxSize() {
515
+ return this.#u;
516
+ }
517
+ get calculatedSize() {
518
+ return this.#b;
519
+ }
520
+ get size() {
521
+ return this.#n;
522
+ }
523
+ get fetchMethod() {
524
+ return this.#M;
525
+ }
526
+ get memoMethod() {
527
+ return this.#U;
528
+ }
529
+ get dispose() {
530
+ return this.#w;
531
+ }
532
+ get onInsert() {
533
+ return this.#x;
534
+ }
535
+ get disposeAfter() {
536
+ return this.#S;
537
+ }
538
+ constructor(e) {
539
+ let { max: t = 0, ttl: i, ttlResolution: s = 1, ttlAutopurge: n, updateAgeOnGet: o, updateAgeOnHas: r, allowStale: h, dispose: l, onInsert: c, disposeAfter: f, noDisposeOnSet: g, noUpdateTTL: p, maxSize: T = 0, maxEntrySize: w = 0, sizeCalculation: y, fetchMethod: a, memoMethod: m, noDeleteOnFetchRejection: _, noDeleteOnStaleGet: b, allowStaleOnFetchRejection: d, allowStaleOnFetchAbort: A, ignoreFetchAbort: z, perf: x } = e;
540
+ if (x !== void 0 && typeof x?.now != "function") throw new TypeError("perf option must have a now() method if specified");
541
+ if (this.#m = x ?? C, t !== 0 && !F(t)) throw new TypeError("max option must be a nonnegative integer");
542
+ let v = t ? j(t) : Array;
543
+ if (!v) throw new Error("invalid max value: " + t);
544
+ if (this.#o = t, this.#u = T, this.maxEntrySize = w || this.#u, this.sizeCalculation = y, this.sizeCalculation) {
545
+ if (!this.#u && !this.maxEntrySize) throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");
546
+ if (typeof this.sizeCalculation != "function") throw new TypeError("sizeCalculation set to non-function");
547
+ }
548
+ if (m !== void 0 && typeof m != "function") throw new TypeError("memoMethod must be a function if defined");
549
+ if (this.#U = m, a !== void 0 && typeof a != "function") throw new TypeError("fetchMethod must be a function if specified");
550
+ if (this.#M = a, this.#W = !!a, this.#s = /* @__PURE__ */ new Map(), this.#i = Array.from({ length: t }).fill(void 0), this.#t = Array.from({ length: t }).fill(void 0), this.#a = new v(t), this.#c = new v(t), this.#l = 0, this.#h = 0, this.#y = R.create(t), this.#n = 0, this.#b = 0, typeof l == "function" && (this.#w = l), typeof c == "function" && (this.#x = c), typeof f == "function" ? (this.#S = f, this.#r = []) : (this.#S = void 0, this.#r = void 0), this.#T = !!this.#w, this.#j = !!this.#x, this.#f = !!this.#S, this.noDisposeOnSet = !!g, this.noUpdateTTL = !!p, this.noDeleteOnFetchRejection = !!_, this.allowStaleOnFetchRejection = !!d, this.allowStaleOnFetchAbort = !!A, this.ignoreFetchAbort = !!z, this.maxEntrySize !== 0) {
551
+ if (this.#u !== 0 && !F(this.#u)) throw new TypeError("maxSize must be a positive integer if specified");
552
+ if (!F(this.maxEntrySize)) throw new TypeError("maxEntrySize must be a positive integer if specified");
553
+ this.#X();
554
+ }
555
+ if (this.allowStale = !!h, this.noDeleteOnStaleGet = !!b, this.updateAgeOnGet = !!o, this.updateAgeOnHas = !!r, this.ttlResolution = F(s) || s === 0 ? s : 1, this.ttlAutopurge = !!n, this.ttl = i || 0, this.ttl) {
556
+ if (!F(this.ttl)) throw new TypeError("ttl must be a positive integer if specified");
557
+ this.#H();
558
+ }
559
+ if (this.#o === 0 && this.ttl === 0 && this.#u === 0) throw new TypeError("At least one of max, maxSize, or ttl is required");
560
+ if (!this.ttlAutopurge && !this.#o && !this.#u) {
561
+ let E = "LRU_CACHE_UNBOUNDED";
562
+ H(E) && (U.add(E), P("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.", "UnboundedCacheWarning", E, u2));
563
+ }
564
+ }
565
+ getRemainingTTL(e) {
566
+ return this.#s.has(e) ? 1 / 0 : 0;
567
+ }
568
+ #H() {
569
+ let e = new O(this.#o), t = new O(this.#o);
570
+ this.#d = e, this.#F = t;
571
+ let i = this.ttlAutopurge ? Array.from({ length: this.#o }) : void 0;
572
+ this.#g = i, this.#N = (r, h, l = this.#m.now()) => {
573
+ t[r] = h !== 0 ? l : 0, e[r] = h, s(r, h);
574
+ }, this.#D = (r) => {
575
+ t[r] = e[r] !== 0 ? this.#m.now() : 0, s(r, e[r]);
576
+ };
577
+ let s = this.ttlAutopurge ? (r, h) => {
578
+ if (i?.[r] && (clearTimeout(i[r]), i[r] = void 0), h && h !== 0 && i) {
579
+ let l = setTimeout(() => {
580
+ this.#p(r) && this.#v(this.#i[r], "expire");
581
+ }, h + 1);
582
+ l.unref && l.unref(), i[r] = l;
583
+ }
584
+ } : () => {
585
+ };
586
+ this.#E = (r, h) => {
587
+ if (e[h]) {
588
+ let l = e[h], c = t[h];
589
+ if (!l || !c) return;
590
+ r.ttl = l, r.start = c, r.now = n || o();
591
+ let f = r.now - c;
592
+ r.remainingTTL = l - f;
593
+ }
594
+ };
595
+ let n = 0, o = () => {
596
+ let r = this.#m.now();
597
+ if (this.ttlResolution > 0) {
598
+ n = r;
599
+ let h = setTimeout(() => n = 0, this.ttlResolution);
600
+ h.unref && h.unref();
601
+ }
602
+ return r;
603
+ };
604
+ this.getRemainingTTL = (r) => {
605
+ let h = this.#s.get(r);
606
+ if (h === void 0) return 0;
607
+ let l = e[h], c = t[h];
608
+ if (!l || !c) return 1 / 0;
609
+ let f = (n || o()) - c;
610
+ return l - f;
611
+ }, this.#p = (r) => {
612
+ let h = t[r], l = e[r];
613
+ return !!l && !!h && (n || o()) - h > l;
614
+ };
615
+ }
616
+ #D = () => {
617
+ };
618
+ #E = () => {
619
+ };
620
+ #N = () => {
621
+ };
622
+ #p = () => false;
623
+ #X() {
624
+ let e = new O(this.#o);
625
+ this.#b = 0, this.#_ = e, this.#R = (t) => {
626
+ this.#b -= e[t], e[t] = 0;
627
+ }, this.#k = (t, i, s, n) => {
628
+ if (this.#e(i)) return 0;
629
+ if (!F(s)) if (n) {
630
+ if (typeof n != "function") throw new TypeError("sizeCalculation must be a function");
631
+ if (s = n(i, t), !F(s)) throw new TypeError("sizeCalculation return invalid (expect positive integer)");
632
+ } else throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");
633
+ return s;
634
+ }, this.#I = (t, i, s) => {
635
+ if (e[t] = i, this.#u) {
636
+ let n = this.#u - e[t];
637
+ for (; this.#b > n; ) this.#G(true);
638
+ }
639
+ this.#b += e[t], s && (s.entrySize = i, s.totalCalculatedSize = this.#b);
640
+ };
641
+ }
642
+ #R = (e) => {
643
+ };
644
+ #I = (e, t, i) => {
645
+ };
646
+ #k = (e, t, i, s) => {
647
+ if (i || s) throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");
648
+ return 0;
649
+ };
650
+ *#A({ allowStale: e = this.allowStale } = {}) {
651
+ if (this.#n) for (let t = this.#h; this.#V(t) && ((e || !this.#p(t)) && (yield t), t !== this.#l); ) t = this.#c[t];
652
+ }
653
+ *#z({ allowStale: e = this.allowStale } = {}) {
654
+ if (this.#n) for (let t = this.#l; this.#V(t) && ((e || !this.#p(t)) && (yield t), t !== this.#h); ) t = this.#a[t];
655
+ }
656
+ #V(e) {
657
+ return e !== void 0 && this.#s.get(this.#i[e]) === e;
658
+ }
659
+ *entries() {
660
+ for (let e of this.#A()) this.#t[e] !== void 0 && this.#i[e] !== void 0 && !this.#e(this.#t[e]) && (yield [this.#i[e], this.#t[e]]);
661
+ }
662
+ *rentries() {
663
+ for (let e of this.#z()) this.#t[e] !== void 0 && this.#i[e] !== void 0 && !this.#e(this.#t[e]) && (yield [this.#i[e], this.#t[e]]);
664
+ }
665
+ *keys() {
666
+ for (let e of this.#A()) {
667
+ let t = this.#i[e];
668
+ t !== void 0 && !this.#e(this.#t[e]) && (yield t);
669
+ }
670
+ }
671
+ *rkeys() {
672
+ for (let e of this.#z()) {
673
+ let t = this.#i[e];
674
+ t !== void 0 && !this.#e(this.#t[e]) && (yield t);
675
+ }
676
+ }
677
+ *values() {
678
+ for (let e of this.#A()) this.#t[e] !== void 0 && !this.#e(this.#t[e]) && (yield this.#t[e]);
679
+ }
680
+ *rvalues() {
681
+ for (let e of this.#z()) this.#t[e] !== void 0 && !this.#e(this.#t[e]) && (yield this.#t[e]);
682
+ }
683
+ [Symbol.iterator]() {
684
+ return this.entries();
685
+ }
686
+ [Symbol.toStringTag] = "LRUCache";
687
+ find(e, t = {}) {
688
+ for (let i of this.#A()) {
689
+ let s = this.#t[i], n = this.#e(s) ? s.__staleWhileFetching : s;
690
+ if (n !== void 0 && e(n, this.#i[i], this)) return this.#C(this.#i[i], t);
691
+ }
692
+ }
693
+ forEach(e, t = this) {
694
+ for (let i of this.#A()) {
695
+ let s = this.#t[i], n = this.#e(s) ? s.__staleWhileFetching : s;
696
+ n !== void 0 && e.call(t, n, this.#i[i], this);
697
+ }
698
+ }
699
+ rforEach(e, t = this) {
700
+ for (let i of this.#z()) {
701
+ let s = this.#t[i], n = this.#e(s) ? s.__staleWhileFetching : s;
702
+ n !== void 0 && e.call(t, n, this.#i[i], this);
703
+ }
704
+ }
705
+ purgeStale() {
706
+ let e = false;
707
+ for (let t of this.#z({ allowStale: true })) this.#p(t) && (this.#v(this.#i[t], "expire"), e = true);
708
+ return e;
709
+ }
710
+ info(e) {
711
+ let t = this.#s.get(e);
712
+ if (t === void 0) return;
713
+ let i = this.#t[t], s = this.#e(i) ? i.__staleWhileFetching : i;
714
+ if (s === void 0) return;
715
+ let n = { value: s };
716
+ if (this.#d && this.#F) {
717
+ let o = this.#d[t], r = this.#F[t];
718
+ if (o && r) {
719
+ let h = o - (this.#m.now() - r);
720
+ n.ttl = h, n.start = Date.now();
721
+ }
722
+ }
723
+ return this.#_ && (n.size = this.#_[t]), n;
724
+ }
725
+ dump() {
726
+ let e = [];
727
+ for (let t of this.#A({ allowStale: true })) {
728
+ let i = this.#i[t], s = this.#t[t], n = this.#e(s) ? s.__staleWhileFetching : s;
729
+ if (n === void 0 || i === void 0) continue;
730
+ let o = { value: n };
731
+ if (this.#d && this.#F) {
732
+ o.ttl = this.#d[t];
733
+ let r = this.#m.now() - this.#F[t];
734
+ o.start = Math.floor(Date.now() - r);
735
+ }
736
+ this.#_ && (o.size = this.#_[t]), e.unshift([i, o]);
737
+ }
738
+ return e;
739
+ }
740
+ load(e) {
741
+ this.clear();
742
+ for (let [t, i] of e) {
743
+ if (i.start) {
744
+ let s = Date.now() - i.start;
745
+ i.start = this.#m.now() - s;
746
+ }
747
+ this.#O(t, i.value, i);
748
+ }
749
+ }
750
+ set(e, t, i = {}) {
751
+ let { status: s = S.hasSubscribers ? {} : void 0 } = i;
752
+ i.status = s, s && (s.op = "set", s.key = e, t !== void 0 && (s.value = t));
753
+ let n = this.#O(e, t, i);
754
+ return s && S.hasSubscribers && S.publish(s), n;
755
+ }
756
+ #O(e, t, i = {}) {
757
+ let { ttl: s = this.ttl, start: n, noDisposeOnSet: o = this.noDisposeOnSet, sizeCalculation: r = this.sizeCalculation, status: h } = i;
758
+ if (t === void 0) return h && (h.set = "deleted"), this.delete(e), this;
759
+ let { noUpdateTTL: l = this.noUpdateTTL } = i;
760
+ h && !this.#e(t) && (h.value = t);
761
+ let c = this.#k(e, t, i.size || 0, r, h);
762
+ if (this.maxEntrySize && c > this.maxEntrySize) return this.#v(e, "set"), h && (h.set = "miss", h.maxEntrySizeExceeded = true), this;
763
+ let f = this.#n === 0 ? void 0 : this.#s.get(e);
764
+ if (f === void 0) f = this.#n === 0 ? this.#h : this.#y.length !== 0 ? this.#y.pop() : this.#n === this.#o ? this.#G(false) : this.#n, this.#i[f] = e, this.#t[f] = t, this.#s.set(e, f), this.#a[this.#h] = f, this.#c[f] = this.#h, this.#h = f, this.#n++, this.#I(f, c, h), h && (h.set = "add"), l = false, this.#j && this.#x?.(t, e, "add");
765
+ else {
766
+ this.#L(f);
767
+ let g = this.#t[f];
768
+ if (t !== g) {
769
+ if (this.#W && this.#e(g)) {
770
+ g.__abortController.abort(new Error("replaced"));
771
+ let { __staleWhileFetching: p } = g;
772
+ p !== void 0 && !o && (this.#T && this.#w?.(p, e, "set"), this.#f && this.#r?.push([p, e, "set"]));
773
+ } else o || (this.#T && this.#w?.(g, e, "set"), this.#f && this.#r?.push([g, e, "set"]));
774
+ if (this.#R(f), this.#I(f, c, h), this.#t[f] = t, h) {
775
+ h.set = "replace";
776
+ let p = g && this.#e(g) ? g.__staleWhileFetching : g;
777
+ p !== void 0 && (h.oldValue = p);
778
+ }
779
+ } else h && (h.set = "update");
780
+ this.#j && this.onInsert?.(t, e, t === g ? "update" : "replace");
781
+ }
782
+ if (s !== 0 && !this.#d && this.#H(), this.#d && (l || this.#N(f, s, n), h && this.#E(h, f)), !o && this.#f && this.#r) {
783
+ let g = this.#r, p;
784
+ for (; p = g?.shift(); ) this.#S?.(...p);
785
+ }
786
+ return this;
787
+ }
788
+ pop() {
789
+ try {
790
+ for (; this.#n; ) {
791
+ let e = this.#t[this.#l];
792
+ if (this.#G(true), this.#e(e)) {
793
+ if (e.__staleWhileFetching) return e.__staleWhileFetching;
794
+ } else if (e !== void 0) return e;
795
+ }
796
+ } finally {
797
+ if (this.#f && this.#r) {
798
+ let e = this.#r, t;
799
+ for (; t = e?.shift(); ) this.#S?.(...t);
800
+ }
801
+ }
802
+ }
803
+ #G(e) {
804
+ let t = this.#l, i = this.#i[t], s = this.#t[t];
805
+ return this.#W && this.#e(s) ? s.__abortController.abort(new Error("evicted")) : (this.#T || this.#f) && (this.#T && this.#w?.(s, i, "evict"), this.#f && this.#r?.push([s, i, "evict"])), this.#R(t), this.#g?.[t] && (clearTimeout(this.#g[t]), this.#g[t] = void 0), e && (this.#i[t] = void 0, this.#t[t] = void 0, this.#y.push(t)), this.#n === 1 ? (this.#l = this.#h = 0, this.#y.length = 0) : this.#l = this.#a[t], this.#s.delete(i), this.#n--, t;
806
+ }
807
+ has(e, t = {}) {
808
+ let { status: i = S.hasSubscribers ? {} : void 0 } = t;
809
+ t.status = i, i && (i.op = "has", i.key = e);
810
+ let s = this.#Y(e, t);
811
+ return S.hasSubscribers && S.publish(i), s;
812
+ }
813
+ #Y(e, t = {}) {
814
+ let { updateAgeOnHas: i = this.updateAgeOnHas, status: s } = t, n = this.#s.get(e);
815
+ if (n !== void 0) {
816
+ let o = this.#t[n];
817
+ if (this.#e(o) && o.__staleWhileFetching === void 0) return false;
818
+ if (this.#p(n)) s && (s.has = "stale", this.#E(s, n));
819
+ else return i && this.#D(n), s && (s.has = "hit", this.#E(s, n)), true;
820
+ } else s && (s.has = "miss");
821
+ return false;
822
+ }
823
+ peek(e, t = {}) {
824
+ let { status: i = D() ? {} : void 0 } = t;
825
+ i && (i.op = "peek", i.key = e), t.status = i;
826
+ let s = this.#J(e, t);
827
+ return S.hasSubscribers && S.publish(i), s;
828
+ }
829
+ #J(e, t) {
830
+ let { status: i, allowStale: s = this.allowStale } = t, n = this.#s.get(e);
831
+ if (n === void 0 || !s && this.#p(n)) {
832
+ i && (i.peek = n === void 0 ? "miss" : "stale");
833
+ return;
834
+ }
835
+ let o = this.#t[n], r = this.#e(o) ? o.__staleWhileFetching : o;
836
+ return i && (r !== void 0 ? (i.peek = "hit", i.value = r) : i.peek = "miss"), r;
837
+ }
838
+ #P(e, t, i, s) {
839
+ let n = t === void 0 ? void 0 : this.#t[t];
840
+ if (this.#e(n)) return n;
841
+ let o = new AbortController(), { signal: r } = i;
842
+ r?.addEventListener("abort", () => o.abort(r.reason), { signal: o.signal });
843
+ let h = { signal: o.signal, options: i, context: s }, l = (w, y = false) => {
844
+ let { aborted: a } = o.signal, m = i.ignoreFetchAbort && w !== void 0, _ = i.ignoreFetchAbort || !!(i.allowStaleOnFetchAbort && w !== void 0);
845
+ if (i.status && (a && !y ? (i.status.fetchAborted = true, i.status.fetchError = o.signal.reason, m && (i.status.fetchAbortIgnored = true)) : i.status.fetchResolved = true), a && !m && !y) return f(o.signal.reason, _);
846
+ let b = p, d = this.#t[t];
847
+ return (d === p || d === void 0 && m && y) && (w === void 0 ? b.__staleWhileFetching !== void 0 ? this.#t[t] = b.__staleWhileFetching : this.#v(e, "fetch") : (i.status && (i.status.fetchUpdated = true), this.#O(e, w, h.options))), w;
848
+ }, c = (w) => (i.status && (i.status.fetchRejected = true, i.status.fetchError = w), f(w, false)), f = (w, y) => {
849
+ let { aborted: a } = o.signal, m = a && i.allowStaleOnFetchAbort, _ = m || i.allowStaleOnFetchRejection, b = _ || i.noDeleteOnFetchRejection, d = p;
850
+ if (this.#t[t] === p && (!b || !y && d.__staleWhileFetching === void 0 ? this.#v(e, "fetch") : m || (this.#t[t] = d.__staleWhileFetching)), _) return i.status && d.__staleWhileFetching !== void 0 && (i.status.returnedStale = true), d.__staleWhileFetching;
851
+ if (d.__returned === d) throw w;
852
+ }, g = (w, y) => {
853
+ let a = this.#M?.(e, n, h);
854
+ a && a instanceof Promise && a.then((m) => w(m === void 0 ? void 0 : m), y), o.signal.addEventListener("abort", () => {
855
+ (!i.ignoreFetchAbort || i.allowStaleOnFetchAbort) && (w(void 0), i.allowStaleOnFetchAbort && (w = (m) => l(m, true)));
856
+ });
857
+ };
858
+ i.status && (i.status.fetchDispatched = true);
859
+ let p = new Promise(g).then(l, c), T = Object.assign(p, { __abortController: o, __staleWhileFetching: n, __returned: void 0 });
860
+ return t === void 0 ? (this.#O(e, T, { ...h.options, status: void 0 }), t = this.#s.get(e)) : this.#t[t] = T, T;
861
+ }
862
+ #e(e) {
863
+ if (!this.#W) return false;
864
+ let t = e;
865
+ return !!t && t instanceof Promise && t.hasOwnProperty("__staleWhileFetching") && t.__abortController instanceof AbortController;
866
+ }
867
+ fetch(e, t = {}) {
868
+ let i = W.hasSubscribers, { status: s = D() ? {} : void 0 } = t;
869
+ t.status = s, s && t.context && (s.context = t.context);
870
+ let n = this.#B(e, t);
871
+ return s && i && (s.trace = true, W.tracePromise(() => n, s).catch(() => {
872
+ })), n;
873
+ }
874
+ async #B(e, t = {}) {
875
+ let { allowStale: i = this.allowStale, updateAgeOnGet: s = this.updateAgeOnGet, noDeleteOnStaleGet: n = this.noDeleteOnStaleGet, ttl: o = this.ttl, noDisposeOnSet: r = this.noDisposeOnSet, size: h = 0, sizeCalculation: l = this.sizeCalculation, noUpdateTTL: c = this.noUpdateTTL, noDeleteOnFetchRejection: f = this.noDeleteOnFetchRejection, allowStaleOnFetchRejection: g = this.allowStaleOnFetchRejection, ignoreFetchAbort: p = this.ignoreFetchAbort, allowStaleOnFetchAbort: T = this.allowStaleOnFetchAbort, context: w, forceRefresh: y = false, status: a, signal: m } = t;
876
+ if (a && (a.op = "fetch", a.key = e, y && (a.forceRefresh = true)), !this.#W) return a && (a.fetch = "get"), this.#C(e, { allowStale: i, updateAgeOnGet: s, noDeleteOnStaleGet: n, status: a });
877
+ let _ = { allowStale: i, updateAgeOnGet: s, noDeleteOnStaleGet: n, ttl: o, noDisposeOnSet: r, size: h, sizeCalculation: l, noUpdateTTL: c, noDeleteOnFetchRejection: f, allowStaleOnFetchRejection: g, allowStaleOnFetchAbort: T, ignoreFetchAbort: p, status: a, signal: m }, b = this.#s.get(e);
878
+ if (b === void 0) {
879
+ a && (a.fetch = "miss");
880
+ let d = this.#P(e, b, _, w);
881
+ return d.__returned = d;
882
+ } else {
883
+ let d = this.#t[b];
884
+ if (this.#e(d)) {
885
+ let E = i && d.__staleWhileFetching !== void 0;
886
+ return a && (a.fetch = "inflight", E && (a.returnedStale = true)), E ? d.__staleWhileFetching : d.__returned = d;
887
+ }
888
+ let A = this.#p(b);
889
+ if (!y && !A) return a && (a.fetch = "hit"), this.#L(b), s && this.#D(b), a && this.#E(a, b), d;
890
+ let z = this.#P(e, b, _, w), v = z.__staleWhileFetching !== void 0 && i;
891
+ return a && (a.fetch = A ? "stale" : "refresh", v && A && (a.returnedStale = true)), v ? z.__staleWhileFetching : z.__returned = z;
892
+ }
893
+ }
894
+ forceFetch(e, t = {}) {
895
+ let i = W.hasSubscribers, { status: s = D() ? {} : void 0 } = t;
896
+ t.status = s, s && t.context && (s.context = t.context);
897
+ let n = this.#K(e, t);
898
+ return s && i && (s.trace = true, W.tracePromise(() => n, s).catch(() => {
899
+ })), n;
900
+ }
901
+ async #K(e, t = {}) {
902
+ let i = await this.#B(e, t);
903
+ if (i === void 0) throw new Error("fetch() returned undefined");
904
+ return i;
905
+ }
906
+ memo(e, t = {}) {
907
+ let { status: i = S.hasSubscribers ? {} : void 0 } = t;
908
+ t.status = i, i && (i.op = "memo", i.key = e, t.context && (i.context = t.context));
909
+ let s = this.#Q(e, t);
910
+ return i && (i.value = s), S.hasSubscribers && S.publish(i), s;
911
+ }
912
+ #Q(e, t = {}) {
913
+ let i = this.#U;
914
+ if (!i) throw new Error("no memoMethod provided to constructor");
915
+ let { context: s, status: n, forceRefresh: o, ...r } = t;
916
+ n && o && (n.forceRefresh = true);
917
+ let h = this.#C(e, r), l = o || h === void 0;
918
+ if (n && (n.memo = l ? "miss" : "hit", l || (n.value = h)), !l) return h;
919
+ let c = i(e, h, { options: r, context: s });
920
+ return n && (n.value = c), this.#O(e, c, r), c;
921
+ }
922
+ get(e, t = {}) {
923
+ let { status: i = S.hasSubscribers ? {} : void 0 } = t;
924
+ t.status = i, i && (i.op = "get", i.key = e);
925
+ let s = this.#C(e, t);
926
+ return i && (s !== void 0 && (i.value = s), S.hasSubscribers && S.publish(i)), s;
927
+ }
928
+ #C(e, t = {}) {
929
+ let { allowStale: i = this.allowStale, updateAgeOnGet: s = this.updateAgeOnGet, noDeleteOnStaleGet: n = this.noDeleteOnStaleGet, status: o } = t, r = this.#s.get(e);
930
+ if (r === void 0) {
931
+ o && (o.get = "miss");
932
+ return;
933
+ }
934
+ let h = this.#t[r], l = this.#e(h);
935
+ return o && this.#E(o, r), this.#p(r) ? l ? (o && (o.get = "stale-fetching"), i && h.__staleWhileFetching !== void 0 ? (o && (o.returnedStale = true), h.__staleWhileFetching) : void 0) : (n || this.#v(e, "expire"), o && (o.get = "stale"), i ? (o && (o.returnedStale = true), h) : void 0) : (o && (o.get = l ? "fetching" : "hit"), this.#L(r), s && this.#D(r), l ? h.__staleWhileFetching : h);
936
+ }
937
+ #$(e, t) {
938
+ this.#c[t] = e, this.#a[e] = t;
939
+ }
940
+ #L(e) {
941
+ e !== this.#h && (e === this.#l ? this.#l = this.#a[e] : this.#$(this.#c[e], this.#a[e]), this.#$(this.#h, e), this.#h = e);
942
+ }
943
+ delete(e) {
944
+ return this.#v(e, "delete");
945
+ }
946
+ #v(e, t) {
947
+ S.hasSubscribers && S.publish({ op: "delete", delete: t, key: e });
948
+ let i = false;
949
+ if (this.#n !== 0) {
950
+ let s = this.#s.get(e);
951
+ if (s !== void 0) if (this.#g?.[s] && (clearTimeout(this.#g?.[s]), this.#g[s] = void 0), i = true, this.#n === 1) this.#q(t);
952
+ else {
953
+ this.#R(s);
954
+ let n = this.#t[s];
955
+ if (this.#e(n) ? n.__abortController.abort(new Error("deleted")) : (this.#T || this.#f) && (this.#T && this.#w?.(n, e, t), this.#f && this.#r?.push([n, e, t])), this.#s.delete(e), this.#i[s] = void 0, this.#t[s] = void 0, s === this.#h) this.#h = this.#c[s];
956
+ else if (s === this.#l) this.#l = this.#a[s];
957
+ else {
958
+ let o = this.#c[s];
959
+ this.#a[o] = this.#a[s];
960
+ let r = this.#a[s];
961
+ this.#c[r] = this.#c[s];
962
+ }
963
+ this.#n--, this.#y.push(s);
964
+ }
965
+ }
966
+ if (this.#f && this.#r?.length) {
967
+ let s = this.#r, n;
968
+ for (; n = s?.shift(); ) this.#S?.(...n);
969
+ }
970
+ return i;
971
+ }
972
+ clear() {
973
+ return this.#q("delete");
974
+ }
975
+ #q(e) {
976
+ for (let t of this.#z({ allowStale: true })) {
977
+ let i = this.#t[t];
978
+ if (this.#e(i)) i.__abortController.abort(new Error("deleted"));
979
+ else {
980
+ let s = this.#i[t];
981
+ this.#T && this.#w?.(i, s, e), this.#f && this.#r?.push([i, s, e]);
982
+ }
983
+ }
984
+ if (this.#s.clear(), this.#t.fill(void 0), this.#i.fill(void 0), this.#d && this.#F) {
985
+ this.#d.fill(0), this.#F.fill(0);
986
+ for (let t of this.#g ?? []) t !== void 0 && clearTimeout(t);
987
+ this.#g?.fill(void 0);
988
+ }
989
+ if (this.#_ && this.#_.fill(0), this.#l = 0, this.#h = 0, this.#y.length = 0, this.#b = 0, this.#n = 0, this.#f && this.#r) {
990
+ let t = this.#r, i;
991
+ for (; i = t?.shift(); ) this.#S?.(...i);
992
+ }
993
+ }
994
+ };
995
+
996
+ // yes/index.ts
997
+ var import_object_hash = __toESM(require_object_hash(), 1);
998
+ var VOID_KEY = "~void";
999
+ function getCacheKeyString(value) {
1000
+ if (value === void 0) return VOID_KEY;
1001
+ if (value === null) {
1002
+ throw new Error("cache key cannot be null");
1003
+ }
1004
+ try {
1005
+ if (typeof value === "string") return value;
1006
+ return (0, import_object_hash.default)(value, { unorderedObjects: true, unorderedArrays: true });
1007
+ } catch (error) {
1008
+ throw new Error(
1009
+ `cache key cannot be hashed: ${error instanceof Error ? error.message : String(error)}`
1010
+ );
1011
+ }
1012
+ }
1013
+ function range(a, b) {
1014
+ if (b === void 0) {
1015
+ return Array.from({ length: a }, (_, i) => i);
1016
+ }
1017
+ if (typeof b === "function") {
1018
+ return Array.from({ length: a }, (_, i) => b(i));
1019
+ }
1020
+ return Array.from({ length: b - a + 1 }, (_, i) => a + i);
1021
+ }
1022
+ function schedule(fn, count) {
1023
+ return Array.from({ length: count }, (_, i) => fn(i));
1024
+ }
1025
+ function validateSchema(schema, value) {
1026
+ const result = schema["~standard"].validate(value);
1027
+ if (result instanceof Promise) {
1028
+ return result.then((res) => {
1029
+ if (res.issues) {
1030
+ const messages = res.issues.map((i) => i.message).join(", ");
1031
+ throw new Error(`validation failed: ${messages}`);
1032
+ }
1033
+ return res.value;
1034
+ });
1035
+ }
1036
+ if (result.issues) {
1037
+ const messages = result.issues.map((i) => i.message).join(", ");
1038
+ throw new Error(`validation failed: ${messages}`);
1039
+ }
1040
+ return result.value;
1041
+ }
1042
+ var log = {
1043
+ info: (...args) => console.log(...args),
1044
+ error: (...args) => console.error(...args),
1045
+ debug: (...args) => {
1046
+ if (process.env.LOG_LEVEL === "debug") console.log(...args);
1047
+ },
1048
+ prod: (...args) => {
1049
+ if (process.env.NODE_ENV === "production") console.log(...args);
1050
+ }
1051
+ };
1052
+ function op(fnOrOptions, options) {
1053
+ if (typeof fnOrOptions === "function") {
1054
+ return _op(fnOrOptions, options ?? {});
1055
+ }
1056
+ const { input: inputSchema, output: outputSchema, run, ...opOptions } = fnOrOptions;
1057
+ const wrappedFn = async (rawInput, ctx) => {
1058
+ let input = rawInput;
1059
+ if (inputSchema) {
1060
+ const validated = validateSchema(inputSchema, rawInput);
1061
+ input = validated instanceof Promise ? await validated : validated;
1062
+ }
1063
+ const result = await run(input, ctx);
1064
+ if (outputSchema) {
1065
+ const validated = validateSchema(outputSchema, result);
1066
+ return validated instanceof Promise ? await validated : validated;
1067
+ }
1068
+ return result;
1069
+ };
1070
+ return _op(wrappedFn, opOptions);
1071
+ }
1072
+ function _op(fn, options) {
1073
+ const shouldCache = options.ttl !== void 0;
1074
+ const lruCache = shouldCache ? new M({
1075
+ max: options.maxItems ?? 1e3,
1076
+ ttl: options.ttl
1077
+ }) : null;
1078
+ const keyMap = shouldCache ? new M({
1079
+ max: options.maxItems ?? 1e3,
1080
+ ttl: options.ttl
1081
+ }) : null;
1082
+ const inFlightPromises = /* @__PURE__ */ new Map();
1083
+ const namePrefix = options.name ? `[${options.name}] ` : "";
1084
+ const defaultCacheHit = options.cacheHit === null ? () => {
1085
+ } : options.cacheHit ?? (() => {
1086
+ if (options.name && shouldCache) log.prod(`${namePrefix}cache hit`);
1087
+ });
1088
+ const defaultCacheMiss = options.cacheMiss === null ? () => {
1089
+ } : options.cacheMiss ?? (() => {
1090
+ if (options.name && shouldCache) log.prod(`${namePrefix}cache miss`);
1091
+ });
1092
+ const acceptsCtx = fn.length === 2;
1093
+ const cachedFn = async (input, ctx) => {
1094
+ let key;
1095
+ try {
1096
+ key = getCacheKeyString(input);
1097
+ } catch (error) {
1098
+ const errorMessage = error instanceof Error ? error.message : String(error);
1099
+ throw new Error(
1100
+ `failed to create cache key${namePrefix ? ` for ${options.name}` : ""}: ${errorMessage}`
1101
+ );
1102
+ }
1103
+ const startTime = performance2.now();
1104
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString();
1105
+ log.debug(`${namePrefix}[${timestamp}] cache lookup started`, { key });
1106
+ if (shouldCache && lruCache) {
1107
+ const cached = lruCache.get(key);
1108
+ if (cached !== void 0) {
1109
+ if (keyMap?.get(key) === void 0) keyMap?.set(key, input);
1110
+ const runtime = performance2.now() - startTime;
1111
+ log.debug(`${namePrefix}[${timestamp}] cache hit (from lru)`, {
1112
+ key,
1113
+ runtime: `${Math.round(runtime)}ms`
1114
+ });
1115
+ defaultCacheHit(key);
1116
+ return cached;
1117
+ }
1118
+ }
1119
+ const inFlight = inFlightPromises.get(key);
1120
+ if (inFlight) {
1121
+ log.debug(`${namePrefix}[${timestamp}] cache hit (in-flight)`, { key });
1122
+ defaultCacheHit(key);
1123
+ return inFlight;
1124
+ }
1125
+ log.debug(`${namePrefix}[${timestamp}] cache miss, executing function`, { key });
1126
+ defaultCacheMiss(key);
1127
+ const retries = options.retries ?? [];
1128
+ let lastError;
1129
+ const execStartTime = performance2.now();
1130
+ const promise = (async () => {
1131
+ for (let attempt = 0; attempt <= retries.length; attempt++) {
1132
+ try {
1133
+ const result = acceptsCtx ? await fn(input, ctx) : await fn(input);
1134
+ const execRuntime2 = performance2.now() - execStartTime;
1135
+ const skip = options.skipCache ? options.skipCache(result) : false;
1136
+ if (shouldCache && lruCache && result !== null && result !== void 0 && !skip) {
1137
+ lruCache.set(key, result);
1138
+ keyMap?.set(key, input);
1139
+ }
1140
+ log.debug(`${namePrefix}[${timestamp}] function executed successfully`, {
1141
+ key,
1142
+ runtime: `${Math.round(execRuntime2)}ms`,
1143
+ attempt: attempt + 1,
1144
+ cached: shouldCache && result !== null && result !== void 0 && !skip
1145
+ });
1146
+ return result;
1147
+ } catch (error) {
1148
+ if (options.bail?.(error)) throw error;
1149
+ lastError = error;
1150
+ const isLastAttempt = attempt >= retries.length;
1151
+ if (isLastAttempt) {
1152
+ if (namePrefix) {
1153
+ log.info(
1154
+ `${namePrefix}attempt ${attempt + 1}/${retries.length + 1} failed, no more retries`
1155
+ );
1156
+ log.info(`${namePrefix}`, { key, error, attempt });
1157
+ } else {
1158
+ log.info(`attempt ${attempt + 1}/${retries.length + 1} failed, no more retries`);
1159
+ log.info({ key, error, attempt });
1160
+ }
1161
+ } else {
1162
+ const delay = retries[attempt];
1163
+ if (namePrefix) {
1164
+ log.info(
1165
+ `${namePrefix}attempt ${attempt + 1}/${retries.length + 1} failed, retrying in ${delay}ms`
1166
+ );
1167
+ log.info(`${namePrefix}`, { key, error, attempt });
1168
+ } else {
1169
+ log.info(
1170
+ `attempt ${attempt + 1}/${retries.length + 1} failed, retrying in ${delay}ms`
1171
+ );
1172
+ log.info({ key, error, attempt });
1173
+ }
1174
+ await sleep(delay);
1175
+ }
1176
+ }
1177
+ }
1178
+ const execRuntime = performance2.now() - execStartTime;
1179
+ log.debug(`${namePrefix}[${timestamp}] function failed after all retries`, {
1180
+ key,
1181
+ runtime: `${Math.round(execRuntime)}ms`,
1182
+ attempts: retries.length + 1,
1183
+ error: lastError instanceof Error ? lastError.message : lastError
1184
+ });
1185
+ throw lastError;
1186
+ })();
1187
+ inFlightPromises.set(key, promise);
1188
+ try {
1189
+ return await promise;
1190
+ } finally {
1191
+ inFlightPromises.delete(key);
1192
+ }
1193
+ };
1194
+ cachedFn.clear = (key) => {
1195
+ if (shouldCache && lruCache) {
1196
+ if (key !== void 0) {
1197
+ let stringKey;
1198
+ try {
1199
+ stringKey = getCacheKeyString(key);
1200
+ } catch (error) {
1201
+ const errorMessage = error instanceof Error ? error.message : String(error);
1202
+ throw new Error(
1203
+ `failed to hash cache key for clear()${namePrefix ? ` in ${options.name}` : ""}: ${errorMessage}`
1204
+ );
1205
+ }
1206
+ lruCache.delete(stringKey);
1207
+ keyMap.delete(stringKey);
1208
+ } else {
1209
+ lruCache.clear();
1210
+ keyMap.clear();
1211
+ }
1212
+ }
1213
+ };
1214
+ cachedFn.has = (key) => {
1215
+ if (!shouldCache || !lruCache) return false;
1216
+ try {
1217
+ const stringKey = getCacheKeyString(key);
1218
+ return lruCache.has(stringKey);
1219
+ } catch (error) {
1220
+ const errorMessage = error instanceof Error ? error.message : String(error);
1221
+ throw new Error(
1222
+ `failed to hash cache key for has()${namePrefix ? ` in ${options.name}` : ""}: ${errorMessage}`
1223
+ );
1224
+ }
1225
+ };
1226
+ cachedFn.invalidate = (predicate) => {
1227
+ if (!shouldCache || !lruCache) return 0;
1228
+ let count = 0;
1229
+ for (const [stringKey, originalKey] of keyMap) {
1230
+ if (predicate(originalKey)) {
1231
+ lruCache.delete(stringKey);
1232
+ keyMap.delete(stringKey);
1233
+ count++;
1234
+ }
1235
+ }
1236
+ return count;
1237
+ };
1238
+ return cachedFn;
1239
+ }
1240
+ export {
1241
+ op,
1242
+ range,
1243
+ schedule
1244
+ };