cache-manager 7.2.0 → 7.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -35,78 +35,9 @@ __export(index_exports, {
35
35
  });
36
36
  module.exports = __toCommonJS(index_exports);
37
37
  var import_node_events = __toESM(require("events"), 1);
38
+ var import_utils = require("@cacheable/utils");
38
39
  var import_keyv = require("keyv");
39
40
 
40
- // src/coalesce-async.ts
41
- var callbacks = /* @__PURE__ */ new Map();
42
- function hasKey(key) {
43
- return callbacks.has(key);
44
- }
45
- function addKey(key) {
46
- callbacks.set(key, []);
47
- }
48
- function removeKey(key) {
49
- callbacks.delete(key);
50
- }
51
- function addCallbackToKey(key, callback) {
52
- const stash = getCallbacksByKey(key);
53
- stash.push(callback);
54
- callbacks.set(key, stash);
55
- }
56
- function getCallbacksByKey(key) {
57
- return callbacks.get(key) ?? [];
58
- }
59
- async function enqueue(key) {
60
- return new Promise((resolve, reject) => {
61
- const callback = { resolve, reject };
62
- addCallbackToKey(key, callback);
63
- });
64
- }
65
- function dequeue(key) {
66
- const stash = getCallbacksByKey(key);
67
- removeKey(key);
68
- return stash;
69
- }
70
- function coalesce(options) {
71
- const { key, error, result } = options;
72
- for (const callback of dequeue(key)) {
73
- if (error) {
74
- callback.reject(error);
75
- } else {
76
- callback.resolve(result);
77
- }
78
- }
79
- }
80
- async function coalesceAsync(key, fnc) {
81
- if (!hasKey(key)) {
82
- addKey(key);
83
- try {
84
- const result = await Promise.resolve(fnc());
85
- coalesce({ key, result });
86
- return result;
87
- } catch (error) {
88
- coalesce({ key, error });
89
- throw error;
90
- }
91
- }
92
- return enqueue(key);
93
- }
94
-
95
- // src/is-object.ts
96
- function isObject(value) {
97
- return value !== null && typeof value === "object" && !Array.isArray(value);
98
- }
99
-
100
- // src/lt.ts
101
- function lt(number1, number2) {
102
- return typeof number1 === "number" && typeof number2 === "number" ? number1 < number2 : false;
103
- }
104
-
105
- // src/run-if-fn.ts
106
- function runIfFn(valueOrFunction, ...arguments_) {
107
- return typeof valueOrFunction === "function" ? valueOrFunction(...arguments_) : valueOrFunction;
108
- }
109
-
110
41
  // src/keyv-adapter.ts
111
42
  var KeyvAdapter = class {
112
43
  // biome-ignore lint/suspicious/noExplicitAny: type format
@@ -361,13 +292,13 @@ var createCache = (options) => {
361
292
  return Promise.reject(error);
362
293
  }
363
294
  };
364
- const wrap = async (key, fnc, ttlOrOptions, refreshThresholdParameter) => coalesceAsync(`${_cacheId}::${key}`, async () => {
295
+ const wrap = async (key, fnc, ttlOrOptions, refreshThresholdParameter) => (0, import_utils.coalesceAsync)(`${_cacheId}::${key}`, async () => {
365
296
  let value;
366
297
  let rawData;
367
298
  let i = 0;
368
299
  let remainingTtl;
369
- const { ttl: ttl2, refreshThreshold, raw } = isObject(ttlOrOptions) ? ttlOrOptions : { ttl: ttlOrOptions, refreshThreshold: refreshThresholdParameter };
370
- const resolveTtl = (result) => runIfFn(ttl2, result) ?? options?.ttl;
300
+ const { ttl: ttl2, refreshThreshold, raw } = (0, import_utils.isObject)(ttlOrOptions) ? ttlOrOptions : { ttl: ttlOrOptions, refreshThreshold: refreshThresholdParameter };
301
+ const resolveTtl = (result) => (0, import_utils.runIfFn)(ttl2, result) ?? options?.ttl;
371
302
  for (; i < stores.length; i++) {
372
303
  try {
373
304
  const data = await stores[i].get(key, { raw: true });
@@ -388,12 +319,12 @@ var createCache = (options) => {
388
319
  await set(stores, key, result, ttl3);
389
320
  return raw ? { value: result, expires: Date.now() + ttl3 } : result;
390
321
  }
391
- const shouldRefresh = lt(
322
+ const shouldRefresh = (0, import_utils.lessThan)(
392
323
  remainingTtl,
393
- runIfFn(refreshThreshold, value) ?? options?.refreshThreshold
324
+ (0, import_utils.runIfFn)(refreshThreshold, value) ?? options?.refreshThreshold
394
325
  );
395
326
  if (shouldRefresh) {
396
- coalesceAsync(`+++${_cacheId}__${key}`, fnc).then(async (result) => {
327
+ (0, import_utils.coalesceAsync)(`+++${_cacheId}__${key}`, fnc).then(async (result) => {
397
328
  try {
398
329
  await set(
399
330
  options?.refreshAllStores ? stores : stores.slice(0, i + 1),
package/dist/index.js CHANGED
@@ -1,77 +1,13 @@
1
1
  // src/index.ts
2
2
  import EventEmitter from "events";
3
+ import {
4
+ coalesceAsync,
5
+ isObject,
6
+ lessThan as lt,
7
+ runIfFn
8
+ } from "@cacheable/utils";
3
9
  import { Keyv } from "keyv";
4
10
 
5
- // src/coalesce-async.ts
6
- var callbacks = /* @__PURE__ */ new Map();
7
- function hasKey(key) {
8
- return callbacks.has(key);
9
- }
10
- function addKey(key) {
11
- callbacks.set(key, []);
12
- }
13
- function removeKey(key) {
14
- callbacks.delete(key);
15
- }
16
- function addCallbackToKey(key, callback) {
17
- const stash = getCallbacksByKey(key);
18
- stash.push(callback);
19
- callbacks.set(key, stash);
20
- }
21
- function getCallbacksByKey(key) {
22
- return callbacks.get(key) ?? [];
23
- }
24
- async function enqueue(key) {
25
- return new Promise((resolve, reject) => {
26
- const callback = { resolve, reject };
27
- addCallbackToKey(key, callback);
28
- });
29
- }
30
- function dequeue(key) {
31
- const stash = getCallbacksByKey(key);
32
- removeKey(key);
33
- return stash;
34
- }
35
- function coalesce(options) {
36
- const { key, error, result } = options;
37
- for (const callback of dequeue(key)) {
38
- if (error) {
39
- callback.reject(error);
40
- } else {
41
- callback.resolve(result);
42
- }
43
- }
44
- }
45
- async function coalesceAsync(key, fnc) {
46
- if (!hasKey(key)) {
47
- addKey(key);
48
- try {
49
- const result = await Promise.resolve(fnc());
50
- coalesce({ key, result });
51
- return result;
52
- } catch (error) {
53
- coalesce({ key, error });
54
- throw error;
55
- }
56
- }
57
- return enqueue(key);
58
- }
59
-
60
- // src/is-object.ts
61
- function isObject(value) {
62
- return value !== null && typeof value === "object" && !Array.isArray(value);
63
- }
64
-
65
- // src/lt.ts
66
- function lt(number1, number2) {
67
- return typeof number1 === "number" && typeof number2 === "number" ? number1 < number2 : false;
68
- }
69
-
70
- // src/run-if-fn.ts
71
- function runIfFn(valueOrFunction, ...arguments_) {
72
- return typeof valueOrFunction === "function" ? valueOrFunction(...arguments_) : valueOrFunction;
73
- }
74
-
75
11
  // src/keyv-adapter.ts
76
12
  var KeyvAdapter = class {
77
13
  // biome-ignore lint/suspicious/noExplicitAny: type format
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cache-manager",
3
- "version": "7.2.0",
3
+ "version": "7.2.2",
4
4
  "description": "Cache Manager for Node.js",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -50,13 +50,14 @@
50
50
  ],
51
51
  "license": "MIT",
52
52
  "dependencies": {
53
- "keyv": "^5.5.0"
53
+ "keyv": "^5.5.2",
54
+ "@cacheable/utils": "^2.0.1"
54
55
  },
55
56
  "devDependencies": {
56
- "@biomejs/biome": "^2.2.0",
57
- "@faker-js/faker": "^9.9.0",
58
- "@keyv/redis": "^5.1.0",
59
- "@types/node": "^24.2.0",
57
+ "@biomejs/biome": "^2.2.3",
58
+ "@faker-js/faker": "^10.0.0",
59
+ "@keyv/redis": "^5.1.1",
60
+ "@types/node": "^24.3.1",
60
61
  "@vitest/coverage-v8": "^3.2.4",
61
62
  "@vitest/spy": "^3.2.4",
62
63
  "cache-manager-redis-yet": "^5.1.5",
@@ -64,7 +65,7 @@
64
65
  "tsup": "^8.5.0",
65
66
  "typescript": "^5.9.2",
66
67
  "vitest": "^3.2.4",
67
- "cacheable": "^1.10.4"
68
+ "cacheable": "^2.0.1"
68
69
  },
69
70
  "scripts": {
70
71
  "clean": "rimraf ./dist ./coverage ./node_modules",