@kikiutils/shared 15.0.1 → 15.0.2
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 +46 -119
- package/dist/crypto-hash.d.ts +145 -0
- package/dist/crypto-hash.d.ts.map +1 -1
- package/dist/crypto-hash.js +137 -7
- package/dist/crypto-hash.js.map +1 -1
- package/dist/datetime.d.ts +0 -2
- package/dist/datetime.d.ts.map +1 -1
- package/dist/datetime.js +0 -2
- package/dist/datetime.js.map +1 -1
- package/dist/env.d.ts +2 -0
- package/dist/env.d.ts.map +1 -1
- package/dist/env.js +2 -0
- package/dist/env.js.map +1 -1
- package/dist/event-awaiter.js +1 -1
- package/dist/event-awaiter.js.map +1 -1
- package/dist/hash.d.ts +48 -5
- package/dist/hash.d.ts.map +1 -1
- package/dist/hash.js +49 -6
- package/dist/hash.js.map +1 -1
- package/dist/math.js +1 -1
- package/dist/math.js.map +1 -1
- package/dist/object.d.ts +4 -0
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +4 -0
- package/dist/object.js.map +1 -1
- package/dist/random.js +2 -0
- package/dist/random.js.map +1 -1
- package/dist/storages/lru/keyed-store.d.ts +22 -0
- package/dist/storages/lru/keyed-store.d.ts.map +1 -1
- package/dist/storages/lru/keyed-store.js +22 -0
- package/dist/storages/lru/keyed-store.js.map +1 -1
- package/dist/storages/redis/keyed-store.d.ts +25 -0
- package/dist/storages/redis/keyed-store.d.ts.map +1 -1
- package/dist/storages/redis/keyed-store.js +25 -0
- package/dist/storages/redis/keyed-store.js.map +1 -1
- package/dist/storages/redis/msgpack.d.ts +20 -0
- package/dist/storages/redis/msgpack.d.ts.map +1 -1
- package/dist/storages/redis/msgpack.js +20 -0
- package/dist/storages/redis/msgpack.js.map +1 -1
- package/dist/storages/redis/types.d.ts +42 -0
- package/dist/storages/redis/types.d.ts.map +1 -1
- package/dist/time.d.ts +17 -0
- package/dist/time.d.ts.map +1 -1
- package/dist/time.js +17 -0
- package/dist/time.js.map +1 -1
- package/dist/url.d.ts +3 -0
- package/dist/url.d.ts.map +1 -1
- package/dist/url.js +8 -2
- package/dist/url.js.map +1 -1
- package/dist/vue.d.ts +6 -0
- package/dist/vue.d.ts.map +1 -1
- package/dist/vue.js +6 -0
- package/dist/vue.js.map +1 -1
- package/package.json +2 -2
- package/src/crypto-hash.ts +143 -14
- package/src/datetime.ts +0 -2
- package/src/env.ts +2 -0
- package/src/event-awaiter.ts +1 -1
- package/src/hash.ts +56 -14
- package/src/math.ts +2 -1
- package/src/object.ts +4 -0
- package/src/random.ts +3 -0
- package/src/storages/lru/keyed-store.ts +22 -0
- package/src/storages/redis/keyed-store.ts +25 -0
- package/src/storages/redis/msgpack.ts +20 -0
- package/src/storages/redis/types.ts +52 -0
- package/src/time.ts +17 -0
- package/src/url.ts +13 -2
- package/src/vue.ts +6 -0
|
@@ -1,19 +1,71 @@
|
|
|
1
1
|
import type { Nullable } from '../../types';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Low-level Redis-like adapter interface for raw buffer operations.
|
|
5
|
+
*/
|
|
3
6
|
export interface RedisLikeAdapter {
|
|
7
|
+
/**
|
|
8
|
+
* Deletes a key and returns the number of keys deleted.
|
|
9
|
+
*/
|
|
4
10
|
delete: (key: string) => Promise<number>;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Gets the raw buffer value for a key.
|
|
14
|
+
*/
|
|
5
15
|
getBuffer: (key: string) => Promise<Nullable<Uint8Array>>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Checks if a key exists.
|
|
19
|
+
*/
|
|
6
20
|
has: (key: string) => Promise<boolean>;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Sets a raw buffer value for a key.
|
|
24
|
+
*/
|
|
7
25
|
setBuffer: (key: string, value: Uint8Array) => Promise<'OK' | void>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Sets a raw buffer value for a key with a TTL.
|
|
29
|
+
*/
|
|
8
30
|
setBufferEx: (key: string, ttlSeconds: number, value: Uint8Array) => Promise<'OK' | void>;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Gets the TTL of a key in seconds.
|
|
34
|
+
*/
|
|
9
35
|
ttl: (key: string) => Promise<number>;
|
|
10
36
|
}
|
|
11
37
|
|
|
38
|
+
/**
|
|
39
|
+
* High-level Redis-like storage interface with typed get/set operations.
|
|
40
|
+
*/
|
|
12
41
|
export interface RedisLikeStorage {
|
|
42
|
+
/**
|
|
43
|
+
* Gets a deserialized value by key.
|
|
44
|
+
*/
|
|
13
45
|
getItem: <T = unknown>(key: string) => Promise<Nullable<T>>;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Gets the TTL of a key in seconds.
|
|
49
|
+
*/
|
|
14
50
|
getItemTtl: (key: string) => Promise<number>;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Checks if a key exists.
|
|
54
|
+
*/
|
|
15
55
|
hasItem: (key: string) => Promise<boolean>;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Removes a key.
|
|
59
|
+
*/
|
|
16
60
|
removeItem: (key: string) => Promise<boolean>;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Sets a value for a key.
|
|
64
|
+
*/
|
|
17
65
|
setItem: (key: string, value: any) => Promise<boolean>;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Sets a value for a key with a TTL.
|
|
69
|
+
*/
|
|
18
70
|
setItemWithTtl: (key: string, ttlSeconds: number, value: any) => Promise<boolean>;
|
|
19
71
|
}
|
package/src/time.ts
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a delay that can be aborted via AbortSignal.
|
|
3
|
+
*
|
|
4
|
+
* @param {number} ms - Delay duration in milliseconds
|
|
5
|
+
* @param {AbortSignal} [signal] - Optional AbortSignal to cancel the delay
|
|
6
|
+
*
|
|
7
|
+
* @returns {Promise<undefined>} A promise that resolves after ms or resolves immediately on abort
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { abortableDelay } from '@kikiutils/shared/time';
|
|
12
|
+
*
|
|
13
|
+
* const controller = new AbortController();
|
|
14
|
+
* setTimeout(() => controller.abort(), 1000);
|
|
15
|
+
* await abortableDelay(5000, controller.signal); // resolves after ~1s when aborted
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
1
18
|
export function abortableDelay(ms: number, signal?: AbortSignal) {
|
|
2
19
|
return new Promise((resolve) => {
|
|
3
20
|
const timeout = setTimeout(resolve, ms);
|
package/src/url.ts
CHANGED
|
@@ -5,12 +5,23 @@
|
|
|
5
5
|
*
|
|
6
6
|
* @param {string} url - The target URL to modify
|
|
7
7
|
* @param {string} redirectPath - The path to use as the redirect destination
|
|
8
|
+
* (must be an absolute path starting with '/')
|
|
8
9
|
*
|
|
9
10
|
* @returns {string} A new URL string with the `redirect` query parameter
|
|
11
|
+
*
|
|
12
|
+
* @throws {Error} If redirectPath is not a valid relative path (must start with '/')
|
|
10
13
|
*/
|
|
11
14
|
export function appendRedirectParamToUrl(url: string, redirectPath: string) {
|
|
12
|
-
|
|
15
|
+
if (!redirectPath.startsWith('/')) {
|
|
16
|
+
throw new Error(
|
|
17
|
+
`Invalid redirect path: "${redirectPath}". Redirect paths must be absolute paths starting with '/'.`,
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const [baseAndHash, rawQuery = ''] = url.split('?');
|
|
22
|
+
const [base, hash] = (baseAndHash || '').split('#');
|
|
13
23
|
const searchParams = new URLSearchParams(rawQuery);
|
|
14
24
|
searchParams.set('redirect', redirectPath);
|
|
15
|
-
|
|
25
|
+
const queryString = searchParams.toString();
|
|
26
|
+
return hash ? `${base}?${queryString}#${hash}` : `${base}?${queryString}`;
|
|
16
27
|
}
|
package/src/vue.ts
CHANGED
|
@@ -43,6 +43,12 @@ export function clearTimeoutRef(timeoutRef: Ref<Nullable<ReturnType<typeof setTi
|
|
|
43
43
|
* A Vue composition function that remembers and restores scroll position
|
|
44
44
|
* of a scrollable container across route changes and keep-alive activation.
|
|
45
45
|
*
|
|
46
|
+
* Designed for use with `<KeepAlive>` components. Scroll state is saved on
|
|
47
|
+
* route leave and restored when the component is activated again.
|
|
48
|
+
*
|
|
49
|
+
* Note: Without `<KeepAlive>`, the component state is destroyed on unmount,
|
|
50
|
+
* so scroll position will not be preserved.
|
|
51
|
+
*
|
|
46
52
|
* @template T - The type of the scrollable element (defaults to HTMLElement)
|
|
47
53
|
*
|
|
48
54
|
* @param {Ref<Nullable<T>>} containerRef - A ref to the scrollable HTML element
|