@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,25 +1,12 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __values = (this && this.__values) || function(o) {
|
|
3
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
4
|
-
if (m) return m.call(o);
|
|
5
|
-
if (o && typeof o.length === "number") return {
|
|
6
|
-
next: function () {
|
|
7
|
-
if (o && i >= o.length) o = void 0;
|
|
8
|
-
return { value: o && o[i++], done: !o };
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
1
|
/**
|
|
15
2
|
* Represents a collection of routes that can be added and resolved.
|
|
16
3
|
*/
|
|
17
|
-
|
|
4
|
+
class Routes {
|
|
18
5
|
/**
|
|
19
6
|
* Initializes a new instance of the class.
|
|
20
7
|
* @constructor
|
|
21
8
|
*/
|
|
22
|
-
|
|
9
|
+
constructor() {
|
|
23
10
|
this.next = {};
|
|
24
11
|
}
|
|
25
12
|
/**
|
|
@@ -29,8 +16,8 @@ var Routes = /** @class */ (function () {
|
|
|
29
16
|
* @returns None
|
|
30
17
|
* @throws {Error} If a duplicate route is detected.
|
|
31
18
|
*/
|
|
32
|
-
|
|
33
|
-
|
|
19
|
+
addRoute(route, parts) {
|
|
20
|
+
const first = parts.shift();
|
|
34
21
|
if (first) {
|
|
35
22
|
if (first.startsWith(':')) {
|
|
36
23
|
this.variable = this.variable || new Routes();
|
|
@@ -43,18 +30,18 @@ var Routes = /** @class */ (function () {
|
|
|
43
30
|
}
|
|
44
31
|
else {
|
|
45
32
|
if (this.current)
|
|
46
|
-
throw new Error(
|
|
33
|
+
throw new Error(`Duplicate route: ${route.method}: ${route.path}`);
|
|
47
34
|
this.current = route;
|
|
48
35
|
}
|
|
49
|
-
}
|
|
36
|
+
}
|
|
50
37
|
/**
|
|
51
38
|
* Resolves a route based on the given parts.
|
|
52
39
|
* @param {string[]} parts - An array of route parts.
|
|
53
40
|
* @returns {Route} The resolved route.
|
|
54
41
|
*/
|
|
55
|
-
|
|
42
|
+
resolveRoute(parts) {
|
|
56
43
|
var _a;
|
|
57
|
-
|
|
44
|
+
const first = parts.shift();
|
|
58
45
|
if (first) {
|
|
59
46
|
if (first in this.next) {
|
|
60
47
|
return this.next[first].resolveRoute(parts);
|
|
@@ -62,20 +49,19 @@ var Routes = /** @class */ (function () {
|
|
|
62
49
|
return (_a = this.variable) === null || _a === void 0 ? void 0 : _a.resolveRoute(parts);
|
|
63
50
|
}
|
|
64
51
|
return this.current;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
}());
|
|
52
|
+
}
|
|
53
|
+
}
|
|
68
54
|
/**
|
|
69
55
|
* A class that resolves routes based on the provided configuration.
|
|
70
56
|
* @class RouteResolver
|
|
71
57
|
*/
|
|
72
|
-
|
|
58
|
+
export default class RouteResolver {
|
|
73
59
|
/**
|
|
74
60
|
* Constructs a new instance of the Router class with the given configuration.
|
|
75
61
|
* @param {RouterConfig} config - The configuration object for the router.
|
|
76
62
|
* @returns None
|
|
77
63
|
*/
|
|
78
|
-
|
|
64
|
+
constructor(config) {
|
|
79
65
|
this.config = config;
|
|
80
66
|
this.routes = {};
|
|
81
67
|
this.buildRoutes(config);
|
|
@@ -86,35 +72,22 @@ var RouteResolver = /** @class */ (function () {
|
|
|
86
72
|
* @param {string} path - The path of the request.
|
|
87
73
|
* @returns {Route | undefined} - The resolved route or undefined if no route is found.
|
|
88
74
|
*/
|
|
89
|
-
|
|
75
|
+
resolveRoute(method, path) {
|
|
90
76
|
var _a;
|
|
91
|
-
|
|
77
|
+
const parts = path.split('/').filter(p => p.length);
|
|
92
78
|
return (_a = this.routes[method]) === null || _a === void 0 ? void 0 : _a.resolveRoute(parts);
|
|
93
|
-
}
|
|
79
|
+
}
|
|
94
80
|
/**
|
|
95
81
|
* Builds the routes for the router based on the given configuration.
|
|
96
82
|
* @param {RouterConfig} config - The router configuration object.
|
|
97
83
|
* @returns None
|
|
98
84
|
*/
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
var parts = route.path.split('/').filter(function (p) { return p.length; });
|
|
105
|
-
this.routes[route.method] = this.routes[route.method] || new Routes();
|
|
106
|
-
this.routes[route.method].addRoute(route, parts);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
110
|
-
finally {
|
|
111
|
-
try {
|
|
112
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
113
|
-
}
|
|
114
|
-
finally { if (e_1) throw e_1.error; }
|
|
85
|
+
buildRoutes(config) {
|
|
86
|
+
for (const route of config.routes) {
|
|
87
|
+
const parts = route.path.split('/').filter(p => p.length);
|
|
88
|
+
this.routes[route.method] = this.routes[route.method] || new Routes();
|
|
89
|
+
this.routes[route.method].addRoute(route, parts);
|
|
115
90
|
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
}());
|
|
119
|
-
exports.default = RouteResolver;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
120
93
|
//# sourceMappingURL=RouteResolver.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RouteResolver.js","sourceRoot":"","sources":["../../../src/Server/RouteResolver.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"RouteResolver.js","sourceRoot":"","sources":["../../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
-
var Server_1 = require("./lib/Server");
|
|
5
|
-
var Utils_1 = require("../Util/Utils");
|
|
1
|
+
import ContainerServer from './lib/ContainerServer';
|
|
2
|
+
import Server from './lib/Server';
|
|
3
|
+
import Utils from '../Util/Utils';
|
|
6
4
|
/**
|
|
7
5
|
* Represents a router that handles routing logic for a web application.
|
|
8
6
|
*/
|
|
9
|
-
|
|
7
|
+
export default class Router {
|
|
10
8
|
/**
|
|
11
9
|
* Constructs a new instance of the Router class.
|
|
12
10
|
* @param {RouterConfig} config - The configuration object for the router.
|
|
13
11
|
* @returns None
|
|
14
12
|
*/
|
|
15
|
-
|
|
13
|
+
constructor(config) {
|
|
16
14
|
this.config = config;
|
|
17
|
-
this.server = this.isContainer() ? new
|
|
15
|
+
this.server = this.isContainer() ? new ContainerServer(config) : new Server(config);
|
|
18
16
|
}
|
|
19
17
|
/**
|
|
20
18
|
* Retrieves the export function from the server.
|
|
21
19
|
* @returns {CallableFunction} The export function from the server.
|
|
22
20
|
*/
|
|
23
|
-
|
|
21
|
+
getExport() {
|
|
24
22
|
return this.server.getExport();
|
|
25
|
-
}
|
|
23
|
+
}
|
|
26
24
|
/**
|
|
27
25
|
* Checks if the current element is a container.
|
|
28
26
|
* @returns {boolean} - True if the element is a container, false otherwise.
|
|
29
27
|
*/
|
|
30
|
-
|
|
31
|
-
return
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
}());
|
|
35
|
-
exports.default = Router;
|
|
28
|
+
isContainer() {
|
|
29
|
+
return Utils.isHybridlessContainer();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
36
32
|
//# sourceMappingURL=Router.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Router.js","sourceRoot":"","sources":["../../../src/Server/Router.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Router.js","sourceRoot":"","sources":["../../../src/Server/Router.ts"],"names":[],"mappings":"AAKA,OAAO,eAAe,MAAM,uBAAuB,CAAA;AACnD,OAAO,MAAM,MAAM,cAAc,CAAA;AAQjC,OAAO,KAAK,MAAM,eAAe,CAAA;AA4HjC;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,MAAM;IAUzB;;;;OAIG;IACH,YAAY,MAAoB;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,CAAA;IACrF,CAAC;IAED;;;OAGG;IACI,SAAS;QACd,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAA;IAChC,CAAC;IAED;;;OAGG;IACK,WAAW;QACjB,OAAO,KAAK,CAAC,qBAAqB,EAAE,CAAA;IACtC,CAAC;CACF"}
|
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -23,106 +7,60 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
23
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
8
|
});
|
|
25
9
|
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
-
function step(op) {
|
|
31
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
33
|
-
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;
|
|
34
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
-
switch (op[0]) {
|
|
36
|
-
case 0: case 1: t = op; break;
|
|
37
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
-
default:
|
|
41
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
-
if (t[2]) _.ops.pop();
|
|
46
|
-
_.trys.pop(); continue;
|
|
47
|
-
}
|
|
48
|
-
op = body.call(thisArg, _);
|
|
49
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
-
var Proxy_1 = require("./container/Proxy");
|
|
55
|
-
var Server_1 = require("./Server");
|
|
10
|
+
import Proxy from './container/Proxy';
|
|
11
|
+
import Server from './Server';
|
|
56
12
|
/**
|
|
57
13
|
* Represents a server container that extends the Server class and handles serverless events.
|
|
58
14
|
*/
|
|
59
|
-
|
|
60
|
-
__extends(ContainerServer, _super);
|
|
15
|
+
export default class ContainerServer extends Server {
|
|
61
16
|
/**
|
|
62
17
|
* Constructs a new instance of the Router class.
|
|
63
18
|
* @param {RouterConfig} config - The configuration object for the router.
|
|
64
19
|
* @returns None
|
|
65
20
|
*/
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return _this;
|
|
21
|
+
constructor(config) {
|
|
22
|
+
super(config);
|
|
23
|
+
this.proxy = new Proxy(config, this.handleServerlessEvent.bind(this));
|
|
24
|
+
this.listenProcessEvents();
|
|
71
25
|
}
|
|
72
26
|
/**
|
|
73
27
|
* Returns a callable function that can be used to export data.
|
|
74
28
|
* @returns {CallableFunction} - A callable function that can be used to export data.
|
|
75
29
|
*/
|
|
76
|
-
|
|
30
|
+
getExport() {
|
|
77
31
|
// start server socket
|
|
78
32
|
this.start();
|
|
79
33
|
// return empty function, we are all done
|
|
80
|
-
return
|
|
81
|
-
}
|
|
34
|
+
return () => { };
|
|
35
|
+
}
|
|
82
36
|
/**
|
|
83
37
|
* Starts the application by loading the proxy.
|
|
84
38
|
* @returns {Promise<void>} - A promise that resolves when the proxy is loaded.
|
|
85
39
|
*/
|
|
86
|
-
|
|
87
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
88
|
-
|
|
89
|
-
switch (_a.label) {
|
|
90
|
-
case 0: return [4 /*yield*/, this.proxy.load()];
|
|
91
|
-
case 1:
|
|
92
|
-
_a.sent();
|
|
93
|
-
return [2 /*return*/];
|
|
94
|
-
}
|
|
95
|
-
});
|
|
40
|
+
start() {
|
|
41
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
yield this.proxy.load();
|
|
96
43
|
});
|
|
97
|
-
}
|
|
44
|
+
}
|
|
98
45
|
/**
|
|
99
46
|
* Stops the execution of the program and unloads the proxy.
|
|
100
47
|
* @param {any} [err] - Optional error object to pass to the unload method.
|
|
101
48
|
* @returns {Promise<void>} - A promise that resolves once the proxy is unloaded.
|
|
102
49
|
*/
|
|
103
|
-
|
|
104
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
105
|
-
|
|
106
|
-
switch (_a.label) {
|
|
107
|
-
case 0: return [4 /*yield*/, this.proxy.unload(err)];
|
|
108
|
-
case 1:
|
|
109
|
-
_a.sent();
|
|
110
|
-
return [2 /*return*/];
|
|
111
|
-
}
|
|
112
|
-
});
|
|
50
|
+
stop(err) {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
yield this.proxy.unload(err);
|
|
113
53
|
});
|
|
114
|
-
}
|
|
54
|
+
}
|
|
115
55
|
/**
|
|
116
56
|
* Listens for process events and handles them accordingly.
|
|
117
57
|
* @private
|
|
118
58
|
* @returns None
|
|
119
59
|
*/
|
|
120
|
-
|
|
60
|
+
listenProcessEvents() {
|
|
121
61
|
// start process listeners
|
|
122
62
|
process.on('unhandledRejection', this.stop.bind(this)); // listen to exceptions
|
|
123
63
|
process.on('SIGINT', this.stop.bind(this)); // listen on SIGINT signal and gracefully stop the server
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
}(Server_1.default));
|
|
127
|
-
exports.default = ContainerServer;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
128
66
|
//# sourceMappingURL=ContainerServer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContainerServer.js","sourceRoot":"","sources":["../../../../src/Server/lib/ContainerServer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ContainerServer.js","sourceRoot":"","sources":["../../../../src/Server/lib/ContainerServer.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,KAAK,MAAM,mBAAmB,CAAA;AACrC,OAAO,MAAM,MAAM,UAAU,CAAA;AAG7B;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,MAAM;IAQjD;;;;OAIG;IACH,YAAY,MAAoB;QAC9B,KAAK,CAAC,MAAM,CAAC,CAAA;QACb,IAAI,CAAC,KAAK,GAAG,IAAI,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;QACrE,IAAI,CAAC,mBAAmB,EAAE,CAAA;IAC5B,CAAC;IAED;;;OAGG;IACI,SAAS;QACd,sBAAsB;QACtB,IAAI,CAAC,KAAK,EAAE,CAAA;QACZ,yCAAyC;QACzC,OAAO,GAAG,EAAE,GAAE,CAAC,CAAA;IACjB,CAAC;IAED;;;OAGG;IACU,KAAK;;YAChB,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAA;QACzB,CAAC;KAAA;IAED;;;;OAIG;IACU,IAAI,CAAC,GAAS;;YACzB,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QAC9B,CAAC;KAAA;IAED;;;;OAIG;IACK,mBAAmB;QACzB,0BAA0B;QAC1B,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA,CAAC,uBAAuB;QAC9E,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA,CAAC,yDAAyD;IACtG,CAAC;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,133 +7,85 @@ 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
|
-
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 path_to_regexp_1 = require("path-to-regexp");
|
|
40
|
-
var Response_1 = require("../../API/Response");
|
|
41
|
-
var Transaction_1 = require("../../BaseEvent/Transaction");
|
|
42
|
-
var Validator_1 = require("../../Validation/Validator");
|
|
43
|
-
var RouteResolver_1 = require("../RouteResolver");
|
|
10
|
+
import { pathToRegexp } from 'path-to-regexp';
|
|
11
|
+
import Response from '../../API/Response';
|
|
12
|
+
import Transaction from '../../BaseEvent/Transaction';
|
|
13
|
+
import Validator from '../../Validation/Validator';
|
|
14
|
+
import RouteResolver from '../RouteResolver';
|
|
44
15
|
/**
|
|
45
16
|
* Represents a server that handles serverless events and routes them to appropriate handlers.
|
|
46
17
|
*/
|
|
47
|
-
|
|
18
|
+
export default class Server {
|
|
48
19
|
/**
|
|
49
20
|
* Constructs a new instance of the Router class.
|
|
50
21
|
* @param {RouterConfig} config - The configuration object for the router.
|
|
51
22
|
* @returns None
|
|
52
23
|
*/
|
|
53
|
-
|
|
24
|
+
constructor(config) {
|
|
54
25
|
this.config = config;
|
|
55
|
-
this.routeResolver = new
|
|
26
|
+
this.routeResolver = new RouteResolver(config);
|
|
56
27
|
}
|
|
57
28
|
/**
|
|
58
29
|
* Returns a callable function that is bound to the `handleServerlessEvent` method of the current object.
|
|
59
30
|
* @returns {CallableFunction} - A callable function that is bound to the `handleServerlessEvent` method.
|
|
60
31
|
*/
|
|
61
|
-
|
|
32
|
+
getExport() {
|
|
62
33
|
return this.handleServerlessEvent.bind(this);
|
|
63
|
-
}
|
|
34
|
+
}
|
|
64
35
|
/**
|
|
65
36
|
* Handles a serverless event by executing a transaction and resolving the route based on the event.
|
|
66
37
|
* @param {APIGatewayProxyEvent} event - The serverless event object.
|
|
67
38
|
* @param {Context} context - The serverless context object.
|
|
68
39
|
* @returns None
|
|
69
40
|
*/
|
|
70
|
-
|
|
71
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
// Validate path
|
|
101
|
-
if (route.pathSchema) {
|
|
102
|
-
validationResp = Validator_1.default.validateSchema(request.getPathParams(), route.pathSchema);
|
|
103
|
-
if (validationResp && validationResp instanceof Response_1.default)
|
|
104
|
-
return [2 /*return*/, validationResp];
|
|
105
|
-
}
|
|
106
|
-
return [4 /*yield*/, route.handler(transaction)];
|
|
107
|
-
case 1:
|
|
108
|
-
// Continue to route handler
|
|
109
|
-
return [2 /*return*/, _a.sent()];
|
|
110
|
-
case 2:
|
|
111
|
-
//No route found :/
|
|
112
|
-
return [2 /*return*/, new Response_1.default(404, { err: 'Route not found!' })];
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
}); })];
|
|
116
|
-
case 1:
|
|
117
|
-
// init transaction
|
|
118
|
-
_a.sent();
|
|
119
|
-
return [2 /*return*/];
|
|
41
|
+
handleServerlessEvent(event, context) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
// init transaction
|
|
44
|
+
yield new Transaction(event, context, this.config).execute((transaction) => __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
const request = transaction.request;
|
|
46
|
+
const route = this.routeResolver.resolveRoute(request.getMethod(), request.getPath());
|
|
47
|
+
if (route) {
|
|
48
|
+
transaction.logger.log('Router accepted route:', route.path);
|
|
49
|
+
// Validate input
|
|
50
|
+
if (route.inputSchema) {
|
|
51
|
+
const validationResp = Validator.validateSchema(request.getBody(), route.inputSchema);
|
|
52
|
+
if (validationResp && validationResp instanceof Response)
|
|
53
|
+
return validationResp;
|
|
54
|
+
}
|
|
55
|
+
// Validate query
|
|
56
|
+
if (route.querySchema) {
|
|
57
|
+
const validationResp = Validator.validateSchema(request.getQueryParams(), route.querySchema);
|
|
58
|
+
if (validationResp && validationResp instanceof Response)
|
|
59
|
+
return validationResp;
|
|
60
|
+
}
|
|
61
|
+
// parse before validating
|
|
62
|
+
this.parsePathParams(request, route.path);
|
|
63
|
+
// Validate path
|
|
64
|
+
if (route.pathSchema) {
|
|
65
|
+
const validationResp = Validator.validateSchema(request.getPathParams(), route.pathSchema);
|
|
66
|
+
if (validationResp && validationResp instanceof Response)
|
|
67
|
+
return validationResp;
|
|
68
|
+
}
|
|
69
|
+
// Continue to route handler
|
|
70
|
+
return yield route.handler(transaction);
|
|
120
71
|
}
|
|
121
|
-
|
|
72
|
+
//No route found :/
|
|
73
|
+
return new Response(404, { err: 'Route not found!' });
|
|
74
|
+
}));
|
|
122
75
|
});
|
|
123
|
-
}
|
|
76
|
+
}
|
|
124
77
|
/**
|
|
125
78
|
* Parses the path parameters from the request URL based on the given route path.
|
|
126
79
|
* @param {Request<any>} req - The request object.
|
|
127
80
|
* @param {string} routePath - The route path pattern to match against.
|
|
128
81
|
* @returns None
|
|
129
82
|
*/
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
83
|
+
parsePathParams(req, routePath) {
|
|
84
|
+
const path = req.getPath();
|
|
85
|
+
const keys = [];
|
|
86
|
+
const result = pathToRegexp(routePath, keys).exec(path);
|
|
134
87
|
if (result)
|
|
135
88
|
req.setFixedPathParams(keys, result);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
}());
|
|
139
|
-
exports.default = Server;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
140
91
|
//# sourceMappingURL=Server.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Server.js","sourceRoot":"","sources":["../../../../src/Server/lib/Server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Server.js","sourceRoot":"","sources":["../../../../src/Server/lib/Server.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAG7C,OAAO,QAA+B,MAAM,oBAAoB,CAAA;AAChE,OAAO,WAA0B,MAAM,6BAA6B,CAAA;AACpE,OAAO,SAAS,MAAM,4BAA4B,CAAA;AAElD,OAAO,aAAa,MAAM,kBAAkB,CAAA;AAE5C;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,MAAM;IAczB;;;;OAIG;IACH,YAAY,MAAoB;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,aAAa,GAAG,IAAI,aAAa,CAAC,MAAM,CAAC,CAAA;IAChD,CAAC;IAED;;;OAGG;IACI,SAAS;QACd,OAAO,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC9C,CAAC;IAED;;;;;OAKG;IACU,qBAAqB,CAAC,KAA2B,EAAE,OAAgB;;YAC9E,mBAAmB;YACnB,MAAM,IAAI,WAAW,CACnB,KAAK,EACL,OAAO,EACP,IAAI,CAAC,MAAM,CACZ,CAAC,OAAO,CAAC,CAAM,WAAW,EAAC,EAAE;gBAC5B,MAAM,OAAO,GAAG,WAAW,CAAC,OAAO,CAAA;gBACnC,MAAM,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAA;gBACrF,IAAI,KAAK,EAAE,CAAC;oBACV,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,wBAAwB,EAAE,KAAK,CAAC,IAAI,CAAC,CAAA;oBAC5D,iBAAiB;oBACjB,IAAI,KAAK,CAAC,WAAW,EAAE,CAAC;wBACtB,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