@kikiutils/shared 9.2.0 → 9.3.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.
Files changed (58) hide show
  1. package/README.md +34 -17
  2. package/dist/env.cjs +10 -13
  3. package/dist/env.cjs.map +1 -1
  4. package/dist/env.d.ts +9 -12
  5. package/dist/env.d.ts.map +1 -1
  6. package/dist/env.mjs +10 -13
  7. package/dist/env.mjs.map +1 -1
  8. package/dist/storage/enhanced/local/core.cjs +103 -0
  9. package/dist/storage/enhanced/local/core.cjs.map +1 -0
  10. package/dist/storage/enhanced/local/core.d.ts +56 -0
  11. package/dist/storage/enhanced/local/core.d.ts.map +1 -0
  12. package/dist/storage/enhanced/local/core.mjs +101 -0
  13. package/dist/storage/enhanced/local/core.mjs.map +1 -0
  14. package/dist/storage/enhanced/local/index.cjs +10 -0
  15. package/dist/storage/enhanced/local/index.cjs.map +1 -0
  16. package/dist/storage/enhanced/local/index.d.ts +3 -0
  17. package/dist/storage/enhanced/local/index.d.ts.map +1 -0
  18. package/dist/storage/enhanced/local/index.mjs +3 -0
  19. package/dist/storage/enhanced/local/index.mjs.map +1 -0
  20. package/dist/storage/enhanced/local/keyed-store.cjs +39 -0
  21. package/dist/storage/enhanced/local/keyed-store.cjs.map +1 -0
  22. package/dist/storage/enhanced/local/keyed-store.d.ts +31 -0
  23. package/dist/storage/enhanced/local/keyed-store.d.ts.map +1 -0
  24. package/dist/storage/enhanced/local/keyed-store.mjs +37 -0
  25. package/dist/storage/enhanced/local/keyed-store.mjs.map +1 -0
  26. package/dist/storage/enhanced/redis/core.cjs +142 -0
  27. package/dist/storage/enhanced/redis/core.cjs.map +1 -0
  28. package/dist/storage/enhanced/redis/core.d.ts +78 -0
  29. package/dist/storage/enhanced/redis/core.d.ts.map +1 -0
  30. package/dist/storage/enhanced/redis/core.mjs +140 -0
  31. package/dist/storage/enhanced/redis/core.mjs.map +1 -0
  32. package/dist/storage/enhanced/redis/index.cjs +10 -0
  33. package/dist/storage/enhanced/redis/index.cjs.map +1 -0
  34. package/dist/storage/enhanced/redis/index.d.ts +3 -0
  35. package/dist/storage/enhanced/redis/index.d.ts.map +1 -0
  36. package/dist/storage/enhanced/redis/index.mjs +3 -0
  37. package/dist/storage/enhanced/redis/index.mjs.map +1 -0
  38. package/dist/storage/enhanced/redis/keyed-store.cjs +44 -0
  39. package/dist/storage/enhanced/redis/keyed-store.cjs.map +1 -0
  40. package/dist/storage/enhanced/redis/keyed-store.d.ts +37 -0
  41. package/dist/storage/enhanced/redis/keyed-store.d.ts.map +1 -0
  42. package/dist/storage/enhanced/redis/keyed-store.mjs +42 -0
  43. package/dist/storage/enhanced/redis/keyed-store.mjs.map +1 -0
  44. package/dist/storage/lru/keyed-store.cjs +49 -0
  45. package/dist/storage/lru/keyed-store.cjs.map +1 -0
  46. package/dist/storage/lru/keyed-store.d.ts +40 -0
  47. package/dist/storage/lru/keyed-store.d.ts.map +1 -0
  48. package/dist/storage/lru/keyed-store.mjs +47 -0
  49. package/dist/storage/lru/keyed-store.mjs.map +1 -0
  50. package/package.json +33 -19
  51. package/src/env.ts +10 -13
  52. package/src/storage/enhanced/local/core.ts +104 -0
  53. package/src/storage/enhanced/local/index.ts +2 -0
  54. package/src/storage/enhanced/local/keyed-store.ts +34 -0
  55. package/src/storage/enhanced/redis/core.ts +149 -0
  56. package/src/storage/enhanced/redis/index.ts +2 -0
  57. package/src/storage/enhanced/redis/keyed-store.ts +41 -0
  58. package/src/storage/lru/keyed-store.ts +48 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyed-store.d.ts","sourceRoot":"","sources":["../../../../src/storage/enhanced/local/keyed-store.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,6BAA6B,CAAC,CAAC,GAAG,OAAO,MAC7C,CAAC,SAAS,GAAG,EAAE,EAAE,gBAAgB,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,MAAM;uBACxC,CAAC;uBACD,CAAC;0BACE,CAAC;IACvB;;;;OAIG;0BACmB,CAAC;qBACN,CAAC,WAAW,CAAC;GAErC"}
@@ -0,0 +1,37 @@
1
+ import { enhancedLocalStorage } from './core.mjs';
2
+
3
+ /**
4
+ * Creates a reusable, type-safe storage interface based on `enhancedLocalStorage`
5
+ * and a dynamic key-generation function.
6
+ *
7
+ * This utility allows you to abstract away key construction logic and work directly
8
+ * with scoped key-value operations like `getItem`, `setItem`, and `removeItem`.
9
+ *
10
+ * @template D - The value type to store.
11
+ *
12
+ * @returns A factory that accepts a key generator function and returns a scoped storage interface.
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * const userStore = createKeyedEnhancedLocalStore<User>()((id: number) => `user:${id}`);
17
+ * userStore.setItem({ id: 123, name: 'user' }, 123);
18
+ * const user = userStore.getItem(123);
19
+ * ```
20
+ */
21
+ function createKeyedEnhancedLocalStore() {
22
+ return (getKeyFunction) => Object.freeze({
23
+ getItem: (...args) => enhancedLocalStorage.getItem(getKeyFunction(...args)),
24
+ hasItem: (...args) => enhancedLocalStorage.hasItem(getKeyFunction(...args)),
25
+ removeItem: (...args) => enhancedLocalStorage.removeItem(getKeyFunction(...args)),
26
+ /**
27
+ * Resolves the storage key from the given arguments.
28
+ *
29
+ * @returns {string} The final string key used internally.
30
+ */
31
+ resolveKey: (...args) => getKeyFunction(...args),
32
+ setItem: (value, ...args) => enhancedLocalStorage.setItem(getKeyFunction(...args), value),
33
+ });
34
+ }
35
+
36
+ export { createKeyedEnhancedLocalStore };
37
+ //# sourceMappingURL=keyed-store.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyed-store.mjs","sources":["../../../../src/storage/enhanced/local/keyed-store.ts"],"sourcesContent":["import { enhancedLocalStorage } from './core';\n\n/**\n * Creates a reusable, type-safe storage interface based on `enhancedLocalStorage`\n * and a dynamic key-generation function.\n *\n * This utility allows you to abstract away key construction logic and work directly\n * with scoped key-value operations like `getItem`, `setItem`, and `removeItem`.\n *\n * @template D - The value type to store.\n *\n * @returns A factory that accepts a key generator function and returns a scoped storage interface.\n *\n * @example\n * ```typescript\n * const userStore = createKeyedEnhancedLocalStore<User>()((id: number) => `user:${id}`);\n * userStore.setItem({ id: 123, name: 'user' }, 123);\n * const user = userStore.getItem(123);\n * ```\n */\nexport function createKeyedEnhancedLocalStore<D = unknown>() {\n return <P extends any[]>(getKeyFunction: (...args: P) => string) => Object.freeze({\n getItem: (...args: P) => enhancedLocalStorage.getItem<D>(getKeyFunction(...args)),\n hasItem: (...args: P) => enhancedLocalStorage.hasItem(getKeyFunction(...args)),\n removeItem: (...args: P) => enhancedLocalStorage.removeItem(getKeyFunction(...args)),\n /**\n * Resolves the storage key from the given arguments.\n *\n * @returns {string} The final string key used internally.\n */\n resolveKey: (...args: P) => getKeyFunction(...args),\n setItem: (value: D, ...args: P) => enhancedLocalStorage.setItem(getKeyFunction(...args), value),\n });\n}\n"],"names":[],"mappings":";;AAEA;;;;;;;;;;;;;;;;;AAiBG;SACa,6BAA6B,GAAA;IACzC,OAAO,CAAkB,cAAsC,KAAK,MAAM,CAAC,MAAM,CAAC;AAC9E,QAAA,OAAO,EAAE,CAAC,GAAG,IAAO,KAAK,oBAAoB,CAAC,OAAO,CAAI,cAAc,CAAC,GAAG,IAAI,CAAC,CAAC;AACjF,QAAA,OAAO,EAAE,CAAC,GAAG,IAAO,KAAK,oBAAoB,CAAC,OAAO,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC,CAAC;AAC9E,QAAA,UAAU,EAAE,CAAC,GAAG,IAAO,KAAK,oBAAoB,CAAC,UAAU,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC,CAAC;AACpF;;;;AAIG;QACH,UAAU,EAAE,CAAC,GAAG,IAAO,KAAK,cAAc,CAAC,GAAG,IAAI,CAAC;QACnD,OAAO,EAAE,CAAC,KAAQ,EAAE,GAAG,IAAO,KAAK,oBAAoB,CAAC,OAAO,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC,EAAE,KAAK,CAAC;AAClG,KAAA,CAAC;AACN;;;;"}
@@ -0,0 +1,142 @@
1
+ 'use strict';
2
+
3
+ const node_buffer = require('node:buffer');
4
+ const ioredis = require('ioredis');
5
+ const superjson = require('superjson');
6
+
7
+ var StorageValueEncodingType;
8
+ (function (StorageValueEncodingType) {
9
+ StorageValueEncodingType[StorageValueEncodingType["Buffer"] = 0] = "Buffer";
10
+ StorageValueEncodingType[StorageValueEncodingType["Json"] = 1] = "Json";
11
+ StorageValueEncodingType[StorageValueEncodingType["String"] = 2] = "String";
12
+ })(StorageValueEncodingType || (StorageValueEncodingType = {}));
13
+ const customValueHeader = node_buffer.Buffer.of(0xE2, 0x81, 0xA0);
14
+ const customValueHeaderLength = customValueHeader.byteLength + 1;
15
+ /**
16
+ * Creates an enhanced Redis-based storage interface using SuperJSON encoding.
17
+ *
18
+ * This utility provides a typed, serializable key-value store backed by Redis,
19
+ * supporting TTL operations and safe deserialization of complex types (e.g. Date, Map).
20
+ *
21
+ * @param {Redis | string} ioRedisInstanceOrUrl - Either an existing `ioredis` instance or a Redis connection string.
22
+ *
23
+ * @returns A frozen object that wraps Redis commands with typed get/set logic and encoding.
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * const redisStorage = createEnhancedRedisStorage('redis://localhost');
28
+ * await redisStorage.setItem('user:1', { name: 'user' });
29
+ * const user = await redisStorage.getItem<{ name: string }>('user:1');
30
+ * ```
31
+ */
32
+ function createEnhancedRedisStorage(ioRedisInstanceOrUrl) {
33
+ const instance = ioRedisInstanceOrUrl instanceof ioredis.Redis ? ioRedisInstanceOrUrl : new ioredis.Redis(ioRedisInstanceOrUrl);
34
+ return Object.freeze({
35
+ /**
36
+ * Retrieves a value from Redis and decodes it.
37
+ *
38
+ * @template T - The expected return type.
39
+ *
40
+ * @param {string} key - The Redis key.
41
+ *
42
+ * @returns {Promise<null | T>} The decoded value or null if not found.
43
+ */
44
+ async getItem(key) {
45
+ const rawValue = await instance.getBuffer(key);
46
+ return rawValue ? decodeStorageValue(rawValue) : null;
47
+ },
48
+ /**
49
+ * Gets the remaining TTL (in seconds) for a given key.
50
+ *
51
+ * @param {string} key - The Redis key.
52
+ *
53
+ * @returns {Promise<number>} The number of seconds until the key expires, or -1 if no expiration is set.
54
+ */
55
+ getItemTtl: (key) => instance.ttl(key),
56
+ /**
57
+ * Checks whether a key exists in Redis.
58
+ *
59
+ * @param {string} key - The Redis key.
60
+ *
61
+ * @returns {Promise<boolean>} True if the key exists, false otherwise.
62
+ */
63
+ hasItem: async (key) => await instance.exists(key) === 1,
64
+ /**
65
+ * The underlying Redis instance, exposed for advanced operations.
66
+ * Use with caution; most use cases should rely on the wrapper methods.
67
+ *
68
+ * @returns {Redis} The underlying Redis instance.
69
+ */
70
+ get instance() {
71
+ return instance;
72
+ },
73
+ /**
74
+ * Removes a key from Redis.
75
+ *
76
+ * @param {string} key - The Redis key to delete.
77
+ *
78
+ * @returns {Promise<boolean>} A Promise that resolves to `true` if the key was removed,
79
+ * or `false` if it did not exist.
80
+ */
81
+ removeItem: async (key) => await instance.del(key) === 1,
82
+ /**
83
+ * Stores a value in Redis without expiration.
84
+ *
85
+ * @param {string} key - The Redis key.
86
+ * @param {any} value - The value to store. Will be serialized.
87
+ */
88
+ setItem: (key, value) => instance.set(key, encodeToStorageValue(value)),
89
+ /**
90
+ * Stores a value in Redis with a time-to-live (TTL).
91
+ *
92
+ * @param {string} key - The Redis key.
93
+ * @param {number} seconds - Expiration time in seconds.
94
+ * @param {any} value - The value to store. Will be serialized.
95
+ */
96
+ setItemWithTtl(key, seconds, value) {
97
+ return instance.setex(key, seconds, encodeToStorageValue(value));
98
+ },
99
+ });
100
+ }
101
+ function decodeStorageValue(data) {
102
+ if (!isCustomFormat(data))
103
+ return data;
104
+ const payload = data.subarray(customValueHeaderLength);
105
+ const type = data[customValueHeader.byteLength];
106
+ switch (type) {
107
+ case StorageValueEncodingType.Buffer: return payload;
108
+ case StorageValueEncodingType.Json:
109
+ try {
110
+ return superjson.deserialize(JSON.parse(payload.toString()));
111
+ }
112
+ catch {
113
+ throw new Error('[RedisStorage] Failed to parse JSON payload.');
114
+ }
115
+ case StorageValueEncodingType.String: return payload.toString();
116
+ default:
117
+ throw new Error(`[RedisStorage] Unknown encoding type: ${type}.`);
118
+ }
119
+ }
120
+ function encodeToStorageValue(value) {
121
+ if (node_buffer.Buffer.isBuffer(value))
122
+ return toCustomValue(StorageValueEncodingType.Buffer, value);
123
+ if (typeof value === 'string')
124
+ return toCustomValue(StorageValueEncodingType.String, node_buffer.Buffer.from(value));
125
+ return toCustomValue(StorageValueEncodingType.Json, node_buffer.Buffer.from(JSON.stringify(superjson.serialize(value))));
126
+ }
127
+ function isCustomFormat(buffer) {
128
+ return (buffer.length >= customValueHeaderLength
129
+ && buffer[0] === customValueHeader[0]
130
+ && buffer[1] === customValueHeader[1]
131
+ && buffer[2] === customValueHeader[2]);
132
+ }
133
+ function toCustomValue(type, payload) {
134
+ return node_buffer.Buffer.concat([
135
+ customValueHeader,
136
+ node_buffer.Buffer.of(type),
137
+ payload,
138
+ ]);
139
+ }
140
+
141
+ exports.createEnhancedRedisStorage = createEnhancedRedisStorage;
142
+ //# sourceMappingURL=core.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core.cjs","sources":["../../../../src/storage/enhanced/redis/core.ts"],"sourcesContent":["import { Buffer } from 'node:buffer';\n\nimport { Redis } from 'ioredis';\nimport {\n deserialize,\n serialize,\n} from 'superjson';\n\nenum StorageValueEncodingType {\n Buffer = 0,\n Json = 1,\n String = 2,\n}\n\nconst customValueHeader = Buffer.of(\n 0xE2,\n 0x81,\n 0xA0,\n);\n\nconst customValueHeaderLength = customValueHeader.byteLength + 1;\n\n/**\n * Creates an enhanced Redis-based storage interface using SuperJSON encoding.\n *\n * This utility provides a typed, serializable key-value store backed by Redis,\n * supporting TTL operations and safe deserialization of complex types (e.g. Date, Map).\n *\n * @param {Redis | string} ioRedisInstanceOrUrl - Either an existing `ioredis` instance or a Redis connection string.\n *\n * @returns A frozen object that wraps Redis commands with typed get/set logic and encoding.\n *\n * @example\n * ```typescript\n * const redisStorage = createEnhancedRedisStorage('redis://localhost');\n * await redisStorage.setItem('user:1', { name: 'user' });\n * const user = await redisStorage.getItem<{ name: string }>('user:1');\n * ```\n */\nexport function createEnhancedRedisStorage(ioRedisInstanceOrUrl: Redis | string) {\n const instance = ioRedisInstanceOrUrl instanceof Redis ? ioRedisInstanceOrUrl : new Redis(ioRedisInstanceOrUrl);\n return Object.freeze({\n /**\n * Retrieves a value from Redis and decodes it.\n *\n * @template T - The expected return type.\n *\n * @param {string} key - The Redis key.\n *\n * @returns {Promise<null | T>} The decoded value or null if not found.\n */\n async getItem<T = unknown>(key: string) {\n const rawValue = await instance.getBuffer(key);\n return rawValue ? decodeStorageValue(rawValue) as T : null;\n },\n /**\n * Gets the remaining TTL (in seconds) for a given key.\n *\n * @param {string} key - The Redis key.\n *\n * @returns {Promise<number>} The number of seconds until the key expires, or -1 if no expiration is set.\n */\n getItemTtl: (key: string) => instance.ttl(key),\n /**\n * Checks whether a key exists in Redis.\n *\n * @param {string} key - The Redis key.\n *\n * @returns {Promise<boolean>} True if the key exists, false otherwise.\n */\n hasItem: async (key: string) => await instance.exists(key) === 1,\n /**\n * The underlying Redis instance, exposed for advanced operations.\n * Use with caution; most use cases should rely on the wrapper methods.\n *\n * @returns {Redis} The underlying Redis instance.\n */\n get instance() {\n return instance;\n },\n /**\n * Removes a key from Redis.\n *\n * @param {string} key - The Redis key to delete.\n *\n * @returns {Promise<boolean>} A Promise that resolves to `true` if the key was removed,\n * or `false` if it did not exist.\n */\n removeItem: async (key: string) => await instance.del(key) === 1,\n /**\n * Stores a value in Redis without expiration.\n *\n * @param {string} key - The Redis key.\n * @param {any} value - The value to store. Will be serialized.\n */\n setItem: (key: string, value: any) => instance.set(key, encodeToStorageValue(value)),\n /**\n * Stores a value in Redis with a time-to-live (TTL).\n *\n * @param {string} key - The Redis key.\n * @param {number} seconds - Expiration time in seconds.\n * @param {any} value - The value to store. Will be serialized.\n */\n setItemWithTtl(key: string, seconds: number, value: any) {\n return instance.setex(key, seconds, encodeToStorageValue(value));\n },\n });\n}\n\nfunction decodeStorageValue(data: Buffer) {\n if (!isCustomFormat(data)) return data;\n const payload = data.subarray(customValueHeaderLength);\n const type = data[customValueHeader.byteLength];\n switch (type) {\n case StorageValueEncodingType.Buffer: return payload;\n case StorageValueEncodingType.Json:\n try {\n return deserialize(JSON.parse(payload.toString()));\n } catch {\n throw new Error('[RedisStorage] Failed to parse JSON payload.');\n }\n case StorageValueEncodingType.String: return payload.toString();\n default:\n throw new Error(`[RedisStorage] Unknown encoding type: ${type}.`);\n }\n}\n\nfunction encodeToStorageValue(value: any) {\n if (Buffer.isBuffer(value)) return toCustomValue(StorageValueEncodingType.Buffer, value);\n if (typeof value === 'string') return toCustomValue(StorageValueEncodingType.String, Buffer.from(value));\n return toCustomValue(StorageValueEncodingType.Json, Buffer.from(JSON.stringify(serialize(value))));\n}\n\nfunction isCustomFormat(buffer: Buffer) {\n return (\n buffer.length >= customValueHeaderLength\n && buffer[0] === customValueHeader[0]\n && buffer[1] === customValueHeader[1]\n && buffer[2] === customValueHeader[2]\n );\n}\n\nfunction toCustomValue(type: StorageValueEncodingType, payload: Buffer) {\n return Buffer.concat([\n customValueHeader,\n Buffer.of(type),\n payload,\n ]);\n}\n"],"names":["Buffer","Redis","deserialize","serialize"],"mappings":";;;;;;AAQA,IAAK,wBAIJ;AAJD,CAAA,UAAK,wBAAwB,EAAA;AACzB,IAAA,wBAAA,CAAA,wBAAA,CAAA,QAAA,CAAA,GAAA,CAAA,CAAA,GAAA,QAAU;AACV,IAAA,wBAAA,CAAA,wBAAA,CAAA,MAAA,CAAA,GAAA,CAAA,CAAA,GAAA,MAAQ;AACR,IAAA,wBAAA,CAAA,wBAAA,CAAA,QAAA,CAAA,GAAA,CAAA,CAAA,GAAA,QAAU;AACd,CAAC,EAJI,wBAAwB,KAAxB,wBAAwB,GAI5B,EAAA,CAA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A,SAAS,cAAc,CAAC,MAAc,EAAA;AAClC,IAAA,QACI,MAAM,CAAC,MAAM,IAAI;AACd,WAAA,MAAM,CAAC,CAAC,CAAC,KAAK,iBAAiB,CAAC,CAAC;AACjC,WAAA,MAAM,CAAC,CAAC,CAAC,KAAK,iBAAiB,CAAC,CAAC;WACjC,MAAM,CAAC,CAAC,CAAC,KAAK,iBAAiB,CAAC,CAAC,CAAC;AAE7C;AAEA,SAAS,aAAa,CAAC,IAA8B,EAAE,OAAe,EAAA;IAClE,OAAOH,kBAAM,CAAC,MAAM,CAAC;QACjB,iBAAiB;AACjB,QAAAA,kBAAM,CAAC,EAAE,CAAC,IAAI,CAAC;QACf,OAAO;AACV,KAAA,CAAC;AACN;;;;"}
@@ -0,0 +1,78 @@
1
+ import { Redis } from 'ioredis';
2
+ /**
3
+ * Creates an enhanced Redis-based storage interface using SuperJSON encoding.
4
+ *
5
+ * This utility provides a typed, serializable key-value store backed by Redis,
6
+ * supporting TTL operations and safe deserialization of complex types (e.g. Date, Map).
7
+ *
8
+ * @param {Redis | string} ioRedisInstanceOrUrl - Either an existing `ioredis` instance or a Redis connection string.
9
+ *
10
+ * @returns A frozen object that wraps Redis commands with typed get/set logic and encoding.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const redisStorage = createEnhancedRedisStorage('redis://localhost');
15
+ * await redisStorage.setItem('user:1', { name: 'user' });
16
+ * const user = await redisStorage.getItem<{ name: string }>('user:1');
17
+ * ```
18
+ */
19
+ export declare function createEnhancedRedisStorage(ioRedisInstanceOrUrl: Redis | string): Readonly<{
20
+ /**
21
+ * Retrieves a value from Redis and decodes it.
22
+ *
23
+ * @template T - The expected return type.
24
+ *
25
+ * @param {string} key - The Redis key.
26
+ *
27
+ * @returns {Promise<null | T>} The decoded value or null if not found.
28
+ */
29
+ getItem<T = unknown>(key: string): Promise<T | null>;
30
+ /**
31
+ * Gets the remaining TTL (in seconds) for a given key.
32
+ *
33
+ * @param {string} key - The Redis key.
34
+ *
35
+ * @returns {Promise<number>} The number of seconds until the key expires, or -1 if no expiration is set.
36
+ */
37
+ getItemTtl: (key: string) => Promise<number>;
38
+ /**
39
+ * Checks whether a key exists in Redis.
40
+ *
41
+ * @param {string} key - The Redis key.
42
+ *
43
+ * @returns {Promise<boolean>} True if the key exists, false otherwise.
44
+ */
45
+ hasItem: (key: string) => Promise<boolean>;
46
+ /**
47
+ * The underlying Redis instance, exposed for advanced operations.
48
+ * Use with caution; most use cases should rely on the wrapper methods.
49
+ *
50
+ * @returns {Redis} The underlying Redis instance.
51
+ */
52
+ readonly instance: Redis;
53
+ /**
54
+ * Removes a key from Redis.
55
+ *
56
+ * @param {string} key - The Redis key to delete.
57
+ *
58
+ * @returns {Promise<boolean>} A Promise that resolves to `true` if the key was removed,
59
+ * or `false` if it did not exist.
60
+ */
61
+ removeItem: (key: string) => Promise<boolean>;
62
+ /**
63
+ * Stores a value in Redis without expiration.
64
+ *
65
+ * @param {string} key - The Redis key.
66
+ * @param {any} value - The value to store. Will be serialized.
67
+ */
68
+ setItem: (key: string, value: any) => Promise<"OK">;
69
+ /**
70
+ * Stores a value in Redis with a time-to-live (TTL).
71
+ *
72
+ * @param {string} key - The Redis key.
73
+ * @param {number} seconds - Expiration time in seconds.
74
+ * @param {any} value - The value to store. Will be serialized.
75
+ */
76
+ setItemWithTtl(key: string, seconds: number, value: any): Promise<"OK">;
77
+ }>;
78
+ //# sourceMappingURL=core.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../../../src/storage/enhanced/redis/core.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAoBhC;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,0BAA0B,CAAC,oBAAoB,EAAE,KAAK,GAAG,MAAM;IAGvE;;;;;;;;OAQG;YACW,CAAC,iBAAiB,MAAM;IAItC;;;;;;OAMG;sBACe,MAAM;IACxB;;;;;;OAMG;mBACkB,MAAM;IAC3B;;;;;OAKG;;IAIH;;;;;;;OAOG;sBACqB,MAAM;IAC9B;;;;;OAKG;mBACY,MAAM,SAAS,GAAG;IACjC;;;;;;OAMG;wBACiB,MAAM,WAAW,MAAM,SAAS,GAAG;GAI9D"}
@@ -0,0 +1,140 @@
1
+ import { Buffer } from 'node:buffer';
2
+ import { Redis } from 'ioredis';
3
+ import { serialize, deserialize } from 'superjson';
4
+
5
+ var StorageValueEncodingType;
6
+ (function (StorageValueEncodingType) {
7
+ StorageValueEncodingType[StorageValueEncodingType["Buffer"] = 0] = "Buffer";
8
+ StorageValueEncodingType[StorageValueEncodingType["Json"] = 1] = "Json";
9
+ StorageValueEncodingType[StorageValueEncodingType["String"] = 2] = "String";
10
+ })(StorageValueEncodingType || (StorageValueEncodingType = {}));
11
+ const customValueHeader = Buffer.of(0xE2, 0x81, 0xA0);
12
+ const customValueHeaderLength = customValueHeader.byteLength + 1;
13
+ /**
14
+ * Creates an enhanced Redis-based storage interface using SuperJSON encoding.
15
+ *
16
+ * This utility provides a typed, serializable key-value store backed by Redis,
17
+ * supporting TTL operations and safe deserialization of complex types (e.g. Date, Map).
18
+ *
19
+ * @param {Redis | string} ioRedisInstanceOrUrl - Either an existing `ioredis` instance or a Redis connection string.
20
+ *
21
+ * @returns A frozen object that wraps Redis commands with typed get/set logic and encoding.
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * const redisStorage = createEnhancedRedisStorage('redis://localhost');
26
+ * await redisStorage.setItem('user:1', { name: 'user' });
27
+ * const user = await redisStorage.getItem<{ name: string }>('user:1');
28
+ * ```
29
+ */
30
+ function createEnhancedRedisStorage(ioRedisInstanceOrUrl) {
31
+ const instance = ioRedisInstanceOrUrl instanceof Redis ? ioRedisInstanceOrUrl : new Redis(ioRedisInstanceOrUrl);
32
+ return Object.freeze({
33
+ /**
34
+ * Retrieves a value from Redis and decodes it.
35
+ *
36
+ * @template T - The expected return type.
37
+ *
38
+ * @param {string} key - The Redis key.
39
+ *
40
+ * @returns {Promise<null | T>} The decoded value or null if not found.
41
+ */
42
+ async getItem(key) {
43
+ const rawValue = await instance.getBuffer(key);
44
+ return rawValue ? decodeStorageValue(rawValue) : null;
45
+ },
46
+ /**
47
+ * Gets the remaining TTL (in seconds) for a given key.
48
+ *
49
+ * @param {string} key - The Redis key.
50
+ *
51
+ * @returns {Promise<number>} The number of seconds until the key expires, or -1 if no expiration is set.
52
+ */
53
+ getItemTtl: (key) => instance.ttl(key),
54
+ /**
55
+ * Checks whether a key exists in Redis.
56
+ *
57
+ * @param {string} key - The Redis key.
58
+ *
59
+ * @returns {Promise<boolean>} True if the key exists, false otherwise.
60
+ */
61
+ hasItem: async (key) => await instance.exists(key) === 1,
62
+ /**
63
+ * The underlying Redis instance, exposed for advanced operations.
64
+ * Use with caution; most use cases should rely on the wrapper methods.
65
+ *
66
+ * @returns {Redis} The underlying Redis instance.
67
+ */
68
+ get instance() {
69
+ return instance;
70
+ },
71
+ /**
72
+ * Removes a key from Redis.
73
+ *
74
+ * @param {string} key - The Redis key to delete.
75
+ *
76
+ * @returns {Promise<boolean>} A Promise that resolves to `true` if the key was removed,
77
+ * or `false` if it did not exist.
78
+ */
79
+ removeItem: async (key) => await instance.del(key) === 1,
80
+ /**
81
+ * Stores a value in Redis without expiration.
82
+ *
83
+ * @param {string} key - The Redis key.
84
+ * @param {any} value - The value to store. Will be serialized.
85
+ */
86
+ setItem: (key, value) => instance.set(key, encodeToStorageValue(value)),
87
+ /**
88
+ * Stores a value in Redis with a time-to-live (TTL).
89
+ *
90
+ * @param {string} key - The Redis key.
91
+ * @param {number} seconds - Expiration time in seconds.
92
+ * @param {any} value - The value to store. Will be serialized.
93
+ */
94
+ setItemWithTtl(key, seconds, value) {
95
+ return instance.setex(key, seconds, encodeToStorageValue(value));
96
+ },
97
+ });
98
+ }
99
+ function decodeStorageValue(data) {
100
+ if (!isCustomFormat(data))
101
+ return data;
102
+ const payload = data.subarray(customValueHeaderLength);
103
+ const type = data[customValueHeader.byteLength];
104
+ switch (type) {
105
+ case StorageValueEncodingType.Buffer: return payload;
106
+ case StorageValueEncodingType.Json:
107
+ try {
108
+ return deserialize(JSON.parse(payload.toString()));
109
+ }
110
+ catch {
111
+ throw new Error('[RedisStorage] Failed to parse JSON payload.');
112
+ }
113
+ case StorageValueEncodingType.String: return payload.toString();
114
+ default:
115
+ throw new Error(`[RedisStorage] Unknown encoding type: ${type}.`);
116
+ }
117
+ }
118
+ function encodeToStorageValue(value) {
119
+ if (Buffer.isBuffer(value))
120
+ return toCustomValue(StorageValueEncodingType.Buffer, value);
121
+ if (typeof value === 'string')
122
+ return toCustomValue(StorageValueEncodingType.String, Buffer.from(value));
123
+ return toCustomValue(StorageValueEncodingType.Json, Buffer.from(JSON.stringify(serialize(value))));
124
+ }
125
+ function isCustomFormat(buffer) {
126
+ return (buffer.length >= customValueHeaderLength
127
+ && buffer[0] === customValueHeader[0]
128
+ && buffer[1] === customValueHeader[1]
129
+ && buffer[2] === customValueHeader[2]);
130
+ }
131
+ function toCustomValue(type, payload) {
132
+ return Buffer.concat([
133
+ customValueHeader,
134
+ Buffer.of(type),
135
+ payload,
136
+ ]);
137
+ }
138
+
139
+ export { createEnhancedRedisStorage };
140
+ //# sourceMappingURL=core.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core.mjs","sources":["../../../../src/storage/enhanced/redis/core.ts"],"sourcesContent":["import { Buffer } from 'node:buffer';\n\nimport { Redis } from 'ioredis';\nimport {\n deserialize,\n serialize,\n} from 'superjson';\n\nenum StorageValueEncodingType {\n Buffer = 0,\n Json = 1,\n String = 2,\n}\n\nconst customValueHeader = Buffer.of(\n 0xE2,\n 0x81,\n 0xA0,\n);\n\nconst customValueHeaderLength = customValueHeader.byteLength + 1;\n\n/**\n * Creates an enhanced Redis-based storage interface using SuperJSON encoding.\n *\n * This utility provides a typed, serializable key-value store backed by Redis,\n * supporting TTL operations and safe deserialization of complex types (e.g. Date, Map).\n *\n * @param {Redis | string} ioRedisInstanceOrUrl - Either an existing `ioredis` instance or a Redis connection string.\n *\n * @returns A frozen object that wraps Redis commands with typed get/set logic and encoding.\n *\n * @example\n * ```typescript\n * const redisStorage = createEnhancedRedisStorage('redis://localhost');\n * await redisStorage.setItem('user:1', { name: 'user' });\n * const user = await redisStorage.getItem<{ name: string }>('user:1');\n * ```\n */\nexport function createEnhancedRedisStorage(ioRedisInstanceOrUrl: Redis | string) {\n const instance = ioRedisInstanceOrUrl instanceof Redis ? ioRedisInstanceOrUrl : new Redis(ioRedisInstanceOrUrl);\n return Object.freeze({\n /**\n * Retrieves a value from Redis and decodes it.\n *\n * @template T - The expected return type.\n *\n * @param {string} key - The Redis key.\n *\n * @returns {Promise<null | T>} The decoded value or null if not found.\n */\n async getItem<T = unknown>(key: string) {\n const rawValue = await instance.getBuffer(key);\n return rawValue ? decodeStorageValue(rawValue) as T : null;\n },\n /**\n * Gets the remaining TTL (in seconds) for a given key.\n *\n * @param {string} key - The Redis key.\n *\n * @returns {Promise<number>} The number of seconds until the key expires, or -1 if no expiration is set.\n */\n getItemTtl: (key: string) => instance.ttl(key),\n /**\n * Checks whether a key exists in Redis.\n *\n * @param {string} key - The Redis key.\n *\n * @returns {Promise<boolean>} True if the key exists, false otherwise.\n */\n hasItem: async (key: string) => await instance.exists(key) === 1,\n /**\n * The underlying Redis instance, exposed for advanced operations.\n * Use with caution; most use cases should rely on the wrapper methods.\n *\n * @returns {Redis} The underlying Redis instance.\n */\n get instance() {\n return instance;\n },\n /**\n * Removes a key from Redis.\n *\n * @param {string} key - The Redis key to delete.\n *\n * @returns {Promise<boolean>} A Promise that resolves to `true` if the key was removed,\n * or `false` if it did not exist.\n */\n removeItem: async (key: string) => await instance.del(key) === 1,\n /**\n * Stores a value in Redis without expiration.\n *\n * @param {string} key - The Redis key.\n * @param {any} value - The value to store. Will be serialized.\n */\n setItem: (key: string, value: any) => instance.set(key, encodeToStorageValue(value)),\n /**\n * Stores a value in Redis with a time-to-live (TTL).\n *\n * @param {string} key - The Redis key.\n * @param {number} seconds - Expiration time in seconds.\n * @param {any} value - The value to store. Will be serialized.\n */\n setItemWithTtl(key: string, seconds: number, value: any) {\n return instance.setex(key, seconds, encodeToStorageValue(value));\n },\n });\n}\n\nfunction decodeStorageValue(data: Buffer) {\n if (!isCustomFormat(data)) return data;\n const payload = data.subarray(customValueHeaderLength);\n const type = data[customValueHeader.byteLength];\n switch (type) {\n case StorageValueEncodingType.Buffer: return payload;\n case StorageValueEncodingType.Json:\n try {\n return deserialize(JSON.parse(payload.toString()));\n } catch {\n throw new Error('[RedisStorage] Failed to parse JSON payload.');\n }\n case StorageValueEncodingType.String: return payload.toString();\n default:\n throw new Error(`[RedisStorage] Unknown encoding type: ${type}.`);\n }\n}\n\nfunction encodeToStorageValue(value: any) {\n if (Buffer.isBuffer(value)) return toCustomValue(StorageValueEncodingType.Buffer, value);\n if (typeof value === 'string') return toCustomValue(StorageValueEncodingType.String, Buffer.from(value));\n return toCustomValue(StorageValueEncodingType.Json, Buffer.from(JSON.stringify(serialize(value))));\n}\n\nfunction isCustomFormat(buffer: Buffer) {\n return (\n buffer.length >= customValueHeaderLength\n && buffer[0] === customValueHeader[0]\n && buffer[1] === customValueHeader[1]\n && buffer[2] === customValueHeader[2]\n );\n}\n\nfunction toCustomValue(type: StorageValueEncodingType, payload: Buffer) {\n return Buffer.concat([\n customValueHeader,\n Buffer.of(type),\n payload,\n ]);\n}\n"],"names":[],"mappings":";;;;AAQA,IAAK,wBAIJ;AAJD,CAAA,UAAK,wBAAwB,EAAA;AACzB,IAAA,wBAAA,CAAA,wBAAA,CAAA,QAAA,CAAA,GAAA,CAAA,CAAA,GAAA,QAAU;AACV,IAAA,wBAAA,CAAA,wBAAA,CAAA,MAAA,CAAA,GAAA,CAAA,CAAA,GAAA,MAAQ;AACR,IAAA,wBAAA,CAAA,wBAAA,CAAA,QAAA,CAAA,GAAA,CAAA,CAAA,GAAA,QAAU;AACd,CAAC,EAJI,wBAAwB,KAAxB,wBAAwB,G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A,SAAS,cAAc,CAAC,MAAc,EAAA;AAClC,IAAA,QACI,MAAM,CAAC,MAAM,IAAI;AACd,WAAA,MAAM,CAAC,CAAC,CAAC,KAAK,iBAAiB,CAAC,CAAC;AACjC,WAAA,MAAM,CAAC,CAAC,CAAC,KAAK,iBAAiB,CAAC,CAAC;WACjC,MAAM,CAAC,CAAC,CAAC,KAAK,iBAAiB,CAAC,CAAC,CAAC;AAE7C;AAEA,SAAS,aAAa,CAAC,IAA8B,EAAE,OAAe,EAAA;IAClE,OAAO,MAAM,CAAC,MAAM,CAAC;QACjB,iBAAiB;AACjB,QAAA,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC;QACf,OAAO;AACV,KAAA,CAAC;AACN;;;;"}
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ const core = require('./core.cjs');
4
+ const keyedStore = require('./keyed-store.cjs');
5
+
6
+
7
+
8
+ exports.createEnhancedRedisStorage = core.createEnhancedRedisStorage;
9
+ exports.createKeyedEnhancedRedisStore = keyedStore.createKeyedEnhancedRedisStore;
10
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
@@ -0,0 +1,3 @@
1
+ export { createEnhancedRedisStorage } from './core';
2
+ export { createKeyedEnhancedRedisStore } from './keyed-store';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/enhanced/redis/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,QAAQ,CAAC;AACpD,OAAO,EAAE,6BAA6B,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { createEnhancedRedisStorage } from './core.mjs';
2
+ export { createKeyedEnhancedRedisStore } from './keyed-store.mjs';
3
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -0,0 +1,44 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Creates a reusable, type-safe Redis-backed storage interface based on `createEnhancedRedisStorage`
5
+ * and a dynamic key-generation function.
6
+ *
7
+ * This utility abstracts away key construction and provides high-level access
8
+ * to Redis operations such as `getItem`, `setItem`, `setItemWithTtl`, and `getItemTtl`.
9
+ * It is ideal for namespaced data, caching, and session handling.
10
+ *
11
+ * @template D - The value type to store.
12
+ *
13
+ * @param {ReturnType<typeof createEnhancedRedisStorage>} storage - The enhanced Redis storage instance.
14
+ *
15
+ * @returns A factory that accepts a key generator function and returns a scoped Redis storage interface.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const userStore = createKeyedEnhancedRedisStore<User>(redisStorage)((id: number) => `user:${id}`);
20
+ * await userStore.setItem({ id: 123, name: 'user' }, 123);
21
+ * const user = await userStore.getItem(123);
22
+ * ```
23
+ */
24
+ function createKeyedEnhancedRedisStore(storage) {
25
+ return (getKeyFunction) => Object.freeze({
26
+ getItem: (...args) => storage.getItem(getKeyFunction(...args)),
27
+ getItemTtl: (...args) => storage.getItemTtl(getKeyFunction(...args)),
28
+ hasItem: (...args) => storage.hasItem(getKeyFunction(...args)),
29
+ removeItem: (...args) => storage.removeItem(getKeyFunction(...args)),
30
+ /**
31
+ * Resolves the storage key from the given arguments.
32
+ *
33
+ * @returns {string} The final string key used internally.
34
+ */
35
+ resolveKey: (...args) => getKeyFunction(...args),
36
+ setItem: (value, ...args) => storage.setItem(getKeyFunction(...args), value),
37
+ setItemWithTtl(seconds, value, ...args) {
38
+ return storage.setItemWithTtl(getKeyFunction(...args), seconds, value);
39
+ },
40
+ });
41
+ }
42
+
43
+ exports.createKeyedEnhancedRedisStore = createKeyedEnhancedRedisStore;
44
+ //# sourceMappingURL=keyed-store.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyed-store.cjs","sources":["../../../../src/storage/enhanced/redis/keyed-store.ts"],"sourcesContent":["import type { createEnhancedRedisStorage } from './core';\n\n/**\n * Creates a reusable, type-safe Redis-backed storage interface based on `createEnhancedRedisStorage`\n * and a dynamic key-generation function.\n *\n * This utility abstracts away key construction and provides high-level access\n * to Redis operations such as `getItem`, `setItem`, `setItemWithTtl`, and `getItemTtl`.\n * It is ideal for namespaced data, caching, and session handling.\n *\n * @template D - The value type to store.\n *\n * @param {ReturnType<typeof createEnhancedRedisStorage>} storage - The enhanced Redis storage instance.\n *\n * @returns A factory that accepts a key generator function and returns a scoped Redis storage interface.\n *\n * @example\n * ```typescript\n * const userStore = createKeyedEnhancedRedisStore<User>(redisStorage)((id: number) => `user:${id}`);\n * await userStore.setItem({ id: 123, name: 'user' }, 123);\n * const user = await userStore.getItem(123);\n * ```\n */\nexport function createKeyedEnhancedRedisStore<D = unknown>(storage: ReturnType<typeof createEnhancedRedisStorage>) {\n return <P extends any[]>(getKeyFunction: (...args: P) => string) => Object.freeze({\n getItem: (...args: P) => storage.getItem<D>(getKeyFunction(...args)),\n getItemTtl: (...args: P) => storage.getItemTtl(getKeyFunction(...args)),\n hasItem: (...args: P) => storage.hasItem(getKeyFunction(...args)),\n removeItem: (...args: P) => storage.removeItem(getKeyFunction(...args)),\n /**\n * Resolves the storage key from the given arguments.\n *\n * @returns {string} The final string key used internally.\n */\n resolveKey: (...args: P) => getKeyFunction(...args),\n setItem: (value: D, ...args: P) => storage.setItem(getKeyFunction(...args), value),\n setItemWithTtl(seconds: number, value: D, ...args: P) {\n return storage.setItemWithTtl(getKeyFunction(...args), seconds, value);\n },\n });\n}\n"],"names":[],"mappings":";;AAEA;;;;;;;;;;;;;;;;;;;;AAoBG;AACG,SAAU,6BAA6B,CAAc,OAAsD,EAAA;IAC7G,OAAO,CAAkB,cAAsC,KAAK,MAAM,CAAC,MAAM,CAAC;AAC9E,QAAA,OAAO,EAAE,CAAC,GAAG,IAAO,KAAK,OAAO,CAAC,OAAO,CAAI,cAAc,CAAC,GAAG,IAAI,CAAC,CAAC;AACpE,QAAA,UAAU,EAAE,CAAC,GAAG,IAAO,KAAK,OAAO,CAAC,UAAU,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC,CAAC;AACvE,QAAA,OAAO,EAAE,CAAC,GAAG,IAAO,KAAK,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC,CAAC;AACjE,QAAA,UAAU,EAAE,CAAC,GAAG,IAAO,KAAK,OAAO,CAAC,UAAU,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC,CAAC;AACvE;;;;AAIG;QACH,UAAU,EAAE,CAAC,GAAG,IAAO,KAAK,cAAc,CAAC,GAAG,IAAI,CAAC;QACnD,OAAO,EAAE,CAAC,KAAQ,EAAE,GAAG,IAAO,KAAK,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC,EAAE,KAAK,CAAC;AAClF,QAAA,cAAc,CAAC,OAAe,EAAE,KAAQ,EAAE,GAAG,IAAO,EAAA;AAChD,YAAA,OAAO,OAAO,CAAC,cAAc,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC;SACzE;AACJ,KAAA,CAAC;AACN;;;;"}
@@ -0,0 +1,37 @@
1
+ import type { createEnhancedRedisStorage } from './core';
2
+ /**
3
+ * Creates a reusable, type-safe Redis-backed storage interface based on `createEnhancedRedisStorage`
4
+ * and a dynamic key-generation function.
5
+ *
6
+ * This utility abstracts away key construction and provides high-level access
7
+ * to Redis operations such as `getItem`, `setItem`, `setItemWithTtl`, and `getItemTtl`.
8
+ * It is ideal for namespaced data, caching, and session handling.
9
+ *
10
+ * @template D - The value type to store.
11
+ *
12
+ * @param {ReturnType<typeof createEnhancedRedisStorage>} storage - The enhanced Redis storage instance.
13
+ *
14
+ * @returns A factory that accepts a key generator function and returns a scoped Redis storage interface.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * const userStore = createKeyedEnhancedRedisStore<User>(redisStorage)((id: number) => `user:${id}`);
19
+ * await userStore.setItem({ id: 123, name: 'user' }, 123);
20
+ * const user = await userStore.getItem(123);
21
+ * ```
22
+ */
23
+ export declare function createKeyedEnhancedRedisStore<D = unknown>(storage: ReturnType<typeof createEnhancedRedisStorage>): <P extends any[]>(getKeyFunction: (...args: P) => string) => Readonly<{
24
+ getItem: (...args: P) => Promise<D | null>;
25
+ getItemTtl: (...args: P) => Promise<number>;
26
+ hasItem: (...args: P) => Promise<boolean>;
27
+ removeItem: (...args: P) => Promise<boolean>;
28
+ /**
29
+ * Resolves the storage key from the given arguments.
30
+ *
31
+ * @returns {string} The final string key used internally.
32
+ */
33
+ resolveKey: (...args: P) => string;
34
+ setItem: (value: D, ...args: P) => Promise<"OK">;
35
+ setItemWithTtl(seconds: number, value: D, ...args: P): Promise<"OK">;
36
+ }>;
37
+ //# sourceMappingURL=keyed-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyed-store.d.ts","sourceRoot":"","sources":["../../../../src/storage/enhanced/redis/keyed-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,QAAQ,CAAC;AAEzD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,6BAA6B,CAAC,CAAC,GAAG,OAAO,EAAE,OAAO,EAAE,UAAU,CAAC,OAAO,0BAA0B,CAAC,IACrG,CAAC,SAAS,GAAG,EAAE,EAAE,gBAAgB,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,MAAM;uBACxC,CAAC;0BACE,CAAC;uBACJ,CAAC;0BACE,CAAC;IACvB;;;;OAIG;0BACmB,CAAC;qBACN,CAAC,WAAW,CAAC;4BACN,MAAM,SAAS,CAAC,WAAW,CAAC;GAI3D"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Creates a reusable, type-safe Redis-backed storage interface based on `createEnhancedRedisStorage`
3
+ * and a dynamic key-generation function.
4
+ *
5
+ * This utility abstracts away key construction and provides high-level access
6
+ * to Redis operations such as `getItem`, `setItem`, `setItemWithTtl`, and `getItemTtl`.
7
+ * It is ideal for namespaced data, caching, and session handling.
8
+ *
9
+ * @template D - The value type to store.
10
+ *
11
+ * @param {ReturnType<typeof createEnhancedRedisStorage>} storage - The enhanced Redis storage instance.
12
+ *
13
+ * @returns A factory that accepts a key generator function and returns a scoped Redis storage interface.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * const userStore = createKeyedEnhancedRedisStore<User>(redisStorage)((id: number) => `user:${id}`);
18
+ * await userStore.setItem({ id: 123, name: 'user' }, 123);
19
+ * const user = await userStore.getItem(123);
20
+ * ```
21
+ */
22
+ function createKeyedEnhancedRedisStore(storage) {
23
+ return (getKeyFunction) => Object.freeze({
24
+ getItem: (...args) => storage.getItem(getKeyFunction(...args)),
25
+ getItemTtl: (...args) => storage.getItemTtl(getKeyFunction(...args)),
26
+ hasItem: (...args) => storage.hasItem(getKeyFunction(...args)),
27
+ removeItem: (...args) => storage.removeItem(getKeyFunction(...args)),
28
+ /**
29
+ * Resolves the storage key from the given arguments.
30
+ *
31
+ * @returns {string} The final string key used internally.
32
+ */
33
+ resolveKey: (...args) => getKeyFunction(...args),
34
+ setItem: (value, ...args) => storage.setItem(getKeyFunction(...args), value),
35
+ setItemWithTtl(seconds, value, ...args) {
36
+ return storage.setItemWithTtl(getKeyFunction(...args), seconds, value);
37
+ },
38
+ });
39
+ }
40
+
41
+ export { createKeyedEnhancedRedisStore };
42
+ //# sourceMappingURL=keyed-store.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyed-store.mjs","sources":["../../../../src/storage/enhanced/redis/keyed-store.ts"],"sourcesContent":["import type { createEnhancedRedisStorage } from './core';\n\n/**\n * Creates a reusable, type-safe Redis-backed storage interface based on `createEnhancedRedisStorage`\n * and a dynamic key-generation function.\n *\n * This utility abstracts away key construction and provides high-level access\n * to Redis operations such as `getItem`, `setItem`, `setItemWithTtl`, and `getItemTtl`.\n * It is ideal for namespaced data, caching, and session handling.\n *\n * @template D - The value type to store.\n *\n * @param {ReturnType<typeof createEnhancedRedisStorage>} storage - The enhanced Redis storage instance.\n *\n * @returns A factory that accepts a key generator function and returns a scoped Redis storage interface.\n *\n * @example\n * ```typescript\n * const userStore = createKeyedEnhancedRedisStore<User>(redisStorage)((id: number) => `user:${id}`);\n * await userStore.setItem({ id: 123, name: 'user' }, 123);\n * const user = await userStore.getItem(123);\n * ```\n */\nexport function createKeyedEnhancedRedisStore<D = unknown>(storage: ReturnType<typeof createEnhancedRedisStorage>) {\n return <P extends any[]>(getKeyFunction: (...args: P) => string) => Object.freeze({\n getItem: (...args: P) => storage.getItem<D>(getKeyFunction(...args)),\n getItemTtl: (...args: P) => storage.getItemTtl(getKeyFunction(...args)),\n hasItem: (...args: P) => storage.hasItem(getKeyFunction(...args)),\n removeItem: (...args: P) => storage.removeItem(getKeyFunction(...args)),\n /**\n * Resolves the storage key from the given arguments.\n *\n * @returns {string} The final string key used internally.\n */\n resolveKey: (...args: P) => getKeyFunction(...args),\n setItem: (value: D, ...args: P) => storage.setItem(getKeyFunction(...args), value),\n setItemWithTtl(seconds: number, value: D, ...args: P) {\n return storage.setItemWithTtl(getKeyFunction(...args), seconds, value);\n },\n });\n}\n"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;AAoBG;AACG,SAAU,6BAA6B,CAAc,OAAsD,EAAA;IAC7G,OAAO,CAAkB,cAAsC,KAAK,MAAM,CAAC,MAAM,CAAC;AAC9E,QAAA,OAAO,EAAE,CAAC,GAAG,IAAO,KAAK,OAAO,CAAC,OAAO,CAAI,cAAc,CAAC,GAAG,IAAI,CAAC,CAAC;AACpE,QAAA,UAAU,EAAE,CAAC,GAAG,IAAO,KAAK,OAAO,CAAC,UAAU,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC,CAAC;AACvE,QAAA,OAAO,EAAE,CAAC,GAAG,IAAO,KAAK,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC,CAAC;AACjE,QAAA,UAAU,EAAE,CAAC,GAAG,IAAO,KAAK,OAAO,CAAC,UAAU,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC,CAAC;AACvE;;;;AAIG;QACH,UAAU,EAAE,CAAC,GAAG,IAAO,KAAK,cAAc,CAAC,GAAG,IAAI,CAAC;QACnD,OAAO,EAAE,CAAC,KAAQ,EAAE,GAAG,IAAO,KAAK,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC,EAAE,KAAK,CAAC;AAClF,QAAA,cAAc,CAAC,OAAe,EAAE,KAAQ,EAAE,GAAG,IAAO,EAAA;AAChD,YAAA,OAAO,OAAO,CAAC,cAAc,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC;SACzE;AACJ,KAAA,CAAC;AACN;;;;"}