@forklaunch/hyper-express 0.1.1 → 0.1.3

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 (72) hide show
  1. package/lib/config.d.ts +2 -0
  2. package/lib/config.d.ts.map +1 -0
  3. package/lib/config.js +1 -0
  4. package/lib/eslint.config.d.mts +3 -0
  5. package/lib/eslint.config.d.mts.map +1 -0
  6. package/lib/eslint.config.mjs +10 -0
  7. package/lib/index.d.ts +23 -0
  8. package/lib/index.d.ts.map +1 -0
  9. package/lib/index.js +25 -0
  10. package/lib/jest.config.d.ts +4 -0
  11. package/lib/jest.config.d.ts.map +1 -0
  12. package/lib/jest.config.js +19 -0
  13. package/lib/src/hyperExpressApplication.d.ts +36 -0
  14. package/lib/src/hyperExpressApplication.d.ts.map +1 -0
  15. package/lib/src/hyperExpressApplication.js +70 -0
  16. package/lib/src/hyperExpressRouter.d.ts +10 -0
  17. package/lib/src/hyperExpressRouter.d.ts.map +1 -0
  18. package/lib/src/hyperExpressRouter.js +22 -0
  19. package/lib/src/middleware/contentParse.middleware.d.ts +8 -0
  20. package/lib/src/middleware/contentParse.middleware.d.ts.map +1 -0
  21. package/lib/src/middleware/contentParse.middleware.js +26 -0
  22. package/lib/src/middleware/enrichResponseTransmission.middleware.d.ts +14 -0
  23. package/lib/src/middleware/enrichResponseTransmission.middleware.d.ts.map +1 -0
  24. package/{dist/middleware/response.middleware.js → lib/src/middleware/enrichResponseTransmission.middleware.js} +19 -17
  25. package/lib/src/middleware/polyfillGetHeaders.middleware.d.ts +3 -0
  26. package/lib/src/middleware/polyfillGetHeaders.middleware.d.ts.map +1 -0
  27. package/lib/src/middleware/polyfillGetHeaders.middleware.js +8 -0
  28. package/{dist → lib/src}/middleware/swagger.middleware.d.ts +1 -0
  29. package/lib/src/middleware/swagger.middleware.d.ts.map +1 -0
  30. package/{dist → lib/src}/middleware/swagger.middleware.js +9 -19
  31. package/lib/src/types/hyperExpress.types.d.ts +42 -0
  32. package/lib/src/types/hyperExpress.types.d.ts.map +1 -0
  33. package/lib/tests/typebox.forklaunch.hyperExpress.test.d.ts +2 -0
  34. package/lib/tests/typebox.forklaunch.hyperExpress.test.d.ts.map +1 -0
  35. package/{dist/tests/zod.forklaunch.hyperExpress.test.js → lib/tests/typebox.forklaunch.hyperExpress.test.js} +23 -53
  36. package/lib/tests/zod.forklaunch.hyperExpress.test.d.ts +2 -0
  37. package/lib/tests/zod.forklaunch.hyperExpress.test.d.ts.map +1 -0
  38. package/{dist/tests/typebox.forklaunch.hyperExpress.test.js → lib/tests/zod.forklaunch.hyperExpress.test.js} +22 -54
  39. package/lib/tsconfig.tsbuildinfo +1 -0
  40. package/lib/vitest.config.d.ts +3 -0
  41. package/lib/vitest.config.d.ts.map +1 -0
  42. package/lib/vitest.config.js +7 -0
  43. package/package.json +27 -14
  44. package/.prettierignore +0 -2
  45. package/.prettierrc +0 -7
  46. package/dist/forklaunch.hyperExpress.d.ts +0 -192
  47. package/dist/forklaunch.hyperExpress.js +0 -358
  48. package/dist/forklaunch.hyperExpress.js.map +0 -1
  49. package/dist/jest.config.d.ts +0 -3
  50. package/dist/jest.config.js.map +0 -1
  51. package/dist/main.js +0 -90
  52. package/dist/main.js.map +0 -1
  53. package/dist/middleware/contentParse.middleware.d.ts +0 -7
  54. package/dist/middleware/contentParse.middleware.js +0 -30
  55. package/dist/middleware/contentParse.middleware.js.map +0 -1
  56. package/dist/middleware/response.middleware.d.ts +0 -12
  57. package/dist/middleware/response.middleware.js.map +0 -1
  58. package/dist/middleware/swagger.middleware.js.map +0 -1
  59. package/dist/tests/typebox.forklaunch.hyperExpress.test.d.ts +0 -1
  60. package/dist/tests/typebox.forklaunch.hyperExpress.test.js.map +0 -1
  61. package/dist/tests/zod.forklaunch.hyperExpress.test.d.ts +0 -1
  62. package/dist/tests/zod.forklaunch.hyperExpress.test.js.map +0 -1
  63. package/dist/types/forklaunch.hyperExpress.types.d.ts +0 -67
  64. package/dist/types/forklaunch.hyperExpress.types.js +0 -3
  65. package/dist/types/forklaunch.hyperExpress.types.js.map +0 -1
  66. package/eslint.config.mjs +0 -12
  67. package/forklaunch.hyperExpress.ts +0 -649
  68. package/jest.config.ts +0 -10
  69. package/main.ts +0 -97
  70. package/tests/typebox.forklaunch.hyperExpress.test.ts +0 -164
  71. package/tests/zod.forklaunch.hyperExpress.test.ts +0 -164
  72. /package/{dist/main.d.ts → lib/src/types/hyperExpress.types.js} +0 -0
@@ -1,649 +0,0 @@
1
- import {
2
- Body,
3
- ForklaunchRoute,
4
- ForklaunchRouter,
5
- HttpContractDetails,
6
- ParamsDictionary,
7
- ParamsObject,
8
- PathParamHttpContractDetails,
9
- QueryObject,
10
- ResponsesObject,
11
- createRequestContext,
12
- enrichRequestDetails,
13
- generateStringFromRegex,
14
- generateSwaggerDocument,
15
- parseRequestAuth,
16
- parseRequestBody,
17
- parseRequestHeaders,
18
- parseRequestParams,
19
- parseRequestQuery
20
- } from '@forklaunch/core';
21
- import {
22
- MiddlewareHandler as ExpressMiddlewareHandler,
23
- Router as ExpressRouter,
24
- MiddlewareNext,
25
- Server,
26
- UsableSpreadableArguments
27
- } from '@forklaunch/hyper-express-fork';
28
- import { AnySchemaValidator } from '@forklaunch/validator';
29
- import { ParsedQs } from 'qs';
30
- import * as uWebsockets from 'uWebSockets.js';
31
- import { contentParse } from './middleware/contentParse.middleware';
32
- import { enrichResponseTransmission } from './middleware/response.middleware';
33
- import { swagger, swaggerRedirect } from './middleware/swagger.middleware';
34
- import {
35
- MiddlewareHandler,
36
- Request,
37
- Response,
38
- SchemaMiddlewareHandler
39
- } from './types/forklaunch.hyperExpress.types';
40
-
41
- /**
42
- * Represents an application built on top of Hyper-Express and Forklaunch.
43
- *
44
- * @template SV - A type that extends AnySchemaValidator.
45
- */
46
- export class Application<SV extends AnySchemaValidator> {
47
- internal = new Server();
48
- private routers: Router<SV>[] = [];
49
-
50
- /**
51
- * Creates an instance of the Application class.
52
- *
53
- * @param {SV} schemaValidator - The schema validator.
54
- */
55
- constructor(private schemaValidator: SV) { }
56
-
57
- /**
58
- * Registers middleware or routers to the application.
59
- *
60
- * @param {(string | Router<SV> | MiddlewareHandler | MiddlewareHandler[])[]} args - The middleware or routers to register.
61
- * @returns {this} - The application instance.
62
- */
63
- use(
64
- router: Router<SV> | MiddlewareHandler<SV> | MiddlewareHandler<SV>[],
65
- ...args: (Router<SV> | MiddlewareHandler<SV> | MiddlewareHandler<SV>[])[]
66
- ): this {
67
- if (router instanceof Router) {
68
- this.routers.push(router);
69
- this.internal.use(router.basePath, router.internal);
70
- return this;
71
- } else {
72
- const router = args.pop();
73
- if (!(router instanceof Router)) {
74
- throw new Error('Last argument must be a router');
75
- }
76
-
77
- args.forEach((arg) => {
78
- if (arg instanceof Router) {
79
- throw new Error('Only one router is allowed');
80
- }
81
- });
82
-
83
- this.internal.use(
84
- router.basePath,
85
- ...(args as unknown as (
86
- | ExpressMiddlewareHandler
87
- | ExpressMiddlewareHandler[]
88
- )[]),
89
- router.internal
90
- );
91
- return this;
92
- }
93
- // const newArgs = args.map((arg) => {
94
- // if (arg instanceof Router) {
95
- // this.routers.push(arg);
96
- // return arg.internal;
97
- // }
98
- // return arg;
99
- // });
100
- // this.internal.use(...(newArgs as UsableSpreadableArguments));
101
- // return this;
102
- }
103
-
104
- /**
105
- * Starts the server and sets up Swagger documentation.
106
- *
107
- * @param {string | number} arg0 - The port number or UNIX path to listen on.
108
- * @param {...unknown[]} args - Additional arguments.
109
- * @returns {Promise<uWebsockets.us_listen_socket>} - A promise that resolves with the listening socket.
110
- */
111
- listen(
112
- port: number,
113
- callback?: (listen_socket: uWebsockets.us_listen_socket) => void
114
- ): Promise<uWebsockets.us_listen_socket>;
115
- listen(
116
- port: number,
117
- host?: string,
118
- callback?: (listen_socket: uWebsockets.us_listen_socket) => void
119
- ): Promise<uWebsockets.us_listen_socket>;
120
- listen(
121
- unix_path: string,
122
- callback?: (listen_socket: uWebsockets.us_listen_socket) => void
123
- ): Promise<uWebsockets.us_listen_socket>;
124
- listen(
125
- arg0: number | string,
126
- arg1?: string | ((listen_socket: uWebsockets.us_listen_socket) => void),
127
- arg2?: (listen_socket: uWebsockets.us_listen_socket) => void
128
- ): Promise<uWebsockets.us_listen_socket> {
129
- if (typeof arg0 === 'number') {
130
- const port = arg0 || Number(process.env.PORT);
131
-
132
- const swaggerPath = `/api${process.env.VERSION ?? '/v1'}${process.env.SWAGGER_PATH ?? '/swagger'}`;
133
- this.internal.use(swaggerPath, swaggerRedirect(swaggerPath));
134
- this.internal.get(
135
- `${swaggerPath}/*`,
136
- swagger(
137
- swaggerPath,
138
- generateSwaggerDocument(this.schemaValidator, port, this.routers)
139
- )
140
- );
141
-
142
- if (arg1 && typeof arg1 === 'string') {
143
- return this.internal.listen(port, arg1, arg2);
144
- } else if (arg1 && typeof arg1 === 'function') {
145
- return this.internal.listen(port, arg1);
146
- }
147
- }
148
-
149
- return this.internal.listen(
150
- arg0 as string,
151
- arg1 as (listen_socket: uWebsockets.us_listen_socket) => void
152
- );
153
- }
154
- }
155
-
156
- /**
157
- * Creates a new instance of Application with the given schema validator.
158
- *
159
- * @template SV - A type that extends AnySchemaValidator.
160
- * @param {SV} schemaValidator - The schema validator.
161
- * @returns {Application<SV>} - The new application instance.
162
- */
163
- export default function forklaunchExpress<SV extends AnySchemaValidator>(
164
- schemaValidator: SV
165
- ) {
166
- return new Application(schemaValidator);
167
- }
168
-
169
- /**
170
- * Represents a router that sets up routes and middleware for an Express router.
171
- *
172
- * @template SV - A type that extends AnySchemaValidator.
173
- * @implements {ForklaunchRouter<SV>}
174
- */
175
- export class Router<SV extends AnySchemaValidator>
176
- implements ForklaunchRouter<SV>
177
- {
178
- readonly routes: ForklaunchRoute<SV>[] = [];
179
- readonly internal: ExpressRouter = new ExpressRouter();
180
-
181
- /**
182
- * Creates an instance of the Router class.
183
- *
184
- * @param {string} basePath - The base path for the router.
185
- * @param {SV} schemaValidator - The schema validator.
186
- */
187
- constructor(
188
- public basePath: string,
189
- private schemaValidator: SV
190
- ) {
191
- this.internal.use(contentParse());
192
- this.internal.use(
193
- createRequestContext(
194
- this.schemaValidator
195
- ) as unknown as ExpressMiddlewareHandler
196
- );
197
- this.internal.use(
198
- enrichResponseTransmission as unknown as ExpressMiddlewareHandler
199
- );
200
- }
201
-
202
- /**
203
- * Resolves middlewares based on the contract details.
204
- *
205
- * @param {PathParamHttpContractDetails<SV> | HttpContractDetails<SV>} contractDetails - The contract details.
206
- * @returns {MiddlewareHandler<SV>[]} - The resolved middlewares.
207
- */
208
- private resolveMiddlewares(
209
- contractDetails: PathParamHttpContractDetails<SV> | HttpContractDetails<SV>
210
- ): MiddlewareHandler<SV>[] {
211
- const middlewares = [enrichRequestDetails(contractDetails)];
212
- if (contractDetails.params) {
213
- middlewares.push(parseRequestParams);
214
- }
215
- if ((contractDetails as HttpContractDetails<SV>).body) {
216
- middlewares.push(parseRequestBody);
217
- }
218
- if (contractDetails.requestHeaders) {
219
- middlewares.push(parseRequestHeaders);
220
- }
221
- if (contractDetails.query) {
222
- middlewares.push(parseRequestQuery);
223
- }
224
- if (contractDetails.auth) {
225
- middlewares.push(parseRequestAuth);
226
- }
227
- return middlewares as MiddlewareHandler<SV>[];
228
- }
229
-
230
- /**
231
- * Parses and runs the controller function with error handling.
232
- *
233
- * @template P - The type of request parameters.
234
- * @template ResBody - The type of response body.
235
- * @template ReqBody - The type of request body.
236
- * @template ReqQuery - The type of request query.
237
- * @template LocalsObj - The type of local variables.
238
- * @template StatusCode - The type of status code.
239
- * @param {MiddlewareHandler<SV, P, ResBody | string, ReqBody, ReqQuery, LocalsObj, StatusCode>} requestHandler - The request handler.
240
- * @returns {ExpressMiddlewareHandler} - The Express request handler.
241
- */
242
- private parseAndRunControllerFunction<
243
- P = ParamsDictionary,
244
- ResBody = unknown,
245
- ReqBody = unknown,
246
- ReqQuery = ParsedQs,
247
- LocalsObj extends Record<string, unknown> = Record<string, unknown>,
248
- StatusCode extends number = number
249
- >(
250
- requestHandler: MiddlewareHandler<
251
- SV,
252
- P,
253
- ResBody | string,
254
- ReqBody,
255
- ReqQuery,
256
- LocalsObj,
257
- StatusCode
258
- >
259
- ): MiddlewareHandler<
260
- SV,
261
- P,
262
- ResBody | string,
263
- ReqBody,
264
- ReqQuery,
265
- LocalsObj,
266
- StatusCode
267
- > {
268
- return async (
269
- req: Request<SV, P, ReqBody, ReqQuery, LocalsObj>,
270
- res: Response<ResBody | string, LocalsObj, StatusCode>,
271
- next?: MiddlewareNext
272
- ) => {
273
- if (!requestHandler) {
274
- throw new Error('Controller function is not defined');
275
- }
276
-
277
- try {
278
- await requestHandler(req, res, next);
279
- } catch (error) {
280
- if (next) {
281
- next(error as Error);
282
- }
283
-
284
- console.error(error);
285
- if (!res.headersSent) {
286
- res.status(500).send('Internal Server Error');
287
- }
288
- }
289
- };
290
- }
291
-
292
- /**
293
- * Extracts the controller function from the provided functions.
294
- *
295
- * @template P - The type of request parameters.
296
- * @template ResBody - The type of response body.
297
- * @template ReqBody - The type of request body.
298
- * @template ReqQuery - The type of request query.
299
- * @template LocalsObj - The type of local variables.
300
- * @param {MiddlewareHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>[]} functions - The provided functions.
301
- * @returns {MiddlewareHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>} - The extracted controller function.
302
- * @throws {Error} - Throws an error if the last argument is not a function.
303
- */
304
- private extractControllerFunction<
305
- P = ParamsDictionary,
306
- ResBody = unknown,
307
- ReqBody = unknown,
308
- ReqQuery = ParsedQs,
309
- LocalsObj extends Record<string, unknown> = Record<string, unknown>
310
- >(
311
- functions: MiddlewareHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>[]
312
- ): MiddlewareHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj> {
313
- const controllerFunction = functions.pop();
314
-
315
- if (typeof controllerFunction !== 'function') {
316
- throw new Error('Last argument must be a function');
317
- }
318
-
319
- return controllerFunction;
320
- }
321
-
322
- /**
323
- * Extracts the SDK path from the given path.
324
- *
325
- * @param {string | RegExp | (string | RegExp)[]} path - The provided path.
326
- * @returns {string} - The extracted SDK path.
327
- * @throws {Error} - Throws an error if the path is not defined.
328
- */
329
- private extractSdkPath(path: string | RegExp | (string | RegExp)[]): string {
330
- let sdkPath = path;
331
-
332
- if (Array.isArray(path)) {
333
- sdkPath = path.pop() || path[0];
334
- }
335
-
336
- if (!sdkPath) {
337
- throw new Error('Path is not defined');
338
- }
339
-
340
- if (sdkPath instanceof RegExp) {
341
- sdkPath = generateStringFromRegex(sdkPath);
342
- }
343
-
344
- return sdkPath as string;
345
- }
346
-
347
- /**
348
- * Registers middleware to the router.
349
- *
350
- * @param {...unknown[]} args - The middleware to register.
351
- * @returns {this} - The router instance.
352
- */
353
- use(...args: unknown[]): this {
354
- this.internal.use(...(args as UsableSpreadableArguments));
355
- return this;
356
- }
357
-
358
- /**
359
- * Registers a GET route with the specified contract details and handler functions.
360
- *
361
- * @template P - The type of request parameters.
362
- * @template ResBody - The type of response body.
363
- * @template ReqBody - The type of request body.
364
- * @template ReqQuery - The type of request query.
365
- * @template LocalsObj - The type of local variables.
366
- * @param {string} path - The path for the route.
367
- * @param {PathParamHttpContractDetails<SV, P, ResBody, ReqQuery>} contractDetails - The contract details.
368
- * @param {...SchemaMiddlewareHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>[]} functions - The handler functions.
369
- * @returns {ExpressRouter} - The Express router.
370
- */
371
- get<
372
- P extends ParamsObject<SV> = ParamsObject<SV>,
373
- ResBody extends ResponsesObject<SV> = ResponsesObject<SV>,
374
- ReqBody extends Body<SV> = Body<SV>,
375
- ReqQuery extends QueryObject<SV> = QueryObject<SV>,
376
- LocalsObj extends Record<string, unknown> = Record<string, unknown>
377
- >(
378
- path: string,
379
- contractDetails: PathParamHttpContractDetails<SV, P, ResBody, ReqQuery>,
380
- ...functions: SchemaMiddlewareHandler<
381
- SV,
382
- P,
383
- ResBody,
384
- ReqBody,
385
- ReqQuery,
386
- LocalsObj
387
- >[]
388
- ): ExpressRouter {
389
- const controllerFunction = this.extractControllerFunction(functions);
390
- const sdkPath = this.extractSdkPath(path);
391
-
392
- this.routes.push({
393
- basePath: this.basePath,
394
- path,
395
- sdkPath,
396
- method: 'get',
397
- contractDetails
398
- });
399
-
400
- return this.internal.get(
401
- path,
402
- ...(functions.concat(
403
- this.resolveMiddlewares(contractDetails) as typeof functions
404
- ) as unknown as ExpressMiddlewareHandler[]),
405
- this.parseAndRunControllerFunction(
406
- controllerFunction
407
- ) as unknown as ExpressMiddlewareHandler
408
- );
409
- }
410
-
411
- /**
412
- * Registers a POST route with the specified contract details and handler functions.
413
- *
414
- * @template P - The type of request parameters.
415
- * @template ResBody - The type of response body.
416
- * @template ReqBody - The type of request body.
417
- * @template ReqQuery - The type of request query.
418
- * @template LocalsObj - The type of local variables.
419
- * @param {string} path - The path for the route.
420
- * @param {HttpContractDetails<SV, P, ResBody, ReqBody, ReqQuery>} contractDetails - The contract details.
421
- * @param {...SchemaMiddlewareHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>[]} functions - The handler functions.
422
- * @returns {ExpressRouter} - The Express router.
423
- */
424
- post<
425
- P extends ParamsObject<SV> = ParamsObject<SV>,
426
- ResBody extends ResponsesObject<SV> = ResponsesObject<SV>,
427
- ReqBody extends Body<SV> = Body<SV>,
428
- ReqQuery extends QueryObject<SV> = QueryObject<SV>,
429
- LocalsObj extends Record<string, unknown> = Record<string, unknown>
430
- >(
431
- path: string,
432
- contractDetails: HttpContractDetails<SV, P, ResBody, ReqBody, ReqQuery>,
433
- ...functions: SchemaMiddlewareHandler<
434
- SV,
435
- P,
436
- ResBody,
437
- ReqBody,
438
- ReqQuery,
439
- LocalsObj
440
- >[]
441
- ): ExpressRouter {
442
- const controllerFunction = this.extractControllerFunction(functions);
443
- const sdkPath = this.extractSdkPath(path);
444
-
445
- this.routes.push({
446
- basePath: this.basePath,
447
- path,
448
- sdkPath,
449
- method: 'post',
450
- contractDetails
451
- });
452
-
453
- return this.internal.post(
454
- path,
455
- ...(functions.concat(
456
- this.resolveMiddlewares(contractDetails) as typeof functions
457
- ) as unknown as ExpressMiddlewareHandler[]),
458
- this.parseAndRunControllerFunction(
459
- controllerFunction
460
- ) as unknown as ExpressMiddlewareHandler
461
- );
462
- }
463
-
464
- /**
465
- * Registers a PUT route with the specified contract details and handler functions.
466
- *
467
- * @template P - The type of request parameters.
468
- * @template ResBody - The type of response body.
469
- * @template ReqBody - The type of request body.
470
- * @template ReqQuery - The type of request query.
471
- * @template LocalsObj - The type of local variables.
472
- * @param {string} path - The path for the route.
473
- * @param {HttpContractDetails<SV, P, ResBody, ReqBody, ReqQuery>} contractDetails - The contract details.
474
- * @param {...SchemaMiddlewareHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>[]} functions - The handler functions.
475
- * @returns {ExpressRouter} - The Express router.
476
- */
477
- put<
478
- P extends ParamsObject<SV> = ParamsObject<SV>,
479
- ResBody extends ResponsesObject<SV> = ResponsesObject<SV>,
480
- ReqBody extends Body<SV> = Body<SV>,
481
- ReqQuery extends QueryObject<SV> = QueryObject<SV>,
482
- LocalsObj extends Record<string, unknown> = Record<string, unknown>
483
- >(
484
- path: string,
485
- contractDetails: HttpContractDetails<SV, P, ResBody, ReqBody, ReqQuery>,
486
- ...functions: SchemaMiddlewareHandler<
487
- SV,
488
- P,
489
- ResBody,
490
- ReqBody,
491
- ReqQuery,
492
- LocalsObj
493
- >[]
494
- ): ExpressRouter {
495
- const controllerFunction = this.extractControllerFunction(functions);
496
- const sdkPath = this.extractSdkPath(path);
497
-
498
- this.routes.push({
499
- basePath: this.basePath,
500
- path,
501
- sdkPath,
502
- method: 'put',
503
- contractDetails
504
- });
505
-
506
- return this.internal.put(
507
- path,
508
- ...(functions.concat(
509
- this.resolveMiddlewares(contractDetails) as typeof functions
510
- ) as unknown as ExpressMiddlewareHandler[]),
511
- this.parseAndRunControllerFunction(
512
- controllerFunction
513
- ) as unknown as ExpressMiddlewareHandler
514
- );
515
- }
516
-
517
- /**
518
- * Registers a PATCH route with the specified contract details and handler functions.
519
- *
520
- * @template P - The type of request parameters.
521
- * @template ResBody - The type of response body.
522
- * @template ReqBody - The type of request body.
523
- * @template ReqQuery - The type of request query.
524
- * @template LocalsObj - The type of local variables.
525
- * @param {string} path - The path for the route.
526
- * @param {HttpContractDetails<SV, P, ResBody, ReqBody, ReqQuery>} contractDetails - The contract details.
527
- * @param {...SchemaMiddlewareHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>[]} functions - The handler functions.
528
- * @returns {ExpressRouter} - The Express router.
529
- */
530
- patch<
531
- P extends ParamsObject<SV> = ParamsObject<SV>,
532
- ResBody extends ResponsesObject<SV> = ResponsesObject<SV>,
533
- ReqBody extends Body<SV> = Body<SV>,
534
- ReqQuery extends QueryObject<SV> = QueryObject<SV>,
535
- LocalsObj extends Record<string, unknown> = Record<string, unknown>
536
- >(
537
- path: string,
538
- contractDetails: HttpContractDetails<SV, P, ResBody, ReqBody, ReqQuery>,
539
- ...functions: SchemaMiddlewareHandler<
540
- SV,
541
- P,
542
- ResBody,
543
- ReqBody,
544
- ReqQuery,
545
- LocalsObj
546
- >[]
547
- ): ExpressRouter {
548
- const controllerFunction = this.extractControllerFunction(functions);
549
- const sdkPath = this.extractSdkPath(path);
550
-
551
- this.routes.push({
552
- basePath: this.basePath,
553
- path,
554
- sdkPath,
555
- method: 'patch',
556
- contractDetails
557
- });
558
-
559
- return this.internal.patch(
560
- path,
561
- ...(functions.concat(
562
- this.resolveMiddlewares(contractDetails) as typeof functions
563
- ) as unknown as ExpressMiddlewareHandler[]),
564
- this.parseAndRunControllerFunction(
565
- controllerFunction
566
- ) as unknown as ExpressMiddlewareHandler
567
- );
568
- }
569
-
570
- /**
571
- * Registers a DELETE route with the specified contract details and handler functions.
572
- *
573
- * @template P - The type of request parameters.
574
- * @template ResBody - The type of response body.
575
- * @template ReqBody - The type of request body.
576
- * @template ReqQuery - The type of request query.
577
- * @template LocalsObj - The type of local variables.
578
- * @param {string} path - The path for the route.
579
- * @param {PathParamHttpContractDetails<SV, P, ResBody, ReqQuery>} contractDetails - The contract details.
580
- * @param {...SchemaMiddlewareHandler<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>[]} functions - The handler functions.
581
- * @returns {ExpressRouter} - The Express router.
582
- */
583
- delete<
584
- P extends ParamsObject<SV> = ParamsObject<SV>,
585
- ResBody extends ResponsesObject<SV> = ResponsesObject<SV>,
586
- ReqBody extends Body<SV> = Body<SV>,
587
- ReqQuery extends QueryObject<SV> = QueryObject<SV>,
588
- LocalsObj extends Record<string, unknown> = Record<string, unknown>
589
- >(
590
- path: string,
591
- contractDetails: PathParamHttpContractDetails<SV, P, ResBody, ReqQuery>,
592
- ...functions: SchemaMiddlewareHandler<
593
- SV,
594
- P,
595
- ResBody,
596
- ReqBody,
597
- ReqQuery,
598
- LocalsObj
599
- >[]
600
- ): ExpressRouter {
601
- const controllerFunction = this.extractControllerFunction(functions);
602
- const sdkPath = this.extractSdkPath(path);
603
-
604
- this.routes.push({
605
- basePath: this.basePath,
606
- path,
607
- sdkPath,
608
- method: 'delete',
609
- contractDetails
610
- });
611
-
612
- return this.internal.delete(
613
- path,
614
- ...(functions.concat(
615
- this.resolveMiddlewares(contractDetails) as typeof functions
616
- ) as unknown as ExpressMiddlewareHandler[]),
617
- this.parseAndRunControllerFunction(
618
- controllerFunction
619
- ) as unknown as ExpressMiddlewareHandler
620
- );
621
- }
622
-
623
- /**
624
- * Handles the incoming request.
625
- *
626
- * @param {Request<SV>} req - The request object.
627
- * @param {Response} res - The response object.
628
- * @param {MiddlewareNext} out - The next middleware function.
629
- */
630
- // handle(req: Request<SV>, res: Response, out: MiddlewareNext) {
631
- // this.internal(req, res, out);
632
- // }
633
- }
634
-
635
- /**
636
- * Creates a new instance of Router with the given base path and schema validator.
637
- *
638
- * @template SV - A type that extends AnySchemaValidator.
639
- * @param {string} basePath - The base path for the router.
640
- * @param {SV} schemaValidator - The schema validator.
641
- * @returns {Router<SV>} - The new router instance.
642
- */
643
- export function forklaunchRouter<SV extends AnySchemaValidator>(
644
- basePath: `/${string}`,
645
- schemaValidator: SV
646
- ): Router<SV> {
647
- const router = new Router(basePath, schemaValidator);
648
- return router;
649
- }
package/jest.config.ts DELETED
@@ -1,10 +0,0 @@
1
- import type { Config } from 'jest';
2
-
3
- const config: Config = {
4
- verbose: true,
5
- preset: 'ts-jest',
6
- testEnvironment: 'node',
7
- testPathIgnorePatterns: ['dist/', 'node_modules/']
8
- };
9
-
10
- export default config;