@kikiutils/shared 13.6.1 → 14.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/storages/lru/keyed-store.d.ts +22 -0
- package/dist/storages/lru/keyed-store.d.ts.map +1 -0
- package/dist/storages/lru/keyed-store.js +17 -0
- package/dist/storages/lru/keyed-store.js.map +1 -0
- package/dist/storages/redis/keyed-store.d.ts +16 -0
- package/dist/storages/redis/keyed-store.d.ts.map +1 -0
- package/dist/storages/redis/keyed-store.js +18 -0
- package/dist/storages/redis/keyed-store.js.map +1 -0
- package/dist/storages/redis/msgpack.d.ts +7 -0
- package/dist/storages/redis/msgpack.d.ts.map +1 -0
- package/dist/storages/redis/msgpack.js +23 -0
- package/dist/storages/redis/msgpack.js.map +1 -0
- package/dist/storages/redis/types.d.ts +22 -0
- package/dist/storages/redis/types.d.ts.map +1 -0
- package/dist/storages/redis/types.js +1 -0
- package/package.json +8 -28
- package/src/storages/lru/keyed-store.ts +23 -0
- package/src/storages/redis/keyed-store.ts +17 -0
- package/src/storages/redis/msgpack.ts +30 -0
- package/src/storages/redis/types.ts +19 -0
- package/dist/storage/enhanced/local/core.d.ts +0 -61
- package/dist/storage/enhanced/local/core.d.ts.map +0 -1
- package/dist/storage/enhanced/local/core.js +0 -63
- package/dist/storage/enhanced/local/core.js.map +0 -1
- package/dist/storage/enhanced/local/index.d.ts +0 -3
- package/dist/storage/enhanced/local/index.js +0 -4
- package/dist/storage/enhanced/local/keyed-store.d.ts +0 -36
- package/dist/storage/enhanced/local/keyed-store.d.ts.map +0 -1
- package/dist/storage/enhanced/local/keyed-store.js +0 -36
- package/dist/storage/enhanced/local/keyed-store.js.map +0 -1
- package/dist/storage/enhanced/redis/core.d.ts +0 -85
- package/dist/storage/enhanced/redis/core.d.ts.map +0 -1
- package/dist/storage/enhanced/redis/core.js +0 -85
- package/dist/storage/enhanced/redis/core.js.map +0 -1
- package/dist/storage/enhanced/redis/index.d.ts +0 -3
- package/dist/storage/enhanced/redis/index.js +0 -4
- package/dist/storage/enhanced/redis/keyed-store.d.ts +0 -44
- package/dist/storage/enhanced/redis/keyed-store.d.ts.map +0 -1
- package/dist/storage/enhanced/redis/keyed-store.js +0 -41
- package/dist/storage/enhanced/redis/keyed-store.js.map +0 -1
- package/dist/storage/lru/keyed-store.d.ts +0 -44
- package/dist/storage/lru/keyed-store.d.ts.map +0 -1
- package/dist/storage/lru/keyed-store.js +0 -40
- package/dist/storage/lru/keyed-store.js.map +0 -1
- package/src/storage/enhanced/local/core.ts +0 -106
- package/src/storage/enhanced/local/index.ts +0 -2
- package/src/storage/enhanced/local/keyed-store.ts +0 -36
- package/src/storage/enhanced/redis/core.ts +0 -151
- package/src/storage/enhanced/redis/index.ts +0 -2
- package/src/storage/enhanced/redis/keyed-store.ts +0 -43
- package/src/storage/lru/keyed-store.ts +0 -46
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { LRUCache } from "lru-cache";
|
|
2
|
+
|
|
3
|
+
//#region src/storages/lru/keyed-store.d.ts
|
|
4
|
+
declare function createLruKeyedStore<D = unknown>(lruInstance: LRUCache<any, any, any>): <P extends any[]>(keyFn: (...args: P) => string) => Readonly<{
|
|
5
|
+
/**
|
|
6
|
+
* Return a value from the cache. Will update the recency of the cache entry found.
|
|
7
|
+
*
|
|
8
|
+
* If the key is not found, returns `null`.
|
|
9
|
+
*/
|
|
10
|
+
getItem(...args: P): NonNullable<D> | null;
|
|
11
|
+
getItemTtl: (...args: P) => number;
|
|
12
|
+
hasItem: (...args: P) => boolean;
|
|
13
|
+
removeItem: (...args: P) => boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Resolves the full cache key from the given arguments.
|
|
16
|
+
*/
|
|
17
|
+
resolveKey: (...args: P) => string;
|
|
18
|
+
setItem: (value: D, ...args: P) => LRUCache<any, any, any>;
|
|
19
|
+
}>;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { createLruKeyedStore };
|
|
22
|
+
//# sourceMappingURL=keyed-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyed-store.d.ts","names":[],"sources":["../../../src/storages/lru/keyed-store.ts"],"sourcesContent":[],"mappings":";;;iBAEgB,8CAA8C,6DAChB,iBAAY;;AAD1D;;;;EAO0B,OAAA,CAAA,GAAA,IAAA,EAAD,CAAC,CAAA,EAAA,WAAA,CAAA,CAAA,CAAA,GAAA,IAAA;EAAA,UAAA,EAAA,CAAA,GAAA,IAAA,EAII,CAJJ,EAAA,GAAA,MAAA;EAII,OAAA,EAAA,CAAA,GAAA,IAAA,EACH,CADG,EAAA,GAAA,OAAA;EACH,UAAA,EAAA,CAAA,GAAA,IAAA,EACG,CADH,EAAA,GAAA,OAAA;EACG;;;EAKO,UAAA,EAAA,CAAA,GAAA,IAAA,EADP,CACO,EAAA,GAAA,MAAA;EAAC,OAAA,EAAA,CAAA,KAAA,EAAb,CAAa,EAAA,GAAA,IAAA,EAAD,CAAC,EAAA,GAAA,QAAA,CAAA,GAAA,EAAA,GAAA,EAAA,GAAA,CAAA;CAjBoB,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/storages/lru/keyed-store.ts
|
|
2
|
+
function createLruKeyedStore(lruInstance) {
|
|
3
|
+
return (keyFn) => Object.freeze({
|
|
4
|
+
getItem(...args) {
|
|
5
|
+
return lruInstance.get(keyFn(...args)) ?? null;
|
|
6
|
+
},
|
|
7
|
+
getItemTtl: (...args) => lruInstance.getRemainingTTL(keyFn(...args)),
|
|
8
|
+
hasItem: (...args) => lruInstance.has(keyFn(...args)),
|
|
9
|
+
removeItem: (...args) => lruInstance.delete(keyFn(...args)),
|
|
10
|
+
resolveKey: (...args) => keyFn(...args),
|
|
11
|
+
setItem: (value, ...args) => lruInstance.set(keyFn(...args), value)
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
export { createLruKeyedStore };
|
|
17
|
+
//# sourceMappingURL=keyed-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyed-store.js","names":[],"sources":["../../../src/storages/lru/keyed-store.ts"],"sourcesContent":["import type { LRUCache } from 'lru-cache';\n\nexport function createLruKeyedStore<D = unknown>(lruInstance: LRUCache<any, any, any>) {\n return <P extends any[]>(keyFn: (...args: P) => string) => Object.freeze({\n /**\n * Return a value from the cache. Will update the recency of the cache entry found.\n *\n * If the key is not found, returns `null`.\n */\n getItem(...args: P) {\n const rawValue = lruInstance.get(keyFn(...args));\n return rawValue as D ?? null;\n },\n getItemTtl: (...args: P) => lruInstance.getRemainingTTL(keyFn(...args)),\n hasItem: (...args: P) => lruInstance.has(keyFn(...args)),\n removeItem: (...args: P) => lruInstance.delete(keyFn(...args)),\n /**\n * Resolves the full cache key from the given arguments.\n */\n resolveKey: (...args: P) => keyFn(...args),\n setItem: (value: D, ...args: P) => lruInstance.set(keyFn(...args), value),\n });\n}\n"],"mappings":";AAEA,SAAgB,oBAAiC,aAAsC;AACnF,SAAyB,UAAkC,OAAO,OAAO;EAMrE,QAAQ,GAAG,MAAS;AAEhB,UADiB,YAAY,IAAI,MAAM,GAAG,KAAK,CAAC,IACxB;;EAE5B,aAAa,GAAG,SAAY,YAAY,gBAAgB,MAAM,GAAG,KAAK,CAAC;EACvE,UAAU,GAAG,SAAY,YAAY,IAAI,MAAM,GAAG,KAAK,CAAC;EACxD,aAAa,GAAG,SAAY,YAAY,OAAO,MAAM,GAAG,KAAK,CAAC;EAI9D,aAAa,GAAG,SAAY,MAAM,GAAG,KAAK;EAC1C,UAAU,OAAU,GAAG,SAAY,YAAY,IAAI,MAAM,GAAG,KAAK,EAAE,MAAM;EAC5E,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { MaybeReadonly, Nullable } from "../../types/index.js";
|
|
2
|
+
import { RedisLikeStorage } from "./types.js";
|
|
3
|
+
|
|
4
|
+
//#region src/storages/redis/keyed-store.d.ts
|
|
5
|
+
declare function createRedisKeyedStore<D = unknown>(storage: MaybeReadonly<RedisLikeStorage>): <P extends any[]>(keyFn: (...args: P) => string) => Readonly<{
|
|
6
|
+
getItem: (...args: P) => Promise<Nullable<D>>;
|
|
7
|
+
getItemTtl: (...args: P) => Promise<number>;
|
|
8
|
+
hasItem: (...args: P) => Promise<boolean>;
|
|
9
|
+
removeItem: (...args: P) => Promise<boolean>;
|
|
10
|
+
resolveKey: (...args: P) => string;
|
|
11
|
+
setItem: (value: D, ...args: P) => Promise<boolean>;
|
|
12
|
+
setItemWithTtl(ttlSeconds: number, value: D, ...args: P): Promise<boolean>;
|
|
13
|
+
}>;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { createRedisKeyedStore };
|
|
16
|
+
//# sourceMappingURL=keyed-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyed-store.d.ts","names":[],"sources":["../../../src/storages/redis/keyed-store.ts"],"sourcesContent":[],"mappings":";;;;iBAIgB,4CAA4C,cAAc,uDAC5B,iBAAY;qBAC/B,MAAC,QAAA,SAAA;EAFZ,UAAA,EAAA,CAAA,GAAA,IAAA,EAGc,CAHd,EAAqB,GAGN,OAHM,CAAA,MAAA,CAAA;EAAqC,OAAA,EAAA,CAAA,GAAA,IAAA,EAI/C,CAJ+C,EAAA,GAI9C,OAJ8C,CAAA,OAAA,CAAA;EAAd,UAAA,EAAA,CAAA,GAAA,IAAA,EAK9B,CAL8B,EAAA,GAK7B,OAL6B,CAAA,OAAA,CAAA;EACd,UAAA,EAAA,CAAA,GAAA,IAAA,EAKhB,CALgB,EAAA,GAAA,MAAA;EACnB,OAAA,EAAA,CAAA,KAAA,EAKF,CALE,EAAA,GAAA,IAAA,EAKU,CALV,EAAA,GAKW,OALX,CAAA,OAAA,CAAA;EAAC,cAAA,CAAA,UAAA,EAAA,MAAA,EAAA,KAAA,EAMsB,CANtB,EAAA,GAAA,IAAA,EAMkC,CANlC,CAAA,EAMmC,OANnC,CAAA,OAAA,CAAA;CAAA,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/storages/redis/keyed-store.ts
|
|
2
|
+
function createRedisKeyedStore(storage) {
|
|
3
|
+
return (keyFn) => Object.freeze({
|
|
4
|
+
getItem: (...args) => storage.getItem(keyFn(...args)),
|
|
5
|
+
getItemTtl: (...args) => storage.getItemTtl(keyFn(...args)),
|
|
6
|
+
hasItem: (...args) => storage.hasItem(keyFn(...args)),
|
|
7
|
+
removeItem: (...args) => storage.removeItem(keyFn(...args)),
|
|
8
|
+
resolveKey: (...args) => keyFn(...args),
|
|
9
|
+
setItem: (value, ...args) => storage.setItem(keyFn(...args), value),
|
|
10
|
+
setItemWithTtl(ttlSeconds, value, ...args) {
|
|
11
|
+
return storage.setItemWithTtl(keyFn(...args), ttlSeconds, value);
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
export { createRedisKeyedStore };
|
|
18
|
+
//# sourceMappingURL=keyed-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyed-store.js","names":[],"sources":["../../../src/storages/redis/keyed-store.ts"],"sourcesContent":["import type { MaybeReadonly } from '../../types';\n\nimport type { RedisLikeStorage } from './types';\n\nexport function createRedisKeyedStore<D = unknown>(storage: MaybeReadonly<RedisLikeStorage>) {\n return <P extends any[]>(keyFn: (...args: P) => string) => Object.freeze({\n getItem: (...args: P) => storage.getItem<D>(keyFn(...args)),\n getItemTtl: (...args: P) => storage.getItemTtl(keyFn(...args)),\n hasItem: (...args: P) => storage.hasItem(keyFn(...args)),\n removeItem: (...args: P) => storage.removeItem(keyFn(...args)),\n resolveKey: (...args: P) => keyFn(...args),\n setItem: (value: D, ...args: P) => storage.setItem(keyFn(...args), value),\n setItemWithTtl(ttlSeconds: number, value: D, ...args: P) {\n return storage.setItemWithTtl(keyFn(...args), ttlSeconds, value);\n },\n });\n}\n"],"mappings":";AAIA,SAAgB,sBAAmC,SAA0C;AACzF,SAAyB,UAAkC,OAAO,OAAO;EACrE,UAAU,GAAG,SAAY,QAAQ,QAAW,MAAM,GAAG,KAAK,CAAC;EAC3D,aAAa,GAAG,SAAY,QAAQ,WAAW,MAAM,GAAG,KAAK,CAAC;EAC9D,UAAU,GAAG,SAAY,QAAQ,QAAQ,MAAM,GAAG,KAAK,CAAC;EACxD,aAAa,GAAG,SAAY,QAAQ,WAAW,MAAM,GAAG,KAAK,CAAC;EAC9D,aAAa,GAAG,SAAY,MAAM,GAAG,KAAK;EAC1C,UAAU,OAAU,GAAG,SAAY,QAAQ,QAAQ,MAAM,GAAG,KAAK,EAAE,MAAM;EACzE,eAAe,YAAoB,OAAU,GAAG,MAAS;AACrD,UAAO,QAAQ,eAAe,MAAM,GAAG,KAAK,EAAE,YAAY,MAAM;;EAEvE,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { RedisLikeAdapter, RedisLikeStorage } from "./types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/storages/redis/msgpack.d.ts
|
|
4
|
+
declare function createRedisMsgpackStorage(adapter: RedisLikeAdapter): Readonly<RedisLikeStorage>;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { createRedisMsgpackStorage };
|
|
7
|
+
//# sourceMappingURL=msgpack.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"msgpack.d.ts","names":[],"sources":["../../../src/storages/redis/msgpack.ts"],"sourcesContent":[],"mappings":";;;iBAegB,yBAAA,UAAmC,mBAAmB,SAAS"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { decode, encode, isNativeAccelerationEnabled } from "msgpackr";
|
|
2
|
+
|
|
3
|
+
//#region src/storages/redis/msgpack.ts
|
|
4
|
+
if (!isNativeAccelerationEnabled) console.warn("Native acceleration not enabled for msgpackr, verify that install finished properly");
|
|
5
|
+
function createRedisMsgpackStorage(adapter) {
|
|
6
|
+
return Object.freeze({
|
|
7
|
+
async getItem(key) {
|
|
8
|
+
const rawValue = await adapter.getBuffer(key);
|
|
9
|
+
return rawValue ? decode(rawValue) : null;
|
|
10
|
+
},
|
|
11
|
+
getItemTtl: (key) => adapter.ttl(key),
|
|
12
|
+
hasItem: (key) => adapter.has(key),
|
|
13
|
+
removeItem: async (key) => await adapter.delete(key) === 1,
|
|
14
|
+
setItem: async (key, value) => await adapter.setBuffer(key, encode(value)) === "OK",
|
|
15
|
+
async setItemWithTtl(key, ttlSeconds, value) {
|
|
16
|
+
return await adapter.setBufferEx(key, ttlSeconds, encode(value)) === "OK";
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
export { createRedisMsgpackStorage };
|
|
23
|
+
//# sourceMappingURL=msgpack.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"msgpack.js","names":[],"sources":["../../../src/storages/redis/msgpack.ts"],"sourcesContent":["import {\n decode,\n encode,\n isNativeAccelerationEnabled,\n} from 'msgpackr';\n\nimport type {\n RedisLikeAdapter,\n RedisLikeStorage,\n} from './types';\n\nif (!isNativeAccelerationEnabled) {\n console.warn('Native acceleration not enabled for msgpackr, verify that install finished properly');\n}\n\nexport function createRedisMsgpackStorage(adapter: RedisLikeAdapter): Readonly<RedisLikeStorage> {\n return Object.freeze({\n async getItem<T = unknown>(key: string) {\n const rawValue = await adapter.getBuffer(key);\n return rawValue ? decode(rawValue) as T : null;\n },\n getItemTtl: (key: string) => adapter.ttl(key),\n hasItem: (key: string) => adapter.has(key),\n removeItem: async (key: string) => await adapter.delete(key) === 1,\n setItem: async (key: string, value: any) => await adapter.setBuffer(key, encode(value)) === 'OK',\n async setItemWithTtl(key: string, ttlSeconds: number, value: any) {\n return await adapter.setBufferEx(key, ttlSeconds, encode(value)) === 'OK';\n },\n });\n}\n"],"mappings":";;;AAWA,IAAI,CAAC,4BACD,SAAQ,KAAK,sFAAsF;AAGvG,SAAgB,0BAA0B,SAAuD;AAC7F,QAAO,OAAO,OAAO;EACjB,MAAM,QAAqB,KAAa;GACpC,MAAM,WAAW,MAAM,QAAQ,UAAU,IAAI;AAC7C,UAAO,WAAW,OAAO,SAAS,GAAQ;;EAE9C,aAAa,QAAgB,QAAQ,IAAI,IAAI;EAC7C,UAAU,QAAgB,QAAQ,IAAI,IAAI;EAC1C,YAAY,OAAO,QAAgB,MAAM,QAAQ,OAAO,IAAI,KAAK;EACjE,SAAS,OAAO,KAAa,UAAe,MAAM,QAAQ,UAAU,KAAK,OAAO,MAAM,CAAC,KAAK;EAC5F,MAAM,eAAe,KAAa,YAAoB,OAAY;AAC9D,UAAO,MAAM,QAAQ,YAAY,KAAK,YAAY,OAAO,MAAM,CAAC,KAAK;;EAE5E,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Nullable } from "../../types/index.js";
|
|
2
|
+
|
|
3
|
+
//#region src/storages/redis/types.d.ts
|
|
4
|
+
interface RedisLikeAdapter {
|
|
5
|
+
delete: (key: string) => Promise<number>;
|
|
6
|
+
getBuffer: (key: string) => Promise<Nullable<Uint8Array>>;
|
|
7
|
+
has: (key: string) => Promise<boolean>;
|
|
8
|
+
setBuffer: (key: string, value: Uint8Array) => Promise<'OK' | void>;
|
|
9
|
+
setBufferEx: (key: string, ttlSeconds: number, value: Uint8Array) => Promise<'OK' | void>;
|
|
10
|
+
ttl: (key: string) => Promise<number>;
|
|
11
|
+
}
|
|
12
|
+
interface RedisLikeStorage {
|
|
13
|
+
getItem: <T = unknown>(key: string) => Promise<Nullable<T>>;
|
|
14
|
+
getItemTtl: (key: string) => Promise<number>;
|
|
15
|
+
hasItem: (key: string) => Promise<boolean>;
|
|
16
|
+
removeItem: (key: string) => Promise<boolean>;
|
|
17
|
+
setItem: (key: string, value: any) => Promise<boolean>;
|
|
18
|
+
setItemWithTtl: (key: string, ttlSeconds: number, value: any) => Promise<boolean>;
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { RedisLikeAdapter, RedisLikeStorage };
|
|
22
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../../../src/storages/redis/types.ts"],"sourcesContent":[],"mappings":";;;UAEiB,gBAAA;2BACY;EADZ,SAAA,EAAA,CAAA,GAAA,EAAA,MAAgB,EAAA,GAED,OAFC,CAEO,QAFP,CAEgB,UAFhB,CAAA,CAAA;EACJ,GAAA,EAAA,CAAA,GAAA,EAAA,MAAA,EAAA,GAEH,OAFG,CAAA,OAAA,CAAA;EACoB,SAAA,EAAA,CAAA,GAAA,EAAA,MAAA,EAAA,KAAA,EAEb,UAFa,EAAA,GAEE,OAFF,CAAA,IAAA,GAAA,IAAA,CAAA;EAAT,WAAA,EAAA,CAAA,GAAA,EAAA,MAAA,EAAA,UAAA,EAAA,MAAA,EAAA,KAAA,EAGkB,UAHlB,EAAA,GAGiC,OAHjC,CAAA,IAAA,GAAA,IAAA,CAAA;EAAR,GAAA,EAAA,CAAA,GAAA,EAAA,MAAA,EAAA,GAIN,OAJM,CAAA,MAAA,CAAA;;AAEI,UAKnB,gBAAA,CALmB;EAAe,OAAA,EAAA,CAAA,IAAA,OAAA,CAAA,CAAA,GAAA,EAAA,MAAA,EAAA,GAMR,OANQ,CAMA,QANA,CAMS,CANT,CAAA,CAAA;EACO,UAAA,EAAA,CAAA,GAAA,EAAA,MAAA,EAAA,GAMzB,OANyB,CAAA,MAAA,CAAA;EAAe,OAAA,EAAA,CAAA,GAAA,EAAA,MAAA,EAAA,GAO3C,OAP2C,CAAA,OAAA,CAAA;EAC/C,UAAA,EAAA,CAAA,GAAA,EAAA,MAAA,EAAA,GAOO,OAPP,CAAA,OAAA,CAAA;EAAO,OAAA,EAAA,CAAA,GAAA,EAAA,MAAA,EAAA,KAAA,EAAA,GAAA,EAAA,GAQS,OART,CAAA,OAAA,CAAA;EAGhB,cAAA,EAAA,CAAA,GAAgB,EAAA,MAAA,EAAA,UAAA,EAAA,MAAA,EAAA,KAAA,EAAA,GAAA,EAAA,GAMoC,OANpC,CAAA,OAAA,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kikiutils/shared",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "14.0.0",
|
|
5
5
|
"description": "A lightweight and modular utility library for modern JavaScript and TypeScript — includes secure hashing, flexible logging, datetime tools, Vue/web helpers, storage abstraction, and more.",
|
|
6
6
|
"author": "kiki-kanri",
|
|
7
7
|
"license": "MIT",
|
|
@@ -35,26 +35,6 @@
|
|
|
35
35
|
"exports": {
|
|
36
36
|
"./*": "./dist/*.js",
|
|
37
37
|
"./package.json": "./package.json",
|
|
38
|
-
"./storage/enhanced/local": {
|
|
39
|
-
"types": "./dist/storage/enhanced/local/index.d.ts",
|
|
40
|
-
"import": "./dist/storage/enhanced/local/index.js",
|
|
41
|
-
"require": null
|
|
42
|
-
},
|
|
43
|
-
"./storage/enhanced/local/index": {
|
|
44
|
-
"types": null,
|
|
45
|
-
"import": null,
|
|
46
|
-
"require": null
|
|
47
|
-
},
|
|
48
|
-
"./storage/enhanced/redis": {
|
|
49
|
-
"types": "./dist/storage/enhanced/redis/index.d.ts",
|
|
50
|
-
"import": "./dist/storage/enhanced/redis/index.js",
|
|
51
|
-
"require": null
|
|
52
|
-
},
|
|
53
|
-
"./storage/enhanced/redis/index": {
|
|
54
|
-
"types": null,
|
|
55
|
-
"import": null,
|
|
56
|
-
"require": null
|
|
57
|
-
},
|
|
58
38
|
"./types": {
|
|
59
39
|
"types": "./dist/types/index.d.ts",
|
|
60
40
|
"import": null,
|
|
@@ -99,9 +79,9 @@
|
|
|
99
79
|
"decimal.js": "^10.6.0",
|
|
100
80
|
"element-plus": "^2.11.3",
|
|
101
81
|
"fs-extra": "^11.3.2",
|
|
102
|
-
"
|
|
103
|
-
"lru-cache": "^11.2.1",
|
|
82
|
+
"lru-cache": "^11.2.4",
|
|
104
83
|
"millify": "^6.1.0",
|
|
84
|
+
"msgpackr": "^1.11.5",
|
|
105
85
|
"node-ssh": "^13.2.1",
|
|
106
86
|
"pino": "^10.0.0",
|
|
107
87
|
"pino-pretty": "^13.1.1",
|
|
@@ -146,15 +126,15 @@
|
|
|
146
126
|
"fs-extra": {
|
|
147
127
|
"optional": true
|
|
148
128
|
},
|
|
149
|
-
"ioredis": {
|
|
150
|
-
"optional": true
|
|
151
|
-
},
|
|
152
129
|
"lru-cache": {
|
|
153
130
|
"optional": true
|
|
154
131
|
},
|
|
155
132
|
"millify": {
|
|
156
133
|
"optional": true
|
|
157
134
|
},
|
|
135
|
+
"msgpackr": {
|
|
136
|
+
"optional": true
|
|
137
|
+
},
|
|
158
138
|
"node-ssh": {
|
|
159
139
|
"optional": true
|
|
160
140
|
},
|
|
@@ -194,15 +174,14 @@
|
|
|
194
174
|
"depcheck": "^1.4.7",
|
|
195
175
|
"element-plus": "^2.11.9",
|
|
196
176
|
"fs-extra": "^11.3.2",
|
|
197
|
-
"ioredis": "^5.8.2",
|
|
198
177
|
"jsdom": "^27.2.0",
|
|
199
178
|
"lru-cache": "^11.2.4",
|
|
200
179
|
"millify": "^6.1.0",
|
|
180
|
+
"msgpackr": "^1.11.5",
|
|
201
181
|
"node-ssh": "^13.2.1",
|
|
202
182
|
"pino": "^10.1.0",
|
|
203
183
|
"pino-pretty": "^13.1.3",
|
|
204
184
|
"publint": "^0.3.15",
|
|
205
|
-
"redis": "^5.10.0",
|
|
206
185
|
"superjson": "^2.2.6",
|
|
207
186
|
"ts-unused-exports": "^11.0.1",
|
|
208
187
|
"tsdown": "^0.16.8",
|
|
@@ -216,6 +195,7 @@
|
|
|
216
195
|
"onlyBuiltDependencies": [
|
|
217
196
|
"cpu-features",
|
|
218
197
|
"esbuild",
|
|
198
|
+
"msgpackr-extract",
|
|
219
199
|
"ssh2",
|
|
220
200
|
"vue-demi"
|
|
221
201
|
]
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { LRUCache } from 'lru-cache';
|
|
2
|
+
|
|
3
|
+
export function createLruKeyedStore<D = unknown>(lruInstance: LRUCache<any, any, any>) {
|
|
4
|
+
return <P extends any[]>(keyFn: (...args: P) => string) => Object.freeze({
|
|
5
|
+
/**
|
|
6
|
+
* Return a value from the cache. Will update the recency of the cache entry found.
|
|
7
|
+
*
|
|
8
|
+
* If the key is not found, returns `null`.
|
|
9
|
+
*/
|
|
10
|
+
getItem(...args: P) {
|
|
11
|
+
const rawValue = lruInstance.get(keyFn(...args));
|
|
12
|
+
return rawValue as D ?? null;
|
|
13
|
+
},
|
|
14
|
+
getItemTtl: (...args: P) => lruInstance.getRemainingTTL(keyFn(...args)),
|
|
15
|
+
hasItem: (...args: P) => lruInstance.has(keyFn(...args)),
|
|
16
|
+
removeItem: (...args: P) => lruInstance.delete(keyFn(...args)),
|
|
17
|
+
/**
|
|
18
|
+
* Resolves the full cache key from the given arguments.
|
|
19
|
+
*/
|
|
20
|
+
resolveKey: (...args: P) => keyFn(...args),
|
|
21
|
+
setItem: (value: D, ...args: P) => lruInstance.set(keyFn(...args), value),
|
|
22
|
+
});
|
|
23
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { MaybeReadonly } from '../../types';
|
|
2
|
+
|
|
3
|
+
import type { RedisLikeStorage } from './types';
|
|
4
|
+
|
|
5
|
+
export function createRedisKeyedStore<D = unknown>(storage: MaybeReadonly<RedisLikeStorage>) {
|
|
6
|
+
return <P extends any[]>(keyFn: (...args: P) => string) => Object.freeze({
|
|
7
|
+
getItem: (...args: P) => storage.getItem<D>(keyFn(...args)),
|
|
8
|
+
getItemTtl: (...args: P) => storage.getItemTtl(keyFn(...args)),
|
|
9
|
+
hasItem: (...args: P) => storage.hasItem(keyFn(...args)),
|
|
10
|
+
removeItem: (...args: P) => storage.removeItem(keyFn(...args)),
|
|
11
|
+
resolveKey: (...args: P) => keyFn(...args),
|
|
12
|
+
setItem: (value: D, ...args: P) => storage.setItem(keyFn(...args), value),
|
|
13
|
+
setItemWithTtl(ttlSeconds: number, value: D, ...args: P) {
|
|
14
|
+
return storage.setItemWithTtl(keyFn(...args), ttlSeconds, value);
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {
|
|
2
|
+
decode,
|
|
3
|
+
encode,
|
|
4
|
+
isNativeAccelerationEnabled,
|
|
5
|
+
} from 'msgpackr';
|
|
6
|
+
|
|
7
|
+
import type {
|
|
8
|
+
RedisLikeAdapter,
|
|
9
|
+
RedisLikeStorage,
|
|
10
|
+
} from './types';
|
|
11
|
+
|
|
12
|
+
if (!isNativeAccelerationEnabled) {
|
|
13
|
+
console.warn('Native acceleration not enabled for msgpackr, verify that install finished properly');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function createRedisMsgpackStorage(adapter: RedisLikeAdapter): Readonly<RedisLikeStorage> {
|
|
17
|
+
return Object.freeze({
|
|
18
|
+
async getItem<T = unknown>(key: string) {
|
|
19
|
+
const rawValue = await adapter.getBuffer(key);
|
|
20
|
+
return rawValue ? decode(rawValue) as T : null;
|
|
21
|
+
},
|
|
22
|
+
getItemTtl: (key: string) => adapter.ttl(key),
|
|
23
|
+
hasItem: (key: string) => adapter.has(key),
|
|
24
|
+
removeItem: async (key: string) => await adapter.delete(key) === 1,
|
|
25
|
+
setItem: async (key: string, value: any) => await adapter.setBuffer(key, encode(value)) === 'OK',
|
|
26
|
+
async setItemWithTtl(key: string, ttlSeconds: number, value: any) {
|
|
27
|
+
return await adapter.setBufferEx(key, ttlSeconds, encode(value)) === 'OK';
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Nullable } from '../../types';
|
|
2
|
+
|
|
3
|
+
export interface RedisLikeAdapter {
|
|
4
|
+
delete: (key: string) => Promise<number>;
|
|
5
|
+
getBuffer: (key: string) => Promise<Nullable<Uint8Array>>;
|
|
6
|
+
has: (key: string) => Promise<boolean>;
|
|
7
|
+
setBuffer: (key: string, value: Uint8Array) => Promise<'OK' | void>;
|
|
8
|
+
setBufferEx: (key: string, ttlSeconds: number, value: Uint8Array) => Promise<'OK' | void>;
|
|
9
|
+
ttl: (key: string) => Promise<number>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface RedisLikeStorage {
|
|
13
|
+
getItem: <T = unknown>(key: string) => Promise<Nullable<T>>;
|
|
14
|
+
getItemTtl: (key: string) => Promise<number>;
|
|
15
|
+
hasItem: (key: string) => Promise<boolean>;
|
|
16
|
+
removeItem: (key: string) => Promise<boolean>;
|
|
17
|
+
setItem: (key: string, value: any) => Promise<boolean>;
|
|
18
|
+
setItemWithTtl: (key: string, ttlSeconds: number, value: any) => Promise<boolean>;
|
|
19
|
+
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
//#region src/storage/enhanced/local/core.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* An enhanced localStorage wrapper that supports storing
|
|
4
|
-
* complex data types (e.g. Dates, Maps, Sets) using SuperJSON encoding.
|
|
5
|
-
*
|
|
6
|
-
* This utility preserves type structure when saving and retrieving values.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```typescript
|
|
10
|
-
* import { enhancedLocalStorage } from '@kikiutils/shared/storage/enhanced/local';
|
|
11
|
-
*
|
|
12
|
-
* enhancedLocalStorage.setItem('user', { name: 'user', createdAt: new Date() });
|
|
13
|
-
* const user = enhancedLocalStorage.getItem<{ name: string, createdAt: Date }>('user');
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
declare const enhancedLocalStorage: Readonly<{
|
|
17
|
-
/**
|
|
18
|
-
* Removes all items from localStorage.
|
|
19
|
-
*/
|
|
20
|
-
clear: () => void;
|
|
21
|
-
/**
|
|
22
|
-
* Retrieves a value by key and decodes it using SuperJSON or raw string.
|
|
23
|
-
*
|
|
24
|
-
* @template T - The expected type of the value
|
|
25
|
-
*
|
|
26
|
-
* @param {string} key - The key of the value to retrieve
|
|
27
|
-
*
|
|
28
|
-
* @returns {null | T} The decoded value or null if not found
|
|
29
|
-
*/
|
|
30
|
-
getItem<T = unknown>(key: string): T | null;
|
|
31
|
-
/**
|
|
32
|
-
* Checks whether a key exists in localStorage.
|
|
33
|
-
*
|
|
34
|
-
* @param {string} key - The key to check
|
|
35
|
-
*
|
|
36
|
-
* @returns {boolean} True if the key exists, false otherwise
|
|
37
|
-
*/
|
|
38
|
-
hasItem: (key: string) => boolean;
|
|
39
|
-
/**
|
|
40
|
-
* Returns the number of items stored in localStorage.
|
|
41
|
-
*
|
|
42
|
-
* @returns {number} The number of items stored in localStorage
|
|
43
|
-
*/
|
|
44
|
-
readonly length: number;
|
|
45
|
-
/**
|
|
46
|
-
* Removes a specific key from localStorage.
|
|
47
|
-
*
|
|
48
|
-
* @param {string} key - The key to remove
|
|
49
|
-
*/
|
|
50
|
-
removeItem: (key: string) => void;
|
|
51
|
-
/**
|
|
52
|
-
* Stores a value in localStorage with automatic serialization.
|
|
53
|
-
*
|
|
54
|
-
* @param {string} key - The key to store the value under
|
|
55
|
-
* @param {any} value - The value to store
|
|
56
|
-
*/
|
|
57
|
-
setItem: (key: string, value: any) => void;
|
|
58
|
-
}>;
|
|
59
|
-
//#endregion
|
|
60
|
-
export { enhancedLocalStorage };
|
|
61
|
-
//# sourceMappingURL=core.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","names":[],"sources":["../../../../src/storage/enhanced/local/core.ts"],"sourcesContent":[],"mappings":";;AA4BA;;;;;;;;;;;;;cAAa,sBAAoB;;;;;;;;;;;;;;qCAcG"}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { deserialize, serialize } from "superjson";
|
|
2
|
-
|
|
3
|
-
//#region src/storage/enhanced/local/core.ts
|
|
4
|
-
var StorageValueEncodingType = /* @__PURE__ */ function(StorageValueEncodingType$1) {
|
|
5
|
-
StorageValueEncodingType$1["Json"] = "0";
|
|
6
|
-
StorageValueEncodingType$1["String"] = "1";
|
|
7
|
-
return StorageValueEncodingType$1;
|
|
8
|
-
}(StorageValueEncodingType || {});
|
|
9
|
-
const customValueHeader = "";
|
|
10
|
-
const customValueHeaderLength = 3;
|
|
11
|
-
const toCustomValue = (type, payload) => `${customValueHeader}${type}${payload}`;
|
|
12
|
-
/**
|
|
13
|
-
* An enhanced localStorage wrapper that supports storing
|
|
14
|
-
* complex data types (e.g. Dates, Maps, Sets) using SuperJSON encoding.
|
|
15
|
-
*
|
|
16
|
-
* This utility preserves type structure when saving and retrieving values.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```typescript
|
|
20
|
-
* import { enhancedLocalStorage } from '@kikiutils/shared/storage/enhanced/local';
|
|
21
|
-
*
|
|
22
|
-
* enhancedLocalStorage.setItem('user', { name: 'user', createdAt: new Date() });
|
|
23
|
-
* const user = enhancedLocalStorage.getItem<{ name: string, createdAt: Date }>('user');
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
const enhancedLocalStorage = Object.freeze({
|
|
27
|
-
clear: () => window.localStorage.clear(),
|
|
28
|
-
getItem(key) {
|
|
29
|
-
const rawValue = window.localStorage.getItem(key);
|
|
30
|
-
return rawValue ? decodeStorageValue(rawValue) : null;
|
|
31
|
-
},
|
|
32
|
-
hasItem: (key) => window.localStorage.getItem(key) !== null,
|
|
33
|
-
get length() {
|
|
34
|
-
return window.localStorage.length;
|
|
35
|
-
},
|
|
36
|
-
removeItem: (key) => window.localStorage.removeItem(key),
|
|
37
|
-
setItem: (key, value) => window.localStorage.setItem(key, encodeToStorageValue(value))
|
|
38
|
-
});
|
|
39
|
-
function decodeStorageValue(data) {
|
|
40
|
-
if (!isCustomFormat(data)) return data;
|
|
41
|
-
const payload = data.substring(customValueHeaderLength);
|
|
42
|
-
const type = data.charAt(2);
|
|
43
|
-
switch (type) {
|
|
44
|
-
case StorageValueEncodingType.Json: try {
|
|
45
|
-
return deserialize(JSON.parse(payload));
|
|
46
|
-
} catch {
|
|
47
|
-
throw new Error("[EnhancedLocalStorage] Failed to parse JSON payload");
|
|
48
|
-
}
|
|
49
|
-
case StorageValueEncodingType.String: return payload;
|
|
50
|
-
default: throw new Error(`[EnhancedLocalStorage] Unknown encoding type: ${type}`);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
function encodeToStorageValue(value) {
|
|
54
|
-
if (typeof value === "string") return toCustomValue(StorageValueEncodingType.String, value);
|
|
55
|
-
return toCustomValue(StorageValueEncodingType.Json, JSON.stringify(serialize(value)));
|
|
56
|
-
}
|
|
57
|
-
function isCustomFormat(data) {
|
|
58
|
-
return data.length >= customValueHeaderLength && data[0] === customValueHeader[0] && data[1] === customValueHeader[1];
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
//#endregion
|
|
62
|
-
export { enhancedLocalStorage };
|
|
63
|
-
//# sourceMappingURL=core.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"core.js","names":[],"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"],"mappings":";;;AAKA,IAAK,gFAAL;AACI;AACA;;EAFC;AAKL,MAAM,oBAAoB;AAC1B,MAAM,0BAA0B;AAChC,MAAM,iBAAiB,MAAgC,YAAoB,GAAG,oBAAoB,OAAO;;;;;;;;;;;;;;;AAgBzG,MAAa,uBAAuB,OAAO,OAAO;CAI9C,aAAa,OAAO,aAAa,OAAO;CAUxC,QAAqB,KAAa;EAC9B,MAAM,WAAW,OAAO,aAAa,QAAQ,IAAI;AACjD,SAAO,WAAW,mBAAmB,SAAS,GAAQ;;CAS1D,UAAU,QAAgB,OAAO,aAAa,QAAQ,IAAI,KAAK;CAM/D,IAAI,SAAS;AACT,SAAO,OAAO,aAAa;;CAO/B,aAAa,QAAgB,OAAO,aAAa,WAAW,IAAI;CAOhE,UAAU,KAAa,UAAe,OAAO,aAAa,QAAQ,KAAK,qBAAqB,MAAM,CAAC;CACtG,CAAC;AAEF,SAAS,mBAAmB,MAAc;AACtC,KAAI,CAAC,eAAe,KAAK,CAAE,QAAO;CAClC,MAAM,UAAU,KAAK,UAAU,wBAAwB;CACvD,MAAM,OAAO,KAAK,OAAO,EAAyB;AAClD,SAAQ,MAAR;EACI,KAAK,yBAAyB,KAC1B,KAAI;AACA,UAAO,YAAY,KAAK,MAAM,QAAQ,CAAC;UACnC;AACJ,SAAM,IAAI,MAAM,sDAAsD;;EAE9E,KAAK,yBAAyB,OAAQ,QAAO;EAC7C,QACI,OAAM,IAAI,MAAM,iDAAiD,OAAO;;;AAIpF,SAAS,qBAAqB,OAAY;AACtC,KAAI,OAAO,UAAU,SAAU,QAAO,cAAc,yBAAyB,QAAQ,MAAM;AAC3F,QAAO,cAAc,yBAAyB,MAAM,KAAK,UAAU,UAAU,MAAM,CAAC,CAAC;;AAGzF,SAAS,eAAe,MAAc;AAClC,QACI,KAAK,UAAU,2BACZ,KAAK,OAAO,kBAAkB,MAC9B,KAAK,OAAO,kBAAkB"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
//#region src/storage/enhanced/local/keyed-store.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Creates a reusable, type-safe storage interface based on `enhancedLocalStorage`
|
|
4
|
-
* and a dynamic key-generation function.
|
|
5
|
-
*
|
|
6
|
-
* This utility allows you to abstract away key construction logic and work directly
|
|
7
|
-
* with scoped key-value operations like `getItem`, `setItem`, and `removeItem`.
|
|
8
|
-
*
|
|
9
|
-
* @template D - The value type to store
|
|
10
|
-
*
|
|
11
|
-
* @returns A factory that accepts a key generator function and returns a scoped storage interface
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```typescript
|
|
15
|
-
* import { createKeyedEnhancedLocalStore } from '@kikiutils/shared/storage/enhanced/local';
|
|
16
|
-
*
|
|
17
|
-
* const userStore = createKeyedEnhancedLocalStore<User>()((id: number) => `user:${id}`);
|
|
18
|
-
* userStore.setItem({ id: 123, name: 'user' }, 123);
|
|
19
|
-
* const user = userStore.getItem(123);
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
declare function createKeyedEnhancedLocalStore<D = unknown>(): <P extends any[]>(getKeyFunction: (...args: P) => string) => Readonly<{
|
|
23
|
-
getItem: (...args: P) => D | null;
|
|
24
|
-
hasItem: (...args: P) => boolean;
|
|
25
|
-
removeItem: (...args: P) => void;
|
|
26
|
-
/**
|
|
27
|
-
* Resolves the storage key from the given arguments.
|
|
28
|
-
*
|
|
29
|
-
* @returns {string} The final string key used internally
|
|
30
|
-
*/
|
|
31
|
-
resolveKey: (...args: P) => string;
|
|
32
|
-
setItem: (value: D, ...args: P) => void;
|
|
33
|
-
}>;
|
|
34
|
-
//#endregion
|
|
35
|
-
export { createKeyedEnhancedLocalStore };
|
|
36
|
-
//# sourceMappingURL=keyed-store.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"keyed-store.d.ts","names":[],"sources":["../../../../src/storage/enhanced/local/keyed-store.ts"],"sourcesContent":[],"mappings":";;AAsBA;;;;;;;;;;;;;;;;;;;iBAAgB,0FACuC,iBAAY;qBACxC,MAAC;qBACD;wBACG;;;;;;wBAMA;mBACL,YAAY"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { enhancedLocalStorage } from "./core.js";
|
|
2
|
-
|
|
3
|
-
//#region src/storage/enhanced/local/keyed-store.ts
|
|
4
|
-
/**
|
|
5
|
-
* Creates a reusable, type-safe storage interface based on `enhancedLocalStorage`
|
|
6
|
-
* and a dynamic key-generation function.
|
|
7
|
-
*
|
|
8
|
-
* This utility allows you to abstract away key construction logic and work directly
|
|
9
|
-
* with scoped key-value operations like `getItem`, `setItem`, and `removeItem`.
|
|
10
|
-
*
|
|
11
|
-
* @template D - The value type to store
|
|
12
|
-
*
|
|
13
|
-
* @returns A factory that accepts a key generator function and returns a scoped storage interface
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```typescript
|
|
17
|
-
* import { createKeyedEnhancedLocalStore } from '@kikiutils/shared/storage/enhanced/local';
|
|
18
|
-
*
|
|
19
|
-
* const userStore = createKeyedEnhancedLocalStore<User>()((id: number) => `user:${id}`);
|
|
20
|
-
* userStore.setItem({ id: 123, name: 'user' }, 123);
|
|
21
|
-
* const user = userStore.getItem(123);
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
function createKeyedEnhancedLocalStore() {
|
|
25
|
-
return (getKeyFunction) => Object.freeze({
|
|
26
|
-
getItem: (...args) => enhancedLocalStorage.getItem(getKeyFunction(...args)),
|
|
27
|
-
hasItem: (...args) => enhancedLocalStorage.hasItem(getKeyFunction(...args)),
|
|
28
|
-
removeItem: (...args) => enhancedLocalStorage.removeItem(getKeyFunction(...args)),
|
|
29
|
-
resolveKey: (...args) => getKeyFunction(...args),
|
|
30
|
-
setItem: (value, ...args) => enhancedLocalStorage.setItem(getKeyFunction(...args), value)
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
//#endregion
|
|
35
|
-
export { createKeyedEnhancedLocalStore };
|
|
36
|
-
//# sourceMappingURL=keyed-store.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"keyed-store.js","names":[],"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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,gCAA6C;AACzD,SAAyB,mBAA2C,OAAO,OAAO;EAC9E,UAAU,GAAG,SAAY,qBAAqB,QAAW,eAAe,GAAG,KAAK,CAAC;EACjF,UAAU,GAAG,SAAY,qBAAqB,QAAQ,eAAe,GAAG,KAAK,CAAC;EAC9E,aAAa,GAAG,SAAY,qBAAqB,WAAW,eAAe,GAAG,KAAK,CAAC;EAMpF,aAAa,GAAG,SAAY,eAAe,GAAG,KAAK;EACnD,UAAU,OAAU,GAAG,SAAY,qBAAqB,QAAQ,eAAe,GAAG,KAAK,EAAE,MAAM;EAClG,CAAC"}
|