@minimaltech/node-infra 0.5.9-22 → 0.5.9-24

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 (175) hide show
  1. package/dist/base/applications/base.application.js +40 -28
  2. package/dist/base/applications/default.application.js +8 -2
  3. package/dist/base/base.component.js +2 -2
  4. package/dist/base/base.helper.js +3 -4
  5. package/dist/base/base.provider.js +2 -2
  6. package/dist/base/base.sequence.js +26 -17
  7. package/dist/base/controllers/common.js +9 -8
  8. package/dist/base/controllers/crud.controller.js +67 -55
  9. package/dist/base/controllers/express-request-handler.js +0 -2
  10. package/dist/base/controllers/kv.controller.js +18 -7
  11. package/dist/base/controllers/relational.controller.d.ts +3 -1
  12. package/dist/base/controllers/relational.controller.js +57 -40
  13. package/dist/base/controllers/service-crud.controller.js +46 -46
  14. package/dist/base/datasources/base.datasource.js +0 -1
  15. package/dist/base/loopback/@lb/core/index.js +1 -0
  16. package/dist/base/loopback/@lb/repository/index.js +1 -0
  17. package/dist/base/loopback/authentication/index.js +2 -0
  18. package/dist/base/loopback/filter/index.js +2 -0
  19. package/dist/base/loopback/http-server/index.js +2 -0
  20. package/dist/base/models/base.model.d.ts +7 -0
  21. package/dist/base/models/base.model.js +23 -5
  22. package/dist/base/repositories/base.repository.d.ts +3 -0
  23. package/dist/base/repositories/base.repository.js +24 -5
  24. package/dist/base/repositories/relations/has-many-polymorphic/decorator.d.ts +8 -0
  25. package/dist/base/repositories/relations/has-many-polymorphic/decorator.js +10 -11
  26. package/dist/base/repositories/relations/has-many-polymorphic/factory.d.ts +9 -0
  27. package/dist/base/repositories/relations/has-many-polymorphic/factory.js +30 -12
  28. package/dist/base/repositories/searchable-tz-crud.repository.js +160 -129
  29. package/dist/base/repositories/tz-crud.repository.js +58 -23
  30. package/dist/base/services/base-crud.service.js +9 -6
  31. package/dist/base/services/base.service.js +2 -2
  32. package/dist/common/constants.js +89 -81
  33. package/dist/common/environments.js +25 -25
  34. package/dist/common/keys.js +2 -2
  35. package/dist/common/statuses.js +31 -28
  36. package/dist/common/types.d.ts +3 -0
  37. package/dist/components/authenticate/common/constants.js +13 -11
  38. package/dist/components/authenticate/common/keys.js +7 -7
  39. package/dist/components/authenticate/common/types.js +3 -11
  40. package/dist/components/authenticate/component.js +28 -20
  41. package/dist/components/authenticate/controllers/auth.controller.js +11 -13
  42. package/dist/components/authenticate/controllers/oauth2.controller.js +20 -18
  43. package/dist/components/authenticate/middleware.js +35 -25
  44. package/dist/components/authenticate/models/oauth2-client.model.js +3 -8
  45. package/dist/components/authenticate/models/oauth2-scope.model.js +0 -4
  46. package/dist/components/authenticate/models/oauth2-token.model.js +0 -7
  47. package/dist/components/authenticate/oauth2-handlers/authorization-code.handler.js +5 -4
  48. package/dist/components/authenticate/oauth2-handlers/base.js +110 -95
  49. package/dist/components/authenticate/oauth2-handlers/client-credential.handler.js +3 -2
  50. package/dist/components/authenticate/oauth2-handlers/oauth2.js +2 -3
  51. package/dist/components/authenticate/repositories/oauth2.repository.js +0 -2
  52. package/dist/components/authenticate/services/basic-token.service.js +29 -18
  53. package/dist/components/authenticate/services/basic.strategy.js +17 -7
  54. package/dist/components/authenticate/services/jwt-token.service.js +40 -27
  55. package/dist/components/authenticate/services/jwt.strategy.js +1 -2
  56. package/dist/components/authenticate/services/oauth2.service.js +110 -98
  57. package/dist/components/authenticate/services/oauth2.strategy.js +31 -19
  58. package/dist/components/authorize/adapters/adapter-builder.js +0 -1
  59. package/dist/components/authorize/adapters/base.adapter.js +9 -2
  60. package/dist/components/authorize/adapters/casbin-postgres-adapter.helper.js +55 -37
  61. package/dist/components/authorize/adapters/casbin-redis-adapter.helper.js +1 -0
  62. package/dist/components/authorize/common/constants.js +12 -10
  63. package/dist/components/authorize/common/keys.js +15 -15
  64. package/dist/components/authorize/common/types.js +2 -2
  65. package/dist/components/authorize/component.js +59 -44
  66. package/dist/components/authorize/decorators/index.d.ts +11 -0
  67. package/dist/components/authorize/decorators/index.js +14 -1
  68. package/dist/components/authorize/interceptor.js +80 -76
  69. package/dist/components/authorize/migrations/0000-create-view-policy.js +14 -3
  70. package/dist/components/authorize/models/defs.js +5 -24
  71. package/dist/components/authorize/models/role.model.js +1 -1
  72. package/dist/components/authorize/models/user-role.model.js +1 -0
  73. package/dist/components/authorize/models/view-authorize-policy.model.js +1 -4
  74. package/dist/components/authorize/provider.js +96 -81
  75. package/dist/components/authorize/repositories/authorize.repository.js +6 -3
  76. package/dist/components/authorize/services/enforcer.service.js +27 -20
  77. package/dist/components/authorize/services/generator.service.d.ts +20 -0
  78. package/dist/components/authorize/services/generator.service.js +96 -62
  79. package/dist/components/crash-report/common/keys.js +10 -8
  80. package/dist/components/crash-report/component.js +44 -31
  81. package/dist/components/crash-report/providers/provider.js +0 -1
  82. package/dist/components/crash-report/providers/third-parties/base.js +2 -2
  83. package/dist/components/crash-report/services/mt-crash-report.service.js +5 -5
  84. package/dist/components/grpc/common/keys.js +4 -4
  85. package/dist/components/grpc/components/server.component.js +8 -8
  86. package/dist/components/grpc/controllers/base.js +0 -1
  87. package/dist/components/grpc/helpers/grpc-client.js +3 -9
  88. package/dist/components/grpc/helpers/grpc-server.js +17 -14
  89. package/dist/components/grpc/persistents/grpc.connector.js +2 -8
  90. package/dist/components/grpc/persistents/grpc.datasource.js +3 -2
  91. package/dist/components/grpc/persistents/grpc.repository.js +2 -3
  92. package/dist/components/health-check/component.js +0 -1
  93. package/dist/components/migration/common/keys.js +3 -3
  94. package/dist/components/migration/component.js +8 -5
  95. package/dist/components/migration/models/migration.model.js +0 -2
  96. package/dist/components/socket-io/common/constants.js +10 -10
  97. package/dist/components/socket-io/common/keys.js +6 -6
  98. package/dist/components/socket-io/component.js +8 -9
  99. package/dist/components/socket-io/helpers/socket-io-client.helper.js +11 -7
  100. package/dist/components/socket-io/helpers/socket-io-server.helper.js +41 -26
  101. package/dist/components/static-asset/common/keys.js +4 -4
  102. package/dist/components/static-asset/component.js +8 -9
  103. package/dist/components/static-asset/controllers/asset.controller.d.ts +8 -0
  104. package/dist/components/static-asset/controllers/asset.controller.js +93 -71
  105. package/dist/components/static-asset/controllers/resource.controller.js +9 -8
  106. package/dist/datasources/memory/datasource.js +3 -3
  107. package/dist/datasources/postgres/datasource.js +10 -10
  108. package/dist/datasources/redis/connector.js +7 -18
  109. package/dist/datasources/redis/datasource.js +7 -7
  110. package/dist/helpers/application-environment.helper.js +3 -3
  111. package/dist/helpers/cron.helper.js +14 -9
  112. package/dist/helpers/crypto/algorithms/aes.algorithm.js +7 -8
  113. package/dist/helpers/crypto/algorithms/base.algorithm.js +4 -3
  114. package/dist/helpers/crypto/algorithms/rsa.algorithm.js +5 -4
  115. package/dist/helpers/database/query-builder.helper.js +5 -2
  116. package/dist/helpers/logger/application-logger.js +17 -7
  117. package/dist/helpers/logger/common/types.js +22 -20
  118. package/dist/helpers/logger/default-logger.js +12 -2
  119. package/dist/helpers/logger/factory.js +1 -1
  120. package/dist/helpers/logger/transports/dgram.transport.js +25 -16
  121. package/dist/helpers/network/http-request/base-network-request.helper.js +34 -36
  122. package/dist/helpers/network/http-request/fetcher/axios-fetcher.js +22 -10
  123. package/dist/helpers/network/http-request/fetcher/base-fetcher.js +36 -13
  124. package/dist/helpers/network/http-request/fetcher/node-fetcher.js +59 -37
  125. package/dist/helpers/network/tcp-socket/base-tcp-client.helper.js +27 -30
  126. package/dist/helpers/network/tcp-socket/base-tcp-server.helper.js +19 -21
  127. package/dist/helpers/network/tcp-socket/network-tcp-client.helper.js +1 -5
  128. package/dist/helpers/network/tcp-socket/network-tcp-server.helper.js +1 -5
  129. package/dist/helpers/network/tcp-socket/network-tls-tcp-client.helper.js +1 -5
  130. package/dist/helpers/network/tcp-socket/network-tls-tcp-server.helper.js +1 -5
  131. package/dist/helpers/network/udp-socket/network-udp-client.helper.js +18 -21
  132. package/dist/helpers/queue/bullmq.helper.js +22 -21
  133. package/dist/helpers/queue/mqtt.helper.js +17 -15
  134. package/dist/helpers/queue/queue.helper.js +145 -74
  135. package/dist/helpers/redis/default.helper.js +162 -117
  136. package/dist/helpers/redis/redis-cluster.helper.js +2 -7
  137. package/dist/helpers/redis/redis.helper.js +5 -8
  138. package/dist/helpers/storage/di-container.helper.js +0 -2
  139. package/dist/helpers/storage/minio.helper.js +128 -88
  140. package/dist/helpers/testing/common.js +3 -3
  141. package/dist/helpers/testing/describe.js +21 -14
  142. package/dist/helpers/testing/test-case.js +0 -5
  143. package/dist/helpers/testing/test-handler.js +30 -23
  144. package/dist/helpers/testing/test-plan/base.js +6 -9
  145. package/dist/helpers/worker-thread/base.js +20 -10
  146. package/dist/helpers/worker-thread/worker-bus.js +12 -11
  147. package/dist/helpers/worker-thread/worker-pool.js +25 -17
  148. package/dist/interceptors/content-range.interceptor.js +132 -115
  149. package/dist/middlewares/request-body-parser.middleware.js +16 -4
  150. package/dist/middlewares/request-spy.middleware.js +5 -4
  151. package/dist/migrations/handler.js +22 -13
  152. package/dist/mixins/data-type.mixin.js +0 -5
  153. package/dist/mixins/deprecated/user-audit.mixin.d.ts +3 -0
  154. package/dist/mixins/deprecated/user-audit.mixin.js +5 -2
  155. package/dist/mixins/duplicatable.mixin.js +0 -1
  156. package/dist/mixins/object-search.mixin.js +0 -1
  157. package/dist/mixins/principal.mixin.js +0 -2
  158. package/dist/mixins/soft-delete.mixin.js +0 -1
  159. package/dist/mixins/soft-persistent.mixin.js +0 -1
  160. package/dist/mixins/text-search.mixin.js +0 -1
  161. package/dist/mixins/tz.mixin.js +0 -2
  162. package/dist/mixins/user-audit.mixin.js +3 -5
  163. package/dist/mixins/vector.mixin.js +6 -9
  164. package/dist/tsconfig.base.json +6 -5
  165. package/dist/utilities/date.utility.js +23 -5
  166. package/dist/utilities/error.utility.js +0 -2
  167. package/dist/utilities/model.utility.js +6 -2
  168. package/dist/utilities/parse.utility.d.ts +16 -0
  169. package/dist/utilities/parse.utility.js +41 -6
  170. package/dist/utilities/performance.utility.js +2 -1
  171. package/dist/utilities/promise.utility.d.ts +17 -0
  172. package/dist/utilities/promise.utility.js +31 -5
  173. package/dist/utilities/query.utility.js +16 -8
  174. package/dist/utilities/request.utility.js +8 -2
  175. package/package.json +2 -3
@@ -13,11 +13,9 @@ exports.UserAuditMixin = void 0;
13
13
  const utilities_1 = require("../utilities");
14
14
  const repository_1 = require("@loopback/repository");
15
15
  const UserAuditMixin = (superClass, opts) => {
16
- const { useRelation = false, creatorResolver, creatorKeyTo, modifierResolver, modifierKeyTo, } = opts ?? {};
16
+ const { useRelation = false, creatorResolver, creatorKeyTo, modifierResolver, modifierKeyTo, } = opts !== null && opts !== void 0 ? opts : {};
17
17
  if (!useRelation) {
18
18
  let Mixed = class Mixed extends superClass {
19
- createdBy;
20
- modifiedBy;
21
19
  };
22
20
  __decorate([
23
21
  (0, repository_1.property)({
@@ -26,6 +24,7 @@ const UserAuditMixin = (superClass, opts) => {
26
24
  columnName: 'created_by',
27
25
  dataType: 'integer',
28
26
  },
27
+ // hidden: true,
29
28
  }),
30
29
  __metadata("design:type", Object)
31
30
  ], Mixed.prototype, "createdBy", void 0);
@@ -36,6 +35,7 @@ const UserAuditMixin = (superClass, opts) => {
36
35
  columnName: 'modified_by',
37
36
  dataType: 'integer',
38
37
  },
38
+ // hidden: true,
39
39
  }),
40
40
  __metadata("design:type", Object)
41
41
  ], Mixed.prototype, "modifiedBy", void 0);
@@ -51,8 +51,6 @@ const UserAuditMixin = (superClass, opts) => {
51
51
  throw (0, utilities_1.getError)({ message: '[UserAuditMixin] Invalid modifierResolver' });
52
52
  }
53
53
  let Mixed = class Mixed extends superClass {
54
- createdBy;
55
- modifiedBy;
56
54
  };
57
55
  __decorate([
58
56
  (0, repository_1.belongsTo)(creatorResolver, { keyFrom: 'createdBy', keyTo: creatorKeyTo, name: 'creator' }, {
@@ -13,18 +13,15 @@ exports.VectorMixin = void 0;
13
13
  const utilities_1 = require("../utilities");
14
14
  const repository_1 = require("@loopback/repository");
15
15
  const VectorMixin = (superClass, options) => {
16
+ var _a, _b, _c;
16
17
  const { uuid, embedding } = options;
17
- const vectorType = embedding?.vectorType ?? 'vector';
18
- if (!embedding?.vectorSize) {
18
+ const vectorType = (_a = embedding === null || embedding === void 0 ? void 0 : embedding.vectorType) !== null && _a !== void 0 ? _a : 'vector';
19
+ if (!(embedding === null || embedding === void 0 ? void 0 : embedding.vectorSize)) {
19
20
  throw (0, utilities_1.getError)({
20
- message: `[VectorMixin] Invalid vector size | class: ${superClass.name} | vectorSize: ${embedding?.vectorSize}`,
21
+ message: `[VectorMixin] Invalid vector size | class: ${superClass.name} | vectorSize: ${embedding === null || embedding === void 0 ? void 0 : embedding.vectorSize}`,
21
22
  });
22
23
  }
23
24
  class Mixed extends superClass {
24
- uuid;
25
- embedding;
26
- metadata;
27
- details;
28
25
  }
29
26
  __decorate([
30
27
  (0, repository_1.property)({
@@ -32,7 +29,7 @@ const VectorMixin = (superClass, options) => {
32
29
  required: true,
33
30
  defaultFn: 'uuidv4',
34
31
  postgresql: {
35
- columnName: uuid?.columnName ?? 'uuid',
32
+ columnName: (_b = uuid === null || uuid === void 0 ? void 0 : uuid.columnName) !== null && _b !== void 0 ? _b : 'uuid',
36
33
  dataType: 'text',
37
34
  },
38
35
  }),
@@ -42,7 +39,7 @@ const VectorMixin = (superClass, options) => {
42
39
  (0, repository_1.property)({
43
40
  type: 'any',
44
41
  postgresql: {
45
- columnName: embedding?.columnName ?? 'embedding',
42
+ columnName: (_c = embedding === null || embedding === void 0 ? void 0 : embedding.columnName) !== null && _c !== void 0 ? _c : 'embedding',
46
43
  dataType: `${vectorType}(${(0, utilities_1.int)(embedding.vectorSize)})`,
47
44
  },
48
45
  }),
@@ -2,7 +2,7 @@
2
2
  "$schema": "http://json.schemastore.org/tsconfig",
3
3
  "extends": "@loopback/build/config/tsconfig.common.json",
4
4
  "compilerOptions": {
5
- "target": "es2023",
5
+ "target": "es2015",
6
6
  "module": "nodenext",
7
7
 
8
8
  /* Bundler mode */
@@ -10,23 +10,23 @@
10
10
  "experimentalDecorators": true,
11
11
  "importHelpers": false,
12
12
  "esModuleInterop": true,
13
- "removeComments": true,
13
+ "removeComments": false,
14
14
  "moduleResolution": "nodenext",
15
-
15
+
16
16
  /* Optimization */
17
17
  "declaration": true,
18
18
  "declarationMap": false,
19
19
  "sourceMap": false,
20
20
  "inlineSourceMap": false,
21
21
  "inlineSources": false,
22
-
22
+
23
23
  /* Linting */
24
24
  "strict": true,
25
25
  "noUnusedLocals": true,
26
26
  "noUnusedParameters": true,
27
27
  "noImplicitOverride": true,
28
28
  "noFallthroughCasesInSwitch": true,
29
-
29
+
30
30
  /* Paths */
31
31
  "outDir": "dist",
32
32
  "rootDir": "src",
@@ -34,6 +34,7 @@
34
34
  "paths": {
35
35
  "@/*": ["./*"]
36
36
  }
37
+
37
38
  },
38
39
  "include": ["src", "./*.config.*", ".prettierrc.*"],
39
40
  "exclude": ["node_modules", "dist"]
@@ -2,6 +2,7 @@
2
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
+ var _a;
5
6
  Object.defineProperty(exports, "__esModule", { value: true });
6
7
  exports.dayjs = exports.hrTime = exports.getDateTz = exports.getNextWeekday = exports.getPreviousWeekday = exports.isWeekday = exports.sleep = void 0;
7
8
  const dayjs_1 = __importDefault(require("dayjs"));
@@ -17,19 +18,28 @@ dayjs_1.default.extend(utc_1.default);
17
18
  dayjs_1.default.extend(timezone_1.default);
18
19
  dayjs_1.default.extend(weekday_1.default);
19
20
  dayjs_1.default.extend(isoWeek_1.default);
20
- const tz = process.env.APP_ENV_APPLICATION_TIMEZONE ?? 'Asia/Ho_Chi_Minh';
21
+ const tz = (_a = process.env.APP_ENV_APPLICATION_TIMEZONE) !== null && _a !== void 0 ? _a : 'Asia/Ho_Chi_Minh';
21
22
  dayjs_1.default.tz.setDefault(tz);
22
23
  const sleep = (ms) => {
23
24
  return new Promise(resolve => setTimeout(resolve, ms));
24
25
  };
25
26
  exports.sleep = sleep;
26
27
  const isWeekday = (date) => {
27
- const isoWeekday = (0, dayjs_1.default)(date)?.isoWeekday();
28
+ var _a;
29
+ const isoWeekday = (_a = (0, dayjs_1.default)(date)) === null || _a === void 0 ? void 0 : _a.isoWeekday();
28
30
  return isoWeekday > 0 && isoWeekday < 6;
29
31
  };
30
32
  exports.isWeekday = isWeekday;
33
+ /* export const getPreviousWeekday = () => {
34
+ let date = dayjs();
35
+ while (!isWeekday(date)) {
36
+ date = date.subtract(1, 'day');
37
+ }
38
+
39
+ return date;
40
+ }; */
31
41
  const getPreviousWeekday = (opts) => {
32
- const { date } = opts ?? { date: (0, dayjs_1.default)() };
42
+ const { date } = opts !== null && opts !== void 0 ? opts : { date: (0, dayjs_1.default)() };
33
43
  let rs = (0, dayjs_1.default)(date).clone().subtract(1, 'day');
34
44
  while (!(0, exports.isWeekday)(rs.toISOString())) {
35
45
  rs = rs.subtract(1, 'day');
@@ -37,8 +47,16 @@ const getPreviousWeekday = (opts) => {
37
47
  return rs;
38
48
  };
39
49
  exports.getPreviousWeekday = getPreviousWeekday;
50
+ /* export const getNextWeekday = () => {
51
+ let date = dayjs();
52
+ while (!isWeekday(date)) {
53
+ date = date.add(1, 'day');
54
+ }
55
+
56
+ return date;
57
+ }; */
40
58
  const getNextWeekday = (opts) => {
41
- const { date } = opts ?? { date: (0, dayjs_1.default)() };
59
+ const { date } = opts !== null && opts !== void 0 ? opts : { date: (0, dayjs_1.default)() };
42
60
  let rs = (0, dayjs_1.default)(date).clone().add(1, 'day');
43
61
  while (!(0, exports.isWeekday)(rs.toISOString())) {
44
62
  rs = rs.add(1, 'day');
@@ -53,6 +71,6 @@ const getDateTz = (opts) => {
53
71
  exports.getDateTz = getDateTz;
54
72
  const hrTime = () => {
55
73
  const curr = process.hrtime();
56
- return (0, parse_utility_1.float)(curr[0] + curr[1] / 10 ** 9, 9);
74
+ return (0, parse_utility_1.float)(curr[0] + curr[1] / Math.pow(10, 9), 9);
57
75
  };
58
76
  exports.hrTime = hrTime;
@@ -2,8 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getError = exports.ApplicationError = void 0;
4
4
  class ApplicationError extends Error {
5
- statusCode;
6
- messageCode;
7
5
  constructor(opts) {
8
6
  const { message, messageCode, statusCode = 400 } = opts;
9
7
  super(message);
@@ -3,17 +3,21 @@ 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
  const getIdSchema = (entity) => {
8
+ var _a;
7
9
  const idProp = entity.getIdProperties()[0];
8
10
  const modelSchema = (0, rest_1.jsonToSchemaObject)((0, rest_1.getJsonSchema)(entity));
9
- return modelSchema.properties?.[idProp];
11
+ return (_a = modelSchema.properties) === null || _a === void 0 ? void 0 : _a[idProp];
10
12
  };
11
13
  exports.getIdSchema = getIdSchema;
14
+ // --------------------------------------------------------------------------------------------------------------
12
15
  const getIdType = (entity) => {
16
+ var _a;
13
17
  let idType = 'number';
14
18
  try {
15
19
  const idMetadata = metadata_1.MetadataInspector.getPropertyMetadata('loopback:model-properties', entity, 'id');
16
- idType = idMetadata?.type ?? 'number';
20
+ idType = (_a = idMetadata === null || idMetadata === void 0 ? void 0 : idMetadata.type) !== null && _a !== void 0 ? _a : 'number';
17
21
  }
18
22
  catch (e) {
19
23
  console.error("[getIdType] Failed to inspect entity id type! Use 'number' by default | Error: ", e);
@@ -10,8 +10,24 @@ export declare const toStringDecimal: (input: any, digit?: number, options?: {
10
10
  useLocaleFormat: boolean;
11
11
  }) => string | 0;
12
12
  export declare const getNumberValue: (input: string, method?: "int" | "float") => number;
13
+ /**
14
+ * Returns an object with the key as the value of the `keyMap` and the value as the object itself.
15
+ *
16
+ * @param arr - The input array
17
+ * @param keyMap - The property key to use as the key in the resulting object
18
+ *
19
+ * Note: In case of duplicate keys, the last element will be used.
20
+ */
13
21
  export declare const parseArrayToRecordWithKey: <T extends Record<K, PropertyKey>, K extends keyof T>(opts: {
14
22
  arr: T[];
15
23
  keyMap: K;
16
24
  }) => Record<T[K], T>;
25
+ /**
26
+ * Return a map with the key as the value of the `keyMap` and the value as the object itself.
27
+ *
28
+ * @param arr - The input array
29
+ * @param keyMap - The property key to use as the key in the resulting object
30
+ *
31
+ * Note: In case of duplicate keys, the last element will be used.
32
+ */
17
33
  export declare const parseArrayToMapWithKey: <T extends Record<K, PropertyKey>, K extends keyof T>(arr: T[], keyMap: K) => Map<T[K], T>;
@@ -7,6 +7,7 @@ exports.parseArrayToMapWithKey = exports.parseArrayToRecordWithKey = exports.get
7
7
  const get_1 = __importDefault(require("lodash/get"));
8
8
  const round_1 = __importDefault(require("lodash/round"));
9
9
  const error_utility_1 = require("./error.utility");
10
+ // -------------------------------------------------------------------------
10
11
  const INTL_0_DIGITS_FORMATER = new Intl.NumberFormat('en-US', {
11
12
  maximumFractionDigits: 0,
12
13
  minimumFractionDigits: 0,
@@ -15,14 +16,17 @@ const INTL_2_DIGITS_FORMATER = new Intl.NumberFormat('en-US', {
15
16
  maximumFractionDigits: 2,
16
17
  minimumFractionDigits: 2,
17
18
  });
19
+ // -------------------------------------------------------------------------
18
20
  const getUID = () => Math.random().toString(36).slice(2).toUpperCase();
19
21
  exports.getUID = getUID;
22
+ // -------------------------------------------------------------------------
20
23
  const toCamel = (s) => {
21
24
  return s.replace(/([-_][a-z])/gi, (sub) => {
22
25
  return sub.toUpperCase().replace('-', '').replace('_', '');
23
26
  });
24
27
  };
25
28
  exports.toCamel = toCamel;
29
+ // -------------------------------------------------------------------------
26
30
  const keysToCamel = (object) => {
27
31
  const n = {};
28
32
  const keys = Object.keys(object);
@@ -44,6 +48,10 @@ const keysToCamel = (object) => {
44
48
  n[(0, exports.toCamel)(key)] = (0, exports.keysToCamel)(value);
45
49
  break;
46
50
  }
51
+ /* case 'array': {
52
+ n[toCamel(key)] = value;
53
+ break;
54
+ } */
47
55
  default: {
48
56
  n[(0, exports.toCamel)(key)] = value;
49
57
  break;
@@ -53,6 +61,7 @@ const keysToCamel = (object) => {
53
61
  return n;
54
62
  };
55
63
  exports.keysToCamel = keysToCamel;
64
+ // -------------------------------------------------------------------------
56
65
  const isInt = (n) => {
57
66
  if (isNaN(n)) {
58
67
  return false;
@@ -60,6 +69,7 @@ const isInt = (n) => {
60
69
  return Number.isInteger(n) || Math.floor(Number(n)) === n || Number(n) % 1 === 0;
61
70
  };
62
71
  exports.isInt = isInt;
72
+ // -------------------------------------------------------------------------
63
73
  const isFloat = (input) => {
64
74
  if (isNaN(input)) {
65
75
  return false;
@@ -67,32 +77,38 @@ const isFloat = (input) => {
67
77
  return Number(input) === input || Number(input) % 1 !== 0;
68
78
  };
69
79
  exports.isFloat = isFloat;
80
+ // -------------------------------------------------------------------------
70
81
  const int = (input) => {
82
+ var _a, _b;
71
83
  if (!input || isNaN(input)) {
72
84
  return 0;
73
85
  }
74
- const normalized = input?.toString()?.replace(/,/g, '');
75
- return Number.parseInt(normalized, 10) ?? 0;
86
+ const normalized = (_a = input === null || input === void 0 ? void 0 : input.toString()) === null || _a === void 0 ? void 0 : _a.replace(/,/g, '');
87
+ return (_b = Number.parseInt(normalized, 10)) !== null && _b !== void 0 ? _b : 0;
76
88
  };
77
89
  exports.int = int;
90
+ // -------------------------------------------------------------------------
78
91
  const float = (input, digit = 2) => {
92
+ var _a;
79
93
  if (!input || isNaN(input)) {
80
94
  return 0;
81
95
  }
82
- const normalized = input?.toString()?.replace(/,/g, '');
96
+ const normalized = (_a = input === null || input === void 0 ? void 0 : input.toString()) === null || _a === void 0 ? void 0 : _a.replace(/,/g, '');
83
97
  return (0, round_1.default)(Number.parseFloat(normalized), digit);
84
98
  };
85
99
  exports.float = float;
100
+ // -------------------------------------------------------------------------
86
101
  const toBoolean = (input) => {
87
- return ((input !== 'false' &&
102
+ var _a;
103
+ return ((_a = (input !== 'false' &&
88
104
  input !== '0' &&
89
105
  input !== false &&
90
106
  input !== 0 &&
91
107
  input !== null &&
92
- input !== undefined) ??
93
- Boolean(input));
108
+ input !== undefined)) !== null && _a !== void 0 ? _a : Boolean(input));
94
109
  };
95
110
  exports.toBoolean = toBoolean;
111
+ // -------------------------------------------------------------------------
96
112
  const toStringDecimal = (input, digit = 2, options = { useLocaleFormat: true }) => {
97
113
  const { useLocaleFormat } = options;
98
114
  if (isNaN(input)) {
@@ -121,6 +137,7 @@ const toStringDecimal = (input, digit = 2, options = { useLocaleFormat: true })
121
137
  return formater.format(number);
122
138
  };
123
139
  exports.toStringDecimal = toStringDecimal;
140
+ // -------------------------------------------------------------------------
124
141
  const getNumberValue = (input, method = 'int') => {
125
142
  if (!input) {
126
143
  return 0;
@@ -146,6 +163,15 @@ const getNumberValue = (input, method = 'int') => {
146
163
  }
147
164
  };
148
165
  exports.getNumberValue = getNumberValue;
166
+ // ---------------------------------------------------------
167
+ /**
168
+ * Returns an object with the key as the value of the `keyMap` and the value as the object itself.
169
+ *
170
+ * @param arr - The input array
171
+ * @param keyMap - The property key to use as the key in the resulting object
172
+ *
173
+ * Note: In case of duplicate keys, the last element will be used.
174
+ */
149
175
  const parseArrayToRecordWithKey = (opts) => {
150
176
  const { arr, keyMap } = opts;
151
177
  const resultRecord = {};
@@ -163,6 +189,15 @@ const parseArrayToRecordWithKey = (opts) => {
163
189
  return resultRecord;
164
190
  };
165
191
  exports.parseArrayToRecordWithKey = parseArrayToRecordWithKey;
192
+ // ---------------------------------------------------------
193
+ /**
194
+ * Return a map with the key as the value of the `keyMap` and the value as the object itself.
195
+ *
196
+ * @param arr - The input array
197
+ * @param keyMap - The property key to use as the key in the resulting object
198
+ *
199
+ * Note: In case of duplicate keys, the last element will be used.
200
+ */
166
201
  const parseArrayToMapWithKey = (arr, keyMap) => {
167
202
  const resultMap = new Map();
168
203
  if (!arr.length) {
@@ -8,6 +8,7 @@ const getPerformanceCheckpoint = () => {
8
8
  };
9
9
  exports.getPerformanceCheckpoint = getPerformanceCheckpoint;
10
10
  const getExecutedPerformance = (opts) => {
11
- return (0, _1.float)(performance.now() - opts.from, opts.digit ?? DEFAULT_PERFORMANCE_DECIMAL);
11
+ var _a;
12
+ return (0, _1.float)(performance.now() - opts.from, (_a = opts.digit) !== null && _a !== void 0 ? _a : DEFAULT_PERFORMANCE_DECIMAL);
12
13
  };
13
14
  exports.getExecutedPerformance = getExecutedPerformance;
@@ -1,5 +1,22 @@
1
1
  import { ValueOrPromise } from '../common';
2
2
  type TTask<T> = () => Promise<T>;
3
+ /**
4
+ * Execute all tasks with limit number of asyncronous tasks.
5
+ * Whenever 1 task's resolved next task will be executed.
6
+ *
7
+ * @example
8
+ * With 20 tasks need to execute with limit is 5 tasks asyncronous
9
+ * ```
10
+ * const tasks = <Array of 20 functions which return promises>
11
+ * await executePromiseWithLimit({
12
+ * tasks,
13
+ * limit: 5,
14
+ onTaskDone: (opts: { result: any }) => {
15
+ // Do something on task done
16
+ },
17
+ * })
18
+ * ```
19
+ */
3
20
  export declare const executePromiseWithLimit: <T>(opts: {
4
21
  tasks: Array<TTask<T>>;
5
22
  limit: number;
@@ -1,7 +1,33 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.executePromiseWithLimit = void 0;
4
- const executePromiseWithLimit = async (opts) => {
13
+ /**
14
+ * Execute all tasks with limit number of asyncronous tasks.
15
+ * Whenever 1 task's resolved next task will be executed.
16
+ *
17
+ * @example
18
+ * With 20 tasks need to execute with limit is 5 tasks asyncronous
19
+ * ```
20
+ * const tasks = <Array of 20 functions which return promises>
21
+ * await executePromiseWithLimit({
22
+ * tasks,
23
+ * limit: 5,
24
+ onTaskDone: (opts: { result: any }) => {
25
+ // Do something on task done
26
+ },
27
+ * })
28
+ * ```
29
+ */
30
+ const executePromiseWithLimit = (opts) => __awaiter(void 0, void 0, void 0, function* () {
5
31
  const { tasks, limit, onTaskDone } = opts;
6
32
  const results = [];
7
33
  const executing = new Set();
@@ -13,11 +39,11 @@ const executePromiseWithLimit = async (opts) => {
13
39
  executing.add(promise);
14
40
  results.push(promise);
15
41
  if (executing.size >= limit) {
16
- const done = await Promise.race(executing);
17
- onTaskDone?.({ result: done });
42
+ const done = yield Promise.race(executing);
43
+ onTaskDone === null || onTaskDone === void 0 ? void 0 : onTaskDone({ result: done });
18
44
  }
19
45
  }
20
- await Promise.all(executing);
46
+ yield Promise.all(executing);
21
47
  return Promise.all(results);
22
- };
48
+ });
23
49
  exports.executePromiseWithLimit = executePromiseWithLimit;
@@ -11,27 +11,29 @@ const snakeCase_1 = __importDefault(require("lodash/snakeCase"));
11
11
  const error_utility_1 = require("./error.utility");
12
12
  const getTableDefinition = (opts) => {
13
13
  const { model, alias } = opts;
14
- const tableAlias = alias ?? model.name.toLowerCase();
14
+ const tableAlias = alias !== null && alias !== void 0 ? alias : model.name.toLowerCase();
15
15
  const tableNameWithAlias = `"${model.name}" ${tableAlias}`;
16
16
  const tableColumns = Object.entries(model.definition.properties)
17
17
  .map(([key, value]) => {
18
- const columnName = value?.name ?? value?.postgresql?.columnName ?? key;
18
+ var _a, _b, _c;
19
+ const columnName = (_c = (_a = value === null || value === void 0 ? void 0 : value.name) !== null && _a !== void 0 ? _a : (_b = value === null || value === void 0 ? void 0 : value.postgresql) === null || _b === void 0 ? void 0 : _b.columnName) !== null && _c !== void 0 ? _c : key;
19
20
  return {
20
21
  [`${key}`]: `${tableAlias}.${columnName}`,
21
22
  };
22
23
  })
23
24
  .reduce((acc, cur) => {
24
- return { ...acc, ...cur };
25
+ return Object.assign(Object.assign({}, acc), cur);
25
26
  }, {});
26
27
  const tableColumnsNoAlias = Object.entries(model.definition.properties)
27
28
  .map(([key, value]) => {
28
- const columnName = value?.name ?? value?.postgresql?.columnName ?? key;
29
+ var _a, _b, _c;
30
+ const columnName = (_c = (_a = value === null || value === void 0 ? void 0 : value.name) !== null && _a !== void 0 ? _a : (_b = value === null || value === void 0 ? void 0 : value.postgresql) === null || _b === void 0 ? void 0 : _b.columnName) !== null && _c !== void 0 ? _c : key;
29
31
  return {
30
32
  [`${key}`]: `${columnName}`,
31
33
  };
32
34
  })
33
35
  .reduce((acc, cur) => {
34
- return { ...acc, ...cur };
36
+ return Object.assign(Object.assign({}, acc), cur);
35
37
  }, {});
36
38
  return {
37
39
  table: { name: model.name, alias: tableAlias, nameWithQuotation: `"${model.name}"` },
@@ -41,22 +43,23 @@ const getTableDefinition = (opts) => {
41
43
  };
42
44
  };
43
45
  exports.getTableDefinition = getTableDefinition;
46
+ // --------------------------------------------------------------------------------
44
47
  const getValue = (value) => {
45
48
  switch (typeof value) {
46
49
  case null: {
47
50
  return 'null';
48
51
  }
49
52
  case 'number': {
50
- return value?.toString();
53
+ return value === null || value === void 0 ? void 0 : value.toString();
51
54
  }
52
55
  case 'boolean': {
53
56
  return value;
54
57
  }
55
58
  case 'string': {
56
- if (value?.toString().trim() === '') {
59
+ if ((value === null || value === void 0 ? void 0 : value.toString().trim()) === '') {
57
60
  return "''";
58
61
  }
59
- return `'${value?.toString().replace(/'/g, "''")}'`;
62
+ return `'${value === null || value === void 0 ? void 0 : value.toString().replace(/'/g, "''")}'`;
60
63
  }
61
64
  default: {
62
65
  return `'${value}'`;
@@ -64,6 +67,7 @@ const getValue = (value) => {
64
67
  }
65
68
  };
66
69
  exports.getValue = getValue;
70
+ // --------------------------------------------------------------------------------
67
71
  const buildBatchUpdateQuery = (opts) => {
68
72
  const { data, tableName, keys, setKeys, whereKeys, whereRaws = [] } = opts;
69
73
  const withAlias = 't';
@@ -73,6 +77,7 @@ const buildBatchUpdateQuery = (opts) => {
73
77
  message: '[batchUpdate] Missing required fields',
74
78
  });
75
79
  }
80
+ // ----------------------------------------
76
81
  const formattedData = data.map(obj => (0, pick_1.default)(obj, ...keys));
77
82
  const withValues = formattedData.map(obj => {
78
83
  const values = [];
@@ -92,6 +97,7 @@ const buildBatchUpdateQuery = (opts) => {
92
97
  return `(${values.toString()})`;
93
98
  });
94
99
  const withKeys = keys.map(key => (0, snakeCase_1.default)(String(key))).sort();
100
+ // ----------------------------------------
95
101
  const updateSets = [];
96
102
  for (const key of setKeys) {
97
103
  switch (typeof key) {
@@ -108,6 +114,7 @@ const buildBatchUpdateQuery = (opts) => {
108
114
  }
109
115
  }
110
116
  }
117
+ // ----------------------------------------
111
118
  const updateWheres = [];
112
119
  for (const key of whereKeys) {
113
120
  switch (typeof key) {
@@ -124,6 +131,7 @@ const buildBatchUpdateQuery = (opts) => {
124
131
  }
125
132
  }
126
133
  }
134
+ // ----------------------------------------
127
135
  return `WITH ${withAlias} (${withKeys}) AS (VALUES ${withValues})
128
136
  UPDATE "${tableName}"
129
137
  SET ${updateSets.join(', ')}
@@ -7,9 +7,10 @@ exports.getRequestRemark = exports.getRequestIp = exports.getRequestId = exports
7
7
  const rest_1 = require("@loopback/rest");
8
8
  const get_1 = __importDefault(require("lodash/get"));
9
9
  const multer_1 = __importDefault(require("multer"));
10
+ // -------------------------------------------------------------------------
10
11
  const parseMultipartBody = (opts) => {
11
12
  const { storage: cStorage, request, response } = opts;
12
- const storage = cStorage ?? multer_1.default.memoryStorage();
13
+ const storage = cStorage !== null && cStorage !== void 0 ? cStorage : multer_1.default.memoryStorage();
13
14
  const upload = (0, multer_1.default)({ storage });
14
15
  return new Promise((resolve, reject) => {
15
16
  upload.any()(request, response, (err) => {
@@ -22,18 +23,23 @@ const parseMultipartBody = (opts) => {
22
23
  });
23
24
  };
24
25
  exports.parseMultipartBody = parseMultipartBody;
26
+ // -------------------------------------------------------------------------
25
27
  const getSchemaObject = (ctor) => {
26
28
  return ctor ? (0, rest_1.getModelSchemaRef)(ctor).definitions[ctor.name] : {};
27
29
  };
28
30
  exports.getSchemaObject = getSchemaObject;
31
+ // -------------------------------------------------------------------------
29
32
  const getRequestId = (opts) => {
30
33
  return (0, get_1.default)(opts.request, 'requestId');
31
34
  };
32
35
  exports.getRequestId = getRequestId;
36
+ // -------------------------------------------------------------------------
33
37
  const getRequestIp = (opts) => {
34
- return (0, get_1.default)(opts.request, 'requestForwardedIp') ?? 'N/A';
38
+ var _a;
39
+ return (_a = (0, get_1.default)(opts.request, 'requestForwardedIp')) !== null && _a !== void 0 ? _a : 'N/A';
35
40
  };
36
41
  exports.getRequestIp = getRequestIp;
42
+ // -------------------------------------------------------------------------
37
43
  const getRequestRemark = (opts) => {
38
44
  return (0, get_1.default)(opts.request, 'requestedRemark');
39
45
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@minimaltech/node-infra",
3
- "version": "0.5.9-22",
3
+ "version": "0.5.9-24",
4
4
  "description": "Minimal Technology - NodeJS Infrastructure - Loopback 4 Framework",
5
5
  "keywords": [
6
6
  "web",
@@ -141,13 +141,12 @@
141
141
  "@types/multer": "^2.0.0",
142
142
  "@types/node": "^24.7.2",
143
143
  "eslint": "^9.36.0",
144
- "mocha": "^11.7.2",
145
144
  "prettier": "^3.6.2",
146
145
  "source-map-support": "^0.5.21",
147
146
  "ts-node": "^10.9.2",
148
147
  "tsc-alias": "^1.8.16",
149
148
  "tsconfig-paths": "^4.2.0",
150
- "typescript": "^5.9.3"
149
+ "typescript": "~5.9.3"
151
150
  },
152
151
  "sideEffects": false,
153
152
  "scripts": {