@forklaunch/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.
@@ -0,0 +1,12 @@
1
+ import { AnySchemaValidator } from '@forklaunch/validator';
2
+ import { NextFunction } from 'express';
3
+ import { Request, Response } from '../types/forklaunch.express.types';
4
+ /**
5
+ * Middleware to enrich the response transmission by intercepting and parsing responses before they are sent.
6
+ *
7
+ * @template SV - A type that extends AnySchemaValidator.
8
+ * @param {Request<SV>} req - The request object.
9
+ * @param {Response} res - The response object.
10
+ * @param {NextFunction} [next] - The next middleware function.
11
+ */
12
+ export declare function enrichResponseTransmission<SV extends AnySchemaValidator>(req: Request<SV>, res: Response, next?: NextFunction): void;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.enrichResponseTransmission = enrichResponseTransmission;
4
+ const core_1 = require("@forklaunch/core");
5
+ /**
6
+ * Middleware to enrich the response transmission by intercepting and parsing responses before they are sent.
7
+ *
8
+ * @template SV - A type that extends AnySchemaValidator.
9
+ * @param {Request<SV>} req - The request object.
10
+ * @param {Response} res - The response object.
11
+ * @param {NextFunction} [next] - The next middleware function.
12
+ */
13
+ function enrichResponseTransmission(req, res, next) {
14
+ const originalSend = res.send;
15
+ const originalJson = res.json;
16
+ /**
17
+ * Intercepts the JSON response to include additional processing.
18
+ *
19
+ * @template T - The type of the response data.
20
+ * @param {unknown} data - The data to send in the response.
21
+ * @returns {T} - The result of the original JSON method.
22
+ */
23
+ res.json = function (data) {
24
+ res.bodyData = data;
25
+ const result = originalJson.call(this, data);
26
+ return result;
27
+ };
28
+ /**
29
+ * Intercepts the send response to include additional processing and error handling.
30
+ *
31
+ * @param {unknown} data - The data to send in the response.
32
+ * @returns {Response} - The result of the original send method.
33
+ */
34
+ res.send = function (data) {
35
+ if (!res.bodyData) {
36
+ res.bodyData = data;
37
+ }
38
+ try {
39
+ (0, core_1.parseResponse)(req, res);
40
+ const result = originalSend.call(this, data);
41
+ return result;
42
+ }
43
+ catch (error) {
44
+ console.error(error);
45
+ res.status(500);
46
+ originalSend.call(this, 'Internal Server Error: ' + error.message);
47
+ if (next) {
48
+ next(error);
49
+ }
50
+ }
51
+ };
52
+ if (next) {
53
+ next();
54
+ }
55
+ }
56
+ //# sourceMappingURL=response.middleware.js.map
@@ -0,0 +1 @@
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,YAAY,GAAG,GAAG,CAAC,IAAI,CAAC;IAE9B;;;;;;OAMG;IACH,GAAG,CAAC,IAAI,GAAG,UAAa,IAAa;QACnC,GAAG,CAAC,QAAQ,GAAG,IAAI,CAAC;QACpB,MAAM,MAAM,GAAG,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC7C,OAAO,MAAW,CAAC;IACrB,CAAC,CAAC;IAEF;;;;;OAKG;IACH,GAAG,CAAC,IAAI,GAAG,UAAU,IAAI;QACvB,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;YAClB,GAAG,CAAC,QAAQ,GAAG,IAAI,CAAC;QACtB,CAAC;QAED,IAAI,CAAC;YACH,IAAA,oBAAa,EAA0C,GAAG,EAAE,GAAG,CAAC,CAAC;YACjE,MAAM,MAAM,GAAG,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YAC7C,OAAO,MAAM,CAAC;QAChB,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACxB,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YACrB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAChB,YAAY,CAAC,IAAI,CACf,IAAI,EACJ,yBAAyB,GAAI,KAAe,CAAC,OAAO,CACrD,CAAC;YACF,IAAI,IAAI,EAAE,CAAC;gBACT,IAAI,CAAC,KAAK,CAAC,CAAC;YACd,CAAC;QACH,CAAC;IACH,CAAC,CAAC;IAEF,IAAI,IAAI,EAAE,CAAC;QACT,IAAI,EAAE,CAAC;IACT,CAAC;AACH,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,141 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const typebox_1 = require("@forklaunch/validator/typebox");
27
+ const kill_port_process_1 = require("kill-port-process");
28
+ const forklaunch_express_1 = __importStar(require("../forklaunch.express"));
29
+ const typeboxSchemaValidator = new typebox_1.TypeboxSchemaValidator();
30
+ describe('Forklaunch Express Tests', () => {
31
+ let forklaunchApplication;
32
+ let forklaunchRouterInstance;
33
+ beforeAll(async () => {
34
+ await (0, kill_port_process_1.killPortProcess)(6934);
35
+ forklaunchApplication = (0, forklaunch_express_1.default)(typeboxSchemaValidator);
36
+ forklaunchRouterInstance = (0, forklaunch_express_1.forklaunchRouter)('/testpath', typeboxSchemaValidator);
37
+ forklaunchRouterInstance.get('/test', {
38
+ name: 'Test',
39
+ summary: 'Test Summary',
40
+ responses: {
41
+ 200: typebox_1.string
42
+ }
43
+ }, (req, res) => {
44
+ res.status(200).send('Hello World');
45
+ });
46
+ forklaunchRouterInstance.post('/test', {
47
+ name: 'Test',
48
+ summary: 'Test Summary',
49
+ body: {
50
+ test: typebox_1.string
51
+ },
52
+ responses: {
53
+ 200: typebox_1.string
54
+ }
55
+ }, (req, res) => {
56
+ res.status(200).send(req.body.test);
57
+ });
58
+ forklaunchRouterInstance.put('/test', {
59
+ name: 'Test',
60
+ summary: 'Test Summary',
61
+ body: {
62
+ test: typebox_1.string
63
+ },
64
+ responses: {
65
+ 200: typebox_1.string
66
+ }
67
+ }, (req, res) => {
68
+ res.status(200).send(req.body.test);
69
+ });
70
+ forklaunchRouterInstance.patch('/test', {
71
+ name: 'Test',
72
+ summary: 'Test Summary',
73
+ body: {
74
+ test: typebox_1.string
75
+ },
76
+ responses: {
77
+ 200: typebox_1.string
78
+ }
79
+ }, (req, res) => {
80
+ res.status(200).send(req.body.test);
81
+ });
82
+ forklaunchRouterInstance.delete('/test', {
83
+ name: 'Test',
84
+ summary: 'Test Summary',
85
+ responses: {
86
+ 200: typebox_1.string
87
+ }
88
+ }, (req, res) => {
89
+ res.status(200).send('Hello World');
90
+ });
91
+ forklaunchApplication.use(forklaunchRouterInstance);
92
+ await forklaunchApplication.listen(6934, () => {
93
+ console.log('Server started');
94
+ });
95
+ });
96
+ test('Get', async () => {
97
+ const testGet = await fetch('http://localhost:6934/testpath/test', {
98
+ method: 'GET'
99
+ });
100
+ expect(testGet.status).toBe(200);
101
+ expect(await testGet.text()).toBe('Hello World');
102
+ });
103
+ test('Post', async () => {
104
+ const testPost = await fetch('http://localhost:6934/testpath/test', {
105
+ method: 'POST',
106
+ body: JSON.stringify({ test: 'Hello World' }),
107
+ headers: { 'Content-Type': 'application/json' }
108
+ });
109
+ expect(testPost.status).toBe(200);
110
+ expect(await testPost.text()).toBe('Hello World');
111
+ });
112
+ test('Put', async () => {
113
+ const testPut = await fetch('http://localhost:6934/testpath/test', {
114
+ method: 'PUT',
115
+ body: JSON.stringify({ test: 'Hello World' }),
116
+ headers: { 'Content-Type': 'application/json' }
117
+ });
118
+ expect(testPut.status).toBe(200);
119
+ expect(await testPut.text()).toBe('Hello World');
120
+ });
121
+ test('Patch', async () => {
122
+ const testPatch = await fetch('http://localhost:6934/testpath/test', {
123
+ method: 'PATCH',
124
+ body: JSON.stringify({ test: 'Hello World' }),
125
+ headers: { 'Content-Type': 'application/json' }
126
+ });
127
+ expect(testPatch.status).toBe(200);
128
+ expect(await testPatch.text()).toBe('Hello World');
129
+ });
130
+ test('Delete', async () => {
131
+ const testDelete = await fetch('http://localhost:6934/testpath/test', {
132
+ method: 'DELETE'
133
+ });
134
+ expect(testDelete.status).toBe(200);
135
+ expect(await testDelete.text()).toBe('Hello World');
136
+ });
137
+ afterAll(async () => {
138
+ setTimeout(async () => await (0, kill_port_process_1.killPortProcess)(6934), 500);
139
+ });
140
+ });
141
+ //# sourceMappingURL=typebox.forklaunch.express.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typebox.forklaunch.express.test.js","sourceRoot":"","sources":["../../tests/typebox.forklaunch.express.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2DAA+E;AAC/E,yDAAoD;AACpD,4EAAiG;AAEjG,MAAM,sBAAsB,GAAG,IAAI,gCAAsB,EAAE,CAAC;AAE5D,QAAQ,CAAC,0BAA0B,EAAE,GAAG,EAAE;IACtC,IAAI,qBAA0D,CAAC;IAC/D,IAAI,wBAAwD,CAAC;IAE7D,SAAS,CAAC,KAAK,IAAI,EAAE;QACjB,MAAM,IAAA,mCA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CAAC,MAAM,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,QAAQ,EAAE,KAAK,IAAI,EAAE;QACtB,MAAM,UAAU,GAAG,MAAM,KAAK,CAAC,qCAAqC,EAAE;YAClE,MAAM,EAAE,QAAQ;SACnB,CAAC,CAAC;QAEH,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACpC,MAAM,CAAC,MAAM,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,KAAK,IAAI,EAAE;QAChB,UAAU,CAAC,KAAK,IAAI,EAAE,CAAC,MAAM,IAAA,mCAAe,EAAC,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC;IAC7D,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,141 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const zod_1 = require("@forklaunch/validator/zod");
27
+ const kill_port_process_1 = require("kill-port-process");
28
+ const forklaunch_express_1 = __importStar(require("../forklaunch.express"));
29
+ const zodSchemaValidator = new zod_1.ZodSchemaValidator();
30
+ describe('Forklaunch Express Tests', () => {
31
+ let forklaunchApplication;
32
+ let forklaunchRouterInstance;
33
+ beforeAll(async () => {
34
+ await (0, kill_port_process_1.killPortProcess)(6935);
35
+ forklaunchApplication = (0, forklaunch_express_1.default)(zodSchemaValidator);
36
+ forklaunchRouterInstance = (0, forklaunch_express_1.forklaunchRouter)('/testpath', zodSchemaValidator);
37
+ forklaunchRouterInstance.get('/test', {
38
+ name: 'Test',
39
+ summary: 'Test Summary',
40
+ responses: {
41
+ 200: zod_1.string
42
+ }
43
+ }, (req, res) => {
44
+ res.status(200).send('Hello World');
45
+ });
46
+ forklaunchRouterInstance.post('/test', {
47
+ name: 'Test',
48
+ summary: 'Test Summary',
49
+ body: {
50
+ test: zod_1.string
51
+ },
52
+ responses: {
53
+ 200: zod_1.string
54
+ }
55
+ }, (req, res) => {
56
+ res.status(200).send(req.body.test);
57
+ });
58
+ forklaunchRouterInstance.put('/test', {
59
+ name: 'Test',
60
+ summary: 'Test Summary',
61
+ body: {
62
+ test: zod_1.string
63
+ },
64
+ responses: {
65
+ 200: zod_1.string
66
+ }
67
+ }, (req, res) => {
68
+ res.status(200).send(req.body.test);
69
+ });
70
+ forklaunchRouterInstance.patch('/test', {
71
+ name: 'Test',
72
+ summary: 'Test Summary',
73
+ body: {
74
+ test: zod_1.string
75
+ },
76
+ responses: {
77
+ 200: zod_1.string
78
+ }
79
+ }, (req, res) => {
80
+ res.status(200).send(req.body.test);
81
+ });
82
+ forklaunchRouterInstance.delete('/test', {
83
+ name: 'Test',
84
+ summary: 'Test Summary',
85
+ responses: {
86
+ 200: zod_1.string
87
+ }
88
+ }, (req, res) => {
89
+ res.status(200).send('Hello World');
90
+ });
91
+ forklaunchApplication.use(forklaunchRouterInstance);
92
+ await forklaunchApplication.listen(6935, () => {
93
+ console.log('Server started');
94
+ });
95
+ });
96
+ test('Get', async () => {
97
+ const testGet = await fetch('http://localhost:6934/testpath/test', {
98
+ method: 'GET'
99
+ });
100
+ expect(testGet.status).toBe(200);
101
+ expect(await testGet.text()).toBe('Hello World');
102
+ });
103
+ test('Post', async () => {
104
+ const testPost = await fetch('http://localhost:6934/testpath/test', {
105
+ method: 'POST',
106
+ body: JSON.stringify({ test: 'Hello World' }),
107
+ headers: { 'Content-Type': 'application/json' }
108
+ });
109
+ expect(testPost.status).toBe(200);
110
+ expect(await testPost.text()).toBe('Hello World');
111
+ });
112
+ test('Put', async () => {
113
+ const testPut = await fetch('http://localhost:6934/testpath/test', {
114
+ method: 'PUT',
115
+ body: JSON.stringify({ test: 'Hello World' }),
116
+ headers: { 'Content-Type': 'application/json' }
117
+ });
118
+ expect(testPut.status).toBe(200);
119
+ expect(await testPut.text()).toBe('Hello World');
120
+ });
121
+ test('Patch', async () => {
122
+ const testPatch = await fetch('http://localhost:6934/testpath/test', {
123
+ method: 'PATCH',
124
+ body: JSON.stringify({ test: 'Hello World' }),
125
+ headers: { 'Content-Type': 'application/json' }
126
+ });
127
+ expect(testPatch.status).toBe(200);
128
+ expect(await testPatch.text()).toBe('Hello World');
129
+ });
130
+ test('Delete', async () => {
131
+ const testDelete = await fetch('http://localhost:6934/testpath/test', {
132
+ method: 'DELETE'
133
+ });
134
+ expect(testDelete.status).toBe(200);
135
+ expect(await testDelete.text()).toBe('Hello World');
136
+ });
137
+ afterAll(async () => {
138
+ setTimeout(async () => await (0, kill_port_process_1.killPortProcess)(6935), 500);
139
+ });
140
+ });
141
+ //# sourceMappingURL=zod.forklaunch.express.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zod.forklaunch.express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AE,KAAK,IAAI,EAAE;QACrB,MAAM,SAAS,GAAG,MAAM,KAAK,CAAC,qCAAqC,EAAE;YACjE,MAAM,EAAE,OAAO;YACf,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC;YAC7C,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;SAClD,CAAC,CAAC;QAEH,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACnC,MAAM,CAAC,MAAM,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,QAAQ,EAAE,KAAK,IAAI,EAAE;QACtB,MAAM,UAAU,GAAG,MAAM,KAAK,CAAC,qCAAqC,EAAE;YAClE,MAAM,EAAE,QAAQ;SACnB,CAAC,CAAC;QAEH,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACpC,MAAM,CAAC,MAAM,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,KAAK,IAAI,EAAE;QAChB,UAAU,CAAC,KAAK,IAAI,EAAE,CAAC,MAAM,IAAA,mCAAe,EAAC,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC;IAC7D,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -0,0 +1,53 @@
1
+ import { FlattenKeys, Prettify } from '@forklaunch/common';
2
+ import { Body, ForklaunchRequest, ForklaunchResponse, MapSchema, ParamsDictionary, ParamsObject, QueryObject, ResponsesObject } from '@forklaunch/core';
3
+ import { AnySchemaValidator } from '@forklaunch/validator';
4
+ import { Request as ExpressRequest, Response as ExpressResponse, NextFunction } from 'express';
5
+ import { ParsedQs } from 'qs';
6
+ /**
7
+ * Extends the Forklaunch request interface with properties from Express's request interface.
8
+ *
9
+ * @template SV - A type that extends AnySchemaValidator.
10
+ * @template P - A type for request parameters, defaulting to ParamsDictionary.
11
+ * @template ResBody - A type for the response body, defaulting to unknown.
12
+ * @template ReqBody - A type for the request body, defaulting to unknown.
13
+ * @template ReqQuery - A type for the request query, defaulting to ParsedQs.
14
+ * @template LocalsObj - A type for local variables, defaulting to an empty object.
15
+ */
16
+ export interface Request<SV extends AnySchemaValidator, P = ParamsDictionary, ResBody = unknown, ReqBody = unknown, ReqQuery = ParsedQs, LocalsObj extends Record<string, unknown> = Record<string, unknown>> extends ForklaunchRequest<SV, P, ReqBody, ReqQuery>, Omit<ExpressRequest<P, ResBody, ReqBody, ReqQuery, LocalsObj>, 'body' | 'params' | 'query'> {
17
+ }
18
+ /**
19
+ * Extends the Forklaunch response interface with properties from Express's response interface.
20
+ *
21
+ * @template ResBody - A type for the response body, defaulting to unknown.
22
+ * @template LocalsObj - A type for local variables, defaulting to an empty object.
23
+ * @template StatusCode - A type for the status code, defaulting to number.
24
+ */
25
+ export interface Response<ResBody = unknown, LocalsObj extends Record<string, unknown> = Record<string, unknown>, StatusCode extends number = number> extends ForklaunchResponse<ResBody, StatusCode>, Omit<ExpressResponse<ResBody, LocalsObj>, 'status' | 'statusCode' | 'sendStatus' | 'getHeaders' | 'setHeader' | 'send' | 'json' | 'jsonp'> {
26
+ }
27
+ /**
28
+ * Represents a request handler with schema validation.
29
+ *
30
+ * @template SV - A type that extends AnySchemaValidator.
31
+ * @template P - A type for request parameters, defaulting to ParamsDictionary.
32
+ * @template ResBody - A type for the response body, defaulting to unknown.
33
+ * @template ReqBody - A type for the request body, defaulting to unknown.
34
+ * @template ReqQuery - A type for the request query, defaulting to ParsedQs.
35
+ * @template LocalsObj - A type for local variables, defaulting to an empty object.
36
+ * @template StatusCode - A type for the status code, defaulting to number.
37
+ */
38
+ export interface RequestHandler<SV extends AnySchemaValidator, P = ParamsDictionary, ResBody = unknown, ReqBody = unknown, ReqQuery = ParsedQs, LocalsObj extends Record<string, unknown> = Record<string, unknown>, StatusCode extends number = number> {
39
+ (req: Request<SV, P, ResBody, ReqBody, ReqQuery, LocalsObj>, res: Response<ResBody, LocalsObj, StatusCode>, next?: NextFunction): void | Promise<void>;
40
+ }
41
+ /**
42
+ * Represents a schema request handler with typed parameters, responses, body, and query.
43
+ *
44
+ * @template SV - A type that extends AnySchemaValidator.
45
+ * @template P - A type for parameter schemas, defaulting to ParamsObject.
46
+ * @template ResBody - A type for response schemas, defaulting to ResponsesObject.
47
+ * @template ReqBody - A type for the request body, defaulting to Body.
48
+ * @template ReqQuery - A type for the request query, defaulting to QueryObject.
49
+ * @template LocalsObj - A type for local variables, defaulting to an empty object.
50
+ */
51
+ export type SchemaRequestHandler<SV extends AnySchemaValidator, 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>> = RequestHandler<SV, MapSchema<SV, P>, Prettify<MapSchema<SV, ResBody> & {
52
+ 500: string;
53
+ }>, MapSchema<SV, ReqBody>, MapSchema<SV, ReqQuery>, LocalsObj, FlattenKeys<ResBody> & number>;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=forklaunch.express.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"forklaunch.express.types.js","sourceRoot":"","sources":["../../types/forklaunch.express.types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,12 @@
1
+ import pluginJs from "@eslint/js";
2
+ import globals from "globals";
3
+ import tseslint from "typescript-eslint";
4
+
5
+
6
+ export default [
7
+ {files: ["**/*.{ts}"]},
8
+ {ignores: ["tests/**/*", "dist/**/*", "node_modules/**/*"]},
9
+ {languageOptions: { globals: globals.browser }},
10
+ pluginJs.configs.recommended,
11
+ ...tseslint.configs.recommended,
12
+ ];