@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.
Files changed (83) hide show
  1. package/dist/browser/cjs/browser/utils/UUID.js +132 -0
  2. package/dist/browser/cjs/shared/managers/SessionManager.js +10 -0
  3. package/dist/browser/cjs/shared/services/time/TimeService.js +16 -0
  4. package/dist/browser/cjs/shared/utils/ArrayUtils.js +5 -0
  5. package/dist/browser/cjs/shared/utils/AxiosUtils.js +2 -0
  6. package/dist/browser/cjs/shared/utils/Calc.js +1 -1
  7. package/dist/browser/cjs/shared/utils/DateUtils.js +1 -0
  8. package/dist/browser/cjs/shared/utils/JuminNumberUtils.js +4 -1
  9. package/dist/browser/cjs/shared/utils/Sequencer.js +6 -0
  10. package/dist/browser/cjs/shared/utils/StringUtils.js +3 -1
  11. package/dist/browser/cjs/shared/utils/UuidUtils.js +3 -0
  12. package/dist/browser/cjs/shared/utils/Validator.js +11 -0
  13. package/dist/browser/cjs/shared/utils/global/firstNonNullish.js +1 -0
  14. package/dist/browser/cjs/shared/utils/global/flat.js +1 -0
  15. package/dist/browser/cjs/shared/utils/global/pureEnum.js +9 -0
  16. package/dist/browser/cjs/shared/utils/try-catch/TryCatch.js +20 -0
  17. package/dist/browser/esm/browser/utils/UUID.mjs +132 -0
  18. package/dist/browser/esm/shared/managers/SessionManager.mjs +10 -0
  19. package/dist/browser/esm/shared/services/time/TimeService.mjs +16 -0
  20. package/dist/browser/esm/shared/utils/ArrayUtils.mjs +5 -0
  21. package/dist/browser/esm/shared/utils/AxiosUtils.mjs +2 -0
  22. package/dist/browser/esm/shared/utils/Calc.mjs +1 -1
  23. package/dist/browser/esm/shared/utils/DateUtils.mjs +1 -0
  24. package/dist/browser/esm/shared/utils/JuminNumberUtils.mjs +4 -1
  25. package/dist/browser/esm/shared/utils/Sequencer.mjs +6 -0
  26. package/dist/browser/esm/shared/utils/StringUtils.mjs +3 -1
  27. package/dist/browser/esm/shared/utils/UuidUtils.mjs +3 -0
  28. package/dist/browser/esm/shared/utils/Validator.mjs +11 -0
  29. package/dist/browser/esm/shared/utils/global/firstNonNullish.mjs +1 -0
  30. package/dist/browser/esm/shared/utils/global/flat.mjs +1 -0
  31. package/dist/browser/esm/shared/utils/global/pureEnum.mjs +9 -0
  32. package/dist/browser/esm/shared/utils/try-catch/TryCatch.mjs +20 -0
  33. package/dist/browser/types/browser/utils/UUID.d.ts +109 -0
  34. package/dist/browser/types/shared/utils/ArrayUtils.d.ts +5 -0
  35. package/dist/browser/types/shared/utils/UuidUtils.d.ts +6 -0
  36. package/dist/browser/types/shared/utils/global/pureEnum.d.ts +9 -0
  37. package/dist/browser/types/shared/utils/try-catch/TryCatch.d.ts +20 -0
  38. package/dist/node/cjs/browser/utils/UUID.js +132 -0
  39. package/dist/node/cjs/nodejs/managers/TransactionManager.js +3 -0
  40. package/dist/node/cjs/nodejs/services/redis/RedisClient.js +2 -0
  41. package/dist/node/cjs/nodejs/services/redis/RedisPublisher.js +1 -0
  42. package/dist/node/cjs/nodejs/services/redis/index.js +1 -0
  43. package/dist/node/cjs/shared/managers/SessionManager.js +10 -0
  44. package/dist/node/cjs/shared/services/time/TimeService.js +16 -0
  45. package/dist/node/cjs/shared/utils/ArrayUtils.js +5 -0
  46. package/dist/node/cjs/shared/utils/AxiosUtils.js +2 -0
  47. package/dist/node/cjs/shared/utils/Calc.js +1 -1
  48. package/dist/node/cjs/shared/utils/DateUtils.js +1 -0
  49. package/dist/node/cjs/shared/utils/JuminNumberUtils.js +4 -1
  50. package/dist/node/cjs/shared/utils/Sequencer.js +6 -0
  51. package/dist/node/cjs/shared/utils/StringUtils.js +3 -1
  52. package/dist/node/cjs/shared/utils/UuidUtils.js +3 -0
  53. package/dist/node/cjs/shared/utils/Validator.js +11 -0
  54. package/dist/node/cjs/shared/utils/global/firstNonNullish.js +1 -0
  55. package/dist/node/cjs/shared/utils/global/flat.js +1 -0
  56. package/dist/node/cjs/shared/utils/global/pureEnum.js +9 -0
  57. package/dist/node/cjs/shared/utils/try-catch/TryCatch.js +20 -0
  58. package/dist/node/esm/browser/utils/UUID.mjs +132 -0
  59. package/dist/node/esm/nodejs/managers/TransactionManager.mjs +3 -0
  60. package/dist/node/esm/nodejs/services/redis/RedisClient.mjs +2 -0
  61. package/dist/node/esm/nodejs/services/redis/RedisPublisher.mjs +1 -0
  62. package/dist/node/esm/nodejs/services/redis/index.mjs +1 -0
  63. package/dist/node/esm/shared/managers/SessionManager.mjs +10 -0
  64. package/dist/node/esm/shared/services/time/TimeService.mjs +16 -0
  65. package/dist/node/esm/shared/utils/ArrayUtils.mjs +5 -0
  66. package/dist/node/esm/shared/utils/AxiosUtils.mjs +2 -0
  67. package/dist/node/esm/shared/utils/Calc.mjs +1 -1
  68. package/dist/node/esm/shared/utils/DateUtils.mjs +1 -0
  69. package/dist/node/esm/shared/utils/JuminNumberUtils.mjs +4 -1
  70. package/dist/node/esm/shared/utils/Sequencer.mjs +6 -0
  71. package/dist/node/esm/shared/utils/StringUtils.mjs +3 -1
  72. package/dist/node/esm/shared/utils/UuidUtils.mjs +3 -0
  73. package/dist/node/esm/shared/utils/Validator.mjs +11 -0
  74. package/dist/node/esm/shared/utils/global/firstNonNullish.mjs +1 -0
  75. package/dist/node/esm/shared/utils/global/flat.mjs +1 -0
  76. package/dist/node/esm/shared/utils/global/pureEnum.mjs +9 -0
  77. package/dist/node/esm/shared/utils/try-catch/TryCatch.mjs +20 -0
  78. package/dist/node/types/browser/utils/UUID.d.ts +109 -0
  79. package/dist/node/types/shared/utils/ArrayUtils.d.ts +5 -0
  80. package/dist/node/types/shared/utils/UuidUtils.d.ts +6 -0
  81. package/dist/node/types/shared/utils/global/pureEnum.d.ts +9 -0
  82. package/dist/node/types/shared/utils/try-catch/TryCatch.d.ts +20 -0
  83. package/package.json +1 -1
@@ -17,7 +17,7 @@ class Calc {
17
17
  const len = values.length;
18
18
  if (len === 0)
19
19
  return NaN;
20
- const sorted = values.slice().sort((a, b) => a - b);
20
+ const sorted = values.slice().sort((a, b) => a - b); // O(n log n)
21
21
  const mid = len >> 1;
22
22
  return len % 2 === 0
23
23
  ? (sorted[mid - 1] + sorted[mid]) / 2
@@ -107,6 +107,7 @@ class DateUtils {
107
107
  }
108
108
  exports.DateUtils = DateUtils;
109
109
  DateUtils.relativeDate = (input, base = Date.now()) => {
110
+ // Create new moment instance to apply new locale
110
111
  const datetime = moment_1.default.isMoment(input) ? (0, moment_1.default)(input.toDate()) : (0, moment_1.default)(input);
111
112
  if (!datetime.isValid()) {
112
113
  console.error('core-js:DateUtils.relativeDate() datetime is invalid', datetime);
@@ -19,9 +19,10 @@ class JuminNumberUtils {
19
19
  if (replacedJuminNumber.length !== 13) {
20
20
  return false;
21
21
  }
22
+ // 연도에 해당하는 숫자와 성별에 해당하는 숫자 비교
22
23
  const TODAY_YEAR = parseInt(new Date().getFullYear().toString().slice(-2), 10);
23
24
  const yearNum = parseInt(replacedJuminNumber.slice(0, 2), 10);
24
- const sexNum = replacedJuminNumber.slice(6, 7);
25
+ const sexNum = replacedJuminNumber.slice(6, 7); // 대시 있는경우 7로 변경
25
26
  if (sexNum === '1' || sexNum === '2') {
26
27
  if (yearNum < TODAY_YEAR)
27
28
  return false;
@@ -32,9 +33,11 @@ class JuminNumberUtils {
32
33
  }
33
34
  else
34
35
  return false;
36
+ // 월과 일에 해당하는 숫자 조건 검사 (정규식으로)
35
37
  const regex = /^\d{2}(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])\d{7}$/;
36
38
  if (!regex.test(replacedJuminNumber))
37
39
  return false;
40
+ // Validation X
38
41
  const currentX = parseInt(replacedJuminNumber.slice(-1), 10);
39
42
  const calculatedX = JuminNumberUtils.calculateX(replacedJuminNumber);
40
43
  if (currentX !== calculatedX) {
@@ -34,9 +34,11 @@ class Sequencer {
34
34
  this.sequences = [];
35
35
  this.status = SequencerStatus.IDLE;
36
36
  this.minimumExecutionTime = 0;
37
+ // Reset variables task is done
37
38
  this.currentSequence = null;
38
39
  this.startTimestamp = null;
39
40
  this.endTimestamp = null;
41
+ // Emitter
40
42
  this.eventEmitter = new eventemitter3_1.default();
41
43
  this.pushSequence = (sequence) => {
42
44
  this.sequences.push(sequence);
@@ -55,6 +57,7 @@ class Sequencer {
55
57
  console.log('Currently total execution time', this.executionTime);
56
58
  const sequenceStartTimeStamp = this.getCurrentTimeStamp;
57
59
  this.currentSequence = sequence;
60
+ // Emitter
58
61
  this.eventEmitter.emit(SequencerEvent.SEQUENCE_START, sequence);
59
62
  try {
60
63
  yield new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
@@ -98,6 +101,7 @@ class Sequencer {
98
101
  }
99
102
  }));
100
103
  console.log('Out of Promise');
104
+ // Emitter
101
105
  this.eventEmitter.emit(SequencerEvent.SEQUENCE_END, sequence);
102
106
  }
103
107
  catch (e) {
@@ -106,12 +110,14 @@ class Sequencer {
106
110
  this.status = SequencerStatus.ERROR;
107
111
  this.currentSequence = null;
108
112
  this.endTimestamp = this.currentSequence;
113
+ // IMPORTANT
109
114
  return Promise.reject({
110
115
  sequence,
111
116
  reason: e,
112
117
  });
113
118
  }
114
119
  console.log(`Sequence ${sequence.key} failed`, e);
120
+ // Emitter
115
121
  this.eventEmitter.emit(SequencerEvent.SEQUENCE_END, sequence);
116
122
  }
117
123
  }
@@ -28,7 +28,9 @@ StringUtils.levenshteinDistance = (str1 = '', str2 = '') => {
28
28
  for (let j = 1; j <= str2.length; j += 1) {
29
29
  for (let i = 1; i <= str1.length; i += 1) {
30
30
  const indicator = str1[i - 1] === str2[j - 1] ? 0 : 1;
31
- track[j][i] = Math.min(track[j][i - 1] + 1, track[j - 1][i] + 1, track[j - 1][i - 1] + indicator);
31
+ track[j][i] = Math.min(track[j][i - 1] + 1, // deletion
32
+ track[j - 1][i] + 1, // insertion
33
+ track[j - 1][i - 1] + indicator);
32
34
  }
33
35
  }
34
36
  return track[str2.length][str1.length];
@@ -42,12 +42,15 @@ class UuidUtils {
42
42
  }
43
43
  static format(uuid) {
44
44
  if (uuid.length === 32) {
45
+ // Without dash: ca23c587d7f84c76be59f53bbc9f91f8
45
46
  return `${uuid.substring(0, 8)}-${uuid.substring(8, 12)}-${uuid.substring(12, 16)}-${uuid.substring(16, 20)}-${uuid.substring(20, 32)}`.toLowerCase();
46
47
  }
47
48
  else if (uuid.length === 36) {
49
+ // With dash: ca23c587-d7f8-4c76-be59-f53bbc9f91f8
48
50
  return uuid.toLowerCase();
49
51
  }
50
52
  else {
53
+ // Unexpected uuid
51
54
  console.warn('Unexpected uuid length', uuid);
52
55
  return uuid;
53
56
  }
@@ -16,12 +16,14 @@ class Validator {
16
16
  const startsWithNumber = /^\d/.test(value);
17
17
  const startsWithAlphabet = /^[A-Za-z]/.test(value);
18
18
  const startsWithSpecialCharacter = /^[~`!@#$%^&*()\-+={[}\]|\\:;"'<,>.?/]/.test(value);
19
+ // 최소 길이
19
20
  if (options.minLength !== undefined && options.minLength > -1) {
20
21
  validations.push(Validator.VALIDATION.MIN_LENGTH);
21
22
  if (length < options.minLength) {
22
23
  errors.push(Validator.VALIDATION.MIN_LENGTH);
23
24
  }
24
25
  }
26
+ // 최대 길이
25
27
  if (options.maxLength !== undefined && options.maxLength > -1) {
26
28
  validations.push(Validator.VALIDATION.MAX_LENGTH);
27
29
  if (length > options.maxLength) {
@@ -44,30 +46,39 @@ class Validator {
44
46
  }
45
47
  }
46
48
  };
49
+ // 공백 개수
47
50
  validateMin(options.spaceMinCount, spaceCount, Validator.VALIDATION.SPACE_MIN_COUNT);
48
51
  validateMax(options.spaceMaxCount, spaceCount, Validator.VALIDATION.SPACE_MAX_COUNT);
52
+ // 숫자 개수
49
53
  validateMin(options.numberMinCount, numberCount, Validator.VALIDATION.NUMBER_MIN_COUNT);
50
54
  validateMax(options.numberMaxCount, numberCount, Validator.VALIDATION.NUMBER_MAX_COUNT);
55
+ // 알파벳 개수
51
56
  validateMin(options.alphabetMinCount, alphabetCount, Validator.VALIDATION.ALPHABET_MIN_COUNT);
52
57
  validateMax(options.alphabetMaxCount, alphabetCount, Validator.VALIDATION.ALPHABET_MAX_COUNT);
58
+ // 알파벳(소문자) 개수
53
59
  validateMin(options.alphabetLowerCaseMinCount, alphabetLowerCaseCount, Validator.VALIDATION.ALPHABET_LOWER_CASE_MIN_COUNT);
54
60
  validateMax(options.alphabetLowerCaseMaxCount, alphabetLowerCaseCount, Validator.VALIDATION.ALPHABET_LOWER_CASE_MAX_COUNT);
61
+ // 알파벳(대문자) 개수
55
62
  validateMin(options.alphabetUpperCaseMinCount, alphabetUpperCaseCount, Validator.VALIDATION.ALPHABET_UPPER_CASE_MIN_COUNT);
56
63
  validateMax(options.alphabetUpperCaseMaxCount, alphabetUpperCaseCount, Validator.VALIDATION.ALPHABET_UPPER_CASE_MAX_COUNT);
64
+ // 특수문자 개수
57
65
  validateMin(options.specialCharacterMinCount, specialCount, Validator.VALIDATION.SPECIAL_CHARACTER_MIN_COUNT);
58
66
  validateMax(options.specialCharacterMaxCount, specialCount, Validator.VALIDATION.SPECIAL_CHARACTER_MAX_COUNT);
67
+ // 숫자로 시작
59
68
  if (options.startsWithNumber) {
60
69
  validations.push(Validator.VALIDATION.STARTS_WITH_NUMBER);
61
70
  if (!startsWithNumber) {
62
71
  errors.push(Validator.VALIDATION.STARTS_WITH_NUMBER);
63
72
  }
64
73
  }
74
+ // 영문으로 시작
65
75
  if (options.startsWithAlphabet) {
66
76
  validations.push(Validator.VALIDATION.STARTS_WITH_ALPHABET);
67
77
  if (!startsWithAlphabet) {
68
78
  errors.push(Validator.VALIDATION.STARTS_WITH_ALPHABET);
69
79
  }
70
80
  }
81
+ // 특수문자로 시작
71
82
  if (options.startsWithSpecialCharacter) {
72
83
  validations.push(Validator.VALIDATION.STARTS_WITH_SPECIAL_CHARACTER);
73
84
  if (!startsWithSpecialCharacter) {
@@ -6,6 +6,7 @@ function firstNonNullish(...args) {
6
6
  return undefined;
7
7
  }
8
8
  if (args[0] != null) {
9
+ // Not Nullish
9
10
  return args[0];
10
11
  }
11
12
  return firstNonNullish(...args.slice(1));
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ // flat.ts
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.flatten = flatten;
4
5
  exports.unflatten = unflatten;
@@ -3,12 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.pureEnum = pureEnum;
4
4
  exports.pureEnumKeys = pureEnumKeys;
5
5
  exports.pureEnumValues = pureEnumValues;
6
+ /**
7
+ * @deprecated Use Enum instead.
8
+ */
6
9
  function pureEnum(e) {
7
10
  return Object.entries(e).filter(([key, value]) => !/^-?\d+$/g.test(key) && typeof value !== 'function');
8
11
  }
12
+ /**
13
+ * @deprecated Use Enum instead.
14
+ */
9
15
  function pureEnumKeys(e) {
10
16
  return pureEnum(e).map(([key]) => key);
11
17
  }
18
+ /**
19
+ * @deprecated Use Enum instead.
20
+ */
12
21
  function pureEnumValues(e) {
13
22
  return pureEnum(e).map(([, value]) => value);
14
23
  }
@@ -10,7 +10,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.TryCatch = void 0;
13
+ /**
14
+ * Provides a utility class for handling synchronous and asynchronous operations with a consistent try-catch pattern.
15
+ * 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).
16
+ */
13
17
  class TryCatch {
18
+ /**
19
+ * Executes a synchronous function within a try-catch block.
20
+ * @template T The return type of the function.
21
+ * @template E The type of the error that might be thrown (defaults to Error).
22
+ * @param fn The synchronous function to execute.
23
+ *@param disableLogging console.error is default way of logging on error. You can disable it by setting it true
24
+ * @returns A tuple containing the result of the function and an error (null if successful).
25
+ */
14
26
  static function(fn, disableLogging) {
15
27
  try {
16
28
  return [
@@ -31,6 +43,14 @@ class TryCatch {
31
43
  ];
32
44
  }
33
45
  }
46
+ /**
47
+ * Executes an asynchronous function (Promise) within a try-catch block.
48
+ * @template T The resolved value type of the Promise.
49
+ * @template E The type of the error that might be rejected (defaults to Error).
50
+ * @param fn The Promise to await.
51
+ * @param disableLogging console.error is default way of logging on error. You can disable it by setting it true
52
+ * @returns A tuple containing the resolved value of the Promise and an error (null if successful).
53
+ */
34
54
  static asyncFunction(fn, disableLogging) {
35
55
  return __awaiter(this, void 0, void 0, function* () {
36
56
  try {
@@ -1,27 +1,59 @@
1
1
  import { Uint8ArrayUtils } from "../../shared/index.mjs";
2
+ /**
3
+ * Represents a UUID (Universally Unique Identifier) and provides various utility
4
+ * methods for validation, conversion, comparison and creation.
5
+ */
2
6
  export class UUID {
7
+ /* --------------------------------------------------------------------
8
+ * Validation helpers
9
+ * -------------------------------------------------------------------- */
10
+ /**
11
+ * Checks if the supplied value is a valid hex representation of a UUID.
12
+ * @param hex - The string to validate.
13
+ * @returns true if the string matches {@link REGEX_HEX}.
14
+ */
3
15
  static isValidHex(hex) {
4
16
  if (typeof hex !== 'string') {
5
17
  return false;
6
18
  }
7
19
  return UUID.REGEX_HEX.test(hex);
8
20
  }
21
+ /**
22
+ * Checks if the supplied value is a valid RFC 4122 UUID string.
23
+ * @param str - The string to validate.
24
+ * @returns true if the string matches {@link REGEX_RFC4122}.
25
+ */
9
26
  static isValidString(str) {
10
27
  if (typeof str !== 'string') {
11
28
  return false;
12
29
  }
13
30
  return UUID.REGEX_RFC4122.test(str);
14
31
  }
32
+ /**
33
+ * Checks whether an ArrayBufferView contains exactly {@link BYTE_LENGTH} bytes.
34
+ * @param bytes - The view to check.
35
+ * @returns true if the byte length is correct.
36
+ */
15
37
  static isValidBytes(bytes) {
16
38
  return bytes.byteLength === UUID.BYTE_LENGTH;
17
39
  }
40
+ /**
41
+ * Generic validation that accepts either a string (hex or RFC 4122 format)
42
+ * or an ArrayBufferView containing the raw bytes.
43
+ * @param input - The value to validate.
44
+ * @returns true if the input is a valid representation of a UUID.
45
+ */
18
46
  static isValid(input) {
19
47
  if (typeof input === 'string') {
20
48
  const length = input.length;
21
49
  switch (length) {
22
50
  case UUID.STR_LENGTH:
51
+ // RFC 4122 uuid(string)
52
+ // 9e472052-a654-4693-9a8b-3ce57ada3d6c
23
53
  return UUID.isValidString(input);
24
54
  case UUID.HEX_STR_LENGTH:
55
+ // RFC 4122 uuid(string) without hyphens
56
+ // 9e472052a65446939a8b3ce57ada3d6c
25
57
  return UUID.isValidHex(input);
26
58
  default:
27
59
  return false;
@@ -34,6 +66,14 @@ export class UUID {
34
66
  return false;
35
67
  }
36
68
  }
69
+ /* --------------------------------------------------------------------
70
+ * Parsing / formatting helpers
71
+ * -------------------------------------------------------------------- */
72
+ /**
73
+ * Inserts hyphens into a 32‑character hex string to produce an RFC 4122 string.
74
+ * @param hex - The plain hexadecimal UUID.
75
+ * @returns The formatted RFC 4122 string.
76
+ */
37
77
  static formatHex(hex) {
38
78
  if (hex.length !== UUID.HEX_STR_LENGTH) {
39
79
  throw new Error(`hex length should be ${UUID.HEX_STR_LENGTH}`);
@@ -44,15 +84,26 @@ export class UUID {
44
84
  hex.slice(16, 20) + '-' +
45
85
  hex.slice(20);
46
86
  }
87
+ /** Removes all hyphens from a UUID string. */
47
88
  static stripHyphens(str) {
48
89
  return str.replace(/-/g, "");
49
90
  }
91
+ /**
92
+ * Converts a plain hexadecimal UUID into a Uint8Array.
93
+ * @param hex - The hex string to parse.
94
+ * @returns A Uint8Array containing the raw bytes.
95
+ */
50
96
  static parseHex(hex) {
51
97
  if (hex.length !== UUID.HEX_STR_LENGTH) {
52
98
  throw new Error(`Invalid hex string, length should be ${UUID.HEX_STR_LENGTH}`);
53
99
  }
54
100
  return Uint8ArrayUtils.fromHex(hex);
55
101
  }
102
+ /**
103
+ * Parses an RFC 4122 string into a Uint8Array.
104
+ * @param str - The formatted UUID string.
105
+ * @returns A Uint8Array containing the raw bytes.
106
+ */
56
107
  static parseString(str) {
57
108
  if (str.length !== UUID.STR_LENGTH) {
58
109
  throw new Error(`Invalid UUID string, invalid character length should be ${UUID.STR_LENGTH}`);
@@ -66,6 +117,11 @@ export class UUID {
66
117
  }
67
118
  return Uint8ArrayUtils.fromHex(hex);
68
119
  }
120
+ /**
121
+ * Parses an ArrayBufferView into a Uint8Array ensuring the correct byte length.
122
+ * @param bytes - The view to parse.
123
+ * @returns A Uint8Array containing the raw bytes.
124
+ */
69
125
  static parseBytes(bytes) {
70
126
  const view = new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength);
71
127
  if (view.length !== UUID.BYTE_LENGTH) {
@@ -73,22 +129,47 @@ export class UUID {
73
129
  }
74
130
  return new Uint8Array(view);
75
131
  }
132
+ /* --------------------------------------------------------------------
133
+ * Factory methods
134
+ * -------------------------------------------------------------------- */
135
+ /**
136
+ * Creates a UUID instance from a plain hexadecimal string.
137
+ * @param hex - The hex representation of the UUID.
138
+ * @returns A new {@link UUID} object.
139
+ */
76
140
  static fromHex(hex) {
77
141
  return new UUID(UUID.parseHex(hex));
78
142
  }
143
+ /**
144
+ * Creates a UUID instance from an RFC 4122 formatted string.
145
+ * @param str - The UUID string with hyphens.
146
+ * @returns A new {@link UUID} object.
147
+ */
79
148
  static fromString(str) {
80
149
  return new UUID(UUID.parseString(str));
81
150
  }
151
+ /**
152
+ * Creates a UUID instance from raw bytes.
153
+ * @param bytes - An ArrayBufferView containing 16 bytes.
154
+ * @returns A new {@link UUID} object.
155
+ */
82
156
  static fromBytes(bytes) {
83
157
  return new UUID(UUID.parseBytes(bytes));
84
158
  }
159
+ /**
160
+ * Parses any supported input (string or bytes) and returns the raw byte array.
161
+ * @param input - The value to parse.
162
+ * @returns A Uint8Array of length {@link BYTE_LENGTH}.
163
+ */
85
164
  static parse(input) {
86
165
  if (typeof input === 'string') {
87
166
  const length = input.length;
88
167
  switch (length) {
89
168
  case UUID.STR_LENGTH:
169
+ // RFC 4122 uuid(string)
90
170
  return UUID.parseString(input);
91
171
  case UUID.HEX_STR_LENGTH:
172
+ // RFC 4122 uuid(string) without hyphens
92
173
  return UUID.parseHex(input);
93
174
  default:
94
175
  throw new Error(`Invalid input string, length should be ${UUID.STR_LENGTH} or ${UUID.HEX_STR_LENGTH}`);
@@ -101,15 +182,30 @@ export class UUID {
101
182
  throw new Error("Invalid input, Expected string or ArrayBufferView");
102
183
  }
103
184
  }
185
+ /**
186
+ * Creates a UUID from any supported input type.
187
+ * @param input - The value to parse.
188
+ * @returns A new {@link UUID} object.
189
+ */
104
190
  static from(input) {
105
191
  return UUID.fromBytes(UUID.parse(input));
106
192
  }
193
+ /** Returns the nil (all zero) UUID. */
107
194
  static nil() {
108
195
  return UUID.fromBytes(new Uint8Array(UUID.BYTE_LENGTH));
109
196
  }
197
+ /** Returns a UUID consisting of all 0xFF bytes. */
110
198
  static max() {
111
199
  return UUID.fromBytes((new Uint8Array(UUID.BYTE_LENGTH)).fill(0xFF));
112
200
  }
201
+ /* --------------------------------------------------------------------
202
+ * Equality / comparison
203
+ * -------------------------------------------------------------------- */
204
+ /**
205
+ * Compares multiple UUIDs for strict equality.
206
+ * @param uuids - The UUIDs to compare (at least two required).
207
+ * @returns true if all provided UUIDs are identical.
208
+ */
113
209
  static equals(...uuids) {
114
210
  const n = uuids.length;
115
211
  if (n < 2) {
@@ -125,6 +221,12 @@ export class UUID {
125
221
  }
126
222
  return true;
127
223
  }
224
+ /**
225
+ * Lexicographically compares two UUIDs.
226
+ * @param uuid1 - The first UUID.
227
+ * @param uuid2 - The second UUID.
228
+ * @returns -1 if uuid1 < uuid2, 1 if uuid1 > uuid2, 0 otherwise.
229
+ */
128
230
  static compare(uuid1, uuid2) {
129
231
  const a = uuid1.bytes;
130
232
  const b = uuid2.bytes;
@@ -134,15 +236,25 @@ export class UUID {
134
236
  }
135
237
  return 0;
136
238
  }
239
+ /**
240
+ * Constructs a new {@link UUID} instance from any supported input type.
241
+ * @param input - The value to parse (string or ArrayBufferView).
242
+ */
137
243
  constructor(input) {
138
244
  this.bytes = UUID.parse(input);
139
245
  }
246
+ /** Instance wrapper for {@link equals}. */
140
247
  equals(...uuids) {
141
248
  return UUID.equals(this, ...uuids);
142
249
  }
250
+ /** Instance wrapper for {@link compare}. */
143
251
  compare(other) {
144
252
  return UUID.compare(this, other);
145
253
  }
254
+ /**
255
+ * Returns the RFC 4122 string representation of this UUID.
256
+ * @returns The formatted UUID string.
257
+ */
146
258
  toString() {
147
259
  if (this._str != null) {
148
260
  return this._str;
@@ -151,6 +263,10 @@ export class UUID {
151
263
  this._str = UUID.formatHex(hex);
152
264
  return this._str;
153
265
  }
266
+ /**
267
+ * Returns the plain hexadecimal representation of this UUID.
268
+ * @returns A 32‑character hex string.
269
+ */
154
270
  toHex() {
155
271
  if (this._hex != null) {
156
272
  return this._hex;
@@ -158,15 +274,31 @@ export class UUID {
158
274
  this._hex = Uint8ArrayUtils.toHex(this.bytes);
159
275
  return this._hex;
160
276
  }
277
+ /**
278
+ * Returns a copy of the raw byte array.
279
+ * @returns A new Uint8Array containing the UUID bytes.
280
+ */
161
281
  toBytes() {
162
282
  return new Uint8Array(this.bytes);
163
283
  }
284
+ /** JSON serialization helper – returns the RFC 4122 string. */
164
285
  toJSON() {
165
286
  return this.toString();
166
287
  }
167
288
  }
289
+ /* --------------------------------------------------------------------
290
+ * Regular expressions used to validate UUIDs in different string forms
291
+ * -------------------------------------------------------------------- */
292
+ /** Matches a 32‑character hexadecimal representation of a UUID without hyphens. */
168
293
  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}$/;
294
+ /** Matches the RFC 4122 canonical UUID format with hyphens. */
169
295
  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}$/;
296
+ /* --------------------------------------------------------------------
297
+ * Constant lengths used throughout the class
298
+ * -------------------------------------------------------------------- */
299
+ /** Number of bytes that represent a UUID. */
170
300
  UUID.BYTE_LENGTH = 16;
301
+ /** Total length of an RFC 4122 UUID string (including hyphens). */
171
302
  UUID.STR_LENGTH = 36;
303
+ /** Length of a UUID represented as a plain hexadecimal string. */
172
304
  UUID.HEX_STR_LENGTH = 32;
@@ -12,8 +12,10 @@ import { TransactionManagerLogLevel, TransactionManagerTimeoutAction } from "../
12
12
  const LOG_TAG = '[TransactionManager]';
13
13
  export class TransactionManager {
14
14
  constructor() {
15
+ // Members
15
16
  this.logLevel = TransactionManagerLogLevel.VERBOSE;
16
17
  this.transactionTimeoutMap = new Map();
18
+ // Emitter
17
19
  this.emitter = new EventEmitter();
18
20
  if (this.logLevel <= TransactionManagerLogLevel.VERBOSE) {
19
21
  console.log(LOG_TAG, 'TransactionManager instance initialized');
@@ -53,6 +55,7 @@ export class TransactionManager {
53
55
  handler,
54
56
  action,
55
57
  });
58
+ // Callback
56
59
  transaction.afterCommit(this.afterCommit.bind(this));
57
60
  }
58
61
  remove(transaction) {
@@ -30,6 +30,7 @@ export class RedisClient {
30
30
  start() {
31
31
  return __awaiter(this, void 0, void 0, function* () {
32
32
  console.log(LOG_PREFIX, 'trying to start');
33
+ // register event callback
33
34
  this.client.on('connect', this.handleOnConnect);
34
35
  this.client.on('error', this.handleOnError);
35
36
  console.log('before connect');
@@ -43,6 +44,7 @@ export class RedisClient {
43
44
  stop() {
44
45
  return __awaiter(this, void 0, void 0, function* () {
45
46
  console.log(LOG_PREFIX, 'trying to stop');
47
+ // unregister event callback
46
48
  this.client.off('connect', this.handleOnConnect);
47
49
  this.client.off('error', this.handleOnError);
48
50
  if (this.client.isOpen) {
@@ -37,6 +37,7 @@ export class RedisPublisher extends RedisClient {
37
37
  getLogging() {
38
38
  return this.logging;
39
39
  }
40
+ // Make public method
40
41
  publish(channel, data) {
41
42
  return __awaiter(this, void 0, void 0, function* () {
42
43
  const stringifyData = typeof data !== 'string' ? JSON.stringify(data) : data;
@@ -1,3 +1,4 @@
1
+ // Files
1
2
  export * from './RedisClient.mjs';
2
3
  export * from './RedisPublisher.mjs';
3
4
  export * from './RedisSubscriber.mjs';
@@ -13,8 +13,10 @@ import EventEmitter from 'eventemitter3';
13
13
  export class SessionManager extends EventEmitter {
14
14
  constructor(options) {
15
15
  super();
16
+ // Init service parameters
16
17
  this.api = options.api;
17
18
  this.storageProvider = options.storageProvider;
19
+ // Logging
18
20
  console.log('SessionManager initialized', Date.now(), options.api);
19
21
  }
20
22
  get key() {
@@ -55,6 +57,7 @@ export class SessionManager extends EventEmitter {
55
57
  return null;
56
58
  }
57
59
  try {
60
+ // Replace Bearer prefix
58
61
  nextAuthorization = nextAuthorization.replace(/^Bearer\s+/, '');
59
62
  const decoded = jwtDecode(nextAuthorization);
60
63
  if (!decoded) {
@@ -95,9 +98,13 @@ export class SessionManager extends EventEmitter {
95
98
  return [decoded.exp, exp.format(), exp.diff(Date.now(), 'days'), 'days left'];
96
99
  })());
97
100
  })();
101
+ // AsyncStorage 에 토큰 저장
98
102
  yield this.storageProvider.set(this.key, nextAuthorization);
103
+ // API Instance header 설정
99
104
  this.api.defaults.headers.common.Authorization = `Bearer ${nextAuthorization}`;
105
+ // Emit
100
106
  this.emit('AUTHORIZATION_CHANGED', nextAuthorization);
107
+ // Return
101
108
  return nextAuthorization;
102
109
  }
103
110
  catch (e) {
@@ -108,8 +115,11 @@ export class SessionManager extends EventEmitter {
108
115
  }
109
116
  removeAuthorization() {
110
117
  return __awaiter(this, void 0, void 0, function* () {
118
+ // API Instance header 에서 토큰 제거
111
119
  delete this.api.defaults.headers.common.Authorization;
120
+ // 스토리지에서 authorization 제거
112
121
  yield this.storageProvider.remove(this.key);
122
+ // Emit
113
123
  this.emit('AUTHORIZATION_CHANGED', null);
114
124
  });
115
125
  }