keyv 6.0.0-beta.3 → 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/dist/index.cjs CHANGED
@@ -177,6 +177,26 @@ function detectKeyvStorage(obj) {
177
177
  };
178
178
  }
179
179
  /**
180
+ * Build the capability descriptor for a v6 storage adapter: the structurally detected
181
+ * methods plus `expires: true`, declaring that the adapter accepts an absolute `expires`
182
+ * timestamp on `set`/`setMany`. First-party adapters expose this from their `capabilities`
183
+ * getter so Keyv uses them directly instead of bridging.
184
+ * @param adapter - The storage adapter to describe (typically `this`).
185
+ * @returns A {@link KeyvStorageCapability} with `expires` set to `true`.
186
+ * @example
187
+ * ```typescript
188
+ * public get capabilities(): KeyvStorageCapability {
189
+ * return keyvStorageCapability(this);
190
+ * }
191
+ * ```
192
+ */
193
+ function keyvStorageCapability(adapter) {
194
+ return {
195
+ ...detectKeyvStorage(adapter),
196
+ expires: true
197
+ };
198
+ }
199
+ /**
180
200
  * Detect whether an object implements the Keyv compression adapter interface
181
201
  * @param obj - The object to check
182
202
  * @returns A {@link KeyvCompressionCapability} where `compatible` is `true` when both `compress` and `decompress` methods are present
@@ -405,7 +425,7 @@ async function deleteExpiredKeys(keys, data, keyv) {
405
425
  /**
406
426
  * Maps new hook names to their deprecated equivalents so both fire during migration.
407
427
  */
408
- const deprecatedHookAliases = new Map([
428
+ const deprecatedHookAliases = /* @__PURE__ */ new Map([
409
429
  ["before:set", "preSet"],
410
430
  ["after:set", "postSet"],
411
431
  ["before:get", "preGet"],
@@ -431,7 +451,7 @@ const deprecatedHookAliases = new Map([
431
451
  * Build the deprecated-hooks map used by Hookified to warn when old PRE_/POST_ hook names are registered.
432
452
  */
433
453
  function buildDeprecatedHooks() {
434
- return new Map([
454
+ return /* @__PURE__ */ new Map([
435
455
  ["preSet", "Use KeyvHooks.BEFORE_SET ('before:set') instead"],
436
456
  ["postSet", "Use KeyvHooks.AFTER_SET ('after:set') instead"],
437
457
  ["preGet", "Use KeyvHooks.BEFORE_GET ('before:get') instead"],
@@ -479,6 +499,12 @@ var KeyvBridgeAdapter = class extends hookified.Hookified {
479
499
  _keySeparator = ":";
480
500
  _capabilities;
481
501
  /**
502
+ * Whether the wrapped store manages its own namespace (exposes a `namespace` property).
503
+ * When true the bridge propagates its namespace to the store and does not prefix keys,
504
+ * so the store's native, namespace-scoped operations (notably `clear()`) are used directly.
505
+ */
506
+ _storeHandlesNamespace;
507
+ /**
482
508
  * Creates a new KeyvBridgeAdapter instance.
483
509
  * @param store - The underlying promise-based store to bridge
484
510
  * @param options - Configuration options for the adapter
@@ -486,9 +512,11 @@ var KeyvBridgeAdapter = class extends hookified.Hookified {
486
512
  constructor(store, options) {
487
513
  super({ throwOnHookError: false });
488
514
  this._store = store;
515
+ this._capabilities = detectKeyvStorage(store);
516
+ this._storeHandlesNamespace = this._capabilities.store === "keyvStorage" && "namespace" in store;
489
517
  if (options?.keySeparator) this._keySeparator = options.keySeparator;
490
518
  if (options?.namespace) this._namespace = options.namespace;
491
- this._capabilities = detectKeyvStorage(store);
519
+ if (this._storeHandlesNamespace) this._store.namespace = this._namespace;
492
520
  if (typeof store.on === "function") store.on("error", (error) => this.emit("error", error));
493
521
  }
494
522
  /**
@@ -504,10 +532,15 @@ var KeyvBridgeAdapter = class extends hookified.Hookified {
504
532
  this._store = store;
505
533
  }
506
534
  /**
507
- * Gets the detected capabilities of the underlying store.
535
+ * Gets the capabilities of the underlying store, with `expires: true` to declare that
536
+ * the bridge accepts an absolute `expires` timestamp (which it converts to a ttl for the
537
+ * wrapped legacy store).
508
538
  */
509
539
  get capabilities() {
510
- return this._capabilities;
540
+ return {
541
+ ...this._capabilities,
542
+ expires: true
543
+ };
511
544
  }
512
545
  /**
513
546
  * Gets the current key separator used between namespace and key.
@@ -528,10 +561,12 @@ var KeyvBridgeAdapter = class extends hookified.Hookified {
528
561
  return this._namespace;
529
562
  }
530
563
  /**
531
- * Sets the namespace.
564
+ * Sets the namespace. When the wrapped store manages its own namespace, the value is
565
+ * propagated to it so its native scoped operations stay in sync.
532
566
  */
533
567
  set namespace(namespace) {
534
568
  this._namespace = namespace;
569
+ if (this._storeHandlesNamespace) this._store.namespace = namespace;
535
570
  }
536
571
  /**
537
572
  * Creates a prefixed key by combining the namespace and key with the separator.
@@ -540,6 +575,7 @@ var KeyvBridgeAdapter = class extends hookified.Hookified {
540
575
  * @returns The prefixed key if namespace is provided, otherwise the original key
541
576
  */
542
577
  getKeyPrefix(key, namespace) {
578
+ if (this._storeHandlesNamespace) return key;
543
579
  if (namespace) return `${namespace}${this._keySeparator}${key}`;
544
580
  return key;
545
581
  }
@@ -605,35 +641,49 @@ var KeyvBridgeAdapter = class extends hookified.Hookified {
605
641
  return values;
606
642
  }
607
643
  /**
608
- * Stores a value in the store with an optional TTL.
644
+ * Stores a value in the store with an optional absolute expiry.
645
+ * The wrapped store's `set(key, value, ttl?)` expects a relative duration, so the absolute
646
+ * `expires` is converted to a remaining ttl (`undefined` when already expired or absent).
647
+ * The value is passed through unchanged — the bridge does not wrap it in an envelope — so
648
+ * expiry is enforced by the wrapped legacy store's own ttl handling. (The read-side
649
+ * {@link isDataExpired} check only fires when a caller stores a raw `{ value, expires }`
650
+ * object directly; when Keyv core drives the bridge the value arrives already encoded.)
609
651
  * @param key - The key to store the value under
610
652
  * @param value - The value to store
611
- * @param ttl - Optional time-to-live in milliseconds
653
+ * @param expires - Optional absolute expiry as Unix ms since epoch
612
654
  * @returns Always returns true indicating success
613
655
  */
614
- async set(key, value, ttl) {
656
+ async set(key, value, expires) {
615
657
  const keyPrefix = this.getKeyPrefix(key, this._namespace);
616
- const result = await this._store.set(keyPrefix, value, ttl);
658
+ if (typeof expires === "number" && expires <= Date.now()) {
659
+ await this._store.delete(keyPrefix);
660
+ return true;
661
+ }
662
+ const result = await this._store.set(keyPrefix, value, ttlFromExpires(expires));
617
663
  if (typeof result === "boolean") return result;
618
664
  return true;
619
665
  }
620
666
  /**
621
667
  * Stores multiple entries in the store at once.
622
668
  * Delegates to the store's native setMany if available, otherwise loops over set.
623
- * @param entries - Array of entries containing key, value, and optional TTL
669
+ * @param entries - Array of entries containing key, value, and optional absolute `expires`
624
670
  */
625
671
  async setMany(entries) {
626
672
  if (this._capabilities.methods.setMany.exists) {
627
- const prefixedEntries = entries.map((entry) => ({
628
- ...entry,
629
- key: this.getKeyPrefix(entry.key, this._namespace)
630
- }));
631
- await this._store.setMany?.(prefixedEntries);
673
+ const now = Date.now();
674
+ const isExpired = (entry) => typeof entry.expires === "number" && entry.expires <= now;
675
+ const live = entries.filter((entry) => !isExpired(entry));
676
+ if (live.length > 0) await this._store.setMany?.(live.map((entry) => ({
677
+ key: this.getKeyPrefix(entry.key, this._namespace),
678
+ value: entry.value,
679
+ ttl: ttlFromExpires(entry.expires)
680
+ })));
681
+ for (const entry of entries) if (isExpired(entry)) await this._store.delete(this.getKeyPrefix(entry.key, this._namespace));
632
682
  return entries.map(() => true);
633
683
  }
634
684
  const results = [];
635
685
  for (const entry of entries) {
636
- await this.set(entry.key, entry.value, entry.ttl);
686
+ await this.set(entry.key, entry.value, entry.expires);
637
687
  results.push(true);
638
688
  }
639
689
  return results;
@@ -707,6 +757,10 @@ var KeyvBridgeAdapter = class extends hookified.Hookified {
707
757
  * entire store is cleared.
708
758
  */
709
759
  async clear() {
760
+ if (this._namespace && this._storeHandlesNamespace) {
761
+ await this._store.clear();
762
+ return;
763
+ }
710
764
  if (!this._namespace || !this._capabilities.methods.iterator.exists) {
711
765
  await this._store.clear();
712
766
  return;
@@ -728,7 +782,7 @@ var KeyvBridgeAdapter = class extends hookified.Hookified {
728
782
  async *iterator() {
729
783
  if (!this._capabilities.methods.iterator.exists) return;
730
784
  const namespace = this._namespace;
731
- const prefix = namespace ? `${namespace}${this._keySeparator}` : void 0;
785
+ const prefix = namespace && !this._storeHandlesNamespace ? `${namespace}${this._keySeparator}` : void 0;
732
786
  /* v8 ignore next -- @preserve */
733
787
  for await (const entry of this._store.iterator?.(this._namespace) ?? []) {
734
788
  const [key, data] = Array.isArray(entry) ? entry : [entry];
@@ -1168,6 +1222,29 @@ var KeyvStats = class {
1168
1222
  //#endregion
1169
1223
  //#region src/keyv.ts
1170
1224
  var Keyv = class Keyv extends hookified.Hookified {
1225
+ /**
1226
+ * Keyv Constructor
1227
+ * @param {KeyvStorageAdapter | KeyvOptions} store
1228
+ * @param {Omit<KeyvOptions, 'store'>} [options] if you provide the store you can then provide the Keyv Options
1229
+ */
1230
+ constructor(store, options) {
1231
+ const mergedOptions = Keyv.resolveOptions(store, options);
1232
+ super({
1233
+ throwOnHookError: false,
1234
+ throwOnEmptyListeners: true,
1235
+ throwOnEmitError: mergedOptions.throwOnErrors ?? false
1236
+ });
1237
+ this.deprecatedHooks = buildDeprecatedHooks();
1238
+ this._compression = mergedOptions.compression;
1239
+ this._encryption = mergedOptions.encryption;
1240
+ this.initSerialization(mergedOptions);
1241
+ this.initSanitize(mergedOptions);
1242
+ this.initNamespace(mergedOptions.namespace);
1243
+ this.initStats(mergedOptions);
1244
+ if (mergedOptions.store) this.setStore(mergedOptions.store);
1245
+ this.setTtl(mergedOptions.ttl);
1246
+ this._checkExpired = mergedOptions.checkExpired ?? true;
1247
+ }
1171
1248
  /**
1172
1249
  * Stats manager for tracking cache operation metrics (hits, misses, sets, deletes, errors).
1173
1250
  * @default this is disabled.
@@ -1204,31 +1281,10 @@ var Keyv = class Keyv extends hookified.Hookified {
1204
1281
  _sanitize;
1205
1282
  /**
1206
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).
1207
1286
  */
1208
- _checkExpired = false;
1209
- /**
1210
- * Keyv Constructor
1211
- * @param {KeyvStorageAdapter | KeyvOptions} store
1212
- * @param {Omit<KeyvOptions, 'store'>} [options] if you provide the store you can then provide the Keyv Options
1213
- */
1214
- constructor(store, options) {
1215
- const mergedOptions = Keyv.resolveOptions(store, options);
1216
- super({
1217
- throwOnHookError: false,
1218
- throwOnEmptyListeners: true,
1219
- throwOnEmitError: mergedOptions.throwOnErrors ?? false
1220
- });
1221
- this.deprecatedHooks = buildDeprecatedHooks();
1222
- this._compression = mergedOptions.compression;
1223
- this._encryption = mergedOptions.encryption;
1224
- this.initSerialization(mergedOptions);
1225
- this.initSanitize(mergedOptions);
1226
- this.initNamespace(mergedOptions.namespace);
1227
- this.initStats(mergedOptions);
1228
- if (mergedOptions.store) this.setStore(mergedOptions.store);
1229
- this.setTtl(mergedOptions.ttl);
1230
- this._checkExpired = mergedOptions.checkExpired ?? false;
1231
- }
1287
+ _checkExpired = true;
1232
1288
  /**
1233
1289
  * Get the current storage adapter.
1234
1290
  * @returns {KeyvStorageAdapter} The current storage adapter.
@@ -1357,13 +1413,6 @@ var Keyv = class Keyv extends hookified.Hookified {
1357
1413
  return this._stats;
1358
1414
  }
1359
1415
  /**
1360
- * When true, Keyv checks expiry at its layer on get/getMany/has/hasMany.
1361
- * When false (default), trusts the storage adapter.
1362
- */
1363
- get checkExpired() {
1364
- return this._checkExpired;
1365
- }
1366
- /**
1367
1416
  * Set the stats. When setting a new instance it will unsubscribe the old listeners
1368
1417
  * and subscribe the new instance.
1369
1418
  * @param {KeyvStats} stats The stats instance to set.
@@ -1374,19 +1423,33 @@ var Keyv = class Keyv extends hookified.Hookified {
1374
1423
  this._stats.subscribe(this);
1375
1424
  }
1376
1425
  /**
1377
- * Resolves a store to a fully-compliant KeyvStorageAdapter using a 3-tier detection chain:
1378
- * 1. If the store already implements the full KeyvStorageAdapter interface, use it directly.
1379
- * 2. If the store is map-like (synchronous get/set/delete/has), wrap it in KeyvMemoryAdapter.
1380
- * 3. If the store has async get/set/delete/clear, wrap it in KeyvBridgeAdapter.
1381
- * 4. Otherwise, emit an error and fall back to a default in-memory KeyvMemoryAdapter.
1426
+ * Get whether Keyv checks expiry at its own layer on get/getMany/has/hasMany.
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.
1429
+ * @returns {boolean} `true` if Keyv checks expiry at its layer.
1430
+ */
1431
+ get checkExpired() {
1432
+ return this._checkExpired;
1433
+ }
1434
+ /**
1435
+ * Resolves a store to a fully-compliant KeyvStorageAdapter:
1436
+ * 1. If the store declares the v6 `capabilities.expires` contract, use it directly (this takes
1437
+ * precedence over structural detection, so a full adapter whose async methods aren't written
1438
+ * with the `async` keyword is not mis-bridged).
1439
+ * 2. If the store implements the full async storage interface (but doesn't declare `expires`),
1440
+ * treat it as a legacy relative-`ttl` adapter and wrap it in KeyvBridgeAdapter.
1441
+ * 3. If the store is map-like (synchronous get/set/delete/has), wrap it in KeyvMemoryAdapter.
1442
+ * 4. If the store has async get/set/delete/clear, wrap it in KeyvBridgeAdapter.
1443
+ * 5. Otherwise, emit an error and fall back to a default in-memory KeyvMemoryAdapter.
1382
1444
  *
1383
1445
  * NOTE: this is used for internal but provided public for custom adapter testing
1384
1446
  * @param {unknown} store The store to resolve.
1385
1447
  * @returns {KeyvStorageAdapter} A fully-compliant storage adapter.
1386
1448
  */
1387
1449
  resolveStore(store) {
1450
+ if (store?.capabilities?.expires === true) return store;
1388
1451
  const cap = detectKeyvStorage(store);
1389
- if (cap.store === "keyvStorage") return store;
1452
+ if (cap.store === "keyvStorage") return new KeyvBridgeAdapter(store);
1390
1453
  if (cap.store === "mapLike") return new KeyvMemoryAdapter(store);
1391
1454
  if (cap.store === "asyncMap") return new KeyvBridgeAdapter(store);
1392
1455
  this.emit("error", /* @__PURE__ */ new Error("Could not use the provided storage adapter, falling back to KeyvMemoryAdapter with Map"));
@@ -1444,13 +1507,27 @@ var Keyv = class Keyv extends hookified.Hookified {
1444
1507
  return data.value;
1445
1508
  }
1446
1509
  /**
1447
- * Get many values of keys
1448
- * @param {string[]} keys passing in a single key or multiple as an array
1510
+ * Reads many keys from the store, preferring its native `getMany` and falling back to parallel
1511
+ * single `get`s when an adapter does not implement it. A directly-used v6 adapter is not
1512
+ * structurally required to provide `getMany` (the bridge and memory adapters always do), so
1513
+ * this keeps `getMany`/`getManyRaw` working regardless of the resolved adapter.
1514
+ * @param keys - the keys to read
1515
+ * @returns the raw store results in the same order as `keys`
1516
+ */
1517
+ async storeGetMany(keys) {
1518
+ if (typeof this._store.getMany === "function") return this._store.getMany(keys);
1519
+ return Promise.all(keys.map(async (key) => this._store.get(key)));
1520
+ }
1521
+ /**
1522
+ * Get many values for an array of keys.
1523
+ * @param {string[]} keys the keys to get
1524
+ * @returns {Promise<Array<Value | undefined>>} an array of values in the same order as the
1525
+ * keys, with `undefined` for keys that do not exist or are expired.
1449
1526
  */
1450
1527
  async getMany(keys) {
1451
1528
  keys = this._sanitize.enabled ? this._sanitize.cleanKeys(keys) : keys;
1452
1529
  await this.hookWithDeprecated("before:getMany", { keys });
1453
- const rawData = await this._store.getMany(keys);
1530
+ const rawData = await this.storeGetMany(keys);
1454
1531
  let deserialized;
1455
1532
  if (this._checkExpired) deserialized = await this.decodeWithExpire(keys, rawData);
1456
1533
  else deserialized = await Promise.all(rawData.map(async (row) => {
@@ -1509,7 +1586,7 @@ var Keyv = class Keyv extends hookified.Hookified {
1509
1586
  });
1510
1587
  return result;
1511
1588
  }
1512
- const rawData = await this._store.getMany(keys);
1589
+ const rawData = await this.storeGetMany(keys);
1513
1590
  let result;
1514
1591
  if (this._checkExpired) result = await this.decodeWithExpire(keys, rawData);
1515
1592
  else result = await Promise.all(rawData.map(async (row) => {
@@ -1526,10 +1603,10 @@ var Keyv = class Keyv extends hookified.Hookified {
1526
1603
  }
1527
1604
  /**
1528
1605
  * Set an item to the store
1529
- * @param {string | Array<KeyvEntry<Value>>} key the key to use. If you pass in an array of KeyvEntry it will set many items
1606
+ * @param {string} key the key to use
1530
1607
  * @param {Value} value the value of the key
1531
- * @param {number} [ttl] time to live in milliseconds
1532
- * @returns {boolean} if it sets then it will return a true. On failure will return false.
1608
+ * @param {number} [ttl] time to live in milliseconds. Overrides the instance-level `ttl`.
1609
+ * @returns {Promise<boolean>} `true` if it was set successfully, `false` on failure.
1533
1610
  */
1534
1611
  async set(key, value, ttl) {
1535
1612
  key = this._sanitize.enabled ? this._sanitize.cleanKey(key) : key;
@@ -1555,7 +1632,7 @@ var Keyv = class Keyv extends hookified.Hookified {
1555
1632
  let encodedValue = formattedValue;
1556
1633
  try {
1557
1634
  encodedValue = await this.encode(formattedValue);
1558
- result = await this._store.set(data.key, encodedValue, data.ttl);
1635
+ result = await this._store.set(data.key, encodedValue, expires);
1559
1636
  } catch (error) {
1560
1637
  result = false;
1561
1638
  this.emit("error", error);
@@ -1572,7 +1649,7 @@ var Keyv = class Keyv extends hookified.Hookified {
1572
1649
  /**
1573
1650
  * Set many items to the store
1574
1651
  * @param {Array<KeyvEntry<Value>>} entries the entries to set
1575
- * @returns {boolean[]} will return an array of booleans if it sets then it will return a true. On failure will return false.
1652
+ * @returns {Promise<boolean[]>} an array of booleans, one per entry: `true` if set successfully, `false` on failure.
1576
1653
  */
1577
1654
  async setMany(entries) {
1578
1655
  entries = entries.map((e) => ({
@@ -1601,7 +1678,7 @@ var Keyv = class Keyv extends hookified.Hookified {
1601
1678
  return {
1602
1679
  key,
1603
1680
  value: await this.encode(formattedValue),
1604
- ttl
1681
+ expires
1605
1682
  };
1606
1683
  }));
1607
1684
  const storeResult = await this._store.setMany(serializedEntries);
@@ -1626,7 +1703,7 @@ var Keyv = class Keyv extends hookified.Hookified {
1626
1703
  * The store-level TTL is derived automatically from `value.expires`.
1627
1704
  * @param {string} key the key to set
1628
1705
  * @param {KeyvValue<Value>} value the raw value envelope to store
1629
- * @returns {boolean} if it sets then it will return a true. On failure will return false.
1706
+ * @returns {Promise<boolean>} `true` if it was set successfully, `false` on failure.
1630
1707
  */
1631
1708
  async setRaw(key, value) {
1632
1709
  key = this._sanitize.enabled ? this._sanitize.cleanKey(key) : key;
@@ -1636,11 +1713,12 @@ var Keyv = class Keyv extends hookified.Hookified {
1636
1713
  value
1637
1714
  };
1638
1715
  await this.hookWithDeprecated("before:setRaw", data);
1639
- const ttl = ttlFromExpires(data.value.expires);
1716
+ const expires = data.value.expires;
1717
+ const ttl = ttlFromExpires(expires);
1640
1718
  let result = true;
1641
1719
  try {
1642
1720
  const encodedValue = await this.encode(data.value);
1643
- const storeResult = await this._store.set(data.key, encodedValue, ttl);
1721
+ const storeResult = await this._store.set(data.key, encodedValue, expires);
1644
1722
  if (typeof storeResult === "boolean") result = storeResult;
1645
1723
  } catch (error) {
1646
1724
  result = false;
@@ -1660,7 +1738,7 @@ var Keyv = class Keyv extends hookified.Hookified {
1660
1738
  * Each entry's value should be a KeyvValue object with { value, expires? }. If you need TTL-based expiration,
1661
1739
  * set `expires` on each value directly. The store-level TTL is derived automatically from `value.expires`.
1662
1740
  * @param {KeyvEntry<KeyvValue<Value>>[]} entries the raw entries to set
1663
- * @returns {boolean[]} will return an array of booleans if it sets then it will return a true. On failure will return false.
1741
+ * @returns {Promise<boolean[]>} an array of booleans, one per entry: `true` if set successfully, `false` on failure.
1664
1742
  */
1665
1743
  async setManyRaw(entries) {
1666
1744
  entries = entries.map((e) => ({
@@ -1672,11 +1750,10 @@ var Keyv = class Keyv extends hookified.Hookified {
1672
1750
  await this.hookWithDeprecated("before:setManyRaw", { entries });
1673
1751
  try {
1674
1752
  const rawEntries = await Promise.all(entries.map(async ({ key, value }) => {
1675
- const ttl = ttlFromExpires(value.expires);
1676
1753
  return {
1677
1754
  key,
1678
1755
  value: await this.encode(value),
1679
- ttl
1756
+ expires: value.expires
1680
1757
  };
1681
1758
  }));
1682
1759
  const storeResult = await this._store.setMany(rawEntries);
@@ -1716,7 +1793,7 @@ var Keyv = class Keyv extends hookified.Hookified {
1716
1793
  /**
1717
1794
  * Delete many items from the store
1718
1795
  * @param {string[]} keys the keys to be deleted
1719
- * @returns {boolean[]} array of booleans indicating success for each key
1796
+ * @returns {Promise<boolean[]>} an array of booleans indicating success for each key.
1720
1797
  */
1721
1798
  async deleteMany(keys) {
1722
1799
  /* v8 ignore next -- @preserve */
@@ -1769,7 +1846,7 @@ var Keyv = class Keyv extends hookified.Hookified {
1769
1846
  /**
1770
1847
  * Check if many keys exist
1771
1848
  * @param {string[]} keys the keys to check
1772
- * @returns {boolean[]} will return an array of booleans if the keys exist
1849
+ * @returns {Promise<boolean[]>} an array of booleans in the same order as the keys, `true` if the key exists.
1773
1850
  */
1774
1851
  async hasMany(keys) {
1775
1852
  keys = this._sanitize.enabled ? this._sanitize.cleanKeys(keys) : keys;
@@ -1777,7 +1854,7 @@ var Keyv = class Keyv extends hookified.Hookified {
1777
1854
  let results = [];
1778
1855
  try {
1779
1856
  if (this._checkExpired) {
1780
- const rawData = await this._store.getMany(keys);
1857
+ const rawData = await this.storeGetMany(keys);
1781
1858
  results = (await this.decodeWithExpire(keys, rawData)).map((row) => row !== void 0);
1782
1859
  } else results = await this._store.hasMany(keys);
1783
1860
  } catch (error) {
@@ -1792,8 +1869,9 @@ var Keyv = class Keyv extends hookified.Hookified {
1792
1869
  return results;
1793
1870
  }
1794
1871
  /**
1795
- * Clear the store
1796
- * @returns {void}
1872
+ * Clear the store. If a namespace is set only entries in that namespace are removed.
1873
+ * Emits a `clear` event.
1874
+ * @returns {Promise<void>} resolves once the entries have been cleared.
1797
1875
  */
1798
1876
  async clear() {
1799
1877
  this.emit("clear");
@@ -2009,10 +2087,14 @@ var KeyvMemoryAdapter = class extends hookified.Hookified {
2009
2087
  if (options?.namespace) this._namespace = options?.namespace;
2010
2088
  }
2011
2089
  /**
2012
- * Gets the detected capabilities of the underlying store.
2090
+ * Gets the capabilities of the underlying store, with `expires: true` to declare that
2091
+ * this adapter accepts an absolute `expires` timestamp (the v6 storage contract).
2013
2092
  */
2014
2093
  get capabilities() {
2015
- return this._capabilities;
2094
+ return {
2095
+ ...this._capabilities,
2096
+ expires: true
2097
+ };
2016
2098
  }
2017
2099
  /**
2018
2100
  * Gets the underlying store instance.
@@ -2089,24 +2171,24 @@ var KeyvMemoryAdapter = class extends hookified.Hookified {
2089
2171
  return entry.value;
2090
2172
  }
2091
2173
  /**
2092
- * Stores a value in the store with an optional TTL.
2174
+ * Stores a value in the store with an optional absolute expiry.
2093
2175
  * @param key - The key to store the value under
2094
2176
  * @param value - The value to store
2095
- * @param ttl - Optional time-to-live in milliseconds
2177
+ * @param expires - Optional absolute expiry as Unix ms since epoch
2096
2178
  * @returns Always returns true indicating success
2097
2179
  */
2098
- async set(key, value, ttl) {
2180
+ async set(key, value, expires) {
2099
2181
  const keyPrefix = this.getKeyPrefix(key, this._namespace);
2100
2182
  const entry = {
2101
2183
  value,
2102
- expires: ttl ? Date.now() + ttl : void 0
2184
+ expires: typeof expires === "number" ? expires : void 0
2103
2185
  };
2104
- this._store.set(keyPrefix, entry, ttl);
2186
+ this._store.set(keyPrefix, entry, ttlFromExpires(expires));
2105
2187
  return true;
2106
2188
  }
2107
2189
  /**
2108
2190
  * Stores multiple entries in the store at once.
2109
- * @param entries - Array of entries containing key, value, and optional TTL
2191
+ * @param entries - Array of entries containing key, value, and optional absolute `expires`
2110
2192
  */
2111
2193
  async setMany(entries) {
2112
2194
  const results = [];
@@ -2114,9 +2196,9 @@ var KeyvMemoryAdapter = class extends hookified.Hookified {
2114
2196
  const keyPrefix = this.getKeyPrefix(entry.key, this._namespace);
2115
2197
  const memEntry = {
2116
2198
  value: entry.value,
2117
- expires: entry.ttl ? Date.now() + entry.ttl : void 0
2199
+ expires: typeof entry.expires === "number" ? entry.expires : void 0
2118
2200
  };
2119
- this._store.set(keyPrefix, memEntry, entry.ttl);
2201
+ this._store.set(keyPrefix, memEntry, ttlFromExpires(entry.expires));
2120
2202
  results.push(true);
2121
2203
  }
2122
2204
  return results;
@@ -2285,3 +2367,4 @@ exports.detectKeyvEncryption = detectKeyvEncryption;
2285
2367
  exports.detectKeyvSerialization = detectKeyvSerialization;
2286
2368
  exports.detectKeyvStorage = detectKeyvStorage;
2287
2369
  exports.jsonSerializer = jsonSerializer;
2370
+ exports.keyvStorageCapability = keyvStorageCapability;