@opra/mongodb 1.4.3 → 1.5.0

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.
@@ -109,7 +109,8 @@ class MongoNestedService extends mongo_service_js_1.MongoService {
109
109
  options,
110
110
  };
111
111
  input[this.nestedKey] =
112
- input[this.nestedKey] == null || input[this.nestedKey] === ''
112
+ input[this.nestedKey] == null ||
113
+ input[this.nestedKey] === ''
113
114
  ? this._generateId(command)
114
115
  : input[this.nestedKey];
115
116
  return this._executeCommand(command, () => this._create(command));
@@ -153,8 +154,13 @@ class MongoNestedService extends mongo_service_js_1.MongoService {
153
154
  options,
154
155
  };
155
156
  return this._executeCommand(command, async () => {
156
- const documentFilter = mongo_adapter_js_1.MongoAdapter.prepareFilter([await this._getDocumentFilter(command)]);
157
- const filter = mongo_adapter_js_1.MongoAdapter.prepareFilter([await this._getNestedFilter(command), command.options?.filter]);
157
+ const documentFilter = mongo_adapter_js_1.MongoAdapter.prepareFilter([
158
+ await this._getDocumentFilter(command),
159
+ ]);
160
+ const filter = mongo_adapter_js_1.MongoAdapter.prepareFilter([
161
+ await this._getNestedFilter(command),
162
+ command.options?.filter,
163
+ ]);
158
164
  command.options = { ...command.options, filter, documentFilter };
159
165
  return this._count(command);
160
166
  });
@@ -207,8 +213,13 @@ class MongoNestedService extends mongo_service_js_1.MongoService {
207
213
  options,
208
214
  };
209
215
  return this._executeCommand(command, async () => {
210
- const documentFilter = mongo_adapter_js_1.MongoAdapter.prepareFilter([await this._getDocumentFilter(command)]);
211
- const filter = mongo_adapter_js_1.MongoAdapter.prepareFilter([await this._getNestedFilter(command), command.options?.filter]);
216
+ const documentFilter = mongo_adapter_js_1.MongoAdapter.prepareFilter([
217
+ await this._getDocumentFilter(command),
218
+ ]);
219
+ const filter = mongo_adapter_js_1.MongoAdapter.prepareFilter([
220
+ await this._getNestedFilter(command),
221
+ command.options?.filter,
222
+ ]);
212
223
  command.options = { ...command.options, filter, documentFilter };
213
224
  return this._delete(command);
214
225
  });
@@ -221,7 +232,10 @@ class MongoNestedService extends mongo_service_js_1.MongoService {
221
232
  mongo_adapter_js_1.MongoAdapter.prepareKeyValues(documentId, ['_id']),
222
233
  options?.documentFilter,
223
234
  ]);
224
- const pullFilter = mongo_adapter_js_1.MongoAdapter.prepareFilter([mongo_adapter_js_1.MongoAdapter.prepareKeyValues(nestedId, [this.nestedKey]), options?.filter]) || {};
235
+ const pullFilter = mongo_adapter_js_1.MongoAdapter.prepareFilter([
236
+ mongo_adapter_js_1.MongoAdapter.prepareKeyValues(nestedId, [this.nestedKey]),
237
+ options?.filter,
238
+ ]) || {};
225
239
  const update = {
226
240
  $pull: { [this.fieldName]: pullFilter },
227
241
  };
@@ -250,8 +264,13 @@ class MongoNestedService extends mongo_service_js_1.MongoService {
250
264
  options,
251
265
  };
252
266
  return this._executeCommand(command, async () => {
253
- const documentFilter = mongo_adapter_js_1.MongoAdapter.prepareFilter([await this._getDocumentFilter(command)]);
254
- const filter = mongo_adapter_js_1.MongoAdapter.prepareFilter([await this._getNestedFilter(command), command.options?.filter]);
267
+ const documentFilter = mongo_adapter_js_1.MongoAdapter.prepareFilter([
268
+ await this._getDocumentFilter(command),
269
+ ]);
270
+ const filter = mongo_adapter_js_1.MongoAdapter.prepareFilter([
271
+ await this._getNestedFilter(command),
272
+ command.options?.filter,
273
+ ]);
255
274
  command.options = { ...command.options, filter, documentFilter };
256
275
  return this._deleteMany(command);
257
276
  });
@@ -302,7 +321,9 @@ class MongoNestedService extends mongo_service_js_1.MongoService {
302
321
  options,
303
322
  };
304
323
  return this._executeCommand(command, async () => {
305
- const documentFilter = mongo_adapter_js_1.MongoAdapter.prepareFilter([await this._getDocumentFilter(command)]);
324
+ const documentFilter = mongo_adapter_js_1.MongoAdapter.prepareFilter([
325
+ await this._getDocumentFilter(command),
326
+ ]);
306
327
  const filter = mongo_adapter_js_1.MongoAdapter.prepareFilter([
307
328
  await this._getNestedFilter(command),
308
329
  documentFilter,
@@ -329,9 +350,17 @@ class MongoNestedService extends mongo_service_js_1.MongoService {
329
350
  };
330
351
  return this._executeCommand(command, async () => {
331
352
  const documentFilter = await this._getDocumentFilter(command);
332
- const filter = mongo_adapter_js_1.MongoAdapter.prepareFilter([documentFilter, command.options?.filter]);
353
+ const filter = mongo_adapter_js_1.MongoAdapter.prepareFilter([
354
+ documentFilter,
355
+ command.options?.filter,
356
+ ]);
333
357
  const findCommand = command;
334
- findCommand.options = { ...command.options, filter, documentFilter, projection: ['_id'] };
358
+ findCommand.options = {
359
+ ...command.options,
360
+ filter,
361
+ documentFilter,
362
+ projection: ['_id'],
363
+ };
335
364
  return !!(await this._findOne(findCommand));
336
365
  });
337
366
  }
@@ -345,8 +374,13 @@ class MongoNestedService extends mongo_service_js_1.MongoService {
345
374
  options,
346
375
  };
347
376
  return this._executeCommand(command, async () => {
348
- const documentFilter = mongo_adapter_js_1.MongoAdapter.prepareFilter([await this._getDocumentFilter(command)]);
349
- const filter = mongo_adapter_js_1.MongoAdapter.prepareFilter([await this._getNestedFilter(command), command.options?.filter]);
377
+ const documentFilter = mongo_adapter_js_1.MongoAdapter.prepareFilter([
378
+ await this._getDocumentFilter(command),
379
+ ]);
380
+ const filter = mongo_adapter_js_1.MongoAdapter.prepareFilter([
381
+ await this._getNestedFilter(command),
382
+ command.options?.filter,
383
+ ]);
350
384
  command.options = { ...command.options, filter, documentFilter };
351
385
  return this._findById(command);
352
386
  });
@@ -381,8 +415,13 @@ class MongoNestedService extends mongo_service_js_1.MongoService {
381
415
  options,
382
416
  };
383
417
  return this._executeCommand(command, async () => {
384
- const documentFilter = mongo_adapter_js_1.MongoAdapter.prepareFilter([await this._getDocumentFilter(command)]);
385
- const filter = mongo_adapter_js_1.MongoAdapter.prepareFilter([await this._getNestedFilter(command), command.options?.filter]);
418
+ const documentFilter = mongo_adapter_js_1.MongoAdapter.prepareFilter([
419
+ await this._getDocumentFilter(command),
420
+ ]);
421
+ const filter = mongo_adapter_js_1.MongoAdapter.prepareFilter([
422
+ await this._getNestedFilter(command),
423
+ command.options?.filter,
424
+ ]);
386
425
  command.options = { ...command.options, filter, documentFilter };
387
426
  return this._findOne(command);
388
427
  });
@@ -438,7 +477,10 @@ class MongoNestedService extends mongo_service_js_1.MongoService {
438
477
  stages.push(...options.preStages);
439
478
  /** Filter */
440
479
  if (options?.filter || options?.nestedFilter) {
441
- const optionsFilter = mongo_adapter_js_1.MongoAdapter.prepareFilter([options?.filter, options.nestedFilter]);
480
+ const optionsFilter = mongo_adapter_js_1.MongoAdapter.prepareFilter([
481
+ options?.filter,
482
+ options.nestedFilter,
483
+ ]);
442
484
  stages.push({ $match: optionsFilter });
443
485
  }
444
486
  /** Sort */
@@ -462,7 +504,15 @@ class MongoNestedService extends mongo_service_js_1.MongoService {
462
504
  const db = this.getDatabase();
463
505
  const collection = await this.getCollection(db);
464
506
  const cursor = collection.aggregate(stages, {
465
- ...(0, objects_1.omit)(options, ['documentFilter', 'nestedFilter', 'projection', 'sort', 'skip', 'limit', 'filter']),
507
+ ...(0, objects_1.omit)(options, [
508
+ 'documentFilter',
509
+ 'nestedFilter',
510
+ 'projection',
511
+ 'sort',
512
+ 'skip',
513
+ 'limit',
514
+ 'filter',
515
+ ]),
466
516
  session: options?.session ?? this.getSession(),
467
517
  });
468
518
  try {
@@ -519,7 +569,10 @@ class MongoNestedService extends mongo_service_js_1.MongoService {
519
569
  dataStages.push(...options.preStages);
520
570
  /** Filter */
521
571
  if (options?.filter || options?.nestedFilter) {
522
- const optionsFilter = mongo_adapter_js_1.MongoAdapter.prepareFilter([options?.filter, options?.nestedFilter]);
572
+ const optionsFilter = mongo_adapter_js_1.MongoAdapter.prepareFilter([
573
+ options?.filter,
574
+ options?.nestedFilter,
575
+ ]);
523
576
  dataStages.push({ $match: optionsFilter });
524
577
  }
525
578
  /** Sort */
@@ -543,7 +596,15 @@ class MongoNestedService extends mongo_service_js_1.MongoService {
543
596
  const db = this.getDatabase();
544
597
  const collection = await this.getCollection(db);
545
598
  const cursor = collection.aggregate(stages, {
546
- ...(0, objects_1.omit)(options, ['documentFilter', 'nestedFilter', 'projection', 'sort', 'skip', 'limit', 'filter']),
599
+ ...(0, objects_1.omit)(options, [
600
+ 'documentFilter',
601
+ 'nestedFilter',
602
+ 'projection',
603
+ 'sort',
604
+ 'skip',
605
+ 'limit',
606
+ 'filter',
607
+ ]),
547
608
  session: options?.session ?? this.getSession(),
548
609
  });
549
610
  try {
@@ -577,8 +638,13 @@ class MongoNestedService extends mongo_service_js_1.MongoService {
577
638
  options,
578
639
  };
579
640
  return this._executeCommand(command, async () => {
580
- const documentFilter = mongo_adapter_js_1.MongoAdapter.prepareFilter([await this._getDocumentFilter(command)]);
581
- const filter = mongo_adapter_js_1.MongoAdapter.prepareFilter([await this._getNestedFilter(command), command.options?.filter]);
641
+ const documentFilter = mongo_adapter_js_1.MongoAdapter.prepareFilter([
642
+ await this._getDocumentFilter(command),
643
+ ]);
644
+ const filter = mongo_adapter_js_1.MongoAdapter.prepareFilter([
645
+ await this._getNestedFilter(command),
646
+ command.options?.filter,
647
+ ]);
582
648
  command.options = {
583
649
  ...command.options,
584
650
  filter,
@@ -621,8 +687,13 @@ class MongoNestedService extends mongo_service_js_1.MongoService {
621
687
  options,
622
688
  };
623
689
  return this._executeCommand(command, async () => {
624
- const documentFilter = mongo_adapter_js_1.MongoAdapter.prepareFilter([await this._getDocumentFilter(command)]);
625
- const filter = mongo_adapter_js_1.MongoAdapter.prepareFilter([await this._getNestedFilter(command), command.options?.filter]);
690
+ const documentFilter = mongo_adapter_js_1.MongoAdapter.prepareFilter([
691
+ await this._getDocumentFilter(command),
692
+ ]);
693
+ const filter = mongo_adapter_js_1.MongoAdapter.prepareFilter([
694
+ await this._getNestedFilter(command),
695
+ command.options?.filter,
696
+ ]);
626
697
  command.options = {
627
698
  ...command.options,
628
699
  filter,
@@ -665,8 +736,13 @@ class MongoNestedService extends mongo_service_js_1.MongoService {
665
736
  options,
666
737
  };
667
738
  return this._executeCommand(command, async () => {
668
- const documentFilter = mongo_adapter_js_1.MongoAdapter.prepareFilter([await this._getDocumentFilter(command)]);
669
- const filter = mongo_adapter_js_1.MongoAdapter.prepareFilter([await this._getNestedFilter(command), command.options?.filter]);
739
+ const documentFilter = mongo_adapter_js_1.MongoAdapter.prepareFilter([
740
+ await this._getDocumentFilter(command),
741
+ ]);
742
+ const filter = mongo_adapter_js_1.MongoAdapter.prepareFilter([
743
+ await this._getNestedFilter(command),
744
+ command.options?.filter,
745
+ ]);
670
746
  command.options = { ...command.options, filter, documentFilter };
671
747
  return this._updateMany(command);
672
748
  });
@@ -685,7 +761,9 @@ class MongoNestedService extends mongo_service_js_1.MongoService {
685
761
  { [this.fieldName]: { $exists: true } },
686
762
  ]);
687
763
  if (options?.filter) {
688
- const elemMatch = mongo_adapter_js_1.MongoAdapter.prepareFilter([options?.filter], { fieldPrefix: 'elem.' });
764
+ const elemMatch = mongo_adapter_js_1.MongoAdapter.prepareFilter([options?.filter], {
765
+ fieldPrefix: 'elem.',
766
+ });
689
767
  options.arrayFilters = [elemMatch];
690
768
  }
691
769
  const patchGenerator = new mongo_patch_generator_js_1.MongoPatchGenerator();
@@ -723,7 +801,9 @@ class MongoNestedService extends mongo_service_js_1.MongoService {
723
801
  * that resolves to the common filter, or undefined if not available.
724
802
  */
725
803
  _getNestedFilter(args) {
726
- return typeof this.nestedFilter === 'function' ? this.nestedFilter(args, this) : this.nestedFilter;
804
+ return typeof this.nestedFilter === 'function'
805
+ ? this.nestedFilter(args, this)
806
+ : this.nestedFilter;
727
807
  }
728
808
  async _executeCommand(command, commandFn) {
729
809
  try {
@@ -769,44 +849,64 @@ class MongoNestedService extends mongo_service_js_1.MongoService {
769
849
  throw e;
770
850
  }
771
851
  }
852
+ async _beforeCreate(
772
853
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
773
- async _beforeCreate(command) {
854
+ command) {
774
855
  // Do nothing
775
856
  }
857
+ async _beforeUpdate(
776
858
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
777
- async _beforeUpdate(command) {
859
+ command) {
778
860
  // Do nothing
779
861
  }
862
+ async _beforeUpdateMany(
780
863
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
781
- async _beforeUpdateMany(command) {
864
+ command) {
782
865
  // Do nothing
783
866
  }
867
+ async _beforeDelete(
784
868
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
785
- async _beforeDelete(command) {
869
+ command) {
786
870
  // Do nothing
787
871
  }
872
+ async _beforeDeleteMany(
788
873
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
789
- async _beforeDeleteMany(command) {
874
+ command) {
790
875
  // Do nothing
791
876
  }
877
+ async _afterCreate(
792
878
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
793
- async _afterCreate(command, result) {
879
+ command,
880
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
881
+ result) {
794
882
  // Do nothing
795
883
  }
884
+ async _afterUpdate(
885
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
886
+ command,
796
887
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
797
- async _afterUpdate(command, result) {
888
+ result) {
798
889
  // Do nothing
799
890
  }
891
+ async _afterUpdateMany(
800
892
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
801
- async _afterUpdateMany(command, affected) {
893
+ command,
894
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
895
+ affected) {
802
896
  // Do nothing
803
897
  }
898
+ async _afterDelete(
899
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
900
+ command,
804
901
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
805
- async _afterDelete(command, affected) {
902
+ affected) {
806
903
  // Do nothing
807
904
  }
905
+ async _afterDeleteMany(
906
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
907
+ command,
808
908
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
809
- async _afterDeleteMany(command, affected) {
909
+ affected) {
810
910
  // Do nothing
811
911
  }
812
912
  }
@@ -45,10 +45,12 @@ class MongoService extends core_1.ServiceBase {
45
45
  for(context, overwriteProperties, overwriteContext) {
46
46
  if (overwriteProperties?.documentFilter && this.documentFilter) {
47
47
  overwriteProperties.documentFilter = [
48
- ...(Array.isArray(this.documentFilter) ? this.documentFilter : [this.documentFilter]),
48
+ ...(Array.isArray(this.documentFilter)
49
+ ? this.documentFilter
50
+ : [this.documentFilter]),
49
51
  ...(Array.isArray(overwriteProperties?.documentFilter)
50
- ? overwriteProperties?.documentFilter
51
- : [overwriteProperties?.documentFilter]),
52
+ ? overwriteProperties.documentFilter
53
+ : [overwriteProperties.documentFilter]),
52
54
  ];
53
55
  }
54
56
  return super.for(context, overwriteProperties, overwriteContext);
@@ -61,7 +63,9 @@ class MongoService extends core_1.ServiceBase {
61
63
  * @throws {Error} If the collection name is not defined.
62
64
  */
63
65
  getCollectionName() {
64
- const out = typeof this.collectionName === 'function' ? this.collectionName(this) : this.collectionName;
66
+ const out = typeof this.collectionName === 'function'
67
+ ? this.collectionName(this)
68
+ : this.collectionName;
65
69
  if (out)
66
70
  return out;
67
71
  throw new Error('collectionName is not defined');
@@ -74,7 +78,9 @@ class MongoService extends core_1.ServiceBase {
74
78
  * @throws {Error} If the resource name is not defined.
75
79
  */
76
80
  getResourceName() {
77
- const out = typeof this.resourceName === 'function' ? this.resourceName(this) : this.resourceName || this.getCollectionName();
81
+ const out = typeof this.resourceName === 'function'
82
+ ? this.resourceName(this)
83
+ : this.resourceName || this.getCollectionName();
78
84
  if (out)
79
85
  return out;
80
86
  throw new Error('resourceName is not defined');
@@ -85,8 +91,14 @@ class MongoService extends core_1.ServiceBase {
85
91
  * @throws {NotAcceptableError} If the data type is not a ComplexType.
86
92
  */
87
93
  get dataType() {
94
+ if (this._dataType && this._dataTypeScope !== this.scopes)
95
+ this._dataType = undefined;
88
96
  if (!this._dataType)
89
97
  this._dataType = this.context.documentNode.getComplexType(this._dataType_);
98
+ this._dataTypeScope = this.scopes;
99
+ this._dataTypeScopes = this.scopes
100
+ ? this.scopes?.split(/\s*,\s*/)
101
+ : undefined;
90
102
  return this._dataType;
91
103
  }
92
104
  /**
@@ -184,7 +196,9 @@ class MongoService extends core_1.ServiceBase {
184
196
  * @returns {MongoAdapter.AnyId} The generated ID.
185
197
  */
186
198
  _generateId(command) {
187
- return typeof this.idGenerator === 'function' ? this.idGenerator(command, this) : new mongodb_1.ObjectId();
199
+ return typeof this.idGenerator === 'function'
200
+ ? this.idGenerator(command, this)
201
+ : new mongodb_1.ObjectId();
188
202
  }
189
203
  /**
190
204
  * Retrieves the common filter used for querying documents.
@@ -195,8 +209,10 @@ class MongoService extends core_1.ServiceBase {
195
209
  * that resolves to the common filter, or undefined if not available.
196
210
  */
197
211
  _getDocumentFilter(command) {
198
- const commonFilter = Array.isArray(this.documentFilter) ? this.documentFilter : [this.documentFilter];
199
- const mapped = commonFilter.map(f => (typeof f === 'function' ? f(command, this) : f));
212
+ const commonFilter = Array.isArray(this.documentFilter)
213
+ ? this.documentFilter
214
+ : [this.documentFilter];
215
+ const mapped = commonFilter.map(f => typeof f === 'function' ? f(command, this) : f);
200
216
  return mapped.length > 1 ? mongo_adapter_js_1.MongoAdapter.prepareFilter(mapped) : mapped[0];
201
217
  }
202
218
  async _executeCommand(command, commandFn) {
@@ -204,7 +220,8 @@ class MongoService extends core_1.ServiceBase {
204
220
  const next = async () => {
205
221
  proto = proto ? Object.getPrototypeOf(proto) : this;
206
222
  while (proto) {
207
- if (proto.interceptor && Object.prototype.hasOwnProperty.call(proto, 'interceptor')) {
223
+ if (proto.interceptor &&
224
+ Object.prototype.hasOwnProperty.call(proto, 'interceptor')) {
208
225
  return await proto.interceptor.call(this, next, command, this);
209
226
  }
210
227
  proto = Object.getPrototypeOf(proto);
@@ -232,6 +249,7 @@ class MongoService extends core_1.ServiceBase {
232
249
  if (validator)
233
250
  return validator;
234
251
  const options = { projection: '*' };
252
+ options.scope = this._dataTypeScopes;
235
253
  if (operation === 'update') {
236
254
  options.partial = 'deep';
237
255
  options.allowPatchOperators = true;
@@ -248,7 +266,11 @@ class MongoService extends core_1.ServiceBase {
248
266
  let validator = this._outputCodecs[operation];
249
267
  if (validator)
250
268
  return validator;
251
- const options = { projection: '*', partial: 'deep', ignoreHiddenFields: true };
269
+ const options = {
270
+ projection: '*',
271
+ partial: 'deep',
272
+ scope: this._dataTypeScopes,
273
+ };
252
274
  const dataType = this.dataType;
253
275
  validator = dataType.generateCodec('decode', options);
254
276
  this._outputCodecs[operation] = validator;
@@ -94,7 +94,10 @@ class MongoSingletonService extends mongo_entity_service_js_1.MongoEntityService
94
94
  options,
95
95
  };
96
96
  return this._executeCommand(command, async () => {
97
- const filter = mongo_adapter_js_1.MongoAdapter.prepareFilter([await this._getDocumentFilter(command), command.options?.filter]);
97
+ const filter = mongo_adapter_js_1.MongoAdapter.prepareFilter([
98
+ await this._getDocumentFilter(command),
99
+ command.options?.filter,
100
+ ]);
98
101
  command.options = { ...command.options, filter };
99
102
  return this._delete(command);
100
103
  });
@@ -115,7 +118,10 @@ class MongoSingletonService extends mongo_entity_service_js_1.MongoEntityService
115
118
  };
116
119
  return this._executeCommand(command, async () => {
117
120
  const documentFilter = await this._getDocumentFilter(command);
118
- const filter = mongo_adapter_js_1.MongoAdapter.prepareFilter([documentFilter, command.options?.filter]);
121
+ const filter = mongo_adapter_js_1.MongoAdapter.prepareFilter([
122
+ documentFilter,
123
+ command.options?.filter,
124
+ ]);
119
125
  const findCommand = command;
120
126
  findCommand.options = { ...command.options, filter, projection: ['_id'] };
121
127
  return !!(await this._findById(findCommand));
@@ -131,7 +137,10 @@ class MongoSingletonService extends mongo_entity_service_js_1.MongoEntityService
131
137
  };
132
138
  return this._executeCommand(command, async () => {
133
139
  const documentFilter = await this._getDocumentFilter(command);
134
- const filter = mongo_adapter_js_1.MongoAdapter.prepareFilter([documentFilter, command.options?.filter]);
140
+ const filter = mongo_adapter_js_1.MongoAdapter.prepareFilter([
141
+ documentFilter,
142
+ command.options?.filter,
143
+ ]);
135
144
  command.options = { ...command.options, filter };
136
145
  return this._findById(command);
137
146
  });
@@ -154,7 +163,10 @@ class MongoSingletonService extends mongo_entity_service_js_1.MongoEntityService
154
163
  options,
155
164
  };
156
165
  return this._executeCommand(command, async () => {
157
- const filter = mongo_adapter_js_1.MongoAdapter.prepareFilter([await this._getDocumentFilter(command), command.options?.filter]);
166
+ const filter = mongo_adapter_js_1.MongoAdapter.prepareFilter([
167
+ await this._getDocumentFilter(command),
168
+ command.options?.filter,
169
+ ]);
158
170
  command.options = { ...command.options, filter };
159
171
  const matchCount = await this._updateOnly(command);
160
172
  if (matchCount) {
@@ -189,7 +201,10 @@ class MongoSingletonService extends mongo_entity_service_js_1.MongoEntityService
189
201
  options,
190
202
  };
191
203
  return this._executeCommand(command, async () => {
192
- const filter = mongo_adapter_js_1.MongoAdapter.prepareFilter([await this._getDocumentFilter(command), command.options?.filter]);
204
+ const filter = mongo_adapter_js_1.MongoAdapter.prepareFilter([
205
+ await this._getDocumentFilter(command),
206
+ command.options?.filter,
207
+ ]);
193
208
  command.options = { ...command.options, filter };
194
209
  return this._updateOnly(command);
195
210
  });
@@ -14,7 +14,8 @@ export var MongoAdapter;
14
14
  }
15
15
  const ctx = context;
16
16
  const { operation } = ctx;
17
- if (operation?.composition?.startsWith('Entity.') && operation.compositionOptions?.type) {
17
+ if (operation?.composition?.startsWith('Entity.') &&
18
+ operation.compositionOptions?.type) {
18
19
  const controller = operation.owner;
19
20
  switch (operation.composition) {
20
21
  case 'Entity.Create': {
@@ -22,15 +23,24 @@ export var MongoAdapter;
22
23
  const options = {
23
24
  projection: ctx.queryParams.projection,
24
25
  };
25
- return { method: 'create', data, options };
26
+ return {
27
+ method: 'create',
28
+ data,
29
+ options,
30
+ };
26
31
  }
27
32
  case 'Entity.Delete': {
28
- const keyParam = operation.parameters.find(p => p.keyParam) || controller.parameters.find(p => p.keyParam);
33
+ const keyParam = operation.parameters.find(p => p.keyParam) ||
34
+ controller.parameters.find(p => p.keyParam);
29
35
  const key = keyParam && ctx.pathParams[String(keyParam.name)];
30
36
  const options = {
31
37
  filter: ctx.queryParams.filter,
32
38
  };
33
- return { method: 'delete', key, options };
39
+ return {
40
+ method: 'delete',
41
+ key,
42
+ options,
43
+ };
34
44
  }
35
45
  case 'Entity.DeleteMany': {
36
46
  const options = {
@@ -41,16 +51,19 @@ export var MongoAdapter;
41
51
  case 'Entity.FindMany': {
42
52
  const options = {
43
53
  filter: ctx.queryParams.filter,
44
- projection: ctx.queryParams.projection || operation.compositionOptions.defaultProjection,
54
+ projection: ctx.queryParams.projection ||
55
+ operation.compositionOptions.defaultProjection,
45
56
  count: ctx.queryParams.count,
46
- limit: ctx.queryParams.limit || operation.compositionOptions.defaultLimit,
57
+ limit: ctx.queryParams.limit ||
58
+ operation.compositionOptions.defaultLimit,
47
59
  skip: ctx.queryParams.skip,
48
60
  sort: ctx.queryParams.sort || operation.compositionOptions.defaultSort,
49
61
  };
50
62
  return { method: 'findMany', options };
51
63
  }
52
64
  case 'Entity.Get': {
53
- const keyParam = operation.parameters.find(p => p.keyParam) || controller.parameters.find(p => p.keyParam);
65
+ const keyParam = operation.parameters.find(p => p.keyParam) ||
66
+ controller.parameters.find(p => p.keyParam);
54
67
  const key = keyParam && ctx.pathParams[String(keyParam.name)];
55
68
  const options = {
56
69
  projection: ctx.queryParams.projection,
@@ -60,30 +73,46 @@ export var MongoAdapter;
60
73
  }
61
74
  case 'Entity.Replace': {
62
75
  const data = await ctx.getBody();
63
- const keyParam = operation.parameters.find(p => p.keyParam) || controller.parameters.find(p => p.keyParam);
76
+ const keyParam = operation.parameters.find(p => p.keyParam) ||
77
+ controller.parameters.find(p => p.keyParam);
64
78
  const key = keyParam && ctx.pathParams[String(keyParam.name)];
65
79
  const options = {
66
80
  projection: ctx.queryParams.projection,
67
81
  filter: ctx.queryParams.filter,
68
82
  };
69
- return { method: 'replace', key, data, options };
83
+ return {
84
+ method: 'replace',
85
+ key,
86
+ data,
87
+ options,
88
+ };
70
89
  }
71
90
  case 'Entity.Update': {
72
91
  const data = await ctx.getBody();
73
- const keyParam = operation.parameters.find(p => p.keyParam) || controller.parameters.find(p => p.keyParam);
92
+ const keyParam = operation.parameters.find(p => p.keyParam) ||
93
+ controller.parameters.find(p => p.keyParam);
74
94
  const key = keyParam && ctx.pathParams[String(keyParam.name)];
75
95
  const options = {
76
96
  projection: ctx.queryParams.projection,
77
97
  filter: ctx.queryParams.filter,
78
98
  };
79
- return { method: 'update', key, data, options };
99
+ return {
100
+ method: 'update',
101
+ key,
102
+ data,
103
+ options,
104
+ };
80
105
  }
81
106
  case 'Entity.UpdateMany': {
82
107
  const data = await ctx.getBody();
83
108
  const options = {
84
109
  filter: ctx.queryParams.filter,
85
110
  };
86
- return { method: 'updateMany', data, options };
111
+ return {
112
+ method: 'updateMany',
113
+ data,
114
+ options,
115
+ };
87
116
  }
88
117
  default:
89
118
  break;
@@ -85,7 +85,9 @@ export class MongoPatchGenerator {
85
85
  delete v[keyField];
86
86
  /** Add array filter */
87
87
  ctx.arrayFilters = ctx.arrayFilters || [];
88
- ctx.arrayFilters.push({ [`${arrayFilterName}.${keyField}`]: keyValue });
88
+ ctx.arrayFilters.push({
89
+ [`${arrayFilterName}.${keyField}`]: keyValue,
90
+ });
89
91
  /** Process each object in array */
90
92
  this._processComplexType(ctx, field.type, pathDot + field.name + `.$[${arrayFilterName}]`, v);
91
93
  }
@@ -135,7 +137,9 @@ export class MongoPatchGenerator {
135
137
  }
136
138
  continue;
137
139
  }
138
- ctx.$push[pathDot + key] = Array.isArray(value) ? { $each: value } : value;
140
+ ctx.$push[pathDot + key] = Array.isArray(value)
141
+ ? { $each: value }
142
+ : value;
139
143
  }
140
144
  }
141
145
  _processPull(ctx, dataType, path, input) {
@@ -155,10 +159,16 @@ export class MongoPatchGenerator {
155
159
  keyField = field.keyField || field.type.keyField;
156
160
  if (!keyField)
157
161
  continue;
158
- ctx.$pull[pathDot + key] = { $elemMatch: { [keyField]: Array.isArray(value) ? { $in: value } : value } };
162
+ ctx.$pull[pathDot + key] = {
163
+ $elemMatch: {
164
+ [keyField]: Array.isArray(value) ? { $in: value } : value,
165
+ },
166
+ };
159
167
  }
160
168
  else {
161
- ctx.$pull[pathDot + key] = Array.isArray(value) ? { $in: value } : value;
169
+ ctx.$pull[pathDot + key] = Array.isArray(value)
170
+ ? { $in: value }
171
+ : value;
162
172
  }
163
173
  }
164
174
  }