@gennext/lb-infra 0.0.12 → 0.0.17

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 (131) hide show
  1. package/README.md +63 -89
  2. package/dist/base/base.helper.d.ts +4 -2
  3. package/dist/base/base.helper.d.ts.map +1 -1
  4. package/dist/base/base.helper.js +8 -2
  5. package/dist/base/base.helper.js.map +1 -1
  6. package/dist/base/datasources/base.datasource.d.ts +2 -2
  7. package/dist/base/datasources/base.datasource.d.ts.map +1 -1
  8. package/dist/base/datasources/base.datasource.js.map +1 -1
  9. package/dist/base/models/base.model.d.ts +10 -0
  10. package/dist/base/models/base.model.d.ts.map +1 -1
  11. package/dist/base/models/base.model.js +10 -3
  12. package/dist/base/models/base.model.js.map +1 -1
  13. package/dist/datasources/redis/connector.d.ts +1 -1
  14. package/dist/datasources/redis/connector.d.ts.map +1 -1
  15. package/dist/datasources/redis/connector.js +8 -4
  16. package/dist/datasources/redis/connector.js.map +1 -1
  17. package/dist/datasources/redis/types.d.ts +1 -1
  18. package/dist/datasources/redis/types.d.ts.map +1 -1
  19. package/dist/helpers/logger/application-logger.d.ts +0 -3
  20. package/dist/helpers/logger/application-logger.d.ts.map +1 -1
  21. package/dist/helpers/logger/application-logger.js +7 -31
  22. package/dist/helpers/logger/application-logger.js.map +1 -1
  23. package/dist/helpers/logger/common/types.d.ts +0 -7
  24. package/dist/helpers/logger/common/types.d.ts.map +1 -1
  25. package/dist/helpers/logger/common/types.js +1 -10
  26. package/dist/helpers/logger/common/types.js.map +1 -1
  27. package/dist/helpers/logger/config-merger.d.ts +27 -0
  28. package/dist/helpers/logger/config-merger.d.ts.map +1 -0
  29. package/dist/helpers/logger/config-merger.js +55 -0
  30. package/dist/helpers/logger/config-merger.js.map +1 -0
  31. package/dist/helpers/logger/config.d.ts +9 -11
  32. package/dist/helpers/logger/config.d.ts.map +1 -1
  33. package/dist/helpers/logger/config.js +18 -30
  34. package/dist/helpers/logger/config.js.map +1 -1
  35. package/dist/helpers/logger/default-logger.d.ts.map +1 -1
  36. package/dist/helpers/logger/default-logger.js +3 -5
  37. package/dist/helpers/logger/default-logger.js.map +1 -1
  38. package/dist/helpers/logger/enhanced-factory.d.ts +3 -3
  39. package/dist/helpers/logger/enhanced-factory.d.ts.map +1 -1
  40. package/dist/helpers/logger/enhanced-factory.js +10 -7
  41. package/dist/helpers/logger/enhanced-factory.js.map +1 -1
  42. package/dist/helpers/logger/factory.d.ts +1 -37
  43. package/dist/helpers/logger/factory.d.ts.map +1 -1
  44. package/dist/helpers/logger/factory.js +11 -86
  45. package/dist/helpers/logger/factory.js.map +1 -1
  46. package/dist/helpers/logger/http/access-logger.d.ts +14 -5
  47. package/dist/helpers/logger/http/access-logger.d.ts.map +1 -1
  48. package/dist/helpers/logger/http/access-logger.js +186 -157
  49. package/dist/helpers/logger/http/access-logger.js.map +1 -1
  50. package/dist/helpers/logger/http/index.d.ts +1 -1
  51. package/dist/helpers/logger/http/index.d.ts.map +1 -1
  52. package/dist/helpers/logger/http/index.js +1 -1
  53. package/dist/helpers/logger/http/index.js.map +1 -1
  54. package/dist/helpers/logger/http/request-context.d.ts +10 -6
  55. package/dist/helpers/logger/http/request-context.d.ts.map +1 -1
  56. package/dist/helpers/logger/http/request-context.js +32 -22
  57. package/dist/helpers/logger/http/request-context.js.map +1 -1
  58. package/dist/helpers/logger/http/request-id-manager.d.ts +13 -8
  59. package/dist/helpers/logger/http/request-id-manager.d.ts.map +1 -1
  60. package/dist/helpers/logger/http/request-id-manager.js +24 -70
  61. package/dist/helpers/logger/http/request-id-manager.js.map +1 -1
  62. package/dist/helpers/logger/http/types.d.ts +3 -3
  63. package/dist/helpers/logger/http/types.d.ts.map +1 -1
  64. package/dist/helpers/logger/index.d.ts +4 -3
  65. package/dist/helpers/logger/index.d.ts.map +1 -1
  66. package/dist/helpers/logger/index.js +4 -3
  67. package/dist/helpers/logger/index.js.map +1 -1
  68. package/dist/helpers/logger/transports/dgram.transport.d.ts +0 -1
  69. package/dist/helpers/logger/transports/dgram.transport.d.ts.map +1 -1
  70. package/dist/helpers/logger/transports/dgram.transport.js +2 -2
  71. package/dist/helpers/logger/transports/dgram.transport.js.map +1 -1
  72. package/dist/helpers/redis/default.helper.d.ts.map +1 -1
  73. package/dist/helpers/redis/default.helper.js +19 -17
  74. package/dist/helpers/redis/default.helper.js.map +1 -1
  75. package/dist/helpers/redis/index.d.ts.map +1 -1
  76. package/dist/helpers/redis/index.js.map +1 -1
  77. package/dist/helpers/redis/redis-cluster.helper.js +2 -2
  78. package/dist/helpers/redis/redis-cluster.helper.js.map +1 -1
  79. package/dist/helpers/redis/redis.helper.d.ts +34 -0
  80. package/dist/helpers/redis/redis.helper.d.ts.map +1 -1
  81. package/dist/helpers/redis/redis.helper.js +34 -0
  82. package/dist/helpers/redis/redis.helper.js.map +1 -1
  83. package/dist/utilities/crypto.utility.d.ts +28 -0
  84. package/dist/utilities/crypto.utility.d.ts.map +1 -1
  85. package/dist/utilities/crypto.utility.js +28 -0
  86. package/dist/utilities/crypto.utility.js.map +1 -1
  87. package/dist/utilities/date.utility.d.ts +57 -0
  88. package/dist/utilities/date.utility.d.ts.map +1 -1
  89. package/dist/utilities/date.utility.js +58 -16
  90. package/dist/utilities/date.utility.js.map +1 -1
  91. package/dist/utilities/error.utility.d.ts +63 -0
  92. package/dist/utilities/error.utility.d.ts.map +1 -1
  93. package/dist/utilities/error.utility.js +82 -4
  94. package/dist/utilities/error.utility.js.map +1 -1
  95. package/dist/utilities/lodash.utility.d.ts +1 -0
  96. package/dist/utilities/lodash.utility.d.ts.map +1 -1
  97. package/dist/utilities/lodash.utility.js +3 -1
  98. package/dist/utilities/lodash.utility.js.map +1 -1
  99. package/dist/utilities/model.utility.d.ts +15 -0
  100. package/dist/utilities/model.utility.d.ts.map +1 -1
  101. package/dist/utilities/model.utility.js +15 -2
  102. package/dist/utilities/model.utility.js.map +1 -1
  103. package/dist/utilities/module.utility.d.ts +8 -0
  104. package/dist/utilities/module.utility.d.ts.map +1 -1
  105. package/dist/utilities/module.utility.js +10 -2
  106. package/dist/utilities/module.utility.js.map +1 -1
  107. package/dist/utilities/parse.utility.d.ts +59 -0
  108. package/dist/utilities/parse.utility.d.ts.map +1 -1
  109. package/dist/utilities/parse.utility.js +76 -15
  110. package/dist/utilities/parse.utility.js.map +1 -1
  111. package/dist/utilities/performance.utility.d.ts +13 -0
  112. package/dist/utilities/performance.utility.d.ts.map +1 -1
  113. package/dist/utilities/performance.utility.js +15 -2
  114. package/dist/utilities/performance.utility.js.map +1 -1
  115. package/dist/utilities/promise.utility.d.ts +18 -18
  116. package/dist/utilities/promise.utility.d.ts.map +1 -1
  117. package/dist/utilities/promise.utility.js +16 -17
  118. package/dist/utilities/promise.utility.js.map +1 -1
  119. package/dist/utilities/query.utility.d.ts +24 -3
  120. package/dist/utilities/query.utility.d.ts.map +1 -1
  121. package/dist/utilities/query.utility.js +29 -7
  122. package/dist/utilities/query.utility.js.map +1 -1
  123. package/dist/utilities/request.utility.d.ts +36 -3
  124. package/dist/utilities/request.utility.d.ts.map +1 -1
  125. package/dist/utilities/request.utility.js +38 -8
  126. package/dist/utilities/request.utility.js.map +1 -1
  127. package/dist/utilities/url.utility.d.ts +16 -0
  128. package/dist/utilities/url.utility.d.ts.map +1 -1
  129. package/dist/utilities/url.utility.js +16 -0
  130. package/dist/utilities/url.utility.js.map +1 -1
  131. package/package.json +2 -1
@@ -7,7 +7,37 @@ exports.RedisHelper = void 0;
7
7
  const parse_utility_1 = require("../../utilities/parse.utility");
8
8
  const ioredis_1 = __importDefault(require("ioredis"));
9
9
  const default_helper_1 = require("./default.helper");
10
+ /**
11
+ * Redis connection helper with automatic retry and connection management
12
+ * Extends DefaultRedisHelper with ioredis client implementation
13
+ *
14
+ * @class RedisHelper
15
+ * @extends DefaultRedisHelper
16
+ * @example
17
+ * const redis = new RedisHelper({
18
+ * name: 'cache',
19
+ * host: 'localhost',
20
+ * port: 6379,
21
+ * password: 'secret',
22
+ * autoConnect: true,
23
+ * maxRetry: 3
24
+ * });
25
+ *
26
+ * await redis.connect();
27
+ * const value = await redis.get('mykey');
28
+ */
10
29
  class RedisHelper extends default_helper_1.DefaultRedisHelper {
30
+ /**
31
+ * Creates a new Redis connection instance
32
+ * @param opts - Connection configuration options
33
+ * @param opts.name - Identifier name for this Redis instance
34
+ * @param opts.host - Redis server hostname
35
+ * @param opts.port - Redis server port (will be parsed to int)
36
+ * @param opts.password - Authentication password (optional)
37
+ * @param opts.database - Database number (default: 0)
38
+ * @param opts.autoConnect - Connect immediately (default: true)
39
+ * @param opts.maxRetry - Maximum retry attempts (default: 0, -1 = unlimited)
40
+ */
11
41
  constructor(opts) {
12
42
  const { name, host, port, password,
13
43
  // Optional
@@ -35,6 +65,10 @@ class RedisHelper extends default_helper_1.DefaultRedisHelper {
35
65
  }),
36
66
  });
37
67
  }
68
+ /**
69
+ * Gets the underlying Redis client instance
70
+ * @returns ioredis Redis client
71
+ */
38
72
  getClient() {
39
73
  return this.client;
40
74
  }
@@ -1 +1 @@
1
- {"version":3,"file":"redis.helper.js","sourceRoot":"","sources":["../../../src/helpers/redis/redis.helper.ts"],"names":[],"mappings":";;;;;;AAAA,6DAAgD;AAChD,sDAA4B;AAC5B,qDAAsD;AAGtD,MAAa,WAAY,SAAQ,mCAAkB;IACjD,YAAY,IAAyB;QACnC,MAAM,EACJ,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,QAAQ;QAER,WAAW;QACX,QAAQ,GAAG,CAAC,EACZ,WAAW,GAAG,IAAI,EAClB,QAAQ,GAAG,CAAC,GACb,GAAG,IAAI,CAAC;QAET,KAAK,CAAC;YACJ,GAAG,IAAI;YACP,KAAK,EAAE,WAAW,CAAC,IAAI;YACvB,UAAU,EAAE,IAAI;YAChB,MAAM,EAAE,IAAI,iBAAK,CAAC;gBAChB,IAAI;gBACJ,IAAI;gBACJ,IAAI,EAAE,IAAA,mBAAG,EAAC,IAAI,CAAC;gBACf,QAAQ;gBACR,EA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EAAE,CAAC,WAAW;gBACzB,sBAAsB,EAAE,IAAI;gBAC5B,aAAa,EAAE,CAAC,cAAsB,EAAE,EAAE;oBACxC,IAAI,QAAQ,GAAG,CAAC,CAAC,IAAI,cAAc,GAAG,QAAQ,EAAE,CAAC;wBAC/C,OAAO,SAAS,CAAC;oBACnB,CAAC;oBAED,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,cAAc,GAAG,IAAI,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;oBACvE,OAAO,QAAQ,CAAC;gBAClB,CAAC;gBACD,oBAAoB,EAAE,IAAI;aAC3B,CAAC;SACH,CAAC,CAAC;IACL,CAAC;IAED;;;OAGG;IACM,SAAS;QAChB,OAAO,IAAI,CAAC,MAAe,CAAC;IAC9B,CAAC;CACF;AAzDD,kCAyDC"}
@@ -1,4 +1,32 @@
1
1
  import C from 'node:crypto';
2
+ /**
3
+ * Generates cryptographic hashes using specified algorithm
4
+ * Supports HMAC-SHA256 and MD5 hashing
5
+ *
6
+ * @param text - Text to hash
7
+ * @param options - Hash configuration
8
+ * @param options.algorithm - Algorithm: 'SHA256' or 'MD5'
9
+ * @param options.secret - Secret key for HMAC-SHA256 (optional)
10
+ * @param options.outputType - Output encoding format (hex, base64, base64url)
11
+ * @returns Hashed string in specified format
12
+ *
13
+ * @example
14
+ * // SHA256 with HMAC
15
+ * const hashed = hash('password', {
16
+ * algorithm: 'SHA256',
17
+ * secret: 'my-secret-key',
18
+ * outputType: 'hex'
19
+ * }); // "a1b2c3..."
20
+ *
21
+ * @example
22
+ * // MD5 hash
23
+ * const md5 = hash('text', {
24
+ * algorithm: 'MD5',
25
+ * outputType: 'hex'
26
+ * }); // "5d41402abc4b2a76b9719d911017c592"
27
+ *
28
+ * @throws No explicit errors, invalid algorithms return original text
29
+ */
2
30
  export declare const hash: (text: string, options: {
3
31
  algorithm: "SHA256" | "MD5";
4
32
  secret?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"crypto.utility.d.ts","sourceRoot":"","sources":["../../src/utilities/crypto.utility.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,aAAa,CAAC;AAE5B,eAAO,MAAM,IAAI,GACf,MAAM,MAAM,EACZ,SAAS;IACP,SAAS,EAAE,QAAQ,GAAG,KAAK,CAAC;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,CAAC,CAAC,oBAAoB,CAAC;CACpC,KACA,MAkBF,CAAC"}
1
+ {"version":3,"file":"crypto.utility.d.ts","sourceRoot":"","sources":["../../src/utilities/crypto.utility.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,aAAa,CAAC;AAE5B;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,IAAI,GACf,MAAM,MAAM,EACZ,SAAS;IACP,SAAS,EAAE,QAAQ,GAAG,KAAK,CAAC;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,CAAC,CAAC,oBAAoB,CAAC;CACpC,KACA,MAkBF,CAAC"}
@@ -5,6 +5,34 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.hash = void 0;
7
7
  const node_crypto_1 = __importDefault(require("node:crypto"));
8
+ /**
9
+ * Generates cryptographic hashes using specified algorithm
10
+ * Supports HMAC-SHA256 and MD5 hashing
11
+ *
12
+ * @param text - Text to hash
13
+ * @param options - Hash configuration
14
+ * @param options.algorithm - Algorithm: 'SHA256' or 'MD5'
15
+ * @param options.secret - Secret key for HMAC-SHA256 (optional)
16
+ * @param options.outputType - Output encoding format (hex, base64, base64url)
17
+ * @returns Hashed string in specified format
18
+ *
19
+ * @example
20
+ * // SHA256 with HMAC
21
+ * const hashed = hash('password', {
22
+ * algorithm: 'SHA256',
23
+ * secret: 'my-secret-key',
24
+ * outputType: 'hex'
25
+ * }); // "a1b2c3..."
26
+ *
27
+ * @example
28
+ * // MD5 hash
29
+ * const md5 = hash('text', {
30
+ * algorithm: 'MD5',
31
+ * outputType: 'hex'
32
+ * }); // "5d41402abc4b2a76b9719d911017c592"
33
+ *
34
+ * @throws No explicit errors, invalid algorithms return original text
35
+ */
8
36
  const hash = (text, options) => {
9
37
  const { algorithm, secret, outputType } = options;
10
38
  switch (algorithm) {
@@ -1 +1 @@
1
- {"version":3,"file":"crypto.utility.js","sourceRoot":"","sources":["../../src/utilities/crypto.utility.ts"],"names":[],"mappings":";;;;;;AAAA,8DAA4B;AAErB,MAAM,IAAI,GAAG,CAClB,IAAY,EACZ,OAIC,EACO,EAAE;IACV,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IAElD,QAAQ,SAAS,EAAE,CAAC;QAClB,KAAK,QAAQ,CAAC,CAAC,CAAC;YACd,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,OAAO,IAAI,CAAC;YACd,CAAC;YAED,OAAO,qBAAC,CAAC,UAAU,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACzE,CAAC;QACD,KAAK,KAAK,CAAC,CAAC,CAAC;YACX,OAAO,qBAAC,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACjE,CAAC;QACD,OAAO,CAAC,CAAC,CAAC;YACR,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;AACH,CAAC,CAAC;AAzBW,QAAA,IAAI,QAyBf"}
1
+ {"version":3,"file":"crypto.utility.js","sourceRoot":"","sources":["../../src/utilities/crypto.utility.ts"],"names":[],"mappings":";;;;;;AAAA,8DAA4B;AAE5B;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACI,MAAM,IAAI,GAAG,CAClB,IAAY,EACZ,OAIC,EACO,EAAE;IACV,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IAElD,QAAQ,SAAS,EAAE,CAAC;QAClB,KAAK,QAAQ,CAAC,CAAC,CAAC;YACd,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,OAAO,IAAI,CAAC;YACd,CAAC;YAED,OAAO,qBAAC,CAAC,UAAU,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACzE,CAAC;QACD,KAAK,KAAK,CAAC,CAAC,CAAC;YACX,OAAO,qBAAC,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACjE,CAAC;QACD,OAAO,CAAC,CAAC,CAAC;YACR,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;AACH,CAAC,CAAC;AAzBW,QAAA,IAAI,QAyBf"}
@@ -1,18 +1,75 @@
1
1
  import dayjs from 'dayjs';
2
+ /**
3
+ * Delays execution for specified milliseconds
4
+ * @param ms - Delay duration in milliseconds
5
+ * @returns Promise that resolves after delay
6
+ * @example
7
+ * await sleep(1000); // Wait 1 second
8
+ */
2
9
  export declare const sleep: (ms: number) => Promise<unknown>;
10
+ /**
11
+ * Checks if a given date is a weekday (Monday-Friday)
12
+ * @param date - Date to check (ISO string or dayjs object)
13
+ * @returns True if date is a weekday
14
+ * @example
15
+ * isWeekday('2024-01-15') // true (Monday)
16
+ * isWeekday('2024-01-20') // false (Saturday)
17
+ */
3
18
  export declare const isWeekday: (date: string | dayjs.Dayjs) => boolean;
19
+ /**
20
+ * Gets the previous weekday from a given date
21
+ * Skips weekends (Saturday and Sunday)
22
+ * @param opts - Configuration options
23
+ * @param opts.date - Starting date (default: today)
24
+ * @returns dayjs object of previous weekday
25
+ * @example
26
+ * getPreviousWeekday({ date: '2024-01-15' }) // Monday 2024-01-15 -> Friday 2024-01-12
27
+ */
4
28
  export declare const getPreviousWeekday: (opts?: {
5
29
  date?: string | dayjs.Dayjs;
6
30
  }) => dayjs.Dayjs;
31
+ /**
32
+ * Gets the next weekday from a given date
33
+ * Skips weekends (Saturday and Sunday)
34
+ * @param opts - Configuration options
35
+ * @param opts.date - Starting date (default: today)
36
+ * @returns dayjs object of next weekday
37
+ * @example
38
+ * getNextWeekday({ date: '2024-01-12' }) // Friday 2024-01-12 -> Monday 2024-01-15
39
+ */
7
40
  export declare const getNextWeekday: (opts?: {
8
41
  date?: string | dayjs.Dayjs;
9
42
  }) => dayjs.Dayjs;
43
+ /**
44
+ * Gets a date adjusted to specific timezone with optional offset
45
+ * @param opts - Configuration options
46
+ * @param opts.date - Input date string
47
+ * @param opts.timezone - Target timezone (e.g., 'America/New_York')
48
+ * @param opts.useClientTz - Use client timezone (default: false)
49
+ * @param opts.timeOffset - Hours to add/subtract (default: 0)
50
+ * @returns dayjs object in target timezone
51
+ * @example
52
+ * getDateTz({
53
+ * date: '2024-01-15T10:00:00Z',
54
+ * timezone: 'America/New_York',
55
+ * timeOffset: -5
56
+ * })
57
+ */
10
58
  export declare const getDateTz: (opts: {
11
59
  date: string;
12
60
  timezone: string;
13
61
  useClientTz?: boolean;
14
62
  timeOffset?: number;
15
63
  }) => dayjs.Dayjs;
64
+ /**
65
+ * Gets high-resolution time in seconds with nanosecond precision
66
+ * Useful for performance measurements
67
+ * @returns Current time as float (seconds.nanoseconds)
68
+ * @example
69
+ * const start = hrTime();
70
+ * // ... do something ...
71
+ * const elapsed = hrTime() - start; // Time in seconds
72
+ */
16
73
  export declare const hrTime: () => number;
17
74
  export { dayjs };
18
75
  //# sourceMappingURL=date.utility.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"date.utility.d.ts","sourceRoot":"","sources":["../../src/utilities/date.utility.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAkB1B,eAAO,MAAM,KAAK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;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,gBAGA,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,MAAM,cAGlB,CAAC;AAEF,OAAO,EAAE,KAAK,EAAE,CAAC"}
@@ -12,6 +12,7 @@ const timezone_1 = __importDefault(require("dayjs/plugin/timezone"));
12
12
  const utc_1 = __importDefault(require("dayjs/plugin/utc"));
13
13
  const weekday_1 = __importDefault(require("dayjs/plugin/weekday"));
14
14
  const parse_utility_1 = require("./parse.utility");
15
+ // Initialize dayjs plugins for comprehensive date/time functionality
15
16
  dayjs_1.default.extend(customParseFormat_1.default);
16
17
  dayjs_1.default.extend(utc_1.default);
17
18
  dayjs_1.default.extend(timezone_1.default);
@@ -19,23 +20,39 @@ dayjs_1.default.extend(weekday_1.default);
19
20
  dayjs_1.default.extend(isoWeek_1.default);
20
21
  const tz = process.env.APP_ENV_APPLICATION_TIMEZONE ?? 'Asia/Ho_Chi_Minh';
21
22
  dayjs_1.default.tz.setDefault(tz);
23
+ /**
24
+ * Delays execution for specified milliseconds
25
+ * @param ms - Delay duration in milliseconds
26
+ * @returns Promise that resolves after delay
27
+ * @example
28
+ * await sleep(1000); // Wait 1 second
29
+ */
22
30
  const sleep = (ms) => {
23
31
  return new Promise(resolve => setTimeout(resolve, ms));
24
32
  };
25
33
  exports.sleep = sleep;
34
+ /**
35
+ * Checks if a given date is a weekday (Monday-Friday)
36
+ * @param date - Date to check (ISO string or dayjs object)
37
+ * @returns True if date is a weekday
38
+ * @example
39
+ * isWeekday('2024-01-15') // true (Monday)
40
+ * isWeekday('2024-01-20') // false (Saturday)
41
+ */
26
42
  const isWeekday = (date) => {
27
43
  const isoWeekday = (0, dayjs_1.default)(date)?.isoWeekday();
28
44
  return isoWeekday > 0 && isoWeekday < 6;
29
45
  };
30
46
  exports.isWeekday = isWeekday;
31
- /* export const getPreviousWeekday = () => {
32
- let date = dayjs();
33
- while (!isWeekday(date)) {
34
- date = date.subtract(1, 'day');
35
- }
36
-
37
- return date;
38
- }; */
47
+ /**
48
+ * Gets the previous weekday from a given date
49
+ * Skips weekends (Saturday and Sunday)
50
+ * @param opts - Configuration options
51
+ * @param opts.date - Starting date (default: today)
52
+ * @returns dayjs object of previous weekday
53
+ * @example
54
+ * getPreviousWeekday({ date: '2024-01-15' }) // Monday 2024-01-15 -> Friday 2024-01-12
55
+ */
39
56
  const getPreviousWeekday = (opts) => {
40
57
  const { date } = opts ?? { date: (0, dayjs_1.default)() };
41
58
  let rs = (0, dayjs_1.default)(date).clone().subtract(1, 'day');
@@ -45,14 +62,15 @@ const getPreviousWeekday = (opts) => {
45
62
  return rs;
46
63
  };
47
64
  exports.getPreviousWeekday = getPreviousWeekday;
48
- /* export const getNextWeekday = () => {
49
- let date = dayjs();
50
- while (!isWeekday(date)) {
51
- date = date.add(1, 'day');
52
- }
53
-
54
- return date;
55
- }; */
65
+ /**
66
+ * Gets the next weekday from a given date
67
+ * Skips weekends (Saturday and Sunday)
68
+ * @param opts - Configuration options
69
+ * @param opts.date - Starting date (default: today)
70
+ * @returns dayjs object of next weekday
71
+ * @example
72
+ * getNextWeekday({ date: '2024-01-12' }) // Friday 2024-01-12 -> Monday 2024-01-15
73
+ */
56
74
  const getNextWeekday = (opts) => {
57
75
  const { date } = opts ?? { date: (0, dayjs_1.default)() };
58
76
  let rs = (0, dayjs_1.default)(date).clone().add(1, 'day');
@@ -62,11 +80,35 @@ const getNextWeekday = (opts) => {
62
80
  return rs;
63
81
  };
64
82
  exports.getNextWeekday = getNextWeekday;
83
+ /**
84
+ * Gets a date adjusted to specific timezone with optional offset
85
+ * @param opts - Configuration options
86
+ * @param opts.date - Input date string
87
+ * @param opts.timezone - Target timezone (e.g., 'America/New_York')
88
+ * @param opts.useClientTz - Use client timezone (default: false)
89
+ * @param opts.timeOffset - Hours to add/subtract (default: 0)
90
+ * @returns dayjs object in target timezone
91
+ * @example
92
+ * getDateTz({
93
+ * date: '2024-01-15T10:00:00Z',
94
+ * timezone: 'America/New_York',
95
+ * timeOffset: -5
96
+ * })
97
+ */
65
98
  const getDateTz = (opts) => {
66
99
  const { date, timezone, useClientTz = false, timeOffset = 0 } = opts;
67
100
  return (0, dayjs_1.default)(date).tz(timezone, useClientTz).add(timeOffset, 'hour');
68
101
  };
69
102
  exports.getDateTz = getDateTz;
103
+ /**
104
+ * Gets high-resolution time in seconds with nanosecond precision
105
+ * Useful for performance measurements
106
+ * @returns Current time as float (seconds.nanoseconds)
107
+ * @example
108
+ * const start = hrTime();
109
+ * // ... do something ...
110
+ * const elapsed = hrTime() - start; // Time in seconds
111
+ */
70
112
  const hrTime = () => {
71
113
  const curr = process.hrtime();
72
114
  return (0, parse_utility_1.float)(curr[0] + curr[1] / 10 ** 9, 9);
@@ -1 +1 @@
1
- {"version":3,"file":"date.utility.js","sourceRoot":"","sources":["../../src/utilities/date.utility.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAkFjB,gBAlFF,eAAK,CAkFE;AAhFd,uFAAqE;AACrE,mEAAiD;AACjD,qEAAmD;AACnD,2DAAyC;AACzC,mEAAiD;AACjD,mDAAwC;AAExC,eAAK,CAAC,MAAM,CAAC,2BAAuB,CAAC,CAAC;AACtC,eAAK,CAAC,MAAM,CAAC,aAAS,CAAC,CAAC;AACxB,eAAK,CAAC,MAAM,CAAC,kBAAc,CAAC,CAAC;AAC7B,eAAK,CAAC,MAAM,CAAC,iBAAa,CAAC,CAAC;AAC5B,eAAK,CAAC,MAAM,CAAC,iBAAa,CAAC,CAAC;AAE5B,MAAM,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,4BAA4B,IAAI,kBAAkB,CAAC;AAC1E,eAAK,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;AAEjB,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,EAAE;IAClC,OAAO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AM,EAAE,IAAI,EAAE,GAAG,IAAI,IAAI,EAAE,IAAI,EAAE,IAAA,eAAK,GAAE,EAAE,CAAC;IAE3C,IAAI,EAAE,GAAG,IAAA,eAAK,EAAC,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IAC3C,OAAO,CAAC,IAAA,iBAAS,EAAC,EAAE,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC;QACpC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IACxB,CAAC;IAED,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC;AATW,QAAA,cAAc,kBASzB;AAEF;;;;;;;;;;;;;;GAcG;AACI,MAAM,SAAS,GAAG,CAAC,IAKzB,EAAE,EAAE;IACH,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,GAAG,KAAK,EAAE,UAAU,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC;IACrE,OAAO,IAAA,eAAK,EAAC,IAAI,CAAC,CAAC,EAAE,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;AACvE,CAAC,CAAC;AARW,QAAA,SAAS,aAQpB;AAEF;;;;;;;;GAQG;AACI,MAAM,MAAM,GAAG,GAAG,EAAE;IACzB,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAC9B,OAAO,IAAA,qBAAK,EAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;AAC/C,CAAC,CAAC;AAHW,QAAA,MAAM,UAGjB"}
@@ -1,15 +1,78 @@
1
+ /**
2
+ * Enhanced application error class with comprehensive error tracking
3
+ * @class ApplicationError
4
+ * @extends Error
5
+ * @example
6
+ * throw new ApplicationError({
7
+ * statusCode: 500,
8
+ * messageCode: 'DATABASE_ERROR',
9
+ * message: 'Failed to connect to database',
10
+ * context: { dbName: 'users' },
11
+ * originalError: err
12
+ * });
13
+ */
1
14
  export declare class ApplicationError extends Error {
2
15
  statusCode: number;
3
16
  messageCode?: string;
17
+ timestamp: Date;
18
+ context?: Record<string, any>;
19
+ originalError?: Error;
20
+ correlationId?: string;
4
21
  constructor(opts: {
5
22
  statusCode?: number;
6
23
  messageCode?: string;
7
24
  message: string;
25
+ context?: Record<string, any>;
26
+ originalError?: Error;
27
+ correlationId?: string;
8
28
  });
29
+ /**
30
+ * Serialize error to JSON format for logging/response
31
+ */
32
+ toJSON(): {
33
+ message: string;
34
+ statusCode: number;
35
+ messageCode: string | undefined;
36
+ timestamp: string;
37
+ context: Record<string, any> | undefined;
38
+ correlationId: string | undefined;
39
+ };
40
+ }
41
+ /**
42
+ * Error for not-implemented methods
43
+ * @class NotImplementedError
44
+ * @extends ApplicationError
45
+ */
46
+ export declare class NotImplementedError extends ApplicationError {
47
+ /**
48
+ * @param methodName - Name of the not-implemented method
49
+ * @param context - Additional context information
50
+ */
51
+ constructor(methodName: string, context?: Record<string, any>);
52
+ }
53
+ /**
54
+ * Error for validation failures
55
+ * @class ValidationError
56
+ * @extends ApplicationError
57
+ */
58
+ export declare class ValidationError extends ApplicationError {
59
+ /**
60
+ * @param message - Error message
61
+ * @param context - Validation context with field errors
62
+ */
63
+ constructor(message: string, context?: Record<string, any>);
9
64
  }
65
+ /**
66
+ * Factory function to create ApplicationError instances
67
+ * @param opts - Error configuration options
68
+ * @returns ApplicationError instance
69
+ */
10
70
  export declare const getError: (opts: {
11
71
  statusCode?: number;
12
72
  messageCode?: string;
13
73
  message: string;
74
+ context?: Record<string, any>;
75
+ originalError?: Error;
76
+ correlationId?: string;
14
77
  }) => ApplicationError;
15
78
  //# sourceMappingURL=error.utility.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"error.utility.d.ts","sourceRoot":"","sources":["../../src/utilities/error.utility.ts"],"names":[],"mappings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;AAED;;;;GAIG;AACH,qBAAa,eAAgB,SAAQ,gBAAgB;IACnD;;;OAGG;gBACS,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;CAS3D;AAED;;;;GAIG;AACH,eAAO,MAAM,QAAQ,GAAI,MAAM;IAC7B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,aAAa,CAAC,EAAE,KAAK,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,qBAEA,CAAC"}
@@ -1,18 +1,96 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getError = exports.ApplicationError = void 0;
3
+ exports.getError = exports.ValidationError = exports.NotImplementedError = exports.ApplicationError = void 0;
4
+ /**
5
+ * Enhanced application error class with comprehensive error tracking
6
+ * @class ApplicationError
7
+ * @extends Error
8
+ * @example
9
+ * throw new ApplicationError({
10
+ * statusCode: 500,
11
+ * messageCode: 'DATABASE_ERROR',
12
+ * message: 'Failed to connect to database',
13
+ * context: { dbName: 'users' },
14
+ * originalError: err
15
+ * });
16
+ */
4
17
  class ApplicationError extends Error {
5
18
  constructor(opts) {
6
- const { message, messageCode, statusCode = 400 } = opts;
19
+ const { message, messageCode, statusCode = 400, context, originalError, correlationId } = opts;
7
20
  super(message);
8
21
  this.statusCode = statusCode;
9
22
  this.messageCode = messageCode;
23
+ this.context = context;
24
+ this.originalError = originalError;
25
+ this.correlationId = correlationId;
26
+ this.timestamp = new Date();
27
+ // Maintain proper prototype chain for instanceof checks
28
+ Object.setPrototypeOf(this, ApplicationError.prototype);
29
+ }
30
+ /**
31
+ * Serialize error to JSON format for logging/response
32
+ */
33
+ toJSON() {
34
+ return {
35
+ message: this.message,
36
+ statusCode: this.statusCode,
37
+ messageCode: this.messageCode,
38
+ timestamp: this.timestamp.toISOString(),
39
+ context: this.context,
40
+ correlationId: this.correlationId,
41
+ };
10
42
  }
11
43
  }
12
44
  exports.ApplicationError = ApplicationError;
45
+ /**
46
+ * Error for not-implemented methods
47
+ * @class NotImplementedError
48
+ * @extends ApplicationError
49
+ */
50
+ class NotImplementedError extends ApplicationError {
51
+ /**
52
+ * @param methodName - Name of the not-implemented method
53
+ * @param context - Additional context information
54
+ */
55
+ constructor(methodName, context) {
56
+ super({
57
+ statusCode: 501,
58
+ messageCode: 'METHOD_NOT_IMPLEMENTED',
59
+ message: `Method '${methodName}' is not implemented.`,
60
+ context,
61
+ });
62
+ Object.setPrototypeOf(this, NotImplementedError.prototype);
63
+ }
64
+ }
65
+ exports.NotImplementedError = NotImplementedError;
66
+ /**
67
+ * Error for validation failures
68
+ * @class ValidationError
69
+ * @extends ApplicationError
70
+ */
71
+ class ValidationError extends ApplicationError {
72
+ /**
73
+ * @param message - Error message
74
+ * @param context - Validation context with field errors
75
+ */
76
+ constructor(message, context) {
77
+ super({
78
+ statusCode: 400,
79
+ messageCode: 'VALIDATION_ERROR',
80
+ message,
81
+ context,
82
+ });
83
+ Object.setPrototypeOf(this, ValidationError.prototype);
84
+ }
85
+ }
86
+ exports.ValidationError = ValidationError;
87
+ /**
88
+ * Factory function to create ApplicationError instances
89
+ * @param opts - Error configuration options
90
+ * @returns ApplicationError instance
91
+ */
13
92
  const getError = (opts) => {
14
- const error = new ApplicationError(opts);
15
- return error;
93
+ return new ApplicationError(opts);
16
94
  };
17
95
  exports.getError = getError;
18
96
  //# sourceMappingURL=error.utility.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"error.utility.js","sourceRoot":"","sources":["../../src/utilities/error.utility.ts"],"names":[],"mappings":";;;AAAA,MAAa,gBAAiB,SAAQ,KAAK;IAIzC,YAAY,IAAoE;QAC9E,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,UAAU,GAAG,GAA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AW,EAAE;YACvC,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,aAAa,EAAE,IAAI,CAAC,aAAa;SAClC,CAAC;IACJ,CAAC;CACF;AA3CD,4CA2CC;AAED;;;;GAIG;AACH,MAAa,mBAAoB,SAAQ,gBAAgB;IACvD;;;OAGG;IACH,YAAY,UAAkB,EAAE,OAA6B;QAC3D,KAAK,CAAC;YACJ,UAAU,EAAE,GAAG;YACf,WAAW,EAAE,wBAAwB;YACrC,OAAO,EAAE,WAAW,UAAU,uBAAuB;YACrD,OAAO;SACR,CAAC,CAAC;QACH,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,mBAAmB,CAAC,SAAS,CAAC,CAAC;IAC7D,CAAC;CACF;AAdD,kDAcC;AAED;;;;GAIG;AACH,MAAa,eAAgB,SAAQ,gBAAgB;IACnD;;;OAGG;IACH,YAAY,OAAe,EAAE,OAA6B;QACxD,KAAK,CAAC;YACJ,UAAU,EAAE,GAAG;YACf,WAAW,EAAE,kBAAkB;YAC/B,OAAO;YACP,OAAO;SACR,CAAC,CAAC;QACH,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC;IACzD,CAAC;CACF;AAdD,0CAcC;AAED;;;;GAIG;AACI,MAAM,QAAQ,GAAG,CAAC,IAOxB,EAAE,EAAE;IACH,OAAO,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAC;AACpC,CAAC,CAAC;AATW,QAAA,QAAQ,YASnB"}
@@ -1,3 +1,4 @@
1
1
  export { default as get } from 'lodash/get';
2
2
  export { default as set } from 'lodash/set';
3
+ export { default as isEmpty } from 'lodash/isEmpty';
3
4
  //# sourceMappingURL=lodash.utility.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"lodash.utility.d.ts","sourceRoot":"","sources":["../../src/utilities/lodash.utility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,GAAG,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,OAAO,IAAI,GAAG,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"lodash.utility.d.ts","sourceRoot":"","sources":["../../src/utilities/lodash.utility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,GAAG,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,OAAO,IAAI,GAAG,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,gBAAgB,CAAC"}
@@ -3,9 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.set = exports.get = void 0;
6
+ exports.isEmpty = exports.set = exports.get = void 0;
7
7
  var get_1 = require("lodash/get");
8
8
  Object.defineProperty(exports, "get", { enumerable: true, get: function () { return __importDefault(get_1).default; } });
9
9
  var set_1 = require("lodash/set");
10
10
  Object.defineProperty(exports, "set", { enumerable: true, get: function () { return __importDefault(set_1).default; } });
11
+ var isEmpty_1 = require("lodash/isEmpty");
12
+ Object.defineProperty(exports, "isEmpty", { enumerable: true, get: function () { return __importDefault(isEmpty_1).default; } });
11
13
  //# sourceMappingURL=lodash.utility.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"lodash.utility.js","sourceRoot":"","sources":["../../src/utilities/lodash.utility.ts"],"names":[],"mappings":";;;;;;AAAA,kCAA4C;AAAnC,2GAAA,OAAO,OAAO;AACvB,kCAA4C;AAAnC,2GAAA,OAAO,OAAO"}
1
+ {"version":3,"file":"lodash.utility.js","sourceRoot":"","sources":["../../src/utilities/lodash.utility.ts"],"names":[],"mappings":";;;;;;AAAA,kCAA4C;AAAnC,2GAAA,OAAO,OAAO;AACvB,kCAA4C;AAAnC,2GAAA,OAAO,OAAO;AACvB,0CAAoD;AAA3C,mHAAA,OAAO,OAAW"}
@@ -1,8 +1,23 @@
1
1
  import { SchemaObject } from '@loopback/rest';
2
2
  import { BaseEntity, BaseIdEntity } from '../base/models/base.model';
3
+ /**
4
+ * Extracts the JSON schema of the ID property from a LoopBack entity
5
+ * @param entity - The LoopBack entity class (must extend BaseEntity)
6
+ * @returns The SchemaObject representing the ID property
7
+ * @example
8
+ * const schema = getIdSchema(User);
9
+ * // { type: 'number', minimum: 1 }
10
+ */
3
11
  export declare const getIdSchema: <E extends BaseEntity>(entity: typeof BaseEntity & {
4
12
  prototype: E;
5
13
  }) => SchemaObject;
14
+ /**
15
+ * Inspects the metadata of a LoopBack entity to determine the ID type
16
+ * @param entity - The LoopBack entity class
17
+ * @returns 'string' or 'number' (default: 'number')
18
+ * @example
19
+ * const type = getIdType(User); // 'number'
20
+ */
6
21
  export declare const getIdType: <E extends BaseEntity>(entity: typeof BaseIdEntity & {
7
22
  prototype: E;
8
23
  }) => "string" | "number";
@@ -1 +1 @@
1
- {"version":3,"file":"model.utility.d.ts","sourceRoot":"","sources":["../../src/utilities/model.utility.ts"],"names":[],"mappings":"AACA,OAAO,EAAqC,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEjF,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAGpE,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,UAAU,EAC9C,QAAQ,OAAO,UAAU,GAAG;IAAE,SAAS,EAAE,CAAC,CAAA;CAAE,KAC3C,YAIF,CAAC;AAGF,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,UAAU,EAC5C,QAAQ,OAAO,YAAY,GAAG;IAAE,SAAS,EAAE,CAAC,CAAA;CAAE,KAC7C,QAAQ,GAAG,QAoBb,CAAC"}
1
+ {"version":3,"file":"model.utility.d.ts","sourceRoot":"","sources":["../../src/utilities/model.utility.ts"],"names":[],"mappings":"AACA,OAAO,EAAqC,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEjF,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAEpE;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,UAAU,EAC9C,QAAQ,OAAO,UAAU,GAAG;IAAE,SAAS,EAAE,CAAC,CAAA;CAAE,KAC3C,YAIF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,UAAU,EAC5C,QAAQ,OAAO,YAAY,GAAG;IAAE,SAAS,EAAE,CAAC,CAAA;CAAE,KAC7C,QAAQ,GAAG,QAoBb,CAAC"}
@@ -3,14 +3,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getIdType = exports.getIdSchema = void 0;
4
4
  const metadata_1 = require("@loopback/metadata");
5
5
  const rest_1 = require("@loopback/rest");
6
- // --------------------------------------------------------------------------------------------------------------
6
+ /**
7
+ * Extracts the JSON schema of the ID property from a LoopBack entity
8
+ * @param entity - The LoopBack entity class (must extend BaseEntity)
9
+ * @returns The SchemaObject representing the ID property
10
+ * @example
11
+ * const schema = getIdSchema(User);
12
+ * // { type: 'number', minimum: 1 }
13
+ */
7
14
  const getIdSchema = (entity) => {
8
15
  const idProp = entity.getIdProperties()[0];
9
16
  const modelSchema = (0, rest_1.jsonToSchemaObject)((0, rest_1.getJsonSchema)(entity));
10
17
  return modelSchema.properties?.[idProp];
11
18
  };
12
19
  exports.getIdSchema = getIdSchema;
13
- // --------------------------------------------------------------------------------------------------------------
20
+ /**
21
+ * Inspects the metadata of a LoopBack entity to determine the ID type
22
+ * @param entity - The LoopBack entity class
23
+ * @returns 'string' or 'number' (default: 'number')
24
+ * @example
25
+ * const type = getIdType(User); // 'number'
26
+ */
14
27
  const getIdType = (entity) => {
15
28
  let idType = 'number';
16
29
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"model.utility.js","sourceRoot":"","sources":["../../src/utilities/model.utility.ts"],"names":[],"mappings":";;;AAAA,iDAAuD;AACvD,yCAAiF;AAIjF,iHAAiH;AAC1G,MAAM,WAAW,GAAG,CACzB,MA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