@opra/mongodb 1.4.2 → 1.4.4
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.
- package/cjs/adapter/mongo-adapter.js +41 -12
- package/cjs/adapter/mongo-patch-generator.js +14 -4
- package/cjs/adapter/prepare-filter.js +11 -3
- package/cjs/adapter/prepare-projection.js +8 -3
- package/cjs/services/mongo-collection-service.js +61 -15
- package/cjs/services/mongo-entity-service.js +36 -12
- package/cjs/services/mongo-nested-service.js +137 -37
- package/cjs/services/mongo-service.js +25 -10
- package/cjs/services/mongo-singleton-service.js +20 -5
- package/esm/adapter/mongo-adapter.js +41 -12
- package/esm/adapter/mongo-patch-generator.js +14 -4
- package/esm/adapter/prepare-filter.js +11 -3
- package/esm/adapter/prepare-projection.js +9 -4
- package/esm/services/mongo-collection-service.js +61 -15
- package/esm/services/mongo-entity-service.js +36 -12
- package/esm/services/mongo-nested-service.js +138 -38
- package/esm/services/mongo-service.js +26 -11
- package/esm/services/mongo-singleton-service.js +20 -5
- package/package.json +4 -4
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import { ComplexType, parseFieldsProjection } from '@opra/common';
|
|
1
|
+
import { ComplexType, parseFieldsProjection, } from '@opra/common';
|
|
2
2
|
export default function prepareProjection(dataType, projection) {
|
|
3
3
|
if (projection === '*')
|
|
4
4
|
return undefined;
|
|
5
|
-
if (projection &&
|
|
5
|
+
if (projection &&
|
|
6
|
+
typeof projection === 'object' &&
|
|
7
|
+
!Array.isArray(projection))
|
|
6
8
|
return projection;
|
|
7
9
|
const out = {};
|
|
8
|
-
const projection_ = typeof projection === 'string' || Array.isArray(projection)
|
|
10
|
+
const projection_ = typeof projection === 'string' || Array.isArray(projection)
|
|
11
|
+
? parseFieldsProjection(projection)
|
|
12
|
+
: projection;
|
|
9
13
|
// const exclusionProjection = !pick && !!omit;
|
|
10
14
|
prepare(dataType, out, projection_);
|
|
11
15
|
return Object.keys(out).length ? out : undefined;
|
|
@@ -32,7 +36,8 @@ export function prepare(dataType, target, projection) {
|
|
|
32
36
|
(defaultFields && field.exclusive && !p)) {
|
|
33
37
|
continue;
|
|
34
38
|
}
|
|
35
|
-
if (field.type instanceof ComplexType &&
|
|
39
|
+
if (field.type instanceof ComplexType &&
|
|
40
|
+
typeof p?.projection === 'object') {
|
|
36
41
|
target[fieldName] = {};
|
|
37
42
|
prepare(field.type, target[fieldName], p.projection);
|
|
38
43
|
continue;
|
|
@@ -38,7 +38,10 @@ export class MongoCollectionService extends MongoEntityService {
|
|
|
38
38
|
input,
|
|
39
39
|
options,
|
|
40
40
|
};
|
|
41
|
-
input._id =
|
|
41
|
+
input._id =
|
|
42
|
+
input._id == null || input._id === ''
|
|
43
|
+
? this._generateId(command)
|
|
44
|
+
: input._id;
|
|
42
45
|
return this._executeCommand(command, async () => {
|
|
43
46
|
const r = await this._create(command);
|
|
44
47
|
const findCommand = {
|
|
@@ -69,7 +72,10 @@ export class MongoCollectionService extends MongoEntityService {
|
|
|
69
72
|
return this._executeCommand(command, async () => {
|
|
70
73
|
const documentFilter = await this._getDocumentFilter(command);
|
|
71
74
|
if (documentFilter) {
|
|
72
|
-
const filter = MongoAdapter.prepareFilter([
|
|
75
|
+
const filter = MongoAdapter.prepareFilter([
|
|
76
|
+
documentFilter,
|
|
77
|
+
command.options?.filter,
|
|
78
|
+
]);
|
|
73
79
|
command.options = { ...command.options, filter };
|
|
74
80
|
}
|
|
75
81
|
return this._count(command);
|
|
@@ -93,7 +99,10 @@ export class MongoCollectionService extends MongoEntityService {
|
|
|
93
99
|
return this._executeCommand(command, async () => {
|
|
94
100
|
const documentFilter = await this._getDocumentFilter(command);
|
|
95
101
|
if (documentFilter) {
|
|
96
|
-
const filter = MongoAdapter.prepareFilter([
|
|
102
|
+
const filter = MongoAdapter.prepareFilter([
|
|
103
|
+
documentFilter,
|
|
104
|
+
command.options?.filter,
|
|
105
|
+
]);
|
|
97
106
|
command.options = { ...command.options, filter };
|
|
98
107
|
}
|
|
99
108
|
return this._delete(command);
|
|
@@ -115,7 +124,10 @@ export class MongoCollectionService extends MongoEntityService {
|
|
|
115
124
|
return this._executeCommand(command, async () => {
|
|
116
125
|
const documentFilter = await this._getDocumentFilter(command);
|
|
117
126
|
if (documentFilter) {
|
|
118
|
-
const filter = MongoAdapter.prepareFilter([
|
|
127
|
+
const filter = MongoAdapter.prepareFilter([
|
|
128
|
+
documentFilter,
|
|
129
|
+
command.options?.filter,
|
|
130
|
+
]);
|
|
119
131
|
command.options = { ...command.options, filter };
|
|
120
132
|
}
|
|
121
133
|
return this._deleteMany(command);
|
|
@@ -138,7 +150,10 @@ export class MongoCollectionService extends MongoEntityService {
|
|
|
138
150
|
return this._executeCommand(command, async () => {
|
|
139
151
|
const documentFilter = await this._getDocumentFilter(command);
|
|
140
152
|
if (documentFilter) {
|
|
141
|
-
const filter = MongoAdapter.prepareFilter([
|
|
153
|
+
const filter = MongoAdapter.prepareFilter([
|
|
154
|
+
documentFilter,
|
|
155
|
+
command.options?.filter,
|
|
156
|
+
]);
|
|
142
157
|
command.options = { ...command.options, filter };
|
|
143
158
|
}
|
|
144
159
|
return this._distinct(command);
|
|
@@ -163,8 +178,15 @@ export class MongoCollectionService extends MongoEntityService {
|
|
|
163
178
|
const findCommand = command;
|
|
164
179
|
const documentFilter = await this._getDocumentFilter(command);
|
|
165
180
|
if (documentFilter) {
|
|
166
|
-
const filter = MongoAdapter.prepareFilter([
|
|
167
|
-
|
|
181
|
+
const filter = MongoAdapter.prepareFilter([
|
|
182
|
+
documentFilter,
|
|
183
|
+
command.options?.filter,
|
|
184
|
+
]);
|
|
185
|
+
findCommand.options = {
|
|
186
|
+
...command.options,
|
|
187
|
+
filter,
|
|
188
|
+
projection: ['_id'],
|
|
189
|
+
};
|
|
168
190
|
}
|
|
169
191
|
return !!(await this._findById(findCommand));
|
|
170
192
|
});
|
|
@@ -189,7 +211,10 @@ export class MongoCollectionService extends MongoEntityService {
|
|
|
189
211
|
return this._executeCommand(command, async () => {
|
|
190
212
|
const documentFilter = await this._getDocumentFilter(command);
|
|
191
213
|
if (documentFilter) {
|
|
192
|
-
const filter = MongoAdapter.prepareFilter([
|
|
214
|
+
const filter = MongoAdapter.prepareFilter([
|
|
215
|
+
documentFilter,
|
|
216
|
+
command.options?.filter,
|
|
217
|
+
]);
|
|
193
218
|
command.options = { ...command.options, filter };
|
|
194
219
|
}
|
|
195
220
|
return this._findById(command);
|
|
@@ -205,7 +230,10 @@ export class MongoCollectionService extends MongoEntityService {
|
|
|
205
230
|
return this._executeCommand(command, async () => {
|
|
206
231
|
const documentFilter = await this._getDocumentFilter(command);
|
|
207
232
|
if (documentFilter) {
|
|
208
|
-
const filter = MongoAdapter.prepareFilter([
|
|
233
|
+
const filter = MongoAdapter.prepareFilter([
|
|
234
|
+
documentFilter,
|
|
235
|
+
command.options?.filter,
|
|
236
|
+
]);
|
|
209
237
|
command.options = { ...command.options, filter };
|
|
210
238
|
}
|
|
211
239
|
return this._findOne(command);
|
|
@@ -222,7 +250,10 @@ export class MongoCollectionService extends MongoEntityService {
|
|
|
222
250
|
const documentFilter = await this._getDocumentFilter(command);
|
|
223
251
|
command.options = command.options || {};
|
|
224
252
|
if (documentFilter) {
|
|
225
|
-
command.options.filter = MongoAdapter.prepareFilter([
|
|
253
|
+
command.options.filter = MongoAdapter.prepareFilter([
|
|
254
|
+
documentFilter,
|
|
255
|
+
command.options?.filter,
|
|
256
|
+
]);
|
|
226
257
|
}
|
|
227
258
|
const limit = command.options?.limit || this.defaultLimit;
|
|
228
259
|
if (limit)
|
|
@@ -241,7 +272,10 @@ export class MongoCollectionService extends MongoEntityService {
|
|
|
241
272
|
const documentFilter = await this._getDocumentFilter(command);
|
|
242
273
|
command.options = command.options || {};
|
|
243
274
|
if (documentFilter) {
|
|
244
|
-
command.options.filter = MongoAdapter.prepareFilter([
|
|
275
|
+
command.options.filter = MongoAdapter.prepareFilter([
|
|
276
|
+
documentFilter,
|
|
277
|
+
command.options?.filter,
|
|
278
|
+
]);
|
|
245
279
|
}
|
|
246
280
|
const limit = command.options?.limit || this.defaultLimit;
|
|
247
281
|
if (limit)
|
|
@@ -268,7 +302,10 @@ export class MongoCollectionService extends MongoEntityService {
|
|
|
268
302
|
return this._executeCommand(command, async () => {
|
|
269
303
|
const documentFilter = await this._getDocumentFilter(command);
|
|
270
304
|
if (documentFilter) {
|
|
271
|
-
const filter = MongoAdapter.prepareFilter([
|
|
305
|
+
const filter = MongoAdapter.prepareFilter([
|
|
306
|
+
documentFilter,
|
|
307
|
+
command.options?.filter,
|
|
308
|
+
]);
|
|
272
309
|
command.options = { ...command.options, filter };
|
|
273
310
|
}
|
|
274
311
|
return await this._replace(command);
|
|
@@ -288,7 +325,10 @@ export class MongoCollectionService extends MongoEntityService {
|
|
|
288
325
|
return this._executeCommand(command, async () => {
|
|
289
326
|
const documentFilter = await this._getDocumentFilter(command);
|
|
290
327
|
if (documentFilter) {
|
|
291
|
-
const filter = MongoAdapter.prepareFilter([
|
|
328
|
+
const filter = MongoAdapter.prepareFilter([
|
|
329
|
+
documentFilter,
|
|
330
|
+
command.options?.filter,
|
|
331
|
+
]);
|
|
292
332
|
command.options = { ...command.options, filter };
|
|
293
333
|
}
|
|
294
334
|
return this._update(command);
|
|
@@ -316,7 +356,10 @@ export class MongoCollectionService extends MongoEntityService {
|
|
|
316
356
|
return this._executeCommand(command, async () => {
|
|
317
357
|
const documentFilter = await this._getDocumentFilter(command);
|
|
318
358
|
if (documentFilter) {
|
|
319
|
-
const filter = MongoAdapter.prepareFilter([
|
|
359
|
+
const filter = MongoAdapter.prepareFilter([
|
|
360
|
+
documentFilter,
|
|
361
|
+
command.options?.filter,
|
|
362
|
+
]);
|
|
320
363
|
command.options = { ...command.options, filter };
|
|
321
364
|
}
|
|
322
365
|
return this._updateOnly(command);
|
|
@@ -342,7 +385,10 @@ export class MongoCollectionService extends MongoEntityService {
|
|
|
342
385
|
return this._executeCommand(command, async () => {
|
|
343
386
|
const documentFilter = await this._getDocumentFilter(command);
|
|
344
387
|
if (documentFilter) {
|
|
345
|
-
const filter = MongoAdapter.prepareFilter([
|
|
388
|
+
const filter = MongoAdapter.prepareFilter([
|
|
389
|
+
documentFilter,
|
|
390
|
+
command.options?.filter,
|
|
391
|
+
]);
|
|
346
392
|
command.options = { ...command.options, filter };
|
|
347
393
|
}
|
|
348
394
|
return this._updateMany(command);
|
|
@@ -461,52 +461,76 @@ export class MongoEntityService extends MongoService {
|
|
|
461
461
|
throw e;
|
|
462
462
|
}
|
|
463
463
|
}
|
|
464
|
+
async _beforeCreate(
|
|
464
465
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
465
|
-
|
|
466
|
+
command) {
|
|
466
467
|
// Do nothing
|
|
467
468
|
}
|
|
469
|
+
async _beforeDelete(
|
|
468
470
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
469
|
-
|
|
471
|
+
command) {
|
|
470
472
|
// Do nothing
|
|
471
473
|
}
|
|
474
|
+
async _beforeDeleteMany(
|
|
472
475
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
473
|
-
|
|
476
|
+
command) {
|
|
474
477
|
// Do nothing
|
|
475
478
|
}
|
|
479
|
+
async _beforeReplace(
|
|
476
480
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
477
|
-
|
|
481
|
+
command) {
|
|
478
482
|
// Do nothing
|
|
479
483
|
}
|
|
484
|
+
async _beforeUpdate(
|
|
480
485
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
481
|
-
|
|
486
|
+
command) {
|
|
482
487
|
// Do nothing
|
|
483
488
|
}
|
|
489
|
+
async _beforeUpdateMany(
|
|
484
490
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
485
|
-
|
|
491
|
+
command) {
|
|
486
492
|
// Do nothing
|
|
487
493
|
}
|
|
494
|
+
async _afterCreate(
|
|
488
495
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
489
|
-
|
|
496
|
+
command,
|
|
497
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
498
|
+
result) {
|
|
490
499
|
// Do nothing
|
|
491
500
|
}
|
|
501
|
+
async _afterReplace(
|
|
502
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
503
|
+
command,
|
|
492
504
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
493
|
-
|
|
505
|
+
result) {
|
|
494
506
|
// Do nothing
|
|
495
507
|
}
|
|
508
|
+
async _afterDelete(
|
|
509
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
510
|
+
command,
|
|
496
511
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
497
|
-
|
|
512
|
+
affected) {
|
|
498
513
|
// Do nothing
|
|
499
514
|
}
|
|
515
|
+
async _afterDeleteMany(
|
|
500
516
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
501
|
-
|
|
517
|
+
command,
|
|
518
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
519
|
+
affected) {
|
|
502
520
|
// Do nothing
|
|
503
521
|
}
|
|
522
|
+
async _afterUpdate(
|
|
523
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
524
|
+
command,
|
|
504
525
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
505
|
-
|
|
526
|
+
result) {
|
|
506
527
|
// Do nothing
|
|
507
528
|
}
|
|
529
|
+
async _afterUpdateMany(
|
|
530
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
531
|
+
command,
|
|
508
532
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
509
|
-
|
|
533
|
+
affected) {
|
|
510
534
|
// Do nothing
|
|
511
535
|
}
|
|
512
536
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { omit } from '@jsopen/objects';
|
|
2
|
-
import { ComplexType, NotAcceptableError, ResourceNotAvailableError } from '@opra/common';
|
|
2
|
+
import { ComplexType, NotAcceptableError, ResourceNotAvailableError, } from '@opra/common';
|
|
3
3
|
import { isNotNullish } from 'valgen';
|
|
4
4
|
import { MongoAdapter } from '../adapter/mongo-adapter.js';
|
|
5
5
|
import { MongoPatchGenerator } from '../adapter/mongo-patch-generator.js';
|
|
@@ -106,7 +106,8 @@ export class MongoNestedService extends MongoService {
|
|
|
106
106
|
options,
|
|
107
107
|
};
|
|
108
108
|
input[this.nestedKey] =
|
|
109
|
-
input[this.nestedKey] == null ||
|
|
109
|
+
input[this.nestedKey] == null ||
|
|
110
|
+
input[this.nestedKey] === ''
|
|
110
111
|
? this._generateId(command)
|
|
111
112
|
: input[this.nestedKey];
|
|
112
113
|
return this._executeCommand(command, () => this._create(command));
|
|
@@ -150,8 +151,13 @@ export class MongoNestedService extends MongoService {
|
|
|
150
151
|
options,
|
|
151
152
|
};
|
|
152
153
|
return this._executeCommand(command, async () => {
|
|
153
|
-
const documentFilter = MongoAdapter.prepareFilter([
|
|
154
|
-
|
|
154
|
+
const documentFilter = MongoAdapter.prepareFilter([
|
|
155
|
+
await this._getDocumentFilter(command),
|
|
156
|
+
]);
|
|
157
|
+
const filter = MongoAdapter.prepareFilter([
|
|
158
|
+
await this._getNestedFilter(command),
|
|
159
|
+
command.options?.filter,
|
|
160
|
+
]);
|
|
155
161
|
command.options = { ...command.options, filter, documentFilter };
|
|
156
162
|
return this._count(command);
|
|
157
163
|
});
|
|
@@ -204,8 +210,13 @@ export class MongoNestedService extends MongoService {
|
|
|
204
210
|
options,
|
|
205
211
|
};
|
|
206
212
|
return this._executeCommand(command, async () => {
|
|
207
|
-
const documentFilter = MongoAdapter.prepareFilter([
|
|
208
|
-
|
|
213
|
+
const documentFilter = MongoAdapter.prepareFilter([
|
|
214
|
+
await this._getDocumentFilter(command),
|
|
215
|
+
]);
|
|
216
|
+
const filter = MongoAdapter.prepareFilter([
|
|
217
|
+
await this._getNestedFilter(command),
|
|
218
|
+
command.options?.filter,
|
|
219
|
+
]);
|
|
209
220
|
command.options = { ...command.options, filter, documentFilter };
|
|
210
221
|
return this._delete(command);
|
|
211
222
|
});
|
|
@@ -218,7 +229,10 @@ export class MongoNestedService extends MongoService {
|
|
|
218
229
|
MongoAdapter.prepareKeyValues(documentId, ['_id']),
|
|
219
230
|
options?.documentFilter,
|
|
220
231
|
]);
|
|
221
|
-
const pullFilter = MongoAdapter.prepareFilter([
|
|
232
|
+
const pullFilter = MongoAdapter.prepareFilter([
|
|
233
|
+
MongoAdapter.prepareKeyValues(nestedId, [this.nestedKey]),
|
|
234
|
+
options?.filter,
|
|
235
|
+
]) || {};
|
|
222
236
|
const update = {
|
|
223
237
|
$pull: { [this.fieldName]: pullFilter },
|
|
224
238
|
};
|
|
@@ -247,8 +261,13 @@ export class MongoNestedService extends MongoService {
|
|
|
247
261
|
options,
|
|
248
262
|
};
|
|
249
263
|
return this._executeCommand(command, async () => {
|
|
250
|
-
const documentFilter = MongoAdapter.prepareFilter([
|
|
251
|
-
|
|
264
|
+
const documentFilter = MongoAdapter.prepareFilter([
|
|
265
|
+
await this._getDocumentFilter(command),
|
|
266
|
+
]);
|
|
267
|
+
const filter = MongoAdapter.prepareFilter([
|
|
268
|
+
await this._getNestedFilter(command),
|
|
269
|
+
command.options?.filter,
|
|
270
|
+
]);
|
|
252
271
|
command.options = { ...command.options, filter, documentFilter };
|
|
253
272
|
return this._deleteMany(command);
|
|
254
273
|
});
|
|
@@ -299,7 +318,9 @@ export class MongoNestedService extends MongoService {
|
|
|
299
318
|
options,
|
|
300
319
|
};
|
|
301
320
|
return this._executeCommand(command, async () => {
|
|
302
|
-
const documentFilter = MongoAdapter.prepareFilter([
|
|
321
|
+
const documentFilter = MongoAdapter.prepareFilter([
|
|
322
|
+
await this._getDocumentFilter(command),
|
|
323
|
+
]);
|
|
303
324
|
const filter = MongoAdapter.prepareFilter([
|
|
304
325
|
await this._getNestedFilter(command),
|
|
305
326
|
documentFilter,
|
|
@@ -326,9 +347,17 @@ export class MongoNestedService extends MongoService {
|
|
|
326
347
|
};
|
|
327
348
|
return this._executeCommand(command, async () => {
|
|
328
349
|
const documentFilter = await this._getDocumentFilter(command);
|
|
329
|
-
const filter = MongoAdapter.prepareFilter([
|
|
350
|
+
const filter = MongoAdapter.prepareFilter([
|
|
351
|
+
documentFilter,
|
|
352
|
+
command.options?.filter,
|
|
353
|
+
]);
|
|
330
354
|
const findCommand = command;
|
|
331
|
-
findCommand.options = {
|
|
355
|
+
findCommand.options = {
|
|
356
|
+
...command.options,
|
|
357
|
+
filter,
|
|
358
|
+
documentFilter,
|
|
359
|
+
projection: ['_id'],
|
|
360
|
+
};
|
|
332
361
|
return !!(await this._findOne(findCommand));
|
|
333
362
|
});
|
|
334
363
|
}
|
|
@@ -342,8 +371,13 @@ export class MongoNestedService extends MongoService {
|
|
|
342
371
|
options,
|
|
343
372
|
};
|
|
344
373
|
return this._executeCommand(command, async () => {
|
|
345
|
-
const documentFilter = MongoAdapter.prepareFilter([
|
|
346
|
-
|
|
374
|
+
const documentFilter = MongoAdapter.prepareFilter([
|
|
375
|
+
await this._getDocumentFilter(command),
|
|
376
|
+
]);
|
|
377
|
+
const filter = MongoAdapter.prepareFilter([
|
|
378
|
+
await this._getNestedFilter(command),
|
|
379
|
+
command.options?.filter,
|
|
380
|
+
]);
|
|
347
381
|
command.options = { ...command.options, filter, documentFilter };
|
|
348
382
|
return this._findById(command);
|
|
349
383
|
});
|
|
@@ -378,8 +412,13 @@ export class MongoNestedService extends MongoService {
|
|
|
378
412
|
options,
|
|
379
413
|
};
|
|
380
414
|
return this._executeCommand(command, async () => {
|
|
381
|
-
const documentFilter = MongoAdapter.prepareFilter([
|
|
382
|
-
|
|
415
|
+
const documentFilter = MongoAdapter.prepareFilter([
|
|
416
|
+
await this._getDocumentFilter(command),
|
|
417
|
+
]);
|
|
418
|
+
const filter = MongoAdapter.prepareFilter([
|
|
419
|
+
await this._getNestedFilter(command),
|
|
420
|
+
command.options?.filter,
|
|
421
|
+
]);
|
|
383
422
|
command.options = { ...command.options, filter, documentFilter };
|
|
384
423
|
return this._findOne(command);
|
|
385
424
|
});
|
|
@@ -435,7 +474,10 @@ export class MongoNestedService extends MongoService {
|
|
|
435
474
|
stages.push(...options.preStages);
|
|
436
475
|
/** Filter */
|
|
437
476
|
if (options?.filter || options?.nestedFilter) {
|
|
438
|
-
const optionsFilter = MongoAdapter.prepareFilter([
|
|
477
|
+
const optionsFilter = MongoAdapter.prepareFilter([
|
|
478
|
+
options?.filter,
|
|
479
|
+
options.nestedFilter,
|
|
480
|
+
]);
|
|
439
481
|
stages.push({ $match: optionsFilter });
|
|
440
482
|
}
|
|
441
483
|
/** Sort */
|
|
@@ -459,7 +501,15 @@ export class MongoNestedService extends MongoService {
|
|
|
459
501
|
const db = this.getDatabase();
|
|
460
502
|
const collection = await this.getCollection(db);
|
|
461
503
|
const cursor = collection.aggregate(stages, {
|
|
462
|
-
...omit(options, [
|
|
504
|
+
...omit(options, [
|
|
505
|
+
'documentFilter',
|
|
506
|
+
'nestedFilter',
|
|
507
|
+
'projection',
|
|
508
|
+
'sort',
|
|
509
|
+
'skip',
|
|
510
|
+
'limit',
|
|
511
|
+
'filter',
|
|
512
|
+
]),
|
|
463
513
|
session: options?.session ?? this.getSession(),
|
|
464
514
|
});
|
|
465
515
|
try {
|
|
@@ -516,7 +566,10 @@ export class MongoNestedService extends MongoService {
|
|
|
516
566
|
dataStages.push(...options.preStages);
|
|
517
567
|
/** Filter */
|
|
518
568
|
if (options?.filter || options?.nestedFilter) {
|
|
519
|
-
const optionsFilter = MongoAdapter.prepareFilter([
|
|
569
|
+
const optionsFilter = MongoAdapter.prepareFilter([
|
|
570
|
+
options?.filter,
|
|
571
|
+
options?.nestedFilter,
|
|
572
|
+
]);
|
|
520
573
|
dataStages.push({ $match: optionsFilter });
|
|
521
574
|
}
|
|
522
575
|
/** Sort */
|
|
@@ -540,7 +593,15 @@ export class MongoNestedService extends MongoService {
|
|
|
540
593
|
const db = this.getDatabase();
|
|
541
594
|
const collection = await this.getCollection(db);
|
|
542
595
|
const cursor = collection.aggregate(stages, {
|
|
543
|
-
...omit(options, [
|
|
596
|
+
...omit(options, [
|
|
597
|
+
'documentFilter',
|
|
598
|
+
'nestedFilter',
|
|
599
|
+
'projection',
|
|
600
|
+
'sort',
|
|
601
|
+
'skip',
|
|
602
|
+
'limit',
|
|
603
|
+
'filter',
|
|
604
|
+
]),
|
|
544
605
|
session: options?.session ?? this.getSession(),
|
|
545
606
|
});
|
|
546
607
|
try {
|
|
@@ -574,8 +635,13 @@ export class MongoNestedService extends MongoService {
|
|
|
574
635
|
options,
|
|
575
636
|
};
|
|
576
637
|
return this._executeCommand(command, async () => {
|
|
577
|
-
const documentFilter = MongoAdapter.prepareFilter([
|
|
578
|
-
|
|
638
|
+
const documentFilter = MongoAdapter.prepareFilter([
|
|
639
|
+
await this._getDocumentFilter(command),
|
|
640
|
+
]);
|
|
641
|
+
const filter = MongoAdapter.prepareFilter([
|
|
642
|
+
await this._getNestedFilter(command),
|
|
643
|
+
command.options?.filter,
|
|
644
|
+
]);
|
|
579
645
|
command.options = {
|
|
580
646
|
...command.options,
|
|
581
647
|
filter,
|
|
@@ -618,8 +684,13 @@ export class MongoNestedService extends MongoService {
|
|
|
618
684
|
options,
|
|
619
685
|
};
|
|
620
686
|
return this._executeCommand(command, async () => {
|
|
621
|
-
const documentFilter = MongoAdapter.prepareFilter([
|
|
622
|
-
|
|
687
|
+
const documentFilter = MongoAdapter.prepareFilter([
|
|
688
|
+
await this._getDocumentFilter(command),
|
|
689
|
+
]);
|
|
690
|
+
const filter = MongoAdapter.prepareFilter([
|
|
691
|
+
await this._getNestedFilter(command),
|
|
692
|
+
command.options?.filter,
|
|
693
|
+
]);
|
|
623
694
|
command.options = {
|
|
624
695
|
...command.options,
|
|
625
696
|
filter,
|
|
@@ -662,8 +733,13 @@ export class MongoNestedService extends MongoService {
|
|
|
662
733
|
options,
|
|
663
734
|
};
|
|
664
735
|
return this._executeCommand(command, async () => {
|
|
665
|
-
const documentFilter = MongoAdapter.prepareFilter([
|
|
666
|
-
|
|
736
|
+
const documentFilter = MongoAdapter.prepareFilter([
|
|
737
|
+
await this._getDocumentFilter(command),
|
|
738
|
+
]);
|
|
739
|
+
const filter = MongoAdapter.prepareFilter([
|
|
740
|
+
await this._getNestedFilter(command),
|
|
741
|
+
command.options?.filter,
|
|
742
|
+
]);
|
|
667
743
|
command.options = { ...command.options, filter, documentFilter };
|
|
668
744
|
return this._updateMany(command);
|
|
669
745
|
});
|
|
@@ -682,7 +758,9 @@ export class MongoNestedService extends MongoService {
|
|
|
682
758
|
{ [this.fieldName]: { $exists: true } },
|
|
683
759
|
]);
|
|
684
760
|
if (options?.filter) {
|
|
685
|
-
const elemMatch = MongoAdapter.prepareFilter([options?.filter], {
|
|
761
|
+
const elemMatch = MongoAdapter.prepareFilter([options?.filter], {
|
|
762
|
+
fieldPrefix: 'elem.',
|
|
763
|
+
});
|
|
686
764
|
options.arrayFilters = [elemMatch];
|
|
687
765
|
}
|
|
688
766
|
const patchGenerator = new MongoPatchGenerator();
|
|
@@ -720,7 +798,9 @@ export class MongoNestedService extends MongoService {
|
|
|
720
798
|
* that resolves to the common filter, or undefined if not available.
|
|
721
799
|
*/
|
|
722
800
|
_getNestedFilter(args) {
|
|
723
|
-
return typeof this.nestedFilter === 'function'
|
|
801
|
+
return typeof this.nestedFilter === 'function'
|
|
802
|
+
? this.nestedFilter(args, this)
|
|
803
|
+
: this.nestedFilter;
|
|
724
804
|
}
|
|
725
805
|
async _executeCommand(command, commandFn) {
|
|
726
806
|
try {
|
|
@@ -766,44 +846,64 @@ export class MongoNestedService extends MongoService {
|
|
|
766
846
|
throw e;
|
|
767
847
|
}
|
|
768
848
|
}
|
|
849
|
+
async _beforeCreate(
|
|
769
850
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
770
|
-
|
|
851
|
+
command) {
|
|
771
852
|
// Do nothing
|
|
772
853
|
}
|
|
854
|
+
async _beforeUpdate(
|
|
773
855
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
774
|
-
|
|
856
|
+
command) {
|
|
775
857
|
// Do nothing
|
|
776
858
|
}
|
|
859
|
+
async _beforeUpdateMany(
|
|
777
860
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
778
|
-
|
|
861
|
+
command) {
|
|
779
862
|
// Do nothing
|
|
780
863
|
}
|
|
864
|
+
async _beforeDelete(
|
|
781
865
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
782
|
-
|
|
866
|
+
command) {
|
|
783
867
|
// Do nothing
|
|
784
868
|
}
|
|
869
|
+
async _beforeDeleteMany(
|
|
785
870
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
786
|
-
|
|
871
|
+
command) {
|
|
787
872
|
// Do nothing
|
|
788
873
|
}
|
|
874
|
+
async _afterCreate(
|
|
789
875
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
790
|
-
|
|
876
|
+
command,
|
|
877
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
878
|
+
result) {
|
|
791
879
|
// Do nothing
|
|
792
880
|
}
|
|
881
|
+
async _afterUpdate(
|
|
882
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
883
|
+
command,
|
|
793
884
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
794
|
-
|
|
885
|
+
result) {
|
|
795
886
|
// Do nothing
|
|
796
887
|
}
|
|
888
|
+
async _afterUpdateMany(
|
|
797
889
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
798
|
-
|
|
890
|
+
command,
|
|
891
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
892
|
+
affected) {
|
|
799
893
|
// Do nothing
|
|
800
894
|
}
|
|
895
|
+
async _afterDelete(
|
|
896
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
897
|
+
command,
|
|
801
898
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
802
|
-
|
|
899
|
+
affected) {
|
|
803
900
|
// Do nothing
|
|
804
901
|
}
|
|
902
|
+
async _afterDeleteMany(
|
|
903
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
904
|
+
command,
|
|
805
905
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
806
|
-
|
|
906
|
+
affected) {
|
|
807
907
|
// Do nothing
|
|
808
908
|
}
|
|
809
909
|
}
|