@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
|
@@ -16,9 +16,11 @@ export class TimeService extends EventEmitter {
|
|
|
16
16
|
}
|
|
17
17
|
constructor(options) {
|
|
18
18
|
super();
|
|
19
|
+
// Options
|
|
19
20
|
this.syncInterval = options === null || options === void 0 ? void 0 : options.syncInterval;
|
|
20
21
|
this.clientTimeProvider = options === null || options === void 0 ? void 0 : options.clientTimeProvider;
|
|
21
22
|
this.serverTimeProvider = options === null || options === void 0 ? void 0 : options.serverTimeProvider;
|
|
23
|
+
// Bind
|
|
22
24
|
this.sync = this.sync.bind(this);
|
|
23
25
|
this.fetchServerNTPResult = this.fetchServerNTPResult.bind(this);
|
|
24
26
|
}
|
|
@@ -45,6 +47,7 @@ export class TimeService extends EventEmitter {
|
|
|
45
47
|
}
|
|
46
48
|
setSyncInterval(interval) {
|
|
47
49
|
this.syncInterval = interval;
|
|
50
|
+
// Emit
|
|
48
51
|
this.emit('SYNC_INTERVAL_CHANGED', interval);
|
|
49
52
|
if (this.syncHandler !== undefined) {
|
|
50
53
|
this.stopSync();
|
|
@@ -99,22 +102,32 @@ export class TimeService extends EventEmitter {
|
|
|
99
102
|
sync() {
|
|
100
103
|
return __awaiter(this, void 0, void 0, function* () {
|
|
101
104
|
try {
|
|
105
|
+
// T1 (Client Request Time)
|
|
102
106
|
const requestedAt = Date.now();
|
|
107
|
+
// Fetch server time from server
|
|
103
108
|
const serverNtpResult = yield this.fetchServerNTPResult(requestedAt);
|
|
109
|
+
// Check is null
|
|
104
110
|
if (serverNtpResult === null) {
|
|
105
111
|
console.warn(LOG_TAG, 'Failed to get server time');
|
|
106
112
|
return null;
|
|
107
113
|
}
|
|
114
|
+
// T2 (Server Receive Time)
|
|
108
115
|
const { t2 } = serverNtpResult;
|
|
116
|
+
// Check is not a number
|
|
109
117
|
if (isNaN(Number(t2))) {
|
|
118
|
+
// Not a Number
|
|
110
119
|
console.error(LOG_TAG, 'invalid server time(t2), not a number', t2);
|
|
111
120
|
return null;
|
|
112
121
|
}
|
|
122
|
+
// T3 (Server Transmit Time)
|
|
113
123
|
const { t3 } = serverNtpResult;
|
|
124
|
+
// Check is not a number
|
|
114
125
|
if (isNaN(Number(t3))) {
|
|
126
|
+
// Not a Number
|
|
115
127
|
console.error(LOG_TAG, 'invalid server time(t2), not a number', t2);
|
|
116
128
|
return null;
|
|
117
129
|
}
|
|
130
|
+
// T4 (Client Receive Time)
|
|
118
131
|
const receivedAt = Date.now();
|
|
119
132
|
const ntpResult = {
|
|
120
133
|
t1: requestedAt,
|
|
@@ -122,8 +135,11 @@ export class TimeService extends EventEmitter {
|
|
|
122
135
|
t3: t3,
|
|
123
136
|
t4: receivedAt,
|
|
124
137
|
};
|
|
138
|
+
// Calculate offset
|
|
125
139
|
const offset = TimeService.calculateNTPResultOffset(ntpResult);
|
|
140
|
+
// Save calculated offset
|
|
126
141
|
this.setOffset(offset);
|
|
142
|
+
// Mark synced timestamp
|
|
127
143
|
const syncedAt = Date.now();
|
|
128
144
|
this.setSyncedAt(syncedAt);
|
|
129
145
|
this.emit('SYNCED', offset, syncedAt);
|
|
@@ -3,6 +3,11 @@ export class ArrayUtils {
|
|
|
3
3
|
static castArray(value) {
|
|
4
4
|
return castArray(value);
|
|
5
5
|
}
|
|
6
|
+
/**
|
|
7
|
+
* 객체를 요소로 가지는 배열에서 가장 큰 값(Property)를 가지는 객체를 반환한다
|
|
8
|
+
* @param e 객체 배열
|
|
9
|
+
* @param key 값을 비교할 Property 키
|
|
10
|
+
*/
|
|
6
11
|
static getGreatestObject(e, key) {
|
|
7
12
|
return e.reduce((prev, current) => ((prev[key] > current[key] ? prev : current)));
|
|
8
13
|
}
|
|
@@ -13,6 +13,7 @@ export class AxiosUtils {
|
|
|
13
13
|
return e;
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
+
// There is no any values having string type
|
|
16
17
|
return null;
|
|
17
18
|
}
|
|
18
19
|
else {
|
|
@@ -35,6 +36,7 @@ export class AxiosUtils {
|
|
|
35
36
|
return e;
|
|
36
37
|
}
|
|
37
38
|
}
|
|
39
|
+
// There is no any values having string type
|
|
38
40
|
return null;
|
|
39
41
|
}
|
|
40
42
|
else {
|
|
@@ -14,7 +14,7 @@ export class Calc {
|
|
|
14
14
|
const len = values.length;
|
|
15
15
|
if (len === 0)
|
|
16
16
|
return NaN;
|
|
17
|
-
const sorted = values.slice().sort((a, b) => a - b);
|
|
17
|
+
const sorted = values.slice().sort((a, b) => a - b); // O(n log n)
|
|
18
18
|
const mid = len >> 1;
|
|
19
19
|
return len % 2 === 0
|
|
20
20
|
? (sorted[mid - 1] + sorted[mid]) / 2
|
|
@@ -100,6 +100,7 @@ export class DateUtils {
|
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
DateUtils.relativeDate = (input, base = Date.now()) => {
|
|
103
|
+
// Create new moment instance to apply new locale
|
|
103
104
|
const datetime = moment.isMoment(input) ? moment(input.toDate()) : moment(input);
|
|
104
105
|
if (!datetime.isValid()) {
|
|
105
106
|
console.error('core-js:DateUtils.relativeDate() datetime is invalid', datetime);
|
|
@@ -16,9 +16,10 @@ export class JuminNumberUtils {
|
|
|
16
16
|
if (replacedJuminNumber.length !== 13) {
|
|
17
17
|
return false;
|
|
18
18
|
}
|
|
19
|
+
// 연도에 해당하는 숫자와 성별에 해당하는 숫자 비교
|
|
19
20
|
const TODAY_YEAR = parseInt(new Date().getFullYear().toString().slice(-2), 10);
|
|
20
21
|
const yearNum = parseInt(replacedJuminNumber.slice(0, 2), 10);
|
|
21
|
-
const sexNum = replacedJuminNumber.slice(6, 7);
|
|
22
|
+
const sexNum = replacedJuminNumber.slice(6, 7); // 대시 있는경우 7로 변경
|
|
22
23
|
if (sexNum === '1' || sexNum === '2') {
|
|
23
24
|
if (yearNum < TODAY_YEAR)
|
|
24
25
|
return false;
|
|
@@ -29,9 +30,11 @@ export class JuminNumberUtils {
|
|
|
29
30
|
}
|
|
30
31
|
else
|
|
31
32
|
return false;
|
|
33
|
+
// 월과 일에 해당하는 숫자 조건 검사 (정규식으로)
|
|
32
34
|
const regex = /^\d{2}(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])\d{7}$/;
|
|
33
35
|
if (!regex.test(replacedJuminNumber))
|
|
34
36
|
return false;
|
|
37
|
+
// Validation X
|
|
35
38
|
const currentX = parseInt(replacedJuminNumber.slice(-1), 10);
|
|
36
39
|
const calculatedX = JuminNumberUtils.calculateX(replacedJuminNumber);
|
|
37
40
|
if (currentX !== calculatedX) {
|
|
@@ -28,9 +28,11 @@ export class Sequencer {
|
|
|
28
28
|
this.sequences = [];
|
|
29
29
|
this.status = SequencerStatus.IDLE;
|
|
30
30
|
this.minimumExecutionTime = 0;
|
|
31
|
+
// Reset variables task is done
|
|
31
32
|
this.currentSequence = null;
|
|
32
33
|
this.startTimestamp = null;
|
|
33
34
|
this.endTimestamp = null;
|
|
35
|
+
// Emitter
|
|
34
36
|
this.eventEmitter = new EventEmitter3();
|
|
35
37
|
this.pushSequence = (sequence) => {
|
|
36
38
|
this.sequences.push(sequence);
|
|
@@ -49,6 +51,7 @@ export class Sequencer {
|
|
|
49
51
|
console.log('Currently total execution time', this.executionTime);
|
|
50
52
|
const sequenceStartTimeStamp = this.getCurrentTimeStamp;
|
|
51
53
|
this.currentSequence = sequence;
|
|
54
|
+
// Emitter
|
|
52
55
|
this.eventEmitter.emit(SequencerEvent.SEQUENCE_START, sequence);
|
|
53
56
|
try {
|
|
54
57
|
yield new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -92,6 +95,7 @@ export class Sequencer {
|
|
|
92
95
|
}
|
|
93
96
|
}));
|
|
94
97
|
console.log('Out of Promise');
|
|
98
|
+
// Emitter
|
|
95
99
|
this.eventEmitter.emit(SequencerEvent.SEQUENCE_END, sequence);
|
|
96
100
|
}
|
|
97
101
|
catch (e) {
|
|
@@ -100,12 +104,14 @@ export class Sequencer {
|
|
|
100
104
|
this.status = SequencerStatus.ERROR;
|
|
101
105
|
this.currentSequence = null;
|
|
102
106
|
this.endTimestamp = this.currentSequence;
|
|
107
|
+
// IMPORTANT
|
|
103
108
|
return Promise.reject({
|
|
104
109
|
sequence,
|
|
105
110
|
reason: e,
|
|
106
111
|
});
|
|
107
112
|
}
|
|
108
113
|
console.log(`Sequence ${sequence.key} failed`, e);
|
|
114
|
+
// Emitter
|
|
109
115
|
this.eventEmitter.emit(SequencerEvent.SEQUENCE_END, sequence);
|
|
110
116
|
}
|
|
111
117
|
}
|
|
@@ -24,7 +24,9 @@ StringUtils.levenshteinDistance = (str1 = '', str2 = '') => {
|
|
|
24
24
|
for (let j = 1; j <= str2.length; j += 1) {
|
|
25
25
|
for (let i = 1; i <= str1.length; i += 1) {
|
|
26
26
|
const indicator = str1[i - 1] === str2[j - 1] ? 0 : 1;
|
|
27
|
-
track[j][i] = Math.min(track[j][i - 1] + 1,
|
|
27
|
+
track[j][i] = Math.min(track[j][i - 1] + 1, // deletion
|
|
28
|
+
track[j - 1][i] + 1, // insertion
|
|
29
|
+
track[j - 1][i - 1] + indicator);
|
|
28
30
|
}
|
|
29
31
|
}
|
|
30
32
|
return track[str2.length][str1.length];
|
|
@@ -6,12 +6,15 @@ export class UuidUtils {
|
|
|
6
6
|
}
|
|
7
7
|
static format(uuid) {
|
|
8
8
|
if (uuid.length === 32) {
|
|
9
|
+
// Without dash: ca23c587d7f84c76be59f53bbc9f91f8
|
|
9
10
|
return `${uuid.substring(0, 8)}-${uuid.substring(8, 12)}-${uuid.substring(12, 16)}-${uuid.substring(16, 20)}-${uuid.substring(20, 32)}`.toLowerCase();
|
|
10
11
|
}
|
|
11
12
|
else if (uuid.length === 36) {
|
|
13
|
+
// With dash: ca23c587-d7f8-4c76-be59-f53bbc9f91f8
|
|
12
14
|
return uuid.toLowerCase();
|
|
13
15
|
}
|
|
14
16
|
else {
|
|
17
|
+
// Unexpected uuid
|
|
15
18
|
console.warn('Unexpected uuid length', uuid);
|
|
16
19
|
return uuid;
|
|
17
20
|
}
|
|
@@ -13,12 +13,14 @@ export class Validator {
|
|
|
13
13
|
const startsWithNumber = /^\d/.test(value);
|
|
14
14
|
const startsWithAlphabet = /^[A-Za-z]/.test(value);
|
|
15
15
|
const startsWithSpecialCharacter = /^[~`!@#$%^&*()\-+={[}\]|\\:;"'<,>.?/]/.test(value);
|
|
16
|
+
// 최소 길이
|
|
16
17
|
if (options.minLength !== undefined && options.minLength > -1) {
|
|
17
18
|
validations.push(Validator.VALIDATION.MIN_LENGTH);
|
|
18
19
|
if (length < options.minLength) {
|
|
19
20
|
errors.push(Validator.VALIDATION.MIN_LENGTH);
|
|
20
21
|
}
|
|
21
22
|
}
|
|
23
|
+
// 최대 길이
|
|
22
24
|
if (options.maxLength !== undefined && options.maxLength > -1) {
|
|
23
25
|
validations.push(Validator.VALIDATION.MAX_LENGTH);
|
|
24
26
|
if (length > options.maxLength) {
|
|
@@ -41,30 +43,39 @@ export class Validator {
|
|
|
41
43
|
}
|
|
42
44
|
}
|
|
43
45
|
};
|
|
46
|
+
// 공백 개수
|
|
44
47
|
validateMin(options.spaceMinCount, spaceCount, Validator.VALIDATION.SPACE_MIN_COUNT);
|
|
45
48
|
validateMax(options.spaceMaxCount, spaceCount, Validator.VALIDATION.SPACE_MAX_COUNT);
|
|
49
|
+
// 숫자 개수
|
|
46
50
|
validateMin(options.numberMinCount, numberCount, Validator.VALIDATION.NUMBER_MIN_COUNT);
|
|
47
51
|
validateMax(options.numberMaxCount, numberCount, Validator.VALIDATION.NUMBER_MAX_COUNT);
|
|
52
|
+
// 알파벳 개수
|
|
48
53
|
validateMin(options.alphabetMinCount, alphabetCount, Validator.VALIDATION.ALPHABET_MIN_COUNT);
|
|
49
54
|
validateMax(options.alphabetMaxCount, alphabetCount, Validator.VALIDATION.ALPHABET_MAX_COUNT);
|
|
55
|
+
// 알파벳(소문자) 개수
|
|
50
56
|
validateMin(options.alphabetLowerCaseMinCount, alphabetLowerCaseCount, Validator.VALIDATION.ALPHABET_LOWER_CASE_MIN_COUNT);
|
|
51
57
|
validateMax(options.alphabetLowerCaseMaxCount, alphabetLowerCaseCount, Validator.VALIDATION.ALPHABET_LOWER_CASE_MAX_COUNT);
|
|
58
|
+
// 알파벳(대문자) 개수
|
|
52
59
|
validateMin(options.alphabetUpperCaseMinCount, alphabetUpperCaseCount, Validator.VALIDATION.ALPHABET_UPPER_CASE_MIN_COUNT);
|
|
53
60
|
validateMax(options.alphabetUpperCaseMaxCount, alphabetUpperCaseCount, Validator.VALIDATION.ALPHABET_UPPER_CASE_MAX_COUNT);
|
|
61
|
+
// 특수문자 개수
|
|
54
62
|
validateMin(options.specialCharacterMinCount, specialCount, Validator.VALIDATION.SPECIAL_CHARACTER_MIN_COUNT);
|
|
55
63
|
validateMax(options.specialCharacterMaxCount, specialCount, Validator.VALIDATION.SPECIAL_CHARACTER_MAX_COUNT);
|
|
64
|
+
// 숫자로 시작
|
|
56
65
|
if (options.startsWithNumber) {
|
|
57
66
|
validations.push(Validator.VALIDATION.STARTS_WITH_NUMBER);
|
|
58
67
|
if (!startsWithNumber) {
|
|
59
68
|
errors.push(Validator.VALIDATION.STARTS_WITH_NUMBER);
|
|
60
69
|
}
|
|
61
70
|
}
|
|
71
|
+
// 영문으로 시작
|
|
62
72
|
if (options.startsWithAlphabet) {
|
|
63
73
|
validations.push(Validator.VALIDATION.STARTS_WITH_ALPHABET);
|
|
64
74
|
if (!startsWithAlphabet) {
|
|
65
75
|
errors.push(Validator.VALIDATION.STARTS_WITH_ALPHABET);
|
|
66
76
|
}
|
|
67
77
|
}
|
|
78
|
+
// 특수문자로 시작
|
|
68
79
|
if (options.startsWithSpecialCharacter) {
|
|
69
80
|
validations.push(Validator.VALIDATION.STARTS_WITH_SPECIAL_CHARACTER);
|
|
70
81
|
if (!startsWithSpecialCharacter) {
|
|
@@ -1,9 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated Use Enum instead.
|
|
3
|
+
*/
|
|
1
4
|
export function pureEnum(e) {
|
|
2
5
|
return Object.entries(e).filter(([key, value]) => !/^-?\d+$/g.test(key) && typeof value !== 'function');
|
|
3
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Use Enum instead.
|
|
9
|
+
*/
|
|
4
10
|
export function pureEnumKeys(e) {
|
|
5
11
|
return pureEnum(e).map(([key]) => key);
|
|
6
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated Use Enum instead.
|
|
15
|
+
*/
|
|
7
16
|
export function pureEnumValues(e) {
|
|
8
17
|
return pureEnum(e).map(([, value]) => value);
|
|
9
18
|
}
|
|
@@ -7,7 +7,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
+
/**
|
|
11
|
+
* Provides a utility class for handling synchronous and asynchronous operations with a consistent try-catch pattern.
|
|
12
|
+
* 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).
|
|
13
|
+
*/
|
|
10
14
|
export class TryCatch {
|
|
15
|
+
/**
|
|
16
|
+
* Executes a synchronous function within a try-catch block.
|
|
17
|
+
* @template T The return type of the function.
|
|
18
|
+
* @template E The type of the error that might be thrown (defaults to Error).
|
|
19
|
+
* @param fn The synchronous function to execute.
|
|
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 result of the function and an error (null if successful).
|
|
22
|
+
*/
|
|
11
23
|
static function(fn, disableLogging) {
|
|
12
24
|
try {
|
|
13
25
|
return [
|
|
@@ -28,6 +40,14 @@ export class TryCatch {
|
|
|
28
40
|
];
|
|
29
41
|
}
|
|
30
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Executes an asynchronous function (Promise) within a try-catch block.
|
|
45
|
+
* @template T The resolved value type of the Promise.
|
|
46
|
+
* @template E The type of the error that might be rejected (defaults to Error).
|
|
47
|
+
* @param fn The Promise to await.
|
|
48
|
+
* @param disableLogging console.error is default way of logging on error. You can disable it by setting it true
|
|
49
|
+
* @returns A tuple containing the resolved value of the Promise and an error (null if successful).
|
|
50
|
+
*/
|
|
31
51
|
static asyncFunction(fn, disableLogging) {
|
|
32
52
|
return __awaiter(this, void 0, void 0, function* () {
|
|
33
53
|
try {
|
|
@@ -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
|
}
|