@forklaunch/express 0.1.0 → 0.1.2

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