@forklaunch/hyper-express 0.1.33 → 0.2.1

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 (39) hide show
  1. package/lib/index.d.mts +95 -0
  2. package/lib/index.d.ts +79 -9
  3. package/lib/index.js +257 -23
  4. package/lib/index.mjs +230 -0
  5. package/package.json +30 -27
  6. package/lib/config.d.ts +0 -2
  7. package/lib/config.d.ts.map +0 -1
  8. package/lib/config.js +0 -1
  9. package/lib/index.d.ts.map +0 -1
  10. package/lib/src/hyperExpressApplication.d.ts +0 -28
  11. package/lib/src/hyperExpressApplication.d.ts.map +0 -1
  12. package/lib/src/hyperExpressApplication.js +0 -41
  13. package/lib/src/hyperExpressRouter.d.ts +0 -10
  14. package/lib/src/hyperExpressRouter.d.ts.map +0 -1
  15. package/lib/src/hyperExpressRouter.js +0 -22
  16. package/lib/src/middleware/contentParse.middleware.d.ts +0 -8
  17. package/lib/src/middleware/contentParse.middleware.d.ts.map +0 -1
  18. package/lib/src/middleware/contentParse.middleware.js +0 -26
  19. package/lib/src/middleware/enrichResponseTransmission.middleware.d.ts +0 -14
  20. package/lib/src/middleware/enrichResponseTransmission.middleware.d.ts.map +0 -1
  21. package/lib/src/middleware/enrichResponseTransmission.middleware.js +0 -56
  22. package/lib/src/middleware/polyfillGetHeaders.middleware.d.ts +0 -3
  23. package/lib/src/middleware/polyfillGetHeaders.middleware.d.ts.map +0 -1
  24. package/lib/src/middleware/polyfillGetHeaders.middleware.js +0 -8
  25. package/lib/src/middleware/swagger.middleware.d.ts +0 -25
  26. package/lib/src/middleware/swagger.middleware.d.ts.map +0 -1
  27. package/lib/src/middleware/swagger.middleware.js +0 -75
  28. package/lib/src/types/hyperExpress.types.d.ts +0 -42
  29. package/lib/src/types/hyperExpress.types.d.ts.map +0 -1
  30. package/lib/src/types/hyperExpress.types.js +0 -1
  31. package/lib/tests/typebox.forklaunch.hyperExpress.test.d.ts +0 -2
  32. package/lib/tests/typebox.forklaunch.hyperExpress.test.d.ts.map +0 -1
  33. package/lib/tests/typebox.forklaunch.hyperExpress.test.js +0 -111
  34. package/lib/tests/zod.forklaunch.hyperExpress.test.d.ts +0 -2
  35. package/lib/tests/zod.forklaunch.hyperExpress.test.d.ts.map +0 -1
  36. package/lib/tests/zod.forklaunch.hyperExpress.test.js +0 -109
  37. package/lib/vitest.config.d.ts +0 -3
  38. package/lib/vitest.config.d.ts.map +0 -1
  39. package/lib/vitest.config.js +0 -7
package/lib/index.mjs ADDED
@@ -0,0 +1,230 @@
1
+ // src/hyperExpressApplication.ts
2
+ import {
3
+ ForklaunchExpressLikeApplication,
4
+ generateSwaggerDocument
5
+ } from "@forklaunch/core/http";
6
+ import { Server } from "@forklaunch/hyper-express-fork";
7
+
8
+ // src/middleware/swagger.middleware.ts
9
+ import LiveDirectory from "live-directory";
10
+ import getAbsoluteSwaggerFsPath from "swagger-ui-dist/absolute-path";
11
+ import swaggerUi from "swagger-ui-express";
12
+ function swaggerRedirect(path) {
13
+ return (req, res, next) => {
14
+ if (req.path === path) {
15
+ res.redirect(`${path}/`);
16
+ }
17
+ return next?.();
18
+ };
19
+ }
20
+ function swagger(path, document, opts, options, customCss, customfavIcon, swaggerUrl, customSiteTitle) {
21
+ const LiveAssets = new LiveDirectory(getAbsoluteSwaggerFsPath(), {
22
+ filter: {
23
+ keep: {
24
+ names: [
25
+ "swagger-ui-bundle.js",
26
+ "swagger-ui-standalone-preset.js",
27
+ "swagger-ui-init.js",
28
+ "swagger-ui.css",
29
+ "favicon-32x32.png",
30
+ "favicon-16x16.png"
31
+ ]
32
+ }
33
+ },
34
+ cache: {
35
+ max_file_count: 10,
36
+ max_file_size: 1024 * 1024 * 1.5
37
+ }
38
+ });
39
+ const serve = swaggerUi.serve[0];
40
+ const staticAssets = (req, res, next) => {
41
+ const filePath = req.path.replace(path, "");
42
+ const file = LiveAssets.get(filePath);
43
+ if (file === void 0) {
44
+ if (next) {
45
+ return next();
46
+ }
47
+ return res.status(404).send();
48
+ }
49
+ const fileParts = file.path.split(".");
50
+ const extension = fileParts[fileParts.length - 1];
51
+ const content = file.content;
52
+ return res.type(extension).send(content);
53
+ };
54
+ const ui = swaggerUi.setup(
55
+ document,
56
+ opts,
57
+ options,
58
+ customCss,
59
+ customfavIcon,
60
+ swaggerUrl,
61
+ customSiteTitle
62
+ );
63
+ return [serve, staticAssets, ui];
64
+ }
65
+
66
+ // src/hyperExpressApplication.ts
67
+ var Application = class extends ForklaunchExpressLikeApplication {
68
+ /**
69
+ * Creates an instance of the Application class.
70
+ *
71
+ * @param {SV} schemaValidator - The schema validator.
72
+ */
73
+ constructor(schemaValidator) {
74
+ super(schemaValidator, new Server());
75
+ }
76
+ listen(arg0, arg1, arg2) {
77
+ if (typeof arg0 === "number") {
78
+ const port = arg0 || Number(process.env.PORT);
79
+ this.internal.set_error_handler((_req, res, err) => {
80
+ res.locals.errorMessage = err.message;
81
+ console.error(err);
82
+ res.status(
83
+ res.statusCode && res.statusCode >= 400 ? res.statusCode : 500
84
+ ).send(`Internal server error:
85
+
86
+ ${err.message}`);
87
+ });
88
+ const swaggerPath = `/api${process.env.VERSION ?? "/v1"}${process.env.SWAGGER_PATH ?? "/swagger"}`;
89
+ this.internal.use(swaggerPath, swaggerRedirect(swaggerPath));
90
+ this.internal.get(
91
+ `${swaggerPath}/*`,
92
+ swagger(
93
+ swaggerPath,
94
+ generateSwaggerDocument(this.schemaValidator, port, this.routers)
95
+ )
96
+ );
97
+ if (arg1 && typeof arg1 === "string") {
98
+ return this.internal.listen(port, arg1, arg2);
99
+ } else if (arg1 && typeof arg1 === "function") {
100
+ return this.internal.listen(port, arg1);
101
+ }
102
+ }
103
+ return this.internal.listen(
104
+ arg0,
105
+ arg1
106
+ );
107
+ }
108
+ };
109
+
110
+ // src/hyperExpressRouter.ts
111
+ import {
112
+ ForklaunchExpressLikeRouter
113
+ } from "@forklaunch/core/http";
114
+ import {
115
+ Router as ExpressRouter
116
+ } from "@forklaunch/hyper-express-fork";
117
+
118
+ // src/middleware/contentParse.middleware.ts
119
+ async function contentParse(req) {
120
+ console.debug("[MIDDLEWARE] contentParse started");
121
+ switch (req.headers["content-type"] && req.headers["content-type"].split(";")[0]) {
122
+ case "application/json":
123
+ req.body = await req.json();
124
+ break;
125
+ case "application/x-www-form-urlencoded":
126
+ req.body = await req.urlencoded();
127
+ break;
128
+ case "text/plain":
129
+ req.body = await req.text();
130
+ break;
131
+ case "application/octet-stream":
132
+ req.body = await req.buffer();
133
+ break;
134
+ default:
135
+ req.body = await req.json();
136
+ break;
137
+ }
138
+ }
139
+
140
+ // src/middleware/enrichResponseTransmission.middleware.ts
141
+ import {
142
+ enrichExpressLikeSend
143
+ } from "@forklaunch/core/http";
144
+ function enrichResponseTransmission(req, res, next) {
145
+ console.debug("[MIDDLEWARE] enrichResponseTransmission");
146
+ const originalSend = res.send;
147
+ const originalJson = res.json;
148
+ const originalSetHeader = res.setHeader;
149
+ res.json = function(data) {
150
+ res.bodyData = data;
151
+ const result = originalJson.call(this, data);
152
+ return result;
153
+ };
154
+ res.send = function(data) {
155
+ if (!res.bodyData) {
156
+ res.bodyData = data;
157
+ res.statusCode = res._status_code;
158
+ }
159
+ return enrichExpressLikeSend(
160
+ this,
161
+ req,
162
+ res,
163
+ originalSend,
164
+ data,
165
+ !res.cors && (res._cork && !res._corked || !res._cork)
166
+ );
167
+ };
168
+ res.setHeader = function(name, value) {
169
+ let stringifiedValue;
170
+ if (Array.isArray(value)) {
171
+ stringifiedValue = value.map(
172
+ (v) => typeof v !== "string" ? JSON.stringify(v) : v
173
+ );
174
+ } else {
175
+ stringifiedValue = typeof value !== "string" ? JSON.stringify(value) : value;
176
+ }
177
+ return originalSetHeader.call(this, name, stringifiedValue);
178
+ };
179
+ next();
180
+ }
181
+
182
+ // src/middleware/polyfillGetHeaders.middleware.ts
183
+ function polyfillGetHeaders(_req, res, next) {
184
+ console.debug("[MIDDLEWARE] polyfillGetHeaders started");
185
+ res.getHeaders = () => {
186
+ return res._headers;
187
+ };
188
+ next?.();
189
+ }
190
+
191
+ // src/hyperExpressRouter.ts
192
+ var Router = class extends ForklaunchExpressLikeRouter {
193
+ constructor(basePath, schemaValidator) {
194
+ super(basePath, schemaValidator, new ExpressRouter());
195
+ this.basePath = basePath;
196
+ this.internal.use(polyfillGetHeaders);
197
+ this.internal.use(contentParse);
198
+ this.internal.use(
199
+ enrichResponseTransmission
200
+ );
201
+ }
202
+ route(path) {
203
+ this.internal.route(path);
204
+ return this;
205
+ }
206
+ any = (pathOrContractDetailsOrMiddlewareOrTypedHandler, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
207
+ return this.registerMiddlewareHandler(
208
+ this.internal.any,
209
+ pathOrContractDetailsOrMiddlewareOrTypedHandler,
210
+ contractDetailsOrMiddlewareOrTypedHandler,
211
+ ...middlewareOrMiddlewareWithTypedHandler
212
+ );
213
+ };
214
+ // TODO: Implement the rest of the methods
215
+ // upgrade
216
+ // ws
217
+ };
218
+
219
+ // index.ts
220
+ function forklaunchExpress(schemaValidator) {
221
+ return new Application(schemaValidator);
222
+ }
223
+ function forklaunchRouter(basePath, schemaValidator) {
224
+ const router = new Router(basePath, schemaValidator);
225
+ return router;
226
+ }
227
+ export {
228
+ forklaunchExpress,
229
+ forklaunchRouter
230
+ };
package/package.json CHANGED
@@ -1,36 +1,44 @@
1
1
  {
2
2
  "name": "@forklaunch/hyper-express",
3
- "version": "0.1.33",
3
+ "version": "0.2.1",
4
4
  "description": "Forklaunch framework for hyper-express.",
5
- "files": [
6
- "lib/**"
7
- ],
8
- "types": "lib/index.d.ts",
5
+ "homepage": "https://github.com/forklaunch/forklaunch-js#readme",
6
+ "bugs": {
7
+ "url": "https://github.com/forklaunch/forklaunch-js/issues"
8
+ },
9
9
  "repository": {
10
10
  "type": "git",
11
11
  "url": "git+https://github.com/forklaunch/forklaunch-js.git"
12
12
  },
13
- "author": "Rohin Bhargava",
14
13
  "license": "MIT",
15
- "bugs": {
16
- "url": "https://github.com/forklaunch/forklaunch-js/issues"
14
+ "author": "Rohin Bhargava",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./lib/index.d.ts",
18
+ "import": "./lib/index.mjs",
19
+ "require": "./lib/index.js",
20
+ "default": "./lib/index.js"
21
+ }
17
22
  },
18
- "homepage": "https://github.com/forklaunch/forklaunch-js#readme",
23
+ "types": "lib/index.d.ts",
24
+ "files": [
25
+ "lib/**"
26
+ ],
19
27
  "dependencies": {
28
+ "@forklaunch/hyper-express-fork": "6.17.3",
20
29
  "cors": "^2.8.5",
21
- "hyper-express": "6.17.2",
22
30
  "live-directory": "^3.0.3",
23
31
  "openapi3-ts": "^4.4.0",
24
32
  "qs": "^6.13.1",
25
33
  "swagger-ui-dist": "^5.18.2",
26
34
  "swagger-ui-express": "^5.0.1",
27
35
  "uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.44.0",
28
- "@forklaunch/common": "0.1.14",
29
- "@forklaunch/validator": "0.3.13",
30
- "@forklaunch/core": "0.2.37"
36
+ "@forklaunch/common": "0.2.0",
37
+ "@forklaunch/core": "0.3.0",
38
+ "@forklaunch/validator": "0.4.0"
31
39
  },
32
40
  "devDependencies": {
33
- "@eslint/js": "^9.16.0",
41
+ "@eslint/js": "^9.17.0",
34
42
  "@types/cors": "^2.8.17",
35
43
  "@types/jest": "^29.5.14",
36
44
  "@types/qs": "^6.9.17",
@@ -38,27 +46,22 @@
38
46
  "@types/swagger-ui-express": "^4.1.7",
39
47
  "jest": "^29.7.0",
40
48
  "kill-port-process": "^3.2.1",
41
- "prettier": "^3.4.1",
49
+ "prettier": "^3.4.2",
42
50
  "ts-jest": "^29.2.5",
43
51
  "ts-node": "^10.9.2",
52
+ "tsup": "^8.3.5",
44
53
  "tsx": "^4.19.2",
45
- "typescript": "^5.7.2",
46
- "typescript-eslint": "^8.17.0"
47
- },
48
- "exports": {
49
- ".": {
50
- "types": "./lib/index.d.ts",
51
- "default": "./lib/index.js"
52
- }
54
+ "typescript": "^5.7.3",
55
+ "typescript-eslint": "^8.19.1"
53
56
  },
54
57
  "scripts": {
55
- "test": "vitest --passWithNoTests",
56
- "build": "tsc",
58
+ "build": "tsc --noEmit && tsup index.ts --format cjs,esm --no-splitting --dts --tsconfig tsconfig.json --out-dir lib --clean",
57
59
  "clean": "rm -rf lib pnpm.lock.yaml node_modules",
58
60
  "docs": "typedoc --out docs *",
61
+ "format": "prettier --ignore-path=.prettierignore --config .prettierrc '**/*.{ts,json}' --write",
59
62
  "lint": "eslint . -c eslint.config.mjs",
60
63
  "lint:fix": "eslint . -c eslint.config.mjs --fix",
61
- "format": "prettier --ignore-path=.prettierignore --config .prettierrc '**/*.ts' --write",
62
- "publish:package": "./publish-package.bash"
64
+ "publish:package": "./publish-package.bash",
65
+ "test": "vitest --passWithNoTests"
63
66
  }
64
67
  }
package/lib/config.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export declare const basePath = "/testpath";
2
- //# sourceMappingURL=config.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../config.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ,cAAc,CAAC"}
package/lib/config.js DELETED
@@ -1 +0,0 @@
1
- export const basePath = '/testpath';
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAElD,MAAM,MAAM,GAAG,CAAC,EAAE,SAAS,kBAAkB,IAAI,WAAW,CAAC,EAAE,CAAC,CAAC;AAEjE;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,SAAS,kBAAkB,EAC7D,eAAe,EAAE,EAAE,mBAGpB;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,EAAE,SAAS,kBAAkB,EAC7B,QAAQ,SAAS,IAAI,MAAM,EAAE,EAC7B,QAAQ,EAAE,QAAQ,EAAE,eAAe,EAAE,EAAE,GAAG,MAAM,CAAC,EAAE,EAAE,QAAQ,CAAC,CAG/D;AAED,YAAY,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACjE,YAAY,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AACvD,cAAc,gCAAgC,CAAC"}
@@ -1,28 +0,0 @@
1
- import { ForklaunchExpressLikeApplication } from '@forklaunch/core/http';
2
- import { AnySchemaValidator } from '@forklaunch/validator';
3
- import { MiddlewareHandler, Server } from 'hyper-express';
4
- import * as uWebsockets from 'uWebSockets.js';
5
- /**
6
- * Represents an application built on top of Hyper-Express and Forklaunch.
7
- *
8
- * @template SV - A type that extends AnySchemaValidator.
9
- */
10
- export declare class Application<SV extends AnySchemaValidator> extends ForklaunchExpressLikeApplication<SV, Server, MiddlewareHandler> {
11
- /**
12
- * Creates an instance of the Application class.
13
- *
14
- * @param {SV} schemaValidator - The schema validator.
15
- */
16
- constructor(schemaValidator: SV);
17
- /**
18
- * Starts the server and sets up Swagger documentation.
19
- *
20
- * @param {string | number} arg0 - The port number or UNIX path to listen on.
21
- * @param {...unknown[]} args - Additional arguments.
22
- * @returns {Promise<uWebsockets.us_listen_socket>} - A promise that resolves with the listening socket.
23
- */
24
- listen(port: number, callback?: (listen_socket: uWebsockets.us_listen_socket) => void): Promise<uWebsockets.us_listen_socket>;
25
- listen(port: number, host?: string, callback?: (listen_socket: uWebsockets.us_listen_socket) => void): Promise<uWebsockets.us_listen_socket>;
26
- listen(unix_path: string, callback?: (listen_socket: uWebsockets.us_listen_socket) => void): Promise<uWebsockets.us_listen_socket>;
27
- }
28
- //# sourceMappingURL=hyperExpressApplication.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hyperExpressApplication.d.ts","sourceRoot":"","sources":["../../src/hyperExpressApplication.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gCAAgC,EAEjC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,KAAK,WAAW,MAAM,gBAAgB,CAAC;AAG9C;;;;GAIG;AACH,qBAAa,WAAW,CACtB,EAAE,SAAS,kBAAkB,CAC7B,SAAQ,gCAAgC,CAAC,EAAE,EAAE,MAAM,EAAE,iBAAiB,CAAC;IACvE;;;;OAIG;gBACS,eAAe,EAAE,EAAE;IAI/B;;;;;;OAMG;IACH,MAAM,CACJ,IAAI,EAAE,MAAM,EACZ,QAAQ,CAAC,EAAE,CAAC,aAAa,EAAE,WAAW,CAAC,gBAAgB,KAAK,IAAI,GAC/D,OAAO,CAAC,WAAW,CAAC,gBAAgB,CAAC;IACxC,MAAM,CACJ,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,MAAM,EACb,QAAQ,CAAC,EAAE,CAAC,aAAa,EAAE,WAAW,CAAC,gBAAgB,KAAK,IAAI,GAC/D,OAAO,CAAC,WAAW,CAAC,gBAAgB,CAAC;IACxC,MAAM,CACJ,SAAS,EAAE,MAAM,EACjB,QAAQ,CAAC,EAAE,CAAC,aAAa,EAAE,WAAW,CAAC,gBAAgB,KAAK,IAAI,GAC/D,OAAO,CAAC,WAAW,CAAC,gBAAgB,CAAC;CA0CzC"}
@@ -1,41 +0,0 @@
1
- import { ForklaunchExpressLikeApplication, generateSwaggerDocument } from '@forklaunch/core/http';
2
- import { Server } from 'hyper-express';
3
- import { swagger, swaggerRedirect } from './middleware/swagger.middleware';
4
- /**
5
- * Represents an application built on top of Hyper-Express and Forklaunch.
6
- *
7
- * @template SV - A type that extends AnySchemaValidator.
8
- */
9
- export class Application extends ForklaunchExpressLikeApplication {
10
- /**
11
- * Creates an instance of the Application class.
12
- *
13
- * @param {SV} schemaValidator - The schema validator.
14
- */
15
- constructor(schemaValidator) {
16
- super(schemaValidator, new Server());
17
- }
18
- listen(arg0, arg1, arg2) {
19
- if (typeof arg0 === 'number') {
20
- const port = arg0 || Number(process.env.PORT);
21
- this.internal.set_error_handler((_req, res, err) => {
22
- res.locals.errorMessage = err.message;
23
- // TODO: replace with logger
24
- console.error(err);
25
- res
26
- .status(res.statusCode && res.statusCode >= 400 ? res.statusCode : 500)
27
- .send(`Internal server error:\n\n${err.message}`);
28
- });
29
- const swaggerPath = `/api${process.env.VERSION ?? '/v1'}${process.env.SWAGGER_PATH ?? '/swagger'}`;
30
- this.internal.use(swaggerPath, swaggerRedirect(swaggerPath));
31
- this.internal.get(`${swaggerPath}/*`, swagger(swaggerPath, generateSwaggerDocument(this.schemaValidator, port, this.routers)));
32
- if (arg1 && typeof arg1 === 'string') {
33
- return this.internal.listen(port, arg1, arg2);
34
- }
35
- else if (arg1 && typeof arg1 === 'function') {
36
- return this.internal.listen(port, arg1);
37
- }
38
- }
39
- return this.internal.listen(arg0, arg1);
40
- }
41
- }
@@ -1,10 +0,0 @@
1
- import { ForklaunchExpressLikeRouter, ForklaunchRouter, TypedMiddlewareDefinition } from '@forklaunch/core/http';
2
- import { AnySchemaValidator } from '@forklaunch/validator';
3
- import { Router as ExpressRouter, MiddlewareHandler } from 'hyper-express';
4
- export declare class Router<SV extends AnySchemaValidator, BasePath extends `/${string}`> extends ForklaunchExpressLikeRouter<SV, BasePath, MiddlewareHandler, ExpressRouter> implements ForklaunchRouter<SV> {
5
- basePath: BasePath;
6
- constructor(basePath: BasePath, schemaValidator: SV);
7
- route(path: string): this;
8
- any: TypedMiddlewareDefinition<this, SV>;
9
- }
10
- //# sourceMappingURL=hyperExpressRouter.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hyperExpressRouter.d.ts","sourceRoot":"","sources":["../../src/hyperExpressRouter.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,2BAA2B,EAC3B,gBAAgB,EAMhB,yBAAyB,EAC1B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,MAAM,IAAI,aAAa,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAM3E,qBAAa,MAAM,CACf,EAAE,SAAS,kBAAkB,EAC7B,QAAQ,SAAS,IAAI,MAAM,EAAE,CAE/B,SAAQ,2BAA2B,CACjC,EAAE,EACF,QAAQ,EACR,iBAAiB,EACjB,aAAa,CAEf,YAAW,gBAAgB,CAAC,EAAE,CAAC;IAGtB,QAAQ,EAAE,QAAQ;gBAAlB,QAAQ,EAAE,QAAQ,EACzB,eAAe,EAAE,EAAE;IAWrB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAKzB,GAAG,EAAE,yBAAyB,CAAC,IAAI,EAAE,EAAE,CAAC,CAgEtC;CAKH"}
@@ -1,22 +0,0 @@
1
- import { ForklaunchExpressLikeRouter } from '@forklaunch/core/http';
2
- import { Router as ExpressRouter } from 'hyper-express';
3
- import { contentParse } from './middleware/contentParse.middleware';
4
- import { enrichResponseTransmission } from './middleware/enrichResponseTransmission.middleware';
5
- import { polyfillGetHeaders } from './middleware/polyfillGetHeaders.middleware';
6
- export class Router extends ForklaunchExpressLikeRouter {
7
- basePath;
8
- constructor(basePath, schemaValidator) {
9
- super(basePath, schemaValidator, new ExpressRouter());
10
- this.basePath = basePath;
11
- this.internal.use(polyfillGetHeaders);
12
- this.internal.use(contentParse);
13
- this.internal.use(enrichResponseTransmission);
14
- }
15
- route(path) {
16
- this.internal.route(path);
17
- return this;
18
- }
19
- any = (pathOrContractDetailsOrMiddlewareOrTypedHandler, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
20
- return this.registerMiddlewareHandler(this.internal.any, pathOrContractDetailsOrMiddlewareOrTypedHandler, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler);
21
- };
22
- }
@@ -1,8 +0,0 @@
1
- import { Request } from 'hyper-express';
2
- /**
3
- * Middleware function to parse the request body based on the content type.
4
- *
5
- * @returns {Function} - The middleware function.
6
- */
7
- export declare function contentParse(req: Request): Promise<void>;
8
- //# sourceMappingURL=contentParse.middleware.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"contentParse.middleware.d.ts","sourceRoot":"","sources":["../../../src/middleware/contentParse.middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC;;;;GAIG;AACH,wBAAsB,YAAY,CAAC,GAAG,EAAE,OAAO,iBAsB9C"}
@@ -1,26 +0,0 @@
1
- /**
2
- * Middleware function to parse the request body based on the content type.
3
- *
4
- * @returns {Function} - The middleware function.
5
- */
6
- export async function contentParse(req) {
7
- console.debug('[MIDDLEWARE] contentParse started');
8
- switch (req.headers['content-type'] &&
9
- req.headers['content-type'].split(';')[0]) {
10
- case 'application/json':
11
- req.body = await req.json();
12
- break;
13
- case 'application/x-www-form-urlencoded':
14
- req.body = await req.urlencoded();
15
- break;
16
- case 'text/plain':
17
- req.body = await req.text();
18
- break;
19
- case 'application/octet-stream':
20
- req.body = await req.buffer();
21
- break;
22
- default:
23
- req.body = await req.json();
24
- break;
25
- }
26
- }
@@ -1,14 +0,0 @@
1
- import { ForklaunchNextFunction, ParamsDictionary } from '@forklaunch/core/http';
2
- import { AnySchemaValidator } from '@forklaunch/validator';
3
- import { ParsedQs } from 'qs';
4
- import { Request, Response } from '../types/hyperExpress.types';
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 {MiddlewareNext} next - The next middleware function.
12
- */
13
- export declare function enrichResponseTransmission<SV extends AnySchemaValidator>(req: Request<SV, ParamsDictionary, Record<string, unknown>, ParsedQs, Record<string, string>, Record<string, unknown>>, res: Response<Record<number, unknown>, Record<string, string>, Record<string, unknown>>, next: ForklaunchNextFunction): void;
14
- //# sourceMappingURL=enrichResponseTransmission.middleware.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"enrichResponseTransmission.middleware.d.ts","sourceRoot":"","sources":["../../../src/middleware/enrichResponseTransmission.middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,sBAAsB,EACtB,gBAAgB,EACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAEhE;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CAAC,EAAE,SAAS,kBAAkB,EACtE,GAAG,EAAE,OAAO,CACV,EAAE,EACF,gBAAgB,EAChB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACvB,QAAQ,EACR,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACtB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CACxB,EACD,GAAG,EAAE,QAAQ,CACX,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACvB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACtB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CACxB,EACD,IAAI,EAAE,sBAAsB,QAsE7B"}
@@ -1,56 +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 {MiddlewareNext} next - The next middleware function.
9
- */
10
- export function enrichResponseTransmission(req, res, next) {
11
- console.debug('[MIDDLEWARE] enrichResponseTransmission');
12
- const originalSend = res.send;
13
- const originalJson = res.json;
14
- const originalSetHeader = res.setHeader;
15
- /**
16
- * Intercepts the JSON response to include additional processing.
17
- *
18
- * @param {unknown} data - The data to send in the response.
19
- * @returns {boolean} - The result of the original JSON method.
20
- */
21
- res.json = function (data) {
22
- res.bodyData = data;
23
- const result = originalJson.call(this, data);
24
- return result;
25
- };
26
- /**
27
- * Intercepts the send response to include additional processing and error handling.
28
- *
29
- * @param {unknown} data - The data to send in the response.
30
- * @returns {Response} - The result of the original send method.
31
- */
32
- res.send = function (data) {
33
- if (!res.bodyData) {
34
- res.bodyData = data;
35
- res.statusCode = res._status_code;
36
- }
37
- return enrichExpressLikeSend(this, req, res, originalSend, data, !res.cors && ((res._cork && !res._corked) || !res._cork));
38
- };
39
- /**
40
- * Intercepts the setHeader method to stringify the value before setting the header.
41
- *
42
- * @param {string}
43
- */
44
- res.setHeader = function (name, value) {
45
- let stringifiedValue;
46
- if (Array.isArray(value)) {
47
- stringifiedValue = value.map((v) => typeof v !== 'string' ? JSON.stringify(v) : v);
48
- }
49
- else {
50
- stringifiedValue =
51
- typeof value !== 'string' ? JSON.stringify(value) : value;
52
- }
53
- return originalSetHeader.call(this, name, stringifiedValue);
54
- };
55
- next();
56
- }
@@ -1,3 +0,0 @@
1
- import { MiddlewareNext, Request, Response } from 'hyper-express';
2
- export declare function polyfillGetHeaders(_req: Request, res: Response, next?: MiddlewareNext): void;
3
- //# sourceMappingURL=polyfillGetHeaders.middleware.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"polyfillGetHeaders.middleware.d.ts","sourceRoot":"","sources":["../../../src/middleware/polyfillGetHeaders.middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGlE,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,OAAO,EACb,GAAG,EAAE,QAAQ,EACb,IAAI,CAAC,EAAE,cAAc,QAOtB"}
@@ -1,8 +0,0 @@
1
- // TODO: Move into fork, and create gh issue
2
- export function polyfillGetHeaders(_req, res, next) {
3
- console.debug('[MIDDLEWARE] polyfillGetHeaders started');
4
- res.getHeaders = () => {
5
- return res._headers;
6
- };
7
- next?.();
8
- }
@@ -1,25 +0,0 @@
1
- import { MiddlewareHandler } from 'hyper-express';
2
- import { OpenAPIObject } from 'openapi3-ts/oas31';
3
- import swaggerUi from 'swagger-ui-express';
4
- /**
5
- * Middleware to redirect requests to the Swagger UI base path.
6
- *
7
- * @param {string} path - The base path for the Swagger UI.
8
- * @returns {MiddlewareHandler} - The middleware handler for redirecting requests.
9
- */
10
- export declare function swaggerRedirect(path: string): MiddlewareHandler;
11
- /**
12
- * Sets up the Swagger UI middleware for serving API documentation.
13
- *
14
- * @param {string} path - The base path for the Swagger UI.
15
- * @param {OpenAPIObject} document - The OpenAPI document to display.
16
- * @param {swaggerUi.SwaggerUiOptions} [opts] - Optional Swagger UI options.
17
- * @param {swaggerUi.SwaggerOptions} [options] - Optional Swagger options.
18
- * @param {string} [customCss] - Custom CSS to apply to the Swagger UI.
19
- * @param {string} [customfavIcon] - Custom favicon to use in the Swagger UI.
20
- * @param {string} [swaggerUrl] - Custom Swagger URL.
21
- * @param {string} [customSiteTitle] - Custom site title for the Swagger UI.
22
- * @returns {MiddlewareHandler[]} - An array of middleware handlers for serving the Swagger UI.
23
- */
24
- export declare function swagger(path: string, document: OpenAPIObject, opts?: swaggerUi.SwaggerUiOptions, options?: swaggerUi.SwaggerOptions, customCss?: string, customfavIcon?: string, swaggerUrl?: string, customSiteTitle?: string): MiddlewareHandler[];
25
- //# sourceMappingURL=swagger.middleware.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"swagger.middleware.d.ts","sourceRoot":"","sources":["../../../src/middleware/swagger.middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EAIlB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAE3C;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,iBAAiB,CAO/D;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,OAAO,CACrB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,aAAa,EACvB,IAAI,CAAC,EAAE,SAAS,CAAC,gBAAgB,EACjC,OAAO,CAAC,EAAE,SAAS,CAAC,cAAc,EAClC,SAAS,CAAC,EAAE,MAAM,EAClB,aAAa,CAAC,EAAE,MAAM,EACtB,UAAU,CAAC,EAAE,MAAM,EACnB,eAAe,CAAC,EAAE,MAAM,GACvB,iBAAiB,EAAE,CA2DrB"}