@resolveio/server-lib 22.2.14 → 22.2.15

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.
@@ -244,38 +244,80 @@ var MongoManager = /** @class */ (function () {
244
244
  MongoManager.prototype.oneTimeTransaction = function (fn) {
245
245
  var _this = this;
246
246
  return asyncLocalStorage.run({}, function () { return __awaiter(_this, void 0, void 0, function () {
247
- var session, result_1, store;
247
+ var attempt, maxRetries, _loop_1, this_1, state_1;
248
248
  var _this = this;
249
249
  return __generator(this, function (_a) {
250
250
  switch (_a.label) {
251
251
  case 0:
252
- session = resolveio_server_app_1.ResolveIOServer.getMongoConnection().startSession();
253
- asyncLocalStorage.getStore().session = session;
252
+ attempt = 0;
253
+ maxRetries = 4;
254
+ _loop_1 = function () {
255
+ var session, store, result_1, err_1, jitter, _b, activeStore;
256
+ return __generator(this, function (_c) {
257
+ switch (_c.label) {
258
+ case 0:
259
+ session = resolveio_server_app_1.ResolveIOServer.getMongoConnection().startSession();
260
+ store = asyncLocalStorage.getStore();
261
+ if (store) {
262
+ store.session = session;
263
+ }
264
+ _c.label = 1;
265
+ case 1:
266
+ _c.trys.push([1, 3, 5, 9]);
267
+ return [4 /*yield*/, session.withTransaction(function () { return __awaiter(_this, void 0, void 0, function () {
268
+ return __generator(this, function (_a) {
269
+ switch (_a.label) {
270
+ case 0: return [4 /*yield*/, fn()];
271
+ case 1:
272
+ result_1 = _a.sent();
273
+ return [2 /*return*/, result_1];
274
+ }
275
+ });
276
+ }); })];
277
+ case 2:
278
+ _c.sent();
279
+ return [2 /*return*/, { value: result_1 }];
280
+ case 3:
281
+ err_1 = _c.sent();
282
+ if (!this_1.shouldRetryTransactionError(err_1) || attempt >= maxRetries) {
283
+ throw err_1;
284
+ }
285
+ attempt += 1;
286
+ jitter = Math.floor(Math.random() * 60);
287
+ return [4 /*yield*/, this_1.delay((120 * attempt) + jitter)];
288
+ case 4:
289
+ _c.sent();
290
+ return [3 /*break*/, 9];
291
+ case 5:
292
+ _c.trys.push([5, 7, , 8]);
293
+ return [4 /*yield*/, session.endSession()];
294
+ case 6:
295
+ _c.sent();
296
+ return [3 /*break*/, 8];
297
+ case 7:
298
+ _b = _c.sent();
299
+ return [3 /*break*/, 8];
300
+ case 8:
301
+ activeStore = asyncLocalStorage.getStore();
302
+ if (activeStore) {
303
+ delete activeStore.session;
304
+ }
305
+ return [7 /*endfinally*/];
306
+ case 9: return [2 /*return*/];
307
+ }
308
+ });
309
+ };
310
+ this_1 = this;
254
311
  _a.label = 1;
255
312
  case 1:
256
- _a.trys.push([1, , 3, 5]);
257
- return [4 /*yield*/, session.withTransaction(function () { return __awaiter(_this, void 0, void 0, function () {
258
- return __generator(this, function (_a) {
259
- switch (_a.label) {
260
- case 0: return [4 /*yield*/, fn()];
261
- case 1:
262
- // Directly assign the result from fn()
263
- result_1 = _a.sent();
264
- return [2 /*return*/, result_1]; // Explicit return for transaction validation
265
- }
266
- });
267
- }); })];
313
+ if (!true) return [3 /*break*/, 3];
314
+ return [5 /*yield**/, _loop_1()];
268
315
  case 2:
269
- _a.sent();
270
- return [2 /*return*/, result_1]; // Transaction committed successfully
271
- case 3: return [4 /*yield*/, session.endSession()];
272
- case 4:
273
- _a.sent();
274
- store = asyncLocalStorage.getStore();
275
- if (store)
276
- delete store.session;
277
- return [7 /*endfinally*/];
278
- case 5: return [2 /*return*/];
316
+ state_1 = _a.sent();
317
+ if (typeof state_1 === "object")
318
+ return [2 /*return*/, state_1.value];
319
+ return [3 /*break*/, 1];
320
+ case 3: return [2 /*return*/];
279
321
  }
280
322
  });
281
323
  }); });
@@ -355,6 +397,43 @@ var MongoManager = /** @class */ (function () {
355
397
  });
356
398
  });
357
399
  };
400
+ MongoManager.prototype.hasMongoErrorLabel = function (err, label) {
401
+ if (!err || !label) {
402
+ return false;
403
+ }
404
+ if (typeof err.hasErrorLabel === 'function') {
405
+ try {
406
+ if (err.hasErrorLabel(label)) {
407
+ return true;
408
+ }
409
+ }
410
+ catch (_a) { }
411
+ }
412
+ if (Array.isArray(err.errorLabels) && err.errorLabels.includes(label)) {
413
+ return true;
414
+ }
415
+ return false;
416
+ };
417
+ MongoManager.prototype.shouldRetryWriteConflict = function (err) {
418
+ if (!err) {
419
+ return false;
420
+ }
421
+ if (err.code === 112 || err.codeName === 'WriteConflict') {
422
+ return true;
423
+ }
424
+ var message = String(err.message || '');
425
+ return /write conflict/i.test(message) || /yielding is disabled/i.test(message);
426
+ };
427
+ MongoManager.prototype.shouldRetryTransactionError = function (err) {
428
+ if (!err) {
429
+ return false;
430
+ }
431
+ if (this.shouldRetryWriteConflict(err) || this.shouldRetryWaitQueueTimeout(err)) {
432
+ return true;
433
+ }
434
+ return this.hasMongoErrorLabel(err, 'TransientTransactionError')
435
+ || this.hasMongoErrorLabel(err, 'UnknownTransactionCommitResult');
436
+ };
358
437
  MongoManager.prototype.shouldRetryWaitQueueTimeout = function (err) {
359
438
  if (!err) {
360
439
  return false;
@@ -366,7 +445,7 @@ var MongoManager = /** @class */ (function () {
366
445
  };
367
446
  MongoManager.prototype.retryRead = function (operation, options) {
368
447
  return __awaiter(this, void 0, void 0, function () {
369
- var attempt, maxRetries, err_1;
448
+ var attempt, maxRetries, err_2;
370
449
  return __generator(this, function (_a) {
371
450
  switch (_a.label) {
372
451
  case 0:
@@ -384,9 +463,9 @@ var MongoManager = /** @class */ (function () {
384
463
  return [4 /*yield*/, operation()];
385
464
  case 3: return [2 /*return*/, _a.sent()];
386
465
  case 4:
387
- err_1 = _a.sent();
388
- if (!this.shouldRetryWaitQueueTimeout(err_1) || attempt >= maxRetries) {
389
- throw err_1;
466
+ err_2 = _a.sent();
467
+ if (!this.shouldRetryWaitQueueTimeout(err_2) || attempt >= maxRetries) {
468
+ throw err_2;
390
469
  }
391
470
  attempt += 1;
392
471
  return [4 /*yield*/, this.delay(100 * attempt)];
@@ -447,7 +526,7 @@ var MongoManager = /** @class */ (function () {
447
526
  };
448
527
  MongoManager.prototype.executeFind = function (collectionName, filter, options, cacheKey) {
449
528
  return __awaiter(this, void 0, void 0, function () {
450
- var result, collection, _a, session, safeOptions, pubContext, monitor, queryStart, err_2, durationMs;
529
+ var result, collection, _a, session, safeOptions, pubContext, monitor, queryStart, err_3, durationMs;
451
530
  return __generator(this, function (_b) {
452
531
  switch (_b.label) {
453
532
  case 0:
@@ -464,15 +543,15 @@ var MongoManager = /** @class */ (function () {
464
543
  result = _b.sent();
465
544
  return [3 /*break*/, 6];
466
545
  case 3:
467
- err_2 = _b.sent();
546
+ err_3 = _b.sent();
468
547
  console.log(JSON.stringify([new Date(), 'Error Execute Find', collectionName, filter, safeOptions, {
469
- code: err_2.code,
470
- codeName: err_2.codeName,
471
- message: err_2.message,
472
- stack: err_2.stack
548
+ code: err_3.code,
549
+ codeName: err_3.codeName,
550
+ message: err_3.message,
551
+ stack: err_3.stack
473
552
  }], null, 2));
474
- err_2.message = "Error in Execute Find: ".concat(collectionName, " => ").concat(err_2.codeName || 'NoCodeName', " => ").concat(err_2.message);
475
- throw err_2;
553
+ err_3.message = "Error in Execute Find: ".concat(collectionName, " => ").concat(err_3.codeName || 'NoCodeName', " => ").concat(err_3.message);
554
+ throw err_3;
476
555
  case 4:
477
556
  durationMs = Date.now() - queryStart;
478
557
  return [4 /*yield*/, monitor.finish()];
@@ -549,7 +628,7 @@ var MongoManager = /** @class */ (function () {
549
628
  };
550
629
  MongoManager.prototype.executeFindOne = function (collectionName, filter, options, cacheKey) {
551
630
  return __awaiter(this, void 0, void 0, function () {
552
- var result, collection, _a, session, safeOptions, pubContext, monitor, queryStart, err_3, durationMs;
631
+ var result, collection, _a, session, safeOptions, pubContext, monitor, queryStart, err_4, durationMs;
553
632
  return __generator(this, function (_b) {
554
633
  switch (_b.label) {
555
634
  case 0:
@@ -566,15 +645,15 @@ var MongoManager = /** @class */ (function () {
566
645
  result = _b.sent();
567
646
  return [3 /*break*/, 6];
568
647
  case 3:
569
- err_3 = _b.sent();
648
+ err_4 = _b.sent();
570
649
  console.log(JSON.stringify([new Date(), 'Error Execute Find One', collectionName, filter, safeOptions, {
571
- code: err_3.code,
572
- codeName: err_3.codeName,
573
- message: err_3.message,
574
- stack: err_3.stack
650
+ code: err_4.code,
651
+ codeName: err_4.codeName,
652
+ message: err_4.message,
653
+ stack: err_4.stack
575
654
  }], null, 2));
576
- err_3.message = "Error in Execute Find One: ".concat(collectionName, " => ").concat(err_3.codeName || 'NoCodeName', " => ").concat(err_3.message);
577
- throw err_3;
655
+ err_4.message = "Error in Execute Find One: ".concat(collectionName, " => ").concat(err_4.codeName || 'NoCodeName', " => ").concat(err_4.message);
656
+ throw err_4;
578
657
  case 4:
579
658
  durationMs = Date.now() - queryStart;
580
659
  return [4 /*yield*/, monitor.finish()];
@@ -651,7 +730,7 @@ var MongoManager = /** @class */ (function () {
651
730
  };
652
731
  MongoManager.prototype.executeAggregate = function (collectionName, pipeline, options, cacheKey, collections) {
653
732
  return __awaiter(this, void 0, void 0, function () {
654
- var result, collection, _a, session, safeOptions, pubContext, monitor, queryStart, err_4, durationMs;
733
+ var result, collection, _a, session, safeOptions, pubContext, monitor, queryStart, err_5, durationMs;
655
734
  return __generator(this, function (_b) {
656
735
  switch (_b.label) {
657
736
  case 0:
@@ -668,15 +747,15 @@ var MongoManager = /** @class */ (function () {
668
747
  result = _b.sent();
669
748
  return [3 /*break*/, 6];
670
749
  case 3:
671
- err_4 = _b.sent();
750
+ err_5 = _b.sent();
672
751
  console.log(JSON.stringify([new Date(), 'Error Execute Aggregate', collectionName, pipeline, collections, safeOptions, {
673
- code: err_4.code,
674
- codeName: err_4.codeName,
675
- message: err_4.message,
676
- stack: err_4.stack
752
+ code: err_5.code,
753
+ codeName: err_5.codeName,
754
+ message: err_5.message,
755
+ stack: err_5.stack
677
756
  }], null, 2));
678
- err_4.message = "Error in Execute Aggregate: ".concat(collectionName, " => ").concat(err_4.codeName || 'NoCodeName', " => ").concat(err_4.message);
679
- throw err_4;
757
+ err_5.message = "Error in Execute Aggregate: ".concat(collectionName, " => ").concat(err_5.codeName || 'NoCodeName', " => ").concat(err_5.message);
758
+ throw err_5;
680
759
  case 4:
681
760
  durationMs = Date.now() - queryStart;
682
761
  return [4 /*yield*/, monitor.finish()];
@@ -738,7 +817,7 @@ var MongoManager = /** @class */ (function () {
738
817
  };
739
818
  MongoManager.prototype.executeCountDocuments = function (collectionName, filter, options, cacheKey) {
740
819
  return __awaiter(this, void 0, void 0, function () {
741
- var result, collection, _a, session, safeOptions, pubContext, monitor, queryStart, err_5, durationMs;
820
+ var result, collection, _a, session, safeOptions, pubContext, monitor, queryStart, err_6, durationMs;
742
821
  return __generator(this, function (_b) {
743
822
  switch (_b.label) {
744
823
  case 0:
@@ -755,15 +834,15 @@ var MongoManager = /** @class */ (function () {
755
834
  result = _b.sent();
756
835
  return [3 /*break*/, 6];
757
836
  case 3:
758
- err_5 = _b.sent();
837
+ err_6 = _b.sent();
759
838
  console.log(JSON.stringify([new Date(), 'Error Execute Count Documents', collectionName, filter, safeOptions, {
760
- code: err_5.code,
761
- codeName: err_5.codeName,
762
- message: err_5.message,
763
- stack: err_5.stack
839
+ code: err_6.code,
840
+ codeName: err_6.codeName,
841
+ message: err_6.message,
842
+ stack: err_6.stack
764
843
  }], null, 2));
765
- err_5.message = "Error in Execute Count Documents: ".concat(collectionName, " => ").concat(err_5.codeName || 'NoCodeName', " => ").concat(err_5.message);
766
- throw err_5;
844
+ err_6.message = "Error in Execute Count Documents: ".concat(collectionName, " => ").concat(err_6.codeName || 'NoCodeName', " => ").concat(err_6.message);
845
+ throw err_6;
767
846
  case 4:
768
847
  durationMs = Date.now() - queryStart;
769
848
  return [4 /*yield*/, monitor.finish()];
@@ -1011,7 +1090,7 @@ var MongoManager = /** @class */ (function () {
1011
1090
  };
1012
1091
  MongoManager.prototype.teardownChangeStream = function (forceClose) {
1013
1092
  return __awaiter(this, void 0, void 0, function () {
1014
- var currentStream, err_6;
1093
+ var currentStream, err_7;
1015
1094
  return __generator(this, function (_a) {
1016
1095
  switch (_a.label) {
1017
1096
  case 0:
@@ -1030,8 +1109,8 @@ var MongoManager = /** @class */ (function () {
1030
1109
  _a.sent();
1031
1110
  return [3 /*break*/, 4];
1032
1111
  case 3:
1033
- err_6 = _a.sent();
1034
- console.log(new Date(), 'Mongo change stream close failed', err_6);
1112
+ err_7 = _a.sent();
1113
+ console.log(new Date(), 'Mongo change stream close failed', err_7);
1035
1114
  return [3 /*break*/, 4];
1036
1115
  case 4: return [2 /*return*/];
1037
1116
  }
@@ -1069,7 +1148,7 @@ var MongoManager = /** @class */ (function () {
1069
1148
  return;
1070
1149
  }
1071
1150
  this._changeStreamRestartTimeout = setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
1072
- var err_7;
1151
+ var err_8;
1073
1152
  return __generator(this, function (_a) {
1074
1153
  switch (_a.label) {
1075
1154
  case 0:
@@ -1082,8 +1161,8 @@ var MongoManager = /** @class */ (function () {
1082
1161
  _a.sent();
1083
1162
  return [3 /*break*/, 4];
1084
1163
  case 3:
1085
- err_7 = _a.sent();
1086
- console.log(new Date(), 'Mongo change stream restart failed. Retrying...', err_7);
1164
+ err_8 = _a.sent();
1165
+ console.log(new Date(), 'Mongo change stream restart failed. Retrying...', err_8);
1087
1166
  this.scheduleChangeStreamRestart(Math.min(delayMs * 2, 60000));
1088
1167
  return [3 /*break*/, 4];
1089
1168
  case 4: return [2 /*return*/];
@@ -1223,7 +1302,8 @@ var MongoManagerCollection = /** @class */ (function () {
1223
1302
  if (err.code === 112 || err.codeName === 'WriteConflict') {
1224
1303
  return true;
1225
1304
  }
1226
- return typeof err.message === 'string' && err.message.includes('Write conflict');
1305
+ var message = String(err.message || '');
1306
+ return /write conflict/i.test(message) || /yielding is disabled/i.test(message);
1227
1307
  };
1228
1308
  MongoManagerCollection.prototype.shouldRetryWaitQueueTimeout = function (err) {
1229
1309
  if (!err) {
@@ -1244,7 +1324,7 @@ var MongoManagerCollection = /** @class */ (function () {
1244
1324
  };
1245
1325
  MongoManagerCollection.prototype.retryWrite = function (operation, options) {
1246
1326
  return __awaiter(this, void 0, void 0, function () {
1247
- var attempt, maxRetries, err_8, shouldRetry;
1327
+ var attempt, configuredMaxRetries, maxRetries, configuredBaseDelay, baseDelayMs, err_9, shouldRetry, backoff, jitter;
1248
1328
  return __generator(this, function (_a) {
1249
1329
  switch (_a.label) {
1250
1330
  case 0:
@@ -1252,7 +1332,14 @@ var MongoManagerCollection = /** @class */ (function () {
1252
1332
  return [2 /*return*/, operation()];
1253
1333
  }
1254
1334
  attempt = 0;
1255
- maxRetries = 5;
1335
+ configuredMaxRetries = Number(process.env.MONGO_WRITE_RETRY_MAX || 8);
1336
+ maxRetries = Number.isFinite(configuredMaxRetries) && configuredMaxRetries >= 0
1337
+ ? Math.min(Math.floor(configuredMaxRetries), 20)
1338
+ : 8;
1339
+ configuredBaseDelay = Number(process.env.MONGO_WRITE_RETRY_BASE_MS || 120);
1340
+ baseDelayMs = Number.isFinite(configuredBaseDelay) && configuredBaseDelay > 0
1341
+ ? Math.min(Math.floor(configuredBaseDelay), 5000)
1342
+ : 120;
1256
1343
  _a.label = 1;
1257
1344
  case 1:
1258
1345
  if (!true) return [3 /*break*/, 7];
@@ -1262,13 +1349,15 @@ var MongoManagerCollection = /** @class */ (function () {
1262
1349
  return [4 /*yield*/, operation()];
1263
1350
  case 3: return [2 /*return*/, _a.sent()];
1264
1351
  case 4:
1265
- err_8 = _a.sent();
1266
- shouldRetry = this.shouldRetryWriteConflict(err_8) || this.shouldRetryWaitQueueTimeout(err_8);
1352
+ err_9 = _a.sent();
1353
+ shouldRetry = this.shouldRetryWriteConflict(err_9) || this.shouldRetryWaitQueueTimeout(err_9);
1267
1354
  if (!shouldRetry || attempt >= maxRetries) {
1268
- throw err_8;
1355
+ throw err_9;
1269
1356
  }
1270
1357
  attempt += 1;
1271
- return [4 /*yield*/, this.delay(75 * attempt)];
1358
+ backoff = Math.min(5000, baseDelayMs * (Math.pow(2, (attempt - 1))));
1359
+ jitter = Math.floor(Math.random() * 90);
1360
+ return [4 /*yield*/, this.delay(backoff + jitter)];
1272
1361
  case 5:
1273
1362
  _a.sent();
1274
1363
  return [3 /*break*/, 6];
@@ -1280,7 +1369,7 @@ var MongoManagerCollection = /** @class */ (function () {
1280
1369
  };
1281
1370
  MongoManagerCollection.prototype.retryRead = function (operation, options) {
1282
1371
  return __awaiter(this, void 0, void 0, function () {
1283
- var attempt, maxRetries, err_9;
1372
+ var attempt, maxRetries, err_10;
1284
1373
  return __generator(this, function (_a) {
1285
1374
  switch (_a.label) {
1286
1375
  case 0:
@@ -1298,9 +1387,9 @@ var MongoManagerCollection = /** @class */ (function () {
1298
1387
  return [4 /*yield*/, operation()];
1299
1388
  case 3: return [2 /*return*/, _a.sent()];
1300
1389
  case 4:
1301
- err_9 = _a.sent();
1302
- if (!this.shouldRetryWaitQueueTimeout(err_9) || attempt >= maxRetries) {
1303
- throw err_9;
1390
+ err_10 = _a.sent();
1391
+ if (!this.shouldRetryWaitQueueTimeout(err_10) || attempt >= maxRetries) {
1392
+ throw err_10;
1304
1393
  }
1305
1394
  attempt += 1;
1306
1395
  return [4 /*yield*/, this.delay(100 * attempt)];
@@ -1315,7 +1404,7 @@ var MongoManagerCollection = /** @class */ (function () {
1315
1404
  };
1316
1405
  MongoManagerCollection.prototype.aggregate = function (pipeline_1, options_1) {
1317
1406
  return __awaiter(this, arguments, void 0, function (pipeline, options, skipCache, bypassSession) {
1318
- var mongoSession, _a, session, safeOptions, monitor, res, err_10;
1407
+ var mongoSession, _a, session, safeOptions, monitor, res, err_11;
1319
1408
  if (skipCache === void 0) { skipCache = false; }
1320
1409
  if (bypassSession === void 0) { bypassSession = false; }
1321
1410
  return __generator(this, function (_b) {
@@ -1346,15 +1435,15 @@ var MongoManagerCollection = /** @class */ (function () {
1346
1435
  (0, subscription_dependency_context_1.recordAggregateDependencies)(this.collectionName, pipeline, res);
1347
1436
  return [2 /*return*/, res];
1348
1437
  case 4:
1349
- err_10 = _b.sent();
1438
+ err_11 = _b.sent();
1350
1439
  console.log(JSON.stringify([new Date(), 'Error Aggregate', this.collectionName, pipeline, safeOptions, {
1351
- code: err_10.code,
1352
- codeName: err_10.codeName,
1353
- message: err_10.message,
1354
- stack: err_10.stack
1440
+ code: err_11.code,
1441
+ codeName: err_11.codeName,
1442
+ message: err_11.message,
1443
+ stack: err_11.stack
1355
1444
  }], null, 2));
1356
- err_10.message = "Error in Aggregate: ".concat(this.collectionName, " => ").concat(err_10.codeName || 'NoCodeName', " => ").concat(err_10.message);
1357
- throw err_10;
1445
+ err_11.message = "Error in Aggregate: ".concat(this.collectionName, " => ").concat(err_11.codeName || 'NoCodeName', " => ").concat(err_11.message);
1446
+ throw err_11;
1358
1447
  case 5: return [4 /*yield*/, monitor.finish()];
1359
1448
  case 6:
1360
1449
  _b.sent();
@@ -1366,7 +1455,7 @@ var MongoManagerCollection = /** @class */ (function () {
1366
1455
  };
1367
1456
  MongoManagerCollection.prototype.aggregateCount = function (pipeline_1, options_1) {
1368
1457
  return __awaiter(this, arguments, void 0, function (pipeline, options, bypassSession) {
1369
- var mongoSession, _a, session, safeOptions, monitor, res, err_11;
1458
+ var mongoSession, _a, session, safeOptions, monitor, res, err_12;
1370
1459
  if (bypassSession === void 0) { bypassSession = false; }
1371
1460
  return __generator(this, function (_b) {
1372
1461
  switch (_b.label) {
@@ -1393,15 +1482,15 @@ var MongoManagerCollection = /** @class */ (function () {
1393
1482
  (0, subscription_dependency_context_1.recordAggregateDependencies)(this.collectionName, pipeline, res);
1394
1483
  return [2 /*return*/, res.length];
1395
1484
  case 3:
1396
- err_11 = _b.sent();
1485
+ err_12 = _b.sent();
1397
1486
  console.log(JSON.stringify([new Date(), 'Error Aggregate Count', this.collectionName, pipeline, safeOptions, {
1398
- code: err_11.code,
1399
- codeName: err_11.codeName,
1400
- message: err_11.message,
1401
- stack: err_11.stack
1487
+ code: err_12.code,
1488
+ codeName: err_12.codeName,
1489
+ message: err_12.message,
1490
+ stack: err_12.stack
1402
1491
  }], null, 2));
1403
- err_11.message = "Error in Aggregate Count: ".concat(this.collectionName, " => ").concat(err_11.codeName || 'NoCodeName', " => ").concat(err_11.message);
1404
- throw err_11;
1492
+ err_12.message = "Error in Aggregate Count: ".concat(this.collectionName, " => ").concat(err_12.codeName || 'NoCodeName', " => ").concat(err_12.message);
1493
+ throw err_12;
1405
1494
  case 4: return [4 /*yield*/, monitor.finish()];
1406
1495
  case 5:
1407
1496
  _b.sent();
@@ -1472,14 +1561,14 @@ var MongoManagerCollection = /** @class */ (function () {
1472
1561
  };
1473
1562
  MongoManagerCollection.prototype.bulkWrite = function (operations_1, options_1) {
1474
1563
  return __awaiter(this, arguments, void 0, function (operations, options, bypassCheckSchema, bypassLogs, bypassVersions, bypassSession) {
1475
- var BATCH_SIZE, opIndex, mongoSession, _a, session, safeOptions, batchOps, logs, versionOps, batchOps_1, batchOps_1_1, op, opType, doc, validationContext, isValid, affectedDocs, versionFilters, versionInserts, _b, _c, monitor, err_12, bwOptions, affectedDocIds, pipeline, oldVersions, _d;
1476
- var e_6, _e;
1564
+ var BATCH_SIZE, opIndex, mongoSession, _a, session, safeOptions, _loop_2, this_2;
1565
+ var _this = this;
1477
1566
  if (bypassCheckSchema === void 0) { bypassCheckSchema = false; }
1478
1567
  if (bypassLogs === void 0) { bypassLogs = false; }
1479
1568
  if (bypassVersions === void 0) { bypassVersions = false; }
1480
1569
  if (bypassSession === void 0) { bypassSession = false; }
1481
- return __generator(this, function (_f) {
1482
- switch (_f.label) {
1570
+ return __generator(this, function (_b) {
1571
+ switch (_b.label) {
1483
1572
  case 0:
1484
1573
  if (!operations.length) {
1485
1574
  return [2 /*return*/, null];
@@ -1496,334 +1585,348 @@ var MongoManagerCollection = /** @class */ (function () {
1496
1585
  }
1497
1586
  }
1498
1587
  _a = options || {}, session = _a.session, safeOptions = __rest(_a, ["session"]);
1499
- _f.label = 1;
1500
- case 1:
1501
- if (!(opIndex < operations.length)) return [3 /*break*/, 27];
1502
- batchOps = operations.slice(opIndex, opIndex + BATCH_SIZE);
1503
- logs = [];
1504
- versionOps = [];
1505
- try {
1506
- for (batchOps_1 = (e_6 = void 0, __values(batchOps)), batchOps_1_1 = batchOps_1.next(); !batchOps_1_1.done; batchOps_1_1 = batchOps_1.next()) {
1507
- op = batchOps_1_1.value;
1508
- opType = Object.keys(op)[0];
1509
- doc = op[opType];
1510
- // Skip validation if bypassCheckSchema is true
1511
- if (this.checkSchema && !bypassCheckSchema) {
1512
- validationContext = this.simplschema.newContext();
1513
- isValid = void 0;
1514
- if (opType === 'insertOne') {
1515
- isValid = validationContext.validate(doc.document);
1516
- }
1517
- else if (opType === 'replaceOne') {
1518
- isValid = validationContext.validate(doc.replacement);
1519
- }
1520
- else if (opType === 'updateOne' || opType === 'updateMany') {
1521
- // For updates, validate the update modifier
1522
- isValid = validationContext.validate(doc.update, { modifier: true });
1523
- }
1524
- else if (opType === 'deleteOne' || opType === 'deleteMany') {
1525
- // No validation needed for deletes
1526
- isValid = true;
1527
- }
1528
- else {
1529
- throw new Error("Unsupported operation type: ".concat(opType));
1530
- }
1531
- if (!isValid) {
1532
- throw new Error("Schema validation failed for ".concat(opType, ": ").concat(JSON.stringify(validationContext.validationErrors(), null, 2)));
1533
- }
1534
- }
1535
- // Now proceed to process the operations
1536
- if (opType === 'insertOne') {
1537
- // If this.timestamps is true, set createdAt and updatedAt
1538
- if (this.timestamps) {
1539
- if (!doc.document.createdAt) {
1540
- doc.document.createdAt = new Date();
1588
+ _loop_2 = function () {
1589
+ var batchOps, logs, versionOps, batchOps_1, batchOps_1_1, op, opType, doc, validationContext, isValid, affectedDocs, versionFilters, versionInserts, _c, _d, monitor, err_13, bwOptions, affectedDocIds, pipeline, oldVersions, _e;
1590
+ var e_6, _f;
1591
+ return __generator(this, function (_g) {
1592
+ switch (_g.label) {
1593
+ case 0:
1594
+ batchOps = operations.slice(opIndex, opIndex + BATCH_SIZE);
1595
+ logs = [];
1596
+ versionOps = [];
1597
+ try {
1598
+ for (batchOps_1 = (e_6 = void 0, __values(batchOps)), batchOps_1_1 = batchOps_1.next(); !batchOps_1_1.done; batchOps_1_1 = batchOps_1.next()) {
1599
+ op = batchOps_1_1.value;
1600
+ opType = Object.keys(op)[0];
1601
+ doc = op[opType];
1602
+ // Skip validation if bypassCheckSchema is true
1603
+ if (this_2.checkSchema && !bypassCheckSchema) {
1604
+ validationContext = this_2.simplschema.newContext();
1605
+ isValid = void 0;
1606
+ if (opType === 'insertOne') {
1607
+ isValid = validationContext.validate(doc.document);
1608
+ }
1609
+ else if (opType === 'replaceOne') {
1610
+ isValid = validationContext.validate(doc.replacement);
1611
+ }
1612
+ else if (opType === 'updateOne' || opType === 'updateMany') {
1613
+ // For updates, validate the update modifier
1614
+ isValid = validationContext.validate(doc.update, { modifier: true });
1615
+ }
1616
+ else if (opType === 'deleteOne' || opType === 'deleteMany') {
1617
+ // No validation needed for deletes
1618
+ isValid = true;
1619
+ }
1620
+ else {
1621
+ throw new Error("Unsupported operation type: ".concat(opType));
1622
+ }
1623
+ if (!isValid) {
1624
+ throw new Error("Schema validation failed for ".concat(opType, ": ").concat(JSON.stringify(validationContext.validationErrors(), null, 2)));
1625
+ }
1626
+ }
1627
+ // Now proceed to process the operations
1628
+ if (opType === 'insertOne') {
1629
+ // If this.timestamps is true, set createdAt and updatedAt
1630
+ if (this_2.timestamps) {
1631
+ if (!doc.document.createdAt) {
1632
+ doc.document.createdAt = new Date();
1633
+ }
1634
+ if (!doc.document.updatedAt) {
1635
+ doc.document.updatedAt = new Date();
1636
+ }
1637
+ }
1638
+ // Prepare log entry
1639
+ if (!bypassLogs && this_2.createLogs) {
1640
+ logs.push({
1641
+ _id: (0, common_1.objectIdHexString)(),
1642
+ type: 'document',
1643
+ collection: this_2.collectionName,
1644
+ id_document: doc.document._id || (0, common_1.objectIdHexString)(),
1645
+ payload: (0, common_1.getBinarySize)(JSON.stringify(doc.document)) < 1000000
1646
+ ? JSON.stringify(doc.document, null, 2)
1647
+ : 'Too Big',
1648
+ method: 'insertOne',
1649
+ id_user: '', // Add user info if available
1650
+ user: '',
1651
+ messageId: 0,
1652
+ route: '',
1653
+ createdAt: new Date(),
1654
+ });
1655
+ }
1656
+ // Since we might have modified doc.document, update the operation
1657
+ op[opType].document = doc.document;
1658
+ }
1659
+ else if (opType === 'updateOne' || opType === 'updateMany') {
1660
+ // If this.timestamps is true, add updatedAt
1661
+ if (this_2.timestamps) {
1662
+ if (!doc.update.$set) {
1663
+ doc.update.$set = {};
1664
+ }
1665
+ doc.update.$set.updatedAt = new Date();
1666
+ }
1667
+ // If this.useVersions is true, increment __v
1668
+ if (!bypassVersions && this_2.useVersions) {
1669
+ if (!doc.update.$inc) {
1670
+ doc.update.$inc = {};
1671
+ }
1672
+ doc.update.$inc.__v = 1;
1673
+ }
1674
+ // Prepare log entry
1675
+ if (!bypassLogs && this_2.createLogs) {
1676
+ logs.push({
1677
+ _id: (0, common_1.objectIdHexString)(),
1678
+ type: 'document',
1679
+ collection: this_2.collectionName,
1680
+ id_document: doc.filter._id || null,
1681
+ payload: (0, common_1.getBinarySize)(JSON.stringify(doc.update)) < 1000000
1682
+ ? JSON.stringify(doc.update, null, 2)
1683
+ : 'Too Big',
1684
+ method: opType,
1685
+ id_user: '', // Add user info if available
1686
+ user: '',
1687
+ messageId: 0,
1688
+ route: '',
1689
+ instance_index: process.env.NODE_APP_INSTANCE || '0',
1690
+ createdAt: new Date()
1691
+ });
1692
+ }
1693
+ // For versioning, store the filter to fetch the document later
1694
+ if (!bypassVersions && this_2.useVersions) {
1695
+ versionOps.push({
1696
+ filter: doc.filter,
1697
+ });
1698
+ }
1699
+ // No need to modify the operation further
1700
+ }
1701
+ else if (opType === 'replaceOne') {
1702
+ // If this.timestamps is true, set updatedAt
1703
+ if (this_2.timestamps) {
1704
+ doc.replacement.updatedAt = new Date();
1705
+ }
1706
+ // If this.useVersions is true, increment __v
1707
+ if (!bypassVersions && this_2.useVersions) {
1708
+ doc.replacement.__v = (doc.replacement.__v || 0) + 1;
1709
+ }
1710
+ // Prepare log entry
1711
+ if (!bypassLogs && this_2.createLogs) {
1712
+ logs.push({
1713
+ _id: (0, common_1.objectIdHexString)(),
1714
+ type: 'document',
1715
+ collection: this_2.collectionName,
1716
+ id_document: doc.filter._id || null,
1717
+ payload: (0, common_1.getBinarySize)(JSON.stringify(doc.replacement)) < 1000000
1718
+ ? JSON.stringify(doc.replacement, null, 2)
1719
+ : 'Too Big',
1720
+ method: 'replaceOne',
1721
+ id_user: '', // Add user info if available
1722
+ user: '',
1723
+ messageId: 0,
1724
+ route: '',
1725
+ createdAt: new Date(),
1726
+ });
1727
+ }
1728
+ // For versioning, store the filter to fetch the document later
1729
+ if (!bypassVersions && this_2.useVersions) {
1730
+ versionOps.push({
1731
+ filter: doc.filter,
1732
+ });
1733
+ }
1734
+ // Since we might have modified doc.replacement, update the operation
1735
+ op[opType].replacement = doc.replacement;
1736
+ }
1737
+ else if (opType === 'deleteOne' || opType === 'deleteMany') {
1738
+ // Prepare log entry
1739
+ if (!bypassLogs && this_2.createLogs) {
1740
+ logs.push({
1741
+ _id: (0, common_1.objectIdHexString)(),
1742
+ type: 'document',
1743
+ collection: this_2.collectionName,
1744
+ id_document: doc.filter._id || null,
1745
+ payload: (0, common_1.getBinarySize)(JSON.stringify(doc.filter)) < 1000000
1746
+ ? JSON.stringify(doc.filter, null, 2)
1747
+ : 'Too Big',
1748
+ method: opType,
1749
+ id_user: '', // Add user info if available
1750
+ user: '',
1751
+ messageId: 0,
1752
+ route: '',
1753
+ createdAt: new Date(),
1754
+ });
1755
+ }
1756
+ // For versioning, store the filter to fetch the document later
1757
+ if (!bypassVersions && this_2.useVersions) {
1758
+ versionOps.push({
1759
+ filter: doc.filter,
1760
+ });
1761
+ }
1762
+ // No need to modify the operation
1763
+ }
1764
+ else {
1765
+ throw new Error("Unsupported operation type: ".concat(opType));
1766
+ }
1767
+ }
1541
1768
  }
1542
- if (!doc.document.updatedAt) {
1543
- doc.document.updatedAt = new Date();
1544
- }
1545
- }
1546
- // Prepare log entry
1547
- if (!bypassLogs && this.createLogs) {
1548
- logs.push({
1549
- _id: (0, common_1.objectIdHexString)(),
1550
- type: 'document',
1551
- collection: this.collectionName,
1552
- id_document: doc.document._id || (0, common_1.objectIdHexString)(),
1553
- payload: (0, common_1.getBinarySize)(JSON.stringify(doc.document)) < 1000000
1554
- ? JSON.stringify(doc.document, null, 2)
1555
- : 'Too Big',
1556
- method: 'insertOne',
1557
- id_user: '', // Add user info if available
1558
- user: '',
1559
- messageId: 0,
1560
- route: '',
1561
- createdAt: new Date(),
1562
- });
1563
- }
1564
- // Since we might have modified doc.document, update the operation
1565
- op[opType].document = doc.document;
1566
- }
1567
- else if (opType === 'updateOne' || opType === 'updateMany') {
1568
- // If this.timestamps is true, add updatedAt
1569
- if (this.timestamps) {
1570
- if (!doc.update.$set) {
1571
- doc.update.$set = {};
1769
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
1770
+ finally {
1771
+ try {
1772
+ if (batchOps_1_1 && !batchOps_1_1.done && (_f = batchOps_1.return)) _f.call(batchOps_1);
1773
+ }
1774
+ finally { if (e_6) throw e_6.error; }
1572
1775
  }
1573
- doc.update.$set.updatedAt = new Date();
1574
- }
1575
- // If this.useVersions is true, increment __v
1576
- if (!bypassVersions && this.useVersions) {
1577
- if (!doc.update.$inc) {
1578
- doc.update.$inc = {};
1776
+ affectedDocs = [];
1777
+ if (!(!bypassVersions && this_2.useVersions && versionOps.length > 0)) return [3 /*break*/, 9];
1778
+ _g.label = 1;
1779
+ case 1:
1780
+ _g.trys.push([1, 8, , 9]);
1781
+ versionFilters = versionOps.map(function (v) { return v.filter; });
1782
+ if (!versionFilters.length) return [3 /*break*/, 3];
1783
+ return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMainDB().collection(this_2.collectionName).find({ $or: versionFilters }, { session: session }).toArray()];
1784
+ case 2:
1785
+ affectedDocs = _g.sent();
1786
+ _g.label = 3;
1787
+ case 3:
1788
+ versionInserts = affectedDocs.map(function (doc) { return ({
1789
+ insertOne: {
1790
+ document: __assign(__assign({}, doc), { _id: { _id: doc._id, __v: doc.__v } }),
1791
+ },
1792
+ }); });
1793
+ if (!(versionInserts.length > 0)) return [3 /*break*/, 7];
1794
+ _g.label = 4;
1795
+ case 4:
1796
+ _g.trys.push([4, 6, , 7]);
1797
+ return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMainDB().collection(this_2.versionCollection).bulkWrite(versionInserts)];
1798
+ case 5:
1799
+ _g.sent();
1800
+ return [3 /*break*/, 7];
1801
+ case 6:
1802
+ _c = _g.sent();
1803
+ return [3 /*break*/, 7];
1804
+ case 7: return [3 /*break*/, 9];
1805
+ case 8:
1806
+ _d = _g.sent();
1807
+ return [3 /*break*/, 9];
1808
+ case 9:
1809
+ monitor = monitor_manager_1.MonitorMongo.create('bulkWrite', this_2.collectionName, JSON.stringify([batchOps, safeOptions]));
1810
+ _g.label = 10;
1811
+ case 10:
1812
+ _g.trys.push([10, 12, 13, 15]);
1813
+ return [4 /*yield*/, this_2.retryWrite(function () { return resolveio_server_app_1.ResolveIOServer.getMainDB().collection(_this.collectionName).bulkWrite(batchOps, options || undefined); }, options)];
1814
+ case 11:
1815
+ _g.sent();
1816
+ return [3 /*break*/, 15];
1817
+ case 12:
1818
+ err_13 = _g.sent();
1819
+ console.log(JSON.stringify([new Date(), 'Error Bulk Write', this_2.collectionName, operations, safeOptions, {
1820
+ code: err_13.code,
1821
+ codeName: err_13.codeName,
1822
+ message: err_13.message,
1823
+ stack: err_13.stack
1824
+ }], null, 2));
1825
+ err_13.message = "Error in Bulk Write: ".concat(this_2.collectionName, " => ").concat(err_13.codeName || 'NoCodeName', " => ").concat(err_13.message);
1826
+ throw err_13;
1827
+ case 13: return [4 /*yield*/, monitor.finish()];
1828
+ case 14:
1829
+ _g.sent();
1830
+ return [7 /*endfinally*/];
1831
+ case 15:
1832
+ if (!(!bypassLogs && this_2.createLogs && logs.length > 0)) return [3 /*break*/, 18];
1833
+ if (!resolveio_server_app_1.ResolveIOServer.shouldWriteLogsOffline()) return [3 /*break*/, 16];
1834
+ resolveio_server_app_1.ResolveIOServer.getLocalLogManager().writeLogs(logs.map(function (a) {
1835
+ return {
1836
+ type: 'log',
1837
+ data: a
1838
+ };
1839
+ }));
1840
+ return [3 /*break*/, 18];
1841
+ case 16:
1842
+ bwOptions = null;
1843
+ bwOptions = { session: session, ordered: false };
1844
+ return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMainDB().collection('logs').bulkWrite(logs.map(function (a) {
1845
+ a.client = 'ResolveIO';
1846
+ a.instance = resolveio_server_app_1.ResolveIOServer.getInstanceHost();
1847
+ return {
1848
+ insertOne: {
1849
+ document: a
1850
+ }
1851
+ };
1852
+ }), bwOptions)];
1853
+ case 17:
1854
+ _g.sent();
1855
+ _g.label = 18;
1856
+ case 18:
1857
+ if (!(!bypassVersions && this_2.useVersions)) return [3 /*break*/, 24];
1858
+ _g.label = 19;
1859
+ case 19:
1860
+ _g.trys.push([19, 23, , 24]);
1861
+ affectedDocIds = affectedDocs.map(function (doc) { return doc._id; });
1862
+ pipeline = [
1863
+ {
1864
+ $match: { '_id._id': { $in: affectedDocIds } },
1865
+ },
1866
+ {
1867
+ $sort: { '_id._id': 1, '_id.__v': -1 },
1868
+ },
1869
+ {
1870
+ $group: {
1871
+ _id: '$_id._id',
1872
+ versions: { $push: '$_id' },
1873
+ },
1874
+ },
1875
+ {
1876
+ $project: {
1877
+ versionsToDelete: { $slice: ['$versions', 5, { $size: '$versions' }] },
1878
+ },
1879
+ },
1880
+ { $unwind: '$versionsToDelete' },
1881
+ {
1882
+ $replaceRoot: { newRoot: { _id: '$versionsToDelete' } },
1883
+ },
1884
+ ];
1885
+ return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMainDB().collection(this_2.versionCollection).aggregate(pipeline).toArray()];
1886
+ case 20:
1887
+ oldVersions = _g.sent();
1888
+ if (!(oldVersions.length > 0)) return [3 /*break*/, 22];
1889
+ return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMainDB().collection(this_2.versionCollection).deleteMany({ _id: { $in: oldVersions.map(function (v) { return v._id; }) } })];
1890
+ case 21:
1891
+ _g.sent();
1892
+ _g.label = 22;
1893
+ case 22: return [3 /*break*/, 24];
1894
+ case 23:
1895
+ _e = _g.sent();
1896
+ return [3 /*break*/, 24];
1897
+ case 24:
1898
+ opIndex += BATCH_SIZE;
1899
+ // Yield to the event loop
1900
+ // eslint-disable-next-line no-restricted-syntax
1901
+ return [4 /*yield*/, new Promise(function (resolve) { return setImmediate(resolve); })];
1902
+ case 25:
1903
+ // Yield to the event loop
1904
+ // eslint-disable-next-line no-restricted-syntax
1905
+ _g.sent();
1906
+ // Invalidate cache
1907
+ if (!this_2.skipCache) {
1908
+ resolveio_server_app_1.ResolveIOServer.getMongoManager().invalidateQueryCache(this_2.collectionName);
1579
1909
  }
1580
- doc.update.$inc.__v = 1;
1581
- }
1582
- // Prepare log entry
1583
- if (!bypassLogs && this.createLogs) {
1584
- logs.push({
1585
- _id: (0, common_1.objectIdHexString)(),
1586
- type: 'document',
1587
- collection: this.collectionName,
1588
- id_document: doc.filter._id || null,
1589
- payload: (0, common_1.getBinarySize)(JSON.stringify(doc.update)) < 1000000
1590
- ? JSON.stringify(doc.update, null, 2)
1591
- : 'Too Big',
1592
- method: opType,
1593
- id_user: '', // Add user info if available
1594
- user: '',
1595
- messageId: 0,
1596
- route: '',
1597
- instance_index: process.env.NODE_APP_INSTANCE || '0',
1598
- createdAt: new Date()
1599
- });
1600
- }
1601
- // For versioning, store the filter to fetch the document later
1602
- if (!bypassVersions && this.useVersions) {
1603
- versionOps.push({
1604
- filter: doc.filter,
1605
- });
1606
- }
1607
- // No need to modify the operation further
1608
- }
1609
- else if (opType === 'replaceOne') {
1610
- // If this.timestamps is true, set updatedAt
1611
- if (this.timestamps) {
1612
- doc.replacement.updatedAt = new Date();
1613
- }
1614
- // If this.useVersions is true, increment __v
1615
- if (!bypassVersions && this.useVersions) {
1616
- doc.replacement.__v = (doc.replacement.__v || 0) + 1;
1617
- }
1618
- // Prepare log entry
1619
- if (!bypassLogs && this.createLogs) {
1620
- logs.push({
1621
- _id: (0, common_1.objectIdHexString)(),
1622
- type: 'document',
1623
- collection: this.collectionName,
1624
- id_document: doc.filter._id || null,
1625
- payload: (0, common_1.getBinarySize)(JSON.stringify(doc.replacement)) < 1000000
1626
- ? JSON.stringify(doc.replacement, null, 2)
1627
- : 'Too Big',
1628
- method: 'replaceOne',
1629
- id_user: '', // Add user info if available
1630
- user: '',
1631
- messageId: 0,
1632
- route: '',
1633
- createdAt: new Date(),
1634
- });
1635
- }
1636
- // For versioning, store the filter to fetch the document later
1637
- if (!bypassVersions && this.useVersions) {
1638
- versionOps.push({
1639
- filter: doc.filter,
1640
- });
1641
- }
1642
- // Since we might have modified doc.replacement, update the operation
1643
- op[opType].replacement = doc.replacement;
1644
- }
1645
- else if (opType === 'deleteOne' || opType === 'deleteMany') {
1646
- // Prepare log entry
1647
- if (!bypassLogs && this.createLogs) {
1648
- logs.push({
1649
- _id: (0, common_1.objectIdHexString)(),
1650
- type: 'document',
1651
- collection: this.collectionName,
1652
- id_document: doc.filter._id || null,
1653
- payload: (0, common_1.getBinarySize)(JSON.stringify(doc.filter)) < 1000000
1654
- ? JSON.stringify(doc.filter, null, 2)
1655
- : 'Too Big',
1656
- method: opType,
1657
- id_user: '', // Add user info if available
1658
- user: '',
1659
- messageId: 0,
1660
- route: '',
1661
- createdAt: new Date(),
1662
- });
1663
- }
1664
- // For versioning, store the filter to fetch the document later
1665
- if (!bypassVersions && this.useVersions) {
1666
- versionOps.push({
1667
- filter: doc.filter,
1668
- });
1669
- }
1670
- // No need to modify the operation
1671
- }
1672
- else {
1673
- throw new Error("Unsupported operation type: ".concat(opType));
1910
+ return [2 /*return*/];
1674
1911
  }
1675
- }
1676
- }
1677
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
1678
- finally {
1679
- try {
1680
- if (batchOps_1_1 && !batchOps_1_1.done && (_e = batchOps_1.return)) _e.call(batchOps_1);
1681
- }
1682
- finally { if (e_6) throw e_6.error; }
1683
- }
1684
- affectedDocs = [];
1685
- if (!(!bypassVersions && this.useVersions && versionOps.length > 0)) return [3 /*break*/, 10];
1686
- _f.label = 2;
1912
+ });
1913
+ };
1914
+ this_2 = this;
1915
+ _b.label = 1;
1916
+ case 1:
1917
+ if (!(opIndex < operations.length)) return [3 /*break*/, 3];
1918
+ return [5 /*yield**/, _loop_2()];
1687
1919
  case 2:
1688
- _f.trys.push([2, 9, , 10]);
1689
- versionFilters = versionOps.map(function (v) { return v.filter; });
1690
- if (!versionFilters.length) return [3 /*break*/, 4];
1691
- return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMainDB().collection(this.collectionName).find({ $or: versionFilters }, { session: session }).toArray()];
1692
- case 3:
1693
- affectedDocs = _f.sent();
1694
- _f.label = 4;
1695
- case 4:
1696
- versionInserts = affectedDocs.map(function (doc) { return ({
1697
- insertOne: {
1698
- document: __assign(__assign({}, doc), { _id: { _id: doc._id, __v: doc.__v } }),
1699
- },
1700
- }); });
1701
- if (!(versionInserts.length > 0)) return [3 /*break*/, 8];
1702
- _f.label = 5;
1703
- case 5:
1704
- _f.trys.push([5, 7, , 8]);
1705
- return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMainDB().collection(this.versionCollection).bulkWrite(versionInserts)];
1706
- case 6:
1707
- _f.sent();
1708
- return [3 /*break*/, 8];
1709
- case 7:
1710
- _b = _f.sent();
1711
- return [3 /*break*/, 8];
1712
- case 8: return [3 /*break*/, 10];
1713
- case 9:
1714
- _c = _f.sent();
1715
- return [3 /*break*/, 10];
1716
- case 10:
1717
- monitor = monitor_manager_1.MonitorMongo.create('bulkWrite', this.collectionName, JSON.stringify([batchOps, safeOptions]));
1718
- _f.label = 11;
1719
- case 11:
1720
- _f.trys.push([11, 13, 14, 16]);
1721
- return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMainDB().collection(this.collectionName).bulkWrite(batchOps, options || undefined)];
1722
- case 12:
1723
- _f.sent();
1724
- return [3 /*break*/, 16];
1725
- case 13:
1726
- err_12 = _f.sent();
1727
- console.log(JSON.stringify([new Date(), 'Error Bulk Write', this.collectionName, operations, safeOptions, {
1728
- code: err_12.code,
1729
- codeName: err_12.codeName,
1730
- message: err_12.message,
1731
- stack: err_12.stack
1732
- }], null, 2));
1733
- err_12.message = "Error in Bulk Write: ".concat(this.collectionName, " => ").concat(err_12.codeName || 'NoCodeName', " => ").concat(err_12.message);
1734
- throw err_12;
1735
- case 14: return [4 /*yield*/, monitor.finish()];
1736
- case 15:
1737
- _f.sent();
1738
- return [7 /*endfinally*/];
1739
- case 16:
1740
- if (!(!bypassLogs && this.createLogs && logs.length > 0)) return [3 /*break*/, 19];
1741
- if (!resolveio_server_app_1.ResolveIOServer.shouldWriteLogsOffline()) return [3 /*break*/, 17];
1742
- resolveio_server_app_1.ResolveIOServer.getLocalLogManager().writeLogs(logs.map(function (a) {
1743
- return {
1744
- type: 'log',
1745
- data: a
1746
- };
1747
- }));
1748
- return [3 /*break*/, 19];
1749
- case 17:
1750
- bwOptions = null;
1751
- bwOptions = { session: session, ordered: false };
1752
- return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMainDB().collection('logs').bulkWrite(logs.map(function (a) {
1753
- a.client = 'ResolveIO';
1754
- a.instance = resolveio_server_app_1.ResolveIOServer.getInstanceHost();
1755
- return {
1756
- insertOne: {
1757
- document: a
1758
- }
1759
- };
1760
- }), bwOptions)];
1761
- case 18:
1762
- _f.sent();
1763
- _f.label = 19;
1764
- case 19:
1765
- if (!(!bypassVersions && this.useVersions)) return [3 /*break*/, 25];
1766
- _f.label = 20;
1767
- case 20:
1768
- _f.trys.push([20, 24, , 25]);
1769
- affectedDocIds = affectedDocs.map(function (doc) { return doc._id; });
1770
- pipeline = [
1771
- {
1772
- $match: { '_id._id': { $in: affectedDocIds } },
1773
- },
1774
- {
1775
- $sort: { '_id._id': 1, '_id.__v': -1 },
1776
- },
1777
- {
1778
- $group: {
1779
- _id: '$_id._id',
1780
- versions: { $push: '$_id' },
1781
- },
1782
- },
1783
- {
1784
- $project: {
1785
- versionsToDelete: { $slice: ['$versions', 5, { $size: '$versions' }] },
1786
- },
1787
- },
1788
- { $unwind: '$versionsToDelete' },
1789
- {
1790
- $replaceRoot: { newRoot: { _id: '$versionsToDelete' } },
1791
- },
1792
- ];
1793
- return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMainDB().collection(this.versionCollection).aggregate(pipeline).toArray()];
1794
- case 21:
1795
- oldVersions = _f.sent();
1796
- if (!(oldVersions.length > 0)) return [3 /*break*/, 23];
1797
- return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMainDB().collection(this.versionCollection).deleteMany({ _id: { $in: oldVersions.map(function (v) { return v._id; }) } })];
1798
- case 22:
1799
- _f.sent();
1800
- _f.label = 23;
1801
- case 23: return [3 /*break*/, 25];
1802
- case 24:
1803
- _d = _f.sent();
1804
- return [3 /*break*/, 25];
1805
- case 25:
1806
- opIndex += BATCH_SIZE;
1807
- // Yield to the event loop
1808
- // eslint-disable-next-line no-restricted-syntax
1809
- return [4 /*yield*/, new Promise(function (resolve) { return setImmediate(resolve); })];
1810
- case 26:
1811
- // Yield to the event loop
1812
- // eslint-disable-next-line no-restricted-syntax
1813
- _f.sent();
1814
- // Invalidate cache
1815
- if (!this.skipCache) {
1816
- resolveio_server_app_1.ResolveIOServer.getMongoManager().invalidateQueryCache(this.collectionName);
1817
- }
1920
+ _b.sent();
1818
1921
  return [3 /*break*/, 1];
1819
- case 27: return [2 /*return*/, { ok: 1 }]; // Adjust return value as per your requirements
1922
+ case 3: return [2 /*return*/, { ok: 1 }]; // Adjust return value as per your requirements
1820
1923
  }
1821
1924
  });
1822
1925
  });
1823
1926
  };
1824
1927
  MongoManagerCollection.prototype.countDocuments = function () {
1825
1928
  return __awaiter(this, arguments, void 0, function (filter, options, skipCache) {
1826
- var _a, session, safeOptions, isUnfiltered, monitor, res, err_13;
1929
+ var _a, session, safeOptions, isUnfiltered, monitor, res, err_14;
1827
1930
  if (filter === void 0) { filter = {}; }
1828
1931
  if (skipCache === void 0) { skipCache = false; }
1829
1932
  return __generator(this, function (_b) {
@@ -1848,15 +1951,15 @@ var MongoManagerCollection = /** @class */ (function () {
1848
1951
  res = _b.sent();
1849
1952
  return [2 /*return*/, res];
1850
1953
  case 5:
1851
- err_13 = _b.sent();
1954
+ err_14 = _b.sent();
1852
1955
  console.log(JSON.stringify([new Date(), 'Error Count Documents', this.collectionName, filter, safeOptions, {
1853
- code: err_13.code,
1854
- codeName: err_13.codeName,
1855
- message: err_13.message,
1856
- stack: err_13.stack
1956
+ code: err_14.code,
1957
+ codeName: err_14.codeName,
1958
+ message: err_14.message,
1959
+ stack: err_14.stack
1857
1960
  }], null, 2));
1858
- err_13.message = "Error in Count Documents: ".concat(this.collectionName, " => ").concat(err_13.codeName || 'NoCodeName', " => ").concat(err_13.message);
1859
- throw err_13;
1961
+ err_14.message = "Error in Count Documents: ".concat(this.collectionName, " => ").concat(err_14.codeName || 'NoCodeName', " => ").concat(err_14.message);
1962
+ throw err_14;
1860
1963
  case 6: return [4 /*yield*/, monitor.finish()];
1861
1964
  case 7:
1862
1965
  _b.sent();
@@ -1933,7 +2036,7 @@ var MongoManagerCollection = /** @class */ (function () {
1933
2036
  };
1934
2037
  MongoManagerCollection.prototype.deleteMany = function () {
1935
2038
  return __awaiter(this, arguments, void 0, function (filter, options, bypassLogs, bypassSession) {
1936
- var mongoSession, _a, session, safeOptions, docs, i, doc, versionDoc, _b, monitor, res, err_14;
2039
+ var mongoSession, _a, session, safeOptions, docs, i, doc, versionDoc, _b, monitor, res, err_15;
1937
2040
  if (filter === void 0) { filter = {}; }
1938
2041
  if (bypassLogs === void 0) { bypassLogs = false; }
1939
2042
  if (bypassSession === void 0) { bypassSession = false; }
@@ -2031,15 +2134,15 @@ var MongoManagerCollection = /** @class */ (function () {
2031
2134
  }
2032
2135
  return [2 /*return*/, res];
2033
2136
  case 14:
2034
- err_14 = _c.sent();
2137
+ err_15 = _c.sent();
2035
2138
  console.log(JSON.stringify([new Date(), 'Error Delete Many', this.collectionName, filter, safeOptions, {
2036
- code: err_14.code,
2037
- codeName: err_14.codeName,
2038
- message: err_14.message,
2039
- stack: err_14.stack
2139
+ code: err_15.code,
2140
+ codeName: err_15.codeName,
2141
+ message: err_15.message,
2142
+ stack: err_15.stack
2040
2143
  }], null, 2));
2041
- err_14.message = "Error in Delete Many: ".concat(this.collectionName, " => ").concat(err_14.codeName || 'NoCodeName', " => ").concat(err_14.message);
2042
- throw err_14;
2144
+ err_15.message = "Error in Delete Many: ".concat(this.collectionName, " => ").concat(err_15.codeName || 'NoCodeName', " => ").concat(err_15.message);
2145
+ throw err_15;
2043
2146
  case 15: return [4 /*yield*/, monitor.finish()];
2044
2147
  case 16:
2045
2148
  _c.sent();
@@ -2051,7 +2154,7 @@ var MongoManagerCollection = /** @class */ (function () {
2051
2154
  };
2052
2155
  MongoManagerCollection.prototype.deleteOne = function () {
2053
2156
  return __awaiter(this, arguments, void 0, function (filter, options, bypassLogs, bypassSession) {
2054
- var mongoSession, _a, session, safeOptions, monitor, res, doc, versionDoc, _b, err_15, monitor, res, err_16;
2157
+ var mongoSession, _a, session, safeOptions, monitor, res, doc, versionDoc, _b, err_16, monitor, res, err_17;
2055
2158
  if (filter === void 0) { filter = {}; }
2056
2159
  if (bypassLogs === void 0) { bypassLogs = false; }
2057
2160
  if (bypassSession === void 0) { bypassSession = false; }
@@ -2143,15 +2246,15 @@ var MongoManagerCollection = /** @class */ (function () {
2143
2246
  _c.label = 12;
2144
2247
  case 12: return [2 /*return*/, res];
2145
2248
  case 13:
2146
- err_15 = _c.sent();
2249
+ err_16 = _c.sent();
2147
2250
  console.log(JSON.stringify([new Date(), 'Error Delete One (Find One And Delete)', this.collectionName, filter, safeOptions, {
2148
- code: err_15.code,
2149
- codeName: err_15.codeName,
2150
- message: err_15.message,
2151
- stack: err_15.stack
2251
+ code: err_16.code,
2252
+ codeName: err_16.codeName,
2253
+ message: err_16.message,
2254
+ stack: err_16.stack
2152
2255
  }], null, 2));
2153
- err_15.message = "Error in Delete One (Find One And Delete): ".concat(this.collectionName, " => ").concat(err_15.codeName || 'NoCodeName', " => ").concat(err_15.message);
2154
- throw err_15;
2256
+ err_16.message = "Error in Delete One (Find One And Delete): ".concat(this.collectionName, " => ").concat(err_16.codeName || 'NoCodeName', " => ").concat(err_16.message);
2257
+ throw err_16;
2155
2258
  case 14: return [4 /*yield*/, monitor.finish()];
2156
2259
  case 15:
2157
2260
  _c.sent();
@@ -2170,15 +2273,15 @@ var MongoManagerCollection = /** @class */ (function () {
2170
2273
  }
2171
2274
  return [2 /*return*/, res];
2172
2275
  case 20:
2173
- err_16 = _c.sent();
2276
+ err_17 = _c.sent();
2174
2277
  console.log(JSON.stringify([new Date(), 'Error Delete One', this.collectionName, filter, safeOptions, {
2175
- code: err_16.code,
2176
- codeName: err_16.codeName,
2177
- message: err_16.message,
2178
- stack: err_16.stack
2278
+ code: err_17.code,
2279
+ codeName: err_17.codeName,
2280
+ message: err_17.message,
2281
+ stack: err_17.stack
2179
2282
  }], null, 2));
2180
- err_16.message = "Error in Delete One: ".concat(this.collectionName, " => ").concat(err_16.codeName || 'NoCodeName', " => ").concat(err_16.message);
2181
- throw err_16;
2283
+ err_17.message = "Error in Delete One: ".concat(this.collectionName, " => ").concat(err_17.codeName || 'NoCodeName', " => ").concat(err_17.message);
2284
+ throw err_17;
2182
2285
  case 21: return [4 /*yield*/, monitor.finish()];
2183
2286
  case 22:
2184
2287
  _c.sent();
@@ -2190,7 +2293,7 @@ var MongoManagerCollection = /** @class */ (function () {
2190
2293
  };
2191
2294
  MongoManagerCollection.prototype.distinct = function (key_1, filter_1, options_1) {
2192
2295
  return __awaiter(this, arguments, void 0, function (key, filter, options, bypassSession) {
2193
- var mongoSession, _a, session, safeOptions, monitor, res, err_17;
2296
+ var mongoSession, _a, session, safeOptions, monitor, res, err_18;
2194
2297
  if (bypassSession === void 0) { bypassSession = false; }
2195
2298
  return __generator(this, function (_b) {
2196
2299
  switch (_b.label) {
@@ -2216,15 +2319,15 @@ var MongoManagerCollection = /** @class */ (function () {
2216
2319
  res = _b.sent();
2217
2320
  return [2 /*return*/, res];
2218
2321
  case 3:
2219
- err_17 = _b.sent();
2322
+ err_18 = _b.sent();
2220
2323
  console.log(JSON.stringify([new Date(), 'Error Distinct', this.collectionName, filter, safeOptions, {
2221
- code: err_17.code,
2222
- codeName: err_17.codeName,
2223
- message: err_17.message,
2224
- stack: err_17.stack
2324
+ code: err_18.code,
2325
+ codeName: err_18.codeName,
2326
+ message: err_18.message,
2327
+ stack: err_18.stack
2225
2328
  }], null, 2));
2226
- err_17.message = "Error in Distinct: ".concat(this.collectionName, " => ").concat(err_17.codeName || 'NoCodeName', " => ").concat(err_17.message);
2227
- throw err_17;
2329
+ err_18.message = "Error in Distinct: ".concat(this.collectionName, " => ").concat(err_18.codeName || 'NoCodeName', " => ").concat(err_18.message);
2330
+ throw err_18;
2228
2331
  case 4: return [4 /*yield*/, monitor.finish()];
2229
2332
  case 5:
2230
2333
  _b.sent();
@@ -2236,7 +2339,7 @@ var MongoManagerCollection = /** @class */ (function () {
2236
2339
  };
2237
2340
  MongoManagerCollection.prototype.drop = function (options_1) {
2238
2341
  return __awaiter(this, arguments, void 0, function (options, bypassSession) {
2239
- var mongoSession, _a, session, safeOptions, monitor, res, err_18;
2342
+ var mongoSession, _a, session, safeOptions, monitor, res, err_19;
2240
2343
  if (bypassSession === void 0) { bypassSession = false; }
2241
2344
  return __generator(this, function (_b) {
2242
2345
  switch (_b.label) {
@@ -2262,15 +2365,15 @@ var MongoManagerCollection = /** @class */ (function () {
2262
2365
  res = _b.sent();
2263
2366
  return [2 /*return*/, res];
2264
2367
  case 3:
2265
- err_18 = _b.sent();
2368
+ err_19 = _b.sent();
2266
2369
  console.log(JSON.stringify([new Date(), 'Error Drop Collection', this.collectionName, safeOptions, {
2267
- code: err_18.code,
2268
- codeName: err_18.codeName,
2269
- message: err_18.message,
2270
- stack: err_18.stack
2370
+ code: err_19.code,
2371
+ codeName: err_19.codeName,
2372
+ message: err_19.message,
2373
+ stack: err_19.stack
2271
2374
  }], null, 2));
2272
- err_18.message = "Error in Drop Collection: ".concat(this.collectionName, " => ").concat(err_18.codeName || 'NoCodeName', " => ").concat(err_18.message);
2273
- throw err_18;
2375
+ err_19.message = "Error in Drop Collection: ".concat(this.collectionName, " => ").concat(err_19.codeName || 'NoCodeName', " => ").concat(err_19.message);
2376
+ throw err_19;
2274
2377
  case 4: return [4 /*yield*/, monitor.finish()];
2275
2378
  case 5:
2276
2379
  _b.sent();
@@ -2282,7 +2385,7 @@ var MongoManagerCollection = /** @class */ (function () {
2282
2385
  };
2283
2386
  MongoManagerCollection.prototype.dropIndex = function (indexName_1, options_1) {
2284
2387
  return __awaiter(this, arguments, void 0, function (indexName, options, bypassSession) {
2285
- var mongoSession, _a, session, safeOptions, monitor, res, err_19;
2388
+ var mongoSession, _a, session, safeOptions, monitor, res, err_20;
2286
2389
  if (bypassSession === void 0) { bypassSession = false; }
2287
2390
  return __generator(this, function (_b) {
2288
2391
  switch (_b.label) {
@@ -2308,15 +2411,15 @@ var MongoManagerCollection = /** @class */ (function () {
2308
2411
  res = _b.sent();
2309
2412
  return [2 /*return*/, res];
2310
2413
  case 3:
2311
- err_19 = _b.sent();
2414
+ err_20 = _b.sent();
2312
2415
  console.log(JSON.stringify([new Date(), 'Error Drop Index', this.collectionName, indexName, safeOptions, {
2313
- code: err_19.code,
2314
- codeName: err_19.codeName,
2315
- message: err_19.message,
2316
- stack: err_19.stack
2416
+ code: err_20.code,
2417
+ codeName: err_20.codeName,
2418
+ message: err_20.message,
2419
+ stack: err_20.stack
2317
2420
  }], null, 2));
2318
- err_19.message = "Error in Drop Index: ".concat(this.collectionName, " => ").concat(err_19.codeName || 'NoCodeName', " => ").concat(err_19.message);
2319
- throw err_19;
2421
+ err_20.message = "Error in Drop Index: ".concat(this.collectionName, " => ").concat(err_20.codeName || 'NoCodeName', " => ").concat(err_20.message);
2422
+ throw err_20;
2320
2423
  case 4: return [4 /*yield*/, monitor.finish()];
2321
2424
  case 5:
2322
2425
  _b.sent();
@@ -2328,7 +2431,7 @@ var MongoManagerCollection = /** @class */ (function () {
2328
2431
  };
2329
2432
  MongoManagerCollection.prototype.dropIndexes = function (options_1) {
2330
2433
  return __awaiter(this, arguments, void 0, function (options, bypassSession) {
2331
- var mongoSession, _a, session, safeOptions, monitor, res, err_20;
2434
+ var mongoSession, _a, session, safeOptions, monitor, res, err_21;
2332
2435
  if (bypassSession === void 0) { bypassSession = false; }
2333
2436
  return __generator(this, function (_b) {
2334
2437
  switch (_b.label) {
@@ -2354,15 +2457,15 @@ var MongoManagerCollection = /** @class */ (function () {
2354
2457
  res = _b.sent();
2355
2458
  return [2 /*return*/, res];
2356
2459
  case 3:
2357
- err_20 = _b.sent();
2460
+ err_21 = _b.sent();
2358
2461
  console.log(JSON.stringify([new Date(), 'Error Drop Indexes', this.collectionName, safeOptions, {
2359
- code: err_20.code,
2360
- codeName: err_20.codeName,
2361
- message: err_20.message,
2362
- stack: err_20.stack
2462
+ code: err_21.code,
2463
+ codeName: err_21.codeName,
2464
+ message: err_21.message,
2465
+ stack: err_21.stack
2363
2466
  }], null, 2));
2364
- err_20.message = "Error in Drop Indexes: ".concat(this.collectionName, " => ").concat(err_20.codeName || 'NoCodeName', " => ").concat(err_20.message);
2365
- throw err_20;
2467
+ err_21.message = "Error in Drop Indexes: ".concat(this.collectionName, " => ").concat(err_21.codeName || 'NoCodeName', " => ").concat(err_21.message);
2468
+ throw err_21;
2366
2469
  case 4: return [4 /*yield*/, monitor.finish()];
2367
2470
  case 5:
2368
2471
  _b.sent();
@@ -2374,7 +2477,7 @@ var MongoManagerCollection = /** @class */ (function () {
2374
2477
  };
2375
2478
  MongoManagerCollection.prototype.find = function () {
2376
2479
  return __awaiter(this, arguments, void 0, function (filter, options, skipCache, bypassSession) {
2377
- var mongoSession, _a, session, safeOptions, monitor, res, err_21;
2480
+ var mongoSession, _a, session, safeOptions, monitor, res, err_22;
2378
2481
  if (filter === void 0) { filter = {}; }
2379
2482
  if (skipCache === void 0) { skipCache = false; }
2380
2483
  if (bypassSession === void 0) { bypassSession = false; }
@@ -2406,15 +2509,15 @@ var MongoManagerCollection = /** @class */ (function () {
2406
2509
  (0, subscription_dependency_context_1.recordDependencyResult)(this.collectionName, res, { filter: filter, meta: buildQueryMetaFromFindOptions(safeOptions) });
2407
2510
  return [2 /*return*/, res];
2408
2511
  case 4:
2409
- err_21 = _b.sent();
2512
+ err_22 = _b.sent();
2410
2513
  console.log(JSON.stringify([new Date(), 'Error Find', this.collectionName, filter, safeOptions, {
2411
- code: err_21.code,
2412
- codeName: err_21.codeName,
2413
- message: err_21.message,
2414
- stack: err_21.stack
2514
+ code: err_22.code,
2515
+ codeName: err_22.codeName,
2516
+ message: err_22.message,
2517
+ stack: err_22.stack
2415
2518
  }], null, 2));
2416
- err_21.message = "Error in Find: ".concat(this.collectionName, " => ").concat(err_21.codeName || 'NoCodeName', " => ").concat(err_21.message);
2417
- throw err_21;
2519
+ err_22.message = "Error in Find: ".concat(this.collectionName, " => ").concat(err_22.codeName || 'NoCodeName', " => ").concat(err_22.message);
2520
+ throw err_22;
2418
2521
  case 5: return [4 /*yield*/, monitor.finish()];
2419
2522
  case 6:
2420
2523
  _b.sent();
@@ -2426,7 +2529,7 @@ var MongoManagerCollection = /** @class */ (function () {
2426
2529
  };
2427
2530
  MongoManagerCollection.prototype.findById = function (id_1, options_1) {
2428
2531
  return __awaiter(this, arguments, void 0, function (id, options, skipCache, bypassSession) {
2429
- var mongoSession, _a, session, safeOptions, monitor, res, err_22;
2532
+ var mongoSession, _a, session, safeOptions, monitor, res, err_23;
2430
2533
  if (skipCache === void 0) { skipCache = false; }
2431
2534
  if (bypassSession === void 0) { bypassSession = false; }
2432
2535
  return __generator(this, function (_b) {
@@ -2457,15 +2560,15 @@ var MongoManagerCollection = /** @class */ (function () {
2457
2560
  (0, subscription_dependency_context_1.recordDependencyResult)(this.collectionName, res, { filter: { _id: id }, meta: buildQueryMetaFromFindOptions(safeOptions) });
2458
2561
  return [2 /*return*/, res];
2459
2562
  case 4:
2460
- err_22 = _b.sent();
2563
+ err_23 = _b.sent();
2461
2564
  console.log(JSON.stringify([new Date(), 'Error Find By ID', this.collectionName, id, safeOptions, {
2462
- code: err_22.code,
2463
- codeName: err_22.codeName,
2464
- message: err_22.message,
2465
- stack: err_22.stack
2565
+ code: err_23.code,
2566
+ codeName: err_23.codeName,
2567
+ message: err_23.message,
2568
+ stack: err_23.stack
2466
2569
  }], null, 2));
2467
- err_22.message = "Error in Find By ID: ".concat(this.collectionName, " => ").concat(err_22.codeName || 'NoCodeName', " => ").concat(err_22.message);
2468
- throw err_22;
2570
+ err_23.message = "Error in Find By ID: ".concat(this.collectionName, " => ").concat(err_23.codeName || 'NoCodeName', " => ").concat(err_23.message);
2571
+ throw err_23;
2469
2572
  case 5: return [4 /*yield*/, monitor.finish()];
2470
2573
  case 6:
2471
2574
  _b.sent();
@@ -2477,7 +2580,7 @@ var MongoManagerCollection = /** @class */ (function () {
2477
2580
  };
2478
2581
  MongoManagerCollection.prototype.findCount = function () {
2479
2582
  return __awaiter(this, arguments, void 0, function (filter, options, bypassSession) {
2480
- var mongoSession, _a, session, safeOptions, monitor, res, err_23;
2583
+ var mongoSession, _a, session, safeOptions, monitor, res, err_24;
2481
2584
  if (filter === void 0) { filter = {}; }
2482
2585
  if (bypassSession === void 0) { bypassSession = false; }
2483
2586
  return __generator(this, function (_b) {
@@ -2505,15 +2608,15 @@ var MongoManagerCollection = /** @class */ (function () {
2505
2608
  (0, subscription_dependency_context_1.recordDependencyResult)(this.collectionName, res, { filter: filter });
2506
2609
  return [2 /*return*/, res];
2507
2610
  case 3:
2508
- err_23 = _b.sent();
2611
+ err_24 = _b.sent();
2509
2612
  console.log(JSON.stringify([new Date(), 'Error Find Count', this.collectionName, filter, safeOptions, {
2510
- code: err_23.code,
2511
- codeName: err_23.codeName,
2512
- message: err_23.message,
2513
- stack: err_23.stack
2613
+ code: err_24.code,
2614
+ codeName: err_24.codeName,
2615
+ message: err_24.message,
2616
+ stack: err_24.stack
2514
2617
  }], null, 2));
2515
- err_23.message = "Error in Find Count: ".concat(this.collectionName, " => ").concat(err_23.codeName || 'NoCodeName', " => ").concat(err_23.message);
2516
- throw err_23;
2618
+ err_24.message = "Error in Find Count: ".concat(this.collectionName, " => ").concat(err_24.codeName || 'NoCodeName', " => ").concat(err_24.message);
2619
+ throw err_24;
2517
2620
  case 4: return [4 /*yield*/, monitor.finish()];
2518
2621
  case 5:
2519
2622
  _b.sent();
@@ -2583,7 +2686,7 @@ var MongoManagerCollection = /** @class */ (function () {
2583
2686
  };
2584
2687
  MongoManagerCollection.prototype.findOne = function () {
2585
2688
  return __awaiter(this, arguments, void 0, function (filter, options, skipCache, bypassSession) {
2586
- var mongoSession, _a, session, safeOptions, monitor, res, err_24;
2689
+ var mongoSession, _a, session, safeOptions, monitor, res, err_25;
2587
2690
  if (filter === void 0) { filter = {}; }
2588
2691
  if (skipCache === void 0) { skipCache = false; }
2589
2692
  if (bypassSession === void 0) { bypassSession = false; }
@@ -2615,15 +2718,15 @@ var MongoManagerCollection = /** @class */ (function () {
2615
2718
  (0, subscription_dependency_context_1.recordDependencyResult)(this.collectionName, res, { filter: filter });
2616
2719
  return [2 /*return*/, res];
2617
2720
  case 4:
2618
- err_24 = _b.sent();
2721
+ err_25 = _b.sent();
2619
2722
  console.log(JSON.stringify([new Date(), 'Error Find One', this.collectionName, filter, safeOptions, {
2620
- code: err_24.code,
2621
- codeName: err_24.codeName,
2622
- message: err_24.message,
2623
- stack: err_24.stack
2723
+ code: err_25.code,
2724
+ codeName: err_25.codeName,
2725
+ message: err_25.message,
2726
+ stack: err_25.stack
2624
2727
  }], null, 2));
2625
- err_24.message = "Error in Find One: ".concat(this.collectionName, " => ").concat(err_24.codeName || 'NoCodeName', " => ").concat(err_24.message);
2626
- throw err_24;
2728
+ err_25.message = "Error in Find One: ".concat(this.collectionName, " => ").concat(err_25.codeName || 'NoCodeName', " => ").concat(err_25.message);
2729
+ throw err_25;
2627
2730
  case 5: return [4 /*yield*/, monitor.finish()];
2628
2731
  case 6:
2629
2732
  _b.sent();
@@ -2635,7 +2738,7 @@ var MongoManagerCollection = /** @class */ (function () {
2635
2738
  };
2636
2739
  MongoManagerCollection.prototype.findOneAndDelete = function () {
2637
2740
  return __awaiter(this, arguments, void 0, function (filter, options, bypassLogs, bypassSession) {
2638
- var mongoSession, _a, session, safeOptions, monitor, doc, versionDoc, _b, err_25;
2741
+ var mongoSession, _a, session, safeOptions, monitor, doc, versionDoc, _b, err_26;
2639
2742
  if (filter === void 0) { filter = {}; }
2640
2743
  if (bypassLogs === void 0) { bypassLogs = false; }
2641
2744
  if (bypassSession === void 0) { bypassSession = false; }
@@ -2721,15 +2824,15 @@ var MongoManagerCollection = /** @class */ (function () {
2721
2824
  case 10: return [2 /*return*/, null];
2722
2825
  case 11: return [3 /*break*/, 15];
2723
2826
  case 12:
2724
- err_25 = _c.sent();
2827
+ err_26 = _c.sent();
2725
2828
  console.log(JSON.stringify([new Date(), 'Error Find One And Delete', this.collectionName, filter, safeOptions, {
2726
- code: err_25.code,
2727
- codeName: err_25.codeName,
2728
- message: err_25.message,
2729
- stack: err_25.stack
2829
+ code: err_26.code,
2830
+ codeName: err_26.codeName,
2831
+ message: err_26.message,
2832
+ stack: err_26.stack
2730
2833
  }], null, 2));
2731
- err_25.message = "Error in Find One And Delete: ".concat(this.collectionName, " => ").concat(err_25.codeName || 'NoCodeName', " => ").concat(err_25.message);
2732
- throw err_25;
2834
+ err_26.message = "Error in Find One And Delete: ".concat(this.collectionName, " => ").concat(err_26.codeName || 'NoCodeName', " => ").concat(err_26.message);
2835
+ throw err_26;
2733
2836
  case 13: return [4 /*yield*/, monitor.finish()];
2734
2837
  case 14:
2735
2838
  _c.sent();
@@ -2741,7 +2844,7 @@ var MongoManagerCollection = /** @class */ (function () {
2741
2844
  };
2742
2845
  MongoManagerCollection.prototype.findOneAndReplace = function () {
2743
2846
  return __awaiter(this, arguments, void 0, function (filter, replacement, options, bypassLogs, bypassCheckSchema, bypassSession) {
2744
- var validation, isValid, date, mongoSession, _a, session, safeOptions, monitor, doc, versionDoc, _b, err_26;
2847
+ var validation, isValid, date, mongoSession, _a, session, safeOptions, monitor, doc, versionDoc, _b, err_27;
2745
2848
  if (filter === void 0) { filter = {}; }
2746
2849
  if (bypassLogs === void 0) { bypassLogs = false; }
2747
2850
  if (bypassCheckSchema === void 0) { bypassCheckSchema = false; }
@@ -2853,15 +2956,15 @@ var MongoManagerCollection = /** @class */ (function () {
2853
2956
  case 12: return [2 /*return*/, null];
2854
2957
  case 13: return [3 /*break*/, 17];
2855
2958
  case 14:
2856
- err_26 = _c.sent();
2959
+ err_27 = _c.sent();
2857
2960
  console.log(JSON.stringify([new Date(), 'Error Find One And Replace', this.collectionName, filter, safeOptions, {
2858
- code: err_26.code,
2859
- codeName: err_26.codeName,
2860
- message: err_26.message,
2861
- stack: err_26.stack
2961
+ code: err_27.code,
2962
+ codeName: err_27.codeName,
2963
+ message: err_27.message,
2964
+ stack: err_27.stack
2862
2965
  }], null, 2));
2863
- err_26.message = "Error in Find One And Replace: ".concat(this.collectionName, " => ").concat(err_26.codeName || 'NoCodeName', " => ").concat(err_26.message);
2864
- throw err_26;
2966
+ err_27.message = "Error in Find One And Replace: ".concat(this.collectionName, " => ").concat(err_27.codeName || 'NoCodeName', " => ").concat(err_27.message);
2967
+ throw err_27;
2865
2968
  case 15: return [4 /*yield*/, monitor.finish()];
2866
2969
  case 16:
2867
2970
  _c.sent();
@@ -2873,7 +2976,7 @@ var MongoManagerCollection = /** @class */ (function () {
2873
2976
  };
2874
2977
  MongoManagerCollection.prototype.findOneAndUpdate = function () {
2875
2978
  return __awaiter(this, arguments, void 0, function (filter, update, options, bypassLogs, bypassCheckSchema, bypassSession) {
2876
- var validation, isValid, date, mongoSession, _a, session, safeOptions, monitor, doc, versionDoc, _b, err_27;
2979
+ var validation, isValid, date, mongoSession, _a, session, safeOptions, monitor, doc, versionDoc, _b, err_28;
2877
2980
  if (filter === void 0) { filter = {}; }
2878
2981
  if (bypassLogs === void 0) { bypassLogs = false; }
2879
2982
  if (bypassCheckSchema === void 0) { bypassCheckSchema = false; }
@@ -3002,15 +3105,15 @@ var MongoManagerCollection = /** @class */ (function () {
3002
3105
  case 12: return [2 /*return*/, null];
3003
3106
  case 13: return [3 /*break*/, 17];
3004
3107
  case 14:
3005
- err_27 = _c.sent();
3108
+ err_28 = _c.sent();
3006
3109
  console.log(JSON.stringify([new Date(), 'Error Find One And Update', this.collectionName, filter, safeOptions, {
3007
- code: err_27.code,
3008
- codeName: err_27.codeName,
3009
- message: err_27.message,
3010
- stack: err_27.stack
3110
+ code: err_28.code,
3111
+ codeName: err_28.codeName,
3112
+ message: err_28.message,
3113
+ stack: err_28.stack
3011
3114
  }], null, 2));
3012
- err_27.message = "Error in Find One And Update: ".concat(this.collectionName, " => ").concat(err_27.codeName || 'NoCodeName', " => ").concat(err_27.message);
3013
- throw err_27;
3115
+ err_28.message = "Error in Find One And Update: ".concat(this.collectionName, " => ").concat(err_28.codeName || 'NoCodeName', " => ").concat(err_28.message);
3116
+ throw err_28;
3014
3117
  case 15: return [4 /*yield*/, monitor.finish()];
3015
3118
  case 16:
3016
3119
  _c.sent();
@@ -3022,7 +3125,7 @@ var MongoManagerCollection = /** @class */ (function () {
3022
3125
  };
3023
3126
  MongoManagerCollection.prototype.indexes = function (options) {
3024
3127
  return __awaiter(this, void 0, void 0, function () {
3025
- var _a, session, safeOptions, monitor, res, err_28;
3128
+ var _a, session, safeOptions, monitor, res, err_29;
3026
3129
  return __generator(this, function (_b) {
3027
3130
  switch (_b.label) {
3028
3131
  case 0:
@@ -3036,15 +3139,15 @@ var MongoManagerCollection = /** @class */ (function () {
3036
3139
  res = _b.sent();
3037
3140
  return [2 /*return*/, res];
3038
3141
  case 3:
3039
- err_28 = _b.sent();
3142
+ err_29 = _b.sent();
3040
3143
  console.log(JSON.stringify([new Date(), 'Error Indexes', this.collectionName, safeOptions, {
3041
- code: err_28.code,
3042
- codeName: err_28.codeName,
3043
- message: err_28.message,
3044
- stack: err_28.stack
3144
+ code: err_29.code,
3145
+ codeName: err_29.codeName,
3146
+ message: err_29.message,
3147
+ stack: err_29.stack
3045
3148
  }], null, 2));
3046
- err_28.message = "Error in Indexes: ".concat(this.collectionName, " => ").concat(err_28.codeName || 'NoCodeName', " => ").concat(err_28.message);
3047
- throw err_28;
3149
+ err_29.message = "Error in Indexes: ".concat(this.collectionName, " => ").concat(err_29.codeName || 'NoCodeName', " => ").concat(err_29.message);
3150
+ throw err_29;
3048
3151
  case 4: return [4 /*yield*/, monitor.finish()];
3049
3152
  case 5:
3050
3153
  _b.sent();
@@ -3056,7 +3159,7 @@ var MongoManagerCollection = /** @class */ (function () {
3056
3159
  };
3057
3160
  MongoManagerCollection.prototype.indexExists = function (indexes, options) {
3058
3161
  return __awaiter(this, void 0, void 0, function () {
3059
- var _a, session, safeOptions, monitor, res, err_29;
3162
+ var _a, session, safeOptions, monitor, res, err_30;
3060
3163
  return __generator(this, function (_b) {
3061
3164
  switch (_b.label) {
3062
3165
  case 0:
@@ -3070,15 +3173,15 @@ var MongoManagerCollection = /** @class */ (function () {
3070
3173
  res = _b.sent();
3071
3174
  return [2 /*return*/, res];
3072
3175
  case 3:
3073
- err_29 = _b.sent();
3176
+ err_30 = _b.sent();
3074
3177
  console.log(JSON.stringify([new Date(), 'Error Index Exists', this.collectionName, indexes, safeOptions, {
3075
- code: err_29.code,
3076
- codeName: err_29.codeName,
3077
- message: err_29.message,
3078
- stack: err_29.stack
3178
+ code: err_30.code,
3179
+ codeName: err_30.codeName,
3180
+ message: err_30.message,
3181
+ stack: err_30.stack
3079
3182
  }], null, 2));
3080
- err_29.message = "Error in Index Exists: ".concat(this.collectionName, " => ").concat(err_29.codeName || 'NoCodeName', " => ").concat(err_29.message);
3081
- throw err_29;
3183
+ err_30.message = "Error in Index Exists: ".concat(this.collectionName, " => ").concat(err_30.codeName || 'NoCodeName', " => ").concat(err_30.message);
3184
+ throw err_30;
3082
3185
  case 4: return [4 /*yield*/, monitor.finish()];
3083
3186
  case 5:
3084
3187
  _b.sent();
@@ -3090,7 +3193,7 @@ var MongoManagerCollection = /** @class */ (function () {
3090
3193
  };
3091
3194
  MongoManagerCollection.prototype.insertMany = function (docs_1, options_1) {
3092
3195
  return __awaiter(this, arguments, void 0, function (docs, options, bypassLogs, bypassCheckSchema, bypassMonitor, bypassSession) {
3093
- var validationResults, docs_2, docs_2_1, doc, validation, isValid, e_7_1, validDocs, mongoSession, _a, session, safeOptions, i, doc, date, monitor, err_30;
3196
+ var validationResults, docs_2, docs_2_1, doc, validation, isValid, e_7_1, validDocs, mongoSession, _a, session, safeOptions, i, doc, date, monitor, err_31;
3094
3197
  var e_7, _b;
3095
3198
  var _this = this;
3096
3199
  if (bypassLogs === void 0) { bypassLogs = false; }
@@ -3230,15 +3333,15 @@ var MongoManagerCollection = /** @class */ (function () {
3230
3333
  }
3231
3334
  return [2 /*return*/, validDocs];
3232
3335
  case 17:
3233
- err_30 = _c.sent();
3336
+ err_31 = _c.sent();
3234
3337
  console.log(JSON.stringify([new Date(), 'Error Insert Many', this.collectionName, docs, safeOptions, {
3235
- code: err_30.code,
3236
- codeName: err_30.codeName,
3237
- message: err_30.message,
3238
- stack: err_30.stack
3338
+ code: err_31.code,
3339
+ codeName: err_31.codeName,
3340
+ message: err_31.message,
3341
+ stack: err_31.stack
3239
3342
  }], null, 2));
3240
- err_30.message = "Error in Insert Many: ".concat(this.collectionName, " => ").concat(err_30.codeName || 'NoCodeName', " => ").concat(err_30.message);
3241
- throw err_30;
3343
+ err_31.message = "Error in Insert Many: ".concat(this.collectionName, " => ").concat(err_31.codeName || 'NoCodeName', " => ").concat(err_31.message);
3344
+ throw err_31;
3242
3345
  case 18:
3243
3346
  if (monitor) {
3244
3347
  monitor.finish();
@@ -3251,7 +3354,7 @@ var MongoManagerCollection = /** @class */ (function () {
3251
3354
  };
3252
3355
  MongoManagerCollection.prototype.insertOne = function (doc_1, options_1) {
3253
3356
  return __awaiter(this, arguments, void 0, function (doc, options, bypassLogs, bypassCheckSchema, bypassSession) {
3254
- var validation, isValid, date, mongoSession, _a, session, safeOptions, monitor, err_31;
3357
+ var validation, isValid, date, mongoSession, _a, session, safeOptions, monitor, err_32;
3255
3358
  var _this = this;
3256
3359
  if (bypassLogs === void 0) { bypassLogs = false; }
3257
3360
  if (bypassCheckSchema === void 0) { bypassCheckSchema = false; }
@@ -3346,15 +3449,15 @@ var MongoManagerCollection = /** @class */ (function () {
3346
3449
  }
3347
3450
  return [2 /*return*/, doc];
3348
3451
  case 8:
3349
- err_31 = _b.sent();
3452
+ err_32 = _b.sent();
3350
3453
  console.log(JSON.stringify([new Date(), 'Error Insert One', this.collectionName, doc, safeOptions, {
3351
- code: err_31.code,
3352
- codeName: err_31.codeName,
3353
- message: err_31.message,
3354
- stack: err_31.stack
3454
+ code: err_32.code,
3455
+ codeName: err_32.codeName,
3456
+ message: err_32.message,
3457
+ stack: err_32.stack
3355
3458
  }], null, 2));
3356
- err_31.message = "Error in Insert One: ".concat(this.collectionName, " => ").concat(err_31.codeName || 'NoCodeName', " => ").concat(err_31.message);
3357
- throw err_31;
3459
+ err_32.message = "Error in Insert One: ".concat(this.collectionName, " => ").concat(err_32.codeName || 'NoCodeName', " => ").concat(err_32.message);
3460
+ throw err_32;
3358
3461
  case 9: return [4 /*yield*/, monitor.finish()];
3359
3462
  case 10:
3360
3463
  _b.sent();
@@ -3394,7 +3497,7 @@ var MongoManagerCollection = /** @class */ (function () {
3394
3497
  };
3395
3498
  MongoManagerCollection.prototype.rename = function (newName_1, options_1) {
3396
3499
  return __awaiter(this, arguments, void 0, function (newName, options, bypassSession) {
3397
- var mongoSession, _a, session, safeOptions, monitor, res, err_32;
3500
+ var mongoSession, _a, session, safeOptions, monitor, res, err_33;
3398
3501
  if (bypassSession === void 0) { bypassSession = false; }
3399
3502
  return __generator(this, function (_b) {
3400
3503
  switch (_b.label) {
@@ -3420,15 +3523,15 @@ var MongoManagerCollection = /** @class */ (function () {
3420
3523
  res = _b.sent();
3421
3524
  return [2 /*return*/, res];
3422
3525
  case 3:
3423
- err_32 = _b.sent();
3526
+ err_33 = _b.sent();
3424
3527
  console.log(JSON.stringify([new Date(), 'Error Rename', this.collectionName, newName, safeOptions, {
3425
- code: err_32.code,
3426
- codeName: err_32.codeName,
3427
- message: err_32.message,
3428
- stack: err_32.stack
3528
+ code: err_33.code,
3529
+ codeName: err_33.codeName,
3530
+ message: err_33.message,
3531
+ stack: err_33.stack
3429
3532
  }], null, 2));
3430
- err_32.message = "Error in Rename: ".concat(this.collectionName, " => ").concat(err_32.codeName || 'NoCodeName', " => ").concat(err_32.message);
3431
- throw err_32;
3533
+ err_33.message = "Error in Rename: ".concat(this.collectionName, " => ").concat(err_33.codeName || 'NoCodeName', " => ").concat(err_33.message);
3534
+ throw err_33;
3432
3535
  case 4: return [4 /*yield*/, monitor.finish()];
3433
3536
  case 5:
3434
3537
  _b.sent();
@@ -3440,7 +3543,7 @@ var MongoManagerCollection = /** @class */ (function () {
3440
3543
  };
3441
3544
  MongoManagerCollection.prototype.replaceOne = function (filter_1, replacement_1, options_1) {
3442
3545
  return __awaiter(this, arguments, void 0, function (filter, replacement, options, bypassLogs, bypassCheckSchema, doc, bypassSession) {
3443
- var validation, isValid, date, mongoSession, _a, session, safeOptions, versionDoc, _b, monitor, res, err_33, prevDoc, docId, docVersion, updatedDoc_1, monitor, res, err_34, monitor, res, err_35, _c, session_1, safeOptions_1, monitor, res, doc_1, err_36, monitor, res, err_37;
3546
+ var validation, isValid, date, mongoSession, _a, session, safeOptions, versionDoc, _b, monitor, res, err_34, prevDoc, docId, docVersion, updatedDoc_1, monitor, res, err_35, monitor, res, err_36, _c, session_1, safeOptions_1, monitor, res, doc_1, err_37, monitor, res, err_38;
3444
3547
  var _this = this;
3445
3548
  if (bypassLogs === void 0) { bypassLogs = false; }
3446
3549
  if (bypassCheckSchema === void 0) { bypassCheckSchema = false; }
@@ -3560,15 +3663,15 @@ var MongoManagerCollection = /** @class */ (function () {
3560
3663
  }
3561
3664
  return [2 /*return*/, res];
3562
3665
  case 16:
3563
- err_33 = _d.sent();
3666
+ err_34 = _d.sent();
3564
3667
  console.log(JSON.stringify([new Date(), 'Error Replace One', this.collectionName, filter, replacement, safeOptions, {
3565
- code: err_33.code,
3566
- codeName: err_33.codeName,
3567
- message: err_33.message,
3568
- stack: err_33.stack
3668
+ code: err_34.code,
3669
+ codeName: err_34.codeName,
3670
+ message: err_34.message,
3671
+ stack: err_34.stack
3569
3672
  }], null, 2));
3570
- err_33.message = "Error in Replace One: ".concat(this.collectionName, " => ").concat(err_33.codeName || 'NoCodeName', " => ").concat(err_33.message);
3571
- throw err_33;
3673
+ err_34.message = "Error in Replace One: ".concat(this.collectionName, " => ").concat(err_34.codeName || 'NoCodeName', " => ").concat(err_34.message);
3674
+ throw err_34;
3572
3675
  case 17: return [4 /*yield*/, monitor.finish()];
3573
3676
  case 18:
3574
3677
  _d.sent();
@@ -3642,15 +3745,15 @@ var MongoManagerCollection = /** @class */ (function () {
3642
3745
  }
3643
3746
  return [2 /*return*/, res];
3644
3747
  case 27:
3645
- err_34 = _d.sent();
3748
+ err_35 = _d.sent();
3646
3749
  console.log(JSON.stringify([new Date(), 'Error Replace One', this.collectionName, filter, replacement, safeOptions, {
3647
- code: err_34.code,
3648
- codeName: err_34.codeName,
3649
- message: err_34.message,
3650
- stack: err_34.stack
3750
+ code: err_35.code,
3751
+ codeName: err_35.codeName,
3752
+ message: err_35.message,
3753
+ stack: err_35.stack
3651
3754
  }], null, 2));
3652
- err_34.message = "Error in Replace One: ".concat(this.collectionName, " => ").concat(err_34.codeName || 'NoCodeName', " => ").concat(err_34.message);
3653
- throw err_34;
3755
+ err_35.message = "Error in Replace One: ".concat(this.collectionName, " => ").concat(err_35.codeName || 'NoCodeName', " => ").concat(err_35.message);
3756
+ throw err_35;
3654
3757
  case 28: return [4 /*yield*/, monitor.finish()];
3655
3758
  case 29:
3656
3759
  _d.sent();
@@ -3719,15 +3822,15 @@ var MongoManagerCollection = /** @class */ (function () {
3719
3822
  }
3720
3823
  return [2 /*return*/, res];
3721
3824
  case 39:
3722
- err_35 = _d.sent();
3825
+ err_36 = _d.sent();
3723
3826
  console.log(JSON.stringify([new Date(), 'Error Replace One', this.collectionName, filter, replacement, safeOptions, {
3724
- code: err_35.code,
3725
- codeName: err_35.codeName,
3726
- message: err_35.message,
3727
- stack: err_35.stack
3827
+ code: err_36.code,
3828
+ codeName: err_36.codeName,
3829
+ message: err_36.message,
3830
+ stack: err_36.stack
3728
3831
  }], null, 2));
3729
- err_35.message = "Error in Replace One: ".concat(this.collectionName, " => ").concat(err_35.codeName || 'NoCodeName', " => ").concat(err_35.message);
3730
- throw err_35;
3832
+ err_36.message = "Error in Replace One: ".concat(this.collectionName, " => ").concat(err_36.codeName || 'NoCodeName', " => ").concat(err_36.message);
3833
+ throw err_36;
3731
3834
  case 40: return [4 /*yield*/, monitor.finish()];
3732
3835
  case 41:
3733
3836
  _d.sent();
@@ -3854,15 +3957,15 @@ var MongoManagerCollection = /** @class */ (function () {
3854
3957
  }
3855
3958
  return [2 /*return*/, res];
3856
3959
  case 56:
3857
- err_36 = _d.sent();
3960
+ err_37 = _d.sent();
3858
3961
  console.log(JSON.stringify([new Date(), 'Error Replace One (Find One And Replace)', this.collectionName, filter, safeOptions_1, {
3859
- code: err_36.code,
3860
- codeName: err_36.codeName,
3861
- message: err_36.message,
3862
- stack: err_36.stack
3962
+ code: err_37.code,
3963
+ codeName: err_37.codeName,
3964
+ message: err_37.message,
3965
+ stack: err_37.stack
3863
3966
  }], null, 2));
3864
- err_36.message = "Error in Replace One (Find One And Replace): ".concat(this.collectionName, " => ").concat(err_36.codeName || 'NoCodeName', " => ").concat(err_36.message);
3865
- throw err_36;
3967
+ err_37.message = "Error in Replace One (Find One And Replace): ".concat(this.collectionName, " => ").concat(err_37.codeName || 'NoCodeName', " => ").concat(err_37.message);
3968
+ throw err_37;
3866
3969
  case 57: return [4 /*yield*/, monitor.finish()];
3867
3970
  case 58:
3868
3971
  _d.sent();
@@ -3881,15 +3984,15 @@ var MongoManagerCollection = /** @class */ (function () {
3881
3984
  }
3882
3985
  return [2 /*return*/, res];
3883
3986
  case 63:
3884
- err_37 = _d.sent();
3987
+ err_38 = _d.sent();
3885
3988
  console.log(JSON.stringify([new Date(), 'Error Replace One', this.collectionName, filter, replacement, safeOptions, {
3886
- code: err_37.code,
3887
- codeName: err_37.codeName,
3888
- message: err_37.message,
3889
- stack: err_37.stack
3989
+ code: err_38.code,
3990
+ codeName: err_38.codeName,
3991
+ message: err_38.message,
3992
+ stack: err_38.stack
3890
3993
  }], null, 2));
3891
- err_37.message = "Error in Replace One: ".concat(this.collectionName, " => ").concat(err_37.codeName || 'NoCodeName', " => ").concat(err_37.message);
3892
- throw err_37;
3994
+ err_38.message = "Error in Replace One: ".concat(this.collectionName, " => ").concat(err_38.codeName || 'NoCodeName', " => ").concat(err_38.message);
3995
+ throw err_38;
3893
3996
  case 64: return [4 /*yield*/, monitor.finish()];
3894
3997
  case 65:
3895
3998
  _d.sent();
@@ -3901,7 +4004,7 @@ var MongoManagerCollection = /** @class */ (function () {
3901
4004
  };
3902
4005
  MongoManagerCollection.prototype.updateMany = function (filter_1, update_1, options_1) {
3903
4006
  return __awaiter(this, arguments, void 0, function (filter, update, options, bypassLogs, bypassCheckSchema, bypassVersions, bypassSession) {
3904
- var isEmptyUpdate, allEmpty, date, validation, isValid, mongoSession, _a, session, safeOptions, docs, i, doc, versionDoc, _b, monitor, res, err_38;
4007
+ var isEmptyUpdate, allEmpty, date, validation, isValid, mongoSession, _a, session, safeOptions, docs, i, doc, versionDoc, _b, monitor, res, err_39;
3905
4008
  var _this = this;
3906
4009
  if (bypassLogs === void 0) { bypassLogs = false; }
3907
4010
  if (bypassCheckSchema === void 0) { bypassCheckSchema = false; }
@@ -4059,15 +4162,15 @@ var MongoManagerCollection = /** @class */ (function () {
4059
4162
  }
4060
4163
  return [2 /*return*/, res];
4061
4164
  case 18:
4062
- err_38 = _c.sent();
4165
+ err_39 = _c.sent();
4063
4166
  console.log(JSON.stringify([new Date(), 'Error Update Many', this.collectionName, filter, update, safeOptions, {
4064
- code: err_38.code,
4065
- codeName: err_38.codeName,
4066
- message: err_38.message,
4067
- stack: err_38.stack
4167
+ code: err_39.code,
4168
+ codeName: err_39.codeName,
4169
+ message: err_39.message,
4170
+ stack: err_39.stack
4068
4171
  }], null, 2));
4069
- err_38.message = "Error in Update Many: ".concat(this.collectionName, " => ").concat(err_38.codeName || 'NoCodeName', " => ").concat(err_38.message);
4070
- throw err_38;
4172
+ err_39.message = "Error in Update Many: ".concat(this.collectionName, " => ").concat(err_39.codeName || 'NoCodeName', " => ").concat(err_39.message);
4173
+ throw err_39;
4071
4174
  case 19: return [4 /*yield*/, monitor.finish()];
4072
4175
  case 20:
4073
4176
  _c.sent();
@@ -4079,7 +4182,7 @@ var MongoManagerCollection = /** @class */ (function () {
4079
4182
  };
4080
4183
  MongoManagerCollection.prototype.updateOne = function (filter_1, update_1, options_1) {
4081
4184
  return __awaiter(this, arguments, void 0, function (filter, update, options, bypassLogs, bypassCheckSchema, bypassSession) {
4082
- var validation, isValid, isEmptyUpdate, allEmpty, date, mongoSession, _a, session, safeOptions, doc, versionDoc, _b, monitor, res, err_39, monitor, res, err_40, monitor, res, doc, err_41, monitor, res, err_42;
4185
+ var validation, isValid, isEmptyUpdate, allEmpty, date, mongoSession, _a, session, safeOptions, doc, versionDoc, _b, monitor, res, err_40, monitor, res, err_41, monitor, res, doc, err_42, monitor, res, err_43;
4083
4186
  var _this = this;
4084
4187
  if (bypassLogs === void 0) { bypassLogs = false; }
4085
4188
  if (bypassCheckSchema === void 0) { bypassCheckSchema = false; }
@@ -4228,15 +4331,15 @@ var MongoManagerCollection = /** @class */ (function () {
4228
4331
  }
4229
4332
  return [2 /*return*/, res];
4230
4333
  case 14:
4231
- err_39 = _c.sent();
4334
+ err_40 = _c.sent();
4232
4335
  console.log(JSON.stringify([new Date(), 'Error Update One', this.collectionName, filter, update, safeOptions, {
4233
- code: err_39.code,
4234
- codeName: err_39.codeName,
4235
- message: err_39.message,
4236
- stack: err_39.stack
4336
+ code: err_40.code,
4337
+ codeName: err_40.codeName,
4338
+ message: err_40.message,
4339
+ stack: err_40.stack
4237
4340
  }], null, 2));
4238
- err_39.message = "Error in Update One: ".concat(this.collectionName, " => ").concat(err_39.codeName || 'NoCodeName', " => ").concat(err_39.message);
4239
- throw err_39;
4341
+ err_40.message = "Error in Update One: ".concat(this.collectionName, " => ").concat(err_40.codeName || 'NoCodeName', " => ").concat(err_40.message);
4342
+ throw err_40;
4240
4343
  case 15: return [4 /*yield*/, monitor.finish()];
4241
4344
  case 16:
4242
4345
  _c.sent();
@@ -4319,15 +4422,15 @@ var MongoManagerCollection = /** @class */ (function () {
4319
4422
  }
4320
4423
  return [2 /*return*/, res];
4321
4424
  case 24:
4322
- err_40 = _c.sent();
4425
+ err_41 = _c.sent();
4323
4426
  console.log(JSON.stringify([new Date(), 'Error Update One', this.collectionName, filter, safeOptions, {
4324
- code: err_40.code,
4325
- codeName: err_40.codeName,
4326
- message: err_40.message,
4327
- stack: err_40.stack
4427
+ code: err_41.code,
4428
+ codeName: err_41.codeName,
4429
+ message: err_41.message,
4430
+ stack: err_41.stack
4328
4431
  }], null, 2));
4329
- err_40.message = "Error in Update One: ".concat(this.collectionName, " => ").concat(err_40.codeName || 'NoCodeName', " => ").concat(err_40.message);
4330
- throw err_40;
4432
+ err_41.message = "Error in Update One: ".concat(this.collectionName, " => ").concat(err_41.codeName || 'NoCodeName', " => ").concat(err_41.message);
4433
+ throw err_41;
4331
4434
  case 25: return [4 /*yield*/, monitor.finish()];
4332
4435
  case 26:
4333
4436
  _c.sent();
@@ -4469,15 +4572,15 @@ var MongoManagerCollection = /** @class */ (function () {
4469
4572
  _c.label = 41;
4470
4573
  case 41: return [2 /*return*/, res];
4471
4574
  case 42:
4472
- err_41 = _c.sent();
4575
+ err_42 = _c.sent();
4473
4576
  console.log(JSON.stringify([new Date(), 'Error Update One (Find One And Update)', this.collectionName, filter, safeOptions, {
4474
- code: err_41.code,
4475
- codeName: err_41.codeName,
4476
- message: err_41.message,
4477
- stack: err_41.stack
4577
+ code: err_42.code,
4578
+ codeName: err_42.codeName,
4579
+ message: err_42.message,
4580
+ stack: err_42.stack
4478
4581
  }], null, 2));
4479
- err_41.message = "Error in Update One (Find One And Update): ".concat(this.collectionName, " => ").concat(err_41.codeName || 'NoCodeName', " => ").concat(err_41.message);
4480
- throw err_41;
4582
+ err_42.message = "Error in Update One (Find One And Update): ".concat(this.collectionName, " => ").concat(err_42.codeName || 'NoCodeName', " => ").concat(err_42.message);
4583
+ throw err_42;
4481
4584
  case 43: return [4 /*yield*/, monitor.finish()];
4482
4585
  case 44:
4483
4586
  _c.sent();
@@ -4496,15 +4599,15 @@ var MongoManagerCollection = /** @class */ (function () {
4496
4599
  }
4497
4600
  return [2 /*return*/, res];
4498
4601
  case 49:
4499
- err_42 = _c.sent();
4602
+ err_43 = _c.sent();
4500
4603
  console.log(JSON.stringify([new Date(), 'Error Update One', this.collectionName, filter, update, safeOptions, {
4501
- code: err_42.code,
4502
- codeName: err_42.codeName,
4503
- message: err_42.message,
4504
- stack: err_42.stack
4604
+ code: err_43.code,
4605
+ codeName: err_43.codeName,
4606
+ message: err_43.message,
4607
+ stack: err_43.stack
4505
4608
  }], null, 2));
4506
- err_42.message = "Error in Update One: ".concat(this.collectionName, " => ").concat(err_42.codeName || 'NoCodeName', " => ").concat(err_42.message);
4507
- throw err_42;
4609
+ err_43.message = "Error in Update One: ".concat(this.collectionName, " => ").concat(err_43.codeName || 'NoCodeName', " => ").concat(err_43.message);
4610
+ throw err_43;
4508
4611
  case 50: return [4 /*yield*/, monitor.finish()];
4509
4612
  case 51:
4510
4613
  _c.sent();
@@ -4544,7 +4647,7 @@ var MongoManagerUserCollection = /** @class */ (function (_super) {
4544
4647
  };
4545
4648
  MongoManagerUserCollection.prototype.authenticate = function (user, password) {
4546
4649
  return __awaiter(this, void 0, void 0, function () {
4547
- var attemptsInterval, calculatedInterval, hashBuffer, err_43;
4650
+ var attemptsInterval, calculatedInterval, hashBuffer, err_44;
4548
4651
  return __generator(this, function (_a) {
4549
4652
  switch (_a.label) {
4550
4653
  case 0:
@@ -4618,9 +4721,9 @@ var MongoManagerUserCollection = /** @class */ (function (_super) {
4618
4721
  _a.label = 10;
4619
4722
  case 10: return [3 /*break*/, 12];
4620
4723
  case 11:
4621
- err_43 = _a.sent();
4622
- err_43.message = "Error in User Authenticate: ".concat(JSON.stringify(user, null, 2), " - ").concat(err_43.message);
4623
- throw err_43;
4724
+ err_44 = _a.sent();
4725
+ err_44.message = "Error in User Authenticate: ".concat(JSON.stringify(user, null, 2), " - ").concat(err_44.message);
4726
+ throw err_44;
4624
4727
  case 12: return [2 /*return*/];
4625
4728
  }
4626
4729
  });
@@ -4641,7 +4744,7 @@ var MongoManagerUserCollection = /** @class */ (function (_super) {
4641
4744
  };
4642
4745
  MongoManagerUserCollection.prototype.setPassword = function (user, password) {
4643
4746
  return __awaiter(this, void 0, void 0, function () {
4644
- var saltBuffer, salt, hashRaw, hash, err_44;
4747
+ var saltBuffer, salt, hashRaw, hash, err_45;
4645
4748
  return __generator(this, function (_a) {
4646
4749
  switch (_a.label) {
4647
4750
  case 0:
@@ -4667,9 +4770,9 @@ var MongoManagerUserCollection = /** @class */ (function (_super) {
4667
4770
  hash = Buffer.from(hashRaw, 'binary').toString('hex');
4668
4771
  return [2 /*return*/, user_collection_1.Users.updateOne({ _id: user._id }, { $set: { hash: hash, salt: salt, services: {}, attempts: 0 } })];
4669
4772
  case 6:
4670
- err_44 = _a.sent();
4671
- err_44.message = "Error in User Set Password: ".concat(JSON.stringify(user, null, 2), " - ").concat(err_44.message);
4672
- throw err_44;
4773
+ err_45 = _a.sent();
4774
+ err_45.message = "Error in User Set Password: ".concat(JSON.stringify(user, null, 2), " - ").concat(err_45.message);
4775
+ throw err_45;
4673
4776
  case 7: return [2 /*return*/];
4674
4777
  }
4675
4778
  });