@kikiutils/shared 18.0.0 → 18.1.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/buffer.d.ts +19 -21
- package/dist/buffer.d.ts.map +1 -1
- package/dist/buffer.js +18 -19
- package/dist/buffer.js.map +1 -1
- package/dist/classes/enhanced-date.d.ts +425 -0
- package/dist/classes/enhanced-date.d.ts.map +1 -0
- package/dist/classes/enhanced-date.js +591 -0
- package/dist/classes/enhanced-date.js.map +1 -0
- package/dist/classes/path.d.ts +211 -48
- package/dist/classes/path.d.ts.map +1 -1
- package/dist/classes/path.js +181 -52
- package/dist/classes/path.js.map +1 -1
- package/dist/classes/precision-number.d.ts +44 -39
- package/dist/classes/precision-number.d.ts.map +1 -1
- package/dist/classes/precision-number.js +51 -45
- package/dist/classes/precision-number.js.map +1 -1
- package/dist/classes/ssh-client.d.ts +3 -4
- package/dist/classes/ssh-client.d.ts.map +1 -1
- package/dist/classes/ssh-client.js +2 -2
- package/dist/classes/ssh-client.js.map +1 -1
- package/dist/clipboard.d.ts +25 -26
- package/dist/clipboard.d.ts.map +1 -1
- package/dist/clipboard.js +23 -23
- package/dist/clipboard.js.map +1 -1
- package/dist/consola.d.ts +12 -15
- package/dist/consola.d.ts.map +1 -1
- package/dist/consola.js +10 -12
- package/dist/consola.js.map +1 -1
- package/dist/crypto-hash.d.ts +65 -56
- package/dist/crypto-hash.d.ts.map +1 -1
- package/dist/crypto-hash.js +55 -45
- package/dist/crypto-hash.js.map +1 -1
- package/dist/datetime.d.ts +41 -53
- package/dist/datetime.d.ts.map +1 -1
- package/dist/datetime.js +53 -66
- package/dist/datetime.js.map +1 -1
- package/dist/element-plus.d.ts +13 -14
- package/dist/element-plus.d.ts.map +1 -1
- package/dist/element-plus.js +11 -11
- package/dist/element-plus.js.map +1 -1
- package/dist/enum.d.ts +39 -36
- package/dist/enum.d.ts.map +1 -1
- package/dist/enum.js +36 -32
- package/dist/enum.js.map +1 -1
- package/dist/env.d.ts +22 -15
- package/dist/env.d.ts.map +1 -1
- package/dist/env.js +20 -12
- package/dist/env.js.map +1 -1
- package/dist/event-awaiter.d.ts +47 -52
- package/dist/event-awaiter.d.ts.map +1 -1
- package/dist/event-awaiter.js +46 -50
- package/dist/event-awaiter.js.map +1 -1
- package/dist/general.d.ts +22 -17
- package/dist/general.d.ts.map +1 -1
- package/dist/general.js.map +1 -1
- package/dist/hash.d.ts +24 -21
- package/dist/hash.d.ts.map +1 -1
- package/dist/hash.js +20 -16
- package/dist/hash.js.map +1 -1
- package/dist/math.d.ts +20 -19
- package/dist/math.d.ts.map +1 -1
- package/dist/math.js +14 -12
- package/dist/math.js.map +1 -1
- package/dist/number.d.ts +10 -9
- package/dist/number.d.ts.map +1 -1
- package/dist/number.js +9 -7
- package/dist/number.js.map +1 -1
- package/dist/object.d.ts +22 -10
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +21 -8
- package/dist/object.js.map +1 -1
- package/dist/pino.d.ts +12 -15
- package/dist/pino.d.ts.map +1 -1
- package/dist/pino.js +10 -15
- package/dist/pino.js.map +1 -1
- package/dist/random.d.ts +17 -15
- package/dist/random.d.ts.map +1 -1
- package/dist/random.js +16 -13
- package/dist/random.js.map +1 -1
- package/dist/redis/script-runner.d.ts +57 -0
- package/dist/redis/script-runner.d.ts.map +1 -0
- package/dist/redis/script-runner.js +46 -0
- package/dist/redis/script-runner.js.map +1 -0
- package/dist/storages/lru/keyed-store.d.ts +18 -14
- package/dist/storages/lru/keyed-store.d.ts.map +1 -1
- package/dist/storages/lru/keyed-store.js +17 -12
- package/dist/storages/lru/keyed-store.js.map +1 -1
- package/dist/storages/redis/keyed-store.d.ts +11 -21
- package/dist/storages/redis/keyed-store.d.ts.map +1 -1
- package/dist/storages/redis/keyed-store.js +10 -19
- package/dist/storages/redis/keyed-store.js.map +1 -1
- package/dist/storages/redis/msgpack.d.ts +33 -13
- package/dist/storages/redis/msgpack.d.ts.map +1 -1
- package/dist/storages/redis/msgpack.js +32 -11
- package/dist/storages/redis/msgpack.js.map +1 -1
- package/dist/storages/redis/types.d.ts +34 -17
- package/dist/storages/redis/types.d.ts.map +1 -1
- package/dist/string.d.ts +12 -11
- package/dist/string.d.ts.map +1 -1
- package/dist/string.js +20 -15
- package/dist/string.js.map +1 -1
- package/dist/time.d.ts +35 -10
- package/dist/time.d.ts.map +1 -1
- package/dist/time.js +49 -9
- package/dist/time.js.map +1 -1
- package/dist/types/filtered-key-path.d.ts +4 -15
- package/dist/types/filtered-key-path.d.ts.map +1 -1
- package/dist/types/index.d.ts +10 -10
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/vue.d.ts +7 -7
- package/dist/types/vue.d.ts.map +1 -1
- package/dist/url.d.ts +15 -14
- package/dist/url.d.ts.map +1 -1
- package/dist/url.js +12 -10
- package/dist/url.js.map +1 -1
- package/dist/vue.d.ts +19 -21
- package/dist/vue.d.ts.map +1 -1
- package/dist/vue.js +15 -16
- package/dist/vue.js.map +1 -1
- package/dist/web.d.ts +14 -11
- package/dist/web.d.ts.map +1 -1
- package/dist/web.js +12 -8
- package/dist/web.js.map +1 -1
- package/package.json +20 -20
- package/src/buffer.ts +18 -19
- package/src/classes/enhanced-date.ts +665 -0
- package/src/classes/path.ts +232 -91
- package/src/classes/precision-number.ts +61 -53
- package/src/classes/ssh-client.ts +8 -5
- package/src/clipboard.ts +23 -23
- package/src/consola.ts +10 -12
- package/src/crypto-hash.ts +55 -45
- package/src/datetime.ts +65 -85
- package/src/element-plus.ts +11 -11
- package/src/enum.ts +36 -32
- package/src/env.ts +20 -12
- package/src/event-awaiter.ts +49 -50
- package/src/general.ts +20 -14
- package/src/hash.ts +20 -16
- package/src/math.ts +18 -16
- package/src/number.ts +9 -7
- package/src/object.ts +21 -8
- package/src/pino.ts +11 -15
- package/src/random.ts +16 -13
- package/src/redis/script-runner.ts +107 -0
- package/src/storages/lru/keyed-store.ts +17 -12
- package/src/storages/redis/keyed-store.ts +10 -19
- package/src/storages/redis/msgpack.ts +32 -11
- package/src/storages/redis/types.ts +32 -14
- package/src/string.ts +10 -8
- package/src/time.ts +52 -8
- package/src/types/filtered-key-path.ts +9 -14
- package/src/types/vue.ts +6 -5
- package/src/url.ts +12 -10
- package/src/vue.ts +15 -16
- package/src/web.ts +12 -8
package/dist/enum.js
CHANGED
|
@@ -2,24 +2,25 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Extracts only the numeric values from an enumeration-like object.
|
|
4
4
|
*
|
|
5
|
-
* @
|
|
5
|
+
* @typeParam T - The type of the enum object.
|
|
6
6
|
*
|
|
7
|
-
* @param
|
|
7
|
+
* @param enumObject - The enumeration-like object to extract numeric values from,
|
|
8
8
|
* the object can contain numeric values, string values, or both.
|
|
9
9
|
*
|
|
10
|
-
* @returns
|
|
10
|
+
* @returns An array of numeric values extracted from the enum object.
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
|
-
*
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
14
15
|
* import { getEnumNumberValues } from '@kikiutils/shared/enum';
|
|
15
16
|
*
|
|
16
17
|
* enum RecordType {
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
18
|
+
* Receive = 0,
|
|
19
|
+
* Send = 1,
|
|
20
|
+
* Unknown = 'unknown',
|
|
20
21
|
* }
|
|
21
22
|
*
|
|
22
|
-
* console.log(getEnumNumberValues(RecordType)); // [0, 1]
|
|
23
|
+
* console.log(getEnumNumberValues(RecordType)); // => [0, 1]
|
|
23
24
|
* ```
|
|
24
25
|
*/
|
|
25
26
|
function getEnumNumberValues(enumObject) {
|
|
@@ -28,24 +29,25 @@ function getEnumNumberValues(enumObject) {
|
|
|
28
29
|
/**
|
|
29
30
|
* Extracts only the string values from an enumeration-like object.
|
|
30
31
|
*
|
|
31
|
-
* @
|
|
32
|
+
* @typeParam T - The type of the enum object.
|
|
32
33
|
*
|
|
33
|
-
* @param
|
|
34
|
+
* @param enumObject - The enumeration-like object to extract string values from,
|
|
34
35
|
* the object can contain numeric values, string values, or both.
|
|
35
36
|
*
|
|
36
|
-
* @returns
|
|
37
|
+
* @returns An array of string values extracted from the enum object.
|
|
37
38
|
*
|
|
38
39
|
* @example
|
|
39
|
-
*
|
|
40
|
+
*
|
|
41
|
+
* ```ts
|
|
40
42
|
* import { getEnumStringValues } from '@kikiutils/shared/enum';
|
|
41
43
|
*
|
|
42
44
|
* enum RecordType {
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
45
|
+
* Receive = 0,
|
|
46
|
+
* Send = 1,
|
|
47
|
+
* Unknown = 'unknown',
|
|
46
48
|
* }
|
|
47
49
|
*
|
|
48
|
-
* console.log(getEnumStringValues(RecordType)); // ['unknown']
|
|
50
|
+
* console.log(getEnumStringValues(RecordType)); // => ['unknown']
|
|
49
51
|
* ```
|
|
50
52
|
*/
|
|
51
53
|
function getEnumStringValues(enumObject) {
|
|
@@ -54,47 +56,49 @@ function getEnumStringValues(enumObject) {
|
|
|
54
56
|
/**
|
|
55
57
|
* Extracts all values from an enumeration-like object.
|
|
56
58
|
*
|
|
59
|
+
* @remarks
|
|
57
60
|
* This function handles TypeScript enums correctly by accounting for the reverse mapping
|
|
58
61
|
* that occurs with numeric enums. It works with pure numeric enums, pure string enums,
|
|
59
62
|
* and mixed enums.
|
|
60
63
|
*
|
|
61
|
-
* @
|
|
64
|
+
* @typeParam T - The type of the enum object.
|
|
62
65
|
*
|
|
63
|
-
* @param
|
|
66
|
+
* @param enumObject - The enumeration-like object to extract values from,
|
|
64
67
|
* the object can contain numeric values, string values, or both.
|
|
65
68
|
*
|
|
66
|
-
* @returns
|
|
69
|
+
* @returns An array containing all the values from the enum object.
|
|
67
70
|
*
|
|
68
71
|
* @example
|
|
69
|
-
*
|
|
72
|
+
*
|
|
73
|
+
* ```ts
|
|
70
74
|
* import { getEnumValues } from '@kikiutils/shared/enum';
|
|
71
75
|
*
|
|
72
76
|
* // Numeric enum
|
|
73
77
|
* enum Status {
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
78
|
+
* Active = 0,
|
|
79
|
+
* Inactive = 1,
|
|
80
|
+
* Pending = 2,
|
|
77
81
|
* }
|
|
78
82
|
*
|
|
79
|
-
* console.log(getEnumValues(Status)); // [0, 1, 2]
|
|
83
|
+
* console.log(getEnumValues(Status)); // => [0, 1, 2]
|
|
80
84
|
*
|
|
81
85
|
* // String enum
|
|
82
86
|
* enum Color {
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
87
|
+
* Red = 'RED',
|
|
88
|
+
* Green = 'GREEN',
|
|
89
|
+
* Blue = 'BLUE',
|
|
86
90
|
* }
|
|
87
91
|
*
|
|
88
|
-
* console.log(getEnumValues(Color)); // ['RED', 'GREEN', 'BLUE']
|
|
92
|
+
* console.log(getEnumValues(Color)); // => ['RED', 'GREEN', 'BLUE']
|
|
89
93
|
*
|
|
90
94
|
* // Mixed enum
|
|
91
95
|
* enum RecordType {
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
96
|
+
* Receive = 0,
|
|
97
|
+
* Send = 1,
|
|
98
|
+
* Unknown = 'unknown',
|
|
95
99
|
* }
|
|
96
100
|
*
|
|
97
|
-
* console.log(getEnumValues(RecordType)); // [0, 1, 'unknown']
|
|
101
|
+
* console.log(getEnumValues(RecordType)); // => [0, 1, 'unknown']
|
|
98
102
|
* ```
|
|
99
103
|
*/
|
|
100
104
|
function getEnumValues(enumObject) {
|
package/dist/enum.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enum.js","names":[],"sources":["../src/enum.ts"],"sourcesContent":["/**\n * Extracts only the numeric values from an enumeration-like object.\n *\n * @
|
|
1
|
+
{"version":3,"file":"enum.js","names":[],"sources":["../src/enum.ts"],"sourcesContent":["/**\n * Extracts only the numeric values from an enumeration-like object.\n *\n * @typeParam T - The type of the enum object.\n *\n * @param enumObject - The enumeration-like object to extract numeric values from,\n * the object can contain numeric values, string values, or both.\n *\n * @returns An array of numeric values extracted from the enum object.\n *\n * @example\n *\n * ```ts\n * import { getEnumNumberValues } from '@kikiutils/shared/enum';\n *\n * enum RecordType {\n * Receive = 0,\n * Send = 1,\n * Unknown = 'unknown',\n * }\n *\n * console.log(getEnumNumberValues(RecordType)); // => [0, 1]\n * ```\n */\nexport function getEnumNumberValues<T extends Record<string, any>>(enumObject: T): Extract<T[keyof T], number>[] {\n return getEnumValues(enumObject).filter((value) => typeof value === 'number');\n}\n\n/**\n * Extracts only the string values from an enumeration-like object.\n *\n * @typeParam T - The type of the enum object.\n *\n * @param enumObject - The enumeration-like object to extract string values from,\n * the object can contain numeric values, string values, or both.\n *\n * @returns An array of string values extracted from the enum object.\n *\n * @example\n *\n * ```ts\n * import { getEnumStringValues } from '@kikiutils/shared/enum';\n *\n * enum RecordType {\n * Receive = 0,\n * Send = 1,\n * Unknown = 'unknown',\n * }\n *\n * console.log(getEnumStringValues(RecordType)); // => ['unknown']\n * ```\n */\nexport function getEnumStringValues<T extends Record<string, any>>(enumObject: T): Extract<T[keyof T], string>[] {\n return getEnumValues(enumObject).filter((value) => typeof value === 'string');\n}\n\n/**\n * Extracts all values from an enumeration-like object.\n *\n * @remarks\n * This function handles TypeScript enums correctly by accounting for the reverse mapping\n * that occurs with numeric enums. It works with pure numeric enums, pure string enums,\n * and mixed enums.\n *\n * @typeParam T - The type of the enum object.\n *\n * @param enumObject - The enumeration-like object to extract values from,\n * the object can contain numeric values, string values, or both.\n *\n * @returns An array containing all the values from the enum object.\n *\n * @example\n *\n * ```ts\n * import { getEnumValues } from '@kikiutils/shared/enum';\n *\n * // Numeric enum\n * enum Status {\n * Active = 0,\n * Inactive = 1,\n * Pending = 2,\n * }\n *\n * console.log(getEnumValues(Status)); // => [0, 1, 2]\n *\n * // String enum\n * enum Color {\n * Red = 'RED',\n * Green = 'GREEN',\n * Blue = 'BLUE',\n * }\n *\n * console.log(getEnumValues(Color)); // => ['RED', 'GREEN', 'BLUE']\n *\n * // Mixed enum\n * enum RecordType {\n * Receive = 0,\n * Send = 1,\n * Unknown = 'unknown',\n * }\n *\n * console.log(getEnumValues(RecordType)); // => [0, 1, 'unknown']\n * ```\n */\nexport function getEnumValues<T extends Record<string, any>>(enumObject: T): (T[keyof T])[] {\n const values = Object.values(enumObject);\n const hasNumberValues = values.some((value) => typeof value === 'number');\n if (!hasNumberValues) return values;\n return Object.keys(enumObject).filter((key) => Number.isNaN(Number(key))).map((key) => enumObject[key]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,SAAgB,oBAAmD,YAA8C;CAC7G,OAAO,cAAc,UAAU,CAAC,CAAC,QAAQ,UAAU,OAAO,UAAU,QAAQ;AAChF;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,SAAgB,oBAAmD,YAA8C;CAC7G,OAAO,cAAc,UAAU,CAAC,CAAC,QAAQ,UAAU,OAAO,UAAU,QAAQ;AAChF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDA,SAAgB,cAA6C,YAA+B;CACxF,MAAM,SAAS,OAAO,OAAO,UAAU;CAEvC,IAAI,CADoB,OAAO,MAAM,UAAU,OAAO,UAAU,QAC7C,GAAG,OAAO;CAC7B,OAAO,OAAO,KAAK,UAAU,CAAC,CAAC,QAAQ,QAAQ,OAAO,MAAM,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,QAAQ,WAAW,IAAI;AAC1G"}
|
package/dist/env.d.ts
CHANGED
|
@@ -2,43 +2,50 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Custom error class for handling missing environment variables.
|
|
4
4
|
*
|
|
5
|
+
* @remarks
|
|
5
6
|
* Extends the built-in `Error` class and includes the missing key.
|
|
6
|
-
*
|
|
7
|
-
* @extends {Error}
|
|
8
7
|
*/
|
|
9
|
-
declare class EnvironmentNotFoundError extends Error {
|
|
8
|
+
export declare class EnvironmentNotFoundError extends Error {
|
|
10
9
|
readonly key: string;
|
|
11
10
|
/**
|
|
12
|
-
* Creates a
|
|
11
|
+
* Creates an error identifying a missing environment variable.
|
|
13
12
|
*
|
|
14
|
-
* @param
|
|
13
|
+
* @param key - The missing environment variable key.
|
|
15
14
|
*/
|
|
16
15
|
constructor(key: string);
|
|
17
16
|
}
|
|
18
17
|
/**
|
|
19
18
|
* Retrieves the value of an environment variable, or throws an error if it is not defined.
|
|
20
19
|
*
|
|
21
|
-
*
|
|
20
|
+
* @remarks
|
|
21
|
+
* Only checks for `process.env[key] === undefined`. An empty string (for example `''`) or any falsy string
|
|
22
22
|
* value like `'0'` or `'false'` is considered a valid (defined) value.
|
|
23
23
|
*
|
|
24
|
-
* @param
|
|
24
|
+
* @param key - The environment variable key to retrieve.
|
|
25
25
|
*
|
|
26
|
-
* @returns
|
|
26
|
+
* @returns The value of the environment variable.
|
|
27
27
|
*
|
|
28
|
-
* @throws
|
|
28
|
+
* @throws EnvironmentNotFoundError if the environment variable is not defined.
|
|
29
29
|
*
|
|
30
30
|
* @example
|
|
31
|
-
*
|
|
32
|
-
*
|
|
31
|
+
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* import {
|
|
34
|
+
* checkAndGetEnvValue,
|
|
35
|
+
* EnvironmentNotFoundError,
|
|
36
|
+
* } from '@kikiutils/shared/env';
|
|
33
37
|
*
|
|
34
38
|
* process.env.API_KEY = '';
|
|
35
|
-
* checkAndGetEnvValue('API_KEY'); //
|
|
39
|
+
* checkAndGetEnvValue('API_KEY'); // => ''
|
|
36
40
|
*
|
|
37
41
|
* delete process.env.API_KEY;
|
|
38
|
-
*
|
|
42
|
+
* try {
|
|
43
|
+
* checkAndGetEnvValue('API_KEY');
|
|
44
|
+
* } catch (error) {
|
|
45
|
+
* console.log(error instanceof EnvironmentNotFoundError); // => true
|
|
46
|
+
* }
|
|
39
47
|
* ```
|
|
40
48
|
*/
|
|
41
|
-
declare function checkAndGetEnvValue(key: string): string;
|
|
49
|
+
export declare function checkAndGetEnvValue(key: string): string;
|
|
42
50
|
//#endregion
|
|
43
|
-
export { EnvironmentNotFoundError, checkAndGetEnvValue };
|
|
44
51
|
//# sourceMappingURL=env.d.ts.map
|
package/dist/env.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.d.ts","names":[],"sources":["../src/env.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"env.d.ts","names":[],"sources":["../src/env.ts"],"mappings":";;;;;;;qBAMa,iCAAiC;WACjC;;;;;;EAOG,YAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAwCA,oBAAoB"}
|
package/dist/env.js
CHANGED
|
@@ -2,16 +2,15 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Custom error class for handling missing environment variables.
|
|
4
4
|
*
|
|
5
|
+
* @remarks
|
|
5
6
|
* Extends the built-in `Error` class and includes the missing key.
|
|
6
|
-
*
|
|
7
|
-
* @extends {Error}
|
|
8
7
|
*/
|
|
9
8
|
var EnvironmentNotFoundError = class extends Error {
|
|
10
9
|
key;
|
|
11
10
|
/**
|
|
12
|
-
* Creates a
|
|
11
|
+
* Creates an error identifying a missing environment variable.
|
|
13
12
|
*
|
|
14
|
-
* @param
|
|
13
|
+
* @param key - The missing environment variable key.
|
|
15
14
|
*/
|
|
16
15
|
constructor(key) {
|
|
17
16
|
super(`Missing environment variable: ${key}`);
|
|
@@ -23,24 +22,33 @@ var EnvironmentNotFoundError = class extends Error {
|
|
|
23
22
|
/**
|
|
24
23
|
* Retrieves the value of an environment variable, or throws an error if it is not defined.
|
|
25
24
|
*
|
|
26
|
-
*
|
|
25
|
+
* @remarks
|
|
26
|
+
* Only checks for `process.env[key] === undefined`. An empty string (for example `''`) or any falsy string
|
|
27
27
|
* value like `'0'` or `'false'` is considered a valid (defined) value.
|
|
28
28
|
*
|
|
29
|
-
* @param
|
|
29
|
+
* @param key - The environment variable key to retrieve.
|
|
30
30
|
*
|
|
31
|
-
* @returns
|
|
31
|
+
* @returns The value of the environment variable.
|
|
32
32
|
*
|
|
33
|
-
* @throws
|
|
33
|
+
* @throws EnvironmentNotFoundError if the environment variable is not defined.
|
|
34
34
|
*
|
|
35
35
|
* @example
|
|
36
|
-
*
|
|
37
|
-
*
|
|
36
|
+
*
|
|
37
|
+
* ```ts
|
|
38
|
+
* import {
|
|
39
|
+
* checkAndGetEnvValue,
|
|
40
|
+
* EnvironmentNotFoundError,
|
|
41
|
+
* } from '@kikiutils/shared/env';
|
|
38
42
|
*
|
|
39
43
|
* process.env.API_KEY = '';
|
|
40
|
-
* checkAndGetEnvValue('API_KEY'); //
|
|
44
|
+
* checkAndGetEnvValue('API_KEY'); // => ''
|
|
41
45
|
*
|
|
42
46
|
* delete process.env.API_KEY;
|
|
43
|
-
*
|
|
47
|
+
* try {
|
|
48
|
+
* checkAndGetEnvValue('API_KEY');
|
|
49
|
+
* } catch (error) {
|
|
50
|
+
* console.log(error instanceof EnvironmentNotFoundError); // => true
|
|
51
|
+
* }
|
|
44
52
|
* ```
|
|
45
53
|
*/
|
|
46
54
|
function checkAndGetEnvValue(key) {
|
package/dist/env.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.js","names":[],"sources":["../src/env.ts"],"sourcesContent":["/**\n * Custom error class for handling missing environment variables.\n *\n * Extends the built-in `Error` class and includes the missing key.\n
|
|
1
|
+
{"version":3,"file":"env.js","names":[],"sources":["../src/env.ts"],"sourcesContent":["/**\n * Custom error class for handling missing environment variables.\n *\n * @remarks\n * Extends the built-in `Error` class and includes the missing key.\n */\nexport class EnvironmentNotFoundError extends Error {\n readonly key: string;\n\n /**\n * Creates an error identifying a missing environment variable.\n *\n * @param key - The missing environment variable key.\n */\n constructor(key: string) {\n super(`Missing environment variable: ${key}`);\n this.key = key;\n this.name = this.constructor.name;\n Error.captureStackTrace?.(this, this.constructor);\n }\n}\n\n/**\n * Retrieves the value of an environment variable, or throws an error if it is not defined.\n *\n * @remarks\n * Only checks for `process.env[key] === undefined`. An empty string (for example `''`) or any falsy string\n * value like `'0'` or `'false'` is considered a valid (defined) value.\n *\n * @param key - The environment variable key to retrieve.\n *\n * @returns The value of the environment variable.\n *\n * @throws EnvironmentNotFoundError if the environment variable is not defined.\n *\n * @example\n *\n * ```ts\n * import {\n * checkAndGetEnvValue,\n * EnvironmentNotFoundError,\n * } from '@kikiutils/shared/env';\n *\n * process.env.API_KEY = '';\n * checkAndGetEnvValue('API_KEY'); // => ''\n *\n * delete process.env.API_KEY;\n * try {\n * checkAndGetEnvValue('API_KEY');\n * } catch (error) {\n * console.log(error instanceof EnvironmentNotFoundError); // => true\n * }\n * ```\n */\nexport function checkAndGetEnvValue(key: string) {\n if (process.env[key] === undefined) throw new EnvironmentNotFoundError(key);\n return process.env[key];\n}\n"],"mappings":";;;;;;;AAMA,IAAa,2BAAb,cAA8C,MAAM;CAChD;;;;;;CAOA,YAAY,KAAa;EACrB,MAAM,iCAAiC,KAAK;EAC5C,KAAK,MAAM;EACX,KAAK,OAAO,KAAK,YAAY;EAC7B,MAAM,oBAAoB,MAAM,KAAK,WAAW;CACpD;AACJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,SAAgB,oBAAoB,KAAa;CAC7C,IAAI,QAAQ,IAAI,SAAS,KAAA,GAAW,MAAM,IAAI,yBAAyB,GAAG;CAC1E,OAAO,QAAQ,IAAI;AACvB"}
|
package/dist/event-awaiter.d.ts
CHANGED
|
@@ -1,84 +1,79 @@
|
|
|
1
1
|
//#region src/event-awaiter.d.ts
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* An asynchronous keyed event rendezvous for one or more waiting consumers.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Triggers resolve the currently registered waiters; values are not retained for future waits.
|
|
7
|
+
* Timeouts and subsequent abort events resolve affected waiters with `undefined`.
|
|
8
|
+
* Use `triggerAll` to resolve pending waits during cleanup. Timers and abort listeners are not proactively
|
|
9
|
+
* removed by triggers, so they may remain until their timeout or abort event occurs.
|
|
8
10
|
*
|
|
9
|
-
*
|
|
10
|
-
* or implementing event-driven primitives in applications or services.
|
|
11
|
-
*
|
|
12
|
-
* @template T - The type of value that will be resolved when the event is triggered
|
|
11
|
+
* @typeParam T - The value delivered to waiting consumers.
|
|
13
12
|
*/
|
|
14
|
-
declare class EventAwaiter<T> {
|
|
13
|
+
export declare class EventAwaiter<T> {
|
|
15
14
|
#private;
|
|
16
15
|
/**
|
|
17
|
-
*
|
|
18
|
-
* Each promise will be resolved with the provided value.
|
|
16
|
+
* Resolves all currently pending waits for a key with the supplied value.
|
|
19
17
|
*
|
|
20
|
-
* @param
|
|
21
|
-
* @param
|
|
22
|
-
* May be `undefined` to indicate no result or a timeout-like behavior.
|
|
18
|
+
* @param key - The event identifier; a key without pending waits has no effect.
|
|
19
|
+
* @param value - The delivered value; `undefined` indicates no result.
|
|
23
20
|
*/
|
|
24
21
|
trigger(key: string, value: T | undefined): void;
|
|
25
22
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* This is typically used during shutdown or cleanup to ensure that
|
|
29
|
-
* no consumer is left waiting indefinitely.
|
|
23
|
+
* Resolves all currently pending waits and clears their registrations.
|
|
30
24
|
*
|
|
31
|
-
* @param
|
|
32
|
-
* Defaults to `undefined`, which usually indicates cancellation or shutdown.
|
|
25
|
+
* @param value - The delivered value; omission resolves all pending waits with `undefined`.
|
|
33
26
|
*/
|
|
34
27
|
triggerAll(value?: T | undefined): void;
|
|
35
28
|
/**
|
|
36
|
-
* Waits for
|
|
29
|
+
* Waits for a trigger associated with a key.
|
|
37
30
|
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
31
|
+
* @remarks
|
|
32
|
+
* By default, multiple waiters share a key and all receive the next trigger value.
|
|
33
|
+
* `strict` mode rejects duplicate waits; `override` mode resolves existing waits with `undefined` before
|
|
34
|
+
* registering the new wait. Timeout and abort remove only the affected waiter's registration.
|
|
35
|
+
* An already aborted signal is not checked; only an abort event emitted after registration ends the wait.
|
|
36
|
+
* Without a timeout or subsequent abort, the wait remains pending until a trigger arrives.
|
|
42
37
|
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* and only keeps the latest one.
|
|
38
|
+
* @param key - The event identifier to wait for.
|
|
39
|
+
* @param timeoutMs - The optional timeout in milliseconds, using native `setTimeout` timing rules.
|
|
40
|
+
* @param mode - The policy for existing waiters; omission allows multiple waiters.
|
|
41
|
+
* @param signal - A signal whose subsequent abort event ends this wait.
|
|
48
42
|
*
|
|
49
|
-
* @
|
|
50
|
-
* @param {number} [timeoutMs] - Optional timeout (in milliseconds).
|
|
51
|
-
* If reached, the promise resolves with `undefined`.
|
|
52
|
-
* @param {'override' | 'strict'} [mode] - Optional behavior mode for handling multiple waiters
|
|
53
|
-
* @param {AbortSignal} [signal] - Optional AbortSignal. If aborted, the promise resolves with `undefined`
|
|
43
|
+
* @returns A promise resolving to the triggered value, or `undefined` after timeout, abort, or replacement.
|
|
54
44
|
*
|
|
55
|
-
* @
|
|
56
|
-
* or `undefined` if timeout or abort occurs
|
|
45
|
+
* @throws Error through promise rejection if `strict` mode encounters an existing waiter.
|
|
57
46
|
*/
|
|
58
47
|
wait(key: string, timeoutMs?: number, mode?: 'override' | 'strict', signal?: AbortSignal): Promise<T | undefined>;
|
|
59
48
|
/**
|
|
60
|
-
* Waits for
|
|
61
|
-
*
|
|
62
|
-
*
|
|
49
|
+
* Waits for a key while rejecting duplicate registrations.
|
|
50
|
+
*
|
|
51
|
+
* @param key - The event identifier to wait for.
|
|
52
|
+
* @param timeoutMs - The optional timeout in milliseconds.
|
|
53
|
+
* @param signal - A signal whose subsequent abort event ends this wait; an already aborted signal is not checked.
|
|
54
|
+
*
|
|
55
|
+
* @returns A promise resolving to the triggered value, or `undefined` on timeout or subsequent abort.
|
|
63
56
|
*
|
|
64
|
-
* @
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
* @param {AbortSignal} [signal] - Optional AbortSignal. If aborted, the promise resolves with `undefined`
|
|
57
|
+
* @throws Error through promise rejection if the key already has a pending waiter.
|
|
58
|
+
*
|
|
59
|
+
* @see {@link EventAwaiter.wait}
|
|
68
60
|
*/
|
|
69
61
|
waitExclusive(key: string, timeoutMs?: number, signal?: AbortSignal): Promise<T | undefined>;
|
|
70
62
|
/**
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
63
|
+
* Replaces existing waiters for a key and waits for its next trigger.
|
|
64
|
+
*
|
|
65
|
+
* @remarks
|
|
66
|
+
* Existing waiters resolve with `undefined` before the new waiter is registered.
|
|
67
|
+
*
|
|
68
|
+
* @param key - The event identifier to wait for.
|
|
69
|
+
* @param timeoutMs - The optional timeout in milliseconds.
|
|
70
|
+
* @param signal - A signal whose subsequent abort event ends this wait; an already aborted signal is not checked.
|
|
71
|
+
*
|
|
72
|
+
* @returns A promise resolving to the triggered value, or `undefined` on timeout, subsequent abort, or replacement.
|
|
74
73
|
*
|
|
75
|
-
* @
|
|
76
|
-
* @param {number} [timeoutMs] - Optional timeout (in milliseconds).
|
|
77
|
-
* If reached, the promise resolves with `undefined`.
|
|
78
|
-
* @param {AbortSignal} [signal] - Optional AbortSignal. If aborted, the promise resolves with `undefined`
|
|
74
|
+
* @see {@link EventAwaiter.wait}
|
|
79
75
|
*/
|
|
80
76
|
waitLatest(key: string, timeoutMs?: number, signal?: AbortSignal): Promise<T | undefined>;
|
|
81
77
|
}
|
|
82
78
|
//#endregion
|
|
83
|
-
export { EventAwaiter };
|
|
84
79
|
//# sourceMappingURL=event-awaiter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-awaiter.d.ts","names":[],"sources":["../src/event-awaiter.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"event-awaiter.d.ts","names":[],"sources":["../src/event-awaiter.ts"],"mappings":";;;;;;;;;;;;qBAWa,aAAa;;;;;;;;EAYtB,QAAQ,aAAa,OAAO;;;;;;EAa5B,WAAW,QAAO;;;;;;;;;;;;;;;;;;;;EAwBlB,KAAK,aAAa,oBAAoB,8BAA8B,SAAS,cAAW,QAAA;;;;;;;;;;;;;;EA8DxF,cAAc,aAAa,oBAAoB,SAAS,cAAW,QAAA;;;;;;;;;;;;;;;EAkBnE,WAAW,aAAa,oBAAoB,SAAS,cAAW,QAAA"}
|
package/dist/event-awaiter.js
CHANGED
|
@@ -1,25 +1,22 @@
|
|
|
1
1
|
//#region src/event-awaiter.ts
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* An asynchronous keyed event rendezvous for one or more waiting consumers.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Triggers resolve the currently registered waiters; values are not retained for future waits.
|
|
7
|
+
* Timeouts and subsequent abort events resolve affected waiters with `undefined`.
|
|
8
|
+
* Use `triggerAll` to resolve pending waits during cleanup. Timers and abort listeners are not proactively
|
|
9
|
+
* removed by triggers, so they may remain until their timeout or abort event occurs.
|
|
8
10
|
*
|
|
9
|
-
*
|
|
10
|
-
* or implementing event-driven primitives in applications or services.
|
|
11
|
-
*
|
|
12
|
-
* @template T - The type of value that will be resolved when the event is triggered
|
|
11
|
+
* @typeParam T - The value delivered to waiting consumers.
|
|
13
12
|
*/
|
|
14
13
|
var EventAwaiter = class {
|
|
15
14
|
#promiseResolvers = /* @__PURE__ */ new Map();
|
|
16
15
|
/**
|
|
17
|
-
*
|
|
18
|
-
* Each promise will be resolved with the provided value.
|
|
16
|
+
* Resolves all currently pending waits for a key with the supplied value.
|
|
19
17
|
*
|
|
20
|
-
* @param
|
|
21
|
-
* @param
|
|
22
|
-
* May be `undefined` to indicate no result or a timeout-like behavior.
|
|
18
|
+
* @param key - The event identifier; a key without pending waits has no effect.
|
|
19
|
+
* @param value - The delivered value; `undefined` indicates no result.
|
|
23
20
|
*/
|
|
24
21
|
trigger(key, value) {
|
|
25
22
|
const resolvers = this.#promiseResolvers.get(key);
|
|
@@ -29,40 +26,32 @@ var EventAwaiter = class {
|
|
|
29
26
|
}
|
|
30
27
|
}
|
|
31
28
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* This is typically used during shutdown or cleanup to ensure that
|
|
35
|
-
* no consumer is left waiting indefinitely.
|
|
29
|
+
* Resolves all currently pending waits and clears their registrations.
|
|
36
30
|
*
|
|
37
|
-
* @param
|
|
38
|
-
* Defaults to `undefined`, which usually indicates cancellation or shutdown.
|
|
31
|
+
* @param value - The delivered value; omission resolves all pending waits with `undefined`.
|
|
39
32
|
*/
|
|
40
33
|
triggerAll(value = void 0) {
|
|
41
34
|
for (const [_, resolvers] of this.#promiseResolvers.entries()) resolvers.forEach((resolve) => resolve(value));
|
|
42
35
|
this.#promiseResolvers.clear();
|
|
43
36
|
}
|
|
44
37
|
/**
|
|
45
|
-
* Waits for
|
|
38
|
+
* Waits for a trigger associated with a key.
|
|
46
39
|
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
40
|
+
* @remarks
|
|
41
|
+
* By default, multiple waiters share a key and all receive the next trigger value.
|
|
42
|
+
* `strict` mode rejects duplicate waits; `override` mode resolves existing waits with `undefined` before
|
|
43
|
+
* registering the new wait. Timeout and abort remove only the affected waiter's registration.
|
|
44
|
+
* An already aborted signal is not checked; only an abort event emitted after registration ends the wait.
|
|
45
|
+
* Without a timeout or subsequent abort, the wait remains pending until a trigger arrives.
|
|
51
46
|
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* and only keeps the latest one.
|
|
47
|
+
* @param key - The event identifier to wait for.
|
|
48
|
+
* @param timeoutMs - The optional timeout in milliseconds, using native `setTimeout` timing rules.
|
|
49
|
+
* @param mode - The policy for existing waiters; omission allows multiple waiters.
|
|
50
|
+
* @param signal - A signal whose subsequent abort event ends this wait.
|
|
57
51
|
*
|
|
58
|
-
* @
|
|
59
|
-
* @param {number} [timeoutMs] - Optional timeout (in milliseconds).
|
|
60
|
-
* If reached, the promise resolves with `undefined`.
|
|
61
|
-
* @param {'override' | 'strict'} [mode] - Optional behavior mode for handling multiple waiters
|
|
62
|
-
* @param {AbortSignal} [signal] - Optional AbortSignal. If aborted, the promise resolves with `undefined`
|
|
52
|
+
* @returns A promise resolving to the triggered value, or `undefined` after timeout, abort, or replacement.
|
|
63
53
|
*
|
|
64
|
-
* @
|
|
65
|
-
* or `undefined` if timeout or abort occurs
|
|
54
|
+
* @throws Error through promise rejection if `strict` mode encounters an existing waiter.
|
|
66
55
|
*/
|
|
67
56
|
wait(key, timeoutMs, mode, signal) {
|
|
68
57
|
return new Promise((resolve) => {
|
|
@@ -97,27 +86,34 @@ var EventAwaiter = class {
|
|
|
97
86
|
});
|
|
98
87
|
}
|
|
99
88
|
/**
|
|
100
|
-
* Waits for
|
|
101
|
-
*
|
|
102
|
-
*
|
|
89
|
+
* Waits for a key while rejecting duplicate registrations.
|
|
90
|
+
*
|
|
91
|
+
* @param key - The event identifier to wait for.
|
|
92
|
+
* @param timeoutMs - The optional timeout in milliseconds.
|
|
93
|
+
* @param signal - A signal whose subsequent abort event ends this wait; an already aborted signal is not checked.
|
|
94
|
+
*
|
|
95
|
+
* @returns A promise resolving to the triggered value, or `undefined` on timeout or subsequent abort.
|
|
103
96
|
*
|
|
104
|
-
* @
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
* @param {AbortSignal} [signal] - Optional AbortSignal. If aborted, the promise resolves with `undefined`
|
|
97
|
+
* @throws Error through promise rejection if the key already has a pending waiter.
|
|
98
|
+
*
|
|
99
|
+
* @see {@link EventAwaiter.wait}
|
|
108
100
|
*/
|
|
109
101
|
waitExclusive(key, timeoutMs, signal) {
|
|
110
102
|
return this.wait(key, timeoutMs, "strict", signal);
|
|
111
103
|
}
|
|
112
104
|
/**
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
105
|
+
* Replaces existing waiters for a key and waits for its next trigger.
|
|
106
|
+
*
|
|
107
|
+
* @remarks
|
|
108
|
+
* Existing waiters resolve with `undefined` before the new waiter is registered.
|
|
109
|
+
*
|
|
110
|
+
* @param key - The event identifier to wait for.
|
|
111
|
+
* @param timeoutMs - The optional timeout in milliseconds.
|
|
112
|
+
* @param signal - A signal whose subsequent abort event ends this wait; an already aborted signal is not checked.
|
|
113
|
+
*
|
|
114
|
+
* @returns A promise resolving to the triggered value, or `undefined` on timeout, subsequent abort, or replacement.
|
|
116
115
|
*
|
|
117
|
-
* @
|
|
118
|
-
* @param {number} [timeoutMs] - Optional timeout (in milliseconds).
|
|
119
|
-
* If reached, the promise resolves with `undefined`.
|
|
120
|
-
* @param {AbortSignal} [signal] - Optional AbortSignal. If aborted, the promise resolves with `undefined`
|
|
116
|
+
* @see {@link EventAwaiter.wait}
|
|
121
117
|
*/
|
|
122
118
|
waitLatest(key, timeoutMs, signal) {
|
|
123
119
|
return this.wait(key, timeoutMs, "override", signal);
|