keyv 6.0.0-beta.4 → 6.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.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` is a two-way contract: the adapter is then used directly and
31
- * must ENFORCE expiry on read. Keyv core does not filter expired entries by default
32
- * (`checkExpired` is off), so the adapter is the expiry authority — `get`/`getMany`/`has`
33
- * must return nothing for a key past its deadline, via a native mechanism (TTL index, key
34
- * expiry, lease) and/or a client-side check. Validate with `@keyv/test-suite`'s
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. */readonly enabled: boolean; /** The key sanitization pattern configuration. */
231
- readonly keys: KeyvSanitizePatterns; /** The namespace sanitization pattern configuration. */
232
- readonly namespace: KeyvSanitizePatterns; /** Sanitize a single key. */
233
- cleanKey(key: string): string; /** Sanitize an array of keys. */
234
- cleanKeys(keys: string[]): string[]; /** Sanitize a namespace string. */
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"). */event: string; /** The cache key involved, if applicable. */
291
- key?: string; /** The namespace of the Keyv instance. */
292
- namespace?: string; /** Unix timestamp in milliseconds when the event occurred. */
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 = {
@@ -387,7 +396,7 @@ declare class KeyvStats {
387
396
  set enabled(value: boolean);
388
397
  /**
389
398
  * Build a composite key from a telemetry event.
390
- * Format: "namespace:key" if namespace is present, otherwise just "key".
399
+ * Format: "namespace::key" if namespace is present, otherwise just "key".
391
400
  */
392
401
  buildKeyEventName(event: KeyvTelemetryEvent): string;
393
402
  /**
@@ -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<any, any> | any;
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. */value?: Value; /** Absolute expiration timestamp in milliseconds since epoch, or `undefined` for no expiry. */
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 = any> = {
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 = any> = {
549
- /** Key to set. */key: string; /** Value to set (already encoded by Keyv core). */
550
- value: Value; /** Absolute expiry as Unix ms since epoch, or `undefined` for no expiry. */
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
  /**
@@ -560,7 +585,9 @@ type KeyvOptions = {
560
585
  */
561
586
  namespace?: string;
562
587
  /**
563
- * A custom serialization adapter with stringify and parse methods.
588
+ * A custom serialization adapter with stringify and parse methods. Pass `false` to store
589
+ * values as they are, without compression. Encryption needs serialization, so with an
590
+ * encryption adapter set, `false` makes every write fail with an error.
564
591
  * @default KeyvJsonSerializer (built-in)
565
592
  */
566
593
  serialization?: KeyvSerializationAdapter | false;
@@ -568,7 +595,7 @@ type KeyvOptions = {
568
595
  * The storage adapter instance to be used by Keyv.
569
596
  * @default new Map() - in-memory store
570
597
  */
571
- store?: KeyvStorageAdapter | Map<any, any> | any;
598
+ store?: KeyvStorageAdapter | Map<KeyvAny, KeyvAny> | KeyvAny;
572
599
  /**
573
600
  * Default TTL in milliseconds. Can be overridden by specifying a TTL on `.set()`.
574
601
  * @default undefined
@@ -578,19 +605,12 @@ type KeyvOptions = {
578
605
  * Enable compression option
579
606
  * @default undefined
580
607
  */
581
- compression?: KeyvCompressionAdapter | any;
608
+ compression?: KeyvCompressionAdapter | KeyvAny;
582
609
  /**
583
610
  * Enable or disable statistics (default is false)
584
611
  * @default false
585
612
  */
586
613
  stats?: boolean;
587
- /**
588
- * Will throw on all errors if this is enabled to true. By default, errors
589
- * will only throw if there are no listeners to the error event.
590
- * This maps to hookified's `throwOnEmitError` under the hood.
591
- * @default false
592
- */
593
- throwOnErrors?: boolean;
594
614
  /**
595
615
  * Enable sanitization of keys and namespaces by detecting dangerous patterns
596
616
  * for SQL, MongoDB, or filesystem-based storage backends. Pass a `KeyvSanitizeOptions`
@@ -600,14 +620,20 @@ type KeyvOptions = {
600
620
  sanitize?: KeyvSanitizeOptions;
601
621
  /**
602
622
  * Enable encryption of stored values. Pass a `KeyvEncryptionAdapter` with
603
- * `encrypt` and `decrypt` methods.
623
+ * `encrypt` and `decrypt` methods. Encryption runs on the serialized value, so it needs
624
+ * serialization. With `serialization: false`, writes fail with an error instead of storing
625
+ * values unencrypted.
604
626
  * @default undefined
605
627
  */
606
628
  encryption?: KeyvEncryptionAdapter;
607
629
  /**
608
- * When true, Keyv checks expiry on get/getMany/has/hasMany at its layer.
609
- * When false (default), trusts the storage adapter to handle expiry.
610
- * @default false
630
+ * When true (default), Keyv checks expiry on get/getMany/has/hasMany at its own layer,
631
+ * filtering (and deleting) expired entries using the absolute `expires` stored in the
632
+ * serialized envelope. This keeps reads millisecond-precise even on adapters whose native
633
+ * expiry is coarse or lazily swept (e.g. Memcached's second-granular exptime, DynamoDB's
634
+ * background TTL sweep that can lag for hours). Set to false to trust the storage adapter
635
+ * to handle expiry on its own (skips the extra decode + expiry check on reads).
636
+ * @default true
611
637
  */
612
638
  checkExpired?: boolean;
613
639
  };
@@ -618,7 +644,9 @@ type KeyvOptions = {
618
644
  * Implement `stringify` and `parse` to control how values are serialized to/from strings.
619
645
  */
620
646
  type KeyvSerializationAdapter = {
621
- /** Converts a value to a string representation. */stringify: (object: unknown) => string | Promise<string>; /** Parses a string back into its original value. */
647
+ /** Converts a value to a string representation. */
648
+ stringify: (object: unknown) => string | Promise<string>;
649
+ /** Parses a string back into its original value. */
622
650
  parse: <T>(data: string) => T | Promise<T>;
623
651
  };
624
652
  /**
@@ -626,7 +654,9 @@ type KeyvSerializationAdapter = {
626
654
  * Implement `compress` and `decompress` to add compression to stored values.
627
655
  */
628
656
  type KeyvCompressionAdapter = {
629
- /** Compresses a string value. */compress(value: string): Promise<string>; /** Decompresses a string value back to its original form. */
657
+ /** Compresses a string value. */
658
+ compress(value: string): Promise<string>;
659
+ /** Decompresses a string value back to its original form. */
630
660
  decompress(value: string): Promise<string>;
631
661
  };
632
662
  /**
@@ -634,7 +664,9 @@ type KeyvCompressionAdapter = {
634
664
  * Implement `encrypt` and `decrypt` to add encryption to stored values.
635
665
  */
636
666
  type KeyvEncryptionAdapter = {
637
- /** Encrypts a string value. */encrypt: (data: string) => string | Promise<string>; /** Decrypts a string value back to its original form. */
667
+ /** Encrypts a string value. */
668
+ encrypt: (data: string) => string | Promise<string>;
669
+ /** Decrypts a string value back to its original form. */
638
670
  decrypt: (data: string) => string | Promise<string>;
639
671
  };
640
672
  type KeyvStorageGetResult<Value> = KeyvValue<Value> | string | undefined;
@@ -643,33 +675,46 @@ type KeyvStorageGetResult<Value> = KeyvValue<Value> | string | undefined;
643
675
  * Adapters handle the actual persistence of key-value pairs.
644
676
  */
645
677
  type KeyvStorageAdapter = {
646
- /** Optional namespace for key isolation. */namespace?: string | undefined;
678
+ /** Optional namespace for key isolation. */
679
+ namespace?: string | undefined;
647
680
  /**
648
681
  * The adapter's capabilities. v6 adapters set `capabilities.expires = true` (e.g. via
649
682
  * `keyvStorageCapability(this)`) to declare they accept an absolute `expires` timestamp
650
683
  * on `set`/`setMany`. Full storage adapters that omit it are treated as legacy relative-`ttl`
651
684
  * adapters and wrapped by `KeyvBridgeAdapter`, which converts `expires` back to a ttl.
652
685
  *
653
- * Declaring `expires: true` also obliges the adapter to enforce expiry on read: Keyv core
654
- * does not filter expired entries by default, so `get`/`getMany`/`has` must not return a key
655
- * past its deadline. See {@link KeyvStorageCapability.expires}.
656
- */
657
- capabilities?: KeyvStorageCapability; /** Retrieves a value by key. */
686
+ * Declaring `expires: true` means the adapter should enforce expiry on read so `get`/`getMany`/
687
+ * `has` do not return a key past its deadline (ideally backed by a native mechanism that also
688
+ * reclaims space). Keyv core additionally filters expired reads by default (`checkExpired` is
689
+ * on), as a safety net for backends with coarse or lazily-swept native expiry. See
690
+ * {@link KeyvStorageCapability.expires}.
691
+ */
692
+ capabilities?: KeyvStorageCapability;
693
+ /** Retrieves a value by key. */
658
694
  get<Value>(key: string): Promise<KeyvStorageGetResult<Value>>;
659
695
  /**
660
696
  * Stores a value with a key and optional absolute expiry.
661
697
  * @param expires Absolute expiry as Unix ms since epoch; `undefined` means no expiry.
662
698
  * A value `<= Date.now()` is already expired and the adapter may delete/skip it.
663
699
  */
664
- set(key: string, value: unknown, expires?: number): Promise<boolean>; /** Stores multiple entries at once, each with an absolute `expires` timestamp. */
665
- setMany<Value>(values: KeyvStorageEntry<Value>[]): Promise<boolean[] | undefined>; /** Deletes a key from the store. */
666
- delete(key: string): Promise<boolean>; /** Clears all entries from the store (respects namespace if set). */
667
- clear(): Promise<void>; /** Checks if a key exists in the store. */
668
- has(key: string): Promise<boolean>; /** Checks if multiple keys exist in the store. */
669
- hasMany(keys: string[]): Promise<boolean[]>; /** Retrieves multiple values by keys. */
670
- getMany<Value>(keys: string[]): Promise<Array<KeyvStorageGetResult<Value | undefined>>>; /** Disconnects from the store and releases resources. */
671
- disconnect?(): Promise<void>; /** Deletes multiple keys from the store. */
672
- deleteMany(key: string[]): Promise<boolean[]>; /** Returns an async iterator over all key-value pairs. */
700
+ set(key: string, value: unknown, expires?: number): Promise<boolean>;
701
+ /** Stores multiple entries at once, each with an absolute `expires` timestamp. */
702
+ setMany<Value>(values: KeyvStorageEntry<Value>[]): Promise<boolean[] | undefined>;
703
+ /** Deletes a key from the store. */
704
+ delete(key: string): Promise<boolean>;
705
+ /** Clears all entries from the store (respects namespace if set). */
706
+ clear(): Promise<void>;
707
+ /** Checks if a key exists in the store. */
708
+ has(key: string): Promise<boolean>;
709
+ /** Checks if multiple keys exist in the store. */
710
+ hasMany(keys: string[]): Promise<boolean[]>;
711
+ /** Retrieves multiple values by keys. */
712
+ getMany<Value>(keys: string[]): Promise<Array<KeyvStorageGetResult<Value | undefined>>>;
713
+ /** Disconnects from the store and releases resources. */
714
+ disconnect?(): Promise<void>;
715
+ /** Deletes multiple keys from the store. */
716
+ deleteMany(key: string[]): Promise<boolean[]>;
717
+ /** Returns an async iterator over all key-value pairs. */
673
718
  iterator?<Value>(): AsyncGenerator<Array<string | Awaited<Value> | undefined>, void>;
674
719
  } & IEventEmitter;
675
720
  /**
@@ -688,13 +733,13 @@ type KeyvCompression = KeyvCompressionAdapter;
688
733
  type KeyvBridgeAdapterOptions = {
689
734
  /**
690
735
  * The namespace to use for keys.
691
- * When set, all keys will be prefixed with the namespace followed by the key separator.
736
+ * When set, all keys will be prefixed with the namespace followed by the namespace separator.
692
737
  */
693
738
  namespace?: string;
694
739
  /**
695
- * The separator used between namespace and key. Defaults to ":".
740
+ * The separator between the namespace and the key. Defaults to `::`.
696
741
  */
697
- keySeparator?: string;
742
+ namespaceSeparator?: string;
698
743
  };
699
744
  /**
700
745
  * Interface for a promise-based store that can be used with KeyvBridgeAdapter.
@@ -703,26 +748,42 @@ type KeyvBridgeAdapterOptions = {
703
748
  * will be delegated to the store if present, otherwise fallback implementations are used.
704
749
  */
705
750
  type KeyvBridgeStore = {
706
- /** Store configuration/options (e.g. dialect, url) */opts?: any; /** Namespace the store scopes its keys under, when it manages its own namespacing. */
707
- namespace?: string; /** Retrieves a value by key */
708
- get(key: string): Promise<any>; /** Sets a value with a key and optional TTL */
709
- set(key: string, value: any, ttl?: number): Promise<any>; /** Deletes a key from the store */
710
- delete(key: string): Promise<boolean>; /** Clears all entries from the store */
711
- clear(): Promise<void>; /** Checks if a key exists in the store */
712
- has?(key: string): Promise<boolean>; /** Checks if multiple keys exist in the store */
713
- hasMany?(keys: string[]): Promise<boolean[]>; /** Retrieves multiple values by keys */
714
- getMany?(keys: string[]): Promise<any[]>; /** Sets multiple entries at once */
715
- setMany?(entries: any[]): Promise<any>; /** Deletes multiple keys at once */
716
- deleteMany?(keys: string[]): Promise<boolean | boolean[]>; /** Iterates over all entries, optionally filtered by namespace */
717
- iterator?(namespace?: string): AsyncGenerator<any>; /** Disconnects from the store */
718
- disconnect?(): Promise<void>; /** Subscribe to events (e.g. error events from v5 adapters) */
719
- on?(event: string, listener: (...args: any[]) => void): any;
751
+ /** Store configuration/options (e.g. dialect, url) */
752
+ opts?: KeyvAny;
753
+ /** Namespace the store scopes its keys under, when it manages its own namespacing. */
754
+ namespace?: string;
755
+ /** Retrieves a value by key */
756
+ get(key: string): Promise<KeyvAny>;
757
+ /** Sets a value with a key and optional TTL */
758
+ set(key: string, value: KeyvAny, ttl?: number): Promise<KeyvAny>;
759
+ /** Deletes a key from the store */
760
+ delete(key: string): Promise<boolean>;
761
+ /** Clears all entries from the store */
762
+ clear(): Promise<void>;
763
+ /** Checks if a key exists in the store */
764
+ has?(key: string): Promise<boolean>;
765
+ /** Checks if multiple keys exist in the store */
766
+ hasMany?(keys: string[]): Promise<boolean[]>;
767
+ /** Retrieves multiple values by keys */
768
+ getMany?(keys: string[]): Promise<KeyvAnyArray>;
769
+ /** Sets multiple entries at once */
770
+ setMany?(entries: KeyvAnyArray): Promise<KeyvAny>;
771
+ /** Deletes multiple keys at once */
772
+ deleteMany?(keys: string[]): Promise<boolean | boolean[]>;
773
+ /** Iterates over all entries, optionally filtered by namespace */
774
+ iterator?(namespace?: string): AsyncGenerator<KeyvAny>;
775
+ /** Disconnects from the store */
776
+ disconnect?(): Promise<void>;
777
+ /** Subscribe to events (e.g. error events from v5 adapters) */
778
+ on?(event: string, listener: (...args: KeyvAnyArray) => void): KeyvAny;
720
779
  };
721
780
  /**
722
781
  * Data structure returned when parsing a prefixed key.
723
782
  */
724
783
  type KeyPrefixData = {
725
- /** The namespace extracted from the key, if present */namespace?: string; /** The key without the namespace prefix */
784
+ /** The namespace extracted from the key, if present */
785
+ namespace?: string;
786
+ /** The key without the namespace prefix */
726
787
  key: string;
727
788
  };
728
789
  /**
@@ -745,7 +806,7 @@ type KeyPrefixData = {
745
806
  declare class KeyvBridgeAdapter extends Hookified implements KeyvStorageAdapter {
746
807
  private _store;
747
808
  private _namespace?;
748
- private _keySeparator;
809
+ private _namespaceSeparator;
749
810
  private readonly _capabilities;
750
811
  /**
751
812
  * Whether the wrapped store manages its own namespace (exposes a `namespace` property).
@@ -774,13 +835,13 @@ declare class KeyvBridgeAdapter extends Hookified implements KeyvStorageAdapter
774
835
  */
775
836
  get capabilities(): KeyvStorageCapability;
776
837
  /**
777
- * Gets the current key separator used between namespace and key.
838
+ * Gets the separator between the namespace and the key. Defaults to `::`.
778
839
  */
779
- get keySeparator(): string;
840
+ get namespaceSeparator(): string;
780
841
  /**
781
- * Sets the key separator used between namespace and key.
842
+ * Sets the separator between the namespace and the key.
782
843
  */
783
- set keySeparator(separator: string);
844
+ set namespaceSeparator(separator: string);
784
845
  /**
785
846
  * Gets the current namespace.
786
847
  */
@@ -830,11 +891,12 @@ declare class KeyvBridgeAdapter extends Hookified implements KeyvStorageAdapter
830
891
  * @param expires - Optional absolute expiry as Unix ms since epoch
831
892
  * @returns Always returns true indicating success
832
893
  */
833
- set(key: string, value: any, expires?: number): Promise<boolean>;
894
+ set(key: string, value: KeyvAny, expires?: number): Promise<boolean>;
834
895
  /**
835
896
  * Stores multiple entries in the store at once.
836
897
  * Delegates to the store's native setMany if available, otherwise loops over set.
837
898
  * @param entries - Array of entries containing key, value, and optional absolute `expires`
899
+ * @returns One boolean per entry, `false` where the store reported that the write failed
838
900
  */
839
901
  setMany<Value>(entries: KeyvStorageEntry<Value>[]): Promise<boolean[] | undefined>;
840
902
  /**
@@ -865,9 +927,12 @@ declare class KeyvBridgeAdapter extends Hookified implements KeyvStorageAdapter
865
927
  */
866
928
  deleteMany(keys: string[]): Promise<boolean[]>;
867
929
  /**
868
- * Clears entries from the store. If a namespace is set and the store supports
869
- * iteration, only entries within that namespace are removed. Otherwise, the
870
- * entire store is cleared.
930
+ * Clears entries from the store. With no namespace, the whole store is cleared. With a
931
+ * namespace, only that namespace's entries are removed: a store that manages its own
932
+ * namespace clears them itself, and otherwise the bridge finds them with the store's
933
+ * `iterator()`. A store with neither can't tell namespaces apart, so this throws rather
934
+ * than call the store's `clear()` and delete every namespace's entries.
935
+ * @throws {Error} If a namespace is set and the store neither manages it nor has `iterator()`.
871
936
  */
872
937
  clear(): Promise<void>;
873
938
  /**
@@ -884,7 +949,7 @@ declare class KeyvBridgeAdapter extends Hookified implements KeyvStorageAdapter
884
949
  }
885
950
  //#endregion
886
951
  //#region src/keyv.d.ts
887
- declare class Keyv<GenericValue = any> extends Hookified {
952
+ declare class Keyv<GenericValue = KeyvAny> extends Hookified {
888
953
  /**
889
954
  * Keyv Constructor
890
955
  * @param {KeyvStorageAdapter | KeyvOptions | Map<any, any> | any} store to be provided or just the options
@@ -932,6 +997,8 @@ declare class Keyv<GenericValue = any> extends Hookified {
932
997
  private _sanitize;
933
998
  /**
934
999
  * When true, Keyv checks expiry at its layer on get/getMany/has/hasMany.
1000
+ * Defaults to true so reads stay millisecond-precise even on adapters whose
1001
+ * native expiry is coarse or lazily swept (e.g. Memcached, DynamoDB).
935
1002
  */
936
1003
  private _checkExpired;
937
1004
  /**
@@ -965,7 +1032,8 @@ declare class Keyv<GenericValue = any> extends Hookified {
965
1032
  */
966
1033
  set encryption(encryption: KeyvEncryptionAdapter | undefined);
967
1034
  /**
968
- * Get the current namespace.
1035
+ * Get the current namespace. When Keyv has no namespace of its own, this is the namespace
1036
+ * configured on the storage adapter.
969
1037
  * @returns {string | undefined} The current namespace.
970
1038
  */
971
1039
  get namespace(): string | undefined;
@@ -995,18 +1063,6 @@ declare class Keyv<GenericValue = any> extends Hookified {
995
1063
  * @param {KeyvSerializationAdapter | undefined} serialization The serialization adapter to set.
996
1064
  */
997
1065
  set serialization(serialization: KeyvSerializationAdapter | false | undefined);
998
- /**
999
- * Get the current throwOnErrors value. When enabled, all errors with throw. By default, errors
1000
- * will only throw if there are no listeners to the error event.
1001
- * @return {boolean} The current throwOnErrors value.
1002
- */
1003
- get throwOnErrors(): boolean;
1004
- /**
1005
- * Set the current throwOnErrors value. When enabled, all errors will throw. By default, errors
1006
- * will only throw if there are no listeners to the error event.
1007
- * @param {boolean} value The throwOnErrors value to set.
1008
- */
1009
- set throwOnErrors(value: boolean);
1010
1066
  /**
1011
1067
  * Get the current sanitize adapter. Sanitization is disabled by default. To
1012
1068
  * enable it `sanitize.keys` or `sanitize.namespace` to true or set KeyvSanitizePatterns
@@ -1015,7 +1071,8 @@ declare class Keyv<GenericValue = any> extends Hookified {
1015
1071
  */
1016
1072
  get sanitize(): KeyvSanitizeAdapter;
1017
1073
  /**
1018
- * Set the sanitize adapter directly and will run sanitization on namespace.
1074
+ * Set the sanitize adapter directly and will run sanitization on namespace, including a
1075
+ * namespace kept from the storage adapter, and apply the result to the adapter.
1019
1076
  * @param {KeyvSanitizeAdapter} value The sanitize adapter to use.
1020
1077
  */
1021
1078
  set sanitize(value: KeyvSanitizeAdapter);
@@ -1032,7 +1089,8 @@ declare class Keyv<GenericValue = any> extends Hookified {
1032
1089
  set stats(stats: KeyvStats);
1033
1090
  /**
1034
1091
  * Get whether Keyv checks expiry at its own layer on get/getMany/has/hasMany.
1035
- * When false (default), it trusts the storage adapter to handle expiry.
1092
+ * When true (default), expired entries are filtered (and deleted) by Keyv regardless of
1093
+ * the adapter. Set to false to trust the storage adapter to handle expiry on its own.
1036
1094
  * @returns {boolean} `true` if Keyv checks expiry at its layer.
1037
1095
  */
1038
1096
  get checkExpired(): boolean;
@@ -1043,7 +1101,9 @@ declare class Keyv<GenericValue = any> extends Hookified {
1043
1101
  * with the `async` keyword is not mis-bridged).
1044
1102
  * 2. If the store implements the full async storage interface (but doesn't declare `expires`),
1045
1103
  * treat it as a legacy relative-`ttl` adapter and wrap it in KeyvBridgeAdapter.
1046
- * 3. If the store is map-like (synchronous get/set/delete/has), wrap it in KeyvMemoryAdapter.
1104
+ * 3. If the store is map-like (get/set/delete/has that aren't native `async` functions), wrap it
1105
+ * in KeyvMemoryAdapter. A store other than a Map is first asked once, through `has`, whether
1106
+ * it returns promises; if it does, wrap it in KeyvBridgeAdapter instead.
1047
1107
  * 4. If the store has async get/set/delete/clear, wrap it in KeyvBridgeAdapter.
1048
1108
  * 5. Otherwise, emit an error and fall back to a default in-memory KeyvMemoryAdapter.
1049
1109
  *
@@ -1051,10 +1111,11 @@ declare class Keyv<GenericValue = any> extends Hookified {
1051
1111
  * @param {unknown} store The store to resolve.
1052
1112
  * @returns {KeyvStorageAdapter} A fully-compliant storage adapter.
1053
1113
  */
1054
- resolveStore(store: any): KeyvStorageAdapter;
1114
+ resolveStore(store: KeyvAny): KeyvStorageAdapter;
1055
1115
  /**
1056
1116
  * Sets the storage adapter by resolving it via {@link resolveStore}, then wires up
1057
- * error forwarding and namespace propagation.
1117
+ * error forwarding and namespace propagation. Keyv's namespace, when set, is applied to the
1118
+ * adapter. Without one, the adapter keeps the namespace it was configured with.
1058
1119
  * @param {KeyvStorageAdapter | Map<any, any> | any} store The storage adapter to set.
1059
1120
  */
1060
1121
  setStore(store: KeyvStorageAdapter | KeyvMapAny): void;
@@ -1082,6 +1143,16 @@ declare class Keyv<GenericValue = any> extends Hookified {
1082
1143
  * @returns the raw store results in the same order as `keys`
1083
1144
  */
1084
1145
  private storeGetMany;
1146
+ /**
1147
+ * Runs a batch operation without the keys or entries whose key is empty, then returns its results
1148
+ * in the original order with `fallback` for each empty key. As with the single-key methods, an
1149
+ * empty key never reaches hooks, telemetry or the store.
1150
+ * @param items - the keys or entries of the batch
1151
+ * @param fallback - the result for an item whose key is empty
1152
+ * @param run - runs the batch operation on the items whose key is not empty
1153
+ * @returns one result per item, in the same order as `items`
1154
+ */
1155
+ private skipEmptyKeys;
1085
1156
  /**
1086
1157
  * Get many values for an array of keys.
1087
1158
  * @param {string[]} keys the keys to get
@@ -1120,7 +1191,8 @@ declare class Keyv<GenericValue = any> extends Hookified {
1120
1191
  * Set a raw value to the store without wrapping or serialization. This is the write-side counterpart to getRaw().
1121
1192
  * The value should be a KeyvValue object with { value, expires? }. If you need TTL-based expiration,
1122
1193
  * set `expires` on the value directly (e.g. `{ value: 'bar', expires: Date.now() + 60000 }`).
1123
- * The store-level TTL is derived automatically from `value.expires`.
1194
+ * The store-level expiry is derived automatically from `value.expires`, rounded up to a whole millisecond
1195
+ * (a non-finite `expires` means no store-level expiry).
1124
1196
  * @param {string} key the key to set
1125
1197
  * @param {KeyvValue<Value>} value the raw value envelope to store
1126
1198
  * @returns {Promise<boolean>} `true` if it was set successfully, `false` on failure.
@@ -1129,7 +1201,8 @@ declare class Keyv<GenericValue = any> extends Hookified {
1129
1201
  /**
1130
1202
  * Set many raw values to the store without wrapping or serialization. This is the write-side counterpart to getManyRaw().
1131
1203
  * Each entry's value should be a KeyvValue object with { value, expires? }. If you need TTL-based expiration,
1132
- * set `expires` on each value directly. The store-level TTL is derived automatically from `value.expires`.
1204
+ * set `expires` on each value directly. The store-level expiry is derived automatically from `value.expires`,
1205
+ * rounded up to a whole millisecond (a non-finite `expires` means no store-level expiry).
1133
1206
  * @param {KeyvEntry<KeyvValue<Value>>[]} entries the raw entries to set
1134
1207
  * @returns {Promise<boolean[]>} an array of booleans, one per entry: `true` if set successfully, `false` on failure.
1135
1208
  */
@@ -1169,7 +1242,8 @@ declare class Keyv<GenericValue = any> extends Hookified {
1169
1242
  */
1170
1243
  hasMany(keys: string[]): Promise<boolean[]>;
1171
1244
  /**
1172
- * Clear the store. If a namespace is set only entries in that namespace are removed.
1245
+ * Clear the store. If a namespace is set only entries in that namespace are removed. When the
1246
+ * store can't limit the removal to the namespace, nothing is removed and `error` is emitted.
1173
1247
  * Emits a `clear` event.
1174
1248
  * @returns {Promise<void>} resolves once the entries have been cleared.
1175
1249
  */
@@ -1184,12 +1258,15 @@ declare class Keyv<GenericValue = any> extends Hookified {
1184
1258
  * filters out expired entries, and deletes them from the store.
1185
1259
  * @returns {AsyncGenerator<Array<string | unknown>, void>} An async generator yielding `[key, value]` pairs.
1186
1260
  */
1187
- iterator(): AsyncGenerator<[string, any], void>;
1261
+ iterator(): AsyncGenerator<[string, KeyvAny], void>;
1188
1262
  /**
1189
1263
  * Encodes a value for storage. Pipeline: serialize → compress → encrypt.
1190
- * If serialization is not configured, returns the data as-is.
1264
+ * If serialization is not configured, returns the data as-is, skipping compression. With an
1265
+ * encryption adapter set, it throws instead, since the value can't be encrypted and storing it
1266
+ * unencrypted would defeat the adapter.
1191
1267
  * @param {KeyvValue<T>} data The value envelope to encode.
1192
- * @returns {Promise<unknown>} The encoded value, or the original data on failure.
1268
+ * @returns {Promise<unknown>} The encoded value.
1269
+ * @throws {Error} If an encryption adapter is set while serialization is disabled.
1193
1270
  */
1194
1271
  encode<T>(data: KeyvValue<T>): Promise<unknown>;
1195
1272
  /**
@@ -1239,6 +1316,15 @@ declare class Keyv<GenericValue = any> extends Hookified {
1239
1316
  * Initializes the namespace, applying sanitization if enabled.
1240
1317
  */
1241
1318
  private initNamespace;
1319
+ /**
1320
+ * Sanitizes a namespace. When sanitizing leaves nothing, it returns {@link emptiedNamespace} so
1321
+ * the instance keeps a namespace of its own.
1322
+ */
1323
+ private cleanNamespace;
1324
+ /**
1325
+ * Sanitizes the namespace kept from the storage adapter when Keyv has none of its own.
1326
+ */
1327
+ private sanitizeStoreNamespace;
1242
1328
  }
1243
1329
  //#endregion
1244
1330
  //#region src/adapters/memory.d.ts
@@ -1248,13 +1334,13 @@ declare class Keyv<GenericValue = any> extends Hookified {
1248
1334
  type KeyvMemoryAdapterOptions = {
1249
1335
  /**
1250
1336
  * The namespace to use for keys.
1251
- * When set, all keys will be prefixed with the namespace followed by the key separator.
1337
+ * When set, all keys will be prefixed with the namespace followed by the namespace separator.
1252
1338
  */
1253
1339
  namespace?: string;
1254
1340
  /**
1255
- * The separator used between namespace and key. Defaults to ":".
1341
+ * The separator between the namespace and the key. Defaults to `::`.
1256
1342
  */
1257
- keySeparator?: string;
1343
+ namespaceSeparator?: string;
1258
1344
  };
1259
1345
  /**
1260
1346
  * Interface for a Map-like store that can be used with KeyvMemoryAdapter.
@@ -1262,10 +1348,15 @@ type KeyvMemoryAdapterOptions = {
1262
1348
  * Compatible with Map, QuickLRU, lru.min, and other LRU cache implementations.
1263
1349
  */
1264
1350
  type KeyvMapType = {
1265
- /** Retrieves a value by key */get: (key: string) => any; /** Sets a value with a key. Additional parameters (like TTL) vary by implementation. */
1266
- set: (key: string, value: any, ...args: any[]) => any; /** Deletes a key from the store */
1267
- delete: (key: string) => boolean; /** Clears all entries from the store */
1268
- clear: () => void; /** Checks if a key exists in the store */
1351
+ /** Retrieves a value by key */
1352
+ get: (key: string) => KeyvAny;
1353
+ /** Sets a value with a key. Additional parameters (like TTL) vary by implementation. */
1354
+ set: (key: string, value: KeyvAny, ...args: KeyvAnyArray) => KeyvAny;
1355
+ /** Deletes a key from the store */
1356
+ delete: (key: string) => boolean;
1357
+ /** Clears all entries from the store */
1358
+ clear: () => void;
1359
+ /** Checks if a key exists in the store */
1269
1360
  has: (key: string) => boolean;
1270
1361
  };
1271
1362
  /**
@@ -1282,14 +1373,14 @@ type KeyvMapType = {
1282
1373
  * // Using with a custom store
1283
1374
  * const customStore = new KeyvMemoryAdapter(myCustomMapLikeStore, {
1284
1375
  * namespace: 'tenant-123',
1285
- * keySeparator: ':'
1376
+ * namespaceSeparator: '::'
1286
1377
  * });
1287
1378
  * ```
1288
1379
  */
1289
1380
  declare class KeyvMemoryAdapter extends Hookified implements KeyvStorageAdapter {
1290
1381
  private _store;
1291
1382
  private _namespace?;
1292
- private _keySeparator;
1383
+ private _namespaceSeparator;
1293
1384
  private readonly _capabilities;
1294
1385
  /**
1295
1386
  * Creates a new KeyvMemoryAdapter instance.
@@ -1311,13 +1402,13 @@ declare class KeyvMemoryAdapter extends Hookified implements KeyvStorageAdapter
1311
1402
  */
1312
1403
  set store(store: KeyvMapType);
1313
1404
  /**
1314
- * Gets the current key separator used between namespace and key.
1405
+ * Gets the separator between the namespace and the key. Defaults to `::`.
1315
1406
  */
1316
- get keySeparator(): string;
1407
+ get namespaceSeparator(): string;
1317
1408
  /**
1318
- * Sets the key separator used between namespace and key.
1409
+ * Sets the separator between the namespace and the key.
1319
1410
  */
1320
- set keySeparator(separator: string);
1411
+ set namespaceSeparator(separator: string);
1321
1412
  /**
1322
1413
  * Gets the current namespace.
1323
1414
  */
@@ -1342,8 +1433,8 @@ declare class KeyvMemoryAdapter extends Hookified implements KeyvStorageAdapter
1342
1433
  namespace: string;
1343
1434
  key: string;
1344
1435
  } | {
1345
- key: string;
1346
1436
  namespace?: undefined;
1437
+ key: string;
1347
1438
  };
1348
1439
  /**
1349
1440
  * Retrieves a value from the store by key.
@@ -1359,7 +1450,7 @@ declare class KeyvMemoryAdapter extends Hookified implements KeyvStorageAdapter
1359
1450
  * @param expires - Optional absolute expiry as Unix ms since epoch
1360
1451
  * @returns Always returns true indicating success
1361
1452
  */
1362
- set(key: string, value: any, expires?: number): Promise<boolean>;
1453
+ set(key: string, value: KeyvAny, expires?: number): Promise<boolean>;
1363
1454
  /**
1364
1455
  * Stores multiple entries in the store at once.
1365
1456
  * @param entries - Array of entries containing key, value, and optional absolute `expires`
@@ -1372,9 +1463,11 @@ declare class KeyvMemoryAdapter extends Hookified implements KeyvStorageAdapter
1372
1463
  */
1373
1464
  delete(key: string): Promise<boolean>;
1374
1465
  /**
1375
- * Clears entries from the store. If a namespace is set, only entries
1376
- * within that namespace are removed. Otherwise, the entire store is cleared.
1377
- * NOTE: if there is no `keys()` then we just do a full clear.
1466
+ * Clears entries from the store. With no namespace, the whole store is cleared. With a
1467
+ * namespace, only that namespace's entries are removed, found through the store's `keys()`.
1468
+ * A store without `keys()` can't tell namespaces apart, so this throws rather than call the
1469
+ * store's `clear()` and delete every namespace's entries.
1470
+ * @throws {Error} If a namespace is set and the store has no `keys()`.
1378
1471
  */
1379
1472
  clear(): Promise<void>;
1380
1473
  /**
@@ -1432,7 +1525,7 @@ declare class KeyvMemoryAdapter extends Hookified implements KeyvStorageAdapter
1432
1525
  * // Create with namespace for multi-tenant scenarios
1433
1526
  * const tenantCache = createKeyv(new Map(), {
1434
1527
  * namespace: 'tenant-123',
1435
- * keySeparator: ':'
1528
+ * namespaceSeparator: '::'
1436
1529
  * });
1437
1530
  * ```
1438
1531
  */
@@ -1445,4 +1538,4 @@ declare class KeyvJsonSerializer implements KeyvSerializationAdapter {
1445
1538
  }
1446
1539
  declare const jsonSerializer: KeyvJsonSerializer;
1447
1540
  //#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 };
1541
+ 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 };