@boredland/node-ts-cache 1.0.1 → 2.0.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.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @boredland/node-ts-cache
2
2
 
3
- Simple and extensible caching module supporting multiple caching strategies.
3
+ Simple and extensible caching module with Stale-While-Revalidate (SWR) strategy support.
4
4
 
5
5
  [![CI](https://github.com/boredland/node-ts-cache/actions/workflows/ci.yml/badge.svg)](https://github.com/boredland/node-ts-cache/actions/workflows/ci.yml)
6
6
  [![The MIT License](https://img.shields.io/npm/l/node-ts-cache.svg)](http://opensource.org/licenses/MIT)
@@ -15,7 +15,7 @@ npm i @boredland/node-ts-cache
15
15
 
16
16
  ### Wrap your function calls with `withCacheFactory`
17
17
 
18
- Function wrapper factory for arbitrary functions. The cache key is calculated based on the parameters passed to the function.
18
+ Function wrapper factory for arbitrary async functions. The cache key is calculated based on the parameters passed to the function.
19
19
 
20
20
  ```ts
21
21
  import {
@@ -24,73 +24,93 @@ import {
24
24
  LRUStorage,
25
25
  } from "@boredland/node-ts-cache";
26
26
 
27
- const doThingsCache = new CacheContainer(new LRUStorage());
27
+ const cache = new CacheContainer(new LRUStorage());
28
28
 
29
29
  const someFn = (input: { a: string; b: number }) => Promise.resolve("result");
30
30
 
31
- const wrappedFn = withCacheFactory(doThingsCache)(someFn, {
31
+ const wrappedFn = withCacheFactory(cache)(someFn, {
32
32
  prefix: "my-function",
33
- strategy: "eager", // or "lazy" or "swr"
33
+ cacheTimeMs: 60000,
34
+ staleTimeMs: 120000,
34
35
  });
35
36
 
36
- const result = await wrappedFn({ a: "lala", b: 123 });
37
+ const result = await wrappedFn({ a: "hello", b: 123 });
37
38
  ```
38
39
 
39
- ### Caching Strategies
40
+ ### Caching Strategy: Stale-While-Revalidate (SWR)
40
41
 
41
- The `withCache` wrapper supports three different caching strategies:
42
+ The `withCache` wrapper implements the Stale-While-Revalidate (SWR) caching strategy:
42
43
 
43
- #### Eager (Default)
44
+ - **Fresh content** (within `cacheTimeMs`): returned immediately without revalidation
45
+ - **Stale content** (within `staleTimeMs` after expiration): returned immediately while revalidating in the background
46
+ - **Expired content** (beyond `staleTimeMs`): waits for fresh revalidation
47
+ - **No caching** (when `cacheTimeMs=0` and `staleTimeMs=0`): function executes every time
48
+
49
+ This strategy is ideal for scenarios where:
50
+
51
+ - You want fast response times even with slightly outdated data
52
+ - Background revalidation is acceptable
53
+ - You want to minimize the number of cache misses
54
+
55
+ ### Options
44
56
 
45
57
  ```ts
46
58
  const wrappedFn = withCacheFactory(cacheContainer)(someFn, {
47
- strategy: "eager",
59
+ // Cache key prefix for namespacing
60
+ prefix?: string;
61
+
62
+ // Time in milliseconds after which cached content is considered "expired"
63
+ // During this period, cached content is returned immediately without revalidation
64
+ // Default: 0 (no caching)
65
+ cacheTimeMs?: number;
66
+
67
+ // Time in milliseconds after which cached content is considered "stale"
68
+ // Used for Stale-While-Revalidate: stale content is returned immediately while revalidation happens in the background
69
+ // Must be greater than cacheTimeMs to be effective
70
+ // Default: 0 (no stale caching)
71
+ staleTimeMs?: number;
72
+
73
+ // Custom cache key calculation function
74
+ // Default: hash-based on parameters
75
+ calculateKey?: (params: Parameters) => string;
76
+
77
+ // Conditional caching predicate
78
+ // Return true to cache the result, false to skip caching
79
+ shouldStore?: (result: Awaited<Result>) => boolean;
80
+
81
+ // Concurrency limit for background revalidation tasks
82
+ // Default: 1
83
+ revalidationConcurrency?: number;
48
84
  });
49
85
  ```
50
86
 
51
- - Cache is populated before returning the result
52
- - Expired items are removed and the function is called again
87
+ ### Example: Different Cache Configurations
53
88
 
54
- #### Lazy
89
+ #### No Caching (Pass-through)
55
90
 
56
91
  ```ts
57
- const wrappedFn = withCacheFactory(cacheContainer)(someFn, {
58
- strategy: "lazy",
92
+ const wrappedFn = withCacheFactory(cache)(someFn, {
93
+ cacheTimeMs: 0,
94
+ staleTimeMs: 0,
59
95
  });
60
96
  ```
61
97
 
62
- - Cache is populated in the background after returning the result
63
- - Expired items are invalidated on touch (when accessed)
64
-
65
- #### Stale-While-Revalidate (SWR)
98
+ #### Fresh-only Caching (60 seconds)
66
99
 
67
100
  ```ts
68
- const wrappedFn = withCacheFactory(cacheContainer)(someFn, {
69
- strategy: "swr",
101
+ const wrappedFn = withCacheFactory(cache)(someFn, {
102
+ cacheTimeMs: 60000,
103
+ staleTimeMs: 0,
70
104
  });
71
105
  ```
72
106
 
73
- - Returns expired cache immediately while revalidating in the background
74
- - Revalidation is queued with configurable concurrency
75
- - Perfect for scenarios where stale data is acceptable
76
- - Only one concurrent revalidation is enqueued per cache-key
77
-
78
- ### Advanced Options
107
+ #### Stale-While-Revalidate (Fresh for 60s, stale for 120s)
79
108
 
80
109
  ```ts
81
- const wrappedFn = withCacheFactory(cacheContainer)(someFn, {
82
- prefix: "my-function", // Cache key prefix
83
- strategy: "swr", // Caching strategy
84
- ttl: 60000, // Time-to-live in milliseconds (null = forever)
85
- revalidationConcurrency: 5, // Max concurrent background revalidations (default: 1)
86
- calculateKey: (params) => {
87
- // Custom key calculation
88
- return `${params[0]}-${params[1]}`;
89
- },
90
- shouldStore: (result) => {
91
- // Conditional caching
92
- return result && result.success;
93
- },
110
+ const wrappedFn = withCacheFactory(cache)(someFn, {
111
+ cacheTimeMs: 60000,
112
+ staleTimeMs: 120000,
113
+ revalidationConcurrency: 5,
94
114
  });
95
115
  ```
96
116
 
@@ -105,29 +125,32 @@ class MyService {
105
125
  public async getUsers(): Promise<string[]> {
106
126
  const cachedUsers = await myCache.getItem<string[]>("users");
107
127
 
108
- if (cachedUsers) {
128
+ if (cachedUsers?.content) {
109
129
  return cachedUsers.content;
110
130
  }
111
131
 
112
- const newUsers = ["Max", "User"];
132
+ const newUsers = ["Alice", "Bob"];
113
133
 
114
- await myCache.setItem("users", newUsers, { ttl: 60000 });
134
+ await myCache.setItem("users", newUsers, {
135
+ ttl: 60000, // Content expires after 60 seconds
136
+ staleTtl: 120000, // Content is stale after 120 seconds
137
+ });
115
138
 
116
139
  return newUsers;
117
140
  }
118
141
  }
119
142
  ```
120
143
 
144
+ ## Storage Adapters
145
+
121
146
  ### LRUStorage
122
147
 
123
- The `LRUStorage` adapter uses an in-memory LRU (Least Recently Used) cache with configurable capacity:
148
+ In-memory LRU (Least Recently Used) cache with automatic eviction:
124
149
 
125
150
  ```ts
126
151
  import { LRUStorage } from "@boredland/node-ts-cache";
127
152
 
128
- // Create an LRU cache with max 10,000 items
129
153
  const storage = new LRUStorage({ max: 10000 });
130
-
131
154
  const container = new CacheContainer(storage);
132
155
  ```
133
156
 
@@ -138,6 +161,33 @@ const container = new CacheContainer(storage);
138
161
  - Configurable maximum size
139
162
  - Perfect for testing and single-process applications
140
163
 
164
+ ### FallbackStorage
165
+
166
+ Cascading storage that tries multiple storages in order:
167
+
168
+ ```ts
169
+ import {
170
+ FallbackStorage,
171
+ LRUStorage,
172
+ RedisStorage,
173
+ } from "@boredland/node-ts-cache";
174
+
175
+ // Try Redis first, fall back to LRU if Redis is unavailable
176
+ const storage = new FallbackStorage([
177
+ new RedisStorage(),
178
+ new LRUStorage({ max: 5000 }),
179
+ ]);
180
+
181
+ const container = new CacheContainer(storage);
182
+ ```
183
+
184
+ **Behavior:**
185
+
186
+ - On `getItem`: tries each storage in order until finding a hit
187
+ - If found in a lower-priority storage: writes it back to all higher-priority storages
188
+ - On `setItem`: always writes to the primary storage, attempts to write to others in the background
189
+ - Ensures data consistency across multiple storage layers
190
+
141
191
  ## Logging
142
192
 
143
193
  This project uses `debug` to log useful information.
@@ -149,14 +199,6 @@ Set environment variable **DEBUG=node-ts-cache** to enable logging.
149
199
  npm test
150
200
  ```
151
201
 
152
- ### Example Test Usage
153
-
154
- For a complete example of how to test with `LRUStorage`, see the [comprehensive test suite](./src/lruStorage.test.ts):
155
-
156
- ## LICENSE
157
-
158
- Distributed under the MIT License. See LICENSE.md for more information.
159
-
160
202
  ## Development & Testing
161
203
 
162
204
  ### Setup
@@ -175,6 +217,10 @@ npm run lint
175
217
  - `npm run lint` - Run TypeScript and Biome linting
176
218
  - `npm run build` - Build the project
177
219
 
220
+ ## LICENSE
221
+
222
+ Distributed under the MIT License. See LICENSE.md for more information.
223
+
178
224
  ## Credits
179
225
 
180
226
  As this is a fork of the original [node-ts-cache](https://github.com/havsar/node-ts-cache), all credit goes to the upstream project by [havsar](https://github.com/havsar).
package/dist/index.d.mts CHANGED
@@ -30,14 +30,14 @@ type CachedItem<T = unknown> = {
30
30
  meta: {
31
31
  createdAt: number;
32
32
  ttl: number | null;
33
- isLazy: boolean;
33
+ staleTtl?: number | null;
34
34
  };
35
35
  };
36
36
  type CachingOptions = {
37
- /** Number of milliseconds to expire the cachte item - defaults to forever */
37
+ /** Number of milliseconds to expire the cached item - defaults to forever */
38
38
  ttl: number | null;
39
- /** (Default: true) If true, expired cache entries will be deleted on touch and returned anyway. If false, entries will be deleted after the given ttl. */
40
- isLazy: boolean;
39
+ /** Number of milliseconds to mark the cached item stale - defaults to the ttl */
40
+ staleTtl: number | null;
41
41
  /** (Default: JSON.stringify combination of className, methodName and call args) */
42
42
  calculateKey: (data: {
43
43
  /** The class name for the method being decorated */
@@ -55,12 +55,14 @@ declare class CacheContainer {
55
55
  content: T;
56
56
  meta: {
57
57
  expired: boolean;
58
+ stale: boolean;
58
59
  createdAt: number;
59
60
  };
60
61
  } | undefined>;
61
62
  setItem(key: string, content: unknown, options?: Partial<CachingOptions>): Promise<void>;
62
63
  clear(): Promise<void>;
63
64
  private isItemExpired;
65
+ private isStaleItem;
64
66
  unsetKey(key: string): Promise<void>;
65
67
  }
66
68
  //#endregion
@@ -76,34 +78,70 @@ declare class LRUStorage implements Storage {
76
78
  removeItem(key: string): Promise<void>;
77
79
  }
78
80
  //#endregion
81
+ //#region src/fallbackStorage.d.ts
82
+ /**
83
+ * Fallback Cache Provider that tries multiple storages in order.
84
+ *
85
+ * On getItem, it tries each storage in order until it finds a hit.
86
+ * If a hit is found in a lower-priority storage, it writes it back to all higher-priority storages.
87
+ * **It only guarantees writing to the highest priority storage on setItem.**
88
+ */
89
+ declare class FallbackStorage implements Storage {
90
+ private storages;
91
+ constructor(storages: [Storage, ...Storage[]]);
92
+ clear(): Promise<void>;
93
+ getItem(key: string): Promise<CachedItem | undefined>;
94
+ setItem(key: string, content: CachedItem): Promise<void>;
95
+ removeItem(key: string): Promise<void>;
96
+ }
97
+ //#endregion
79
98
  //#region src/withCache.d.ts
80
- type WithCacheOptions<Parameters, Result> = Partial<Omit<CachingOptions, "calculateKey" | "isLazy">> & {
81
- /** an optional prefix to prepend to the key */
99
+ type WithCacheOptions<Parameters, Result> = {
100
+ /** An optional prefix to prepend to the cache key for namespacing purposes */
82
101
  prefix?: string;
83
- /** an optional function to calculate a key based on the parameters of the wrapped function */
102
+ /** An optional function to calculate a cache key based on the function parameters. Defaults to hashing the parameters */
84
103
  calculateKey?: (input: Parameters) => string;
85
- /** an optional function that is called just before the result is stored to the storage */
104
+ /** An optional predicate function to determine whether a result should be cached. Useful for filtering out error responses or invalid data */
86
105
  shouldStore?: (result: Awaited<Result>) => boolean;
87
106
  /**
88
- * caching strategy to use
89
- * - "lazy": cache is populated in the background after returning the result
90
- * - "swr": stale-while-revalidate, cache is returned if present and updated in the background
91
- * - "eager": cache is populated before returning the result
92
- * @default "eager"
93
- */
94
- strategy?: "lazy" | "swr" | "eager";
95
- /**
96
- * Concurrency for revalidation queue
107
+ * Concurrency limit for background revalidation tasks in the queue
97
108
  * @default 1
98
109
  */
99
110
  revalidationConcurrency?: number;
111
+ /**
112
+ * Time in milliseconds after which cached content is considered "expired" and no longer fresh.
113
+ * During this period, cached content is returned immediately without revalidation.
114
+ * When set to 0 along with staleTimeMs=0, caching is disabled entirely.
115
+ * @default 0 (no caching)
116
+ */
117
+ cacheTimeMs?: number;
118
+ /**
119
+ * Time in milliseconds after which cached content is considered "stale".
120
+ * Used for Stale-While-Revalidate: stale content is returned immediately while revalidation happens in the background.
121
+ * Must be greater than cacheTimeMs to be effective. When both cacheTimeMs and staleTimeMs are 0, caching is disabled.
122
+ * @default 0 (no stale caching)
123
+ */
124
+ staleTimeMs?: number;
100
125
  };
101
126
  /**
102
- * wrapped function factory
103
- * @param container - cache container to create the fn for
104
- * @returns wrapping function
127
+ * Creates a withCache wrapper function for a specific cache container.
128
+ * Implements Stale-While-Revalidate (SWR) caching strategy:
129
+ * - Fresh content (within cacheTimeMs): returned immediately without revalidation
130
+ * - Stale content (within staleTimeMs after expiration): returned immediately while revalidating in background
131
+ * - Expired content (beyond staleTimeMs): waits for fresh revalidation
132
+ * - No caching (when cacheTimeMs=0 and staleTimeMs=0): function executes every time
133
+ *
134
+ * @param container - The cache container instance to store and retrieve cached values
135
+ * @returns A withCache function bound to the provided container
105
136
  */
106
- declare const withCacheFactory: (container: CacheContainer) => <Parameters extends Array<unknown>, Result extends Promise<unknown>>(operation: (...parameters: Parameters) => Result, options?: WithCacheOptions<Parameters, Result>) => (...parameters: Parameters) => Promise<Result>;
137
+ declare const withCacheFactory: (container: CacheContainer) => <Parameters extends Array<unknown>, Result extends Promise<unknown>>(operation: (...parameters: Parameters) => Result, {
138
+ cacheTimeMs,
139
+ staleTimeMs,
140
+ calculateKey,
141
+ revalidationConcurrency: concurrency,
142
+ prefix,
143
+ shouldStore
144
+ }?: WithCacheOptions<Parameters, Result>) => (...parameters: Parameters) => Promise<Result>;
107
145
  //#endregion
108
- export { CacheContainer, CachedItem, CachingOptions, LRUStorage, Storage, withCacheFactory };
146
+ export { CacheContainer, CachedItem, CachingOptions, FallbackStorage, LRUStorage, Storage, withCacheFactory };
109
147
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/storage.ts","../src/cacheContainer.ts","../src/lruStorage.ts","../src/withCache.ts"],"sourcesContent":[],"mappings":";;;UAEiB,OAAA;;AAAjB;;;EAY+B,OAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAPR,OAOQ,CAPA,UAOA,GAAA,SAAA,CAAA;EAAa;;;;;gCAAb,aAAa;;ACX5C;AASA;AAgBA;EAC8B,UAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EDTJ,OCSI,CAAA,IAAA,CAAA;EAKjB;;;EAwBD,KAAA,EAAA,EDjCF,OCiCE,CAAA,IAAA,CAAA;;;;KAvDA;WACF;EDFO,IAAA,EAAA;IAKc,SAAA,EAAA,MAAA;IAAR,GAAA,EAAA,MAAA,GAAA,IAAA;IAOQ,MAAA,EAAA,OAAA;EAAa,CAAA;CAMlB;AAKhB,KCbE,cAAA,GDaF;EAAO;;;;ECtBL;EASA,YAAA,EAAA,CAAA,IAAc,EAAA;IAgBb;IACiB,SAAA,EAAA,MAAA;IAKjB;IADT,UAAA,EAAA,MAAA;IAyBgB;IAAR,IAAA,EAAA,OAAA,EAAA;EACR,CAAA,EAAA,GAAA,MAAA;CAgBmB;AAWc,cA1DxB,cAAA,CA0DwB;EAAO,QAAA,OAAA;uBAzDd;2BAI1B;aACS;IC9BA,IAAA,EAAA;MAIX,OAAA,EAAA,OAAA;MAC2B,SAAA,EAAA,MAAA;IAAjB,CAAA;EAAR,CAAA,GAAA,SAAA,CAAA;EAMY,OAAA,CAAA,GAAA,EAAA,MAAA,EAAA,OAAA,EAAA,OAAA,EAAA,OAAA,CAAA,ED2CJ,OC3CI,CD2CI,cC3CJ,CAAA,CAAA,ED4CZ,OC5CY,CAAA,IAAA,CAAA;EAIU,KAAA,CAAA,CAAA,EDwDH,OCxDG,CAAA,IAAA,CAAA;EAAA,QAAA,aAAA;EAKW,QAAA,CAAA,GAAA,EAAA,MAAA,CAAA,ED8DA,OC9DA,CAAA,IAAA,CAAA;;;;AFtBpB,cEEJ,UAAA,YAAsB,OFFX,CAAA;EAKO,QAAA,KAAA;EAAR,WAAA,CAAA;IAAA;EAAA,CAAA,CAAA,EEEnB,OFFmB,CEEX,QFFW,CAAA,MAAA,EEEM,UFFN,EAAA,OAAA,CAAA,CAAA;EAOQ,KAAA,CAAA,CAAA,EECf,OFDe,CAAA,IAAA,CAAA;EAAa,OAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EEKlB,OFLkB,CEKlB,UFLkB,GAAA,SAAA,CAAA;EAMlB,OAAA,CAAA,GAAA,EAAA,MAAA,EAAA,OAAA,EEIW,UFJX,CAAA,EEIqB,OFJrB,CAAA,IAAA,CAAA;EAKhB,UAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EEGmB,OFHnB,CAAA,IAAA,CAAA;;;;KGnBL,uCAAuC,QAC1C,KAAK;;EHLU,MAAA,CAAA,EAAA,MAAO;EAKO;EAAR,YAAA,CAAA,EAAA,CAAA,KAAA,EGKE,UHLF,EAAA,GAAA,MAAA;EAOQ;EAAa,WAAA,CAAA,EAAA,CAAA,MAAA,EGAnB,OHAmB,CGAX,MHAW,CAAA,EAAA,GAAA,OAAA;EAMlB;;;;;;ACjB1B;EASY,QAAA,CAAA,EAAA,MAAc,GAAA,KAAA,GAAA,OAAA;EAgBb;;;;EA8BO,uBAAA,CAAA,EAAA,MAAA;CAAR;;;;;;cEvBC,8BAA+B,uCAQrB,+BACJ,6CAEY,eAAe,kBACjC,iBAAiB,YAAY,4BAET,eAAa,QAAQ"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/storage.ts","../src/cacheContainer.ts","../src/lruStorage.ts","../src/fallbackStorage.ts","../src/withCache.ts"],"sourcesContent":[],"mappings":";;;UAEiB,OAAA;;AAAjB;;;EAY+B,OAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAPR,OAOQ,CAPA,UAOA,GAAA,SAAA,CAAA;EAAa;;;;;gCAAb,aAAa;;ACX5C;AASA;AAgBA;EAC8B,UAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EDTJ,OCSI,CAAA,IAAA,CAAA;EAIjB;;;EA6BD,KAAA,EAAA,EDrCF,OCqCE,CAAA,IAAA,CAAA;;;;KA3DA;WACF;EDFO,IAAA,EAAA;IAKc,SAAA,EAAA,MAAA;IAAR,GAAA,EAAA,MAAA,GAAA,IAAA;IAOQ,QAAA,CAAA,EAAA,MAAA,GAAA,IAAA;EAAa,CAAA;CAMlB;AAKhB,KCbE,cAAA,GDaF;EAAO;;;;ECtBL;EASA,YAAA,EAAA,CAAA,IAAc,EAAA;IAgBb;IACiB,SAAA,EAAA,MAAA;IAIjB;IAF0B,UAAA,EAAA,MAAA;IA+BnB;IAAR,IAAA,EAAA,OAAA,EAAA;EACR,CAAA,EAAA,GAAA,MAAA;CAgBmB;AAiBc,cApExB,cAAA,CAoEwB;EAAO,QAAA,OAAA;uBAnEd;2BAES;aAE1B;IC7BA,IAAA,EAAA;MAIX,OAAA,EAAA,OAAA;MAC2B,KAAA,EAAA,OAAA;MAAjB,SAAA,EAAA,MAAA;IAAR,CAAA;EAMY,CAAA,GAAA,SAAA,CAAA;EAIU,OAAA,CAAA,GAAA,EAAA,MAAA,EAAA,OAAA,EAAA,OAAA,EAAA,OAAA,CAAA,ED2Cd,OC3Cc,CD2CN,cC3CM,CAAA,CAAA,ED4CtB,OC5CsB,CAAA,IAAA,CAAA;EAAA,KAAA,CAAA,CAAA,ED4DH,OC5DG,CAAA,IAAA,CAAA;EAKW,QAAA,aAAA;EAAU,QAAA,WAAA;EAIlB,QAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EDoEQ,OCpER,CAAA,IAAA,CAAA;;;;AF1BZ,cEEJ,UAAA,YAAsB,OFFX,CAAA;EAKO,QAAA,KAAA;EAAR,WAAA,CAAA;IAAA;EAAA,CAAA,CAAA,EEEnB,OFFmB,CEEX,QFFW,CAAA,MAAA,EEEM,UFFN,EAAA,OAAA,CAAA,CAAA;EAOQ,KAAA,CAAA,CAAA,EECf,OFDe,CAAA,IAAA,CAAA;EAAa,OAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EEKlB,OFLkB,CEKlB,UFLkB,GAAA,SAAA,CAAA;EAMlB,OAAA,CAAA,GAAA,EAAA,MAAA,EAAA,OAAA,EEIW,UFJX,CAAA,EEIqB,OFJrB,CAAA,IAAA,CAAA;EAKhB,UAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EEGmB,OFHnB,CAAA,IAAA,CAAA;;;;;AAvBV;;;;;;AAuBU,cGfG,eAAA,YAA2B,OHe9B,CAAA;EAAO,QAAA,QAAA;yBGZO,YAAY;WAIpB;wBAIa,QAAQ;EFlBzB,OAAA,CAAA,GAAA,EAAU,MAAA,EAAA,OACX,EEoC0B,UFpC1B,CAAA,EEoCuC,OFpCvC,CAAA,IAAA,CAAA;EAQC,UAAA,CAAA,GAAA,EAAA,MAAc,CAAA,EEoCM,OFpCN,CAAA,IAAA,CAAA;AAgB1B;;;KGtBK;;EJJY,MAAA,CAAA,EAAA,MAAO;EAKO;EAAR,YAAA,CAAA,EAAA,CAAA,KAAA,EIGC,UJHD,EAAA,GAAA,MAAA;EAOQ;EAAa,WAAA,CAAA,EAAA,CAAA,MAAA,EIFpB,OJEoB,CIFZ,MJEY,CAAA,EAAA,GAAA,OAAA;EAMlB;;;;;;ACjB1B;AASA;AAgBA;;;EAGuC,WAAA,CAAA,EAAA,MAAA;EA+BnB;;;;;;;;;AC1DpB;;;;;;;;;;AAwB6B,cEiBhB,gBFjBgB,EAAA,CAAA,SAAA,EEiBe,cFjBf,EAAA,GAAA,CAAA,mBE2BR,KF3BQ,CAAA,OAAA,CAAA,EAAA,eE4BZ,OF5BY,CAAA,OAAA,CAAA,CAAA,CAAA,SAAA,EAAA,CAAA,GAAA,UAAA,EE8BA,UF9BA,EAAA,GE8Be,MF9Bf,EAAA;EAAA,WAAA;EAAA,WAAA;EAAA,YAAA;EAAA,uBAAA,EE8BqB,WF9BrB;EAAA,MAAA;EAAA;AAAA,CAAA,CAAA,EEsCxB,gBFtCwB,CEsCP,UFtCO,EEsCK,MFtCL,CAAA,EAAA,GAAA,CAAA,GAAA,UAAA,EEwCE,UFxCF,EAAA,GEwCe,OFxCf,CEwCuB,MFxCvB,CAAA"}
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import{createRequire as e}from"node:module";import{debug as t}from"node:util";var n=Object.create,r=Object.defineProperty,i=Object.getOwnPropertyDescriptor,a=Object.getOwnPropertyNames,o=Object.getPrototypeOf,s=Object.prototype.hasOwnProperty,c=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),l=(e,t,n,o)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var c=a(t),l=0,u=c.length,d;l<u;l++)d=c[l],!s.call(e,d)&&d!==n&&r(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(o=i(t,d))||o.enumerable});return e},u=(e,t,i)=>(i=e==null?{}:n(o(e)),l(t||!e||!e.__esModule?r(i,`default`,{value:e,enumerable:!0}):i,e)),d=e(import.meta.url);const f=t(`node-ts-cache`);var p=class{constructor(e){this.storage=e}async getItem(e){let t=await this.storage.getItem(e);if(!t)return;let n={content:t.content,meta:{createdAt:t.meta.createdAt,expired:this.isItemExpired(t)}};if(n.meta.expired&&await this.unsetKey(e),!(n.meta.expired&&!t.meta.isLazy))return n}async setItem(e,t,n){let r={ttl:null,isLazy:!0,...n},i={createdAt:Date.now(),isLazy:r.isLazy,ttl:r.ttl};await this.storage.setItem(e,{meta:i,content:t})}async clear(){await this.storage.clear(),f(`Cleared cache`)}isItemExpired(e){return e.meta.ttl===null?!1:Date.now()>e.meta.createdAt+e.meta.ttl}async unsetKey(e){await this.storage.removeItem(e)}};const m=typeof performance==`object`&&performance&&typeof performance.now==`function`?performance:Date,h=new Set,g=typeof process==`object`&&process?process:{},_=(e,t,n,r)=>{typeof g.emitWarning==`function`?g.emitWarning(e,t,n,r):console.error(`[${n}] ${t}: ${e}`)};let v=globalThis.AbortController,y=globalThis.AbortSignal;if(v===void 0){y=class{onabort;_onabort=[];reason;aborted=!1;addEventListener(e,t){this._onabort.push(t)}},v=class{constructor(){t()}signal=new y;abort(e){if(!this.signal.aborted){this.signal.reason=e,this.signal.aborted=!0;for(let t of this.signal._onabort)t(e);this.signal.onabort?.(e)}}};let e=g.env?.LRU_CACHE_IGNORE_AC_WARNING!==`1`,t=()=>{e&&(e=!1,_("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))}}const b=e=>!h.has(e),x=e=>e&&e===Math.floor(e)&&e>0&&isFinite(e),S=e=>x(e)?e<=2**8?Uint8Array:e<=2**16?Uint16Array:e<=2**32?Uint32Array:e<=2**53-1?C:null:null;var C=class extends Array{constructor(e){super(e),this.fill(0)}},w=class e{heap;length;static#e=!1;static create(t){let n=S(t);if(!n)return[];e.#e=!0;let r=new e(t,n);return e.#e=!1,r}constructor(t,n){if(!e.#e)throw TypeError(`instantiate Stack using Stack.create(n)`);this.heap=new n(t),this.length=0}push(e){this.heap[this.length++]=e}pop(){return this.heap[--this.length]}},T=class e{#e;#t;#n;#r;#i;#a;#o;#s;get perf(){return this.#s}ttl;ttlResolution;ttlAutopurge;updateAgeOnGet;updateAgeOnHas;allowStale;noDisposeOnSet;noUpdateTTL;maxEntrySize;sizeCalculation;noDeleteOnFetchRejection;noDeleteOnStaleGet;allowStaleOnFetchAbort;allowStaleOnFetchRejection;ignoreFetchAbort;#c;#l;#u;#d;#f;#p;#m;#h;#g;#_;#v;#y;#b;#x;#S;#C;#w;#T;static unsafeExposeInternals(e){return{starts:e.#b,ttls:e.#x,sizes:e.#y,keyMap:e.#u,keyList:e.#d,valList:e.#f,next:e.#p,prev:e.#m,get head(){return e.#h},get tail(){return e.#g},free:e.#_,isBackgroundFetch:t=>e.#B(t),backgroundFetch:(t,n,r,i)=>e.#z(t,n,r,i),moveToTail:t=>e.#H(t),indexes:t=>e.#F(t),rindexes:t=>e.#I(t),isStale:t=>e.#A(t)}}get max(){return this.#e}get maxSize(){return this.#t}get calculatedSize(){return this.#l}get size(){return this.#c}get fetchMethod(){return this.#a}get memoMethod(){return this.#o}get dispose(){return this.#n}get onInsert(){return this.#r}get disposeAfter(){return this.#i}constructor(t){let{max:n=0,ttl:r,ttlResolution:i=1,ttlAutopurge:a,updateAgeOnGet:o,updateAgeOnHas:s,allowStale:c,dispose:l,onInsert:u,disposeAfter:d,noDisposeOnSet:f,noUpdateTTL:p,maxSize:g=0,maxEntrySize:v=0,sizeCalculation:y,fetchMethod:C,memoMethod:T,noDeleteOnFetchRejection:E,noDeleteOnStaleGet:D,allowStaleOnFetchRejection:O,allowStaleOnFetchAbort:k,ignoreFetchAbort:A,perf:j}=t;if(j!==void 0&&typeof j?.now!=`function`)throw TypeError(`perf option must have a now() method if specified`);if(this.#s=j??m,n!==0&&!x(n))throw TypeError(`max option must be a nonnegative integer`);let M=n?S(n):Array;if(!M)throw Error(`invalid max value: `+n);if(this.#e=n,this.#t=g,this.maxEntrySize=v||this.#t,this.sizeCalculation=y,this.sizeCalculation){if(!this.#t&&!this.maxEntrySize)throw TypeError(`cannot set sizeCalculation without setting maxSize or maxEntrySize`);if(typeof this.sizeCalculation!=`function`)throw TypeError(`sizeCalculation set to non-function`)}if(T!==void 0&&typeof T!=`function`)throw TypeError(`memoMethod must be a function if defined`);if(this.#o=T,C!==void 0&&typeof C!=`function`)throw TypeError(`fetchMethod must be a function if specified`);if(this.#a=C,this.#C=!!C,this.#u=new Map,this.#d=Array(n).fill(void 0),this.#f=Array(n).fill(void 0),this.#p=new M(n),this.#m=new M(n),this.#h=0,this.#g=0,this.#_=w.create(n),this.#c=0,this.#l=0,typeof l==`function`&&(this.#n=l),typeof u==`function`&&(this.#r=u),typeof d==`function`?(this.#i=d,this.#v=[]):(this.#i=void 0,this.#v=void 0),this.#S=!!this.#n,this.#T=!!this.#r,this.#w=!!this.#i,this.noDisposeOnSet=!!f,this.noUpdateTTL=!!p,this.noDeleteOnFetchRejection=!!E,this.allowStaleOnFetchRejection=!!O,this.allowStaleOnFetchAbort=!!k,this.ignoreFetchAbort=!!A,this.maxEntrySize!==0){if(this.#t!==0&&!x(this.#t))throw TypeError(`maxSize must be a positive integer if specified`);if(!x(this.maxEntrySize))throw TypeError(`maxEntrySize must be a positive integer if specified`);this.#j()}if(this.allowStale=!!c,this.noDeleteOnStaleGet=!!D,this.updateAgeOnGet=!!o,this.updateAgeOnHas=!!s,this.ttlResolution=x(i)||i===0?i:1,this.ttlAutopurge=!!a,this.ttl=r||0,this.ttl){if(!x(this.ttl))throw TypeError(`ttl must be a positive integer if specified`);this.#E()}if(this.#e===0&&this.ttl===0&&this.#t===0)throw TypeError(`At least one of max, maxSize, or ttl is required`);if(!this.ttlAutopurge&&!this.#e&&!this.#t){let t=`LRU_CACHE_UNBOUNDED`;b(t)&&(h.add(t),_(`TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.`,`UnboundedCacheWarning`,t,e))}}getRemainingTTL(e){return this.#u.has(e)?1/0:0}#E(){let e=new C(this.#e),t=new C(this.#e);this.#x=e,this.#b=t,this.#k=(n,r,i=this.#s.now())=>{if(t[n]=r===0?0:i,e[n]=r,r!==0&&this.ttlAutopurge){let e=setTimeout(()=>{this.#A(n)&&this.#U(this.#d[n],`expire`)},r+1);e.unref&&e.unref()}},this.#D=n=>{t[n]=e[n]===0?0:this.#s.now()},this.#O=(i,a)=>{if(e[a]){let o=e[a],s=t[a];if(!o||!s)return;i.ttl=o,i.start=s,i.now=n||r(),i.remainingTTL=o-(i.now-s)}};let n=0,r=()=>{let e=this.#s.now();if(this.ttlResolution>0){n=e;let t=setTimeout(()=>n=0,this.ttlResolution);t.unref&&t.unref()}return e};this.getRemainingTTL=i=>{let a=this.#u.get(i);if(a===void 0)return 0;let o=e[a],s=t[a];return!o||!s?1/0:o-((n||r())-s)},this.#A=i=>{let a=t[i],o=e[i];return!!o&&!!a&&(n||r())-a>o}}#D=()=>{};#O=()=>{};#k=()=>{};#A=()=>!1;#j(){let e=new C(this.#e);this.#l=0,this.#y=e,this.#M=t=>{this.#l-=e[t],e[t]=0},this.#P=(e,t,n,r)=>{if(this.#B(t))return 0;if(!x(n))if(r){if(typeof r!=`function`)throw TypeError(`sizeCalculation must be a function`);if(n=r(t,e),!x(n))throw TypeError(`sizeCalculation return invalid (expect positive integer)`)}else throw TypeError(`invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.`);return n},this.#N=(t,n,r)=>{if(e[t]=n,this.#t){let n=this.#t-e[t];for(;this.#l>n;)this.#R(!0)}this.#l+=e[t],r&&(r.entrySize=n,r.totalCalculatedSize=this.#l)}}#M=e=>{};#N=(e,t,n)=>{};#P=(e,t,n,r)=>{if(n||r)throw TypeError(`cannot set size without setting maxSize or maxEntrySize on cache`);return 0};*#F({allowStale:e=this.allowStale}={}){if(this.#c)for(let t=this.#g;!(!this.#L(t)||((e||!this.#A(t))&&(yield t),t===this.#h));)t=this.#m[t]}*#I({allowStale:e=this.allowStale}={}){if(this.#c)for(let t=this.#h;!(!this.#L(t)||((e||!this.#A(t))&&(yield t),t===this.#g));)t=this.#p[t]}#L(e){return e!==void 0&&this.#u.get(this.#d[e])===e}*entries(){for(let e of this.#F())this.#f[e]!==void 0&&this.#d[e]!==void 0&&!this.#B(this.#f[e])&&(yield[this.#d[e],this.#f[e]])}*rentries(){for(let e of this.#I())this.#f[e]!==void 0&&this.#d[e]!==void 0&&!this.#B(this.#f[e])&&(yield[this.#d[e],this.#f[e]])}*keys(){for(let e of this.#F()){let t=this.#d[e];t!==void 0&&!this.#B(this.#f[e])&&(yield t)}}*rkeys(){for(let e of this.#I()){let t=this.#d[e];t!==void 0&&!this.#B(this.#f[e])&&(yield t)}}*values(){for(let e of this.#F())this.#f[e]!==void 0&&!this.#B(this.#f[e])&&(yield this.#f[e])}*rvalues(){for(let e of this.#I())this.#f[e]!==void 0&&!this.#B(this.#f[e])&&(yield this.#f[e])}[Symbol.iterator](){return this.entries()}[Symbol.toStringTag]=`LRUCache`;find(e,t={}){for(let n of this.#F()){let r=this.#f[n],i=this.#B(r)?r.__staleWhileFetching:r;if(i!==void 0&&e(i,this.#d[n],this))return this.get(this.#d[n],t)}}forEach(e,t=this){for(let n of this.#F()){let r=this.#f[n],i=this.#B(r)?r.__staleWhileFetching:r;i!==void 0&&e.call(t,i,this.#d[n],this)}}rforEach(e,t=this){for(let n of this.#I()){let r=this.#f[n],i=this.#B(r)?r.__staleWhileFetching:r;i!==void 0&&e.call(t,i,this.#d[n],this)}}purgeStale(){let e=!1;for(let t of this.#I({allowStale:!0}))this.#A(t)&&(this.#U(this.#d[t],`expire`),e=!0);return e}info(e){let t=this.#u.get(e);if(t===void 0)return;let n=this.#f[t],r=this.#B(n)?n.__staleWhileFetching:n;if(r===void 0)return;let i={value:r};if(this.#x&&this.#b){let e=this.#x[t],n=this.#b[t];e&&n&&(i.ttl=e-(this.#s.now()-n),i.start=Date.now())}return this.#y&&(i.size=this.#y[t]),i}dump(){let e=[];for(let t of this.#F({allowStale:!0})){let n=this.#d[t],r=this.#f[t],i=this.#B(r)?r.__staleWhileFetching:r;if(i===void 0||n===void 0)continue;let a={value:i};if(this.#x&&this.#b){a.ttl=this.#x[t];let e=this.#s.now()-this.#b[t];a.start=Math.floor(Date.now()-e)}this.#y&&(a.size=this.#y[t]),e.unshift([n,a])}return e}load(e){this.clear();for(let[t,n]of e){if(n.start){let e=Date.now()-n.start;n.start=this.#s.now()-e}this.set(t,n.value,n)}}set(e,t,n={}){if(t===void 0)return this.delete(e),this;let{ttl:r=this.ttl,start:i,noDisposeOnSet:a=this.noDisposeOnSet,sizeCalculation:o=this.sizeCalculation,status:s}=n,{noUpdateTTL:c=this.noUpdateTTL}=n,l=this.#P(e,t,n.size||0,o);if(this.maxEntrySize&&l>this.maxEntrySize)return s&&(s.set=`miss`,s.maxEntrySizeExceeded=!0),this.#U(e,`set`),this;let u=this.#c===0?void 0:this.#u.get(e);if(u===void 0)u=this.#c===0?this.#g:this.#_.length===0?this.#c===this.#e?this.#R(!1):this.#c:this.#_.pop(),this.#d[u]=e,this.#f[u]=t,this.#u.set(e,u),this.#p[this.#g]=u,this.#m[u]=this.#g,this.#g=u,this.#c++,this.#N(u,l,s),s&&(s.set=`add`),c=!1,this.#T&&this.#r?.(t,e,`add`);else{this.#H(u);let n=this.#f[u];if(t!==n){if(this.#C&&this.#B(n)){n.__abortController.abort(Error(`replaced`));let{__staleWhileFetching:t}=n;t!==void 0&&!a&&(this.#S&&this.#n?.(t,e,`set`),this.#w&&this.#v?.push([t,e,`set`]))}else a||(this.#S&&this.#n?.(n,e,`set`),this.#w&&this.#v?.push([n,e,`set`]));if(this.#M(u),this.#N(u,l,s),this.#f[u]=t,s){s.set=`replace`;let e=n&&this.#B(n)?n.__staleWhileFetching:n;e!==void 0&&(s.oldValue=e)}}else s&&(s.set=`update`);this.#T&&this.onInsert?.(t,e,t===n?`update`:`replace`)}if(r!==0&&!this.#x&&this.#E(),this.#x&&(c||this.#k(u,r,i),s&&this.#O(s,u)),!a&&this.#w&&this.#v){let e=this.#v,t;for(;t=e?.shift();)this.#i?.(...t)}return this}pop(){try{for(;this.#c;){let e=this.#f[this.#h];if(this.#R(!0),this.#B(e)){if(e.__staleWhileFetching)return e.__staleWhileFetching}else if(e!==void 0)return e}}finally{if(this.#w&&this.#v){let e=this.#v,t;for(;t=e?.shift();)this.#i?.(...t)}}}#R(e){let t=this.#h,n=this.#d[t],r=this.#f[t];return this.#C&&this.#B(r)?r.__abortController.abort(Error(`evicted`)):(this.#S||this.#w)&&(this.#S&&this.#n?.(r,n,`evict`),this.#w&&this.#v?.push([r,n,`evict`])),this.#M(t),e&&(this.#d[t]=void 0,this.#f[t]=void 0,this.#_.push(t)),this.#c===1?(this.#h=this.#g=0,this.#_.length=0):this.#h=this.#p[t],this.#u.delete(n),this.#c--,t}has(e,t={}){let{updateAgeOnHas:n=this.updateAgeOnHas,status:r}=t,i=this.#u.get(e);if(i!==void 0){let e=this.#f[i];if(this.#B(e)&&e.__staleWhileFetching===void 0)return!1;if(this.#A(i))r&&(r.has=`stale`,this.#O(r,i));else return n&&this.#D(i),r&&(r.has=`hit`,this.#O(r,i)),!0}else r&&(r.has=`miss`);return!1}peek(e,t={}){let{allowStale:n=this.allowStale}=t,r=this.#u.get(e);if(r===void 0||!n&&this.#A(r))return;let i=this.#f[r];return this.#B(i)?i.__staleWhileFetching:i}#z(e,t,n,r){let i=t===void 0?void 0:this.#f[t];if(this.#B(i))return i;let a=new v,{signal:o}=n;o?.addEventListener(`abort`,()=>a.abort(o.reason),{signal:a.signal});let s={signal:a.signal,options:n,context:r},c=(r,i=!1)=>{let{aborted:o}=a.signal,c=n.ignoreFetchAbort&&r!==void 0;if(n.status&&(o&&!i?(n.status.fetchAborted=!0,n.status.fetchError=a.signal.reason,c&&(n.status.fetchAbortIgnored=!0)):n.status.fetchResolved=!0),o&&!c&&!i)return u(a.signal.reason);let l=f,d=this.#f[t];return(d===f||c&&i&&d===void 0)&&(r===void 0?l.__staleWhileFetching===void 0?this.#U(e,`fetch`):this.#f[t]=l.__staleWhileFetching:(n.status&&(n.status.fetchUpdated=!0),this.set(e,r,s.options))),r},l=e=>(n.status&&(n.status.fetchRejected=!0,n.status.fetchError=e),u(e)),u=r=>{let{aborted:i}=a.signal,o=i&&n.allowStaleOnFetchAbort,s=o||n.allowStaleOnFetchRejection,c=s||n.noDeleteOnFetchRejection,l=f;if(this.#f[t]===f&&(!c||l.__staleWhileFetching===void 0?this.#U(e,`fetch`):o||(this.#f[t]=l.__staleWhileFetching)),s)return n.status&&l.__staleWhileFetching!==void 0&&(n.status.returnedStale=!0),l.__staleWhileFetching;if(l.__returned===l)throw r},d=(t,r)=>{let o=this.#a?.(e,i,s);o&&o instanceof Promise&&o.then(e=>t(e===void 0?void 0:e),r),a.signal.addEventListener(`abort`,()=>{(!n.ignoreFetchAbort||n.allowStaleOnFetchAbort)&&(t(void 0),n.allowStaleOnFetchAbort&&(t=e=>c(e,!0)))})};n.status&&(n.status.fetchDispatched=!0);let f=new Promise(d).then(c,l),p=Object.assign(f,{__abortController:a,__staleWhileFetching:i,__returned:void 0});return t===void 0?(this.set(e,p,{...s.options,status:void 0}),t=this.#u.get(e)):this.#f[t]=p,p}#B(e){if(!this.#C)return!1;let t=e;return!!t&&t instanceof Promise&&t.hasOwnProperty(`__staleWhileFetching`)&&t.__abortController instanceof v}async fetch(e,t={}){let{allowStale:n=this.allowStale,updateAgeOnGet:r=this.updateAgeOnGet,noDeleteOnStaleGet:i=this.noDeleteOnStaleGet,ttl:a=this.ttl,noDisposeOnSet:o=this.noDisposeOnSet,size:s=0,sizeCalculation:c=this.sizeCalculation,noUpdateTTL:l=this.noUpdateTTL,noDeleteOnFetchRejection:u=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:d=this.allowStaleOnFetchRejection,ignoreFetchAbort:f=this.ignoreFetchAbort,allowStaleOnFetchAbort:p=this.allowStaleOnFetchAbort,context:m,forceRefresh:h=!1,status:g,signal:_}=t;if(!this.#C)return g&&(g.fetch=`get`),this.get(e,{allowStale:n,updateAgeOnGet:r,noDeleteOnStaleGet:i,status:g});let v={allowStale:n,updateAgeOnGet:r,noDeleteOnStaleGet:i,ttl:a,noDisposeOnSet:o,size:s,sizeCalculation:c,noUpdateTTL:l,noDeleteOnFetchRejection:u,allowStaleOnFetchRejection:d,allowStaleOnFetchAbort:p,ignoreFetchAbort:f,status:g,signal:_},y=this.#u.get(e);if(y===void 0){g&&(g.fetch=`miss`);let t=this.#z(e,y,v,m);return t.__returned=t}else{let t=this.#f[y];if(this.#B(t)){let e=n&&t.__staleWhileFetching!==void 0;return g&&(g.fetch=`inflight`,e&&(g.returnedStale=!0)),e?t.__staleWhileFetching:t.__returned=t}let i=this.#A(y);if(!h&&!i)return g&&(g.fetch=`hit`),this.#H(y),r&&this.#D(y),g&&this.#O(g,y),t;let a=this.#z(e,y,v,m),o=a.__staleWhileFetching!==void 0&&n;return g&&(g.fetch=i?`stale`:`refresh`,o&&i&&(g.returnedStale=!0)),o?a.__staleWhileFetching:a.__returned=a}}async forceFetch(e,t={}){let n=await this.fetch(e,t);if(n===void 0)throw Error(`fetch() returned undefined`);return n}memo(e,t={}){let n=this.#o;if(!n)throw Error(`no memoMethod provided to constructor`);let{context:r,forceRefresh:i,...a}=t,o=this.get(e,a);if(!i&&o!==void 0)return o;let s=n(e,o,{options:a,context:r});return this.set(e,s,a),s}get(e,t={}){let{allowStale:n=this.allowStale,updateAgeOnGet:r=this.updateAgeOnGet,noDeleteOnStaleGet:i=this.noDeleteOnStaleGet,status:a}=t,o=this.#u.get(e);if(o!==void 0){let t=this.#f[o],s=this.#B(t);return a&&this.#O(a,o),this.#A(o)?(a&&(a.get=`stale`),s?(a&&n&&t.__staleWhileFetching!==void 0&&(a.returnedStale=!0),n?t.__staleWhileFetching:void 0):(i||this.#U(e,`expire`),a&&n&&(a.returnedStale=!0),n?t:void 0)):(a&&(a.get=`hit`),s?t.__staleWhileFetching:(this.#H(o),r&&this.#D(o),t))}else a&&(a.get=`miss`)}#V(e,t){this.#m[t]=e,this.#p[e]=t}#H(e){e!==this.#g&&(e===this.#h?this.#h=this.#p[e]:this.#V(this.#m[e],this.#p[e]),this.#V(this.#g,e),this.#g=e)}delete(e){return this.#U(e,`delete`)}#U(e,t){let n=!1;if(this.#c!==0){let r=this.#u.get(e);if(r!==void 0)if(n=!0,this.#c===1)this.#W(t);else{this.#M(r);let n=this.#f[r];if(this.#B(n)?n.__abortController.abort(Error(`deleted`)):(this.#S||this.#w)&&(this.#S&&this.#n?.(n,e,t),this.#w&&this.#v?.push([n,e,t])),this.#u.delete(e),this.#d[r]=void 0,this.#f[r]=void 0,r===this.#g)this.#g=this.#m[r];else if(r===this.#h)this.#h=this.#p[r];else{let e=this.#m[r];this.#p[e]=this.#p[r];let t=this.#p[r];this.#m[t]=this.#m[r]}this.#c--,this.#_.push(r)}}if(this.#w&&this.#v?.length){let e=this.#v,t;for(;t=e?.shift();)this.#i?.(...t)}return n}clear(){return this.#W(`delete`)}#W(e){for(let t of this.#I({allowStale:!0})){let n=this.#f[t];if(this.#B(n))n.__abortController.abort(Error(`deleted`));else{let r=this.#d[t];this.#S&&this.#n?.(n,r,e),this.#w&&this.#v?.push([n,r,e])}}if(this.#u.clear(),this.#f.fill(void 0),this.#d.fill(void 0),this.#x&&this.#b&&(this.#x.fill(0),this.#b.fill(0)),this.#y&&this.#y.fill(0),this.#h=0,this.#g=0,this.#_.length=0,this.#l=0,this.#c=0,this.#w&&this.#v){let e=this.#v,t;for(;t=e?.shift();)this.#i?.(...t)}}},E=class{cache;constructor({max:e=1e4}={}){this.cache=new T({max:e})}async clear(){this.cache.clear()}async getItem(e){return this.cache.get(e)}async setItem(e,t){this.cache.set(e,t)}async removeItem(e){this.cache.delete(e)}},D=u(c(((e,t)=>{var n=Object.prototype.hasOwnProperty,r=`~`;function i(){}Object.create&&(i.prototype=Object.create(null),new i().__proto__||(r=!1));function a(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function o(e,t,n,i,o){if(typeof n!=`function`)throw TypeError(`The listener must be a function`);var s=new a(n,i||e,o),c=r?r+t:t;return e._events[c]?e._events[c].fn?e._events[c]=[e._events[c],s]:e._events[c].push(s):(e._events[c]=s,e._eventsCount++),e}function s(e,t){--e._eventsCount===0?e._events=new i:delete e._events[t]}function c(){this._events=new i,this._eventsCount=0}c.prototype.eventNames=function(){var e=[],t,i;if(this._eventsCount===0)return e;for(i in t=this._events)n.call(t,i)&&e.push(r?i.slice(1):i);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e},c.prototype.listeners=function(e){var t=r?r+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var i=0,a=n.length,o=Array(a);i<a;i++)o[i]=n[i].fn;return o},c.prototype.listenerCount=function(e){var t=r?r+e:e,n=this._events[t];return n?n.fn?1:n.length:0},c.prototype.emit=function(e,t,n,i,a,o){var s=r?r+e:e;if(!this._events[s])return!1;var c=this._events[s],l=arguments.length,u,d;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),l){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,t),!0;case 3:return c.fn.call(c.context,t,n),!0;case 4:return c.fn.call(c.context,t,n,i),!0;case 5:return c.fn.call(c.context,t,n,i,a),!0;case 6:return c.fn.call(c.context,t,n,i,a,o),!0}for(d=1,u=Array(l-1);d<l;d++)u[d-1]=arguments[d];c.fn.apply(c.context,u)}else{var f=c.length,p;for(d=0;d<f;d++)switch(c[d].once&&this.removeListener(e,c[d].fn,void 0,!0),l){case 1:c[d].fn.call(c[d].context);break;case 2:c[d].fn.call(c[d].context,t);break;case 3:c[d].fn.call(c[d].context,t,n);break;case 4:c[d].fn.call(c[d].context,t,n,i);break;default:if(!u)for(p=1,u=Array(l-1);p<l;p++)u[p-1]=arguments[p];c[d].fn.apply(c[d].context,u)}}return!0},c.prototype.on=function(e,t,n){return o(this,e,t,n,!1)},c.prototype.once=function(e,t,n){return o(this,e,t,n,!0)},c.prototype.removeListener=function(e,t,n,i){var a=r?r+e:e;if(!this._events[a])return this;if(!t)return s(this,a),this;var o=this._events[a];if(o.fn)o.fn===t&&(!i||o.once)&&(!n||o.context===n)&&s(this,a);else{for(var c=0,l=[],u=o.length;c<u;c++)(o[c].fn!==t||i&&!o[c].once||n&&o[c].context!==n)&&l.push(o[c]);l.length?this._events[a]=l.length===1?l[0]:l:s(this,a)}return this},c.prototype.removeAllListeners=function(e){var t;return e?(t=r?r+e:e,this._events[t]&&s(this,t)):(this._events=new i,this._eventsCount=0),this},c.prototype.off=c.prototype.removeListener,c.prototype.addListener=c.prototype.on,c.prefixed=r,c.EventEmitter=c,t!==void 0&&(t.exports=c)}))(),1),O=class e extends Error{name=`TimeoutError`;constructor(t,n){super(t,n),Error.captureStackTrace?.(this,e)}};const k=e=>e.reason??new DOMException(`This operation was aborted.`,`AbortError`);function A(e,t){let{milliseconds:n,fallback:r,message:i,customTimers:a={setTimeout,clearTimeout},signal:o}=t,s,c,l=new Promise((t,l)=>{if(typeof n!=`number`||Math.sign(n)!==1)throw TypeError(`Expected \`milliseconds\` to be a positive number, got \`${n}\``);if(o?.aborted){l(k(o));return}if(o&&(c=()=>{l(k(o))},o.addEventListener(`abort`,c,{once:!0})),e.then(t,l),n===1/0)return;let u=new O;s=a.setTimeout.call(void 0,()=>{if(r){try{t(r())}catch(e){l(e)}return}typeof e.cancel==`function`&&e.cancel(),i===!1?t():i instanceof Error?l(i):(u.message=i??`Promise timed out after ${n} milliseconds`,l(u))},n)}).finally(()=>{l.clear(),c&&o&&o.removeEventListener(`abort`,c)});return l.clear=()=>{a.clearTimeout.call(void 0,s),s=void 0},l}function j(e,t,n){let r=0,i=e.length;for(;i>0;){let a=Math.trunc(i/2),o=r+a;n(e[o],t)<=0?(r=++o,i-=a+1):i=a}return r}var M=class{#e=[];enqueue(e,t){let{priority:n=0,id:r}=t??{},i={priority:n,id:r,run:e};if(this.size===0||this.#e[this.size-1].priority>=n){this.#e.push(i);return}let a=j(this.#e,i,(e,t)=>t.priority-e.priority);this.#e.splice(a,0,i)}setPriority(e,t){let n=this.#e.findIndex(t=>t.id===e);if(n===-1)throw ReferenceError(`No promise function with the id "${e}" exists in the queue.`);let[r]=this.#e.splice(n,1);this.enqueue(r.run,{priority:t,id:e})}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(t=>t.priority===e.priority).map(e=>e.run)}get size(){return this.#e.length}},N=class extends D.default{#e;#t;#n=0;#r;#i=!1;#a=!1;#o;#s=0;#c=0;#l;#u;#d;#f;#p=0;#m;#h;#g=1n;#_=new Map;timeout;constructor(e){if(super(),e={carryoverIntervalCount:!1,intervalCap:1/0,interval:0,concurrency:1/0,autoStart:!0,queueClass:M,...e},!(typeof e.intervalCap==`number`&&e.intervalCap>=1))throw TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${e.intervalCap?.toString()??``}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${e.interval?.toString()??``}\` (${typeof e.interval})`);if(this.#e=e.carryoverIntervalCount??e.carryoverConcurrencyCount??!1,this.#t=e.intervalCap===1/0||e.interval===0,this.#r=e.intervalCap,this.#o=e.interval,this.#d=new e.queueClass,this.#f=e.queueClass,this.concurrency=e.concurrency,e.timeout!==void 0&&!(Number.isFinite(e.timeout)&&e.timeout>0))throw TypeError(`Expected \`timeout\` to be a positive finite number, got \`${e.timeout}\` (${typeof e.timeout})`);this.timeout=e.timeout,this.#h=e.autoStart===!1,this.#M()}get#v(){return this.#t||this.#n<this.#r}get#y(){return this.#p<this.#m}#b(){this.#p--,this.#p===0&&this.emit(`pendingZero`),this.#E(),this.emit(`next`)}#x(){this.#O(),this.#D(),this.#u=void 0}get#S(){let e=Date.now();if(this.#l===void 0){let t=this.#s-e;if(t<0){if(this.#c>0){let t=e-this.#c;if(t<this.#o)return this.#C(this.#o-t),!0}this.#n=this.#e?this.#p:0}else return this.#C(t),!0}return!1}#C(e){this.#u===void 0&&(this.#u=setTimeout(()=>{this.#x()},e))}#w(){this.#l&&=(clearInterval(this.#l),void 0)}#T(){this.#u&&=(clearTimeout(this.#u),void 0)}#E(){if(this.#d.size===0)return this.#w(),this.emit(`empty`),this.#p===0&&(this.#T(),this.emit(`idle`)),!1;let e=!1;if(!this.#h){let t=!this.#S;if(this.#v&&this.#y){let n=this.#d.dequeue();this.#t||(this.#n++,this.#N()),this.emit(`active`),this.#c=Date.now(),n(),t&&this.#D(),e=!0}}return e}#D(){this.#t||this.#l!==void 0||(this.#l=setInterval(()=>{this.#O()},this.#o),this.#s=Date.now()+this.#o)}#O(){this.#n===0&&this.#p===0&&this.#l&&this.#w(),this.#n=this.#e?this.#p:0,this.#k(),this.#N()}#k(){for(;this.#E(););}get concurrency(){return this.#m}set concurrency(e){if(!(typeof e==`number`&&e>=1))throw TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);this.#m=e,this.#k()}async#A(e){return new Promise((t,n)=>{e.addEventListener(`abort`,()=>{n(e.reason)},{once:!0})})}setPriority(e,t){if(typeof t!=`number`||!Number.isFinite(t))throw TypeError(`Expected \`priority\` to be a finite number, got \`${t}\` (${typeof t})`);this.#d.setPriority(e,t)}async add(e,t={}){return t.id??=(this.#g++).toString(),t={timeout:this.timeout,...t},new Promise((n,r)=>{let i=Symbol(`task-${t.id}`);this.#d.enqueue(async()=>{this.#p++,this.#_.set(i,{id:t.id,priority:t.priority??0,startTime:Date.now(),timeout:t.timeout});try{try{t.signal?.throwIfAborted()}catch(e){throw this.#t||this.#n--,this.#_.delete(i),e}let r=e({signal:t.signal});t.timeout&&(r=A(Promise.resolve(r),{milliseconds:t.timeout,message:`Task timed out after ${t.timeout}ms (queue has ${this.#p} running, ${this.#d.size} waiting)`})),t.signal&&(r=Promise.race([r,this.#A(t.signal)]));let a=await r;n(a),this.emit(`completed`,a)}catch(e){r(e),this.emit(`error`,e)}finally{this.#_.delete(i),queueMicrotask(()=>{this.#b()})}},t),this.emit(`add`),this.#E()})}async addAll(e,t){return Promise.all(e.map(async e=>this.add(e,t)))}start(){return this.#h?(this.#h=!1,this.#k(),this):this}pause(){this.#h=!0}clear(){this.#d=new this.#f,this.#P()}async onEmpty(){this.#d.size!==0&&await this.#j(`empty`)}async onSizeLessThan(e){this.#d.size<e||await this.#j(`next`,()=>this.#d.size<e)}async onIdle(){this.#p===0&&this.#d.size===0||await this.#j(`idle`)}async onPendingZero(){this.#p!==0&&await this.#j(`pendingZero`)}async onRateLimit(){this.isRateLimited||await this.#j(`rateLimit`)}async onRateLimitCleared(){this.isRateLimited&&await this.#j(`rateLimitCleared`)}async onError(){return new Promise((e,t)=>{let n=e=>{this.off(`error`,n),t(e)};this.on(`error`,n)})}async#j(e,t){return new Promise(n=>{let r=()=>{t&&!t()||(this.off(e,r),n())};this.on(e,r)})}get size(){return this.#d.size}sizeBy(e){return this.#d.filter(e).length}get pending(){return this.#p}get isPaused(){return this.#h}#M(){this.#t||(this.on(`add`,()=>{this.#d.size>0&&this.#N()}),this.on(`next`,()=>{this.#N()}))}#N(){this.#t||this.#a||(this.#a=!0,queueMicrotask(()=>{this.#a=!1,this.#P()}))}#P(){let e=this.#i,t=!this.#t&&this.#n>=this.#r&&this.#d.size>0;t!==e&&(this.#i=t,this.emit(t?`rateLimit`:`rateLimitCleared`))}get isRateLimited(){return this.#i}get isSaturated(){return this.#p===this.#m&&this.#d.size>0||this.isRateLimited&&this.#d.size>0}get runningTasks(){return[...this.#_.values()].map(e=>({...e}))}},P=c((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.instanceOfHashable=e.guessType=e.guessObjectType=e.TYPE_MAP=void 0,e.TYPE_MAP={Array:`array`,Int8Array:`typedarray`,Uint8Array:`typedarray`,Uint8ClampedArray:`typedarray`,Int16Array:`typedarray`,Uint16Array:`typedarray`,Int32Array:`typedarray`,Uint32Array:`typedarray`,Float32Array:`typedarray`,Float64Array:`typedarray`,BigUint64Array:`typedarray`,BigInt64Array:`typedarray`,Buffer:`typedarray`,Map:`map`,Set:`set`,Date:`date`,String:`string`,Number:`number`,BigInt:`bigint`,Boolean:`boolean`,Object:`object`},e.guessObjectType=t=>{if(t===null)return`null`;if((0,e.instanceOfHashable)(t))return`hashable`;let n=t?.constructor?.name??`unknown`;return e.TYPE_MAP[n]||`unknown`},e.guessType=t=>{let n=typeof t;return n===`object`?(0,e.guessObjectType)(t):n},e.instanceOfHashable=e=>typeof e.toHashableString==`function`})),F=c((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e._mapSort=e._map=e._objectSort=e._object=e._setCoerce=e._set=e._setSort=e._setSortCoerce=e._typedArray=e._typedArraySort=e._array=e._arraySort=e._date=e._dateCoerce=e._functionTrim=e._functionTrimCoerce=e._function=e._functionCoerce=e._null=e._nullCoerce=e._undefined=e._undefinedCoerce=e._symbol=e._symbolCoerce=e._boolean=e._booleanCoerce=e._bigInt=e._bigIntCoerce=e._number=e._numberCoerce=e._stringTrim=e._stringTrimCoerce=e._string=e._stringCoerce=e._hashable=e.PREFIX=void 0;let t=P();e.PREFIX={string:`<:s>`,number:`<:n>`,bigint:`<:bi>`,boolean:`<:b>`,symbol:`<:smbl>`,undefined:`<:undf>`,null:`<:null>`,function:`<:func>`,array:``,date:`<:date>`,set:`<:set>`,map:`<:map>`};function n(e){return e.toHashableString()}e._hashable=n;function r(e){return e}e._stringCoerce=r;function i(t){return e.PREFIX.string+`:`+t}e._string=i;function a(e){return e.replace(/(\s+|\t|\r\n|\n|\r)/gm,` `).trim()}e._stringTrimCoerce=a;function o(t){return e.PREFIX.string+`:`+t.replace(/(\s+|\t|\r\n|\n|\r)/gm,` `).trim()}e._stringTrim=o;function s(e){return e.toString()}e._numberCoerce=s;function c(t){return`${e.PREFIX.number}:${t}`}e._number=c;function l(e){return e.toString()}e._bigIntCoerce=l;function u(t){return`${e.PREFIX.bigint}:${t.toString()}`}e._bigInt=u;function d(e){return e?`1`:`0`}e._booleanCoerce=d;function f(t){return e.PREFIX.boolean+`:`+t.toString()}e._boolean=f;function p(){return e.PREFIX.symbol}e._symbolCoerce=p;function m(t){return e.PREFIX.symbol+`:`+t.toString()}e._symbol=m;function h(){return``}e._undefinedCoerce=h;function g(){return e.PREFIX.undefined}e._undefined=g;function _(){return``}e._nullCoerce=_;function v(){return e.PREFIX.null}e._null=v;function y(e){return e.name+`=>`+e.toString()}e._functionCoerce=y;function b(t){return e.PREFIX.function+`:`+t.name+`=>`+t.toString()}e._function=b;function x(e){return e.name+`=>`+e.toString().replace(/(\s+|\t|\r\n|\n|\r)/gm,` `).trim()}e._functionTrimCoerce=x;function S(t){return e.PREFIX.function+`:`+t.name+`=>`+t.toString().replace(/(\s+|\t|\r\n|\n|\r)/gm,` `).trim()}e._functionTrim=S;function C(e){return e.toISOString()}e._dateCoerce=C;function w(t){return e.PREFIX.date+`:`+t.toISOString()}e._date=w;function T(e){let n=this;return`[`+e.map(e=>n[(0,t.guessType)(e)](e)).sort().toString()+`]`}e._arraySort=T;function E(e){let n=this;return`[`+e.map(e=>n[(0,t.guessType)(e)](e)).toString()+`]`}e._array=E;function D(e){let n=this;return`[`+Array.prototype.slice.call(e).map(e=>n[(0,t.guessType)(e)](e)).sort().toString()+`]`}e._typedArraySort=D;function O(e){let n=this;return`[`+Array.prototype.slice.call(e).map(e=>n[(0,t.guessType)(e)](e)).toString()+`]`}e._typedArray=O;function k(e){return T.call(this,Array.from(e))}e._setSortCoerce=k;function A(t){return`${e.PREFIX.set}:${T.call(this,Array.from(t))}`}e._setSort=A;function j(t){return`${e.PREFIX.set}:${E.call(this,Array.from(t))}`}e._set=j;function M(e){return E.call(this,Array.from(e))}e._setCoerce=M;function N(e){let n=this,r=Object.keys(e),i=[];for(let a of r){let r=e[a],o=(0,t.guessType)(r);i.push(a+`:`+n[o](r))}return`{`+i.toString()+`}`}e._object=N;function F(e){let n=this,r=Object.keys(e).sort(),i=[];for(let a of r){let r=e[a],o=(0,t.guessType)(r);i.push(a+`:`+n[o](r))}return`{`+i.toString()+`}`}e._objectSort=F;function I(e){let n=this,r=Array.from(e),i=[];for(let e of r){let[r,a]=e;i.push([n[(0,t.guessType)(r)](r),n[(0,t.guessType)(a)](a)])}return`[`+i.join(`;`)+`]`}e._map=I;function L(e){let n=this,r=Array.from(e),i=[];for(let e of r){let[r,a]=e;i.push([n[(0,t.guessType)(r)](r),n[(0,t.guessType)(a)](a)])}return`[`+i.sort().join(`;`)+`]`}e._mapSort=L})),I=c((e=>{var t=e&&e.__createBinding||(Object.create?(function(e,t,n,r){r===void 0&&(r=n);var i=Object.getOwnPropertyDescriptor(t,n);(!i||(`get`in i?!t.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,i)}):(function(e,t,n,r){r===void 0&&(r=n),e[r]=t[n]})),n=e&&e.__setModuleDefault||(Object.create?(function(e,t){Object.defineProperty(e,`default`,{enumerable:!0,value:t})}):function(e,t){e.default=t}),r=e&&e.__importStar||function(e){if(e&&e.__esModule)return e;var r={};if(e!=null)for(var i in e)i!==`default`&&Object.prototype.hasOwnProperty.call(e,i)&&t(r,e,i);return n(r,e),r};Object.defineProperty(e,`__esModule`,{value:!0}),e.objectSorter=void 0;let i=r(F()),a=P();e.objectSorter=e=>{let{sort:t,coerce:n,trim:r}={sort:!0,coerce:!0,trim:!1,...e},o={array:typeof t==`boolean`?t:t?.array??!1,typedArray:typeof t==`boolean`?!1:t?.typedArray??!1,object:typeof t==`boolean`?t:t?.object??!1,set:typeof t==`boolean`?t:t?.set??!1,map:typeof t==`boolean`?t:t?.map??!1},s={boolean:typeof n==`boolean`?n:n?.boolean??!1,number:typeof n==`boolean`?n:n?.number??!1,bigint:typeof n==`boolean`?n:n?.bigint??!1,string:typeof n==`boolean`?n:n?.string??!1,undefined:typeof n==`boolean`?n:n?.undefined??!1,null:typeof n==`boolean`?n:n?.null??!1,symbol:typeof n==`boolean`?n:n?.symbol??!1,function:typeof n==`boolean`?n:n?.function??!1,date:typeof n==`boolean`?n:n?.date??!1,set:typeof n==`boolean`?n:n?.set??!1},c={string:typeof r==`boolean`?r:r?.string??!1,function:typeof r==`boolean`?r:r?.function??!1},l={unknown:function(e){let t=e.constructor?.name??`unknonw`,n=`unknown`;return typeof e.toString==`function`?n=e.toString():Object.keys(e).length>0&&(n=JSON.stringify(e)),`<:${t}>:${n}`}};l.hashable=i._hashable.bind(l),c.string?l.string=s.string?i._stringTrimCoerce.bind(l):i._stringTrim.bind(l):l.string=s.string?i._stringCoerce.bind(l):i._string.bind(l),l.number=s.number?i._numberCoerce.bind(l):i._number.bind(l),l.bigint=s.bigint?i._bigIntCoerce.bind(l):i._bigInt.bind(l),l.boolean=s.boolean?i._booleanCoerce.bind(l):i._boolean.bind(l),l.symbol=s.symbol?i._symbolCoerce.bind(l):i._symbol.bind(l),l.undefined=s.undefined?i._undefinedCoerce.bind(l):i._undefined.bind(l),l.null=s.null?i._nullCoerce.bind(l):i._null.bind(l),c.function?l.function=s.function?i._functionTrimCoerce.bind(l):i._functionTrim.bind(l):l.function=s.function?i._functionCoerce.bind(l):i._function.bind(l),l.date=s.date?i._dateCoerce.bind(l):i._date.bind(l),l.array=o.array?i._arraySort.bind(l):i._array.bind(l),l.typedarray=o.typedArray?i._typedArraySort.bind(l):i._typedArray.bind(l),o.set?l.set=s.set?i._setSortCoerce.bind(l):i._setSort.bind(l):l.set=s.set?i._setCoerce.bind(l):i._set.bind(l),l.object=o.object?i._objectSort.bind(l):i._object.bind(l),l.map=o.map?i._mapSort.bind(l):i._map.bind(l);function u(e){return l[(0,a.guessType)(e)](e)}return u}}));const{hash:L}=(0,u(c((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.hasher=void 0;let t=d(`crypto`),n=I();e.hasher=e=>{let r=(0,n.objectSorter)(e);return{hash:(n,i)=>{let a=i?.alg||e?.alg||`sha256`,o=i?.enc||e?.enc||`hex`,s=r(n);return(0,t.createHash)(a).update(s).digest(o)},sort:r,sortObject:r}}}))(),1).hasher)({sort:!0,coerce:!0});var R=L;const z={},B=e=>(t,n={})=>async(...r)=>{let{calculateKey:i,strategy:a=`eager`,revalidationConcurrency:o=1,...s}=n,c=n.prefix??`default`,l=`${t.name}:${c}:${i?i(r):R(r)}`,u=`${t.name}:${c}`;z[u]=z[u]??new N({concurrency:o}),z[u].concurrency=o;let d=await e.getItem(l),f=async()=>{let i=await t(...r);return(!n.shouldStore||n.shouldStore(i))&&await e.setItem(l,i,{...s,isLazy:a===`lazy`||a===`swr`}),i};return a===`swr`&&d?.meta.expired&&(z[u].runningTasks.some(e=>e.id===l&&e.startTime)||z[u].add(f,{id:l})),d?d.content:await f()};export{p as CacheContainer,E as LRUStorage,B as withCacheFactory};
1
+ import{createRequire as e}from"node:module";import{debug as t}from"node:util";var n=Object.create,r=Object.defineProperty,i=Object.getOwnPropertyDescriptor,a=Object.getOwnPropertyNames,o=Object.getPrototypeOf,s=Object.prototype.hasOwnProperty,c=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),l=(e,t,n,o)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var c=a(t),l=0,u=c.length,d;l<u;l++)d=c[l],!s.call(e,d)&&d!==n&&r(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(o=i(t,d))||o.enumerable});return e},u=(e,t,i)=>(i=e==null?{}:n(o(e)),l(t||!e||!e.__esModule?r(i,`default`,{value:e,enumerable:!0}):i,e)),d=e(import.meta.url);const f=t(`node-ts-cache`);var p=class{constructor(e){this.storage=e}async getItem(e){let t=await this.storage.getItem(e);if(!t)return;let n={content:t.content,meta:{createdAt:t.meta.createdAt,expired:this.isItemExpired(t),stale:this.isStaleItem(t)}};if(n.meta.expired&&!n.meta.stale){await this.unsetKey(e);return}return n}async setItem(e,t,n){let r={ttl:null,staleTtl:null,...n},i={createdAt:Date.now(),staleTtl:r.staleTtl,ttl:r.ttl};await this.storage.setItem(e,{meta:i,content:t})}async clear(){await this.storage.clear(),f(`Cleared cache`)}isItemExpired(e){return e.meta.ttl===null?!1:Date.now()>e.meta.createdAt+e.meta.ttl}isStaleItem(e){let t=e.meta.staleTtl??e.meta.ttl;return t===null?!1:Date.now()>e.meta.createdAt+t}async unsetKey(e){await this.storage.removeItem(e)}};const m=typeof performance==`object`&&performance&&typeof performance.now==`function`?performance:Date,h=new Set,g=typeof process==`object`&&process?process:{},_=(e,t,n,r)=>{typeof g.emitWarning==`function`?g.emitWarning(e,t,n,r):console.error(`[${n}] ${t}: ${e}`)};let v=globalThis.AbortController,y=globalThis.AbortSignal;if(v===void 0){y=class{onabort;_onabort=[];reason;aborted=!1;addEventListener(e,t){this._onabort.push(t)}},v=class{constructor(){t()}signal=new y;abort(e){if(!this.signal.aborted){this.signal.reason=e,this.signal.aborted=!0;for(let t of this.signal._onabort)t(e);this.signal.onabort?.(e)}}};let e=g.env?.LRU_CACHE_IGNORE_AC_WARNING!==`1`,t=()=>{e&&(e=!1,_("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))}}const b=e=>!h.has(e),x=e=>e&&e===Math.floor(e)&&e>0&&isFinite(e),S=e=>x(e)?e<=2**8?Uint8Array:e<=2**16?Uint16Array:e<=2**32?Uint32Array:e<=2**53-1?C:null:null;var C=class extends Array{constructor(e){super(e),this.fill(0)}},w=class e{heap;length;static#e=!1;static create(t){let n=S(t);if(!n)return[];e.#e=!0;let r=new e(t,n);return e.#e=!1,r}constructor(t,n){if(!e.#e)throw TypeError(`instantiate Stack using Stack.create(n)`);this.heap=new n(t),this.length=0}push(e){this.heap[this.length++]=e}pop(){return this.heap[--this.length]}},T=class e{#e;#t;#n;#r;#i;#a;#o;#s;get perf(){return this.#s}ttl;ttlResolution;ttlAutopurge;updateAgeOnGet;updateAgeOnHas;allowStale;noDisposeOnSet;noUpdateTTL;maxEntrySize;sizeCalculation;noDeleteOnFetchRejection;noDeleteOnStaleGet;allowStaleOnFetchAbort;allowStaleOnFetchRejection;ignoreFetchAbort;#c;#l;#u;#d;#f;#p;#m;#h;#g;#_;#v;#y;#b;#x;#S;#C;#w;#T;static unsafeExposeInternals(e){return{starts:e.#b,ttls:e.#x,sizes:e.#y,keyMap:e.#u,keyList:e.#d,valList:e.#f,next:e.#p,prev:e.#m,get head(){return e.#h},get tail(){return e.#g},free:e.#_,isBackgroundFetch:t=>e.#B(t),backgroundFetch:(t,n,r,i)=>e.#z(t,n,r,i),moveToTail:t=>e.#H(t),indexes:t=>e.#F(t),rindexes:t=>e.#I(t),isStale:t=>e.#A(t)}}get max(){return this.#e}get maxSize(){return this.#t}get calculatedSize(){return this.#l}get size(){return this.#c}get fetchMethod(){return this.#a}get memoMethod(){return this.#o}get dispose(){return this.#n}get onInsert(){return this.#r}get disposeAfter(){return this.#i}constructor(t){let{max:n=0,ttl:r,ttlResolution:i=1,ttlAutopurge:a,updateAgeOnGet:o,updateAgeOnHas:s,allowStale:c,dispose:l,onInsert:u,disposeAfter:d,noDisposeOnSet:f,noUpdateTTL:p,maxSize:g=0,maxEntrySize:v=0,sizeCalculation:y,fetchMethod:C,memoMethod:T,noDeleteOnFetchRejection:E,noDeleteOnStaleGet:D,allowStaleOnFetchRejection:O,allowStaleOnFetchAbort:k,ignoreFetchAbort:A,perf:j}=t;if(j!==void 0&&typeof j?.now!=`function`)throw TypeError(`perf option must have a now() method if specified`);if(this.#s=j??m,n!==0&&!x(n))throw TypeError(`max option must be a nonnegative integer`);let M=n?S(n):Array;if(!M)throw Error(`invalid max value: `+n);if(this.#e=n,this.#t=g,this.maxEntrySize=v||this.#t,this.sizeCalculation=y,this.sizeCalculation){if(!this.#t&&!this.maxEntrySize)throw TypeError(`cannot set sizeCalculation without setting maxSize or maxEntrySize`);if(typeof this.sizeCalculation!=`function`)throw TypeError(`sizeCalculation set to non-function`)}if(T!==void 0&&typeof T!=`function`)throw TypeError(`memoMethod must be a function if defined`);if(this.#o=T,C!==void 0&&typeof C!=`function`)throw TypeError(`fetchMethod must be a function if specified`);if(this.#a=C,this.#C=!!C,this.#u=new Map,this.#d=Array(n).fill(void 0),this.#f=Array(n).fill(void 0),this.#p=new M(n),this.#m=new M(n),this.#h=0,this.#g=0,this.#_=w.create(n),this.#c=0,this.#l=0,typeof l==`function`&&(this.#n=l),typeof u==`function`&&(this.#r=u),typeof d==`function`?(this.#i=d,this.#v=[]):(this.#i=void 0,this.#v=void 0),this.#S=!!this.#n,this.#T=!!this.#r,this.#w=!!this.#i,this.noDisposeOnSet=!!f,this.noUpdateTTL=!!p,this.noDeleteOnFetchRejection=!!E,this.allowStaleOnFetchRejection=!!O,this.allowStaleOnFetchAbort=!!k,this.ignoreFetchAbort=!!A,this.maxEntrySize!==0){if(this.#t!==0&&!x(this.#t))throw TypeError(`maxSize must be a positive integer if specified`);if(!x(this.maxEntrySize))throw TypeError(`maxEntrySize must be a positive integer if specified`);this.#j()}if(this.allowStale=!!c,this.noDeleteOnStaleGet=!!D,this.updateAgeOnGet=!!o,this.updateAgeOnHas=!!s,this.ttlResolution=x(i)||i===0?i:1,this.ttlAutopurge=!!a,this.ttl=r||0,this.ttl){if(!x(this.ttl))throw TypeError(`ttl must be a positive integer if specified`);this.#E()}if(this.#e===0&&this.ttl===0&&this.#t===0)throw TypeError(`At least one of max, maxSize, or ttl is required`);if(!this.ttlAutopurge&&!this.#e&&!this.#t){let t=`LRU_CACHE_UNBOUNDED`;b(t)&&(h.add(t),_(`TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.`,`UnboundedCacheWarning`,t,e))}}getRemainingTTL(e){return this.#u.has(e)?1/0:0}#E(){let e=new C(this.#e),t=new C(this.#e);this.#x=e,this.#b=t,this.#k=(n,r,i=this.#s.now())=>{if(t[n]=r===0?0:i,e[n]=r,r!==0&&this.ttlAutopurge){let e=setTimeout(()=>{this.#A(n)&&this.#U(this.#d[n],`expire`)},r+1);e.unref&&e.unref()}},this.#D=n=>{t[n]=e[n]===0?0:this.#s.now()},this.#O=(i,a)=>{if(e[a]){let o=e[a],s=t[a];if(!o||!s)return;i.ttl=o,i.start=s,i.now=n||r(),i.remainingTTL=o-(i.now-s)}};let n=0,r=()=>{let e=this.#s.now();if(this.ttlResolution>0){n=e;let t=setTimeout(()=>n=0,this.ttlResolution);t.unref&&t.unref()}return e};this.getRemainingTTL=i=>{let a=this.#u.get(i);if(a===void 0)return 0;let o=e[a],s=t[a];return!o||!s?1/0:o-((n||r())-s)},this.#A=i=>{let a=t[i],o=e[i];return!!o&&!!a&&(n||r())-a>o}}#D=()=>{};#O=()=>{};#k=()=>{};#A=()=>!1;#j(){let e=new C(this.#e);this.#l=0,this.#y=e,this.#M=t=>{this.#l-=e[t],e[t]=0},this.#P=(e,t,n,r)=>{if(this.#B(t))return 0;if(!x(n))if(r){if(typeof r!=`function`)throw TypeError(`sizeCalculation must be a function`);if(n=r(t,e),!x(n))throw TypeError(`sizeCalculation return invalid (expect positive integer)`)}else throw TypeError(`invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.`);return n},this.#N=(t,n,r)=>{if(e[t]=n,this.#t){let n=this.#t-e[t];for(;this.#l>n;)this.#R(!0)}this.#l+=e[t],r&&(r.entrySize=n,r.totalCalculatedSize=this.#l)}}#M=e=>{};#N=(e,t,n)=>{};#P=(e,t,n,r)=>{if(n||r)throw TypeError(`cannot set size without setting maxSize or maxEntrySize on cache`);return 0};*#F({allowStale:e=this.allowStale}={}){if(this.#c)for(let t=this.#g;!(!this.#L(t)||((e||!this.#A(t))&&(yield t),t===this.#h));)t=this.#m[t]}*#I({allowStale:e=this.allowStale}={}){if(this.#c)for(let t=this.#h;!(!this.#L(t)||((e||!this.#A(t))&&(yield t),t===this.#g));)t=this.#p[t]}#L(e){return e!==void 0&&this.#u.get(this.#d[e])===e}*entries(){for(let e of this.#F())this.#f[e]!==void 0&&this.#d[e]!==void 0&&!this.#B(this.#f[e])&&(yield[this.#d[e],this.#f[e]])}*rentries(){for(let e of this.#I())this.#f[e]!==void 0&&this.#d[e]!==void 0&&!this.#B(this.#f[e])&&(yield[this.#d[e],this.#f[e]])}*keys(){for(let e of this.#F()){let t=this.#d[e];t!==void 0&&!this.#B(this.#f[e])&&(yield t)}}*rkeys(){for(let e of this.#I()){let t=this.#d[e];t!==void 0&&!this.#B(this.#f[e])&&(yield t)}}*values(){for(let e of this.#F())this.#f[e]!==void 0&&!this.#B(this.#f[e])&&(yield this.#f[e])}*rvalues(){for(let e of this.#I())this.#f[e]!==void 0&&!this.#B(this.#f[e])&&(yield this.#f[e])}[Symbol.iterator](){return this.entries()}[Symbol.toStringTag]=`LRUCache`;find(e,t={}){for(let n of this.#F()){let r=this.#f[n],i=this.#B(r)?r.__staleWhileFetching:r;if(i!==void 0&&e(i,this.#d[n],this))return this.get(this.#d[n],t)}}forEach(e,t=this){for(let n of this.#F()){let r=this.#f[n],i=this.#B(r)?r.__staleWhileFetching:r;i!==void 0&&e.call(t,i,this.#d[n],this)}}rforEach(e,t=this){for(let n of this.#I()){let r=this.#f[n],i=this.#B(r)?r.__staleWhileFetching:r;i!==void 0&&e.call(t,i,this.#d[n],this)}}purgeStale(){let e=!1;for(let t of this.#I({allowStale:!0}))this.#A(t)&&(this.#U(this.#d[t],`expire`),e=!0);return e}info(e){let t=this.#u.get(e);if(t===void 0)return;let n=this.#f[t],r=this.#B(n)?n.__staleWhileFetching:n;if(r===void 0)return;let i={value:r};if(this.#x&&this.#b){let e=this.#x[t],n=this.#b[t];e&&n&&(i.ttl=e-(this.#s.now()-n),i.start=Date.now())}return this.#y&&(i.size=this.#y[t]),i}dump(){let e=[];for(let t of this.#F({allowStale:!0})){let n=this.#d[t],r=this.#f[t],i=this.#B(r)?r.__staleWhileFetching:r;if(i===void 0||n===void 0)continue;let a={value:i};if(this.#x&&this.#b){a.ttl=this.#x[t];let e=this.#s.now()-this.#b[t];a.start=Math.floor(Date.now()-e)}this.#y&&(a.size=this.#y[t]),e.unshift([n,a])}return e}load(e){this.clear();for(let[t,n]of e){if(n.start){let e=Date.now()-n.start;n.start=this.#s.now()-e}this.set(t,n.value,n)}}set(e,t,n={}){if(t===void 0)return this.delete(e),this;let{ttl:r=this.ttl,start:i,noDisposeOnSet:a=this.noDisposeOnSet,sizeCalculation:o=this.sizeCalculation,status:s}=n,{noUpdateTTL:c=this.noUpdateTTL}=n,l=this.#P(e,t,n.size||0,o);if(this.maxEntrySize&&l>this.maxEntrySize)return s&&(s.set=`miss`,s.maxEntrySizeExceeded=!0),this.#U(e,`set`),this;let u=this.#c===0?void 0:this.#u.get(e);if(u===void 0)u=this.#c===0?this.#g:this.#_.length===0?this.#c===this.#e?this.#R(!1):this.#c:this.#_.pop(),this.#d[u]=e,this.#f[u]=t,this.#u.set(e,u),this.#p[this.#g]=u,this.#m[u]=this.#g,this.#g=u,this.#c++,this.#N(u,l,s),s&&(s.set=`add`),c=!1,this.#T&&this.#r?.(t,e,`add`);else{this.#H(u);let n=this.#f[u];if(t!==n){if(this.#C&&this.#B(n)){n.__abortController.abort(Error(`replaced`));let{__staleWhileFetching:t}=n;t!==void 0&&!a&&(this.#S&&this.#n?.(t,e,`set`),this.#w&&this.#v?.push([t,e,`set`]))}else a||(this.#S&&this.#n?.(n,e,`set`),this.#w&&this.#v?.push([n,e,`set`]));if(this.#M(u),this.#N(u,l,s),this.#f[u]=t,s){s.set=`replace`;let e=n&&this.#B(n)?n.__staleWhileFetching:n;e!==void 0&&(s.oldValue=e)}}else s&&(s.set=`update`);this.#T&&this.onInsert?.(t,e,t===n?`update`:`replace`)}if(r!==0&&!this.#x&&this.#E(),this.#x&&(c||this.#k(u,r,i),s&&this.#O(s,u)),!a&&this.#w&&this.#v){let e=this.#v,t;for(;t=e?.shift();)this.#i?.(...t)}return this}pop(){try{for(;this.#c;){let e=this.#f[this.#h];if(this.#R(!0),this.#B(e)){if(e.__staleWhileFetching)return e.__staleWhileFetching}else if(e!==void 0)return e}}finally{if(this.#w&&this.#v){let e=this.#v,t;for(;t=e?.shift();)this.#i?.(...t)}}}#R(e){let t=this.#h,n=this.#d[t],r=this.#f[t];return this.#C&&this.#B(r)?r.__abortController.abort(Error(`evicted`)):(this.#S||this.#w)&&(this.#S&&this.#n?.(r,n,`evict`),this.#w&&this.#v?.push([r,n,`evict`])),this.#M(t),e&&(this.#d[t]=void 0,this.#f[t]=void 0,this.#_.push(t)),this.#c===1?(this.#h=this.#g=0,this.#_.length=0):this.#h=this.#p[t],this.#u.delete(n),this.#c--,t}has(e,t={}){let{updateAgeOnHas:n=this.updateAgeOnHas,status:r}=t,i=this.#u.get(e);if(i!==void 0){let e=this.#f[i];if(this.#B(e)&&e.__staleWhileFetching===void 0)return!1;if(this.#A(i))r&&(r.has=`stale`,this.#O(r,i));else return n&&this.#D(i),r&&(r.has=`hit`,this.#O(r,i)),!0}else r&&(r.has=`miss`);return!1}peek(e,t={}){let{allowStale:n=this.allowStale}=t,r=this.#u.get(e);if(r===void 0||!n&&this.#A(r))return;let i=this.#f[r];return this.#B(i)?i.__staleWhileFetching:i}#z(e,t,n,r){let i=t===void 0?void 0:this.#f[t];if(this.#B(i))return i;let a=new v,{signal:o}=n;o?.addEventListener(`abort`,()=>a.abort(o.reason),{signal:a.signal});let s={signal:a.signal,options:n,context:r},c=(r,i=!1)=>{let{aborted:o}=a.signal,c=n.ignoreFetchAbort&&r!==void 0;if(n.status&&(o&&!i?(n.status.fetchAborted=!0,n.status.fetchError=a.signal.reason,c&&(n.status.fetchAbortIgnored=!0)):n.status.fetchResolved=!0),o&&!c&&!i)return u(a.signal.reason);let l=f,d=this.#f[t];return(d===f||c&&i&&d===void 0)&&(r===void 0?l.__staleWhileFetching===void 0?this.#U(e,`fetch`):this.#f[t]=l.__staleWhileFetching:(n.status&&(n.status.fetchUpdated=!0),this.set(e,r,s.options))),r},l=e=>(n.status&&(n.status.fetchRejected=!0,n.status.fetchError=e),u(e)),u=r=>{let{aborted:i}=a.signal,o=i&&n.allowStaleOnFetchAbort,s=o||n.allowStaleOnFetchRejection,c=s||n.noDeleteOnFetchRejection,l=f;if(this.#f[t]===f&&(!c||l.__staleWhileFetching===void 0?this.#U(e,`fetch`):o||(this.#f[t]=l.__staleWhileFetching)),s)return n.status&&l.__staleWhileFetching!==void 0&&(n.status.returnedStale=!0),l.__staleWhileFetching;if(l.__returned===l)throw r},d=(t,r)=>{let o=this.#a?.(e,i,s);o&&o instanceof Promise&&o.then(e=>t(e===void 0?void 0:e),r),a.signal.addEventListener(`abort`,()=>{(!n.ignoreFetchAbort||n.allowStaleOnFetchAbort)&&(t(void 0),n.allowStaleOnFetchAbort&&(t=e=>c(e,!0)))})};n.status&&(n.status.fetchDispatched=!0);let f=new Promise(d).then(c,l),p=Object.assign(f,{__abortController:a,__staleWhileFetching:i,__returned:void 0});return t===void 0?(this.set(e,p,{...s.options,status:void 0}),t=this.#u.get(e)):this.#f[t]=p,p}#B(e){if(!this.#C)return!1;let t=e;return!!t&&t instanceof Promise&&t.hasOwnProperty(`__staleWhileFetching`)&&t.__abortController instanceof v}async fetch(e,t={}){let{allowStale:n=this.allowStale,updateAgeOnGet:r=this.updateAgeOnGet,noDeleteOnStaleGet:i=this.noDeleteOnStaleGet,ttl:a=this.ttl,noDisposeOnSet:o=this.noDisposeOnSet,size:s=0,sizeCalculation:c=this.sizeCalculation,noUpdateTTL:l=this.noUpdateTTL,noDeleteOnFetchRejection:u=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:d=this.allowStaleOnFetchRejection,ignoreFetchAbort:f=this.ignoreFetchAbort,allowStaleOnFetchAbort:p=this.allowStaleOnFetchAbort,context:m,forceRefresh:h=!1,status:g,signal:_}=t;if(!this.#C)return g&&(g.fetch=`get`),this.get(e,{allowStale:n,updateAgeOnGet:r,noDeleteOnStaleGet:i,status:g});let v={allowStale:n,updateAgeOnGet:r,noDeleteOnStaleGet:i,ttl:a,noDisposeOnSet:o,size:s,sizeCalculation:c,noUpdateTTL:l,noDeleteOnFetchRejection:u,allowStaleOnFetchRejection:d,allowStaleOnFetchAbort:p,ignoreFetchAbort:f,status:g,signal:_},y=this.#u.get(e);if(y===void 0){g&&(g.fetch=`miss`);let t=this.#z(e,y,v,m);return t.__returned=t}else{let t=this.#f[y];if(this.#B(t)){let e=n&&t.__staleWhileFetching!==void 0;return g&&(g.fetch=`inflight`,e&&(g.returnedStale=!0)),e?t.__staleWhileFetching:t.__returned=t}let i=this.#A(y);if(!h&&!i)return g&&(g.fetch=`hit`),this.#H(y),r&&this.#D(y),g&&this.#O(g,y),t;let a=this.#z(e,y,v,m),o=a.__staleWhileFetching!==void 0&&n;return g&&(g.fetch=i?`stale`:`refresh`,o&&i&&(g.returnedStale=!0)),o?a.__staleWhileFetching:a.__returned=a}}async forceFetch(e,t={}){let n=await this.fetch(e,t);if(n===void 0)throw Error(`fetch() returned undefined`);return n}memo(e,t={}){let n=this.#o;if(!n)throw Error(`no memoMethod provided to constructor`);let{context:r,forceRefresh:i,...a}=t,o=this.get(e,a);if(!i&&o!==void 0)return o;let s=n(e,o,{options:a,context:r});return this.set(e,s,a),s}get(e,t={}){let{allowStale:n=this.allowStale,updateAgeOnGet:r=this.updateAgeOnGet,noDeleteOnStaleGet:i=this.noDeleteOnStaleGet,status:a}=t,o=this.#u.get(e);if(o!==void 0){let t=this.#f[o],s=this.#B(t);return a&&this.#O(a,o),this.#A(o)?(a&&(a.get=`stale`),s?(a&&n&&t.__staleWhileFetching!==void 0&&(a.returnedStale=!0),n?t.__staleWhileFetching:void 0):(i||this.#U(e,`expire`),a&&n&&(a.returnedStale=!0),n?t:void 0)):(a&&(a.get=`hit`),s?t.__staleWhileFetching:(this.#H(o),r&&this.#D(o),t))}else a&&(a.get=`miss`)}#V(e,t){this.#m[t]=e,this.#p[e]=t}#H(e){e!==this.#g&&(e===this.#h?this.#h=this.#p[e]:this.#V(this.#m[e],this.#p[e]),this.#V(this.#g,e),this.#g=e)}delete(e){return this.#U(e,`delete`)}#U(e,t){let n=!1;if(this.#c!==0){let r=this.#u.get(e);if(r!==void 0)if(n=!0,this.#c===1)this.#W(t);else{this.#M(r);let n=this.#f[r];if(this.#B(n)?n.__abortController.abort(Error(`deleted`)):(this.#S||this.#w)&&(this.#S&&this.#n?.(n,e,t),this.#w&&this.#v?.push([n,e,t])),this.#u.delete(e),this.#d[r]=void 0,this.#f[r]=void 0,r===this.#g)this.#g=this.#m[r];else if(r===this.#h)this.#h=this.#p[r];else{let e=this.#m[r];this.#p[e]=this.#p[r];let t=this.#p[r];this.#m[t]=this.#m[r]}this.#c--,this.#_.push(r)}}if(this.#w&&this.#v?.length){let e=this.#v,t;for(;t=e?.shift();)this.#i?.(...t)}return n}clear(){return this.#W(`delete`)}#W(e){for(let t of this.#I({allowStale:!0})){let n=this.#f[t];if(this.#B(n))n.__abortController.abort(Error(`deleted`));else{let r=this.#d[t];this.#S&&this.#n?.(n,r,e),this.#w&&this.#v?.push([n,r,e])}}if(this.#u.clear(),this.#f.fill(void 0),this.#d.fill(void 0),this.#x&&this.#b&&(this.#x.fill(0),this.#b.fill(0)),this.#y&&this.#y.fill(0),this.#h=0,this.#g=0,this.#_.length=0,this.#l=0,this.#c=0,this.#w&&this.#v){let e=this.#v,t;for(;t=e?.shift();)this.#i?.(...t)}}},E=class{cache;constructor({max:e=1e4}={}){this.cache=new T({max:e})}async clear(){this.cache.clear()}async getItem(e){return this.cache.get(e)}async setItem(e,t){this.cache.set(e,t)}async removeItem(e){this.cache.delete(e)}},D=class{storages;constructor(e){this.storages=e}async clear(){await Promise.all([...this.storages.map(e=>e.clear())])}async getItem(e){for(let t=0;t<this.storages.length;t++){let n=await this.storages[t]?.getItem(e);if(n!==void 0)return t!==0&&await Promise.all(this.storages.slice(0,t).map(t=>t.setItem(e,n))),n}}async setItem(e,t){let[n,...r]=this.storages;await n.setItem(e,t),Promise.all(r.map(n=>n.setItem(e,t)))}async removeItem(e){await Promise.all(this.storages.map(t=>t.removeItem(e)))}},O=u(c(((e,t)=>{var n=Object.prototype.hasOwnProperty,r=`~`;function i(){}Object.create&&(i.prototype=Object.create(null),new i().__proto__||(r=!1));function a(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function o(e,t,n,i,o){if(typeof n!=`function`)throw TypeError(`The listener must be a function`);var s=new a(n,i||e,o),c=r?r+t:t;return e._events[c]?e._events[c].fn?e._events[c]=[e._events[c],s]:e._events[c].push(s):(e._events[c]=s,e._eventsCount++),e}function s(e,t){--e._eventsCount===0?e._events=new i:delete e._events[t]}function c(){this._events=new i,this._eventsCount=0}c.prototype.eventNames=function(){var e=[],t,i;if(this._eventsCount===0)return e;for(i in t=this._events)n.call(t,i)&&e.push(r?i.slice(1):i);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e},c.prototype.listeners=function(e){var t=r?r+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var i=0,a=n.length,o=Array(a);i<a;i++)o[i]=n[i].fn;return o},c.prototype.listenerCount=function(e){var t=r?r+e:e,n=this._events[t];return n?n.fn?1:n.length:0},c.prototype.emit=function(e,t,n,i,a,o){var s=r?r+e:e;if(!this._events[s])return!1;var c=this._events[s],l=arguments.length,u,d;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),l){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,t),!0;case 3:return c.fn.call(c.context,t,n),!0;case 4:return c.fn.call(c.context,t,n,i),!0;case 5:return c.fn.call(c.context,t,n,i,a),!0;case 6:return c.fn.call(c.context,t,n,i,a,o),!0}for(d=1,u=Array(l-1);d<l;d++)u[d-1]=arguments[d];c.fn.apply(c.context,u)}else{var f=c.length,p;for(d=0;d<f;d++)switch(c[d].once&&this.removeListener(e,c[d].fn,void 0,!0),l){case 1:c[d].fn.call(c[d].context);break;case 2:c[d].fn.call(c[d].context,t);break;case 3:c[d].fn.call(c[d].context,t,n);break;case 4:c[d].fn.call(c[d].context,t,n,i);break;default:if(!u)for(p=1,u=Array(l-1);p<l;p++)u[p-1]=arguments[p];c[d].fn.apply(c[d].context,u)}}return!0},c.prototype.on=function(e,t,n){return o(this,e,t,n,!1)},c.prototype.once=function(e,t,n){return o(this,e,t,n,!0)},c.prototype.removeListener=function(e,t,n,i){var a=r?r+e:e;if(!this._events[a])return this;if(!t)return s(this,a),this;var o=this._events[a];if(o.fn)o.fn===t&&(!i||o.once)&&(!n||o.context===n)&&s(this,a);else{for(var c=0,l=[],u=o.length;c<u;c++)(o[c].fn!==t||i&&!o[c].once||n&&o[c].context!==n)&&l.push(o[c]);l.length?this._events[a]=l.length===1?l[0]:l:s(this,a)}return this},c.prototype.removeAllListeners=function(e){var t;return e?(t=r?r+e:e,this._events[t]&&s(this,t)):(this._events=new i,this._eventsCount=0),this},c.prototype.off=c.prototype.removeListener,c.prototype.addListener=c.prototype.on,c.prefixed=r,c.EventEmitter=c,t!==void 0&&(t.exports=c)}))(),1),k=class e extends Error{name=`TimeoutError`;constructor(t,n){super(t,n),Error.captureStackTrace?.(this,e)}};const A=e=>e.reason??new DOMException(`This operation was aborted.`,`AbortError`);function j(e,t){let{milliseconds:n,fallback:r,message:i,customTimers:a={setTimeout,clearTimeout},signal:o}=t,s,c,l=new Promise((t,l)=>{if(typeof n!=`number`||Math.sign(n)!==1)throw TypeError(`Expected \`milliseconds\` to be a positive number, got \`${n}\``);if(o?.aborted){l(A(o));return}if(o&&(c=()=>{l(A(o))},o.addEventListener(`abort`,c,{once:!0})),e.then(t,l),n===1/0)return;let u=new k;s=a.setTimeout.call(void 0,()=>{if(r){try{t(r())}catch(e){l(e)}return}typeof e.cancel==`function`&&e.cancel(),i===!1?t():i instanceof Error?l(i):(u.message=i??`Promise timed out after ${n} milliseconds`,l(u))},n)}).finally(()=>{l.clear(),c&&o&&o.removeEventListener(`abort`,c)});return l.clear=()=>{a.clearTimeout.call(void 0,s),s=void 0},l}function M(e,t,n){let r=0,i=e.length;for(;i>0;){let a=Math.trunc(i/2),o=r+a;n(e[o],t)<=0?(r=++o,i-=a+1):i=a}return r}var N=class{#e=[];enqueue(e,t){let{priority:n=0,id:r}=t??{},i={priority:n,id:r,run:e};if(this.size===0||this.#e[this.size-1].priority>=n){this.#e.push(i);return}let a=M(this.#e,i,(e,t)=>t.priority-e.priority);this.#e.splice(a,0,i)}setPriority(e,t){let n=this.#e.findIndex(t=>t.id===e);if(n===-1)throw ReferenceError(`No promise function with the id "${e}" exists in the queue.`);let[r]=this.#e.splice(n,1);this.enqueue(r.run,{priority:t,id:e})}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(t=>t.priority===e.priority).map(e=>e.run)}get size(){return this.#e.length}},P=class extends O.default{#e;#t;#n=0;#r;#i=!1;#a=!1;#o;#s=0;#c=0;#l;#u;#d;#f;#p=0;#m;#h;#g=1n;#_=new Map;timeout;constructor(e){if(super(),e={carryoverIntervalCount:!1,intervalCap:1/0,interval:0,concurrency:1/0,autoStart:!0,queueClass:N,...e},!(typeof e.intervalCap==`number`&&e.intervalCap>=1))throw TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${e.intervalCap?.toString()??``}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${e.interval?.toString()??``}\` (${typeof e.interval})`);if(this.#e=e.carryoverIntervalCount??e.carryoverConcurrencyCount??!1,this.#t=e.intervalCap===1/0||e.interval===0,this.#r=e.intervalCap,this.#o=e.interval,this.#d=new e.queueClass,this.#f=e.queueClass,this.concurrency=e.concurrency,e.timeout!==void 0&&!(Number.isFinite(e.timeout)&&e.timeout>0))throw TypeError(`Expected \`timeout\` to be a positive finite number, got \`${e.timeout}\` (${typeof e.timeout})`);this.timeout=e.timeout,this.#h=e.autoStart===!1,this.#M()}get#v(){return this.#t||this.#n<this.#r}get#y(){return this.#p<this.#m}#b(){this.#p--,this.#p===0&&this.emit(`pendingZero`),this.#E(),this.emit(`next`)}#x(){this.#O(),this.#D(),this.#u=void 0}get#S(){let e=Date.now();if(this.#l===void 0){let t=this.#s-e;if(t<0){if(this.#c>0){let t=e-this.#c;if(t<this.#o)return this.#C(this.#o-t),!0}this.#n=this.#e?this.#p:0}else return this.#C(t),!0}return!1}#C(e){this.#u===void 0&&(this.#u=setTimeout(()=>{this.#x()},e))}#w(){this.#l&&=(clearInterval(this.#l),void 0)}#T(){this.#u&&=(clearTimeout(this.#u),void 0)}#E(){if(this.#d.size===0)return this.#w(),this.emit(`empty`),this.#p===0&&(this.#T(),this.emit(`idle`)),!1;let e=!1;if(!this.#h){let t=!this.#S;if(this.#v&&this.#y){let n=this.#d.dequeue();this.#t||(this.#n++,this.#N()),this.emit(`active`),this.#c=Date.now(),n(),t&&this.#D(),e=!0}}return e}#D(){this.#t||this.#l!==void 0||(this.#l=setInterval(()=>{this.#O()},this.#o),this.#s=Date.now()+this.#o)}#O(){this.#n===0&&this.#p===0&&this.#l&&this.#w(),this.#n=this.#e?this.#p:0,this.#k(),this.#N()}#k(){for(;this.#E(););}get concurrency(){return this.#m}set concurrency(e){if(!(typeof e==`number`&&e>=1))throw TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);this.#m=e,this.#k()}async#A(e){return new Promise((t,n)=>{e.addEventListener(`abort`,()=>{n(e.reason)},{once:!0})})}setPriority(e,t){if(typeof t!=`number`||!Number.isFinite(t))throw TypeError(`Expected \`priority\` to be a finite number, got \`${t}\` (${typeof t})`);this.#d.setPriority(e,t)}async add(e,t={}){return t.id??=(this.#g++).toString(),t={timeout:this.timeout,...t},new Promise((n,r)=>{let i=Symbol(`task-${t.id}`);this.#d.enqueue(async()=>{this.#p++,this.#_.set(i,{id:t.id,priority:t.priority??0,startTime:Date.now(),timeout:t.timeout});try{try{t.signal?.throwIfAborted()}catch(e){throw this.#t||this.#n--,this.#_.delete(i),e}let r=e({signal:t.signal});t.timeout&&(r=j(Promise.resolve(r),{milliseconds:t.timeout,message:`Task timed out after ${t.timeout}ms (queue has ${this.#p} running, ${this.#d.size} waiting)`})),t.signal&&(r=Promise.race([r,this.#A(t.signal)]));let a=await r;n(a),this.emit(`completed`,a)}catch(e){r(e),this.emit(`error`,e)}finally{this.#_.delete(i),queueMicrotask(()=>{this.#b()})}},t),this.emit(`add`),this.#E()})}async addAll(e,t){return Promise.all(e.map(async e=>this.add(e,t)))}start(){return this.#h?(this.#h=!1,this.#k(),this):this}pause(){this.#h=!0}clear(){this.#d=new this.#f,this.#P()}async onEmpty(){this.#d.size!==0&&await this.#j(`empty`)}async onSizeLessThan(e){this.#d.size<e||await this.#j(`next`,()=>this.#d.size<e)}async onIdle(){this.#p===0&&this.#d.size===0||await this.#j(`idle`)}async onPendingZero(){this.#p!==0&&await this.#j(`pendingZero`)}async onRateLimit(){this.isRateLimited||await this.#j(`rateLimit`)}async onRateLimitCleared(){this.isRateLimited&&await this.#j(`rateLimitCleared`)}async onError(){return new Promise((e,t)=>{let n=e=>{this.off(`error`,n),t(e)};this.on(`error`,n)})}async#j(e,t){return new Promise(n=>{let r=()=>{t&&!t()||(this.off(e,r),n())};this.on(e,r)})}get size(){return this.#d.size}sizeBy(e){return this.#d.filter(e).length}get pending(){return this.#p}get isPaused(){return this.#h}#M(){this.#t||(this.on(`add`,()=>{this.#d.size>0&&this.#N()}),this.on(`next`,()=>{this.#N()}))}#N(){this.#t||this.#a||(this.#a=!0,queueMicrotask(()=>{this.#a=!1,this.#P()}))}#P(){let e=this.#i,t=!this.#t&&this.#n>=this.#r&&this.#d.size>0;t!==e&&(this.#i=t,this.emit(t?`rateLimit`:`rateLimitCleared`))}get isRateLimited(){return this.#i}get isSaturated(){return this.#p===this.#m&&this.#d.size>0||this.isRateLimited&&this.#d.size>0}get runningTasks(){return[...this.#_.values()].map(e=>({...e}))}},F=c((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.instanceOfHashable=e.guessType=e.guessObjectType=e.TYPE_MAP=void 0,e.TYPE_MAP={Array:`array`,Int8Array:`typedarray`,Uint8Array:`typedarray`,Uint8ClampedArray:`typedarray`,Int16Array:`typedarray`,Uint16Array:`typedarray`,Int32Array:`typedarray`,Uint32Array:`typedarray`,Float32Array:`typedarray`,Float64Array:`typedarray`,BigUint64Array:`typedarray`,BigInt64Array:`typedarray`,Buffer:`typedarray`,Map:`map`,Set:`set`,Date:`date`,String:`string`,Number:`number`,BigInt:`bigint`,Boolean:`boolean`,Object:`object`},e.guessObjectType=t=>{if(t===null)return`null`;if((0,e.instanceOfHashable)(t))return`hashable`;let n=t?.constructor?.name??`unknown`;return e.TYPE_MAP[n]||`unknown`},e.guessType=t=>{let n=typeof t;return n===`object`?(0,e.guessObjectType)(t):n},e.instanceOfHashable=e=>typeof e.toHashableString==`function`})),I=c((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e._mapSort=e._map=e._objectSort=e._object=e._setCoerce=e._set=e._setSort=e._setSortCoerce=e._typedArray=e._typedArraySort=e._array=e._arraySort=e._date=e._dateCoerce=e._functionTrim=e._functionTrimCoerce=e._function=e._functionCoerce=e._null=e._nullCoerce=e._undefined=e._undefinedCoerce=e._symbol=e._symbolCoerce=e._boolean=e._booleanCoerce=e._bigInt=e._bigIntCoerce=e._number=e._numberCoerce=e._stringTrim=e._stringTrimCoerce=e._string=e._stringCoerce=e._hashable=e.PREFIX=void 0;let t=F();e.PREFIX={string:`<:s>`,number:`<:n>`,bigint:`<:bi>`,boolean:`<:b>`,symbol:`<:smbl>`,undefined:`<:undf>`,null:`<:null>`,function:`<:func>`,array:``,date:`<:date>`,set:`<:set>`,map:`<:map>`};function n(e){return e.toHashableString()}e._hashable=n;function r(e){return e}e._stringCoerce=r;function i(t){return e.PREFIX.string+`:`+t}e._string=i;function a(e){return e.replace(/(\s+|\t|\r\n|\n|\r)/gm,` `).trim()}e._stringTrimCoerce=a;function o(t){return e.PREFIX.string+`:`+t.replace(/(\s+|\t|\r\n|\n|\r)/gm,` `).trim()}e._stringTrim=o;function s(e){return e.toString()}e._numberCoerce=s;function c(t){return`${e.PREFIX.number}:${t}`}e._number=c;function l(e){return e.toString()}e._bigIntCoerce=l;function u(t){return`${e.PREFIX.bigint}:${t.toString()}`}e._bigInt=u;function d(e){return e?`1`:`0`}e._booleanCoerce=d;function f(t){return e.PREFIX.boolean+`:`+t.toString()}e._boolean=f;function p(){return e.PREFIX.symbol}e._symbolCoerce=p;function m(t){return e.PREFIX.symbol+`:`+t.toString()}e._symbol=m;function h(){return``}e._undefinedCoerce=h;function g(){return e.PREFIX.undefined}e._undefined=g;function _(){return``}e._nullCoerce=_;function v(){return e.PREFIX.null}e._null=v;function y(e){return e.name+`=>`+e.toString()}e._functionCoerce=y;function b(t){return e.PREFIX.function+`:`+t.name+`=>`+t.toString()}e._function=b;function x(e){return e.name+`=>`+e.toString().replace(/(\s+|\t|\r\n|\n|\r)/gm,` `).trim()}e._functionTrimCoerce=x;function S(t){return e.PREFIX.function+`:`+t.name+`=>`+t.toString().replace(/(\s+|\t|\r\n|\n|\r)/gm,` `).trim()}e._functionTrim=S;function C(e){return e.toISOString()}e._dateCoerce=C;function w(t){return e.PREFIX.date+`:`+t.toISOString()}e._date=w;function T(e){let n=this;return`[`+e.map(e=>n[(0,t.guessType)(e)](e)).sort().toString()+`]`}e._arraySort=T;function E(e){let n=this;return`[`+e.map(e=>n[(0,t.guessType)(e)](e)).toString()+`]`}e._array=E;function D(e){let n=this;return`[`+Array.prototype.slice.call(e).map(e=>n[(0,t.guessType)(e)](e)).sort().toString()+`]`}e._typedArraySort=D;function O(e){let n=this;return`[`+Array.prototype.slice.call(e).map(e=>n[(0,t.guessType)(e)](e)).toString()+`]`}e._typedArray=O;function k(e){return T.call(this,Array.from(e))}e._setSortCoerce=k;function A(t){return`${e.PREFIX.set}:${T.call(this,Array.from(t))}`}e._setSort=A;function j(t){return`${e.PREFIX.set}:${E.call(this,Array.from(t))}`}e._set=j;function M(e){return E.call(this,Array.from(e))}e._setCoerce=M;function N(e){let n=this,r=Object.keys(e),i=[];for(let a of r){let r=e[a],o=(0,t.guessType)(r);i.push(a+`:`+n[o](r))}return`{`+i.toString()+`}`}e._object=N;function P(e){let n=this,r=Object.keys(e).sort(),i=[];for(let a of r){let r=e[a],o=(0,t.guessType)(r);i.push(a+`:`+n[o](r))}return`{`+i.toString()+`}`}e._objectSort=P;function I(e){let n=this,r=Array.from(e),i=[];for(let e of r){let[r,a]=e;i.push([n[(0,t.guessType)(r)](r),n[(0,t.guessType)(a)](a)])}return`[`+i.join(`;`)+`]`}e._map=I;function L(e){let n=this,r=Array.from(e),i=[];for(let e of r){let[r,a]=e;i.push([n[(0,t.guessType)(r)](r),n[(0,t.guessType)(a)](a)])}return`[`+i.sort().join(`;`)+`]`}e._mapSort=L})),L=c((e=>{var t=e&&e.__createBinding||(Object.create?(function(e,t,n,r){r===void 0&&(r=n);var i=Object.getOwnPropertyDescriptor(t,n);(!i||(`get`in i?!t.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,i)}):(function(e,t,n,r){r===void 0&&(r=n),e[r]=t[n]})),n=e&&e.__setModuleDefault||(Object.create?(function(e,t){Object.defineProperty(e,`default`,{enumerable:!0,value:t})}):function(e,t){e.default=t}),r=e&&e.__importStar||function(e){if(e&&e.__esModule)return e;var r={};if(e!=null)for(var i in e)i!==`default`&&Object.prototype.hasOwnProperty.call(e,i)&&t(r,e,i);return n(r,e),r};Object.defineProperty(e,`__esModule`,{value:!0}),e.objectSorter=void 0;let i=r(I()),a=F();e.objectSorter=e=>{let{sort:t,coerce:n,trim:r}={sort:!0,coerce:!0,trim:!1,...e},o={array:typeof t==`boolean`?t:t?.array??!1,typedArray:typeof t==`boolean`?!1:t?.typedArray??!1,object:typeof t==`boolean`?t:t?.object??!1,set:typeof t==`boolean`?t:t?.set??!1,map:typeof t==`boolean`?t:t?.map??!1},s={boolean:typeof n==`boolean`?n:n?.boolean??!1,number:typeof n==`boolean`?n:n?.number??!1,bigint:typeof n==`boolean`?n:n?.bigint??!1,string:typeof n==`boolean`?n:n?.string??!1,undefined:typeof n==`boolean`?n:n?.undefined??!1,null:typeof n==`boolean`?n:n?.null??!1,symbol:typeof n==`boolean`?n:n?.symbol??!1,function:typeof n==`boolean`?n:n?.function??!1,date:typeof n==`boolean`?n:n?.date??!1,set:typeof n==`boolean`?n:n?.set??!1},c={string:typeof r==`boolean`?r:r?.string??!1,function:typeof r==`boolean`?r:r?.function??!1},l={unknown:function(e){let t=e.constructor?.name??`unknonw`,n=`unknown`;return typeof e.toString==`function`?n=e.toString():Object.keys(e).length>0&&(n=JSON.stringify(e)),`<:${t}>:${n}`}};l.hashable=i._hashable.bind(l),c.string?l.string=s.string?i._stringTrimCoerce.bind(l):i._stringTrim.bind(l):l.string=s.string?i._stringCoerce.bind(l):i._string.bind(l),l.number=s.number?i._numberCoerce.bind(l):i._number.bind(l),l.bigint=s.bigint?i._bigIntCoerce.bind(l):i._bigInt.bind(l),l.boolean=s.boolean?i._booleanCoerce.bind(l):i._boolean.bind(l),l.symbol=s.symbol?i._symbolCoerce.bind(l):i._symbol.bind(l),l.undefined=s.undefined?i._undefinedCoerce.bind(l):i._undefined.bind(l),l.null=s.null?i._nullCoerce.bind(l):i._null.bind(l),c.function?l.function=s.function?i._functionTrimCoerce.bind(l):i._functionTrim.bind(l):l.function=s.function?i._functionCoerce.bind(l):i._function.bind(l),l.date=s.date?i._dateCoerce.bind(l):i._date.bind(l),l.array=o.array?i._arraySort.bind(l):i._array.bind(l),l.typedarray=o.typedArray?i._typedArraySort.bind(l):i._typedArray.bind(l),o.set?l.set=s.set?i._setSortCoerce.bind(l):i._setSort.bind(l):l.set=s.set?i._setCoerce.bind(l):i._set.bind(l),l.object=o.object?i._objectSort.bind(l):i._object.bind(l),l.map=o.map?i._mapSort.bind(l):i._map.bind(l);function u(e){return l[(0,a.guessType)(e)](e)}return u}}));const{hash:R}=(0,u(c((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.hasher=void 0;let t=d(`crypto`),n=L();e.hasher=e=>{let r=(0,n.objectSorter)(e);return{hash:(n,i)=>{let a=i?.alg||e?.alg||`sha256`,o=i?.enc||e?.enc||`hex`,s=r(n);return(0,t.createHash)(a).update(s).digest(o)},sort:r,sortObject:r}}}))(),1).hasher)({sort:!0,coerce:!0});var z=R;const B={},V=e=>(t,{cacheTimeMs:n=0,staleTimeMs:r=0,calculateKey:i=z,revalidationConcurrency:a=1,prefix:o=`default`,shouldStore:s=()=>!0}={})=>async(...c)=>{let l=`${t.name}:${o}:${i?i(c):z(c)}`,u=`${t.name}:${o}`;B[u]=B[u]??new P({concurrency:a}),B[u].concurrency=a;let d=await e.getItem(l),f=async()=>{let i=await t(...c);return s(i)&&await e.setItem(l,i,{ttl:n,staleTtl:r}),i};return n===0&&r===0?f():d&&!d.meta.expired?d.content:d?.meta.expired&&d?.meta.stale?(B[u].runningTasks.some(e=>e.id===l&&e.startTime)||B[u].add(f,{id:l}),d.content):await f()};export{p as CacheContainer,D as FallbackStorage,E as LRUStorage,V as withCacheFactory};
2
2
  //# sourceMappingURL=index.mjs.map