@sdflc/backend-helpers 1.0.47 → 1.0.50

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,20 @@ 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) {
63
25
  this.dateTime = new utils_1.DateTimeHelpers();
64
26
  this.dateTimeNow = new Date();
65
27
  this.config = props;
@@ -70,458 +32,333 @@ var BaseGateway = /** @class */ (function () {
70
32
  : [utils_1.STATUSES.ACTIVE];
71
33
  this.loader = typeof this.config.loader === 'function' ? this.config.loader : new DataCache_1.DataCache(this.config);
72
34
  }
73
- BaseGateway.prototype.setConfigPart = function (props) {
35
+ setConfigPart(props) {
74
36
  Object.assign(this.config, props);
75
37
  return this;
76
- };
38
+ }
77
39
  // 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
- });
40
+ generateId(args) {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ return (0, uuid_1.v4)();
83
43
  });
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
- });
44
+ }
45
+ onListFilter(query, filterParams) {
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ const { hasStatus, hasRemovedAt, hasSpace, activeStatuses, hasLang, fieldForKeyword, filterByUserField } = this.config || {};
48
+ // This function should be overriden
49
+ if (hasStatus) {
50
+ 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));
51
+ }
52
+ if (hasRemovedAt) {
53
+ query.whereNull(constants_1.FIELDS.REMOVED_AT);
54
+ }
55
+ if (hasSpace && ((filterParams === null || filterParams === void 0 ? void 0 : filterParams[constants_1.FIELDS.SPACE_ID]) != undefined || this.config.context.spaceId)) {
56
+ query.where({
57
+ [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,
58
+ });
59
+ }
60
+ if (hasLang && (filterParams === null || filterParams === void 0 ? void 0 : filterParams[constants_1.FIELDS.LANG]) != undefined) {
61
+ query.whereIn(constants_1.FIELDS.LANG, (0, lodash_1.castArray)(filterParams === null || filterParams === void 0 ? void 0 : filterParams[constants_1.FIELDS.LANG]));
62
+ }
63
+ if (filterParams === null || filterParams === void 0 ? void 0 : filterParams[this.getIdField()]) {
64
+ query.whereIn(constants_1.FIELDS.ID, (0, lodash_1.castArray)(filterParams === null || filterParams === void 0 ? void 0 : filterParams[this.getIdField()]));
65
+ }
66
+ if (fieldForKeyword && filterParams.keyword) {
67
+ query.whereRaw(`${fieldForKeyword} ILIKE ?`, `%${filterParams.keyword}%`);
68
+ }
69
+ if (filterByUserField) {
70
+ query.where({ [filterByUserField]: this.getContext().userId });
71
+ }
72
+ // TODO: prse filterParams and buils where clause automatically here
117
73
  });
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
- }
74
+ }
75
+ onUpdateFilter(query, filterParams) {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ // This function should be overriden
78
+ const { hasStatus, hasVersion } = this.config;
79
+ const idName = this.getIdField();
80
+ if (filterParams[idName]) {
81
+ query.where(idName, filterParams[idName]);
82
+ }
83
+ if (hasVersion) {
84
+ if (filterParams[constants_1.FIELDS.VERSION] != null && !isNaN(filterParams[constants_1.FIELDS.VERSION])) {
85
+ query.where({ [constants_1.FIELDS.VERSION]: filterParams[constants_1.FIELDS.VERSION] });
133
86
  }
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
- }
87
+ }
88
+ if (hasStatus) {
89
+ if (Array.isArray(filterParams === null || filterParams === void 0 ? void 0 : filterParams[constants_1.FIELDS.STATUS])) {
90
+ query.whereIn(constants_1.FIELDS.STATUS, filterParams === null || filterParams === void 0 ? void 0 : filterParams[constants_1.FIELDS.STATUS]);
141
91
  }
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) {
92
+ else {
155
93
  query.where(constants_1.FIELDS.STATUS, '!=', utils_1.STATUSES.REMOVED);
156
94
  }
157
- return [2 /*return*/];
158
- });
95
+ }
159
96
  });
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;
97
+ }
98
+ onRemoveFilter(query, filterParams) {
99
+ return __awaiter(this, void 0, void 0, function* () {
100
+ // This function should be overriden
101
+ const { hasStatus } = this.config;
102
+ const arr = (0, lodash_1.castArray)(filterParams);
103
+ query = query.whereIn(this.getIdField(), arr.map((item) => item[this.getIdField()]));
104
+ if (hasStatus === true) {
105
+ query.where(constants_1.FIELDS.STATUS, '!=', utils_1.STATUSES.REMOVED);
106
+ }
107
+ });
108
+ }
109
+ transformOnCreate(params) {
110
+ return __awaiter(this, void 0, void 0, function* () {
111
+ const { hasCreatedAt, hasCreatedBy, hasSpace, hasVersion, hasLang, localizationForField, hasUserId } = this.config;
112
+ if (hasCreatedAt) {
113
+ params[(0, lodash_1.camelCase)(constants_1.FIELDS.CREATED_AT)] = this.dateTime.dbFormat(this.dateTimeNow);
114
+ }
115
+ if (hasCreatedBy) {
116
+ const createdBy = (0, lodash_1.camelCase)(constants_1.FIELDS.CREATED_BY);
117
+ if (params[createdBy] === undefined) {
118
+ params[createdBy] = this.getContext().userId;
186
119
  }
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)]]);
120
+ }
121
+ if (hasUserId) {
122
+ const userId = (0, lodash_1.camelCase)(constants_1.FIELDS.USER_ID);
123
+ if (params[userId] === undefined) {
124
+ params[userId] = this.getContext().userId;
189
125
  }
190
- return [2 /*return*/, params];
191
- });
126
+ }
127
+ if (hasSpace) {
128
+ params[(0, lodash_1.camelCase)(constants_1.FIELDS.SPACE_ID)] = this.getContext().spaceId;
129
+ }
130
+ if (hasVersion) {
131
+ params[(0, lodash_1.camelCase)(constants_1.FIELDS.VERSION)] = 0;
132
+ }
133
+ if (hasLang && localizationForField) {
134
+ params[this.getIdField()] = (0, utils_1.buildKey)([params[(0, lodash_1.camelCase)(localizationForField)], params[(0, lodash_1.camelCase)(constants_1.FIELDS.LANG)]]);
135
+ }
136
+ return params;
192
137
  });
193
- };
138
+ }
194
139
  // 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
- }
140
+ transformOnUpdate(params, where) {
141
+ return __awaiter(this, void 0, void 0, function* () {
142
+ const { hasUpdatedAt, hasUpdatedBy, hasVersion, hasLang, localizationForField } = this.config;
143
+ if (hasUpdatedAt) {
144
+ params[(0, lodash_1.camelCase)(constants_1.FIELDS.UPDATED_AT)] = this.dateTime.dbFormat(this.dateTimeNow);
145
+ }
146
+ if (hasUpdatedBy) {
147
+ const updatedBy = (0, lodash_1.camelCase)(constants_1.FIELDS.UPDATED_BY);
148
+ if (params[updatedBy] === undefined) {
149
+ params[updatedBy] = this.getContext().userId;
214
150
  }
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)]]);
151
+ }
152
+ if (hasVersion) {
153
+ const version = (0, lodash_1.camelCase)(constants_1.FIELDS.VERSION);
154
+ if (params[version] != null && !isNaN(params[version])) {
155
+ params[version] = params[version] + 1;
217
156
  }
218
- return [2 /*return*/, params];
219
- });
157
+ }
158
+ if (hasLang && localizationForField) {
159
+ params[this.getIdField()] = (0, utils_1.buildKey)([params[(0, lodash_1.camelCase)(localizationForField)], params[(0, lodash_1.camelCase)(constants_1.FIELDS.LANG)]]);
160
+ }
161
+ return params;
220
162
  });
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;
163
+ }
164
+ transformOnSet(params) {
165
+ return __awaiter(this, void 0, void 0, function* () {
166
+ const { hasCreatedAt, hasCreatedBy, hasSpace, hasUpdatedAt, hasUpdatedBy, hasVersion, hasLang, localizationForField, hasUserId, } = this.config;
167
+ if (hasCreatedAt) {
168
+ params[(0, lodash_1.camelCase)(constants_1.FIELDS.CREATED_AT)] = this.dateTime.dbFormat(this.dateTimeNow);
169
+ }
170
+ if (hasCreatedBy) {
171
+ const createdBy = (0, lodash_1.camelCase)(constants_1.FIELDS.CREATED_BY);
172
+ if (params[createdBy] === undefined) {
173
+ params[createdBy] = this.getContext().userId;
244
174
  }
245
- if (hasUpdatedAt) {
246
- params[(0, lodash_1.camelCase)(constants_1.FIELDS.UPDATED_AT)] = this.dateTime.dbFormat(this.dateTimeNow);
175
+ }
176
+ if (hasUserId) {
177
+ const userId = (0, lodash_1.camelCase)(constants_1.FIELDS.USER_ID);
178
+ if (params[userId] === undefined) {
179
+ params[userId] = this.getContext().userId;
247
180
  }
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
- }
181
+ }
182
+ if (hasSpace) {
183
+ params[(0, lodash_1.camelCase)(constants_1.FIELDS.SPACE_ID)] = this.getContext().spaceId;
184
+ }
185
+ if (hasUpdatedAt) {
186
+ params[(0, lodash_1.camelCase)(constants_1.FIELDS.UPDATED_AT)] = this.dateTime.dbFormat(this.dateTimeNow);
187
+ }
188
+ if (hasUpdatedBy) {
189
+ const updatedBy = (0, lodash_1.camelCase)(constants_1.FIELDS.UPDATED_BY);
190
+ if (params[updatedBy] === undefined) {
191
+ params[updatedBy] = this.getContext().userId;
253
192
  }
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
- }
193
+ }
194
+ if (hasVersion) {
195
+ const version = (0, lodash_1.camelCase)(constants_1.FIELDS.VERSION);
196
+ if (params[version] != null && !isNaN(params[version])) {
197
+ params[version] = params[version] + 1;
262
198
  }
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)]]);
199
+ else {
200
+ params[version] = 0;
265
201
  }
266
- return [2 /*return*/, params];
267
- });
202
+ }
203
+ if (hasLang && localizationForField) {
204
+ params[this.getIdField()] = (0, utils_1.buildKey)([params[(0, lodash_1.camelCase)(localizationForField)], params[(0, lodash_1.camelCase)(constants_1.FIELDS.LANG)]]);
205
+ }
206
+ return params;
268
207
  });
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, "')"));
208
+ }
209
+ transformOnRemove(args) {
210
+ return __awaiter(this, void 0, void 0, function* () {
211
+ const { hasRemovedAt, hasRemovedAtStr, hasStatus, hasRemovedBy, hasLang, localizationForField } = this.config;
212
+ const removalTime = (0, dayjs_1.default)();
213
+ const removalTimeStr = removalTime.format('YYYYMMDDTHHmmssZ');
214
+ const obj = Object.assign({}, (args || {}));
215
+ if (hasRemovedAt) {
216
+ obj[constants_1.FIELDS.REMOVED_AT] = removalTime.toDate();
217
+ }
218
+ if (hasRemovedAtStr === true) {
219
+ obj[constants_1.FIELDS.REMOVED_AT_STR] = removalTimeStr;
220
+ }
221
+ if (hasStatus) {
222
+ obj[constants_1.FIELDS.STATUS] = utils_1.STATUSES.REMOVED;
223
+ }
224
+ if (hasRemovedBy) {
225
+ if (obj[constants_1.FIELDS.REMOVED_BY] === undefined) {
226
+ obj[constants_1.FIELDS.REMOVED_BY] = this.getContext().userId;
294
227
  }
295
- return [2 /*return*/, obj];
296
- });
228
+ }
229
+ if (hasLang && localizationForField) {
230
+ obj[this.getIdField()] = this.getDb().raw(`CONCAT(id, '-${removalTimeStr}')`);
231
+ }
232
+ return obj;
297
233
  });
298
- };
299
- BaseGateway.prototype.getRequestId = function () {
234
+ }
235
+ getRequestId() {
300
236
  return this.config.context.requestId;
301
- };
302
- BaseGateway.prototype.getContext = function () {
237
+ }
238
+ getContext() {
303
239
  return this.config.context;
304
- };
305
- BaseGateway.prototype.getGateways = function () {
240
+ }
241
+ getGateways() {
306
242
  return this.config.context.gateways || {};
307
- };
308
- BaseGateway.prototype.getDb = function () {
243
+ }
244
+ getDb() {
309
245
  return this.config.db;
310
- };
311
- BaseGateway.prototype.getBuilder = function () {
246
+ }
247
+ getBuilder() {
312
248
  var _a;
313
249
  return (_a = this.getDb()) === null || _a === void 0 ? void 0 : _a.getBuilder(this.config.table);
314
- };
315
- BaseGateway.prototype.getIdField = function () {
250
+ }
251
+ getIdField() {
316
252
  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
- });
253
+ }
254
+ get(id) {
255
+ return __awaiter(this, void 0, void 0, function* () {
256
+ return this.loader.load(id);
323
257
  });
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
- });
258
+ }
259
+ getMany(ids) {
260
+ return __awaiter(this, void 0, void 0, function* () {
261
+ return this.loader.loadMany(ids);
330
262
  });
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
- });
263
+ }
264
+ list(args) {
265
+ return __awaiter(this, void 0, void 0, function* () {
266
+ const { filter, params } = args || {};
267
+ const { limit, offset, sortBy } = this.getDb().createLimitOffsetSortBy(params, this.config.defaultSorting || []);
268
+ if (!this.config.table) {
269
+ return [];
270
+ }
271
+ const query = this.getBuilder();
272
+ const fieldsToUse = this.config.noCache === true && Array.isArray(this.config.selectFields)
273
+ ? this.config.selectFields
274
+ : this.getIdField();
275
+ query.select(fieldsToUse);
276
+ yield this.onListFilter(query, filter);
277
+ if (limit && !isNaN(limit) && limit > 0) {
278
+ query.offset(offset).limit(limit);
279
+ }
280
+ if (sortBy) {
281
+ query.orderBy(sortBy);
282
+ }
283
+ const items = yield query;
284
+ return this.config.noCache === true ? items : yield this.getMany(items.map((row) => row.id));
370
285
  });
371
- };
372
- BaseGateway.prototype.create = function (args) {
286
+ }
287
+ create(args) {
373
288
  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
- });
289
+ return __awaiter(this, void 0, void 0, function* () {
290
+ const objects = (0, lodash_1.castArray)(args);
291
+ if (!args || objects.length === 0) {
292
+ return [];
293
+ }
294
+ for (let idx = 0, len = objects.length; idx < len; ++idx) {
295
+ const object = objects[idx];
296
+ const id = yield this.generateId(object);
297
+ objects[idx] = yield this.transformOnCreate(Object.assign({ id }, object));
298
+ //objects.push(obj);
299
+ }
300
+ const result = [];
301
+ const chunks = (0, utils_1.arrToChunks)(objects, ((_a = this.config) === null || _a === void 0 ? void 0 : _a.insertChunkSize) || DEFAULT_CHUNCK_SIZE);
302
+ for (let idx = 0, len = chunks.length; idx < len; ++idx) {
303
+ const items = yield this.getBuilder().insert(chunks[idx]).returning(this.config.returnFields);
304
+ result.push(...items);
305
+ }
306
+ return result;
418
307
  });
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
- });
308
+ }
309
+ update(where, params) {
310
+ return __awaiter(this, void 0, void 0, function* () {
311
+ const object = yield this.transformOnUpdate(params, where);
312
+ const query = this.getBuilder().update(object).returning(this.config.returnFields);
313
+ yield this.onUpdateFilter(query, where);
314
+ const items = yield query;
315
+ if (items.length > 0 && this.config.noCache !== true) {
316
+ items.forEach((item) => this.loader.clear(item[this.getIdField()]));
317
+ }
318
+ return items;
442
319
  });
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
- });
320
+ }
321
+ updateMany(params) {
322
+ return __awaiter(this, void 0, void 0, function* () {
323
+ if (!Array.isArray(params)) {
324
+ params = [params];
325
+ }
326
+ const results = [];
327
+ for (let idx = 0, len = params.length; idx < len; ++idx) {
328
+ const item = params[idx];
329
+ const items = yield this.update(item.where, item.params);
330
+ results.push(...items);
331
+ }
332
+ if (results.length > 0 && this.config.noCache !== true) {
333
+ results.forEach((item) => this.loader.clear(item[this.getIdField()]));
334
+ }
335
+ return results;
475
336
  });
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
- });
337
+ }
338
+ increment(where, params) {
339
+ return __awaiter(this, void 0, void 0, function* () {
340
+ const object = yield this.transformOnUpdate(params, where);
341
+ const query = this.getBuilder().increment(object).returning(this.config.returnFields);
342
+ yield this.onUpdateFilter(query, where);
343
+ const items = yield query;
344
+ if (items.length > 0 && this.config.noCache !== true) {
345
+ items.forEach((item) => this.loader.clear(item[this.getIdField()]));
346
+ }
347
+ return items;
499
348
  });
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
- });
349
+ }
350
+ decrement(where, params) {
351
+ return __awaiter(this, void 0, void 0, function* () {
352
+ const object = yield this.transformOnUpdate(params, where);
353
+ const query = this.getBuilder().decrement(object).returning(this.config.returnFields);
354
+ yield this.onUpdateFilter(query, where);
355
+ const items = yield query;
356
+ if (items.length > 0 && this.config.noCache !== true) {
357
+ items.forEach((item) => this.loader.clear(item[this.getIdField()]));
358
+ }
359
+ return items;
523
360
  });
524
- };
361
+ }
525
362
  /**
526
363
  * Inserts or updates data in the database.
527
364
  * If the element of given array has not empty id field then the record is updated
@@ -529,104 +366,63 @@ var BaseGateway = /** @class */ (function () {
529
366
  * @param params Array of objects to update or create
530
367
  * @returns Array of updated or inserted objects
531
368
  */
532
- BaseGateway.prototype.set = function (params) {
369
+ set(params) {
533
370
  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];
371
+ return __awaiter(this, void 0, void 0, function* () {
372
+ const { hasCreatedAt, hasCreatedBy, hasSpace, mergeFields } = this.config || {};
373
+ const objects = (0, lodash_1.castArray)(params);
374
+ if (!params || objects.length === 0) {
375
+ return [];
376
+ }
377
+ const skipFields = [];
378
+ if (hasCreatedAt) {
379
+ skipFields.push(constants_1.FIELDS.CREATED_AT);
380
+ }
381
+ if (hasCreatedBy) {
382
+ skipFields.push(constants_1.FIELDS.CREATED_BY);
383
+ }
384
+ if (hasSpace) {
385
+ skipFields.push(constants_1.FIELDS.SPACE_ID);
386
+ }
387
+ for (let idx = 0, len = objects.length; idx < len; ++idx) {
388
+ const object = objects[idx];
389
+ objects[idx] = yield this.transformOnSet(object);
390
+ if (objects[idx][this.getIdField()] == null) {
391
+ objects[idx][this.getIdField()] = yield this.generateId(object);
595
392
  }
596
- });
393
+ }
394
+ const fields = Array.isArray(mergeFields) ? mergeFields : Object.keys(objects[0]);
395
+ const result = [];
396
+ const chunks = (0, utils_1.arrToChunks)(objects, ((_a = this.config) === null || _a === void 0 ? void 0 : _a.insertChunkSize) || DEFAULT_CHUNCK_SIZE);
397
+ for (let idx = 0, len = chunks.length; idx < len; ++idx) {
398
+ const items = yield this.getBuilder()
399
+ .insert(chunks[idx])
400
+ .returning(this.config.returnFields)
401
+ .onConflict(this.config.setFields || this.getIdField())
402
+ .merge((0, lodash_1.pullAll)(fields, skipFields));
403
+ result.push(...items);
404
+ }
405
+ return result;
597
406
  });
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
- });
407
+ }
408
+ remove(where) {
409
+ return __awaiter(this, void 0, void 0, function* () {
410
+ const { hardRemove } = this.config || {};
411
+ const query = this.getBuilder();
412
+ if (hardRemove) {
413
+ query.delete(this.config.returnFields);
414
+ }
415
+ else {
416
+ const object = yield this.transformOnRemove();
417
+ query.update(object).returning(this.config.returnFields);
418
+ }
419
+ yield this.onRemoveFilter(query, where);
420
+ const items = yield query;
421
+ if (items.length > 0 && this.config.noCache !== true) {
422
+ items.forEach((item) => this.loader.clear(item[this.getIdField()]));
423
+ }
424
+ return items;
628
425
  });
629
- };
630
- return BaseGateway;
631
- }());
426
+ }
427
+ }
632
428
  exports.BaseGateway = BaseGateway;