@kikiutils/shared 12.0.0 → 13.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/buffer.d.ts +7 -3
- package/dist/buffer.d.ts.map +1 -1
- package/dist/buffer.js +42 -0
- package/dist/buffer.js.map +1 -0
- package/dist/clipboard.d.ts +8 -6
- package/dist/clipboard.d.ts.map +1 -1
- package/dist/clipboard.js +86 -0
- package/dist/clipboard.js.map +1 -0
- package/dist/consola.d.ts +8 -2
- package/dist/consola.d.ts.map +1 -1
- package/dist/consola.js +32 -0
- package/dist/consola.js.map +1 -0
- package/dist/crypto-hash.d.ts +16 -26
- package/dist/crypto-hash.d.ts.map +1 -1
- package/dist/crypto-hash.js +37 -0
- package/dist/crypto-hash.js.map +1 -0
- package/dist/datetime.d.ts +13 -9
- package/dist/datetime.d.ts.map +1 -1
- package/dist/datetime.js +131 -0
- package/dist/datetime.js.map +1 -0
- package/dist/element-plus.d.ts +8 -4
- package/dist/element-plus.d.ts.map +1 -1
- package/dist/element-plus.js +37 -0
- package/dist/element-plus.js.map +1 -0
- package/dist/enum.d.ts +6 -3
- package/dist/enum.d.ts.map +1 -1
- package/dist/enum.js +108 -0
- package/dist/enum.js.map +1 -0
- package/dist/env.d.ts +12 -9
- package/dist/env.d.ts.map +1 -1
- package/dist/env.js +51 -0
- package/dist/env.js.map +1 -0
- package/dist/general.d.ts +5 -2
- package/dist/general.d.ts.map +1 -1
- package/dist/general.js +8 -0
- package/dist/general.js.map +1 -0
- package/dist/hash.d.ts +7 -4
- package/dist/hash.d.ts.map +1 -1
- package/dist/hash.js +20 -0
- package/dist/hash.js.map +1 -0
- package/dist/math.d.ts +20 -17
- package/dist/math.d.ts.map +1 -1
- package/dist/math.js +36 -0
- package/dist/math.js.map +1 -0
- package/dist/number.d.ts +7 -2
- package/dist/number.d.ts.map +1 -1
- package/dist/number.js +32 -0
- package/dist/number.js.map +1 -0
- package/dist/object.d.ts +4 -1
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +42 -0
- package/dist/object.js.map +1 -0
- package/dist/pino.d.ts +8 -2
- package/dist/pino.d.ts.map +1 -1
- package/dist/pino.js +40 -0
- package/dist/pino.js.map +1 -0
- package/dist/random.d.ts +4 -1
- package/dist/random.d.ts.map +1 -1
- package/dist/random.js +31 -0
- package/dist/random.js.map +1 -0
- package/dist/storage/enhanced/local/core.d.ts +45 -42
- package/dist/storage/enhanced/local/core.d.ts.map +1 -1
- package/dist/storage/enhanced/local/core.js +63 -0
- package/dist/storage/enhanced/local/core.js.map +1 -0
- package/dist/storage/enhanced/local/index.d.ts +3 -3
- package/dist/storage/enhanced/local/index.js +4 -0
- package/dist/storage/enhanced/local/keyed-store.d.ts +14 -11
- package/dist/storage/enhanced/local/keyed-store.d.ts.map +1 -1
- package/dist/storage/enhanced/local/keyed-store.js +36 -0
- package/dist/storage/enhanced/local/keyed-store.js.map +1 -0
- package/dist/storage/enhanced/redis/core.d.ts +64 -59
- package/dist/storage/enhanced/redis/core.d.ts.map +1 -1
- package/dist/storage/enhanced/redis/core.js +85 -0
- package/dist/storage/enhanced/redis/core.js.map +1 -0
- package/dist/storage/enhanced/redis/index.d.ts +3 -3
- package/dist/storage/enhanced/redis/index.js +4 -0
- package/dist/storage/enhanced/redis/keyed-store.d.ts +19 -14
- package/dist/storage/enhanced/redis/keyed-store.d.ts.map +1 -1
- package/dist/storage/enhanced/redis/keyed-store.js +41 -0
- package/dist/storage/enhanced/redis/keyed-store.js.map +1 -0
- package/dist/storage/lru/keyed-store.d.ts +21 -16
- package/dist/storage/lru/keyed-store.d.ts.map +1 -1
- package/dist/storage/lru/keyed-store.js +40 -0
- package/dist/storage/lru/keyed-store.js.map +1 -0
- package/dist/string.d.ts +5 -2
- package/dist/string.d.ts.map +1 -1
- package/dist/string.js +42 -0
- package/dist/string.js.map +1 -0
- package/dist/url.d.ts +4 -1
- package/dist/url.d.ts.map +1 -1
- package/dist/url.js +21 -0
- package/dist/url.js.map +1 -0
- package/dist/vue.d.ts +10 -5
- package/dist/vue.d.ts.map +1 -1
- package/dist/vue.js +58 -0
- package/dist/vue.js.map +1 -0
- package/dist/web.d.ts +5 -2
- package/dist/web.d.ts.map +1 -1
- package/dist/web.js +32 -0
- package/dist/web.js.map +1 -0
- package/package.json +43 -27
- package/src/env.ts +1 -1
- package/src/vue.ts +1 -1
- package/src/web.ts +1 -1
- package/dist/buffer.cjs +0 -43
- package/dist/buffer.cjs.map +0 -1
- package/dist/buffer.mjs +0 -41
- package/dist/buffer.mjs.map +0 -1
- package/dist/clipboard.cjs +0 -91
- package/dist/clipboard.cjs.map +0 -1
- package/dist/clipboard.mjs +0 -88
- package/dist/clipboard.mjs.map +0 -1
- package/dist/consola.cjs +0 -35
- package/dist/consola.cjs.map +0 -1
- package/dist/consola.mjs +0 -32
- package/dist/consola.mjs.map +0 -1
- package/dist/crypto-hash.cjs +0 -61
- package/dist/crypto-hash.cjs.map +0 -1
- package/dist/crypto-hash.mjs +0 -50
- package/dist/crypto-hash.mjs.map +0 -1
- package/dist/datetime.cjs +0 -134
- package/dist/datetime.cjs.map +0 -1
- package/dist/datetime.mjs +0 -130
- package/dist/datetime.mjs.map +0 -1
- package/dist/element-plus.cjs +0 -37
- package/dist/element-plus.cjs.map +0 -1
- package/dist/element-plus.mjs +0 -35
- package/dist/element-plus.mjs.map +0 -1
- package/dist/enum.cjs +0 -112
- package/dist/enum.cjs.map +0 -1
- package/dist/enum.mjs +0 -108
- package/dist/enum.mjs.map +0 -1
- package/dist/env.cjs +0 -53
- package/dist/env.cjs.map +0 -1
- package/dist/env.mjs +0 -50
- package/dist/env.mjs.map +0 -1
- package/dist/general.cjs +0 -10
- package/dist/general.cjs.map +0 -1
- package/dist/general.mjs +0 -8
- package/dist/general.mjs.map +0 -1
- package/dist/hash.cjs +0 -36
- package/dist/hash.cjs.map +0 -1
- package/dist/hash.mjs +0 -31
- package/dist/hash.mjs.map +0 -1
- package/dist/math.cjs +0 -38
- package/dist/math.cjs.map +0 -1
- package/dist/math.mjs +0 -36
- package/dist/math.mjs.map +0 -1
- package/dist/number.cjs +0 -32
- package/dist/number.cjs.map +0 -1
- package/dist/number.mjs +0 -30
- package/dist/number.mjs.map +0 -1
- package/dist/object.cjs +0 -55
- package/dist/object.cjs.map +0 -1
- package/dist/object.mjs +0 -53
- package/dist/object.mjs.map +0 -1
- package/dist/pino.cjs +0 -42
- package/dist/pino.cjs.map +0 -1
- package/dist/pino.mjs +0 -39
- package/dist/pino.mjs.map +0 -1
- package/dist/random.cjs +0 -31
- package/dist/random.cjs.map +0 -1
- package/dist/random.mjs +0 -29
- package/dist/random.mjs.map +0 -1
- package/dist/storage/enhanced/local/core.cjs +0 -105
- package/dist/storage/enhanced/local/core.cjs.map +0 -1
- package/dist/storage/enhanced/local/core.mjs +0 -103
- package/dist/storage/enhanced/local/core.mjs.map +0 -1
- package/dist/storage/enhanced/local/index.cjs +0 -10
- package/dist/storage/enhanced/local/index.cjs.map +0 -1
- package/dist/storage/enhanced/local/index.d.ts.map +0 -1
- package/dist/storage/enhanced/local/index.mjs +0 -3
- package/dist/storage/enhanced/local/index.mjs.map +0 -1
- package/dist/storage/enhanced/local/keyed-store.cjs +0 -41
- package/dist/storage/enhanced/local/keyed-store.cjs.map +0 -1
- package/dist/storage/enhanced/local/keyed-store.mjs +0 -39
- package/dist/storage/enhanced/local/keyed-store.mjs.map +0 -1
- package/dist/storage/enhanced/redis/core.cjs +0 -144
- package/dist/storage/enhanced/redis/core.cjs.map +0 -1
- package/dist/storage/enhanced/redis/core.mjs +0 -142
- package/dist/storage/enhanced/redis/core.mjs.map +0 -1
- package/dist/storage/enhanced/redis/index.cjs +0 -10
- package/dist/storage/enhanced/redis/index.cjs.map +0 -1
- package/dist/storage/enhanced/redis/index.d.ts.map +0 -1
- package/dist/storage/enhanced/redis/index.mjs +0 -3
- package/dist/storage/enhanced/redis/index.mjs.map +0 -1
- package/dist/storage/enhanced/redis/keyed-store.cjs +0 -46
- package/dist/storage/enhanced/redis/keyed-store.cjs.map +0 -1
- package/dist/storage/enhanced/redis/keyed-store.mjs +0 -44
- package/dist/storage/enhanced/redis/keyed-store.mjs.map +0 -1
- package/dist/storage/lru/keyed-store.cjs +0 -49
- package/dist/storage/lru/keyed-store.cjs.map +0 -1
- package/dist/storage/lru/keyed-store.mjs +0 -47
- package/dist/storage/lru/keyed-store.mjs.map +0 -1
- package/dist/string.cjs +0 -45
- package/dist/string.cjs.map +0 -1
- package/dist/string.mjs +0 -43
- package/dist/string.mjs.map +0 -1
- package/dist/url.cjs +0 -21
- package/dist/url.cjs.map +0 -1
- package/dist/url.mjs +0 -19
- package/dist/url.mjs.map +0 -1
- package/dist/vue.cjs +0 -64
- package/dist/vue.cjs.map +0 -1
- package/dist/vue.mjs +0 -59
- package/dist/vue.mjs.map +0 -1
- package/dist/web.cjs +0 -35
- package/dist/web.cjs.map +0 -1
- package/dist/web.mjs +0 -32
- package/dist/web.mjs.map +0 -1
package/dist/random.cjs
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Generates a value using a provided generator function, where the input length
|
|
5
|
-
* is determined by two levels of nested random ranges:
|
|
6
|
-
*
|
|
7
|
-
* 1. First, a random number (`innerMin`) is chosen between `minMin` and `minMax`.
|
|
8
|
-
* 2. Then, a final length is chosen between `Math.max(innerMin, maxMin)` and `maxMax`.
|
|
9
|
-
* 3. The generator is called with the final length and its result is returned.
|
|
10
|
-
*
|
|
11
|
-
* This function supports any return type by using a generic type parameter.
|
|
12
|
-
*
|
|
13
|
-
* @template T - The return type of the generator function
|
|
14
|
-
*
|
|
15
|
-
* @param {(length: number) => T} generator - A function that accepts a length and returns a value of type T
|
|
16
|
-
* @param {number} minMin - Lower bound of the first random range
|
|
17
|
-
* @param {number} minMax - Upper bound of the first random range
|
|
18
|
-
* @param {number} maxMin - Lower bound of the second random range
|
|
19
|
-
* @param {number} maxMax - Upper bound of the second random range
|
|
20
|
-
*
|
|
21
|
-
* @returns {T} The result of the generator function using the computed final length
|
|
22
|
-
*/
|
|
23
|
-
function generateWithNestedRandomLength(generator, minMin, minMax, maxMin, maxMax) {
|
|
24
|
-
const random = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;
|
|
25
|
-
const innerMin = random(minMin, minMax);
|
|
26
|
-
const finalLength = random(Math.max(innerMin, maxMin), maxMax);
|
|
27
|
-
return generator(finalLength);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
exports.generateWithNestedRandomLength = generateWithNestedRandomLength;
|
|
31
|
-
//# sourceMappingURL=random.cjs.map
|
package/dist/random.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"random.cjs","sources":["../src/random.ts"],"sourcesContent":["/**\n * Generates a value using a provided generator function, where the input length\n * is determined by two levels of nested random ranges:\n *\n * 1. First, a random number (`innerMin`) is chosen between `minMin` and `minMax`.\n * 2. Then, a final length is chosen between `Math.max(innerMin, maxMin)` and `maxMax`.\n * 3. The generator is called with the final length and its result is returned.\n *\n * This function supports any return type by using a generic type parameter.\n *\n * @template T - The return type of the generator function\n *\n * @param {(length: number) => T} generator - A function that accepts a length and returns a value of type T\n * @param {number} minMin - Lower bound of the first random range\n * @param {number} minMax - Upper bound of the first random range\n * @param {number} maxMin - Lower bound of the second random range\n * @param {number} maxMax - Upper bound of the second random range\n *\n * @returns {T} The result of the generator function using the computed final length\n */\nexport function generateWithNestedRandomLength<T = string>(\n generator: (length: number) => T,\n minMin: number,\n minMax: number,\n maxMin: number,\n maxMax: number,\n) {\n const random = (min: number, max: number) => Math.floor(Math.random() * (max - min + 1)) + min;\n const innerMin = random(minMin, minMax);\n const finalLength = random(Math.max(innerMin, maxMin), maxMax);\n return generator(finalLength);\n}\n"],"names":[],"mappings":";;AAAA;;;;;;;;;;;;;;;;;;;AAmBG;AACG,SAAU,8BAA8B,CAC1C,SAAgC,EAChC,MAAc,EACd,MAAc,EACd,MAAc,EACd,MAAc,EAAA;AAEd,IAAA,MAAM,MAAM,GAAG,CAAC,GAAW,EAAE,GAAW,KAAK,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG;IAC9F,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;AACvC,IAAA,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC;AAC9D,IAAA,OAAO,SAAS,CAAC,WAAW,CAAC;AACjC;;;;"}
|
package/dist/random.mjs
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generates a value using a provided generator function, where the input length
|
|
3
|
-
* is determined by two levels of nested random ranges:
|
|
4
|
-
*
|
|
5
|
-
* 1. First, a random number (`innerMin`) is chosen between `minMin` and `minMax`.
|
|
6
|
-
* 2. Then, a final length is chosen between `Math.max(innerMin, maxMin)` and `maxMax`.
|
|
7
|
-
* 3. The generator is called with the final length and its result is returned.
|
|
8
|
-
*
|
|
9
|
-
* This function supports any return type by using a generic type parameter.
|
|
10
|
-
*
|
|
11
|
-
* @template T - The return type of the generator function
|
|
12
|
-
*
|
|
13
|
-
* @param {(length: number) => T} generator - A function that accepts a length and returns a value of type T
|
|
14
|
-
* @param {number} minMin - Lower bound of the first random range
|
|
15
|
-
* @param {number} minMax - Upper bound of the first random range
|
|
16
|
-
* @param {number} maxMin - Lower bound of the second random range
|
|
17
|
-
* @param {number} maxMax - Upper bound of the second random range
|
|
18
|
-
*
|
|
19
|
-
* @returns {T} The result of the generator function using the computed final length
|
|
20
|
-
*/
|
|
21
|
-
function generateWithNestedRandomLength(generator, minMin, minMax, maxMin, maxMax) {
|
|
22
|
-
const random = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;
|
|
23
|
-
const innerMin = random(minMin, minMax);
|
|
24
|
-
const finalLength = random(Math.max(innerMin, maxMin), maxMax);
|
|
25
|
-
return generator(finalLength);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export { generateWithNestedRandomLength };
|
|
29
|
-
//# sourceMappingURL=random.mjs.map
|
package/dist/random.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"random.mjs","sources":["../src/random.ts"],"sourcesContent":["/**\n * Generates a value using a provided generator function, where the input length\n * is determined by two levels of nested random ranges:\n *\n * 1. First, a random number (`innerMin`) is chosen between `minMin` and `minMax`.\n * 2. Then, a final length is chosen between `Math.max(innerMin, maxMin)` and `maxMax`.\n * 3. The generator is called with the final length and its result is returned.\n *\n * This function supports any return type by using a generic type parameter.\n *\n * @template T - The return type of the generator function\n *\n * @param {(length: number) => T} generator - A function that accepts a length and returns a value of type T\n * @param {number} minMin - Lower bound of the first random range\n * @param {number} minMax - Upper bound of the first random range\n * @param {number} maxMin - Lower bound of the second random range\n * @param {number} maxMax - Upper bound of the second random range\n *\n * @returns {T} The result of the generator function using the computed final length\n */\nexport function generateWithNestedRandomLength<T = string>(\n generator: (length: number) => T,\n minMin: number,\n minMax: number,\n maxMin: number,\n maxMax: number,\n) {\n const random = (min: number, max: number) => Math.floor(Math.random() * (max - min + 1)) + min;\n const innerMin = random(minMin, minMax);\n const finalLength = random(Math.max(innerMin, maxMin), maxMax);\n return generator(finalLength);\n}\n"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;AAmBG;AACG,SAAU,8BAA8B,CAC1C,SAAgC,EAChC,MAAc,EACd,MAAc,EACd,MAAc,EACd,MAAc,EAAA;AAEd,IAAA,MAAM,MAAM,GAAG,CAAC,GAAW,EAAE,GAAW,KAAK,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG;IAC9F,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;AACvC,IAAA,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC;AAC9D,IAAA,OAAO,SAAS,CAAC,WAAW,CAAC;AACjC;;;;"}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const superjson = require('superjson');
|
|
4
|
-
|
|
5
|
-
var StorageValueEncodingType;
|
|
6
|
-
(function (StorageValueEncodingType) {
|
|
7
|
-
StorageValueEncodingType["Json"] = "0";
|
|
8
|
-
StorageValueEncodingType["String"] = "1";
|
|
9
|
-
})(StorageValueEncodingType || (StorageValueEncodingType = {}));
|
|
10
|
-
const customValueHeader = '';
|
|
11
|
-
const customValueHeaderLength = customValueHeader.length + 1;
|
|
12
|
-
const toCustomValue = (type, payload) => `${customValueHeader}${type}${payload}`;
|
|
13
|
-
/**
|
|
14
|
-
* An enhanced localStorage wrapper that supports storing
|
|
15
|
-
* complex data types (e.g. Dates, Maps, Sets) using SuperJSON encoding.
|
|
16
|
-
*
|
|
17
|
-
* This utility preserves type structure when saving and retrieving values.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```typescript
|
|
21
|
-
* import { enhancedLocalStorage } from '@kikiutils/shared/storage/enhanced/local';
|
|
22
|
-
*
|
|
23
|
-
* enhancedLocalStorage.setItem('user', { name: 'user', createdAt: new Date() });
|
|
24
|
-
* const user = enhancedLocalStorage.getItem<{ name: string, createdAt: Date }>('user');
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
const enhancedLocalStorage = Object.freeze({
|
|
28
|
-
/**
|
|
29
|
-
* Removes all items from localStorage.
|
|
30
|
-
*/
|
|
31
|
-
clear: () => window.localStorage.clear(),
|
|
32
|
-
/**
|
|
33
|
-
* Retrieves a value by key and decodes it using SuperJSON or raw string.
|
|
34
|
-
*
|
|
35
|
-
* @template T - The expected type of the value
|
|
36
|
-
*
|
|
37
|
-
* @param {string} key - The key of the value to retrieve
|
|
38
|
-
*
|
|
39
|
-
* @returns {null | T} The decoded value or null if not found
|
|
40
|
-
*/
|
|
41
|
-
getItem(key) {
|
|
42
|
-
const rawValue = window.localStorage.getItem(key);
|
|
43
|
-
return rawValue ? decodeStorageValue(rawValue) : null;
|
|
44
|
-
},
|
|
45
|
-
/**
|
|
46
|
-
* Checks whether a key exists in localStorage.
|
|
47
|
-
*
|
|
48
|
-
* @param {string} key - The key to check
|
|
49
|
-
*
|
|
50
|
-
* @returns {boolean} True if the key exists, false otherwise
|
|
51
|
-
*/
|
|
52
|
-
hasItem: (key) => window.localStorage.getItem(key) !== null,
|
|
53
|
-
/**
|
|
54
|
-
* Returns the number of items stored in localStorage.
|
|
55
|
-
*
|
|
56
|
-
* @returns {number} The number of items stored in localStorage
|
|
57
|
-
*/
|
|
58
|
-
get length() {
|
|
59
|
-
return window.localStorage.length;
|
|
60
|
-
},
|
|
61
|
-
/**
|
|
62
|
-
* Removes a specific key from localStorage.
|
|
63
|
-
*
|
|
64
|
-
* @param {string} key - The key to remove
|
|
65
|
-
*/
|
|
66
|
-
removeItem: (key) => window.localStorage.removeItem(key),
|
|
67
|
-
/**
|
|
68
|
-
* Stores a value in localStorage with automatic serialization.
|
|
69
|
-
*
|
|
70
|
-
* @param {string} key - The key to store the value under
|
|
71
|
-
* @param {any} value - The value to store
|
|
72
|
-
*/
|
|
73
|
-
setItem: (key, value) => window.localStorage.setItem(key, encodeToStorageValue(value)),
|
|
74
|
-
});
|
|
75
|
-
function decodeStorageValue(data) {
|
|
76
|
-
if (!isCustomFormat(data))
|
|
77
|
-
return data;
|
|
78
|
-
const payload = data.substring(customValueHeaderLength);
|
|
79
|
-
const type = data.charAt(customValueHeader.length);
|
|
80
|
-
switch (type) {
|
|
81
|
-
case StorageValueEncodingType.Json:
|
|
82
|
-
try {
|
|
83
|
-
return superjson.deserialize(JSON.parse(payload));
|
|
84
|
-
}
|
|
85
|
-
catch {
|
|
86
|
-
throw new Error('[EnhancedLocalStorage] Failed to parse JSON payload');
|
|
87
|
-
}
|
|
88
|
-
case StorageValueEncodingType.String: return payload;
|
|
89
|
-
default:
|
|
90
|
-
throw new Error(`[EnhancedLocalStorage] Unknown encoding type: ${type}`);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
function encodeToStorageValue(value) {
|
|
94
|
-
if (typeof value === 'string')
|
|
95
|
-
return toCustomValue(StorageValueEncodingType.String, value);
|
|
96
|
-
return toCustomValue(StorageValueEncodingType.Json, JSON.stringify(superjson.serialize(value)));
|
|
97
|
-
}
|
|
98
|
-
function isCustomFormat(data) {
|
|
99
|
-
return (data.length >= customValueHeaderLength
|
|
100
|
-
&& data[0] === customValueHeader[0]
|
|
101
|
-
&& data[1] === customValueHeader[1]);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
exports.enhancedLocalStorage = enhancedLocalStorage;
|
|
105
|
-
//# sourceMappingURL=core.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"core.cjs","sources":["../../../../src/storage/enhanced/local/core.ts"],"sourcesContent":["import {\n deserialize,\n serialize,\n} from 'superjson';\n\nenum StorageValueEncodingType {\n Json = '0',\n String = '1',\n}\n\nconst customValueHeader = '';\nconst customValueHeaderLength = customValueHeader.length + 1;\nconst toCustomValue = (type: StorageValueEncodingType, payload: string) => `${customValueHeader}${type}${payload}`;\n\n/**\n * An enhanced localStorage wrapper that supports storing\n * complex data types (e.g. Dates, Maps, Sets) using SuperJSON encoding.\n *\n * This utility preserves type structure when saving and retrieving values.\n *\n * @example\n * ```typescript\n * import { enhancedLocalStorage } from '@kikiutils/shared/storage/enhanced/local';\n *\n * enhancedLocalStorage.setItem('user', { name: 'user', createdAt: new Date() });\n * const user = enhancedLocalStorage.getItem<{ name: string, createdAt: Date }>('user');\n * ```\n */\nexport const enhancedLocalStorage = Object.freeze({\n /**\n * Removes all items from localStorage.\n */\n clear: () => window.localStorage.clear(),\n /**\n * Retrieves a value by key and decodes it using SuperJSON or raw string.\n *\n * @template T - The expected type of the value\n *\n * @param {string} key - The key of the value to retrieve\n *\n * @returns {null | T} The decoded value or null if not found\n */\n getItem<T = unknown>(key: string) {\n const rawValue = window.localStorage.getItem(key);\n return rawValue ? decodeStorageValue(rawValue) as T : null;\n },\n /**\n * Checks whether a key exists in localStorage.\n *\n * @param {string} key - The key to check\n *\n * @returns {boolean} True if the key exists, false otherwise\n */\n hasItem: (key: string) => window.localStorage.getItem(key) !== null,\n /**\n * Returns the number of items stored in localStorage.\n *\n * @returns {number} The number of items stored in localStorage\n */\n get length() {\n return window.localStorage.length;\n },\n /**\n * Removes a specific key from localStorage.\n *\n * @param {string} key - The key to remove\n */\n removeItem: (key: string) => window.localStorage.removeItem(key),\n /**\n * Stores a value in localStorage with automatic serialization.\n *\n * @param {string} key - The key to store the value under\n * @param {any} value - The value to store\n */\n setItem: (key: string, value: any) => window.localStorage.setItem(key, encodeToStorageValue(value)),\n});\n\nfunction decodeStorageValue(data: string) {\n if (!isCustomFormat(data)) return data;\n const payload = data.substring(customValueHeaderLength);\n const type = data.charAt(customValueHeader.length);\n switch (type) {\n case StorageValueEncodingType.Json:\n try {\n return deserialize(JSON.parse(payload));\n } catch {\n throw new Error('[EnhancedLocalStorage] Failed to parse JSON payload');\n }\n case StorageValueEncodingType.String: return payload;\n default:\n throw new Error(`[EnhancedLocalStorage] Unknown encoding type: ${type}`);\n }\n}\n\nfunction encodeToStorageValue(value: any) {\n if (typeof value === 'string') return toCustomValue(StorageValueEncodingType.String, value);\n return toCustomValue(StorageValueEncodingType.Json, JSON.stringify(serialize(value)));\n}\n\nfunction isCustomFormat(data: string) {\n return (\n data.length >= customValueHeaderLength\n && data[0] === customValueHeader[0]\n && data[1] === customValueHeader[1]\n );\n}\n"],"names":["deserialize","serialize"],"mappings":";;;;AAKA,IAAK,wBAGJ;AAHD,CAAA,UAAK,wBAAwB,EAAA;A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ueEncodingType["Json"] = "0";
|
|
6
|
-
StorageValueEncodingType["String"] = "1";
|
|
7
|
-
})(StorageValueEncodingType || (StorageValueEncodingType = {}));
|
|
8
|
-
const customValueHeader = '';
|
|
9
|
-
const customValueHeaderLength = customValueHeader.length + 1;
|
|
10
|
-
const toCustomValue = (type, payload) => `${customValueHeader}${type}${payload}`;
|
|
11
|
-
/**
|
|
12
|
-
* An enhanced localStorage wrapper that supports storing
|
|
13
|
-
* complex data types (e.g. Dates, Maps, Sets) using SuperJSON encoding.
|
|
14
|
-
*
|
|
15
|
-
* This utility preserves type structure when saving and retrieving values.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```typescript
|
|
19
|
-
* import { enhancedLocalStorage } from '@kikiutils/shared/storage/enhanced/local';
|
|
20
|
-
*
|
|
21
|
-
* enhancedLocalStorage.setItem('user', { name: 'user', createdAt: new Date() });
|
|
22
|
-
* const user = enhancedLocalStorage.getItem<{ name: string, createdAt: Date }>('user');
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
const enhancedLocalStorage = Object.freeze({
|
|
26
|
-
/**
|
|
27
|
-
* Removes all items from localStorage.
|
|
28
|
-
*/
|
|
29
|
-
clear: () => window.localStorage.clear(),
|
|
30
|
-
/**
|
|
31
|
-
* Retrieves a value by key and decodes it using SuperJSON or raw string.
|
|
32
|
-
*
|
|
33
|
-
* @template T - The expected type of the value
|
|
34
|
-
*
|
|
35
|
-
* @param {string} key - The key of the value to retrieve
|
|
36
|
-
*
|
|
37
|
-
* @returns {null | T} The decoded value or null if not found
|
|
38
|
-
*/
|
|
39
|
-
getItem(key) {
|
|
40
|
-
const rawValue = window.localStorage.getItem(key);
|
|
41
|
-
return rawValue ? decodeStorageValue(rawValue) : null;
|
|
42
|
-
},
|
|
43
|
-
/**
|
|
44
|
-
* Checks whether a key exists in localStorage.
|
|
45
|
-
*
|
|
46
|
-
* @param {string} key - The key to check
|
|
47
|
-
*
|
|
48
|
-
* @returns {boolean} True if the key exists, false otherwise
|
|
49
|
-
*/
|
|
50
|
-
hasItem: (key) => window.localStorage.getItem(key) !== null,
|
|
51
|
-
/**
|
|
52
|
-
* Returns the number of items stored in localStorage.
|
|
53
|
-
*
|
|
54
|
-
* @returns {number} The number of items stored in localStorage
|
|
55
|
-
*/
|
|
56
|
-
get length() {
|
|
57
|
-
return window.localStorage.length;
|
|
58
|
-
},
|
|
59
|
-
/**
|
|
60
|
-
* Removes a specific key from localStorage.
|
|
61
|
-
*
|
|
62
|
-
* @param {string} key - The key to remove
|
|
63
|
-
*/
|
|
64
|
-
removeItem: (key) => window.localStorage.removeItem(key),
|
|
65
|
-
/**
|
|
66
|
-
* Stores a value in localStorage with automatic serialization.
|
|
67
|
-
*
|
|
68
|
-
* @param {string} key - The key to store the value under
|
|
69
|
-
* @param {any} value - The value to store
|
|
70
|
-
*/
|
|
71
|
-
setItem: (key, value) => window.localStorage.setItem(key, encodeToStorageValue(value)),
|
|
72
|
-
});
|
|
73
|
-
function decodeStorageValue(data) {
|
|
74
|
-
if (!isCustomFormat(data))
|
|
75
|
-
return data;
|
|
76
|
-
const payload = data.substring(customValueHeaderLength);
|
|
77
|
-
const type = data.charAt(customValueHeader.length);
|
|
78
|
-
switch (type) {
|
|
79
|
-
case StorageValueEncodingType.Json:
|
|
80
|
-
try {
|
|
81
|
-
return deserialize(JSON.parse(payload));
|
|
82
|
-
}
|
|
83
|
-
catch {
|
|
84
|
-
throw new Error('[EnhancedLocalStorage] Failed to parse JSON payload');
|
|
85
|
-
}
|
|
86
|
-
case StorageValueEncodingType.String: return payload;
|
|
87
|
-
default:
|
|
88
|
-
throw new Error(`[EnhancedLocalStorage] Unknown encoding type: ${type}`);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
function encodeToStorageValue(value) {
|
|
92
|
-
if (typeof value === 'string')
|
|
93
|
-
return toCustomValue(StorageValueEncodingType.String, value);
|
|
94
|
-
return toCustomValue(StorageValueEncodingType.Json, JSON.stringify(serialize(value)));
|
|
95
|
-
}
|
|
96
|
-
function isCustomFormat(data) {
|
|
97
|
-
return (data.length >= customValueHeaderLength
|
|
98
|
-
&& data[0] === customValueHeader[0]
|
|
99
|
-
&& data[1] === customValueHeader[1]);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export { enhancedLocalStorage };
|
|
103
|
-
//# sourceMappingURL=core.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"core.mjs","sources":["../../../../src/storage/enhanced/local/core.ts"],"sourcesContent":["import {\n deserialize,\n serialize,\n} from 'superjson';\n\nenum StorageValueEncodingType {\n Json = '0',\n String = '1',\n}\n\nconst customValueHeader = '';\nconst customValueHeaderLength = customValueHeader.length + 1;\nconst toCustomValue = (type: StorageValueEncodingType, payload: string) => `${customValueHeader}${type}${payload}`;\n\n/**\n * An enhanced localStorage wrapper that supports storing\n * complex data types (e.g. Dates, Maps, Sets) using SuperJSON encoding.\n *\n * This utility preserves type structure when saving and retrieving values.\n *\n * @example\n * ```typescript\n * import { enhancedLocalStorage } from '@kikiutils/shared/storage/enhanced/local';\n *\n * enhancedLocalStorage.setItem('user', { name: 'user', createdAt: new Date() });\n * const user = enhancedLocalStorage.getItem<{ name: string, createdAt: Date }>('user');\n * ```\n */\nexport const enhancedLocalStorage = Object.freeze({\n /**\n * Removes all items from localStorage.\n */\n clear: () => window.localStorage.clear(),\n /**\n * Retrieves a value by key and decodes it using SuperJSON or raw string.\n *\n * @template T - The expected type of the value\n *\n * @param {string} key - The key of the value to retrieve\n *\n * @returns {null | T} The decoded value or null if not found\n */\n getItem<T = unknown>(key: string) {\n const rawValue = window.localStorage.getItem(key);\n return rawValue ? decodeStorageValue(rawValue) as T : null;\n },\n /**\n * Checks whether a key exists in localStorage.\n *\n * @param {string} key - The key to check\n *\n * @returns {boolean} True if the key exists, false otherwise\n */\n hasItem: (key: string) => window.localStorage.getItem(key) !== null,\n /**\n * Returns the number of items stored in localStorage.\n *\n * @returns {number} The number of items stored in localStorage\n */\n get length() {\n return window.localStorage.length;\n },\n /**\n * Removes a specific key from localStorage.\n *\n * @param {string} key - The key to remove\n */\n removeItem: (key: string) => window.localStorage.removeItem(key),\n /**\n * Stores a value in localStorage with automatic serialization.\n *\n * @param {string} key - The key to store the value under\n * @param {any} value - The value to store\n */\n setItem: (key: string, value: any) => window.localStorage.setItem(key, encodeToStorageValue(value)),\n});\n\nfunction decodeStorageValue(data: string) {\n if (!isCustomFormat(data)) return data;\n const payload = data.substring(customValueHeaderLength);\n const type = data.charAt(customValueHeader.length);\n switch (type) {\n case StorageValueEncodingType.Json:\n try {\n return deserialize(JSON.parse(payload));\n } catch {\n throw new Error('[EnhancedLocalStorage] Failed to parse JSON payload');\n }\n case StorageValueEncodingType.String: return payload;\n default:\n throw new Error(`[EnhancedLocalStorage] Unknown encoding type: ${type}`);\n }\n}\n\nfunction encodeToStorageValue(value: any) {\n if (typeof value === 'string') return toCustomValue(StorageValueEncodingType.String, value);\n return toCustomValue(StorageValueEncodingType.Json, JSON.stringify(serialize(value)));\n}\n\nfunction isCustomFormat(data: string) {\n return (\n data.length >= customValueHeaderLength\n && data[0] === customValueHeader[0]\n && data[1] === customValueHeader[1]\n );\n}\n"],"names":[],"mappings":";;AAKA,IAAK,wBAGJ;AAHD,CAAA,UAAK,wBAAwB,EAAA;AACzB,IAAA,wBAAA,CAAA,MAAA,CAAA,GAAA,GAAU;AACV,IAAA,wBAAA,CAAA,QAAA,CAAA,GAAA,GAAY;AAChB,CAAC,EAHI,wBAAwB,KAAxB,wBAAwB,GAAA,EAAA,CAAA,CAAA;AAK7B,MAAM,iBAAiB,GAAG,IAAI;AAC9B,MAAM,uBAAuB,GAAG,iBAAiB,CAAC,MAAM,GAAG,CAAC;AAC5D,MAAM,aAAa,GAAG,CAAC,IAA8B,EAAE,OAAe,KAAK,CAAA,EAAG,iBAAiB,CAAA,EAAG,IAAI,CAAA,EAAG,OAAO,EAAE;AAElH;;;;;;;;;;;;;AAaG;AACI,MAA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AAM,IAAI,KAAK,CAAC,qDAAqD,CAAC;YAC1E;AACJ,QAAA,KAAK,wBAAwB,CAAC,MAAM,EAAE,OAAO,OAAO;AACpD,QAAA;AACI,YAAA,MAAM,IAAI,KAAK,CAAC,iDAAiD,IAAI,CAAA,CAAE,CAAC;;AAEpF;AAEA,SAAS,oBAAoB,CAAC,KAAU,EAAA;IACpC,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,aAAa,CAAC,wBAAwB,CAAC,MAAM,EAAE,KAAK,CAAC;AAC3F,IAAA,OAAO,aAAa,CAAC,wBAAwB,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;AACzF;AAEA,SAAS,cAAc,CAAC,IAAY,EAAA;AAChC,IAAA,QACI,IAAI,CAAC,MAAM,IAAI;AACZ,WAAA,IAAI,CAAC,CAAC,CAAC,KAAK,iBAAiB,CAAC,CAAC;WAC/B,IAAI,CAAC,CAAC,CAAC,KAAK,iBAAiB,CAAC,CAAC,CAAC;AAE3C;;;;"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const core = require('./core.cjs');
|
|
4
|
-
const keyedStore = require('./keyed-store.cjs');
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
exports.enhancedLocalStorage = core.enhancedLocalStorage;
|
|
9
|
-
exports.createKeyedEnhancedLocalStore = keyedStore.createKeyedEnhancedLocalStore;
|
|
10
|
-
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/enhanced/local/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,6BAA6B,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const core = require('./core.cjs');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Creates a reusable, type-safe storage interface based on `enhancedLocalStorage`
|
|
7
|
-
* and a dynamic key-generation function.
|
|
8
|
-
*
|
|
9
|
-
* This utility allows you to abstract away key construction logic and work directly
|
|
10
|
-
* with scoped key-value operations like `getItem`, `setItem`, and `removeItem`.
|
|
11
|
-
*
|
|
12
|
-
* @template D - The value type to store
|
|
13
|
-
*
|
|
14
|
-
* @returns A factory that accepts a key generator function and returns a scoped storage interface
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```typescript
|
|
18
|
-
* import { createKeyedEnhancedLocalStore } from '@kikiutils/shared/storage/enhanced/local';
|
|
19
|
-
*
|
|
20
|
-
* const userStore = createKeyedEnhancedLocalStore<User>()((id: number) => `user:${id}`);
|
|
21
|
-
* userStore.setItem({ id: 123, name: 'user' }, 123);
|
|
22
|
-
* const user = userStore.getItem(123);
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
function createKeyedEnhancedLocalStore() {
|
|
26
|
-
return (getKeyFunction) => Object.freeze({
|
|
27
|
-
getItem: (...args) => core.enhancedLocalStorage.getItem(getKeyFunction(...args)),
|
|
28
|
-
hasItem: (...args) => core.enhancedLocalStorage.hasItem(getKeyFunction(...args)),
|
|
29
|
-
removeItem: (...args) => core.enhancedLocalStorage.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) => core.enhancedLocalStorage.setItem(getKeyFunction(...args), value),
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
exports.createKeyedEnhancedLocalStore = createKeyedEnhancedLocalStore;
|
|
41
|
-
//# sourceMappingURL=keyed-store.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"keyed-store.cjs","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 * import { createKeyedEnhancedLocalStore } from '@kikiutils/shared/storage/enhanced/local';\n *\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":["enhancedLocalStorage"],"mappings":";;;;AAEA;;;;;;;;;;;;;;;;;;;AAmBG;SACa,6BAA6B,GAAA;IACzC,OAAO,CAAkB,cAAsC,KAAK,MAAM,CAAC,MAAM,CAAC;AAC9E,QAAA,OAAO,EAAE,CAAC,GAAG,IAAO,KAAKA,yBAAoB,CAAC,OAAO,CAAI,cAAc,CAAC,GAAG,IAAI,CAAC,CAAC;AACjF,QAAA,OAAO,EAAE,CAAC,GAAG,IAAO,KAAKA,yBAAoB,CAAC,OAAO,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC,CAAC;AAC9E,QAAA,UAAU,EAAE,CAAC,GAAG,IAAO,KAAKA,yBAAoB,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,KAAKA,yBAAoB,CAAC,OAAO,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC,EAAE,KAAK,CAAC;AAClG,KAAA,CAAC;AACN;;;;"}
|
|
@@ -1,39 +0,0 @@
|
|
|
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
|
-
* import { createKeyedEnhancedLocalStore } from '@kikiutils/shared/storage/enhanced/local';
|
|
17
|
-
*
|
|
18
|
-
* const userStore = createKeyedEnhancedLocalStore<User>()((id: number) => `user:${id}`);
|
|
19
|
-
* userStore.setItem({ id: 123, name: 'user' }, 123);
|
|
20
|
-
* const user = userStore.getItem(123);
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
function createKeyedEnhancedLocalStore() {
|
|
24
|
-
return (getKeyFunction) => Object.freeze({
|
|
25
|
-
getItem: (...args) => enhancedLocalStorage.getItem(getKeyFunction(...args)),
|
|
26
|
-
hasItem: (...args) => enhancedLocalStorage.hasItem(getKeyFunction(...args)),
|
|
27
|
-
removeItem: (...args) => enhancedLocalStorage.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) => enhancedLocalStorage.setItem(getKeyFunction(...args), value),
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export { createKeyedEnhancedLocalStore };
|
|
39
|
-
//# sourceMappingURL=keyed-store.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
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 * import { createKeyedEnhancedLocalStore } from '@kikiutils/shared/storage/enhanced/local';\n *\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;;;;;;;;;;;;;;;;;;;AAmBG;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;;;;"}
|
|
@@ -1,144 +0,0 @@
|
|
|
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
|
-
* import { createEnhancedRedisStorage } from '@kikiutils/shared/storage/enhanced/redis';
|
|
28
|
-
*
|
|
29
|
-
* const redisStorage = createEnhancedRedisStorage('redis://localhost');
|
|
30
|
-
* await redisStorage.setItem('user:1', { name: 'user' });
|
|
31
|
-
* const user = await redisStorage.getItem<{ name: string }>('user:1');
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
function createEnhancedRedisStorage(ioRedisInstanceOrUrl) {
|
|
35
|
-
const instance = ioRedisInstanceOrUrl instanceof ioredis.Redis ? ioRedisInstanceOrUrl : new ioredis.Redis(ioRedisInstanceOrUrl);
|
|
36
|
-
return Object.freeze({
|
|
37
|
-
/**
|
|
38
|
-
* Retrieves a value from Redis and decodes it.
|
|
39
|
-
*
|
|
40
|
-
* @template T - The expected return type
|
|
41
|
-
*
|
|
42
|
-
* @param {string} key - The Redis key
|
|
43
|
-
*
|
|
44
|
-
* @returns {Promise<null | T>} The decoded value or null if not found
|
|
45
|
-
*/
|
|
46
|
-
async getItem(key) {
|
|
47
|
-
const rawValue = await instance.getBuffer(key);
|
|
48
|
-
return rawValue ? decodeStorageValue(rawValue) : null;
|
|
49
|
-
},
|
|
50
|
-
/**
|
|
51
|
-
* Gets the remaining TTL (in seconds) for a given key.
|
|
52
|
-
*
|
|
53
|
-
* @param {string} key - The Redis key
|
|
54
|
-
*
|
|
55
|
-
* @returns {Promise<number>} The number of seconds until the key expires, or -1 if no expiration is set
|
|
56
|
-
*/
|
|
57
|
-
getItemTtl: (key) => instance.ttl(key),
|
|
58
|
-
/**
|
|
59
|
-
* Checks whether a key exists in Redis.
|
|
60
|
-
*
|
|
61
|
-
* @param {string} key - The Redis key
|
|
62
|
-
*
|
|
63
|
-
* @returns {Promise<boolean>} True if the key exists, false otherwise
|
|
64
|
-
*/
|
|
65
|
-
hasItem: async (key) => await instance.exists(key) === 1,
|
|
66
|
-
/**
|
|
67
|
-
* The underlying Redis instance, exposed for advanced operations.
|
|
68
|
-
* Use with caution; most use cases should rely on the wrapper methods.
|
|
69
|
-
*
|
|
70
|
-
* @returns {Redis} The underlying Redis instance
|
|
71
|
-
*/
|
|
72
|
-
get instance() {
|
|
73
|
-
return instance;
|
|
74
|
-
},
|
|
75
|
-
/**
|
|
76
|
-
* Removes a key from Redis.
|
|
77
|
-
*
|
|
78
|
-
* @param {string} key - The Redis key to delete
|
|
79
|
-
*
|
|
80
|
-
* @returns {Promise<boolean>} A Promise that resolves to `true` if the key was removed,
|
|
81
|
-
* or `false` if it did not exist.
|
|
82
|
-
*/
|
|
83
|
-
removeItem: async (key) => await instance.del(key) === 1,
|
|
84
|
-
/**
|
|
85
|
-
* Stores a value in Redis without expiration.
|
|
86
|
-
*
|
|
87
|
-
* @param {string} key - The Redis key
|
|
88
|
-
* @param {any} value - The value to store. Will be serialized
|
|
89
|
-
*/
|
|
90
|
-
setItem: (key, value) => instance.set(key, encodeToStorageValue(value)),
|
|
91
|
-
/**
|
|
92
|
-
* Stores a value in Redis with a time-to-live (TTL).
|
|
93
|
-
*
|
|
94
|
-
* @param {string} key - The Redis key
|
|
95
|
-
* @param {number} seconds - Expiration time in seconds
|
|
96
|
-
* @param {any} value - The value to store. Will be serialized
|
|
97
|
-
*/
|
|
98
|
-
setItemWithTtl(key, seconds, value) {
|
|
99
|
-
return instance.setex(key, seconds, encodeToStorageValue(value));
|
|
100
|
-
},
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
function decodeStorageValue(data) {
|
|
104
|
-
if (!isCustomFormat(data))
|
|
105
|
-
return data;
|
|
106
|
-
const payload = data.subarray(customValueHeaderLength);
|
|
107
|
-
const type = data[customValueHeader.byteLength];
|
|
108
|
-
switch (type) {
|
|
109
|
-
case StorageValueEncodingType.Buffer: return payload;
|
|
110
|
-
case StorageValueEncodingType.Json:
|
|
111
|
-
try {
|
|
112
|
-
return superjson.deserialize(JSON.parse(payload.toString()));
|
|
113
|
-
}
|
|
114
|
-
catch {
|
|
115
|
-
throw new Error('[RedisStorage] Failed to parse JSON payload');
|
|
116
|
-
}
|
|
117
|
-
case StorageValueEncodingType.String: return payload.toString();
|
|
118
|
-
default:
|
|
119
|
-
throw new Error(`[RedisStorage] Unknown encoding type: ${type}`);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
function encodeToStorageValue(value) {
|
|
123
|
-
if (node_buffer.Buffer.isBuffer(value))
|
|
124
|
-
return toCustomValue(StorageValueEncodingType.Buffer, value);
|
|
125
|
-
if (typeof value === 'string')
|
|
126
|
-
return toCustomValue(StorageValueEncodingType.String, node_buffer.Buffer.from(value));
|
|
127
|
-
return toCustomValue(StorageValueEncodingType.Json, node_buffer.Buffer.from(JSON.stringify(superjson.serialize(value))));
|
|
128
|
-
}
|
|
129
|
-
function isCustomFormat(buffer) {
|
|
130
|
-
return (buffer.length >= customValueHeaderLength
|
|
131
|
-
&& buffer[0] === customValueHeader[0]
|
|
132
|
-
&& buffer[1] === customValueHeader[1]
|
|
133
|
-
&& buffer[2] === customValueHeader[2]);
|
|
134
|
-
}
|
|
135
|
-
function toCustomValue(type, payload) {
|
|
136
|
-
return node_buffer.Buffer.concat([
|
|
137
|
-
customValueHeader,
|
|
138
|
-
node_buffer.Buffer.of(type),
|
|
139
|
-
payload,
|
|
140
|
-
]);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
exports.createEnhancedRedisStorage = createEnhancedRedisStorage;
|
|
144
|
-
//# sourceMappingURL=core.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
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 * import { createEnhancedRedisStorage } from '@kikiutils/shared/storage/enhanced/redis';\n *\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,GAAA,EAAA,CAAA,CAAA;AAM7B,MAAM,iBAAiB,GAAGA,kBAAM,CAAC,EAAE,CAC/B,IAAI,EACJ,IAAI,EACJ,IAAI,CACP;AAED,MAAM,uBAAuB,GAAG,iBAAiB,CAAC,UAAU,GAAG,CAAC;AAEhE;;;;;;;;;;;;;;;;;;AAkBG;AACG,SAAU,0BAA0B,CAAC,oBAAoC,EAAA;AAC3E,IAAA,MAAM,QAAQ,GAAG,oBAAoB,YAAYC,aAAK,GAAG,oBAAoB,GAAG,IAAIA,aAAK,CAAC,oBAAoB,CAAC;IAC/G,OAAO,MAAM,CAAC,MAAM,CAAC;AACjB;;;;;;;;AAQG;QACH,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