@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,15 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -19,42 +7,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
19
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
8
|
});
|
|
21
9
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
-
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;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
-
var Transaction_1 = require("./Transaction");
|
|
51
|
-
var Response_1 = require("../API/Response");
|
|
52
|
-
var Globals_1 = require("../Globals");
|
|
10
|
+
import Transaction from './Transaction';
|
|
11
|
+
import Response from '../API/Response';
|
|
12
|
+
import Globals from '../Globals';
|
|
53
13
|
/**
|
|
54
14
|
* EventProcessor class that processes events from an SQS queue.
|
|
55
15
|
* @template ResponseInnerType - The type of the inner response object.
|
|
56
16
|
*/
|
|
57
|
-
|
|
17
|
+
export default class EventProcessor {
|
|
58
18
|
/**
|
|
59
19
|
* Constructs a new instance of the class.
|
|
60
20
|
* @param {SQSEvent} event - The event object representing the incoming SQS message.
|
|
@@ -63,7 +23,7 @@ var EventProcessor = /** @class */ (function () {
|
|
|
63
23
|
* @param {boolean} [allowFailure] - Optional flag indicating whether to allow failure for the transaction.
|
|
64
24
|
* @returns None
|
|
65
25
|
*/
|
|
66
|
-
|
|
26
|
+
constructor(event, context, config, allowFailure) {
|
|
67
27
|
this.event = event;
|
|
68
28
|
this.context = context;
|
|
69
29
|
this.config = config || {};
|
|
@@ -76,99 +36,61 @@ var EventProcessor = /** @class */ (function () {
|
|
|
76
36
|
* @returns {Promise<Response<ResponseErrorType> | null | SQSBatchResponse>} - A promise that resolves to the response object, or null if no response is available.
|
|
77
37
|
* @throws {Error} - Throws an error if the response code is not within the range of 200 to 299 and failure is not allowed.
|
|
78
38
|
*/
|
|
79
|
-
|
|
80
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
!(resp.getCode() >= 200 && resp.getCode() < 300))
|
|
91
|
-
throw new Error(JSON.stringify(resp.getBody() || {}));
|
|
92
|
-
else if (resp)
|
|
93
|
-
return [2 /*return*/, resp];
|
|
94
|
-
return [2 /*return*/, null];
|
|
95
|
-
}
|
|
96
|
-
});
|
|
39
|
+
processEvent(execution, doNotDecodeMessage) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
const resp = yield this.processRawEvent(execution, !!doNotDecodeMessage);
|
|
42
|
+
if (!this.allowFailure &&
|
|
43
|
+
resp &&
|
|
44
|
+
resp instanceof Response &&
|
|
45
|
+
!(resp.getCode() >= 200 && resp.getCode() < 300))
|
|
46
|
+
throw new Error(JSON.stringify(resp.getBody() || {}));
|
|
47
|
+
else if (resp)
|
|
48
|
+
return resp;
|
|
49
|
+
return null;
|
|
97
50
|
});
|
|
98
|
-
}
|
|
51
|
+
}
|
|
99
52
|
/**
|
|
100
53
|
* Processes a raw event by executing the provided execution function and handling any errors or failures.
|
|
101
54
|
* @param {EventProcessorExecution<ResponseInnerType>} execution - The execution function to process the event.
|
|
102
55
|
* @param {boolean} doNotDecodeMessage - Flag indicating whether to decode the message or not.
|
|
103
56
|
* @returns {Promise<Response<ResponseErrorType> | null | SQSBatchResponse>} - A promise that resolves to a response object, null, or a SQS batch response.
|
|
104
57
|
*/
|
|
105
|
-
|
|
106
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
if (!resp ||
|
|
141
|
-
(resp instanceof Response_1.default && !((resp === null || resp === void 0 ? void 0 : resp.getCode()) >= 200 && (resp === null || resp === void 0 ? void 0 : resp.getCode()) < 300))) {
|
|
142
|
-
//response with failures or fail hard at first
|
|
143
|
-
if (this.allowFailure)
|
|
144
|
-
failureIDs.push(message.messageId);
|
|
145
|
-
else
|
|
146
|
-
return [2 /*return*/, resp];
|
|
147
|
-
}
|
|
148
|
-
_d.label = 3;
|
|
149
|
-
case 3:
|
|
150
|
-
_i++;
|
|
151
|
-
return [3 /*break*/, 1];
|
|
152
|
-
case 4:
|
|
153
|
-
//not errored and loop ended - succeeded (might have failures)
|
|
154
|
-
if (this.allowFailure)
|
|
155
|
-
return [2 /*return*/, {
|
|
156
|
-
batchItemFailures: failureIDs.map(function (id) { return ({ itemIdentifier: id }); }),
|
|
157
|
-
}];
|
|
158
|
-
return [2 /*return*/, Response_1.default.SuccessResponse(null)];
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
}); })];
|
|
162
|
-
case 1:
|
|
163
|
-
//safe check for empty events?
|
|
164
|
-
//init transaction for all records
|
|
165
|
-
return [2 /*return*/, _a.sent()];
|
|
166
|
-
case 2: return [2 /*return*/, Response_1.default.BadRequestResponse(Globals_1.default.ErrorResponseNoRecords, Globals_1.default.ErrorCode_NoRecords)]; //no event to be processed?
|
|
167
|
-
}
|
|
168
|
-
});
|
|
58
|
+
processRawEvent(execution, doNotDecodeMessage) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
if (this.event.Records && this.event.Records.length > 0) {
|
|
61
|
+
//safe check for empty events?
|
|
62
|
+
//init transaction for all records
|
|
63
|
+
return yield new Transaction(this.event, this.context, Object.assign(Object.assign({}, this.config), { syncReturn: true })).execute((transaction) => __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
//Map records with decoded message when required
|
|
65
|
+
const decodedRecords = this.event.Records.map(eventRecord => doNotDecodeMessage ? eventRecord.body : JSON.parse(eventRecord.body));
|
|
66
|
+
//for each available event
|
|
67
|
+
const failureIDs = [];
|
|
68
|
+
for (const eventRecordIdx in decodedRecords) {
|
|
69
|
+
const eventRecord = decodedRecords[eventRecordIdx];
|
|
70
|
+
const message = this.event.Records[eventRecordIdx];
|
|
71
|
+
//Call execution
|
|
72
|
+
const resp = yield execution(transaction, eventRecord);
|
|
73
|
+
//check for failure
|
|
74
|
+
if (!resp ||
|
|
75
|
+
(resp instanceof Response && !((resp === null || resp === void 0 ? void 0 : resp.getCode()) >= 200 && (resp === null || resp === void 0 ? void 0 : resp.getCode()) < 300))) {
|
|
76
|
+
//response with failures or fail hard at first
|
|
77
|
+
if (this.allowFailure)
|
|
78
|
+
failureIDs.push(message.messageId);
|
|
79
|
+
else
|
|
80
|
+
return resp;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
//not errored and loop ended - succeeded (might have failures)
|
|
84
|
+
if (this.allowFailure)
|
|
85
|
+
return {
|
|
86
|
+
batchItemFailures: failureIDs.map(id => ({ itemIdentifier: id })),
|
|
87
|
+
};
|
|
88
|
+
return Response.SuccessResponse(null);
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
91
|
+
else
|
|
92
|
+
return Response.BadRequestResponse(Globals.ErrorResponseNoRecords, Globals.ErrorCode_NoRecords); //no event to be processed?
|
|
169
93
|
});
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
}());
|
|
173
|
-
exports.default = EventProcessor;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
174
96
|
//# sourceMappingURL=EventProcessor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EventProcessor.js","sourceRoot":"","sources":["../../../src/BaseEvent/EventProcessor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"EventProcessor.js","sourceRoot":"","sources":["../../../src/BaseEvent/EventProcessor.ts"],"names":[],"mappings":";;;;;;;;;AAEA,OAAO,WAAkC,MAAM,eAAe,CAAA;AAC9D,OAAO,QAA+B,MAAM,iBAAiB,CAAA;AAC7D,OAAO,OAAO,MAAM,YAAY,CAAA;AAahC;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,cAAc;IAoBjC;;;;;;;OAOG;IACH,YACE,KAAe,EACf,OAAgB,EAChB,MAA0B,EAC1B,YAAsB;QAEtB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,EAAE,CAAA;QAC1B,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC,YAAY,CAAA;IACpC,CAAC;IAED;;;;;;OAMG;IACG,YAAY,CAChB,SAAqD,EACrD,kBAA4B;;YAE5B,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,SAAS,EAAE,CAAC,CAAC,kB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AC,cAAc,CAAC,CAAA;wBAClD,gBAAgB;wBAChB,MAAM,IAAI,GAAG,MAAM,SAAS,CAAC,WAAW,EAAE,WAAW,CAAC,CAAA;wBACtD,mBAAmB;wBACnB,IACE,CAAC,IAAI;4BACL,CAAC,IAAI,YAAY,QAAQ,IAAI,CAAC,CAAC,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,EAAE,KAAI,GAAG,IAAI,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,EAAE,IAAG,GAAG,CAAC,CAAC,EAChF,CAAC;4BACD,8CAA8C;4BAC9C,IAAI,IAAI,CAAC,YAAY;gCAAE,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;;gCACpD,OAAO,IAAI,CAAA;wBAClB,CAAC;oBACH,CAAC;oBACD,8DAA8D;oBAC9D,IAAI,IAAI,CAAC,YAAY;wBACnB,OAAO;4BACL,iBAAiB,EAAE,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,cAAc,EAAE,EAAE,EAAE,CAAC,CAAC;yBAClE,CAAA;oBACH,OAAO,QAAQ,CAAC,eAAe,CAAC,IAAI,CAAC,CAAA;gBACvC,CAAC,CAAA,CAAC,CAAA;YACJ,CAAC;;gBACC,OAAO,QAAQ,CAAC,kBAAkB,CAChC,OAAO,CAAC,sBAAsB,EAC9B,OAAO,CAAC,mBAAmB,CAC5B,CAAA,CAAC,2BAA2B;QACjC,CAAC;KAAA;CACF"}
|
|
@@ -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,124 +7,67 @@ 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
|
-
return g = { next: verb(0), "throw": verb(1), "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
|
-
var Logger_1 = require("../Logger/Logger");
|
|
40
|
-
var Publisher_1 = require("../Publisher/Publisher");
|
|
10
|
+
import Logger from '../Logger/Logger';
|
|
11
|
+
import Publisher from '../Publisher/Publisher';
|
|
41
12
|
/**
|
|
42
13
|
* Represents a long-running process that executes a given function at a specified interval.
|
|
43
14
|
*/
|
|
44
|
-
|
|
15
|
+
export default class Process {
|
|
45
16
|
/**
|
|
46
17
|
* Constructs a new instance of the LongRunningProcess class.
|
|
47
18
|
* @param {ProcessConfig} config - The configuration object for the process.
|
|
48
19
|
* @param {number} interval - The interval at which the process should run.
|
|
49
20
|
* @returns None
|
|
50
21
|
*/
|
|
51
|
-
|
|
22
|
+
constructor(config, interval) {
|
|
52
23
|
this.interval = interval;
|
|
53
|
-
this.logger = new
|
|
54
|
-
this.publisher = new
|
|
24
|
+
this.logger = new Logger(config.logger, 'long-running-process');
|
|
25
|
+
this.publisher = new Publisher(config.publisher);
|
|
55
26
|
}
|
|
56
27
|
/**
|
|
57
28
|
* Executes the provided execution function at a specified interval.
|
|
58
29
|
* @param {Function} executionFunc - The function to execute.
|
|
59
30
|
* @returns None
|
|
60
31
|
*/
|
|
61
|
-
|
|
62
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return __generator(this, function (_a) {
|
|
71
|
-
switch (_a.label) {
|
|
72
|
-
case 0: return [4 /*yield*/, this.iexecute(executionFunc)];
|
|
73
|
-
case 1:
|
|
74
|
-
_a.sent();
|
|
75
|
-
return [2 /*return*/];
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
}); }, this.interval);
|
|
79
|
-
return [2 /*return*/];
|
|
80
|
-
});
|
|
32
|
+
execute(executionFunc) {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
this.logger.debug('Starting main process code');
|
|
35
|
+
//Connect DB
|
|
36
|
+
// if (this.db) await this.db.connect();
|
|
37
|
+
//Program loop
|
|
38
|
+
this.timeout = setInterval(() => __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
yield this.iexecute(executionFunc);
|
|
40
|
+
}), this.interval);
|
|
81
41
|
});
|
|
82
|
-
}
|
|
42
|
+
}
|
|
83
43
|
/**
|
|
84
44
|
* Executes the given execution function asynchronously and handles any exceptions that occur.
|
|
85
45
|
* @param {Function} executionFunc - The function to execute.
|
|
86
46
|
* @returns {boolean} - Returns true if the execution failed, false otherwise.
|
|
87
47
|
*/
|
|
88
|
-
|
|
89
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
//Execute
|
|
111
|
-
_a.sent();
|
|
112
|
-
//Commit DB
|
|
113
|
-
// if (this.db) await this.db.commit();
|
|
114
|
-
//
|
|
115
|
-
executionFailed = false;
|
|
116
|
-
return [3 /*break*/, 4];
|
|
117
|
-
case 3:
|
|
118
|
-
e_1 = _a.sent();
|
|
119
|
-
/*EXECUTION FAIL*/
|
|
120
|
-
this.logger.error('Exception when executing main process code. Rolling back DB!');
|
|
121
|
-
this.logger.exception(e_1);
|
|
122
|
-
return [3 /*break*/, 4];
|
|
123
|
-
case 4: return [2 /*return*/, executionFailed];
|
|
124
|
-
}
|
|
125
|
-
});
|
|
48
|
+
iexecute(executionFunc) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
let executionFailed = true; //failled til we say no!
|
|
51
|
+
//safe execution handler
|
|
52
|
+
try {
|
|
53
|
+
//start DB transaction
|
|
54
|
+
// if (this.db) await this.db.beginTransaction();
|
|
55
|
+
//Execute
|
|
56
|
+
yield executionFunc(this);
|
|
57
|
+
//Commit DB
|
|
58
|
+
// if (this.db) await this.db.commit();
|
|
59
|
+
//
|
|
60
|
+
executionFailed = false;
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
/*EXECUTION FAIL*/
|
|
64
|
+
this.logger.error('Exception when executing main process code. Rolling back DB!');
|
|
65
|
+
this.logger.exception(e);
|
|
66
|
+
//Rollback DB
|
|
67
|
+
// if (this.db) await this.db.rollback();
|
|
68
|
+
}
|
|
69
|
+
return executionFailed;
|
|
126
70
|
});
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
}());
|
|
130
|
-
exports.default = Process;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
131
73
|
//# sourceMappingURL=Process.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Process.js","sourceRoot":"","sources":["../../../src/BaseEvent/Process.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Process.js","sourceRoot":"","sources":["../../../src/BaseEvent/Process.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,MAAM,MAAM,kBAAkB,CAAA;AACrC,OAAO,SAAS,MAAM,wBAAwB,CAAA;AAO9C;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,OAAO;IAqB1B;;;;;OAKG;IACH,YAAY,MAAqB,EAAE,QAAgB;QACjD,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAA;QAC/D,IAAI,CAAC,SAAS,GAAG,IAAI,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;IAClD,CAAC;IAED;;;;OAIG;IACU,OAAO,CAAC,aAAa;;YAChC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,4BAA4B,CAAC,CAAA;YA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