@creator.co/wapi 1.2.3 → 1.2.5
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 +2 -5
- package/README.md +1 -3
- package/dist/index.d.ts +11 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/jest.config.d.ts +3 -0
- package/dist/jest.config.js +34 -0
- package/dist/jest.config.js.map +1 -0
- package/dist/package.json +70 -0
- package/dist/src/API/Request.d.ts +140 -0
- package/dist/src/API/Request.js +182 -0
- package/dist/src/API/Request.js.map +1 -0
- package/dist/src/API/Response.d.ts +256 -0
- package/dist/src/API/Response.js +398 -0
- package/dist/src/API/Response.js.map +1 -0
- package/dist/src/API/Utils.d.ts +63 -0
- package/dist/src/API/Utils.js +104 -0
- package/dist/src/API/Utils.js.map +1 -0
- package/dist/src/BaseEvent/EventProcessor.d.ts +81 -0
- package/dist/src/BaseEvent/EventProcessor.js +182 -0
- package/dist/src/BaseEvent/EventProcessor.js.map +1 -0
- package/dist/src/BaseEvent/Process.d.ts +74 -0
- package/dist/src/BaseEvent/Process.js +142 -0
- package/dist/src/BaseEvent/Process.js.map +1 -0
- package/dist/src/BaseEvent/Transaction.d.ts +39 -0
- package/dist/src/BaseEvent/Transaction.js +354 -0
- package/dist/src/BaseEvent/Transaction.js.map +1 -0
- package/dist/src/Config/Configuration.d.ts +131 -0
- package/dist/src/Config/Configuration.js +153 -0
- package/dist/src/Config/Configuration.js.map +1 -0
- package/dist/src/Config/EnvironmentVar.d.ts +101 -0
- package/dist/src/Config/EnvironmentVar.js +213 -0
- package/dist/src/Config/EnvironmentVar.js.map +1 -0
- package/dist/src/Crypto/Crypto.d.ts +57 -0
- package/dist/src/Crypto/Crypto.js +126 -0
- package/dist/src/Crypto/Crypto.js.map +1 -0
- package/dist/src/Crypto/JWT.d.ts +64 -0
- package/dist/src/Crypto/JWT.js +74 -0
- package/dist/src/Crypto/JWT.js.map +1 -0
- package/dist/src/Database/Database.d.ts +18 -0
- package/dist/src/Database/Database.js +18 -0
- package/dist/src/Database/Database.js.map +1 -0
- package/dist/src/Database/DatabaseManager.d.ts +32 -0
- package/dist/src/Database/DatabaseManager.js +50 -0
- package/dist/src/Database/DatabaseManager.js.map +1 -0
- package/dist/src/Database/DatabaseTransaction.d.ts +65 -0
- package/dist/src/Database/DatabaseTransaction.js +183 -0
- package/dist/src/Database/DatabaseTransaction.js.map +1 -0
- package/dist/src/Database/integrations/knex/KnexDatabase.d.ts +22 -0
- package/dist/src/Database/integrations/knex/KnexDatabase.js +108 -0
- package/dist/src/Database/integrations/knex/KnexDatabase.js.map +1 -0
- package/dist/src/Database/integrations/knex/KnexTransaction.d.ts +37 -0
- package/dist/src/Database/integrations/knex/KnexTransaction.js +60 -0
- package/dist/src/Database/integrations/knex/KnexTransaction.js.map +1 -0
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.d.ts +30 -0
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.js +108 -0
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.js.map +1 -0
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.d.ts +37 -0
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.js +60 -0
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.js.map +1 -0
- package/dist/src/Globals.d.ts +161 -0
- package/dist/src/Globals.js +173 -0
- package/dist/src/Globals.js.map +1 -0
- package/dist/src/Logger/Logger.d.ts +180 -0
- package/dist/src/Logger/Logger.js +412 -0
- package/dist/src/Logger/Logger.js.map +1 -0
- package/dist/src/Mailer/Mailer.d.ts +107 -0
- package/dist/src/Mailer/Mailer.js +313 -0
- package/dist/src/Mailer/Mailer.js.map +1 -0
- package/dist/src/Publisher/Publisher.d.ts +47 -0
- package/dist/src/Publisher/Publisher.js +141 -0
- package/dist/src/Publisher/Publisher.js.map +1 -0
- package/dist/src/Server/RouteResolver.d.ts +41 -0
- package/dist/src/Server/RouteResolver.js +135 -0
- package/dist/src/Server/RouteResolver.js.map +1 -0
- package/dist/src/Server/Router.d.ts +104 -0
- package/dist/src/Server/Router.js +45 -0
- package/dist/src/Server/Router.js.map +1 -0
- package/dist/src/Server/lib/ContainerServer.d.ts +58 -0
- package/dist/src/Server/lib/ContainerServer.js +143 -0
- package/dist/src/Server/lib/ContainerServer.js.map +1 -0
- package/dist/src/Server/lib/Server.d.ts +60 -0
- package/dist/src/Server/lib/Server.js +137 -0
- package/dist/src/Server/lib/Server.js.map +1 -0
- package/dist/src/Server/lib/container/GenericHandler.d.ts +4 -0
- package/dist/src/Server/lib/container/GenericHandler.js +138 -0
- package/dist/src/Server/lib/container/GenericHandler.js.map +1 -0
- package/dist/src/Server/lib/container/GenericHandlerEvent.d.ts +67 -0
- package/dist/src/Server/lib/container/GenericHandlerEvent.js +189 -0
- package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +1 -0
- package/dist/src/Server/lib/container/HealthHandler.d.ts +3 -0
- package/dist/src/Server/lib/container/HealthHandler.js +45 -0
- package/dist/src/Server/lib/container/HealthHandler.js.map +1 -0
- package/dist/src/Server/lib/container/Proxy.d.ts +95 -0
- package/dist/src/Server/lib/container/Proxy.js +202 -0
- package/dist/src/Server/lib/container/Proxy.js.map +1 -0
- package/dist/src/Server/lib/container/Utils.d.ts +18 -0
- package/dist/src/Server/lib/container/Utils.js +84 -0
- package/dist/src/Server/lib/container/Utils.js.map +1 -0
- package/dist/src/Validation/Validator.d.ts +21 -0
- package/dist/src/Validation/Validator.js +48 -0
- package/dist/src/Validation/Validator.js.map +1 -0
- package/jest.config.ts +2 -9
- package/package.json +10 -4
- package/src/BaseEvent/Transaction.ts +48 -18
- package/src/Database/Database.ts +19 -0
- package/src/Database/DatabaseManager.ts +51 -0
- package/src/Database/DatabaseTransaction.ts +118 -0
- package/src/Database/integrations/knex/KnexDatabase.ts +47 -0
- package/src/Database/integrations/knex/KnexTransaction.ts +51 -0
- package/src/Database/integrations/pgsql/PostgresDatabase.ts +49 -0
- package/src/Database/integrations/pgsql/PostgresTransaction.ts +54 -0
- package/src/Database/types.d.ts +49 -0
- package/src/Server/lib/container/Proxy.ts +2 -1
- package/tests/BaseEvent/Transaction.test.ts +59 -0
- package/tests/Database/DatabaseManager.test.ts +55 -0
- package/tests/Database/integrations/knex/KnexDatabase.test.ts +53 -0
- package/tests/Database/integrations/knex/KnexTransaction.test.ts +133 -0
- package/tests/Database/integrations/pg/PostgresDatabase.test.ts +50 -0
- package/tests/Database/integrations/pg/PostgresTransaction.test.ts +51 -0
- package/tsconfig.json +5 -0
|
@@ -0,0 +1,135 @@
|
|
|
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
|
+
/**
|
|
15
|
+
* ${1:Description placeholder}
|
|
16
|
+
*
|
|
17
|
+
* @class Routes
|
|
18
|
+
* @typedef {Routes}
|
|
19
|
+
*/
|
|
20
|
+
var Routes = /** @class */ (function () {
|
|
21
|
+
/**
|
|
22
|
+
* Creates an instance of Routes.
|
|
23
|
+
*
|
|
24
|
+
* @constructor
|
|
25
|
+
*/
|
|
26
|
+
function Routes() {
|
|
27
|
+
this.next = {};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* ${1:Description placeholder}
|
|
31
|
+
*
|
|
32
|
+
* @public
|
|
33
|
+
* @param {Route} route
|
|
34
|
+
* @param {string[]} parts
|
|
35
|
+
*/
|
|
36
|
+
Routes.prototype.addRoute = function (route, parts) {
|
|
37
|
+
var first = parts.shift();
|
|
38
|
+
if (first) {
|
|
39
|
+
if (first.startsWith(':')) {
|
|
40
|
+
this.variable = this.variable || new Routes();
|
|
41
|
+
this.variable.addRoute(route, parts);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
this.next[first] = this.next[first] || new Routes();
|
|
45
|
+
this.next[first].addRoute(route, parts);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
if (this.current)
|
|
50
|
+
throw new Error("Duplicate route: ".concat(route.method, ": ").concat(route.path));
|
|
51
|
+
this.current = route;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* ${1:Description placeholder}
|
|
56
|
+
*
|
|
57
|
+
* @public
|
|
58
|
+
* @param {string[]} parts
|
|
59
|
+
* @returns {Route}
|
|
60
|
+
*/
|
|
61
|
+
Routes.prototype.resolveRoute = function (parts) {
|
|
62
|
+
var _a;
|
|
63
|
+
var first = parts.shift();
|
|
64
|
+
if (first) {
|
|
65
|
+
if (first in this.next) {
|
|
66
|
+
return this.next[first].resolveRoute(parts);
|
|
67
|
+
}
|
|
68
|
+
return (_a = this.variable) === null || _a === void 0 ? void 0 : _a.resolveRoute(parts);
|
|
69
|
+
}
|
|
70
|
+
return this.current;
|
|
71
|
+
};
|
|
72
|
+
return Routes;
|
|
73
|
+
}());
|
|
74
|
+
/**
|
|
75
|
+
* ${1:Description placeholder}
|
|
76
|
+
*
|
|
77
|
+
* @export
|
|
78
|
+
* @class RouteResolver
|
|
79
|
+
* @typedef {RouteResolver}
|
|
80
|
+
*/
|
|
81
|
+
var RouteResolver = /** @class */ (function () {
|
|
82
|
+
/**
|
|
83
|
+
* Creates an instance of RouteResolver.
|
|
84
|
+
*
|
|
85
|
+
* @constructor
|
|
86
|
+
* @param {RouterConfig} config
|
|
87
|
+
*/
|
|
88
|
+
function RouteResolver(config) {
|
|
89
|
+
this.config = config;
|
|
90
|
+
this.routes = {};
|
|
91
|
+
this.buildRoutes(config);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* ${1:Description placeholder}
|
|
95
|
+
*
|
|
96
|
+
* @public
|
|
97
|
+
* @param {string} method
|
|
98
|
+
* @param {string} path
|
|
99
|
+
* @returns {(Route | undefined)}
|
|
100
|
+
*/
|
|
101
|
+
RouteResolver.prototype.resolveRoute = function (method, path) {
|
|
102
|
+
var _a;
|
|
103
|
+
method = method.toLowerCase();
|
|
104
|
+
var parts = path.split('/').filter(function (p) { return p.length; });
|
|
105
|
+
return (_a = this.routes[method]) === null || _a === void 0 ? void 0 : _a.resolveRoute(parts);
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Description placeholder
|
|
109
|
+
*
|
|
110
|
+
* @private
|
|
111
|
+
* @param {RouterConfig} config
|
|
112
|
+
*/
|
|
113
|
+
RouteResolver.prototype.buildRoutes = function (config) {
|
|
114
|
+
var e_1, _a;
|
|
115
|
+
try {
|
|
116
|
+
for (var _b = __values(config.routes), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
117
|
+
var route = _c.value;
|
|
118
|
+
var method = route.method.toLowerCase();
|
|
119
|
+
var parts = route.path.split('/').filter(function (p) { return p.length; });
|
|
120
|
+
this.routes[method] = this.routes[method] || new Routes();
|
|
121
|
+
this.routes[method].addRoute(route, parts);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
125
|
+
finally {
|
|
126
|
+
try {
|
|
127
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
128
|
+
}
|
|
129
|
+
finally { if (e_1) throw e_1.error; }
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
return RouteResolver;
|
|
133
|
+
}());
|
|
134
|
+
exports.default = RouteResolver;
|
|
135
|
+
//# sourceMappingURL=RouteResolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Rou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M,CAAC,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;aAC3C;;;;;;;;;IACH,CAAC;IACH,oBAAC;AAAD,CAAC,AAlDD,IAkDC"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ResponseErrorType } from '../API/Response';
|
|
3
|
+
import Transaction, { TransactionConfig, TransactionExecution } from '../BaseEvent/Transaction';
|
|
4
|
+
/**
|
|
5
|
+
* Description placeholder
|
|
6
|
+
*
|
|
7
|
+
* @export
|
|
8
|
+
* @interface Route
|
|
9
|
+
* @typedef {Route}
|
|
10
|
+
* @template [InputType=any]
|
|
11
|
+
* @template [OutputType=any]
|
|
12
|
+
*/
|
|
13
|
+
export interface Route<InputType = any, OutputType = any> {
|
|
14
|
+
/**
|
|
15
|
+
* Description placeholder
|
|
16
|
+
*
|
|
17
|
+
* @type {string}
|
|
18
|
+
*/
|
|
19
|
+
path: string;
|
|
20
|
+
/**
|
|
21
|
+
* Description placeholder
|
|
22
|
+
*
|
|
23
|
+
* @type {string}
|
|
24
|
+
*/
|
|
25
|
+
method: string;
|
|
26
|
+
/**
|
|
27
|
+
* Description placeholder
|
|
28
|
+
*
|
|
29
|
+
* @type {TransactionExecution<
|
|
30
|
+
* Transaction<InputType, OutputType | ResponseErrorType>,
|
|
31
|
+
* OutputType | ResponseErrorType
|
|
32
|
+
* >}
|
|
33
|
+
*/
|
|
34
|
+
handler: TransactionExecution<Transaction<InputType, OutputType | ResponseErrorType>, OutputType | ResponseErrorType>;
|
|
35
|
+
/**
|
|
36
|
+
* Description placeholder
|
|
37
|
+
*
|
|
38
|
+
* @type {?z.ZodObject<any>}
|
|
39
|
+
*/
|
|
40
|
+
inputSchema?: z.ZodObject<any>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Description placeholder
|
|
44
|
+
*
|
|
45
|
+
* @export
|
|
46
|
+
* @typedef {RouterConfig}
|
|
47
|
+
*/
|
|
48
|
+
export type RouterConfig = TransactionConfig & {
|
|
49
|
+
routes: Route[];
|
|
50
|
+
port?: number;
|
|
51
|
+
timeout?: number;
|
|
52
|
+
cors?: {
|
|
53
|
+
origin?: string | string[];
|
|
54
|
+
headers?: string[];
|
|
55
|
+
allowCredentials?: boolean;
|
|
56
|
+
};
|
|
57
|
+
healthCheckRoute?: string;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Description placeholder
|
|
61
|
+
*
|
|
62
|
+
* @export
|
|
63
|
+
* @class Router
|
|
64
|
+
* @typedef {Router}
|
|
65
|
+
*/
|
|
66
|
+
export default class Router {
|
|
67
|
+
/**
|
|
68
|
+
* Description placeholder
|
|
69
|
+
*
|
|
70
|
+
* @private
|
|
71
|
+
* @readonly
|
|
72
|
+
* @type {RouterConfig}
|
|
73
|
+
*/
|
|
74
|
+
private readonly config;
|
|
75
|
+
/**
|
|
76
|
+
* Description placeholder
|
|
77
|
+
*
|
|
78
|
+
* @private
|
|
79
|
+
* @readonly
|
|
80
|
+
* @type {Server}
|
|
81
|
+
*/
|
|
82
|
+
private readonly server;
|
|
83
|
+
/**
|
|
84
|
+
* Creates an instance of Router.
|
|
85
|
+
*
|
|
86
|
+
* @constructor
|
|
87
|
+
* @param {RouterConfig} config
|
|
88
|
+
*/
|
|
89
|
+
constructor(config: RouterConfig);
|
|
90
|
+
/**
|
|
91
|
+
* Description placeholder
|
|
92
|
+
*
|
|
93
|
+
* @public
|
|
94
|
+
* @returns {CallableFunction}
|
|
95
|
+
*/
|
|
96
|
+
getExport(): CallableFunction;
|
|
97
|
+
/**
|
|
98
|
+
* Description placeholder
|
|
99
|
+
*
|
|
100
|
+
* @private
|
|
101
|
+
* @returns {boolean}
|
|
102
|
+
*/
|
|
103
|
+
private isContainer;
|
|
104
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var ContainerServer_1 = require("./lib/ContainerServer");
|
|
4
|
+
var Server_1 = require("./lib/Server");
|
|
5
|
+
var Utils_1 = require("../API/Utils");
|
|
6
|
+
/**
|
|
7
|
+
* Description placeholder
|
|
8
|
+
*
|
|
9
|
+
* @export
|
|
10
|
+
* @class Router
|
|
11
|
+
* @typedef {Router}
|
|
12
|
+
*/
|
|
13
|
+
var Router = /** @class */ (function () {
|
|
14
|
+
/**
|
|
15
|
+
* Creates an instance of Router.
|
|
16
|
+
*
|
|
17
|
+
* @constructor
|
|
18
|
+
* @param {RouterConfig} config
|
|
19
|
+
*/
|
|
20
|
+
function Router(config) {
|
|
21
|
+
this.config = config;
|
|
22
|
+
this.server = this.isContainer() ? new ContainerServer_1.default(config) : new Server_1.default(config);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Description placeholder
|
|
26
|
+
*
|
|
27
|
+
* @public
|
|
28
|
+
* @returns {CallableFunction}
|
|
29
|
+
*/
|
|
30
|
+
Router.prototype.getExport = function () {
|
|
31
|
+
return this.server.getExport();
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Description placeholder
|
|
35
|
+
*
|
|
36
|
+
* @private
|
|
37
|
+
* @returns {boolean}
|
|
38
|
+
*/
|
|
39
|
+
Router.prototype.isContainer = function () {
|
|
40
|
+
return Utils_1.default.isHybridlessContainer();
|
|
41
|
+
};
|
|
42
|
+
return Router;
|
|
43
|
+
}());
|
|
44
|
+
exports.default = Router;
|
|
45
|
+
//# sourceMappingURL=Router.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Router.js","sourceRoot":"","sources":["../../../src/Server/Router.ts"],"names":[],"mappings":";;AAEA,yDAAmD;AACnD,uCAAiC;AAEjC,sCAAgC;AAwEhC;;;;;;GAMG;AACH;IAiBE;;;;;OAKG;IACH,gBAAY,MAAoB;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,IAAI,yBAAe,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,gBAAM,CAAC,MAAM,CAAC,CAAA;IACrF,CAAC;IACD;;;;;OAKG;IACI,0BAAS,GAAhB;QACE,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAA;IAChC,CAAC;IACD;;;;;OAKG;IACK,4BAAW,GAAnB;QACE,OAAO,eAAK,CAAC,qBAAqB,EAAE,CAAA;IACtC,CAAC;IACH,aAAC;AAAD,CAAC,AA7CD,IA6CC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import Proxy from './container/Proxy';
|
|
2
|
+
import Server from './Server';
|
|
3
|
+
import { RouterConfig } from '../Router';
|
|
4
|
+
/**
|
|
5
|
+
* ${1:Description placeholder}
|
|
6
|
+
*
|
|
7
|
+
* @export
|
|
8
|
+
* @class ContainerServer
|
|
9
|
+
* @typedef {ContainerServer}
|
|
10
|
+
* @extends {Server}
|
|
11
|
+
*/
|
|
12
|
+
export default class ContainerServer extends Server {
|
|
13
|
+
/**
|
|
14
|
+
* ${1:Description placeholder}
|
|
15
|
+
*
|
|
16
|
+
* @protected
|
|
17
|
+
* @readonly
|
|
18
|
+
* @type {Proxy}
|
|
19
|
+
*/
|
|
20
|
+
protected readonly proxy: Proxy;
|
|
21
|
+
/**
|
|
22
|
+
* Creates an instance of ContainerServer.
|
|
23
|
+
*
|
|
24
|
+
* @constructor
|
|
25
|
+
* @param {RouterConfig} config
|
|
26
|
+
*/
|
|
27
|
+
constructor(config: RouterConfig);
|
|
28
|
+
/**
|
|
29
|
+
* ${1:Description placeholder}
|
|
30
|
+
*
|
|
31
|
+
* @public
|
|
32
|
+
* @returns {CallableFunction}
|
|
33
|
+
*/
|
|
34
|
+
getExport(): CallableFunction;
|
|
35
|
+
/**
|
|
36
|
+
* ${1:Description placeholder}
|
|
37
|
+
*
|
|
38
|
+
* @public
|
|
39
|
+
* @async
|
|
40
|
+
* @returns {*}
|
|
41
|
+
*/
|
|
42
|
+
start(): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* ${1:Description placeholder}
|
|
45
|
+
*
|
|
46
|
+
* @public
|
|
47
|
+
* @async
|
|
48
|
+
* @param {?*} [err]
|
|
49
|
+
* @returns {*}
|
|
50
|
+
*/
|
|
51
|
+
stop(err?: any): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* ${1:Description placeholder}
|
|
54
|
+
*
|
|
55
|
+
* @private
|
|
56
|
+
*/
|
|
57
|
+
private listenProcessEvents;
|
|
58
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
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
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
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");
|
|
56
|
+
/**
|
|
57
|
+
* ${1:Description placeholder}
|
|
58
|
+
*
|
|
59
|
+
* @export
|
|
60
|
+
* @class ContainerServer
|
|
61
|
+
* @typedef {ContainerServer}
|
|
62
|
+
* @extends {Server}
|
|
63
|
+
*/
|
|
64
|
+
var ContainerServer = /** @class */ (function (_super) {
|
|
65
|
+
__extends(ContainerServer, _super);
|
|
66
|
+
/**
|
|
67
|
+
* Creates an instance of ContainerServer.
|
|
68
|
+
*
|
|
69
|
+
* @constructor
|
|
70
|
+
* @param {RouterConfig} config
|
|
71
|
+
*/
|
|
72
|
+
function ContainerServer(config) {
|
|
73
|
+
var _this = _super.call(this, config) || this;
|
|
74
|
+
_this.proxy = new Proxy_1.default(config, _this.handleServerlessEvent.bind(_this));
|
|
75
|
+
_this.listenProcessEvents();
|
|
76
|
+
return _this;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* ${1:Description placeholder}
|
|
80
|
+
*
|
|
81
|
+
* @public
|
|
82
|
+
* @returns {CallableFunction}
|
|
83
|
+
*/
|
|
84
|
+
ContainerServer.prototype.getExport = function () {
|
|
85
|
+
// start server socket
|
|
86
|
+
this.start();
|
|
87
|
+
// return empty function, we are all done
|
|
88
|
+
return function () { };
|
|
89
|
+
};
|
|
90
|
+
/* private */
|
|
91
|
+
/**
|
|
92
|
+
* ${1:Description placeholder}
|
|
93
|
+
*
|
|
94
|
+
* @public
|
|
95
|
+
* @async
|
|
96
|
+
* @returns {*}
|
|
97
|
+
*/
|
|
98
|
+
ContainerServer.prototype.start = function () {
|
|
99
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
100
|
+
return __generator(this, function (_a) {
|
|
101
|
+
switch (_a.label) {
|
|
102
|
+
case 0: return [4 /*yield*/, this.proxy.load()];
|
|
103
|
+
case 1:
|
|
104
|
+
_a.sent();
|
|
105
|
+
return [2 /*return*/];
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* ${1:Description placeholder}
|
|
112
|
+
*
|
|
113
|
+
* @public
|
|
114
|
+
* @async
|
|
115
|
+
* @param {?*} [err]
|
|
116
|
+
* @returns {*}
|
|
117
|
+
*/
|
|
118
|
+
ContainerServer.prototype.stop = function (err) {
|
|
119
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
120
|
+
return __generator(this, function (_a) {
|
|
121
|
+
switch (_a.label) {
|
|
122
|
+
case 0: return [4 /*yield*/, this.proxy.unload(err)];
|
|
123
|
+
case 1:
|
|
124
|
+
_a.sent();
|
|
125
|
+
return [2 /*return*/];
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* ${1:Description placeholder}
|
|
132
|
+
*
|
|
133
|
+
* @private
|
|
134
|
+
*/
|
|
135
|
+
ContainerServer.prototype.listenProcessEvents = function () {
|
|
136
|
+
// start process listeners
|
|
137
|
+
process.on('unhandledRejection', this.stop.bind(this)); // listen to exceptions
|
|
138
|
+
process.on('SIGINT', this.stop.bind(this)); // listen on SIGINT signal and gracefully stop the server
|
|
139
|
+
};
|
|
140
|
+
return ContainerServer;
|
|
141
|
+
}(Server_1.default));
|
|
142
|
+
exports.default = ContainerServer;
|
|
143
|
+
//# sourceMappingURL=ContainerServer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContainerServer.js","sourceRoot":"","sources":["../../../../src/Server/lib/ContainerServer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAqC;AACrC,mCAA6B;AAG7B;;;;;;;GAOG;AACH;IAA6C,mCAAM;IASjD;;;;;OAKG;IACH,yBAAY,MAAoB;QAAhC,YACE,kBAAM,MAAM,CAAC,SAGd;QAFC,KAAI,CAAC,KAAK,GAAG,IAAI,eAAK,CAAC,MAAM,EAAE,KAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,KAAI,CAAC,CAAC,CAAA;QACrE,KAAI,CAAC,mBAAmB,EAAE,CAAA;;IAC5B,CAAC;IACD;;;;;OAKG;IACI,mCAAS,GAAhB;QACE,sBAAsB;QACtB,IAAI,CAAC,KAAK,EAAE,CAAA;QACZ,yCAAyC;QACzC,OAAO,cAAO,CAAC,CAAA;IACjB,CAAC;IACD,aAAa;IACb;;;;;;OAMG;IACU,+BAAK,GAAlB;;;;4BACE,qBAAM,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,EAAA;;wBAAvB,SAAuB,CAAA;;;;;KACxB;IACD;;;;;;;OAOG;IACU,8BAAI,GAAjB,UAAkB,GAAS;;;;4BACzB,qBAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,EAAA;;wBAA5B,SAA4B,CAAA;;;;;KAC7B;IACD;;;;OAIG;IACK,6CAAmB,GAA3B;QACE,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;IACH,sBAAC;AAAD,CAAC,AAhED,CAA6C,gBAAM,GAgElD"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { APIGatewayProxyEvent, Context } from 'aws-lambda';
|
|
2
|
+
import { RouterConfig } from '../Router';
|
|
3
|
+
import RouteResolver from '../RouteResolver';
|
|
4
|
+
/**
|
|
5
|
+
* ${1:Description placeholder}
|
|
6
|
+
*
|
|
7
|
+
* @export
|
|
8
|
+
* @class Server
|
|
9
|
+
* @typedef {Server}
|
|
10
|
+
*/
|
|
11
|
+
export default class Server {
|
|
12
|
+
/**
|
|
13
|
+
* ${1:Description placeholder}
|
|
14
|
+
*
|
|
15
|
+
* @protected
|
|
16
|
+
* @readonly
|
|
17
|
+
* @type {RouterConfig}
|
|
18
|
+
*/
|
|
19
|
+
protected readonly config: RouterConfig;
|
|
20
|
+
/**
|
|
21
|
+
* ${1:Description placeholder}
|
|
22
|
+
*
|
|
23
|
+
* @protected
|
|
24
|
+
* @readonly
|
|
25
|
+
* @type {RouteResolver}
|
|
26
|
+
*/
|
|
27
|
+
protected readonly routeResolver: RouteResolver;
|
|
28
|
+
/**
|
|
29
|
+
* Creates an instance of Server.
|
|
30
|
+
*
|
|
31
|
+
* @constructor
|
|
32
|
+
* @param {RouterConfig} config
|
|
33
|
+
*/
|
|
34
|
+
constructor(config: RouterConfig);
|
|
35
|
+
/**
|
|
36
|
+
* ${1:Description placeholder}
|
|
37
|
+
*
|
|
38
|
+
* @public
|
|
39
|
+
* @returns {CallableFunction}
|
|
40
|
+
*/
|
|
41
|
+
getExport(): CallableFunction;
|
|
42
|
+
/**
|
|
43
|
+
* ${1:Description placeholder}
|
|
44
|
+
*
|
|
45
|
+
* @public
|
|
46
|
+
* @async
|
|
47
|
+
* @param {APIGatewayProxyEvent} event
|
|
48
|
+
* @param {Context} context
|
|
49
|
+
* @returns {*}
|
|
50
|
+
*/
|
|
51
|
+
handleServerlessEvent(event: APIGatewayProxyEvent, context: Context): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* ${1:Description placeholder}
|
|
54
|
+
*
|
|
55
|
+
* @private
|
|
56
|
+
* @param {Request<any>} req
|
|
57
|
+
* @param {string} routePath
|
|
58
|
+
*/
|
|
59
|
+
private parsePathParams;
|
|
60
|
+
}
|