keyv 6.0.0-beta.4 → 6.0.0-rc.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 +68 -8
- package/dist/index.cjs +9 -6
- package/dist/index.d.cts +142 -70
- package/dist/index.d.mts +142 -70
- package/dist/index.mjs +9 -6
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -37,6 +37,7 @@ There are a few existing modules similar to Keyv, however Keyv is different beca
|
|
|
37
37
|
- [Serialization](#serialization)
|
|
38
38
|
- [Official Storage Adapters](#official-storage-adapters)
|
|
39
39
|
- [Third-party Storage Adapters](#third-party-storage-adapters)
|
|
40
|
+
- [Built-in Adapters: Memory and Bridge](#built-in-adapters-memory-and-bridge)
|
|
40
41
|
- [Using BigMap to Scale](#using-bigmap-to-scale)
|
|
41
42
|
- [Compression](#compression)
|
|
42
43
|
- [Capability Detection](#capability-detection)
|
|
@@ -436,9 +437,61 @@ class MyAdapter {
|
|
|
436
437
|
}
|
|
437
438
|
```
|
|
438
439
|
|
|
439
|
-
A v6 adapter declares `capabilities.expires === true` (the `keyvStorageCapability(this)` helper sets it for you). Keyv then passes the absolute `expires` to it directly — this takes precedence over structural detection, so an adapter whose methods aren't written with `async` is still used directly rather than bridged. Any **legacy** storage adapter that does *not* declare `capabilities.expires` is treated as a relative-TTL adapter and transparently wrapped by [`KeyvBridgeAdapter`](#
|
|
440
|
+
A v6 adapter declares `capabilities.expires === true` (the `keyvStorageCapability(this)` helper sets it for you). Keyv then passes the absolute `expires` to it directly — this takes precedence over structural detection, so an adapter whose methods aren't written with `async` is still used directly rather than bridged. Any **legacy** storage adapter that does *not* declare `capabilities.expires` is treated as a relative-TTL adapter and transparently wrapped by [`KeyvBridgeAdapter`](#built-in-adapters-memory-and-bridge), which converts the absolute `expires` back to a relative TTL before delegating (and deletes outright when the deadline has already elapsed) — so existing third-party adapters keep working unchanged. Stores that expose absolute-expiry primitives (e.g. Redis `PXAT`) use `expires` directly. Map-like stores wrapped via `new Keyv({ store: new Map() })` are unaffected.
|
|
440
441
|
|
|
441
|
-
> **Adapters
|
|
442
|
+
> **Adapters should enforce expiry — and Keyv double-checks by default.** Declaring `capabilities.expires === true` means a v6 adapter should enforce expiry itself — ideally via a native mechanism (key expiry, TTL index, lease) so the backend reclaims space, and/or a client-side check on read. On top of that, Keyv core filters expired reads at its own layer by default ([`checkExpired`](#checkexpired) is `true`), using the absolute `expires` in the serialized envelope, so `get`/`getMany`/`has` never surface a key past its deadline even on backends whose native expiry is coarse or lazily swept (e.g. Memcached, DynamoDB). Run `@keyv/test-suite`'s `storageTtlTests` against your adapter to verify its own expiry behaviour.
|
|
443
|
+
|
|
444
|
+
# Built-in Adapters: Memory and Bridge
|
|
445
|
+
|
|
446
|
+
Keyv ships with two storage adapters built directly into the core package. You rarely instantiate them yourself — Keyv selects and wires up the right one automatically when you create an instance — but knowing how they work explains how the default in-memory store behaves and how legacy or async stores are adapted to the v6 contract. Both are exported from `keyv`:
|
|
447
|
+
|
|
448
|
+
## KeyvMemoryAdapter
|
|
449
|
+
|
|
450
|
+
`KeyvMemoryAdapter` is the **default store**. When you create a Keyv instance without a store (`new Keyv()`), it uses `new KeyvMemoryAdapter(new Map())` under the hood. It wraps any synchronous, `Map`-like object — the built-in `Map`, [`quick-lru`](https://github.com/sindresorhus/quick-lru), [`lru.min`](https://github.com/wellwelwel/lru.min), or anything exposing `get`, `set`, `delete`, `clear`, and `has`.
|
|
451
|
+
|
|
452
|
+
It adds the pieces a raw `Map` does not have:
|
|
453
|
+
|
|
454
|
+
- **Namespace prefixing** — keys are prefixed with the `namespace` and `keySeparator` (default `:`), so one underlying store can host multiple namespaces. A namespaced `clear()` removes only the current namespace's keys **when the underlying store exposes a `keys()` method** (a standard `Map` does); a minimal store without `keys()` falls back to wiping the **entire** store, so take care sharing one such store across namespaces.
|
|
455
|
+
- **TTL expiry** — the adapter keeps a copy of each entry's expiry in its own `{ value, expires }` wrapper *alongside* the stored value, so it can evict expired entries lazily on `get`, `getMany`, `has`, and `iterator()` without decoding the value. This wrapper is **separate from** the `{ value, expires }` envelope Keyv core builds and runs through serialization/compression/encryption — with the default serializer that encoded payload still contains `expires`, so custom serializer/encryption adapters must still handle the `expires` field; only the adapter's outer copy lives outside the payload. When the underlying store accepts a TTL argument (e.g. QuickLRU), the adapter also passes a derived relative duration so the store can evict on its own.
|
|
456
|
+
- **Batch and iteration** — `getMany`, `setMany`, `hasMany`, `deleteMany`, and an async `iterator()` (when the store supports `entries()`).
|
|
457
|
+
- **v6 contract** — declares `capabilities.expires === true`, so Keyv hands it the absolute `expires` timestamp directly and trusts it to enforce expiry.
|
|
458
|
+
|
|
459
|
+
```js
|
|
460
|
+
import Keyv, { KeyvMemoryAdapter } from 'keyv';
|
|
461
|
+
|
|
462
|
+
// Wrap any Map-like store. Put the namespace on the Keyv options, not the adapter: Keyv
|
|
463
|
+
// propagates its own namespace to the store, overwriting any namespace set on the adapter.
|
|
464
|
+
const keyv = new Keyv({ store: new KeyvMemoryAdapter(new Map()), namespace: 'cache' });
|
|
465
|
+
|
|
466
|
+
// Or wrap an LRU to bound memory usage
|
|
467
|
+
import QuickLRU from 'quick-lru';
|
|
468
|
+
const cache = new Keyv({ store: new KeyvMemoryAdapter(new QuickLRU({ maxSize: 1000 })) });
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
## KeyvBridgeAdapter
|
|
472
|
+
|
|
473
|
+
`KeyvBridgeAdapter` wraps any **promise-based / async store** and adapts it to the v6 storage contract. Keyv applies it automatically when you pass:
|
|
474
|
+
|
|
475
|
+
- a **legacy storage adapter** — a full async adapter that does *not* declare `capabilities.expires` (i.e. pre-v6 third-party adapters), or
|
|
476
|
+
- an **async `Map`-like store** with async `get`, `set`, `delete`, and `clear`. For such a store to actually expire data, its `set(key, value, ttl)` must honor the relative millisecond `ttl` the bridge passes as the third argument — a plain Promise-wrapped `Map` that ignores it won't evict on its own. Keyv's `checkExpired` (on by default) still filters expired entries on read, but they linger in the store until read; for native eviction, prefer a full v6 adapter or a store that honors the `ttl`.
|
|
477
|
+
|
|
478
|
+
This is why existing third-party adapters keep working unchanged on v6. The bridge:
|
|
479
|
+
|
|
480
|
+
- **Converts expiry** — Keyv passes an absolute `expires` timestamp; the bridge converts it back to the relative TTL the wrapped store expects. A write whose deadline has already elapsed is deleted instead of stored, so a past `expires` becomes an absent key — matching how the native adapters treat an already-expired write.
|
|
481
|
+
- **Delegates when it can** — if the wrapped store implements `getMany`, `setMany`, `has`, `hasMany`, `deleteMany`, `iterator`, or `disconnect`, the bridge calls them directly; otherwise it falls back to looping over the single-key primitives.
|
|
482
|
+
- **Handles namespacing both ways** — if the wrapped store manages its own namespace (a full adapter exposing a `namespace` property), the bridge propagates its namespace to the store and does *not* prefix keys, avoiding double-namespacing, so the store's native scoped `clear()` and `iterator()` are used. Otherwise the bridge prefixes keys itself, letting one shared store host multiple namespaces.
|
|
483
|
+
- **Forwards errors** — re-emits `error` events from the wrapped store so connection failures surface on the Keyv instance.
|
|
484
|
+
|
|
485
|
+
```js
|
|
486
|
+
import Keyv, { KeyvBridgeAdapter } from 'keyv';
|
|
487
|
+
|
|
488
|
+
// Usually automatic — just pass the store:
|
|
489
|
+
const keyv = new Keyv({ store: myAsyncStore });
|
|
490
|
+
|
|
491
|
+
// ...which is equivalent to wrapping it explicitly. Put the namespace on the Keyv options —
|
|
492
|
+
// Keyv overwrites any namespace set on the adapter directly:
|
|
493
|
+
const explicit = new Keyv({ store: new KeyvBridgeAdapter(myAsyncStore), namespace: 'cache' });
|
|
494
|
+
```
|
|
442
495
|
|
|
443
496
|
# Using BigMap to Scale
|
|
444
497
|
|
|
@@ -770,9 +823,9 @@ Encryption adapter used to encrypt and decrypt stored values. See [Encryption](#
|
|
|
770
823
|
## options.checkExpired
|
|
771
824
|
|
|
772
825
|
Type: `Boolean`<br />
|
|
773
|
-
Default: `
|
|
826
|
+
Default: `true`
|
|
774
827
|
|
|
775
|
-
When `true
|
|
828
|
+
When `true` (default), Keyv checks expiry at its own layer on `get`/`getMany`/`has`/`hasMany` in addition to the storage adapter. Set to `false` to trust the storage adapter alone. See [.checkExpired](#checkexpired) for details.
|
|
776
829
|
|
|
777
830
|
# Keyv Instance
|
|
778
831
|
|
|
@@ -1010,13 +1063,20 @@ console.log(keyv.encryption); // the encryption adapter
|
|
|
1010
1063
|
## .checkExpired
|
|
1011
1064
|
|
|
1012
1065
|
Type: `Boolean`<br />
|
|
1013
|
-
Default: `
|
|
1066
|
+
Default: `true`
|
|
1067
|
+
|
|
1068
|
+
A read-only property (configured via the `checkExpired` constructor option). When `true` (the default), Keyv checks expiry at its own layer on `get`, `getMany`, `has`, and `hasMany`, deleting any expired entries it encounters. It does this using the absolute `expires` stored in the serialized envelope, so reads stay **millisecond-precise regardless of the adapter**.
|
|
1014
1069
|
|
|
1015
|
-
|
|
1070
|
+
This defaults to `true` because some backends can return entries that are already logically expired: Memcached's `exptime` is **second-granular** (a value can linger up to ~1s past a sub-second deadline), and DynamoDB's native TTL is a **background sweep that can lag by hours** before it deletes expired items. Trusting the backend alone would surface those stale reads; the Keyv-layer check closes that gap.
|
|
1071
|
+
|
|
1072
|
+
Set it to `false` to trust the storage adapter to handle expiry on its own. That skips the extra decode + expiry check on every read (and lets `has`/`hasMany` use the adapter's native existence check), at the cost of backend-granularity expiry.
|
|
1016
1073
|
|
|
1017
1074
|
```js
|
|
1018
|
-
const keyv = new Keyv(
|
|
1019
|
-
console.log(keyv.checkExpired); // true
|
|
1075
|
+
const keyv = new Keyv();
|
|
1076
|
+
console.log(keyv.checkExpired); // true (default)
|
|
1077
|
+
|
|
1078
|
+
const trusting = new Keyv({ checkExpired: false });
|
|
1079
|
+
console.log(trusting.checkExpired); // false
|
|
1020
1080
|
```
|
|
1021
1081
|
|
|
1022
1082
|
## .throwOnErrors
|
package/dist/index.cjs
CHANGED
|
@@ -425,7 +425,7 @@ async function deleteExpiredKeys(keys, data, keyv) {
|
|
|
425
425
|
/**
|
|
426
426
|
* Maps new hook names to their deprecated equivalents so both fire during migration.
|
|
427
427
|
*/
|
|
428
|
-
const deprecatedHookAliases = new Map([
|
|
428
|
+
const deprecatedHookAliases = /* @__PURE__ */ new Map([
|
|
429
429
|
["before:set", "preSet"],
|
|
430
430
|
["after:set", "postSet"],
|
|
431
431
|
["before:get", "preGet"],
|
|
@@ -451,7 +451,7 @@ const deprecatedHookAliases = new Map([
|
|
|
451
451
|
* Build the deprecated-hooks map used by Hookified to warn when old PRE_/POST_ hook names are registered.
|
|
452
452
|
*/
|
|
453
453
|
function buildDeprecatedHooks() {
|
|
454
|
-
return new Map([
|
|
454
|
+
return /* @__PURE__ */ new Map([
|
|
455
455
|
["preSet", "Use KeyvHooks.BEFORE_SET ('before:set') instead"],
|
|
456
456
|
["postSet", "Use KeyvHooks.AFTER_SET ('after:set') instead"],
|
|
457
457
|
["preGet", "Use KeyvHooks.BEFORE_GET ('before:get') instead"],
|
|
@@ -1243,7 +1243,7 @@ var Keyv = class Keyv extends hookified.Hookified {
|
|
|
1243
1243
|
this.initStats(mergedOptions);
|
|
1244
1244
|
if (mergedOptions.store) this.setStore(mergedOptions.store);
|
|
1245
1245
|
this.setTtl(mergedOptions.ttl);
|
|
1246
|
-
this._checkExpired = mergedOptions.checkExpired ??
|
|
1246
|
+
this._checkExpired = mergedOptions.checkExpired ?? true;
|
|
1247
1247
|
}
|
|
1248
1248
|
/**
|
|
1249
1249
|
* Stats manager for tracking cache operation metrics (hits, misses, sets, deletes, errors).
|
|
@@ -1281,8 +1281,10 @@ var Keyv = class Keyv extends hookified.Hookified {
|
|
|
1281
1281
|
_sanitize;
|
|
1282
1282
|
/**
|
|
1283
1283
|
* When true, Keyv checks expiry at its layer on get/getMany/has/hasMany.
|
|
1284
|
+
* Defaults to true so reads stay millisecond-precise even on adapters whose
|
|
1285
|
+
* native expiry is coarse or lazily swept (e.g. Memcached, DynamoDB).
|
|
1284
1286
|
*/
|
|
1285
|
-
_checkExpired =
|
|
1287
|
+
_checkExpired = true;
|
|
1286
1288
|
/**
|
|
1287
1289
|
* Get the current storage adapter.
|
|
1288
1290
|
* @returns {KeyvStorageAdapter} The current storage adapter.
|
|
@@ -1422,7 +1424,8 @@ var Keyv = class Keyv extends hookified.Hookified {
|
|
|
1422
1424
|
}
|
|
1423
1425
|
/**
|
|
1424
1426
|
* Get whether Keyv checks expiry at its own layer on get/getMany/has/hasMany.
|
|
1425
|
-
* When
|
|
1427
|
+
* When true (default), expired entries are filtered (and deleted) by Keyv regardless of
|
|
1428
|
+
* the adapter. Set to false to trust the storage adapter to handle expiry on its own.
|
|
1426
1429
|
* @returns {boolean} `true` if Keyv checks expiry at its layer.
|
|
1427
1430
|
*/
|
|
1428
1431
|
get checkExpired() {
|
|
@@ -1851,7 +1854,7 @@ var Keyv = class Keyv extends hookified.Hookified {
|
|
|
1851
1854
|
let results = [];
|
|
1852
1855
|
try {
|
|
1853
1856
|
if (this._checkExpired) {
|
|
1854
|
-
const rawData = await this.
|
|
1857
|
+
const rawData = await this.storeGetMany(keys);
|
|
1855
1858
|
results = (await this.decodeWithExpire(keys, rawData)).map((row) => row !== void 0);
|
|
1856
1859
|
} else results = await this._store.hasMany(keys);
|
|
1857
1860
|
} catch (error) {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Hookified, IEventEmitter } from "hookified";
|
|
2
|
-
|
|
3
2
|
//#region src/capabilities.d.ts
|
|
4
3
|
type MethodType = "sync" | "async" | "none";
|
|
5
4
|
type KeyvStorageMethod = {
|
|
@@ -27,11 +26,11 @@ type KeyvStorageCapability = {
|
|
|
27
26
|
* (legacy relative-`ttl` adapters) are wrapped by `KeyvBridgeAdapter`, which converts
|
|
28
27
|
* the absolute `expires` back to a relative ttl before delegating.
|
|
29
28
|
*
|
|
30
|
-
* Declaring `expires: true`
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
29
|
+
* Declaring `expires: true` means the adapter is used directly and should ENFORCE expiry —
|
|
30
|
+
* ideally via a native mechanism (TTL index, key expiry, lease) so the backend reclaims
|
|
31
|
+
* space, and/or a client-side check on read. Keyv core also filters expired reads by default
|
|
32
|
+
* (`checkExpired` is on), so an adapter with coarse or lazily-swept native expiry (e.g.
|
|
33
|
+
* Memcached, DynamoDB) still reads millisecond-precise. Validate with `@keyv/test-suite`'s
|
|
35
34
|
* `storageTtlTests`.
|
|
36
35
|
*/
|
|
37
36
|
expires?: boolean;
|
|
@@ -227,11 +226,17 @@ type KeyvSanitizeOptions = {
|
|
|
227
226
|
* Implement this to provide custom sanitization logic to Keyv.
|
|
228
227
|
*/
|
|
229
228
|
type KeyvSanitizeAdapter = {
|
|
230
|
-
/** Whether any sanitization is currently enabled. */
|
|
231
|
-
readonly
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
229
|
+
/** Whether any sanitization is currently enabled. */
|
|
230
|
+
readonly enabled: boolean;
|
|
231
|
+
/** The key sanitization pattern configuration. */
|
|
232
|
+
readonly keys: KeyvSanitizePatterns;
|
|
233
|
+
/** The namespace sanitization pattern configuration. */
|
|
234
|
+
readonly namespace: KeyvSanitizePatterns;
|
|
235
|
+
/** Sanitize a single key. */
|
|
236
|
+
cleanKey(key: string): string;
|
|
237
|
+
/** Sanitize an array of keys. */
|
|
238
|
+
cleanKeys(keys: string[]): string[];
|
|
239
|
+
/** Sanitize a namespace string. */
|
|
235
240
|
cleanNamespace(ns: string): string;
|
|
236
241
|
};
|
|
237
242
|
/**
|
|
@@ -287,9 +292,13 @@ declare class KeyvSanitize implements KeyvSanitizeAdapter {
|
|
|
287
292
|
* Structure of a telemetry event emitted by Keyv.
|
|
288
293
|
*/
|
|
289
294
|
type KeyvTelemetryEvent = {
|
|
290
|
-
/** The event type (e.g. "hit", "miss", "set", "delete", "error"). */
|
|
291
|
-
|
|
292
|
-
|
|
295
|
+
/** The event type (e.g. "hit", "miss", "set", "delete", "error"). */
|
|
296
|
+
event: string;
|
|
297
|
+
/** The cache key involved, if applicable. */
|
|
298
|
+
key?: string;
|
|
299
|
+
/** The namespace of the Keyv instance. */
|
|
300
|
+
namespace?: string;
|
|
301
|
+
/** Unix timestamp in milliseconds when the event occurred. */
|
|
293
302
|
timestamp: number;
|
|
294
303
|
};
|
|
295
304
|
type KeyvStatsOptions = {
|
|
@@ -412,16 +421,29 @@ declare class KeyvStats {
|
|
|
412
421
|
}
|
|
413
422
|
//#endregion
|
|
414
423
|
//#region src/types/keyv.d.ts
|
|
424
|
+
/**
|
|
425
|
+
* A permissive `any` type used at Keyv's dynamic boundaries — untyped store
|
|
426
|
+
* values, parameterized query arguments, and other places where the concrete
|
|
427
|
+
* type is intentionally open. Centralizing it keeps the `noExplicitAny`
|
|
428
|
+
* suppression in one place instead of scattered across the codebase.
|
|
429
|
+
*/
|
|
430
|
+
type KeyvAny = any;
|
|
431
|
+
/**
|
|
432
|
+
* The array counterpart to {@link KeyvAny} (i.e. `any[]`).
|
|
433
|
+
*/
|
|
434
|
+
type KeyvAnyArray = KeyvAny[];
|
|
415
435
|
/**
|
|
416
436
|
* A Map or any Map-like object. Used as a flexible input type for stores.
|
|
417
437
|
*/
|
|
418
|
-
type KeyvMapAny = Map<
|
|
438
|
+
type KeyvMapAny = Map<KeyvAny, KeyvAny> | KeyvAny;
|
|
419
439
|
/**
|
|
420
440
|
* The envelope structure used to store values in Keyv.
|
|
421
441
|
* Wraps the actual value with an optional expiration timestamp.
|
|
422
442
|
*/
|
|
423
443
|
type KeyvValue<Value> = {
|
|
424
|
-
/** The stored value. */
|
|
444
|
+
/** The stored value. */
|
|
445
|
+
value?: Value;
|
|
446
|
+
/** Absolute expiration timestamp in milliseconds since epoch, or `undefined` for no expiry. */
|
|
425
447
|
expires?: number | undefined;
|
|
426
448
|
};
|
|
427
449
|
/** @deprecated Use `KeyvValue` instead. */
|
|
@@ -525,7 +547,7 @@ declare enum KeyvHooks {
|
|
|
525
547
|
* Represents a key-value entry with an optional TTL, used for the public
|
|
526
548
|
* batch API `Keyv.setMany`.
|
|
527
549
|
*/
|
|
528
|
-
type KeyvEntry<Value =
|
|
550
|
+
type KeyvEntry<Value = KeyvAny> = {
|
|
529
551
|
/**
|
|
530
552
|
* Key to set.
|
|
531
553
|
*/
|
|
@@ -545,9 +567,12 @@ type KeyvEntry<Value = any> = {
|
|
|
545
567
|
* `expires` once and passes these to a storage adapter's `setMany`, so adapters
|
|
546
568
|
* never derive expiry themselves.
|
|
547
569
|
*/
|
|
548
|
-
type KeyvStorageEntry<Value =
|
|
549
|
-
/** Key to set. */
|
|
550
|
-
|
|
570
|
+
type KeyvStorageEntry<Value = KeyvAny> = {
|
|
571
|
+
/** Key to set. */
|
|
572
|
+
key: string;
|
|
573
|
+
/** Value to set (already encoded by Keyv core). */
|
|
574
|
+
value: Value;
|
|
575
|
+
/** Absolute expiry as Unix ms since epoch, or `undefined` for no expiry. */
|
|
551
576
|
expires?: number;
|
|
552
577
|
};
|
|
553
578
|
/**
|
|
@@ -568,7 +593,7 @@ type KeyvOptions = {
|
|
|
568
593
|
* The storage adapter instance to be used by Keyv.
|
|
569
594
|
* @default new Map() - in-memory store
|
|
570
595
|
*/
|
|
571
|
-
store?: KeyvStorageAdapter | Map<
|
|
596
|
+
store?: KeyvStorageAdapter | Map<KeyvAny, KeyvAny> | KeyvAny;
|
|
572
597
|
/**
|
|
573
598
|
* Default TTL in milliseconds. Can be overridden by specifying a TTL on `.set()`.
|
|
574
599
|
* @default undefined
|
|
@@ -578,7 +603,7 @@ type KeyvOptions = {
|
|
|
578
603
|
* Enable compression option
|
|
579
604
|
* @default undefined
|
|
580
605
|
*/
|
|
581
|
-
compression?: KeyvCompressionAdapter |
|
|
606
|
+
compression?: KeyvCompressionAdapter | KeyvAny;
|
|
582
607
|
/**
|
|
583
608
|
* Enable or disable statistics (default is false)
|
|
584
609
|
* @default false
|
|
@@ -605,9 +630,13 @@ type KeyvOptions = {
|
|
|
605
630
|
*/
|
|
606
631
|
encryption?: KeyvEncryptionAdapter;
|
|
607
632
|
/**
|
|
608
|
-
* When true, Keyv checks expiry on get/getMany/has/hasMany at its layer
|
|
609
|
-
*
|
|
610
|
-
*
|
|
633
|
+
* When true (default), Keyv checks expiry on get/getMany/has/hasMany at its own layer,
|
|
634
|
+
* filtering (and deleting) expired entries using the absolute `expires` stored in the
|
|
635
|
+
* serialized envelope. This keeps reads millisecond-precise even on adapters whose native
|
|
636
|
+
* expiry is coarse or lazily swept (e.g. Memcached's second-granular exptime, DynamoDB's
|
|
637
|
+
* background TTL sweep that can lag for hours). Set to false to trust the storage adapter
|
|
638
|
+
* to handle expiry on its own (skips the extra decode + expiry check on reads).
|
|
639
|
+
* @default true
|
|
611
640
|
*/
|
|
612
641
|
checkExpired?: boolean;
|
|
613
642
|
};
|
|
@@ -618,7 +647,9 @@ type KeyvOptions = {
|
|
|
618
647
|
* Implement `stringify` and `parse` to control how values are serialized to/from strings.
|
|
619
648
|
*/
|
|
620
649
|
type KeyvSerializationAdapter = {
|
|
621
|
-
/** Converts a value to a string representation. */
|
|
650
|
+
/** Converts a value to a string representation. */
|
|
651
|
+
stringify: (object: unknown) => string | Promise<string>;
|
|
652
|
+
/** Parses a string back into its original value. */
|
|
622
653
|
parse: <T>(data: string) => T | Promise<T>;
|
|
623
654
|
};
|
|
624
655
|
/**
|
|
@@ -626,7 +657,9 @@ type KeyvSerializationAdapter = {
|
|
|
626
657
|
* Implement `compress` and `decompress` to add compression to stored values.
|
|
627
658
|
*/
|
|
628
659
|
type KeyvCompressionAdapter = {
|
|
629
|
-
/** Compresses a string value. */
|
|
660
|
+
/** Compresses a string value. */
|
|
661
|
+
compress(value: string): Promise<string>;
|
|
662
|
+
/** Decompresses a string value back to its original form. */
|
|
630
663
|
decompress(value: string): Promise<string>;
|
|
631
664
|
};
|
|
632
665
|
/**
|
|
@@ -634,7 +667,9 @@ type KeyvCompressionAdapter = {
|
|
|
634
667
|
* Implement `encrypt` and `decrypt` to add encryption to stored values.
|
|
635
668
|
*/
|
|
636
669
|
type KeyvEncryptionAdapter = {
|
|
637
|
-
/** Encrypts a string value. */
|
|
670
|
+
/** Encrypts a string value. */
|
|
671
|
+
encrypt: (data: string) => string | Promise<string>;
|
|
672
|
+
/** Decrypts a string value back to its original form. */
|
|
638
673
|
decrypt: (data: string) => string | Promise<string>;
|
|
639
674
|
};
|
|
640
675
|
type KeyvStorageGetResult<Value> = KeyvValue<Value> | string | undefined;
|
|
@@ -643,33 +678,46 @@ type KeyvStorageGetResult<Value> = KeyvValue<Value> | string | undefined;
|
|
|
643
678
|
* Adapters handle the actual persistence of key-value pairs.
|
|
644
679
|
*/
|
|
645
680
|
type KeyvStorageAdapter = {
|
|
646
|
-
/** Optional namespace for key isolation. */
|
|
681
|
+
/** Optional namespace for key isolation. */
|
|
682
|
+
namespace?: string | undefined;
|
|
647
683
|
/**
|
|
648
684
|
* The adapter's capabilities. v6 adapters set `capabilities.expires = true` (e.g. via
|
|
649
685
|
* `keyvStorageCapability(this)`) to declare they accept an absolute `expires` timestamp
|
|
650
686
|
* on `set`/`setMany`. Full storage adapters that omit it are treated as legacy relative-`ttl`
|
|
651
687
|
* adapters and wrapped by `KeyvBridgeAdapter`, which converts `expires` back to a ttl.
|
|
652
688
|
*
|
|
653
|
-
* Declaring `expires: true`
|
|
654
|
-
*
|
|
655
|
-
*
|
|
656
|
-
|
|
657
|
-
|
|
689
|
+
* Declaring `expires: true` means the adapter should enforce expiry on read so `get`/`getMany`/
|
|
690
|
+
* `has` do not return a key past its deadline (ideally backed by a native mechanism that also
|
|
691
|
+
* reclaims space). Keyv core additionally filters expired reads by default (`checkExpired` is
|
|
692
|
+
* on), as a safety net for backends with coarse or lazily-swept native expiry. See
|
|
693
|
+
* {@link KeyvStorageCapability.expires}.
|
|
694
|
+
*/
|
|
695
|
+
capabilities?: KeyvStorageCapability;
|
|
696
|
+
/** Retrieves a value by key. */
|
|
658
697
|
get<Value>(key: string): Promise<KeyvStorageGetResult<Value>>;
|
|
659
698
|
/**
|
|
660
699
|
* Stores a value with a key and optional absolute expiry.
|
|
661
700
|
* @param expires Absolute expiry as Unix ms since epoch; `undefined` means no expiry.
|
|
662
701
|
* A value `<= Date.now()` is already expired and the adapter may delete/skip it.
|
|
663
702
|
*/
|
|
664
|
-
set(key: string, value: unknown, expires?: number): Promise<boolean>;
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
703
|
+
set(key: string, value: unknown, expires?: number): Promise<boolean>;
|
|
704
|
+
/** Stores multiple entries at once, each with an absolute `expires` timestamp. */
|
|
705
|
+
setMany<Value>(values: KeyvStorageEntry<Value>[]): Promise<boolean[] | undefined>;
|
|
706
|
+
/** Deletes a key from the store. */
|
|
707
|
+
delete(key: string): Promise<boolean>;
|
|
708
|
+
/** Clears all entries from the store (respects namespace if set). */
|
|
709
|
+
clear(): Promise<void>;
|
|
710
|
+
/** Checks if a key exists in the store. */
|
|
711
|
+
has(key: string): Promise<boolean>;
|
|
712
|
+
/** Checks if multiple keys exist in the store. */
|
|
713
|
+
hasMany(keys: string[]): Promise<boolean[]>;
|
|
714
|
+
/** Retrieves multiple values by keys. */
|
|
715
|
+
getMany<Value>(keys: string[]): Promise<Array<KeyvStorageGetResult<Value | undefined>>>;
|
|
716
|
+
/** Disconnects from the store and releases resources. */
|
|
717
|
+
disconnect?(): Promise<void>;
|
|
718
|
+
/** Deletes multiple keys from the store. */
|
|
719
|
+
deleteMany(key: string[]): Promise<boolean[]>;
|
|
720
|
+
/** Returns an async iterator over all key-value pairs. */
|
|
673
721
|
iterator?<Value>(): AsyncGenerator<Array<string | Awaited<Value> | undefined>, void>;
|
|
674
722
|
} & IEventEmitter;
|
|
675
723
|
/**
|
|
@@ -703,26 +751,42 @@ type KeyvBridgeAdapterOptions = {
|
|
|
703
751
|
* will be delegated to the store if present, otherwise fallback implementations are used.
|
|
704
752
|
*/
|
|
705
753
|
type KeyvBridgeStore = {
|
|
706
|
-
/** Store configuration/options (e.g. dialect, url) */
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
754
|
+
/** Store configuration/options (e.g. dialect, url) */
|
|
755
|
+
opts?: KeyvAny;
|
|
756
|
+
/** Namespace the store scopes its keys under, when it manages its own namespacing. */
|
|
757
|
+
namespace?: string;
|
|
758
|
+
/** Retrieves a value by key */
|
|
759
|
+
get(key: string): Promise<KeyvAny>;
|
|
760
|
+
/** Sets a value with a key and optional TTL */
|
|
761
|
+
set(key: string, value: KeyvAny, ttl?: number): Promise<KeyvAny>;
|
|
762
|
+
/** Deletes a key from the store */
|
|
763
|
+
delete(key: string): Promise<boolean>;
|
|
764
|
+
/** Clears all entries from the store */
|
|
765
|
+
clear(): Promise<void>;
|
|
766
|
+
/** Checks if a key exists in the store */
|
|
767
|
+
has?(key: string): Promise<boolean>;
|
|
768
|
+
/** Checks if multiple keys exist in the store */
|
|
769
|
+
hasMany?(keys: string[]): Promise<boolean[]>;
|
|
770
|
+
/** Retrieves multiple values by keys */
|
|
771
|
+
getMany?(keys: string[]): Promise<KeyvAnyArray>;
|
|
772
|
+
/** Sets multiple entries at once */
|
|
773
|
+
setMany?(entries: KeyvAnyArray): Promise<KeyvAny>;
|
|
774
|
+
/** Deletes multiple keys at once */
|
|
775
|
+
deleteMany?(keys: string[]): Promise<boolean | boolean[]>;
|
|
776
|
+
/** Iterates over all entries, optionally filtered by namespace */
|
|
777
|
+
iterator?(namespace?: string): AsyncGenerator<KeyvAny>;
|
|
778
|
+
/** Disconnects from the store */
|
|
779
|
+
disconnect?(): Promise<void>;
|
|
780
|
+
/** Subscribe to events (e.g. error events from v5 adapters) */
|
|
781
|
+
on?(event: string, listener: (...args: KeyvAnyArray) => void): KeyvAny;
|
|
720
782
|
};
|
|
721
783
|
/**
|
|
722
784
|
* Data structure returned when parsing a prefixed key.
|
|
723
785
|
*/
|
|
724
786
|
type KeyPrefixData = {
|
|
725
|
-
/** The namespace extracted from the key, if present */
|
|
787
|
+
/** The namespace extracted from the key, if present */
|
|
788
|
+
namespace?: string;
|
|
789
|
+
/** The key without the namespace prefix */
|
|
726
790
|
key: string;
|
|
727
791
|
};
|
|
728
792
|
/**
|
|
@@ -830,7 +894,7 @@ declare class KeyvBridgeAdapter extends Hookified implements KeyvStorageAdapter
|
|
|
830
894
|
* @param expires - Optional absolute expiry as Unix ms since epoch
|
|
831
895
|
* @returns Always returns true indicating success
|
|
832
896
|
*/
|
|
833
|
-
set(key: string, value:
|
|
897
|
+
set(key: string, value: KeyvAny, expires?: number): Promise<boolean>;
|
|
834
898
|
/**
|
|
835
899
|
* Stores multiple entries in the store at once.
|
|
836
900
|
* Delegates to the store's native setMany if available, otherwise loops over set.
|
|
@@ -884,7 +948,7 @@ declare class KeyvBridgeAdapter extends Hookified implements KeyvStorageAdapter
|
|
|
884
948
|
}
|
|
885
949
|
//#endregion
|
|
886
950
|
//#region src/keyv.d.ts
|
|
887
|
-
declare class Keyv<GenericValue =
|
|
951
|
+
declare class Keyv<GenericValue = KeyvAny> extends Hookified {
|
|
888
952
|
/**
|
|
889
953
|
* Keyv Constructor
|
|
890
954
|
* @param {KeyvStorageAdapter | KeyvOptions | Map<any, any> | any} store to be provided or just the options
|
|
@@ -932,6 +996,8 @@ declare class Keyv<GenericValue = any> extends Hookified {
|
|
|
932
996
|
private _sanitize;
|
|
933
997
|
/**
|
|
934
998
|
* When true, Keyv checks expiry at its layer on get/getMany/has/hasMany.
|
|
999
|
+
* Defaults to true so reads stay millisecond-precise even on adapters whose
|
|
1000
|
+
* native expiry is coarse or lazily swept (e.g. Memcached, DynamoDB).
|
|
935
1001
|
*/
|
|
936
1002
|
private _checkExpired;
|
|
937
1003
|
/**
|
|
@@ -1032,7 +1098,8 @@ declare class Keyv<GenericValue = any> extends Hookified {
|
|
|
1032
1098
|
set stats(stats: KeyvStats);
|
|
1033
1099
|
/**
|
|
1034
1100
|
* Get whether Keyv checks expiry at its own layer on get/getMany/has/hasMany.
|
|
1035
|
-
* When
|
|
1101
|
+
* When true (default), expired entries are filtered (and deleted) by Keyv regardless of
|
|
1102
|
+
* the adapter. Set to false to trust the storage adapter to handle expiry on its own.
|
|
1036
1103
|
* @returns {boolean} `true` if Keyv checks expiry at its layer.
|
|
1037
1104
|
*/
|
|
1038
1105
|
get checkExpired(): boolean;
|
|
@@ -1051,7 +1118,7 @@ declare class Keyv<GenericValue = any> extends Hookified {
|
|
|
1051
1118
|
* @param {unknown} store The store to resolve.
|
|
1052
1119
|
* @returns {KeyvStorageAdapter} A fully-compliant storage adapter.
|
|
1053
1120
|
*/
|
|
1054
|
-
resolveStore(store:
|
|
1121
|
+
resolveStore(store: KeyvAny): KeyvStorageAdapter;
|
|
1055
1122
|
/**
|
|
1056
1123
|
* Sets the storage adapter by resolving it via {@link resolveStore}, then wires up
|
|
1057
1124
|
* error forwarding and namespace propagation.
|
|
@@ -1184,7 +1251,7 @@ declare class Keyv<GenericValue = any> extends Hookified {
|
|
|
1184
1251
|
* filters out expired entries, and deletes them from the store.
|
|
1185
1252
|
* @returns {AsyncGenerator<Array<string | unknown>, void>} An async generator yielding `[key, value]` pairs.
|
|
1186
1253
|
*/
|
|
1187
|
-
iterator(): AsyncGenerator<[string,
|
|
1254
|
+
iterator(): AsyncGenerator<[string, KeyvAny], void>;
|
|
1188
1255
|
/**
|
|
1189
1256
|
* Encodes a value for storage. Pipeline: serialize → compress → encrypt.
|
|
1190
1257
|
* If serialization is not configured, returns the data as-is.
|
|
@@ -1262,10 +1329,15 @@ type KeyvMemoryAdapterOptions = {
|
|
|
1262
1329
|
* Compatible with Map, QuickLRU, lru.min, and other LRU cache implementations.
|
|
1263
1330
|
*/
|
|
1264
1331
|
type KeyvMapType = {
|
|
1265
|
-
/** Retrieves a value by key */
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1332
|
+
/** Retrieves a value by key */
|
|
1333
|
+
get: (key: string) => KeyvAny;
|
|
1334
|
+
/** Sets a value with a key. Additional parameters (like TTL) vary by implementation. */
|
|
1335
|
+
set: (key: string, value: KeyvAny, ...args: KeyvAnyArray) => KeyvAny;
|
|
1336
|
+
/** Deletes a key from the store */
|
|
1337
|
+
delete: (key: string) => boolean;
|
|
1338
|
+
/** Clears all entries from the store */
|
|
1339
|
+
clear: () => void;
|
|
1340
|
+
/** Checks if a key exists in the store */
|
|
1269
1341
|
has: (key: string) => boolean;
|
|
1270
1342
|
};
|
|
1271
1343
|
/**
|
|
@@ -1342,8 +1414,8 @@ declare class KeyvMemoryAdapter extends Hookified implements KeyvStorageAdapter
|
|
|
1342
1414
|
namespace: string;
|
|
1343
1415
|
key: string;
|
|
1344
1416
|
} | {
|
|
1345
|
-
key: string;
|
|
1346
1417
|
namespace?: undefined;
|
|
1418
|
+
key: string;
|
|
1347
1419
|
};
|
|
1348
1420
|
/**
|
|
1349
1421
|
* Retrieves a value from the store by key.
|
|
@@ -1359,7 +1431,7 @@ declare class KeyvMemoryAdapter extends Hookified implements KeyvStorageAdapter
|
|
|
1359
1431
|
* @param expires - Optional absolute expiry as Unix ms since epoch
|
|
1360
1432
|
* @returns Always returns true indicating success
|
|
1361
1433
|
*/
|
|
1362
|
-
set(key: string, value:
|
|
1434
|
+
set(key: string, value: KeyvAny, expires?: number): Promise<boolean>;
|
|
1363
1435
|
/**
|
|
1364
1436
|
* Stores multiple entries in the store at once.
|
|
1365
1437
|
* @param entries - Array of entries containing key, value, and optional absolute `expires`
|
|
@@ -1445,4 +1517,4 @@ declare class KeyvJsonSerializer implements KeyvSerializationAdapter {
|
|
|
1445
1517
|
}
|
|
1446
1518
|
declare const jsonSerializer: KeyvJsonSerializer;
|
|
1447
1519
|
//#endregion
|
|
1448
|
-
export { type DeserializedData, Keyv, Keyv as default, KeyvBridgeAdapter, type KeyvBridgeAdapterOptions, type KeyvBridgeStore, type KeyvCapability, type KeyvCompression, type KeyvCompressionAdapter, type KeyvCompressionCapability, type KeyvCompressionMethods, type KeyvEncryptionAdapter, type KeyvEncryptionCapability, type KeyvEncryptionMethods, type KeyvEntry, KeyvEvents, KeyvHooks, KeyvJsonSerializer, type KeyvMapAny, type KeyvMapType, KeyvMemoryAdapter, type KeyvMemoryAdapterOptions, type KeyvMethods, type KeyvOptions, type KeyvProperties, KeyvSanitize, type KeyvSanitizeAdapter, type KeyvSanitizeOptions, type KeyvSanitizePatterns, type KeyvSerializationAdapter, type KeyvSerializationCapability, type KeyvSerializationMethods, KeyvStats, type KeyvStatsOptions, type KeyvStorageAdapter, type KeyvStorageCapability, type KeyvStorageEntry, type KeyvStorageGetResult, type KeyvStorageMethod, type KeyvStorageMethods, type KeyvStoreAdapter, type KeyvTelemetryEvent, type KeyvValue, type MethodType, createKeyv, detectKeyv, detectKeyvCompression, detectKeyvEncryption, detectKeyvSerialization, detectKeyvStorage, jsonSerializer, keyvStorageCapability };
|
|
1520
|
+
export { type DeserializedData, Keyv, Keyv as default, type KeyvAny, type KeyvAnyArray, KeyvBridgeAdapter, type KeyvBridgeAdapterOptions, type KeyvBridgeStore, type KeyvCapability, type KeyvCompression, type KeyvCompressionAdapter, type KeyvCompressionCapability, type KeyvCompressionMethods, type KeyvEncryptionAdapter, type KeyvEncryptionCapability, type KeyvEncryptionMethods, type KeyvEntry, KeyvEvents, KeyvHooks, KeyvJsonSerializer, type KeyvMapAny, type KeyvMapType, KeyvMemoryAdapter, type KeyvMemoryAdapterOptions, type KeyvMethods, type KeyvOptions, type KeyvProperties, KeyvSanitize, type KeyvSanitizeAdapter, type KeyvSanitizeOptions, type KeyvSanitizePatterns, type KeyvSerializationAdapter, type KeyvSerializationCapability, type KeyvSerializationMethods, KeyvStats, type KeyvStatsOptions, type KeyvStorageAdapter, type KeyvStorageCapability, type KeyvStorageEntry, type KeyvStorageGetResult, type KeyvStorageMethod, type KeyvStorageMethods, type KeyvStoreAdapter, type KeyvTelemetryEvent, type KeyvValue, type MethodType, createKeyv, detectKeyv, detectKeyvCompression, detectKeyvEncryption, detectKeyvSerialization, detectKeyvStorage, jsonSerializer, keyvStorageCapability };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Hookified, IEventEmitter } from "hookified";
|
|
2
|
-
|
|
3
2
|
//#region src/capabilities.d.ts
|
|
4
3
|
type MethodType = "sync" | "async" | "none";
|
|
5
4
|
type KeyvStorageMethod = {
|
|
@@ -27,11 +26,11 @@ type KeyvStorageCapability = {
|
|
|
27
26
|
* (legacy relative-`ttl` adapters) are wrapped by `KeyvBridgeAdapter`, which converts
|
|
28
27
|
* the absolute `expires` back to a relative ttl before delegating.
|
|
29
28
|
*
|
|
30
|
-
* Declaring `expires: true`
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
29
|
+
* Declaring `expires: true` means the adapter is used directly and should ENFORCE expiry —
|
|
30
|
+
* ideally via a native mechanism (TTL index, key expiry, lease) so the backend reclaims
|
|
31
|
+
* space, and/or a client-side check on read. Keyv core also filters expired reads by default
|
|
32
|
+
* (`checkExpired` is on), so an adapter with coarse or lazily-swept native expiry (e.g.
|
|
33
|
+
* Memcached, DynamoDB) still reads millisecond-precise. Validate with `@keyv/test-suite`'s
|
|
35
34
|
* `storageTtlTests`.
|
|
36
35
|
*/
|
|
37
36
|
expires?: boolean;
|
|
@@ -227,11 +226,17 @@ type KeyvSanitizeOptions = {
|
|
|
227
226
|
* Implement this to provide custom sanitization logic to Keyv.
|
|
228
227
|
*/
|
|
229
228
|
type KeyvSanitizeAdapter = {
|
|
230
|
-
/** Whether any sanitization is currently enabled. */
|
|
231
|
-
readonly
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
229
|
+
/** Whether any sanitization is currently enabled. */
|
|
230
|
+
readonly enabled: boolean;
|
|
231
|
+
/** The key sanitization pattern configuration. */
|
|
232
|
+
readonly keys: KeyvSanitizePatterns;
|
|
233
|
+
/** The namespace sanitization pattern configuration. */
|
|
234
|
+
readonly namespace: KeyvSanitizePatterns;
|
|
235
|
+
/** Sanitize a single key. */
|
|
236
|
+
cleanKey(key: string): string;
|
|
237
|
+
/** Sanitize an array of keys. */
|
|
238
|
+
cleanKeys(keys: string[]): string[];
|
|
239
|
+
/** Sanitize a namespace string. */
|
|
235
240
|
cleanNamespace(ns: string): string;
|
|
236
241
|
};
|
|
237
242
|
/**
|
|
@@ -287,9 +292,13 @@ declare class KeyvSanitize implements KeyvSanitizeAdapter {
|
|
|
287
292
|
* Structure of a telemetry event emitted by Keyv.
|
|
288
293
|
*/
|
|
289
294
|
type KeyvTelemetryEvent = {
|
|
290
|
-
/** The event type (e.g. "hit", "miss", "set", "delete", "error"). */
|
|
291
|
-
|
|
292
|
-
|
|
295
|
+
/** The event type (e.g. "hit", "miss", "set", "delete", "error"). */
|
|
296
|
+
event: string;
|
|
297
|
+
/** The cache key involved, if applicable. */
|
|
298
|
+
key?: string;
|
|
299
|
+
/** The namespace of the Keyv instance. */
|
|
300
|
+
namespace?: string;
|
|
301
|
+
/** Unix timestamp in milliseconds when the event occurred. */
|
|
293
302
|
timestamp: number;
|
|
294
303
|
};
|
|
295
304
|
type KeyvStatsOptions = {
|
|
@@ -412,16 +421,29 @@ declare class KeyvStats {
|
|
|
412
421
|
}
|
|
413
422
|
//#endregion
|
|
414
423
|
//#region src/types/keyv.d.ts
|
|
424
|
+
/**
|
|
425
|
+
* A permissive `any` type used at Keyv's dynamic boundaries — untyped store
|
|
426
|
+
* values, parameterized query arguments, and other places where the concrete
|
|
427
|
+
* type is intentionally open. Centralizing it keeps the `noExplicitAny`
|
|
428
|
+
* suppression in one place instead of scattered across the codebase.
|
|
429
|
+
*/
|
|
430
|
+
type KeyvAny = any;
|
|
431
|
+
/**
|
|
432
|
+
* The array counterpart to {@link KeyvAny} (i.e. `any[]`).
|
|
433
|
+
*/
|
|
434
|
+
type KeyvAnyArray = KeyvAny[];
|
|
415
435
|
/**
|
|
416
436
|
* A Map or any Map-like object. Used as a flexible input type for stores.
|
|
417
437
|
*/
|
|
418
|
-
type KeyvMapAny = Map<
|
|
438
|
+
type KeyvMapAny = Map<KeyvAny, KeyvAny> | KeyvAny;
|
|
419
439
|
/**
|
|
420
440
|
* The envelope structure used to store values in Keyv.
|
|
421
441
|
* Wraps the actual value with an optional expiration timestamp.
|
|
422
442
|
*/
|
|
423
443
|
type KeyvValue<Value> = {
|
|
424
|
-
/** The stored value. */
|
|
444
|
+
/** The stored value. */
|
|
445
|
+
value?: Value;
|
|
446
|
+
/** Absolute expiration timestamp in milliseconds since epoch, or `undefined` for no expiry. */
|
|
425
447
|
expires?: number | undefined;
|
|
426
448
|
};
|
|
427
449
|
/** @deprecated Use `KeyvValue` instead. */
|
|
@@ -525,7 +547,7 @@ declare enum KeyvHooks {
|
|
|
525
547
|
* Represents a key-value entry with an optional TTL, used for the public
|
|
526
548
|
* batch API `Keyv.setMany`.
|
|
527
549
|
*/
|
|
528
|
-
type KeyvEntry<Value =
|
|
550
|
+
type KeyvEntry<Value = KeyvAny> = {
|
|
529
551
|
/**
|
|
530
552
|
* Key to set.
|
|
531
553
|
*/
|
|
@@ -545,9 +567,12 @@ type KeyvEntry<Value = any> = {
|
|
|
545
567
|
* `expires` once and passes these to a storage adapter's `setMany`, so adapters
|
|
546
568
|
* never derive expiry themselves.
|
|
547
569
|
*/
|
|
548
|
-
type KeyvStorageEntry<Value =
|
|
549
|
-
/** Key to set. */
|
|
550
|
-
|
|
570
|
+
type KeyvStorageEntry<Value = KeyvAny> = {
|
|
571
|
+
/** Key to set. */
|
|
572
|
+
key: string;
|
|
573
|
+
/** Value to set (already encoded by Keyv core). */
|
|
574
|
+
value: Value;
|
|
575
|
+
/** Absolute expiry as Unix ms since epoch, or `undefined` for no expiry. */
|
|
551
576
|
expires?: number;
|
|
552
577
|
};
|
|
553
578
|
/**
|
|
@@ -568,7 +593,7 @@ type KeyvOptions = {
|
|
|
568
593
|
* The storage adapter instance to be used by Keyv.
|
|
569
594
|
* @default new Map() - in-memory store
|
|
570
595
|
*/
|
|
571
|
-
store?: KeyvStorageAdapter | Map<
|
|
596
|
+
store?: KeyvStorageAdapter | Map<KeyvAny, KeyvAny> | KeyvAny;
|
|
572
597
|
/**
|
|
573
598
|
* Default TTL in milliseconds. Can be overridden by specifying a TTL on `.set()`.
|
|
574
599
|
* @default undefined
|
|
@@ -578,7 +603,7 @@ type KeyvOptions = {
|
|
|
578
603
|
* Enable compression option
|
|
579
604
|
* @default undefined
|
|
580
605
|
*/
|
|
581
|
-
compression?: KeyvCompressionAdapter |
|
|
606
|
+
compression?: KeyvCompressionAdapter | KeyvAny;
|
|
582
607
|
/**
|
|
583
608
|
* Enable or disable statistics (default is false)
|
|
584
609
|
* @default false
|
|
@@ -605,9 +630,13 @@ type KeyvOptions = {
|
|
|
605
630
|
*/
|
|
606
631
|
encryption?: KeyvEncryptionAdapter;
|
|
607
632
|
/**
|
|
608
|
-
* When true, Keyv checks expiry on get/getMany/has/hasMany at its layer
|
|
609
|
-
*
|
|
610
|
-
*
|
|
633
|
+
* When true (default), Keyv checks expiry on get/getMany/has/hasMany at its own layer,
|
|
634
|
+
* filtering (and deleting) expired entries using the absolute `expires` stored in the
|
|
635
|
+
* serialized envelope. This keeps reads millisecond-precise even on adapters whose native
|
|
636
|
+
* expiry is coarse or lazily swept (e.g. Memcached's second-granular exptime, DynamoDB's
|
|
637
|
+
* background TTL sweep that can lag for hours). Set to false to trust the storage adapter
|
|
638
|
+
* to handle expiry on its own (skips the extra decode + expiry check on reads).
|
|
639
|
+
* @default true
|
|
611
640
|
*/
|
|
612
641
|
checkExpired?: boolean;
|
|
613
642
|
};
|
|
@@ -618,7 +647,9 @@ type KeyvOptions = {
|
|
|
618
647
|
* Implement `stringify` and `parse` to control how values are serialized to/from strings.
|
|
619
648
|
*/
|
|
620
649
|
type KeyvSerializationAdapter = {
|
|
621
|
-
/** Converts a value to a string representation. */
|
|
650
|
+
/** Converts a value to a string representation. */
|
|
651
|
+
stringify: (object: unknown) => string | Promise<string>;
|
|
652
|
+
/** Parses a string back into its original value. */
|
|
622
653
|
parse: <T>(data: string) => T | Promise<T>;
|
|
623
654
|
};
|
|
624
655
|
/**
|
|
@@ -626,7 +657,9 @@ type KeyvSerializationAdapter = {
|
|
|
626
657
|
* Implement `compress` and `decompress` to add compression to stored values.
|
|
627
658
|
*/
|
|
628
659
|
type KeyvCompressionAdapter = {
|
|
629
|
-
/** Compresses a string value. */
|
|
660
|
+
/** Compresses a string value. */
|
|
661
|
+
compress(value: string): Promise<string>;
|
|
662
|
+
/** Decompresses a string value back to its original form. */
|
|
630
663
|
decompress(value: string): Promise<string>;
|
|
631
664
|
};
|
|
632
665
|
/**
|
|
@@ -634,7 +667,9 @@ type KeyvCompressionAdapter = {
|
|
|
634
667
|
* Implement `encrypt` and `decrypt` to add encryption to stored values.
|
|
635
668
|
*/
|
|
636
669
|
type KeyvEncryptionAdapter = {
|
|
637
|
-
/** Encrypts a string value. */
|
|
670
|
+
/** Encrypts a string value. */
|
|
671
|
+
encrypt: (data: string) => string | Promise<string>;
|
|
672
|
+
/** Decrypts a string value back to its original form. */
|
|
638
673
|
decrypt: (data: string) => string | Promise<string>;
|
|
639
674
|
};
|
|
640
675
|
type KeyvStorageGetResult<Value> = KeyvValue<Value> | string | undefined;
|
|
@@ -643,33 +678,46 @@ type KeyvStorageGetResult<Value> = KeyvValue<Value> | string | undefined;
|
|
|
643
678
|
* Adapters handle the actual persistence of key-value pairs.
|
|
644
679
|
*/
|
|
645
680
|
type KeyvStorageAdapter = {
|
|
646
|
-
/** Optional namespace for key isolation. */
|
|
681
|
+
/** Optional namespace for key isolation. */
|
|
682
|
+
namespace?: string | undefined;
|
|
647
683
|
/**
|
|
648
684
|
* The adapter's capabilities. v6 adapters set `capabilities.expires = true` (e.g. via
|
|
649
685
|
* `keyvStorageCapability(this)`) to declare they accept an absolute `expires` timestamp
|
|
650
686
|
* on `set`/`setMany`. Full storage adapters that omit it are treated as legacy relative-`ttl`
|
|
651
687
|
* adapters and wrapped by `KeyvBridgeAdapter`, which converts `expires` back to a ttl.
|
|
652
688
|
*
|
|
653
|
-
* Declaring `expires: true`
|
|
654
|
-
*
|
|
655
|
-
*
|
|
656
|
-
|
|
657
|
-
|
|
689
|
+
* Declaring `expires: true` means the adapter should enforce expiry on read so `get`/`getMany`/
|
|
690
|
+
* `has` do not return a key past its deadline (ideally backed by a native mechanism that also
|
|
691
|
+
* reclaims space). Keyv core additionally filters expired reads by default (`checkExpired` is
|
|
692
|
+
* on), as a safety net for backends with coarse or lazily-swept native expiry. See
|
|
693
|
+
* {@link KeyvStorageCapability.expires}.
|
|
694
|
+
*/
|
|
695
|
+
capabilities?: KeyvStorageCapability;
|
|
696
|
+
/** Retrieves a value by key. */
|
|
658
697
|
get<Value>(key: string): Promise<KeyvStorageGetResult<Value>>;
|
|
659
698
|
/**
|
|
660
699
|
* Stores a value with a key and optional absolute expiry.
|
|
661
700
|
* @param expires Absolute expiry as Unix ms since epoch; `undefined` means no expiry.
|
|
662
701
|
* A value `<= Date.now()` is already expired and the adapter may delete/skip it.
|
|
663
702
|
*/
|
|
664
|
-
set(key: string, value: unknown, expires?: number): Promise<boolean>;
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
703
|
+
set(key: string, value: unknown, expires?: number): Promise<boolean>;
|
|
704
|
+
/** Stores multiple entries at once, each with an absolute `expires` timestamp. */
|
|
705
|
+
setMany<Value>(values: KeyvStorageEntry<Value>[]): Promise<boolean[] | undefined>;
|
|
706
|
+
/** Deletes a key from the store. */
|
|
707
|
+
delete(key: string): Promise<boolean>;
|
|
708
|
+
/** Clears all entries from the store (respects namespace if set). */
|
|
709
|
+
clear(): Promise<void>;
|
|
710
|
+
/** Checks if a key exists in the store. */
|
|
711
|
+
has(key: string): Promise<boolean>;
|
|
712
|
+
/** Checks if multiple keys exist in the store. */
|
|
713
|
+
hasMany(keys: string[]): Promise<boolean[]>;
|
|
714
|
+
/** Retrieves multiple values by keys. */
|
|
715
|
+
getMany<Value>(keys: string[]): Promise<Array<KeyvStorageGetResult<Value | undefined>>>;
|
|
716
|
+
/** Disconnects from the store and releases resources. */
|
|
717
|
+
disconnect?(): Promise<void>;
|
|
718
|
+
/** Deletes multiple keys from the store. */
|
|
719
|
+
deleteMany(key: string[]): Promise<boolean[]>;
|
|
720
|
+
/** Returns an async iterator over all key-value pairs. */
|
|
673
721
|
iterator?<Value>(): AsyncGenerator<Array<string | Awaited<Value> | undefined>, void>;
|
|
674
722
|
} & IEventEmitter;
|
|
675
723
|
/**
|
|
@@ -703,26 +751,42 @@ type KeyvBridgeAdapterOptions = {
|
|
|
703
751
|
* will be delegated to the store if present, otherwise fallback implementations are used.
|
|
704
752
|
*/
|
|
705
753
|
type KeyvBridgeStore = {
|
|
706
|
-
/** Store configuration/options (e.g. dialect, url) */
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
754
|
+
/** Store configuration/options (e.g. dialect, url) */
|
|
755
|
+
opts?: KeyvAny;
|
|
756
|
+
/** Namespace the store scopes its keys under, when it manages its own namespacing. */
|
|
757
|
+
namespace?: string;
|
|
758
|
+
/** Retrieves a value by key */
|
|
759
|
+
get(key: string): Promise<KeyvAny>;
|
|
760
|
+
/** Sets a value with a key and optional TTL */
|
|
761
|
+
set(key: string, value: KeyvAny, ttl?: number): Promise<KeyvAny>;
|
|
762
|
+
/** Deletes a key from the store */
|
|
763
|
+
delete(key: string): Promise<boolean>;
|
|
764
|
+
/** Clears all entries from the store */
|
|
765
|
+
clear(): Promise<void>;
|
|
766
|
+
/** Checks if a key exists in the store */
|
|
767
|
+
has?(key: string): Promise<boolean>;
|
|
768
|
+
/** Checks if multiple keys exist in the store */
|
|
769
|
+
hasMany?(keys: string[]): Promise<boolean[]>;
|
|
770
|
+
/** Retrieves multiple values by keys */
|
|
771
|
+
getMany?(keys: string[]): Promise<KeyvAnyArray>;
|
|
772
|
+
/** Sets multiple entries at once */
|
|
773
|
+
setMany?(entries: KeyvAnyArray): Promise<KeyvAny>;
|
|
774
|
+
/** Deletes multiple keys at once */
|
|
775
|
+
deleteMany?(keys: string[]): Promise<boolean | boolean[]>;
|
|
776
|
+
/** Iterates over all entries, optionally filtered by namespace */
|
|
777
|
+
iterator?(namespace?: string): AsyncGenerator<KeyvAny>;
|
|
778
|
+
/** Disconnects from the store */
|
|
779
|
+
disconnect?(): Promise<void>;
|
|
780
|
+
/** Subscribe to events (e.g. error events from v5 adapters) */
|
|
781
|
+
on?(event: string, listener: (...args: KeyvAnyArray) => void): KeyvAny;
|
|
720
782
|
};
|
|
721
783
|
/**
|
|
722
784
|
* Data structure returned when parsing a prefixed key.
|
|
723
785
|
*/
|
|
724
786
|
type KeyPrefixData = {
|
|
725
|
-
/** The namespace extracted from the key, if present */
|
|
787
|
+
/** The namespace extracted from the key, if present */
|
|
788
|
+
namespace?: string;
|
|
789
|
+
/** The key without the namespace prefix */
|
|
726
790
|
key: string;
|
|
727
791
|
};
|
|
728
792
|
/**
|
|
@@ -830,7 +894,7 @@ declare class KeyvBridgeAdapter extends Hookified implements KeyvStorageAdapter
|
|
|
830
894
|
* @param expires - Optional absolute expiry as Unix ms since epoch
|
|
831
895
|
* @returns Always returns true indicating success
|
|
832
896
|
*/
|
|
833
|
-
set(key: string, value:
|
|
897
|
+
set(key: string, value: KeyvAny, expires?: number): Promise<boolean>;
|
|
834
898
|
/**
|
|
835
899
|
* Stores multiple entries in the store at once.
|
|
836
900
|
* Delegates to the store's native setMany if available, otherwise loops over set.
|
|
@@ -884,7 +948,7 @@ declare class KeyvBridgeAdapter extends Hookified implements KeyvStorageAdapter
|
|
|
884
948
|
}
|
|
885
949
|
//#endregion
|
|
886
950
|
//#region src/keyv.d.ts
|
|
887
|
-
declare class Keyv<GenericValue =
|
|
951
|
+
declare class Keyv<GenericValue = KeyvAny> extends Hookified {
|
|
888
952
|
/**
|
|
889
953
|
* Keyv Constructor
|
|
890
954
|
* @param {KeyvStorageAdapter | KeyvOptions | Map<any, any> | any} store to be provided or just the options
|
|
@@ -932,6 +996,8 @@ declare class Keyv<GenericValue = any> extends Hookified {
|
|
|
932
996
|
private _sanitize;
|
|
933
997
|
/**
|
|
934
998
|
* When true, Keyv checks expiry at its layer on get/getMany/has/hasMany.
|
|
999
|
+
* Defaults to true so reads stay millisecond-precise even on adapters whose
|
|
1000
|
+
* native expiry is coarse or lazily swept (e.g. Memcached, DynamoDB).
|
|
935
1001
|
*/
|
|
936
1002
|
private _checkExpired;
|
|
937
1003
|
/**
|
|
@@ -1032,7 +1098,8 @@ declare class Keyv<GenericValue = any> extends Hookified {
|
|
|
1032
1098
|
set stats(stats: KeyvStats);
|
|
1033
1099
|
/**
|
|
1034
1100
|
* Get whether Keyv checks expiry at its own layer on get/getMany/has/hasMany.
|
|
1035
|
-
* When
|
|
1101
|
+
* When true (default), expired entries are filtered (and deleted) by Keyv regardless of
|
|
1102
|
+
* the adapter. Set to false to trust the storage adapter to handle expiry on its own.
|
|
1036
1103
|
* @returns {boolean} `true` if Keyv checks expiry at its layer.
|
|
1037
1104
|
*/
|
|
1038
1105
|
get checkExpired(): boolean;
|
|
@@ -1051,7 +1118,7 @@ declare class Keyv<GenericValue = any> extends Hookified {
|
|
|
1051
1118
|
* @param {unknown} store The store to resolve.
|
|
1052
1119
|
* @returns {KeyvStorageAdapter} A fully-compliant storage adapter.
|
|
1053
1120
|
*/
|
|
1054
|
-
resolveStore(store:
|
|
1121
|
+
resolveStore(store: KeyvAny): KeyvStorageAdapter;
|
|
1055
1122
|
/**
|
|
1056
1123
|
* Sets the storage adapter by resolving it via {@link resolveStore}, then wires up
|
|
1057
1124
|
* error forwarding and namespace propagation.
|
|
@@ -1184,7 +1251,7 @@ declare class Keyv<GenericValue = any> extends Hookified {
|
|
|
1184
1251
|
* filters out expired entries, and deletes them from the store.
|
|
1185
1252
|
* @returns {AsyncGenerator<Array<string | unknown>, void>} An async generator yielding `[key, value]` pairs.
|
|
1186
1253
|
*/
|
|
1187
|
-
iterator(): AsyncGenerator<[string,
|
|
1254
|
+
iterator(): AsyncGenerator<[string, KeyvAny], void>;
|
|
1188
1255
|
/**
|
|
1189
1256
|
* Encodes a value for storage. Pipeline: serialize → compress → encrypt.
|
|
1190
1257
|
* If serialization is not configured, returns the data as-is.
|
|
@@ -1262,10 +1329,15 @@ type KeyvMemoryAdapterOptions = {
|
|
|
1262
1329
|
* Compatible with Map, QuickLRU, lru.min, and other LRU cache implementations.
|
|
1263
1330
|
*/
|
|
1264
1331
|
type KeyvMapType = {
|
|
1265
|
-
/** Retrieves a value by key */
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1332
|
+
/** Retrieves a value by key */
|
|
1333
|
+
get: (key: string) => KeyvAny;
|
|
1334
|
+
/** Sets a value with a key. Additional parameters (like TTL) vary by implementation. */
|
|
1335
|
+
set: (key: string, value: KeyvAny, ...args: KeyvAnyArray) => KeyvAny;
|
|
1336
|
+
/** Deletes a key from the store */
|
|
1337
|
+
delete: (key: string) => boolean;
|
|
1338
|
+
/** Clears all entries from the store */
|
|
1339
|
+
clear: () => void;
|
|
1340
|
+
/** Checks if a key exists in the store */
|
|
1269
1341
|
has: (key: string) => boolean;
|
|
1270
1342
|
};
|
|
1271
1343
|
/**
|
|
@@ -1342,8 +1414,8 @@ declare class KeyvMemoryAdapter extends Hookified implements KeyvStorageAdapter
|
|
|
1342
1414
|
namespace: string;
|
|
1343
1415
|
key: string;
|
|
1344
1416
|
} | {
|
|
1345
|
-
key: string;
|
|
1346
1417
|
namespace?: undefined;
|
|
1418
|
+
key: string;
|
|
1347
1419
|
};
|
|
1348
1420
|
/**
|
|
1349
1421
|
* Retrieves a value from the store by key.
|
|
@@ -1359,7 +1431,7 @@ declare class KeyvMemoryAdapter extends Hookified implements KeyvStorageAdapter
|
|
|
1359
1431
|
* @param expires - Optional absolute expiry as Unix ms since epoch
|
|
1360
1432
|
* @returns Always returns true indicating success
|
|
1361
1433
|
*/
|
|
1362
|
-
set(key: string, value:
|
|
1434
|
+
set(key: string, value: KeyvAny, expires?: number): Promise<boolean>;
|
|
1363
1435
|
/**
|
|
1364
1436
|
* Stores multiple entries in the store at once.
|
|
1365
1437
|
* @param entries - Array of entries containing key, value, and optional absolute `expires`
|
|
@@ -1445,4 +1517,4 @@ declare class KeyvJsonSerializer implements KeyvSerializationAdapter {
|
|
|
1445
1517
|
}
|
|
1446
1518
|
declare const jsonSerializer: KeyvJsonSerializer;
|
|
1447
1519
|
//#endregion
|
|
1448
|
-
export { type DeserializedData, Keyv, Keyv as default, KeyvBridgeAdapter, type KeyvBridgeAdapterOptions, type KeyvBridgeStore, type KeyvCapability, type KeyvCompression, type KeyvCompressionAdapter, type KeyvCompressionCapability, type KeyvCompressionMethods, type KeyvEncryptionAdapter, type KeyvEncryptionCapability, type KeyvEncryptionMethods, type KeyvEntry, KeyvEvents, KeyvHooks, KeyvJsonSerializer, type KeyvMapAny, type KeyvMapType, KeyvMemoryAdapter, type KeyvMemoryAdapterOptions, type KeyvMethods, type KeyvOptions, type KeyvProperties, KeyvSanitize, type KeyvSanitizeAdapter, type KeyvSanitizeOptions, type KeyvSanitizePatterns, type KeyvSerializationAdapter, type KeyvSerializationCapability, type KeyvSerializationMethods, KeyvStats, type KeyvStatsOptions, type KeyvStorageAdapter, type KeyvStorageCapability, type KeyvStorageEntry, type KeyvStorageGetResult, type KeyvStorageMethod, type KeyvStorageMethods, type KeyvStoreAdapter, type KeyvTelemetryEvent, type KeyvValue, type MethodType, createKeyv, detectKeyv, detectKeyvCompression, detectKeyvEncryption, detectKeyvSerialization, detectKeyvStorage, jsonSerializer, keyvStorageCapability };
|
|
1520
|
+
export { type DeserializedData, Keyv, Keyv as default, type KeyvAny, type KeyvAnyArray, KeyvBridgeAdapter, type KeyvBridgeAdapterOptions, type KeyvBridgeStore, type KeyvCapability, type KeyvCompression, type KeyvCompressionAdapter, type KeyvCompressionCapability, type KeyvCompressionMethods, type KeyvEncryptionAdapter, type KeyvEncryptionCapability, type KeyvEncryptionMethods, type KeyvEntry, KeyvEvents, KeyvHooks, KeyvJsonSerializer, type KeyvMapAny, type KeyvMapType, KeyvMemoryAdapter, type KeyvMemoryAdapterOptions, type KeyvMethods, type KeyvOptions, type KeyvProperties, KeyvSanitize, type KeyvSanitizeAdapter, type KeyvSanitizeOptions, type KeyvSanitizePatterns, type KeyvSerializationAdapter, type KeyvSerializationCapability, type KeyvSerializationMethods, KeyvStats, type KeyvStatsOptions, type KeyvStorageAdapter, type KeyvStorageCapability, type KeyvStorageEntry, type KeyvStorageGetResult, type KeyvStorageMethod, type KeyvStorageMethods, type KeyvStoreAdapter, type KeyvTelemetryEvent, type KeyvValue, type MethodType, createKeyv, detectKeyv, detectKeyvCompression, detectKeyvEncryption, detectKeyvSerialization, detectKeyvStorage, jsonSerializer, keyvStorageCapability };
|
package/dist/index.mjs
CHANGED
|
@@ -421,7 +421,7 @@ async function deleteExpiredKeys(keys, data, keyv) {
|
|
|
421
421
|
/**
|
|
422
422
|
* Maps new hook names to their deprecated equivalents so both fire during migration.
|
|
423
423
|
*/
|
|
424
|
-
const deprecatedHookAliases = new Map([
|
|
424
|
+
const deprecatedHookAliases = /* @__PURE__ */ new Map([
|
|
425
425
|
["before:set", "preSet"],
|
|
426
426
|
["after:set", "postSet"],
|
|
427
427
|
["before:get", "preGet"],
|
|
@@ -447,7 +447,7 @@ const deprecatedHookAliases = new Map([
|
|
|
447
447
|
* Build the deprecated-hooks map used by Hookified to warn when old PRE_/POST_ hook names are registered.
|
|
448
448
|
*/
|
|
449
449
|
function buildDeprecatedHooks() {
|
|
450
|
-
return new Map([
|
|
450
|
+
return /* @__PURE__ */ new Map([
|
|
451
451
|
["preSet", "Use KeyvHooks.BEFORE_SET ('before:set') instead"],
|
|
452
452
|
["postSet", "Use KeyvHooks.AFTER_SET ('after:set') instead"],
|
|
453
453
|
["preGet", "Use KeyvHooks.BEFORE_GET ('before:get') instead"],
|
|
@@ -1239,7 +1239,7 @@ var Keyv = class Keyv extends Hookified {
|
|
|
1239
1239
|
this.initStats(mergedOptions);
|
|
1240
1240
|
if (mergedOptions.store) this.setStore(mergedOptions.store);
|
|
1241
1241
|
this.setTtl(mergedOptions.ttl);
|
|
1242
|
-
this._checkExpired = mergedOptions.checkExpired ??
|
|
1242
|
+
this._checkExpired = mergedOptions.checkExpired ?? true;
|
|
1243
1243
|
}
|
|
1244
1244
|
/**
|
|
1245
1245
|
* Stats manager for tracking cache operation metrics (hits, misses, sets, deletes, errors).
|
|
@@ -1277,8 +1277,10 @@ var Keyv = class Keyv extends Hookified {
|
|
|
1277
1277
|
_sanitize;
|
|
1278
1278
|
/**
|
|
1279
1279
|
* When true, Keyv checks expiry at its layer on get/getMany/has/hasMany.
|
|
1280
|
+
* Defaults to true so reads stay millisecond-precise even on adapters whose
|
|
1281
|
+
* native expiry is coarse or lazily swept (e.g. Memcached, DynamoDB).
|
|
1280
1282
|
*/
|
|
1281
|
-
_checkExpired =
|
|
1283
|
+
_checkExpired = true;
|
|
1282
1284
|
/**
|
|
1283
1285
|
* Get the current storage adapter.
|
|
1284
1286
|
* @returns {KeyvStorageAdapter} The current storage adapter.
|
|
@@ -1418,7 +1420,8 @@ var Keyv = class Keyv extends Hookified {
|
|
|
1418
1420
|
}
|
|
1419
1421
|
/**
|
|
1420
1422
|
* Get whether Keyv checks expiry at its own layer on get/getMany/has/hasMany.
|
|
1421
|
-
* When
|
|
1423
|
+
* When true (default), expired entries are filtered (and deleted) by Keyv regardless of
|
|
1424
|
+
* the adapter. Set to false to trust the storage adapter to handle expiry on its own.
|
|
1422
1425
|
* @returns {boolean} `true` if Keyv checks expiry at its layer.
|
|
1423
1426
|
*/
|
|
1424
1427
|
get checkExpired() {
|
|
@@ -1847,7 +1850,7 @@ var Keyv = class Keyv extends Hookified {
|
|
|
1847
1850
|
let results = [];
|
|
1848
1851
|
try {
|
|
1849
1852
|
if (this._checkExpired) {
|
|
1850
|
-
const rawData = await this.
|
|
1853
|
+
const rawData = await this.storeGetMany(keys);
|
|
1851
1854
|
results = (await this.decodeWithExpire(keys, rawData)).map((row) => row !== void 0);
|
|
1852
1855
|
} else results = await this._store.hasMany(keys);
|
|
1853
1856
|
} catch (error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keyv",
|
|
3
|
-
"version": "6.0.0-
|
|
3
|
+
"version": "6.0.0-rc.1",
|
|
4
4
|
"description": "Simple key-value storage with support for multiple backends",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.mjs",
|
|
@@ -50,27 +50,27 @@
|
|
|
50
50
|
},
|
|
51
51
|
"homepage": "https://github.com/jaredwray/keyv",
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"hookified": "^3.0.
|
|
53
|
+
"hookified": "^3.0.2"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@biomejs/biome": "^2.
|
|
57
|
-
"@faker-js/faker": "^10.
|
|
58
|
-
"@vitest/coverage-v8": "^4.1.
|
|
59
|
-
"happy-dom": "^20.
|
|
56
|
+
"@biomejs/biome": "^2.5.6",
|
|
57
|
+
"@faker-js/faker": "^10.5.0",
|
|
58
|
+
"@vitest/coverage-v8": "^4.1.10",
|
|
59
|
+
"happy-dom": "^20.11.1",
|
|
60
60
|
"keyv-anyredis": "^3.3.0",
|
|
61
|
-
"keyv-file": "^5.3.
|
|
61
|
+
"keyv-file": "^5.3.5",
|
|
62
62
|
"lru.min": "^1.1.4",
|
|
63
63
|
"quick-lru": "^7.0.0",
|
|
64
64
|
"rimraf": "^6.1.3",
|
|
65
65
|
"timekeeper": "^2.3.1",
|
|
66
66
|
"tsd": "^0.33.0",
|
|
67
|
-
"vitest": "^4.1.
|
|
67
|
+
"vitest": "^4.1.10"
|
|
68
68
|
},
|
|
69
69
|
"tsd": {
|
|
70
70
|
"directory": "test"
|
|
71
71
|
},
|
|
72
72
|
"engines": {
|
|
73
|
-
"node": ">= 22.
|
|
73
|
+
"node": ">= 22.19.0"
|
|
74
74
|
},
|
|
75
75
|
"files": [
|
|
76
76
|
"dist",
|