@mastra/react 0.2.3 → 0.2.4-alpha.1

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 (22) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/{chunk-REDZDNFN-B1ouuY83.js → chunk-REDZDNFN-D4oanb5P.js} +2 -2
  3. package/dist/{chunk-REDZDNFN-B1ouuY83.js.map → chunk-REDZDNFN-D4oanb5P.js.map} +1 -1
  4. package/dist/{chunk-REDZDNFN-CbkG5d3w.cjs → chunk-REDZDNFN-fhjnNsSU.cjs} +2 -2
  5. package/dist/{chunk-REDZDNFN-CbkG5d3w.cjs.map → chunk-REDZDNFN-fhjnNsSU.cjs.map} +1 -1
  6. package/dist/{index-BQSALCsO.js → index-DAN4vgIA.js} +829 -2355
  7. package/dist/index-DAN4vgIA.js.map +1 -0
  8. package/dist/{index-DT_KGByV.cjs → index-VHXhgr5V.cjs} +160 -1686
  9. package/dist/index-VHXhgr5V.cjs.map +1 -0
  10. package/dist/index.cjs +1 -1
  11. package/dist/index.js +1 -1
  12. package/dist/{token-6GSAFR2W-XRCSVUPZ-nW1dYF0l.js → token-6GSAFR2W-XRCSVUPZ-D1m4Pmyv.js} +3 -3
  13. package/dist/{token-6GSAFR2W-XRCSVUPZ-nW1dYF0l.js.map → token-6GSAFR2W-XRCSVUPZ-D1m4Pmyv.js.map} +1 -1
  14. package/dist/{token-6GSAFR2W-XRCSVUPZ-D4lFShVi.cjs → token-6GSAFR2W-XRCSVUPZ-DtWMGnar.cjs} +3 -3
  15. package/dist/{token-6GSAFR2W-XRCSVUPZ-D4lFShVi.cjs.map → token-6GSAFR2W-XRCSVUPZ-DtWMGnar.cjs.map} +1 -1
  16. package/dist/{token-util-NEHG7TUY-U7CX7GS4-IihD8c3p.js → token-util-NEHG7TUY-U7CX7GS4-C_TOJaxg.js} +2 -2
  17. package/dist/{token-util-NEHG7TUY-U7CX7GS4-IihD8c3p.js.map → token-util-NEHG7TUY-U7CX7GS4-C_TOJaxg.js.map} +1 -1
  18. package/dist/{token-util-NEHG7TUY-U7CX7GS4-BZFIAvf9.cjs → token-util-NEHG7TUY-U7CX7GS4-MfOGpyjN.cjs} +2 -2
  19. package/dist/{token-util-NEHG7TUY-U7CX7GS4-BZFIAvf9.cjs.map → token-util-NEHG7TUY-U7CX7GS4-MfOGpyjN.cjs.map} +1 -1
  20. package/package.json +5 -5
  21. package/dist/index-BQSALCsO.js.map +0 -1
  22. package/dist/index-DT_KGByV.cjs.map +0 -1
@@ -367,7 +367,7 @@ const toUIMessage = ({ chunk, conversation, metadata }) => {
367
367
  toolCallId,
368
368
  state: "output-error",
369
369
  input: toolPart.input,
370
- errorText: String(error),
370
+ errorText: typeof error === "string" ? error : error instanceof Error ? error.message : error?.message ?? String(error),
371
371
  callProviderMetadata: chunk.payload.providerMetadata
372
372
  };
373
373
  } else {
@@ -986,125 +986,6 @@ const resolveToChildMessages = (messages) => {
986
986
  return childMessages;
987
987
  };
988
988
 
989
- // src/request-context/index.ts
990
- var RequestContext = class {
991
- registry = /* @__PURE__ */ new Map();
992
- constructor(iterable) {
993
- this.registry = new Map(iterable);
994
- }
995
- /**
996
- * set a value with strict typing if `Values` is a Record and the key exists in it.
997
- */
998
- set(key, value) {
999
- this.registry.set(key, value);
1000
- }
1001
- /**
1002
- * Get a value with its type
1003
- */
1004
- get(key) {
1005
- return this.registry.get(key);
1006
- }
1007
- /**
1008
- * Check if a key exists in the container
1009
- */
1010
- has(key) {
1011
- return this.registry.has(key);
1012
- }
1013
- /**
1014
- * Delete a value by key
1015
- */
1016
- delete(key) {
1017
- return this.registry.delete(key);
1018
- }
1019
- /**
1020
- * Clear all values from the container
1021
- */
1022
- clear() {
1023
- this.registry.clear();
1024
- }
1025
- /**
1026
- * Get all keys in the container
1027
- */
1028
- keys() {
1029
- return this.registry.keys();
1030
- }
1031
- /**
1032
- * Get all values in the container
1033
- */
1034
- values() {
1035
- return this.registry.values();
1036
- }
1037
- /**
1038
- * Get all entries in the container.
1039
- * Returns a discriminated union of tuples for proper type narrowing when iterating.
1040
- */
1041
- entries() {
1042
- return this.registry.entries();
1043
- }
1044
- /**
1045
- * Get the size of the container
1046
- */
1047
- size() {
1048
- return this.registry.size;
1049
- }
1050
- /**
1051
- * Execute a function for each entry in the container.
1052
- * The callback receives properly typed key-value pairs.
1053
- */
1054
- forEach(callbackfn) {
1055
- this.registry.forEach(callbackfn);
1056
- }
1057
- /**
1058
- * Custom JSON serialization method.
1059
- * Converts the internal Map to a plain object for proper JSON serialization.
1060
- * Non-serializable values (e.g., RPC proxies, functions, circular references)
1061
- * are skipped to prevent serialization errors when storing to database.
1062
- */
1063
- toJSON() {
1064
- const result = {};
1065
- for (const [key, value] of this.registry.entries()) {
1066
- if (this.isSerializable(value)) {
1067
- result[key] = value;
1068
- }
1069
- }
1070
- return result;
1071
- }
1072
- /**
1073
- * Check if a value can be safely serialized to JSON.
1074
- */
1075
- isSerializable(value) {
1076
- if (value === null || value === void 0) return true;
1077
- if (typeof value === "function") return false;
1078
- if (typeof value === "symbol") return false;
1079
- if (typeof value !== "object") return true;
1080
- try {
1081
- JSON.stringify(value);
1082
- return true;
1083
- } catch {
1084
- return false;
1085
- }
1086
- }
1087
- /**
1088
- * Get all values as a typed object for destructuring.
1089
- * Returns Record<string, any> when untyped, or the Values type when typed.
1090
- *
1091
- * @example
1092
- * ```typescript
1093
- * const ctx = new RequestContext<{ userId: string; apiKey: string }>();
1094
- * ctx.set('userId', 'user-123');
1095
- * ctx.set('apiKey', 'key-456');
1096
- * const { userId, apiKey } = ctx.all;
1097
- * ```
1098
- */
1099
- get all() {
1100
- return Object.fromEntries(this.registry);
1101
- }
1102
- };
1103
-
1104
- function getDefaultExportFromCjs (x) {
1105
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
1106
- }
1107
-
1108
989
  var __create$4 = Object.create;
1109
990
  var __defProp$6 = Object.defineProperty;
1110
991
  var __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor;
@@ -3288,8 +3169,8 @@ var require_get_vercel_oidc_token = __commonJS$3({
3288
3169
  }
3289
3170
  try {
3290
3171
  const [{ getTokenPayload, isExpired }, { refreshToken }] = await Promise.all([
3291
- await Promise.resolve().then(() => require('./token-util-NEHG7TUY-U7CX7GS4-BZFIAvf9.cjs')),
3292
- await Promise.resolve().then(() => require('./token-6GSAFR2W-XRCSVUPZ-D4lFShVi.cjs'))
3172
+ await Promise.resolve().then(() => require('./token-util-NEHG7TUY-U7CX7GS4-MfOGpyjN.cjs')),
3173
+ await Promise.resolve().then(() => require('./token-6GSAFR2W-XRCSVUPZ-DtWMGnar.cjs'))
3293
3174
  ]);
3294
3175
  if (!token || isExpired(getTokenPayload(token))) {
3295
3176
  await refreshToken();
@@ -5885,6 +5766,125 @@ var MastraBaseError = class extends Error {
5885
5766
  var MastraError = class extends MastraBaseError {
5886
5767
  };
5887
5768
 
5769
+ // src/request-context/index.ts
5770
+ var RequestContext = class {
5771
+ registry = /* @__PURE__ */ new Map();
5772
+ constructor(iterable) {
5773
+ this.registry = new Map(iterable);
5774
+ }
5775
+ /**
5776
+ * set a value with strict typing if `Values` is a Record and the key exists in it.
5777
+ */
5778
+ set(key, value) {
5779
+ this.registry.set(key, value);
5780
+ }
5781
+ /**
5782
+ * Get a value with its type
5783
+ */
5784
+ get(key) {
5785
+ return this.registry.get(key);
5786
+ }
5787
+ /**
5788
+ * Check if a key exists in the container
5789
+ */
5790
+ has(key) {
5791
+ return this.registry.has(key);
5792
+ }
5793
+ /**
5794
+ * Delete a value by key
5795
+ */
5796
+ delete(key) {
5797
+ return this.registry.delete(key);
5798
+ }
5799
+ /**
5800
+ * Clear all values from the container
5801
+ */
5802
+ clear() {
5803
+ this.registry.clear();
5804
+ }
5805
+ /**
5806
+ * Get all keys in the container
5807
+ */
5808
+ keys() {
5809
+ return this.registry.keys();
5810
+ }
5811
+ /**
5812
+ * Get all values in the container
5813
+ */
5814
+ values() {
5815
+ return this.registry.values();
5816
+ }
5817
+ /**
5818
+ * Get all entries in the container.
5819
+ * Returns a discriminated union of tuples for proper type narrowing when iterating.
5820
+ */
5821
+ entries() {
5822
+ return this.registry.entries();
5823
+ }
5824
+ /**
5825
+ * Get the size of the container
5826
+ */
5827
+ size() {
5828
+ return this.registry.size;
5829
+ }
5830
+ /**
5831
+ * Execute a function for each entry in the container.
5832
+ * The callback receives properly typed key-value pairs.
5833
+ */
5834
+ forEach(callbackfn) {
5835
+ this.registry.forEach(callbackfn);
5836
+ }
5837
+ /**
5838
+ * Custom JSON serialization method.
5839
+ * Converts the internal Map to a plain object for proper JSON serialization.
5840
+ * Non-serializable values (e.g., RPC proxies, functions, circular references)
5841
+ * are skipped to prevent serialization errors when storing to database.
5842
+ */
5843
+ toJSON() {
5844
+ const result = {};
5845
+ for (const [key, value] of this.registry.entries()) {
5846
+ if (this.isSerializable(value)) {
5847
+ result[key] = value;
5848
+ }
5849
+ }
5850
+ return result;
5851
+ }
5852
+ /**
5853
+ * Check if a value can be safely serialized to JSON.
5854
+ */
5855
+ isSerializable(value) {
5856
+ if (value === null || value === void 0) return true;
5857
+ if (typeof value === "function") return false;
5858
+ if (typeof value === "symbol") return false;
5859
+ if (typeof value !== "object") return true;
5860
+ try {
5861
+ JSON.stringify(value);
5862
+ return true;
5863
+ } catch {
5864
+ return false;
5865
+ }
5866
+ }
5867
+ /**
5868
+ * Get all values as a typed object for destructuring.
5869
+ * Returns Record<string, any> when untyped, or the Values type when typed.
5870
+ *
5871
+ * @example
5872
+ * ```typescript
5873
+ * const ctx = new RequestContext<{ userId: string; apiKey: string }>();
5874
+ * ctx.set('userId', 'user-123');
5875
+ * ctx.set('apiKey', 'key-456');
5876
+ * const { userId, apiKey } = ctx.all;
5877
+ * ```
5878
+ */
5879
+ get all() {
5880
+ return Object.fromEntries(this.registry);
5881
+ }
5882
+ };
5883
+
5884
+ function getDefaultExportFromCjs (x) {
5885
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
5886
+ }
5887
+
5888
5888
  // ../_vendored/ai_v4/dist/chunk-OPIPXJLE.js
5889
5889
  var __create$2 = Object.create;
5890
5890
  var __defProp$3 = Object.defineProperty;
@@ -11744,6 +11744,34 @@ function aiV5UIMessagesToAIV5ModelMessages(messages, dbMessages, filterIncomplet
11744
11744
  const sanitized = sanitizeV5UIMessages(messages, filterIncompleteToolCalls);
11745
11745
  const preprocessed = addStartStepPartsForAIV5(sanitized);
11746
11746
  const result = convertToModelMessages(preprocessed);
11747
+ const storedModelOutputs = /* @__PURE__ */ new Map();
11748
+ for (const dbMsg of dbMessages) {
11749
+ if (dbMsg.content?.format === 2 && dbMsg.content.parts) {
11750
+ for (const part of dbMsg.content.parts) {
11751
+ if (part.type === "tool-invocation" && part.toolInvocation?.state === "result" && part.providerMetadata?.mastra && typeof part.providerMetadata.mastra === "object" && "modelOutput" in part.providerMetadata.mastra) {
11752
+ storedModelOutputs.set(
11753
+ part.toolInvocation.toolCallId,
11754
+ part.providerMetadata.mastra.modelOutput
11755
+ );
11756
+ }
11757
+ }
11758
+ }
11759
+ }
11760
+ if (storedModelOutputs.size > 0) {
11761
+ for (const modelMsg of result) {
11762
+ if (modelMsg.role === "tool" && Array.isArray(modelMsg.content)) {
11763
+ for (let i = 0; i < modelMsg.content.length; i++) {
11764
+ const part = modelMsg.content[i];
11765
+ if (part.type === "tool-result" && storedModelOutputs.has(part.toolCallId)) {
11766
+ modelMsg.content[i] = {
11767
+ ...part,
11768
+ output: storedModelOutputs.get(part.toolCallId)
11769
+ };
11770
+ }
11771
+ }
11772
+ }
11773
+ }
11774
+ }
11747
11775
  const withProviderOptions = result.map((modelMsg, index) => {
11748
11776
  const uiMsg = preprocessed[index];
11749
11777
  if (uiMsg?.metadata && typeof uiMsg.metadata === "object" && "providerMetadata" in uiMsg.metadata && uiMsg.metadata.providerMetadata) {
@@ -12014,6 +12042,12 @@ var MessageMerger = class _MessageMerger {
12014
12042
  ...part.toolInvocation.args
12015
12043
  }
12016
12044
  };
12045
+ if (part.providerMetadata) {
12046
+ existingCallPart.providerMetadata = {
12047
+ ...existingCallPart.providerMetadata,
12048
+ ...part.providerMetadata
12049
+ };
12050
+ }
12017
12051
  if (!latestMessage.content.toolInvocations) {
12018
12052
  latestMessage.content.toolInvocations = [];
12019
12053
  }
@@ -24075,1568 +24109,7 @@ __publicField(Tiktoken, "specialTokenRegex", (tokens) => {
24075
24109
  return new RegExp(tokens.map((i) => escapeRegex(i)).join("|"), "g");
24076
24110
  });
24077
24111
 
24078
- /**
24079
- * @module LRUCache
24080
- */
24081
- const defaultPerf = (typeof performance === 'object' &&
24082
- performance &&
24083
- typeof performance.now === 'function') ?
24084
- performance
24085
- : Date;
24086
- const warned = new Set();
24087
- /* c8 ignore start */
24088
- const PROCESS = (typeof process === 'object' && !!process ?
24089
- process
24090
- : {});
24091
- /* c8 ignore start */
24092
- const emitWarning = (msg, type, code, fn) => {
24093
- typeof PROCESS.emitWarning === 'function' ?
24094
- PROCESS.emitWarning(msg, type, code, fn)
24095
- : console.error(`[${code}] ${type}: ${msg}`);
24096
- };
24097
- let AC = globalThis.AbortController;
24098
- let AS = globalThis.AbortSignal;
24099
- /* c8 ignore start */
24100
- if (typeof AC === 'undefined') {
24101
- //@ts-ignore
24102
- AS = class AbortSignal {
24103
- onabort;
24104
- _onabort = [];
24105
- reason;
24106
- aborted = false;
24107
- addEventListener(_, fn) {
24108
- this._onabort.push(fn);
24109
- }
24110
- };
24111
- //@ts-ignore
24112
- AC = class AbortController {
24113
- constructor() {
24114
- warnACPolyfill();
24115
- }
24116
- signal = new AS();
24117
- abort(reason) {
24118
- if (this.signal.aborted)
24119
- return;
24120
- //@ts-ignore
24121
- this.signal.reason = reason;
24122
- //@ts-ignore
24123
- this.signal.aborted = true;
24124
- //@ts-ignore
24125
- for (const fn of this.signal._onabort) {
24126
- fn(reason);
24127
- }
24128
- this.signal.onabort?.(reason);
24129
- }
24130
- };
24131
- let printACPolyfillWarning = PROCESS.env?.LRU_CACHE_IGNORE_AC_WARNING !== '1';
24132
- const warnACPolyfill = () => {
24133
- if (!printACPolyfillWarning)
24134
- return;
24135
- printACPolyfillWarning = false;
24136
- emitWarning('AbortController is not defined. If using lru-cache in ' +
24137
- 'node 14, load an AbortController polyfill from the ' +
24138
- '`node-abort-controller` package. A minimal polyfill is ' +
24139
- 'provided for use by LRUCache.fetch(), but it should not be ' +
24140
- 'relied upon in other contexts (eg, passing it to other APIs that ' +
24141
- 'use AbortController/AbortSignal might have undesirable effects). ' +
24142
- 'You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.', 'NO_ABORT_CONTROLLER', 'ENOTSUP', warnACPolyfill);
24143
- };
24144
- }
24145
- /* c8 ignore stop */
24146
- const shouldWarn = (code) => !warned.has(code);
24147
- const isPosInt = (n) => n && n === Math.floor(n) && n > 0 && isFinite(n);
24148
- /* c8 ignore start */
24149
- // This is a little bit ridiculous, tbh.
24150
- // The maximum array length is 2^32-1 or thereabouts on most JS impls.
24151
- // And well before that point, you're caching the entire world, I mean,
24152
- // that's ~32GB of just integers for the next/prev links, plus whatever
24153
- // else to hold that many keys and values. Just filling the memory with
24154
- // zeroes at init time is brutal when you get that big.
24155
- // But why not be complete?
24156
- // Maybe in the future, these limits will have expanded.
24157
- const getUintArray = (max) => !isPosInt(max) ? null
24158
- : max <= Math.pow(2, 8) ? Uint8Array
24159
- : max <= Math.pow(2, 16) ? Uint16Array
24160
- : max <= Math.pow(2, 32) ? Uint32Array
24161
- : max <= Number.MAX_SAFE_INTEGER ? ZeroArray
24162
- : null;
24163
- /* c8 ignore stop */
24164
- class ZeroArray extends Array {
24165
- constructor(size) {
24166
- super(size);
24167
- this.fill(0);
24168
- }
24169
- }
24170
- class Stack {
24171
- heap;
24172
- length;
24173
- // private constructor
24174
- static #constructing = false;
24175
- static create(max) {
24176
- const HeapCls = getUintArray(max);
24177
- if (!HeapCls)
24178
- return [];
24179
- Stack.#constructing = true;
24180
- const s = new Stack(max, HeapCls);
24181
- Stack.#constructing = false;
24182
- return s;
24183
- }
24184
- constructor(max, HeapCls) {
24185
- /* c8 ignore start */
24186
- if (!Stack.#constructing) {
24187
- throw new TypeError('instantiate Stack using Stack.create(n)');
24188
- }
24189
- /* c8 ignore stop */
24190
- this.heap = new HeapCls(max);
24191
- this.length = 0;
24192
- }
24193
- push(n) {
24194
- this.heap[this.length++] = n;
24195
- }
24196
- pop() {
24197
- return this.heap[--this.length];
24198
- }
24199
- }
24200
- /**
24201
- * Default export, the thing you're using this module to get.
24202
- *
24203
- * The `K` and `V` types define the key and value types, respectively. The
24204
- * optional `FC` type defines the type of the `context` object passed to
24205
- * `cache.fetch()` and `cache.memo()`.
24206
- *
24207
- * Keys and values **must not** be `null` or `undefined`.
24208
- *
24209
- * All properties from the options object (with the exception of `max`,
24210
- * `maxSize`, `fetchMethod`, `memoMethod`, `dispose` and `disposeAfter`) are
24211
- * added as normal public members. (The listed options are read-only getters.)
24212
- *
24213
- * Changing any of these will alter the defaults for subsequent method calls.
24214
- */
24215
- class LRUCache {
24216
- // options that cannot be changed without disaster
24217
- #max;
24218
- #maxSize;
24219
- #dispose;
24220
- #onInsert;
24221
- #disposeAfter;
24222
- #fetchMethod;
24223
- #memoMethod;
24224
- #perf;
24225
- /**
24226
- * {@link LRUCache.OptionsBase.perf}
24227
- */
24228
- get perf() {
24229
- return this.#perf;
24230
- }
24231
- /**
24232
- * {@link LRUCache.OptionsBase.ttl}
24233
- */
24234
- ttl;
24235
- /**
24236
- * {@link LRUCache.OptionsBase.ttlResolution}
24237
- */
24238
- ttlResolution;
24239
- /**
24240
- * {@link LRUCache.OptionsBase.ttlAutopurge}
24241
- */
24242
- ttlAutopurge;
24243
- /**
24244
- * {@link LRUCache.OptionsBase.updateAgeOnGet}
24245
- */
24246
- updateAgeOnGet;
24247
- /**
24248
- * {@link LRUCache.OptionsBase.updateAgeOnHas}
24249
- */
24250
- updateAgeOnHas;
24251
- /**
24252
- * {@link LRUCache.OptionsBase.allowStale}
24253
- */
24254
- allowStale;
24255
- /**
24256
- * {@link LRUCache.OptionsBase.noDisposeOnSet}
24257
- */
24258
- noDisposeOnSet;
24259
- /**
24260
- * {@link LRUCache.OptionsBase.noUpdateTTL}
24261
- */
24262
- noUpdateTTL;
24263
- /**
24264
- * {@link LRUCache.OptionsBase.maxEntrySize}
24265
- */
24266
- maxEntrySize;
24267
- /**
24268
- * {@link LRUCache.OptionsBase.sizeCalculation}
24269
- */
24270
- sizeCalculation;
24271
- /**
24272
- * {@link LRUCache.OptionsBase.noDeleteOnFetchRejection}
24273
- */
24274
- noDeleteOnFetchRejection;
24275
- /**
24276
- * {@link LRUCache.OptionsBase.noDeleteOnStaleGet}
24277
- */
24278
- noDeleteOnStaleGet;
24279
- /**
24280
- * {@link LRUCache.OptionsBase.allowStaleOnFetchAbort}
24281
- */
24282
- allowStaleOnFetchAbort;
24283
- /**
24284
- * {@link LRUCache.OptionsBase.allowStaleOnFetchRejection}
24285
- */
24286
- allowStaleOnFetchRejection;
24287
- /**
24288
- * {@link LRUCache.OptionsBase.ignoreFetchAbort}
24289
- */
24290
- ignoreFetchAbort;
24291
- // computed properties
24292
- #size;
24293
- #calculatedSize;
24294
- #keyMap;
24295
- #keyList;
24296
- #valList;
24297
- #next;
24298
- #prev;
24299
- #head;
24300
- #tail;
24301
- #free;
24302
- #disposed;
24303
- #sizes;
24304
- #starts;
24305
- #ttls;
24306
- #hasDispose;
24307
- #hasFetchMethod;
24308
- #hasDisposeAfter;
24309
- #hasOnInsert;
24310
- /**
24311
- * Do not call this method unless you need to inspect the
24312
- * inner workings of the cache. If anything returned by this
24313
- * object is modified in any way, strange breakage may occur.
24314
- *
24315
- * These fields are private for a reason!
24316
- *
24317
- * @internal
24318
- */
24319
- static unsafeExposeInternals(c) {
24320
- return {
24321
- // properties
24322
- starts: c.#starts,
24323
- ttls: c.#ttls,
24324
- sizes: c.#sizes,
24325
- keyMap: c.#keyMap,
24326
- keyList: c.#keyList,
24327
- valList: c.#valList,
24328
- next: c.#next,
24329
- prev: c.#prev,
24330
- get head() {
24331
- return c.#head;
24332
- },
24333
- get tail() {
24334
- return c.#tail;
24335
- },
24336
- free: c.#free,
24337
- // methods
24338
- isBackgroundFetch: (p) => c.#isBackgroundFetch(p),
24339
- backgroundFetch: (k, index, options, context) => c.#backgroundFetch(k, index, options, context),
24340
- moveToTail: (index) => c.#moveToTail(index),
24341
- indexes: (options) => c.#indexes(options),
24342
- rindexes: (options) => c.#rindexes(options),
24343
- isStale: (index) => c.#isStale(index),
24344
- };
24345
- }
24346
- // Protected read-only members
24347
- /**
24348
- * {@link LRUCache.OptionsBase.max} (read-only)
24349
- */
24350
- get max() {
24351
- return this.#max;
24352
- }
24353
- /**
24354
- * {@link LRUCache.OptionsBase.maxSize} (read-only)
24355
- */
24356
- get maxSize() {
24357
- return this.#maxSize;
24358
- }
24359
- /**
24360
- * The total computed size of items in the cache (read-only)
24361
- */
24362
- get calculatedSize() {
24363
- return this.#calculatedSize;
24364
- }
24365
- /**
24366
- * The number of items stored in the cache (read-only)
24367
- */
24368
- get size() {
24369
- return this.#size;
24370
- }
24371
- /**
24372
- * {@link LRUCache.OptionsBase.fetchMethod} (read-only)
24373
- */
24374
- get fetchMethod() {
24375
- return this.#fetchMethod;
24376
- }
24377
- get memoMethod() {
24378
- return this.#memoMethod;
24379
- }
24380
- /**
24381
- * {@link LRUCache.OptionsBase.dispose} (read-only)
24382
- */
24383
- get dispose() {
24384
- return this.#dispose;
24385
- }
24386
- /**
24387
- * {@link LRUCache.OptionsBase.onInsert} (read-only)
24388
- */
24389
- get onInsert() {
24390
- return this.#onInsert;
24391
- }
24392
- /**
24393
- * {@link LRUCache.OptionsBase.disposeAfter} (read-only)
24394
- */
24395
- get disposeAfter() {
24396
- return this.#disposeAfter;
24397
- }
24398
- constructor(options) {
24399
- const { max = 0, ttl, ttlResolution = 1, ttlAutopurge, updateAgeOnGet, updateAgeOnHas, allowStale, dispose, onInsert, disposeAfter, noDisposeOnSet, noUpdateTTL, maxSize = 0, maxEntrySize = 0, sizeCalculation, fetchMethod, memoMethod, noDeleteOnFetchRejection, noDeleteOnStaleGet, allowStaleOnFetchRejection, allowStaleOnFetchAbort, ignoreFetchAbort, perf, } = options;
24400
- if (perf !== undefined) {
24401
- if (typeof perf?.now !== 'function') {
24402
- throw new TypeError('perf option must have a now() method if specified');
24403
- }
24404
- }
24405
- this.#perf = perf ?? defaultPerf;
24406
- if (max !== 0 && !isPosInt(max)) {
24407
- throw new TypeError('max option must be a nonnegative integer');
24408
- }
24409
- const UintArray = max ? getUintArray(max) : Array;
24410
- if (!UintArray) {
24411
- throw new Error('invalid max value: ' + max);
24412
- }
24413
- this.#max = max;
24414
- this.#maxSize = maxSize;
24415
- this.maxEntrySize = maxEntrySize || this.#maxSize;
24416
- this.sizeCalculation = sizeCalculation;
24417
- if (this.sizeCalculation) {
24418
- if (!this.#maxSize && !this.maxEntrySize) {
24419
- throw new TypeError('cannot set sizeCalculation without setting maxSize or maxEntrySize');
24420
- }
24421
- if (typeof this.sizeCalculation !== 'function') {
24422
- throw new TypeError('sizeCalculation set to non-function');
24423
- }
24424
- }
24425
- if (memoMethod !== undefined &&
24426
- typeof memoMethod !== 'function') {
24427
- throw new TypeError('memoMethod must be a function if defined');
24428
- }
24429
- this.#memoMethod = memoMethod;
24430
- if (fetchMethod !== undefined &&
24431
- typeof fetchMethod !== 'function') {
24432
- throw new TypeError('fetchMethod must be a function if specified');
24433
- }
24434
- this.#fetchMethod = fetchMethod;
24435
- this.#hasFetchMethod = !!fetchMethod;
24436
- this.#keyMap = new Map();
24437
- this.#keyList = new Array(max).fill(undefined);
24438
- this.#valList = new Array(max).fill(undefined);
24439
- this.#next = new UintArray(max);
24440
- this.#prev = new UintArray(max);
24441
- this.#head = 0;
24442
- this.#tail = 0;
24443
- this.#free = Stack.create(max);
24444
- this.#size = 0;
24445
- this.#calculatedSize = 0;
24446
- if (typeof dispose === 'function') {
24447
- this.#dispose = dispose;
24448
- }
24449
- if (typeof onInsert === 'function') {
24450
- this.#onInsert = onInsert;
24451
- }
24452
- if (typeof disposeAfter === 'function') {
24453
- this.#disposeAfter = disposeAfter;
24454
- this.#disposed = [];
24455
- }
24456
- else {
24457
- this.#disposeAfter = undefined;
24458
- this.#disposed = undefined;
24459
- }
24460
- this.#hasDispose = !!this.#dispose;
24461
- this.#hasOnInsert = !!this.#onInsert;
24462
- this.#hasDisposeAfter = !!this.#disposeAfter;
24463
- this.noDisposeOnSet = !!noDisposeOnSet;
24464
- this.noUpdateTTL = !!noUpdateTTL;
24465
- this.noDeleteOnFetchRejection = !!noDeleteOnFetchRejection;
24466
- this.allowStaleOnFetchRejection = !!allowStaleOnFetchRejection;
24467
- this.allowStaleOnFetchAbort = !!allowStaleOnFetchAbort;
24468
- this.ignoreFetchAbort = !!ignoreFetchAbort;
24469
- // NB: maxEntrySize is set to maxSize if it's set
24470
- if (this.maxEntrySize !== 0) {
24471
- if (this.#maxSize !== 0) {
24472
- if (!isPosInt(this.#maxSize)) {
24473
- throw new TypeError('maxSize must be a positive integer if specified');
24474
- }
24475
- }
24476
- if (!isPosInt(this.maxEntrySize)) {
24477
- throw new TypeError('maxEntrySize must be a positive integer if specified');
24478
- }
24479
- this.#initializeSizeTracking();
24480
- }
24481
- this.allowStale = !!allowStale;
24482
- this.noDeleteOnStaleGet = !!noDeleteOnStaleGet;
24483
- this.updateAgeOnGet = !!updateAgeOnGet;
24484
- this.updateAgeOnHas = !!updateAgeOnHas;
24485
- this.ttlResolution =
24486
- isPosInt(ttlResolution) || ttlResolution === 0 ?
24487
- ttlResolution
24488
- : 1;
24489
- this.ttlAutopurge = !!ttlAutopurge;
24490
- this.ttl = ttl || 0;
24491
- if (this.ttl) {
24492
- if (!isPosInt(this.ttl)) {
24493
- throw new TypeError('ttl must be a positive integer if specified');
24494
- }
24495
- this.#initializeTTLTracking();
24496
- }
24497
- // do not allow completely unbounded caches
24498
- if (this.#max === 0 && this.ttl === 0 && this.#maxSize === 0) {
24499
- throw new TypeError('At least one of max, maxSize, or ttl is required');
24500
- }
24501
- if (!this.ttlAutopurge && !this.#max && !this.#maxSize) {
24502
- const code = 'LRU_CACHE_UNBOUNDED';
24503
- if (shouldWarn(code)) {
24504
- warned.add(code);
24505
- const msg = 'TTL caching without ttlAutopurge, max, or maxSize can ' +
24506
- 'result in unbounded memory consumption.';
24507
- emitWarning(msg, 'UnboundedCacheWarning', code, LRUCache);
24508
- }
24509
- }
24510
- }
24511
- /**
24512
- * Return the number of ms left in the item's TTL. If item is not in cache,
24513
- * returns `0`. Returns `Infinity` if item is in cache without a defined TTL.
24514
- */
24515
- getRemainingTTL(key) {
24516
- return this.#keyMap.has(key) ? Infinity : 0;
24517
- }
24518
- #initializeTTLTracking() {
24519
- const ttls = new ZeroArray(this.#max);
24520
- const starts = new ZeroArray(this.#max);
24521
- this.#ttls = ttls;
24522
- this.#starts = starts;
24523
- this.#setItemTTL = (index, ttl, start = this.#perf.now()) => {
24524
- starts[index] = ttl !== 0 ? start : 0;
24525
- ttls[index] = ttl;
24526
- if (ttl !== 0 && this.ttlAutopurge) {
24527
- const t = setTimeout(() => {
24528
- if (this.#isStale(index)) {
24529
- this.#delete(this.#keyList[index], 'expire');
24530
- }
24531
- }, ttl + 1);
24532
- // unref() not supported on all platforms
24533
- /* c8 ignore start */
24534
- if (t.unref) {
24535
- t.unref();
24536
- }
24537
- /* c8 ignore stop */
24538
- }
24539
- };
24540
- this.#updateItemAge = index => {
24541
- starts[index] = ttls[index] !== 0 ? this.#perf.now() : 0;
24542
- };
24543
- this.#statusTTL = (status, index) => {
24544
- if (ttls[index]) {
24545
- const ttl = ttls[index];
24546
- const start = starts[index];
24547
- /* c8 ignore next */
24548
- if (!ttl || !start)
24549
- return;
24550
- status.ttl = ttl;
24551
- status.start = start;
24552
- status.now = cachedNow || getNow();
24553
- const age = status.now - start;
24554
- status.remainingTTL = ttl - age;
24555
- }
24556
- };
24557
- // debounce calls to perf.now() to 1s so we're not hitting
24558
- // that costly call repeatedly.
24559
- let cachedNow = 0;
24560
- const getNow = () => {
24561
- const n = this.#perf.now();
24562
- if (this.ttlResolution > 0) {
24563
- cachedNow = n;
24564
- const t = setTimeout(() => (cachedNow = 0), this.ttlResolution);
24565
- // not available on all platforms
24566
- /* c8 ignore start */
24567
- if (t.unref) {
24568
- t.unref();
24569
- }
24570
- /* c8 ignore stop */
24571
- }
24572
- return n;
24573
- };
24574
- this.getRemainingTTL = key => {
24575
- const index = this.#keyMap.get(key);
24576
- if (index === undefined) {
24577
- return 0;
24578
- }
24579
- const ttl = ttls[index];
24580
- const start = starts[index];
24581
- if (!ttl || !start) {
24582
- return Infinity;
24583
- }
24584
- const age = (cachedNow || getNow()) - start;
24585
- return ttl - age;
24586
- };
24587
- this.#isStale = index => {
24588
- const s = starts[index];
24589
- const t = ttls[index];
24590
- return !!t && !!s && (cachedNow || getNow()) - s > t;
24591
- };
24592
- }
24593
- // conditionally set private methods related to TTL
24594
- #updateItemAge = () => { };
24595
- #statusTTL = () => { };
24596
- #setItemTTL = () => { };
24597
- /* c8 ignore stop */
24598
- #isStale = () => false;
24599
- #initializeSizeTracking() {
24600
- const sizes = new ZeroArray(this.#max);
24601
- this.#calculatedSize = 0;
24602
- this.#sizes = sizes;
24603
- this.#removeItemSize = index => {
24604
- this.#calculatedSize -= sizes[index];
24605
- sizes[index] = 0;
24606
- };
24607
- this.#requireSize = (k, v, size, sizeCalculation) => {
24608
- // provisionally accept background fetches.
24609
- // actual value size will be checked when they return.
24610
- if (this.#isBackgroundFetch(v)) {
24611
- return 0;
24612
- }
24613
- if (!isPosInt(size)) {
24614
- if (sizeCalculation) {
24615
- if (typeof sizeCalculation !== 'function') {
24616
- throw new TypeError('sizeCalculation must be a function');
24617
- }
24618
- size = sizeCalculation(v, k);
24619
- if (!isPosInt(size)) {
24620
- throw new TypeError('sizeCalculation return invalid (expect positive integer)');
24621
- }
24622
- }
24623
- else {
24624
- throw new TypeError('invalid size value (must be positive integer). ' +
24625
- 'When maxSize or maxEntrySize is used, sizeCalculation ' +
24626
- 'or size must be set.');
24627
- }
24628
- }
24629
- return size;
24630
- };
24631
- this.#addItemSize = (index, size, status) => {
24632
- sizes[index] = size;
24633
- if (this.#maxSize) {
24634
- const maxSize = this.#maxSize - sizes[index];
24635
- while (this.#calculatedSize > maxSize) {
24636
- this.#evict(true);
24637
- }
24638
- }
24639
- this.#calculatedSize += sizes[index];
24640
- if (status) {
24641
- status.entrySize = size;
24642
- status.totalCalculatedSize = this.#calculatedSize;
24643
- }
24644
- };
24645
- }
24646
- #removeItemSize = _i => { };
24647
- #addItemSize = (_i, _s, _st) => { };
24648
- #requireSize = (_k, _v, size, sizeCalculation) => {
24649
- if (size || sizeCalculation) {
24650
- throw new TypeError('cannot set size without setting maxSize or maxEntrySize on cache');
24651
- }
24652
- return 0;
24653
- };
24654
- *#indexes({ allowStale = this.allowStale } = {}) {
24655
- if (this.#size) {
24656
- for (let i = this.#tail; true;) {
24657
- if (!this.#isValidIndex(i)) {
24658
- break;
24659
- }
24660
- if (allowStale || !this.#isStale(i)) {
24661
- yield i;
24662
- }
24663
- if (i === this.#head) {
24664
- break;
24665
- }
24666
- else {
24667
- i = this.#prev[i];
24668
- }
24669
- }
24670
- }
24671
- }
24672
- *#rindexes({ allowStale = this.allowStale } = {}) {
24673
- if (this.#size) {
24674
- for (let i = this.#head; true;) {
24675
- if (!this.#isValidIndex(i)) {
24676
- break;
24677
- }
24678
- if (allowStale || !this.#isStale(i)) {
24679
- yield i;
24680
- }
24681
- if (i === this.#tail) {
24682
- break;
24683
- }
24684
- else {
24685
- i = this.#next[i];
24686
- }
24687
- }
24688
- }
24689
- }
24690
- #isValidIndex(index) {
24691
- return (index !== undefined &&
24692
- this.#keyMap.get(this.#keyList[index]) === index);
24693
- }
24694
- /**
24695
- * Return a generator yielding `[key, value]` pairs,
24696
- * in order from most recently used to least recently used.
24697
- */
24698
- *entries() {
24699
- for (const i of this.#indexes()) {
24700
- if (this.#valList[i] !== undefined &&
24701
- this.#keyList[i] !== undefined &&
24702
- !this.#isBackgroundFetch(this.#valList[i])) {
24703
- yield [this.#keyList[i], this.#valList[i]];
24704
- }
24705
- }
24706
- }
24707
- /**
24708
- * Inverse order version of {@link LRUCache.entries}
24709
- *
24710
- * Return a generator yielding `[key, value]` pairs,
24711
- * in order from least recently used to most recently used.
24712
- */
24713
- *rentries() {
24714
- for (const i of this.#rindexes()) {
24715
- if (this.#valList[i] !== undefined &&
24716
- this.#keyList[i] !== undefined &&
24717
- !this.#isBackgroundFetch(this.#valList[i])) {
24718
- yield [this.#keyList[i], this.#valList[i]];
24719
- }
24720
- }
24721
- }
24722
- /**
24723
- * Return a generator yielding the keys in the cache,
24724
- * in order from most recently used to least recently used.
24725
- */
24726
- *keys() {
24727
- for (const i of this.#indexes()) {
24728
- const k = this.#keyList[i];
24729
- if (k !== undefined &&
24730
- !this.#isBackgroundFetch(this.#valList[i])) {
24731
- yield k;
24732
- }
24733
- }
24734
- }
24735
- /**
24736
- * Inverse order version of {@link LRUCache.keys}
24737
- *
24738
- * Return a generator yielding the keys in the cache,
24739
- * in order from least recently used to most recently used.
24740
- */
24741
- *rkeys() {
24742
- for (const i of this.#rindexes()) {
24743
- const k = this.#keyList[i];
24744
- if (k !== undefined &&
24745
- !this.#isBackgroundFetch(this.#valList[i])) {
24746
- yield k;
24747
- }
24748
- }
24749
- }
24750
- /**
24751
- * Return a generator yielding the values in the cache,
24752
- * in order from most recently used to least recently used.
24753
- */
24754
- *values() {
24755
- for (const i of this.#indexes()) {
24756
- const v = this.#valList[i];
24757
- if (v !== undefined &&
24758
- !this.#isBackgroundFetch(this.#valList[i])) {
24759
- yield this.#valList[i];
24760
- }
24761
- }
24762
- }
24763
- /**
24764
- * Inverse order version of {@link LRUCache.values}
24765
- *
24766
- * Return a generator yielding the values in the cache,
24767
- * in order from least recently used to most recently used.
24768
- */
24769
- *rvalues() {
24770
- for (const i of this.#rindexes()) {
24771
- const v = this.#valList[i];
24772
- if (v !== undefined &&
24773
- !this.#isBackgroundFetch(this.#valList[i])) {
24774
- yield this.#valList[i];
24775
- }
24776
- }
24777
- }
24778
- /**
24779
- * Iterating over the cache itself yields the same results as
24780
- * {@link LRUCache.entries}
24781
- */
24782
- [Symbol.iterator]() {
24783
- return this.entries();
24784
- }
24785
- /**
24786
- * A String value that is used in the creation of the default string
24787
- * description of an object. Called by the built-in method
24788
- * `Object.prototype.toString`.
24789
- */
24790
- [Symbol.toStringTag] = 'LRUCache';
24791
- /**
24792
- * Find a value for which the supplied fn method returns a truthy value,
24793
- * similar to `Array.find()`. fn is called as `fn(value, key, cache)`.
24794
- */
24795
- find(fn, getOptions = {}) {
24796
- for (const i of this.#indexes()) {
24797
- const v = this.#valList[i];
24798
- const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
24799
- if (value === undefined)
24800
- continue;
24801
- if (fn(value, this.#keyList[i], this)) {
24802
- return this.get(this.#keyList[i], getOptions);
24803
- }
24804
- }
24805
- }
24806
- /**
24807
- * Call the supplied function on each item in the cache, in order from most
24808
- * recently used to least recently used.
24809
- *
24810
- * `fn` is called as `fn(value, key, cache)`.
24811
- *
24812
- * If `thisp` is provided, function will be called in the `this`-context of
24813
- * the provided object, or the cache if no `thisp` object is provided.
24814
- *
24815
- * Does not update age or recenty of use, or iterate over stale values.
24816
- */
24817
- forEach(fn, thisp = this) {
24818
- for (const i of this.#indexes()) {
24819
- const v = this.#valList[i];
24820
- const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
24821
- if (value === undefined)
24822
- continue;
24823
- fn.call(thisp, value, this.#keyList[i], this);
24824
- }
24825
- }
24826
- /**
24827
- * The same as {@link LRUCache.forEach} but items are iterated over in
24828
- * reverse order. (ie, less recently used items are iterated over first.)
24829
- */
24830
- rforEach(fn, thisp = this) {
24831
- for (const i of this.#rindexes()) {
24832
- const v = this.#valList[i];
24833
- const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
24834
- if (value === undefined)
24835
- continue;
24836
- fn.call(thisp, value, this.#keyList[i], this);
24837
- }
24838
- }
24839
- /**
24840
- * Delete any stale entries. Returns true if anything was removed,
24841
- * false otherwise.
24842
- */
24843
- purgeStale() {
24844
- let deleted = false;
24845
- for (const i of this.#rindexes({ allowStale: true })) {
24846
- if (this.#isStale(i)) {
24847
- this.#delete(this.#keyList[i], 'expire');
24848
- deleted = true;
24849
- }
24850
- }
24851
- return deleted;
24852
- }
24853
- /**
24854
- * Get the extended info about a given entry, to get its value, size, and
24855
- * TTL info simultaneously. Returns `undefined` if the key is not present.
24856
- *
24857
- * Unlike {@link LRUCache#dump}, which is designed to be portable and survive
24858
- * serialization, the `start` value is always the current timestamp, and the
24859
- * `ttl` is a calculated remaining time to live (negative if expired).
24860
- *
24861
- * Always returns stale values, if their info is found in the cache, so be
24862
- * sure to check for expirations (ie, a negative {@link LRUCache.Entry#ttl})
24863
- * if relevant.
24864
- */
24865
- info(key) {
24866
- const i = this.#keyMap.get(key);
24867
- if (i === undefined)
24868
- return undefined;
24869
- const v = this.#valList[i];
24870
- /* c8 ignore start - this isn't tested for the info function,
24871
- * but it's the same logic as found in other places. */
24872
- const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
24873
- if (value === undefined)
24874
- return undefined;
24875
- /* c8 ignore end */
24876
- const entry = { value };
24877
- if (this.#ttls && this.#starts) {
24878
- const ttl = this.#ttls[i];
24879
- const start = this.#starts[i];
24880
- if (ttl && start) {
24881
- const remain = ttl - (this.#perf.now() - start);
24882
- entry.ttl = remain;
24883
- entry.start = Date.now();
24884
- }
24885
- }
24886
- if (this.#sizes) {
24887
- entry.size = this.#sizes[i];
24888
- }
24889
- return entry;
24890
- }
24891
- /**
24892
- * Return an array of [key, {@link LRUCache.Entry}] tuples which can be
24893
- * passed to {@link LRUCache#load}.
24894
- *
24895
- * The `start` fields are calculated relative to a portable `Date.now()`
24896
- * timestamp, even if `performance.now()` is available.
24897
- *
24898
- * Stale entries are always included in the `dump`, even if
24899
- * {@link LRUCache.OptionsBase.allowStale} is false.
24900
- *
24901
- * Note: this returns an actual array, not a generator, so it can be more
24902
- * easily passed around.
24903
- */
24904
- dump() {
24905
- const arr = [];
24906
- for (const i of this.#indexes({ allowStale: true })) {
24907
- const key = this.#keyList[i];
24908
- const v = this.#valList[i];
24909
- const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
24910
- if (value === undefined || key === undefined)
24911
- continue;
24912
- const entry = { value };
24913
- if (this.#ttls && this.#starts) {
24914
- entry.ttl = this.#ttls[i];
24915
- // always dump the start relative to a portable timestamp
24916
- // it's ok for this to be a bit slow, it's a rare operation.
24917
- const age = this.#perf.now() - this.#starts[i];
24918
- entry.start = Math.floor(Date.now() - age);
24919
- }
24920
- if (this.#sizes) {
24921
- entry.size = this.#sizes[i];
24922
- }
24923
- arr.unshift([key, entry]);
24924
- }
24925
- return arr;
24926
- }
24927
- /**
24928
- * Reset the cache and load in the items in entries in the order listed.
24929
- *
24930
- * The shape of the resulting cache may be different if the same options are
24931
- * not used in both caches.
24932
- *
24933
- * The `start` fields are assumed to be calculated relative to a portable
24934
- * `Date.now()` timestamp, even if `performance.now()` is available.
24935
- */
24936
- load(arr) {
24937
- this.clear();
24938
- for (const [key, entry] of arr) {
24939
- if (entry.start) {
24940
- // entry.start is a portable timestamp, but we may be using
24941
- // node's performance.now(), so calculate the offset, so that
24942
- // we get the intended remaining TTL, no matter how long it's
24943
- // been on ice.
24944
- //
24945
- // it's ok for this to be a bit slow, it's a rare operation.
24946
- const age = Date.now() - entry.start;
24947
- entry.start = this.#perf.now() - age;
24948
- }
24949
- this.set(key, entry.value, entry);
24950
- }
24951
- }
24952
- /**
24953
- * Add a value to the cache.
24954
- *
24955
- * Note: if `undefined` is specified as a value, this is an alias for
24956
- * {@link LRUCache#delete}
24957
- *
24958
- * Fields on the {@link LRUCache.SetOptions} options param will override
24959
- * their corresponding values in the constructor options for the scope
24960
- * of this single `set()` operation.
24961
- *
24962
- * If `start` is provided, then that will set the effective start
24963
- * time for the TTL calculation. Note that this must be a previous
24964
- * value of `performance.now()` if supported, or a previous value of
24965
- * `Date.now()` if not.
24966
- *
24967
- * Options object may also include `size`, which will prevent
24968
- * calling the `sizeCalculation` function and just use the specified
24969
- * number if it is a positive integer, and `noDisposeOnSet` which
24970
- * will prevent calling a `dispose` function in the case of
24971
- * overwrites.
24972
- *
24973
- * If the `size` (or return value of `sizeCalculation`) for a given
24974
- * entry is greater than `maxEntrySize`, then the item will not be
24975
- * added to the cache.
24976
- *
24977
- * Will update the recency of the entry.
24978
- *
24979
- * If the value is `undefined`, then this is an alias for
24980
- * `cache.delete(key)`. `undefined` is never stored in the cache.
24981
- */
24982
- set(k, v, setOptions = {}) {
24983
- if (v === undefined) {
24984
- this.delete(k);
24985
- return this;
24986
- }
24987
- const { ttl = this.ttl, start, noDisposeOnSet = this.noDisposeOnSet, sizeCalculation = this.sizeCalculation, status, } = setOptions;
24988
- let { noUpdateTTL = this.noUpdateTTL } = setOptions;
24989
- const size = this.#requireSize(k, v, setOptions.size || 0, sizeCalculation);
24990
- // if the item doesn't fit, don't do anything
24991
- // NB: maxEntrySize set to maxSize by default
24992
- if (this.maxEntrySize && size > this.maxEntrySize) {
24993
- if (status) {
24994
- status.set = 'miss';
24995
- status.maxEntrySizeExceeded = true;
24996
- }
24997
- // have to delete, in case something is there already.
24998
- this.#delete(k, 'set');
24999
- return this;
25000
- }
25001
- let index = this.#size === 0 ? undefined : this.#keyMap.get(k);
25002
- if (index === undefined) {
25003
- // addition
25004
- index = (this.#size === 0 ? this.#tail
25005
- : this.#free.length !== 0 ? this.#free.pop()
25006
- : this.#size === this.#max ? this.#evict(false)
25007
- : this.#size);
25008
- this.#keyList[index] = k;
25009
- this.#valList[index] = v;
25010
- this.#keyMap.set(k, index);
25011
- this.#next[this.#tail] = index;
25012
- this.#prev[index] = this.#tail;
25013
- this.#tail = index;
25014
- this.#size++;
25015
- this.#addItemSize(index, size, status);
25016
- if (status)
25017
- status.set = 'add';
25018
- noUpdateTTL = false;
25019
- if (this.#hasOnInsert) {
25020
- this.#onInsert?.(v, k, 'add');
25021
- }
25022
- }
25023
- else {
25024
- // update
25025
- this.#moveToTail(index);
25026
- const oldVal = this.#valList[index];
25027
- if (v !== oldVal) {
25028
- if (this.#hasFetchMethod && this.#isBackgroundFetch(oldVal)) {
25029
- oldVal.__abortController.abort(new Error('replaced'));
25030
- const { __staleWhileFetching: s } = oldVal;
25031
- if (s !== undefined && !noDisposeOnSet) {
25032
- if (this.#hasDispose) {
25033
- this.#dispose?.(s, k, 'set');
25034
- }
25035
- if (this.#hasDisposeAfter) {
25036
- this.#disposed?.push([s, k, 'set']);
25037
- }
25038
- }
25039
- }
25040
- else if (!noDisposeOnSet) {
25041
- if (this.#hasDispose) {
25042
- this.#dispose?.(oldVal, k, 'set');
25043
- }
25044
- if (this.#hasDisposeAfter) {
25045
- this.#disposed?.push([oldVal, k, 'set']);
25046
- }
25047
- }
25048
- this.#removeItemSize(index);
25049
- this.#addItemSize(index, size, status);
25050
- this.#valList[index] = v;
25051
- if (status) {
25052
- status.set = 'replace';
25053
- const oldValue = oldVal && this.#isBackgroundFetch(oldVal) ?
25054
- oldVal.__staleWhileFetching
25055
- : oldVal;
25056
- if (oldValue !== undefined)
25057
- status.oldValue = oldValue;
25058
- }
25059
- }
25060
- else if (status) {
25061
- status.set = 'update';
25062
- }
25063
- if (this.#hasOnInsert) {
25064
- this.onInsert?.(v, k, v === oldVal ? 'update' : 'replace');
25065
- }
25066
- }
25067
- if (ttl !== 0 && !this.#ttls) {
25068
- this.#initializeTTLTracking();
25069
- }
25070
- if (this.#ttls) {
25071
- if (!noUpdateTTL) {
25072
- this.#setItemTTL(index, ttl, start);
25073
- }
25074
- if (status)
25075
- this.#statusTTL(status, index);
25076
- }
25077
- if (!noDisposeOnSet && this.#hasDisposeAfter && this.#disposed) {
25078
- const dt = this.#disposed;
25079
- let task;
25080
- while ((task = dt?.shift())) {
25081
- this.#disposeAfter?.(...task);
25082
- }
25083
- }
25084
- return this;
25085
- }
25086
- /**
25087
- * Evict the least recently used item, returning its value or
25088
- * `undefined` if cache is empty.
25089
- */
25090
- pop() {
25091
- try {
25092
- while (this.#size) {
25093
- const val = this.#valList[this.#head];
25094
- this.#evict(true);
25095
- if (this.#isBackgroundFetch(val)) {
25096
- if (val.__staleWhileFetching) {
25097
- return val.__staleWhileFetching;
25098
- }
25099
- }
25100
- else if (val !== undefined) {
25101
- return val;
25102
- }
25103
- }
25104
- }
25105
- finally {
25106
- if (this.#hasDisposeAfter && this.#disposed) {
25107
- const dt = this.#disposed;
25108
- let task;
25109
- while ((task = dt?.shift())) {
25110
- this.#disposeAfter?.(...task);
25111
- }
25112
- }
25113
- }
25114
- }
25115
- #evict(free) {
25116
- const head = this.#head;
25117
- const k = this.#keyList[head];
25118
- const v = this.#valList[head];
25119
- if (this.#hasFetchMethod && this.#isBackgroundFetch(v)) {
25120
- v.__abortController.abort(new Error('evicted'));
25121
- }
25122
- else if (this.#hasDispose || this.#hasDisposeAfter) {
25123
- if (this.#hasDispose) {
25124
- this.#dispose?.(v, k, 'evict');
25125
- }
25126
- if (this.#hasDisposeAfter) {
25127
- this.#disposed?.push([v, k, 'evict']);
25128
- }
25129
- }
25130
- this.#removeItemSize(head);
25131
- // if we aren't about to use the index, then null these out
25132
- if (free) {
25133
- this.#keyList[head] = undefined;
25134
- this.#valList[head] = undefined;
25135
- this.#free.push(head);
25136
- }
25137
- if (this.#size === 1) {
25138
- this.#head = this.#tail = 0;
25139
- this.#free.length = 0;
25140
- }
25141
- else {
25142
- this.#head = this.#next[head];
25143
- }
25144
- this.#keyMap.delete(k);
25145
- this.#size--;
25146
- return head;
25147
- }
25148
- /**
25149
- * Check if a key is in the cache, without updating the recency of use.
25150
- * Will return false if the item is stale, even though it is technically
25151
- * in the cache.
25152
- *
25153
- * Check if a key is in the cache, without updating the recency of
25154
- * use. Age is updated if {@link LRUCache.OptionsBase.updateAgeOnHas} is set
25155
- * to `true` in either the options or the constructor.
25156
- *
25157
- * Will return `false` if the item is stale, even though it is technically in
25158
- * the cache. The difference can be determined (if it matters) by using a
25159
- * `status` argument, and inspecting the `has` field.
25160
- *
25161
- * Will not update item age unless
25162
- * {@link LRUCache.OptionsBase.updateAgeOnHas} is set.
25163
- */
25164
- has(k, hasOptions = {}) {
25165
- const { updateAgeOnHas = this.updateAgeOnHas, status } = hasOptions;
25166
- const index = this.#keyMap.get(k);
25167
- if (index !== undefined) {
25168
- const v = this.#valList[index];
25169
- if (this.#isBackgroundFetch(v) &&
25170
- v.__staleWhileFetching === undefined) {
25171
- return false;
25172
- }
25173
- if (!this.#isStale(index)) {
25174
- if (updateAgeOnHas) {
25175
- this.#updateItemAge(index);
25176
- }
25177
- if (status) {
25178
- status.has = 'hit';
25179
- this.#statusTTL(status, index);
25180
- }
25181
- return true;
25182
- }
25183
- else if (status) {
25184
- status.has = 'stale';
25185
- this.#statusTTL(status, index);
25186
- }
25187
- }
25188
- else if (status) {
25189
- status.has = 'miss';
25190
- }
25191
- return false;
25192
- }
25193
- /**
25194
- * Like {@link LRUCache#get} but doesn't update recency or delete stale
25195
- * items.
25196
- *
25197
- * Returns `undefined` if the item is stale, unless
25198
- * {@link LRUCache.OptionsBase.allowStale} is set.
25199
- */
25200
- peek(k, peekOptions = {}) {
25201
- const { allowStale = this.allowStale } = peekOptions;
25202
- const index = this.#keyMap.get(k);
25203
- if (index === undefined ||
25204
- (!allowStale && this.#isStale(index))) {
25205
- return;
25206
- }
25207
- const v = this.#valList[index];
25208
- // either stale and allowed, or forcing a refresh of non-stale value
25209
- return this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
25210
- }
25211
- #backgroundFetch(k, index, options, context) {
25212
- const v = index === undefined ? undefined : this.#valList[index];
25213
- if (this.#isBackgroundFetch(v)) {
25214
- return v;
25215
- }
25216
- const ac = new AC();
25217
- const { signal } = options;
25218
- // when/if our AC signals, then stop listening to theirs.
25219
- signal?.addEventListener('abort', () => ac.abort(signal.reason), {
25220
- signal: ac.signal,
25221
- });
25222
- const fetchOpts = {
25223
- signal: ac.signal,
25224
- options,
25225
- context,
25226
- };
25227
- const cb = (v, updateCache = false) => {
25228
- const { aborted } = ac.signal;
25229
- const ignoreAbort = options.ignoreFetchAbort && v !== undefined;
25230
- if (options.status) {
25231
- if (aborted && !updateCache) {
25232
- options.status.fetchAborted = true;
25233
- options.status.fetchError = ac.signal.reason;
25234
- if (ignoreAbort)
25235
- options.status.fetchAbortIgnored = true;
25236
- }
25237
- else {
25238
- options.status.fetchResolved = true;
25239
- }
25240
- }
25241
- if (aborted && !ignoreAbort && !updateCache) {
25242
- return fetchFail(ac.signal.reason);
25243
- }
25244
- // either we didn't abort, and are still here, or we did, and ignored
25245
- const bf = p;
25246
- // if nothing else has been written there but we're set to update the
25247
- // cache and ignore the abort, or if it's still pending on this specific
25248
- // background request, then write it to the cache.
25249
- const vl = this.#valList[index];
25250
- if (vl === p || ignoreAbort && updateCache && vl === undefined) {
25251
- if (v === undefined) {
25252
- if (bf.__staleWhileFetching !== undefined) {
25253
- this.#valList[index] = bf.__staleWhileFetching;
25254
- }
25255
- else {
25256
- this.#delete(k, 'fetch');
25257
- }
25258
- }
25259
- else {
25260
- if (options.status)
25261
- options.status.fetchUpdated = true;
25262
- this.set(k, v, fetchOpts.options);
25263
- }
25264
- }
25265
- return v;
25266
- };
25267
- const eb = (er) => {
25268
- if (options.status) {
25269
- options.status.fetchRejected = true;
25270
- options.status.fetchError = er;
25271
- }
25272
- return fetchFail(er);
25273
- };
25274
- const fetchFail = (er) => {
25275
- const { aborted } = ac.signal;
25276
- const allowStaleAborted = aborted && options.allowStaleOnFetchAbort;
25277
- const allowStale = allowStaleAborted || options.allowStaleOnFetchRejection;
25278
- const noDelete = allowStale || options.noDeleteOnFetchRejection;
25279
- const bf = p;
25280
- if (this.#valList[index] === p) {
25281
- // if we allow stale on fetch rejections, then we need to ensure that
25282
- // the stale value is not removed from the cache when the fetch fails.
25283
- const del = !noDelete || bf.__staleWhileFetching === undefined;
25284
- if (del) {
25285
- this.#delete(k, 'fetch');
25286
- }
25287
- else if (!allowStaleAborted) {
25288
- // still replace the *promise* with the stale value,
25289
- // since we are done with the promise at this point.
25290
- // leave it untouched if we're still waiting for an
25291
- // aborted background fetch that hasn't yet returned.
25292
- this.#valList[index] = bf.__staleWhileFetching;
25293
- }
25294
- }
25295
- if (allowStale) {
25296
- if (options.status && bf.__staleWhileFetching !== undefined) {
25297
- options.status.returnedStale = true;
25298
- }
25299
- return bf.__staleWhileFetching;
25300
- }
25301
- else if (bf.__returned === bf) {
25302
- throw er;
25303
- }
25304
- };
25305
- const pcall = (res, rej) => {
25306
- const fmp = this.#fetchMethod?.(k, v, fetchOpts);
25307
- if (fmp && fmp instanceof Promise) {
25308
- fmp.then(v => res(v === undefined ? undefined : v), rej);
25309
- }
25310
- // ignored, we go until we finish, regardless.
25311
- // defer check until we are actually aborting,
25312
- // so fetchMethod can override.
25313
- ac.signal.addEventListener('abort', () => {
25314
- if (!options.ignoreFetchAbort ||
25315
- options.allowStaleOnFetchAbort) {
25316
- res(undefined);
25317
- // when it eventually resolves, update the cache.
25318
- if (options.allowStaleOnFetchAbort) {
25319
- res = v => cb(v, true);
25320
- }
25321
- }
25322
- });
25323
- };
25324
- if (options.status)
25325
- options.status.fetchDispatched = true;
25326
- const p = new Promise(pcall).then(cb, eb);
25327
- const bf = Object.assign(p, {
25328
- __abortController: ac,
25329
- __staleWhileFetching: v,
25330
- __returned: undefined,
25331
- });
25332
- if (index === undefined) {
25333
- // internal, don't expose status.
25334
- this.set(k, bf, { ...fetchOpts.options, status: undefined });
25335
- index = this.#keyMap.get(k);
25336
- }
25337
- else {
25338
- this.#valList[index] = bf;
25339
- }
25340
- return bf;
25341
- }
25342
- #isBackgroundFetch(p) {
25343
- if (!this.#hasFetchMethod)
25344
- return false;
25345
- const b = p;
25346
- return (!!b &&
25347
- b instanceof Promise &&
25348
- b.hasOwnProperty('__staleWhileFetching') &&
25349
- b.__abortController instanceof AC);
25350
- }
25351
- async fetch(k, fetchOptions = {}) {
25352
- const {
25353
- // get options
25354
- allowStale = this.allowStale, updateAgeOnGet = this.updateAgeOnGet, noDeleteOnStaleGet = this.noDeleteOnStaleGet,
25355
- // set options
25356
- ttl = this.ttl, noDisposeOnSet = this.noDisposeOnSet, size = 0, sizeCalculation = this.sizeCalculation, noUpdateTTL = this.noUpdateTTL,
25357
- // fetch exclusive options
25358
- noDeleteOnFetchRejection = this.noDeleteOnFetchRejection, allowStaleOnFetchRejection = this.allowStaleOnFetchRejection, ignoreFetchAbort = this.ignoreFetchAbort, allowStaleOnFetchAbort = this.allowStaleOnFetchAbort, context, forceRefresh = false, status, signal, } = fetchOptions;
25359
- if (!this.#hasFetchMethod) {
25360
- if (status)
25361
- status.fetch = 'get';
25362
- return this.get(k, {
25363
- allowStale,
25364
- updateAgeOnGet,
25365
- noDeleteOnStaleGet,
25366
- status,
25367
- });
25368
- }
25369
- const options = {
25370
- allowStale,
25371
- updateAgeOnGet,
25372
- noDeleteOnStaleGet,
25373
- ttl,
25374
- noDisposeOnSet,
25375
- size,
25376
- sizeCalculation,
25377
- noUpdateTTL,
25378
- noDeleteOnFetchRejection,
25379
- allowStaleOnFetchRejection,
25380
- allowStaleOnFetchAbort,
25381
- ignoreFetchAbort,
25382
- status,
25383
- signal,
25384
- };
25385
- let index = this.#keyMap.get(k);
25386
- if (index === undefined) {
25387
- if (status)
25388
- status.fetch = 'miss';
25389
- const p = this.#backgroundFetch(k, index, options, context);
25390
- return (p.__returned = p);
25391
- }
25392
- else {
25393
- // in cache, maybe already fetching
25394
- const v = this.#valList[index];
25395
- if (this.#isBackgroundFetch(v)) {
25396
- const stale = allowStale && v.__staleWhileFetching !== undefined;
25397
- if (status) {
25398
- status.fetch = 'inflight';
25399
- if (stale)
25400
- status.returnedStale = true;
25401
- }
25402
- return stale ? v.__staleWhileFetching : (v.__returned = v);
25403
- }
25404
- // if we force a refresh, that means do NOT serve the cached value,
25405
- // unless we are already in the process of refreshing the cache.
25406
- const isStale = this.#isStale(index);
25407
- if (!forceRefresh && !isStale) {
25408
- if (status)
25409
- status.fetch = 'hit';
25410
- this.#moveToTail(index);
25411
- if (updateAgeOnGet) {
25412
- this.#updateItemAge(index);
25413
- }
25414
- if (status)
25415
- this.#statusTTL(status, index);
25416
- return v;
25417
- }
25418
- // ok, it is stale or a forced refresh, and not already fetching.
25419
- // refresh the cache.
25420
- const p = this.#backgroundFetch(k, index, options, context);
25421
- const hasStale = p.__staleWhileFetching !== undefined;
25422
- const staleVal = hasStale && allowStale;
25423
- if (status) {
25424
- status.fetch = isStale ? 'stale' : 'refresh';
25425
- if (staleVal && isStale)
25426
- status.returnedStale = true;
25427
- }
25428
- return staleVal ? p.__staleWhileFetching : (p.__returned = p);
25429
- }
25430
- }
25431
- async forceFetch(k, fetchOptions = {}) {
25432
- const v = await this.fetch(k, fetchOptions);
25433
- if (v === undefined)
25434
- throw new Error('fetch() returned undefined');
25435
- return v;
25436
- }
25437
- memo(k, memoOptions = {}) {
25438
- const memoMethod = this.#memoMethod;
25439
- if (!memoMethod) {
25440
- throw new Error('no memoMethod provided to constructor');
25441
- }
25442
- const { context, forceRefresh, ...options } = memoOptions;
25443
- const v = this.get(k, options);
25444
- if (!forceRefresh && v !== undefined)
25445
- return v;
25446
- const vv = memoMethod(k, v, {
25447
- options,
25448
- context,
25449
- });
25450
- this.set(k, vv, options);
25451
- return vv;
25452
- }
25453
- /**
25454
- * Return a value from the cache. Will update the recency of the cache
25455
- * entry found.
25456
- *
25457
- * If the key is not found, get() will return `undefined`.
25458
- */
25459
- get(k, getOptions = {}) {
25460
- const { allowStale = this.allowStale, updateAgeOnGet = this.updateAgeOnGet, noDeleteOnStaleGet = this.noDeleteOnStaleGet, status, } = getOptions;
25461
- const index = this.#keyMap.get(k);
25462
- if (index !== undefined) {
25463
- const value = this.#valList[index];
25464
- const fetching = this.#isBackgroundFetch(value);
25465
- if (status)
25466
- this.#statusTTL(status, index);
25467
- if (this.#isStale(index)) {
25468
- if (status)
25469
- status.get = 'stale';
25470
- // delete only if not an in-flight background fetch
25471
- if (!fetching) {
25472
- if (!noDeleteOnStaleGet) {
25473
- this.#delete(k, 'expire');
25474
- }
25475
- if (status && allowStale)
25476
- status.returnedStale = true;
25477
- return allowStale ? value : undefined;
25478
- }
25479
- else {
25480
- if (status &&
25481
- allowStale &&
25482
- value.__staleWhileFetching !== undefined) {
25483
- status.returnedStale = true;
25484
- }
25485
- return allowStale ? value.__staleWhileFetching : undefined;
25486
- }
25487
- }
25488
- else {
25489
- if (status)
25490
- status.get = 'hit';
25491
- // if we're currently fetching it, we don't actually have it yet
25492
- // it's not stale, which means this isn't a staleWhileRefetching.
25493
- // If it's not stale, and fetching, AND has a __staleWhileFetching
25494
- // value, then that means the user fetched with {forceRefresh:true},
25495
- // so it's safe to return that value.
25496
- if (fetching) {
25497
- return value.__staleWhileFetching;
25498
- }
25499
- this.#moveToTail(index);
25500
- if (updateAgeOnGet) {
25501
- this.#updateItemAge(index);
25502
- }
25503
- return value;
25504
- }
25505
- }
25506
- else if (status) {
25507
- status.get = 'miss';
25508
- }
25509
- }
25510
- #connect(p, n) {
25511
- this.#prev[n] = p;
25512
- this.#next[p] = n;
25513
- }
25514
- #moveToTail(index) {
25515
- // if tail already, nothing to do
25516
- // if head, move head to next[index]
25517
- // else
25518
- // move next[prev[index]] to next[index] (head has no prev)
25519
- // move prev[next[index]] to prev[index]
25520
- // prev[index] = tail
25521
- // next[tail] = index
25522
- // tail = index
25523
- if (index !== this.#tail) {
25524
- if (index === this.#head) {
25525
- this.#head = this.#next[index];
25526
- }
25527
- else {
25528
- this.#connect(this.#prev[index], this.#next[index]);
25529
- }
25530
- this.#connect(this.#tail, index);
25531
- this.#tail = index;
25532
- }
25533
- }
25534
- /**
25535
- * Deletes a key out of the cache.
25536
- *
25537
- * Returns true if the key was deleted, false otherwise.
25538
- */
25539
- delete(k) {
25540
- return this.#delete(k, 'delete');
25541
- }
25542
- #delete(k, reason) {
25543
- let deleted = false;
25544
- if (this.#size !== 0) {
25545
- const index = this.#keyMap.get(k);
25546
- if (index !== undefined) {
25547
- deleted = true;
25548
- if (this.#size === 1) {
25549
- this.#clear(reason);
25550
- }
25551
- else {
25552
- this.#removeItemSize(index);
25553
- const v = this.#valList[index];
25554
- if (this.#isBackgroundFetch(v)) {
25555
- v.__abortController.abort(new Error('deleted'));
25556
- }
25557
- else if (this.#hasDispose || this.#hasDisposeAfter) {
25558
- if (this.#hasDispose) {
25559
- this.#dispose?.(v, k, reason);
25560
- }
25561
- if (this.#hasDisposeAfter) {
25562
- this.#disposed?.push([v, k, reason]);
25563
- }
25564
- }
25565
- this.#keyMap.delete(k);
25566
- this.#keyList[index] = undefined;
25567
- this.#valList[index] = undefined;
25568
- if (index === this.#tail) {
25569
- this.#tail = this.#prev[index];
25570
- }
25571
- else if (index === this.#head) {
25572
- this.#head = this.#next[index];
25573
- }
25574
- else {
25575
- const pi = this.#prev[index];
25576
- this.#next[pi] = this.#next[index];
25577
- const ni = this.#next[index];
25578
- this.#prev[ni] = this.#prev[index];
25579
- }
25580
- this.#size--;
25581
- this.#free.push(index);
25582
- }
25583
- }
25584
- }
25585
- if (this.#hasDisposeAfter && this.#disposed?.length) {
25586
- const dt = this.#disposed;
25587
- let task;
25588
- while ((task = dt?.shift())) {
25589
- this.#disposeAfter?.(...task);
25590
- }
25591
- }
25592
- return deleted;
25593
- }
25594
- /**
25595
- * Clear the cache entirely, throwing away all values.
25596
- */
25597
- clear() {
25598
- return this.#clear('delete');
25599
- }
25600
- #clear(reason) {
25601
- for (const index of this.#rindexes({ allowStale: true })) {
25602
- const v = this.#valList[index];
25603
- if (this.#isBackgroundFetch(v)) {
25604
- v.__abortController.abort(new Error('deleted'));
25605
- }
25606
- else {
25607
- const k = this.#keyList[index];
25608
- if (this.#hasDispose) {
25609
- this.#dispose?.(v, k, reason);
25610
- }
25611
- if (this.#hasDisposeAfter) {
25612
- this.#disposed?.push([v, k, reason]);
25613
- }
25614
- }
25615
- }
25616
- this.#keyMap.clear();
25617
- this.#valList.fill(undefined);
25618
- this.#keyList.fill(undefined);
25619
- if (this.#ttls && this.#starts) {
25620
- this.#ttls.fill(0);
25621
- this.#starts.fill(0);
25622
- }
25623
- if (this.#sizes) {
25624
- this.#sizes.fill(0);
25625
- }
25626
- this.#head = 0;
25627
- this.#tail = 0;
25628
- this.#free.length = 0;
25629
- this.#calculatedSize = 0;
25630
- this.#size = 0;
25631
- if (this.#hasDisposeAfter && this.#disposed) {
25632
- const dt = this.#disposed;
25633
- let task;
25634
- while ((task = dt?.shift())) {
25635
- this.#disposeAfter?.(...task);
25636
- }
25637
- }
25638
- }
25639
- }
24112
+ var M=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,I=new Set,R=typeof process=="object"&&process?process:{},x=(a,t,e,i)=>{typeof R.emitWarning=="function"?R.emitWarning(a,t,e,i):console.error(`[${e}] ${t}: ${a}`);},C=globalThis.AbortController,D=globalThis.AbortSignal;if(typeof C>"u"){D=class{onabort;_onabort=[];reason;aborted=false;addEventListener(i,s){this._onabort.push(s);}},C=class{constructor(){t();}signal=new D;abort(i){if(!this.signal.aborted){this.signal.reason=i,this.signal.aborted=true;for(let s of this.signal._onabort)s(i);this.signal.onabort?.(i);}}};let a=R.env?.LRU_CACHE_IGNORE_AC_WARNING!=="1",t=()=>{a&&(a=false,x("AbortController is not defined. If using lru-cache in node 14, load an AbortController polyfill from the `node-abort-controller` package. A minimal polyfill is provided for use by LRUCache.fetch(), but it should not be relied upon in other contexts (eg, passing it to other APIs that use AbortController/AbortSignal might have undesirable effects). You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.","NO_ABORT_CONTROLLER","ENOTSUP",t));};}var G=a=>!I.has(a),y=a=>a&&a===Math.floor(a)&&a>0&&isFinite(a),U=a=>y(a)?a<=Math.pow(2,8)?Uint8Array:a<=Math.pow(2,16)?Uint16Array:a<=Math.pow(2,32)?Uint32Array:a<=Number.MAX_SAFE_INTEGER?z:null:null,z=class extends Array{constructor(t){super(t),this.fill(0);}},W=class a{heap;length;static#o=false;static create(t){let e=U(t);if(!e)return [];a.#o=true;let i=new a(t,e);return a.#o=false,i}constructor(t,e){if(!a.#o)throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new e(t),this.length=0;}push(t){this.heap[this.length++]=t;}pop(){return this.heap[--this.length]}},L=class a{#o;#c;#w;#C;#S;#L;#I;#m;get perf(){return this.#m}ttl;ttlResolution;ttlAutopurge;updateAgeOnGet;updateAgeOnHas;allowStale;noDisposeOnSet;noUpdateTTL;maxEntrySize;sizeCalculation;noDeleteOnFetchRejection;noDeleteOnStaleGet;allowStaleOnFetchAbort;allowStaleOnFetchRejection;ignoreFetchAbort;#n;#_;#s;#i;#t;#a;#u;#l;#h;#b;#r;#y;#A;#d;#g;#T;#v;#f;#x;static unsafeExposeInternals(t){return {starts:t.#A,ttls:t.#d,autopurgeTimers:t.#g,sizes:t.#y,keyMap:t.#s,keyList:t.#i,valList:t.#t,next:t.#a,prev:t.#u,get head(){return t.#l},get tail(){return t.#h},free:t.#b,isBackgroundFetch:e=>t.#e(e),backgroundFetch:(e,i,s,h)=>t.#G(e,i,s,h),moveToTail:e=>t.#D(e),indexes:e=>t.#F(e),rindexes:e=>t.#O(e),isStale:e=>t.#p(e)}}get max(){return this.#o}get maxSize(){return this.#c}get calculatedSize(){return this.#_}get size(){return this.#n}get fetchMethod(){return this.#L}get memoMethod(){return this.#I}get dispose(){return this.#w}get onInsert(){return this.#C}get disposeAfter(){return this.#S}constructor(t){let{max:e=0,ttl:i,ttlResolution:s=1,ttlAutopurge:h,updateAgeOnGet:n,updateAgeOnHas:o,allowStale:r,dispose:f,onInsert:m,disposeAfter:c,noDisposeOnSet:d,noUpdateTTL:g,maxSize:A=0,maxEntrySize:p=0,sizeCalculation:_,fetchMethod:l,memoMethod:w,noDeleteOnFetchRejection:b,noDeleteOnStaleGet:S,allowStaleOnFetchRejection:u,allowStaleOnFetchAbort:T,ignoreFetchAbort:F,perf:v}=t;if(v!==void 0&&typeof v?.now!="function")throw new TypeError("perf option must have a now() method if specified");if(this.#m=v??M,e!==0&&!y(e))throw new TypeError("max option must be a nonnegative integer");let O=e?U(e):Array;if(!O)throw new Error("invalid max value: "+e);if(this.#o=e,this.#c=A,this.maxEntrySize=p||this.#c,this.sizeCalculation=_,this.sizeCalculation){if(!this.#c&&!this.maxEntrySize)throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");if(typeof this.sizeCalculation!="function")throw new TypeError("sizeCalculation set to non-function")}if(w!==void 0&&typeof w!="function")throw new TypeError("memoMethod must be a function if defined");if(this.#I=w,l!==void 0&&typeof l!="function")throw new TypeError("fetchMethod must be a function if specified");if(this.#L=l,this.#v=!!l,this.#s=new Map,this.#i=new Array(e).fill(void 0),this.#t=new Array(e).fill(void 0),this.#a=new O(e),this.#u=new O(e),this.#l=0,this.#h=0,this.#b=W.create(e),this.#n=0,this.#_=0,typeof f=="function"&&(this.#w=f),typeof m=="function"&&(this.#C=m),typeof c=="function"?(this.#S=c,this.#r=[]):(this.#S=void 0,this.#r=void 0),this.#T=!!this.#w,this.#x=!!this.#C,this.#f=!!this.#S,this.noDisposeOnSet=!!d,this.noUpdateTTL=!!g,this.noDeleteOnFetchRejection=!!b,this.allowStaleOnFetchRejection=!!u,this.allowStaleOnFetchAbort=!!T,this.ignoreFetchAbort=!!F,this.maxEntrySize!==0){if(this.#c!==0&&!y(this.#c))throw new TypeError("maxSize must be a positive integer if specified");if(!y(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");this.#B();}if(this.allowStale=!!r,this.noDeleteOnStaleGet=!!S,this.updateAgeOnGet=!!n,this.updateAgeOnHas=!!o,this.ttlResolution=y(s)||s===0?s:1,this.ttlAutopurge=!!h,this.ttl=i||0,this.ttl){if(!y(this.ttl))throw new TypeError("ttl must be a positive integer if specified");this.#j();}if(this.#o===0&&this.ttl===0&&this.#c===0)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!this.#o&&!this.#c){let E="LRU_CACHE_UNBOUNDED";G(E)&&(I.add(E),x("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",E,a));}}getRemainingTTL(t){return this.#s.has(t)?1/0:0}#j(){let t=new z(this.#o),e=new z(this.#o);this.#d=t,this.#A=e;let i=this.ttlAutopurge?new Array(this.#o):void 0;this.#g=i,this.#N=(n,o,r=this.#m.now())=>{if(e[n]=o!==0?r:0,t[n]=o,i?.[n]&&(clearTimeout(i[n]),i[n]=void 0),o!==0&&i){let f=setTimeout(()=>{this.#p(n)&&this.#E(this.#i[n],"expire");},o+1);f.unref&&f.unref(),i[n]=f;}},this.#R=n=>{e[n]=t[n]!==0?this.#m.now():0;},this.#z=(n,o)=>{if(t[o]){let r=t[o],f=e[o];if(!r||!f)return;n.ttl=r,n.start=f,n.now=s||h();let m=n.now-f;n.remainingTTL=r-m;}};let s=0,h=()=>{let n=this.#m.now();if(this.ttlResolution>0){s=n;let o=setTimeout(()=>s=0,this.ttlResolution);o.unref&&o.unref();}return n};this.getRemainingTTL=n=>{let o=this.#s.get(n);if(o===void 0)return 0;let r=t[o],f=e[o];if(!r||!f)return 1/0;let m=(s||h())-f;return r-m},this.#p=n=>{let o=e[n],r=t[n];return !!r&&!!o&&(s||h())-o>r};}#R=()=>{};#z=()=>{};#N=()=>{};#p=()=>false;#B(){let t=new z(this.#o);this.#_=0,this.#y=t,this.#W=e=>{this.#_-=t[e],t[e]=0;},this.#P=(e,i,s,h)=>{if(this.#e(i))return 0;if(!y(s))if(h){if(typeof h!="function")throw new TypeError("sizeCalculation must be a function");if(s=h(i,e),!y(s))throw new TypeError("sizeCalculation return invalid (expect positive integer)")}else throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");return s},this.#U=(e,i,s)=>{if(t[e]=i,this.#c){let h=this.#c-t[e];for(;this.#_>h;)this.#M(true);}this.#_+=t[e],s&&(s.entrySize=i,s.totalCalculatedSize=this.#_);};}#W=t=>{};#U=(t,e,i)=>{};#P=(t,e,i,s)=>{if(i||s)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0};*#F({allowStale:t=this.allowStale}={}){if(this.#n)for(let e=this.#h;!(!this.#H(e)||((t||!this.#p(e))&&(yield e),e===this.#l));)e=this.#u[e];}*#O({allowStale:t=this.allowStale}={}){if(this.#n)for(let e=this.#l;!(!this.#H(e)||((t||!this.#p(e))&&(yield e),e===this.#h));)e=this.#a[e];}#H(t){return t!==void 0&&this.#s.get(this.#i[t])===t}*entries(){for(let t of this.#F())this.#t[t]!==void 0&&this.#i[t]!==void 0&&!this.#e(this.#t[t])&&(yield [this.#i[t],this.#t[t]]);}*rentries(){for(let t of this.#O())this.#t[t]!==void 0&&this.#i[t]!==void 0&&!this.#e(this.#t[t])&&(yield [this.#i[t],this.#t[t]]);}*keys(){for(let t of this.#F()){let e=this.#i[t];e!==void 0&&!this.#e(this.#t[t])&&(yield e);}}*rkeys(){for(let t of this.#O()){let e=this.#i[t];e!==void 0&&!this.#e(this.#t[t])&&(yield e);}}*values(){for(let t of this.#F())this.#t[t]!==void 0&&!this.#e(this.#t[t])&&(yield this.#t[t]);}*rvalues(){for(let t of this.#O())this.#t[t]!==void 0&&!this.#e(this.#t[t])&&(yield this.#t[t]);}[Symbol.iterator](){return this.entries()}[Symbol.toStringTag]="LRUCache";find(t,e={}){for(let i of this.#F()){let s=this.#t[i],h=this.#e(s)?s.__staleWhileFetching:s;if(h!==void 0&&t(h,this.#i[i],this))return this.get(this.#i[i],e)}}forEach(t,e=this){for(let i of this.#F()){let s=this.#t[i],h=this.#e(s)?s.__staleWhileFetching:s;h!==void 0&&t.call(e,h,this.#i[i],this);}}rforEach(t,e=this){for(let i of this.#O()){let s=this.#t[i],h=this.#e(s)?s.__staleWhileFetching:s;h!==void 0&&t.call(e,h,this.#i[i],this);}}purgeStale(){let t=false;for(let e of this.#O({allowStale:true}))this.#p(e)&&(this.#E(this.#i[e],"expire"),t=true);return t}info(t){let e=this.#s.get(t);if(e===void 0)return;let i=this.#t[e],s=this.#e(i)?i.__staleWhileFetching:i;if(s===void 0)return;let h={value:s};if(this.#d&&this.#A){let n=this.#d[e],o=this.#A[e];if(n&&o){let r=n-(this.#m.now()-o);h.ttl=r,h.start=Date.now();}}return this.#y&&(h.size=this.#y[e]),h}dump(){let t=[];for(let e of this.#F({allowStale:true})){let i=this.#i[e],s=this.#t[e],h=this.#e(s)?s.__staleWhileFetching:s;if(h===void 0||i===void 0)continue;let n={value:h};if(this.#d&&this.#A){n.ttl=this.#d[e];let o=this.#m.now()-this.#A[e];n.start=Math.floor(Date.now()-o);}this.#y&&(n.size=this.#y[e]),t.unshift([i,n]);}return t}load(t){this.clear();for(let[e,i]of t){if(i.start){let s=Date.now()-i.start;i.start=this.#m.now()-s;}this.set(e,i.value,i);}}set(t,e,i={}){if(e===void 0)return this.delete(t),this;let{ttl:s=this.ttl,start:h,noDisposeOnSet:n=this.noDisposeOnSet,sizeCalculation:o=this.sizeCalculation,status:r}=i,{noUpdateTTL:f=this.noUpdateTTL}=i,m=this.#P(t,e,i.size||0,o);if(this.maxEntrySize&&m>this.maxEntrySize)return r&&(r.set="miss",r.maxEntrySizeExceeded=true),this.#E(t,"set"),this;let c=this.#n===0?void 0:this.#s.get(t);if(c===void 0)c=this.#n===0?this.#h:this.#b.length!==0?this.#b.pop():this.#n===this.#o?this.#M(false):this.#n,this.#i[c]=t,this.#t[c]=e,this.#s.set(t,c),this.#a[this.#h]=c,this.#u[c]=this.#h,this.#h=c,this.#n++,this.#U(c,m,r),r&&(r.set="add"),f=false,this.#x&&this.#C?.(e,t,"add");else {this.#D(c);let d=this.#t[c];if(e!==d){if(this.#v&&this.#e(d)){d.__abortController.abort(new Error("replaced"));let{__staleWhileFetching:g}=d;g!==void 0&&!n&&(this.#T&&this.#w?.(g,t,"set"),this.#f&&this.#r?.push([g,t,"set"]));}else n||(this.#T&&this.#w?.(d,t,"set"),this.#f&&this.#r?.push([d,t,"set"]));if(this.#W(c),this.#U(c,m,r),this.#t[c]=e,r){r.set="replace";let g=d&&this.#e(d)?d.__staleWhileFetching:d;g!==void 0&&(r.oldValue=g);}}else r&&(r.set="update");this.#x&&this.onInsert?.(e,t,e===d?"update":"replace");}if(s!==0&&!this.#d&&this.#j(),this.#d&&(f||this.#N(c,s,h),r&&this.#z(r,c)),!n&&this.#f&&this.#r){let d=this.#r,g;for(;g=d?.shift();)this.#S?.(...g);}return this}pop(){try{for(;this.#n;){let t=this.#t[this.#l];if(this.#M(!0),this.#e(t)){if(t.__staleWhileFetching)return t.__staleWhileFetching}else if(t!==void 0)return t}}finally{if(this.#f&&this.#r){let t=this.#r,e;for(;e=t?.shift();)this.#S?.(...e);}}}#M(t){let e=this.#l,i=this.#i[e],s=this.#t[e];return this.#v&&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.#W(e),this.#g?.[e]&&(clearTimeout(this.#g[e]),this.#g[e]=void 0),t&&(this.#i[e]=void 0,this.#t[e]=void 0,this.#b.push(e)),this.#n===1?(this.#l=this.#h=0,this.#b.length=0):this.#l=this.#a[e],this.#s.delete(i),this.#n--,e}has(t,e={}){let{updateAgeOnHas:i=this.updateAgeOnHas,status:s}=e,h=this.#s.get(t);if(h!==void 0){let n=this.#t[h];if(this.#e(n)&&n.__staleWhileFetching===void 0)return false;if(this.#p(h))s&&(s.has="stale",this.#z(s,h));else return i&&this.#R(h),s&&(s.has="hit",this.#z(s,h)),true}else s&&(s.has="miss");return false}peek(t,e={}){let{allowStale:i=this.allowStale}=e,s=this.#s.get(t);if(s===void 0||!i&&this.#p(s))return;let h=this.#t[s];return this.#e(h)?h.__staleWhileFetching:h}#G(t,e,i,s){let h=e===void 0?void 0:this.#t[e];if(this.#e(h))return h;let n=new C,{signal:o}=i;o?.addEventListener("abort",()=>n.abort(o.reason),{signal:n.signal});let r={signal:n.signal,options:i,context:s},f=(p,_=false)=>{let{aborted:l}=n.signal,w=i.ignoreFetchAbort&&p!==void 0,b=i.ignoreFetchAbort||!!(i.allowStaleOnFetchAbort&&p!==void 0);if(i.status&&(l&&!_?(i.status.fetchAborted=true,i.status.fetchError=n.signal.reason,w&&(i.status.fetchAbortIgnored=true)):i.status.fetchResolved=true),l&&!w&&!_)return c(n.signal.reason,b);let S=g,u=this.#t[e];return (u===g||w&&_&&u===void 0)&&(p===void 0?S.__staleWhileFetching!==void 0?this.#t[e]=S.__staleWhileFetching:this.#E(t,"fetch"):(i.status&&(i.status.fetchUpdated=true),this.set(t,p,r.options))),p},m=p=>(i.status&&(i.status.fetchRejected=true,i.status.fetchError=p),c(p,false)),c=(p,_)=>{let{aborted:l}=n.signal,w=l&&i.allowStaleOnFetchAbort,b=w||i.allowStaleOnFetchRejection,S=b||i.noDeleteOnFetchRejection,u=g;if(this.#t[e]===g&&(!S||!_&&u.__staleWhileFetching===void 0?this.#E(t,"fetch"):w||(this.#t[e]=u.__staleWhileFetching)),b)return i.status&&u.__staleWhileFetching!==void 0&&(i.status.returnedStale=true),u.__staleWhileFetching;if(u.__returned===u)throw p},d=(p,_)=>{let l=this.#L?.(t,h,r);l&&l instanceof Promise&&l.then(w=>p(w===void 0?void 0:w),_),n.signal.addEventListener("abort",()=>{(!i.ignoreFetchAbort||i.allowStaleOnFetchAbort)&&(p(void 0),i.allowStaleOnFetchAbort&&(p=w=>f(w,true)));});};i.status&&(i.status.fetchDispatched=true);let g=new Promise(d).then(f,m),A=Object.assign(g,{__abortController:n,__staleWhileFetching:h,__returned:void 0});return e===void 0?(this.set(t,A,{...r.options,status:void 0}),e=this.#s.get(t)):this.#t[e]=A,A}#e(t){if(!this.#v)return false;let e=t;return !!e&&e instanceof Promise&&e.hasOwnProperty("__staleWhileFetching")&&e.__abortController instanceof C}async fetch(t,e={}){let{allowStale:i=this.allowStale,updateAgeOnGet:s=this.updateAgeOnGet,noDeleteOnStaleGet:h=this.noDeleteOnStaleGet,ttl:n=this.ttl,noDisposeOnSet:o=this.noDisposeOnSet,size:r=0,sizeCalculation:f=this.sizeCalculation,noUpdateTTL:m=this.noUpdateTTL,noDeleteOnFetchRejection:c=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:d=this.allowStaleOnFetchRejection,ignoreFetchAbort:g=this.ignoreFetchAbort,allowStaleOnFetchAbort:A=this.allowStaleOnFetchAbort,context:p,forceRefresh:_=false,status:l,signal:w}=e;if(!this.#v)return l&&(l.fetch="get"),this.get(t,{allowStale:i,updateAgeOnGet:s,noDeleteOnStaleGet:h,status:l});let b={allowStale:i,updateAgeOnGet:s,noDeleteOnStaleGet:h,ttl:n,noDisposeOnSet:o,size:r,sizeCalculation:f,noUpdateTTL:m,noDeleteOnFetchRejection:c,allowStaleOnFetchRejection:d,allowStaleOnFetchAbort:A,ignoreFetchAbort:g,status:l,signal:w},S=this.#s.get(t);if(S===void 0){l&&(l.fetch="miss");let u=this.#G(t,S,b,p);return u.__returned=u}else {let u=this.#t[S];if(this.#e(u)){let E=i&&u.__staleWhileFetching!==void 0;return l&&(l.fetch="inflight",E&&(l.returnedStale=true)),E?u.__staleWhileFetching:u.__returned=u}let T=this.#p(S);if(!_&&!T)return l&&(l.fetch="hit"),this.#D(S),s&&this.#R(S),l&&this.#z(l,S),u;let F=this.#G(t,S,b,p),O=F.__staleWhileFetching!==void 0&&i;return l&&(l.fetch=T?"stale":"refresh",O&&T&&(l.returnedStale=true)),O?F.__staleWhileFetching:F.__returned=F}}async forceFetch(t,e={}){let i=await this.fetch(t,e);if(i===void 0)throw new Error("fetch() returned undefined");return i}memo(t,e={}){let i=this.#I;if(!i)throw new Error("no memoMethod provided to constructor");let{context:s,forceRefresh:h,...n}=e,o=this.get(t,n);if(!h&&o!==void 0)return o;let r=i(t,o,{options:n,context:s});return this.set(t,r,n),r}get(t,e={}){let{allowStale:i=this.allowStale,updateAgeOnGet:s=this.updateAgeOnGet,noDeleteOnStaleGet:h=this.noDeleteOnStaleGet,status:n}=e,o=this.#s.get(t);if(o!==void 0){let r=this.#t[o],f=this.#e(r);return n&&this.#z(n,o),this.#p(o)?(n&&(n.get="stale"),f?(n&&i&&r.__staleWhileFetching!==void 0&&(n.returnedStale=true),i?r.__staleWhileFetching:void 0):(h||this.#E(t,"expire"),n&&i&&(n.returnedStale=true),i?r:void 0)):(n&&(n.get="hit"),f?r.__staleWhileFetching:(this.#D(o),s&&this.#R(o),r))}else n&&(n.get="miss");}#k(t,e){this.#u[e]=t,this.#a[t]=e;}#D(t){t!==this.#h&&(t===this.#l?this.#l=this.#a[t]:this.#k(this.#u[t],this.#a[t]),this.#k(this.#h,t),this.#h=t);}delete(t){return this.#E(t,"delete")}#E(t,e){let i=false;if(this.#n!==0){let s=this.#s.get(t);if(s!==void 0)if(this.#g?.[s]&&(clearTimeout(this.#g?.[s]),this.#g[s]=void 0),i=true,this.#n===1)this.#V(e);else {this.#W(s);let h=this.#t[s];if(this.#e(h)?h.__abortController.abort(new Error("deleted")):(this.#T||this.#f)&&(this.#T&&this.#w?.(h,t,e),this.#f&&this.#r?.push([h,t,e])),this.#s.delete(t),this.#i[s]=void 0,this.#t[s]=void 0,s===this.#h)this.#h=this.#u[s];else if(s===this.#l)this.#l=this.#a[s];else {let n=this.#u[s];this.#a[n]=this.#a[s];let o=this.#a[s];this.#u[o]=this.#u[s];}this.#n--,this.#b.push(s);}}if(this.#f&&this.#r?.length){let s=this.#r,h;for(;h=s?.shift();)this.#S?.(...h);}return i}clear(){return this.#V("delete")}#V(t){for(let e of this.#O({allowStale:true})){let i=this.#t[e];if(this.#e(i))i.__abortController.abort(new Error("deleted"));else {let s=this.#i[e];this.#T&&this.#w?.(i,s,t),this.#f&&this.#r?.push([i,s,t]);}}if(this.#s.clear(),this.#t.fill(void 0),this.#i.fill(void 0),this.#d&&this.#A){this.#d.fill(0),this.#A.fill(0);for(let e of this.#g??[])e!==void 0&&clearTimeout(e);this.#g?.fill(void 0);}if(this.#y&&this.#y.fill(0),this.#l=0,this.#h=0,this.#b.length=0,this.#_=0,this.#n=0,this.#f&&this.#r){let e=this.#r,i;for(;i=e?.shift();)this.#S?.(...i);}}};
25640
24113
 
25641
24114
  // ../../node_modules/.pnpm/fast-deep-equal@3.1.3/node_modules/fast-deep-equal/index.js
25642
24115
  var require_fast_deep_equal = __commonJS$4({
@@ -26009,6 +24482,7 @@ var coreToolSchema = z10.z.object({
26009
24482
  ]),
26010
24483
  outputSchema: z10.z.union([z10.z.record(z10.z.string(), z10.z.any()), z10.z.any()]).optional(),
26011
24484
  execute: z10.z.optional(z10.z.function(z10.z.tuple([z10.z.any(), z10.z.any()]), z10.z.promise(z10.z.any()))),
24485
+ toModelOutput: z10.z.optional(z10.z.function(z10.z.tuple([z10.z.any()]), z10.z.any())),
26012
24486
  type: z10.z.union([z10.z.literal("function"), z10.z.literal("provider-defined"), z10.z.undefined()]).optional(),
26013
24487
  args: z10.z.record(z10.z.string(), z10.z.any()).optional()
26014
24488
  });
@@ -26038,7 +24512,7 @@ z10.z.object({
26038
24512
  }).optional()
26039
24513
  });
26040
24514
  var DEFAULT_CACHE_MAX_SIZE = 1e3;
26041
- new LRUCache({
24515
+ new L({
26042
24516
  max: DEFAULT_CACHE_MAX_SIZE
26043
24517
  });
26044
24518
 
@@ -27786,4 +26260,4 @@ exports.useCreateWorkflowRun = useCreateWorkflowRun;
27786
26260
  exports.useEntity = useEntity;
27787
26261
  exports.useMastraClient = useMastraClient;
27788
26262
  exports.useStreamWorkflow = useStreamWorkflow;
27789
- //# sourceMappingURL=index-DT_KGByV.cjs.map
26263
+ //# sourceMappingURL=index-VHXhgr5V.cjs.map