@powfix/core-js 0.19.0 → 0.19.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/dist/browser/cjs/browser/utils/UUID.js +132 -0
- package/dist/browser/cjs/shared/managers/SessionManager.js +10 -0
- package/dist/browser/cjs/shared/services/time/TimeService.js +16 -0
- package/dist/browser/cjs/shared/utils/ArrayUtils.js +5 -0
- package/dist/browser/cjs/shared/utils/AxiosUtils.js +2 -0
- package/dist/browser/cjs/shared/utils/Calc.js +1 -1
- package/dist/browser/cjs/shared/utils/DateUtils.js +1 -0
- package/dist/browser/cjs/shared/utils/JuminNumberUtils.js +4 -1
- package/dist/browser/cjs/shared/utils/Sequencer.js +6 -0
- package/dist/browser/cjs/shared/utils/StringUtils.js +3 -1
- package/dist/browser/cjs/shared/utils/UuidUtils.js +3 -0
- package/dist/browser/cjs/shared/utils/Validator.js +11 -0
- package/dist/browser/cjs/shared/utils/global/firstNonNullish.js +1 -0
- package/dist/browser/cjs/shared/utils/global/flat.js +1 -0
- package/dist/browser/cjs/shared/utils/global/pureEnum.js +9 -0
- package/dist/browser/cjs/shared/utils/try-catch/TryCatch.js +20 -0
- package/dist/browser/esm/browser/utils/UUID.mjs +132 -0
- package/dist/browser/esm/shared/managers/SessionManager.mjs +10 -0
- package/dist/browser/esm/shared/services/time/TimeService.mjs +16 -0
- package/dist/browser/esm/shared/utils/ArrayUtils.mjs +5 -0
- package/dist/browser/esm/shared/utils/AxiosUtils.mjs +2 -0
- package/dist/browser/esm/shared/utils/Calc.mjs +1 -1
- package/dist/browser/esm/shared/utils/DateUtils.mjs +1 -0
- package/dist/browser/esm/shared/utils/JuminNumberUtils.mjs +4 -1
- package/dist/browser/esm/shared/utils/Sequencer.mjs +6 -0
- package/dist/browser/esm/shared/utils/StringUtils.mjs +3 -1
- package/dist/browser/esm/shared/utils/UuidUtils.mjs +3 -0
- package/dist/browser/esm/shared/utils/Validator.mjs +11 -0
- package/dist/browser/esm/shared/utils/global/firstNonNullish.mjs +1 -0
- package/dist/browser/esm/shared/utils/global/flat.mjs +1 -0
- package/dist/browser/esm/shared/utils/global/pureEnum.mjs +9 -0
- package/dist/browser/esm/shared/utils/try-catch/TryCatch.mjs +20 -0
- package/dist/browser/types/browser/utils/UUID.d.ts +109 -0
- package/dist/browser/types/shared/utils/ArrayUtils.d.ts +5 -0
- package/dist/browser/types/shared/utils/UuidUtils.d.ts +6 -0
- package/dist/browser/types/shared/utils/global/pureEnum.d.ts +9 -0
- package/dist/browser/types/shared/utils/try-catch/TryCatch.d.ts +20 -0
- package/dist/node/cjs/browser/utils/UUID.js +132 -0
- package/dist/node/cjs/nodejs/managers/TransactionManager.js +3 -0
- package/dist/node/cjs/nodejs/services/redis/RedisClient.js +2 -0
- package/dist/node/cjs/nodejs/services/redis/RedisPublisher.js +1 -0
- package/dist/node/cjs/nodejs/services/redis/index.js +1 -0
- package/dist/node/cjs/shared/managers/SessionManager.js +10 -0
- package/dist/node/cjs/shared/services/time/TimeService.js +16 -0
- package/dist/node/cjs/shared/utils/ArrayUtils.js +5 -0
- package/dist/node/cjs/shared/utils/AxiosUtils.js +2 -0
- package/dist/node/cjs/shared/utils/Calc.js +1 -1
- package/dist/node/cjs/shared/utils/DateUtils.js +1 -0
- package/dist/node/cjs/shared/utils/JuminNumberUtils.js +4 -1
- package/dist/node/cjs/shared/utils/Sequencer.js +6 -0
- package/dist/node/cjs/shared/utils/StringUtils.js +3 -1
- package/dist/node/cjs/shared/utils/UuidUtils.js +3 -0
- package/dist/node/cjs/shared/utils/Validator.js +11 -0
- package/dist/node/cjs/shared/utils/global/firstNonNullish.js +1 -0
- package/dist/node/cjs/shared/utils/global/flat.js +1 -0
- package/dist/node/cjs/shared/utils/global/pureEnum.js +9 -0
- package/dist/node/cjs/shared/utils/try-catch/TryCatch.js +20 -0
- package/dist/node/esm/browser/utils/UUID.mjs +132 -0
- package/dist/node/esm/nodejs/managers/TransactionManager.mjs +3 -0
- package/dist/node/esm/nodejs/services/redis/RedisClient.mjs +2 -0
- package/dist/node/esm/nodejs/services/redis/RedisPublisher.mjs +1 -0
- package/dist/node/esm/nodejs/services/redis/index.mjs +1 -0
- package/dist/node/esm/shared/managers/SessionManager.mjs +10 -0
- package/dist/node/esm/shared/services/time/TimeService.mjs +16 -0
- package/dist/node/esm/shared/utils/ArrayUtils.mjs +5 -0
- package/dist/node/esm/shared/utils/AxiosUtils.mjs +2 -0
- package/dist/node/esm/shared/utils/Calc.mjs +1 -1
- package/dist/node/esm/shared/utils/DateUtils.mjs +1 -0
- package/dist/node/esm/shared/utils/JuminNumberUtils.mjs +4 -1
- package/dist/node/esm/shared/utils/Sequencer.mjs +6 -0
- package/dist/node/esm/shared/utils/StringUtils.mjs +3 -1
- package/dist/node/esm/shared/utils/UuidUtils.mjs +3 -0
- package/dist/node/esm/shared/utils/Validator.mjs +11 -0
- package/dist/node/esm/shared/utils/global/firstNonNullish.mjs +1 -0
- package/dist/node/esm/shared/utils/global/flat.mjs +1 -0
- package/dist/node/esm/shared/utils/global/pureEnum.mjs +9 -0
- package/dist/node/esm/shared/utils/try-catch/TryCatch.mjs +20 -0
- package/dist/node/types/browser/utils/UUID.d.ts +109 -0
- package/dist/node/types/shared/utils/ArrayUtils.d.ts +5 -0
- package/dist/node/types/shared/utils/UuidUtils.d.ts +6 -0
- package/dist/node/types/shared/utils/global/pureEnum.d.ts +9 -0
- package/dist/node/types/shared/utils/try-catch/TryCatch.d.ts +20 -0
- package/package.json +1 -1
|
@@ -1,35 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a UUID (Universally Unique Identifier) and provides various utility
|
|
3
|
+
* methods for validation, conversion, comparison and creation.
|
|
4
|
+
*/
|
|
1
5
|
export declare class UUID {
|
|
6
|
+
/** Matches a 32‑character hexadecimal representation of a UUID without hyphens. */
|
|
2
7
|
private static REGEX_HEX;
|
|
8
|
+
/** Matches the RFC 4122 canonical UUID format with hyphens. */
|
|
3
9
|
private static REGEX_RFC4122;
|
|
10
|
+
/** Number of bytes that represent a UUID. */
|
|
4
11
|
private static BYTE_LENGTH;
|
|
12
|
+
/** Total length of an RFC 4122 UUID string (including hyphens). */
|
|
5
13
|
private static STR_LENGTH;
|
|
14
|
+
/** Length of a UUID represented as a plain hexadecimal string. */
|
|
6
15
|
private static HEX_STR_LENGTH;
|
|
16
|
+
/**
|
|
17
|
+
* Checks if the supplied value is a valid hex representation of a UUID.
|
|
18
|
+
* @param hex - The string to validate.
|
|
19
|
+
* @returns true if the string matches {@link REGEX_HEX}.
|
|
20
|
+
*/
|
|
7
21
|
static isValidHex(hex: string): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Checks if the supplied value is a valid RFC 4122 UUID string.
|
|
24
|
+
* @param str - The string to validate.
|
|
25
|
+
* @returns true if the string matches {@link REGEX_RFC4122}.
|
|
26
|
+
*/
|
|
8
27
|
static isValidString(str: string): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Checks whether an ArrayBufferView contains exactly {@link BYTE_LENGTH} bytes.
|
|
30
|
+
* @param bytes - The view to check.
|
|
31
|
+
* @returns true if the byte length is correct.
|
|
32
|
+
*/
|
|
9
33
|
static isValidBytes(bytes: ArrayBufferView): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Generic validation that accepts either a string (hex or RFC 4122 format)
|
|
36
|
+
* or an ArrayBufferView containing the raw bytes.
|
|
37
|
+
* @param input - The value to validate.
|
|
38
|
+
* @returns true if the input is a valid representation of a UUID.
|
|
39
|
+
*/
|
|
10
40
|
static isValid(input: string | ArrayBufferView): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Inserts hyphens into a 32‑character hex string to produce an RFC 4122 string.
|
|
43
|
+
* @param hex - The plain hexadecimal UUID.
|
|
44
|
+
* @returns The formatted RFC 4122 string.
|
|
45
|
+
*/
|
|
11
46
|
private static formatHex;
|
|
47
|
+
/** Removes all hyphens from a UUID string. */
|
|
12
48
|
private static stripHyphens;
|
|
49
|
+
/**
|
|
50
|
+
* Converts a plain hexadecimal UUID into a Uint8Array.
|
|
51
|
+
* @param hex - The hex string to parse.
|
|
52
|
+
* @returns A Uint8Array containing the raw bytes.
|
|
53
|
+
*/
|
|
13
54
|
private static parseHex;
|
|
55
|
+
/**
|
|
56
|
+
* Parses an RFC 4122 string into a Uint8Array.
|
|
57
|
+
* @param str - The formatted UUID string.
|
|
58
|
+
* @returns A Uint8Array containing the raw bytes.
|
|
59
|
+
*/
|
|
14
60
|
private static parseString;
|
|
61
|
+
/**
|
|
62
|
+
* Parses an ArrayBufferView into a Uint8Array ensuring the correct byte length.
|
|
63
|
+
* @param bytes - The view to parse.
|
|
64
|
+
* @returns A Uint8Array containing the raw bytes.
|
|
65
|
+
*/
|
|
15
66
|
private static parseBytes;
|
|
67
|
+
/**
|
|
68
|
+
* Creates a UUID instance from a plain hexadecimal string.
|
|
69
|
+
* @param hex - The hex representation of the UUID.
|
|
70
|
+
* @returns A new {@link UUID} object.
|
|
71
|
+
*/
|
|
16
72
|
static fromHex(hex: string): UUID;
|
|
73
|
+
/**
|
|
74
|
+
* Creates a UUID instance from an RFC 4122 formatted string.
|
|
75
|
+
* @param str - The UUID string with hyphens.
|
|
76
|
+
* @returns A new {@link UUID} object.
|
|
77
|
+
*/
|
|
17
78
|
static fromString(str: string): UUID;
|
|
79
|
+
/**
|
|
80
|
+
* Creates a UUID instance from raw bytes.
|
|
81
|
+
* @param bytes - An ArrayBufferView containing 16 bytes.
|
|
82
|
+
* @returns A new {@link UUID} object.
|
|
83
|
+
*/
|
|
18
84
|
static fromBytes(bytes: ArrayBufferView): UUID;
|
|
85
|
+
/**
|
|
86
|
+
* Parses any supported input (string or bytes) and returns the raw byte array.
|
|
87
|
+
* @param input - The value to parse.
|
|
88
|
+
* @returns A Uint8Array of length {@link BYTE_LENGTH}.
|
|
89
|
+
*/
|
|
19
90
|
private static parse;
|
|
91
|
+
/**
|
|
92
|
+
* Creates a UUID from any supported input type.
|
|
93
|
+
* @param input - The value to parse.
|
|
94
|
+
* @returns A new {@link UUID} object.
|
|
95
|
+
*/
|
|
20
96
|
static from(input: string | ArrayBufferView): UUID;
|
|
97
|
+
/** Returns the nil (all zero) UUID. */
|
|
21
98
|
static nil(): UUID;
|
|
99
|
+
/** Returns a UUID consisting of all 0xFF bytes. */
|
|
22
100
|
static max(): UUID;
|
|
101
|
+
/**
|
|
102
|
+
* Compares multiple UUIDs for strict equality.
|
|
103
|
+
* @param uuids - The UUIDs to compare (at least two required).
|
|
104
|
+
* @returns true if all provided UUIDs are identical.
|
|
105
|
+
*/
|
|
23
106
|
static equals(...uuids: UUID[]): boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Lexicographically compares two UUIDs.
|
|
109
|
+
* @param uuid1 - The first UUID.
|
|
110
|
+
* @param uuid2 - The second UUID.
|
|
111
|
+
* @returns -1 if uuid1 < uuid2, 1 if uuid1 > uuid2, 0 otherwise.
|
|
112
|
+
*/
|
|
24
113
|
static compare(uuid1: UUID, uuid2: UUID): number;
|
|
114
|
+
/** Raw byte representation of the UUID. */
|
|
25
115
|
protected readonly bytes: Uint8Array;
|
|
26
116
|
private _str?;
|
|
27
117
|
private _hex?;
|
|
118
|
+
/**
|
|
119
|
+
* Constructs a new {@link UUID} instance from any supported input type.
|
|
120
|
+
* @param input - The value to parse (string or ArrayBufferView).
|
|
121
|
+
*/
|
|
28
122
|
constructor(input: string | ArrayBufferView);
|
|
123
|
+
/** Instance wrapper for {@link equals}. */
|
|
29
124
|
equals(...uuids: UUID[]): boolean;
|
|
125
|
+
/** Instance wrapper for {@link compare}. */
|
|
30
126
|
compare(other: UUID): number;
|
|
127
|
+
/**
|
|
128
|
+
* Returns the RFC 4122 string representation of this UUID.
|
|
129
|
+
* @returns The formatted UUID string.
|
|
130
|
+
*/
|
|
31
131
|
toString(): string;
|
|
132
|
+
/**
|
|
133
|
+
* Returns the plain hexadecimal representation of this UUID.
|
|
134
|
+
* @returns A 32‑character hex string.
|
|
135
|
+
*/
|
|
32
136
|
toHex(): string;
|
|
137
|
+
/**
|
|
138
|
+
* Returns a copy of the raw byte array.
|
|
139
|
+
* @returns A new Uint8Array containing the UUID bytes.
|
|
140
|
+
*/
|
|
33
141
|
toBytes(): Uint8Array;
|
|
142
|
+
/** JSON serialization helper – returns the RFC 4122 string. */
|
|
34
143
|
toJSON(): string;
|
|
35
144
|
}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
export declare class ArrayUtils {
|
|
2
2
|
static castArray<T>(value: T | T[]): T[];
|
|
3
|
+
/**
|
|
4
|
+
* 객체를 요소로 가지는 배열에서 가장 큰 값(Property)를 가지는 객체를 반환한다
|
|
5
|
+
* @param e 객체 배열
|
|
6
|
+
* @param key 값을 비교할 Property 키
|
|
7
|
+
*/
|
|
3
8
|
static getGreatestObject(e: any[], key: string): any;
|
|
4
9
|
static removeDuplicate<T>(arr: T[]): T[];
|
|
5
10
|
static removeObjectDuplicate(arr: any[], key: string): any[];
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
export declare class UuidUtils {
|
|
2
2
|
static v4(): string;
|
|
3
3
|
static format(uuid: string): string;
|
|
4
|
+
/**
|
|
5
|
+
* (UUID: Buffer) to (UUID: string)
|
|
6
|
+
* @param binary UUID
|
|
7
|
+
* @returns {string|null} When binary not exists return null
|
|
8
|
+
*/
|
|
4
9
|
static toString(binary: Uint8Array): string;
|
|
10
|
+
/** (UUID: string) to (UUID: Buffer) */
|
|
5
11
|
static toBuffer(uuid: string): Buffer;
|
|
6
12
|
static toBuffer(uuid: string | null | undefined): Buffer | null;
|
|
7
13
|
static isValidUUID(uuid: string): boolean;
|
|
@@ -2,7 +2,16 @@ type NonFunction<T, Type extends "keys" | "values"> = {
|
|
|
2
2
|
[K in keyof T]: T[K] extends Function ? never : Type extends "keys" ? K : T[K];
|
|
3
3
|
}[keyof T] extends infer R ? (R extends never ? never : R) : never;
|
|
4
4
|
type PureEnumReturnType<E extends object> = [NonFunction<E, "keys">, NonFunction<E, "values">][];
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated Use Enum instead.
|
|
7
|
+
*/
|
|
5
8
|
export declare function pureEnum<E extends object>(e: E): PureEnumReturnType<E>;
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated Use Enum instead.
|
|
11
|
+
*/
|
|
6
12
|
export declare function pureEnumKeys<E extends object>(e: E): NonFunction<E, "keys">[];
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated Use Enum instead.
|
|
15
|
+
*/
|
|
7
16
|
export declare function pureEnumValues<E extends object>(e: E): NonFunction<E, "values">[];
|
|
8
17
|
export {};
|
|
@@ -1,4 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provides a utility class for handling synchronous and asynchronous operations with a consistent try-catch pattern.
|
|
3
|
+
* It returns a tuple where the first element is the error (or null on success) and the second element is the result (or undefined on error).
|
|
4
|
+
*/
|
|
1
5
|
export declare class TryCatch {
|
|
6
|
+
/**
|
|
7
|
+
* Executes a synchronous function within a try-catch block.
|
|
8
|
+
* @template T The return type of the function.
|
|
9
|
+
* @template E The type of the error that might be thrown (defaults to Error).
|
|
10
|
+
* @param fn The synchronous function to execute.
|
|
11
|
+
*@param disableLogging console.error is default way of logging on error. You can disable it by setting it true
|
|
12
|
+
* @returns A tuple containing the result of the function and an error (null if successful).
|
|
13
|
+
*/
|
|
2
14
|
static function<T, E = Error>(fn: () => T, disableLogging?: boolean): readonly [null, T] | readonly [E, undefined];
|
|
15
|
+
/**
|
|
16
|
+
* Executes an asynchronous function (Promise) within a try-catch block.
|
|
17
|
+
* @template T The resolved value type of the Promise.
|
|
18
|
+
* @template E The type of the error that might be rejected (defaults to Error).
|
|
19
|
+
* @param fn The Promise to await.
|
|
20
|
+
* @param disableLogging console.error is default way of logging on error. You can disable it by setting it true
|
|
21
|
+
* @returns A tuple containing the resolved value of the Promise and an error (null if successful).
|
|
22
|
+
*/
|
|
3
23
|
static asyncFunction<T, E = Error>(fn: Promise<T>, disableLogging?: boolean): Promise<readonly [null, Awaited<T>] | readonly [E, undefined]>;
|
|
4
24
|
}
|
|
@@ -2,29 +2,61 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UUID = void 0;
|
|
4
4
|
const shared_1 = require("../../shared");
|
|
5
|
+
/**
|
|
6
|
+
* Represents a UUID (Universally Unique Identifier) and provides various utility
|
|
7
|
+
* methods for validation, conversion, comparison and creation.
|
|
8
|
+
*/
|
|
5
9
|
class UUID {
|
|
10
|
+
/* --------------------------------------------------------------------
|
|
11
|
+
* Validation helpers
|
|
12
|
+
* -------------------------------------------------------------------- */
|
|
13
|
+
/**
|
|
14
|
+
* Checks if the supplied value is a valid hex representation of a UUID.
|
|
15
|
+
* @param hex - The string to validate.
|
|
16
|
+
* @returns true if the string matches {@link REGEX_HEX}.
|
|
17
|
+
*/
|
|
6
18
|
static isValidHex(hex) {
|
|
7
19
|
if (typeof hex !== 'string') {
|
|
8
20
|
return false;
|
|
9
21
|
}
|
|
10
22
|
return UUID.REGEX_HEX.test(hex);
|
|
11
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Checks if the supplied value is a valid RFC 4122 UUID string.
|
|
26
|
+
* @param str - The string to validate.
|
|
27
|
+
* @returns true if the string matches {@link REGEX_RFC4122}.
|
|
28
|
+
*/
|
|
12
29
|
static isValidString(str) {
|
|
13
30
|
if (typeof str !== 'string') {
|
|
14
31
|
return false;
|
|
15
32
|
}
|
|
16
33
|
return UUID.REGEX_RFC4122.test(str);
|
|
17
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Checks whether an ArrayBufferView contains exactly {@link BYTE_LENGTH} bytes.
|
|
37
|
+
* @param bytes - The view to check.
|
|
38
|
+
* @returns true if the byte length is correct.
|
|
39
|
+
*/
|
|
18
40
|
static isValidBytes(bytes) {
|
|
19
41
|
return bytes.byteLength === UUID.BYTE_LENGTH;
|
|
20
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Generic validation that accepts either a string (hex or RFC 4122 format)
|
|
45
|
+
* or an ArrayBufferView containing the raw bytes.
|
|
46
|
+
* @param input - The value to validate.
|
|
47
|
+
* @returns true if the input is a valid representation of a UUID.
|
|
48
|
+
*/
|
|
21
49
|
static isValid(input) {
|
|
22
50
|
if (typeof input === 'string') {
|
|
23
51
|
const length = input.length;
|
|
24
52
|
switch (length) {
|
|
25
53
|
case UUID.STR_LENGTH:
|
|
54
|
+
// RFC 4122 uuid(string)
|
|
55
|
+
// 9e472052-a654-4693-9a8b-3ce57ada3d6c
|
|
26
56
|
return UUID.isValidString(input);
|
|
27
57
|
case UUID.HEX_STR_LENGTH:
|
|
58
|
+
// RFC 4122 uuid(string) without hyphens
|
|
59
|
+
// 9e472052a65446939a8b3ce57ada3d6c
|
|
28
60
|
return UUID.isValidHex(input);
|
|
29
61
|
default:
|
|
30
62
|
return false;
|
|
@@ -37,6 +69,14 @@ class UUID {
|
|
|
37
69
|
return false;
|
|
38
70
|
}
|
|
39
71
|
}
|
|
72
|
+
/* --------------------------------------------------------------------
|
|
73
|
+
* Parsing / formatting helpers
|
|
74
|
+
* -------------------------------------------------------------------- */
|
|
75
|
+
/**
|
|
76
|
+
* Inserts hyphens into a 32‑character hex string to produce an RFC 4122 string.
|
|
77
|
+
* @param hex - The plain hexadecimal UUID.
|
|
78
|
+
* @returns The formatted RFC 4122 string.
|
|
79
|
+
*/
|
|
40
80
|
static formatHex(hex) {
|
|
41
81
|
if (hex.length !== UUID.HEX_STR_LENGTH) {
|
|
42
82
|
throw new Error(`hex length should be ${UUID.HEX_STR_LENGTH}`);
|
|
@@ -47,15 +87,26 @@ class UUID {
|
|
|
47
87
|
hex.slice(16, 20) + '-' +
|
|
48
88
|
hex.slice(20);
|
|
49
89
|
}
|
|
90
|
+
/** Removes all hyphens from a UUID string. */
|
|
50
91
|
static stripHyphens(str) {
|
|
51
92
|
return str.replace(/-/g, "");
|
|
52
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Converts a plain hexadecimal UUID into a Uint8Array.
|
|
96
|
+
* @param hex - The hex string to parse.
|
|
97
|
+
* @returns A Uint8Array containing the raw bytes.
|
|
98
|
+
*/
|
|
53
99
|
static parseHex(hex) {
|
|
54
100
|
if (hex.length !== UUID.HEX_STR_LENGTH) {
|
|
55
101
|
throw new Error(`Invalid hex string, length should be ${UUID.HEX_STR_LENGTH}`);
|
|
56
102
|
}
|
|
57
103
|
return shared_1.Uint8ArrayUtils.fromHex(hex);
|
|
58
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* Parses an RFC 4122 string into a Uint8Array.
|
|
107
|
+
* @param str - The formatted UUID string.
|
|
108
|
+
* @returns A Uint8Array containing the raw bytes.
|
|
109
|
+
*/
|
|
59
110
|
static parseString(str) {
|
|
60
111
|
if (str.length !== UUID.STR_LENGTH) {
|
|
61
112
|
throw new Error(`Invalid UUID string, invalid character length should be ${UUID.STR_LENGTH}`);
|
|
@@ -69,6 +120,11 @@ class UUID {
|
|
|
69
120
|
}
|
|
70
121
|
return shared_1.Uint8ArrayUtils.fromHex(hex);
|
|
71
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* Parses an ArrayBufferView into a Uint8Array ensuring the correct byte length.
|
|
125
|
+
* @param bytes - The view to parse.
|
|
126
|
+
* @returns A Uint8Array containing the raw bytes.
|
|
127
|
+
*/
|
|
72
128
|
static parseBytes(bytes) {
|
|
73
129
|
const view = new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
74
130
|
if (view.length !== UUID.BYTE_LENGTH) {
|
|
@@ -76,22 +132,47 @@ class UUID {
|
|
|
76
132
|
}
|
|
77
133
|
return new Uint8Array(view);
|
|
78
134
|
}
|
|
135
|
+
/* --------------------------------------------------------------------
|
|
136
|
+
* Factory methods
|
|
137
|
+
* -------------------------------------------------------------------- */
|
|
138
|
+
/**
|
|
139
|
+
* Creates a UUID instance from a plain hexadecimal string.
|
|
140
|
+
* @param hex - The hex representation of the UUID.
|
|
141
|
+
* @returns A new {@link UUID} object.
|
|
142
|
+
*/
|
|
79
143
|
static fromHex(hex) {
|
|
80
144
|
return new UUID(UUID.parseHex(hex));
|
|
81
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* Creates a UUID instance from an RFC 4122 formatted string.
|
|
148
|
+
* @param str - The UUID string with hyphens.
|
|
149
|
+
* @returns A new {@link UUID} object.
|
|
150
|
+
*/
|
|
82
151
|
static fromString(str) {
|
|
83
152
|
return new UUID(UUID.parseString(str));
|
|
84
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* Creates a UUID instance from raw bytes.
|
|
156
|
+
* @param bytes - An ArrayBufferView containing 16 bytes.
|
|
157
|
+
* @returns A new {@link UUID} object.
|
|
158
|
+
*/
|
|
85
159
|
static fromBytes(bytes) {
|
|
86
160
|
return new UUID(UUID.parseBytes(bytes));
|
|
87
161
|
}
|
|
162
|
+
/**
|
|
163
|
+
* Parses any supported input (string or bytes) and returns the raw byte array.
|
|
164
|
+
* @param input - The value to parse.
|
|
165
|
+
* @returns A Uint8Array of length {@link BYTE_LENGTH}.
|
|
166
|
+
*/
|
|
88
167
|
static parse(input) {
|
|
89
168
|
if (typeof input === 'string') {
|
|
90
169
|
const length = input.length;
|
|
91
170
|
switch (length) {
|
|
92
171
|
case UUID.STR_LENGTH:
|
|
172
|
+
// RFC 4122 uuid(string)
|
|
93
173
|
return UUID.parseString(input);
|
|
94
174
|
case UUID.HEX_STR_LENGTH:
|
|
175
|
+
// RFC 4122 uuid(string) without hyphens
|
|
95
176
|
return UUID.parseHex(input);
|
|
96
177
|
default:
|
|
97
178
|
throw new Error(`Invalid input string, length should be ${UUID.STR_LENGTH} or ${UUID.HEX_STR_LENGTH}`);
|
|
@@ -104,15 +185,30 @@ class UUID {
|
|
|
104
185
|
throw new Error("Invalid input, Expected string or ArrayBufferView");
|
|
105
186
|
}
|
|
106
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* Creates a UUID from any supported input type.
|
|
190
|
+
* @param input - The value to parse.
|
|
191
|
+
* @returns A new {@link UUID} object.
|
|
192
|
+
*/
|
|
107
193
|
static from(input) {
|
|
108
194
|
return UUID.fromBytes(UUID.parse(input));
|
|
109
195
|
}
|
|
196
|
+
/** Returns the nil (all zero) UUID. */
|
|
110
197
|
static nil() {
|
|
111
198
|
return UUID.fromBytes(new Uint8Array(UUID.BYTE_LENGTH));
|
|
112
199
|
}
|
|
200
|
+
/** Returns a UUID consisting of all 0xFF bytes. */
|
|
113
201
|
static max() {
|
|
114
202
|
return UUID.fromBytes((new Uint8Array(UUID.BYTE_LENGTH)).fill(0xFF));
|
|
115
203
|
}
|
|
204
|
+
/* --------------------------------------------------------------------
|
|
205
|
+
* Equality / comparison
|
|
206
|
+
* -------------------------------------------------------------------- */
|
|
207
|
+
/**
|
|
208
|
+
* Compares multiple UUIDs for strict equality.
|
|
209
|
+
* @param uuids - The UUIDs to compare (at least two required).
|
|
210
|
+
* @returns true if all provided UUIDs are identical.
|
|
211
|
+
*/
|
|
116
212
|
static equals(...uuids) {
|
|
117
213
|
const n = uuids.length;
|
|
118
214
|
if (n < 2) {
|
|
@@ -128,6 +224,12 @@ class UUID {
|
|
|
128
224
|
}
|
|
129
225
|
return true;
|
|
130
226
|
}
|
|
227
|
+
/**
|
|
228
|
+
* Lexicographically compares two UUIDs.
|
|
229
|
+
* @param uuid1 - The first UUID.
|
|
230
|
+
* @param uuid2 - The second UUID.
|
|
231
|
+
* @returns -1 if uuid1 < uuid2, 1 if uuid1 > uuid2, 0 otherwise.
|
|
232
|
+
*/
|
|
131
233
|
static compare(uuid1, uuid2) {
|
|
132
234
|
const a = uuid1.bytes;
|
|
133
235
|
const b = uuid2.bytes;
|
|
@@ -137,15 +239,25 @@ class UUID {
|
|
|
137
239
|
}
|
|
138
240
|
return 0;
|
|
139
241
|
}
|
|
242
|
+
/**
|
|
243
|
+
* Constructs a new {@link UUID} instance from any supported input type.
|
|
244
|
+
* @param input - The value to parse (string or ArrayBufferView).
|
|
245
|
+
*/
|
|
140
246
|
constructor(input) {
|
|
141
247
|
this.bytes = UUID.parse(input);
|
|
142
248
|
}
|
|
249
|
+
/** Instance wrapper for {@link equals}. */
|
|
143
250
|
equals(...uuids) {
|
|
144
251
|
return UUID.equals(this, ...uuids);
|
|
145
252
|
}
|
|
253
|
+
/** Instance wrapper for {@link compare}. */
|
|
146
254
|
compare(other) {
|
|
147
255
|
return UUID.compare(this, other);
|
|
148
256
|
}
|
|
257
|
+
/**
|
|
258
|
+
* Returns the RFC 4122 string representation of this UUID.
|
|
259
|
+
* @returns The formatted UUID string.
|
|
260
|
+
*/
|
|
149
261
|
toString() {
|
|
150
262
|
if (this._str != null) {
|
|
151
263
|
return this._str;
|
|
@@ -154,6 +266,10 @@ class UUID {
|
|
|
154
266
|
this._str = UUID.formatHex(hex);
|
|
155
267
|
return this._str;
|
|
156
268
|
}
|
|
269
|
+
/**
|
|
270
|
+
* Returns the plain hexadecimal representation of this UUID.
|
|
271
|
+
* @returns A 32‑character hex string.
|
|
272
|
+
*/
|
|
157
273
|
toHex() {
|
|
158
274
|
if (this._hex != null) {
|
|
159
275
|
return this._hex;
|
|
@@ -161,16 +277,32 @@ class UUID {
|
|
|
161
277
|
this._hex = shared_1.Uint8ArrayUtils.toHex(this.bytes);
|
|
162
278
|
return this._hex;
|
|
163
279
|
}
|
|
280
|
+
/**
|
|
281
|
+
* Returns a copy of the raw byte array.
|
|
282
|
+
* @returns A new Uint8Array containing the UUID bytes.
|
|
283
|
+
*/
|
|
164
284
|
toBytes() {
|
|
165
285
|
return new Uint8Array(this.bytes);
|
|
166
286
|
}
|
|
287
|
+
/** JSON serialization helper – returns the RFC 4122 string. */
|
|
167
288
|
toJSON() {
|
|
168
289
|
return this.toString();
|
|
169
290
|
}
|
|
170
291
|
}
|
|
171
292
|
exports.UUID = UUID;
|
|
293
|
+
/* --------------------------------------------------------------------
|
|
294
|
+
* Regular expressions used to validate UUIDs in different string forms
|
|
295
|
+
* -------------------------------------------------------------------- */
|
|
296
|
+
/** Matches a 32‑character hexadecimal representation of a UUID without hyphens. */
|
|
172
297
|
UUID.REGEX_HEX = /^[0-9a-fA-F]{8}[0-9a-fA-F]{4}[1-5][0-9a-fA-F]{3}[89abAB][0-9a-fA-F]{3}[0-9a-fA-F]{12}$/;
|
|
298
|
+
/** Matches the RFC 4122 canonical UUID format with hyphens. */
|
|
173
299
|
UUID.REGEX_RFC4122 = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/;
|
|
300
|
+
/* --------------------------------------------------------------------
|
|
301
|
+
* Constant lengths used throughout the class
|
|
302
|
+
* -------------------------------------------------------------------- */
|
|
303
|
+
/** Number of bytes that represent a UUID. */
|
|
174
304
|
UUID.BYTE_LENGTH = 16;
|
|
305
|
+
/** Total length of an RFC 4122 UUID string (including hyphens). */
|
|
175
306
|
UUID.STR_LENGTH = 36;
|
|
307
|
+
/** Length of a UUID represented as a plain hexadecimal string. */
|
|
176
308
|
UUID.HEX_STR_LENGTH = 32;
|
|
@@ -18,8 +18,10 @@ const constants_1 = require("../constants");
|
|
|
18
18
|
const LOG_TAG = '[TransactionManager]';
|
|
19
19
|
class TransactionManager {
|
|
20
20
|
constructor() {
|
|
21
|
+
// Members
|
|
21
22
|
this.logLevel = constants_1.TransactionManagerLogLevel.VERBOSE;
|
|
22
23
|
this.transactionTimeoutMap = new Map();
|
|
24
|
+
// Emitter
|
|
23
25
|
this.emitter = new eventemitter3_1.default();
|
|
24
26
|
if (this.logLevel <= constants_1.TransactionManagerLogLevel.VERBOSE) {
|
|
25
27
|
console.log(LOG_TAG, 'TransactionManager instance initialized');
|
|
@@ -59,6 +61,7 @@ class TransactionManager {
|
|
|
59
61
|
handler,
|
|
60
62
|
action,
|
|
61
63
|
});
|
|
64
|
+
// Callback
|
|
62
65
|
transaction.afterCommit(this.afterCommit.bind(this));
|
|
63
66
|
}
|
|
64
67
|
remove(transaction) {
|
|
@@ -33,6 +33,7 @@ class RedisClient {
|
|
|
33
33
|
start() {
|
|
34
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
35
|
console.log(LOG_PREFIX, 'trying to start');
|
|
36
|
+
// register event callback
|
|
36
37
|
this.client.on('connect', this.handleOnConnect);
|
|
37
38
|
this.client.on('error', this.handleOnError);
|
|
38
39
|
console.log('before connect');
|
|
@@ -46,6 +47,7 @@ class RedisClient {
|
|
|
46
47
|
stop() {
|
|
47
48
|
return __awaiter(this, void 0, void 0, function* () {
|
|
48
49
|
console.log(LOG_PREFIX, 'trying to stop');
|
|
50
|
+
// unregister event callback
|
|
49
51
|
this.client.off('connect', this.handleOnConnect);
|
|
50
52
|
this.client.off('error', this.handleOnError);
|
|
51
53
|
if (this.client.isOpen) {
|
|
@@ -40,6 +40,7 @@ class RedisPublisher extends RedisClient_1.RedisClient {
|
|
|
40
40
|
getLogging() {
|
|
41
41
|
return this.logging;
|
|
42
42
|
}
|
|
43
|
+
// Make public method
|
|
43
44
|
publish(channel, data) {
|
|
44
45
|
return __awaiter(this, void 0, void 0, function* () {
|
|
45
46
|
const stringifyData = typeof data !== 'string' ? JSON.stringify(data) : data;
|
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
// Files
|
|
17
18
|
__exportStar(require("./RedisClient"), exports);
|
|
18
19
|
__exportStar(require("./RedisPublisher"), exports);
|
|
19
20
|
__exportStar(require("./RedisSubscriber"), exports);
|
|
@@ -19,8 +19,10 @@ const eventemitter3_1 = __importDefault(require("eventemitter3"));
|
|
|
19
19
|
class SessionManager extends eventemitter3_1.default {
|
|
20
20
|
constructor(options) {
|
|
21
21
|
super();
|
|
22
|
+
// Init service parameters
|
|
22
23
|
this.api = options.api;
|
|
23
24
|
this.storageProvider = options.storageProvider;
|
|
25
|
+
// Logging
|
|
24
26
|
console.log('SessionManager initialized', Date.now(), options.api);
|
|
25
27
|
}
|
|
26
28
|
get key() {
|
|
@@ -61,6 +63,7 @@ class SessionManager extends eventemitter3_1.default {
|
|
|
61
63
|
return null;
|
|
62
64
|
}
|
|
63
65
|
try {
|
|
66
|
+
// Replace Bearer prefix
|
|
64
67
|
nextAuthorization = nextAuthorization.replace(/^Bearer\s+/, '');
|
|
65
68
|
const decoded = (0, jwt_decode_1.jwtDecode)(nextAuthorization);
|
|
66
69
|
if (!decoded) {
|
|
@@ -101,9 +104,13 @@ class SessionManager extends eventemitter3_1.default {
|
|
|
101
104
|
return [decoded.exp, exp.format(), exp.diff(Date.now(), 'days'), 'days left'];
|
|
102
105
|
})());
|
|
103
106
|
})();
|
|
107
|
+
// AsyncStorage 에 토큰 저장
|
|
104
108
|
yield this.storageProvider.set(this.key, nextAuthorization);
|
|
109
|
+
// API Instance header 설정
|
|
105
110
|
this.api.defaults.headers.common.Authorization = `Bearer ${nextAuthorization}`;
|
|
111
|
+
// Emit
|
|
106
112
|
this.emit('AUTHORIZATION_CHANGED', nextAuthorization);
|
|
113
|
+
// Return
|
|
107
114
|
return nextAuthorization;
|
|
108
115
|
}
|
|
109
116
|
catch (e) {
|
|
@@ -114,8 +121,11 @@ class SessionManager extends eventemitter3_1.default {
|
|
|
114
121
|
}
|
|
115
122
|
removeAuthorization() {
|
|
116
123
|
return __awaiter(this, void 0, void 0, function* () {
|
|
124
|
+
// API Instance header 에서 토큰 제거
|
|
117
125
|
delete this.api.defaults.headers.common.Authorization;
|
|
126
|
+
// 스토리지에서 authorization 제거
|
|
118
127
|
yield this.storageProvider.remove(this.key);
|
|
128
|
+
// Emit
|
|
119
129
|
this.emit('AUTHORIZATION_CHANGED', null);
|
|
120
130
|
});
|
|
121
131
|
}
|
|
@@ -22,9 +22,11 @@ class TimeService extends eventemitter3_1.default {
|
|
|
22
22
|
}
|
|
23
23
|
constructor(options) {
|
|
24
24
|
super();
|
|
25
|
+
// Options
|
|
25
26
|
this.syncInterval = options === null || options === void 0 ? void 0 : options.syncInterval;
|
|
26
27
|
this.clientTimeProvider = options === null || options === void 0 ? void 0 : options.clientTimeProvider;
|
|
27
28
|
this.serverTimeProvider = options === null || options === void 0 ? void 0 : options.serverTimeProvider;
|
|
29
|
+
// Bind
|
|
28
30
|
this.sync = this.sync.bind(this);
|
|
29
31
|
this.fetchServerNTPResult = this.fetchServerNTPResult.bind(this);
|
|
30
32
|
}
|
|
@@ -51,6 +53,7 @@ class TimeService extends eventemitter3_1.default {
|
|
|
51
53
|
}
|
|
52
54
|
setSyncInterval(interval) {
|
|
53
55
|
this.syncInterval = interval;
|
|
56
|
+
// Emit
|
|
54
57
|
this.emit('SYNC_INTERVAL_CHANGED', interval);
|
|
55
58
|
if (this.syncHandler !== undefined) {
|
|
56
59
|
this.stopSync();
|
|
@@ -105,22 +108,32 @@ class TimeService extends eventemitter3_1.default {
|
|
|
105
108
|
sync() {
|
|
106
109
|
return __awaiter(this, void 0, void 0, function* () {
|
|
107
110
|
try {
|
|
111
|
+
// T1 (Client Request Time)
|
|
108
112
|
const requestedAt = Date.now();
|
|
113
|
+
// Fetch server time from server
|
|
109
114
|
const serverNtpResult = yield this.fetchServerNTPResult(requestedAt);
|
|
115
|
+
// Check is null
|
|
110
116
|
if (serverNtpResult === null) {
|
|
111
117
|
console.warn(LOG_TAG, 'Failed to get server time');
|
|
112
118
|
return null;
|
|
113
119
|
}
|
|
120
|
+
// T2 (Server Receive Time)
|
|
114
121
|
const { t2 } = serverNtpResult;
|
|
122
|
+
// Check is not a number
|
|
115
123
|
if (isNaN(Number(t2))) {
|
|
124
|
+
// Not a Number
|
|
116
125
|
console.error(LOG_TAG, 'invalid server time(t2), not a number', t2);
|
|
117
126
|
return null;
|
|
118
127
|
}
|
|
128
|
+
// T3 (Server Transmit Time)
|
|
119
129
|
const { t3 } = serverNtpResult;
|
|
130
|
+
// Check is not a number
|
|
120
131
|
if (isNaN(Number(t3))) {
|
|
132
|
+
// Not a Number
|
|
121
133
|
console.error(LOG_TAG, 'invalid server time(t2), not a number', t2);
|
|
122
134
|
return null;
|
|
123
135
|
}
|
|
136
|
+
// T4 (Client Receive Time)
|
|
124
137
|
const receivedAt = Date.now();
|
|
125
138
|
const ntpResult = {
|
|
126
139
|
t1: requestedAt,
|
|
@@ -128,8 +141,11 @@ class TimeService extends eventemitter3_1.default {
|
|
|
128
141
|
t3: t3,
|
|
129
142
|
t4: receivedAt,
|
|
130
143
|
};
|
|
144
|
+
// Calculate offset
|
|
131
145
|
const offset = TimeService.calculateNTPResultOffset(ntpResult);
|
|
146
|
+
// Save calculated offset
|
|
132
147
|
this.setOffset(offset);
|
|
148
|
+
// Mark synced timestamp
|
|
133
149
|
const syncedAt = Date.now();
|
|
134
150
|
this.setSyncedAt(syncedAt);
|
|
135
151
|
this.emit('SYNCED', offset, syncedAt);
|
|
@@ -6,6 +6,11 @@ class ArrayUtils {
|
|
|
6
6
|
static castArray(value) {
|
|
7
7
|
return (0, global_1.castArray)(value);
|
|
8
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* 객체를 요소로 가지는 배열에서 가장 큰 값(Property)를 가지는 객체를 반환한다
|
|
11
|
+
* @param e 객체 배열
|
|
12
|
+
* @param key 값을 비교할 Property 키
|
|
13
|
+
*/
|
|
9
14
|
static getGreatestObject(e, key) {
|
|
10
15
|
return e.reduce((prev, current) => ((prev[key] > current[key] ? prev : current)));
|
|
11
16
|
}
|
|
@@ -16,6 +16,7 @@ class AxiosUtils {
|
|
|
16
16
|
return e;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
+
// There is no any values having string type
|
|
19
20
|
return null;
|
|
20
21
|
}
|
|
21
22
|
else {
|
|
@@ -38,6 +39,7 @@ class AxiosUtils {
|
|
|
38
39
|
return e;
|
|
39
40
|
}
|
|
40
41
|
}
|
|
42
|
+
// There is no any values having string type
|
|
41
43
|
return null;
|
|
42
44
|
}
|
|
43
45
|
else {
|