@resolveio/server-lib 9.0.36 → 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
  }
@@ -551,7 +551,7 @@ var Collection = /** @class */ (function () {
551
551
  validation = this.simplschema.newContext();
552
552
  isValid = validation.validate(replacement);
553
553
  if (!!isValid) return [3 /*break*/, 1];
554
- console.log(new Date(), this.collectionName, 'Schema Errors', validation.validationErrors());
554
+ console.log(new Date(), this.collectionName, 'Schema Errors - findOneAndReplace', validation.validationErrors());
555
555
  index_1.ResolveIOServer.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on findOneAndReplace - ' + this.collectionName, [validation.validationErrors(), replacement]);
556
556
  reject(validation.validationErrors());
557
557
  return [3 /*break*/, 4];
@@ -573,7 +573,7 @@ var Collection = /** @class */ (function () {
573
573
  method: 'findOneAndReplace',
574
574
  id_user: '',
575
575
  user: '',
576
- messageId: '',
576
+ messageId: 0,
577
577
  route: ''
578
578
  });
579
579
  }
@@ -605,7 +605,7 @@ var Collection = /** @class */ (function () {
605
605
  validation = this.simplschema.newContext();
606
606
  isValid = validation.validate(update, { modifier: true });
607
607
  if (!!isValid) return [3 /*break*/, 1];
608
- console.log(new Date(), this.collectionName, 'Schema Errors', validation.validationErrors());
608
+ console.log(new Date(), this.collectionName, 'Schema Errors - findOneAndUpdate', validation.validationErrors());
609
609
  index_1.ResolveIOServer.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on findOneAndUpdate - ' + this.collectionName, [validation.validationErrors(), update]);
610
610
  reject(validation.validationErrors());
611
611
  return [3 /*break*/, 4];
@@ -632,7 +632,7 @@ var Collection = /** @class */ (function () {
632
632
  method: 'findOneAndUpdate',
633
633
  id_user: '',
634
634
  user: '',
635
- messageId: '',
635
+ messageId: 0,
636
636
  route: ''
637
637
  });
638
638
  }
@@ -671,7 +671,7 @@ var Collection = /** @class */ (function () {
671
671
  var validation = _this.simplschema.newContext();
672
672
  var isValid = validation.validate(doc);
673
673
  if (!isValid) {
674
- console.log(new Date(), _this.collectionName, 'Schema Errors', validation.validationErrors());
674
+ console.log(new Date(), _this.collectionName, 'Schema Errors - insertMany', validation.validationErrors());
675
675
  index_1.ResolveIOServer.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on insertMany - ' + _this.collectionName, [validation.validationErrors(), doc]);
676
676
  validationResults.push(false);
677
677
  }
@@ -695,7 +695,7 @@ var Collection = /** @class */ (function () {
695
695
  method: 'insertMany',
696
696
  id_user: '',
697
697
  user: '',
698
- messageId: '',
698
+ messageId: 0,
699
699
  route: ''
700
700
  });
701
701
  }
@@ -721,7 +721,7 @@ var Collection = /** @class */ (function () {
721
721
  var validation = _this.simplschema.newContext();
722
722
  var isValid = validation.validate(doc);
723
723
  if (!isValid) {
724
- console.log(new Date(), _this.collectionName, 'Schema Errors', validation.validationErrors());
724
+ console.log(new Date(), _this.collectionName, 'Schema Errors - insertOne', validation.validationErrors());
725
725
  index_1.ResolveIOServer.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on insertOne - ' + _this.collectionName, [validation.validationErrors(), doc]);
726
726
  reject(validation.validationErrors());
727
727
  }
@@ -740,7 +740,7 @@ var Collection = /** @class */ (function () {
740
740
  method: 'insertOne',
741
741
  id_user: '',
742
742
  user: '',
743
- messageId: '',
743
+ messageId: 0,
744
744
  route: ''
745
745
  });
746
746
  }
@@ -766,31 +766,33 @@ var Collection = /** @class */ (function () {
766
766
  Collection.prototype.rename = function (newName, options) {
767
767
  return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).rename(newName, options);
768
768
  };
769
- Collection.prototype.replaceOne = function (filter, replacement, options, bypassLogs, bypassDocument) {
769
+ Collection.prototype.replaceOne = function (filter, replacement, options, bypassLogs, doc) {
770
770
  var _this = this;
771
771
  if (bypassLogs === void 0) { bypassLogs = false; }
772
- if (bypassDocument === void 0) { bypassDocument = false; }
772
+ if (doc === void 0) { doc = null; }
773
773
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
774
- var validation, isValid, doc, versionDoc, prevDoc, docId, docVersion, updatedDoc;
774
+ var validation, isValid, versionDoc, prevDoc, docId, docVersion, updatedDoc;
775
775
  return __generator(this, function (_a) {
776
776
  switch (_a.label) {
777
777
  case 0:
778
778
  validation = this.simplschema.newContext();
779
779
  isValid = validation.validate(replacement);
780
780
  if (!!isValid) return [3 /*break*/, 1];
781
- console.log(new Date(), this.collectionName, 'Schema Errors', validation.validationErrors());
781
+ console.log(new Date(), this.collectionName, 'Schema Errors - replaceOne', validation.validationErrors());
782
782
  index_1.ResolveIOServer.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on replaceOne - ' + this.collectionName, [validation.validationErrors(), replacement]);
783
783
  reject(validation.validationErrors());
784
- return [3 /*break*/, 11];
784
+ return [3 /*break*/, 10];
785
785
  case 1:
786
786
  if (this.timestamps) {
787
787
  replacement['updatedAt'] = new Date();
788
788
  }
789
- if (!!bypassDocument) return [3 /*break*/, 10];
789
+ if (!!doc) return [3 /*break*/, 3];
790
790
  return [4 /*yield*/, this.findOne(filter)];
791
791
  case 2:
792
792
  doc = _a.sent();
793
- if (!doc) return [3 /*break*/, 8];
793
+ _a.label = 3;
794
+ case 3:
795
+ if (!doc) return [3 /*break*/, 9];
794
796
  if (this.createLogs && !bypassLogs) {
795
797
  log_collection_1.Logs.insertOne({
796
798
  _id: objectIdHexString(),
@@ -801,11 +803,11 @@ var Collection = /** @class */ (function () {
801
803
  method: 'replaceOne',
802
804
  id_user: '',
803
805
  user: '',
804
- messageId: '',
806
+ messageId: 0,
805
807
  route: ''
806
808
  });
807
809
  }
808
- if (!this.useVersions) return [3 /*break*/, 6];
810
+ if (!this.useVersions) return [3 /*break*/, 7];
809
811
  versionDoc = common_1.deepCopy(doc);
810
812
  versionDoc['_id'] = { _id: doc['_id'], __v: doc['__v'] };
811
813
  index_1.ResolveIOServer.getMongoManager().collection(this.versionCollection).insertOne(versionDoc);
@@ -815,7 +817,7 @@ var Collection = /** @class */ (function () {
815
817
  { '_id.__v': { $lte: doc['__v'] - 4 } }
816
818
  ] });
817
819
  }
818
- if (!(doc['__v'] === replacement['__v'])) return [3 /*break*/, 3];
820
+ if (!(doc['__v'] === replacement['__v'])) return [3 /*break*/, 4];
819
821
  replacement['__v'] += 1;
820
822
  index_1.ResolveIOServer.getMainDB().collection(this.collectionName).replaceOne(filter, replacement, options).then(function (res) {
821
823
  if (res.result.ok) {
@@ -827,8 +829,8 @@ var Collection = /** @class */ (function () {
827
829
  }, function (err) {
828
830
  reject(err);
829
831
  });
830
- return [3 /*break*/, 5];
831
- case 3:
832
+ return [3 /*break*/, 6];
833
+ case 4:
832
834
  console.log('invalid version - ' + this.collectionName, doc['__v'], replacement['__v']);
833
835
  return [4 /*yield*/, index_1.ResolveIOServer.getMongoManager().collection(this.versionCollection).findOne({
834
836
  $and: [
@@ -836,7 +838,7 @@ var Collection = /** @class */ (function () {
836
838
  { '_id.__v': replacement['__v'] }
837
839
  ]
838
840
  })];
839
- case 4:
841
+ case 5:
840
842
  prevDoc = _a.sent();
841
843
  if (prevDoc) {
842
844
  docId = doc['_id'];
@@ -844,7 +846,6 @@ var Collection = /** @class */ (function () {
844
846
  updatedDoc = common_1.getMongoMergeUpdatedDoc(replacement, doc, prevDoc);
845
847
  updatedDoc['_id'] = docId;
846
848
  updatedDoc['__v'] = docVersion + 1;
847
- updatedDoc['updatedAt'] = new Date();
848
849
  index_1.ResolveIOServer.getMainDB().collection(this.collectionName).replaceOne(filter, updatedDoc, options).then(function (res) {
849
850
  if (res.result.ok) {
850
851
  resolve(res.result.nModified);
@@ -859,9 +860,9 @@ var Collection = /** @class */ (function () {
859
860
  else {
860
861
  reject('Invalid Version And Could Not Find History - DB: ' + doc['__v'] + ', Trying to update with :' + replacement['__v']);
861
862
  }
862
- _a.label = 5;
863
- case 5: return [3 /*break*/, 7];
864
- case 6:
863
+ _a.label = 6;
864
+ case 6: return [3 /*break*/, 8];
865
+ case 7:
865
866
  index_1.ResolveIOServer.getMainDB().collection(this.collectionName).replaceOne(filter, replacement, options).then(function (res) {
866
867
  if (res.result.ok) {
867
868
  resolve(res.result.nModified);
@@ -872,25 +873,12 @@ var Collection = /** @class */ (function () {
872
873
  }, function (err) {
873
874
  reject(err);
874
875
  });
875
- _a.label = 7;
876
- case 7: return [3 /*break*/, 9];
877
- case 8:
876
+ _a.label = 8;
877
+ case 8: return [3 /*break*/, 10];
878
+ case 9:
878
879
  reject('No Document');
879
- _a.label = 9;
880
- case 9: return [3 /*break*/, 11];
881
- case 10:
882
- index_1.ResolveIOServer.getMainDB().collection(this.collectionName).replaceOne(filter, replacement, options).then(function (res) {
883
- if (res.result.ok) {
884
- resolve(res.result.nModified);
885
- }
886
- else {
887
- reject(res.result.ok);
888
- }
889
- }, function (err) {
890
- reject(err);
891
- });
892
- _a.label = 11;
893
- case 11: return [2 /*return*/];
880
+ _a.label = 10;
881
+ case 10: return [2 /*return*/];
894
882
  }
895
883
  });
896
884
  }); });
@@ -918,7 +906,7 @@ var Collection = /** @class */ (function () {
918
906
  validation = this.simplschema.newContext();
919
907
  isValid = validation.validate(update, { modifier: true });
920
908
  if (!!isValid) return [3 /*break*/, 1];
921
- console.log(new Date(), this.collectionName, 'Schema Errors', validation.validationErrors());
909
+ console.log(new Date(), this.collectionName, 'Schema Errors - updateMany', validation.validationErrors());
922
910
  index_1.ResolveIOServer.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on updateMany - ' + this.collectionName, [validation.validationErrors(), update]);
923
911
  reject(validation.validationErrors());
924
912
  return [3 /*break*/, 4];
@@ -937,7 +925,7 @@ var Collection = /** @class */ (function () {
937
925
  method: 'updateMany',
938
926
  id_user: '',
939
927
  user: '',
940
- messageId: '',
928
+ messageId: 0,
941
929
  route: ''
942
930
  });
943
931
  });
@@ -976,7 +964,7 @@ var Collection = /** @class */ (function () {
976
964
  validation = this.simplschema.newContext();
977
965
  isValid = validation.validate(update, { modifier: true });
978
966
  if (!!isValid) return [3 /*break*/, 1];
979
- console.log(new Date(), this.collectionName, 'Schema Errors', validation.validationErrors());
967
+ console.log(new Date(), this.collectionName, 'Schema Errors - updateOne', validation.validationErrors());
980
968
  index_1.ResolveIOServer.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on updateOne - ' + this.collectionName, [validation.validationErrors(), update]);
981
969
  reject(validation.validationErrors());
982
970
  return [3 /*break*/, 3];
@@ -994,7 +982,7 @@ var Collection = /** @class */ (function () {
994
982
  method: 'updateOne',
995
983
  id_user: '',
996
984
  user: '',
997
- messageId: '',
985
+ messageId: 0,
998
986
  route: ''
999
987
  });
1000
988
  }