@resolveio/server-lib 9.1.19 → 9.1.21

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.
@@ -224,6 +224,18 @@ var Collection = /** @class */ (function () {
224
224
  Collection.prototype.aggregate = function (pipeline, options) {
225
225
  var _this = this;
226
226
  return new Promise(function (resolve, reject) {
227
+ log_collection_1.Logs.insertOne({
228
+ _id: objectIdHexString(),
229
+ type: 'query',
230
+ collection: _this.collectionName,
231
+ id_document: '',
232
+ payload: common_1.getBinarySize(JSON.stringify([pipeline, options])) < 200000 ? JSON.stringify([pipeline, options], null, 2) : 'Too Big',
233
+ method: 'aggregate',
234
+ id_user: '',
235
+ user: '',
236
+ messageId: 0,
237
+ route: ''
238
+ });
227
239
  index_1.ResolveIOServer.getMongoManager().addToQueue({
228
240
  _id: 0,
229
241
  name_collection: _this.collectionName,
@@ -238,6 +250,18 @@ var Collection = /** @class */ (function () {
238
250
  else {
239
251
  resolve(res);
240
252
  }
253
+ log_collection_1.Logs.insertOne({
254
+ _id: objectIdHexString(),
255
+ type: 'queryResponse',
256
+ collection: _this.collectionName,
257
+ id_document: '',
258
+ payload: common_1.getBinarySize(JSON.stringify([err, res])) < 200000 ? JSON.stringify([err, res], null, 2) : 'Too Big',
259
+ method: 'aggregate',
260
+ id_user: '',
261
+ user: '',
262
+ messageId: 0,
263
+ route: ''
264
+ });
241
265
  }],
242
266
  cbs_next: [],
243
267
  running: false
@@ -299,40 +323,38 @@ var Collection = /** @class */ (function () {
299
323
  return __generator(this, function (_a) {
300
324
  switch (_a.label) {
301
325
  case 0:
302
- if (!(this.createLogs && !bypassLogs)) return [3 /*break*/, 6];
326
+ if (!(this.createLogs && !bypassLogs)) return [3 /*break*/, 5];
303
327
  return [4 /*yield*/, this.find(filter)];
304
328
  case 1:
305
329
  docs = _a.sent();
306
330
  i = 0;
307
331
  _a.label = 2;
308
332
  case 2:
309
- if (!(i < docs.length)) return [3 /*break*/, 6];
333
+ if (!(i < docs.length)) return [3 /*break*/, 5];
310
334
  doc = docs[i];
311
- return [4 /*yield*/, log_collection_1.Logs.insertOne({
312
- _id: objectIdHexString(),
313
- type: 'document',
314
- collection: this.collectionName,
315
- id_document: doc['_id'],
316
- payload: common_1.getBinarySize(JSON.stringify([doc, filter, options])) < 200000 ? JSON.stringify([doc, filter, options], null, 2) : 'Too Big',
317
- method: 'deleteMany',
318
- id_user: '',
319
- user: '',
320
- messageId: 0,
321
- route: ''
322
- })];
323
- case 3:
324
- _a.sent();
325
- if (!this.useVersions) return [3 /*break*/, 5];
335
+ log_collection_1.Logs.insertOne({
336
+ _id: objectIdHexString(),
337
+ type: 'document',
338
+ collection: this.collectionName,
339
+ id_document: doc['_id'],
340
+ payload: common_1.getBinarySize(JSON.stringify([doc, filter, options])) < 200000 ? JSON.stringify([doc, filter, options], null, 2) : 'Too Big',
341
+ method: 'deleteMany',
342
+ id_user: '',
343
+ user: '',
344
+ messageId: 0,
345
+ route: ''
346
+ });
347
+ if (!this.useVersions) return [3 /*break*/, 4];
326
348
  versionDoc = common_1.deepCopy(doc);
327
349
  versionDoc['_id'] = { _id: doc['_id'], __v: doc['__v'] };
328
350
  return [4 /*yield*/, index_1.ResolveIOServer.getMongoManager().collection(this.versionCollection).replaceOne({ _id: { _id: doc['_id'], __v: doc['__v'] } }, versionDoc, { upsert: true })];
329
- case 4:
351
+ case 3:
330
352
  _a.sent();
331
- _a.label = 5;
332
- case 5:
353
+ _a.label = 4;
354
+ case 4:
333
355
  i++;
334
356
  return [3 /*break*/, 2];
335
- case 6:
357
+ case 5:
336
358
  index_1.ResolveIOServer.getMainDB().collection(this.collectionName).deleteMany(filter, options).then(function (res) {
337
359
  if (res.result.ok) {
338
360
  resolve(res.deletedCount);
@@ -355,33 +377,31 @@ var Collection = /** @class */ (function () {
355
377
  return __generator(this, function (_a) {
356
378
  switch (_a.label) {
357
379
  case 0:
358
- if (!(this.createLogs && !bypassLogs)) return [3 /*break*/, 4];
380
+ if (!(this.createLogs && !bypassLogs)) return [3 /*break*/, 3];
359
381
  return [4 /*yield*/, this.findOne(filter)];
360
382
  case 1:
361
383
  doc = _a.sent();
362
- if (!doc) return [3 /*break*/, 4];
363
- return [4 /*yield*/, log_collection_1.Logs.insertOne({
364
- _id: objectIdHexString(),
365
- type: 'document',
366
- collection: this.collectionName,
367
- id_document: doc['_id'],
368
- payload: common_1.getBinarySize(JSON.stringify([doc, filter, options])) < 200000 ? JSON.stringify([doc, filter, options], null, 2) : 'Too Big',
369
- method: 'deleteOne',
370
- id_user: '',
371
- user: '',
372
- messageId: 0,
373
- route: ''
374
- })];
375
- case 2:
376
- _a.sent();
377
- if (!this.useVersions) return [3 /*break*/, 4];
384
+ if (!doc) return [3 /*break*/, 3];
385
+ log_collection_1.Logs.insertOne({
386
+ _id: objectIdHexString(),
387
+ type: 'document',
388
+ collection: this.collectionName,
389
+ id_document: doc['_id'],
390
+ payload: common_1.getBinarySize(JSON.stringify([doc, filter, options])) < 200000 ? JSON.stringify([doc, filter, options], null, 2) : 'Too Big',
391
+ method: 'deleteOne',
392
+ id_user: '',
393
+ user: '',
394
+ messageId: 0,
395
+ route: ''
396
+ });
397
+ if (!this.useVersions) return [3 /*break*/, 3];
378
398
  versionDoc = common_1.deepCopy(doc);
379
399
  versionDoc['_id'] = { _id: doc['_id'], __v: doc['__v'] };
380
400
  return [4 /*yield*/, index_1.ResolveIOServer.getMongoManager().collection(this.versionCollection).replaceOne({ _id: { _id: doc['_id'], __v: doc['__v'] } }, versionDoc, { upsert: true })];
381
- case 3:
401
+ case 2:
382
402
  _a.sent();
383
- _a.label = 4;
384
- case 4:
403
+ _a.label = 3;
404
+ case 3:
385
405
  index_1.ResolveIOServer.getMainDB().collection(this.collectionName).deleteOne(filter, options).then(function (res) {
386
406
  if (res.result.ok) {
387
407
  resolve(res.deletedCount);
@@ -412,46 +432,53 @@ var Collection = /** @class */ (function () {
412
432
  if (filter === void 0) { filter = {}; }
413
433
  if (bypassLogs === void 0) { bypassLogs = false; }
414
434
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
435
+ var _this = this;
415
436
  return __generator(this, function (_a) {
416
- switch (_a.label) {
417
- case 0:
418
- if (!(this.createLogs && !bypassLogs)) return [3 /*break*/, 2];
419
- return [4 /*yield*/, log_collection_1.Logs.insertOne({
437
+ if (this.createLogs && !bypassLogs) {
438
+ log_collection_1.Logs.insertOne({
439
+ _id: objectIdHexString(),
440
+ type: 'query',
441
+ collection: this.collectionName,
442
+ id_document: '',
443
+ payload: common_1.getBinarySize(JSON.stringify([filter, options])) < 200000 ? JSON.stringify([filter, options], null, 2) : 'Too Big',
444
+ method: 'find',
445
+ id_user: '',
446
+ user: '',
447
+ messageId: 0,
448
+ route: ''
449
+ });
450
+ }
451
+ index_1.ResolveIOServer.getMongoManager().addToQueue({
452
+ _id: 0,
453
+ name_collection: this.collectionName,
454
+ name_function: 'find',
455
+ name_function_addt: 'toArray',
456
+ data_function: [filter, options],
457
+ data_function_addt: [],
458
+ cbs: [function (err, res) {
459
+ if (err) {
460
+ reject(err);
461
+ }
462
+ else {
463
+ resolve(res);
464
+ }
465
+ log_collection_1.Logs.insertOne({
420
466
  _id: objectIdHexString(),
421
- type: 'query',
422
- collection: this.collectionName,
467
+ type: 'queryResponse',
468
+ collection: _this.collectionName,
423
469
  id_document: '',
424
- payload: common_1.getBinarySize(JSON.stringify([filter, options])) < 200000 ? JSON.stringify([filter, options], null, 2) : 'Too Big',
470
+ payload: JSON.stringify([err, res], null, 2),
425
471
  method: 'find',
426
472
  id_user: '',
427
473
  user: '',
428
474
  messageId: 0,
429
475
  route: ''
430
- })];
431
- case 1:
432
- _a.sent();
433
- _a.label = 2;
434
- case 2:
435
- index_1.ResolveIOServer.getMongoManager().addToQueue({
436
- _id: 0,
437
- name_collection: this.collectionName,
438
- name_function: 'find',
439
- name_function_addt: 'toArray',
440
- data_function: [filter, options],
441
- data_function_addt: [],
442
- cbs: [function (err, res) {
443
- if (err) {
444
- reject(err);
445
- }
446
- else {
447
- resolve(res);
448
- }
449
- }],
450
- cbs_next: [],
451
- running: false
452
- });
453
- return [2 /*return*/];
454
- }
476
+ });
477
+ }],
478
+ cbs_next: [],
479
+ running: false
480
+ });
481
+ return [2 /*return*/];
455
482
  });
456
483
  }); });
457
484
  };
@@ -518,6 +545,18 @@ var Collection = /** @class */ (function () {
518
545
  else {
519
546
  resolve(res);
520
547
  }
548
+ log_collection_1.Logs.insertOne({
549
+ _id: objectIdHexString(),
550
+ type: 'queryResponse',
551
+ collection: _this.collectionName,
552
+ id_document: '',
553
+ payload: JSON.stringify([err, res], null, 2),
554
+ method: 'findOne',
555
+ id_user: '',
556
+ user: '',
557
+ messageId: 0,
558
+ route: ''
559
+ });
521
560
  }],
522
561
  cbs_next: [],
523
562
  running: false
@@ -530,15 +569,16 @@ var Collection = /** @class */ (function () {
530
569
  if (bypassLogs === void 0) { bypassLogs = false; }
531
570
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
532
571
  var doc;
572
+ var _this = this;
533
573
  return __generator(this, function (_a) {
534
574
  switch (_a.label) {
535
575
  case 0:
536
- if (!(this.createLogs && !bypassLogs)) return [3 /*break*/, 3];
576
+ if (!(this.createLogs && !bypassLogs)) return [3 /*break*/, 2];
537
577
  return [4 /*yield*/, this.findOne(filter)];
538
578
  case 1:
539
579
  doc = _a.sent();
540
- if (!doc) return [3 /*break*/, 3];
541
- return [4 /*yield*/, log_collection_1.Logs.insertOne({
580
+ if (doc) {
581
+ log_collection_1.Logs.insertOne({
542
582
  _id: objectIdHexString(),
543
583
  type: 'document',
544
584
  collection: this.collectionName,
@@ -549,11 +589,10 @@ var Collection = /** @class */ (function () {
549
589
  user: '',
550
590
  messageId: 0,
551
591
  route: ''
552
- })];
592
+ });
593
+ }
594
+ _a.label = 2;
553
595
  case 2:
554
- _a.sent();
555
- _a.label = 3;
556
- case 3:
557
596
  index_1.ResolveIOServer.getMainDB().collection(this.collectionName).findOneAndDelete(filter, options).then(function (res) {
558
597
  if (res.ok) {
559
598
  resolve(res.value);
@@ -561,22 +600,50 @@ var Collection = /** @class */ (function () {
561
600
  else {
562
601
  reject(res.lastErrorObject);
563
602
  }
564
- }, function (err) { return reject(err); });
603
+ log_collection_1.Logs.insertOne({
604
+ _id: objectIdHexString(),
605
+ type: 'queryResponse',
606
+ collection: _this.collectionName,
607
+ id_document: '',
608
+ payload: JSON.stringify([res.value], null, 2),
609
+ method: 'findOneAndDelete',
610
+ id_user: '',
611
+ user: '',
612
+ messageId: 0,
613
+ route: ''
614
+ });
615
+ }, function (err) {
616
+ reject(err);
617
+ log_collection_1.Logs.insertOne({
618
+ _id: objectIdHexString(),
619
+ type: 'queryResponse',
620
+ collection: _this.collectionName,
621
+ id_document: '',
622
+ payload: JSON.stringify([err], null, 2),
623
+ method: 'findOneAndDelete',
624
+ id_user: '',
625
+ user: '',
626
+ messageId: 0,
627
+ route: ''
628
+ });
629
+ });
565
630
  return [2 /*return*/];
566
631
  }
567
632
  });
568
633
  }); });
569
634
  };
570
- Collection.prototype.findOneAndReplace = function (filter, replacement, options, bypassLogs) {
635
+ Collection.prototype.findOneAndReplace = function (filter, replacement, options, bypassLogs, bypassCheckSchema) {
571
636
  var _this = this;
572
637
  if (filter === void 0) { filter = {}; }
573
638
  if (bypassLogs === void 0) { bypassLogs = false; }
639
+ if (bypassCheckSchema === void 0) { bypassCheckSchema = false; }
574
640
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
575
641
  var validation, isValid, date, doc;
642
+ var _this = this;
576
643
  return __generator(this, function (_a) {
577
644
  switch (_a.label) {
578
645
  case 0:
579
- if (this.checkSchema) {
646
+ if (this.checkSchema && !bypassCheckSchema) {
580
647
  validation = this.simplschema.newContext();
581
648
  isValid = validation.validate(replacement);
582
649
  if (!isValid) {
@@ -590,12 +657,12 @@ var Collection = /** @class */ (function () {
590
657
  if (this.timestamps) {
591
658
  replacement['updatedAt'] = date;
592
659
  }
593
- if (!(this.createLogs && !bypassLogs)) return [3 /*break*/, 3];
660
+ if (!(this.createLogs && !bypassLogs)) return [3 /*break*/, 2];
594
661
  return [4 /*yield*/, this.findOne(filter)];
595
662
  case 1:
596
663
  doc = _a.sent();
597
- if (!doc) return [3 /*break*/, 3];
598
- return [4 /*yield*/, log_collection_1.Logs.insertOne({
664
+ if (doc) {
665
+ log_collection_1.Logs.insertOne({
599
666
  _id: objectIdHexString(),
600
667
  type: 'document',
601
668
  collection: this.collectionName,
@@ -606,11 +673,10 @@ var Collection = /** @class */ (function () {
606
673
  user: '',
607
674
  messageId: 0,
608
675
  route: ''
609
- })];
676
+ });
677
+ }
678
+ _a.label = 2;
610
679
  case 2:
611
- _a.sent();
612
- _a.label = 3;
613
- case 3:
614
680
  index_1.ResolveIOServer.getMainDB().collection(this.collectionName).findOneAndReplace(filter, replacement, options).then(function (res) {
615
681
  if (res.ok) {
616
682
  resolve(res.value);
@@ -618,22 +684,50 @@ var Collection = /** @class */ (function () {
618
684
  else {
619
685
  reject(res.lastErrorObject);
620
686
  }
621
- }, function (err) { return reject(err); });
687
+ log_collection_1.Logs.insertOne({
688
+ _id: objectIdHexString(),
689
+ type: 'queryResponse',
690
+ collection: _this.collectionName,
691
+ id_document: '',
692
+ payload: JSON.stringify([res.value], null, 2),
693
+ method: 'findOneAndReplace',
694
+ id_user: '',
695
+ user: '',
696
+ messageId: 0,
697
+ route: ''
698
+ });
699
+ }, function (err) {
700
+ reject(err);
701
+ log_collection_1.Logs.insertOne({
702
+ _id: objectIdHexString(),
703
+ type: 'queryResponse',
704
+ collection: _this.collectionName,
705
+ id_document: '',
706
+ payload: JSON.stringify([err], null, 2),
707
+ method: 'findOneAndReplace',
708
+ id_user: '',
709
+ user: '',
710
+ messageId: 0,
711
+ route: ''
712
+ });
713
+ });
622
714
  return [2 /*return*/];
623
715
  }
624
716
  });
625
717
  }); });
626
718
  };
627
- Collection.prototype.findOneAndUpdate = function (filter, update, options, bypassLogs) {
719
+ Collection.prototype.findOneAndUpdate = function (filter, update, options, bypassLogs, bypassCheckSchema) {
628
720
  var _this = this;
629
721
  if (filter === void 0) { filter = {}; }
630
722
  if (bypassLogs === void 0) { bypassLogs = false; }
723
+ if (bypassCheckSchema === void 0) { bypassCheckSchema = false; }
631
724
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
632
725
  var validation, isValid, date, doc;
726
+ var _this = this;
633
727
  return __generator(this, function (_a) {
634
728
  switch (_a.label) {
635
729
  case 0:
636
- if (this.checkSchema) {
730
+ if (this.checkSchema && !bypassCheckSchema) {
637
731
  validation = this.simplschema.newContext();
638
732
  isValid = validation.validate(update, { modifier: true });
639
733
  if (!isValid) {
@@ -652,12 +746,12 @@ var Collection = /** @class */ (function () {
652
746
  update['$set']['updatedAt'] = date;
653
747
  }
654
748
  }
655
- if (!(this.createLogs && !bypassLogs)) return [3 /*break*/, 3];
749
+ if (!(this.createLogs && !bypassLogs)) return [3 /*break*/, 2];
656
750
  return [4 /*yield*/, this.findOne(filter)];
657
751
  case 1:
658
752
  doc = _a.sent();
659
- if (!doc) return [3 /*break*/, 3];
660
- return [4 /*yield*/, log_collection_1.Logs.insertOne({
753
+ if (doc) {
754
+ log_collection_1.Logs.insertOne({
661
755
  _id: objectIdHexString(),
662
756
  type: 'document',
663
757
  collection: this.collectionName,
@@ -668,11 +762,10 @@ var Collection = /** @class */ (function () {
668
762
  user: '',
669
763
  messageId: 0,
670
764
  route: ''
671
- })];
765
+ });
766
+ }
767
+ _a.label = 2;
672
768
  case 2:
673
- _a.sent();
674
- _a.label = 3;
675
- case 3:
676
769
  index_1.ResolveIOServer.getMainDB().collection(this.collectionName).findOneAndUpdate(filter, update, options).then(function (res) {
677
770
  if (res.ok) {
678
771
  resolve(res.value);
@@ -680,7 +773,33 @@ var Collection = /** @class */ (function () {
680
773
  else {
681
774
  reject(res.lastErrorObject);
682
775
  }
683
- }, function (err) { return reject(err); });
776
+ log_collection_1.Logs.insertOne({
777
+ _id: objectIdHexString(),
778
+ type: 'queryResponse',
779
+ collection: _this.collectionName,
780
+ id_document: '',
781
+ payload: JSON.stringify([res.value], null, 2),
782
+ method: 'findOneAndUpdate',
783
+ id_user: '',
784
+ user: '',
785
+ messageId: 0,
786
+ route: ''
787
+ });
788
+ }, function (err) {
789
+ reject(err);
790
+ log_collection_1.Logs.insertOne({
791
+ _id: objectIdHexString(),
792
+ type: 'queryResponse',
793
+ collection: _this.collectionName,
794
+ id_document: '',
795
+ payload: JSON.stringify([err], null, 2),
796
+ method: 'findOneAndUpdate',
797
+ id_user: '',
798
+ user: '',
799
+ messageId: 0,
800
+ route: ''
801
+ });
802
+ });
684
803
  return [2 /*return*/];
685
804
  }
686
805
  });
@@ -692,137 +811,128 @@ var Collection = /** @class */ (function () {
692
811
  Collection.prototype.indexExists = function (indexes, options) {
693
812
  return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).indexExists(indexes, options);
694
813
  };
695
- Collection.prototype.insertMany = function (docs, options, bypassLogs) {
814
+ Collection.prototype.insertMany = function (docs, options, bypassLogs, bypassCheckSchema) {
696
815
  var _this = this;
697
816
  if (bypassLogs === void 0) { bypassLogs = false; }
817
+ if (bypassCheckSchema === void 0) { bypassCheckSchema = false; }
698
818
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
699
819
  var validationResults, validDocs, i, doc, date;
700
820
  var _this = this;
701
821
  return __generator(this, function (_a) {
702
- switch (_a.label) {
703
- case 0:
704
- if (!docs.length) {
705
- reject('No Documents');
706
- return [2 /*return*/];
822
+ if (!docs.length) {
823
+ reject('No Documents');
824
+ return [2 /*return*/];
825
+ }
826
+ validationResults = [];
827
+ if (this.checkSchema && !bypassCheckSchema) {
828
+ docs.forEach(function (doc) {
829
+ var validation = _this.simplschema.newContext();
830
+ var isValid = validation.validate(doc);
831
+ if (!isValid) {
832
+ console.log(new Date(), _this.collectionName, 'Schema Errors - insertMany', validation.validationErrors());
833
+ index_1.ResolveIOServer.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on insertMany - ' + _this.collectionName, [validation.validationErrors(), doc]);
834
+ validationResults.push(false);
707
835
  }
708
- validationResults = [];
709
- if (this.checkSchema) {
710
- docs.forEach(function (doc) {
711
- var validation = _this.simplschema.newContext();
712
- var isValid = validation.validate(doc);
713
- if (!isValid) {
714
- console.log(new Date(), _this.collectionName, 'Schema Errors - insertMany', validation.validationErrors());
715
- index_1.ResolveIOServer.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on insertMany - ' + _this.collectionName, [validation.validationErrors(), doc]);
716
- validationResults.push(false);
717
- }
718
- else {
719
- validationResults.push(true);
720
- }
721
- });
836
+ else {
837
+ validationResults.push(true);
722
838
  }
723
- validDocs = this.checkSchema ? docs.filter(function (a, idx) { return validationResults[idx]; }) : docs;
724
- i = 0;
725
- _a.label = 1;
726
- case 1:
727
- if (!(i < validDocs.length)) return [3 /*break*/, 4];
728
- doc = validDocs[i];
729
- if (this.timestamps) {
730
- date = new Date();
731
- doc['createdAt'] = date;
732
- doc['updatedAt'] = date;
839
+ });
840
+ }
841
+ validDocs = this.checkSchema ? docs.filter(function (a, idx) { return validationResults[idx]; }) : docs;
842
+ for (i = 0; i < validDocs.length; i++) {
843
+ doc = validDocs[i];
844
+ if (!doc['_id']) {
845
+ doc['_id'] = objectIdHexString();
846
+ }
847
+ if (this.timestamps) {
848
+ date = new Date();
849
+ doc['createdAt'] = date;
850
+ doc['updatedAt'] = date;
851
+ }
852
+ if (this.createLogs && !bypassLogs) {
853
+ log_collection_1.Logs.insertOne({
854
+ _id: objectIdHexString(),
855
+ type: 'document',
856
+ collection: this.collectionName,
857
+ id_document: doc['_id'],
858
+ payload: common_1.getBinarySize(JSON.stringify([doc, options])) < 200000 ? JSON.stringify([doc, options], null, 2) : 'Too Big',
859
+ method: 'insertMany',
860
+ id_user: '',
861
+ user: '',
862
+ messageId: 0,
863
+ route: ''
864
+ });
865
+ }
866
+ }
867
+ if (validDocs.length) {
868
+ index_1.ResolveIOServer.getMainDB().collection(this.collectionName).insertMany(validDocs, options).then(function (res) {
869
+ if (res.result.ok) {
870
+ resolve(validDocs);
733
871
  }
734
- if (!(this.createLogs && !bypassLogs)) return [3 /*break*/, 3];
735
- return [4 /*yield*/, log_collection_1.Logs.insertOne({
736
- _id: objectIdHexString(),
737
- type: 'document',
738
- collection: this.collectionName,
739
- id_document: doc['_id'],
740
- payload: common_1.getBinarySize(JSON.stringify([doc, options])) < 200000 ? JSON.stringify([doc, options], null, 2) : 'Too Big',
741
- method: 'insertMany',
742
- id_user: '',
743
- user: '',
744
- messageId: 0,
745
- route: ''
746
- })];
747
- case 2:
748
- _a.sent();
749
- _a.label = 3;
750
- case 3:
751
- i++;
752
- return [3 /*break*/, 1];
753
- case 4:
754
- if (validDocs.length) {
755
- index_1.ResolveIOServer.getMainDB().collection(this.collectionName).insertMany(validDocs, options).then(function (res) {
756
- if (res.result.ok) {
757
- resolve(validDocs);
758
- }
759
- else {
760
- reject(res.result.ok);
761
- }
762
- }, function (err) {
763
- reject(err);
764
- });
872
+ else {
873
+ reject(res.result.ok);
765
874
  }
766
- return [2 /*return*/];
875
+ }, function (err) {
876
+ reject(err);
877
+ });
767
878
  }
879
+ return [2 /*return*/];
768
880
  });
769
881
  }); });
770
882
  };
771
- Collection.prototype.insertOne = function (doc, options, bypassLogs) {
883
+ Collection.prototype.insertOne = function (doc, options, bypassLogs, bypassCheckSchema) {
772
884
  var _this = this;
773
885
  if (bypassLogs === void 0) { bypassLogs = false; }
886
+ if (bypassCheckSchema === void 0) { bypassCheckSchema = false; }
774
887
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
775
888
  var validation, isValid, date;
776
889
  return __generator(this, function (_a) {
777
- switch (_a.label) {
778
- case 0:
779
- if (this.checkSchema) {
780
- validation = this.simplschema.newContext();
781
- isValid = validation.validate(doc);
782
- if (!isValid) {
783
- console.log(new Date(), this.collectionName, 'Schema Errors - insertOne', validation.validationErrors());
784
- index_1.ResolveIOServer.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on insertOne - ' + this.collectionName, [validation.validationErrors(), doc]);
785
- reject(validation.validationErrors());
786
- return [2 /*return*/];
787
- }
788
- }
789
- if (this.timestamps) {
790
- date = new Date();
791
- doc['createdAt'] = date;
792
- doc['updatedAt'] = date;
793
- }
794
- if (!(this.createLogs && !bypassLogs)) return [3 /*break*/, 2];
795
- return [4 /*yield*/, log_collection_1.Logs.insertOne({
796
- _id: objectIdHexString(),
797
- type: 'document',
798
- collection: this.collectionName,
799
- id_document: doc['_id'],
800
- payload: common_1.getBinarySize(JSON.stringify([doc, options])) < 200000 ? JSON.stringify([doc, options], null, 2) : 'Too Big',
801
- method: 'insertOne',
802
- id_user: '',
803
- user: '',
804
- messageId: 0,
805
- route: ''
806
- })];
807
- case 1:
808
- _a.sent();
809
- _a.label = 2;
810
- case 2:
811
- if (this.useVersions && !doc.hasOwnProperty('__v')) {
812
- doc['__v'] = 0;
813
- }
814
- index_1.ResolveIOServer.getMainDB().collection(this.collectionName).insertOne(doc, options).then(function (res) {
815
- if (res.result.ok) {
816
- resolve(doc);
817
- }
818
- else {
819
- reject(res.result.ok);
820
- }
821
- }, function (err) {
822
- reject(err);
823
- });
890
+ if (!doc['_id']) {
891
+ doc['_id'] = objectIdHexString();
892
+ }
893
+ if (this.checkSchema && !bypassCheckSchema) {
894
+ validation = this.simplschema.newContext();
895
+ isValid = validation.validate(doc);
896
+ if (!isValid) {
897
+ console.log(new Date(), this.collectionName, 'Schema Errors - insertOne', validation.validationErrors());
898
+ index_1.ResolveIOServer.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on insertOne - ' + this.collectionName, [validation.validationErrors(), doc]);
899
+ reject(validation.validationErrors());
824
900
  return [2 /*return*/];
901
+ }
902
+ }
903
+ if (this.timestamps) {
904
+ date = new Date();
905
+ doc['createdAt'] = date;
906
+ doc['updatedAt'] = date;
825
907
  }
908
+ if (this.createLogs && !bypassLogs) {
909
+ log_collection_1.Logs.insertOne({
910
+ _id: objectIdHexString(),
911
+ type: 'document',
912
+ collection: this.collectionName,
913
+ id_document: doc['_id'],
914
+ payload: common_1.getBinarySize(JSON.stringify([doc, options])) < 200000 ? JSON.stringify([doc, options], null, 2) : 'Too Big',
915
+ method: 'insertOne',
916
+ id_user: '',
917
+ user: '',
918
+ messageId: 0,
919
+ route: ''
920
+ });
921
+ }
922
+ if (this.useVersions && !doc.hasOwnProperty('__v')) {
923
+ doc['__v'] = 0;
924
+ }
925
+ index_1.ResolveIOServer.getMainDB().collection(this.collectionName).insertOne(doc, options).then(function (res) {
926
+ if (res.result.ok) {
927
+ resolve(doc);
928
+ }
929
+ else {
930
+ reject(res.result.ok);
931
+ }
932
+ }, function (err) {
933
+ reject(err);
934
+ });
935
+ return [2 /*return*/];
826
936
  });
827
937
  }); });
828
938
  };
@@ -835,16 +945,17 @@ var Collection = /** @class */ (function () {
835
945
  Collection.prototype.rename = function (newName, options) {
836
946
  return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).rename(newName, options);
837
947
  };
838
- Collection.prototype.replaceOne = function (filter, replacement, options, bypassLogs, doc) {
948
+ Collection.prototype.replaceOne = function (filter, replacement, options, bypassLogs, bypassCheckSchema, doc) {
839
949
  var _this = this;
840
950
  if (bypassLogs === void 0) { bypassLogs = false; }
951
+ if (bypassCheckSchema === void 0) { bypassCheckSchema = false; }
841
952
  if (doc === void 0) { doc = null; }
842
953
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
843
954
  var validation, isValid, date, versionDoc, prevDoc, docId, docVersion, updatedDoc;
844
955
  return __generator(this, function (_a) {
845
956
  switch (_a.label) {
846
957
  case 0:
847
- if (this.checkSchema) {
958
+ if (this.checkSchema && !bypassCheckSchema) {
848
959
  validation = this.simplschema.newContext();
849
960
  isValid = validation.validate(replacement);
850
961
  if (!isValid) {
@@ -864,9 +975,9 @@ var Collection = /** @class */ (function () {
864
975
  doc = _a.sent();
865
976
  _a.label = 2;
866
977
  case 2:
867
- if (!doc) return [3 /*break*/, 13];
868
- if (!(this.createLogs && !bypassLogs)) return [3 /*break*/, 4];
869
- return [4 /*yield*/, log_collection_1.Logs.insertOne({
978
+ if (!doc) return [3 /*break*/, 11];
979
+ if (this.createLogs && !bypassLogs) {
980
+ log_collection_1.Logs.insertOne({
870
981
  _id: objectIdHexString(),
871
982
  type: 'document',
872
983
  collection: this.collectionName,
@@ -877,30 +988,27 @@ var Collection = /** @class */ (function () {
877
988
  user: '',
878
989
  messageId: 0,
879
990
  route: ''
880
- })];
881
- case 3:
882
- _a.sent();
883
- _a.label = 4;
884
- case 4:
885
- if (!this.useVersions) return [3 /*break*/, 11];
886
- if (!(doc['__v'] === replacement['__v'])) return [3 /*break*/, 8];
991
+ });
992
+ }
993
+ if (!this.useVersions) return [3 /*break*/, 9];
994
+ if (!(doc['__v'] === replacement['__v'])) return [3 /*break*/, 6];
887
995
  replacement['__v'] += 1;
888
996
  versionDoc = common_1.deepCopy(doc);
889
997
  versionDoc['_id'] = { _id: doc['_id'], __v: doc['__v'] };
890
998
  return [4 /*yield*/, index_1.ResolveIOServer.getMongoManager().collection(this.versionCollection).replaceOne({ _id: { _id: doc['_id'], __v: doc['__v'] } }, versionDoc, { upsert: true })];
891
- case 5:
999
+ case 3:
892
1000
  _a.sent();
893
- if (!(doc['__v'] >= 4)) return [3 /*break*/, 7];
1001
+ if (!(doc['__v'] >= 4)) return [3 /*break*/, 5];
894
1002
  return [4 /*yield*/, index_1.ResolveIOServer.getMongoManager().collection(this.versionCollection).deleteMany({
895
1003
  _id: {
896
1004
  _id: doc['_id'],
897
1005
  __v: { $lte: doc['__v'] - 4 }
898
1006
  }
899
1007
  })];
900
- case 6:
1008
+ case 4:
901
1009
  _a.sent();
902
- _a.label = 7;
903
- case 7:
1010
+ _a.label = 5;
1011
+ case 5:
904
1012
  index_1.ResolveIOServer.getMainDB().collection(this.collectionName).replaceOne(filter, replacement, options).then(function (res) {
905
1013
  if (res.result.ok) {
906
1014
  resolve(res.result.nModified);
@@ -911,8 +1019,8 @@ var Collection = /** @class */ (function () {
911
1019
  }, function (err) {
912
1020
  reject(err);
913
1021
  });
914
- return [3 /*break*/, 10];
915
- case 8:
1022
+ return [3 /*break*/, 8];
1023
+ case 6:
916
1024
  console.log('invalid version - ' + this.collectionName, doc['__v'], replacement['__v']);
917
1025
  return [4 /*yield*/, index_1.ResolveIOServer.getMongoManager().collection(this.versionCollection).findOne({
918
1026
  _id: {
@@ -920,7 +1028,7 @@ var Collection = /** @class */ (function () {
920
1028
  __v: replacement['__v']
921
1029
  }
922
1030
  })];
923
- case 9:
1031
+ case 7:
924
1032
  prevDoc = _a.sent();
925
1033
  if (prevDoc) {
926
1034
  docId = doc['_id'];
@@ -942,9 +1050,9 @@ var Collection = /** @class */ (function () {
942
1050
  else {
943
1051
  reject('Invalid Version And Could Not Find History - DB: ' + doc['__v'] + ', Trying to update with :' + replacement['__v']);
944
1052
  }
945
- _a.label = 10;
946
- case 10: return [3 /*break*/, 12];
947
- case 11:
1053
+ _a.label = 8;
1054
+ case 8: return [3 /*break*/, 10];
1055
+ case 9:
948
1056
  index_1.ResolveIOServer.getMainDB().collection(this.collectionName).replaceOne(filter, replacement, options).then(function (res) {
949
1057
  if (res.result.ok) {
950
1058
  resolve(res.result.nModified);
@@ -955,48 +1063,46 @@ var Collection = /** @class */ (function () {
955
1063
  }, function (err) {
956
1064
  reject(err);
957
1065
  });
958
- _a.label = 12;
959
- case 12: return [3 /*break*/, 17];
960
- case 13:
961
- if (!(options && options.upsert)) return [3 /*break*/, 16];
962
- if (this.timestamps) {
963
- replacement['createdAt'] = date;
964
- }
965
- if (!(this.createLogs && !bypassLogs)) return [3 /*break*/, 15];
966
- return [4 /*yield*/, log_collection_1.Logs.insertOne({
967
- _id: objectIdHexString(),
968
- type: 'document',
969
- collection: this.collectionName,
970
- id_document: replacement['_id'],
971
- payload: common_1.getBinarySize(JSON.stringify([filter, replacement, options])) < 200000 ? JSON.stringify([filter, replacement, options], null, 2) : 'Too Big',
972
- method: 'replaceOne',
973
- id_user: '',
974
- user: '',
975
- messageId: 0,
976
- route: ''
977
- })];
978
- case 14:
979
- _a.sent();
980
- _a.label = 15;
981
- case 15:
982
- if (this.useVersions) {
983
- replacement['__v'] = 0;
984
- }
985
- index_1.ResolveIOServer.getMainDB().collection(this.collectionName).replaceOne(filter, replacement, options).then(function (res) {
986
- if (res.result.ok) {
987
- resolve(res.result.nModified);
1066
+ _a.label = 10;
1067
+ case 10: return [3 /*break*/, 12];
1068
+ case 11:
1069
+ if (options && options.upsert) {
1070
+ if (this.timestamps) {
1071
+ replacement['createdAt'] = date;
988
1072
  }
989
- else {
990
- reject(res.result.ok);
1073
+ if (this.createLogs && !bypassLogs) {
1074
+ log_collection_1.Logs.insertOne({
1075
+ _id: objectIdHexString(),
1076
+ type: 'document',
1077
+ collection: this.collectionName,
1078
+ id_document: replacement['_id'],
1079
+ payload: common_1.getBinarySize(JSON.stringify([filter, replacement, options])) < 200000 ? JSON.stringify([filter, replacement, options], null, 2) : 'Too Big',
1080
+ method: 'replaceOne',
1081
+ id_user: '',
1082
+ user: '',
1083
+ messageId: 0,
1084
+ route: ''
1085
+ });
991
1086
  }
992
- }, function (err) {
993
- reject(err);
994
- });
995
- return [3 /*break*/, 17];
996
- case 16:
997
- reject('No Document');
998
- _a.label = 17;
999
- case 17: return [2 /*return*/];
1087
+ if (this.useVersions) {
1088
+ replacement['__v'] = 0;
1089
+ }
1090
+ index_1.ResolveIOServer.getMainDB().collection(this.collectionName).replaceOne(filter, replacement, options).then(function (res) {
1091
+ if (res.result.ok) {
1092
+ resolve(res.result.nModified);
1093
+ }
1094
+ else {
1095
+ reject(res.result.ok);
1096
+ }
1097
+ }, function (err) {
1098
+ reject(err);
1099
+ });
1100
+ }
1101
+ else {
1102
+ reject('No Document');
1103
+ }
1104
+ _a.label = 12;
1105
+ case 12: return [2 /*return*/];
1000
1106
  }
1001
1107
  });
1002
1108
  }); });
@@ -1004,9 +1110,10 @@ var Collection = /** @class */ (function () {
1004
1110
  Collection.prototype.stats = function (options) {
1005
1111
  return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).stats(options);
1006
1112
  };
1007
- Collection.prototype.updateMany = function (filter, update, options, bypassLogs) {
1113
+ Collection.prototype.updateMany = function (filter, update, options, bypassLogs, bypassCheckSchema) {
1008
1114
  var _this = this;
1009
1115
  if (bypassLogs === void 0) { bypassLogs = false; }
1116
+ if (bypassCheckSchema === void 0) { bypassCheckSchema = false; }
1010
1117
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1011
1118
  var date, validation, isValid, docs, i, doc;
1012
1119
  return __generator(this, function (_a) {
@@ -1021,7 +1128,7 @@ var Collection = /** @class */ (function () {
1021
1128
  update.$set['updatedAt'] = date;
1022
1129
  }
1023
1130
  }
1024
- if (this.checkSchema) {
1131
+ if (this.checkSchema && !bypassCheckSchema) {
1025
1132
  validation = this.simplschema.newContext();
1026
1133
  isValid = validation.validate(update, { modifier: true });
1027
1134
  if (!isValid) {
@@ -1031,16 +1138,13 @@ var Collection = /** @class */ (function () {
1031
1138
  return [2 /*return*/];
1032
1139
  }
1033
1140
  }
1034
- if (!(this.createLogs && !bypassLogs)) return [3 /*break*/, 5];
1141
+ if (!(this.createLogs && !bypassLogs)) return [3 /*break*/, 2];
1035
1142
  return [4 /*yield*/, this.find(filter)];
1036
1143
  case 1:
1037
1144
  docs = _a.sent();
1038
- i = 0;
1039
- _a.label = 2;
1040
- case 2:
1041
- if (!(i < docs.length)) return [3 /*break*/, 5];
1042
- doc = docs[i];
1043
- return [4 /*yield*/, log_collection_1.Logs.insertOne({
1145
+ for (i = 0; i < docs.length; i++) {
1146
+ doc = docs[i];
1147
+ log_collection_1.Logs.insertOne({
1044
1148
  _id: objectIdHexString(),
1045
1149
  type: 'document',
1046
1150
  collection: this.collectionName,
@@ -1051,14 +1155,10 @@ var Collection = /** @class */ (function () {
1051
1155
  user: '',
1052
1156
  messageId: 0,
1053
1157
  route: ''
1054
- })];
1055
- case 3:
1056
- _a.sent();
1057
- _a.label = 4;
1058
- case 4:
1059
- i++;
1060
- return [3 /*break*/, 2];
1061
- case 5:
1158
+ });
1159
+ }
1160
+ _a.label = 2;
1161
+ case 2:
1062
1162
  index_1.ResolveIOServer.getMainDB().collection(this.collectionName).updateMany(filter, update, options).then(function (res) {
1063
1163
  if (res.result.ok) {
1064
1164
  resolve(res.result.nModified);
@@ -1072,9 +1172,10 @@ var Collection = /** @class */ (function () {
1072
1172
  });
1073
1173
  }); });
1074
1174
  };
1075
- Collection.prototype.updateOne = function (filter, update, options, bypassLogs) {
1175
+ Collection.prototype.updateOne = function (filter, update, options, bypassLogs, bypassCheckSchema) {
1076
1176
  var _this = this;
1077
1177
  if (bypassLogs === void 0) { bypassLogs = false; }
1178
+ if (bypassCheckSchema === void 0) { bypassCheckSchema = false; }
1078
1179
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1079
1180
  var date, validation, isValid, doc, versionDoc;
1080
1181
  return __generator(this, function (_a) {
@@ -1089,7 +1190,7 @@ var Collection = /** @class */ (function () {
1089
1190
  update.$set['updatedAt'] = date;
1090
1191
  }
1091
1192
  }
1092
- if (this.checkSchema) {
1193
+ if (this.checkSchema && !bypassCheckSchema) {
1093
1194
  validation = this.simplschema.newContext();
1094
1195
  isValid = validation.validate(update, { modifier: true });
1095
1196
  if (!isValid) {
@@ -1102,9 +1203,9 @@ var Collection = /** @class */ (function () {
1102
1203
  return [4 /*yield*/, this.findOne(filter)];
1103
1204
  case 1:
1104
1205
  doc = _a.sent();
1105
- if (!doc) return [3 /*break*/, 9];
1106
- if (!(this.createLogs && !bypassLogs)) return [3 /*break*/, 3];
1107
- return [4 /*yield*/, log_collection_1.Logs.insertOne({
1206
+ if (!doc) return [3 /*break*/, 7];
1207
+ if (this.createLogs && !bypassLogs) {
1208
+ log_collection_1.Logs.insertOne({
1108
1209
  _id: objectIdHexString(),
1109
1210
  type: 'document',
1110
1211
  collection: this.collectionName,
@@ -1115,28 +1216,25 @@ var Collection = /** @class */ (function () {
1115
1216
  user: '',
1116
1217
  messageId: 0,
1117
1218
  route: ''
1118
- })];
1119
- case 2:
1120
- _a.sent();
1121
- _a.label = 3;
1122
- case 3:
1123
- if (!this.useVersions) return [3 /*break*/, 7];
1219
+ });
1220
+ }
1221
+ if (!this.useVersions) return [3 /*break*/, 5];
1124
1222
  versionDoc = common_1.deepCopy(doc);
1125
1223
  versionDoc['_id'] = { _id: doc['_id'], __v: doc['__v'] };
1126
1224
  return [4 /*yield*/, index_1.ResolveIOServer.getMongoManager().collection(this.versionCollection).replaceOne({ _id: { _id: doc['_id'], __v: doc['__v'] } }, versionDoc, { upsert: true })];
1127
- case 4:
1225
+ case 2:
1128
1226
  _a.sent();
1129
- if (!(doc['__v'] >= 4)) return [3 /*break*/, 6];
1227
+ if (!(doc['__v'] >= 4)) return [3 /*break*/, 4];
1130
1228
  return [4 /*yield*/, index_1.ResolveIOServer.getMongoManager().collection(this.versionCollection).deleteMany({
1131
1229
  _id: {
1132
1230
  _id: doc['_id'],
1133
1231
  __v: { $lte: doc['__v'] - 4 }
1134
1232
  }
1135
1233
  })];
1136
- case 5:
1234
+ case 3:
1137
1235
  _a.sent();
1138
- _a.label = 6;
1139
- case 6:
1236
+ _a.label = 4;
1237
+ case 4:
1140
1238
  if (!objectContainsPropertyDeep(update, '__v')) {
1141
1239
  if (!update.$inc) {
1142
1240
  update.$inc = { __v: 1 };
@@ -1153,8 +1251,8 @@ var Collection = /** @class */ (function () {
1153
1251
  reject(res.result.ok);
1154
1252
  }
1155
1253
  }, function (err) { return reject(err); });
1156
- return [3 /*break*/, 8];
1157
- case 7:
1254
+ return [3 /*break*/, 6];
1255
+ case 5:
1158
1256
  index_1.ResolveIOServer.getMainDB().collection(this.collectionName).updateOne(filter, update, options).then(function (res) {
1159
1257
  if (res.result.ok) {
1160
1258
  resolve(res.result.nModified);
@@ -1163,50 +1261,48 @@ var Collection = /** @class */ (function () {
1163
1261
  reject(res.result.ok);
1164
1262
  }
1165
1263
  }, function (err) { return reject(err); });
1166
- _a.label = 8;
1167
- case 8: return [3 /*break*/, 13];
1168
- case 9:
1169
- if (!(options && options.upsert && update.$setOnInsert && update.$setOnInsert._id)) return [3 /*break*/, 12];
1170
- if (this.timestamps) {
1171
- if (!update.$setOnInsert.createdAt) {
1172
- update.$setOnInsert.createdAt = date;
1173
- }
1174
- }
1175
- if (!(this.createLogs && !bypassLogs)) return [3 /*break*/, 11];
1176
- return [4 /*yield*/, log_collection_1.Logs.insertOne({
1177
- _id: objectIdHexString(),
1178
- type: 'document',
1179
- collection: this.collectionName,
1180
- id_document: update.$setOnInsert._id,
1181
- payload: common_1.getBinarySize(JSON.stringify([filter, update, options])) < 200000 ? JSON.stringify([filter, update, options], null, 2) : 'Too Big',
1182
- method: 'updateOne',
1183
- id_user: '',
1184
- user: '',
1185
- messageId: 0,
1186
- route: ''
1187
- })];
1188
- case 10:
1189
- _a.sent();
1190
- _a.label = 11;
1191
- case 11:
1192
- if (this.useVersions) {
1193
- if (!objectContainsPropertyDeep(update, '__v')) {
1194
- update.$setOnInsert.__v = 0;
1264
+ _a.label = 6;
1265
+ case 6: return [3 /*break*/, 8];
1266
+ case 7:
1267
+ if (options && options.upsert && update.$setOnInsert && update.$setOnInsert._id) {
1268
+ if (this.timestamps) {
1269
+ if (!update.$setOnInsert.createdAt) {
1270
+ update.$setOnInsert.createdAt = date;
1271
+ }
1195
1272
  }
1196
- }
1197
- index_1.ResolveIOServer.getMainDB().collection(this.collectionName).updateOne(filter, update, options).then(function (res) {
1198
- if (res.result.ok) {
1199
- resolve(res.result.nModified);
1273
+ if (this.createLogs && !bypassLogs) {
1274
+ log_collection_1.Logs.insertOne({
1275
+ _id: objectIdHexString(),
1276
+ type: 'document',
1277
+ collection: this.collectionName,
1278
+ id_document: update.$setOnInsert._id,
1279
+ payload: common_1.getBinarySize(JSON.stringify([filter, update, options])) < 200000 ? JSON.stringify([filter, update, options], null, 2) : 'Too Big',
1280
+ method: 'updateOne',
1281
+ id_user: '',
1282
+ user: '',
1283
+ messageId: 0,
1284
+ route: ''
1285
+ });
1200
1286
  }
1201
- else {
1202
- reject(res.result.ok);
1287
+ if (this.useVersions) {
1288
+ if (!objectContainsPropertyDeep(update, '__v')) {
1289
+ update.$setOnInsert.__v = 0;
1290
+ }
1203
1291
  }
1204
- }, function (err) { return reject(err); });
1205
- return [3 /*break*/, 13];
1206
- case 12:
1207
- reject('No Document');
1208
- _a.label = 13;
1209
- case 13: return [2 /*return*/];
1292
+ index_1.ResolveIOServer.getMainDB().collection(this.collectionName).updateOne(filter, update, options).then(function (res) {
1293
+ if (res.result.ok) {
1294
+ resolve(res.result.nModified);
1295
+ }
1296
+ else {
1297
+ reject(res.result.ok);
1298
+ }
1299
+ }, function (err) { return reject(err); });
1300
+ }
1301
+ else {
1302
+ reject('No Document');
1303
+ }
1304
+ _a.label = 8;
1305
+ case 8: return [2 /*return*/];
1210
1306
  }
1211
1307
  });
1212
1308
  }); });