@resolveio/server-lib 9.2.20 → 9.2.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.
|
@@ -393,38 +393,32 @@ var Collection = /** @class */ (function () {
|
|
|
393
393
|
return __generator(this, function (_a) {
|
|
394
394
|
switch (_a.label) {
|
|
395
395
|
case 0:
|
|
396
|
-
if (!(this.createLogs && !bypassLogs)) return [3 /*break*/,
|
|
396
|
+
if (!(this.createLogs && !bypassLogs)) return [3 /*break*/, 2];
|
|
397
397
|
return [4 /*yield*/, this.find(filter)];
|
|
398
398
|
case 1:
|
|
399
399
|
docs = _a.sent();
|
|
400
|
-
i = 0;
|
|
400
|
+
for (i = 0; i < docs.length; i++) {
|
|
401
|
+
doc = docs[i];
|
|
402
|
+
log_collection_1.Logs.insertOne({
|
|
403
|
+
_id: objectIdHexString(),
|
|
404
|
+
type: 'document',
|
|
405
|
+
collection: this.collectionName,
|
|
406
|
+
id_document: doc['_id'],
|
|
407
|
+
payload: common_1.getBinarySize(JSON.stringify([doc, filter, options])) < 200000 ? JSON.stringify([doc, filter, options], null, 2) : 'Too Big',
|
|
408
|
+
method: 'deleteMany',
|
|
409
|
+
id_user: '',
|
|
410
|
+
user: '',
|
|
411
|
+
messageId: 0,
|
|
412
|
+
route: ''
|
|
413
|
+
});
|
|
414
|
+
if (this.useVersions) {
|
|
415
|
+
versionDoc = common_1.deepCopy(doc);
|
|
416
|
+
versionDoc['_id'] = { _id: doc['_id'], __v: doc['__v'] };
|
|
417
|
+
index_1.ResolveIOServer.getMongoManager().collection(this.versionCollection).replaceOne({ _id: { _id: doc['_id'], __v: doc['__v'] } }, versionDoc, { upsert: true });
|
|
418
|
+
}
|
|
419
|
+
}
|
|
401
420
|
_a.label = 2;
|
|
402
421
|
case 2:
|
|
403
|
-
if (!(i < docs.length)) return [3 /*break*/, 5];
|
|
404
|
-
doc = docs[i];
|
|
405
|
-
log_collection_1.Logs.insertOne({
|
|
406
|
-
_id: objectIdHexString(),
|
|
407
|
-
type: 'document',
|
|
408
|
-
collection: this.collectionName,
|
|
409
|
-
id_document: doc['_id'],
|
|
410
|
-
payload: common_1.getBinarySize(JSON.stringify([doc, filter, options])) < 200000 ? JSON.stringify([doc, filter, options], null, 2) : 'Too Big',
|
|
411
|
-
method: 'deleteMany',
|
|
412
|
-
id_user: '',
|
|
413
|
-
user: '',
|
|
414
|
-
messageId: 0,
|
|
415
|
-
route: ''
|
|
416
|
-
});
|
|
417
|
-
if (!this.useVersions) return [3 /*break*/, 4];
|
|
418
|
-
versionDoc = common_1.deepCopy(doc);
|
|
419
|
-
versionDoc['_id'] = { _id: doc['_id'], __v: doc['__v'] };
|
|
420
|
-
return [4 /*yield*/, index_1.ResolveIOServer.getMongoManager().collection(this.versionCollection).replaceOne({ _id: { _id: doc['_id'], __v: doc['__v'] } }, versionDoc, { upsert: true })];
|
|
421
|
-
case 3:
|
|
422
|
-
_a.sent();
|
|
423
|
-
_a.label = 4;
|
|
424
|
-
case 4:
|
|
425
|
-
i++;
|
|
426
|
-
return [3 /*break*/, 2];
|
|
427
|
-
case 5:
|
|
428
422
|
index_1.ResolveIOServer.getMainDB().collection(this.collectionName).deleteMany(filter, options).then(function (res) {
|
|
429
423
|
if (res.result.ok) {
|
|
430
424
|
resolve(res.deletedCount);
|
|
@@ -443,45 +437,53 @@ var Collection = /** @class */ (function () {
|
|
|
443
437
|
if (filter === void 0) { filter = {}; }
|
|
444
438
|
if (bypassLogs === void 0) { bypassLogs = false; }
|
|
445
439
|
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
446
|
-
var
|
|
440
|
+
var _this = this;
|
|
447
441
|
return __generator(this, function (_a) {
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
return
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
case 3:
|
|
475
|
-
index_1.ResolveIOServer.getMainDB().collection(this.collectionName).deleteOne(filter, options).then(function (res) {
|
|
476
|
-
if (res.result.ok) {
|
|
477
|
-
resolve(res.deletedCount);
|
|
442
|
+
if (this.createLogs && !bypassLogs) {
|
|
443
|
+
index_1.ResolveIOServer.getMainDB().collection(this.collectionName).findOneAndDelete(filter, options).then(function (returnVal) { return __awaiter(_this, void 0, void 0, function () {
|
|
444
|
+
var doc, versionDoc;
|
|
445
|
+
return __generator(this, function (_a) {
|
|
446
|
+
doc = returnVal.value;
|
|
447
|
+
if (doc) {
|
|
448
|
+
if (this.createLogs && !bypassLogs) {
|
|
449
|
+
log_collection_1.Logs.insertOne({
|
|
450
|
+
_id: objectIdHexString(),
|
|
451
|
+
type: 'document',
|
|
452
|
+
collection: this.collectionName,
|
|
453
|
+
id_document: doc['_id'],
|
|
454
|
+
payload: common_1.getBinarySize(JSON.stringify([doc, filter, options])) < 200000 ? JSON.stringify([doc, filter, options], null, 2) : 'Too Big',
|
|
455
|
+
method: 'deleteOne',
|
|
456
|
+
id_user: '',
|
|
457
|
+
user: '',
|
|
458
|
+
messageId: 0,
|
|
459
|
+
route: ''
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
if (this.useVersions) {
|
|
463
|
+
versionDoc = common_1.deepCopy(doc);
|
|
464
|
+
versionDoc['_id'] = { _id: doc['_id'], __v: doc['__v'] };
|
|
465
|
+
index_1.ResolveIOServer.getMongoManager().collection(this.versionCollection).replaceOne({ _id: { _id: doc['_id'], __v: doc['__v'] } }, versionDoc, { upsert: true });
|
|
466
|
+
}
|
|
467
|
+
resolve(1);
|
|
478
468
|
}
|
|
479
469
|
else {
|
|
480
|
-
|
|
470
|
+
resolve(0);
|
|
481
471
|
}
|
|
482
|
-
|
|
483
|
-
|
|
472
|
+
return [2 /*return*/];
|
|
473
|
+
});
|
|
474
|
+
}); }, function (err) { return reject(err); });
|
|
484
475
|
}
|
|
476
|
+
else {
|
|
477
|
+
index_1.ResolveIOServer.getMainDB().collection(this.collectionName).deleteOne(filter, options).then(function (res) {
|
|
478
|
+
if (res.result.ok) {
|
|
479
|
+
resolve(res.deletedCount);
|
|
480
|
+
}
|
|
481
|
+
else {
|
|
482
|
+
reject(res.result.ok);
|
|
483
|
+
}
|
|
484
|
+
}, function (err) { return reject(err); });
|
|
485
|
+
}
|
|
486
|
+
return [2 /*return*/];
|
|
485
487
|
});
|
|
486
488
|
}); });
|
|
487
489
|
};
|
|
@@ -652,20 +654,16 @@ var Collection = /** @class */ (function () {
|
|
|
652
654
|
if (filter === void 0) { filter = {}; }
|
|
653
655
|
if (bypassLogs === void 0) { bypassLogs = false; }
|
|
654
656
|
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
655
|
-
var doc;
|
|
656
657
|
var _this = this;
|
|
657
658
|
return __generator(this, function (_a) {
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
case 1:
|
|
663
|
-
doc = _a.sent();
|
|
664
|
-
if (doc) {
|
|
659
|
+
index_1.ResolveIOServer.getMainDB().collection(this.collectionName).findOneAndDelete(filter, options).then(function (res) {
|
|
660
|
+
var doc = res.value;
|
|
661
|
+
if (doc) {
|
|
662
|
+
if (_this.createLogs && !bypassLogs) {
|
|
665
663
|
log_collection_1.Logs.insertOne({
|
|
666
664
|
_id: objectIdHexString(),
|
|
667
665
|
type: 'document',
|
|
668
|
-
collection:
|
|
666
|
+
collection: _this.collectionName,
|
|
669
667
|
id_document: doc['_id'],
|
|
670
668
|
payload: common_1.getBinarySize(JSON.stringify([doc, filter, options])) < 200000 ? JSON.stringify([doc, filter, options], null, 2) : 'Too Big',
|
|
671
669
|
method: 'findOneAndDelete',
|
|
@@ -675,48 +673,18 @@ var Collection = /** @class */ (function () {
|
|
|
675
673
|
route: ''
|
|
676
674
|
});
|
|
677
675
|
}
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
// type: 'queryResponse',
|
|
691
|
-
// collection: this.collectionName,
|
|
692
|
-
// id_document: '',
|
|
693
|
-
// payload: getBinarySize(JSON.stringify([res.value])) < 200000 ? JSON.stringify([res.value], null, 2) : 'Too Big',
|
|
694
|
-
// method: 'findOneAndDelete',
|
|
695
|
-
// id_user: '',
|
|
696
|
-
// user: '',
|
|
697
|
-
// messageId: 0,
|
|
698
|
-
// route: ''
|
|
699
|
-
// });
|
|
700
|
-
}
|
|
701
|
-
}, function (err) {
|
|
702
|
-
reject(err);
|
|
703
|
-
if (_this.createLogs && !bypassLogs) {
|
|
704
|
-
// Logs.insertOne({
|
|
705
|
-
// _id: objectIdHexString(),
|
|
706
|
-
// type: 'queryResponse',
|
|
707
|
-
// collection: this.collectionName,
|
|
708
|
-
// id_document: '',
|
|
709
|
-
// payload: getBinarySize(JSON.stringify([err])) < 200000 ? JSON.stringify([err], null, 2) : 'Too Big',
|
|
710
|
-
// method: 'findOneAndDelete',
|
|
711
|
-
// id_user: '',
|
|
712
|
-
// user: '',
|
|
713
|
-
// messageId: 0,
|
|
714
|
-
// route: ''
|
|
715
|
-
// });
|
|
716
|
-
}
|
|
717
|
-
});
|
|
718
|
-
return [2 /*return*/];
|
|
719
|
-
}
|
|
676
|
+
if (_this.useVersions) {
|
|
677
|
+
var versionDoc = common_1.deepCopy(doc);
|
|
678
|
+
versionDoc['_id'] = { _id: doc['_id'], __v: doc['__v'] };
|
|
679
|
+
index_1.ResolveIOServer.getMongoManager().collection(_this.versionCollection).replaceOne({ _id: { _id: doc['_id'], __v: doc['__v'] } }, versionDoc, { upsert: true });
|
|
680
|
+
}
|
|
681
|
+
resolve(doc);
|
|
682
|
+
}
|
|
683
|
+
else {
|
|
684
|
+
resolve(null);
|
|
685
|
+
}
|
|
686
|
+
}, function (err) { return reject(err); });
|
|
687
|
+
return [2 /*return*/];
|
|
720
688
|
});
|
|
721
689
|
}); });
|
|
722
690
|
};
|
|
@@ -726,34 +694,42 @@ var Collection = /** @class */ (function () {
|
|
|
726
694
|
if (bypassLogs === void 0) { bypassLogs = false; }
|
|
727
695
|
if (bypassCheckSchema === void 0) { bypassCheckSchema = false; }
|
|
728
696
|
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
729
|
-
var validation, isValid, date
|
|
697
|
+
var validation, isValid, date;
|
|
730
698
|
var _this = this;
|
|
731
699
|
return __generator(this, function (_a) {
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
700
|
+
if (this.checkSchema && !bypassCheckSchema) {
|
|
701
|
+
validation = this.simplschema.newContext();
|
|
702
|
+
isValid = validation.validate(replacement);
|
|
703
|
+
if (!isValid) {
|
|
704
|
+
console.log(new Date(), this.collectionName, 'Schema Errors - findOneAndReplace', validation.validationErrors());
|
|
705
|
+
index_1.ResolveIOServer.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on findOneAndReplace - ' + this.collectionName, [validation.validationErrors(), replacement]);
|
|
706
|
+
reject(validation.validationErrors());
|
|
707
|
+
return [2 /*return*/];
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
date = new Date();
|
|
711
|
+
if (this.timestamps) {
|
|
712
|
+
replacement['updatedAt'] = date;
|
|
713
|
+
}
|
|
714
|
+
if (options && options.upsert) {
|
|
715
|
+
if (!replacement['_id']) {
|
|
716
|
+
replacement['_id'] = objectIdHexString();
|
|
717
|
+
}
|
|
718
|
+
if (this.useVersions) {
|
|
719
|
+
replacement['__v'] = 0;
|
|
720
|
+
}
|
|
721
|
+
if (this.timestamps && !replacement['createdAt']) {
|
|
722
|
+
replacement['createdAt'] = date;
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
index_1.ResolveIOServer.getMainDB().collection(this.collectionName).findOneAndReplace(filter, replacement, options).then(function (res) {
|
|
726
|
+
var doc = res.value;
|
|
727
|
+
if (doc) {
|
|
728
|
+
if (_this.createLogs && !bypassLogs) {
|
|
753
729
|
log_collection_1.Logs.insertOne({
|
|
754
730
|
_id: objectIdHexString(),
|
|
755
731
|
type: 'document',
|
|
756
|
-
collection:
|
|
732
|
+
collection: _this.collectionName,
|
|
757
733
|
id_document: doc['_id'],
|
|
758
734
|
payload: common_1.getBinarySize(JSON.stringify([doc, filter, replacement, options])) < 200000 ? JSON.stringify([doc, filter, replacement, options], null, 2) : 'Too Big',
|
|
759
735
|
method: 'findOneAndReplace',
|
|
@@ -763,48 +739,18 @@ var Collection = /** @class */ (function () {
|
|
|
763
739
|
route: ''
|
|
764
740
|
});
|
|
765
741
|
}
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
// type: 'queryResponse',
|
|
779
|
-
// collection: this.collectionName,
|
|
780
|
-
// id_document: '',
|
|
781
|
-
// payload: getBinarySize(JSON.stringify([res.value])) < 200000 ? JSON.stringify([res.value], null, 2) : 'Too Big',
|
|
782
|
-
// method: 'findOneAndReplace',
|
|
783
|
-
// id_user: '',
|
|
784
|
-
// user: '',
|
|
785
|
-
// messageId: 0,
|
|
786
|
-
// route: ''
|
|
787
|
-
// });
|
|
788
|
-
}
|
|
789
|
-
}, function (err) {
|
|
790
|
-
reject(err);
|
|
791
|
-
if (_this.createLogs && !bypassLogs) {
|
|
792
|
-
// Logs.insertOne({
|
|
793
|
-
// _id: objectIdHexString(),
|
|
794
|
-
// type: 'queryResponse',
|
|
795
|
-
// collection: this.collectionName,
|
|
796
|
-
// id_document: '',
|
|
797
|
-
// payload: getBinarySize(JSON.stringify([err])) < 200000 ? JSON.stringify([err], null, 2) : 'Too Big',
|
|
798
|
-
// method: 'findOneAndReplace',
|
|
799
|
-
// id_user: '',
|
|
800
|
-
// user: '',
|
|
801
|
-
// messageId: 0,
|
|
802
|
-
// route: ''
|
|
803
|
-
// });
|
|
804
|
-
}
|
|
805
|
-
});
|
|
806
|
-
return [2 /*return*/];
|
|
807
|
-
}
|
|
742
|
+
if (_this.useVersions) {
|
|
743
|
+
var versionDoc = common_1.deepCopy(doc);
|
|
744
|
+
versionDoc['_id'] = { _id: doc['_id'], __v: doc['__v'] };
|
|
745
|
+
index_1.ResolveIOServer.getMongoManager().collection(_this.versionCollection).replaceOne({ _id: { _id: doc['_id'], __v: doc['__v'] } }, versionDoc, { upsert: true });
|
|
746
|
+
}
|
|
747
|
+
resolve(doc);
|
|
748
|
+
}
|
|
749
|
+
else {
|
|
750
|
+
resolve(null);
|
|
751
|
+
}
|
|
752
|
+
}, function (err) { return reject(err); });
|
|
753
|
+
return [2 /*return*/];
|
|
808
754
|
});
|
|
809
755
|
}); });
|
|
810
756
|
};
|
|
@@ -814,90 +760,82 @@ var Collection = /** @class */ (function () {
|
|
|
814
760
|
if (bypassLogs === void 0) { bypassLogs = false; }
|
|
815
761
|
if (bypassCheckSchema === void 0) { bypassCheckSchema = false; }
|
|
816
762
|
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
817
|
-
var validation, isValid, date
|
|
763
|
+
var validation, isValid, date;
|
|
818
764
|
var _this = this;
|
|
819
765
|
return __generator(this, function (_a) {
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
766
|
+
if (this.checkSchema && !bypassCheckSchema) {
|
|
767
|
+
validation = this.simplschema.newContext();
|
|
768
|
+
isValid = validation.validate(update, { modifier: true });
|
|
769
|
+
if (!isValid) {
|
|
770
|
+
console.log(new Date(), this.collectionName, 'Schema Errors - findOneAndUpdate', validation.validationErrors());
|
|
771
|
+
index_1.ResolveIOServer.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on findOneAndUpdate - ' + this.collectionName, [validation.validationErrors(), update]);
|
|
772
|
+
reject(validation.validationErrors());
|
|
773
|
+
return [2 /*return*/];
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
if (this.timestamps) {
|
|
777
|
+
date = new Date();
|
|
778
|
+
if (!update['$set']) {
|
|
779
|
+
update['$set'] = { updatedAt: date };
|
|
780
|
+
}
|
|
781
|
+
else {
|
|
782
|
+
update['$set']['updatedAt'] = date;
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
if (options && options.upsert) {
|
|
786
|
+
if (!update.$setOnInsert) {
|
|
832
787
|
if (this.timestamps) {
|
|
833
|
-
|
|
834
|
-
if (!update['$set']) {
|
|
835
|
-
update['$set'] = { updatedAt: date };
|
|
836
|
-
}
|
|
837
|
-
else {
|
|
838
|
-
update['$set']['updatedAt'] = date;
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
if (!(this.createLogs && !bypassLogs)) return [3 /*break*/, 2];
|
|
842
|
-
return [4 /*yield*/, this.findOne(filter, null, true)];
|
|
843
|
-
case 1:
|
|
844
|
-
doc = _a.sent();
|
|
845
|
-
if (doc) {
|
|
846
|
-
log_collection_1.Logs.insertOne({
|
|
788
|
+
update.$setOnInsert = {
|
|
847
789
|
_id: objectIdHexString(),
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
id_document: doc['_id'],
|
|
851
|
-
payload: common_1.getBinarySize(JSON.stringify([doc, filter, update, options])) < 200000 ? JSON.stringify([doc, filter, update, options], null, 2) : 'Too Big',
|
|
852
|
-
method: 'findOneAndUpdate',
|
|
853
|
-
id_user: '',
|
|
854
|
-
user: '',
|
|
855
|
-
messageId: 0,
|
|
856
|
-
route: ''
|
|
857
|
-
});
|
|
790
|
+
createdAt: new Date()
|
|
791
|
+
};
|
|
858
792
|
}
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
// id_document: '',
|
|
874
|
-
// payload: getBinarySize(JSON.stringify([res.value])) < 200000 ? JSON.stringify([res.value], null, 2) : 'Too Big',
|
|
875
|
-
// method: 'findOneAndUpdate',
|
|
876
|
-
// id_user: '',
|
|
877
|
-
// user: '',
|
|
878
|
-
// messageId: 0,
|
|
879
|
-
// route: ''
|
|
880
|
-
// });
|
|
881
|
-
}
|
|
882
|
-
}, function (err) {
|
|
883
|
-
reject(err);
|
|
884
|
-
if (_this.createLogs && !bypassLogs) {
|
|
885
|
-
// Logs.insertOne({
|
|
886
|
-
// _id: objectIdHexString(),
|
|
887
|
-
// type: 'queryResponse',
|
|
888
|
-
// collection: this.collectionName,
|
|
889
|
-
// id_document: '',
|
|
890
|
-
// payload: getBinarySize(JSON.stringify([err])) < 200000 ? JSON.stringify([err], null, 2) : 'Too Big',
|
|
891
|
-
// method: 'findOneAndUpdate',
|
|
892
|
-
// id_user: '',
|
|
893
|
-
// user: '',
|
|
894
|
-
// messageId: 0,
|
|
895
|
-
// route: ''
|
|
896
|
-
// });
|
|
897
|
-
}
|
|
898
|
-
});
|
|
899
|
-
return [2 /*return*/];
|
|
793
|
+
else {
|
|
794
|
+
update.$setOnInsert = {
|
|
795
|
+
_id: objectIdHexString()
|
|
796
|
+
};
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
else {
|
|
800
|
+
if (!update.$setOnInsert._id) {
|
|
801
|
+
update.$setOnInsert._id = objectIdHexString();
|
|
802
|
+
}
|
|
803
|
+
if (this.timestamps) {
|
|
804
|
+
update.$setOnInsert.createdAt = new Date();
|
|
805
|
+
}
|
|
806
|
+
}
|
|
900
807
|
}
|
|
808
|
+
index_1.ResolveIOServer.getMainDB().collection(this.collectionName).findOneAndUpdate(filter, update, options).then(function (res) {
|
|
809
|
+
var doc = res.value;
|
|
810
|
+
if (doc) {
|
|
811
|
+
if (_this.createLogs && !bypassLogs) {
|
|
812
|
+
log_collection_1.Logs.insertOne({
|
|
813
|
+
_id: objectIdHexString(),
|
|
814
|
+
type: 'document',
|
|
815
|
+
collection: _this.collectionName,
|
|
816
|
+
id_document: doc['_id'],
|
|
817
|
+
payload: common_1.getBinarySize(JSON.stringify([doc, filter, update, options])) < 200000 ? JSON.stringify([doc, filter, update, options], null, 2) : 'Too Big',
|
|
818
|
+
method: 'findOneAndUpdate',
|
|
819
|
+
id_user: '',
|
|
820
|
+
user: '',
|
|
821
|
+
messageId: 0,
|
|
822
|
+
route: ''
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
if (_this.useVersions) {
|
|
826
|
+
var versionDoc = common_1.deepCopy(doc);
|
|
827
|
+
versionDoc['_id'] = { _id: doc['_id'], __v: doc['__v'] };
|
|
828
|
+
index_1.ResolveIOServer.getMongoManager().collection(_this.versionCollection).replaceOne({ _id: { _id: doc['_id'], __v: doc['__v'] } }, versionDoc, { upsert: true });
|
|
829
|
+
}
|
|
830
|
+
resolve(doc);
|
|
831
|
+
}
|
|
832
|
+
else {
|
|
833
|
+
resolve(null);
|
|
834
|
+
}
|
|
835
|
+
}, function (err) {
|
|
836
|
+
reject(err);
|
|
837
|
+
});
|
|
838
|
+
return [2 /*return*/];
|
|
901
839
|
});
|
|
902
840
|
}); });
|
|
903
841
|
};
|
|
@@ -1048,6 +986,7 @@ var Collection = /** @class */ (function () {
|
|
|
1048
986
|
if (doc === void 0) { doc = null; }
|
|
1049
987
|
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
1050
988
|
var validation, isValid, date, versionDoc, prevDoc, docId, docVersion, updatedDoc;
|
|
989
|
+
var _this = this;
|
|
1051
990
|
return __generator(this, function (_a) {
|
|
1052
991
|
switch (_a.label) {
|
|
1053
992
|
case 0:
|
|
@@ -1065,16 +1004,30 @@ var Collection = /** @class */ (function () {
|
|
|
1065
1004
|
if (this.timestamps) {
|
|
1066
1005
|
replacement['updatedAt'] = date;
|
|
1067
1006
|
}
|
|
1007
|
+
if (!this.useVersions) return [3 /*break*/, 8];
|
|
1068
1008
|
if (!!doc) return [3 /*break*/, 2];
|
|
1069
1009
|
return [4 /*yield*/, this.findOne(filter, null, true)];
|
|
1070
1010
|
case 1:
|
|
1071
1011
|
doc = _a.sent();
|
|
1072
1012
|
_a.label = 2;
|
|
1073
1013
|
case 2:
|
|
1074
|
-
if (!doc) return [3 /*break*/,
|
|
1014
|
+
if (!doc) return [3 /*break*/, 6];
|
|
1075
1015
|
if (this.timestamps && !replacement['createdAt'] && doc['createdAt']) {
|
|
1076
1016
|
replacement['createdAt'] = doc['createdAt'];
|
|
1077
1017
|
}
|
|
1018
|
+
if (!(doc['__v'] === replacement['__v'])) return [3 /*break*/, 3];
|
|
1019
|
+
replacement['__v'] += 1;
|
|
1020
|
+
versionDoc = common_1.deepCopy(doc);
|
|
1021
|
+
versionDoc['_id'] = { _id: doc['_id'], __v: doc['__v'] };
|
|
1022
|
+
index_1.ResolveIOServer.getMongoManager().collection(this.versionCollection).replaceOne({ _id: { _id: doc['_id'], __v: doc['__v'] } }, versionDoc, { upsert: true });
|
|
1023
|
+
if (doc['__v'] >= 4) {
|
|
1024
|
+
index_1.ResolveIOServer.getMongoManager().collection(this.versionCollection).deleteMany({
|
|
1025
|
+
_id: {
|
|
1026
|
+
_id: doc['_id'],
|
|
1027
|
+
__v: { $lte: doc['__v'] - 4 }
|
|
1028
|
+
}
|
|
1029
|
+
});
|
|
1030
|
+
}
|
|
1078
1031
|
if (this.createLogs && !bypassLogs) {
|
|
1079
1032
|
log_collection_1.Logs.insertOne({
|
|
1080
1033
|
_id: objectIdHexString(),
|
|
@@ -1089,25 +1042,6 @@ var Collection = /** @class */ (function () {
|
|
|
1089
1042
|
route: ''
|
|
1090
1043
|
});
|
|
1091
1044
|
}
|
|
1092
|
-
if (!this.useVersions) return [3 /*break*/, 9];
|
|
1093
|
-
if (!(doc['__v'] === replacement['__v'])) return [3 /*break*/, 6];
|
|
1094
|
-
replacement['__v'] += 1;
|
|
1095
|
-
versionDoc = common_1.deepCopy(doc);
|
|
1096
|
-
versionDoc['_id'] = { _id: doc['_id'], __v: doc['__v'] };
|
|
1097
|
-
return [4 /*yield*/, index_1.ResolveIOServer.getMongoManager().collection(this.versionCollection).replaceOne({ _id: { _id: doc['_id'], __v: doc['__v'] } }, versionDoc, { upsert: true })];
|
|
1098
|
-
case 3:
|
|
1099
|
-
_a.sent();
|
|
1100
|
-
if (!(doc['__v'] >= 4)) return [3 /*break*/, 5];
|
|
1101
|
-
return [4 /*yield*/, index_1.ResolveIOServer.getMongoManager().collection(this.versionCollection).deleteMany({
|
|
1102
|
-
_id: {
|
|
1103
|
-
_id: doc['_id'],
|
|
1104
|
-
__v: { $lte: doc['__v'] - 4 }
|
|
1105
|
-
}
|
|
1106
|
-
})];
|
|
1107
|
-
case 4:
|
|
1108
|
-
_a.sent();
|
|
1109
|
-
_a.label = 5;
|
|
1110
|
-
case 5:
|
|
1111
1045
|
index_1.ResolveIOServer.getMainDB().collection(this.collectionName).replaceOne(filter, replacement, options).then(function (res) {
|
|
1112
1046
|
if (res.result.ok) {
|
|
1113
1047
|
resolve(res.result.nModified);
|
|
@@ -1118,8 +1052,8 @@ var Collection = /** @class */ (function () {
|
|
|
1118
1052
|
}, function (err) {
|
|
1119
1053
|
reject(err);
|
|
1120
1054
|
});
|
|
1121
|
-
return [3 /*break*/,
|
|
1122
|
-
case
|
|
1055
|
+
return [3 /*break*/, 5];
|
|
1056
|
+
case 3:
|
|
1123
1057
|
console.log('invalid version - ' + this.collectionName, doc['__v'], replacement['__v']);
|
|
1124
1058
|
return [4 /*yield*/, index_1.ResolveIOServer.getMongoManager().collection(this.versionCollection).findOne({
|
|
1125
1059
|
_id: {
|
|
@@ -1127,7 +1061,7 @@ var Collection = /** @class */ (function () {
|
|
|
1127
1061
|
__v: replacement['__v']
|
|
1128
1062
|
}
|
|
1129
1063
|
}, null, true)];
|
|
1130
|
-
case
|
|
1064
|
+
case 4:
|
|
1131
1065
|
prevDoc = _a.sent();
|
|
1132
1066
|
if (prevDoc) {
|
|
1133
1067
|
docId = doc['_id'];
|
|
@@ -1135,6 +1069,20 @@ var Collection = /** @class */ (function () {
|
|
|
1135
1069
|
updatedDoc = common_1.getMongoMergeUpdatedDoc(replacement, doc, prevDoc);
|
|
1136
1070
|
updatedDoc['_id'] = docId;
|
|
1137
1071
|
updatedDoc['__v'] = docVersion + 1;
|
|
1072
|
+
if (this.createLogs && !bypassLogs) {
|
|
1073
|
+
log_collection_1.Logs.insertOne({
|
|
1074
|
+
_id: objectIdHexString(),
|
|
1075
|
+
type: 'document',
|
|
1076
|
+
collection: this.collectionName,
|
|
1077
|
+
id_document: doc['_id'],
|
|
1078
|
+
payload: common_1.getBinarySize(JSON.stringify(['invalidVersion - merge', doc, filter, updatedDoc, options])) < 200000 ? JSON.stringify(['invalidVersion - merge', doc, filter, updatedDoc, options], null, 2) : 'Too Big',
|
|
1079
|
+
method: 'replaceOne',
|
|
1080
|
+
id_user: '',
|
|
1081
|
+
user: '',
|
|
1082
|
+
messageId: 0,
|
|
1083
|
+
route: ''
|
|
1084
|
+
});
|
|
1085
|
+
}
|
|
1138
1086
|
index_1.ResolveIOServer.getMainDB().collection(this.collectionName).replaceOne(filter, updatedDoc, options).then(function (res) {
|
|
1139
1087
|
if (res.result.ok) {
|
|
1140
1088
|
resolve(res.result.nModified);
|
|
@@ -1149,33 +1097,24 @@ var Collection = /** @class */ (function () {
|
|
|
1149
1097
|
else {
|
|
1150
1098
|
reject('Invalid Version And Could Not Find History - DB: ' + doc['__v'] + ', Trying to update with :' + replacement['__v']);
|
|
1151
1099
|
}
|
|
1152
|
-
_a.label =
|
|
1153
|
-
case
|
|
1154
|
-
case
|
|
1155
|
-
index_1.ResolveIOServer.getMainDB().collection(this.collectionName).replaceOne(filter, replacement, options).then(function (res) {
|
|
1156
|
-
if (res.result.ok) {
|
|
1157
|
-
resolve(res.result.nModified);
|
|
1158
|
-
}
|
|
1159
|
-
else {
|
|
1160
|
-
reject(res.result.ok);
|
|
1161
|
-
}
|
|
1162
|
-
}, function (err) {
|
|
1163
|
-
reject(err);
|
|
1164
|
-
});
|
|
1165
|
-
_a.label = 10;
|
|
1166
|
-
case 10: return [3 /*break*/, 12];
|
|
1167
|
-
case 11:
|
|
1100
|
+
_a.label = 5;
|
|
1101
|
+
case 5: return [3 /*break*/, 7];
|
|
1102
|
+
case 6:
|
|
1168
1103
|
if (options && options.upsert) {
|
|
1169
1104
|
if (this.timestamps) {
|
|
1170
1105
|
replacement['createdAt'] = date;
|
|
1171
1106
|
}
|
|
1107
|
+
if (!replacement['_id']) {
|
|
1108
|
+
replacement['_id'] = objectIdHexString();
|
|
1109
|
+
}
|
|
1110
|
+
replacement['__v'] = 0;
|
|
1172
1111
|
if (this.createLogs && !bypassLogs) {
|
|
1173
1112
|
log_collection_1.Logs.insertOne({
|
|
1174
1113
|
_id: objectIdHexString(),
|
|
1175
1114
|
type: 'document',
|
|
1176
1115
|
collection: this.collectionName,
|
|
1177
1116
|
id_document: replacement['_id'],
|
|
1178
|
-
payload: common_1.getBinarySize(JSON.stringify([filter, replacement, options])) < 200000 ? JSON.stringify([filter, replacement, options], null, 2) : 'Too Big',
|
|
1117
|
+
payload: common_1.getBinarySize(JSON.stringify(['upsert', filter, replacement, options])) < 200000 ? JSON.stringify(['upsert', filter, replacement, options], null, 2) : 'Too Big',
|
|
1179
1118
|
method: 'replaceOne',
|
|
1180
1119
|
id_user: '',
|
|
1181
1120
|
user: '',
|
|
@@ -1183,9 +1122,6 @@ var Collection = /** @class */ (function () {
|
|
|
1183
1122
|
route: ''
|
|
1184
1123
|
});
|
|
1185
1124
|
}
|
|
1186
|
-
if (this.useVersions) {
|
|
1187
|
-
replacement['__v'] = 0;
|
|
1188
|
-
}
|
|
1189
1125
|
index_1.ResolveIOServer.getMainDB().collection(this.collectionName).replaceOne(filter, replacement, options).then(function (res) {
|
|
1190
1126
|
if (res.result.ok) {
|
|
1191
1127
|
resolve(res.result.nModified);
|
|
@@ -1200,8 +1136,72 @@ var Collection = /** @class */ (function () {
|
|
|
1200
1136
|
else {
|
|
1201
1137
|
reject('No Document');
|
|
1202
1138
|
}
|
|
1203
|
-
_a.label =
|
|
1204
|
-
case
|
|
1139
|
+
_a.label = 7;
|
|
1140
|
+
case 7: return [3 /*break*/, 9];
|
|
1141
|
+
case 8:
|
|
1142
|
+
if (options && options.upsert) {
|
|
1143
|
+
if (this.timestamps && !replacement['createdAt']) {
|
|
1144
|
+
replacement['createdAt'] = date;
|
|
1145
|
+
}
|
|
1146
|
+
if (!replacement['_id']) {
|
|
1147
|
+
replacement['_id'] = objectIdHexString();
|
|
1148
|
+
}
|
|
1149
|
+
replacement['__v'] = 0;
|
|
1150
|
+
}
|
|
1151
|
+
if (this.createLogs && !bypassLogs) {
|
|
1152
|
+
if (!options) {
|
|
1153
|
+
options = { returnOriginal: true };
|
|
1154
|
+
}
|
|
1155
|
+
else {
|
|
1156
|
+
options.returnOriginal = true;
|
|
1157
|
+
}
|
|
1158
|
+
index_1.ResolveIOServer.getMainDB().collection(this.collectionName).findOneAndReplace(filter, replacement, options).then(function (res) {
|
|
1159
|
+
var doc = res.value;
|
|
1160
|
+
if (doc) {
|
|
1161
|
+
log_collection_1.Logs.insertOne({
|
|
1162
|
+
_id: objectIdHexString(),
|
|
1163
|
+
type: 'document',
|
|
1164
|
+
collection: _this.collectionName,
|
|
1165
|
+
id_document: doc._id,
|
|
1166
|
+
payload: common_1.getBinarySize(JSON.stringify([doc, filter, replacement, options])) < 200000 ? JSON.stringify([doc, filter, replacement, options], null, 2) : 'Too Big',
|
|
1167
|
+
method: 'replaceOne',
|
|
1168
|
+
id_user: '',
|
|
1169
|
+
user: '',
|
|
1170
|
+
messageId: 0,
|
|
1171
|
+
route: ''
|
|
1172
|
+
});
|
|
1173
|
+
}
|
|
1174
|
+
else {
|
|
1175
|
+
log_collection_1.Logs.insertOne({
|
|
1176
|
+
_id: objectIdHexString(),
|
|
1177
|
+
type: 'document',
|
|
1178
|
+
collection: _this.collectionName,
|
|
1179
|
+
id_document: replacement['_id'],
|
|
1180
|
+
payload: common_1.getBinarySize(JSON.stringify(['upsert', filter, replacement, options])) < 200000 ? JSON.stringify(['upsert', filter, replacement, options], null, 2) : 'Too Big',
|
|
1181
|
+
method: 'replaceOne',
|
|
1182
|
+
id_user: '',
|
|
1183
|
+
user: '',
|
|
1184
|
+
messageId: 0,
|
|
1185
|
+
route: ''
|
|
1186
|
+
});
|
|
1187
|
+
}
|
|
1188
|
+
resolve(res.ok);
|
|
1189
|
+
}, function (err) { return reject(err); });
|
|
1190
|
+
}
|
|
1191
|
+
else {
|
|
1192
|
+
index_1.ResolveIOServer.getMainDB().collection(this.collectionName).replaceOne(filter, replacement, options).then(function (res) {
|
|
1193
|
+
if (res.result.ok) {
|
|
1194
|
+
resolve(res.result.nModified);
|
|
1195
|
+
}
|
|
1196
|
+
else {
|
|
1197
|
+
reject(res.result.ok);
|
|
1198
|
+
}
|
|
1199
|
+
}, function (err) {
|
|
1200
|
+
reject(err);
|
|
1201
|
+
});
|
|
1202
|
+
}
|
|
1203
|
+
_a.label = 9;
|
|
1204
|
+
case 9: return [2 /*return*/];
|
|
1205
1205
|
}
|
|
1206
1206
|
});
|
|
1207
1207
|
}); });
|
|
@@ -1214,7 +1214,7 @@ var Collection = /** @class */ (function () {
|
|
|
1214
1214
|
if (bypassLogs === void 0) { bypassLogs = false; }
|
|
1215
1215
|
if (bypassCheckSchema === void 0) { bypassCheckSchema = false; }
|
|
1216
1216
|
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
1217
|
-
var date, validation, isValid, docs, i, doc;
|
|
1217
|
+
var date, validation, isValid, docs, i, doc, versionDoc;
|
|
1218
1218
|
return __generator(this, function (_a) {
|
|
1219
1219
|
switch (_a.label) {
|
|
1220
1220
|
case 0:
|
|
@@ -1237,24 +1237,47 @@ var Collection = /** @class */ (function () {
|
|
|
1237
1237
|
return [2 /*return*/];
|
|
1238
1238
|
}
|
|
1239
1239
|
}
|
|
1240
|
-
if (!(this.createLogs && !bypassLogs)) return [3 /*break*/, 2];
|
|
1240
|
+
if (!(this.useVersions || (this.createLogs && !bypassLogs))) return [3 /*break*/, 2];
|
|
1241
1241
|
return [4 /*yield*/, this.find(filter)];
|
|
1242
1242
|
case 1:
|
|
1243
1243
|
docs = _a.sent();
|
|
1244
1244
|
for (i = 0; i < docs.length; i++) {
|
|
1245
1245
|
doc = docs[i];
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1246
|
+
if (this.createLogs && !bypassLogs) {
|
|
1247
|
+
log_collection_1.Logs.insertOne({
|
|
1248
|
+
_id: objectIdHexString(),
|
|
1249
|
+
type: 'document',
|
|
1250
|
+
collection: this.collectionName,
|
|
1251
|
+
id_document: doc['_id'],
|
|
1252
|
+
payload: common_1.getBinarySize(JSON.stringify([doc, filter, update, options])) < 200000 ? JSON.stringify([doc, filter, update, options], null, 2) : 'Too Big',
|
|
1253
|
+
method: 'updateMany',
|
|
1254
|
+
id_user: '',
|
|
1255
|
+
user: '',
|
|
1256
|
+
messageId: 0,
|
|
1257
|
+
route: ''
|
|
1258
|
+
});
|
|
1259
|
+
}
|
|
1260
|
+
if (this.useVersions) {
|
|
1261
|
+
versionDoc = common_1.deepCopy(doc);
|
|
1262
|
+
versionDoc['_id'] = { _id: doc['_id'], __v: doc['__v'] };
|
|
1263
|
+
index_1.ResolveIOServer.getMongoManager().collection(this.versionCollection).replaceOne({ _id: { _id: doc['_id'], __v: doc['__v'] } }, versionDoc, { upsert: true });
|
|
1264
|
+
if (doc['__v'] >= 4) {
|
|
1265
|
+
index_1.ResolveIOServer.getMongoManager().collection(this.versionCollection).deleteMany({
|
|
1266
|
+
_id: {
|
|
1267
|
+
_id: doc['_id'],
|
|
1268
|
+
__v: { $lte: doc['__v'] - 4 }
|
|
1269
|
+
}
|
|
1270
|
+
});
|
|
1271
|
+
}
|
|
1272
|
+
if (!objectContainsPropertyDeep(update, '__v')) {
|
|
1273
|
+
if (!update.$inc) {
|
|
1274
|
+
update.$inc = { __v: 1 };
|
|
1275
|
+
}
|
|
1276
|
+
else if (!update.$inc.__v) {
|
|
1277
|
+
update.$inc.__v = 1;
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1258
1281
|
}
|
|
1259
1282
|
_a.label = 2;
|
|
1260
1283
|
case 2:
|
|
@@ -1276,19 +1299,11 @@ var Collection = /** @class */ (function () {
|
|
|
1276
1299
|
if (bypassLogs === void 0) { bypassLogs = false; }
|
|
1277
1300
|
if (bypassCheckSchema === void 0) { bypassCheckSchema = false; }
|
|
1278
1301
|
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
1279
|
-
var
|
|
1302
|
+
var validation, isValid, date, doc, versionDoc;
|
|
1303
|
+
var _this = this;
|
|
1280
1304
|
return __generator(this, function (_a) {
|
|
1281
1305
|
switch (_a.label) {
|
|
1282
1306
|
case 0:
|
|
1283
|
-
date = new Date();
|
|
1284
|
-
if (this.timestamps) {
|
|
1285
|
-
if (!update.$set) {
|
|
1286
|
-
update.$set = { updatedAt: date };
|
|
1287
|
-
}
|
|
1288
|
-
else {
|
|
1289
|
-
update.$set['updatedAt'] = date;
|
|
1290
|
-
}
|
|
1291
|
-
}
|
|
1292
1307
|
if (this.checkSchema && !bypassCheckSchema) {
|
|
1293
1308
|
validation = this.simplschema.newContext();
|
|
1294
1309
|
isValid = validation.validate(update, { modifier: true });
|
|
@@ -1299,74 +1314,84 @@ var Collection = /** @class */ (function () {
|
|
|
1299
1314
|
return [2 /*return*/];
|
|
1300
1315
|
}
|
|
1301
1316
|
}
|
|
1317
|
+
date = new Date();
|
|
1318
|
+
if (this.timestamps) {
|
|
1319
|
+
if (!update.$set) {
|
|
1320
|
+
update.$set = { updatedAt: date };
|
|
1321
|
+
}
|
|
1322
|
+
else {
|
|
1323
|
+
update.$set['updatedAt'] = date;
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
if (!this.useVersions) return [3 /*break*/, 2];
|
|
1302
1327
|
return [4 /*yield*/, this.findOne(filter, null, true)];
|
|
1303
1328
|
case 1:
|
|
1304
1329
|
doc = _a.sent();
|
|
1305
|
-
if (
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
}
|
|
1320
|
-
if (!this.useVersions) return [3 /*break*/, 5];
|
|
1321
|
-
versionDoc = common_1.deepCopy(doc);
|
|
1322
|
-
versionDoc['_id'] = { _id: doc['_id'], __v: doc['__v'] };
|
|
1323
|
-
return [4 /*yield*/, index_1.ResolveIOServer.getMongoManager().collection(this.versionCollection).replaceOne({ _id: { _id: doc['_id'], __v: doc['__v'] } }, versionDoc, { upsert: true })];
|
|
1324
|
-
case 2:
|
|
1325
|
-
_a.sent();
|
|
1326
|
-
if (!(doc['__v'] >= 4)) return [3 /*break*/, 4];
|
|
1327
|
-
return [4 /*yield*/, index_1.ResolveIOServer.getMongoManager().collection(this.versionCollection).deleteMany({
|
|
1328
|
-
_id: {
|
|
1329
|
-
_id: doc['_id'],
|
|
1330
|
-
__v: { $lte: doc['__v'] - 4 }
|
|
1331
|
-
}
|
|
1332
|
-
})];
|
|
1333
|
-
case 3:
|
|
1334
|
-
_a.sent();
|
|
1335
|
-
_a.label = 4;
|
|
1336
|
-
case 4:
|
|
1337
|
-
if (!objectContainsPropertyDeep(update, '__v')) {
|
|
1338
|
-
if (!update.$inc) {
|
|
1339
|
-
update.$inc = { __v: 1 };
|
|
1340
|
-
}
|
|
1341
|
-
else if (!update.$inc.__v) {
|
|
1342
|
-
update.$inc.__v = 1;
|
|
1330
|
+
if (doc) {
|
|
1331
|
+
if (this.createLogs && !bypassLogs) {
|
|
1332
|
+
log_collection_1.Logs.insertOne({
|
|
1333
|
+
_id: objectIdHexString(),
|
|
1334
|
+
type: 'document',
|
|
1335
|
+
collection: this.collectionName,
|
|
1336
|
+
id_document: doc['_id'],
|
|
1337
|
+
payload: common_1.getBinarySize(JSON.stringify([doc, filter, update, options])) < 200000 ? JSON.stringify([doc, filter, update, options], null, 2) : 'Too Big',
|
|
1338
|
+
method: 'updateOne',
|
|
1339
|
+
id_user: '',
|
|
1340
|
+
user: '',
|
|
1341
|
+
messageId: 0,
|
|
1342
|
+
route: ''
|
|
1343
|
+
});
|
|
1343
1344
|
}
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1345
|
+
versionDoc = common_1.deepCopy(doc);
|
|
1346
|
+
versionDoc['_id'] = { _id: doc['_id'], __v: doc['__v'] };
|
|
1347
|
+
index_1.ResolveIOServer.getMongoManager().collection(this.versionCollection).replaceOne({ _id: { _id: doc['_id'], __v: doc['__v'] } }, versionDoc, { upsert: true });
|
|
1348
|
+
if (doc['__v'] >= 4) {
|
|
1349
|
+
index_1.ResolveIOServer.getMongoManager().collection(this.versionCollection).deleteMany({
|
|
1350
|
+
_id: {
|
|
1351
|
+
_id: doc['_id'],
|
|
1352
|
+
__v: { $lte: doc['__v'] - 4 }
|
|
1353
|
+
}
|
|
1354
|
+
});
|
|
1348
1355
|
}
|
|
1349
|
-
|
|
1350
|
-
|
|
1356
|
+
if (!objectContainsPropertyDeep(update, '__v')) {
|
|
1357
|
+
if (!update.$inc) {
|
|
1358
|
+
update.$inc = { __v: 1 };
|
|
1359
|
+
}
|
|
1360
|
+
else if (!update.$inc.__v) {
|
|
1361
|
+
update.$inc.__v = 1;
|
|
1362
|
+
}
|
|
1351
1363
|
}
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1364
|
+
index_1.ResolveIOServer.getMainDB().collection(this.collectionName).updateOne(filter, update, options).then(function (res) {
|
|
1365
|
+
if (res.result.ok) {
|
|
1366
|
+
resolve(res.result.nModified);
|
|
1367
|
+
}
|
|
1368
|
+
else {
|
|
1369
|
+
reject(res.result.ok);
|
|
1370
|
+
}
|
|
1371
|
+
}, function (err) { return reject(err); });
|
|
1372
|
+
}
|
|
1373
|
+
else if (options && options.upsert) {
|
|
1374
|
+
if (!update.$setOnInsert) {
|
|
1375
|
+
if (this.timestamps) {
|
|
1376
|
+
update.$setOnInsert = {
|
|
1377
|
+
_id: objectIdHexString(),
|
|
1378
|
+
__v: 0,
|
|
1379
|
+
createdAt: new Date()
|
|
1380
|
+
};
|
|
1381
|
+
}
|
|
1382
|
+
else {
|
|
1383
|
+
update.$setOnInsert = {
|
|
1384
|
+
_id: objectIdHexString(),
|
|
1385
|
+
__v: 0
|
|
1386
|
+
};
|
|
1387
|
+
}
|
|
1358
1388
|
}
|
|
1359
1389
|
else {
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
case 7:
|
|
1366
|
-
if (options && options.upsert && update.$setOnInsert && update.$setOnInsert._id) {
|
|
1367
|
-
if (this.timestamps) {
|
|
1368
|
-
if (!update.$setOnInsert.createdAt) {
|
|
1369
|
-
update.$setOnInsert.createdAt = date;
|
|
1390
|
+
if (!update.$setOnInsert._id) {
|
|
1391
|
+
update.$setOnInsert._id = objectIdHexString();
|
|
1392
|
+
}
|
|
1393
|
+
if (this.timestamps) {
|
|
1394
|
+
update.$setOnInsert.createdAt = new Date();
|
|
1370
1395
|
}
|
|
1371
1396
|
}
|
|
1372
1397
|
if (this.createLogs && !bypassLogs) {
|
|
@@ -1375,7 +1400,7 @@ var Collection = /** @class */ (function () {
|
|
|
1375
1400
|
type: 'document',
|
|
1376
1401
|
collection: this.collectionName,
|
|
1377
1402
|
id_document: update.$setOnInsert._id,
|
|
1378
|
-
payload: common_1.getBinarySize(JSON.stringify([filter, update, options])) < 200000 ? JSON.stringify([filter, update, options], null, 2) : 'Too Big',
|
|
1403
|
+
payload: common_1.getBinarySize(JSON.stringify(['upsert', filter, update, options])) < 200000 ? JSON.stringify(['upsert', filter, update, options], null, 2) : 'Too Big',
|
|
1379
1404
|
method: 'updateOne',
|
|
1380
1405
|
id_user: '',
|
|
1381
1406
|
user: '',
|
|
@@ -1383,11 +1408,6 @@ var Collection = /** @class */ (function () {
|
|
|
1383
1408
|
route: ''
|
|
1384
1409
|
});
|
|
1385
1410
|
}
|
|
1386
|
-
if (this.useVersions) {
|
|
1387
|
-
if (!objectContainsPropertyDeep(update, '__v')) {
|
|
1388
|
-
update.$setOnInsert.__v = 0;
|
|
1389
|
-
}
|
|
1390
|
-
}
|
|
1391
1411
|
index_1.ResolveIOServer.getMainDB().collection(this.collectionName).updateOne(filter, update, options).then(function (res) {
|
|
1392
1412
|
if (res.result.ok) {
|
|
1393
1413
|
resolve(res.result.nModified);
|
|
@@ -1400,8 +1420,83 @@ var Collection = /** @class */ (function () {
|
|
|
1400
1420
|
else {
|
|
1401
1421
|
reject('No Document');
|
|
1402
1422
|
}
|
|
1403
|
-
|
|
1404
|
-
case
|
|
1423
|
+
return [3 /*break*/, 3];
|
|
1424
|
+
case 2:
|
|
1425
|
+
if (options && options.upsert) {
|
|
1426
|
+
if (!update.$setOnInsert) {
|
|
1427
|
+
if (this.timestamps) {
|
|
1428
|
+
update.$setOnInsert = {
|
|
1429
|
+
_id: objectIdHexString(),
|
|
1430
|
+
createdAt: new Date()
|
|
1431
|
+
};
|
|
1432
|
+
}
|
|
1433
|
+
else {
|
|
1434
|
+
update.$setOnInsert = {
|
|
1435
|
+
_id: objectIdHexString()
|
|
1436
|
+
};
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
else {
|
|
1440
|
+
if (!update.$setOnInsert._id) {
|
|
1441
|
+
update.$setOnInsert._id = objectIdHexString();
|
|
1442
|
+
}
|
|
1443
|
+
if (this.timestamps) {
|
|
1444
|
+
update.$setOnInsert.createdAt = new Date();
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
if (this.createLogs && !bypassLogs) {
|
|
1449
|
+
if (!options) {
|
|
1450
|
+
options = { returnOriginal: true };
|
|
1451
|
+
}
|
|
1452
|
+
else {
|
|
1453
|
+
options.returnOriginal = true;
|
|
1454
|
+
}
|
|
1455
|
+
index_1.ResolveIOServer.getMainDB().collection(this.collectionName).findOneAndUpdate(filter, update, options).then(function (res) {
|
|
1456
|
+
var doc = res.value;
|
|
1457
|
+
if (doc) {
|
|
1458
|
+
log_collection_1.Logs.insertOne({
|
|
1459
|
+
_id: objectIdHexString(),
|
|
1460
|
+
type: 'document',
|
|
1461
|
+
collection: _this.collectionName,
|
|
1462
|
+
id_document: doc._id,
|
|
1463
|
+
payload: common_1.getBinarySize(JSON.stringify([doc, filter, update, options])) < 200000 ? JSON.stringify([doc, filter, update, options], null, 2) : 'Too Big',
|
|
1464
|
+
method: 'updateOne',
|
|
1465
|
+
id_user: '',
|
|
1466
|
+
user: '',
|
|
1467
|
+
messageId: 0,
|
|
1468
|
+
route: ''
|
|
1469
|
+
});
|
|
1470
|
+
}
|
|
1471
|
+
else {
|
|
1472
|
+
log_collection_1.Logs.insertOne({
|
|
1473
|
+
_id: objectIdHexString(),
|
|
1474
|
+
type: 'document',
|
|
1475
|
+
collection: _this.collectionName,
|
|
1476
|
+
id_document: update.$setOnInsert._id,
|
|
1477
|
+
payload: common_1.getBinarySize(JSON.stringify(['upsert', filter, update, options])) < 200000 ? JSON.stringify(['upsert', filter, update, options], null, 2) : 'Too Big',
|
|
1478
|
+
method: 'updateOne',
|
|
1479
|
+
id_user: '',
|
|
1480
|
+
user: '',
|
|
1481
|
+
messageId: 0,
|
|
1482
|
+
route: ''
|
|
1483
|
+
});
|
|
1484
|
+
}
|
|
1485
|
+
resolve(res.ok);
|
|
1486
|
+
}, function (err) { return reject(err); });
|
|
1487
|
+
}
|
|
1488
|
+
else {
|
|
1489
|
+
index_1.ResolveIOServer.getMainDB().collection(this.collectionName).updateOne(filter, update, options).then(function (res) {
|
|
1490
|
+
if (res.result.ok) {
|
|
1491
|
+
resolve(res.result.nModified);
|
|
1492
|
+
}
|
|
1493
|
+
else {
|
|
1494
|
+
reject(res.result.ok);
|
|
1495
|
+
}
|
|
1496
|
+
}, function (err) { return reject(err); });
|
|
1497
|
+
}
|
|
1498
|
+
_a.label = 3;
|
|
1499
|
+
case 3: return [2 /*return*/];
|
|
1405
1500
|
}
|
|
1406
1501
|
});
|
|
1407
1502
|
}); });
|