@cacheable/utils 2.1.0 → 2.3.0

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.js CHANGED
@@ -1 +1,598 @@
1
- var a=t=>{let e;if(t!==void 0){if(typeof t=="number")e=t;else if(typeof t=="string")if(t=t.trim(),Number.isNaN(Number(t))){let r=/^([\d.]+)\s*(ms|s|m|h|hr|d)$/i.exec(t);if(!r)throw new Error(`Unsupported time format: "${t}". Use 'ms', 's', 'm', 'h', 'hr', or 'd'.`);let[,i,s]=r,n=Number.parseFloat(i);switch(s.toLowerCase()){case"ms":{e=n;break}case"s":{e=n*1e3;break}case"m":{e=n*1e3*60;break}case"h":{e=n*1e3*60*60;break}case"hr":{e=n*1e3*60*60;break}case"d":{e=n*1e3*60*60*24;break}default:e=Number(t)}}else e=Number(t);else throw new TypeError("Time must be a string or a number.");return e}},g=(t,e)=>{e??=new Date;let r=a(t);return r===void 0?e.getTime():e.getTime()+r};var u=new Map;function _(t){return u.has(t)}function y(t){u.set(t,[])}function T(t){u.delete(t)}function v(t,e){let r=b(t);r.push(e),u.set(t,r)}function b(t){return u.get(t)??[]}async function x(t){return new Promise((e,r)=>{v(t,{resolve:e,reject:r})})}function z(t){let e=b(t);return T(t),e}function h(t){let{key:e,error:r,result:i}=t;for(let s of z(e))r?s.reject(r):s.resolve(i)}async function S(t,e){if(!_(t)){y(t);try{let r=await Promise.resolve(e());return h({key:t,result:r}),r}catch(r){throw h({key:t,error:r}),r}}return x(t)}import*as l from"crypto";var f=(s=>(s.SHA256="sha256",s.SHA512="sha512",s.MD5="md5",s.DJB2="djb2",s))(f||{});function d(t,e={algorithm:"sha256",serialize:JSON.stringify}){e?.algorithm||(e.algorithm="sha256"),e?.serialize||(e.serialize=JSON.stringify);let r=e.serialize(t);if(e?.algorithm==="djb2")return w(r);if(!l.getHashes().includes(e.algorithm))throw new Error(`Unsupported hash algorithm: '${e?.algorithm}'`);let i=l.createHash(e.algorithm);return i.update(r),i.digest("hex")}function k(t,e={min:0,max:10,algorithm:"sha256",serialize:JSON.stringify}){let r=e?.min??0,i=e?.max??10;if(r>=i)throw new Error(`Invalid range: min (${r}) must be less than max (${i})`);e?.algorithm||(e.algorithm="sha256"),e?.serialize||(e.serialize=JSON.stringify);let s=d(t,e),n=Number.parseInt(s,16),o=i-r+1,c=r+n%o;return c<r?r:c>i?i:c}function w(t){let e=5381;for(let r=0;r<t.length;r++)e=e*33^t.charCodeAt(r);return e.toString()}import{Keyv as O}from"keyv";function P(t){return t==null?!1:t instanceof O?!0:["generateIterator","get","getMany","set","setMany","delete","deleteMany","has","hasMany","clear","disconnect","serialize","deserialize"].every(r=>typeof t[r]=="function")}function C(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}function N(t,e){return typeof t=="number"&&typeof e=="number"?t<e:!1}function A(t,...e){return typeof t=="function"?t(...e):t}var H=async t=>new Promise(e=>setTimeout(e,t));var m=class{_hits=0;_misses=0;_gets=0;_sets=0;_deletes=0;_clears=0;_vsize=0;_ksize=0;_count=0;_enabled=!1;constructor(e){e?.enabled&&(this._enabled=e.enabled)}get enabled(){return this._enabled}set enabled(e){this._enabled=e}get hits(){return this._hits}get misses(){return this._misses}get gets(){return this._gets}get sets(){return this._sets}get deletes(){return this._deletes}get clears(){return this._clears}get vsize(){return this._vsize}get ksize(){return this._ksize}get count(){return this._count}incrementHits(){this._enabled&&this._hits++}incrementMisses(){this._enabled&&this._misses++}incrementGets(){this._enabled&&this._gets++}incrementSets(){this._enabled&&this._sets++}incrementDeletes(){this._enabled&&this._deletes++}incrementClears(){this._enabled&&this._clears++}incrementVSize(e){this._enabled&&(this._vsize+=this.roughSizeOfObject(e))}decreaseVSize(e){this._enabled&&(this._vsize-=this.roughSizeOfObject(e))}incrementKSize(e){this._enabled&&(this._ksize+=this.roughSizeOfString(e))}decreaseKSize(e){this._enabled&&(this._ksize-=this.roughSizeOfString(e))}incrementCount(){this._enabled&&this._count++}decreaseCount(){this._enabled&&this._count--}setCount(e){this._enabled&&(this._count=e)}roughSizeOfString(e){return e.length*2}roughSizeOfObject(e){let r=[],i=[e],s=0;for(;i.length>0;){let n=i.pop();if(typeof n=="boolean")s+=4;else if(typeof n=="string")s+=n.length*2;else if(typeof n=="number")s+=8;else if(typeof n=="object"&&n!==null&&!r.includes(n)){r.push(n);for(let o in n)s+=o.length*2,i.push(n[o])}}return s}reset(){this._hits=0,this._misses=0,this._gets=0,this._sets=0,this._deletes=0,this._clears=0,this._vsize=0,this._ksize=0,this._count=0}resetStoreValues(){this._vsize=0,this._ksize=0,this._count=0}};function p(t){if(t==null)return;let e=Date.now();if(!(t<e))return t-e}function j(t,e,r){return r??e??a(t)}function E(t,e){let r=p(e),i=t?Date.now()+t:void 0;return r===void 0?t:i===void 0?r:e&&e>i?t:r}export{f as HashAlgorithm,m as Stats,E as calculateTtlFromExpiration,S as coalesceAsync,j as getCascadingTtl,p as getTtlFromExpires,d as hash,k as hashToNumber,P as isKeyvInstance,C as isObject,N as lessThan,A as runIfFn,a as shorthandToMilliseconds,g as shorthandToTime,H as sleep};
1
+ // src/shorthand-time.ts
2
+ var shorthandToMilliseconds = (shorthand) => {
3
+ let milliseconds;
4
+ if (shorthand === void 0) {
5
+ return void 0;
6
+ }
7
+ if (typeof shorthand === "number") {
8
+ milliseconds = shorthand;
9
+ } else {
10
+ if (typeof shorthand !== "string") {
11
+ return void 0;
12
+ }
13
+ shorthand = shorthand.trim();
14
+ if (Number.isNaN(Number(shorthand))) {
15
+ const match = /^([\d.]+)\s*(ms|s|m|h|hr|d)$/i.exec(shorthand);
16
+ if (!match) {
17
+ throw new Error(
18
+ `Unsupported time format: "${shorthand}". Use 'ms', 's', 'm', 'h', 'hr', or 'd'.`
19
+ );
20
+ }
21
+ const [, value, unit] = match;
22
+ const numericValue = Number.parseFloat(value);
23
+ const unitLower = unit.toLowerCase();
24
+ switch (unitLower) {
25
+ case "ms": {
26
+ milliseconds = numericValue;
27
+ break;
28
+ }
29
+ case "s": {
30
+ milliseconds = numericValue * 1e3;
31
+ break;
32
+ }
33
+ case "m": {
34
+ milliseconds = numericValue * 1e3 * 60;
35
+ break;
36
+ }
37
+ case "h": {
38
+ milliseconds = numericValue * 1e3 * 60 * 60;
39
+ break;
40
+ }
41
+ case "hr": {
42
+ milliseconds = numericValue * 1e3 * 60 * 60;
43
+ break;
44
+ }
45
+ case "d": {
46
+ milliseconds = numericValue * 1e3 * 60 * 60 * 24;
47
+ break;
48
+ }
49
+ /* v8 ignore next -- @preserve */
50
+ default: {
51
+ milliseconds = Number(shorthand);
52
+ }
53
+ }
54
+ } else {
55
+ milliseconds = Number(shorthand);
56
+ }
57
+ }
58
+ return milliseconds;
59
+ };
60
+ var shorthandToTime = (shorthand, fromDate) => {
61
+ fromDate ??= /* @__PURE__ */ new Date();
62
+ const milliseconds = shorthandToMilliseconds(shorthand);
63
+ if (milliseconds === void 0) {
64
+ return fromDate.getTime();
65
+ }
66
+ return fromDate.getTime() + milliseconds;
67
+ };
68
+
69
+ // src/coalesce-async.ts
70
+ var callbacks = /* @__PURE__ */ new Map();
71
+ function hasKey(key) {
72
+ return callbacks.has(key);
73
+ }
74
+ function addKey(key) {
75
+ callbacks.set(key, []);
76
+ }
77
+ function removeKey(key) {
78
+ callbacks.delete(key);
79
+ }
80
+ function addCallbackToKey(key, callback) {
81
+ const stash = getCallbacksByKey(key);
82
+ stash.push(callback);
83
+ callbacks.set(key, stash);
84
+ }
85
+ function getCallbacksByKey(key) {
86
+ return callbacks.get(key) ?? [];
87
+ }
88
+ async function enqueue(key) {
89
+ return new Promise((resolve, reject) => {
90
+ const callback = { resolve, reject };
91
+ addCallbackToKey(key, callback);
92
+ });
93
+ }
94
+ function dequeue(key) {
95
+ const stash = getCallbacksByKey(key);
96
+ removeKey(key);
97
+ return stash;
98
+ }
99
+ function coalesce(options) {
100
+ const { key, error, result } = options;
101
+ for (const callback of dequeue(key)) {
102
+ if (error) {
103
+ callback.reject(error);
104
+ } else {
105
+ callback.resolve(result);
106
+ }
107
+ }
108
+ }
109
+ async function coalesceAsync(key, fnc) {
110
+ if (!hasKey(key)) {
111
+ addKey(key);
112
+ try {
113
+ const result = await Promise.resolve(fnc());
114
+ coalesce({ key, result });
115
+ return result;
116
+ } catch (error) {
117
+ coalesce({ key, error });
118
+ throw error;
119
+ }
120
+ }
121
+ return enqueue(key);
122
+ }
123
+
124
+ // src/hash.ts
125
+ import { Hashery } from "hashery";
126
+ var HashAlgorithm = /* @__PURE__ */ ((HashAlgorithm2) => {
127
+ HashAlgorithm2["SHA256"] = "SHA-256";
128
+ HashAlgorithm2["SHA384"] = "SHA-384";
129
+ HashAlgorithm2["SHA512"] = "SHA-512";
130
+ HashAlgorithm2["DJB2"] = "djb2";
131
+ HashAlgorithm2["FNV1"] = "fnv1";
132
+ HashAlgorithm2["MURMER"] = "murmer";
133
+ HashAlgorithm2["CRC32"] = "crc32";
134
+ return HashAlgorithm2;
135
+ })(HashAlgorithm || {});
136
+ async function hash(object, options = {
137
+ algorithm: "SHA-256" /* SHA256 */,
138
+ serialize: JSON.stringify
139
+ }) {
140
+ const algorithm = options?.algorithm ?? "SHA-256" /* SHA256 */;
141
+ const serialize = options?.serialize ?? JSON.stringify;
142
+ const objectString = serialize(object);
143
+ const hashery = new Hashery();
144
+ return hashery.toHash(objectString, { algorithm });
145
+ }
146
+ function hashSync(object, options = {
147
+ algorithm: "djb2" /* DJB2 */,
148
+ serialize: JSON.stringify
149
+ }) {
150
+ const algorithm = options?.algorithm ?? "djb2" /* DJB2 */;
151
+ const serialize = options?.serialize ?? JSON.stringify;
152
+ const objectString = serialize(object);
153
+ const hashery = new Hashery();
154
+ return hashery.toHashSync(objectString, { algorithm });
155
+ }
156
+ async function hashToNumber(object, options = {
157
+ min: 0,
158
+ max: 10,
159
+ algorithm: "SHA-256" /* SHA256 */,
160
+ serialize: JSON.stringify
161
+ }) {
162
+ const min = options?.min ?? 0;
163
+ const max = options?.max ?? 10;
164
+ const algorithm = options?.algorithm ?? "SHA-256" /* SHA256 */;
165
+ const serialize = options?.serialize ?? JSON.stringify;
166
+ const hashLength = options?.hashLength ?? 16;
167
+ if (min >= max) {
168
+ throw new Error(
169
+ `Invalid range: min (${min}) must be less than max (${max})`
170
+ );
171
+ }
172
+ const objectString = serialize(object);
173
+ const hashery = new Hashery();
174
+ return hashery.toNumber(objectString, {
175
+ algorithm,
176
+ min,
177
+ max,
178
+ hashLength
179
+ });
180
+ }
181
+ function hashToNumberSync(object, options = {
182
+ min: 0,
183
+ max: 10,
184
+ algorithm: "djb2" /* DJB2 */,
185
+ serialize: JSON.stringify
186
+ }) {
187
+ const min = options?.min ?? 0;
188
+ const max = options?.max ?? 10;
189
+ const algorithm = options?.algorithm ?? "djb2" /* DJB2 */;
190
+ const serialize = options?.serialize ?? JSON.stringify;
191
+ const hashLength = options?.hashLength ?? 16;
192
+ if (min >= max) {
193
+ throw new Error(
194
+ `Invalid range: min (${min}) must be less than max (${max})`
195
+ );
196
+ }
197
+ const objectString = serialize(object);
198
+ const hashery = new Hashery();
199
+ return hashery.toNumberSync(objectString, {
200
+ algorithm,
201
+ min,
202
+ max,
203
+ hashLength
204
+ });
205
+ }
206
+
207
+ // src/is-keyv-instance.ts
208
+ import { Keyv } from "keyv";
209
+ function isKeyvInstance(keyv) {
210
+ if (keyv === null || keyv === void 0) {
211
+ return false;
212
+ }
213
+ if (keyv instanceof Keyv) {
214
+ return true;
215
+ }
216
+ const keyvMethods = [
217
+ "generateIterator",
218
+ "get",
219
+ "getMany",
220
+ "set",
221
+ "setMany",
222
+ "delete",
223
+ "deleteMany",
224
+ "has",
225
+ "hasMany",
226
+ "clear",
227
+ "disconnect",
228
+ "serialize",
229
+ "deserialize"
230
+ ];
231
+ return keyvMethods.every((method) => typeof keyv[method] === "function");
232
+ }
233
+
234
+ // src/is-object.ts
235
+ function isObject(value) {
236
+ return value !== null && typeof value === "object" && !Array.isArray(value);
237
+ }
238
+
239
+ // src/less-than.ts
240
+ function lessThan(number1, number2) {
241
+ return typeof number1 === "number" && typeof number2 === "number" ? number1 < number2 : false;
242
+ }
243
+
244
+ // src/memoize.ts
245
+ function wrapSync(function_, options) {
246
+ const { ttl, keyPrefix, cache, serialize } = options;
247
+ return (...arguments_) => {
248
+ let cacheKey = createWrapKey(function_, arguments_, {
249
+ keyPrefix,
250
+ serialize
251
+ });
252
+ if (options.createKey) {
253
+ cacheKey = options.createKey(function_, arguments_, options);
254
+ }
255
+ let value = cache.get(cacheKey);
256
+ if (value === void 0) {
257
+ try {
258
+ value = function_(...arguments_);
259
+ cache.set(cacheKey, value, ttl);
260
+ } catch (error) {
261
+ cache.emit("error", error);
262
+ if (options.cacheErrors) {
263
+ cache.set(cacheKey, error, ttl);
264
+ }
265
+ }
266
+ }
267
+ return value;
268
+ };
269
+ }
270
+ async function getOrSet(key, function_, options) {
271
+ const keyString = typeof key === "function" ? key(options) : key;
272
+ let value = await options.cache.get(keyString);
273
+ if (value === void 0) {
274
+ const cacheId = options.cacheId ?? "default";
275
+ const coalesceKey = `${cacheId}::${keyString}`;
276
+ value = await coalesceAsync(coalesceKey, async () => {
277
+ try {
278
+ const result = await function_();
279
+ await options.cache.set(keyString, result, options.ttl);
280
+ return result;
281
+ } catch (error) {
282
+ options.cache.emit("error", error);
283
+ if (options.cacheErrors) {
284
+ await options.cache.set(keyString, error, options.ttl);
285
+ }
286
+ if (options.throwErrors) {
287
+ throw error;
288
+ }
289
+ }
290
+ });
291
+ }
292
+ return value;
293
+ }
294
+ function wrap(function_, options) {
295
+ const { keyPrefix, serialize } = options;
296
+ return async (...arguments_) => {
297
+ let cacheKey = createWrapKey(function_, arguments_, {
298
+ keyPrefix,
299
+ serialize
300
+ });
301
+ if (options.createKey) {
302
+ cacheKey = options.createKey(function_, arguments_, options);
303
+ }
304
+ return getOrSet(
305
+ cacheKey,
306
+ async () => function_(...arguments_),
307
+ options
308
+ );
309
+ };
310
+ }
311
+ function createWrapKey(function_, arguments_, options) {
312
+ const { keyPrefix, serialize } = options || {};
313
+ if (!keyPrefix) {
314
+ return `${function_.name}::${hashSync(arguments_, { serialize })}`;
315
+ }
316
+ return `${keyPrefix}::${function_.name}::${hashSync(arguments_, { serialize })}`;
317
+ }
318
+
319
+ // src/run-if-fn.ts
320
+ function runIfFn(valueOrFunction, ...arguments_) {
321
+ return typeof valueOrFunction === "function" ? valueOrFunction(...arguments_) : valueOrFunction;
322
+ }
323
+
324
+ // src/sleep.ts
325
+ var sleep = async (ms) => new Promise((resolve) => setTimeout(resolve, ms));
326
+
327
+ // src/stats.ts
328
+ var Stats = class {
329
+ _hits = 0;
330
+ _misses = 0;
331
+ _gets = 0;
332
+ _sets = 0;
333
+ _deletes = 0;
334
+ _clears = 0;
335
+ _vsize = 0;
336
+ _ksize = 0;
337
+ _count = 0;
338
+ _enabled = false;
339
+ constructor(options) {
340
+ if (options?.enabled) {
341
+ this._enabled = options.enabled;
342
+ }
343
+ }
344
+ /**
345
+ * @returns {boolean} - Whether the stats are enabled
346
+ */
347
+ get enabled() {
348
+ return this._enabled;
349
+ }
350
+ /**
351
+ * @param {boolean} enabled - Whether to enable the stats
352
+ */
353
+ set enabled(enabled) {
354
+ this._enabled = enabled;
355
+ }
356
+ /**
357
+ * @returns {number} - The number of hits
358
+ * @readonly
359
+ */
360
+ get hits() {
361
+ return this._hits;
362
+ }
363
+ /**
364
+ * @returns {number} - The number of misses
365
+ * @readonly
366
+ */
367
+ get misses() {
368
+ return this._misses;
369
+ }
370
+ /**
371
+ * @returns {number} - The number of gets
372
+ * @readonly
373
+ */
374
+ get gets() {
375
+ return this._gets;
376
+ }
377
+ /**
378
+ * @returns {number} - The number of sets
379
+ * @readonly
380
+ */
381
+ get sets() {
382
+ return this._sets;
383
+ }
384
+ /**
385
+ * @returns {number} - The number of deletes
386
+ * @readonly
387
+ */
388
+ get deletes() {
389
+ return this._deletes;
390
+ }
391
+ /**
392
+ * @returns {number} - The number of clears
393
+ * @readonly
394
+ */
395
+ get clears() {
396
+ return this._clears;
397
+ }
398
+ /**
399
+ * @returns {number} - The vsize (value size) of the cache instance
400
+ * @readonly
401
+ */
402
+ get vsize() {
403
+ return this._vsize;
404
+ }
405
+ /**
406
+ * @returns {number} - The ksize (key size) of the cache instance
407
+ * @readonly
408
+ */
409
+ get ksize() {
410
+ return this._ksize;
411
+ }
412
+ /**
413
+ * @returns {number} - The count of the cache instance
414
+ * @readonly
415
+ */
416
+ get count() {
417
+ return this._count;
418
+ }
419
+ incrementHits() {
420
+ if (!this._enabled) {
421
+ return;
422
+ }
423
+ this._hits++;
424
+ }
425
+ incrementMisses() {
426
+ if (!this._enabled) {
427
+ return;
428
+ }
429
+ this._misses++;
430
+ }
431
+ incrementGets() {
432
+ if (!this._enabled) {
433
+ return;
434
+ }
435
+ this._gets++;
436
+ }
437
+ incrementSets() {
438
+ if (!this._enabled) {
439
+ return;
440
+ }
441
+ this._sets++;
442
+ }
443
+ incrementDeletes() {
444
+ if (!this._enabled) {
445
+ return;
446
+ }
447
+ this._deletes++;
448
+ }
449
+ incrementClears() {
450
+ if (!this._enabled) {
451
+ return;
452
+ }
453
+ this._clears++;
454
+ }
455
+ incrementVSize(value) {
456
+ if (!this._enabled) {
457
+ return;
458
+ }
459
+ this._vsize += this.roughSizeOfObject(value);
460
+ }
461
+ decreaseVSize(value) {
462
+ if (!this._enabled) {
463
+ return;
464
+ }
465
+ this._vsize -= this.roughSizeOfObject(value);
466
+ }
467
+ incrementKSize(key) {
468
+ if (!this._enabled) {
469
+ return;
470
+ }
471
+ this._ksize += this.roughSizeOfString(key);
472
+ }
473
+ decreaseKSize(key) {
474
+ if (!this._enabled) {
475
+ return;
476
+ }
477
+ this._ksize -= this.roughSizeOfString(key);
478
+ }
479
+ incrementCount() {
480
+ if (!this._enabled) {
481
+ return;
482
+ }
483
+ this._count++;
484
+ }
485
+ decreaseCount() {
486
+ if (!this._enabled) {
487
+ return;
488
+ }
489
+ this._count--;
490
+ }
491
+ setCount(count) {
492
+ if (!this._enabled) {
493
+ return;
494
+ }
495
+ this._count = count;
496
+ }
497
+ roughSizeOfString(value) {
498
+ return value.length * 2;
499
+ }
500
+ roughSizeOfObject(object) {
501
+ const objectList = [];
502
+ const stack = [object];
503
+ let bytes = 0;
504
+ while (stack.length > 0) {
505
+ const value = stack.pop();
506
+ if (typeof value === "boolean") {
507
+ bytes += 4;
508
+ } else if (typeof value === "string") {
509
+ bytes += value.length * 2;
510
+ } else if (typeof value === "number") {
511
+ bytes += 8;
512
+ } else {
513
+ if (value === null || value === void 0) {
514
+ bytes += 4;
515
+ continue;
516
+ }
517
+ if (objectList.includes(value)) {
518
+ continue;
519
+ }
520
+ objectList.push(value);
521
+ for (const key in value) {
522
+ bytes += key.length * 2;
523
+ stack.push(value[key]);
524
+ }
525
+ }
526
+ }
527
+ return bytes;
528
+ }
529
+ reset() {
530
+ this._hits = 0;
531
+ this._misses = 0;
532
+ this._gets = 0;
533
+ this._sets = 0;
534
+ this._deletes = 0;
535
+ this._clears = 0;
536
+ this._vsize = 0;
537
+ this._ksize = 0;
538
+ this._count = 0;
539
+ }
540
+ resetStoreValues() {
541
+ this._vsize = 0;
542
+ this._ksize = 0;
543
+ this._count = 0;
544
+ }
545
+ };
546
+
547
+ // src/ttl.ts
548
+ function getTtlFromExpires(expires) {
549
+ if (expires === void 0 || expires === null) {
550
+ return void 0;
551
+ }
552
+ const now = Date.now();
553
+ if (expires < now) {
554
+ return void 0;
555
+ }
556
+ return expires - now;
557
+ }
558
+ function getCascadingTtl(cacheableTtl, primaryTtl, secondaryTtl) {
559
+ return secondaryTtl ?? primaryTtl ?? shorthandToMilliseconds(cacheableTtl);
560
+ }
561
+ function calculateTtlFromExpiration(ttl, expires) {
562
+ const ttlFromExpires = getTtlFromExpires(expires);
563
+ const expiresFromTtl = ttl ? Date.now() + ttl : void 0;
564
+ if (ttlFromExpires === void 0) {
565
+ return ttl;
566
+ }
567
+ if (expiresFromTtl === void 0) {
568
+ return ttlFromExpires;
569
+ }
570
+ if (expires && expires > expiresFromTtl) {
571
+ return ttl;
572
+ }
573
+ return ttlFromExpires;
574
+ }
575
+ export {
576
+ HashAlgorithm,
577
+ Stats,
578
+ calculateTtlFromExpiration,
579
+ coalesceAsync,
580
+ createWrapKey,
581
+ getCascadingTtl,
582
+ getOrSet,
583
+ getTtlFromExpires,
584
+ hash,
585
+ hashSync,
586
+ hashToNumber,
587
+ hashToNumberSync,
588
+ isKeyvInstance,
589
+ isObject,
590
+ lessThan,
591
+ runIfFn,
592
+ shorthandToMilliseconds,
593
+ shorthandToTime,
594
+ sleep,
595
+ wrap,
596
+ wrapSync
597
+ };
598
+ /* v8 ignore next -- @preserve */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cacheable/utils",
3
- "version": "2.1.0",
3
+ "version": "2.3.0",
4
4
  "description": "Cacheable Utilities for Caching Libraries",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -21,17 +21,15 @@
21
21
  "license": "MIT",
22
22
  "private": false,
23
23
  "devDependencies": {
24
- "@biomejs/biome": "^2.2.4",
25
- "@faker-js/faker": "^10.0.0",
26
- "@keyv/redis": "^5.1.2",
27
- "@keyv/valkey": "^1.0.8",
28
- "@types/node": "^24.5.2",
29
- "@vitest/coverage-v8": "^3.2.4",
24
+ "@biomejs/biome": "^2.3.5",
25
+ "@faker-js/faker": "^10.1.0",
26
+ "@types/node": "^24.10.1",
27
+ "@vitest/coverage-v8": "^4.0.9",
30
28
  "lru-cache": "^11.2.2",
31
- "rimraf": "^6.0.1",
32
- "tsup": "^8.5.0",
33
- "typescript": "^5.9.2",
34
- "vitest": "^3.2.4"
29
+ "rimraf": "^6.1.0",
30
+ "tsup": "^8.5.1",
31
+ "typescript": "^5.9.3",
32
+ "vitest": "^4.0.9"
35
33
  },
36
34
  "keywords": [
37
35
  "cacheable",
@@ -46,10 +44,13 @@
46
44
  "LICENSE"
47
45
  ],
48
46
  "dependencies": {
49
- "keyv": "^5.5.3"
47
+ "hashery": "^1.2.0"
48
+ },
49
+ "peerDependencies": {
50
+ "keyv": "^5.5.4"
50
51
  },
51
52
  "scripts": {
52
- "build": "rimraf ./dist && tsup src/index.ts --format cjs,esm --dts --clean --minify",
53
+ "build": "rimraf ./dist && tsup src/index.ts --format cjs,esm --dts --clean",
53
54
  "prepublish": "pnpm build",
54
55
  "lint": "biome check --write --error-on-warnings",
55
56
  "test": "pnpm lint && vitest run --coverage",