@iskra-bun/kv-kit 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/types.ts CHANGED
@@ -3,8 +3,36 @@ export interface KVAdapter {
3
3
  connect(): Promise<void> | void;
4
4
  disconnect(): Promise<void> | void;
5
5
 
6
- get(key: string): Promise<any>;
7
- set(key: string, value: any, ttl?: number): Promise<void>;
6
+ get<T = unknown>(key: string): Promise<T | undefined>;
7
+ set<T = unknown>(key: string, value: T, ttl?: number): Promise<void>;
8
8
  del(key: string): Promise<void>;
9
9
  has(key: string): Promise<boolean>;
10
+
11
+ // Optional native batch operations. When an adapter implements these, the
12
+ // KVManager prefers them over a per-key loop to avoid N+1 round-trips.
13
+ // Adapters that omit them remain fully compatible.
14
+ //
15
+ // Storing `null`/`undefined` is normalized to "absent" by the adapters that
16
+ // round-trip through JSON (see RedisAdapter); the in-memory adapter stores
17
+ // them verbatim. Callers should treat `null`/`undefined` values as
18
+ // undefined behavior and avoid relying on either form being preserved.
19
+ mget?<T = unknown>(keys: string[]): Promise<(T | undefined)[]>;
20
+ mset?<T = unknown>(entries: Array<[string, T]>, ttl?: number): Promise<void>;
21
+ mdel?(keys: string[]): Promise<void>;
22
+
23
+ /**
24
+ * Deletes every key that starts with `prefix` (every key the adapter holds
25
+ * without one), without touching the connection. An adapter that cannot
26
+ * leaves it out, and callers such as cache-kit's `clear()` then fail.
27
+ */
28
+ clear?(prefix?: string): Promise<void>;
29
+
30
+ /**
31
+ * Expiring sets, for cache-kit's tag index: `sadd` adds `member` to the set
32
+ * at `key` for `ttl` seconds (for good without one), and the set lives as
33
+ * long as its longest-lived member. `sdrain` deletes the set and returns
34
+ * its unexpired members in one step, so a member added meanwhile is never lost.
35
+ */
36
+ sadd?(key: string, member: string, ttl?: number): Promise<void>;
37
+ sdrain?(key: string): Promise<string[]>;
10
38
  }