@resolveio/server-lib 20.12.12 → 20.12.14

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.
@@ -0,0 +1,2 @@
1
+ import * as express from 'express';
2
+ export declare function setupSlowQueryPublicationRoutes(app: express.Application): void;
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.setupSlowQueryPublicationRoutes = setupSlowQueryPublicationRoutes;
40
+ var express = require("express");
41
+ var resolveio_server_app_1 = require("../resolveio-server-app");
42
+ function setupSlowQueryPublicationRoutes(app) {
43
+ var _this = this;
44
+ app.post('/api/slow-queries/run-publication', express.json(), function (request, response) { return __awaiter(_this, void 0, void 0, function () {
45
+ var body, publication, subscriptionData, userId, manager, startTime, execution, durationMs, err_1;
46
+ return __generator(this, function (_a) {
47
+ switch (_a.label) {
48
+ case 0:
49
+ body = request.body || {};
50
+ publication = typeof body.publication === 'string' ? body.publication.trim() : '';
51
+ subscriptionData = Array.isArray(body.subscriptionData) ? body.subscriptionData : [];
52
+ userId = typeof body.userId === 'string' ? body.userId : undefined;
53
+ if (!publication) {
54
+ response.status(400).send(JSON.stringify({
55
+ error: true,
56
+ result: 'Publication name is required.'
57
+ }));
58
+ return [2 /*return*/];
59
+ }
60
+ manager = resolveio_server_app_1.ResolveIOServer.getMainServer().getSubscriptionManager();
61
+ if (!manager) {
62
+ response.status(503).send(JSON.stringify({
63
+ error: true,
64
+ result: 'Subscription manager is not available.'
65
+ }));
66
+ return [2 /*return*/];
67
+ }
68
+ _a.label = 1;
69
+ case 1:
70
+ _a.trys.push([1, 3, , 4]);
71
+ startTime = Date.now();
72
+ return [4 /*yield*/, manager.runPublicationOnce(publication, subscriptionData, { userId: userId })];
73
+ case 2:
74
+ execution = _a.sent();
75
+ durationMs = Date.now() - startTime;
76
+ response.send(JSON.stringify({
77
+ error: false,
78
+ result: {
79
+ durationMs: durationMs,
80
+ data: execution === null || execution === void 0 ? void 0 : execution.result,
81
+ snapshot: execution === null || execution === void 0 ? void 0 : execution.snapshot
82
+ }
83
+ }));
84
+ return [3 /*break*/, 4];
85
+ case 3:
86
+ err_1 = _a.sent();
87
+ console.error('Slow query publication run failed', err_1);
88
+ response.status(500).send(JSON.stringify({
89
+ error: true,
90
+ result: (err_1 === null || err_1 === void 0 ? void 0 : err_1.message) || 'Failed to run publication.'
91
+ }));
92
+ return [3 /*break*/, 4];
93
+ case 4: return [2 /*return*/];
94
+ }
95
+ });
96
+ }); });
97
+ }
98
+
99
+ //# sourceMappingURL=slow-query-publication.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/http/slow-query-publication.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,0EA6CC;AAhDD,iCAAmC;AACnC,gEAA0D;AAE1D,SAAgB,+BAA+B,CAAC,GAAwB;IAAxE,iBA6CC;IA5CA,GAAG,CAAC,IAAI,CAAC,mCAAmC,EAAE,OAAO,CAAC,IAAI,EAAE,EAAE,UAAO,OAAO,EAAE,QAAQ;;;;;oBAC/E,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,EAAE,CAAC;oBAC1B,WAAW,GAAG,OAAO,IAAI,CAAC,WAAW,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;oBAClF,gBAAgB,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC;oBACrF,MAAM,GAAG,OAAO,IAAI,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;oBAEzE,IAAI,CAAC,WAAW,EAAE,CAAC;wBAClB,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC;4BACxC,KAAK,EAAE,IAAI;4BACX,MAAM,EAAE,+BAA+B;yBACvC,CAAC,CAAC,CAAC;wBACJ,sBAAO;oBACR,CAAC;oBAEK,OAAO,GAAG,sCAAe,CAAC,aAAa,EAAE,CAAC,sBAAsB,EAAE,CAAC;oBACzE,IAAI,CAAC,OAAO,EAAE,CAAC;wBACd,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC;4BACxC,KAAK,EAAE,IAAI;4BACX,MAAM,EAAE,wCAAwC;yBAChD,CAAC,CAAC,CAAC;wBACJ,sBAAO;oBACR,CAAC;;;;oBAGK,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;oBACX,qBAAM,OAAO,CAAC,kBAAkB,CAAC,WAAW,EAAE,gBAAgB,EAAE,EAAC,MAAM,QAAA,EAAC,CAAC,EAAA;;oBAArF,SAAS,GAAG,SAAyE;oBACrF,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;oBAC1C,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC;wBAC5B,KAAK,EAAE,KAAK;wBACZ,MAAM,EAAE;4BACP,UAAU,YAAA;4BACV,IAAI,EAAE,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,MAAM;4BACvB,QAAQ,EAAE,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,QAAQ;yBAC7B;qBACD,CAAC,CAAC,CAAC;;;;oBAGJ,OAAO,CAAC,KAAK,CAAC,mCAAmC,EAAE,KAAG,CAAC,CAAC;oBACvD,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC;wBACxC,KAAK,EAAE,IAAI;wBACX,MAAM,EAAE,CAAA,KAAG,aAAH,KAAG,uBAAH,KAAG,CAAE,OAAO,KAAI,4BAA4B;qBACpD,CAAC,CAAC,CAAC;;;;;SAEL,CAAC,CAAC;AACJ,CAAC","file":"slow-query-publication.js","sourcesContent":["import * as express from 'express';\nimport { ResolveIOServer } from '../resolveio-server-app';\n\nexport function setupSlowQueryPublicationRoutes(app: express.Application) {\n\tapp.post('/api/slow-queries/run-publication', express.json(), async (request, response) => {\n\t\tconst body = request.body || {};\n\t\tconst publication = typeof body.publication === 'string' ? body.publication.trim() : '';\n\t\tconst subscriptionData = Array.isArray(body.subscriptionData) ? body.subscriptionData : [];\n\t\tconst userId = typeof body.userId === 'string' ? body.userId : undefined;\n\n\t\tif (!publication) {\n\t\t\tresponse.status(400).send(JSON.stringify({\n\t\t\t\terror: true,\n\t\t\t\tresult: 'Publication name is required.'\n\t\t\t}));\n\t\t\treturn;\n\t\t}\n\n\t\tconst manager = ResolveIOServer.getMainServer().getSubscriptionManager();\n\t\tif (!manager) {\n\t\t\tresponse.status(503).send(JSON.stringify({\n\t\t\t\terror: true,\n\t\t\t\tresult: 'Subscription manager is not available.'\n\t\t\t}));\n\t\t\treturn;\n\t\t}\n\n\ttry {\n\t\tconst startTime = Date.now();\n\t\tconst execution = await manager.runPublicationOnce(publication, subscriptionData, {userId});\n\t\tconst durationMs = Date.now() - startTime;\n\t\tresponse.send(JSON.stringify({\n\t\t\terror: false,\n\t\t\tresult: {\n\t\t\t\tdurationMs,\n\t\t\t\tdata: execution?.result,\n\t\t\t\tsnapshot: execution?.snapshot\n\t\t\t}\n\t\t}));\n\t}\n\tcatch (err) {\n\t\tconsole.error('Slow query publication run failed', err);\n\t\t\tresponse.status(500).send(JSON.stringify({\n\t\t\t\terror: true,\n\t\t\t\tresult: err?.message || 'Failed to run publication.'\n\t\t\t}));\n\t\t}\n\t});\n}\n"]}
@@ -508,11 +508,10 @@ var MethodManager = /** @class */ (function () {
508
508
  };
509
509
  MethodManager.prototype.callMethodInternal = function (correlationId, methodName, methodData) {
510
510
  return __awaiter(this, void 0, void 0, function () {
511
- var method, functionMethodData, session, monitor_2, monitor, res, err_3, _a, normalizedError, resolvedCorrelationId;
512
- var _b;
511
+ var method, methodCallback, functionMethodData, session, shouldStartTransaction, executeWithExistingSession, monitor_2;
513
512
  var _this = this;
514
- return __generator(this, function (_c) {
515
- switch (_c.label) {
513
+ return __generator(this, function (_a) {
514
+ switch (_a.label) {
516
515
  case 0:
517
516
  method = this.getMethod(methodName);
518
517
  if (!method) {
@@ -576,15 +575,16 @@ var MethodManager = /** @class */ (function () {
576
575
  correlationId: correlationId
577
576
  })];
578
577
  case 2:
579
- _c.sent();
580
- _c.label = 3;
578
+ _a.sent();
579
+ _a.label = 3;
581
580
  case 3:
582
581
  ;
583
- _c.label = 4;
582
+ _a.label = 4;
584
583
  case 4:
585
- functionMethodData = typeof (methodData[methodData.length - 1]) === 'function' ? methodData.slice(0, -1) : methodData;
584
+ methodCallback = typeof (methodData[methodData.length - 1]) === 'function' ? methodData[methodData.length - 1] : null;
585
+ functionMethodData = methodCallback ? methodData.slice(0, -1) : methodData;
586
586
  session = resolveio_server_app_1.ResolveIOServer.getMongoManager().getSession();
587
- if (!(!method.bypassSession &&
587
+ shouldStartTransaction = !method.bypassSession &&
588
588
  !session &&
589
589
  ![
590
590
  'insertErrorLog', // CIRCULAR LOOP - DO NOT REMOVE
@@ -592,133 +592,155 @@ var MethodManager = /** @class */ (function () {
592
592
  'sendEmail' // ALWAYS SEND SO ALWAYS HAVE RECORD - DONT ROLL BACK - BYPASS SESSION
593
593
  ].includes(methodName) &&
594
594
  !methodName.startsWith('monitor-') &&
595
- !methodName.startsWith('log'))) return [3 /*break*/, 5];
596
- monitor_2 = null;
597
- return [2 /*return*/, resolveio_server_app_1.ResolveIOServer.getMongoManager().oneTimeTransaction(function () { return __awaiter(_this, void 0, void 0, function () {
598
- var res, err_4, _a, normalizedError, resolvedCorrelationId;
599
- var _b;
600
- return __generator(this, function (_c) {
601
- switch (_c.label) {
602
- case 0:
603
- // console.log(new Date(), 'Calling Method - New Session', methodName);
604
- monitor_2 = this._monitorManagerFunction.startMonitorFunction('Method', methodName, this['user'] || '', '', functionMethodData);
605
- _c.label = 1;
606
- case 1:
607
- _c.trys.push([1, 3, 7, 9]);
608
- return [4 /*yield*/, (_b = method.function).call.apply(_b, __spreadArray([Object.assign({}, this, MethodManager.prototype)], __read(functionMethodData), false))];
609
- case 2:
610
- res = _c.sent();
611
- if (methodData[methodData.length - 1] && typeof (methodData[methodData.length - 1]) === 'function') {
612
- methodData[methodData.length - 1](null, res);
613
- }
614
- return [2 /*return*/, res];
615
- case 3:
616
- err_4 = _c.sent();
617
- if (err_4.code === 112 || err_4.codeName === 'WriteConflict' || err_4.code === 251 || err_4.codeName === 'NoSuchTransaction') {
618
- throw err_4; // Write error, retry
619
- }
620
- _a = (0, error_tracking_1.ensureErrorWithCorrelation)(err_4, correlationId), normalizedError = _a.error, resolvedCorrelationId = _a.correlationId;
621
- console.log(JSON.stringify([new Date(), 'Error Method Manager - Run Method - New Session', methodName, {
622
- code: normalizedError.code,
623
- codeName: normalizedError.codeName,
595
+ !methodName.startsWith('log');
596
+ executeWithExistingSession = function () { return __awaiter(_this, void 0, void 0, function () {
597
+ var monitor, res, err_3, _a, normalizedError, resolvedCorrelationId;
598
+ var _b;
599
+ return __generator(this, function (_c) {
600
+ switch (_c.label) {
601
+ case 0:
602
+ monitor = this._monitorManagerFunction.startMonitorFunction('Method', methodName, this['user'] || '', '', functionMethodData);
603
+ _c.label = 1;
604
+ case 1:
605
+ _c.trys.push([1, 3, 7, 9]);
606
+ return [4 /*yield*/, (_b = method.function).call.apply(_b, __spreadArray([Object.assign({}, this, MethodManager.prototype)], __read(functionMethodData), false))];
607
+ case 2:
608
+ res = _c.sent();
609
+ if (methodCallback) {
610
+ methodCallback(null, res);
611
+ }
612
+ return [2 /*return*/, res];
613
+ case 3:
614
+ err_3 = _c.sent();
615
+ if (err_3.code === 112 || err_3.codeName === 'WriteConflict' || err_3.code === 251 || err_3.codeName === 'NoSuchTransaction') {
616
+ throw err_3; // Write error, retry
617
+ }
618
+ _a = (0, error_tracking_1.ensureErrorWithCorrelation)(err_3, correlationId), normalizedError = _a.error, resolvedCorrelationId = _a.correlationId;
619
+ console.log(JSON.stringify([new Date(), 'Error Method Manager - Run Method - Existing Session', methodName, {
620
+ code: normalizedError.code,
621
+ codeName: normalizedError.codeName,
622
+ message: normalizedError.message,
623
+ stack: normalizedError.stack,
624
+ correlationId: resolvedCorrelationId
625
+ }], null, 2));
626
+ return [4 /*yield*/, this.reportMethodError('SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], resolvedCorrelationId, {
627
+ message: 'Error detected during method execution (existing session)',
628
+ method: methodName,
629
+ data: methodData,
630
+ error: normalizedError
631
+ }, { context: 'callMethod-existing-session', methodName: methodName }, normalizedError.stack)];
632
+ case 4:
633
+ _c.sent();
634
+ normalizedError.message = "".concat(new Date().toISOString(), " - Error in Method (").concat(methodName, ") - Existing Session: ").concat(normalizedError.message);
635
+ if (methodCallback) {
636
+ methodCallback(normalizedError, null);
637
+ }
638
+ if (!!process.env.IS_WORKER_INSTANCE) return [3 /*break*/, 6];
639
+ return [4 /*yield*/, this.callMethod('insertErrorLog', "Error in Method: ".concat(methodName), {
640
+ method: methodName,
641
+ methodData: methodData,
642
+ error: {
624
643
  message: normalizedError.message,
625
644
  stack: normalizedError.stack,
626
- correlationId: resolvedCorrelationId
627
- }], null, 2));
628
- return [4 /*yield*/, this.reportMethodError('SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], resolvedCorrelationId, {
629
- message: 'Error detected during method execution (new session)',
630
- method: methodName,
631
- data: methodData,
632
- error: normalizedError
633
- }, { context: 'callMethod-new-session', methodName: methodName }, normalizedError.stack)];
634
- case 4:
635
- _c.sent();
636
- normalizedError.message = "".concat(new Date().toISOString(), " - Error in Method With Session (").concat(methodName, ") - New Session: ").concat(normalizedError.message);
637
- if (methodData[methodData.length - 1] && typeof (methodData[methodData.length - 1]) === 'function') {
638
- methodData[methodData.length - 1](normalizedError, null);
639
- }
640
- if (!!process.env.IS_WORKER_INSTANCE) return [3 /*break*/, 6];
641
- return [4 /*yield*/, this.callMethod('insertErrorLog', "Error in Method: ".concat(methodName), {
642
- method: methodName,
643
- methodData: methodData,
644
- error: {
645
+ code: normalizedError.code,
646
+ codeName: normalizedError.codeName
647
+ },
648
+ correlationId: resolvedCorrelationId
649
+ })];
650
+ case 5:
651
+ _c.sent();
652
+ _c.label = 6;
653
+ case 6: throw normalizedError;
654
+ case 7: return [4 /*yield*/, this._monitorManagerFunction.finishMonitorFunction(monitor)];
655
+ case 8:
656
+ _c.sent();
657
+ return [7 /*endfinally*/];
658
+ case 9: return [2 /*return*/];
659
+ }
660
+ });
661
+ }); };
662
+ if (shouldStartTransaction) {
663
+ monitor_2 = null;
664
+ return [2 /*return*/, resolveio_server_app_1.ResolveIOServer.getMongoManager().oneTimeTransaction(function () { return __awaiter(_this, void 0, void 0, function () {
665
+ var res, err_4, _a, normalizedError, resolvedCorrelationId;
666
+ var _b;
667
+ return __generator(this, function (_c) {
668
+ switch (_c.label) {
669
+ case 0:
670
+ // console.log(new Date(), 'Calling Method - New Session', methodName);
671
+ monitor_2 = this._monitorManagerFunction.startMonitorFunction('Method', methodName, this['user'] || '', '', functionMethodData);
672
+ _c.label = 1;
673
+ case 1:
674
+ _c.trys.push([1, 3, 7, 9]);
675
+ return [4 /*yield*/, (_b = method.function).call.apply(_b, __spreadArray([Object.assign({}, this, MethodManager.prototype)], __read(functionMethodData), false))];
676
+ case 2:
677
+ res = _c.sent();
678
+ if (methodCallback) {
679
+ methodCallback(null, res);
680
+ }
681
+ return [2 /*return*/, res];
682
+ case 3:
683
+ err_4 = _c.sent();
684
+ if (err_4.code === 112 || err_4.codeName === 'WriteConflict' || err_4.code === 251 || err_4.codeName === 'NoSuchTransaction') {
685
+ throw err_4; // Write error, retry
686
+ }
687
+ _a = (0, error_tracking_1.ensureErrorWithCorrelation)(err_4, correlationId), normalizedError = _a.error, resolvedCorrelationId = _a.correlationId;
688
+ console.log(JSON.stringify([new Date(), 'Error Method Manager - Run Method - New Session', methodName, {
689
+ code: normalizedError.code,
690
+ codeName: normalizedError.codeName,
645
691
  message: normalizedError.message,
646
692
  stack: normalizedError.stack,
647
- code: normalizedError.code,
648
- codeName: normalizedError.codeName
649
- },
650
- correlationId: resolvedCorrelationId
651
- })];
652
- case 5:
653
- _c.sent();
654
- _c.label = 6;
655
- case 6: throw normalizedError;
656
- case 7: return [4 /*yield*/, this._monitorManagerFunction.finishMonitorFunction(monitor_2)];
657
- case 8:
658
- _c.sent();
659
- return [7 /*endfinally*/];
660
- case 9: return [2 /*return*/];
661
- }
662
- });
663
- }); })];
664
- case 5:
665
- monitor = this._monitorManagerFunction.startMonitorFunction('Method', methodName, this['user'] || '', '', functionMethodData);
666
- _c.label = 6;
667
- case 6:
668
- _c.trys.push([6, 8, 12, 14]);
669
- return [4 /*yield*/, (_b = method.function).call.apply(_b, __spreadArray([Object.assign({}, this, MethodManager.prototype)], __read(functionMethodData), false))];
670
- case 7:
671
- res = _c.sent();
672
- if (methodData[methodData.length - 1] && typeof (methodData[methodData.length - 1]) === 'function') {
673
- methodData[methodData.length - 1](null, res);
693
+ correlationId: resolvedCorrelationId
694
+ }], null, 2));
695
+ return [4 /*yield*/, this.reportMethodError('SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], resolvedCorrelationId, {
696
+ message: 'Error detected during method execution (new session)',
697
+ method: methodName,
698
+ data: methodData,
699
+ error: normalizedError
700
+ }, { context: 'callMethod-new-session', methodName: methodName }, normalizedError.stack)];
701
+ case 4:
702
+ _c.sent();
703
+ normalizedError.message = "".concat(new Date().toISOString(), " - Error in Method With Session (").concat(methodName, ") - New Session: ").concat(normalizedError.message);
704
+ if (methodCallback) {
705
+ methodCallback(normalizedError, null);
706
+ }
707
+ if (!!process.env.IS_WORKER_INSTANCE) return [3 /*break*/, 6];
708
+ return [4 /*yield*/, this.callMethod('insertErrorLog', "Error in Method: ".concat(methodName), {
709
+ method: methodName,
710
+ methodData: methodData,
711
+ error: {
712
+ message: normalizedError.message,
713
+ stack: normalizedError.stack,
714
+ code: normalizedError.code,
715
+ codeName: normalizedError.codeName
716
+ },
717
+ correlationId: resolvedCorrelationId
718
+ })];
719
+ case 5:
720
+ _c.sent();
721
+ _c.label = 6;
722
+ case 6: throw normalizedError;
723
+ case 7: return [4 /*yield*/, this._monitorManagerFunction.finishMonitorFunction(monitor_2)];
724
+ case 8:
725
+ _c.sent();
726
+ return [7 /*endfinally*/];
727
+ case 9: return [2 /*return*/];
728
+ }
729
+ });
730
+ }); })];
674
731
  }
675
- return [2 /*return*/, res];
676
- case 8:
677
- err_3 = _c.sent();
678
- if (err_3.code === 112 || err_3.codeName === 'WriteConflict' || err_3.code === 251 || err_3.codeName === 'NoSuchTransaction') {
679
- throw err_3; // Write error, retry
732
+ else if (method.bypassSession && session) {
733
+ return [2 /*return*/, resolveio_server_app_1.ResolveIOServer.getMongoManager().runWithoutSession(function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
734
+ switch (_a.label) {
735
+ case 0: return [4 /*yield*/, executeWithExistingSession()];
736
+ case 1: return [2 /*return*/, _a.sent()];
737
+ }
738
+ }); }); })];
680
739
  }
681
- _a = (0, error_tracking_1.ensureErrorWithCorrelation)(err_3, correlationId), normalizedError = _a.error, resolvedCorrelationId = _a.correlationId;
682
- console.log(JSON.stringify([new Date(), 'Error Method Manager - Run Method - Existing Session', methodName, {
683
- code: normalizedError.code,
684
- codeName: normalizedError.codeName,
685
- message: normalizedError.message,
686
- stack: normalizedError.stack,
687
- correlationId: resolvedCorrelationId
688
- }], null, 2));
689
- return [4 /*yield*/, this.reportMethodError('SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], resolvedCorrelationId, {
690
- message: 'Error detected during method execution (existing session)',
691
- method: methodName,
692
- data: methodData,
693
- error: normalizedError
694
- }, { context: 'callMethod-existing-session', methodName: methodName }, normalizedError.stack)];
695
- case 9:
696
- _c.sent();
697
- normalizedError.message = "".concat(new Date().toISOString(), " - Error in Method (").concat(methodName, ") - Existing Session: ").concat(normalizedError.message);
698
- if (methodData[methodData.length - 1] && typeof (methodData[methodData.length - 1]) === 'function') {
699
- methodData[methodData.length - 1](normalizedError, null);
740
+ else {
741
+ return [2 /*return*/, executeWithExistingSession()];
700
742
  }
701
- if (!!process.env.IS_WORKER_INSTANCE) return [3 /*break*/, 11];
702
- return [4 /*yield*/, this.callMethod('insertErrorLog', "Error in Method: ".concat(methodName), {
703
- method: methodName,
704
- methodData: methodData,
705
- error: {
706
- message: normalizedError.message,
707
- stack: normalizedError.stack,
708
- code: normalizedError.code,
709
- codeName: normalizedError.codeName
710
- },
711
- correlationId: resolvedCorrelationId
712
- })];
713
- case 10:
714
- _c.sent();
715
- _c.label = 11;
716
- case 11: throw normalizedError;
717
- case 12: return [4 /*yield*/, this._monitorManagerFunction.finishMonitorFunction(monitor)];
718
- case 13:
719
- _c.sent();
720
- return [7 /*endfinally*/];
721
- case 14: return [2 /*return*/];
743
+ return [2 /*return*/];
722
744
  }
723
745
  });
724
746
  });