limited-cache 2.2.0 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +4 -3
  3. package/dist/cjs/index.cjs +273 -380
  4. package/dist/cjs/index.d.cts +84 -76
  5. package/dist/cjs/index.d.cts.map +1 -0
  6. package/dist/esm/index.d.ts +99 -6
  7. package/dist/esm/index.d.ts.map +1 -1
  8. package/dist/esm/index.js +279 -6
  9. package/dist/esm/index.js.map +1 -1
  10. package/package.json +34 -53
  11. package/src/__tests__/LimitedCache.test.ts +2 -2
  12. package/src/__tests__/LimitedCacheObject.test.ts +30 -27
  13. package/src/__tests__/lowLevelFunctions.test.ts +10 -8
  14. package/src/__tests__/scenarios/keys.test.ts +2 -2
  15. package/src/__tests__/scenarios/maxCacheSize.test.ts +8 -5
  16. package/src/__tests__/scenarios/maxCacheTime.test.ts +58 -58
  17. package/src/__tests__/scenarios/values.test.ts +2 -2
  18. package/src/__tests__/typeChecks/LimitedCacheObjectTypes.test.ts +15 -15
  19. package/src/__tests__/typeChecks/LimitedCacheTypes.test.ts +1 -1
  20. package/src/__tests__/typeChecks/lowLevelFunctionsTypes.test.ts +2 -2
  21. package/src/core/LimitedCache.ts +20 -21
  22. package/src/core/LimitedCacheObject.ts +30 -19
  23. package/src/core/defaultOptions.ts +5 -4
  24. package/src/core/limitedCacheUtil.ts +15 -3
  25. package/src/core/lowLevelFunctions.ts +43 -32
  26. package/src/types.ts +4 -3
  27. package/dist/esm/core/LimitedCache.d.ts +0 -4
  28. package/dist/esm/core/LimitedCache.d.ts.map +0 -1
  29. package/dist/esm/core/LimitedCache.js +0 -29
  30. package/dist/esm/core/LimitedCache.js.map +0 -1
  31. package/dist/esm/core/LimitedCacheObject.d.ts +0 -5
  32. package/dist/esm/core/LimitedCacheObject.d.ts.map +0 -1
  33. package/dist/esm/core/LimitedCacheObject.js +0 -52
  34. package/dist/esm/core/LimitedCacheObject.js.map +0 -1
  35. package/dist/esm/core/builtIns.d.ts +0 -12
  36. package/dist/esm/core/builtIns.d.ts.map +0 -1
  37. package/dist/esm/core/builtIns.js +0 -5
  38. package/dist/esm/core/builtIns.js.map +0 -1
  39. package/dist/esm/core/defaultOptions.d.ts +0 -6
  40. package/dist/esm/core/defaultOptions.d.ts.map +0 -1
  41. package/dist/esm/core/defaultOptions.js +0 -14
  42. package/dist/esm/core/defaultOptions.js.map +0 -1
  43. package/dist/esm/core/limitedCacheUtil.d.ts +0 -13
  44. package/dist/esm/core/limitedCacheUtil.d.ts.map +0 -1
  45. package/dist/esm/core/limitedCacheUtil.js +0 -14
  46. package/dist/esm/core/limitedCacheUtil.js.map +0 -1
  47. package/dist/esm/core/lowLevelFunctions.d.ts +0 -14
  48. package/dist/esm/core/lowLevelFunctions.d.ts.map +0 -1
  49. package/dist/esm/core/lowLevelFunctions.js +0 -240
  50. package/dist/esm/core/lowLevelFunctions.js.map +0 -1
  51. package/dist/esm/types.d.ts +0 -58
  52. package/dist/esm/types.d.ts.map +0 -1
  53. package/dist/esm/types.js +0 -2
  54. package/dist/esm/types.js.map +0 -1
  55. package/legacy-types/ts3.5/dist/esm/core/LimitedCache.d.ts +0 -4
  56. package/legacy-types/ts3.5/dist/esm/core/LimitedCacheObject.d.ts +0 -5
  57. package/legacy-types/ts3.5/dist/esm/core/builtIns.d.ts +0 -12
  58. package/legacy-types/ts3.5/dist/esm/core/defaultOptions.d.ts +0 -6
  59. package/legacy-types/ts3.5/dist/esm/core/limitedCacheUtil.d.ts +0 -13
  60. package/legacy-types/ts3.5/dist/esm/core/lowLevelFunctions.d.ts +0 -14
  61. package/legacy-types/ts3.5/dist/esm/index.d.ts +0 -7
  62. package/legacy-types/ts3.5/dist/esm/types.d.ts +0 -61
  63. package/legacy-types/ts4.0/dist/esm/core/LimitedCache.d.ts +0 -4
  64. package/legacy-types/ts4.0/dist/esm/core/LimitedCacheObject.d.ts +0 -5
  65. package/legacy-types/ts4.0/dist/esm/core/builtIns.d.ts +0 -12
  66. package/legacy-types/ts4.0/dist/esm/core/defaultOptions.d.ts +0 -6
  67. package/legacy-types/ts4.0/dist/esm/core/limitedCacheUtil.d.ts +0 -13
  68. package/legacy-types/ts4.0/dist/esm/core/lowLevelFunctions.d.ts +0 -14
  69. package/legacy-types/ts4.0/dist/esm/index.d.ts +0 -7
  70. package/legacy-types/ts4.0/dist/esm/types.d.ts +0 -61
  71. package/legacy-types/ts4.5/dist/esm/core/LimitedCache.d.ts +0 -4
  72. package/legacy-types/ts4.5/dist/esm/core/LimitedCacheObject.d.ts +0 -5
  73. package/legacy-types/ts4.5/dist/esm/core/builtIns.d.ts +0 -12
  74. package/legacy-types/ts4.5/dist/esm/core/defaultOptions.d.ts +0 -6
  75. package/legacy-types/ts4.5/dist/esm/core/limitedCacheUtil.d.ts +0 -13
  76. package/legacy-types/ts4.5/dist/esm/core/lowLevelFunctions.d.ts +0 -14
  77. package/legacy-types/ts4.5/dist/esm/index.d.ts +0 -7
  78. package/legacy-types/ts4.5/dist/esm/types.d.ts +0 -61
  79. package/src/core/builtIns.ts +0 -9
@@ -1,24 +1,24 @@
1
- import { objectAssign, objectCreate, dateNow, hasOwnProperty } from './builtIns.js';
2
- import { CURRENT_META_VERSION, MAXIMUM_CACHE_TIME, defaultOptions } from './defaultOptions.js';
3
- import {
4
- LimitedCacheOptions,
5
- LimitedCacheOptionsReadonly,
1
+ import type {
2
+ DefaultItemType,
6
3
  LimitedCacheMeta,
4
+ LimitedCacheOptions,
7
5
  LimitedCacheOptionsFull,
8
- DefaultItemType,
6
+ LimitedCacheOptionsReadonly,
9
7
  } from '../types.js';
8
+ import { CURRENT_META_VERSION, defaultOptions, MAXIMUM_CACHE_TIME } from './defaultOptions.js';
10
9
 
11
10
  /* Initialization and options */
12
11
 
13
12
  const positiveNumberOrZero = (value: number): number => Math.max(value, 0) || 0;
14
13
 
15
14
  const normalizeOptions = (cacheMetaOptions: LimitedCacheOptionsFull): LimitedCacheOptionsFull => {
16
- objectAssign(cacheMetaOptions, {
15
+ Object.assign(cacheMetaOptions, {
17
16
  maxCacheSize: positiveNumberOrZero(cacheMetaOptions.maxCacheSize),
18
17
  maxCacheTime: positiveNumberOrZero(cacheMetaOptions.maxCacheTime),
19
18
  opLimit: positiveNumberOrZero(cacheMetaOptions.opLimit),
20
19
  });
21
20
 
21
+ // @ts-expect-error `process.env.NODE_ENV` left intact and not added to global typings
22
22
  if (process.env.NODE_ENV !== 'production') {
23
23
  cacheMetaOptions.warnIfItemPurgedBeforeTime = positiveNumberOrZero(
24
24
  cacheMetaOptions.warnIfItemPurgedBeforeTime,
@@ -27,8 +27,9 @@ const normalizeOptions = (cacheMetaOptions: LimitedCacheOptionsFull): LimitedCac
27
27
  return cacheMetaOptions;
28
28
  };
29
29
 
30
- const isCacheMeta = (cacheMeta: LimitedCacheMeta): boolean => {
31
- return !!cacheMeta && !!cacheMeta.limitedCacheMetaVersion;
30
+ const isCacheMeta = (cacheMeta: unknown): cacheMeta is LimitedCacheMeta => {
31
+ // @ts-expect-error Duck-typing the unknown value
32
+ return !!cacheMeta?.limitedCacheMetaVersion;
32
33
  };
33
34
 
34
35
  const upgradeCacheMeta = (cacheMeta: LimitedCacheMeta): void => {
@@ -38,6 +39,7 @@ const upgradeCacheMeta = (cacheMeta: LimitedCacheMeta): void => {
38
39
  if (cacheMeta.limitedCacheMetaVersion !== CURRENT_META_VERSION) {
39
40
  // Version is out of date! (Today the only prior version is 1)
40
41
  // Version 1: Cache meta cannot be migrated because timestamps and keys are incompatible
42
+ // biome-ignore lint/suspicious/noConsole: Intentional warning
41
43
  console.warn('Limited-cache metadata is from an incompatible version (1). It must be reset.');
42
44
  cacheMeta.limitedCacheMetaVersion = CURRENT_META_VERSION;
43
45
  lowLevelReset(cacheMeta);
@@ -49,19 +51,22 @@ const lowLevelSetOptions = <ItemType = DefaultItemType>(
49
51
  options: LimitedCacheOptions,
50
52
  ): LimitedCacheOptionsReadonly => {
51
53
  upgradeCacheMeta(cacheMeta);
52
- return normalizeOptions(objectAssign(cacheMeta.options, options));
54
+ return normalizeOptions(Object.assign(cacheMeta.options, options));
53
55
  };
54
56
 
55
57
  const lowLevelInit = <ItemType = DefaultItemType>(
56
58
  optionsOrCacheMeta?: LimitedCacheOptions | LimitedCacheMeta<ItemType>,
57
59
  ): LimitedCacheMeta<ItemType> => {
58
- if (isCacheMeta(optionsOrCacheMeta as LimitedCacheMeta<ItemType>)) {
59
- const existingCacheMeta = optionsOrCacheMeta as LimitedCacheMeta<ItemType>;
60
+ if (isCacheMeta(optionsOrCacheMeta)) {
61
+ const existingCacheMeta = optionsOrCacheMeta;
60
62
  upgradeCacheMeta(existingCacheMeta);
61
63
  return existingCacheMeta;
62
64
  }
63
65
  // Else: it's options
64
- const fullOptions = normalizeOptions({ ...defaultOptions, ...optionsOrCacheMeta });
66
+ const fullOptions = normalizeOptions({
67
+ ...defaultOptions,
68
+ ...optionsOrCacheMeta,
69
+ });
65
70
 
66
71
  // The cacheMeta is created once, and persists per instance
67
72
  const newCacheMeta = lowLevelReset({
@@ -101,7 +106,7 @@ const lowLevelDoMaintenance = <ItemType = DefaultItemType>(
101
106
  ): LimitedCacheMeta<ItemType> => {
102
107
  upgradeCacheMeta(cacheMeta);
103
108
  const { cache, keyList, keyInfo } = cacheMeta;
104
- const now = dateNow();
109
+ const now = Date.now();
105
110
 
106
111
  // Rebuild cache from keyList only, checking timestamps to auto-remove expired
107
112
  const [newCache, newKeyList, newKeyInfo] = keyList.reduce(
@@ -115,13 +120,15 @@ const lowLevelDoMaintenance = <ItemType = DefaultItemType>(
115
120
  return acc;
116
121
  },
117
122
  [
123
+ // This manual assertion is required because TypeScript doesn't know that the initial value is of the same type as the accumulator.
124
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
118
125
  {} as (typeof cacheMeta)['cache'],
119
126
  [] as (typeof cacheMeta)['keyList'],
120
- objectCreate(null) as (typeof cacheMeta)['keyInfo'],
127
+ Object.create(null) as (typeof cacheMeta)['keyInfo'],
121
128
  ],
122
129
  );
123
130
 
124
- return objectAssign(cacheMeta, {
131
+ return Object.assign(cacheMeta, {
125
132
  cache: newCache,
126
133
  keyList: newKeyList,
127
134
  keyInfo: newKeyInfo,
@@ -134,7 +141,7 @@ const _removeFromIndex = (cacheMeta: LimitedCacheMeta, startIndex: number, now:
134
141
 
135
142
  // Always remove the item requested, and also remove any neighbors who have expired
136
143
  let nextIndex = startIndex;
137
- let nextCacheKey = keyList[startIndex];
144
+ let nextCacheKey = keyList[startIndex] as string;
138
145
  const keyListLength = keyList.length;
139
146
  do {
140
147
  // Remove the 'next' item
@@ -143,7 +150,7 @@ const _removeFromIndex = (cacheMeta: LimitedCacheMeta, startIndex: number, now:
143
150
 
144
151
  // Now advance and decide whether to keep going
145
152
  nextIndex++;
146
- nextCacheKey = keyList[nextIndex];
153
+ nextCacheKey = keyList[nextIndex] as string;
147
154
  } while (nextIndex < keyListLength && _cacheKeyHasExpired(cacheMeta, nextCacheKey, now));
148
155
 
149
156
  // Remove the index for everything from the startIndex until we stopped
@@ -161,14 +168,14 @@ const _removeItemsToMakeRoom = (cacheMeta: LimitedCacheMeta, now: number): void
161
168
  // These track the soonest-to-expire thing we've found. It may not actually be "oldest".
162
169
  // By default we'll remove the item at the head of the queue, unless we find something better.
163
170
  let oldestItemIndex = 0;
164
- let oldestExpireTime = _getExpireTime(cacheMeta, keyList[0]);
171
+ let oldestExpireTime = _getExpireTime(cacheMeta, keyList[0] as string);
165
172
 
166
173
  if (oldestExpireTime > now) {
167
174
  // The head of the list hasn't yet expired: scan for a better candidate to remove
168
175
  let indexToCheck = 0;
169
176
  const maxIndexToCheck = Math.min(keyList.length, scanLimit);
170
177
  while (indexToCheck < maxIndexToCheck) {
171
- const cacheKeyForIndex = keyList[indexToCheck];
178
+ const cacheKeyForIndex = keyList[indexToCheck] as string;
172
179
  const expireTimeForIndex = _getExpireTime(cacheMeta, cacheKeyForIndex);
173
180
 
174
181
  // We only consider it if it's eligible for expiration: otherwise it can't be a better option
@@ -191,19 +198,22 @@ const _removeItemsToMakeRoom = (cacheMeta: LimitedCacheMeta, now: number): void
191
198
  // Warn if the 'oldest' item is more recent than we'd like: this means it cycled into and out of
192
199
  // cache too quickly for the cache to be useful.
193
200
  if (
201
+ // @ts-expect-error `process.env.NODE_ENV` left intact and not added to global typings
194
202
  process.env.NODE_ENV !== 'production' &&
195
203
  warnIfItemPurgedBeforeTime &&
196
204
  oldestExpireTime > now
197
205
  ) {
198
- const oldestItemKey = keyList[oldestItemIndex];
206
+ const oldestItemKey = keyList[oldestItemIndex] as string;
199
207
  const [oldestItemSetTime, oldestItemExpireTime] = keyInfo[oldestItemKey] as [number, number];
200
208
 
201
209
  if (now - oldestItemSetTime < warnIfItemPurgedBeforeTime) {
210
+ // biome-ignore lint/suspicious/noConsole: Dev-only code
202
211
  console.warn(
203
212
  'Purged an item from cache while it was still fresh: you may want to increase maxCacheSize',
204
213
  {
205
214
  currentTime: now,
206
215
  key: oldestItemKey,
216
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
207
217
  item: cache[oldestItemKey],
208
218
  setTime: oldestItemSetTime,
209
219
  expireTime: oldestItemExpireTime,
@@ -225,8 +235,9 @@ const lowLevelHas = <ItemType = DefaultItemType>(
225
235
  ): boolean => {
226
236
  upgradeCacheMeta(cacheMeta);
227
237
  const { cache } = cacheMeta;
228
- if (hasOwnProperty.call(cache, cacheKey) && cache[cacheKey] !== undefined) {
229
- if (!_cacheKeyHasExpired(cacheMeta, cacheKey, dateNow())) {
238
+ // biome-ignore lint/suspicious/noPrototypeBuiltins: Keeping the legacy hasOwnProperty to avoid a breaking change
239
+ if (Object.prototype.hasOwnProperty.call(cache, cacheKey) && cache[cacheKey] !== undefined) {
240
+ if (!_cacheKeyHasExpired(cacheMeta, cacheKey, Date.now())) {
230
241
  return true;
231
242
  }
232
243
  // If it's expired, clear the value so that we can short-circuit future lookups
@@ -269,7 +280,7 @@ const lowLevelSet = <ItemType = DefaultItemType>(
269
280
  keyInfo,
270
281
  } = cacheMeta;
271
282
 
272
- const now = dateNow();
283
+ const now = Date.now();
273
284
  const isNew = !keyInfo[cacheKey];
274
285
 
275
286
  if (cacheMeta.cache[cacheKey] !== item) {
@@ -299,7 +310,7 @@ const lowLevelSet = <ItemType = DefaultItemType>(
299
310
  }
300
311
  }
301
312
 
302
- if (_cacheKeyHasExpired(cacheMeta, keyList[0], now)) {
313
+ if (_cacheKeyHasExpired(cacheMeta, keyList[0] as string, now)) {
303
314
  // While we're here, if we need to expire the head of the queue then drop it
304
315
  _removeFromIndex(cacheMeta, 0, now);
305
316
  }
@@ -331,24 +342,24 @@ const lowLevelReset = <ItemType = DefaultItemType>(
331
342
  cacheMeta: LimitedCacheMeta<ItemType>,
332
343
  ): LimitedCacheMeta<ItemType> => {
333
344
  upgradeCacheMeta(cacheMeta);
334
- return objectAssign(cacheMeta, {
345
+ return Object.assign(cacheMeta, {
335
346
  cache: {},
336
347
  keyList: [],
337
- keyInfo: objectCreate(null),
348
+ keyInfo: Object.create(null) as Record<string, ItemType>,
338
349
  opsLeft: cacheMeta.options.opLimit,
339
350
  });
340
351
  };
341
352
 
342
353
  export {
343
354
  isCacheMeta,
344
- upgradeCacheMeta,
345
- lowLevelInit,
346
- lowLevelGetOne,
355
+ lowLevelDoMaintenance,
347
356
  lowLevelGetAll,
357
+ lowLevelGetOne,
348
358
  lowLevelHas,
349
- lowLevelSet,
359
+ lowLevelInit,
350
360
  lowLevelRemove,
351
361
  lowLevelReset,
352
- lowLevelDoMaintenance,
362
+ lowLevelSet,
353
363
  lowLevelSetOptions,
364
+ upgradeCacheMeta,
354
365
  };
package/src/types.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  // This makes it easy to ensure that ItemType gets passed to any nested generics:
2
- // Using `unknown` helps catch errors during development but is a pain for consumers.
3
- // Using `any` is nicer for consumers, but errors could slip through during development.
4
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2
+ // * Using `unknown` helps catch errors during development but is a pain for consumers.
3
+ // * Using `any` is nicer for consumers, but errors could slip through during development.
4
+ // In v3.0.0 the default will change from `any` to `unknown`
5
+ // biome-ignore lint/suspicious/noExplicitAny: Intentionally left as any for better DX
5
6
  export type DefaultItemType = any;
6
7
 
7
8
  export interface LimitedCacheOptionsFull {
@@ -1,4 +0,0 @@
1
- import { LimitedCacheOptions, LimitedCacheInstance } from '../types.js';
2
- declare const LimitedCache: <ItemType = any>(options?: LimitedCacheOptions) => LimitedCacheInstance<ItemType>;
3
- export { LimitedCache };
4
- //# sourceMappingURL=LimitedCache.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LimitedCache.d.ts","sourceRoot":"","sources":["../../../src/core/LimitedCache.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,mBAAmB,EAEnB,oBAAoB,EAGrB,MAAM,aAAa,CAAC;AAUrB,QAAA,MAAM,YAAY,6BACN,mBAAmB,mCAsB9B,CAAC;AAEF,OAAO,EAAE,YAAY,EAAE,CAAC"}
@@ -1,29 +0,0 @@
1
- import { lowLevelInit, lowLevelGetOne, lowLevelGetAll, lowLevelHas, lowLevelSet, lowLevelRemove, lowLevelReset, lowLevelSetOptions, lowLevelDoMaintenance, } from './lowLevelFunctions.js';
2
- // Most public functions just call a low-level function directly, passing the cacheMeta.
3
- // Doing this via a helper function makes the typeChecks easier, and minifies better.
4
- const bindFunctionToCacheMeta = (
5
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
- fn, cacheMeta) => fn.bind(null, cacheMeta);
7
- const LimitedCache = (options) => {
8
- const cacheMeta = lowLevelInit(options);
9
- return {
10
- get: bindFunctionToCacheMeta(lowLevelGetOne, cacheMeta),
11
- getAll: bindFunctionToCacheMeta(lowLevelGetAll, cacheMeta),
12
- has: bindFunctionToCacheMeta(lowLevelHas, cacheMeta),
13
- set: (cacheKey, item) => {
14
- lowLevelSet(cacheMeta, cacheKey, item);
15
- return item;
16
- },
17
- remove: (cacheKey) => {
18
- lowLevelRemove(cacheMeta, cacheKey);
19
- return true;
20
- },
21
- reset: bindFunctionToCacheMeta(lowLevelReset, cacheMeta),
22
- getCacheMeta: () => cacheMeta,
23
- getOptions: () => cacheMeta.options,
24
- setOptions: bindFunctionToCacheMeta(lowLevelSetOptions, cacheMeta),
25
- doMaintenance: bindFunctionToCacheMeta(lowLevelDoMaintenance, cacheMeta),
26
- };
27
- };
28
- export { LimitedCache };
29
- //# sourceMappingURL=LimitedCache.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LimitedCache.js","sourceRoot":"","sources":["../../../src/core/LimitedCache.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,cAAc,EACd,cAAc,EACd,WAAW,EACX,WAAW,EACX,cAAc,EACd,aAAa,EACb,kBAAkB,EAClB,qBAAqB,GACtB,MAAM,wBAAwB,CAAC;AAShC,wFAAwF;AACxF,qFAAqF;AACrF,MAAM,uBAAuB,GAAG;AAC9B,8DAA8D;AAC9D,EAAqE,EACrE,SAAqC,EACrC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;AAE9B,MAAM,YAAY,GAAG,CACnB,OAA6B,EACG,EAAE;IAClC,MAAM,SAAS,GAAG,YAAY,CAAW,OAAO,CAAC,CAAC;IAElD,OAAO;QACL,GAAG,EAAE,uBAAuB,CAAW,cAAc,EAAE,SAAS,CAAC;QACjE,MAAM,EAAE,uBAAuB,CAAW,cAAc,EAAE,SAAS,CAAC;QACpE,GAAG,EAAE,uBAAuB,CAAW,WAAW,EAAE,SAAS,CAAC;QAC9D,GAAG,EAAE,CAAC,QAAQ,EAAE,IAAI,EAAY,EAAE;YAChC,WAAW,CAAC,SAAS,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;YACvC,OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,EAAE,CAAC,QAAQ,EAAQ,EAAE;YACzB,cAAc,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;YACpC,OAAO,IAAI,CAAC;QACd,CAAC;QACD,KAAK,EAAE,uBAAuB,CAAW,aAAa,EAAE,SAAS,CAAC;QAClE,YAAY,EAAE,GAA+B,EAAE,CAAC,SAAS;QACzD,UAAU,EAAE,GAAgC,EAAE,CAAC,SAAS,CAAC,OAAO;QAChE,UAAU,EAAE,uBAAuB,CAAW,kBAAkB,EAAE,SAAS,CAAC;QAC5E,aAAa,EAAE,uBAAuB,CAAW,qBAAqB,EAAE,SAAS,CAAC;KACnF,CAAC;AACJ,CAAC,CAAC;AAEF,OAAO,EAAE,YAAY,EAAE,CAAC"}
@@ -1,5 +0,0 @@
1
- import { LimitedCacheOptions, LimitedCacheObjectInstance, LimitedCacheMeta } from '../types.js';
2
- declare const LimitedCacheObject: <ItemType = any>(options?: LimitedCacheOptions) => LimitedCacheObjectInstance<ItemType>;
3
- declare const getCacheMetaFromObject: (instance: LimitedCacheObjectInstance) => LimitedCacheMeta;
4
- export { LimitedCacheObject, getCacheMetaFromObject };
5
- //# sourceMappingURL=LimitedCacheObject.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LimitedCacheObject.d.ts","sourceRoot":"","sources":["../../../src/core/LimitedCacheObject.ts"],"names":[],"mappings":"AASA,OAAO,EACL,mBAAmB,EACnB,0BAA0B,EAC1B,gBAAgB,EAEjB,MAAM,aAAa,CAAC;AA4CrB,QAAA,MAAM,kBAAkB,6BACZ,mBAAmB,yCAO9B,CAAC;AAEF,QAAA,MAAM,sBAAsB,aAAc,0BAA0B,KAAG,gBAEtE,CAAC;AAEF,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,CAAC"}
@@ -1,52 +0,0 @@
1
- import { hasOwnProperty } from './builtIns.js';
2
- import { lowLevelInit, lowLevelGetOne, lowLevelGetAll, lowLevelHas, lowLevelSet, lowLevelRemove, } from './lowLevelFunctions.js';
3
- // The `any` here doesn't escape out anywhere: it's overridden by the constructor below
4
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
- const proxyHandler = {
6
- get: (cacheMeta, cacheKey) => {
7
- if (cacheKey === 'hasOwnProperty') {
8
- return hasOwnProperty;
9
- }
10
- return lowLevelGetOne(cacheMeta, cacheKey);
11
- },
12
- getOwnPropertyDescriptor: (cacheMeta, cacheKey) => {
13
- const hasResult = lowLevelHas(cacheMeta, cacheKey);
14
- const getResult = lowLevelGetOne(cacheMeta, cacheKey);
15
- if (hasResult) {
16
- return {
17
- configurable: true,
18
- enumerable: hasResult,
19
- value: getResult,
20
- writable: true,
21
- };
22
- }
23
- return;
24
- },
25
- has: lowLevelHas,
26
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
- set: (cacheMeta, cacheKey, item) => {
28
- lowLevelSet(cacheMeta, cacheKey, item);
29
- return item;
30
- },
31
- deleteProperty: (cacheMeta, cacheKey) => {
32
- lowLevelRemove(cacheMeta, cacheKey);
33
- return true;
34
- },
35
- ownKeys: (cacheMeta) => Object.keys(lowLevelGetAll(cacheMeta)),
36
- };
37
- /**
38
- * So that we can retrieve the cacheMeta for a LimitedCacheObject, without polluting its properties, each proxy
39
- * is associated back to its internal cacheMeta here.
40
- */
41
- const cacheMetasForProxies = new WeakMap();
42
- const LimitedCacheObject = (options) => {
43
- const cacheMeta = lowLevelInit(options);
44
- const limitedCacheObject = new Proxy(cacheMeta, proxyHandler);
45
- cacheMetasForProxies.set(limitedCacheObject, cacheMeta);
46
- return limitedCacheObject;
47
- };
48
- const getCacheMetaFromObject = (instance) => {
49
- return cacheMetasForProxies.get(instance);
50
- };
51
- export { LimitedCacheObject, getCacheMetaFromObject };
52
- //# sourceMappingURL=LimitedCacheObject.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LimitedCacheObject.js","sourceRoot":"","sources":["../../../src/core/LimitedCacheObject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EACL,YAAY,EACZ,cAAc,EACd,cAAc,EACd,WAAW,EACX,WAAW,EACX,cAAc,GACf,MAAM,wBAAwB,CAAC;AAQhC,uFAAuF;AACvF,8DAA8D;AAC9D,MAAM,YAAY,GAAkD;IAClE,GAAG,EAAE,CAAC,SAA2B,EAAE,QAAgB,EAAE,EAAE;QACrD,IAAI,QAAQ,KAAK,gBAAgB,EAAE,CAAC;YAClC,OAAO,cAAc,CAAC;QACxB,CAAC;QACD,OAAO,cAAc,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IAC7C,CAAC;IACD,wBAAwB,EAAE,CAAC,SAA2B,EAAE,QAAgB,EAAE,EAAE;QAC1E,MAAM,SAAS,GAAG,WAAW,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QACnD,MAAM,SAAS,GAAG,cAAc,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QAEtD,IAAI,SAAS,EAAE,CAAC;YACd,OAAO;gBACL,YAAY,EAAE,IAAI;gBAClB,UAAU,EAAE,SAAS;gBACrB,KAAK,EAAE,SAAS;gBAChB,QAAQ,EAAE,IAAI;aACf,CAAC;QACJ,CAAC;QACD,OAAO;IACT,CAAC;IACD,GAAG,EAAE,WAAW;IAChB,8DAA8D;IAC9D,GAAG,EAAE,CAAC,SAA2B,EAAE,QAAgB,EAAE,IAAS,EAAO,EAAE;QACrE,WAAW,CAAC,SAAS,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;QACvC,OAAO,IAAI,CAAC;IACd,CAAC;IACD,cAAc,EAAE,CAAC,SAA2B,EAAE,QAAgB,EAAQ,EAAE;QACtE,cAAc,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QACpC,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,EAAE,CAAC,SAA2B,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;CACjF,CAAC;AAEF;;;GAGG;AACH,MAAM,oBAAoB,GAAG,IAAI,OAAO,EAAE,CAAC;AAE3C,MAAM,kBAAkB,GAAG,CACzB,OAA6B,EACS,EAAE;IACxC,MAAM,SAAS,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;IACxC,MAAM,kBAAkB,GAAG,IAAI,KAAK,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;IAE9D,oBAAoB,CAAC,GAAG,CAAC,kBAAkB,EAAE,SAAS,CAAC,CAAC;IACxD,OAAO,kBAAkB,CAAC;AAC5B,CAAC,CAAC;AAEF,MAAM,sBAAsB,GAAG,CAAC,QAAoC,EAAoB,EAAE;IACxF,OAAO,oBAAoB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC5C,CAAC,CAAC;AAEF,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,CAAC"}
@@ -1,12 +0,0 @@
1
- declare const objectCreate: {
2
- (o: object | null): any;
3
- (o: object | null, properties: PropertyDescriptorMap & ThisType<any>): any;
4
- }, objectAssign: {
5
- <T extends {}, U>(target: T, source: U): T & U;
6
- <T_1 extends {}, U_1, V>(target: T_1, source1: U_1, source2: V): T_1 & U_1 & V;
7
- <T_2 extends {}, U_2, V_1, W>(target: T_2, source1: U_2, source2: V_1, source3: W): T_2 & U_2 & V_1 & W;
8
- (target: object, ...sources: any[]): any;
9
- }, hasOwnProperty: (v: PropertyKey) => boolean;
10
- declare const dateNow: () => number;
11
- export { objectAssign, objectCreate, dateNow, hasOwnProperty };
12
- //# sourceMappingURL=builtIns.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"builtIns.d.ts","sourceRoot":"","sources":["../../../src/core/builtIns.ts"],"names":[],"mappings":"AACA,QAAA,MACU,YAAY;;;GACZ,YAAY;;;;;GACP,cAAc,6BACnB,CAAC;AACX,QAAA,MAAM,OAAO,cAAW,CAAC;AAEzB,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC"}
@@ -1,5 +0,0 @@
1
- // To help minification
2
- const { create: objectCreate, assign: objectAssign, prototype: { hasOwnProperty }, } = Object;
3
- const dateNow = Date.now;
4
- export { objectAssign, objectCreate, dateNow, hasOwnProperty };
5
- //# sourceMappingURL=builtIns.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"builtIns.js","sourceRoot":"","sources":["../../../src/core/builtIns.ts"],"names":[],"mappings":"AAAA,uBAAuB;AACvB,MAAM,EACJ,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,YAAY,EACpB,SAAS,EAAE,EAAE,cAAc,EAAE,GAC9B,GAAG,MAAM,CAAC;AACX,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC;AAEzB,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC"}
@@ -1,6 +0,0 @@
1
- import { LimitedCacheOptionsReadonly } from '../types.js';
2
- declare const CURRENT_META_VERSION = 2;
3
- declare const MAXIMUM_CACHE_TIME: number;
4
- declare const defaultOptions: LimitedCacheOptionsReadonly;
5
- export { CURRENT_META_VERSION, MAXIMUM_CACHE_TIME, defaultOptions };
6
- //# sourceMappingURL=defaultOptions.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"defaultOptions.d.ts","sourceRoot":"","sources":["../../../src/core/defaultOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AAE1D,QAAA,MAAM,oBAAoB,IAAI,CAAC;AAC/B,QAAA,MAAM,kBAAkB,QAAqB,CAAC;AAE9C,QAAA,MAAM,cAAc,EAAE,2BASrB,CAAC;AAEF,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,cAAc,EAAE,CAAC"}
@@ -1,14 +0,0 @@
1
- const CURRENT_META_VERSION = 2;
2
- const MAXIMUM_CACHE_TIME = 365 * 86400 * 1000;
3
- const defaultOptions = {
4
- // Public
5
- maxCacheSize: 100,
6
- maxCacheTime: 86400 * 1000,
7
- // Development-only
8
- warnIfItemPurgedBeforeTime: 5000,
9
- // Private
10
- opLimit: 200,
11
- scanLimit: 50,
12
- };
13
- export { CURRENT_META_VERSION, MAXIMUM_CACHE_TIME, defaultOptions };
14
- //# sourceMappingURL=defaultOptions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"defaultOptions.js","sourceRoot":"","sources":["../../../src/core/defaultOptions.ts"],"names":[],"mappings":"AAEA,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAC/B,MAAM,kBAAkB,GAAG,GAAG,GAAG,KAAK,GAAG,IAAI,CAAC;AAE9C,MAAM,cAAc,GAAgC;IAClD,SAAS;IACT,YAAY,EAAE,GAAG;IACjB,YAAY,EAAE,KAAK,GAAG,IAAI;IAC1B,mBAAmB;IACnB,0BAA0B,EAAE,IAAI;IAChC,UAAU;IACV,OAAO,EAAE,GAAG;IACZ,SAAS,EAAE,EAAE;CACd,CAAC;AAEF,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,cAAc,EAAE,CAAC"}
@@ -1,13 +0,0 @@
1
- declare const limitedCacheUtil: {
2
- init: <ItemType = any>(optionsOrCacheMeta?: import("../types.js").LimitedCacheOptions | import("../types.js").LimitedCacheMeta<ItemType> | undefined) => import("../types.js").LimitedCacheMeta<ItemType>;
3
- get: <ItemType_1 = any>(cacheMeta: import("../types.js").LimitedCacheMeta<ItemType_1>, cacheKey: string) => ItemType_1 | undefined;
4
- getAll: <ItemType_2 = any>(cacheMeta: import("../types.js").LimitedCacheMeta<ItemType_2>) => Record<string, ItemType_2>;
5
- has: <ItemType_3 = any>(cacheMeta: import("../types.js").LimitedCacheMeta<ItemType_3>, cacheKey: string) => boolean;
6
- set: <ItemType_4 = any>(cacheMeta: import("../types.js").LimitedCacheMeta<ItemType_4>, cacheKey: string, item: ItemType_4) => import("../types.js").LimitedCacheMeta<ItemType_4>;
7
- remove: <ItemType_5 = any>(cacheMeta: import("../types.js").LimitedCacheMeta<ItemType_5>, cacheKey: string) => import("../types.js").LimitedCacheMeta<ItemType_5>;
8
- reset: <ItemType_6 = any>(cacheMeta: import("../types.js").LimitedCacheMeta<ItemType_6>) => import("../types.js").LimitedCacheMeta<ItemType_6>;
9
- doMaintenance: <ItemType_7 = any>(cacheMeta: import("../types.js").LimitedCacheMeta<ItemType_7>) => import("../types.js").LimitedCacheMeta<ItemType_7>;
10
- setOptions: <ItemType_8 = any>(cacheMeta: import("../types.js").LimitedCacheMeta<ItemType_8>, options: import("../types.js").LimitedCacheOptions) => Readonly<import("../types.js").LimitedCacheOptionsFull>;
11
- };
12
- export { limitedCacheUtil };
13
- //# sourceMappingURL=limitedCacheUtil.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"limitedCacheUtil.d.ts","sourceRoot":"","sources":["../../../src/core/limitedCacheUtil.ts"],"names":[],"mappings":"AAYA,QAAA,MAAM,gBAAgB;;;;;;;;;;CAUrB,CAAC;AAEF,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
@@ -1,14 +0,0 @@
1
- import { lowLevelGetOne, lowLevelGetAll, lowLevelHas, lowLevelInit, lowLevelDoMaintenance, lowLevelRemove, lowLevelReset, lowLevelSet, lowLevelSetOptions, } from './lowLevelFunctions.js';
2
- const limitedCacheUtil = {
3
- init: lowLevelInit,
4
- get: lowLevelGetOne,
5
- getAll: lowLevelGetAll,
6
- has: lowLevelHas,
7
- set: lowLevelSet,
8
- remove: lowLevelRemove,
9
- reset: lowLevelReset,
10
- doMaintenance: lowLevelDoMaintenance,
11
- setOptions: lowLevelSetOptions,
12
- };
13
- export { limitedCacheUtil };
14
- //# sourceMappingURL=limitedCacheUtil.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"limitedCacheUtil.js","sourceRoot":"","sources":["../../../src/core/limitedCacheUtil.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,EACd,WAAW,EACX,YAAY,EACZ,qBAAqB,EACrB,cAAc,EACd,aAAa,EACb,WAAW,EACX,kBAAkB,GACnB,MAAM,wBAAwB,CAAC;AAEhC,MAAM,gBAAgB,GAAG;IACvB,IAAI,EAAE,YAAY;IAClB,GAAG,EAAE,cAAc;IACnB,MAAM,EAAE,cAAc;IACtB,GAAG,EAAE,WAAW;IAChB,GAAG,EAAE,WAAW;IAChB,MAAM,EAAE,cAAc;IACtB,KAAK,EAAE,aAAa;IACpB,aAAa,EAAE,qBAAqB;IACpC,UAAU,EAAE,kBAAkB;CAC/B,CAAC;AAEF,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
@@ -1,14 +0,0 @@
1
- import { LimitedCacheOptions, LimitedCacheOptionsReadonly, LimitedCacheMeta } from '../types.js';
2
- declare const isCacheMeta: (cacheMeta: LimitedCacheMeta) => boolean;
3
- declare const upgradeCacheMeta: (cacheMeta: LimitedCacheMeta) => void;
4
- declare const lowLevelSetOptions: <ItemType = any>(cacheMeta: LimitedCacheMeta<ItemType>, options: LimitedCacheOptions) => LimitedCacheOptionsReadonly;
5
- declare const lowLevelInit: <ItemType = any>(optionsOrCacheMeta?: LimitedCacheOptions | LimitedCacheMeta<ItemType> | undefined) => LimitedCacheMeta<ItemType>;
6
- declare const lowLevelDoMaintenance: <ItemType = any>(cacheMeta: LimitedCacheMeta<ItemType>) => LimitedCacheMeta<ItemType>;
7
- declare const lowLevelHas: <ItemType = any>(cacheMeta: LimitedCacheMeta<ItemType>, cacheKey: string) => boolean;
8
- declare const lowLevelGetOne: <ItemType = any>(cacheMeta: LimitedCacheMeta<ItemType>, cacheKey: string) => ItemType | undefined;
9
- declare const lowLevelGetAll: <ItemType = any>(cacheMeta: LimitedCacheMeta<ItemType>) => Record<string, ItemType>;
10
- declare const lowLevelSet: <ItemType = any>(cacheMeta: LimitedCacheMeta<ItemType>, cacheKey: string, item: ItemType) => LimitedCacheMeta<ItemType>;
11
- declare const lowLevelRemove: <ItemType = any>(cacheMeta: LimitedCacheMeta<ItemType>, cacheKey: string) => LimitedCacheMeta<ItemType>;
12
- declare const lowLevelReset: <ItemType = any>(cacheMeta: LimitedCacheMeta<ItemType>) => LimitedCacheMeta<ItemType>;
13
- export { isCacheMeta, upgradeCacheMeta, lowLevelInit, lowLevelGetOne, lowLevelGetAll, lowLevelHas, lowLevelSet, lowLevelRemove, lowLevelReset, lowLevelDoMaintenance, lowLevelSetOptions, };
14
- //# sourceMappingURL=lowLevelFunctions.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"lowLevelFunctions.d.ts","sourceRoot":"","sources":["../../../src/core/lowLevelFunctions.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,mBAAmB,EACnB,2BAA2B,EAC3B,gBAAgB,EAGjB,MAAM,aAAa,CAAC;AAqBrB,QAAA,MAAM,WAAW,cAAe,gBAAgB,KAAG,OAElD,CAAC;AAEF,QAAA,MAAM,gBAAgB,cAAe,gBAAgB,KAAG,IAWvD,CAAC;AAEF,QAAA,MAAM,kBAAkB,mEAEb,mBAAmB,KAC3B,2BAGF,CAAC;AAEF,QAAA,MAAM,YAAY,mIAkBjB,CAAC;AA0BF,QAAA,MAAM,qBAAqB,uFA+B1B,CAAC;AA4FF,QAAA,MAAM,WAAW,oEAEL,MAAM,KACf,OAWF,CAAC;AAEF,QAAA,MAAM,cAAc,oEAER,MAAM,yBAOjB,CAAC;AAEF,QAAA,MAAM,cAAc,qFAQnB,CAAC;AAEF,QAAA,MAAM,WAAW,oEAEL,MAAM,+CA+CjB,CAAC;AAEF,QAAA,MAAM,cAAc,oEAER,MAAM,+BAgBjB,CAAC;AAEF,QAAA,MAAM,aAAa,uFAUlB,CAAC;AAEF,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,cAAc,EACd,cAAc,EACd,WAAW,EACX,WAAW,EACX,cAAc,EACd,aAAa,EACb,qBAAqB,EACrB,kBAAkB,GACnB,CAAC"}