@powfix/core-js 0.18.2 → 0.19.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/browser/cjs/browser/utils/UUID.js +95 -30
- package/dist/browser/cjs/shared/managers/SessionManager.js +0 -10
- package/dist/browser/cjs/shared/services/time/TimeService.js +0 -16
- package/dist/browser/cjs/shared/utils/ArrayUtils.js +0 -5
- package/dist/browser/cjs/shared/utils/AxiosUtils.js +0 -2
- package/dist/browser/cjs/shared/utils/Calc.js +1 -1
- package/dist/browser/cjs/shared/utils/DateUtils.js +0 -1
- package/dist/browser/cjs/shared/utils/Enum.js +36 -0
- package/dist/browser/cjs/shared/utils/Enum.types.js +2 -0
- package/dist/browser/cjs/shared/utils/JuminNumberUtils.js +1 -4
- package/dist/browser/cjs/shared/utils/Sequencer.js +0 -6
- package/dist/browser/cjs/shared/utils/StringUtils.js +1 -3
- package/dist/browser/cjs/shared/utils/UuidUtils.js +0 -3
- package/dist/browser/cjs/shared/utils/Validator.js +0 -11
- package/dist/browser/cjs/shared/utils/global/firstNonNullish.js +0 -1
- package/dist/browser/cjs/shared/utils/global/flat.js +0 -1
- package/dist/browser/cjs/shared/utils/index.js +2 -0
- package/dist/browser/cjs/shared/utils/try-catch/TryCatch.js +0 -20
- package/dist/browser/esm/browser/utils/UUID.mjs +94 -29
- package/dist/browser/esm/shared/managers/SessionManager.mjs +0 -10
- package/dist/browser/esm/shared/services/time/TimeService.mjs +0 -16
- package/dist/browser/esm/shared/utils/ArrayUtils.mjs +0 -5
- package/dist/browser/esm/shared/utils/AxiosUtils.mjs +0 -2
- package/dist/browser/esm/shared/utils/Calc.mjs +1 -1
- package/dist/browser/esm/shared/utils/DateUtils.mjs +0 -1
- package/dist/browser/esm/shared/utils/Enum.mjs +32 -0
- package/dist/browser/esm/shared/utils/Enum.types.mjs +1 -0
- package/dist/browser/esm/shared/utils/JuminNumberUtils.mjs +1 -4
- package/dist/browser/esm/shared/utils/Sequencer.mjs +0 -6
- package/dist/browser/esm/shared/utils/StringUtils.mjs +1 -3
- package/dist/browser/esm/shared/utils/UuidUtils.mjs +0 -3
- package/dist/browser/esm/shared/utils/Validator.mjs +0 -11
- package/dist/browser/esm/shared/utils/global/firstNonNullish.mjs +0 -1
- package/dist/browser/esm/shared/utils/global/flat.mjs +0 -1
- package/dist/browser/esm/shared/utils/index.mjs +2 -0
- package/dist/browser/esm/shared/utils/try-catch/TryCatch.mjs +0 -20
- package/dist/browser/types/browser/utils/UUID.d.ts +14 -2
- package/dist/browser/types/shared/utils/ArrayUtils.d.ts +0 -5
- package/dist/browser/types/shared/utils/Enum.d.ts +16 -0
- package/dist/browser/types/shared/utils/Enum.types.d.ts +6 -0
- package/dist/browser/types/shared/utils/UuidUtils.d.ts +0 -6
- package/dist/browser/types/shared/utils/index.d.ts +2 -0
- package/dist/browser/types/shared/utils/try-catch/TryCatch.d.ts +0 -20
- package/dist/node/cjs/browser/utils/UUID.js +95 -30
- package/dist/node/cjs/nodejs/managers/TransactionManager.js +0 -3
- package/dist/node/cjs/nodejs/services/redis/RedisClient.js +0 -2
- package/dist/node/cjs/nodejs/services/redis/RedisPublisher.js +0 -1
- package/dist/node/cjs/nodejs/services/redis/index.js +0 -1
- package/dist/node/cjs/nodejs/utils/UUID.js +3 -0
- package/dist/node/cjs/shared/managers/SessionManager.js +0 -10
- package/dist/node/cjs/shared/services/time/TimeService.js +0 -16
- package/dist/node/cjs/shared/utils/ArrayUtils.js +0 -5
- package/dist/node/cjs/shared/utils/AxiosUtils.js +0 -2
- package/dist/node/cjs/shared/utils/Calc.js +1 -1
- package/dist/node/cjs/shared/utils/DateUtils.js +0 -1
- package/dist/node/cjs/shared/utils/Enum.js +36 -0
- package/dist/node/cjs/shared/utils/Enum.types.js +2 -0
- package/dist/node/cjs/shared/utils/JuminNumberUtils.js +1 -4
- package/dist/node/cjs/shared/utils/Sequencer.js +0 -6
- package/dist/node/cjs/shared/utils/StringUtils.js +1 -3
- package/dist/node/cjs/shared/utils/UuidUtils.js +0 -3
- package/dist/node/cjs/shared/utils/Validator.js +0 -11
- package/dist/node/cjs/shared/utils/global/firstNonNullish.js +0 -1
- package/dist/node/cjs/shared/utils/global/flat.js +0 -1
- package/dist/node/cjs/shared/utils/index.js +2 -0
- package/dist/node/cjs/shared/utils/try-catch/TryCatch.js +0 -20
- package/dist/node/esm/browser/utils/UUID.mjs +94 -29
- package/dist/node/esm/nodejs/managers/TransactionManager.mjs +0 -3
- package/dist/node/esm/nodejs/services/redis/RedisClient.mjs +0 -2
- package/dist/node/esm/nodejs/services/redis/RedisPublisher.mjs +0 -1
- package/dist/node/esm/nodejs/services/redis/index.mjs +0 -1
- package/dist/node/esm/nodejs/utils/UUID.mjs +3 -0
- package/dist/node/esm/shared/managers/SessionManager.mjs +0 -10
- package/dist/node/esm/shared/services/time/TimeService.mjs +0 -16
- package/dist/node/esm/shared/utils/ArrayUtils.mjs +0 -5
- package/dist/node/esm/shared/utils/AxiosUtils.mjs +0 -2
- package/dist/node/esm/shared/utils/Calc.mjs +1 -1
- package/dist/node/esm/shared/utils/DateUtils.mjs +0 -1
- package/dist/node/esm/shared/utils/Enum.mjs +32 -0
- package/dist/node/esm/shared/utils/Enum.types.mjs +1 -0
- package/dist/node/esm/shared/utils/JuminNumberUtils.mjs +1 -4
- package/dist/node/esm/shared/utils/Sequencer.mjs +0 -6
- package/dist/node/esm/shared/utils/StringUtils.mjs +1 -3
- package/dist/node/esm/shared/utils/UuidUtils.mjs +0 -3
- package/dist/node/esm/shared/utils/Validator.mjs +0 -11
- package/dist/node/esm/shared/utils/global/firstNonNullish.mjs +0 -1
- package/dist/node/esm/shared/utils/global/flat.mjs +0 -1
- package/dist/node/esm/shared/utils/index.mjs +2 -0
- package/dist/node/esm/shared/utils/try-catch/TryCatch.mjs +0 -20
- package/dist/node/types/browser/utils/UUID.d.ts +14 -2
- package/dist/node/types/nodejs/services/redis/RedisClient.d.ts +2 -2
- package/dist/node/types/nodejs/utils/UUID.d.ts +1 -0
- package/dist/node/types/shared/utils/ArrayUtils.d.ts +0 -5
- package/dist/node/types/shared/utils/Enum.d.ts +16 -0
- package/dist/node/types/shared/utils/Enum.types.d.ts +6 -0
- package/dist/node/types/shared/utils/UuidUtils.d.ts +0 -6
- package/dist/node/types/shared/utils/index.d.ts +2 -0
- package/dist/node/types/shared/utils/try-catch/TryCatch.d.ts +0 -20
- package/package.json +2 -2
|
@@ -1,5 +1,39 @@
|
|
|
1
|
-
import { Uint8ArrayUtils } from "../../shared/
|
|
1
|
+
import { Uint8ArrayUtils } from "../../shared/index.mjs";
|
|
2
2
|
export class UUID {
|
|
3
|
+
static isValidHex(hex) {
|
|
4
|
+
if (typeof hex !== 'string') {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
return UUID.REGEX_HEX.test(hex);
|
|
8
|
+
}
|
|
9
|
+
static isValidString(str) {
|
|
10
|
+
if (typeof str !== 'string') {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
return UUID.REGEX_RFC4122.test(str);
|
|
14
|
+
}
|
|
15
|
+
static isValidBytes(bytes) {
|
|
16
|
+
return bytes.byteLength === UUID.BYTE_LENGTH;
|
|
17
|
+
}
|
|
18
|
+
static isValid(input) {
|
|
19
|
+
if (typeof input === 'string') {
|
|
20
|
+
const length = input.length;
|
|
21
|
+
switch (length) {
|
|
22
|
+
case UUID.STR_LENGTH:
|
|
23
|
+
return UUID.isValidString(input);
|
|
24
|
+
case UUID.HEX_STR_LENGTH:
|
|
25
|
+
return UUID.isValidHex(input);
|
|
26
|
+
default:
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
else if (ArrayBuffer.isView(input)) {
|
|
31
|
+
return UUID.isValidBytes(input);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
3
37
|
static formatHex(hex) {
|
|
4
38
|
if (hex.length !== UUID.HEX_STR_LENGTH) {
|
|
5
39
|
throw new Error(`hex length should be ${UUID.HEX_STR_LENGTH}`);
|
|
@@ -13,34 +47,74 @@ export class UUID {
|
|
|
13
47
|
static stripHyphens(str) {
|
|
14
48
|
return str.replace(/-/g, "");
|
|
15
49
|
}
|
|
50
|
+
static parseHex(hex) {
|
|
51
|
+
if (hex.length !== UUID.HEX_STR_LENGTH) {
|
|
52
|
+
throw new Error(`Invalid hex string, length should be ${UUID.HEX_STR_LENGTH}`);
|
|
53
|
+
}
|
|
54
|
+
return Uint8ArrayUtils.fromHex(hex);
|
|
55
|
+
}
|
|
16
56
|
static parseString(str) {
|
|
57
|
+
if (str.length !== UUID.STR_LENGTH) {
|
|
58
|
+
throw new Error(`Invalid UUID string, invalid character length should be ${UUID.STR_LENGTH}`);
|
|
59
|
+
}
|
|
60
|
+
if (!UUID.isValid(str)) {
|
|
61
|
+
throw new Error('Invalid UUID string, should be RFC 4122 format');
|
|
62
|
+
}
|
|
17
63
|
const hex = UUID.stripHyphens(str);
|
|
18
64
|
if (hex.length !== UUID.HEX_STR_LENGTH) {
|
|
19
|
-
throw new Error('Invalid UUID string');
|
|
65
|
+
throw new Error('Invalid UUID string, invalid character length after strip hyphens');
|
|
20
66
|
}
|
|
21
67
|
return Uint8ArrayUtils.fromHex(hex);
|
|
22
68
|
}
|
|
69
|
+
static parseBytes(bytes) {
|
|
70
|
+
const view = new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
71
|
+
if (view.length !== UUID.BYTE_LENGTH) {
|
|
72
|
+
throw new Error(`Expected ${UUID.BYTE_LENGTH} bytes`);
|
|
73
|
+
}
|
|
74
|
+
return new Uint8Array(view);
|
|
75
|
+
}
|
|
76
|
+
static fromHex(hex) {
|
|
77
|
+
return new UUID(UUID.parseHex(hex));
|
|
78
|
+
}
|
|
23
79
|
static fromString(str) {
|
|
24
|
-
return new UUID(str);
|
|
80
|
+
return new UUID(UUID.parseString(str));
|
|
25
81
|
}
|
|
26
|
-
static
|
|
27
|
-
|
|
28
|
-
|
|
82
|
+
static fromBytes(bytes) {
|
|
83
|
+
return new UUID(UUID.parseBytes(bytes));
|
|
84
|
+
}
|
|
85
|
+
static parse(input) {
|
|
86
|
+
if (typeof input === 'string') {
|
|
87
|
+
const length = input.length;
|
|
88
|
+
switch (length) {
|
|
89
|
+
case UUID.STR_LENGTH:
|
|
90
|
+
return UUID.parseString(input);
|
|
91
|
+
case UUID.HEX_STR_LENGTH:
|
|
92
|
+
return UUID.parseHex(input);
|
|
93
|
+
default:
|
|
94
|
+
throw new Error(`Invalid input string, length should be ${UUID.STR_LENGTH} or ${UUID.HEX_STR_LENGTH}`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else if (ArrayBuffer.isView(input)) {
|
|
98
|
+
return UUID.parseBytes(input);
|
|
29
99
|
}
|
|
30
100
|
else {
|
|
31
|
-
|
|
101
|
+
throw new Error("Invalid input, Expected string or ArrayBufferView");
|
|
32
102
|
}
|
|
33
103
|
}
|
|
34
|
-
static
|
|
35
|
-
return
|
|
104
|
+
static from(input) {
|
|
105
|
+
return UUID.fromBytes(UUID.parse(input));
|
|
36
106
|
}
|
|
37
107
|
static nil() {
|
|
38
|
-
return
|
|
108
|
+
return UUID.fromBytes(new Uint8Array(UUID.BYTE_LENGTH));
|
|
109
|
+
}
|
|
110
|
+
static max() {
|
|
111
|
+
return UUID.fromBytes((new Uint8Array(UUID.BYTE_LENGTH)).fill(0xFF));
|
|
39
112
|
}
|
|
40
113
|
static equals(...uuids) {
|
|
41
114
|
const n = uuids.length;
|
|
42
|
-
if (n
|
|
43
|
-
|
|
115
|
+
if (n < 2) {
|
|
116
|
+
throw new Error('At least two UUIDs required for comparison');
|
|
117
|
+
}
|
|
44
118
|
const ref = uuids[0].bytes;
|
|
45
119
|
for (let i = 1; i < n; ++i) {
|
|
46
120
|
const b = uuids[i].bytes;
|
|
@@ -61,21 +135,7 @@ export class UUID {
|
|
|
61
135
|
return 0;
|
|
62
136
|
}
|
|
63
137
|
constructor(input) {
|
|
64
|
-
|
|
65
|
-
throw new Error('Input cannot be null');
|
|
66
|
-
}
|
|
67
|
-
if (typeof input === 'string') {
|
|
68
|
-
this.bytes = UUID.parseString(input);
|
|
69
|
-
}
|
|
70
|
-
else if (ArrayBuffer.isView(input)) {
|
|
71
|
-
this.bytes = UUID.parseBytes(input);
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
throw new Error("Expected string or ArrayBufferView");
|
|
75
|
-
}
|
|
76
|
-
if (this.bytes.byteLength !== UUID.BYTE_LENGTH) {
|
|
77
|
-
throw new Error(`UUID must be ${UUID.BYTE_LENGTH} bytes`);
|
|
78
|
-
}
|
|
138
|
+
this.bytes = UUID.parse(input);
|
|
79
139
|
}
|
|
80
140
|
equals(...uuids) {
|
|
81
141
|
return UUID.equals(this, ...uuids);
|
|
@@ -88,13 +148,15 @@ export class UUID {
|
|
|
88
148
|
return this._str;
|
|
89
149
|
}
|
|
90
150
|
const hex = this.toHex();
|
|
91
|
-
|
|
151
|
+
this._str = UUID.formatHex(hex);
|
|
152
|
+
return this._str;
|
|
92
153
|
}
|
|
93
154
|
toHex() {
|
|
94
155
|
if (this._hex != null) {
|
|
95
156
|
return this._hex;
|
|
96
157
|
}
|
|
97
|
-
|
|
158
|
+
this._hex = Uint8ArrayUtils.toHex(this.bytes);
|
|
159
|
+
return this._hex;
|
|
98
160
|
}
|
|
99
161
|
toBytes() {
|
|
100
162
|
return new Uint8Array(this.bytes);
|
|
@@ -103,5 +165,8 @@ export class UUID {
|
|
|
103
165
|
return this.toString();
|
|
104
166
|
}
|
|
105
167
|
}
|
|
168
|
+
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}$/;
|
|
169
|
+
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}$/;
|
|
106
170
|
UUID.BYTE_LENGTH = 16;
|
|
171
|
+
UUID.STR_LENGTH = 36;
|
|
107
172
|
UUID.HEX_STR_LENGTH = 32;
|
|
@@ -13,10 +13,8 @@ import EventEmitter from 'eventemitter3';
|
|
|
13
13
|
export class SessionManager extends EventEmitter {
|
|
14
14
|
constructor(options) {
|
|
15
15
|
super();
|
|
16
|
-
// Init service parameters
|
|
17
16
|
this.api = options.api;
|
|
18
17
|
this.storageProvider = options.storageProvider;
|
|
19
|
-
// Logging
|
|
20
18
|
console.log('SessionManager initialized', Date.now(), options.api);
|
|
21
19
|
}
|
|
22
20
|
get key() {
|
|
@@ -57,7 +55,6 @@ export class SessionManager extends EventEmitter {
|
|
|
57
55
|
return null;
|
|
58
56
|
}
|
|
59
57
|
try {
|
|
60
|
-
// Replace Bearer prefix
|
|
61
58
|
nextAuthorization = nextAuthorization.replace(/^Bearer\s+/, '');
|
|
62
59
|
const decoded = jwtDecode(nextAuthorization);
|
|
63
60
|
if (!decoded) {
|
|
@@ -98,13 +95,9 @@ export class SessionManager extends EventEmitter {
|
|
|
98
95
|
return [decoded.exp, exp.format(), exp.diff(Date.now(), 'days'), 'days left'];
|
|
99
96
|
})());
|
|
100
97
|
})();
|
|
101
|
-
// AsyncStorage 에 토큰 저장
|
|
102
98
|
yield this.storageProvider.set(this.key, nextAuthorization);
|
|
103
|
-
// API Instance header 설정
|
|
104
99
|
this.api.defaults.headers.common.Authorization = `Bearer ${nextAuthorization}`;
|
|
105
|
-
// Emit
|
|
106
100
|
this.emit('AUTHORIZATION_CHANGED', nextAuthorization);
|
|
107
|
-
// Return
|
|
108
101
|
return nextAuthorization;
|
|
109
102
|
}
|
|
110
103
|
catch (e) {
|
|
@@ -115,11 +108,8 @@ export class SessionManager extends EventEmitter {
|
|
|
115
108
|
}
|
|
116
109
|
removeAuthorization() {
|
|
117
110
|
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
-
// API Instance header 에서 토큰 제거
|
|
119
111
|
delete this.api.defaults.headers.common.Authorization;
|
|
120
|
-
// 스토리지에서 authorization 제거
|
|
121
112
|
yield this.storageProvider.remove(this.key);
|
|
122
|
-
// Emit
|
|
123
113
|
this.emit('AUTHORIZATION_CHANGED', null);
|
|
124
114
|
});
|
|
125
115
|
}
|
|
@@ -16,11 +16,9 @@ export class TimeService extends EventEmitter {
|
|
|
16
16
|
}
|
|
17
17
|
constructor(options) {
|
|
18
18
|
super();
|
|
19
|
-
// Options
|
|
20
19
|
this.syncInterval = options === null || options === void 0 ? void 0 : options.syncInterval;
|
|
21
20
|
this.clientTimeProvider = options === null || options === void 0 ? void 0 : options.clientTimeProvider;
|
|
22
21
|
this.serverTimeProvider = options === null || options === void 0 ? void 0 : options.serverTimeProvider;
|
|
23
|
-
// Bind
|
|
24
22
|
this.sync = this.sync.bind(this);
|
|
25
23
|
this.fetchServerNTPResult = this.fetchServerNTPResult.bind(this);
|
|
26
24
|
}
|
|
@@ -47,7 +45,6 @@ export class TimeService extends EventEmitter {
|
|
|
47
45
|
}
|
|
48
46
|
setSyncInterval(interval) {
|
|
49
47
|
this.syncInterval = interval;
|
|
50
|
-
// Emit
|
|
51
48
|
this.emit('SYNC_INTERVAL_CHANGED', interval);
|
|
52
49
|
if (this.syncHandler !== undefined) {
|
|
53
50
|
this.stopSync();
|
|
@@ -102,32 +99,22 @@ export class TimeService extends EventEmitter {
|
|
|
102
99
|
sync() {
|
|
103
100
|
return __awaiter(this, void 0, void 0, function* () {
|
|
104
101
|
try {
|
|
105
|
-
// T1 (Client Request Time)
|
|
106
102
|
const requestedAt = Date.now();
|
|
107
|
-
// Fetch server time from server
|
|
108
103
|
const serverNtpResult = yield this.fetchServerNTPResult(requestedAt);
|
|
109
|
-
// Check is null
|
|
110
104
|
if (serverNtpResult === null) {
|
|
111
105
|
console.warn(LOG_TAG, 'Failed to get server time');
|
|
112
106
|
return null;
|
|
113
107
|
}
|
|
114
|
-
// T2 (Server Receive Time)
|
|
115
108
|
const { t2 } = serverNtpResult;
|
|
116
|
-
// Check is not a number
|
|
117
109
|
if (isNaN(Number(t2))) {
|
|
118
|
-
// Not a Number
|
|
119
110
|
console.error(LOG_TAG, 'invalid server time(t2), not a number', t2);
|
|
120
111
|
return null;
|
|
121
112
|
}
|
|
122
|
-
// T3 (Server Transmit Time)
|
|
123
113
|
const { t3 } = serverNtpResult;
|
|
124
|
-
// Check is not a number
|
|
125
114
|
if (isNaN(Number(t3))) {
|
|
126
|
-
// Not a Number
|
|
127
115
|
console.error(LOG_TAG, 'invalid server time(t2), not a number', t2);
|
|
128
116
|
return null;
|
|
129
117
|
}
|
|
130
|
-
// T4 (Client Receive Time)
|
|
131
118
|
const receivedAt = Date.now();
|
|
132
119
|
const ntpResult = {
|
|
133
120
|
t1: requestedAt,
|
|
@@ -135,11 +122,8 @@ export class TimeService extends EventEmitter {
|
|
|
135
122
|
t3: t3,
|
|
136
123
|
t4: receivedAt,
|
|
137
124
|
};
|
|
138
|
-
// Calculate offset
|
|
139
125
|
const offset = TimeService.calculateNTPResultOffset(ntpResult);
|
|
140
|
-
// Save calculated offset
|
|
141
126
|
this.setOffset(offset);
|
|
142
|
-
// Mark synced timestamp
|
|
143
127
|
const syncedAt = Date.now();
|
|
144
128
|
this.setSyncedAt(syncedAt);
|
|
145
129
|
this.emit('SYNCED', offset, syncedAt);
|
|
@@ -3,11 +3,6 @@ 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
|
-
*/
|
|
11
6
|
static getGreatestObject(e, key) {
|
|
12
7
|
return e.reduce((prev, current) => ((prev[key] > current[key] ? prev : current)));
|
|
13
8
|
}
|
|
@@ -13,7 +13,6 @@ export class AxiosUtils {
|
|
|
13
13
|
return e;
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
-
// There is no any values having string type
|
|
17
16
|
return null;
|
|
18
17
|
}
|
|
19
18
|
else {
|
|
@@ -36,7 +35,6 @@ export class AxiosUtils {
|
|
|
36
35
|
return e;
|
|
37
36
|
}
|
|
38
37
|
}
|
|
39
|
-
// There is no any values having string type
|
|
40
38
|
return null;
|
|
41
39
|
}
|
|
42
40
|
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);
|
|
18
18
|
const mid = len >> 1;
|
|
19
19
|
return len % 2 === 0
|
|
20
20
|
? (sorted[mid - 1] + sorted[mid]) / 2
|
|
@@ -100,7 +100,6 @@ export class DateUtils {
|
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
DateUtils.relativeDate = (input, base = Date.now()) => {
|
|
103
|
-
// Create new moment instance to apply new locale
|
|
104
103
|
const datetime = moment.isMoment(input) ? moment(input.toDate()) : moment(input);
|
|
105
104
|
if (!datetime.isValid()) {
|
|
106
105
|
console.error('core-js:DateUtils.relativeDate() datetime is invalid', datetime);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export class Enum {
|
|
2
|
+
static entries(e) {
|
|
3
|
+
return Object.entries(e).filter(([key, value]) => !/^-?\d+$/g.test(key) && typeof value !== 'function');
|
|
4
|
+
}
|
|
5
|
+
static keys(e) {
|
|
6
|
+
return Enum.entries(e).map(([key,]) => key);
|
|
7
|
+
}
|
|
8
|
+
static values(e) {
|
|
9
|
+
return Enum.entries(e).map(([, value]) => value);
|
|
10
|
+
}
|
|
11
|
+
static from(e) {
|
|
12
|
+
return new Enum(e);
|
|
13
|
+
}
|
|
14
|
+
constructor(e) {
|
|
15
|
+
this._e = e;
|
|
16
|
+
this._entries = Enum.entries(e);
|
|
17
|
+
this._keys = Enum.keys(e);
|
|
18
|
+
this._values = Enum.values(e);
|
|
19
|
+
}
|
|
20
|
+
value() {
|
|
21
|
+
return this._e;
|
|
22
|
+
}
|
|
23
|
+
entries() {
|
|
24
|
+
return this._entries;
|
|
25
|
+
}
|
|
26
|
+
keys() {
|
|
27
|
+
return this._keys;
|
|
28
|
+
}
|
|
29
|
+
values() {
|
|
30
|
+
return this._values;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -16,10 +16,9 @@ export class JuminNumberUtils {
|
|
|
16
16
|
if (replacedJuminNumber.length !== 13) {
|
|
17
17
|
return false;
|
|
18
18
|
}
|
|
19
|
-
// 연도에 해당하는 숫자와 성별에 해당하는 숫자 비교
|
|
20
19
|
const TODAY_YEAR = parseInt(new Date().getFullYear().toString().slice(-2), 10);
|
|
21
20
|
const yearNum = parseInt(replacedJuminNumber.slice(0, 2), 10);
|
|
22
|
-
const sexNum = replacedJuminNumber.slice(6, 7);
|
|
21
|
+
const sexNum = replacedJuminNumber.slice(6, 7);
|
|
23
22
|
if (sexNum === '1' || sexNum === '2') {
|
|
24
23
|
if (yearNum < TODAY_YEAR)
|
|
25
24
|
return false;
|
|
@@ -30,11 +29,9 @@ export class JuminNumberUtils {
|
|
|
30
29
|
}
|
|
31
30
|
else
|
|
32
31
|
return false;
|
|
33
|
-
// 월과 일에 해당하는 숫자 조건 검사 (정규식으로)
|
|
34
32
|
const regex = /^\d{2}(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])\d{7}$/;
|
|
35
33
|
if (!regex.test(replacedJuminNumber))
|
|
36
34
|
return false;
|
|
37
|
-
// Validation X
|
|
38
35
|
const currentX = parseInt(replacedJuminNumber.slice(-1), 10);
|
|
39
36
|
const calculatedX = JuminNumberUtils.calculateX(replacedJuminNumber);
|
|
40
37
|
if (currentX !== calculatedX) {
|
|
@@ -28,11 +28,9 @@ export class Sequencer {
|
|
|
28
28
|
this.sequences = [];
|
|
29
29
|
this.status = SequencerStatus.IDLE;
|
|
30
30
|
this.minimumExecutionTime = 0;
|
|
31
|
-
// Reset variables task is done
|
|
32
31
|
this.currentSequence = null;
|
|
33
32
|
this.startTimestamp = null;
|
|
34
33
|
this.endTimestamp = null;
|
|
35
|
-
// Emitter
|
|
36
34
|
this.eventEmitter = new EventEmitter3();
|
|
37
35
|
this.pushSequence = (sequence) => {
|
|
38
36
|
this.sequences.push(sequence);
|
|
@@ -51,7 +49,6 @@ export class Sequencer {
|
|
|
51
49
|
console.log('Currently total execution time', this.executionTime);
|
|
52
50
|
const sequenceStartTimeStamp = this.getCurrentTimeStamp;
|
|
53
51
|
this.currentSequence = sequence;
|
|
54
|
-
// Emitter
|
|
55
52
|
this.eventEmitter.emit(SequencerEvent.SEQUENCE_START, sequence);
|
|
56
53
|
try {
|
|
57
54
|
yield new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -95,7 +92,6 @@ export class Sequencer {
|
|
|
95
92
|
}
|
|
96
93
|
}));
|
|
97
94
|
console.log('Out of Promise');
|
|
98
|
-
// Emitter
|
|
99
95
|
this.eventEmitter.emit(SequencerEvent.SEQUENCE_END, sequence);
|
|
100
96
|
}
|
|
101
97
|
catch (e) {
|
|
@@ -104,14 +100,12 @@ export class Sequencer {
|
|
|
104
100
|
this.status = SequencerStatus.ERROR;
|
|
105
101
|
this.currentSequence = null;
|
|
106
102
|
this.endTimestamp = this.currentSequence;
|
|
107
|
-
// IMPORTANT
|
|
108
103
|
return Promise.reject({
|
|
109
104
|
sequence,
|
|
110
105
|
reason: e,
|
|
111
106
|
});
|
|
112
107
|
}
|
|
113
108
|
console.log(`Sequence ${sequence.key} failed`, e);
|
|
114
|
-
// Emitter
|
|
115
109
|
this.eventEmitter.emit(SequencerEvent.SEQUENCE_END, sequence);
|
|
116
110
|
}
|
|
117
111
|
}
|
|
@@ -24,9 +24,7 @@ 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,
|
|
28
|
-
track[j - 1][i] + 1, // insertion
|
|
29
|
-
track[j - 1][i - 1] + indicator);
|
|
27
|
+
track[j][i] = Math.min(track[j][i - 1] + 1, track[j - 1][i] + 1, track[j - 1][i - 1] + indicator);
|
|
30
28
|
}
|
|
31
29
|
}
|
|
32
30
|
return track[str2.length][str1.length];
|
|
@@ -6,15 +6,12 @@ export class UuidUtils {
|
|
|
6
6
|
}
|
|
7
7
|
static format(uuid) {
|
|
8
8
|
if (uuid.length === 32) {
|
|
9
|
-
// Without dash: ca23c587d7f84c76be59f53bbc9f91f8
|
|
10
9
|
return `${uuid.substring(0, 8)}-${uuid.substring(8, 12)}-${uuid.substring(12, 16)}-${uuid.substring(16, 20)}-${uuid.substring(20, 32)}`.toLowerCase();
|
|
11
10
|
}
|
|
12
11
|
else if (uuid.length === 36) {
|
|
13
|
-
// With dash: ca23c587-d7f8-4c76-be59-f53bbc9f91f8
|
|
14
12
|
return uuid.toLowerCase();
|
|
15
13
|
}
|
|
16
14
|
else {
|
|
17
|
-
// Unexpected uuid
|
|
18
15
|
console.warn('Unexpected uuid length', uuid);
|
|
19
16
|
return uuid;
|
|
20
17
|
}
|
|
@@ -13,14 +13,12 @@ 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
|
-
// 최소 길이
|
|
17
16
|
if (options.minLength !== undefined && options.minLength > -1) {
|
|
18
17
|
validations.push(Validator.VALIDATION.MIN_LENGTH);
|
|
19
18
|
if (length < options.minLength) {
|
|
20
19
|
errors.push(Validator.VALIDATION.MIN_LENGTH);
|
|
21
20
|
}
|
|
22
21
|
}
|
|
23
|
-
// 최대 길이
|
|
24
22
|
if (options.maxLength !== undefined && options.maxLength > -1) {
|
|
25
23
|
validations.push(Validator.VALIDATION.MAX_LENGTH);
|
|
26
24
|
if (length > options.maxLength) {
|
|
@@ -43,39 +41,30 @@ export class Validator {
|
|
|
43
41
|
}
|
|
44
42
|
}
|
|
45
43
|
};
|
|
46
|
-
// 공백 개수
|
|
47
44
|
validateMin(options.spaceMinCount, spaceCount, Validator.VALIDATION.SPACE_MIN_COUNT);
|
|
48
45
|
validateMax(options.spaceMaxCount, spaceCount, Validator.VALIDATION.SPACE_MAX_COUNT);
|
|
49
|
-
// 숫자 개수
|
|
50
46
|
validateMin(options.numberMinCount, numberCount, Validator.VALIDATION.NUMBER_MIN_COUNT);
|
|
51
47
|
validateMax(options.numberMaxCount, numberCount, Validator.VALIDATION.NUMBER_MAX_COUNT);
|
|
52
|
-
// 알파벳 개수
|
|
53
48
|
validateMin(options.alphabetMinCount, alphabetCount, Validator.VALIDATION.ALPHABET_MIN_COUNT);
|
|
54
49
|
validateMax(options.alphabetMaxCount, alphabetCount, Validator.VALIDATION.ALPHABET_MAX_COUNT);
|
|
55
|
-
// 알파벳(소문자) 개수
|
|
56
50
|
validateMin(options.alphabetLowerCaseMinCount, alphabetLowerCaseCount, Validator.VALIDATION.ALPHABET_LOWER_CASE_MIN_COUNT);
|
|
57
51
|
validateMax(options.alphabetLowerCaseMaxCount, alphabetLowerCaseCount, Validator.VALIDATION.ALPHABET_LOWER_CASE_MAX_COUNT);
|
|
58
|
-
// 알파벳(대문자) 개수
|
|
59
52
|
validateMin(options.alphabetUpperCaseMinCount, alphabetUpperCaseCount, Validator.VALIDATION.ALPHABET_UPPER_CASE_MIN_COUNT);
|
|
60
53
|
validateMax(options.alphabetUpperCaseMaxCount, alphabetUpperCaseCount, Validator.VALIDATION.ALPHABET_UPPER_CASE_MAX_COUNT);
|
|
61
|
-
// 특수문자 개수
|
|
62
54
|
validateMin(options.specialCharacterMinCount, specialCount, Validator.VALIDATION.SPECIAL_CHARACTER_MIN_COUNT);
|
|
63
55
|
validateMax(options.specialCharacterMaxCount, specialCount, Validator.VALIDATION.SPECIAL_CHARACTER_MAX_COUNT);
|
|
64
|
-
// 숫자로 시작
|
|
65
56
|
if (options.startsWithNumber) {
|
|
66
57
|
validations.push(Validator.VALIDATION.STARTS_WITH_NUMBER);
|
|
67
58
|
if (!startsWithNumber) {
|
|
68
59
|
errors.push(Validator.VALIDATION.STARTS_WITH_NUMBER);
|
|
69
60
|
}
|
|
70
61
|
}
|
|
71
|
-
// 영문으로 시작
|
|
72
62
|
if (options.startsWithAlphabet) {
|
|
73
63
|
validations.push(Validator.VALIDATION.STARTS_WITH_ALPHABET);
|
|
74
64
|
if (!startsWithAlphabet) {
|
|
75
65
|
errors.push(Validator.VALIDATION.STARTS_WITH_ALPHABET);
|
|
76
66
|
}
|
|
77
67
|
}
|
|
78
|
-
// 특수문자로 시작
|
|
79
68
|
if (options.startsWithSpecialCharacter) {
|
|
80
69
|
validations.push(Validator.VALIDATION.STARTS_WITH_SPECIAL_CHARACTER);
|
|
81
70
|
if (!startsWithSpecialCharacter) {
|
|
@@ -8,6 +8,8 @@ export * from './BooleanUtils.mjs';
|
|
|
8
8
|
export * from './Calc.mjs';
|
|
9
9
|
export * from './CoordinateUtils.mjs';
|
|
10
10
|
export * from './DateUtils.mjs';
|
|
11
|
+
export * from './Enum.mjs';
|
|
12
|
+
export * from './Enum.types.mjs';
|
|
11
13
|
export * from './I18nUtils.mjs';
|
|
12
14
|
export * from './NumberUtils.mjs';
|
|
13
15
|
export * from './ObjectIdUtils.mjs';
|
|
@@ -7,19 +7,7 @@ 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
|
-
*/
|
|
14
10
|
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
|
-
*/
|
|
23
11
|
static function(fn, disableLogging) {
|
|
24
12
|
try {
|
|
25
13
|
return [
|
|
@@ -40,14 +28,6 @@ export class TryCatch {
|
|
|
40
28
|
];
|
|
41
29
|
}
|
|
42
30
|
}
|
|
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
|
-
*/
|
|
51
31
|
static asyncFunction(fn, disableLogging) {
|
|
52
32
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53
33
|
try {
|
|
@@ -1,16 +1,28 @@
|
|
|
1
1
|
export declare class UUID {
|
|
2
|
+
private static REGEX_HEX;
|
|
3
|
+
private static REGEX_RFC4122;
|
|
2
4
|
private static BYTE_LENGTH;
|
|
5
|
+
private static STR_LENGTH;
|
|
3
6
|
private static HEX_STR_LENGTH;
|
|
7
|
+
static isValidHex(hex: string): boolean;
|
|
8
|
+
static isValidString(str: string): boolean;
|
|
9
|
+
static isValidBytes(bytes: ArrayBufferView): boolean;
|
|
10
|
+
static isValid(input: string | ArrayBufferView): boolean;
|
|
4
11
|
private static formatHex;
|
|
5
12
|
private static stripHyphens;
|
|
13
|
+
private static parseHex;
|
|
6
14
|
private static parseString;
|
|
7
|
-
static fromString(str: string): UUID;
|
|
8
15
|
private static parseBytes;
|
|
16
|
+
static fromHex(hex: string): UUID;
|
|
17
|
+
static fromString(str: string): UUID;
|
|
9
18
|
static fromBytes(bytes: ArrayBufferView): UUID;
|
|
19
|
+
private static parse;
|
|
20
|
+
static from(input: string | ArrayBufferView): UUID;
|
|
10
21
|
static nil(): UUID;
|
|
22
|
+
static max(): UUID;
|
|
11
23
|
static equals(...uuids: UUID[]): boolean;
|
|
12
24
|
static compare(uuid1: UUID, uuid2: UUID): number;
|
|
13
|
-
|
|
25
|
+
protected readonly bytes: Uint8Array;
|
|
14
26
|
private _str?;
|
|
15
27
|
private _hex?;
|
|
16
28
|
constructor(input: string | ArrayBufferView);
|
|
@@ -1,10 +1,5 @@
|
|
|
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
|
-
*/
|
|
8
3
|
static getGreatestObject(e: any[], key: string): any;
|
|
9
4
|
static removeDuplicate<T>(arr: T[]): T[];
|
|
10
5
|
static removeObjectDuplicate(arr: any[], key: string): any[];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { EnumEntries } from "./Enum.types";
|
|
2
|
+
export declare class Enum<E extends object> {
|
|
3
|
+
static entries<E extends object>(e: E): EnumEntries<E>;
|
|
4
|
+
static keys<E extends object>(e: E): ({ [K in keyof E]: E[K] extends Function ? never : K; }[keyof E] extends infer R ? R extends never ? never : R : never)[];
|
|
5
|
+
static values<E extends object>(e: E): ({ [K in keyof E]: E[K] extends Function ? never : E[K]; }[keyof E] extends infer R ? R extends never ? never : R : never)[];
|
|
6
|
+
static from<E extends object>(e: E): Enum<E>;
|
|
7
|
+
private readonly _e;
|
|
8
|
+
private readonly _entries;
|
|
9
|
+
private readonly _keys;
|
|
10
|
+
private readonly _values;
|
|
11
|
+
constructor(e: E);
|
|
12
|
+
value(): E;
|
|
13
|
+
entries(): EnumEntries<E>;
|
|
14
|
+
keys(): ({ [K in keyof E]: E[K] extends Function ? never : K; }[keyof E] extends infer R ? R extends never ? never : R : never)[];
|
|
15
|
+
values(): ({ [K in keyof E]: E[K] extends Function ? never : E[K]; }[keyof E] extends infer R ? R extends never ? never : R : never)[];
|
|
16
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
type NonFunction<T, Type extends "keys" | "values"> = {
|
|
2
|
+
[K in keyof T]: T[K] extends Function ? never : Type extends "keys" ? K : T[K];
|
|
3
|
+
}[keyof T] extends infer R ? (R extends never ? never : R) : never;
|
|
4
|
+
export type EnumEntry<E extends object> = [NonFunction<E, "keys">, NonFunction<E, "values">];
|
|
5
|
+
export type EnumEntries<E extends object> = EnumEntry<E>[];
|
|
6
|
+
export {};
|
|
@@ -1,13 +1,7 @@
|
|
|
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
|
-
*/
|
|
9
4
|
static toString(binary: Uint8Array): string;
|
|
10
|
-
/** (UUID: string) to (UUID: Buffer) */
|
|
11
5
|
static toBuffer(uuid: string): Buffer;
|
|
12
6
|
static toBuffer(uuid: string | null | undefined): Buffer | null;
|
|
13
7
|
static isValidUUID(uuid: string): boolean;
|