@sdflc/backend-helpers 1.0.78 → 1.0.80

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 (123) hide show
  1. package/build/BaseCore.js +496 -603
  2. package/build/BaseGateway.js +331 -379
  3. package/build/DataCache.js +16 -19
  4. package/build/Database.js +55 -74
  5. package/build/DbMigratorAndSeeder.js +88 -114
  6. package/build/RedisDataLoader.js +153 -189
  7. package/build/apiContext.js +35 -33
  8. package/build/baseController.js +9 -16
  9. package/build/commonValidators.js +22 -37
  10. package/build/configBulder.js +5 -1
  11. package/build/dbHelpers.js +19 -29
  12. package/build/dbSeeder.js +11 -20
  13. package/build/dbTableHelpers.js +10 -10
  14. package/build/downloadHelpers.js +15 -25
  15. package/build/esm/BaseCore.d.ts +88 -0
  16. package/build/esm/BaseCore.js +706 -0
  17. package/build/esm/BaseGateway.d.ts +49 -0
  18. package/build/esm/BaseGateway.js +430 -0
  19. package/build/esm/DataCache.d.ts +14 -0
  20. package/build/esm/DataCache.js +95 -0
  21. package/build/esm/Database.d.ts +32 -0
  22. package/build/esm/Database.js +173 -0
  23. package/build/esm/DbMigratorAndSeeder.d.ts +49 -0
  24. package/build/esm/DbMigratorAndSeeder.js +173 -0
  25. package/build/esm/RedisDataLoader.d.ts +41 -0
  26. package/build/esm/RedisDataLoader.js +206 -0
  27. package/build/esm/apiContext.d.ts +11 -0
  28. package/build/esm/apiContext.js +137 -0
  29. package/build/esm/baseController.d.ts +17 -0
  30. package/build/esm/baseController.js +53 -0
  31. package/build/esm/checkItHelpers.d.ts +3 -0
  32. package/build/esm/checkItHelpers.js +23 -0
  33. package/build/esm/commonValidators.d.ts +17 -0
  34. package/build/esm/commonValidators.js +264 -0
  35. package/build/esm/configBulder.d.ts +2 -0
  36. package/build/esm/configBulder.js +32 -0
  37. package/build/esm/constants.d.ts +30 -0
  38. package/build/esm/constants.js +69 -0
  39. package/build/esm/dbHelpers.d.ts +43 -0
  40. package/build/esm/dbHelpers.js +144 -0
  41. package/build/esm/dbSeeder.d.ts +2 -0
  42. package/build/esm/dbSeeder.js +44 -0
  43. package/build/esm/dbTableHelpers.d.ts +11 -0
  44. package/build/esm/dbTableHelpers.js +99 -0
  45. package/build/esm/downloadHelpers.d.ts +2 -0
  46. package/build/esm/downloadHelpers.js +66 -0
  47. package/build/esm/index.d.ts +21 -0
  48. package/build/esm/index.js +21 -0
  49. package/build/esm/interfaces/ApiContext.d.ts +24 -0
  50. package/build/esm/interfaces/ApiContext.js +1 -0
  51. package/build/esm/interfaces/ApiContextInterface.d.ts +12 -0
  52. package/build/esm/interfaces/ApiContextInterface.js +1 -0
  53. package/build/esm/interfaces/BaseCoreActionsInterface.d.ts +38 -0
  54. package/build/esm/interfaces/BaseCoreActionsInterface.js +1 -0
  55. package/build/esm/interfaces/BaseCoreDoAuthOnActionInterface.d.ts +12 -0
  56. package/build/esm/interfaces/BaseCoreDoAuthOnActionInterface.js +1 -0
  57. package/build/esm/interfaces/BaseCoreDoingWhatInterface.d.ts +13 -0
  58. package/build/esm/interfaces/BaseCoreDoingWhatInterface.js +1 -0
  59. package/build/esm/interfaces/BaseCorePropsInterface.d.ts +36 -0
  60. package/build/esm/interfaces/BaseCorePropsInterface.js +1 -0
  61. package/build/esm/interfaces/BaseCoreValidatorsInterface.d.ts +13 -0
  62. package/build/esm/interfaces/BaseCoreValidatorsInterface.js +1 -0
  63. package/build/esm/interfaces/BaseGatewayPropsInterface.d.ts +39 -0
  64. package/build/esm/interfaces/BaseGatewayPropsInterface.js +1 -0
  65. package/build/esm/interfaces/BuildConfigOptions.d.ts +6 -0
  66. package/build/esm/interfaces/BuildConfigOptions.js +1 -0
  67. package/build/esm/interfaces/BuildDefaultResolversOptions.d.ts +17 -0
  68. package/build/esm/interfaces/BuildDefaultResolversOptions.js +1 -0
  69. package/build/esm/interfaces/BuildListQueryArgsInterface.d.ts +6 -0
  70. package/build/esm/interfaces/BuildListQueryArgsInterface.js +1 -0
  71. package/build/esm/interfaces/CacheInterface.d.ts +15 -0
  72. package/build/esm/interfaces/CacheInterface.js +1 -0
  73. package/build/esm/interfaces/CommonValidatorArgs.d.ts +3 -0
  74. package/build/esm/interfaces/CommonValidatorArgs.js +1 -0
  75. package/build/esm/interfaces/CoreActionInterface.d.ts +14 -0
  76. package/build/esm/interfaces/CoreActionInterface.js +1 -0
  77. package/build/esm/interfaces/CreateUserTokenArgs.d.ts +11 -0
  78. package/build/esm/interfaces/CreateUserTokenArgs.js +1 -0
  79. package/build/esm/interfaces/CreateUserTokenResult.d.ts +4 -0
  80. package/build/esm/interfaces/CreateUserTokenResult.js +1 -0
  81. package/build/esm/interfaces/DatabaseOptions.d.ts +22 -0
  82. package/build/esm/interfaces/DatabaseOptions.js +1 -0
  83. package/build/esm/interfaces/DatabaseReadInterface.d.ts +14 -0
  84. package/build/esm/interfaces/DatabaseReadInterface.js +1 -0
  85. package/build/esm/interfaces/DbFieldAddDefaultInterface.d.ts +9 -0
  86. package/build/esm/interfaces/DbFieldAddDefaultInterface.js +1 -0
  87. package/build/esm/interfaces/DownloadFileArgs.d.ts +6 -0
  88. package/build/esm/interfaces/DownloadFileArgs.js +1 -0
  89. package/build/esm/interfaces/ExtractCredentialsArgs.d.ts +19 -0
  90. package/build/esm/interfaces/ExtractCredentialsArgs.js +1 -0
  91. package/build/esm/interfaces/JwtTokenSecretAndSettings.d.ts +5 -0
  92. package/build/esm/interfaces/JwtTokenSecretAndSettings.js +1 -0
  93. package/build/esm/interfaces/ListArgsInterface.d.ts +5 -0
  94. package/build/esm/interfaces/ListArgsInterface.js +1 -0
  95. package/build/esm/interfaces/LoaderInterface.d.ts +4 -0
  96. package/build/esm/interfaces/LoaderInterface.js +1 -0
  97. package/build/esm/interfaces/PaginationInterface.d.ts +7 -0
  98. package/build/esm/interfaces/PaginationInterface.js +1 -0
  99. package/build/esm/interfaces/SortItemInterface.d.ts +4 -0
  100. package/build/esm/interfaces/SortItemInterface.js +1 -0
  101. package/build/esm/interfaces/UserTokenParams.d.ts +8 -0
  102. package/build/esm/interfaces/UserTokenParams.js +1 -0
  103. package/build/esm/interfaces/VerifyUserTokenArgs.d.ts +13 -0
  104. package/build/esm/interfaces/VerifyUserTokenArgs.js +1 -0
  105. package/build/esm/interfaces/index.d.ts +28 -0
  106. package/build/esm/interfaces/index.js +27 -0
  107. package/build/esm/knexConfigBuilder.d.ts +1 -0
  108. package/build/esm/knexConfigBuilder.js +83 -0
  109. package/build/esm/passwordHelpers.d.ts +5 -0
  110. package/build/esm/passwordHelpers.js +13 -0
  111. package/build/esm/redisClient.d.ts +17 -0
  112. package/build/esm/redisClient.js +94 -0
  113. package/build/esm/resolversHelpers.d.ts +3 -0
  114. package/build/esm/resolversHelpers.js +66 -0
  115. package/build/esm/userToken.d.ts +8 -0
  116. package/build/esm/userToken.js +74 -0
  117. package/build/esm/utils.d.ts +2 -0
  118. package/build/esm/utils.js +13 -0
  119. package/build/knexConfigBuilder.js +17 -7
  120. package/build/passwordHelpers.js +7 -16
  121. package/build/resolversHelpers.js +11 -4
  122. package/build/userToken.js +2 -2
  123. package/package.json +13 -6
@@ -1,13 +1,4 @@
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
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -22,25 +13,27 @@ const DataCache_1 = require("./DataCache");
22
13
  const constants_1 = require("./constants");
23
14
  const DEFAULT_CHUNCK_SIZE = 2500;
24
15
  class BaseGateway {
16
+ config;
17
+ logger;
18
+ loader;
19
+ dateTime = new utils_1.DateTimeHelpers();
20
+ dateTimeNow = new Date();
25
21
  constructor(props) {
26
- var _a, _b, _c;
27
- this.dateTime = new utils_1.DateTimeHelpers();
28
- this.dateTimeNow = new Date();
29
22
  this.config = props;
30
23
  this.config.returnFields =
31
24
  Array.isArray(this.config.returnFields) && this.config.returnFields.length > 0 ? this.config.returnFields : ['*'];
32
25
  this.config.activeStatuses = Array.isArray(this.config.activeStatuses)
33
26
  ? this.config.activeStatuses
34
27
  : [utils_1.STATUSES.ACTIVE];
35
- this.config.keyPrefix = ((_a = this.config.context) === null || _a === void 0 ? void 0 : _a.keyPrefix) || this.config.keyPrefix || this.config.table;
36
- if (this.config.keyPrefix && ((_b = this.config.context) === null || _b === void 0 ? void 0 : _b.usedKeyPrefixes)) {
28
+ this.config.keyPrefix = this.config.context?.keyPrefix || this.config.keyPrefix || this.config.table;
29
+ if (this.config.keyPrefix && this.config.context?.usedKeyPrefixes) {
37
30
  if (this.config.context.usedKeyPrefixes[this.config.keyPrefix]) {
38
31
  throw new Error(`The "${this.config.keyPrefix}" is already used as the "keyPrefix" in the application. Please use another one that is not as: ${Object.keys(this.config.context.usedKeyPrefixes).join(', ')}`);
39
32
  }
40
33
  this.config.context.usedKeyPrefixes[this.config.keyPrefix] = true;
41
34
  }
42
- this.logger = (props === null || props === void 0 ? void 0 : props.logger) instanceof utils_1.Logger ? props.logger : new utils_1.Logger({ level: utils_1.LoggerLevels.WARNING });
43
- this.loader = check_types_1.default.function((_c = this.config) === null || _c === void 0 ? void 0 : _c.loader) ? this.config.loader : new DataCache_1.DataCache(this.config);
35
+ this.logger = props?.logger instanceof utils_1.Logger ? props.logger : new utils_1.Logger({ level: utils_1.LoggerLevels.WARNING });
36
+ this.loader = check_types_1.default.function(this.config?.loader) ? this.config.loader : new DataCache_1.DataCache(this.config);
44
37
  }
45
38
  getConfig() {
46
39
  return this.config;
@@ -54,217 +47,201 @@ class BaseGateway {
54
47
  return this;
55
48
  }
56
49
  setLoaderConfig(config) {
57
- this.loader = new DataCache_1.DataCache(Object.assign(Object.assign({}, this.config), config));
50
+ this.loader = new DataCache_1.DataCache({ ...this.config, ...config });
58
51
  return this;
59
52
  }
60
- // eslint-disable-next-line
61
- generateId(args) {
62
- return __awaiter(this, void 0, void 0, function* () {
63
- return (0, uuid_1.v4)();
64
- });
53
+ async generateId(args) {
54
+ return (0, uuid_1.v4)();
65
55
  }
66
- onListFilter(query, filterParams) {
67
- return __awaiter(this, void 0, void 0, function* () {
68
- const { table, hasStatus, hasRemovedAt, hasSpace, activeStatuses, hasLang, fieldForKeyword, filterByUserField } = this.config || {};
69
- // This function should be overriden
70
- if (hasStatus) {
71
- query.whereIn(`${table}.${constants_1.FIELDS.STATUS}`, Array.isArray(filterParams === null || filterParams === void 0 ? void 0 : filterParams[constants_1.FIELDS.STATUS]) ? filterParams === null || filterParams === void 0 ? void 0 : filterParams[constants_1.FIELDS.STATUS] : (0, lodash_1.castArray)(activeStatuses));
72
- }
73
- if (hasRemovedAt) {
74
- query.whereNull(`${table}.${constants_1.FIELDS.REMOVED_AT}`);
75
- }
76
- if (hasSpace && ((filterParams === null || filterParams === void 0 ? void 0 : filterParams[constants_1.FIELDS.SPACE_ID]) != undefined || this.config.context.spaceId)) {
77
- query.where({
78
- [`${table}.${constants_1.FIELDS.SPACE_ID}`]: (filterParams === null || filterParams === void 0 ? void 0 : filterParams[constants_1.FIELDS.SPACE_ID]) != undefined ? filterParams === null || filterParams === void 0 ? void 0 : filterParams[constants_1.FIELDS.SPACE_ID] : this.config.context.spaceId,
79
- });
80
- }
81
- if (hasLang && (filterParams === null || filterParams === void 0 ? void 0 : filterParams[constants_1.FIELDS.LANG]) != undefined) {
82
- query.whereIn(`${table}.${constants_1.FIELDS.LANG}`, (0, lodash_1.castArray)(filterParams === null || filterParams === void 0 ? void 0 : filterParams[constants_1.FIELDS.LANG]));
83
- }
84
- const idField = this.getIdField();
85
- if (filterParams === null || filterParams === void 0 ? void 0 : filterParams[idField]) {
86
- query.whereIn(idField.includes('.') ? `${idField}` : `${table}.${idField}`, (0, lodash_1.castArray)(filterParams === null || filterParams === void 0 ? void 0 : filterParams[idField]));
87
- }
88
- if (fieldForKeyword && filterParams.keyword) {
89
- query.whereRaw(`${fieldForKeyword} ILIKE ?`, `%${filterParams.keyword}%`);
90
- }
91
- if (filterByUserField) {
92
- query.where({ [filterByUserField]: this.getContext().userId });
93
- }
94
- // TODO: prse filterParams and buils where clause automatically here
95
- });
56
+ async onListFilter(query, filterParams) {
57
+ const { table, hasStatus, hasRemovedAt, hasSpace, activeStatuses, hasLang, fieldForKeyword, filterByUserField } = this.config || {};
58
+ // This function should be overriden
59
+ if (hasStatus) {
60
+ query.whereIn(`${table}.${constants_1.FIELDS.STATUS}`, Array.isArray(filterParams?.[constants_1.FIELDS.STATUS]) ? filterParams?.[constants_1.FIELDS.STATUS] : (0, lodash_1.castArray)(activeStatuses));
61
+ }
62
+ if (hasRemovedAt) {
63
+ query.whereNull(`${table}.${constants_1.FIELDS.REMOVED_AT}`);
64
+ }
65
+ if (hasSpace && (filterParams?.[constants_1.FIELDS.SPACE_ID] != undefined || this.config.context.spaceId)) {
66
+ query.where({
67
+ [`${table}.${constants_1.FIELDS.SPACE_ID}`]: filterParams?.[constants_1.FIELDS.SPACE_ID] != undefined ? filterParams?.[constants_1.FIELDS.SPACE_ID] : this.config.context.spaceId,
68
+ });
69
+ }
70
+ if (hasLang && filterParams?.[constants_1.FIELDS.LANG] != undefined) {
71
+ query.whereIn(`${table}.${constants_1.FIELDS.LANG}`, (0, lodash_1.castArray)(filterParams?.[constants_1.FIELDS.LANG]));
72
+ }
73
+ const idField = this.getIdField();
74
+ if (filterParams?.[idField]) {
75
+ query.whereIn(idField.includes('.') ? `${idField}` : `${table}.${idField}`, (0, lodash_1.castArray)(filterParams?.[idField]));
76
+ }
77
+ if (fieldForKeyword && filterParams.keyword) {
78
+ query.whereRaw(`${fieldForKeyword} ILIKE ?`, `%${filterParams.keyword}%`);
79
+ }
80
+ if (filterByUserField) {
81
+ query.where({ [filterByUserField]: this.getContext().userId });
82
+ }
83
+ // TODO: prse filterParams and buils where clause automatically here
96
84
  }
97
- onUpdateFilter(query, filterParams) {
98
- return __awaiter(this, void 0, void 0, function* () {
99
- // This function should be overriden
100
- const { hasStatus, hasVersion } = this.config;
101
- const idName = this.getIdFieldUpdateRemove();
102
- let filtersAppliedQty = 0;
103
- if (filterParams[idName]) {
104
- filtersAppliedQty++;
105
- query.whereIn(idName, (0, lodash_1.castArray)(filterParams[idName]));
106
- }
107
- if (hasVersion) {
108
- if (filterParams[constants_1.FIELDS.VERSION] != null && !isNaN(filterParams[constants_1.FIELDS.VERSION])) {
109
- filtersAppliedQty++;
110
- query.where({ [constants_1.FIELDS.VERSION]: filterParams[constants_1.FIELDS.VERSION] });
111
- }
112
- }
113
- if (hasStatus) {
85
+ async onUpdateFilter(query, filterParams) {
86
+ // This function should be overriden
87
+ const { hasStatus, hasVersion } = this.config;
88
+ const idName = this.getIdFieldUpdateRemove();
89
+ let filtersAppliedQty = 0;
90
+ if (filterParams[idName]) {
91
+ filtersAppliedQty++;
92
+ query.whereIn(idName, (0, lodash_1.castArray)(filterParams[idName]));
93
+ }
94
+ if (hasVersion) {
95
+ if (filterParams[constants_1.FIELDS.VERSION] != null && !isNaN(filterParams[constants_1.FIELDS.VERSION])) {
114
96
  filtersAppliedQty++;
115
- if (Array.isArray(filterParams === null || filterParams === void 0 ? void 0 : filterParams[constants_1.FIELDS.STATUS])) {
116
- query.whereIn(constants_1.FIELDS.STATUS, filterParams === null || filterParams === void 0 ? void 0 : filterParams[constants_1.FIELDS.STATUS]);
117
- }
118
- else {
119
- query.where(constants_1.FIELDS.STATUS, '!=', utils_1.STATUSES.REMOVED);
120
- }
97
+ query.where({ [constants_1.FIELDS.VERSION]: filterParams[constants_1.FIELDS.VERSION] });
121
98
  }
122
- return filtersAppliedQty;
123
- });
124
- }
125
- onRemoveFilter(query, filterParams) {
126
- return __awaiter(this, void 0, void 0, function* () {
127
- // This function should be overriden
128
- const { hasStatus } = this.config;
129
- const arr = filterParams ? (0, lodash_1.castArray)(filterParams) : [];
130
- let filtersAppliedQty = 1;
131
- if (arr.length > 0) {
132
- filtersAppliedQty++;
133
- const idName = this.getIdFieldUpdateRemove();
134
- query = query.whereIn(idName, arr.map((item) => item[idName]));
99
+ }
100
+ if (hasStatus) {
101
+ filtersAppliedQty++;
102
+ if (Array.isArray(filterParams?.[constants_1.FIELDS.STATUS])) {
103
+ query.whereIn(constants_1.FIELDS.STATUS, filterParams?.[constants_1.FIELDS.STATUS]);
135
104
  }
136
- if (hasStatus === true) {
137
- filtersAppliedQty++;
105
+ else {
138
106
  query.where(constants_1.FIELDS.STATUS, '!=', utils_1.STATUSES.REMOVED);
139
107
  }
140
- return filtersAppliedQty;
141
- });
108
+ }
109
+ return filtersAppliedQty;
142
110
  }
143
- transformOnCreate(params) {
144
- return __awaiter(this, void 0, void 0, function* () {
145
- const { hasCreatedAt, hasCreatedBy, hasSpace, hasVersion, hasLang, localizationForField, hasUserId } = this.config;
146
- if (hasCreatedAt) {
147
- params[(0, lodash_1.camelCase)(constants_1.FIELDS.CREATED_AT)] = this.dateTime.dbFormat(this.dateTimeNow);
148
- }
149
- if (hasCreatedBy) {
150
- const createdBy = (0, lodash_1.camelCase)(constants_1.FIELDS.CREATED_BY);
151
- if (params[createdBy] === undefined) {
152
- params[createdBy] = this.getContext().userId;
153
- }
154
- }
155
- if (hasUserId) {
156
- const userId = (0, lodash_1.camelCase)(constants_1.FIELDS.USER_ID);
157
- if (params[userId] === undefined) {
158
- params[userId] = this.getContext().userId;
159
- }
160
- }
161
- if (hasSpace) {
162
- params[(0, lodash_1.camelCase)(constants_1.FIELDS.SPACE_ID)] = this.getContext().spaceId;
163
- }
164
- if (hasVersion) {
165
- params[(0, lodash_1.camelCase)(constants_1.FIELDS.VERSION)] = 0;
166
- }
167
- if (hasLang && localizationForField) {
168
- params[this.getIdField()] = (0, utils_1.buildKey)([params[(0, lodash_1.camelCase)(localizationForField)], params[(0, lodash_1.camelCase)(constants_1.FIELDS.LANG)]]);
169
- }
170
- return params;
171
- });
111
+ async onRemoveFilter(query, filterParams) {
112
+ // This function should be overriden
113
+ const { hasStatus } = this.config;
114
+ const arr = filterParams ? (0, lodash_1.castArray)(filterParams) : [];
115
+ let filtersAppliedQty = 1;
116
+ if (arr.length > 0) {
117
+ filtersAppliedQty++;
118
+ const idName = this.getIdFieldUpdateRemove();
119
+ query = query.whereIn(idName, arr.map((item) => item[idName]));
120
+ }
121
+ if (hasStatus === true) {
122
+ filtersAppliedQty++;
123
+ query.where(constants_1.FIELDS.STATUS, '!=', utils_1.STATUSES.REMOVED);
124
+ }
125
+ return filtersAppliedQty;
172
126
  }
173
- // eslint-disable-next-line
174
- transformOnUpdate(params, where) {
175
- return __awaiter(this, void 0, void 0, function* () {
176
- const { hasUpdatedAt, hasUpdatedBy, hasVersion, hasLang, localizationForField } = this.config;
177
- if (hasUpdatedAt) {
178
- params[(0, lodash_1.camelCase)(constants_1.FIELDS.UPDATED_AT)] = this.dateTime.dbFormat(this.dateTimeNow);
179
- }
180
- if (hasUpdatedBy) {
181
- const updatedBy = (0, lodash_1.camelCase)(constants_1.FIELDS.UPDATED_BY);
182
- if (params[updatedBy] === undefined) {
183
- params[updatedBy] = this.getContext().userId;
184
- }
185
- }
186
- if (hasVersion) {
187
- const version = (0, lodash_1.camelCase)(constants_1.FIELDS.VERSION);
188
- if (params[version] != null && !isNaN(params[version])) {
189
- params[version] = params[version] + 1;
190
- }
127
+ async transformOnCreate(params) {
128
+ const { hasCreatedAt, hasCreatedBy, hasSpace, hasVersion, hasLang, localizationForField, hasUserId } = this.config;
129
+ if (hasCreatedAt) {
130
+ params[(0, lodash_1.camelCase)(constants_1.FIELDS.CREATED_AT)] = this.dateTime.dbFormat(this.dateTimeNow);
131
+ }
132
+ if (hasCreatedBy) {
133
+ const createdBy = (0, lodash_1.camelCase)(constants_1.FIELDS.CREATED_BY);
134
+ if (params[createdBy] === undefined) {
135
+ params[createdBy] = this.getContext().userId;
191
136
  }
192
- if (hasLang && localizationForField) {
193
- params[this.getIdField()] = (0, utils_1.buildKey)([params[(0, lodash_1.camelCase)(localizationForField)], params[(0, lodash_1.camelCase)(constants_1.FIELDS.LANG)]]);
137
+ }
138
+ if (hasUserId) {
139
+ const userId = (0, lodash_1.camelCase)(constants_1.FIELDS.USER_ID);
140
+ if (params[userId] === undefined) {
141
+ params[userId] = this.getContext().userId;
194
142
  }
195
- return params;
196
- });
143
+ }
144
+ if (hasSpace) {
145
+ params[(0, lodash_1.camelCase)(constants_1.FIELDS.SPACE_ID)] = this.getContext().spaceId;
146
+ }
147
+ if (hasVersion) {
148
+ params[(0, lodash_1.camelCase)(constants_1.FIELDS.VERSION)] = 0;
149
+ }
150
+ if (hasLang && localizationForField) {
151
+ params[this.getIdField()] = (0, utils_1.buildKey)([params[(0, lodash_1.camelCase)(localizationForField)], params[(0, lodash_1.camelCase)(constants_1.FIELDS.LANG)]]);
152
+ }
153
+ return params;
197
154
  }
198
- transformOnSet(params) {
199
- return __awaiter(this, void 0, void 0, function* () {
200
- const { hasCreatedAt, hasCreatedBy, hasSpace, hasUpdatedAt, hasUpdatedBy, hasVersion, hasLang, localizationForField, hasUserId, } = this.config;
201
- if (hasCreatedAt) {
202
- params[(0, lodash_1.camelCase)(constants_1.FIELDS.CREATED_AT)] = this.dateTime.dbFormat(this.dateTimeNow);
203
- }
204
- if (hasCreatedBy) {
205
- const createdBy = (0, lodash_1.camelCase)(constants_1.FIELDS.CREATED_BY);
206
- if (params[createdBy] === undefined) {
207
- params[createdBy] = this.getContext().userId;
208
- }
155
+ async transformOnUpdate(params, where) {
156
+ const { hasUpdatedAt, hasUpdatedBy, hasVersion, hasLang, localizationForField } = this.config;
157
+ if (hasUpdatedAt) {
158
+ params[(0, lodash_1.camelCase)(constants_1.FIELDS.UPDATED_AT)] = this.dateTime.dbFormat(this.dateTimeNow);
159
+ }
160
+ if (hasUpdatedBy) {
161
+ const updatedBy = (0, lodash_1.camelCase)(constants_1.FIELDS.UPDATED_BY);
162
+ if (params[updatedBy] === undefined) {
163
+ params[updatedBy] = this.getContext().userId;
209
164
  }
210
- if (hasUserId) {
211
- const userId = (0, lodash_1.camelCase)(constants_1.FIELDS.USER_ID);
212
- if (params[userId] === undefined) {
213
- params[userId] = this.getContext().userId;
214
- }
165
+ }
166
+ if (hasVersion) {
167
+ const version = (0, lodash_1.camelCase)(constants_1.FIELDS.VERSION);
168
+ if (params[version] != null && !isNaN(params[version])) {
169
+ params[version] = params[version] + 1;
215
170
  }
216
- if (hasSpace) {
217
- params[(0, lodash_1.camelCase)(constants_1.FIELDS.SPACE_ID)] = this.getContext().spaceId;
171
+ }
172
+ if (hasLang && localizationForField) {
173
+ params[this.getIdField()] = (0, utils_1.buildKey)([params[(0, lodash_1.camelCase)(localizationForField)], params[(0, lodash_1.camelCase)(constants_1.FIELDS.LANG)]]);
174
+ }
175
+ return params;
176
+ }
177
+ async transformOnSet(params) {
178
+ const { hasCreatedAt, hasCreatedBy, hasSpace, hasUpdatedAt, hasUpdatedBy, hasVersion, hasLang, localizationForField, hasUserId, } = this.config;
179
+ if (hasCreatedAt) {
180
+ params[(0, lodash_1.camelCase)(constants_1.FIELDS.CREATED_AT)] = this.dateTime.dbFormat(this.dateTimeNow);
181
+ }
182
+ if (hasCreatedBy) {
183
+ const createdBy = (0, lodash_1.camelCase)(constants_1.FIELDS.CREATED_BY);
184
+ if (params[createdBy] === undefined) {
185
+ params[createdBy] = this.getContext().userId;
218
186
  }
219
- if (hasUpdatedAt) {
220
- params[(0, lodash_1.camelCase)(constants_1.FIELDS.UPDATED_AT)] = this.dateTime.dbFormat(this.dateTimeNow);
187
+ }
188
+ if (hasUserId) {
189
+ const userId = (0, lodash_1.camelCase)(constants_1.FIELDS.USER_ID);
190
+ if (params[userId] === undefined) {
191
+ params[userId] = this.getContext().userId;
221
192
  }
222
- if (hasUpdatedBy) {
223
- const updatedBy = (0, lodash_1.camelCase)(constants_1.FIELDS.UPDATED_BY);
224
- if (params[updatedBy] === undefined) {
225
- params[updatedBy] = this.getContext().userId;
226
- }
193
+ }
194
+ if (hasSpace) {
195
+ params[(0, lodash_1.camelCase)(constants_1.FIELDS.SPACE_ID)] = this.getContext().spaceId;
196
+ }
197
+ if (hasUpdatedAt) {
198
+ params[(0, lodash_1.camelCase)(constants_1.FIELDS.UPDATED_AT)] = this.dateTime.dbFormat(this.dateTimeNow);
199
+ }
200
+ if (hasUpdatedBy) {
201
+ const updatedBy = (0, lodash_1.camelCase)(constants_1.FIELDS.UPDATED_BY);
202
+ if (params[updatedBy] === undefined) {
203
+ params[updatedBy] = this.getContext().userId;
227
204
  }
228
- if (hasVersion) {
229
- const version = (0, lodash_1.camelCase)(constants_1.FIELDS.VERSION);
230
- if (params[version] != null && !isNaN(params[version])) {
231
- params[version] = params[version] + 1;
232
- }
233
- else {
234
- params[version] = 0;
235
- }
205
+ }
206
+ if (hasVersion) {
207
+ const version = (0, lodash_1.camelCase)(constants_1.FIELDS.VERSION);
208
+ if (params[version] != null && !isNaN(params[version])) {
209
+ params[version] = params[version] + 1;
236
210
  }
237
- if (hasLang && localizationForField) {
238
- params[this.getIdField()] = (0, utils_1.buildKey)([params[(0, lodash_1.camelCase)(localizationForField)], params[(0, lodash_1.camelCase)(constants_1.FIELDS.LANG)]]);
211
+ else {
212
+ params[version] = 0;
239
213
  }
240
- return params;
241
- });
214
+ }
215
+ if (hasLang && localizationForField) {
216
+ params[this.getIdField()] = (0, utils_1.buildKey)([params[(0, lodash_1.camelCase)(localizationForField)], params[(0, lodash_1.camelCase)(constants_1.FIELDS.LANG)]]);
217
+ }
218
+ return params;
242
219
  }
243
- transformOnRemove(args) {
244
- return __awaiter(this, void 0, void 0, function* () {
245
- const { hasRemovedAt, hasRemovedAtStr, hasStatus, hasRemovedBy, hasLang, localizationForField } = this.config;
246
- const removalTime = (0, dayjs_1.default)();
247
- const removalTimeStr = removalTime.format('YYYYMMDDTHHmmssZ');
248
- const obj = Object.assign({}, (args || {}));
249
- if (hasRemovedAt) {
250
- obj[constants_1.FIELDS.REMOVED_AT] = removalTime.toDate();
251
- }
252
- if (hasRemovedAtStr === true) {
253
- obj[constants_1.FIELDS.REMOVED_AT_STR] = removalTimeStr;
254
- }
255
- if (hasStatus) {
256
- obj[constants_1.FIELDS.STATUS] = utils_1.STATUSES.REMOVED;
257
- }
258
- if (hasRemovedBy) {
259
- if (obj[constants_1.FIELDS.REMOVED_BY] === undefined) {
260
- obj[constants_1.FIELDS.REMOVED_BY] = this.getContext().userId;
261
- }
262
- }
263
- if (hasLang && localizationForField) {
264
- obj[this.getIdField()] = this.getDb().raw(`CONCAT(id, '-${removalTimeStr}')`);
220
+ async transformOnRemove(args) {
221
+ const { hasRemovedAt, hasRemovedAtStr, hasStatus, hasRemovedBy, hasLang, localizationForField } = this.config;
222
+ const removalTime = (0, dayjs_1.default)();
223
+ const removalTimeStr = removalTime.format('YYYYMMDDTHHmmssZ');
224
+ const obj = {
225
+ ...(args || {}),
226
+ };
227
+ if (hasRemovedAt) {
228
+ obj[constants_1.FIELDS.REMOVED_AT] = removalTime.toDate();
229
+ }
230
+ if (hasRemovedAtStr === true) {
231
+ obj[constants_1.FIELDS.REMOVED_AT_STR] = removalTimeStr;
232
+ }
233
+ if (hasStatus) {
234
+ obj[constants_1.FIELDS.STATUS] = utils_1.STATUSES.REMOVED;
235
+ }
236
+ if (hasRemovedBy) {
237
+ if (obj[constants_1.FIELDS.REMOVED_BY] === undefined) {
238
+ obj[constants_1.FIELDS.REMOVED_BY] = this.getContext().userId;
265
239
  }
266
- return obj;
267
- });
240
+ }
241
+ if (hasLang && localizationForField) {
242
+ obj[this.getIdField()] = this.getDb().raw(`CONCAT(id, '-${removalTimeStr}')`);
243
+ }
244
+ return obj;
268
245
  }
269
246
  getRequestId() {
270
247
  return this.config.context.requestId;
@@ -279,8 +256,7 @@ class BaseGateway {
279
256
  return this.config.db;
280
257
  }
281
258
  getBuilder() {
282
- var _a;
283
- return (_a = this.getDb()) === null || _a === void 0 ? void 0 : _a.getBuilder(this.config.table);
259
+ return this.getDb()?.getBuilder(this.config.table);
284
260
  }
285
261
  getIdField() {
286
262
  return this.config.idField || constants_1.ID_FIELD;
@@ -288,129 +264,110 @@ class BaseGateway {
288
264
  getIdFieldUpdateRemove() {
289
265
  return this.config.idFieldUpdateRemove || this.config.idField || constants_1.ID_FIELD;
290
266
  }
291
- get(id) {
292
- return __awaiter(this, void 0, void 0, function* () {
293
- return this.loader.load(id);
294
- });
267
+ async get(id) {
268
+ return this.loader.load(id);
295
269
  }
296
- getMany(ids) {
297
- return __awaiter(this, void 0, void 0, function* () {
298
- return this.loader.loadMany(ids);
299
- });
270
+ async getMany(ids) {
271
+ return this.loader.loadMany(ids);
300
272
  }
301
- buildListQuery(args) {
302
- return __awaiter(this, void 0, void 0, function* () {
303
- const { fieldsToUse } = args || {};
304
- const query = this.getBuilder();
305
- query.select(fieldsToUse);
306
- return { query };
307
- });
273
+ async buildListQuery(args) {
274
+ const { fieldsToUse } = args || {};
275
+ const query = this.getBuilder();
276
+ query.select(fieldsToUse);
277
+ return { query };
308
278
  }
309
- list(args) {
310
- return __awaiter(this, void 0, void 0, function* () {
311
- const { filter, params, useCache } = args || {};
312
- const { limit, offset, sortBy } = this.getDb().createLimitOffsetSortBy(params, this.config.defaultSorting || []);
313
- if (!this.config.table) {
314
- return [];
315
- }
316
- const shouldUseCache = useCache != null ? useCache : !this.config.noCache;
317
- const fieldsToUse = !shouldUseCache && Array.isArray(this.config.selectFields) ? this.config.selectFields : this.getIdField();
318
- const { query } = yield this.buildListQuery({ filter, params, fieldsToUse, useCache: shouldUseCache });
319
- yield this.onListFilter(query, filter);
320
- if (limit && !isNaN(limit) && limit > 0) {
321
- query.offset(offset).limit(limit);
322
- }
323
- if (sortBy) {
324
- query.orderBy(sortBy);
325
- }
326
- const items = yield query;
327
- const result = shouldUseCache ? yield this.getMany(items.map((row) => row.id)) : items;
328
- return result;
329
- });
279
+ async list(args) {
280
+ const { filter, params, useCache } = args || {};
281
+ const { limit, offset, sortBy } = this.getDb().createLimitOffsetSortBy(params, this.config.defaultSorting || []);
282
+ if (!this.config.table) {
283
+ return [];
284
+ }
285
+ const shouldUseCache = useCache != null ? useCache : !this.config.noCache;
286
+ const fieldsToUse = !shouldUseCache && Array.isArray(this.config.selectFields) ? this.config.selectFields : this.getIdField();
287
+ const { query } = await this.buildListQuery({ filter, params, fieldsToUse, useCache: shouldUseCache });
288
+ await this.onListFilter(query, filter);
289
+ if (limit && !isNaN(limit) && limit > 0) {
290
+ query.offset(offset).limit(limit);
291
+ }
292
+ if (sortBy) {
293
+ query.orderBy(sortBy);
294
+ }
295
+ const items = await query;
296
+ const result = shouldUseCache ? await this.getMany(items.map((row) => row.id)) : items;
297
+ return result;
330
298
  }
331
- create(args) {
332
- return __awaiter(this, void 0, void 0, function* () {
333
- var _a;
334
- const objects = (0, lodash_1.castArray)(args);
335
- if (!args || objects.length === 0) {
336
- return [];
337
- }
338
- for (let idx = 0, len = objects.length; idx < len; ++idx) {
339
- const object = objects[idx];
340
- const id = yield this.generateId(object);
341
- objects[idx] = yield this.transformOnCreate(Object.assign({ id }, object));
342
- //objects.push(obj);
343
- }
344
- const result = [];
345
- const chunks = (0, utils_1.arrToChunks)(objects, ((_a = this.config) === null || _a === void 0 ? void 0 : _a.insertChunkSize) || DEFAULT_CHUNCK_SIZE);
346
- for (let idx = 0, len = chunks.length; idx < len; ++idx) {
347
- const items = yield this.getBuilder().insert(chunks[idx]).returning(this.config.returnFields);
348
- result.push(...items);
349
- }
350
- return result;
351
- });
299
+ async create(args) {
300
+ const objects = (0, lodash_1.castArray)(args);
301
+ if (!args || objects.length === 0) {
302
+ return [];
303
+ }
304
+ for (let idx = 0, len = objects.length; idx < len; ++idx) {
305
+ const object = objects[idx];
306
+ const id = await this.generateId(object);
307
+ objects[idx] = await this.transformOnCreate({ id, ...object });
308
+ //objects.push(obj);
309
+ }
310
+ const result = [];
311
+ const chunks = (0, utils_1.arrToChunks)(objects, this.config?.insertChunkSize || DEFAULT_CHUNCK_SIZE);
312
+ for (let idx = 0, len = chunks.length; idx < len; ++idx) {
313
+ const items = await this.getBuilder().insert(chunks[idx]).returning(this.config.returnFields);
314
+ result.push(...items);
315
+ }
316
+ return result;
352
317
  }
353
- update(where, params) {
354
- return __awaiter(this, void 0, void 0, function* () {
355
- const object = yield this.transformOnUpdate(params, where);
356
- const query = this.getBuilder().update(object).returning(this.config.returnFields);
357
- const filtersAppliedQty = yield this.onUpdateFilter(query, where);
358
- if (filtersAppliedQty == null || filtersAppliedQty <= 0) {
359
- throw new Error(`Failed to update the table '${this.config.table}' as none of filters applied: ${JSON.stringify(where, null, 2)}`);
360
- }
361
- const items = yield query;
362
- if (items.length > 0 && this.config.noCache !== true) {
363
- items.forEach((item) => this.loader.clear(item[this.getIdField()]));
364
- }
365
- return items;
366
- });
318
+ async update(where, params) {
319
+ const object = await this.transformOnUpdate(params, where);
320
+ const query = this.getBuilder().update(object).returning(this.config.returnFields);
321
+ const filtersAppliedQty = await this.onUpdateFilter(query, where);
322
+ if (filtersAppliedQty == null || filtersAppliedQty <= 0) {
323
+ throw new Error(`Failed to update the table '${this.config.table}' as none of filters applied: ${JSON.stringify(where, null, 2)}`);
324
+ }
325
+ const items = await query;
326
+ if (items.length > 0 && this.config.noCache !== true) {
327
+ items.forEach((item) => this.loader.clear(item[this.getIdField()]));
328
+ }
329
+ return items;
367
330
  }
368
- updateMany(params) {
369
- return __awaiter(this, void 0, void 0, function* () {
370
- if (!Array.isArray(params)) {
371
- params = [params];
372
- }
373
- const results = [];
374
- for (let idx = 0, len = params.length; idx < len; ++idx) {
375
- const item = params[idx];
376
- const items = yield this.update(item.where, item.params);
377
- results.push(...items);
378
- }
379
- if (results.length > 0 && this.config.noCache !== true) {
380
- results.forEach((item) => this.loader.clear(item[this.getIdField()]));
381
- }
382
- return results;
383
- });
331
+ async updateMany(params) {
332
+ if (!Array.isArray(params)) {
333
+ params = [params];
334
+ }
335
+ const results = [];
336
+ for (let idx = 0, len = params.length; idx < len; ++idx) {
337
+ const item = params[idx];
338
+ const items = await this.update(item.where, item.params);
339
+ results.push(...items);
340
+ }
341
+ if (results.length > 0 && this.config.noCache !== true) {
342
+ results.forEach((item) => this.loader.clear(item[this.getIdField()]));
343
+ }
344
+ return results;
384
345
  }
385
- increment(where, params) {
386
- return __awaiter(this, void 0, void 0, function* () {
387
- const object = yield this.transformOnUpdate(params, where);
388
- const query = this.getBuilder().increment(object).returning(this.config.returnFields);
389
- const filtersAppliedQty = yield this.onUpdateFilter(query, where);
390
- if (filtersAppliedQty == null || filtersAppliedQty <= 0) {
391
- throw new Error(`Failed to update the table '${this.config.table}' as none of filters applied: ${JSON.stringify(where, null, 2)}`);
392
- }
393
- const items = yield query;
394
- if (items.length > 0 && this.config.noCache !== true) {
395
- items.forEach((item) => this.loader.clear(item[this.getIdField()]));
396
- }
397
- return items;
398
- });
346
+ async increment(where, params) {
347
+ const object = await this.transformOnUpdate(params, where);
348
+ const query = this.getBuilder().increment(object).returning(this.config.returnFields);
349
+ const filtersAppliedQty = await this.onUpdateFilter(query, where);
350
+ if (filtersAppliedQty == null || filtersAppliedQty <= 0) {
351
+ throw new Error(`Failed to update the table '${this.config.table}' as none of filters applied: ${JSON.stringify(where, null, 2)}`);
352
+ }
353
+ const items = await query;
354
+ if (items.length > 0 && this.config.noCache !== true) {
355
+ items.forEach((item) => this.loader.clear(item[this.getIdField()]));
356
+ }
357
+ return items;
399
358
  }
400
- decrement(where, params) {
401
- return __awaiter(this, void 0, void 0, function* () {
402
- const object = yield this.transformOnUpdate(params, where);
403
- const query = this.getBuilder().decrement(object).returning(this.config.returnFields);
404
- const filtersAppliedQty = yield this.onUpdateFilter(query, where);
405
- if (filtersAppliedQty == null || filtersAppliedQty <= 0) {
406
- throw new Error(`Failed to update the table '${this.config.table}' as none of filters applied: ${JSON.stringify(where, null, 2)}`);
407
- }
408
- const items = yield query;
409
- if (items.length > 0 && this.config.noCache !== true) {
410
- items.forEach((item) => this.loader.clear(item[this.getIdField()]));
411
- }
412
- return items;
413
- });
359
+ async decrement(where, params) {
360
+ const object = await this.transformOnUpdate(params, where);
361
+ const query = this.getBuilder().decrement(object).returning(this.config.returnFields);
362
+ const filtersAppliedQty = await this.onUpdateFilter(query, where);
363
+ if (filtersAppliedQty == null || filtersAppliedQty <= 0) {
364
+ throw new Error(`Failed to update the table '${this.config.table}' as none of filters applied: ${JSON.stringify(where, null, 2)}`);
365
+ }
366
+ const items = await query;
367
+ if (items.length > 0 && this.config.noCache !== true) {
368
+ items.forEach((item) => this.loader.clear(item[this.getIdField()]));
369
+ }
370
+ return items;
414
371
  }
415
372
  /**
416
373
  * Inserts or updates data in the database.
@@ -419,66 +376,61 @@ class BaseGateway {
419
376
  * @param params Array of objects to update or create
420
377
  * @returns Array of updated or inserted objects
421
378
  */
422
- set(params) {
423
- return __awaiter(this, void 0, void 0, function* () {
424
- var _a;
425
- const { hasCreatedAt, hasCreatedBy, hasSpace, mergeFields } = this.config || {};
426
- const objects = (0, lodash_1.castArray)(params);
427
- if (!params || objects.length === 0) {
428
- return [];
429
- }
430
- const skipFields = [];
431
- if (hasCreatedAt) {
432
- skipFields.push(constants_1.FIELDS.CREATED_AT);
433
- }
434
- if (hasCreatedBy) {
435
- skipFields.push(constants_1.FIELDS.CREATED_BY);
436
- }
437
- if (hasSpace) {
438
- skipFields.push(constants_1.FIELDS.SPACE_ID);
439
- }
440
- for (let idx = 0, len = objects.length; idx < len; ++idx) {
441
- const object = objects[idx];
442
- objects[idx] = yield this.transformOnSet(object);
443
- if (objects[idx][this.getIdField()] == null) {
444
- objects[idx][this.getIdField()] = yield this.generateId(object);
445
- }
446
- }
447
- const fields = Array.isArray(mergeFields) ? mergeFields : Object.keys(objects[0]);
448
- const result = [];
449
- const chunks = (0, utils_1.arrToChunks)(objects, ((_a = this.config) === null || _a === void 0 ? void 0 : _a.insertChunkSize) || DEFAULT_CHUNCK_SIZE);
450
- for (let idx = 0, len = chunks.length; idx < len; ++idx) {
451
- const items = yield this.getBuilder()
452
- .insert(chunks[idx])
453
- .returning(this.config.returnFields)
454
- .onConflict(this.config.setFields || this.getIdField())
455
- .merge((0, lodash_1.pullAll)(fields, skipFields));
456
- result.push(...items);
379
+ async set(params) {
380
+ const { hasCreatedAt, hasCreatedBy, hasSpace, mergeFields } = this.config || {};
381
+ const objects = (0, lodash_1.castArray)(params);
382
+ if (!params || objects.length === 0) {
383
+ return [];
384
+ }
385
+ const skipFields = [];
386
+ if (hasCreatedAt) {
387
+ skipFields.push(constants_1.FIELDS.CREATED_AT);
388
+ }
389
+ if (hasCreatedBy) {
390
+ skipFields.push(constants_1.FIELDS.CREATED_BY);
391
+ }
392
+ if (hasSpace) {
393
+ skipFields.push(constants_1.FIELDS.SPACE_ID);
394
+ }
395
+ for (let idx = 0, len = objects.length; idx < len; ++idx) {
396
+ const object = objects[idx];
397
+ objects[idx] = await this.transformOnSet(object);
398
+ if (objects[idx][this.getIdField()] == null) {
399
+ objects[idx][this.getIdField()] = await this.generateId(object);
457
400
  }
458
- return result;
459
- });
401
+ }
402
+ const fields = Array.isArray(mergeFields) ? mergeFields : Object.keys(objects[0]);
403
+ const result = [];
404
+ const chunks = (0, utils_1.arrToChunks)(objects, this.config?.insertChunkSize || DEFAULT_CHUNCK_SIZE);
405
+ for (let idx = 0, len = chunks.length; idx < len; ++idx) {
406
+ const items = await this.getBuilder()
407
+ .insert(chunks[idx])
408
+ .returning(this.config.returnFields)
409
+ .onConflict(this.config.setFields || this.getIdField())
410
+ .merge((0, lodash_1.pullAll)(fields, skipFields));
411
+ result.push(...items);
412
+ }
413
+ return result;
460
414
  }
461
- remove(where) {
462
- return __awaiter(this, void 0, void 0, function* () {
463
- const { hardRemove } = this.config || {};
464
- const query = this.getBuilder();
465
- if (hardRemove) {
466
- query.delete(this.config.returnFields);
467
- }
468
- else {
469
- const object = yield this.transformOnRemove();
470
- query.update(object).returning(this.config.returnFields);
471
- }
472
- const filtersAppliedQty = yield this.onRemoveFilter(query, where);
473
- if (filtersAppliedQty == null || filtersAppliedQty <= 0) {
474
- throw new Error(`Failed to remove records in the table '${this.config.table}' as none of filters applied: ${JSON.stringify(where, null, 2)}`);
475
- }
476
- const items = yield query;
477
- if (items.length > 0 && this.config.noCache !== true) {
478
- items.forEach((item) => this.loader.clear(item[this.getIdField()]));
479
- }
480
- return items;
481
- });
415
+ async remove(where) {
416
+ const { hardRemove } = this.config || {};
417
+ const query = this.getBuilder();
418
+ if (hardRemove) {
419
+ query.delete(this.config.returnFields);
420
+ }
421
+ else {
422
+ const object = await this.transformOnRemove();
423
+ query.update(object).returning(this.config.returnFields);
424
+ }
425
+ const filtersAppliedQty = await this.onRemoveFilter(query, where);
426
+ if (filtersAppliedQty == null || filtersAppliedQty <= 0) {
427
+ throw new Error(`Failed to remove records in the table '${this.config.table}' as none of filters applied: ${JSON.stringify(where, null, 2)}`);
428
+ }
429
+ const items = await query;
430
+ if (items.length > 0 && this.config.noCache !== true) {
431
+ items.forEach((item) => this.loader.clear(item[this.getIdField()]));
432
+ }
433
+ return items;
482
434
  }
483
435
  }
484
436
  exports.BaseGateway = BaseGateway;