@creator.co/wapi 1.6.1 → 2.0.0-alpha.1
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.
- package/.github/workflows/npmpublish.yml +1 -1
- package/.github/workflows/prs.yml +1 -1
- package/dist/index.js +45 -31
- package/dist/index.js.map +1 -1
- package/dist/jest.config.js +2 -4
- package/dist/jest.config.js.map +1 -1
- package/dist/package.json +12 -12
- package/dist/src/API/Request.js +53 -59
- package/dist/src/API/Request.js.map +1 -1
- package/dist/src/API/Response.js +81 -156
- package/dist/src/API/Response.js.map +1 -1
- package/dist/src/BaseEvent/EventProcessor.js +54 -132
- package/dist/src/BaseEvent/EventProcessor.js.map +1 -1
- package/dist/src/BaseEvent/Process.js +40 -98
- package/dist/src/BaseEvent/Process.js.map +1 -1
- package/dist/src/BaseEvent/Transaction.js +122 -310
- package/dist/src/BaseEvent/Transaction.js.map +1 -1
- package/dist/src/Cache/Redis.js +55 -119
- package/dist/src/Cache/Redis.js.map +1 -1
- package/dist/src/Cache/types.js +1 -2
- package/dist/src/Config/Configuration.js +46 -86
- package/dist/src/Config/Configuration.js.map +1 -1
- package/dist/src/Config/EnvironmentVar.js +57 -119
- package/dist/src/Config/EnvironmentVar.js.map +1 -1
- package/dist/src/Crypto/Crypto.js +35 -82
- package/dist/src/Crypto/Crypto.js.map +1 -1
- package/dist/src/Crypto/JWT.js +12 -27
- package/dist/src/Crypto/JWT.js.map +1 -1
- package/dist/src/Database/Database.js +3 -8
- package/dist/src/Database/Database.js.map +1 -1
- package/dist/src/Database/DatabaseManager.js +23 -28
- package/dist/src/Database/DatabaseManager.js.map +1 -1
- package/dist/src/Database/DatabaseTransaction.js +50 -166
- package/dist/src/Database/DatabaseTransaction.js.map +1 -1
- package/dist/src/Database/index.js +11 -15
- package/dist/src/Database/index.js.map +1 -1
- package/dist/src/Database/integrations/knex/KnexDatabase.js +22 -76
- package/dist/src/Database/integrations/knex/KnexDatabase.js.map +1 -1
- package/dist/src/Database/integrations/knex/KnexTransaction.js +19 -85
- package/dist/src/Database/integrations/knex/KnexTransaction.js.map +1 -1
- package/dist/src/Database/integrations/kysely/KyselyDatabase.js +37 -88
- package/dist/src/Database/integrations/kysely/KyselyDatabase.js.map +1 -1
- package/dist/src/Database/integrations/kysely/KyselyTransaction.js +46 -114
- package/dist/src/Database/integrations/kysely/KyselyTransaction.js.map +1 -1
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.js +20 -71
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.js.map +1 -1
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.js +19 -85
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.js.map +1 -1
- package/dist/src/Database/types.js +1 -2
- package/dist/src/Globals.js +93 -98
- package/dist/src/Globals.js.map +1 -1
- package/dist/src/Logger/Logger.js +88 -222
- package/dist/src/Logger/Logger.js.map +1 -1
- package/dist/src/Mailer/Mailer.js +83 -204
- package/dist/src/Mailer/Mailer.js.map +1 -1
- package/dist/src/Publisher/Publisher.js +43 -107
- package/dist/src/Publisher/Publisher.js.map +1 -1
- package/dist/src/Server/RouteResolver.js +22 -49
- package/dist/src/Server/RouteResolver.js.map +1 -1
- package/dist/src/Server/Router.js +12 -16
- package/dist/src/Server/Router.js.map +1 -1
- package/dist/src/Server/lib/ContainerServer.js +21 -83
- package/dist/src/Server/lib/ContainerServer.js.map +1 -1
- package/dist/src/Server/lib/Server.js +50 -99
- package/dist/src/Server/lib/Server.js.map +1 -1
- package/dist/src/Server/lib/container/GenericHandler.js +32 -107
- package/dist/src/Server/lib/container/GenericHandler.js.map +1 -1
- package/dist/src/Server/lib/container/GenericHandlerEvent.js +37 -81
- package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +1 -1
- package/dist/src/Server/lib/container/HealthHandler.js +3 -35
- package/dist/src/Server/lib/container/HealthHandler.js.map +1 -1
- package/dist/src/Server/lib/container/Proxy.js +64 -127
- package/dist/src/Server/lib/container/Proxy.js.map +1 -1
- package/dist/src/Server/lib/container/Utils.js +12 -55
- package/dist/src/Server/lib/container/Utils.js.map +1 -1
- package/dist/src/Util/AsyncSingleton.js +40 -164
- package/dist/src/Util/AsyncSingleton.js.map +1 -1
- package/dist/src/Util/Utils.js +18 -24
- package/dist/src/Util/Utils.js.map +1 -1
- package/dist/src/Validation/Validator.js +10 -16
- package/dist/src/Validation/Validator.js.map +1 -1
- package/package.json +12 -12
- package/tests/Logger/Logger.test.ts +5 -3
- package/tsconfig.json +3 -1
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,83 +7,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
8
|
});
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
39
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
40
|
-
if (!m) return o;
|
|
41
|
-
var i = m.call(o), r, ar = [], e;
|
|
42
|
-
try {
|
|
43
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
44
|
-
}
|
|
45
|
-
catch (error) { e = { error: error }; }
|
|
46
|
-
finally {
|
|
47
|
-
try {
|
|
48
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
49
|
-
}
|
|
50
|
-
finally { if (e) throw e.error; }
|
|
51
|
-
}
|
|
52
|
-
return ar;
|
|
53
|
-
};
|
|
54
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
55
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
56
|
-
if (ar || !(i in from)) {
|
|
57
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
58
|
-
ar[i] = from[i];
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
62
|
-
};
|
|
63
|
-
var __values = (this && this.__values) || function(o) {
|
|
64
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
65
|
-
if (m) return m.call(o);
|
|
66
|
-
if (o && typeof o.length === "number") return {
|
|
67
|
-
next: function () {
|
|
68
|
-
if (o && i >= o.length) o = void 0;
|
|
69
|
-
return { value: o && o[i++], done: !o };
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
73
|
-
};
|
|
74
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
75
|
-
var Request_1 = require("../API/Request");
|
|
76
|
-
var Response_1 = require("../API/Response");
|
|
77
|
-
var DatabaseManager_1 = require("../Database/DatabaseManager");
|
|
78
|
-
var Globals_1 = require("../Globals");
|
|
79
|
-
var Logger_1 = require("../Logger/Logger");
|
|
80
|
-
var Publisher_1 = require("../Publisher/Publisher");
|
|
10
|
+
import Request from '../API/Request';
|
|
11
|
+
import Response from '../API/Response';
|
|
12
|
+
import { DatabaseManager } from '../Database/DatabaseManager';
|
|
13
|
+
import Globals from '../Globals';
|
|
14
|
+
import Logger from '../Logger/Logger';
|
|
15
|
+
import Publisher from '../Publisher/Publisher';
|
|
81
16
|
/**
|
|
82
17
|
* Represents a transaction object that handles the execution of a request and manages the response.
|
|
83
18
|
* @template InputType - The type of the input data for the transaction.
|
|
84
19
|
* @template ResponseInnerType - The type of the inner response data for the transaction.
|
|
85
20
|
* @template MiscRespType - The type of miscellaneous response data for the transaction.
|
|
86
21
|
*/
|
|
87
|
-
|
|
22
|
+
export default class Transaction {
|
|
88
23
|
/**
|
|
89
24
|
* Constructs a new instance of the Transaction class.
|
|
90
25
|
* @param {APIGatewayEvent | SQSEvent} event - The event object passed to the Lambda function.
|
|
@@ -92,17 +27,17 @@ var Transaction = /** @class */ (function () {
|
|
|
92
27
|
* @param {TransactionConfig} [config] - Optional configuration object for the transaction.
|
|
93
28
|
* @returns None
|
|
94
29
|
*/
|
|
95
|
-
|
|
30
|
+
constructor(event, context, config) {
|
|
96
31
|
/**
|
|
97
32
|
* The instance of the DatabaseManager class used for managing the database.
|
|
98
33
|
*/
|
|
99
|
-
this.databaseManager =
|
|
34
|
+
this.databaseManager = DatabaseManager.INSTANCE;
|
|
100
35
|
/**
|
|
101
36
|
* An array of database transactions.
|
|
102
37
|
* @type {DatabaseTransaction[]}
|
|
103
38
|
*/
|
|
104
39
|
this.transactions = [];
|
|
105
|
-
|
|
40
|
+
const transactionId = context.awsRequestId
|
|
106
41
|
? context.awsRequestId
|
|
107
42
|
: event.requestContext
|
|
108
43
|
? event.requestContext.requestId
|
|
@@ -116,9 +51,9 @@ var Transaction = /** @class */ (function () {
|
|
|
116
51
|
this.syncReturn = !!(config === null || config === void 0 ? void 0 : config.syncReturn);
|
|
117
52
|
this.retrowErrors = !!(config === null || config === void 0 ? void 0 : config.throwOnErrors); /* retrow internal errors */
|
|
118
53
|
// components
|
|
119
|
-
this.logger = new
|
|
120
|
-
this.request = new
|
|
121
|
-
this.publisher = new
|
|
54
|
+
this.logger = new Logger(config === null || config === void 0 ? void 0 : config.logger, transactionId);
|
|
55
|
+
this.request = new Request(this.event, this.context, this.logger);
|
|
56
|
+
this.publisher = new Publisher(config === null || config === void 0 ? void 0 : config.publisher);
|
|
122
57
|
}
|
|
123
58
|
/**
|
|
124
59
|
* Executes a transaction using the provided execution function and returns a promise
|
|
@@ -126,280 +61,157 @@ var Transaction = /** @class */ (function () {
|
|
|
126
61
|
* @param {TransactionExecution<Transaction<InputType, ResponseInnerType, MiscRespType>, ResponseInnerType, MiscRespType>} executionFunc - The execution function to be executed.
|
|
127
62
|
* @returns {Promise<Response<ResponseInnerType | ResponseErrorType> | MiscRespType>} - A promise that resolves to the response or miscellaneous response.
|
|
128
63
|
*/
|
|
129
|
-
|
|
130
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
case 0: return [4 /*yield*/, this.iexecute(executionFunc)];
|
|
142
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
}); })];
|
|
146
|
-
case 1:
|
|
147
|
-
_a.sent();
|
|
148
|
-
return [2 /*return*/];
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
}); })
|
|
152
|
-
// return raw response if sync return is requested
|
|
153
|
-
];
|
|
154
|
-
case 1:
|
|
155
|
-
_a.sent();
|
|
156
|
-
// return raw response if sync return is requested
|
|
157
|
-
if (this.syncReturn)
|
|
158
|
-
return [2 /*return*/, this.response
|
|
159
|
-
// allow request to async succeed through lambda context
|
|
160
|
-
];
|
|
161
|
-
// allow request to async succeed through lambda context
|
|
162
|
-
return [2 /*return*/, null];
|
|
163
|
-
}
|
|
164
|
-
});
|
|
64
|
+
execute(executionFunc) {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
yield this.executeLoggerFlush(() => __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
yield this.executeDBTransactions(() => __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
return yield this.iexecute(executionFunc);
|
|
69
|
+
}));
|
|
70
|
+
}));
|
|
71
|
+
// return raw response if sync return is requested
|
|
72
|
+
if (this.syncReturn)
|
|
73
|
+
return this.response;
|
|
74
|
+
// allow request to async succeed through lambda context
|
|
75
|
+
return null;
|
|
165
76
|
});
|
|
166
|
-
}
|
|
77
|
+
}
|
|
167
78
|
/**
|
|
168
79
|
* Executes a transaction using the provided execution function and handles the response.
|
|
169
80
|
* @param {TransactionExecution<Transaction<InputType, ResponseInnerType, MiscRespType>, ResponseInnerType, MiscRespType>} executionFunc - The function to execute the transaction.
|
|
170
81
|
* @returns {Promise<boolean>} - A promise that resolves to a boolean indicating whether the execution failed or not.
|
|
171
82
|
*/
|
|
172
|
-
|
|
173
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
case 2:
|
|
190
|
-
_a.response = _b.sent();
|
|
191
|
-
if (!(this.response && this.response instanceof Response_1.default)) return [3 /*break*/, 4];
|
|
192
|
-
return [4 /*yield*/, this.response.build(this.context, this, this.syncReturn)];
|
|
193
|
-
case 3:
|
|
194
|
-
_b.sent();
|
|
195
|
-
executionFailed = !!(this.response.getBody() && this.response.getBody()['rollback']);
|
|
196
|
-
return [3 /*break*/, 7];
|
|
197
|
-
case 4:
|
|
198
|
-
if (!(this.syncReturn && this.response)) return [3 /*break*/, 5];
|
|
199
|
-
this.logger.log('Sync return with different response object');
|
|
200
|
-
this.logger.debug(this.response);
|
|
201
|
-
executionFailed = false;
|
|
202
|
-
return [3 /*break*/, 7];
|
|
203
|
-
case 5:
|
|
204
|
-
this.response = this.getErrorResponse(Globals_1.default.ErrorResponseInvalidServerResponse, Globals_1.default.ErrorCode_APIError);
|
|
205
|
-
return [4 /*yield*/, this.response.build(this.context, this, this.syncReturn)];
|
|
206
|
-
case 6:
|
|
207
|
-
_b.sent();
|
|
208
|
-
this.logger.error('Invalid response object from main request code.');
|
|
209
|
-
_b.label = 7;
|
|
210
|
-
case 7: return [3 /*break*/, 10];
|
|
211
|
-
case 8:
|
|
212
|
-
e_1 = _b.sent();
|
|
213
|
-
/*EXECUTION FAIL*/
|
|
214
|
-
this.logger.error('Exception when executing main request code.');
|
|
215
|
-
this.logger.exception(e_1);
|
|
216
|
-
//retrow?
|
|
217
|
-
if (this.retrowErrors)
|
|
218
|
-
throw e_1;
|
|
219
|
-
//envelope exception?
|
|
220
|
-
this.response = this.getErrorResponse(Globals_1.default.ErrorResponseUnhandledError, Globals_1.default.ErrorCode_APIError);
|
|
221
|
-
return [4 /*yield*/, this.response.build(this.context, this, this.syncReturn)];
|
|
222
|
-
case 9:
|
|
223
|
-
_b.sent();
|
|
224
|
-
return [3 /*break*/, 10];
|
|
225
|
-
case 10: return [2 /*return*/, executionFailed];
|
|
83
|
+
iexecute(executionFunc) {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
let executionFailed = true; //failed til we say no!
|
|
86
|
+
//safe execution handler
|
|
87
|
+
try {
|
|
88
|
+
//Execute
|
|
89
|
+
this.logger.debug('Starting main request code');
|
|
90
|
+
this.response = yield executionFunc(this);
|
|
91
|
+
//Answer client
|
|
92
|
+
if (this.response && this.response instanceof Response) {
|
|
93
|
+
yield this.response.build(this.context, this, this.syncReturn);
|
|
94
|
+
executionFailed = !!(this.response.getBody() && this.response.getBody()['rollback']);
|
|
95
|
+
}
|
|
96
|
+
else if (this.syncReturn && this.response) {
|
|
97
|
+
this.logger.log('Sync return with different response object');
|
|
98
|
+
this.logger.debug(this.response);
|
|
99
|
+
executionFailed = false;
|
|
226
100
|
}
|
|
227
|
-
|
|
101
|
+
else {
|
|
102
|
+
this.response = this.getErrorResponse(Globals.ErrorResponseInvalidServerResponse, Globals.ErrorCode_APIError);
|
|
103
|
+
yield this.response.build(this.context, this, this.syncReturn);
|
|
104
|
+
this.logger.error('Invalid response object from main request code.');
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
catch (e) {
|
|
108
|
+
/*EXECUTION FAIL*/
|
|
109
|
+
this.logger.error('Exception when executing main request code.');
|
|
110
|
+
this.logger.exception(e);
|
|
111
|
+
//retrow?
|
|
112
|
+
if (this.retrowErrors)
|
|
113
|
+
throw e;
|
|
114
|
+
//envelope exception?
|
|
115
|
+
this.response = this.getErrorResponse(Globals.ErrorResponseUnhandledError, Globals.ErrorCode_APIError);
|
|
116
|
+
yield this.response.build(this.context, this, this.syncReturn);
|
|
117
|
+
}
|
|
118
|
+
return executionFailed;
|
|
228
119
|
});
|
|
229
|
-
}
|
|
120
|
+
}
|
|
230
121
|
/**
|
|
231
122
|
* Retrieves a database transaction based on the provided database configuration.
|
|
232
123
|
* @param {DbConfig<S>} config - The configuration object for the database.
|
|
233
124
|
* @returns {Promise<DatabaseTransactionType<S, DBSchema>>} A promise that resolves to the database transaction.
|
|
234
125
|
*/
|
|
235
|
-
|
|
236
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
db = this.getDatabase(config);
|
|
242
|
-
return [4 /*yield*/, db.transaction()];
|
|
243
|
-
case 1:
|
|
244
|
-
dbTrans = _a.sent();
|
|
245
|
-
this.transactions.push(dbTrans);
|
|
246
|
-
return [2 /*return*/, dbTrans];
|
|
247
|
-
}
|
|
248
|
-
});
|
|
126
|
+
getDbTransaction(config) {
|
|
127
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
+
const db = this.getDatabase(config);
|
|
129
|
+
const dbTrans = yield db.transaction();
|
|
130
|
+
this.transactions.push(dbTrans);
|
|
131
|
+
return dbTrans;
|
|
249
132
|
});
|
|
250
|
-
}
|
|
133
|
+
}
|
|
251
134
|
/**
|
|
252
135
|
* Retrieves a database instance based on the provided configuration.
|
|
253
136
|
* @param {DbConfig<S>} config - The configuration object specifying the type of database.
|
|
254
137
|
* @returns {DatabaseImplType<S, DBSchema>} A database instance based on the provided configuration.
|
|
255
138
|
*/
|
|
256
|
-
|
|
139
|
+
getDatabase(config) {
|
|
257
140
|
return this.databaseManager.create(config);
|
|
258
|
-
}
|
|
141
|
+
}
|
|
259
142
|
/*
|
|
260
143
|
* Executes a series of database transactions in a safe manner.
|
|
261
144
|
* @param {Function} safeExecution - The function that contains the database transactions to be executed.
|
|
262
145
|
* @returns None
|
|
263
146
|
* @throws {Error} - If an exception occurs during the execution of the transactions and `retrowErrors` is true.
|
|
264
147
|
*/
|
|
265
|
-
|
|
266
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
execFailed = _g.sent();
|
|
276
|
-
_g.label = 2;
|
|
277
|
-
case 2:
|
|
278
|
-
_g.trys.push([2, 9, 10, 11]);
|
|
279
|
-
_a = __values(__spreadArray([], __read(this.transactions), false).reverse()), _b = _a.next();
|
|
280
|
-
_g.label = 3;
|
|
281
|
-
case 3:
|
|
282
|
-
if (!!_b.done) return [3 /*break*/, 8];
|
|
283
|
-
transaction = _b.value;
|
|
284
|
-
_g.label = 4;
|
|
285
|
-
case 4:
|
|
286
|
-
_g.trys.push([4, 6, , 7]);
|
|
287
|
-
return [4 /*yield*/, transaction[execFailed ? 'closeFailure' : 'closeSuccess']()];
|
|
288
|
-
case 5:
|
|
289
|
-
_g.sent();
|
|
290
|
-
return [3 /*break*/, 7];
|
|
291
|
-
case 6:
|
|
292
|
-
e_2 = _g.sent();
|
|
148
|
+
executeDBTransactions(safeExecution) {
|
|
149
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
150
|
+
try {
|
|
151
|
+
// Execute
|
|
152
|
+
const execFailed = yield safeExecution();
|
|
153
|
+
for (const transaction of [...this.transactions].reverse()) {
|
|
154
|
+
try {
|
|
155
|
+
yield transaction[execFailed ? 'closeFailure' : 'closeSuccess']();
|
|
156
|
+
}
|
|
157
|
+
catch (e) {
|
|
293
158
|
// TODO: should we keep committing transactions even if one fails?
|
|
294
159
|
this.logger.error('Exception when closing DB transactions after success.');
|
|
295
|
-
this.logger.exception(
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
|
|
308
|
-
}
|
|
309
|
-
finally { if (e_3) throw e_3.error; }
|
|
310
|
-
return [7 /*endfinally*/];
|
|
311
|
-
case 11: return [3 /*break*/, 23];
|
|
312
|
-
case 12:
|
|
313
|
-
e_4 = _g.sent();
|
|
314
|
-
_g.label = 13;
|
|
315
|
-
case 13:
|
|
316
|
-
_g.trys.push([13, 20, 21, 22]);
|
|
317
|
-
_c = __values(__spreadArray([], __read(this.transactions), false).reverse()), _d = _c.next();
|
|
318
|
-
_g.label = 14;
|
|
319
|
-
case 14:
|
|
320
|
-
if (!!_d.done) return [3 /*break*/, 19];
|
|
321
|
-
transaction = _d.value;
|
|
322
|
-
_g.label = 15;
|
|
323
|
-
case 15:
|
|
324
|
-
_g.trys.push([15, 17, , 18]);
|
|
325
|
-
return [4 /*yield*/, transaction.closeFailure()];
|
|
326
|
-
case 16:
|
|
327
|
-
_g.sent();
|
|
328
|
-
return [3 /*break*/, 18];
|
|
329
|
-
case 17:
|
|
330
|
-
e_5 = _g.sent();
|
|
160
|
+
this.logger.exception(e);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
catch (e) {
|
|
165
|
+
/* this part of the code handle exceptions at transaction level,
|
|
166
|
+
so probably a bug but we still handle such */
|
|
167
|
+
for (const transaction of [...this.transactions].reverse()) {
|
|
168
|
+
try {
|
|
169
|
+
yield transaction.closeFailure();
|
|
170
|
+
}
|
|
171
|
+
catch (e) {
|
|
331
172
|
this.logger.error('Exception when closing DB transactions after failure.');
|
|
332
|
-
this.logger.exception(
|
|
333
|
-
|
|
334
|
-
case 18:
|
|
335
|
-
_d = _c.next();
|
|
336
|
-
return [3 /*break*/, 14];
|
|
337
|
-
case 19: return [3 /*break*/, 22];
|
|
338
|
-
case 20:
|
|
339
|
-
e_6_1 = _g.sent();
|
|
340
|
-
e_6 = { error: e_6_1 };
|
|
341
|
-
return [3 /*break*/, 22];
|
|
342
|
-
case 21:
|
|
343
|
-
try {
|
|
344
|
-
if (_d && !_d.done && (_f = _c.return)) _f.call(_c);
|
|
345
|
-
}
|
|
346
|
-
finally { if (e_6) throw e_6.error; }
|
|
347
|
-
return [7 /*endfinally*/];
|
|
348
|
-
case 22:
|
|
349
|
-
this.logger.error('Exception when executing DB transactions.');
|
|
350
|
-
this.logger.log(e_4.stack);
|
|
351
|
-
//retrow?
|
|
352
|
-
if (this.retrowErrors)
|
|
353
|
-
throw e_4;
|
|
354
|
-
return [3 /*break*/, 23];
|
|
355
|
-
case 23: return [2 /*return*/];
|
|
173
|
+
this.logger.exception(e);
|
|
174
|
+
}
|
|
356
175
|
}
|
|
357
|
-
|
|
176
|
+
this.logger.error('Exception when executing DB transactions.');
|
|
177
|
+
this.logger.log(e.stack);
|
|
178
|
+
//retrow?
|
|
179
|
+
if (this.retrowErrors)
|
|
180
|
+
throw e;
|
|
181
|
+
}
|
|
358
182
|
});
|
|
359
|
-
}
|
|
183
|
+
}
|
|
360
184
|
/**
|
|
361
185
|
* Executes a logger flush operation with error handling and logging.
|
|
362
186
|
* @param {Function} safeExecution - The function to execute safely.
|
|
363
187
|
* @returns None
|
|
364
188
|
* @throws {Error} - If `retrowErrors` is true and an error occurs during execution.
|
|
365
189
|
*/
|
|
366
|
-
|
|
367
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
//retrow?
|
|
382
|
-
if (this.retrowErrors)
|
|
383
|
-
throw e_7;
|
|
384
|
-
return [3 /*break*/, 4];
|
|
385
|
-
case 3:
|
|
386
|
-
this.logger.debug('Transaction ended');
|
|
387
|
-
return [7 /*endfinally*/];
|
|
388
|
-
case 4: return [2 /*return*/];
|
|
389
|
-
}
|
|
390
|
-
});
|
|
190
|
+
executeLoggerFlush(safeExecution) {
|
|
191
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
192
|
+
try {
|
|
193
|
+
yield safeExecution();
|
|
194
|
+
}
|
|
195
|
+
catch (e) {
|
|
196
|
+
this.logger.error('Exception when flushing logs.');
|
|
197
|
+
this.logger.exception(e);
|
|
198
|
+
//retrow?
|
|
199
|
+
if (this.retrowErrors)
|
|
200
|
+
throw e;
|
|
201
|
+
}
|
|
202
|
+
finally {
|
|
203
|
+
this.logger.debug('Transaction ended');
|
|
204
|
+
}
|
|
391
205
|
});
|
|
392
|
-
}
|
|
206
|
+
}
|
|
393
207
|
/**
|
|
394
208
|
* Returns an error response with the specified error message and error code.
|
|
395
209
|
* @param {string} error - The error message.
|
|
396
210
|
* @param {string} code - The error code.
|
|
397
211
|
* @returns {Response<ResponseErrorType>} - The error response.
|
|
398
212
|
*/
|
|
399
|
-
|
|
400
|
-
return
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
}());
|
|
404
|
-
exports.default = Transaction;
|
|
213
|
+
getErrorResponse(error, code) {
|
|
214
|
+
return Response.BadRequestResponseWithRollback(error, code);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
405
217
|
//# sourceMappingURL=Transaction.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Transaction.js","sourceRoot":"","sources":["../../../src/BaseEvent/Transaction.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Transaction.js","sourceRoot":"","sources":["../../../src/BaseEvent/Transaction.ts"],"names":[],"mappings":";;;;;;;;;AAEA,OAAO,OAAO,MAAM,gBAAgB,CAAA;AACpC,OAAO,QAA+B,MAAM,iBAAiB,CAAA;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAA;AAQ7D,OAAO,OAAO,MAAM,YAAY,CAAA;AAChC,OAAO,MAAwB,MAAM,kBAAkB,CAAA;AACvD,OAAO,SAA8B,MAAM,wBAAwB,CAAA;AAgCnE;;;;;GAKG;AACH,MAAM,CAAC,OAAO,OAAO,WAAW;IA8D9B;;;;;;OAMG;IACH,YAAY,KAAiC,EAAE,OAAgB,EAAE,MAA0B;QA9D3F;;WAEG;QACK,oBAAe,GAAoB,eAAe,CAAC,QA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