@sdflc/backend-helpers 1.0.49 → 1.0.52

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.
@@ -1,15 +1,4 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -19,47 +8,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
19
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
20
9
  });
21
10
  };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (_) try {
29
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
50
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
51
13
  };
52
14
  Object.defineProperty(exports, "__esModule", { value: true });
53
15
  exports.BaseGateway = void 0;
54
- var uuid_1 = require("uuid");
55
- var dayjs_1 = __importDefault(require("dayjs"));
56
- var lodash_1 = require("lodash");
57
- var utils_1 = require("@sdflc/utils");
58
- var DataCache_1 = require("./DataCache");
59
- var constants_1 = require("./constants");
60
- var DEFAULT_CHUNCK_SIZE = 2500;
61
- var BaseGateway = /** @class */ (function () {
62
- function BaseGateway(props) {
16
+ const uuid_1 = require("uuid");
17
+ const dayjs_1 = __importDefault(require("dayjs"));
18
+ const lodash_1 = require("lodash");
19
+ const utils_1 = require("@sdflc/utils");
20
+ const DataCache_1 = require("./DataCache");
21
+ const constants_1 = require("./constants");
22
+ const DEFAULT_CHUNCK_SIZE = 2500;
23
+ class BaseGateway {
24
+ constructor(props) {
25
+ var _a, _b;
63
26
  this.dateTime = new utils_1.DateTimeHelpers();
64
27
  this.dateTimeNow = new Date();
65
28
  this.config = props;
@@ -68,460 +31,342 @@ var BaseGateway = /** @class */ (function () {
68
31
  this.config.activeStatuses = Array.isArray(this.config.activeStatuses)
69
32
  ? this.config.activeStatuses
70
33
  : [utils_1.STATUSES.ACTIVE];
34
+ this.config.keyPrefix = ((_a = this.config.context) === null || _a === void 0 ? void 0 : _a.keyPrefix) || this.config.keyPrefix || this.config.table;
35
+ if (this.config.keyPrefix && ((_b = this.config.context) === null || _b === void 0 ? void 0 : _b.usedKeyPrefixes)) {
36
+ if (this.config.context.usedKeyPrefixes[this.config.keyPrefix]) {
37
+ 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(', ')}`);
38
+ }
39
+ this.config.context.usedKeyPrefixes[this.config.keyPrefix] = true;
40
+ }
71
41
  this.loader = typeof this.config.loader === 'function' ? this.config.loader : new DataCache_1.DataCache(this.config);
72
42
  }
73
- BaseGateway.prototype.setConfigPart = function (props) {
43
+ setConfigPart(props) {
74
44
  Object.assign(this.config, props);
75
45
  return this;
76
- };
46
+ }
77
47
  // eslint-disable-next-line
78
- BaseGateway.prototype.generateId = function (args) {
79
- return __awaiter(this, void 0, void 0, function () {
80
- return __generator(this, function (_a) {
81
- return [2 /*return*/, (0, uuid_1.v4)()];
82
- });
48
+ generateId(args) {
49
+ return __awaiter(this, void 0, void 0, function* () {
50
+ return (0, uuid_1.v4)();
83
51
  });
84
- };
85
- BaseGateway.prototype.onListFilter = function (query, filterParams) {
86
- return __awaiter(this, void 0, void 0, function () {
87
- var _a, hasStatus, hasRemovedAt, hasSpace, activeStatuses, hasLang, fieldForKeyword, filterByUserField;
88
- var _b, _c;
89
- return __generator(this, function (_d) {
90
- _a = this.config || {}, hasStatus = _a.hasStatus, hasRemovedAt = _a.hasRemovedAt, hasSpace = _a.hasSpace, activeStatuses = _a.activeStatuses, hasLang = _a.hasLang, fieldForKeyword = _a.fieldForKeyword, filterByUserField = _a.filterByUserField;
91
- // This function should be overriden
92
- if (hasStatus) {
93
- query.whereIn(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));
94
- }
95
- if (hasRemovedAt) {
96
- query.whereNull(constants_1.FIELDS.REMOVED_AT);
97
- }
98
- if (hasSpace && ((filterParams === null || filterParams === void 0 ? void 0 : filterParams[constants_1.FIELDS.SPACE_ID]) != undefined || this.config.context.spaceId)) {
99
- query.where((_b = {},
100
- _b[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,
101
- _b));
102
- }
103
- if (hasLang && (filterParams === null || filterParams === void 0 ? void 0 : filterParams[constants_1.FIELDS.LANG]) != undefined) {
104
- query.whereIn(constants_1.FIELDS.LANG, (0, lodash_1.castArray)(filterParams === null || filterParams === void 0 ? void 0 : filterParams[constants_1.FIELDS.LANG]));
105
- }
106
- if (filterParams === null || filterParams === void 0 ? void 0 : filterParams[this.getIdField()]) {
107
- query.whereIn(constants_1.FIELDS.ID, (0, lodash_1.castArray)(filterParams === null || filterParams === void 0 ? void 0 : filterParams[this.getIdField()]));
108
- }
109
- if (fieldForKeyword && filterParams.keyword) {
110
- query.whereRaw("".concat(fieldForKeyword, " ILIKE ?"), "%".concat(filterParams.keyword, "%"));
111
- }
112
- if (filterByUserField) {
113
- query.where((_c = {}, _c[filterByUserField] = this.getContext().userId, _c));
114
- }
115
- return [2 /*return*/];
116
- });
52
+ }
53
+ onListFilter(query, filterParams) {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ const { hasStatus, hasRemovedAt, hasSpace, activeStatuses, hasLang, fieldForKeyword, filterByUserField } = this.config || {};
56
+ // This function should be overriden
57
+ if (hasStatus) {
58
+ query.whereIn(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));
59
+ }
60
+ if (hasRemovedAt) {
61
+ query.whereNull(constants_1.FIELDS.REMOVED_AT);
62
+ }
63
+ if (hasSpace && ((filterParams === null || filterParams === void 0 ? void 0 : filterParams[constants_1.FIELDS.SPACE_ID]) != undefined || this.config.context.spaceId)) {
64
+ query.where({
65
+ [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,
66
+ });
67
+ }
68
+ if (hasLang && (filterParams === null || filterParams === void 0 ? void 0 : filterParams[constants_1.FIELDS.LANG]) != undefined) {
69
+ query.whereIn(constants_1.FIELDS.LANG, (0, lodash_1.castArray)(filterParams === null || filterParams === void 0 ? void 0 : filterParams[constants_1.FIELDS.LANG]));
70
+ }
71
+ if (filterParams === null || filterParams === void 0 ? void 0 : filterParams[this.getIdField()]) {
72
+ query.whereIn(constants_1.FIELDS.ID, (0, lodash_1.castArray)(filterParams === null || filterParams === void 0 ? void 0 : filterParams[this.getIdField()]));
73
+ }
74
+ if (fieldForKeyword && filterParams.keyword) {
75
+ query.whereRaw(`${fieldForKeyword} ILIKE ?`, `%${filterParams.keyword}%`);
76
+ }
77
+ if (filterByUserField) {
78
+ query.where({ [filterByUserField]: this.getContext().userId });
79
+ }
80
+ // TODO: prse filterParams and buils where clause automatically here
117
81
  });
118
- };
119
- BaseGateway.prototype.onUpdateFilter = function (query, filterParams) {
120
- return __awaiter(this, void 0, void 0, function () {
121
- var _a, hasStatus, hasVersion, idName;
122
- var _b;
123
- return __generator(this, function (_c) {
124
- _a = this.config, hasStatus = _a.hasStatus, hasVersion = _a.hasVersion;
125
- idName = this.getIdField();
126
- if (filterParams[idName]) {
127
- query.where(idName, filterParams[idName]);
128
- }
129
- if (hasVersion) {
130
- if (filterParams[constants_1.FIELDS.VERSION] != null && !isNaN(filterParams[constants_1.FIELDS.VERSION])) {
131
- query.where((_b = {}, _b[constants_1.FIELDS.VERSION] = filterParams[constants_1.FIELDS.VERSION], _b));
132
- }
82
+ }
83
+ onUpdateFilter(query, filterParams) {
84
+ return __awaiter(this, void 0, void 0, function* () {
85
+ // This function should be overriden
86
+ const { hasStatus, hasVersion } = this.config;
87
+ const idName = this.getIdField();
88
+ if (filterParams[idName]) {
89
+ query.where(idName, filterParams[idName]);
90
+ }
91
+ if (hasVersion) {
92
+ if (filterParams[constants_1.FIELDS.VERSION] != null && !isNaN(filterParams[constants_1.FIELDS.VERSION])) {
93
+ query.where({ [constants_1.FIELDS.VERSION]: filterParams[constants_1.FIELDS.VERSION] });
133
94
  }
134
- if (hasStatus) {
135
- if (Array.isArray(filterParams === null || filterParams === void 0 ? void 0 : filterParams[constants_1.FIELDS.STATUS])) {
136
- query.whereIn(constants_1.FIELDS.STATUS, filterParams === null || filterParams === void 0 ? void 0 : filterParams[constants_1.FIELDS.STATUS]);
137
- }
138
- else {
139
- query.where(constants_1.FIELDS.STATUS, '!=', utils_1.STATUSES.REMOVED);
140
- }
95
+ }
96
+ if (hasStatus) {
97
+ if (Array.isArray(filterParams === null || filterParams === void 0 ? void 0 : filterParams[constants_1.FIELDS.STATUS])) {
98
+ query.whereIn(constants_1.FIELDS.STATUS, filterParams === null || filterParams === void 0 ? void 0 : filterParams[constants_1.FIELDS.STATUS]);
141
99
  }
142
- return [2 /*return*/];
143
- });
144
- });
145
- };
146
- BaseGateway.prototype.onRemoveFilter = function (query, filterParams) {
147
- return __awaiter(this, void 0, void 0, function () {
148
- var hasStatus, arr;
149
- var _this = this;
150
- return __generator(this, function (_a) {
151
- hasStatus = this.config.hasStatus;
152
- arr = (0, lodash_1.castArray)(filterParams);
153
- query = query.whereIn(this.getIdField(), arr.map(function (item) { return item[_this.getIdField()]; }));
154
- if (hasStatus === true) {
100
+ else {
155
101
  query.where(constants_1.FIELDS.STATUS, '!=', utils_1.STATUSES.REMOVED);
156
102
  }
157
- return [2 /*return*/];
158
- });
103
+ }
159
104
  });
160
- };
161
- BaseGateway.prototype.transformOnCreate = function (params) {
162
- return __awaiter(this, void 0, void 0, function () {
163
- var _a, hasCreatedAt, hasCreatedBy, hasSpace, hasVersion, hasLang, localizationForField, hasUserId, createdBy, userId;
164
- return __generator(this, function (_b) {
165
- _a = this.config, hasCreatedAt = _a.hasCreatedAt, hasCreatedBy = _a.hasCreatedBy, hasSpace = _a.hasSpace, hasVersion = _a.hasVersion, hasLang = _a.hasLang, localizationForField = _a.localizationForField, hasUserId = _a.hasUserId;
166
- if (hasCreatedAt) {
167
- params[(0, lodash_1.camelCase)(constants_1.FIELDS.CREATED_AT)] = this.dateTime.dbFormat(this.dateTimeNow);
168
- }
169
- if (hasCreatedBy) {
170
- createdBy = (0, lodash_1.camelCase)(constants_1.FIELDS.CREATED_BY);
171
- if (params[createdBy] === undefined) {
172
- params[createdBy] = this.getContext().userId;
173
- }
174
- }
175
- if (hasUserId) {
176
- userId = (0, lodash_1.camelCase)(constants_1.FIELDS.USER_ID);
177
- if (params[userId] === undefined) {
178
- params[userId] = this.getContext().userId;
179
- }
180
- }
181
- if (hasSpace) {
182
- params[(0, lodash_1.camelCase)(constants_1.FIELDS.SPACE_ID)] = this.getContext().spaceId;
183
- }
184
- if (hasVersion) {
185
- params[(0, lodash_1.camelCase)(constants_1.FIELDS.VERSION)] = 0;
105
+ }
106
+ onRemoveFilter(query, filterParams) {
107
+ return __awaiter(this, void 0, void 0, function* () {
108
+ // This function should be overriden
109
+ const { hasStatus } = this.config;
110
+ const arr = (0, lodash_1.castArray)(filterParams);
111
+ query = query.whereIn(this.getIdField(), arr.map((item) => item[this.getIdField()]));
112
+ if (hasStatus === true) {
113
+ query.where(constants_1.FIELDS.STATUS, '!=', utils_1.STATUSES.REMOVED);
114
+ }
115
+ });
116
+ }
117
+ transformOnCreate(params) {
118
+ return __awaiter(this, void 0, void 0, function* () {
119
+ const { hasCreatedAt, hasCreatedBy, hasSpace, hasVersion, hasLang, localizationForField, hasUserId } = this.config;
120
+ if (hasCreatedAt) {
121
+ params[(0, lodash_1.camelCase)(constants_1.FIELDS.CREATED_AT)] = this.dateTime.dbFormat(this.dateTimeNow);
122
+ }
123
+ if (hasCreatedBy) {
124
+ const createdBy = (0, lodash_1.camelCase)(constants_1.FIELDS.CREATED_BY);
125
+ if (params[createdBy] === undefined) {
126
+ params[createdBy] = this.getContext().userId;
186
127
  }
187
- if (hasLang && localizationForField) {
188
- params[this.getIdField()] = (0, utils_1.buildKey)([params[(0, lodash_1.camelCase)(localizationForField)], params[(0, lodash_1.camelCase)(constants_1.FIELDS.LANG)]]);
128
+ }
129
+ if (hasUserId) {
130
+ const userId = (0, lodash_1.camelCase)(constants_1.FIELDS.USER_ID);
131
+ if (params[userId] === undefined) {
132
+ params[userId] = this.getContext().userId;
189
133
  }
190
- return [2 /*return*/, params];
191
- });
134
+ }
135
+ if (hasSpace) {
136
+ params[(0, lodash_1.camelCase)(constants_1.FIELDS.SPACE_ID)] = this.getContext().spaceId;
137
+ }
138
+ if (hasVersion) {
139
+ params[(0, lodash_1.camelCase)(constants_1.FIELDS.VERSION)] = 0;
140
+ }
141
+ if (hasLang && localizationForField) {
142
+ params[this.getIdField()] = (0, utils_1.buildKey)([params[(0, lodash_1.camelCase)(localizationForField)], params[(0, lodash_1.camelCase)(constants_1.FIELDS.LANG)]]);
143
+ }
144
+ return params;
192
145
  });
193
- };
146
+ }
194
147
  // eslint-disable-next-line
195
- BaseGateway.prototype.transformOnUpdate = function (params, where) {
196
- return __awaiter(this, void 0, void 0, function () {
197
- var _a, hasUpdatedAt, hasUpdatedBy, hasVersion, hasLang, localizationForField, updatedBy, version;
198
- return __generator(this, function (_b) {
199
- _a = this.config, hasUpdatedAt = _a.hasUpdatedAt, hasUpdatedBy = _a.hasUpdatedBy, hasVersion = _a.hasVersion, hasLang = _a.hasLang, localizationForField = _a.localizationForField;
200
- if (hasUpdatedAt) {
201
- params[(0, lodash_1.camelCase)(constants_1.FIELDS.UPDATED_AT)] = this.dateTime.dbFormat(this.dateTimeNow);
202
- }
203
- if (hasUpdatedBy) {
204
- updatedBy = (0, lodash_1.camelCase)(constants_1.FIELDS.UPDATED_BY);
205
- if (params[updatedBy] === undefined) {
206
- params[updatedBy] = this.getContext().userId;
207
- }
208
- }
209
- if (hasVersion) {
210
- version = (0, lodash_1.camelCase)(constants_1.FIELDS.VERSION);
211
- if (params[version] != null && !isNaN(params[version])) {
212
- params[version] = params[version] + 1;
213
- }
148
+ transformOnUpdate(params, where) {
149
+ return __awaiter(this, void 0, void 0, function* () {
150
+ const { hasUpdatedAt, hasUpdatedBy, hasVersion, hasLang, localizationForField } = this.config;
151
+ if (hasUpdatedAt) {
152
+ params[(0, lodash_1.camelCase)(constants_1.FIELDS.UPDATED_AT)] = this.dateTime.dbFormat(this.dateTimeNow);
153
+ }
154
+ if (hasUpdatedBy) {
155
+ const updatedBy = (0, lodash_1.camelCase)(constants_1.FIELDS.UPDATED_BY);
156
+ if (params[updatedBy] === undefined) {
157
+ params[updatedBy] = this.getContext().userId;
214
158
  }
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)]]);
159
+ }
160
+ if (hasVersion) {
161
+ const version = (0, lodash_1.camelCase)(constants_1.FIELDS.VERSION);
162
+ if (params[version] != null && !isNaN(params[version])) {
163
+ params[version] = params[version] + 1;
217
164
  }
218
- return [2 /*return*/, params];
219
- });
165
+ }
166
+ if (hasLang && localizationForField) {
167
+ params[this.getIdField()] = (0, utils_1.buildKey)([params[(0, lodash_1.camelCase)(localizationForField)], params[(0, lodash_1.camelCase)(constants_1.FIELDS.LANG)]]);
168
+ }
169
+ return params;
220
170
  });
221
- };
222
- BaseGateway.prototype.transformOnSet = function (params) {
223
- return __awaiter(this, void 0, void 0, function () {
224
- var _a, hasCreatedAt, hasCreatedBy, hasSpace, hasUpdatedAt, hasUpdatedBy, hasVersion, hasLang, localizationForField, hasUserId, createdBy, userId, updatedBy, version;
225
- return __generator(this, function (_b) {
226
- _a = this.config, hasCreatedAt = _a.hasCreatedAt, hasCreatedBy = _a.hasCreatedBy, hasSpace = _a.hasSpace, hasUpdatedAt = _a.hasUpdatedAt, hasUpdatedBy = _a.hasUpdatedBy, hasVersion = _a.hasVersion, hasLang = _a.hasLang, localizationForField = _a.localizationForField, hasUserId = _a.hasUserId;
227
- if (hasCreatedAt) {
228
- params[(0, lodash_1.camelCase)(constants_1.FIELDS.CREATED_AT)] = this.dateTime.dbFormat(this.dateTimeNow);
229
- }
230
- if (hasCreatedBy) {
231
- createdBy = (0, lodash_1.camelCase)(constants_1.FIELDS.CREATED_BY);
232
- if (params[createdBy] === undefined) {
233
- params[createdBy] = this.getContext().userId;
234
- }
235
- }
236
- if (hasUserId) {
237
- userId = (0, lodash_1.camelCase)(constants_1.FIELDS.USER_ID);
238
- if (params[userId] === undefined) {
239
- params[userId] = this.getContext().userId;
240
- }
241
- }
242
- if (hasSpace) {
243
- params[(0, lodash_1.camelCase)(constants_1.FIELDS.SPACE_ID)] = this.getContext().spaceId;
171
+ }
172
+ transformOnSet(params) {
173
+ return __awaiter(this, void 0, void 0, function* () {
174
+ const { hasCreatedAt, hasCreatedBy, hasSpace, hasUpdatedAt, hasUpdatedBy, hasVersion, hasLang, localizationForField, hasUserId, } = this.config;
175
+ if (hasCreatedAt) {
176
+ params[(0, lodash_1.camelCase)(constants_1.FIELDS.CREATED_AT)] = this.dateTime.dbFormat(this.dateTimeNow);
177
+ }
178
+ if (hasCreatedBy) {
179
+ const createdBy = (0, lodash_1.camelCase)(constants_1.FIELDS.CREATED_BY);
180
+ if (params[createdBy] === undefined) {
181
+ params[createdBy] = this.getContext().userId;
244
182
  }
245
- if (hasUpdatedAt) {
246
- params[(0, lodash_1.camelCase)(constants_1.FIELDS.UPDATED_AT)] = this.dateTime.dbFormat(this.dateTimeNow);
183
+ }
184
+ if (hasUserId) {
185
+ const userId = (0, lodash_1.camelCase)(constants_1.FIELDS.USER_ID);
186
+ if (params[userId] === undefined) {
187
+ params[userId] = this.getContext().userId;
247
188
  }
248
- if (hasUpdatedBy) {
249
- updatedBy = (0, lodash_1.camelCase)(constants_1.FIELDS.UPDATED_BY);
250
- if (params[updatedBy] === undefined) {
251
- params[updatedBy] = this.getContext().userId;
252
- }
189
+ }
190
+ if (hasSpace) {
191
+ params[(0, lodash_1.camelCase)(constants_1.FIELDS.SPACE_ID)] = this.getContext().spaceId;
192
+ }
193
+ if (hasUpdatedAt) {
194
+ params[(0, lodash_1.camelCase)(constants_1.FIELDS.UPDATED_AT)] = this.dateTime.dbFormat(this.dateTimeNow);
195
+ }
196
+ if (hasUpdatedBy) {
197
+ const updatedBy = (0, lodash_1.camelCase)(constants_1.FIELDS.UPDATED_BY);
198
+ if (params[updatedBy] === undefined) {
199
+ params[updatedBy] = this.getContext().userId;
253
200
  }
254
- if (hasVersion) {
255
- version = (0, lodash_1.camelCase)(constants_1.FIELDS.VERSION);
256
- if (params[version] != null && !isNaN(params[version])) {
257
- params[version] = params[version] + 1;
258
- }
259
- else {
260
- params[version] = 0;
261
- }
201
+ }
202
+ if (hasVersion) {
203
+ const version = (0, lodash_1.camelCase)(constants_1.FIELDS.VERSION);
204
+ if (params[version] != null && !isNaN(params[version])) {
205
+ params[version] = params[version] + 1;
262
206
  }
263
- if (hasLang && localizationForField) {
264
- params[this.getIdField()] = (0, utils_1.buildKey)([params[(0, lodash_1.camelCase)(localizationForField)], params[(0, lodash_1.camelCase)(constants_1.FIELDS.LANG)]]);
207
+ else {
208
+ params[version] = 0;
265
209
  }
266
- return [2 /*return*/, params];
267
- });
210
+ }
211
+ if (hasLang && localizationForField) {
212
+ params[this.getIdField()] = (0, utils_1.buildKey)([params[(0, lodash_1.camelCase)(localizationForField)], params[(0, lodash_1.camelCase)(constants_1.FIELDS.LANG)]]);
213
+ }
214
+ return params;
268
215
  });
269
- };
270
- BaseGateway.prototype.transformOnRemove = function (args) {
271
- return __awaiter(this, void 0, void 0, function () {
272
- var _a, hasRemovedAt, hasRemovedAtStr, hasStatus, hasRemovedBy, hasLang, localizationForField, removalTime, removalTimeStr, obj;
273
- return __generator(this, function (_b) {
274
- _a = this.config, hasRemovedAt = _a.hasRemovedAt, hasRemovedAtStr = _a.hasRemovedAtStr, hasStatus = _a.hasStatus, hasRemovedBy = _a.hasRemovedBy, hasLang = _a.hasLang, localizationForField = _a.localizationForField;
275
- removalTime = (0, dayjs_1.default)();
276
- removalTimeStr = removalTime.format('YYYYMMDDTHHmmssZ');
277
- obj = __assign({}, (args || {}));
278
- if (hasRemovedAt) {
279
- obj[constants_1.FIELDS.REMOVED_AT] = removalTime.toDate();
280
- }
281
- if (hasRemovedAtStr === true) {
282
- obj[constants_1.FIELDS.REMOVED_AT_STR] = removalTimeStr;
283
- }
284
- if (hasStatus) {
285
- obj[constants_1.FIELDS.STATUS] = utils_1.STATUSES.REMOVED;
286
- }
287
- if (hasRemovedBy) {
288
- if (obj[constants_1.FIELDS.REMOVED_BY] === undefined) {
289
- obj[constants_1.FIELDS.REMOVED_BY] = this.getContext().userId;
290
- }
291
- }
292
- if (hasLang && localizationForField) {
293
- obj[this.getIdField()] = this.getDb().raw("CONCAT(id, '-".concat(removalTimeStr, "')"));
216
+ }
217
+ transformOnRemove(args) {
218
+ return __awaiter(this, void 0, void 0, function* () {
219
+ const { hasRemovedAt, hasRemovedAtStr, hasStatus, hasRemovedBy, hasLang, localizationForField } = this.config;
220
+ const removalTime = (0, dayjs_1.default)();
221
+ const removalTimeStr = removalTime.format('YYYYMMDDTHHmmssZ');
222
+ const obj = Object.assign({}, (args || {}));
223
+ if (hasRemovedAt) {
224
+ obj[constants_1.FIELDS.REMOVED_AT] = removalTime.toDate();
225
+ }
226
+ if (hasRemovedAtStr === true) {
227
+ obj[constants_1.FIELDS.REMOVED_AT_STR] = removalTimeStr;
228
+ }
229
+ if (hasStatus) {
230
+ obj[constants_1.FIELDS.STATUS] = utils_1.STATUSES.REMOVED;
231
+ }
232
+ if (hasRemovedBy) {
233
+ if (obj[constants_1.FIELDS.REMOVED_BY] === undefined) {
234
+ obj[constants_1.FIELDS.REMOVED_BY] = this.getContext().userId;
294
235
  }
295
- return [2 /*return*/, obj];
296
- });
236
+ }
237
+ if (hasLang && localizationForField) {
238
+ obj[this.getIdField()] = this.getDb().raw(`CONCAT(id, '-${removalTimeStr}')`);
239
+ }
240
+ return obj;
297
241
  });
298
- };
299
- BaseGateway.prototype.getRequestId = function () {
242
+ }
243
+ getRequestId() {
300
244
  return this.config.context.requestId;
301
- };
302
- BaseGateway.prototype.getContext = function () {
245
+ }
246
+ getContext() {
303
247
  return this.config.context;
304
- };
305
- BaseGateway.prototype.getGateways = function () {
248
+ }
249
+ getGateways() {
306
250
  return this.config.context.gateways || {};
307
- };
308
- BaseGateway.prototype.getDb = function () {
251
+ }
252
+ getDb() {
309
253
  return this.config.db;
310
- };
311
- BaseGateway.prototype.getBuilder = function () {
254
+ }
255
+ getBuilder() {
312
256
  var _a;
313
257
  return (_a = this.getDb()) === null || _a === void 0 ? void 0 : _a.getBuilder(this.config.table);
314
- };
315
- BaseGateway.prototype.getIdField = function () {
258
+ }
259
+ getIdField() {
316
260
  return this.config.idField || constants_1.ID_FIELD;
317
- };
318
- BaseGateway.prototype.get = function (id) {
319
- return __awaiter(this, void 0, void 0, function () {
320
- return __generator(this, function (_a) {
321
- return [2 /*return*/, this.loader.load(id)];
322
- });
261
+ }
262
+ get(id) {
263
+ return __awaiter(this, void 0, void 0, function* () {
264
+ return this.loader.load(id);
323
265
  });
324
- };
325
- BaseGateway.prototype.getMany = function (ids) {
326
- return __awaiter(this, void 0, void 0, function () {
327
- return __generator(this, function (_a) {
328
- return [2 /*return*/, this.loader.loadMany(ids)];
329
- });
266
+ }
267
+ getMany(ids) {
268
+ return __awaiter(this, void 0, void 0, function* () {
269
+ return this.loader.loadMany(ids);
330
270
  });
331
- };
332
- BaseGateway.prototype.list = function (args) {
333
- return __awaiter(this, void 0, void 0, function () {
334
- var _a, filter, params, _b, limit, offset, sortBy, query, fieldsToUse, items, _c;
335
- return __generator(this, function (_d) {
336
- switch (_d.label) {
337
- case 0:
338
- _a = args || {}, filter = _a.filter, params = _a.params;
339
- _b = this.getDb().createLimitOffsetSortBy(params, this.config.defaultSorting || []), limit = _b.limit, offset = _b.offset, sortBy = _b.sortBy;
340
- if (!this.config.table) {
341
- return [2 /*return*/, []];
342
- }
343
- query = this.getBuilder();
344
- fieldsToUse = this.config.noCache === true && Array.isArray(this.config.selectFields)
345
- ? this.config.selectFields
346
- : this.getIdField();
347
- query.select(fieldsToUse);
348
- return [4 /*yield*/, this.onListFilter(query, filter)];
349
- case 1:
350
- _d.sent();
351
- if (limit && !isNaN(limit) && limit > 0) {
352
- query.offset(offset).limit(limit);
353
- }
354
- if (sortBy) {
355
- query.orderBy(sortBy);
356
- }
357
- return [4 /*yield*/, query];
358
- case 2:
359
- items = _d.sent();
360
- if (!(this.config.noCache === true)) return [3 /*break*/, 3];
361
- _c = items;
362
- return [3 /*break*/, 5];
363
- case 3: return [4 /*yield*/, this.getMany(items.map(function (row) { return row.id; }))];
364
- case 4:
365
- _c = _d.sent();
366
- _d.label = 5;
367
- case 5: return [2 /*return*/, _c];
368
- }
369
- });
271
+ }
272
+ list(args) {
273
+ return __awaiter(this, void 0, void 0, function* () {
274
+ const { filter, params } = args || {};
275
+ const { limit, offset, sortBy } = this.getDb().createLimitOffsetSortBy(params, this.config.defaultSorting || []);
276
+ if (!this.config.table) {
277
+ return [];
278
+ }
279
+ const query = this.getBuilder();
280
+ const fieldsToUse = this.config.noCache === true && Array.isArray(this.config.selectFields)
281
+ ? this.config.selectFields
282
+ : this.getIdField();
283
+ query.select(fieldsToUse);
284
+ yield this.onListFilter(query, filter);
285
+ if (limit && !isNaN(limit) && limit > 0) {
286
+ query.offset(offset).limit(limit);
287
+ }
288
+ if (sortBy) {
289
+ query.orderBy(sortBy);
290
+ }
291
+ const items = yield query;
292
+ return this.config.noCache === true ? items : yield this.getMany(items.map((row) => row.id));
370
293
  });
371
- };
372
- BaseGateway.prototype.create = function (args) {
294
+ }
295
+ create(args) {
373
296
  var _a;
374
- return __awaiter(this, void 0, void 0, function () {
375
- var objects, idx, len, object, id, _b, _c, result, chunks, idx, len, items;
376
- return __generator(this, function (_d) {
377
- switch (_d.label) {
378
- case 0:
379
- objects = (0, lodash_1.castArray)(args);
380
- if (!args || objects.length === 0) {
381
- return [2 /*return*/, []];
382
- }
383
- idx = 0, len = objects.length;
384
- _d.label = 1;
385
- case 1:
386
- if (!(idx < len)) return [3 /*break*/, 5];
387
- object = objects[idx];
388
- return [4 /*yield*/, this.generateId(object)];
389
- case 2:
390
- id = _d.sent();
391
- _b = objects;
392
- _c = idx;
393
- return [4 /*yield*/, this.transformOnCreate(__assign({ id: id }, object))];
394
- case 3:
395
- _b[_c] = _d.sent();
396
- _d.label = 4;
397
- case 4:
398
- ++idx;
399
- return [3 /*break*/, 1];
400
- case 5:
401
- result = [];
402
- chunks = (0, utils_1.arrToChunks)(objects, ((_a = this.config) === null || _a === void 0 ? void 0 : _a.insertChunkSize) || DEFAULT_CHUNCK_SIZE);
403
- idx = 0, len = chunks.length;
404
- _d.label = 6;
405
- case 6:
406
- if (!(idx < len)) return [3 /*break*/, 9];
407
- return [4 /*yield*/, this.getBuilder().insert(chunks[idx]).returning(this.config.returnFields)];
408
- case 7:
409
- items = _d.sent();
410
- result.push.apply(result, items);
411
- _d.label = 8;
412
- case 8:
413
- ++idx;
414
- return [3 /*break*/, 6];
415
- case 9: return [2 /*return*/, result];
416
- }
417
- });
297
+ return __awaiter(this, void 0, void 0, function* () {
298
+ const objects = (0, lodash_1.castArray)(args);
299
+ if (!args || objects.length === 0) {
300
+ return [];
301
+ }
302
+ for (let idx = 0, len = objects.length; idx < len; ++idx) {
303
+ const object = objects[idx];
304
+ const id = yield this.generateId(object);
305
+ objects[idx] = yield this.transformOnCreate(Object.assign({ id }, object));
306
+ //objects.push(obj);
307
+ }
308
+ const result = [];
309
+ const chunks = (0, utils_1.arrToChunks)(objects, ((_a = this.config) === null || _a === void 0 ? void 0 : _a.insertChunkSize) || DEFAULT_CHUNCK_SIZE);
310
+ for (let idx = 0, len = chunks.length; idx < len; ++idx) {
311
+ const items = yield this.getBuilder().insert(chunks[idx]).returning(this.config.returnFields);
312
+ result.push(...items);
313
+ }
314
+ return result;
418
315
  });
419
- };
420
- BaseGateway.prototype.update = function (where, params) {
421
- return __awaiter(this, void 0, void 0, function () {
422
- var object, query, items;
423
- var _this = this;
424
- return __generator(this, function (_a) {
425
- switch (_a.label) {
426
- case 0: return [4 /*yield*/, this.transformOnUpdate(params, where)];
427
- case 1:
428
- object = _a.sent();
429
- query = this.getBuilder().update(object).returning(this.config.returnFields);
430
- return [4 /*yield*/, this.onUpdateFilter(query, where)];
431
- case 2:
432
- _a.sent();
433
- return [4 /*yield*/, query];
434
- case 3:
435
- items = _a.sent();
436
- if (items.length > 0 && this.config.noCache !== true) {
437
- items.forEach(function (item) { return _this.loader.clear(item[_this.getIdField()]); });
438
- }
439
- return [2 /*return*/, items];
440
- }
441
- });
316
+ }
317
+ update(where, params) {
318
+ return __awaiter(this, void 0, void 0, function* () {
319
+ const object = yield this.transformOnUpdate(params, where);
320
+ const query = this.getBuilder().update(object).returning(this.config.returnFields);
321
+ yield this.onUpdateFilter(query, where);
322
+ const items = yield query;
323
+ if (items.length > 0 && this.config.noCache !== true) {
324
+ items.forEach((item) => this.loader.clear(item[this.getIdField()]));
325
+ }
326
+ return items;
442
327
  });
443
- };
444
- BaseGateway.prototype.updateMany = function (params) {
445
- return __awaiter(this, void 0, void 0, function () {
446
- var results, idx, len, item, items;
447
- var _this = this;
448
- return __generator(this, function (_a) {
449
- switch (_a.label) {
450
- case 0:
451
- if (!Array.isArray(params)) {
452
- params = [params];
453
- }
454
- results = [];
455
- idx = 0, len = params.length;
456
- _a.label = 1;
457
- case 1:
458
- if (!(idx < len)) return [3 /*break*/, 4];
459
- item = params[idx];
460
- return [4 /*yield*/, this.update(item.where, item.params)];
461
- case 2:
462
- items = _a.sent();
463
- results.push.apply(results, items);
464
- _a.label = 3;
465
- case 3:
466
- ++idx;
467
- return [3 /*break*/, 1];
468
- case 4:
469
- if (results.length > 0 && this.config.noCache !== true) {
470
- results.forEach(function (item) { return _this.loader.clear(item[_this.getIdField()]); });
471
- }
472
- return [2 /*return*/, results];
473
- }
474
- });
328
+ }
329
+ updateMany(params) {
330
+ return __awaiter(this, void 0, void 0, function* () {
331
+ if (!Array.isArray(params)) {
332
+ params = [params];
333
+ }
334
+ const results = [];
335
+ for (let idx = 0, len = params.length; idx < len; ++idx) {
336
+ const item = params[idx];
337
+ const items = yield this.update(item.where, item.params);
338
+ results.push(...items);
339
+ }
340
+ if (results.length > 0 && this.config.noCache !== true) {
341
+ results.forEach((item) => this.loader.clear(item[this.getIdField()]));
342
+ }
343
+ return results;
475
344
  });
476
- };
477
- BaseGateway.prototype.increment = function (where, params) {
478
- return __awaiter(this, void 0, void 0, function () {
479
- var object, query, items;
480
- var _this = this;
481
- return __generator(this, function (_a) {
482
- switch (_a.label) {
483
- case 0: return [4 /*yield*/, this.transformOnUpdate(params, where)];
484
- case 1:
485
- object = _a.sent();
486
- query = this.getBuilder().increment(object).returning(this.config.returnFields);
487
- return [4 /*yield*/, this.onUpdateFilter(query, where)];
488
- case 2:
489
- _a.sent();
490
- return [4 /*yield*/, query];
491
- case 3:
492
- items = _a.sent();
493
- if (items.length > 0 && this.config.noCache !== true) {
494
- items.forEach(function (item) { return _this.loader.clear(item[_this.getIdField()]); });
495
- }
496
- return [2 /*return*/, items];
497
- }
498
- });
345
+ }
346
+ increment(where, params) {
347
+ return __awaiter(this, void 0, void 0, function* () {
348
+ const object = yield this.transformOnUpdate(params, where);
349
+ const query = this.getBuilder().increment(object).returning(this.config.returnFields);
350
+ yield this.onUpdateFilter(query, where);
351
+ const items = yield query;
352
+ if (items.length > 0 && this.config.noCache !== true) {
353
+ items.forEach((item) => this.loader.clear(item[this.getIdField()]));
354
+ }
355
+ return items;
499
356
  });
500
- };
501
- BaseGateway.prototype.decrement = function (where, params) {
502
- return __awaiter(this, void 0, void 0, function () {
503
- var object, query, items;
504
- var _this = this;
505
- return __generator(this, function (_a) {
506
- switch (_a.label) {
507
- case 0: return [4 /*yield*/, this.transformOnUpdate(params, where)];
508
- case 1:
509
- object = _a.sent();
510
- query = this.getBuilder().decrement(object).returning(this.config.returnFields);
511
- return [4 /*yield*/, this.onUpdateFilter(query, where)];
512
- case 2:
513
- _a.sent();
514
- return [4 /*yield*/, query];
515
- case 3:
516
- items = _a.sent();
517
- if (items.length > 0 && this.config.noCache !== true) {
518
- items.forEach(function (item) { return _this.loader.clear(item[_this.getIdField()]); });
519
- }
520
- return [2 /*return*/, items];
521
- }
522
- });
357
+ }
358
+ decrement(where, params) {
359
+ return __awaiter(this, void 0, void 0, function* () {
360
+ const object = yield this.transformOnUpdate(params, where);
361
+ const query = this.getBuilder().decrement(object).returning(this.config.returnFields);
362
+ yield this.onUpdateFilter(query, where);
363
+ const items = yield query;
364
+ if (items.length > 0 && this.config.noCache !== true) {
365
+ items.forEach((item) => this.loader.clear(item[this.getIdField()]));
366
+ }
367
+ return items;
523
368
  });
524
- };
369
+ }
525
370
  /**
526
371
  * Inserts or updates data in the database.
527
372
  * If the element of given array has not empty id field then the record is updated
@@ -529,104 +374,63 @@ var BaseGateway = /** @class */ (function () {
529
374
  * @param params Array of objects to update or create
530
375
  * @returns Array of updated or inserted objects
531
376
  */
532
- BaseGateway.prototype.set = function (params) {
377
+ set(params) {
533
378
  var _a;
534
- return __awaiter(this, void 0, void 0, function () {
535
- var _b, hasCreatedAt, hasCreatedBy, hasSpace, mergeFields, objects, skipFields, idx, len, object, _c, _d, _e, _f, fields, result, chunks, idx, len, items;
536
- return __generator(this, function (_g) {
537
- switch (_g.label) {
538
- case 0:
539
- _b = this.config || {}, hasCreatedAt = _b.hasCreatedAt, hasCreatedBy = _b.hasCreatedBy, hasSpace = _b.hasSpace, mergeFields = _b.mergeFields;
540
- objects = (0, lodash_1.castArray)(params);
541
- if (!params || objects.length === 0) {
542
- return [2 /*return*/, []];
543
- }
544
- skipFields = [];
545
- if (hasCreatedAt) {
546
- skipFields.push(constants_1.FIELDS.CREATED_AT);
547
- }
548
- if (hasCreatedBy) {
549
- skipFields.push(constants_1.FIELDS.CREATED_BY);
550
- }
551
- if (hasSpace) {
552
- skipFields.push(constants_1.FIELDS.SPACE_ID);
553
- }
554
- idx = 0, len = objects.length;
555
- _g.label = 1;
556
- case 1:
557
- if (!(idx < len)) return [3 /*break*/, 5];
558
- object = objects[idx];
559
- _c = objects;
560
- _d = idx;
561
- return [4 /*yield*/, this.transformOnSet(object)];
562
- case 2:
563
- _c[_d] = _g.sent();
564
- if (!(objects[idx][this.getIdField()] == null)) return [3 /*break*/, 4];
565
- _e = objects[idx];
566
- _f = this.getIdField();
567
- return [4 /*yield*/, this.generateId(object)];
568
- case 3:
569
- _e[_f] = _g.sent();
570
- _g.label = 4;
571
- case 4:
572
- ++idx;
573
- return [3 /*break*/, 1];
574
- case 5:
575
- fields = Array.isArray(mergeFields) ? mergeFields : Object.keys(objects[0]);
576
- result = [];
577
- chunks = (0, utils_1.arrToChunks)(objects, ((_a = this.config) === null || _a === void 0 ? void 0 : _a.insertChunkSize) || DEFAULT_CHUNCK_SIZE);
578
- idx = 0, len = chunks.length;
579
- _g.label = 6;
580
- case 6:
581
- if (!(idx < len)) return [3 /*break*/, 9];
582
- return [4 /*yield*/, this.getBuilder()
583
- .insert(chunks[idx])
584
- .returning(this.config.returnFields)
585
- .onConflict(this.config.setFields || this.getIdField())
586
- .merge((0, lodash_1.pullAll)(fields, skipFields))];
587
- case 7:
588
- items = _g.sent();
589
- result.push.apply(result, items);
590
- _g.label = 8;
591
- case 8:
592
- ++idx;
593
- return [3 /*break*/, 6];
594
- case 9: return [2 /*return*/, result];
379
+ return __awaiter(this, void 0, void 0, function* () {
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] = yield this.transformOnSet(object);
398
+ if (objects[idx][this.getIdField()] == null) {
399
+ objects[idx][this.getIdField()] = yield this.generateId(object);
595
400
  }
596
- });
401
+ }
402
+ const fields = Array.isArray(mergeFields) ? mergeFields : Object.keys(objects[0]);
403
+ const result = [];
404
+ const chunks = (0, utils_1.arrToChunks)(objects, ((_a = this.config) === null || _a === void 0 ? void 0 : _a.insertChunkSize) || DEFAULT_CHUNCK_SIZE);
405
+ for (let idx = 0, len = chunks.length; idx < len; ++idx) {
406
+ const items = yield 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;
597
414
  });
598
- };
599
- BaseGateway.prototype.remove = function (where) {
600
- return __awaiter(this, void 0, void 0, function () {
601
- var hardRemove, query, object, items;
602
- var _this = this;
603
- return __generator(this, function (_a) {
604
- switch (_a.label) {
605
- case 0:
606
- hardRemove = (this.config || {}).hardRemove;
607
- query = this.getBuilder();
608
- if (!hardRemove) return [3 /*break*/, 1];
609
- query.delete(this.config.returnFields);
610
- return [3 /*break*/, 3];
611
- case 1: return [4 /*yield*/, this.transformOnRemove()];
612
- case 2:
613
- object = _a.sent();
614
- query.update(object).returning(this.config.returnFields);
615
- _a.label = 3;
616
- case 3: return [4 /*yield*/, this.onRemoveFilter(query, where)];
617
- case 4:
618
- _a.sent();
619
- return [4 /*yield*/, query];
620
- case 5:
621
- items = _a.sent();
622
- if (items.length > 0 && this.config.noCache !== true) {
623
- items.forEach(function (item) { return _this.loader.clear(item[_this.getIdField()]); });
624
- }
625
- return [2 /*return*/, items];
626
- }
627
- });
415
+ }
416
+ remove(where) {
417
+ return __awaiter(this, void 0, void 0, function* () {
418
+ const { hardRemove } = this.config || {};
419
+ const query = this.getBuilder();
420
+ if (hardRemove) {
421
+ query.delete(this.config.returnFields);
422
+ }
423
+ else {
424
+ const object = yield this.transformOnRemove();
425
+ query.update(object).returning(this.config.returnFields);
426
+ }
427
+ yield this.onRemoveFilter(query, where);
428
+ const items = yield query;
429
+ if (items.length > 0 && this.config.noCache !== true) {
430
+ items.forEach((item) => this.loader.clear(item[this.getIdField()]));
431
+ }
432
+ return items;
628
433
  });
629
- };
630
- return BaseGateway;
631
- }());
434
+ }
435
+ }
632
436
  exports.BaseGateway = BaseGateway;