@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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","names":[],"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"],"mappings":";;;;;AAQA,IAAK,gFAAL;AACI;AACA;AACA;;EAHC;AAML,MAAM,oBAAoB,OAAO,GAC7B,KACA,KACA,IACH;AAED,MAAM,0BAA0B,kBAAkB,aAAa;;;;;;;;;;;;;;;;;;;;AAqB/D,SAAgB,2BAA2B,sBAAsC;CAC7E,MAAM,WAAW,gCAAgC,QAAQ,uBAAuB,IAAI,MAAM,qBAAqB;AAC/G,QAAO,OAAO,OAAO;EAUjB,MAAM,QAAqB,KAAa;GACpC,MAAM,WAAW,MAAM,SAAS,UAAU,IAAI;AAC9C,UAAO,WAAW,mBAAmB,SAAS,GAAQ;;EAS1D,aAAa,QAAgB,SAAS,IAAI,IAAI;EAQ9C,SAAS,OAAO,QAAgB,MAAM,SAAS,OAAO,IAAI,KAAK;EAO/D,IAAI,WAAW;AACX,UAAO;;EAUX,YAAY,OAAO,QAAgB,MAAM,SAAS,IAAI,IAAI,KAAK;EAO/D,UAAU,KAAa,UAAe,SAAS,IAAI,KAAK,qBAAqB,MAAM,CAAC;EAQpF,eAAe,KAAa,SAAiB,OAAY;AACrD,UAAO,SAAS,MAAM,KAAK,SAAS,qBAAqB,MAAM,CAAC;;EAEvE,CAAC;;AAGN,SAAS,mBAAmB,MAAc;AACtC,KAAI,CAAC,eAAe,KAAK,CAAE,QAAO;CAClC,MAAM,UAAU,KAAK,SAAS,wBAAwB;CACtD,MAAM,OAAO,KAAK,kBAAkB;AACpC,SAAQ,MAAR;EACI,KAAK,yBAAyB,OAAQ,QAAO;EAC7C,KAAK,yBAAyB,KAC1B,KAAI;AACA,UAAO,YAAY,KAAK,MAAM,QAAQ,UAAU,CAAC,CAAC;UAC9C;AACJ,SAAM,IAAI,MAAM,8CAA8C;;EAEtE,KAAK,yBAAyB,OAAQ,QAAO,QAAQ,UAAU;EAC/D,QACI,OAAM,IAAI,MAAM,yCAAyC,OAAO;;;AAI5E,SAAS,qBAAqB,OAAY;AACtC,KAAI,OAAO,SAAS,MAAM,CAAE,QAAO,cAAc,yBAAyB,QAAQ,MAAM;AACxF,KAAI,OAAO,UAAU,SAAU,QAAO,cAAc,yBAAyB,QAAQ,OAAO,KAAK,MAAM,CAAC;AACxG,QAAO,cAAc,yBAAyB,MAAM,OAAO,KAAK,KAAK,UAAU,UAAU,MAAM,CAAC,CAAC,CAAC;;AAGtG,SAAS,eAAe,QAAgB;AACpC,QACI,OAAO,UAAU,2BACd,OAAO,OAAO,kBAAkB,MAChC,OAAO,OAAO,kBAAkB,MAChC,OAAO,OAAO,kBAAkB;;AAI3C,SAAS,cAAc,MAAgC,SAAiB;AACpE,QAAO,OAAO,OAAO;EACjB;EACA,OAAO,GAAG,KAAK;EACf;EACH,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { createEnhancedRedisStorage } from "./core.js";
|
|
2
|
+
import { createKeyedEnhancedRedisStore } from "./keyed-store.js";
|
|
3
|
+
export { createEnhancedRedisStorage, createKeyedEnhancedRedisStore };
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { createEnhancedRedisStorage } from "./core.js";
|
|
2
|
+
|
|
3
|
+
//#region src/storage/enhanced/redis/keyed-store.d.ts
|
|
4
|
+
|
|
2
5
|
/**
|
|
3
6
|
* Creates a reusable, type-safe Redis-backed storage interface based on `createEnhancedRedisStorage`
|
|
4
7
|
* and a dynamic key-generation function.
|
|
@@ -22,18 +25,20 @@ import type { createEnhancedRedisStorage } from './core';
|
|
|
22
25
|
* const user = await userStore.getItem(123);
|
|
23
26
|
* ```
|
|
24
27
|
*/
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
28
|
+
declare function createKeyedEnhancedRedisStore<D = unknown>(storage: ReturnType<typeof createEnhancedRedisStorage>): <P extends any[]>(getKeyFunction: (...args: P) => string) => Readonly<{
|
|
29
|
+
getItem: (...args: P) => Promise<D | null>;
|
|
30
|
+
getItemTtl: (...args: P) => Promise<number>;
|
|
31
|
+
hasItem: (...args: P) => Promise<boolean>;
|
|
32
|
+
removeItem: (...args: P) => Promise<boolean>;
|
|
33
|
+
/**
|
|
34
|
+
* Resolves the storage key from the given arguments.
|
|
35
|
+
*
|
|
36
|
+
* @returns {string} The final string key used internally
|
|
37
|
+
*/
|
|
38
|
+
resolveKey: (...args: P) => string;
|
|
39
|
+
setItem: (value: D, ...args: P) => Promise<"OK">;
|
|
40
|
+
setItemWithTtl(seconds: number, value: D, ...args: P): Promise<"OK">;
|
|
38
41
|
}>;
|
|
42
|
+
//#endregion
|
|
43
|
+
export { createKeyedEnhancedRedisStore };
|
|
39
44
|
//# sourceMappingURL=keyed-store.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyed-store.d.ts","
|
|
1
|
+
{"version":3,"file":"keyed-store.d.ts","names":[],"sources":["../../../../src/storage/enhanced/redis/keyed-store.ts"],"sourcesContent":[],"mappings":";;;;;;AAyBA;;;;;;;;;;;;;;;;;;;;;AACmE,iBADnD,6BACmD,CAAA,IAAA,OAAA,CAAA,CAAA,OAAA,EADC,UACD,CAAA,OADmB,0BACnB,CAAA,CAAA,EAAA,CAAA,UAAA,GAAA,EAAA,CAAA,CAAA,cAAA,EAAA,CAAA,GAAA,IAAA,EAAZ,CAAY,EAAA,GAAA,MAAA,EAAA,GAAA,QAAA,CAAA;EAAA,OAAA,EAAA,CAAA,GAAA,IAAA,EACxC,CADwC,EAAA,GACvC,OADuC,CACvC,CADuC,GAAA,IAAA,CAAA;wBAErC,MAAC;qBACJ,MAAC;wBACE,MAAC;;;;;;wBAMD;mBACL,YAAY,MAAC;yCACS,YAAY,IAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
//#region src/storage/enhanced/redis/keyed-store.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a reusable, type-safe Redis-backed storage interface based on `createEnhancedRedisStorage`
|
|
4
|
+
* and a dynamic key-generation function.
|
|
5
|
+
*
|
|
6
|
+
* This utility abstracts away key construction and provides high-level access
|
|
7
|
+
* to Redis operations such as `getItem`, `setItem`, `setItemWithTtl`, and `getItemTtl`.
|
|
8
|
+
* It is ideal for namespaced data, caching, and session handling.
|
|
9
|
+
*
|
|
10
|
+
* @template D - The value type to store
|
|
11
|
+
*
|
|
12
|
+
* @param {ReturnType<typeof createEnhancedRedisStorage>} storage - The enhanced Redis storage instance
|
|
13
|
+
*
|
|
14
|
+
* @returns A factory that accepts a key generator function and returns a scoped Redis storage interface
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { createKeyedEnhancedRedisStore } from '@kikiutils/shared/storage/enhanced/redis';
|
|
19
|
+
*
|
|
20
|
+
* const userStore = createKeyedEnhancedRedisStore<User>(redisStorage)((id: number) => `user:${id}`);
|
|
21
|
+
* await userStore.setItem({ id: 123, name: 'user' }, 123);
|
|
22
|
+
* const user = await userStore.getItem(123);
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
function createKeyedEnhancedRedisStore(storage) {
|
|
26
|
+
return (getKeyFunction) => Object.freeze({
|
|
27
|
+
getItem: (...args) => storage.getItem(getKeyFunction(...args)),
|
|
28
|
+
getItemTtl: (...args) => storage.getItemTtl(getKeyFunction(...args)),
|
|
29
|
+
hasItem: (...args) => storage.hasItem(getKeyFunction(...args)),
|
|
30
|
+
removeItem: (...args) => storage.removeItem(getKeyFunction(...args)),
|
|
31
|
+
resolveKey: (...args) => getKeyFunction(...args),
|
|
32
|
+
setItem: (value, ...args) => storage.setItem(getKeyFunction(...args), value),
|
|
33
|
+
setItemWithTtl(seconds, value, ...args) {
|
|
34
|
+
return storage.setItemWithTtl(getKeyFunction(...args), seconds, value);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
export { createKeyedEnhancedRedisStore };
|
|
41
|
+
//# sourceMappingURL=keyed-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyed-store.js","names":[],"sources":["../../../../src/storage/enhanced/redis/keyed-store.ts"],"sourcesContent":["import type { createEnhancedRedisStorage } from './core';\n\n/**\n * Creates a reusable, type-safe Redis-backed storage interface based on `createEnhancedRedisStorage`\n * and a dynamic key-generation function.\n *\n * This utility abstracts away key construction and provides high-level access\n * to Redis operations such as `getItem`, `setItem`, `setItemWithTtl`, and `getItemTtl`.\n * It is ideal for namespaced data, caching, and session handling.\n *\n * @template D - The value type to store\n *\n * @param {ReturnType<typeof createEnhancedRedisStorage>} storage - The enhanced Redis storage instance\n *\n * @returns A factory that accepts a key generator function and returns a scoped Redis storage interface\n *\n * @example\n * ```typescript\n * import { createKeyedEnhancedRedisStore } from '@kikiutils/shared/storage/enhanced/redis';\n *\n * const userStore = createKeyedEnhancedRedisStore<User>(redisStorage)((id: number) => `user:${id}`);\n * await userStore.setItem({ id: 123, name: 'user' }, 123);\n * const user = await userStore.getItem(123);\n * ```\n */\nexport function createKeyedEnhancedRedisStore<D = unknown>(storage: ReturnType<typeof createEnhancedRedisStorage>) {\n return <P extends any[]>(getKeyFunction: (...args: P) => string) => Object.freeze({\n getItem: (...args: P) => storage.getItem<D>(getKeyFunction(...args)),\n getItemTtl: (...args: P) => storage.getItemTtl(getKeyFunction(...args)),\n hasItem: (...args: P) => storage.hasItem(getKeyFunction(...args)),\n removeItem: (...args: P) => storage.removeItem(getKeyFunction(...args)),\n /**\n * Resolves the storage key from the given arguments.\n *\n * @returns {string} The final string key used internally\n */\n resolveKey: (...args: P) => getKeyFunction(...args),\n setItem: (value: D, ...args: P) => storage.setItem(getKeyFunction(...args), value),\n setItemWithTtl(seconds: number, value: D, ...args: P) {\n return storage.setItemWithTtl(getKeyFunction(...args), seconds, value);\n },\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAyBA,SAAgB,8BAA2C,SAAwD;AAC/G,SAAyB,mBAA2C,OAAO,OAAO;EAC9E,UAAU,GAAG,SAAY,QAAQ,QAAW,eAAe,GAAG,KAAK,CAAC;EACpE,aAAa,GAAG,SAAY,QAAQ,WAAW,eAAe,GAAG,KAAK,CAAC;EACvE,UAAU,GAAG,SAAY,QAAQ,QAAQ,eAAe,GAAG,KAAK,CAAC;EACjE,aAAa,GAAG,SAAY,QAAQ,WAAW,eAAe,GAAG,KAAK,CAAC;EAMvE,aAAa,GAAG,SAAY,eAAe,GAAG,KAAK;EACnD,UAAU,OAAU,GAAG,SAAY,QAAQ,QAAQ,eAAe,GAAG,KAAK,EAAE,MAAM;EAClF,eAAe,SAAiB,OAAU,GAAG,MAAS;AAClD,UAAO,QAAQ,eAAe,eAAe,GAAG,KAAK,EAAE,SAAS,MAAM;;EAE7E,CAAC"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { LRUCache } from "lru-cache";
|
|
2
|
+
|
|
3
|
+
//#region src/storage/lru/keyed-store.d.ts
|
|
4
|
+
|
|
2
5
|
/**
|
|
3
6
|
* Creates a reusable, type-safe keyed store wrapper for an LRUCache instance.
|
|
4
7
|
*
|
|
@@ -20,20 +23,22 @@ import type { LRUCache } from 'lru-cache';
|
|
|
20
23
|
* const user = userStore.getItem(1);
|
|
21
24
|
* ```
|
|
22
25
|
*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
26
|
+
declare function createKeyedLruStore<D = unknown>(lruInstance: LRUCache<any, any, any>): <P extends any[]>(getKeyFunction: (...args: P) => string) => Readonly<{
|
|
27
|
+
/**
|
|
28
|
+
* Return a value from the cache. Will update the recency of the cache entry found.
|
|
29
|
+
*
|
|
30
|
+
* If the key is not found, returns `null`.
|
|
31
|
+
*/
|
|
32
|
+
getItem(...args: P): NonNullable<D> | null;
|
|
33
|
+
getItemTtl: (...args: P) => number;
|
|
34
|
+
hasItem: (...args: P) => boolean;
|
|
35
|
+
removeItem: (...args: P) => boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Resolves the full cache key from the given arguments.
|
|
38
|
+
*/
|
|
39
|
+
resolveKey: (...args: P) => string;
|
|
40
|
+
setItem(value: D, ...args: P): void;
|
|
38
41
|
}>;
|
|
42
|
+
//#endregion
|
|
43
|
+
export { createKeyedLruStore };
|
|
39
44
|
//# sourceMappingURL=keyed-store.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyed-store.d.ts","
|
|
1
|
+
{"version":3,"file":"keyed-store.d.ts","names":[],"sources":["../../../src/storage/lru/keyed-store.ts"],"sourcesContent":[],"mappings":";;;;;;AAuBA;;;;;;;;;;;;;;;;;;;iBAAgB,8CAA8C,sEACP,iBAAY;;;;;;mBAM1C,IAAC,YAAA;wBAII;qBACH;wBACG;;;;wBAIA;iBACP,YAAY"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
//#region src/storage/lru/keyed-store.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a reusable, type-safe keyed store wrapper for an LRUCache instance.
|
|
4
|
+
*
|
|
5
|
+
* This utility allows structured access to cache entries using a dynamic key-generation function.
|
|
6
|
+
*
|
|
7
|
+
* @template D - The specific value type exposed by this store (must extend `V`)
|
|
8
|
+
*
|
|
9
|
+
* @param {LRUCache<any, any, any>} lruInstance - An instance of `lru-cache`
|
|
10
|
+
*
|
|
11
|
+
* @returns A factory that accepts a key generator and returns a scoped, type-safe LRU-based store
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { createKeyedLruStore } from '@kikiutils/shared/storage/lru/keyed-store';
|
|
16
|
+
*
|
|
17
|
+
* const lruCache = new LRUCache({ max: 5000 });
|
|
18
|
+
* const userStore = createKeyedLruStore<User>(lruCache)((id: number) => `user:${id}`);
|
|
19
|
+
* userStore.setItem({ id: 1 }, 1);
|
|
20
|
+
* const user = userStore.getItem(1);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
function createKeyedLruStore(lruInstance) {
|
|
24
|
+
return (getKeyFunction) => Object.freeze({
|
|
25
|
+
getItem(...args) {
|
|
26
|
+
return lruInstance.get(getKeyFunction(...args)) ?? null;
|
|
27
|
+
},
|
|
28
|
+
getItemTtl: (...args) => lruInstance.getRemainingTTL(getKeyFunction(...args)),
|
|
29
|
+
hasItem: (...args) => lruInstance.has(getKeyFunction(...args)),
|
|
30
|
+
removeItem: (...args) => lruInstance.delete(getKeyFunction(...args)),
|
|
31
|
+
resolveKey: (...args) => getKeyFunction(...args),
|
|
32
|
+
setItem(value, ...args) {
|
|
33
|
+
lruInstance.set(getKeyFunction(...args), value);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
export { createKeyedLruStore };
|
|
40
|
+
//# sourceMappingURL=keyed-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyed-store.js","names":[],"sources":["../../../src/storage/lru/keyed-store.ts"],"sourcesContent":["import type { LRUCache } from 'lru-cache';\n\n/**\n * Creates a reusable, type-safe keyed store wrapper for an LRUCache instance.\n *\n * This utility allows structured access to cache entries using a dynamic key-generation function.\n *\n * @template D - The specific value type exposed by this store (must extend `V`)\n *\n * @param {LRUCache<any, any, any>} lruInstance - An instance of `lru-cache`\n *\n * @returns A factory that accepts a key generator and returns a scoped, type-safe LRU-based store\n *\n * @example\n * ```typescript\n * import { createKeyedLruStore } from '@kikiutils/shared/storage/lru/keyed-store';\n *\n * const lruCache = new LRUCache({ max: 5000 });\n * const userStore = createKeyedLruStore<User>(lruCache)((id: number) => `user:${id}`);\n * userStore.setItem({ id: 1 }, 1);\n * const user = userStore.getItem(1);\n * ```\n */\nexport function createKeyedLruStore<D = unknown>(lruInstance: LRUCache<any, any, any>) {\n return <P extends any[]>(getKeyFunction: (...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(getKeyFunction(...args));\n return rawValue as D ?? null;\n },\n getItemTtl: (...args: P) => lruInstance.getRemainingTTL(getKeyFunction(...args)),\n hasItem: (...args: P) => lruInstance.has(getKeyFunction(...args)),\n removeItem: (...args: P) => lruInstance.delete(getKeyFunction(...args)),\n /**\n * Resolves the full cache key from the given arguments.\n */\n resolveKey: (...args: P) => getKeyFunction(...args),\n setItem(value: D, ...args: P) {\n lruInstance.set(getKeyFunction(...args), value);\n },\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,oBAAiC,aAAsC;AACnF,SAAyB,mBAA2C,OAAO,OAAO;EAM9E,QAAQ,GAAG,MAAS;AAEhB,UADiB,YAAY,IAAI,eAAe,GAAG,KAAK,CAAC,IACjC;;EAE5B,aAAa,GAAG,SAAY,YAAY,gBAAgB,eAAe,GAAG,KAAK,CAAC;EAChF,UAAU,GAAG,SAAY,YAAY,IAAI,eAAe,GAAG,KAAK,CAAC;EACjE,aAAa,GAAG,SAAY,YAAY,OAAO,eAAe,GAAG,KAAK,CAAC;EAIvE,aAAa,GAAG,SAAY,eAAe,GAAG,KAAK;EACnD,QAAQ,OAAU,GAAG,MAAS;AAC1B,eAAY,IAAI,eAAe,GAAG,KAAK,EAAE,MAAM;;EAEtD,CAAC"}
|
package/dist/string.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/string.d.ts
|
|
2
|
+
type RandomStringMode = 'alphabetic' | 'alphanumeric' | 'lowercase' | 'lowercase-numeric' | 'numeric' | 'uppercase' | 'uppercase-numeric';
|
|
2
3
|
/**
|
|
3
4
|
* Generates a random string of a given length using a specified character set.
|
|
4
5
|
*
|
|
@@ -18,5 +19,7 @@ export type RandomStringMode = 'alphabetic' | 'alphanumeric' | 'lowercase' | 'lo
|
|
|
18
19
|
* console.log(randomString(10, 'alphanumeric')); // e.g. 'a9Z4pQ8xY2'
|
|
19
20
|
* ```
|
|
20
21
|
*/
|
|
21
|
-
|
|
22
|
+
declare function randomString(length: number, mode?: RandomStringMode): string;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { RandomStringMode, randomString };
|
|
22
25
|
//# sourceMappingURL=string.d.ts.map
|
package/dist/string.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string.d.ts","
|
|
1
|
+
{"version":3,"file":"string.d.ts","names":[],"sources":["../src/string.ts"],"sourcesContent":[],"mappings":";KAAY,gBAAA;AAAZ;AAyCA;;;;;;;;;;;;;;;;;;iBAAgB,YAAA,wBAAmC"}
|
package/dist/string.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
//#region src/string.ts
|
|
2
|
+
const DIGITS = "0123456789";
|
|
3
|
+
const LOWERCASE = "abcdefghijklmnopqrstuvwxyz";
|
|
4
|
+
const UPPERCASE = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
5
|
+
const CHARSETS = {
|
|
6
|
+
"alphabetic": LOWERCASE + UPPERCASE,
|
|
7
|
+
"alphanumeric": DIGITS + LOWERCASE + UPPERCASE,
|
|
8
|
+
"lowercase": LOWERCASE,
|
|
9
|
+
"lowercase-numeric": DIGITS + LOWERCASE,
|
|
10
|
+
"numeric": DIGITS,
|
|
11
|
+
"uppercase": UPPERCASE,
|
|
12
|
+
"uppercase-numeric": DIGITS + UPPERCASE
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Generates a random string of a given length using a specified character set.
|
|
16
|
+
*
|
|
17
|
+
* @param {number} length - The length of the string to generate. Must be a positive integer
|
|
18
|
+
* @param {RandomStringMode} [mode] - The character set to use
|
|
19
|
+
*
|
|
20
|
+
* @returns {string} The generated random string
|
|
21
|
+
*
|
|
22
|
+
* @throws {Error} If the length is not a positive integer or the mode is unsupported
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* import { randomString } from '@kikiutils/shared/string';
|
|
27
|
+
*
|
|
28
|
+
* console.log(randomString(8)); // e.g. 'aZbXwTyQ' (alphabetic)
|
|
29
|
+
* console.log(randomString(6, 'numeric')); // e.g. '402398'
|
|
30
|
+
* console.log(randomString(10, 'alphanumeric')); // e.g. 'a9Z4pQ8xY2'
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
function randomString(length, mode = "alphabetic") {
|
|
34
|
+
if (!Number.isInteger(length) || length <= 0) throw new Error(`Invalid length: ${length}. Must be a positive integer`);
|
|
35
|
+
const charset = CHARSETS[mode];
|
|
36
|
+
if (!charset) throw new Error(`Unsupported mode: ${mode}`);
|
|
37
|
+
return Array.from({ length }, () => charset[Math.floor(Math.random() * charset.length)]).join("");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
export { randomString };
|
|
42
|
+
//# sourceMappingURL=string.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string.js","names":["CHARSETS: Record<RandomStringMode, string>"],"sources":["../src/string.ts"],"sourcesContent":["export type RandomStringMode =\n | 'alphabetic'\n | 'alphanumeric'\n | 'lowercase'\n | 'lowercase-numeric'\n | 'numeric'\n | 'uppercase'\n | 'uppercase-numeric';\n\nconst DIGITS = '0123456789';\nconst LOWERCASE = 'abcdefghijklmnopqrstuvwxyz';\nconst UPPERCASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\nconst CHARSETS: Record<RandomStringMode, string> = {\n 'alphabetic': LOWERCASE + UPPERCASE,\n 'alphanumeric': DIGITS + LOWERCASE + UPPERCASE,\n 'lowercase': LOWERCASE,\n 'lowercase-numeric': DIGITS + LOWERCASE,\n 'numeric': DIGITS,\n 'uppercase': UPPERCASE,\n 'uppercase-numeric': DIGITS + UPPERCASE,\n};\n\n/**\n * Generates a random string of a given length using a specified character set.\n *\n * @param {number} length - The length of the string to generate. Must be a positive integer\n * @param {RandomStringMode} [mode] - The character set to use\n *\n * @returns {string} The generated random string\n *\n * @throws {Error} If the length is not a positive integer or the mode is unsupported\n *\n * @example\n * ```typescript\n * import { randomString } from '@kikiutils/shared/string';\n *\n * console.log(randomString(8)); // e.g. 'aZbXwTyQ' (alphabetic)\n * console.log(randomString(6, 'numeric')); // e.g. '402398'\n * console.log(randomString(10, 'alphanumeric')); // e.g. 'a9Z4pQ8xY2'\n * ```\n */\nexport function randomString(length: number, mode: RandomStringMode = 'alphabetic') {\n if (!Number.isInteger(length) || length <= 0) {\n throw new Error(`Invalid length: ${length}. Must be a positive integer`);\n }\n\n const charset = CHARSETS[mode];\n if (!charset) throw new Error(`Unsupported mode: ${mode}`);\n return Array.from({ length }, () => charset[Math.floor(Math.random() * charset.length)]).join('');\n}\n"],"mappings":";AASA,MAAM,SAAS;AACf,MAAM,YAAY;AAClB,MAAM,YAAY;AAClB,MAAMA,WAA6C;CAC/C,cAAc,YAAY;CAC1B,gBAAgB,SAAS,YAAY;CACrC,aAAa;CACb,qBAAqB,SAAS;CAC9B,WAAW;CACX,aAAa;CACb,qBAAqB,SAAS;CACjC;;;;;;;;;;;;;;;;;;;;AAqBD,SAAgB,aAAa,QAAgB,OAAyB,cAAc;AAChF,KAAI,CAAC,OAAO,UAAU,OAAO,IAAI,UAAU,EACvC,OAAM,IAAI,MAAM,mBAAmB,OAAO,8BAA8B;CAG5E,MAAM,UAAU,SAAS;AACzB,KAAI,CAAC,QAAS,OAAM,IAAI,MAAM,qBAAqB,OAAO;AAC1D,QAAO,MAAM,KAAK,EAAE,QAAQ,QAAQ,QAAQ,KAAK,MAAM,KAAK,QAAQ,GAAG,QAAQ,OAAO,EAAE,CAAC,KAAK,GAAG"}
|
package/dist/url.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/url.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Appends or updates the `redirect` query parameter on a given URL.
|
|
3
4
|
*
|
|
@@ -8,5 +9,7 @@
|
|
|
8
9
|
*
|
|
9
10
|
* @returns {string} A new URL string with the `redirect` query parameter
|
|
10
11
|
*/
|
|
11
|
-
|
|
12
|
+
declare function appendRedirectParamToUrl(url: string, redirectPath: string): string;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { appendRedirectParamToUrl };
|
|
12
15
|
//# sourceMappingURL=url.d.ts.map
|
package/dist/url.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"url.d.ts","
|
|
1
|
+
{"version":3,"file":"url.d.ts","names":[],"sources":["../src/url.ts"],"sourcesContent":[],"mappings":";;AAUA;;;;;;;;;iBAAgB,wBAAA"}
|
package/dist/url.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/url.ts
|
|
2
|
+
/**
|
|
3
|
+
* Appends or updates the `redirect` query parameter on a given URL.
|
|
4
|
+
*
|
|
5
|
+
* Typically used to preserve the user's current path for post-login navigation.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} url - The target URL to modify
|
|
8
|
+
* @param {string} redirectPath - The path to use as the redirect destination
|
|
9
|
+
*
|
|
10
|
+
* @returns {string} A new URL string with the `redirect` query parameter
|
|
11
|
+
*/
|
|
12
|
+
function appendRedirectParamToUrl(url, redirectPath) {
|
|
13
|
+
const [base, rawQuery = ""] = url.split("?");
|
|
14
|
+
const searchParams = new URLSearchParams(rawQuery);
|
|
15
|
+
searchParams.set("redirect", redirectPath);
|
|
16
|
+
return `${base}?${searchParams.toString()}`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { appendRedirectParamToUrl };
|
|
21
|
+
//# sourceMappingURL=url.js.map
|
package/dist/url.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url.js","names":[],"sources":["../src/url.ts"],"sourcesContent":["/**\n * Appends or updates the `redirect` query parameter on a given URL.\n *\n * Typically used to preserve the user's current path for post-login navigation.\n *\n * @param {string} url - The target URL to modify\n * @param {string} redirectPath - The path to use as the redirect destination\n *\n * @returns {string} A new URL string with the `redirect` query parameter\n */\nexport function appendRedirectParamToUrl(url: string, redirectPath: string) {\n const [base, rawQuery = ''] = url.split('?');\n const searchParams = new URLSearchParams(rawQuery);\n searchParams.set('redirect', redirectPath);\n return `${base}?${searchParams.toString()}`;\n}\n"],"mappings":";;;;;;;;;;;AAUA,SAAgB,yBAAyB,KAAa,cAAsB;CACxE,MAAM,CAAC,MAAM,WAAW,MAAM,IAAI,MAAM,IAAI;CAC5C,MAAM,eAAe,IAAI,gBAAgB,SAAS;AAClD,cAAa,IAAI,YAAY,aAAa;AAC1C,QAAO,GAAG,KAAK,GAAG,aAAa,UAAU"}
|
package/dist/vue.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Ref } from "vue";
|
|
2
|
+
|
|
3
|
+
//#region src/vue.d.ts
|
|
4
|
+
|
|
2
5
|
/**
|
|
3
6
|
* Appends the current Vue Router route's fullPath as the `redirect` query parameter to the given URL.
|
|
4
7
|
*
|
|
@@ -6,19 +9,19 @@ import type { Ref } from 'vue';
|
|
|
6
9
|
*
|
|
7
10
|
* @returns {string} A new URL with the current route fullPath as the `redirect` parameter
|
|
8
11
|
*/
|
|
9
|
-
|
|
12
|
+
declare function appendRedirectParamFromCurrentRouteToUrl(url: string): string;
|
|
10
13
|
/**
|
|
11
14
|
* Clears an interval referenced by a Vue ref and sets it to null.
|
|
12
15
|
*
|
|
13
16
|
* @param {Ref<null | ReturnType<typeof setInterval>>} intervalRef - A Vue ref holding a NodeJS.Timeout or null
|
|
14
17
|
*/
|
|
15
|
-
|
|
18
|
+
declare function clearIntervalRef(intervalRef: Ref<null | ReturnType<typeof setInterval>>): void;
|
|
16
19
|
/**
|
|
17
20
|
* Clears a timeout referenced by a Vue ref and sets it to null.
|
|
18
21
|
*
|
|
19
22
|
* @param {Ref<null | ReturnType<typeof setTimeout>>} timeoutRef - A Vue ref holding a NodeJS.Timeout or null
|
|
20
23
|
*/
|
|
21
|
-
|
|
24
|
+
declare function clearTimeoutRef(timeoutRef: Ref<null | ReturnType<typeof setTimeout>>): void;
|
|
22
25
|
/**
|
|
23
26
|
* A Vue composition function that remembers and restores scroll position
|
|
24
27
|
* of a scrollable container across route changes and keep-alive activation.
|
|
@@ -27,5 +30,7 @@ export declare function clearTimeoutRef(timeoutRef: Ref<null | ReturnType<typeof
|
|
|
27
30
|
*
|
|
28
31
|
* @param {Ref<null | T>} containerRef - A ref to the scrollable HTML element
|
|
29
32
|
*/
|
|
30
|
-
|
|
33
|
+
declare function usePreserveScroll<T extends Element = HTMLElement>(containerRef: Ref<null | T>): void;
|
|
34
|
+
//#endregion
|
|
35
|
+
export { appendRedirectParamFromCurrentRouteToUrl, clearIntervalRef, clearTimeoutRef, usePreserveScroll };
|
|
31
36
|
//# sourceMappingURL=vue.d.ts.map
|
package/dist/vue.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vue.d.ts","
|
|
1
|
+
{"version":3,"file":"vue.d.ts","names":[],"sources":["../src/vue.ts"],"sourcesContent":[],"mappings":";;;;;;AAgBA;AASA;;;;AAA8C,iBAT9B,wCAAA,CAS8B,GAAA,EAAA,MAAA,CAAA,EAAA,MAAA;;AAU9C;;;;AAA4C,iBAV5B,gBAAA,CAU4B,WAAA,EAVE,GAUF,CAAA,IAAA,GAVa,UAUb,CAAA,OAV+B,WAU/B,CAAA,CAAA,CAAA,EAAA,IAAA;;AAa5C;;;;AAA4F,iBAb5E,eAAA,CAa4E,UAAA,EAbhD,GAagD,CAAA,IAAA,GAbrC,UAaqC,CAAA,OAbnB,UAamB,CAAA,CAAA,CAAA,EAAA,IAAA;;;;;;;;;iBAA5E,4BAA4B,UAAU,2BAA2B,WAAW"}
|
package/dist/vue.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { appendRedirectParamToUrl } from "./url.js";
|
|
2
|
+
import { onActivated } from "vue";
|
|
3
|
+
import { onBeforeRouteLeave, useRoute } from "vue-router";
|
|
4
|
+
|
|
5
|
+
//#region src/vue.ts
|
|
6
|
+
/**
|
|
7
|
+
* Appends the current Vue Router route's fullPath as the `redirect` query parameter to the given URL.
|
|
8
|
+
*
|
|
9
|
+
* @param {string} url - The base URL to modify
|
|
10
|
+
*
|
|
11
|
+
* @returns {string} A new URL with the current route fullPath as the `redirect` parameter
|
|
12
|
+
*/
|
|
13
|
+
function appendRedirectParamFromCurrentRouteToUrl(url) {
|
|
14
|
+
return appendRedirectParamToUrl(url, useRoute().fullPath);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Clears an interval referenced by a Vue ref and sets it to null.
|
|
18
|
+
*
|
|
19
|
+
* @param {Ref<null | ReturnType<typeof setInterval>>} intervalRef - A Vue ref holding a NodeJS.Timeout or null
|
|
20
|
+
*/
|
|
21
|
+
function clearIntervalRef(intervalRef) {
|
|
22
|
+
if (intervalRef.value) clearInterval(intervalRef.value);
|
|
23
|
+
intervalRef.value = null;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Clears a timeout referenced by a Vue ref and sets it to null.
|
|
27
|
+
*
|
|
28
|
+
* @param {Ref<null | ReturnType<typeof setTimeout>>} timeoutRef - A Vue ref holding a NodeJS.Timeout or null
|
|
29
|
+
*/
|
|
30
|
+
function clearTimeoutRef(timeoutRef) {
|
|
31
|
+
if (timeoutRef.value) clearTimeout(timeoutRef.value);
|
|
32
|
+
timeoutRef.value = null;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A Vue composition function that remembers and restores scroll position
|
|
36
|
+
* of a scrollable container across route changes and keep-alive activation.
|
|
37
|
+
*
|
|
38
|
+
* @template T - The type of the scrollable element (defaults to HTMLElement)
|
|
39
|
+
*
|
|
40
|
+
* @param {Ref<null | T>} containerRef - A ref to the scrollable HTML element
|
|
41
|
+
*/
|
|
42
|
+
function usePreserveScroll(containerRef) {
|
|
43
|
+
let scrollLeft = 0;
|
|
44
|
+
let scrollTop = 0;
|
|
45
|
+
onActivated(() => {
|
|
46
|
+
if (!containerRef.value) return;
|
|
47
|
+
containerRef.value.scrollLeft = scrollLeft;
|
|
48
|
+
containerRef.value.scrollTop = scrollTop;
|
|
49
|
+
});
|
|
50
|
+
onBeforeRouteLeave(() => {
|
|
51
|
+
scrollLeft = containerRef.value?.scrollLeft || 0;
|
|
52
|
+
scrollTop = containerRef.value?.scrollTop || 0;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
//#endregion
|
|
57
|
+
export { appendRedirectParamFromCurrentRouteToUrl, clearIntervalRef, clearTimeoutRef, usePreserveScroll };
|
|
58
|
+
//# sourceMappingURL=vue.js.map
|
package/dist/vue.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vue.js","names":[],"sources":["../src/vue.ts"],"sourcesContent":["import { onActivated } from 'vue';\nimport type { Ref } from 'vue';\nimport {\n onBeforeRouteLeave,\n useRoute,\n} from 'vue-router';\n\nimport { appendRedirectParamToUrl } from '@/url';\n\n/**\n * Appends the current Vue Router route's fullPath as the `redirect` query parameter to the given URL.\n *\n * @param {string} url - The base URL to modify\n *\n * @returns {string} A new URL with the current route fullPath as the `redirect` parameter\n */\nexport function appendRedirectParamFromCurrentRouteToUrl(url: string) {\n return appendRedirectParamToUrl(url, useRoute().fullPath);\n}\n\n/**\n * Clears an interval referenced by a Vue ref and sets it to null.\n *\n * @param {Ref<null | ReturnType<typeof setInterval>>} intervalRef - A Vue ref holding a NodeJS.Timeout or null\n */\nexport function clearIntervalRef(intervalRef: Ref<null | ReturnType<typeof setInterval>>) {\n if (intervalRef.value) clearInterval(intervalRef.value);\n intervalRef.value = null;\n}\n\n/**\n * Clears a timeout referenced by a Vue ref and sets it to null.\n *\n * @param {Ref<null | ReturnType<typeof setTimeout>>} timeoutRef - A Vue ref holding a NodeJS.Timeout or null\n */\nexport function clearTimeoutRef(timeoutRef: Ref<null | ReturnType<typeof setTimeout>>) {\n if (timeoutRef.value) clearTimeout(timeoutRef.value);\n timeoutRef.value = null;\n}\n\n/**\n * A Vue composition function that remembers and restores scroll position\n * of a scrollable container across route changes and keep-alive activation.\n *\n * @template T - The type of the scrollable element (defaults to HTMLElement)\n *\n * @param {Ref<null | T>} containerRef - A ref to the scrollable HTML element\n */\nexport function usePreserveScroll<T extends Element = HTMLElement>(containerRef: Ref<null | T>) {\n let scrollLeft = 0;\n let scrollTop = 0;\n onActivated(() => {\n if (!containerRef.value) return;\n containerRef.value.scrollLeft = scrollLeft;\n containerRef.value.scrollTop = scrollTop;\n });\n\n onBeforeRouteLeave(() => {\n scrollLeft = containerRef.value?.scrollLeft || 0;\n scrollTop = containerRef.value?.scrollTop || 0;\n });\n}\n"],"mappings":";;;;;;;;;;;;AAgBA,SAAgB,yCAAyC,KAAa;AAClE,QAAO,yBAAyB,KAAK,UAAU,CAAC,SAAS;;;;;;;AAQ7D,SAAgB,iBAAiB,aAAyD;AACtF,KAAI,YAAY,MAAO,eAAc,YAAY,MAAM;AACvD,aAAY,QAAQ;;;;;;;AAQxB,SAAgB,gBAAgB,YAAuD;AACnF,KAAI,WAAW,MAAO,cAAa,WAAW,MAAM;AACpD,YAAW,QAAQ;;;;;;;;;;AAWvB,SAAgB,kBAAmD,cAA6B;CAC5F,IAAI,aAAa;CACjB,IAAI,YAAY;AAChB,mBAAkB;AACd,MAAI,CAAC,aAAa,MAAO;AACzB,eAAa,MAAM,aAAa;AAChC,eAAa,MAAM,YAAY;GACjC;AAEF,0BAAyB;AACrB,eAAa,aAAa,OAAO,cAAc;AAC/C,cAAY,aAAa,OAAO,aAAa;GAC/C"}
|
package/dist/web.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/web.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Appends the current browser URL (including path, query, and hash) as the `redirect` query parameter to the given URL.
|
|
3
4
|
*
|
|
@@ -5,7 +6,7 @@
|
|
|
5
6
|
*
|
|
6
7
|
* @returns {string} A new URL with the current location as the `redirect` parameter
|
|
7
8
|
*/
|
|
8
|
-
|
|
9
|
+
declare function appendRedirectParamFromCurrentLocationToUrl(url: string): string;
|
|
9
10
|
/**
|
|
10
11
|
* Navigates to the given URL, appending the current browser location
|
|
11
12
|
* (path, query, and hash) as the `redirect` query parameter.
|
|
@@ -16,5 +17,7 @@ export declare function appendRedirectParamFromCurrentLocationToUrl(url: string)
|
|
|
16
17
|
* @param {string} url - The destination URL to navigate to
|
|
17
18
|
* @param {number} [delayMs] - Optional delay in milliseconds before navigation
|
|
18
19
|
*/
|
|
19
|
-
|
|
20
|
+
declare function assignUrlWithRedirectParamFromCurrentLocation(url: string, delayMs?: number): NodeJS.Timeout | undefined;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { appendRedirectParamFromCurrentLocationToUrl, assignUrlWithRedirectParamFromCurrentLocation };
|
|
20
23
|
//# sourceMappingURL=web.d.ts.map
|
package/dist/web.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web.d.ts","
|
|
1
|
+
{"version":3,"file":"web.d.ts","names":[],"sources":["../src/web.ts"],"sourcesContent":[],"mappings":";;AASA;AAeA;;;;;iBAfgB,2CAAA;;;;;;;;;;;iBAeA,6CAAA,iCAA2E,MAAA,CAAA"}
|
package/dist/web.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { appendRedirectParamToUrl } from "./url.js";
|
|
2
|
+
|
|
3
|
+
//#region src/web.ts
|
|
4
|
+
/**
|
|
5
|
+
* Appends the current browser URL (including path, query, and hash) as the `redirect` query parameter to the given URL.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} url - The base URL to modify
|
|
8
|
+
*
|
|
9
|
+
* @returns {string} A new URL with the current location as the `redirect` parameter
|
|
10
|
+
*/
|
|
11
|
+
function appendRedirectParamFromCurrentLocationToUrl(url) {
|
|
12
|
+
const currentPath = `${window.location.pathname}${window.location.search}${window.location.hash}`;
|
|
13
|
+
return appendRedirectParamToUrl(url, currentPath);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Navigates to the given URL, appending the current browser location
|
|
17
|
+
* (path, query, and hash) as the `redirect` query parameter.
|
|
18
|
+
*
|
|
19
|
+
* Useful for redirecting to login or other gateways while preserving
|
|
20
|
+
* the current location for post-auth navigation.
|
|
21
|
+
*
|
|
22
|
+
* @param {string} url - The destination URL to navigate to
|
|
23
|
+
* @param {number} [delayMs] - Optional delay in milliseconds before navigation
|
|
24
|
+
*/
|
|
25
|
+
function assignUrlWithRedirectParamFromCurrentLocation(url, delayMs) {
|
|
26
|
+
if (delayMs === void 0) window.location.assign(appendRedirectParamFromCurrentLocationToUrl(url));
|
|
27
|
+
else return setTimeout(() => window.location.assign(appendRedirectParamFromCurrentLocationToUrl(url)), delayMs);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
export { appendRedirectParamFromCurrentLocationToUrl, assignUrlWithRedirectParamFromCurrentLocation };
|
|
32
|
+
//# sourceMappingURL=web.js.map
|
package/dist/web.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.js","names":[],"sources":["../src/web.ts"],"sourcesContent":["import { appendRedirectParamToUrl } from '@/url';\n\n/**\n * Appends the current browser URL (including path, query, and hash) as the `redirect` query parameter to the given URL.\n *\n * @param {string} url - The base URL to modify\n *\n * @returns {string} A new URL with the current location as the `redirect` parameter\n */\nexport function appendRedirectParamFromCurrentLocationToUrl(url: string) {\n const currentPath = `${window.location.pathname}${window.location.search}${window.location.hash}`;\n return appendRedirectParamToUrl(url, currentPath);\n}\n\n/**\n * Navigates to the given URL, appending the current browser location\n * (path, query, and hash) as the `redirect` query parameter.\n *\n * Useful for redirecting to login or other gateways while preserving\n * the current location for post-auth navigation.\n *\n * @param {string} url - The destination URL to navigate to\n * @param {number} [delayMs] - Optional delay in milliseconds before navigation\n */\nexport function assignUrlWithRedirectParamFromCurrentLocation(url: string, delayMs?: number) {\n if (delayMs === undefined) window.location.assign(appendRedirectParamFromCurrentLocationToUrl(url));\n else return setTimeout(() => window.location.assign(appendRedirectParamFromCurrentLocationToUrl(url)), delayMs);\n}\n"],"mappings":";;;;;;;;;;AASA,SAAgB,4CAA4C,KAAa;CACrE,MAAM,cAAc,GAAG,OAAO,SAAS,WAAW,OAAO,SAAS,SAAS,OAAO,SAAS;AAC3F,QAAO,yBAAyB,KAAK,YAAY;;;;;;;;;;;;AAarD,SAAgB,8CAA8C,KAAa,SAAkB;AACzF,KAAI,YAAY,OAAW,QAAO,SAAS,OAAO,4CAA4C,IAAI,CAAC;KAC9F,QAAO,iBAAiB,OAAO,SAAS,OAAO,4CAA4C,IAAI,CAAC,EAAE,QAAQ"}
|