@forklaunch/hyper-express 0.1.0

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.
Files changed (35) hide show
  1. package/.prettierignore +2 -0
  2. package/.prettierrc +7 -0
  3. package/dist/forklaunch.hyperExpress.d.ts +192 -0
  4. package/dist/forklaunch.hyperExpress.js +358 -0
  5. package/dist/forklaunch.hyperExpress.js.map +1 -0
  6. package/dist/jest.config.d.ts +3 -0
  7. package/dist/jest.config.js.map +1 -0
  8. package/dist/main.d.ts +1 -0
  9. package/dist/main.js +90 -0
  10. package/dist/main.js.map +1 -0
  11. package/dist/middleware/contentParse.middleware.d.ts +7 -0
  12. package/dist/middleware/contentParse.middleware.js +30 -0
  13. package/dist/middleware/contentParse.middleware.js.map +1 -0
  14. package/dist/middleware/response.middleware.d.ts +12 -0
  15. package/dist/middleware/response.middleware.js +54 -0
  16. package/dist/middleware/response.middleware.js.map +1 -0
  17. package/dist/middleware/swagger.middleware.d.ts +24 -0
  18. package/dist/middleware/swagger.middleware.js +90 -0
  19. package/dist/middleware/swagger.middleware.js.map +1 -0
  20. package/dist/tests/typebox.forklaunch.hyperExpress.test.d.ts +1 -0
  21. package/dist/tests/typebox.forklaunch.hyperExpress.test.js +141 -0
  22. package/dist/tests/typebox.forklaunch.hyperExpress.test.js.map +1 -0
  23. package/dist/tests/zod.forklaunch.hyperExpress.test.d.ts +1 -0
  24. package/dist/tests/zod.forklaunch.hyperExpress.test.js +141 -0
  25. package/dist/tests/zod.forklaunch.hyperExpress.test.js.map +1 -0
  26. package/dist/types/forklaunch.hyperExpress.types.d.ts +67 -0
  27. package/dist/types/forklaunch.hyperExpress.types.js +3 -0
  28. package/dist/types/forklaunch.hyperExpress.types.js.map +1 -0
  29. package/eslint.config.mjs +12 -0
  30. package/forklaunch.hyperExpress.ts +649 -0
  31. package/jest.config.ts +10 -0
  32. package/main.ts +97 -0
  33. package/package.json +45 -0
  34. package/tests/typebox.forklaunch.hyperExpress.test.ts +164 -0
  35. package/tests/zod.forklaunch.hyperExpress.test.ts +164 -0
@@ -0,0 +1,2 @@
1
+ node_modules/
2
+ dist/
package/.prettierrc ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "semi": true,
3
+ "trailingComma": "none",
4
+ "singleQuote": true,
5
+ "printWidth": 80,
6
+ "tabWidth": 2
7
+ }
@@ -0,0 +1,192 @@
1
+ import { Body, ForklaunchRoute, ForklaunchRouter, HttpContractDetails, ParamsObject, PathParamHttpContractDetails, QueryObject, ResponsesObject } from '@forklaunch/core';
2
+ import { AnySchemaValidator } from '@forklaunch/validator';
3
+ import { Router as ExpressRouter, Server } from 'hyper-express';
4
+ import * as uWebsockets from 'uWebSockets.js';
5
+ import { MiddlewareHandler, SchemaMiddlewareHandler } from './types/forklaunch.hyperExpress.types';
6
+ /**
7
+ * Represents an application built on top of Hyper-Express and Forklaunch.
8
+ *
9
+ * @template SV - A type that extends AnySchemaValidator.
10
+ */
11
+ export declare class Application<SV extends AnySchemaValidator> {
12
+ private schemaValidator;
13
+ internal: Server;
14
+ private routers;
15
+ /**
16
+ * Creates an instance of the Application class.
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 {(string | Router<SV> | MiddlewareHandler | MiddlewareHandler[])[]} args - The middleware or routers to register.
25
+ * @returns {this} - The application instance.
26
+ */
27
+ use(router: Router<SV> | MiddlewareHandler<SV> | MiddlewareHandler<SV>[], ...args: (Router<SV> | MiddlewareHandler<SV> | MiddlewareHandler<SV>[])[]): this;
28
+ /**
29
+ * Starts the server and sets up Swagger documentation.
30
+ *
31
+ * @param {string | number} arg0 - The port number or UNIX path to listen on.
32
+ * @param {...unknown[]} args - Additional arguments.
33
+ * @returns {Promise<uWebsockets.us_listen_socket>} - A promise that resolves with the listening socket.
34
+ */
35
+ listen(port: number, callback?: (listen_socket: uWebsockets.us_listen_socket) => void): Promise<uWebsockets.us_listen_socket>;
36
+ listen(port: number, host?: string, callback?: (listen_socket: uWebsockets.us_listen_socket) => void): Promise<uWebsockets.us_listen_socket>;
37
+ listen(unix_path: string, callback?: (listen_socket: uWebsockets.us_listen_socket) => void): Promise<uWebsockets.us_listen_socket>;
38
+ }
39
+ /**
40
+ * Creates a new instance of Application with the given schema validator.
41
+ *
42
+ * @template SV - A type that extends AnySchemaValidator.
43
+ * @param {SV} schemaValidator - The schema validator.
44
+ * @returns {Application<SV>} - The new application instance.
45
+ */
46
+ export default function forklaunchExpress<SV extends AnySchemaValidator>(schemaValidator: SV): Application<SV>;
47
+ /**
48
+ * Represents a router that sets up routes and middleware for an Express router.
49
+ *
50
+ * @template SV - A type that extends AnySchemaValidator.
51
+ * @implements {ForklaunchRouter<SV>}
52
+ */
53
+ export declare class Router<SV extends AnySchemaValidator> implements ForklaunchRouter<SV> {
54
+ basePath: string;
55
+ private schemaValidator;
56
+ readonly routes: ForklaunchRoute<SV>[];
57
+ readonly internal: ExpressRouter;
58
+ /**
59
+ * Creates an instance of the Router class.
60
+ *
61
+ * @param {string} basePath - The base path for the router.
62
+ * @param {SV} schemaValidator - The schema validator.
63
+ */
64
+ constructor(basePath: string, schemaValidator: SV);
65
+ /**
66
+ * Resolves middlewares based on the contract details.
67
+ *
68
+ * @param {PathParamHttpContractDetails<SV> | HttpContractDetails<SV>} contractDetails - The contract details.
69
+ * @returns {MiddlewareHandler<SV>[]} - The resolved middlewares.
70
+ */
71
+ private resolveMiddlewares;
72
+ /**
73
+ * Parses and runs the controller function with error handling.
74
+ *
75
+ * @template P - The type of request parameters.
76
+ * @template ResBody - The type of response body.
77
+ * @template ReqBody - The type of request body.
78
+ * @template ReqQuery - The type of request query.
79
+ * @template LocalsObj - The type of local variables.
80
+ * @template StatusCode - The type of status code.
81
+ * @param {MiddlewareHandler<SV, P, ResBody | string, ReqBody, ReqQuery, LocalsObj, StatusCode>} requestHandler - The request handler.
82
+ * @returns {ExpressMiddlewareHandler} - The Express request handler.
83
+ */
84
+ private parseAndRunControllerFunction;
85
+ /**
86
+ * Extracts the controller function from the provided functions.
87
+ *
88
+ * @template P - The type of request parameters.
89
+ * @template ResBody - The type of response body.
90
+ * @template ReqBody - The type of request body.
91
+ * @template ReqQuery - The type of request query.
92
+ * @template LocalsObj - The type of local variables.
93
+ * @param {MiddlewareHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>[]} functions - The provided functions.
94
+ * @returns {MiddlewareHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>} - The extracted controller function.
95
+ * @throws {Error} - Throws an error if the last argument is not a function.
96
+ */
97
+ private extractControllerFunction;
98
+ /**
99
+ * Extracts the SDK path from the given path.
100
+ *
101
+ * @param {string | RegExp | (string | RegExp)[]} path - The provided path.
102
+ * @returns {string} - The extracted SDK path.
103
+ * @throws {Error} - Throws an error if the path is not defined.
104
+ */
105
+ private extractSdkPath;
106
+ /**
107
+ * Registers middleware to the router.
108
+ *
109
+ * @param {...unknown[]} args - The middleware to register.
110
+ * @returns {this} - The router instance.
111
+ */
112
+ use(...args: unknown[]): this;
113
+ /**
114
+ * Registers a GET route with the specified contract details and handler functions.
115
+ *
116
+ * @template P - The type of request parameters.
117
+ * @template ResBody - The type of response body.
118
+ * @template ReqBody - The type of request body.
119
+ * @template ReqQuery - The type of request query.
120
+ * @template LocalsObj - The type of local variables.
121
+ * @param {string} path - The path for the route.
122
+ * @param {PathParamHttpContractDetails<SV, P, ResBody, ReqQuery>} contractDetails - The contract details.
123
+ * @param {...SchemaMiddlewareHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>[]} functions - The handler functions.
124
+ * @returns {ExpressRouter} - The Express router.
125
+ */
126
+ 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, contractDetails: PathParamHttpContractDetails<SV, P, ResBody, ReqQuery>, ...functions: SchemaMiddlewareHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>[]): ExpressRouter;
127
+ /**
128
+ * Registers a POST route with the specified contract details and handler functions.
129
+ *
130
+ * @template P - The type of request parameters.
131
+ * @template ResBody - The type of response body.
132
+ * @template ReqBody - The type of request body.
133
+ * @template ReqQuery - The type of request query.
134
+ * @template LocalsObj - The type of local variables.
135
+ * @param {string} path - The path for the route.
136
+ * @param {HttpContractDetails<SV, P, ResBody, ReqBody, ReqQuery>} contractDetails - The contract details.
137
+ * @param {...SchemaMiddlewareHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>[]} functions - The handler functions.
138
+ * @returns {ExpressRouter} - The Express router.
139
+ */
140
+ 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, contractDetails: HttpContractDetails<SV, P, ResBody, ReqBody, ReqQuery>, ...functions: SchemaMiddlewareHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>[]): ExpressRouter;
141
+ /**
142
+ * Registers a PUT route with the specified contract details and handler functions.
143
+ *
144
+ * @template P - The type of request parameters.
145
+ * @template ResBody - The type of response body.
146
+ * @template ReqBody - The type of request body.
147
+ * @template ReqQuery - The type of request query.
148
+ * @template LocalsObj - The type of local variables.
149
+ * @param {string} path - The path for the route.
150
+ * @param {HttpContractDetails<SV, P, ResBody, ReqBody, ReqQuery>} contractDetails - The contract details.
151
+ * @param {...SchemaMiddlewareHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>[]} functions - The handler functions.
152
+ * @returns {ExpressRouter} - The Express router.
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, contractDetails: HttpContractDetails<SV, P, ResBody, ReqBody, ReqQuery>, ...functions: SchemaMiddlewareHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>[]): ExpressRouter;
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} path - The path for the route.
164
+ * @param {HttpContractDetails<SV, P, ResBody, ReqBody, ReqQuery>} contractDetails - The contract details.
165
+ * @param {...SchemaMiddlewareHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>[]} functions - The handler functions.
166
+ * @returns {ExpressRouter} - The Express router.
167
+ */
168
+ 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, contractDetails: HttpContractDetails<SV, P, ResBody, ReqBody, ReqQuery>, ...functions: SchemaMiddlewareHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>[]): ExpressRouter;
169
+ /**
170
+ * Registers a DELETE route with the specified contract details and handler functions.
171
+ *
172
+ * @template P - The type of request parameters.
173
+ * @template ResBody - The type of response body.
174
+ * @template ReqBody - The type of request body.
175
+ * @template ReqQuery - The type of request query.
176
+ * @template LocalsObj - The type of local variables.
177
+ * @param {string} path - The path for the route.
178
+ * @param {PathParamHttpContractDetails<SV, P, ResBody, ReqQuery>} contractDetails - The contract details.
179
+ * @param {...SchemaMiddlewareHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>[]} functions - The handler functions.
180
+ * @returns {ExpressRouter} - The Express router.
181
+ */
182
+ 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, contractDetails: PathParamHttpContractDetails<SV, P, ResBody, ReqQuery>, ...functions: SchemaMiddlewareHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>[]): ExpressRouter;
183
+ }
184
+ /**
185
+ * Creates a new instance of Router with the given base path and schema validator.
186
+ *
187
+ * @template SV - A type that extends AnySchemaValidator.
188
+ * @param {string} basePath - The base path for the router.
189
+ * @param {SV} schemaValidator - The schema validator.
190
+ * @returns {Router<SV>} - The new router instance.
191
+ */
192
+ export declare function forklaunchRouter<SV extends AnySchemaValidator>(basePath: `/${string}`, schemaValidator: SV): Router<SV>;
@@ -0,0 +1,358 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Router = exports.Application = void 0;
4
+ exports.default = forklaunchExpress;
5
+ exports.forklaunchRouter = forklaunchRouter;
6
+ const core_1 = require("@forklaunch/core");
7
+ const hyper_express_1 = require("hyper-express");
8
+ const contentParse_middleware_1 = require("./middleware/contentParse.middleware");
9
+ const response_middleware_1 = require("./middleware/response.middleware");
10
+ const swagger_middleware_1 = require("./middleware/swagger.middleware");
11
+ /**
12
+ * Represents an application built on top of Hyper-Express and Forklaunch.
13
+ *
14
+ * @template SV - A type that extends AnySchemaValidator.
15
+ */
16
+ class Application {
17
+ schemaValidator;
18
+ internal = new hyper_express_1.Server();
19
+ routers = [];
20
+ /**
21
+ * Creates an instance of the Application class.
22
+ *
23
+ * @param {SV} schemaValidator - The schema validator.
24
+ */
25
+ constructor(schemaValidator) {
26
+ this.schemaValidator = schemaValidator;
27
+ }
28
+ /**
29
+ * Registers middleware or routers to the application.
30
+ *
31
+ * @param {(string | Router<SV> | MiddlewareHandler | MiddlewareHandler[])[]} args - The middleware or routers to register.
32
+ * @returns {this} - The application instance.
33
+ */
34
+ use(router, ...args) {
35
+ if (router instanceof Router) {
36
+ this.routers.push(router);
37
+ this.internal.use(router.basePath, router.internal);
38
+ return this;
39
+ }
40
+ else {
41
+ const router = args.pop();
42
+ if (!(router instanceof Router)) {
43
+ throw new Error('Last argument must be a router');
44
+ }
45
+ args.forEach((arg) => {
46
+ if (arg instanceof Router) {
47
+ throw new Error('Only one router is allowed');
48
+ }
49
+ });
50
+ this.internal.use(router.basePath, ...args, router.internal);
51
+ return this;
52
+ }
53
+ // const newArgs = args.map((arg) => {
54
+ // if (arg instanceof Router) {
55
+ // this.routers.push(arg);
56
+ // return arg.internal;
57
+ // }
58
+ // return arg;
59
+ // });
60
+ // this.internal.use(...(newArgs as UsableSpreadableArguments));
61
+ // return this;
62
+ }
63
+ listen(arg0, arg1, arg2) {
64
+ if (typeof arg0 === 'number') {
65
+ const port = arg0 || Number(process.env.PORT);
66
+ const swaggerPath = `/api${process.env.VERSION ?? '/v1'}${process.env.SWAGGER_PATH ?? '/swagger'}`;
67
+ this.internal.use(swaggerPath, (0, swagger_middleware_1.swaggerRedirect)(swaggerPath));
68
+ this.internal.get(`${swaggerPath}/*`, (0, swagger_middleware_1.swagger)(swaggerPath, (0, core_1.generateSwaggerDocument)(this.schemaValidator, port, this.routers)));
69
+ if (arg1 && typeof arg1 === 'string') {
70
+ return this.internal.listen(port, arg1, arg2);
71
+ }
72
+ else if (arg1 && typeof arg1 === 'function') {
73
+ return this.internal.listen(port, arg1);
74
+ }
75
+ }
76
+ return this.internal.listen(arg0, arg1);
77
+ }
78
+ }
79
+ exports.Application = Application;
80
+ /**
81
+ * Creates a new instance of Application with the given schema validator.
82
+ *
83
+ * @template SV - A type that extends AnySchemaValidator.
84
+ * @param {SV} schemaValidator - The schema validator.
85
+ * @returns {Application<SV>} - The new application instance.
86
+ */
87
+ function forklaunchExpress(schemaValidator) {
88
+ return new Application(schemaValidator);
89
+ }
90
+ /**
91
+ * Represents a router that sets up routes and middleware for an Express router.
92
+ *
93
+ * @template SV - A type that extends AnySchemaValidator.
94
+ * @implements {ForklaunchRouter<SV>}
95
+ */
96
+ class Router {
97
+ basePath;
98
+ schemaValidator;
99
+ routes = [];
100
+ internal = new hyper_express_1.Router();
101
+ /**
102
+ * Creates an instance of the Router class.
103
+ *
104
+ * @param {string} basePath - The base path for the router.
105
+ * @param {SV} schemaValidator - The schema validator.
106
+ */
107
+ constructor(basePath, schemaValidator) {
108
+ this.basePath = basePath;
109
+ this.schemaValidator = schemaValidator;
110
+ this.internal.use((0, contentParse_middleware_1.contentParse)());
111
+ this.internal.use((0, core_1.createRequestContext)(this.schemaValidator));
112
+ this.internal.use(response_middleware_1.enrichResponseTransmission);
113
+ }
114
+ /**
115
+ * Resolves middlewares based on the contract details.
116
+ *
117
+ * @param {PathParamHttpContractDetails<SV> | HttpContractDetails<SV>} contractDetails - The contract details.
118
+ * @returns {MiddlewareHandler<SV>[]} - The resolved middlewares.
119
+ */
120
+ resolveMiddlewares(contractDetails) {
121
+ const middlewares = [(0, core_1.enrichRequestDetails)(contractDetails)];
122
+ if (contractDetails.params) {
123
+ middlewares.push(core_1.parseRequestParams);
124
+ }
125
+ if (contractDetails.body) {
126
+ middlewares.push(core_1.parseRequestBody);
127
+ }
128
+ if (contractDetails.requestHeaders) {
129
+ middlewares.push(core_1.parseRequestHeaders);
130
+ }
131
+ if (contractDetails.query) {
132
+ middlewares.push(core_1.parseRequestQuery);
133
+ }
134
+ if (contractDetails.auth) {
135
+ middlewares.push(core_1.parseRequestAuth);
136
+ }
137
+ return middlewares;
138
+ }
139
+ /**
140
+ * Parses and runs the controller function with error handling.
141
+ *
142
+ * @template P - The type of request parameters.
143
+ * @template ResBody - The type of response body.
144
+ * @template ReqBody - The type of request body.
145
+ * @template ReqQuery - The type of request query.
146
+ * @template LocalsObj - The type of local variables.
147
+ * @template StatusCode - The type of status code.
148
+ * @param {MiddlewareHandler<SV, P, ResBody | string, ReqBody, ReqQuery, LocalsObj, StatusCode>} requestHandler - The request handler.
149
+ * @returns {ExpressMiddlewareHandler} - The Express request handler.
150
+ */
151
+ parseAndRunControllerFunction(requestHandler) {
152
+ return async (req, res, next) => {
153
+ if (!requestHandler) {
154
+ throw new Error('Controller function is not defined');
155
+ }
156
+ try {
157
+ await requestHandler(req, res, next);
158
+ }
159
+ catch (error) {
160
+ if (next) {
161
+ next(error);
162
+ }
163
+ console.error(error);
164
+ if (!res.headersSent) {
165
+ res.status(500).send('Internal Server Error');
166
+ }
167
+ }
168
+ };
169
+ }
170
+ /**
171
+ * Extracts the controller function from the provided functions.
172
+ *
173
+ * @template P - The type of request parameters.
174
+ * @template ResBody - The type of response body.
175
+ * @template ReqBody - The type of request body.
176
+ * @template ReqQuery - The type of request query.
177
+ * @template LocalsObj - The type of local variables.
178
+ * @param {MiddlewareHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>[]} functions - The provided functions.
179
+ * @returns {MiddlewareHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>} - The extracted controller function.
180
+ * @throws {Error} - Throws an error if the last argument is not a function.
181
+ */
182
+ extractControllerFunction(functions) {
183
+ const controllerFunction = functions.pop();
184
+ if (typeof controllerFunction !== 'function') {
185
+ throw new Error('Last argument must be a function');
186
+ }
187
+ return controllerFunction;
188
+ }
189
+ /**
190
+ * Extracts the SDK path from the given path.
191
+ *
192
+ * @param {string | RegExp | (string | RegExp)[]} path - The provided path.
193
+ * @returns {string} - The extracted SDK path.
194
+ * @throws {Error} - Throws an error if the path is not defined.
195
+ */
196
+ extractSdkPath(path) {
197
+ let sdkPath = path;
198
+ if (Array.isArray(path)) {
199
+ sdkPath = path.pop() || path[0];
200
+ }
201
+ if (!sdkPath) {
202
+ throw new Error('Path is not defined');
203
+ }
204
+ if (sdkPath instanceof RegExp) {
205
+ sdkPath = (0, core_1.generateStringFromRegex)(sdkPath);
206
+ }
207
+ return sdkPath;
208
+ }
209
+ /**
210
+ * Registers middleware to the router.
211
+ *
212
+ * @param {...unknown[]} args - The middleware to register.
213
+ * @returns {this} - The router instance.
214
+ */
215
+ use(...args) {
216
+ this.internal.use(...args);
217
+ return this;
218
+ }
219
+ /**
220
+ * Registers a GET route with the specified contract details and handler functions.
221
+ *
222
+ * @template P - The type of request parameters.
223
+ * @template ResBody - The type of response body.
224
+ * @template ReqBody - The type of request body.
225
+ * @template ReqQuery - The type of request query.
226
+ * @template LocalsObj - The type of local variables.
227
+ * @param {string} path - The path for the route.
228
+ * @param {PathParamHttpContractDetails<SV, P, ResBody, ReqQuery>} contractDetails - The contract details.
229
+ * @param {...SchemaMiddlewareHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>[]} functions - The handler functions.
230
+ * @returns {ExpressRouter} - The Express router.
231
+ */
232
+ get(path, contractDetails, ...functions) {
233
+ const controllerFunction = this.extractControllerFunction(functions);
234
+ const sdkPath = this.extractSdkPath(path);
235
+ this.routes.push({
236
+ basePath: this.basePath,
237
+ path,
238
+ sdkPath,
239
+ method: 'get',
240
+ contractDetails
241
+ });
242
+ return this.internal.get(path, ...functions.concat(this.resolveMiddlewares(contractDetails)), this.parseAndRunControllerFunction(controllerFunction));
243
+ }
244
+ /**
245
+ * Registers a POST route with the specified contract details and handler functions.
246
+ *
247
+ * @template P - The type of request parameters.
248
+ * @template ResBody - The type of response body.
249
+ * @template ReqBody - The type of request body.
250
+ * @template ReqQuery - The type of request query.
251
+ * @template LocalsObj - The type of local variables.
252
+ * @param {string} path - The path for the route.
253
+ * @param {HttpContractDetails<SV, P, ResBody, ReqBody, ReqQuery>} contractDetails - The contract details.
254
+ * @param {...SchemaMiddlewareHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>[]} functions - The handler functions.
255
+ * @returns {ExpressRouter} - The Express router.
256
+ */
257
+ post(path, contractDetails, ...functions) {
258
+ const controllerFunction = this.extractControllerFunction(functions);
259
+ const sdkPath = this.extractSdkPath(path);
260
+ this.routes.push({
261
+ basePath: this.basePath,
262
+ path,
263
+ sdkPath,
264
+ method: 'post',
265
+ contractDetails
266
+ });
267
+ return this.internal.post(path, ...functions.concat(this.resolveMiddlewares(contractDetails)), this.parseAndRunControllerFunction(controllerFunction));
268
+ }
269
+ /**
270
+ * Registers a PUT route with the specified contract details and handler functions.
271
+ *
272
+ * @template P - The type of request parameters.
273
+ * @template ResBody - The type of response body.
274
+ * @template ReqBody - The type of request body.
275
+ * @template ReqQuery - The type of request query.
276
+ * @template LocalsObj - The type of local variables.
277
+ * @param {string} path - The path for the route.
278
+ * @param {HttpContractDetails<SV, P, ResBody, ReqBody, ReqQuery>} contractDetails - The contract details.
279
+ * @param {...SchemaMiddlewareHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>[]} functions - The handler functions.
280
+ * @returns {ExpressRouter} - The Express router.
281
+ */
282
+ put(path, contractDetails, ...functions) {
283
+ const controllerFunction = this.extractControllerFunction(functions);
284
+ const sdkPath = this.extractSdkPath(path);
285
+ this.routes.push({
286
+ basePath: this.basePath,
287
+ path,
288
+ sdkPath,
289
+ method: 'put',
290
+ contractDetails
291
+ });
292
+ return this.internal.put(path, ...functions.concat(this.resolveMiddlewares(contractDetails)), this.parseAndRunControllerFunction(controllerFunction));
293
+ }
294
+ /**
295
+ * Registers a PATCH route with the specified contract details and handler functions.
296
+ *
297
+ * @template P - The type of request parameters.
298
+ * @template ResBody - The type of response body.
299
+ * @template ReqBody - The type of request body.
300
+ * @template ReqQuery - The type of request query.
301
+ * @template LocalsObj - The type of local variables.
302
+ * @param {string} path - The path for the route.
303
+ * @param {HttpContractDetails<SV, P, ResBody, ReqBody, ReqQuery>} contractDetails - The contract details.
304
+ * @param {...SchemaMiddlewareHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>[]} functions - The handler functions.
305
+ * @returns {ExpressRouter} - The Express router.
306
+ */
307
+ patch(path, contractDetails, ...functions) {
308
+ const controllerFunction = this.extractControllerFunction(functions);
309
+ const sdkPath = this.extractSdkPath(path);
310
+ this.routes.push({
311
+ basePath: this.basePath,
312
+ path,
313
+ sdkPath,
314
+ method: 'patch',
315
+ contractDetails
316
+ });
317
+ return this.internal.patch(path, ...functions.concat(this.resolveMiddlewares(contractDetails)), this.parseAndRunControllerFunction(controllerFunction));
318
+ }
319
+ /**
320
+ * Registers a DELETE route with the specified contract details and handler functions.
321
+ *
322
+ * @template P - The type of request parameters.
323
+ * @template ResBody - The type of response body.
324
+ * @template ReqBody - The type of request body.
325
+ * @template ReqQuery - The type of request query.
326
+ * @template LocalsObj - The type of local variables.
327
+ * @param {string} path - The path for the route.
328
+ * @param {PathParamHttpContractDetails<SV, P, ResBody, ReqQuery>} contractDetails - The contract details.
329
+ * @param {...SchemaMiddlewareHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>[]} functions - The handler functions.
330
+ * @returns {ExpressRouter} - The Express router.
331
+ */
332
+ delete(path, contractDetails, ...functions) {
333
+ const controllerFunction = this.extractControllerFunction(functions);
334
+ const sdkPath = this.extractSdkPath(path);
335
+ this.routes.push({
336
+ basePath: this.basePath,
337
+ path,
338
+ sdkPath,
339
+ method: 'delete',
340
+ contractDetails
341
+ });
342
+ return this.internal.delete(path, ...functions.concat(this.resolveMiddlewares(contractDetails)), this.parseAndRunControllerFunction(controllerFunction));
343
+ }
344
+ }
345
+ exports.Router = Router;
346
+ /**
347
+ * Creates a new instance of Router with the given base path and schema validator.
348
+ *
349
+ * @template SV - A type that extends AnySchemaValidator.
350
+ * @param {string} basePath - The base path for the router.
351
+ * @param {SV} schemaValidator - The schema validator.
352
+ * @returns {Router<SV>} - The new router instance.
353
+ */
354
+ function forklaunchRouter(basePath, schemaValidator) {
355
+ const router = new Router(basePath, schemaValidator);
356
+ return router;
357
+ }
358
+ //# sourceMappingURL=forklaunch.hyperExpress.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"forklaunch.hyperExpress.js","sourceRoot":"","sources":["../forklaunch.hyperExpress.ts"],"names":[],"mappings":";;;AAkKA,oCAIC;A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,6BAA6B,CAChC,kBAAkB,CACoB,CACzC,CAAC;IACJ,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,MAAM,CAOJ,IAAY,EACZ,eAAuE,EACvE,GAAG,SAOA;QAEH,MAAM,kBAAkB,GAAG,IAAI,CAAC,yBAAyB,CAAC,SAAS,CAAC,CAAC;QACrE,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAE1C,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;YACf,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,IAAI;YACJ,OAAO;YACP,MAAM,EAAE,QAAQ;YAChB,eAAe;SAChB,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CACzB,IAAI,EACJ,GAAI,SAAS,CAAC,MAAM,CAClB,IAAI,CAAC,kBAAkB,CAAC,eAAe,CAAqB,CACnB,EAC3C,IAAI,CAAC,6BAA6B,CAChC,kBAAkB,CACoB,CACzC,CAAC;IACJ,CAAC;CAYF;AA1cD,wBA0cC;AAED;;;;;;;GAOG;AACH,SAAgB,gBAAgB,CAC9B,QAAsB,EACtB,eAAmB;IAEnB,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;IACrD,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Config } from 'jest';
2
+ declare const config: Config;
3
+ export default config;
@@ -0,0 +1 @@
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"}
package/dist/main.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};