@forklaunch/express 0.1.0 → 0.1.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/LICENSE +21 -0
- package/lib/eslint.config.d.mts +3 -0
- package/lib/eslint.config.d.mts.map +1 -0
- package/lib/eslint.config.mjs +10 -0
- package/lib/index.d.ts +22 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +25 -0
- package/lib/jest.config.d.ts +4 -0
- package/lib/jest.config.d.ts.map +1 -0
- package/lib/jest.config.js +21 -0
- package/lib/src/expressApplication.d.ts +37 -0
- package/lib/src/expressApplication.d.ts.map +1 -0
- package/lib/src/expressApplication.js +60 -0
- package/lib/src/expressRouter.d.ts +46 -0
- package/lib/src/expressRouter.d.ts.map +1 -0
- package/lib/src/expressRouter.js +91 -0
- package/lib/src/middleware/async.middleware.d.ts +16 -0
- package/lib/src/middleware/async.middleware.d.ts.map +1 -0
- package/{dist → lib/src}/middleware/async.middleware.js +5 -11
- package/{dist → lib/src}/middleware/response.middleware.d.ts +5 -2
- package/lib/src/middleware/response.middleware.d.ts.map +1 -0
- package/{dist → lib/src}/middleware/response.middleware.js +20 -22
- package/lib/src/types/express.types.d.ts +28 -0
- package/lib/src/types/express.types.d.ts.map +1 -0
- package/lib/tests/typebox.forklaunch.express.test.d.ts +2 -0
- package/lib/tests/typebox.forklaunch.express.test.d.ts.map +1 -0
- package/{tests/typebox.forklaunch.express.test.ts → lib/tests/typebox.forklaunch.express.test.js} +11 -36
- package/lib/tests/zod.forklaunch.express.test.d.ts +2 -0
- package/lib/tests/zod.forklaunch.express.test.d.ts.map +1 -0
- package/{tests/zod.forklaunch.express.test.ts → lib/tests/zod.forklaunch.express.test.js} +16 -41
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/vitest.config.d.ts +3 -0
- package/lib/vitest.config.d.ts.map +1 -0
- package/lib/vitest.config.js +7 -0
- package/package.json +29 -16
- package/.prettierignore +0 -2
- package/.prettierrc +0 -7
- package/dist/forklaunch.express.d.ts +0 -198
- package/dist/forklaunch.express.js +0 -375
- package/dist/forklaunch.express.js.map +0 -1
- package/dist/jest.config.d.ts +0 -3
- package/dist/jest.config.js.map +0 -1
- package/dist/middleware/async.middleware.d.ts +0 -18
- package/dist/middleware/async.middleware.js.map +0 -1
- package/dist/middleware/response.middleware.js.map +0 -1
- package/dist/tests/typebox.forklaunch.express.test.js +0 -141
- package/dist/tests/typebox.forklaunch.express.test.js.map +0 -1
- package/dist/tests/zod.forklaunch.express.test.d.ts +0 -1
- package/dist/tests/zod.forklaunch.express.test.js +0 -141
- package/dist/tests/zod.forklaunch.express.test.js.map +0 -1
- package/dist/types/forklaunch.express.types.d.ts +0 -53
- package/dist/types/forklaunch.express.types.js +0 -3
- package/dist/types/forklaunch.express.types.js.map +0 -1
- package/eslint.config.mjs +0 -12
- package/forklaunch.express.ts +0 -617
- package/jest.config.ts +0 -10
- /package/{dist/tests/typebox.forklaunch.express.test.d.ts → lib/src/types/express.types.js} +0 -0
@@ -1,198 +0,0 @@
|
|
1
|
-
import { Body, ForklaunchRoute, ForklaunchRouter, HttpContractDetails, ParamsObject, PathParamHttpContractDetails, QueryObject, ResponsesObject } from '@forklaunch/core';
|
2
|
-
import { AnySchemaValidator } from '@forklaunch/validator';
|
3
|
-
import { Router as ExpressRouter, NextFunction } from 'express';
|
4
|
-
import { Server } from 'http';
|
5
|
-
import { Request, RequestHandler, Response, SchemaRequestHandler } from './types/forklaunch.express.types';
|
6
|
-
/**
|
7
|
-
* Application class that sets up an Express server with Forklaunch routers and middleware.
|
8
|
-
*
|
9
|
-
* @template SV - A type that extends AnySchemaValidator.
|
10
|
-
*/
|
11
|
-
export declare class Application<SV extends AnySchemaValidator> {
|
12
|
-
private schemaValidator;
|
13
|
-
internal: import("express-serve-static-core").Express;
|
14
|
-
private routers;
|
15
|
-
/**
|
16
|
-
* Creates an instance of Application.
|
17
|
-
*
|
18
|
-
* @param {SV} schemaValidator - The schema validator.
|
19
|
-
*/
|
20
|
-
constructor(schemaValidator: SV);
|
21
|
-
/**
|
22
|
-
* Registers middleware or routers to the application.
|
23
|
-
*
|
24
|
-
* @param {...(Router<SV> | RequestHandler<SV>)[]} args - The middleware or routers to register.
|
25
|
-
* @returns {this} - The application instance.
|
26
|
-
*/
|
27
|
-
use(router: (Router<SV> | RequestHandler<SV>), ...args: (Router<SV> | RequestHandler<SV>)[]): this;
|
28
|
-
/**
|
29
|
-
* Starts the server and sets up Swagger documentation.
|
30
|
-
*
|
31
|
-
* @param {...unknown[]} args - The arguments to pass to the listen method.
|
32
|
-
* @returns {Server} - The HTTP server.
|
33
|
-
*/
|
34
|
-
listen(port: number, hostname: string, backlog: number, callback?: () => void): Server;
|
35
|
-
listen(port: number, hostname: string, callback?: () => void): Server;
|
36
|
-
listen(port: number, callback?: () => void): Server;
|
37
|
-
listen(callback?: () => void): Server;
|
38
|
-
listen(path: string, callback?: () => void): Server;
|
39
|
-
listen(handle: any, listeningListener?: () => void): Server;
|
40
|
-
}
|
41
|
-
/**
|
42
|
-
* Creates a new instance of Application with the given schema validator.
|
43
|
-
*
|
44
|
-
* @template SV - A type that extends AnySchemaValidator.
|
45
|
-
* @param {SV} schemaValidator - The schema validator.
|
46
|
-
* @returns {Application<SV>} - The new application instance.
|
47
|
-
*/
|
48
|
-
export default function forklaunchExpress<SV extends AnySchemaValidator>(schemaValidator: SV): Application<SV>;
|
49
|
-
/**
|
50
|
-
* Router class that sets up routes and middleware for an Express router.
|
51
|
-
*
|
52
|
-
* @template SV - A type that extends AnySchemaValidator.
|
53
|
-
* @implements {ForklaunchRouter<SV>}
|
54
|
-
*/
|
55
|
-
export declare class Router<SV extends AnySchemaValidator> implements ForklaunchRouter<SV> {
|
56
|
-
basePath: `/${string}`;
|
57
|
-
schemaValidator: SV;
|
58
|
-
readonly routes: ForklaunchRoute<SV>[];
|
59
|
-
readonly internal: ExpressRouter;
|
60
|
-
/**
|
61
|
-
* Creates an instance of Router.
|
62
|
-
*
|
63
|
-
* @param {string} basePath - The base path for the router.
|
64
|
-
* @param {SV} schemaValidator - The schema validator.
|
65
|
-
*/
|
66
|
-
constructor(basePath: `/${string}`, schemaValidator: SV);
|
67
|
-
/**
|
68
|
-
* Resolves middlewares based on the contract details.
|
69
|
-
*
|
70
|
-
* @param {PathParamHttpContractDetails<SV> | HttpContractDetails<SV>} contractDetails - The contract details.
|
71
|
-
* @returns {RequestHandler<SV>[]} - The resolved middlewares.
|
72
|
-
*/
|
73
|
-
private resolveMiddlewares;
|
74
|
-
/**
|
75
|
-
* Parses and runs the controller function with error handling.
|
76
|
-
*
|
77
|
-
* @template P - The type of request parameters.
|
78
|
-
* @template ResBody - The type of response body.
|
79
|
-
* @template ReqBody - The type of request body.
|
80
|
-
* @template ReqQuery - The type of request query.
|
81
|
-
* @template LocalsObj - The type of local variables.
|
82
|
-
* @template StatusCode - The type of status code.
|
83
|
-
* @param {RequestHandler<SV, P, ResBody | string, ReqBody, ReqQuery, LocalsObj, StatusCode>} requestHandler - The request handler.
|
84
|
-
* @returns {ExpressRequestHandler} - The Express request handler.
|
85
|
-
*/
|
86
|
-
private parseAndRunControllerFunction;
|
87
|
-
/**
|
88
|
-
* Extracts the controller function from the provided functions.
|
89
|
-
*
|
90
|
-
* @template P - The type of request parameters.
|
91
|
-
* @template ResBody - The type of response body.
|
92
|
-
* @template ReqBody - The type of request body.
|
93
|
-
* @template ReqQuery - The type of request query.
|
94
|
-
* @template LocalsObj - The type of local variables.
|
95
|
-
* @template StatusCode - The type of status code.
|
96
|
-
* @param {RequestHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj, StatusCode>[]} functions - The provided functions.
|
97
|
-
* @returns {RequestHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj, StatusCode>} - The extracted controller function.
|
98
|
-
* @throws {Error} - Throws an error if the last argument is not a function.
|
99
|
-
*/
|
100
|
-
private extractControllerFunction;
|
101
|
-
/**
|
102
|
-
* Extracts the SDK path from the given path.
|
103
|
-
*
|
104
|
-
* @param {string | RegExp | (string | RegExp)[]} path - The provided path.
|
105
|
-
* @returns {string} - The extracted SDK path.
|
106
|
-
* @throws {Error} - Throws an error if the path is not defined.
|
107
|
-
*/
|
108
|
-
private extractSdkPath;
|
109
|
-
/**
|
110
|
-
* Registers middleware to the router.
|
111
|
-
*
|
112
|
-
* @param {...unknown[]} args - The middleware to register.
|
113
|
-
* @returns {this} - The router instance.
|
114
|
-
*/
|
115
|
-
use(...args: unknown[]): this;
|
116
|
-
/**
|
117
|
-
* Registers a GET route with the specified contract details and handler functions.
|
118
|
-
*
|
119
|
-
* @template P - The type of request parameters.
|
120
|
-
* @template ResBody - The type of response body.
|
121
|
-
* @template ReqBody - The type of request body.
|
122
|
-
* @template ReqQuery - The type of request query.
|
123
|
-
* @template LocalsObj - The type of local variables.
|
124
|
-
* @param {string | RegExp | (string | RegExp)[]} path - The path for the route.
|
125
|
-
* @param {PathParamHttpContractDetails<SV, P, ResBody, ReqQuery>} contractDetails - The contract details.
|
126
|
-
* @param {...SchemaRequestHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>[]} functions - The handler functions.
|
127
|
-
*/
|
128
|
-
get<P extends ParamsObject<SV> = ParamsObject<SV>, ResBody extends ResponsesObject<SV> = ResponsesObject<SV>, ReqBody extends Body<SV> = Body<SV>, ReqQuery extends QueryObject<SV> = QueryObject<SV>, LocalsObj extends Record<string, unknown> = Record<string, unknown>>(path: string | RegExp | (string | RegExp)[], contractDetails: PathParamHttpContractDetails<SV, P, ResBody, ReqQuery>, ...functions: SchemaRequestHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>[]): void;
|
129
|
-
/**
|
130
|
-
* Registers a POST route with the specified contract details and handler functions.
|
131
|
-
*
|
132
|
-
* @template P - The type of request parameters.
|
133
|
-
* @template ResBody - The type of response body.
|
134
|
-
* @template ReqBody - The type of request body.
|
135
|
-
* @template ReqQuery - The type of request query.
|
136
|
-
* @template LocalsObj - The type of local variables.
|
137
|
-
* @param {string | RegExp | (string | RegExp)[]} path - The path for the route.
|
138
|
-
* @param {HttpContractDetails<SV, P, ResBody, ReqBody, ReqQuery>} contractDetails - The contract details.
|
139
|
-
* @param {...SchemaRequestHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>[]} functions - The handler functions.
|
140
|
-
*/
|
141
|
-
post<P extends ParamsObject<SV> = ParamsObject<SV>, ResBody extends ResponsesObject<SV> = ResponsesObject<SV>, ReqBody extends Body<SV> = Body<SV>, ReqQuery extends QueryObject<SV> = QueryObject<SV>, LocalsObj extends Record<string, unknown> = Record<string, unknown>>(path: string | RegExp | (string | RegExp)[], contractDetails: HttpContractDetails<SV, P, ResBody, ReqBody, ReqQuery>, ...functions: SchemaRequestHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>[]): void;
|
142
|
-
/**
|
143
|
-
* Registers a PUT route with the specified contract details and handler functions.
|
144
|
-
*
|
145
|
-
* @template P - The type of request parameters.
|
146
|
-
* @template ResBody - The type of response body.
|
147
|
-
* @template ReqBody - The type of request body.
|
148
|
-
* @template ReqQuery - The type of request query.
|
149
|
-
* @template LocalsObj - The type of local variables.
|
150
|
-
* @param {string | RegExp | (string | RegExp)[]} path - The path for the route.
|
151
|
-
* @param {HttpContractDetails<SV, P, ResBody, ReqBody, ReqQuery>} contractDetails - The contract details.
|
152
|
-
* @param {...SchemaRequestHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>[]} functions - The handler functions.
|
153
|
-
*/
|
154
|
-
put<P extends ParamsObject<SV> = ParamsObject<SV>, ResBody extends ResponsesObject<SV> = ResponsesObject<SV>, ReqBody extends Body<SV> = Body<SV>, ReqQuery extends QueryObject<SV> = QueryObject<SV>, LocalsObj extends Record<string, unknown> = Record<string, unknown>>(path: string | RegExp | (string | RegExp)[], contractDetails: HttpContractDetails<SV, P, ResBody, ReqBody, ReqQuery>, ...functions: SchemaRequestHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>[]): void;
|
155
|
-
/**
|
156
|
-
* Registers a PATCH route with the specified contract details and handler functions.
|
157
|
-
*
|
158
|
-
* @template P - The type of request parameters.
|
159
|
-
* @template ResBody - The type of response body.
|
160
|
-
* @template ReqBody - The type of request body.
|
161
|
-
* @template ReqQuery - The type of request query.
|
162
|
-
* @template LocalsObj - The type of local variables.
|
163
|
-
* @param {string | RegExp | (string | RegExp)[]} path - The path for the route.
|
164
|
-
* @param {HttpContractDetails<SV, P, ResBody, ReqBody, ReqQuery>} contractDetails - The contract details.
|
165
|
-
* @param {...SchemaRequestHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>[]} functions - The handler functions.
|
166
|
-
*/
|
167
|
-
patch<P extends ParamsObject<SV> = ParamsObject<SV>, ResBody extends ResponsesObject<SV> = ResponsesObject<SV>, ReqBody extends Body<SV> = Body<SV>, ReqQuery extends QueryObject<SV> = QueryObject<SV>, LocalsObj extends Record<string, unknown> = Record<string, unknown>>(path: string | RegExp | (string | RegExp)[], contractDetails: HttpContractDetails<SV, P, ResBody, ReqBody, ReqQuery>, ...functions: SchemaRequestHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>[]): void;
|
168
|
-
/**
|
169
|
-
* Registers a DELETE route with the specified contract details and handler functions.
|
170
|
-
*
|
171
|
-
* @template P - The type of request parameters.
|
172
|
-
* @template ResBody - The type of response body.
|
173
|
-
* @template ReqBody - The type of request body.
|
174
|
-
* @template ReqQuery - The type of request query.
|
175
|
-
* @template LocalsObj - The type of local variables.
|
176
|
-
* @param {string | RegExp | (string | RegExp)[]} path - The path for the route.
|
177
|
-
* @param {PathParamHttpContractDetails<SV, P, ResBody, ReqQuery>} contractDetails - The contract details.
|
178
|
-
* @param {...SchemaRequestHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>[]} functions - The handler functions.
|
179
|
-
*/
|
180
|
-
delete<P extends ParamsObject<SV> = ParamsObject<SV>, ResBody extends ResponsesObject<SV> = ResponsesObject<SV>, ReqBody extends Body<SV> = Body<SV>, ReqQuery extends QueryObject<SV> = QueryObject<SV>, LocalsObj extends Record<string, unknown> = Record<string, unknown>>(path: string | RegExp | (string | RegExp)[], contractDetails: PathParamHttpContractDetails<SV, P, ResBody, ReqQuery>, ...functions: SchemaRequestHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>[]): void;
|
181
|
-
/**
|
182
|
-
* Handles the incoming request.
|
183
|
-
*
|
184
|
-
* @param {Request<SV>} req - The request object.
|
185
|
-
* @param {Response} res - The response object.
|
186
|
-
* @param {NextFunction} out - The next middleware function.
|
187
|
-
*/
|
188
|
-
handle(req: Request<SV>, res: Response, out: NextFunction): void;
|
189
|
-
}
|
190
|
-
/**
|
191
|
-
* Creates a new instance of Router with the given base path and schema validator.
|
192
|
-
*
|
193
|
-
* @template SV - A type that extends AnySchemaValidator.
|
194
|
-
* @param {string} basePath - The base path for the router.
|
195
|
-
* @param {SV} schemaValidator - The schema validator.
|
196
|
-
* @returns {Router<SV>} - The new router instance.
|
197
|
-
*/
|
198
|
-
export declare function forklaunchRouter<SV extends AnySchemaValidator>(basePath: `/${string}`, schemaValidator: SV): Router<SV>;
|
@@ -1,375 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
-
if (k2 === undefined) k2 = k;
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
-
}
|
8
|
-
Object.defineProperty(o, k2, desc);
|
9
|
-
}) : (function(o, m, k, k2) {
|
10
|
-
if (k2 === undefined) k2 = k;
|
11
|
-
o[k2] = m[k];
|
12
|
-
}));
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
-
}) : function(o, v) {
|
16
|
-
o["default"] = v;
|
17
|
-
});
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
-
if (mod && mod.__esModule) return mod;
|
20
|
-
var result = {};
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
-
__setModuleDefault(result, mod);
|
23
|
-
return result;
|
24
|
-
};
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
27
|
-
};
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
29
|
-
exports.Router = exports.Application = void 0;
|
30
|
-
exports.default = forklaunchExpress;
|
31
|
-
exports.forklaunchRouter = forklaunchRouter;
|
32
|
-
const core_1 = require("@forklaunch/core");
|
33
|
-
const express_1 = __importStar(require("express"));
|
34
|
-
const swagger_ui_express_1 = __importDefault(require("swagger-ui-express"));
|
35
|
-
const async_middleware_1 = require("./middleware/async.middleware");
|
36
|
-
const response_middleware_1 = require("./middleware/response.middleware");
|
37
|
-
/**
|
38
|
-
* Application class that sets up an Express server with Forklaunch routers and middleware.
|
39
|
-
*
|
40
|
-
* @template SV - A type that extends AnySchemaValidator.
|
41
|
-
*/
|
42
|
-
class Application {
|
43
|
-
schemaValidator;
|
44
|
-
internal = (0, express_1.default)();
|
45
|
-
routers = [];
|
46
|
-
/**
|
47
|
-
* Creates an instance of Application.
|
48
|
-
*
|
49
|
-
* @param {SV} schemaValidator - The schema validator.
|
50
|
-
*/
|
51
|
-
constructor(schemaValidator) {
|
52
|
-
this.schemaValidator = schemaValidator;
|
53
|
-
}
|
54
|
-
//TODO: change this to different signatures and handle different cases
|
55
|
-
/**
|
56
|
-
* Registers middleware or routers to the application.
|
57
|
-
*
|
58
|
-
* @param {...(Router<SV> | RequestHandler<SV>)[]} args - The middleware or routers to register.
|
59
|
-
* @returns {this} - The application instance.
|
60
|
-
*/
|
61
|
-
use(router, ...args) {
|
62
|
-
if (router instanceof Router) {
|
63
|
-
this.routers.push(router);
|
64
|
-
this.internal.use(router.basePath, router.internal);
|
65
|
-
return this;
|
66
|
-
}
|
67
|
-
else {
|
68
|
-
const router = args.pop();
|
69
|
-
if (!(router instanceof Router)) {
|
70
|
-
throw new Error('Last argument must be a router');
|
71
|
-
}
|
72
|
-
args.forEach((arg) => {
|
73
|
-
if (arg instanceof Router) {
|
74
|
-
throw new Error('Only one router is allowed');
|
75
|
-
}
|
76
|
-
});
|
77
|
-
this.internal.use(router.basePath, ...args, router.internal);
|
78
|
-
return this;
|
79
|
-
}
|
80
|
-
}
|
81
|
-
listen(...args) {
|
82
|
-
const port = typeof args[0] === 'number' ? args[0] : Number(process.env.PORT);
|
83
|
-
this.internal.use(`/api${process.env.VERSION ?? '/v1'}${process.env.SWAGGER_PATH ?? '/swagger'}`, swagger_ui_express_1.default.serve, swagger_ui_express_1.default.setup((0, core_1.generateSwaggerDocument)(this.schemaValidator, port, this.routers)));
|
84
|
-
return this.internal.listen(...args);
|
85
|
-
}
|
86
|
-
}
|
87
|
-
exports.Application = Application;
|
88
|
-
/**
|
89
|
-
* Creates a new instance of Application with the given schema validator.
|
90
|
-
*
|
91
|
-
* @template SV - A type that extends AnySchemaValidator.
|
92
|
-
* @param {SV} schemaValidator - The schema validator.
|
93
|
-
* @returns {Application<SV>} - The new application instance.
|
94
|
-
*/
|
95
|
-
function forklaunchExpress(schemaValidator) {
|
96
|
-
return new Application(schemaValidator);
|
97
|
-
}
|
98
|
-
/**
|
99
|
-
* Router class that sets up routes and middleware for an Express router.
|
100
|
-
*
|
101
|
-
* @template SV - A type that extends AnySchemaValidator.
|
102
|
-
* @implements {ForklaunchRouter<SV>}
|
103
|
-
*/
|
104
|
-
class Router {
|
105
|
-
basePath;
|
106
|
-
schemaValidator;
|
107
|
-
routes = [];
|
108
|
-
internal = (0, express_1.Router)();
|
109
|
-
/**
|
110
|
-
* Creates an instance of Router.
|
111
|
-
*
|
112
|
-
* @param {string} basePath - The base path for the router.
|
113
|
-
* @param {SV} schemaValidator - The schema validator.
|
114
|
-
*/
|
115
|
-
constructor(basePath, schemaValidator) {
|
116
|
-
this.basePath = basePath;
|
117
|
-
this.schemaValidator = schemaValidator;
|
118
|
-
this.internal.use(express_1.default.json());
|
119
|
-
this.internal.use((0, core_1.createRequestContext)(schemaValidator));
|
120
|
-
this.internal.use(response_middleware_1.enrichResponseTransmission);
|
121
|
-
}
|
122
|
-
/**
|
123
|
-
* Resolves middlewares based on the contract details.
|
124
|
-
*
|
125
|
-
* @param {PathParamHttpContractDetails<SV> | HttpContractDetails<SV>} contractDetails - The contract details.
|
126
|
-
* @returns {RequestHandler<SV>[]} - The resolved middlewares.
|
127
|
-
*/
|
128
|
-
resolveMiddlewares(contractDetails) {
|
129
|
-
const middlewares = [
|
130
|
-
(0, core_1.enrichRequestDetails)(contractDetails)
|
131
|
-
];
|
132
|
-
if (contractDetails.params) {
|
133
|
-
middlewares.push(core_1.parseRequestParams);
|
134
|
-
}
|
135
|
-
if (contractDetails.body) {
|
136
|
-
middlewares.push(core_1.parseRequestBody);
|
137
|
-
}
|
138
|
-
if (contractDetails.requestHeaders) {
|
139
|
-
middlewares.push(core_1.parseRequestHeaders);
|
140
|
-
}
|
141
|
-
if (contractDetails.query) {
|
142
|
-
middlewares.push(core_1.parseRequestQuery);
|
143
|
-
}
|
144
|
-
if (contractDetails.auth) {
|
145
|
-
middlewares.push((0, async_middleware_1.asyncMiddleware)(core_1.parseRequestAuth));
|
146
|
-
}
|
147
|
-
return middlewares;
|
148
|
-
}
|
149
|
-
/**
|
150
|
-
* Parses and runs the controller function with error handling.
|
151
|
-
*
|
152
|
-
* @template P - The type of request parameters.
|
153
|
-
* @template ResBody - The type of response body.
|
154
|
-
* @template ReqBody - The type of request body.
|
155
|
-
* @template ReqQuery - The type of request query.
|
156
|
-
* @template LocalsObj - The type of local variables.
|
157
|
-
* @template StatusCode - The type of status code.
|
158
|
-
* @param {RequestHandler<SV, P, ResBody | string, ReqBody, ReqQuery, LocalsObj, StatusCode>} requestHandler - The request handler.
|
159
|
-
* @returns {ExpressRequestHandler} - The Express request handler.
|
160
|
-
*/
|
161
|
-
parseAndRunControllerFunction(requestHandler) {
|
162
|
-
return async (req, res, next) => {
|
163
|
-
if (!requestHandler) {
|
164
|
-
throw new Error('Controller function is not defined');
|
165
|
-
}
|
166
|
-
try {
|
167
|
-
// TODO: Add support for transactions
|
168
|
-
await requestHandler(req, res, next);
|
169
|
-
}
|
170
|
-
catch (error) {
|
171
|
-
if (next) {
|
172
|
-
next(error);
|
173
|
-
}
|
174
|
-
console.error(error);
|
175
|
-
if (!res.headersSent) {
|
176
|
-
res.status(500).send('Internal Server Error');
|
177
|
-
}
|
178
|
-
}
|
179
|
-
};
|
180
|
-
}
|
181
|
-
/**
|
182
|
-
* Extracts the controller function from the provided functions.
|
183
|
-
*
|
184
|
-
* @template P - The type of request parameters.
|
185
|
-
* @template ResBody - The type of response body.
|
186
|
-
* @template ReqBody - The type of request body.
|
187
|
-
* @template ReqQuery - The type of request query.
|
188
|
-
* @template LocalsObj - The type of local variables.
|
189
|
-
* @template StatusCode - The type of status code.
|
190
|
-
* @param {RequestHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj, StatusCode>[]} functions - The provided functions.
|
191
|
-
* @returns {RequestHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj, StatusCode>} - The extracted controller function.
|
192
|
-
* @throws {Error} - Throws an error if the last argument is not a function.
|
193
|
-
*/
|
194
|
-
extractControllerFunction(functions) {
|
195
|
-
const controllerFunction = functions.pop();
|
196
|
-
if (typeof controllerFunction !== 'function') {
|
197
|
-
throw new Error('Last argument must be a function');
|
198
|
-
}
|
199
|
-
return controllerFunction;
|
200
|
-
}
|
201
|
-
/**
|
202
|
-
* Extracts the SDK path from the given path.
|
203
|
-
*
|
204
|
-
* @param {string | RegExp | (string | RegExp)[]} path - The provided path.
|
205
|
-
* @returns {string} - The extracted SDK path.
|
206
|
-
* @throws {Error} - Throws an error if the path is not defined.
|
207
|
-
*/
|
208
|
-
extractSdkPath(path) {
|
209
|
-
let sdkPath = path;
|
210
|
-
if (Array.isArray(path)) {
|
211
|
-
sdkPath = path.pop() || path[0];
|
212
|
-
}
|
213
|
-
if (!sdkPath) {
|
214
|
-
throw new Error('Path is not defined');
|
215
|
-
}
|
216
|
-
if (sdkPath instanceof RegExp) {
|
217
|
-
sdkPath = (0, core_1.generateStringFromRegex)(sdkPath);
|
218
|
-
}
|
219
|
-
return sdkPath;
|
220
|
-
}
|
221
|
-
/**
|
222
|
-
* Registers middleware to the router.
|
223
|
-
*
|
224
|
-
* @param {...unknown[]} args - The middleware to register.
|
225
|
-
* @returns {this} - The router instance.
|
226
|
-
*/
|
227
|
-
use(...args) {
|
228
|
-
this.internal.use(...args);
|
229
|
-
return this;
|
230
|
-
}
|
231
|
-
/**
|
232
|
-
* Registers a GET route with the specified contract details and handler functions.
|
233
|
-
*
|
234
|
-
* @template P - The type of request parameters.
|
235
|
-
* @template ResBody - The type of response body.
|
236
|
-
* @template ReqBody - The type of request body.
|
237
|
-
* @template ReqQuery - The type of request query.
|
238
|
-
* @template LocalsObj - The type of local variables.
|
239
|
-
* @param {string | RegExp | (string | RegExp)[]} path - The path for the route.
|
240
|
-
* @param {PathParamHttpContractDetails<SV, P, ResBody, ReqQuery>} contractDetails - The contract details.
|
241
|
-
* @param {...SchemaRequestHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>[]} functions - The handler functions.
|
242
|
-
*/
|
243
|
-
get(path, contractDetails, ...functions) {
|
244
|
-
const controllerFunction = this.extractControllerFunction(functions);
|
245
|
-
const sdkPath = this.extractSdkPath(path);
|
246
|
-
this.routes.push({
|
247
|
-
basePath: this.basePath,
|
248
|
-
path,
|
249
|
-
sdkPath,
|
250
|
-
method: 'get',
|
251
|
-
contractDetails
|
252
|
-
});
|
253
|
-
this.internal.get(path, ...functions.concat(this.resolveMiddlewares(contractDetails)), this.parseAndRunControllerFunction(controllerFunction));
|
254
|
-
}
|
255
|
-
/**
|
256
|
-
* Registers a POST route with the specified contract details and handler functions.
|
257
|
-
*
|
258
|
-
* @template P - The type of request parameters.
|
259
|
-
* @template ResBody - The type of response body.
|
260
|
-
* @template ReqBody - The type of request body.
|
261
|
-
* @template ReqQuery - The type of request query.
|
262
|
-
* @template LocalsObj - The type of local variables.
|
263
|
-
* @param {string | RegExp | (string | RegExp)[]} path - The path for the route.
|
264
|
-
* @param {HttpContractDetails<SV, P, ResBody, ReqBody, ReqQuery>} contractDetails - The contract details.
|
265
|
-
* @param {...SchemaRequestHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>[]} functions - The handler functions.
|
266
|
-
*/
|
267
|
-
post(path, contractDetails, ...functions) {
|
268
|
-
const controllerFunction = this.extractControllerFunction(functions);
|
269
|
-
const sdkPath = this.extractSdkPath(path);
|
270
|
-
this.routes.push({
|
271
|
-
basePath: this.basePath,
|
272
|
-
path,
|
273
|
-
sdkPath,
|
274
|
-
method: 'post',
|
275
|
-
contractDetails
|
276
|
-
});
|
277
|
-
this.internal.post(path, ...functions.concat(this.resolveMiddlewares(contractDetails)), this.parseAndRunControllerFunction(controllerFunction));
|
278
|
-
}
|
279
|
-
/**
|
280
|
-
* Registers a PUT route with the specified contract details and handler functions.
|
281
|
-
*
|
282
|
-
* @template P - The type of request parameters.
|
283
|
-
* @template ResBody - The type of response body.
|
284
|
-
* @template ReqBody - The type of request body.
|
285
|
-
* @template ReqQuery - The type of request query.
|
286
|
-
* @template LocalsObj - The type of local variables.
|
287
|
-
* @param {string | RegExp | (string | RegExp)[]} path - The path for the route.
|
288
|
-
* @param {HttpContractDetails<SV, P, ResBody, ReqBody, ReqQuery>} contractDetails - The contract details.
|
289
|
-
* @param {...SchemaRequestHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>[]} functions - The handler functions.
|
290
|
-
*/
|
291
|
-
put(path, contractDetails, ...functions) {
|
292
|
-
const controllerFunction = this.extractControllerFunction(functions);
|
293
|
-
const sdkPath = this.extractSdkPath(path);
|
294
|
-
this.routes.push({
|
295
|
-
basePath: this.basePath,
|
296
|
-
path,
|
297
|
-
sdkPath,
|
298
|
-
method: 'put',
|
299
|
-
contractDetails
|
300
|
-
});
|
301
|
-
this.internal.put(path, ...functions.concat(this.resolveMiddlewares(contractDetails)), this.parseAndRunControllerFunction(controllerFunction));
|
302
|
-
}
|
303
|
-
/**
|
304
|
-
* Registers a PATCH route with the specified contract details and handler functions.
|
305
|
-
*
|
306
|
-
* @template P - The type of request parameters.
|
307
|
-
* @template ResBody - The type of response body.
|
308
|
-
* @template ReqBody - The type of request body.
|
309
|
-
* @template ReqQuery - The type of request query.
|
310
|
-
* @template LocalsObj - The type of local variables.
|
311
|
-
* @param {string | RegExp | (string | RegExp)[]} path - The path for the route.
|
312
|
-
* @param {HttpContractDetails<SV, P, ResBody, ReqBody, ReqQuery>} contractDetails - The contract details.
|
313
|
-
* @param {...SchemaRequestHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>[]} functions - The handler functions.
|
314
|
-
*/
|
315
|
-
patch(path, contractDetails, ...functions) {
|
316
|
-
const controllerFunction = this.extractControllerFunction(functions);
|
317
|
-
const sdkPath = this.extractSdkPath(path);
|
318
|
-
this.routes.push({
|
319
|
-
basePath: this.basePath,
|
320
|
-
path,
|
321
|
-
sdkPath,
|
322
|
-
method: 'patch',
|
323
|
-
contractDetails
|
324
|
-
});
|
325
|
-
this.internal.patch(path, ...functions.concat(this.resolveMiddlewares(contractDetails)), this.parseAndRunControllerFunction(controllerFunction));
|
326
|
-
}
|
327
|
-
/**
|
328
|
-
* Registers a DELETE route with the specified contract details and handler functions.
|
329
|
-
*
|
330
|
-
* @template P - The type of request parameters.
|
331
|
-
* @template ResBody - The type of response body.
|
332
|
-
* @template ReqBody - The type of request body.
|
333
|
-
* @template ReqQuery - The type of request query.
|
334
|
-
* @template LocalsObj - The type of local variables.
|
335
|
-
* @param {string | RegExp | (string | RegExp)[]} path - The path for the route.
|
336
|
-
* @param {PathParamHttpContractDetails<SV, P, ResBody, ReqQuery>} contractDetails - The contract details.
|
337
|
-
* @param {...SchemaRequestHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>[]} functions - The handler functions.
|
338
|
-
*/
|
339
|
-
delete(path, contractDetails, ...functions) {
|
340
|
-
const controllerFunction = this.extractControllerFunction(functions);
|
341
|
-
const sdkPath = this.extractSdkPath(path);
|
342
|
-
this.routes.push({
|
343
|
-
basePath: this.basePath,
|
344
|
-
path,
|
345
|
-
sdkPath,
|
346
|
-
method: 'delete',
|
347
|
-
contractDetails
|
348
|
-
});
|
349
|
-
this.internal.delete(path, ...functions.concat(this.resolveMiddlewares(contractDetails)), this.parseAndRunControllerFunction(controllerFunction));
|
350
|
-
}
|
351
|
-
/**
|
352
|
-
* Handles the incoming request.
|
353
|
-
*
|
354
|
-
* @param {Request<SV>} req - The request object.
|
355
|
-
* @param {Response} res - The response object.
|
356
|
-
* @param {NextFunction} out - The next middleware function.
|
357
|
-
*/
|
358
|
-
handle(req, res, out) {
|
359
|
-
this.internal(req, res, out);
|
360
|
-
}
|
361
|
-
}
|
362
|
-
exports.Router = Router;
|
363
|
-
/**
|
364
|
-
* Creates a new instance of Router with the given base path and schema validator.
|
365
|
-
*
|
366
|
-
* @template SV - A type that extends AnySchemaValidator.
|
367
|
-
* @param {string} basePath - The base path for the router.
|
368
|
-
* @param {SV} schemaValidator - The schema validator.
|
369
|
-
* @returns {Router<SV>} - The new router instance.
|
370
|
-
*/
|
371
|
-
function forklaunchRouter(basePath, schemaValidator) {
|
372
|
-
const router = new Router(basePath, schemaValidator);
|
373
|
-
return router;
|
374
|
-
}
|
375
|
-
//# sourceMappingURL=forklaunch.express.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"forklaunch.express.js","sourceRoot":"","sources":["../forklaunch.express.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2HA,oCAIC;AAme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B,CACxB,EACxC,IAAI,CAAC,6BAA6B,CAC9B,kBAAkB,CACe,CACxC,CAAC;IACN,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,GAAgB,EAAE,GAAa,EAAE,GAAiB;QACrD,IAAI,CAAC,QAAQ,CACT,GAAqB,EACrB,GAAiC,EACjC,GAAG,CACN,CAAC;IACN,CAAC;CACJ;AAjdD,wBAidC;AAED;;;;;;;GAOG;AACH,SAAgB,gBAAgB,CAC5B,QAAsB,EACtB,eAAmB;IAEnB,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;IACrD,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
package/dist/jest.config.d.ts
DELETED
package/dist/jest.config.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"jest.config.js","sourceRoot":"","sources":["../jest.config.ts"],"names":[],"mappings":";;AAEA,MAAM,MAAM,GAAW;IACrB,OAAO,EAAE,IAAI;IACb,MAAM,EAAE,SAAS;IACjB,eAAe,EAAE,MAAM;IACvB,sBAAsB,EAAE,CAAC,OAAO,EAAE,eAAe,CAAC;CACnD,CAAC;AAEF,kBAAe,MAAM,CAAC"}
|
@@ -1,18 +0,0 @@
|
|
1
|
-
import { ParamsDictionary } from '@forklaunch/core';
|
2
|
-
import { AnySchemaValidator } from '@forklaunch/validator';
|
3
|
-
import { ParsedQs } from 'qs';
|
4
|
-
import { RequestHandler } from '../types/forklaunch.express.types';
|
5
|
-
/**
|
6
|
-
* Wraps an asynchronous middleware function to handle errors and pass them to the next middleware.
|
7
|
-
*
|
8
|
-
* @template SV - A type that extends AnySchemaValidator.
|
9
|
-
* @template P - A type for request parameters, defaulting to ParamsDictionary.
|
10
|
-
* @template ResBody - A type for the response body, defaulting to unknown.
|
11
|
-
* @template ReqBody - A type for the request body, defaulting to unknown.
|
12
|
-
* @template ReqQuery - A type for the request query, defaulting to ParsedQs.
|
13
|
-
* @template LocalsObj - A type for local variables, defaulting to an empty object.
|
14
|
-
* @template StatusCode - A type for the status code, defaulting to number.
|
15
|
-
* @param {RequestHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj, StatusCode>} fn - The asynchronous middleware function to wrap.
|
16
|
-
* @returns {RequestHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj, StatusCode>} - The wrapped middleware function.
|
17
|
-
*/
|
18
|
-
export declare function asyncMiddleware<SV extends AnySchemaValidator, P = ParamsDictionary, ResBody = unknown, ReqBody = unknown, ReqQuery = ParsedQs, LocalsObj extends Record<string, unknown> = Record<string, unknown>, StatusCode extends number = number>(fn: RequestHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj, StatusCode>): RequestHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj, StatusCode>;
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"async.middleware.js","sourceRoot":"","sources":["../../middleware/async.middleware.ts"],"names":[],"mappings":";;AAkBA,0CAiBC;AA9BD;;;;;;;;;;;;GAYG;AACH,SAAgB,eAAe,CAS7B,EAA4E;IAE5E,OAAO,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QAC9B,MAAM,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACtD,IAAI,IAAI,EAAE,CAAC;YACT,IAAI,EAAE,CAAC;QACT,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"response.middleware.js","sourceRoot":"","sources":["../../middleware/response.middleware.ts"],"names":[],"mappings":";;AAaA,gEAoDC;AAjED,2CAAiD;AAKjD;;;;;;;GAOG;AACH,SAAgB,0BAA0B,CACxC,GAAgB,EAChB,GAAa,EACb,IAAmB;IAEnB,MAAM,YAAY,GAAG,GAAG,CAAC,IAAI,CAAC;IAC9B,MAAM,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