@resolveio/server-lib 9.0.35 → 9.0.37

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.
@@ -308,7 +308,7 @@ var Collection = /** @class */ (function () {
308
308
  method: 'deleteMany',
309
309
  id_user: '',
310
310
  user: '',
311
- messageId: '',
311
+ messageId: 0,
312
312
  route: ''
313
313
  });
314
314
  if (_this.useVersions) {
@@ -354,7 +354,7 @@ var Collection = /** @class */ (function () {
354
354
  method: 'deleteOne',
355
355
  id_user: '',
356
356
  user: '',
357
- messageId: '',
357
+ messageId: 0,
358
358
  route: ''
359
359
  });
360
360
  if (this.useVersions) {
@@ -404,7 +404,7 @@ var Collection = /** @class */ (function () {
404
404
  method: 'find',
405
405
  id_user: '',
406
406
  user: '',
407
- messageId: '',
407
+ messageId: 0,
408
408
  route: ''
409
409
  });
410
410
  }
@@ -444,7 +444,7 @@ var Collection = /** @class */ (function () {
444
444
  method: 'findCount',
445
445
  id_user: '',
446
446
  user: '',
447
- messageId: '',
447
+ messageId: 0,
448
448
  route: ''
449
449
  });
450
450
  }
@@ -473,7 +473,7 @@ var Collection = /** @class */ (function () {
473
473
  method: 'findOne',
474
474
  id_user: '',
475
475
  user: '',
476
- messageId: '',
476
+ messageId: 0,
477
477
  route: ''
478
478
  });
479
479
  }
@@ -520,7 +520,7 @@ var Collection = /** @class */ (function () {
520
520
  method: 'findOneAndDelete',
521
521
  id_user: '',
522
522
  user: '',
523
- messageId: '',
523
+ messageId: 0,
524
524
  route: ''
525
525
  });
526
526
  }
@@ -544,13 +544,14 @@ var Collection = /** @class */ (function () {
544
544
  if (filter === void 0) { filter = {}; }
545
545
  if (bypassLogs === void 0) { bypassLogs = false; }
546
546
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
547
- var validation, doc;
547
+ var validation, isValid, doc;
548
548
  return __generator(this, function (_a) {
549
549
  switch (_a.label) {
550
550
  case 0:
551
- validation = this.simplschema.newContext().validate(replacement);
552
- if (!!validation.isValid()) return [3 /*break*/, 1];
553
- console.log(new Date(), this.collectionName, 'Schema Errors', validation.validationErrors());
551
+ validation = this.simplschema.newContext();
552
+ isValid = validation.validate(replacement);
553
+ if (!!isValid) return [3 /*break*/, 1];
554
+ console.log(new Date(), this.collectionName, 'Schema Errors - findOneAndReplace', validation.validationErrors());
554
555
  index_1.ResolveIOServer.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on findOneAndReplace - ' + this.collectionName, [validation.validationErrors(), replacement]);
555
556
  reject(validation.validationErrors());
556
557
  return [3 /*break*/, 4];
@@ -572,7 +573,7 @@ var Collection = /** @class */ (function () {
572
573
  method: 'findOneAndReplace',
573
574
  id_user: '',
574
575
  user: '',
575
- messageId: '',
576
+ messageId: 0,
576
577
  route: ''
577
578
  });
578
579
  }
@@ -597,13 +598,14 @@ var Collection = /** @class */ (function () {
597
598
  if (filter === void 0) { filter = {}; }
598
599
  if (bypassLogs === void 0) { bypassLogs = false; }
599
600
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
600
- var validation, doc;
601
+ var validation, isValid, doc;
601
602
  return __generator(this, function (_a) {
602
603
  switch (_a.label) {
603
604
  case 0:
604
- validation = this.simplschema.newContext().validate(update, { modifier: true });
605
- if (!!validation.isValid()) return [3 /*break*/, 1];
606
- console.log(new Date(), this.collectionName, 'Schema Errors', validation.validationErrors());
605
+ validation = this.simplschema.newContext();
606
+ isValid = validation.validate(update, { modifier: true });
607
+ if (!!isValid) return [3 /*break*/, 1];
608
+ console.log(new Date(), this.collectionName, 'Schema Errors - findOneAndUpdate', validation.validationErrors());
607
609
  index_1.ResolveIOServer.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on findOneAndUpdate - ' + this.collectionName, [validation.validationErrors(), update]);
608
610
  reject(validation.validationErrors());
609
611
  return [3 /*break*/, 4];
@@ -630,7 +632,7 @@ var Collection = /** @class */ (function () {
630
632
  method: 'findOneAndUpdate',
631
633
  id_user: '',
632
634
  user: '',
633
- messageId: '',
635
+ messageId: 0,
634
636
  route: ''
635
637
  });
636
638
  }
@@ -666,9 +668,10 @@ var Collection = /** @class */ (function () {
666
668
  }
667
669
  var validationResults = [];
668
670
  docs.forEach(function (doc) {
669
- var validation = _this.simplschema.newContext().validate(doc);
670
- if (!validation.isValid()) {
671
- console.log(new Date(), _this.collectionName, 'Schema Errors', validation.validationErrors());
671
+ var validation = _this.simplschema.newContext();
672
+ var isValid = validation.validate(doc);
673
+ if (!isValid) {
674
+ console.log(new Date(), _this.collectionName, 'Schema Errors - insertMany', validation.validationErrors());
672
675
  index_1.ResolveIOServer.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on insertMany - ' + _this.collectionName, [validation.validationErrors(), doc]);
673
676
  validationResults.push(false);
674
677
  }
@@ -692,7 +695,7 @@ var Collection = /** @class */ (function () {
692
695
  method: 'insertMany',
693
696
  id_user: '',
694
697
  user: '',
695
- messageId: '',
698
+ messageId: 0,
696
699
  route: ''
697
700
  });
698
701
  }
@@ -715,9 +718,10 @@ var Collection = /** @class */ (function () {
715
718
  var _this = this;
716
719
  if (bypassLogs === void 0) { bypassLogs = false; }
717
720
  return new Promise(function (resolve, reject) {
718
- var validation = _this.simplschema.newContext().validate(doc);
719
- if (!validation.isValid()) {
720
- console.log(new Date(), _this.collectionName, 'Schema Errors', validation.validationErrors());
721
+ var validation = _this.simplschema.newContext();
722
+ var isValid = validation.validate(doc);
723
+ if (!isValid) {
724
+ console.log(new Date(), _this.collectionName, 'Schema Errors - insertOne', validation.validationErrors());
721
725
  index_1.ResolveIOServer.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on insertOne - ' + _this.collectionName, [validation.validationErrors(), doc]);
722
726
  reject(validation.validationErrors());
723
727
  }
@@ -736,7 +740,7 @@ var Collection = /** @class */ (function () {
736
740
  method: 'insertOne',
737
741
  id_user: '',
738
742
  user: '',
739
- messageId: '',
743
+ messageId: 0,
740
744
  route: ''
741
745
  });
742
746
  }
@@ -762,30 +766,33 @@ var Collection = /** @class */ (function () {
762
766
  Collection.prototype.rename = function (newName, options) {
763
767
  return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).rename(newName, options);
764
768
  };
765
- Collection.prototype.replaceOne = function (filter, replacement, options, bypassLogs, bypassDocument) {
769
+ Collection.prototype.replaceOne = function (filter, replacement, options, bypassLogs, doc) {
766
770
  var _this = this;
767
771
  if (bypassLogs === void 0) { bypassLogs = false; }
768
- if (bypassDocument === void 0) { bypassDocument = false; }
772
+ if (doc === void 0) { doc = null; }
769
773
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
770
- var validation, doc, versionDoc, prevDoc, docId, docVersion, updatedDoc;
774
+ var validation, isValid, versionDoc, prevDoc, docId, docVersion, updatedDoc;
771
775
  return __generator(this, function (_a) {
772
776
  switch (_a.label) {
773
777
  case 0:
774
- validation = this.simplschema.newContext().validate(replacement);
775
- if (!!validation.isValid()) return [3 /*break*/, 1];
776
- console.log(new Date(), this.collectionName, 'Schema Errors', validation.validationErrors());
778
+ validation = this.simplschema.newContext();
779
+ isValid = validation.validate(replacement);
780
+ if (!!isValid) return [3 /*break*/, 1];
781
+ console.log(new Date(), this.collectionName, 'Schema Errors - replaceOne', validation.validationErrors());
777
782
  index_1.ResolveIOServer.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on replaceOne - ' + this.collectionName, [validation.validationErrors(), replacement]);
778
783
  reject(validation.validationErrors());
779
- return [3 /*break*/, 11];
784
+ return [3 /*break*/, 10];
780
785
  case 1:
781
786
  if (this.timestamps) {
782
787
  replacement['updatedAt'] = new Date();
783
788
  }
784
- if (!!bypassDocument) return [3 /*break*/, 10];
789
+ if (!!doc) return [3 /*break*/, 3];
785
790
  return [4 /*yield*/, this.findOne(filter)];
786
791
  case 2:
787
792
  doc = _a.sent();
788
- if (!doc) return [3 /*break*/, 8];
793
+ _a.label = 3;
794
+ case 3:
795
+ if (!doc) return [3 /*break*/, 9];
789
796
  if (this.createLogs && !bypassLogs) {
790
797
  log_collection_1.Logs.insertOne({
791
798
  _id: objectIdHexString(),
@@ -796,11 +803,11 @@ var Collection = /** @class */ (function () {
796
803
  method: 'replaceOne',
797
804
  id_user: '',
798
805
  user: '',
799
- messageId: '',
806
+ messageId: 0,
800
807
  route: ''
801
808
  });
802
809
  }
803
- if (!this.useVersions) return [3 /*break*/, 6];
810
+ if (!this.useVersions) return [3 /*break*/, 7];
804
811
  versionDoc = common_1.deepCopy(doc);
805
812
  versionDoc['_id'] = { _id: doc['_id'], __v: doc['__v'] };
806
813
  index_1.ResolveIOServer.getMongoManager().collection(this.versionCollection).insertOne(versionDoc);
@@ -810,7 +817,7 @@ var Collection = /** @class */ (function () {
810
817
  { '_id.__v': { $lte: doc['__v'] - 4 } }
811
818
  ] });
812
819
  }
813
- if (!(doc['__v'] === replacement['__v'])) return [3 /*break*/, 3];
820
+ if (!(doc['__v'] === replacement['__v'])) return [3 /*break*/, 4];
814
821
  replacement['__v'] += 1;
815
822
  index_1.ResolveIOServer.getMainDB().collection(this.collectionName).replaceOne(filter, replacement, options).then(function (res) {
816
823
  if (res.result.ok) {
@@ -822,8 +829,8 @@ var Collection = /** @class */ (function () {
822
829
  }, function (err) {
823
830
  reject(err);
824
831
  });
825
- return [3 /*break*/, 5];
826
- case 3:
832
+ return [3 /*break*/, 6];
833
+ case 4:
827
834
  console.log('invalid version - ' + this.collectionName, doc['__v'], replacement['__v']);
828
835
  return [4 /*yield*/, index_1.ResolveIOServer.getMongoManager().collection(this.versionCollection).findOne({
829
836
  $and: [
@@ -831,7 +838,7 @@ var Collection = /** @class */ (function () {
831
838
  { '_id.__v': replacement['__v'] }
832
839
  ]
833
840
  })];
834
- case 4:
841
+ case 5:
835
842
  prevDoc = _a.sent();
836
843
  if (prevDoc) {
837
844
  docId = doc['_id'];
@@ -839,7 +846,6 @@ var Collection = /** @class */ (function () {
839
846
  updatedDoc = common_1.getMongoMergeUpdatedDoc(replacement, doc, prevDoc);
840
847
  updatedDoc['_id'] = docId;
841
848
  updatedDoc['__v'] = docVersion + 1;
842
- updatedDoc['updatedAt'] = new Date();
843
849
  index_1.ResolveIOServer.getMainDB().collection(this.collectionName).replaceOne(filter, updatedDoc, options).then(function (res) {
844
850
  if (res.result.ok) {
845
851
  resolve(res.result.nModified);
@@ -854,9 +860,9 @@ var Collection = /** @class */ (function () {
854
860
  else {
855
861
  reject('Invalid Version And Could Not Find History - DB: ' + doc['__v'] + ', Trying to update with :' + replacement['__v']);
856
862
  }
857
- _a.label = 5;
858
- case 5: return [3 /*break*/, 7];
859
- case 6:
863
+ _a.label = 6;
864
+ case 6: return [3 /*break*/, 8];
865
+ case 7:
860
866
  index_1.ResolveIOServer.getMainDB().collection(this.collectionName).replaceOne(filter, replacement, options).then(function (res) {
861
867
  if (res.result.ok) {
862
868
  resolve(res.result.nModified);
@@ -867,25 +873,12 @@ var Collection = /** @class */ (function () {
867
873
  }, function (err) {
868
874
  reject(err);
869
875
  });
870
- _a.label = 7;
871
- case 7: return [3 /*break*/, 9];
872
- case 8:
876
+ _a.label = 8;
877
+ case 8: return [3 /*break*/, 10];
878
+ case 9:
873
879
  reject('No Document');
874
- _a.label = 9;
875
- case 9: return [3 /*break*/, 11];
876
- case 10:
877
- index_1.ResolveIOServer.getMainDB().collection(this.collectionName).replaceOne(filter, replacement, options).then(function (res) {
878
- if (res.result.ok) {
879
- resolve(res.result.nModified);
880
- }
881
- else {
882
- reject(res.result.ok);
883
- }
884
- }, function (err) {
885
- reject(err);
886
- });
887
- _a.label = 11;
888
- case 11: return [2 /*return*/];
880
+ _a.label = 10;
881
+ case 10: return [2 /*return*/];
889
882
  }
890
883
  });
891
884
  }); });
@@ -897,7 +890,7 @@ var Collection = /** @class */ (function () {
897
890
  var _this = this;
898
891
  if (bypassLogs === void 0) { bypassLogs = false; }
899
892
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
900
- var validation, docs;
893
+ var validation, isValid, docs;
901
894
  var _this = this;
902
895
  return __generator(this, function (_a) {
903
896
  switch (_a.label) {
@@ -910,9 +903,10 @@ var Collection = /** @class */ (function () {
910
903
  update.$set['updatedAt'] = new Date();
911
904
  }
912
905
  }
913
- validation = this.simplschema.newContext().validate(update, { modifier: true });
914
- if (!!validation.isValid()) return [3 /*break*/, 1];
915
- console.log(new Date(), this.collectionName, 'Schema Errors', validation.validationErrors());
906
+ validation = this.simplschema.newContext();
907
+ isValid = validation.validate(update, { modifier: true });
908
+ if (!!isValid) return [3 /*break*/, 1];
909
+ console.log(new Date(), this.collectionName, 'Schema Errors - updateMany', validation.validationErrors());
916
910
  index_1.ResolveIOServer.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on updateMany - ' + this.collectionName, [validation.validationErrors(), update]);
917
911
  reject(validation.validationErrors());
918
912
  return [3 /*break*/, 4];
@@ -931,7 +925,7 @@ var Collection = /** @class */ (function () {
931
925
  method: 'updateMany',
932
926
  id_user: '',
933
927
  user: '',
934
- messageId: '',
928
+ messageId: 0,
935
929
  route: ''
936
930
  });
937
931
  });
@@ -955,7 +949,7 @@ var Collection = /** @class */ (function () {
955
949
  var _this = this;
956
950
  if (bypassLogs === void 0) { bypassLogs = false; }
957
951
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
958
- var validation, doc, versionDoc;
952
+ var validation, isValid, doc, versionDoc;
959
953
  return __generator(this, function (_a) {
960
954
  switch (_a.label) {
961
955
  case 0:
@@ -967,9 +961,10 @@ var Collection = /** @class */ (function () {
967
961
  update.$set['updatedAt'] = new Date();
968
962
  }
969
963
  }
970
- validation = this.simplschema.newContext().validate(update, { modifier: true });
971
- if (!!validation.isValid()) return [3 /*break*/, 1];
972
- console.log(new Date(), this.collectionName, 'Schema Errors', validation.validationErrors());
964
+ validation = this.simplschema.newContext();
965
+ isValid = validation.validate(update, { modifier: true });
966
+ if (!!isValid) return [3 /*break*/, 1];
967
+ console.log(new Date(), this.collectionName, 'Schema Errors - updateOne', validation.validationErrors());
973
968
  index_1.ResolveIOServer.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on updateOne - ' + this.collectionName, [validation.validationErrors(), update]);
974
969
  reject(validation.validationErrors());
975
970
  return [3 /*break*/, 3];
@@ -987,7 +982,7 @@ var Collection = /** @class */ (function () {
987
982
  method: 'updateOne',
988
983
  id_user: '',
989
984
  user: '',
990
- messageId: '',
985
+ messageId: 0,
991
986
  route: ''
992
987
  });
993
988
  }