@forklaunch/express 0.1.32 → 0.2.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.
- package/lib/index.d.mts +118 -0
- package/lib/index.d.ts +103 -9
- package/lib/index.js +301 -23
- package/lib/index.mjs +270 -0
- package/package.json +13 -10
- package/lib/index.d.ts.map +0 -1
- package/lib/src/expressApplication.d.ts +0 -30
- package/lib/src/expressApplication.d.ts.map +0 -1
- package/lib/src/expressApplication.js +0 -32
- package/lib/src/expressRouter.d.ts +0 -46
- package/lib/src/expressRouter.d.ts.map +0 -1
- package/lib/src/expressRouter.js +0 -92
- package/lib/src/middleware/async.middleware.d.ts +0 -16
- package/lib/src/middleware/async.middleware.d.ts.map +0 -1
- package/lib/src/middleware/async.middleware.js +0 -19
- package/lib/src/middleware/response.middleware.d.ts +0 -15
- package/lib/src/middleware/response.middleware.d.ts.map +0 -1
- package/lib/src/middleware/response.middleware.js +0 -54
- package/lib/src/types/express.types.d.ts +0 -28
- package/lib/src/types/express.types.d.ts.map +0 -1
- package/lib/src/types/express.types.js +0 -1
- package/lib/tests/typebox.forklaunch.express.test.d.ts +0 -2
- package/lib/tests/typebox.forklaunch.express.test.d.ts.map +0 -1
- package/lib/tests/typebox.forklaunch.express.test.js +0 -110
- package/lib/tests/zod.forklaunch.express.test.d.ts +0 -2
- package/lib/tests/zod.forklaunch.express.test.d.ts.map +0 -1
- package/lib/tests/zod.forklaunch.express.test.js +0 -110
- package/lib/vitest.config.d.ts +0 -3
- package/lib/vitest.config.d.ts.map +0 -1
- package/lib/vitest.config.js +0 -7
@@ -1,54 +0,0 @@
|
|
1
|
-
import { enrichExpressLikeSend } from '@forklaunch/core/http';
|
2
|
-
/**
|
3
|
-
* Middleware to enrich the response transmission by intercepting and parsing responses before they are sent.
|
4
|
-
*
|
5
|
-
* @template SV - A type that extends AnySchemaValidator.
|
6
|
-
* @param {Request<SV>} req - The request object.
|
7
|
-
* @param {Response} res - The response object.
|
8
|
-
* @param {NextFunction} [next] - The next middleware function.
|
9
|
-
*/
|
10
|
-
export function enrichResponseTransmission(req, res, next) {
|
11
|
-
const originalSend = res.send;
|
12
|
-
const originalJson = res.json;
|
13
|
-
const originalSetHeader = res.setHeader;
|
14
|
-
/**
|
15
|
-
* Intercepts the JSON response to include additional processing.
|
16
|
-
*
|
17
|
-
* @template T - The type of the response data.
|
18
|
-
* @param {unknown} data - The data to send in the response.
|
19
|
-
* @returns {T} - The result of the original JSON method.
|
20
|
-
*/
|
21
|
-
res.json = function (data) {
|
22
|
-
res.bodyData = data;
|
23
|
-
return originalJson.call(this, data);
|
24
|
-
};
|
25
|
-
/**
|
26
|
-
* Intercepts the send response to include additional processing and error handling.
|
27
|
-
*
|
28
|
-
* @param {unknown} data - The data to send in the response.
|
29
|
-
* @returns {Response} - The result of the original send method.
|
30
|
-
*/
|
31
|
-
res.send = function (data) {
|
32
|
-
if (!res.bodyData) {
|
33
|
-
res.bodyData = data;
|
34
|
-
}
|
35
|
-
return enrichExpressLikeSend(this, req, res, originalSend, data, !res.cors);
|
36
|
-
};
|
37
|
-
/**
|
38
|
-
* Intercepts the setHeader method to stringify the value before setting the header.
|
39
|
-
*
|
40
|
-
* @param {string}
|
41
|
-
*/
|
42
|
-
res.setHeader = function (name, value) {
|
43
|
-
let stringifiedValue;
|
44
|
-
if (Array.isArray(value)) {
|
45
|
-
stringifiedValue = value.map((v) => typeof v !== 'string' ? JSON.stringify(v) : v);
|
46
|
-
}
|
47
|
-
else {
|
48
|
-
stringifiedValue =
|
49
|
-
typeof value !== 'string' ? JSON.stringify(value) : value;
|
50
|
-
}
|
51
|
-
return originalSetHeader.call(this, name, stringifiedValue);
|
52
|
-
};
|
53
|
-
next?.();
|
54
|
-
}
|
@@ -1,28 +0,0 @@
|
|
1
|
-
import { ForklaunchRequest, ForklaunchResponse, ForklaunchSendableData, ForklaunchStatusResponse, ParamsDictionary } from '@forklaunch/core/http';
|
2
|
-
import { AnySchemaValidator } from '@forklaunch/validator';
|
3
|
-
import { Request as ExpressRequest, Response as ExpressResponse } from 'express';
|
4
|
-
import { ParsedQs } from 'qs';
|
5
|
-
/**
|
6
|
-
* Extends the Forklaunch request interface with properties from Express's request interface.
|
7
|
-
*
|
8
|
-
* @template SV - A type that extends AnySchemaValidator.
|
9
|
-
* @template P - A type for request parameters, defaulting to ParamsDictionary.
|
10
|
-
* @template ResBodyMap - A type for the response body, defaulting to unknown.
|
11
|
-
* @template ReqBody - A type for the request body, defaulting to unknown.
|
12
|
-
* @template ReqQuery - A type for the request query, defaulting to ParsedQs.
|
13
|
-
* @template LocalsObj - A type for local variables, defaulting to an empty object.
|
14
|
-
*/
|
15
|
-
export interface Request<SV extends AnySchemaValidator, P extends ParamsDictionary, ResBodyMap extends Record<number, unknown>, ReqBody extends Record<string, unknown>, ReqQuery extends ParsedQs, ReqHeaders extends Record<string, string>, LocalsObj extends Record<string, unknown>> extends ForklaunchRequest<SV, P, ReqBody, ReqQuery, ReqHeaders>, Omit<ExpressRequest<P, ResBodyMap, ReqBody, ReqQuery, LocalsObj>, 'method' | 'body' | 'params' | 'query' | 'headers'> {
|
16
|
-
}
|
17
|
-
/**
|
18
|
-
* Extends the Forklaunch response interface with properties from Express's response interface.
|
19
|
-
*
|
20
|
-
* @template ResBodyMap - A type for the response body, defaulting to unknown.
|
21
|
-
* @template LocalsObj - A type for local variables, defaulting to an empty object.
|
22
|
-
* @template StatusCode - A type for the status code, defaulting to number.
|
23
|
-
*/
|
24
|
-
export interface Response<ResBodyMap extends Record<number, unknown>, ResHeaders extends Record<string, string>, LocalsObj extends Record<string, unknown> = Record<string, unknown>> extends ForklaunchResponse<ResBodyMap, ResHeaders, LocalsObj>, Omit<ExpressResponse<ResBodyMap, LocalsObj>, 'status' | 'statusCode' | 'sendStatus' | 'getHeaders' | 'setHeader' | 'send' | 'json' | 'jsonp' | 'end' | 'locals'>, ForklaunchStatusResponse<ForklaunchSendableData> {
|
25
|
-
/** If cors are applied to the response */
|
26
|
-
cors: boolean;
|
27
|
-
}
|
28
|
-
//# sourceMappingURL=express.types.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"express.types.d.ts","sourceRoot":"","sources":["../../../src/types/express.types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,EACtB,wBAAwB,EACxB,gBAAgB,EACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EACL,OAAO,IAAI,cAAc,EACzB,QAAQ,IAAI,eAAe,EAC5B,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAE9B;;;;;;;;;GASG;AACH,MAAM,WAAW,OAAO,CACtB,EAAE,SAAS,kBAAkB,EAC7B,CAAC,SAAS,gBAAgB,EAC1B,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC1C,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACvC,QAAQ,SAAS,QAAQ,EACzB,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACzC,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CACzC,SAAQ,iBAAiB,CAAC,EAAE,EAAE,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,CAAC,EAC7D,IAAI,CACF,cAAc,CAAC,CAAC,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,EAC3D,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,GAAG,SAAS,CACnD;CAAG;AAER;;;;;;GAMG;AACH,MAAM,WAAW,QAAQ,CACvB,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC1C,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACzC,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CACnE,SAAQ,kBAAkB,CAAC,UAAU,EAAE,UAAU,EAAE,SAAS,CAAC,EAC3D,IAAI,CACF,eAAe,CAAC,UAAU,EAAE,SAAS,CAAC,EACpC,QAAQ,GACR,YAAY,GACZ,YAAY,GACZ,YAAY,GACZ,WAAW,GACX,MAAM,GACN,MAAM,GACN,OAAO,GACP,KAAK,GACL,QAAQ,CACX,EACD,wBAAwB,CAAC,sBAAsB,CAAC;IAClD,0CAA0C;IAC1C,IAAI,EAAE,OAAO,CAAC;CACf"}
|
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"typebox.forklaunch.express.test.d.ts","sourceRoot":"","sources":["../../tests/typebox.forklaunch.express.test.ts"],"names":[],"mappings":""}
|
@@ -1,110 +0,0 @@
|
|
1
|
-
import { SchemaValidator, string } from '@forklaunch/validator/typebox';
|
2
|
-
import { forklaunchExpress, forklaunchRouter } from '../index';
|
3
|
-
const typeboxSchemaValidator = SchemaValidator();
|
4
|
-
const forklaunchApplication = forklaunchExpress(typeboxSchemaValidator);
|
5
|
-
const forklaunchRouterInstance = forklaunchRouter('/testpath', typeboxSchemaValidator);
|
6
|
-
describe('Forklaunch Express Tests', () => {
|
7
|
-
let server;
|
8
|
-
beforeAll(async () => {
|
9
|
-
forklaunchRouterInstance.get('/test', {
|
10
|
-
name: 'Test',
|
11
|
-
summary: 'Test Summary',
|
12
|
-
responses: {
|
13
|
-
200: string
|
14
|
-
}
|
15
|
-
}, async (_req, res) => {
|
16
|
-
res.status(200).send('Hello World');
|
17
|
-
});
|
18
|
-
forklaunchRouterInstance.post('/test', {
|
19
|
-
name: 'Test',
|
20
|
-
summary: 'Test Summary',
|
21
|
-
body: {
|
22
|
-
test: string
|
23
|
-
},
|
24
|
-
responses: {
|
25
|
-
200: string
|
26
|
-
}
|
27
|
-
}, (req, res) => {
|
28
|
-
res.status(200).send(req.body.test);
|
29
|
-
});
|
30
|
-
forklaunchRouterInstance.put('/test', {
|
31
|
-
name: 'Test',
|
32
|
-
summary: 'Test Summary',
|
33
|
-
body: {
|
34
|
-
test: string
|
35
|
-
},
|
36
|
-
responses: {
|
37
|
-
200: string
|
38
|
-
}
|
39
|
-
}, (req, res) => {
|
40
|
-
res.status(200).send(req.body.test);
|
41
|
-
});
|
42
|
-
forklaunchRouterInstance.patch('/test', {
|
43
|
-
name: 'Test',
|
44
|
-
summary: 'Test Summary',
|
45
|
-
body: {
|
46
|
-
test: string
|
47
|
-
},
|
48
|
-
responses: {
|
49
|
-
200: string
|
50
|
-
}
|
51
|
-
}, (req, res) => {
|
52
|
-
res.status(200).send(req.body.test);
|
53
|
-
});
|
54
|
-
forklaunchRouterInstance.delete('/test', {
|
55
|
-
name: 'Test',
|
56
|
-
summary: 'Test Summary',
|
57
|
-
responses: {
|
58
|
-
200: string
|
59
|
-
}
|
60
|
-
}, (_req, res) => {
|
61
|
-
res.status(200).send('Hello World');
|
62
|
-
});
|
63
|
-
forklaunchApplication.use(forklaunchRouterInstance);
|
64
|
-
server = await forklaunchApplication.listen(6934, () => { });
|
65
|
-
});
|
66
|
-
test('Get', async () => {
|
67
|
-
const testGet = await fetch('http://localhost:6934/testpath/test', {
|
68
|
-
method: 'GET'
|
69
|
-
});
|
70
|
-
expect(testGet.status).toBe(200);
|
71
|
-
expect(await testGet.text()).toBe('Hello World');
|
72
|
-
});
|
73
|
-
test('Post', async () => {
|
74
|
-
const testPost = await fetch('http://localhost:6934/testpath/test', {
|
75
|
-
method: 'POST',
|
76
|
-
body: JSON.stringify({ test: 'Hello World' }),
|
77
|
-
headers: { 'Content-Type': 'application/json' }
|
78
|
-
});
|
79
|
-
expect(testPost.status).toBe(200);
|
80
|
-
expect(await testPost.text()).toBe('Hello World');
|
81
|
-
});
|
82
|
-
test('Put', async () => {
|
83
|
-
const testPut = await fetch('http://localhost:6934/testpath/test', {
|
84
|
-
method: 'PUT',
|
85
|
-
body: JSON.stringify({ test: 'Hello World' }),
|
86
|
-
headers: { 'Content-Type': 'application/json' }
|
87
|
-
});
|
88
|
-
expect(testPut.status).toBe(200);
|
89
|
-
expect(await testPut.text()).toBe('Hello World');
|
90
|
-
});
|
91
|
-
test('Patch', async () => {
|
92
|
-
const testPatch = await fetch('http://localhost:6934/testpath/test', {
|
93
|
-
method: 'PATCH',
|
94
|
-
body: JSON.stringify({ test: 'Hello World' }),
|
95
|
-
headers: { 'Content-Type': 'application/json' }
|
96
|
-
});
|
97
|
-
expect(testPatch.status).toBe(200);
|
98
|
-
expect(await testPatch.text()).toBe('Hello World');
|
99
|
-
});
|
100
|
-
test('Delete', async () => {
|
101
|
-
const testDelete = await fetch('http://localhost:6934/testpath/test', {
|
102
|
-
method: 'DELETE'
|
103
|
-
});
|
104
|
-
expect(testDelete.status).toBe(200);
|
105
|
-
expect(await testDelete.text()).toBe('Hello World');
|
106
|
-
});
|
107
|
-
afterAll(async () => {
|
108
|
-
server.close();
|
109
|
-
});
|
110
|
-
});
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"zod.forklaunch.express.test.d.ts","sourceRoot":"","sources":["../../tests/zod.forklaunch.express.test.ts"],"names":[],"mappings":""}
|
@@ -1,110 +0,0 @@
|
|
1
|
-
import { SchemaValidator, string } from '@forklaunch/validator/zod';
|
2
|
-
import { forklaunchExpress, forklaunchRouter } from '../index';
|
3
|
-
const zodSchemaValidator = SchemaValidator();
|
4
|
-
const forklaunchApplication = forklaunchExpress(zodSchemaValidator);
|
5
|
-
const forklaunchRouterInstance = forklaunchRouter('/testpath', zodSchemaValidator);
|
6
|
-
describe('Forklaunch Express Tests', () => {
|
7
|
-
let server;
|
8
|
-
beforeAll(async () => {
|
9
|
-
forklaunchRouterInstance.get('/test', {
|
10
|
-
name: 'Test',
|
11
|
-
summary: 'Test Summary',
|
12
|
-
responses: {
|
13
|
-
200: string
|
14
|
-
}
|
15
|
-
}, (_req, res) => {
|
16
|
-
res.status(200).send('Hello World');
|
17
|
-
});
|
18
|
-
forklaunchRouterInstance.post('/test', {
|
19
|
-
name: 'Test',
|
20
|
-
summary: 'Test Summary',
|
21
|
-
body: {
|
22
|
-
test: string
|
23
|
-
},
|
24
|
-
responses: {
|
25
|
-
200: string
|
26
|
-
}
|
27
|
-
}, (req, res) => {
|
28
|
-
res.status(200).send(req.body.test);
|
29
|
-
});
|
30
|
-
forklaunchRouterInstance.put('/test', {
|
31
|
-
name: 'Test',
|
32
|
-
summary: 'Test Summary',
|
33
|
-
body: {
|
34
|
-
test: string
|
35
|
-
},
|
36
|
-
responses: {
|
37
|
-
200: string
|
38
|
-
}
|
39
|
-
}, (req, res) => {
|
40
|
-
res.status(200).send(req.body.test);
|
41
|
-
});
|
42
|
-
forklaunchRouterInstance.patch('/test', {
|
43
|
-
name: 'Test',
|
44
|
-
summary: 'Test Summary',
|
45
|
-
body: {
|
46
|
-
test: string
|
47
|
-
},
|
48
|
-
responses: {
|
49
|
-
200: string
|
50
|
-
}
|
51
|
-
}, (req, res) => {
|
52
|
-
res.status(200).send(req.body.test);
|
53
|
-
});
|
54
|
-
forklaunchRouterInstance.delete('/test', {
|
55
|
-
name: 'Test',
|
56
|
-
summary: 'Test Summary',
|
57
|
-
responses: {
|
58
|
-
200: string
|
59
|
-
}
|
60
|
-
}, (_req, res) => {
|
61
|
-
res.status(200).send('Hello World');
|
62
|
-
});
|
63
|
-
forklaunchApplication.use(forklaunchRouterInstance);
|
64
|
-
server = await forklaunchApplication.listen(6935, () => { });
|
65
|
-
});
|
66
|
-
test('Get', async () => {
|
67
|
-
const testGet = await fetch('http://localhost:6935/testpath/test', {
|
68
|
-
method: 'GET'
|
69
|
-
});
|
70
|
-
expect(testGet.status).toBe(200);
|
71
|
-
expect(await testGet.text()).toBe('Hello World');
|
72
|
-
});
|
73
|
-
test('Post', async () => {
|
74
|
-
const testPost = await fetch('http://localhost:6935/testpath/test', {
|
75
|
-
method: 'POST',
|
76
|
-
body: JSON.stringify({ test: 'Hello World' }),
|
77
|
-
headers: { 'Content-Type': 'application/json' }
|
78
|
-
});
|
79
|
-
expect(testPost.status).toBe(200);
|
80
|
-
expect(await testPost.text()).toBe('Hello World');
|
81
|
-
});
|
82
|
-
test('Put', async () => {
|
83
|
-
const testPut = await fetch('http://localhost:6935/testpath/test', {
|
84
|
-
method: 'PUT',
|
85
|
-
body: JSON.stringify({ test: 'Hello World' }),
|
86
|
-
headers: { 'Content-Type': 'application/json' }
|
87
|
-
});
|
88
|
-
expect(testPut.status).toBe(200);
|
89
|
-
expect(await testPut.text()).toBe('Hello World');
|
90
|
-
});
|
91
|
-
test('Patch', async () => {
|
92
|
-
const testPatch = await fetch('http://localhost:6935/testpath/test', {
|
93
|
-
method: 'PATCH',
|
94
|
-
body: JSON.stringify({ test: 'Hello World' }),
|
95
|
-
headers: { 'Content-Type': 'application/json' }
|
96
|
-
});
|
97
|
-
expect(testPatch.status).toBe(200);
|
98
|
-
expect(await testPatch.text()).toBe('Hello World');
|
99
|
-
});
|
100
|
-
test('Delete', async () => {
|
101
|
-
const testDelete = await fetch('http://localhost:6935/testpath/test', {
|
102
|
-
method: 'DELETE'
|
103
|
-
});
|
104
|
-
expect(testDelete.status).toBe(200);
|
105
|
-
expect(await testDelete.text()).toBe('Hello World');
|
106
|
-
});
|
107
|
-
afterAll(async () => {
|
108
|
-
server.close();
|
109
|
-
});
|
110
|
-
});
|
package/lib/vitest.config.d.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"vitest.config.d.ts","sourceRoot":"","sources":["../vitest.config.ts"],"names":[],"mappings":";AAEA,wBAKG"}
|