@ikonintegration/ikapi 5.0.2 → 5.0.4
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/package.json +1 -1
- package/src/BaseEvent/Launchable/ContainerExec.ts +6 -2
- package/src/Mailer/Mailer.ts +42 -52
- package/dist/index.d.ts +0 -17
- package/dist/index.js +0 -28
- package/dist/index.js.map +0 -1
- package/dist/package-lock.json +0 -11901
- package/dist/package.json +0 -82
- package/dist/src/API/Request.d.ts +0 -125
- package/dist/src/API/Request.js +0 -185
- package/dist/src/API/Request.js.map +0 -1
- package/dist/src/API/Response.d.ts +0 -188
- package/dist/src/API/Response.js +0 -270
- package/dist/src/API/Response.js.map +0 -1
- package/dist/src/BaseEvent/DynamoTransaction.d.ts +0 -70
- package/dist/src/BaseEvent/DynamoTransaction.js +0 -104
- package/dist/src/BaseEvent/DynamoTransaction.js.map +0 -1
- package/dist/src/BaseEvent/EventProcessor.d.ts +0 -58
- package/dist/src/BaseEvent/EventProcessor.js +0 -101
- package/dist/src/BaseEvent/EventProcessor.js.map +0 -1
- package/dist/src/BaseEvent/Launchable/ContainerExec.d.ts +0 -42
- package/dist/src/BaseEvent/Launchable/ContainerExec.js +0 -102
- package/dist/src/BaseEvent/Launchable/ContainerExec.js.map +0 -1
- package/dist/src/BaseEvent/Launchable/index.d.ts +0 -34
- package/dist/src/BaseEvent/Launchable/index.js +0 -43
- package/dist/src/BaseEvent/Launchable/index.js.map +0 -1
- package/dist/src/BaseEvent/Launchable/types.d.ts +0 -10
- package/dist/src/BaseEvent/Launchable/types.js +0 -2
- package/dist/src/BaseEvent/Launchable/types.js.map +0 -1
- package/dist/src/BaseEvent/Process.d.ts +0 -50
- package/dist/src/BaseEvent/Process.js +0 -64
- package/dist/src/BaseEvent/Process.js.map +0 -1
- package/dist/src/BaseEvent/StepTransaction.d.ts +0 -23
- package/dist/src/BaseEvent/StepTransaction.js +0 -27
- package/dist/src/BaseEvent/StepTransaction.js.map +0 -1
- package/dist/src/BaseEvent/Transaction.d.ts +0 -149
- package/dist/src/BaseEvent/Transaction.js +0 -224
- package/dist/src/BaseEvent/Transaction.js.map +0 -1
- package/dist/src/Cache/Redis.d.ts +0 -29
- package/dist/src/Cache/Redis.js +0 -80
- package/dist/src/Cache/Redis.js.map +0 -1
- package/dist/src/Cache/types.d.ts +0 -31
- package/dist/src/Cache/types.js +0 -2
- package/dist/src/Cache/types.js.map +0 -1
- package/dist/src/Config/Configuration.d.ts +0 -123
- package/dist/src/Config/Configuration.js +0 -109
- package/dist/src/Config/Configuration.js.map +0 -1
- package/dist/src/Config/EnvironmentVar.d.ts +0 -74
- package/dist/src/Config/EnvironmentVar.js +0 -138
- package/dist/src/Config/EnvironmentVar.js.map +0 -1
- package/dist/src/Crypto/Crypto.d.ts +0 -45
- package/dist/src/Crypto/Crypto.js +0 -72
- package/dist/src/Crypto/Crypto.js.map +0 -1
- package/dist/src/Database/Database.d.ts +0 -21
- package/dist/src/Database/Database.js +0 -15
- package/dist/src/Database/Database.js.map +0 -1
- package/dist/src/Database/DatabaseManager.d.ts +0 -47
- package/dist/src/Database/DatabaseManager.js +0 -60
- package/dist/src/Database/DatabaseManager.js.map +0 -1
- package/dist/src/Database/DatabaseTransaction.d.ts +0 -101
- package/dist/src/Database/DatabaseTransaction.js +0 -126
- package/dist/src/Database/DatabaseTransaction.js.map +0 -1
- package/dist/src/Database/index.d.ts +0 -10
- package/dist/src/Database/index.js +0 -15
- package/dist/src/Database/index.js.map +0 -1
- package/dist/src/Database/integrations/dynamo/DynamoDatabase.d.ts +0 -35
- package/dist/src/Database/integrations/dynamo/DynamoDatabase.js +0 -59
- package/dist/src/Database/integrations/dynamo/DynamoDatabase.js.map +0 -1
- package/dist/src/Database/integrations/kysely/KyselyDatabase.d.ts +0 -66
- package/dist/src/Database/integrations/kysely/KyselyDatabase.js +0 -86
- package/dist/src/Database/integrations/kysely/KyselyDatabase.js.map +0 -1
- package/dist/src/Database/integrations/kysely/KyselyTransaction.d.ts +0 -70
- package/dist/src/Database/integrations/kysely/KyselyTransaction.js +0 -118
- package/dist/src/Database/integrations/kysely/KyselyTransaction.js.map +0 -1
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.d.ts +0 -36
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.js +0 -54
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.js.map +0 -1
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.d.ts +0 -63
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.js +0 -61
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.js.map +0 -1
- package/dist/src/Database/types.d.ts +0 -76
- package/dist/src/Database/types.js +0 -2
- package/dist/src/Database/types.js.map +0 -1
- package/dist/src/Globals.d.ts +0 -93
- package/dist/src/Globals.js +0 -99
- package/dist/src/Globals.js.map +0 -1
- package/dist/src/Logger/Logger.d.ts +0 -161
- package/dist/src/Logger/Logger.js +0 -299
- package/dist/src/Logger/Logger.js.map +0 -1
- package/dist/src/Mailer/Mailer.d.ts +0 -78
- package/dist/src/Mailer/Mailer.js +0 -182
- package/dist/src/Mailer/Mailer.js.map +0 -1
- package/dist/src/Publisher/Publisher.d.ts +0 -39
- package/dist/src/Publisher/Publisher.js +0 -77
- package/dist/src/Publisher/Publisher.js.map +0 -1
- package/dist/src/Server/RouteResolver.d.ts +0 -33
- package/dist/src/Server/RouteResolver.js +0 -100
- package/dist/src/Server/RouteResolver.js.map +0 -1
- package/dist/src/Server/Router.d.ts +0 -157
- package/dist/src/Server/Router.js +0 -32
- package/dist/src/Server/Router.js.map +0 -1
- package/dist/src/Server/lib/ContainerServer.d.ts +0 -42
- package/dist/src/Server/lib/ContainerServer.js +0 -66
- package/dist/src/Server/lib/ContainerServer.js.map +0 -1
- package/dist/src/Server/lib/Server.d.ts +0 -45
- package/dist/src/Server/lib/Server.js +0 -93
- package/dist/src/Server/lib/Server.js.map +0 -1
- package/dist/src/Server/lib/container/GenericHandler.d.ts +0 -9
- package/dist/src/Server/lib/container/GenericHandler.js +0 -82
- package/dist/src/Server/lib/container/GenericHandler.js.map +0 -1
- package/dist/src/Server/lib/container/GenericHandlerEvent.d.ts +0 -52
- package/dist/src/Server/lib/container/GenericHandlerEvent.js +0 -132
- package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +0 -1
- package/dist/src/Server/lib/container/HealthHandler.d.ts +0 -9
- package/dist/src/Server/lib/container/HealthHandler.js +0 -19
- package/dist/src/Server/lib/container/HealthHandler.js.map +0 -1
- package/dist/src/Server/lib/container/Proxy.d.ts +0 -67
- package/dist/src/Server/lib/container/Proxy.js +0 -143
- package/dist/src/Server/lib/container/Proxy.js.map +0 -1
- package/dist/src/Server/lib/container/Utils.d.ts +0 -14
- package/dist/src/Server/lib/container/Utils.js +0 -37
- package/dist/src/Server/lib/container/Utils.js.map +0 -1
- package/dist/src/Util/AsyncSingleton.d.ts +0 -31
- package/dist/src/Util/AsyncSingleton.js +0 -83
- package/dist/src/Util/AsyncSingleton.js.map +0 -1
- package/dist/src/Util/Utils.d.ts +0 -61
- package/dist/src/Util/Utils.js +0 -147
- package/dist/src/Util/Utils.js.map +0 -1
- package/dist/src/Validation/Validator.d.ts +0 -17
- package/dist/src/Validation/Validator.js +0 -39
- package/dist/src/Validation/Validator.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { SNSClient, PublishCommand, } from '@aws-sdk/client-sns';
|
|
11
|
-
import sha1 from 'sha1';
|
|
12
|
-
//reusable client
|
|
13
|
-
/**
|
|
14
|
-
* A variable that holds the connection to the SNS client for publishing messages.
|
|
15
|
-
* @type {SNSClient | null}
|
|
16
|
-
*/
|
|
17
|
-
// eslint-disable-next-line no-var
|
|
18
|
-
let PUBLISHER_CONN = null;
|
|
19
|
-
/**
|
|
20
|
-
* The connection hash for the publisher. It is initially set to null.
|
|
21
|
-
* @type {string | null}
|
|
22
|
-
*/
|
|
23
|
-
// eslint-disable-next-line no-var
|
|
24
|
-
let PUBLISHER_CONN_HASH = null;
|
|
25
|
-
/**
|
|
26
|
-
* Represents a publisher that can publish messages to an SNS topic.
|
|
27
|
-
*/
|
|
28
|
-
export default class Publisher {
|
|
29
|
-
/**
|
|
30
|
-
* Constructs a new instance of the Publisher class.
|
|
31
|
-
* @param {PublisherConfig} [config] - The configuration object for the Publisher.
|
|
32
|
-
* @returns None
|
|
33
|
-
*/
|
|
34
|
-
constructor(config) {
|
|
35
|
-
if (config && config.region) {
|
|
36
|
-
this.region = config.region;
|
|
37
|
-
// console.debug(`Using region: ${this.region}`);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Publishes a message on a specified topic.
|
|
42
|
-
* @param {any} messageObject - The message object to be published.
|
|
43
|
-
* @param {string} topic - The ARN of the topic to publish the message to.
|
|
44
|
-
* @param {object} [additionalProps] - Additional properties to include in the publish command.
|
|
45
|
-
* @returns {Promise<PublishCommandOutput>} - A promise that resolves to the response from the publish command.
|
|
46
|
-
*/
|
|
47
|
-
publishOnTopic(messageObject, topic, additionalProps) {
|
|
48
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
-
let resp = undefined;
|
|
50
|
-
try {
|
|
51
|
-
this.connect();
|
|
52
|
-
//Send to SNS
|
|
53
|
-
const params = Object.assign({ Message: JSON.stringify(messageObject), TopicArn: topic }, (additionalProps ? additionalProps : {}));
|
|
54
|
-
resp = yield PUBLISHER_CONN.send(new PublishCommand(params));
|
|
55
|
-
}
|
|
56
|
-
catch (e) {
|
|
57
|
-
console.error(`Error while publishing into topic ${topic} with error: ${e}`);
|
|
58
|
-
}
|
|
59
|
-
console.debug('Publisher resp', resp);
|
|
60
|
-
return resp;
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Establishes a connection to the SNS client if it does not already exist or if the region has changed.
|
|
65
|
-
* @returns None
|
|
66
|
-
*/
|
|
67
|
-
connect() {
|
|
68
|
-
if ((!PUBLISHER_CONN && !PUBLISHER_CONN_HASH) || PUBLISHER_CONN_HASH != sha1(this.region)) {
|
|
69
|
-
PUBLISHER_CONN = new SNSClient({
|
|
70
|
-
apiVersion: '2010-03-31',
|
|
71
|
-
region: this.region,
|
|
72
|
-
});
|
|
73
|
-
PUBLISHER_CONN_HASH = sha1(this.region).toString();
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
//# sourceMappingURL=Publisher.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Publisher.js","sourceRoot":"","sources":["../../../src/Publisher/Publisher.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EACL,SAAS,EACT,cAAc,GAGf,MAAM,qBAAqB,CAAA;AAC5B,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,iBAAiB;AACjB;;;GAGG;AACH,kCAAkC;AAClC,IAAI,cAAc,GAAqB,IAAI,CAAA;AAC3C;;;GAGG;AACH,kCAAkC;AAClC,IAAI,mBAAmB,GAAkB,IAAI,CAAA;AAW7C;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,SAAS;IAQ5B;;;;OAIG;IACH,YAAY,MAAwB;QAClC,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;YAC5B,IAAI,CAAC,MAAM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|
3
|
-
/**
|
|
4
|
-
* A class that resolves routes based on the provided configuration.
|
|
5
|
-
* @class RouteResolver
|
|
6
|
-
*/
|
|
7
|
-
export default class RouteResolver {
|
|
8
|
-
/**
|
|
9
|
-
* An object that maps HTTP methods to their corresponding routes.
|
|
10
|
-
* @property {object} routes - The routes object.
|
|
11
|
-
* @property {Routes} routes.method - The routes for the specified HTTP method.
|
|
12
|
-
*/
|
|
13
|
-
private routes;
|
|
14
|
-
/**
|
|
15
|
-
* Constructs a new instance of the Router class with the given configuration.
|
|
16
|
-
* @param {RouterConfig} config - The configuration object for the router.
|
|
17
|
-
* @returns None
|
|
18
|
-
*/
|
|
19
|
-
constructor(config: RouterConfig);
|
|
20
|
-
/**
|
|
21
|
-
* Resolves a route based on the given HTTP method and path.
|
|
22
|
-
* @param {string} method - The HTTP method of the request.
|
|
23
|
-
* @param {string} path - The path of the request.
|
|
24
|
-
* @returns {Route | undefined} - The resolved route or undefined if no route is found.
|
|
25
|
-
*/
|
|
26
|
-
resolveRoute(method: HttpMethod, path: string): AnyRoute | undefined;
|
|
27
|
-
/**
|
|
28
|
-
* Builds the routes for the router based on the given configuration.
|
|
29
|
-
* @param {RouterConfig} config - The router configuration object.
|
|
30
|
-
* @returns None
|
|
31
|
-
*/
|
|
32
|
-
private buildRoutes;
|
|
33
|
-
}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Represents a collection of routes that can be added and resolved.
|
|
3
|
-
*/
|
|
4
|
-
class Routes {
|
|
5
|
-
/**
|
|
6
|
-
* Initializes a new instance of the class.
|
|
7
|
-
* @constructor
|
|
8
|
-
*/
|
|
9
|
-
constructor() {
|
|
10
|
-
this.next = {};
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Adds a route to the routing system.
|
|
14
|
-
* @param {Route} route - The route to add.
|
|
15
|
-
* @param {string[]} parts - The parts of the route path.
|
|
16
|
-
* @returns None
|
|
17
|
-
* @throws {Error} If a duplicate route is detected.
|
|
18
|
-
*/
|
|
19
|
-
addRoute(route, parts) {
|
|
20
|
-
const first = parts.shift();
|
|
21
|
-
if (first) {
|
|
22
|
-
if (first.startsWith(':')) {
|
|
23
|
-
this.variable = this.variable || new Routes();
|
|
24
|
-
this.variable.addRoute(route, parts);
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
this.next[first] = this.next[first] || new Routes();
|
|
28
|
-
this.next[first].addRoute(route, parts);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
if (this.current)
|
|
33
|
-
throw new Error(`Duplicate route: ${route.method}: ${route.path}`);
|
|
34
|
-
this.current = route;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Resolves a route based on the given parts.
|
|
39
|
-
* @param {string[]} parts - An array of route parts.
|
|
40
|
-
* @returns {Route} The resolved route.
|
|
41
|
-
*/
|
|
42
|
-
resolveRoute(parts) {
|
|
43
|
-
var _a;
|
|
44
|
-
const first = parts.shift();
|
|
45
|
-
if (first) {
|
|
46
|
-
if (first in this.next) {
|
|
47
|
-
return this.next[first].resolveRoute(parts);
|
|
48
|
-
}
|
|
49
|
-
return (_a = this.variable) === null || _a === void 0 ? void 0 : _a.resolveRoute(parts);
|
|
50
|
-
}
|
|
51
|
-
return this.current;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* A class that resolves routes based on the provided configuration.
|
|
56
|
-
* @class RouteResolver
|
|
57
|
-
*/
|
|
58
|
-
export default class RouteResolver {
|
|
59
|
-
/**
|
|
60
|
-
* Constructs a new instance of the Router class with the given configuration.
|
|
61
|
-
* @param {RouterConfig} config - The configuration object for the router.
|
|
62
|
-
* @returns None
|
|
63
|
-
*/
|
|
64
|
-
constructor(config) {
|
|
65
|
-
this.routes = {};
|
|
66
|
-
this.buildRoutes(config);
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Resolves a route based on the given HTTP method and path.
|
|
70
|
-
* @param {string} method - The HTTP method of the request.
|
|
71
|
-
* @param {string} path - The path of the request.
|
|
72
|
-
* @returns {Route | undefined} - The resolved route or undefined if no route is found.
|
|
73
|
-
*/
|
|
74
|
-
resolveRoute(method, path) {
|
|
75
|
-
var _a;
|
|
76
|
-
const parts = path.split('/').filter(p => p.length);
|
|
77
|
-
return (_a = this.routes[method]) === null || _a === void 0 ? void 0 : _a.resolveRoute(parts);
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Builds the routes for the router based on the given configuration.
|
|
81
|
-
* @param {RouterConfig} config - The router configuration object.
|
|
82
|
-
* @returns None
|
|
83
|
-
*/
|
|
84
|
-
buildRoutes(config) {
|
|
85
|
-
const addRoute = (path, route) => {
|
|
86
|
-
const parts = path.split('/').filter(p => p.length);
|
|
87
|
-
this.routes[route.method] = this.routes[route.method] || new Routes();
|
|
88
|
-
this.routes[route.method].addRoute(route, parts);
|
|
89
|
-
};
|
|
90
|
-
for (const route of config.routes) {
|
|
91
|
-
if (Array.isArray(route.path)) {
|
|
92
|
-
for (const path of route.path)
|
|
93
|
-
addRoute(path, route);
|
|
94
|
-
}
|
|
95
|
-
else
|
|
96
|
-
addRoute(route.path, route);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
//# sourceMappingURL=RouteResolver.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RouteResolver.js","sourceRoot":"","sources":["../../../src/Server/RouteResolver.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,MAAM;IAkBV;;;OAGG;IACH;QACE,IAAI,CAAC,IAAI,GAAG,EAAE,CAAA;IAChB,CAAC;IAED;;;;;;OAMG;IACI,QAAQ,CAAC,KAAe,EAAE,KAAe;QAC9C,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,EAAE,CAAA;QAC3B,IAAI,KAAK,EAAE,CAAC;YACV,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,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od';
|
|
4
|
-
import { HttpMethod } from '../API/Request.js';
|
|
5
|
-
import { ResponseErrorType } from '../API/Response.js';
|
|
6
|
-
import Transaction, { TransactionConfig, TransactionExecution, StringMap } from '../BaseEvent/Transaction.js';
|
|
7
|
-
/**
|
|
8
|
-
* Represents a route in an API.
|
|
9
|
-
* @template InputType - The type of the input data for the route.
|
|
10
|
-
* @template OutputType - The type of the output data for the route.
|
|
11
|
-
* @property {string} path - The path of the route.
|
|
12
|
-
* @property {string} method - The HTTP method of the route.
|
|
13
|
-
* @property {TransactionExecution<Transaction<InputType, OutputType | ResponseErrorType>, OutputType | ResponseErrorType>} handler - The handler function for the route.
|
|
14
|
-
* @property {?z.ZodObject<any> | z.ZodUnion<any> | z.ZodIntersection<any, any>}[inputSchema] - The input schema for validating the input data.
|
|
15
|
-
* @property {?z.ZodObject<any> | z.ZodUnion<any> | z.ZodIntersection<any, any>}[pathSchema] - The path schema for validating the path data.
|
|
16
|
-
* @property {?z.ZodObject<any> | z.ZodUnion<any> | z.ZodIntersection<any, any>}[querySchema] - The query schema for validating the query data.
|
|
17
|
-
*/
|
|
18
|
-
export interface Route<InputType = never, OutputType = never, PathParamsType = StringMap, QueryParamsType = StringMap> {
|
|
19
|
-
/**
|
|
20
|
-
* Represents a file path as a string.
|
|
21
|
-
* @param {string} path - The file path.
|
|
22
|
-
* @returns None
|
|
23
|
-
*/
|
|
24
|
-
path: string | string[];
|
|
25
|
-
/**
|
|
26
|
-
* Represents the method used in an API request.
|
|
27
|
-
* @type {string}
|
|
28
|
-
*/
|
|
29
|
-
method: HttpMethod;
|
|
30
|
-
/**
|
|
31
|
-
* Represents a handler for executing a transaction with the given input type and output type.
|
|
32
|
-
* @param {Transaction<InputType, OutputType | ResponseErrorType, PathParamsType, QueryParamsType>} transaction - The transaction to execute.
|
|
33
|
-
* @param {OutputType | ResponseErrorType} - The output type or response error type of the transaction.
|
|
34
|
-
*/
|
|
35
|
-
handler: TransactionExecution<Transaction<InputType, OutputType | ResponseErrorType, never, PathParamsType, QueryParamsType>, OutputType | ResponseErrorType>;
|
|
36
|
-
/**
|
|
37
|
-
* An optional input schema for validating the structure of the input data.
|
|
38
|
-
*
|
|
39
|
-
* @type {?z.ZodObject<any> | z.ZodUnion<any> | z.ZodIntersection<any, any>}
|
|
40
|
-
*/
|
|
41
|
-
inputSchema?: z.ZodObject<any> | z.ZodUnion<any> | z.ZodIntersection<any, any>;
|
|
42
|
-
/**
|
|
43
|
-
* An optional input schema for validating the structure of the path params.
|
|
44
|
-
*
|
|
45
|
-
* @type {?z.ZodObject<any> | z.ZodUnion<any> | z.ZodIntersection<any, any>}
|
|
46
|
-
*/
|
|
47
|
-
pathSchema?: z.ZodObject<any> | z.ZodUnion<any> | z.ZodIntersection<any, any>;
|
|
48
|
-
/**
|
|
49
|
-
* An optional input schema for validating the structure of the query params.
|
|
50
|
-
*
|
|
51
|
-
* @type {?z.ZodObject<any> | z.ZodUnion<any> | z.ZodIntersection<any, any>}
|
|
52
|
-
*/
|
|
53
|
-
querySchema?: z.ZodObject<any> | z.ZodUnion<any> | z.ZodIntersection<any, any>;
|
|
54
|
-
/**
|
|
55
|
-
* An optional openApi object with extra metadata for docs generation.
|
|
56
|
-
*/
|
|
57
|
-
openApi?: {
|
|
58
|
-
summary: string;
|
|
59
|
-
description: string;
|
|
60
|
-
tags?: string[];
|
|
61
|
-
outputSchema?: z.ZodObject<any> | z.ZodUnion<any> | z.ZodIntersection<any, any> | z.ZodType<any>;
|
|
62
|
-
successCode?: number;
|
|
63
|
-
security?: {
|
|
64
|
-
[key: string]: string[] | never[];
|
|
65
|
-
}[];
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Represents a route that can accept any type for its parameters and return values.
|
|
70
|
-
*/
|
|
71
|
-
export type AnyRoute = Route<any | never, any | never, any | never, any | never>;
|
|
72
|
-
/**
|
|
73
|
-
* Represents the configuration options for a router.
|
|
74
|
-
* @typedef {TransactionConfig & {
|
|
75
|
-
* routes: Route[]
|
|
76
|
-
* port?: number
|
|
77
|
-
* timeout?: number
|
|
78
|
-
* cors?: {
|
|
79
|
-
* origin?: string | string[]
|
|
80
|
-
* headers?: string[]
|
|
81
|
-
* allowCredentials?: boolean
|
|
82
|
-
* }
|
|
83
|
-
* healthCheckRoute?: string
|
|
84
|
-
* }} RouterConfig
|
|
85
|
-
* @property {Route[]} routes - The routes to be configured in the router.
|
|
86
|
-
* @property {number} [port] - The port number to listen on. If not specified, a default port will be used.
|
|
87
|
-
* @property {number} [timeout] - The timeout duration for requests in milliseconds. If not specified, a default timeout will be
|
|
88
|
-
*/
|
|
89
|
-
export type RouterConfig = TransactionConfig & {
|
|
90
|
-
/**
|
|
91
|
-
* An array of route objects representing the available routes in the application.
|
|
92
|
-
* @type {Route[]}
|
|
93
|
-
*/
|
|
94
|
-
routes: AnyRoute[];
|
|
95
|
-
/**
|
|
96
|
-
* The port number for the server to listen on.
|
|
97
|
-
* @type {number | undefined}
|
|
98
|
-
*/
|
|
99
|
-
port?: number;
|
|
100
|
-
/**
|
|
101
|
-
* Optional timeout value in milliseconds.
|
|
102
|
-
* @type {number | undefined}
|
|
103
|
-
*/
|
|
104
|
-
timeout?: number;
|
|
105
|
-
/**
|
|
106
|
-
* Configuration options for Cross-Origin Resource Sharing (CORS).
|
|
107
|
-
* @property {string | string[]} [origin] - The allowed origin(s) for CORS requests.
|
|
108
|
-
* @property {string[]} [headers] - The allowed headers for CORS requests.
|
|
109
|
-
* @property {boolean} [allowCredentials] - Whether to allow credentials (cookies, HTTP authentication, and client-side SSL certificates) to be sent in CORS requests.
|
|
110
|
-
*/
|
|
111
|
-
cors?: {
|
|
112
|
-
origin?: string | string[];
|
|
113
|
-
headers?: string[];
|
|
114
|
-
allowCredentials?: boolean;
|
|
115
|
-
};
|
|
116
|
-
/**
|
|
117
|
-
* The route for the health check endpoint.
|
|
118
|
-
* @type {string | undefined}
|
|
119
|
-
*/
|
|
120
|
-
healthCheckRoute?: string;
|
|
121
|
-
/**
|
|
122
|
-
* Optional hook function that sets up the container with the provided HTTP server and Express app.
|
|
123
|
-
* @param {HTTPServer} server - The HTTP server instance.
|
|
124
|
-
* @param {express.Express} app - The Express application instance.
|
|
125
|
-
* @returns {Promise<void>} A promise that resolves when the setup is complete.
|
|
126
|
-
*/
|
|
127
|
-
containerSetupHook?: (server: HTTPServer, app: express.Express) => Promise<void>;
|
|
128
|
-
};
|
|
129
|
-
/**
|
|
130
|
-
* Represents a router that handles routing logic for a web application.
|
|
131
|
-
*/
|
|
132
|
-
export default class Router {
|
|
133
|
-
/**
|
|
134
|
-
* The configuration object for the router.
|
|
135
|
-
*/
|
|
136
|
-
private readonly config;
|
|
137
|
-
/**
|
|
138
|
-
* The private readonly server instance.
|
|
139
|
-
*/
|
|
140
|
-
private readonly server;
|
|
141
|
-
/**
|
|
142
|
-
* Constructs a new instance of the Router class.
|
|
143
|
-
* @param {RouterConfig} config - The configuration object for the router.
|
|
144
|
-
* @returns None
|
|
145
|
-
*/
|
|
146
|
-
constructor(config: RouterConfig);
|
|
147
|
-
/**
|
|
148
|
-
* Retrieves the export function from the server.
|
|
149
|
-
* @returns {CallableFunction} The export function from the server.
|
|
150
|
-
*/
|
|
151
|
-
getExport(): CallableFunction;
|
|
152
|
-
/**
|
|
153
|
-
* Checks if the current element is a container.
|
|
154
|
-
* @returns {boolean} - True if the element is a container, false otherwise.
|
|
155
|
-
*/
|
|
156
|
-
private isContainer;
|
|
157
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import ContainerServer from './lib/ContainerServer.js';
|
|
2
|
-
import Server from './lib/Server.js';
|
|
3
|
-
import Utils from '../Util/Utils.js';
|
|
4
|
-
/**
|
|
5
|
-
* Represents a router that handles routing logic for a web application.
|
|
6
|
-
*/
|
|
7
|
-
export default class Router {
|
|
8
|
-
/**
|
|
9
|
-
* Constructs a new instance of the Router class.
|
|
10
|
-
* @param {RouterConfig} config - The configuration object for the router.
|
|
11
|
-
* @returns None
|
|
12
|
-
*/
|
|
13
|
-
constructor(config) {
|
|
14
|
-
this.config = config;
|
|
15
|
-
this.server = this.isContainer() ? new ContainerServer(config) : new Server(config);
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Retrieves the export function from the server.
|
|
19
|
-
* @returns {CallableFunction} The export function from the server.
|
|
20
|
-
*/
|
|
21
|
-
getExport() {
|
|
22
|
-
return this.server.getExport();
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Checks if the current element is a container.
|
|
26
|
-
* @returns {boolean} - True if the element is a container, false otherwise.
|
|
27
|
-
*/
|
|
28
|
-
isContainer() {
|
|
29
|
-
return Utils.isHybridlessContainer();
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
//# sourceMappingURL=Router.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Router.js","sourceRoot":"","sources":["../../../src/Server/Router.ts"],"names":[],"mappings":"AAKA,OAAO,eAAe,MAAM,0BAA0B,CAAA;AACtD,OAAO,MAAM,MAAM,iBAAiB,CAAA;AAQpC,OAAO,KAAK,MAAM,kBAAkB,CAAA;AAmJpC;;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,42 +0,0 @@
|
|
|
1
|
-
import Proxy from './container/Proxy.js';
|
|
2
|
-
import Server from './Server.js';
|
|
3
|
-
import { RouterConfig } from '../Router.js';
|
|
4
|
-
/**
|
|
5
|
-
* Represents a server container that extends the Server class and handles serverless events.
|
|
6
|
-
*/
|
|
7
|
-
export default class ContainerServer extends Server {
|
|
8
|
-
/**
|
|
9
|
-
* The proxy object used for handling requests and responses.
|
|
10
|
-
* @type {Proxy}
|
|
11
|
-
* @protected
|
|
12
|
-
*/
|
|
13
|
-
protected readonly proxy: Proxy;
|
|
14
|
-
/**
|
|
15
|
-
* Constructs a new instance of the Router class.
|
|
16
|
-
* @param {RouterConfig} config - The configuration object for the router.
|
|
17
|
-
* @returns None
|
|
18
|
-
*/
|
|
19
|
-
constructor(config: RouterConfig);
|
|
20
|
-
/**
|
|
21
|
-
* Returns a callable function that can be used to export data.
|
|
22
|
-
* @returns {CallableFunction} - A callable function that can be used to export data.
|
|
23
|
-
*/
|
|
24
|
-
getExport(): CallableFunction;
|
|
25
|
-
/**
|
|
26
|
-
* Starts the application by loading the proxy.
|
|
27
|
-
* @returns {Promise<void>} - A promise that resolves when the proxy is loaded.
|
|
28
|
-
*/
|
|
29
|
-
start(): Promise<void>;
|
|
30
|
-
/**
|
|
31
|
-
* Stops the execution of the program and unloads the proxy.
|
|
32
|
-
* @param {any} [err] - Optional error object to pass to the unload method.
|
|
33
|
-
* @returns {Promise<void>} - A promise that resolves once the proxy is unloaded.
|
|
34
|
-
*/
|
|
35
|
-
stop(err?: any): Promise<void>;
|
|
36
|
-
/**
|
|
37
|
-
* Listens for process events and handles them accordingly.
|
|
38
|
-
* @private
|
|
39
|
-
* @returns None
|
|
40
|
-
*/
|
|
41
|
-
private listenProcessEvents;
|
|
42
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import Proxy from './container/Proxy.js';
|
|
11
|
-
import Server from './Server.js';
|
|
12
|
-
/**
|
|
13
|
-
* Represents a server container that extends the Server class and handles serverless events.
|
|
14
|
-
*/
|
|
15
|
-
export default class ContainerServer extends Server {
|
|
16
|
-
/**
|
|
17
|
-
* Constructs a new instance of the Router class.
|
|
18
|
-
* @param {RouterConfig} config - The configuration object for the router.
|
|
19
|
-
* @returns None
|
|
20
|
-
*/
|
|
21
|
-
constructor(config) {
|
|
22
|
-
super(config);
|
|
23
|
-
this.proxy = new Proxy(config, this.handleServerlessEvent.bind(this));
|
|
24
|
-
this.listenProcessEvents();
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Returns a callable function that can be used to export data.
|
|
28
|
-
* @returns {CallableFunction} - A callable function that can be used to export data.
|
|
29
|
-
*/
|
|
30
|
-
getExport() {
|
|
31
|
-
// start server socket
|
|
32
|
-
this.start();
|
|
33
|
-
// return empty function, we are all done
|
|
34
|
-
return () => { };
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Starts the application by loading the proxy.
|
|
38
|
-
* @returns {Promise<void>} - A promise that resolves when the proxy is loaded.
|
|
39
|
-
*/
|
|
40
|
-
start() {
|
|
41
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
yield this.proxy.load();
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Stops the execution of the program and unloads the proxy.
|
|
47
|
-
* @param {any} [err] - Optional error object to pass to the unload method.
|
|
48
|
-
* @returns {Promise<void>} - A promise that resolves once the proxy is unloaded.
|
|
49
|
-
*/
|
|
50
|
-
stop(err) {
|
|
51
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
-
yield this.proxy.unload(err);
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Listens for process events and handles them accordingly.
|
|
57
|
-
* @private
|
|
58
|
-
* @returns None
|
|
59
|
-
*/
|
|
60
|
-
listenProcessEvents() {
|
|
61
|
-
// start process listeners
|
|
62
|
-
process.on('unhandledRejection', this.stop.bind(this)); // listen to exceptions
|
|
63
|
-
process.on('SIGINT', this.stop.bind(this)); // listen on SIGINT signal and gracefully stop the server
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
//# sourceMappingURL=ContainerServer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ContainerServer.js","sourceRoot":"","sources":["../../../../src/Server/lib/ContainerServer.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,KAAK,MAAM,sBAAsB,CAAA;AACxC,OAAO,MAAM,MAAM,aAAa,CAAA;AAGhC;;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,45 +0,0 @@
|
|
|
1
|
-
import { APIGatewayProxyEvent, Context } from 'aws-lambda';
|
|
2
|
-
import { RouterConfig } from '../Router.js';
|
|
3
|
-
import RouteResolver from '../RouteResolver.js';
|
|
4
|
-
/**
|
|
5
|
-
* Represents a server that handles serverless events and routes them to appropriate handlers.
|
|
6
|
-
*/
|
|
7
|
-
export default class Server {
|
|
8
|
-
/**
|
|
9
|
-
* The configuration object for the router.
|
|
10
|
-
* @readonly
|
|
11
|
-
* @type {RouterConfig}
|
|
12
|
-
*/
|
|
13
|
-
protected readonly config: RouterConfig;
|
|
14
|
-
/**
|
|
15
|
-
* A protected property that holds a RouteResolver object.
|
|
16
|
-
* The RouteResolver is responsible for resolving routes and returning the appropriate response.
|
|
17
|
-
* @type {RouteResolver}
|
|
18
|
-
*/
|
|
19
|
-
protected readonly routeResolver: RouteResolver;
|
|
20
|
-
/**
|
|
21
|
-
* Constructs a new instance of the Router class.
|
|
22
|
-
* @param {RouterConfig} config - The configuration object for the router.
|
|
23
|
-
* @returns None
|
|
24
|
-
*/
|
|
25
|
-
constructor(config: RouterConfig);
|
|
26
|
-
/**
|
|
27
|
-
* Returns a callable function that is bound to the `handleServerlessEvent` method of the current object.
|
|
28
|
-
* @returns {CallableFunction} - A callable function that is bound to the `handleServerlessEvent` method.
|
|
29
|
-
*/
|
|
30
|
-
getExport(): CallableFunction;
|
|
31
|
-
/**
|
|
32
|
-
* Handles a serverless event by executing a transaction and resolving the route based on the event.
|
|
33
|
-
* @param {APIGatewayProxyEvent} event - The serverless event object.
|
|
34
|
-
* @param {Context} context - The serverless context object.
|
|
35
|
-
* @returns None
|
|
36
|
-
*/
|
|
37
|
-
handleServerlessEvent(event: APIGatewayProxyEvent, context: Context): Promise<void>;
|
|
38
|
-
/**
|
|
39
|
-
* Parses the path parameters from the request URL based on the given route path.
|
|
40
|
-
* @param {Request<any>} req - The request object.
|
|
41
|
-
* @param {string} routePath - The route path pattern to match against.
|
|
42
|
-
* @returns None
|
|
43
|
-
*/
|
|
44
|
-
private parsePathParams;
|
|
45
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { pathToRegexp } from 'path-to-regexp';
|
|
11
|
-
import Response from '../../API/Response.js';
|
|
12
|
-
import Transaction from '../../BaseEvent/Transaction.js';
|
|
13
|
-
import Validator from '../../Validation/Validator.js';
|
|
14
|
-
import RouteResolver from '../RouteResolver.js';
|
|
15
|
-
/**
|
|
16
|
-
* Represents a server that handles serverless events and routes them to appropriate handlers.
|
|
17
|
-
*/
|
|
18
|
-
export default class Server {
|
|
19
|
-
/**
|
|
20
|
-
* Constructs a new instance of the Router class.
|
|
21
|
-
* @param {RouterConfig} config - The configuration object for the router.
|
|
22
|
-
* @returns None
|
|
23
|
-
*/
|
|
24
|
-
constructor(config) {
|
|
25
|
-
this.config = config;
|
|
26
|
-
this.routeResolver = new RouteResolver(config);
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Returns a callable function that is bound to the `handleServerlessEvent` method of the current object.
|
|
30
|
-
* @returns {CallableFunction} - A callable function that is bound to the `handleServerlessEvent` method.
|
|
31
|
-
*/
|
|
32
|
-
getExport() {
|
|
33
|
-
return this.handleServerlessEvent.bind(this);
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Handles a serverless event by executing a transaction and resolving the route based on the event.
|
|
37
|
-
* @param {APIGatewayProxyEvent} event - The serverless event object.
|
|
38
|
-
* @param {Context} context - The serverless context object.
|
|
39
|
-
* @returns None
|
|
40
|
-
*/
|
|
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
|
-
for (const path of Array.isArray(route.path) ? route.path : [route.path]) {
|
|
63
|
-
this.parsePathParams(request, path);
|
|
64
|
-
}
|
|
65
|
-
// Validate path
|
|
66
|
-
if (route.pathSchema) {
|
|
67
|
-
const validationResp = Validator.validateSchema(request.getPathParams(), route.pathSchema);
|
|
68
|
-
if (validationResp && validationResp instanceof Response)
|
|
69
|
-
return validationResp;
|
|
70
|
-
}
|
|
71
|
-
// Continue to route handler
|
|
72
|
-
return yield route.handler(transaction);
|
|
73
|
-
}
|
|
74
|
-
//No route found :/
|
|
75
|
-
return new Response(404, { err: 'Route not found!' });
|
|
76
|
-
}));
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Parses the path parameters from the request URL based on the given route path.
|
|
81
|
-
* @param {Request<any>} req - The request object.
|
|
82
|
-
* @param {string} routePath - The route path pattern to match against.
|
|
83
|
-
* @returns None
|
|
84
|
-
*/
|
|
85
|
-
parsePathParams(req, routePath) {
|
|
86
|
-
const path = req.getPath();
|
|
87
|
-
const regex = pathToRegexp(routePath);
|
|
88
|
-
const result = regex.regexp.exec(path);
|
|
89
|
-
if (result)
|
|
90
|
-
req.setFixedPathParams(regex.keys, result);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
//# sourceMappingURL=Server.js.map
|