@opra/sqb 1.0.0-alpha.17 → 1.0.0-alpha.18

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,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = parseFilter;
3
4
  const tslib_1 = require("tslib");
4
5
  require("@opra/core");
5
6
  const common_1 = require("@opra/common");
@@ -31,7 +32,6 @@ function parseFilter(filters) {
31
32
  }
32
33
  return arr.length > 1 ? sqb.And(...arr) : arr[0];
33
34
  }
34
- exports.default = parseFilter;
35
35
  function prepareFilterAst(ast) {
36
36
  if (!ast)
37
37
  return;
@@ -42,14 +42,14 @@ class SqbCollectionService extends sqb_entity_service_js_1.SqbEntityService {
42
42
  * @throws {Error} if an unknown error occurs while creating the resource
43
43
  */
44
44
  async create(input, options) {
45
- const info = {
45
+ const command = {
46
46
  crud: 'create',
47
47
  method: 'create',
48
48
  byId: false,
49
49
  input,
50
50
  options,
51
51
  };
52
- return this._intercept(() => this._create(input, options), info);
52
+ return this._executeCommand(command, () => this._create(command));
53
53
  }
54
54
  /**
55
55
  * Returns the count of records based on the provided options
@@ -58,16 +58,17 @@ class SqbCollectionService extends sqb_entity_service_js_1.SqbEntityService {
58
58
  * @return {Promise<number>} - A promise that resolves to the count of records
59
59
  */
60
60
  async count(options) {
61
- const info = {
61
+ const command = {
62
62
  crud: 'read',
63
63
  method: 'count',
64
64
  byId: false,
65
65
  options,
66
66
  };
67
- return this._intercept(async () => {
68
- const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([await this._getCommonFilter(info), options?.filter]);
69
- return this._count({ ...options, filter });
70
- }, info);
67
+ return this._executeCommand(command, async () => {
68
+ const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([await this._getCommonFilter(command), command.options?.filter]);
69
+ command.options = { ...command.options, filter };
70
+ return this._count(command);
71
+ });
71
72
  }
72
73
  /**
73
74
  * Deletes a record from the collection.
@@ -77,17 +78,18 @@ class SqbCollectionService extends sqb_entity_service_js_1.SqbEntityService {
77
78
  * @return {Promise<number>} - A Promise that resolves to the number of documents deleted.
78
79
  */
79
80
  async delete(id, options) {
80
- const info = {
81
+ const command = {
81
82
  crud: 'delete',
82
83
  method: 'delete',
83
84
  byId: true,
84
85
  documentId: id,
85
86
  options,
86
87
  };
87
- return this._intercept(async () => {
88
- const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([await this._getCommonFilter(info), options?.filter]);
89
- return this._delete(id, { ...options, filter });
90
- }, info);
88
+ return this._executeCommand(command, async () => {
89
+ const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([await this._getCommonFilter(command), command.options?.filter]);
90
+ command.options = { ...command.options, filter };
91
+ return this._delete(command);
92
+ });
91
93
  }
92
94
  /**
93
95
  * Deletes multiple documents from the collection that meet the specified filter criteria.
@@ -96,16 +98,17 @@ class SqbCollectionService extends sqb_entity_service_js_1.SqbEntityService {
96
98
  * @return {Promise<number>} - A promise that resolves to the number of documents deleted.
97
99
  */
98
100
  async deleteMany(options) {
99
- const info = {
101
+ const command = {
100
102
  crud: 'delete',
101
103
  method: 'deleteMany',
102
104
  byId: false,
103
105
  options,
104
106
  };
105
- return this._intercept(async () => {
106
- const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([await this._getCommonFilter(info), options?.filter]);
107
- return this._deleteMany({ ...options, filter });
108
- }, info);
107
+ return this._executeCommand(command, async () => {
108
+ const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([await this._getCommonFilter(command), command.options?.filter]);
109
+ command.options = { ...command.options, filter };
110
+ return this._deleteMany(command);
111
+ });
109
112
  }
110
113
  /**
111
114
  * Checks if a record with the given id exists.
@@ -115,17 +118,18 @@ class SqbCollectionService extends sqb_entity_service_js_1.SqbEntityService {
115
118
  * @return {Promise<boolean>} - A Promise that resolves to a boolean indicating whether the record exists or not.
116
119
  */
117
120
  async exists(id, options) {
118
- const info = {
121
+ const command = {
119
122
  crud: 'read',
120
123
  method: 'exists',
121
124
  byId: true,
122
125
  documentId: id,
123
126
  options,
124
127
  };
125
- return this._intercept(async () => {
126
- const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([await this._getCommonFilter(info), options?.filter]);
127
- return this._exists(id, { ...options, filter });
128
- }, info);
128
+ return this._executeCommand(command, async () => {
129
+ const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([await this._getCommonFilter(command), command.options?.filter]);
130
+ command.options = { ...command.options, filter };
131
+ return this._exists(command);
132
+ });
129
133
  }
130
134
  /**
131
135
  * Checks if a record with the given arguments exists.
@@ -134,37 +138,39 @@ class SqbCollectionService extends sqb_entity_service_js_1.SqbEntityService {
134
138
  * @return {Promise<boolean>} - A Promise that resolves to a boolean indicating whether the record exists or not.
135
139
  */
136
140
  async existsOne(options) {
137
- const info = {
141
+ const command = {
138
142
  crud: 'read',
139
143
  method: 'existsOne',
140
144
  byId: false,
141
145
  options,
142
146
  };
143
- return this._intercept(async () => {
144
- const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([await this._getCommonFilter(info), options?.filter]);
145
- return this._existsOne({ ...options, filter });
146
- }, info);
147
+ return this._executeCommand(command, async () => {
148
+ const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([await this._getCommonFilter(command), command.options?.filter]);
149
+ command.options = { ...command.options, filter };
150
+ return this._existsOne(command);
151
+ });
147
152
  }
148
153
  /**
149
154
  * Finds a record by ID.
150
155
  *
151
- * @param {SQBAdapter.Id} id - The ID of the record.
156
+ * @param {SQBAdapter.IdOrIds} id - The ID of the record.
152
157
  * @param {SqbCollectionService.FindOneOptions} [options] - The options for the find query.
153
158
  * @return {Promise<PartialDTO<T | undefined>>} - A promise resolving to the found document, or undefined if not found.
154
159
  */
155
160
  async findById(id, options) {
156
- const info = {
161
+ const command = {
157
162
  crud: 'read',
158
163
  method: 'findById',
159
164
  byId: true,
160
165
  documentId: id,
161
166
  options,
162
167
  };
163
- return this._intercept(async () => {
164
- const documentFilter = await this._getCommonFilter(info);
165
- const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([documentFilter, options?.filter]);
166
- return this._findById(id, { ...options, filter });
167
- }, info);
168
+ return this._executeCommand(command, async () => {
169
+ const documentFilter = await this._getCommonFilter(command);
170
+ const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([documentFilter, command.options?.filter]);
171
+ command.options = { ...command.options, filter };
172
+ return this._findById(command);
173
+ });
168
174
  }
169
175
  /**
170
176
  * Finds a record in the collection that matches the specified options.
@@ -173,16 +179,17 @@ class SqbCollectionService extends sqb_entity_service_js_1.SqbEntityService {
173
179
  * @return {Promise<PartialDTO<T> | undefined>} A promise that resolves with the found document or undefined if no document is found.
174
180
  */
175
181
  async findOne(options) {
176
- const info = {
182
+ const command = {
177
183
  crud: 'read',
178
184
  method: 'findOne',
179
185
  byId: false,
180
186
  options,
181
187
  };
182
- return this._intercept(async () => {
183
- const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([await this._getCommonFilter(info), options?.filter]);
184
- return this._findOne({ ...options, filter });
185
- }, info);
188
+ return this._executeCommand(command, async () => {
189
+ const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([await this._getCommonFilter(command), command.options?.filter]);
190
+ command.options = { ...command.options, filter };
191
+ return this._findOne(command);
192
+ });
186
193
  }
187
194
  /**
188
195
  * Finds multiple records in collection.
@@ -191,16 +198,17 @@ class SqbCollectionService extends sqb_entity_service_js_1.SqbEntityService {
191
198
  * @return A Promise that resolves to an array of partial outputs of type T.
192
199
  */
193
200
  async findMany(options) {
194
- const info = {
201
+ const command = {
195
202
  crud: 'read',
196
203
  method: 'findMany',
197
204
  byId: false,
198
205
  options,
199
206
  };
200
- return this._intercept(async () => {
201
- const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([await this._getCommonFilter(info), options?.filter]);
202
- return this._findMany({ ...options, filter });
203
- }, info);
207
+ return this._executeCommand(command, async () => {
208
+ const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([await this._getCommonFilter(command), command.options?.filter]);
209
+ command.options = { ...command.options, filter };
210
+ return this._findMany(command);
211
+ });
204
212
  }
205
213
  /**
206
214
  * Finds multiple records in the collection and returns both records (max limit)
@@ -216,7 +224,7 @@ class SqbCollectionService extends sqb_entity_service_js_1.SqbEntityService {
216
224
  /**
217
225
  * Retrieves a records from the collection by its ID. Throws error if not found.
218
226
  *
219
- * @param {SQBAdapter.Id} id - The ID of the document to retrieve.
227
+ * @param {SQBAdapter.IdOrIds} id - The ID of the document to retrieve.
220
228
  * @param {SqbCollectionService.FindOneOptions} [options] - Optional options for the findOne operation.
221
229
  * @returns {Promise<PartialDTO<T>>} - A promise that resolves to the retrieved document,
222
230
  * or rejects with a ResourceNotFoundError if the document does not exist.
@@ -238,7 +246,7 @@ class SqbCollectionService extends sqb_entity_service_js_1.SqbEntityService {
238
246
  * undefined if the document was not found.
239
247
  */
240
248
  async update(id, input, options) {
241
- const info = {
249
+ const command = {
242
250
  crud: 'update',
243
251
  method: 'update',
244
252
  documentId: id,
@@ -246,10 +254,11 @@ class SqbCollectionService extends sqb_entity_service_js_1.SqbEntityService {
246
254
  input,
247
255
  options,
248
256
  };
249
- return this._intercept(async () => {
250
- const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([await this._getCommonFilter(info), options?.filter]);
251
- return this._update(id, input, { ...options, filter });
252
- }, info);
257
+ return this._executeCommand(command, async () => {
258
+ const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([await this._getCommonFilter(command), command.options?.filter]);
259
+ command.options = { ...command.options, filter };
260
+ return this._update(command);
261
+ });
253
262
  }
254
263
  /**
255
264
  * Updates a record in the collection with the specified ID and returns updated record count
@@ -260,7 +269,7 @@ class SqbCollectionService extends sqb_entity_service_js_1.SqbEntityService {
260
269
  * @returns {Promise<number>} - A promise that resolves to the number of documents modified.
261
270
  */
262
271
  async updateOnly(id, input, options) {
263
- const info = {
272
+ const command = {
264
273
  crud: 'update',
265
274
  method: 'update',
266
275
  documentId: id,
@@ -268,10 +277,11 @@ class SqbCollectionService extends sqb_entity_service_js_1.SqbEntityService {
268
277
  input,
269
278
  options,
270
279
  };
271
- return this._intercept(async () => {
272
- const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([await this._getCommonFilter(info), options?.filter]);
273
- return this._updateOnly(id, input, { ...options, filter });
274
- }, info);
280
+ return this._executeCommand(command, async () => {
281
+ const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([await this._getCommonFilter(command), command.options?.filter]);
282
+ command.options = { ...command.options, filter };
283
+ return this._updateOnly(command);
284
+ });
275
285
  }
276
286
  /**
277
287
  * Updates multiple records in the collection based on the specified input and options.
@@ -281,17 +291,18 @@ class SqbCollectionService extends sqb_entity_service_js_1.SqbEntityService {
281
291
  * @return {Promise<number>} - A promise that resolves to the number of documents matched and modified.
282
292
  */
283
293
  async updateMany(input, options) {
284
- const info = {
294
+ const command = {
285
295
  crud: 'update',
286
296
  method: 'updateMany',
287
297
  byId: false,
288
298
  input,
289
299
  options,
290
300
  };
291
- return this._intercept(async () => {
292
- const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([await this._getCommonFilter(info), options?.filter]);
293
- return this._updateMany(input, { ...options, filter });
294
- }, info);
301
+ return this._executeCommand(command, async () => {
302
+ const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([await this._getCommonFilter(command), command.options?.filter]);
303
+ command.options = { ...command.options, filter };
304
+ return this._updateMany(command);
305
+ });
295
306
  }
296
307
  }
297
308
  exports.SqbCollectionService = SqbCollectionService;
@@ -4,6 +4,7 @@ exports.SqbEntityService = void 0;
4
4
  const common_1 = require("@opra/common");
5
5
  const core_1 = require("@opra/core");
6
6
  const connect_1 = require("@sqb/connect");
7
+ const valgen_1 = require("valgen");
7
8
  const sqb_adapter_js_1 = require("./sqb-adapter.js");
8
9
  /**
9
10
  * @class SqbEntityService
@@ -23,9 +24,9 @@ class SqbEntityService extends core_1.ServiceBase {
23
24
  this._outputCodecs = {};
24
25
  this._dataType_ = dataType;
25
26
  this.db = options?.db;
26
- this.$resourceName = options?.resourceName;
27
- this.$commonFilter = this.$commonFilter || options?.commonFilter;
28
- this.$interceptor = this.$interceptor || options?.interceptor;
27
+ this.resourceName = options?.resourceName;
28
+ this.commonFilter = options?.commonFilter;
29
+ this.interceptor = options?.interceptor;
29
30
  }
30
31
  /**
31
32
  * Retrieves the OPRA data type
@@ -69,7 +70,7 @@ class SqbEntityService extends core_1.ServiceBase {
69
70
  * @throws {Error} If the collection name is not defined.
70
71
  */
71
72
  getResourceName() {
72
- const out = typeof this.$resourceName === 'function' ? this.$resourceName(this) : this.$resourceName || this.dataType.name;
73
+ const out = typeof this.resourceName === 'function' ? this.resourceName(this) : this.resourceName || this.dataType.name;
73
74
  if (out)
74
75
  return out;
75
76
  throw new Error('resourceName is not defined');
@@ -107,13 +108,13 @@ class SqbEntityService extends core_1.ServiceBase {
107
108
  /**
108
109
  * Insert a new record into database
109
110
  *
110
- * @param {PartialDTO<T>} input - The input data
111
- * @param {SqbEntityService.CreateOptions} [options] - The options object
112
- * @returns {Promise<PartialDTO<T>>} A promise that resolves to the created resource
113
- * @throws {InternalServerError} if an unknown error occurs while creating the resource
111
+ * @param command
112
+ * @returns - A promise that resolves to the created resource
114
113
  * @protected
115
114
  */
116
- async _create(input, options) {
115
+ async _create(command) {
116
+ const { input, options } = command;
117
+ (0, valgen_1.isNotNullish)(command.input, { label: 'input' });
117
118
  const inputCodec = this.getInputCodec('create');
118
119
  const outputCodec = this.getOutputCodec('create');
119
120
  const data = inputCodec(input);
@@ -125,90 +126,89 @@ class SqbEntityService extends core_1.ServiceBase {
125
126
  /**
126
127
  * Returns the count of records based on the provided options
127
128
  *
128
- * @param {SqbEntityService.CountOptions} options - The options for the count operation.
129
- * @return {Promise<number>} - A promise that resolves to the count of records
129
+ * @param command
130
+ * @return - A promise that resolves to the count of records
130
131
  * @protected
131
132
  */
132
- async _count(options) {
133
- return this._dbCount(options);
133
+ async _count(command) {
134
+ return this._dbCount(command.options);
134
135
  }
135
136
  /**
136
137
  * Deletes a record from the collection.
137
138
  *
138
- * @param {SQBAdapter.IdOrIds} id - The ID of the document to delete.
139
- * @param {SqbEntityService.DeleteOptions} [options] - Optional delete options.
140
- * @return {Promise<number>} - A Promise that resolves to the number of documents deleted.
139
+ * @param command
140
+ * @return - A Promise that resolves to the number of documents deleted.
141
141
  * @protected
142
142
  */
143
- async _delete(id, options) {
144
- return this._dbDelete(id, options);
143
+ async _delete(command) {
144
+ (0, valgen_1.isNotNullish)(command.documentId, { label: 'documentId' });
145
+ return this._dbDelete(command.documentId, command.options);
145
146
  }
146
147
  /**
147
148
  * Deletes multiple documents from the collection that meet the specified filter criteria.
148
149
  *
149
- * @param {SqbEntityService.DeleteManyOptions} options - The options for the delete operation.
150
- * @return {Promise<number>} - A promise that resolves to the number of documents deleted.
150
+ * @param command
151
+ * @return - A promise that resolves to the number of documents deleted.
151
152
  * @protected
152
153
  */
153
- async _deleteMany(options) {
154
- return await this._dbDeleteMany(options);
154
+ async _deleteMany(command) {
155
+ return await this._dbDeleteMany(command.options);
155
156
  }
156
157
  /**
157
158
  * Checks if a record with the given id exists.
158
159
  *
159
- * @param {SQBAdapter.IdOrIds} id - The id of the object to check.
160
- * @param {SqbEntityService.ExistsOptions} [options] - The options for the query (optional).
161
- * @return {Promise<boolean>} - A Promise that resolves to a boolean indicating whether the record exists or not.
160
+ * @param command
162
161
  * @protected
163
162
  */
164
- async _exists(id, options) {
165
- return await this._dbExists(id, options);
163
+ async _exists(command) {
164
+ (0, valgen_1.isNotNullish)(command.documentId, { label: 'documentId' });
165
+ return await this._dbExists(command.documentId, command.options);
166
166
  }
167
167
  /**
168
168
  * Checks if a record with the given arguments exists.
169
169
  *
170
- * @param {SqbEntityService.ExistsOneOptions} [options] - The options for the query (optional).
171
- * @return {Promise<boolean>} - A Promise that resolves to a boolean indicating whether the record exists or not.
170
+ * @param command
171
+ * @return - A Promise that resolves to a boolean indicating whether the record exists or not.
172
172
  * @protected
173
173
  */
174
- async _existsOne(options) {
175
- return await this._dbExistsOne(options);
174
+ async _existsOne(command) {
175
+ return await this._dbExistsOne(command.options);
176
176
  }
177
177
  /**
178
178
  * Finds a record by ID.
179
179
  *
180
- * @param {SQBAdapter.Id} id - The ID of the record.
181
- * @param {SqbEntityService.FindOneOptions} [options] - The options for the find query.
182
- * @return {Promise<PartialDTO<T | undefined>>} - A promise resolving to the found document, or undefined if not found.
180
+ * @param command
181
+ * @return - A promise resolving to the found document, or undefined if not found.
183
182
  * @protected
184
183
  */
185
- async _findById(id, options) {
184
+ async _findById(command) {
185
+ (0, valgen_1.isNotNullish)(command.documentId, { label: 'documentId' });
186
186
  const decode = this.getOutputCodec('find');
187
- const out = await this._dbFindById(id, options);
187
+ const out = await this._dbFindById(command.documentId, command.options);
188
188
  return out ? decode(out) : undefined;
189
189
  }
190
190
  /**
191
191
  * Finds a record in the collection that matches the specified options.
192
192
  *
193
- * @param {SqbEntityService.FindOneOptions} [options] - The options for the query.
194
- * @return {Promise<PartialDTO<T> | undefined>} A promise that resolves with the found document or undefined if no document is found.
193
+ * @param command
194
+ * @return - A promise that resolves with the found document or undefined if no document is found.
195
195
  * @protected
196
196
  */
197
- async _findOne(options) {
197
+ async _findOne(command) {
198
198
  const decode = this.getOutputCodec('find');
199
- const out = await this._dbFindOne(options);
199
+ const out = await this._dbFindOne(command.options);
200
200
  return out ? decode(out) : undefined;
201
201
  }
202
202
  /**
203
203
  * Finds multiple records in collection.
204
204
  *
205
- * @param {SqbEntityService.FindManyOptions} [options] - The options for the find operation.
206
- * @return A Promise that resolves to an array of partial outputs of type T.
205
+ * @param command
206
+ * @return - A Promise that resolves to an array of partial outputs of type T.
207
207
  * @protected
208
208
  */
209
- async _findMany(options) {
209
+ async _findMany(command) {
210
210
  const decode = this.getOutputCodec('find');
211
- const out = await this._dbFindMany(options);
211
+ const out = await this._dbFindMany(command.options);
212
212
  if (out?.length) {
213
213
  return out.map(x => decode(x));
214
214
  }
@@ -217,17 +217,17 @@ class SqbEntityService extends core_1.ServiceBase {
217
217
  /**
218
218
  * Updates a record with the given id in the collection.
219
219
  *
220
- * @param {SQBAdapter.IdOrIds} id - The id of the document to update.
221
- * @param {PatchDTO<T>} input - The partial input object containing the fields to update.
222
- * @param {SqbEntityService.UpdateOptions} [options] - The options for the update operation.
223
- * @returns {Promise<PartialDTO<T> | undefined>} A promise that resolves to the updated document or
224
- * undefined if the document was not found.
220
+ * @param command
221
+ * @returns A promise that resolves to the updated document or undefined if the document was not found.
225
222
  * @protected
226
223
  */
227
- async _update(id, input, options) {
224
+ async _update(command) {
225
+ (0, valgen_1.isNotNullish)(command.documentId, { label: 'documentId' });
226
+ (0, valgen_1.isNotNullish)(command.input, { label: 'input' });
227
+ const { documentId, input, options } = command;
228
228
  const inputCodec = this.getInputCodec('update');
229
229
  const data = inputCodec(input);
230
- const out = await this._dbUpdate(id, data, options);
230
+ const out = await this._dbUpdate(documentId, data, options);
231
231
  const outputCodec = this.getOutputCodec('update');
232
232
  if (out)
233
233
  return outputCodec(out);
@@ -235,29 +235,30 @@ class SqbEntityService extends core_1.ServiceBase {
235
235
  /**
236
236
  * Updates a record in the collection with the specified ID and returns updated record count
237
237
  *
238
- * @param {any} id - The ID of the document to update.
239
- * @param {PatchDTO<T>} input - The partial input data to update the document with.
240
- * @param {SqbEntityService.UpdateOptions} options - The options for updating the document.
241
- * @returns {Promise<number>} - A promise that resolves to the number of documents modified.
238
+ * @param command
239
+ * @returns - A promise that resolves to the number of documents modified.
242
240
  * @protected
243
241
  */
244
- async _updateOnly(id, input, options) {
242
+ async _updateOnly(command) {
243
+ (0, valgen_1.isNotNullish)(command.documentId, { label: 'documentId' });
244
+ (0, valgen_1.isNotNullish)(command.input, { label: 'input' });
245
+ const { documentId, input, options } = command;
245
246
  const inputCodec = this.getInputCodec('update');
246
247
  const data = inputCodec(input);
247
- return await this._dbUpdateOnly(id, data, options);
248
+ return await this._dbUpdateOnly(documentId, data, options);
248
249
  }
249
250
  /**
250
251
  * Updates multiple records in the collection based on the specified input and options.
251
252
  *
252
- * @param {PatchDTO<T>} input - The partial input to update the documents with.
253
- * @param {SqbEntityService.UpdateManyOptions} options - The options for updating the documents.
254
- * @return {Promise<number>} - A promise that resolves to the number of documents matched and modified.
253
+ * @param command
254
+ * @return - A promise that resolves to the number of documents matched and modified.
255
255
  * @protected
256
256
  */
257
- async _updateMany(input, options) {
257
+ async _updateMany(command) {
258
+ (0, valgen_1.isNotNullish)(command.input, { label: 'input' });
258
259
  const inputCodec = this.getInputCodec('update');
259
- const data = inputCodec(input);
260
- return await this._dbUpdateMany(data, options);
260
+ const data = inputCodec(command.input);
261
+ return await this._dbUpdateMany(data, command.options);
261
262
  }
262
263
  /**
263
264
  * Acquires a connection and performs Repository.create operation
@@ -444,17 +445,28 @@ class SqbEntityService extends core_1.ServiceBase {
444
445
  * that resolves to the common filter, or undefined if not available.
445
446
  */
446
447
  _getCommonFilter(args) {
447
- return typeof this.$commonFilter === 'function' ? this.$commonFilter(args, this) : this.$commonFilter;
448
- }
449
- async _intercept(callback, args) {
448
+ return typeof this.commonFilter === 'function' ? this.commonFilter(args, this) : this.commonFilter;
449
+ }
450
+ async _executeCommand(command, commandFn) {
451
+ let proto;
452
+ const next = async () => {
453
+ proto = proto ? Object.getPrototypeOf(proto) : this;
454
+ while (proto) {
455
+ if (proto.interceptor) {
456
+ return await proto.interceptor.call(this, next, command, this);
457
+ }
458
+ proto = Object.getPrototypeOf(proto);
459
+ if (!(proto instanceof SqbEntityService))
460
+ break;
461
+ }
462
+ return commandFn();
463
+ };
450
464
  try {
451
- if (this.$interceptor)
452
- return this.$interceptor(callback, args, this);
453
- return callback();
465
+ return await next();
454
466
  }
455
467
  catch (e) {
456
- Error.captureStackTrace(e, this._intercept);
457
- await this.$onError?.(e, this);
468
+ Error.captureStackTrace(e, this._executeCommand);
469
+ await this.onError?.(e, this);
458
470
  throw e;
459
471
  }
460
472
  }