@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
@@ -0,0 +1,95 @@
1
+ import { AnySchemaValidator } from '@forklaunch/validator';
2
+ import { ForklaunchExpressLikeApplication, ForklaunchExpressLikeRouter, ForklaunchRouter, TypedMiddlewareDefinition, ParamsDictionary, ForklaunchRequest, ForklaunchResponse, ForklaunchStatusResponse, ForklaunchSendableData } from '@forklaunch/core/http';
3
+ import { Server, MiddlewareHandler, Router as Router$1, Request as Request$1, Response as Response$1 } from '@forklaunch/hyper-express-fork';
4
+ import * as uWebsockets from 'uWebSockets.js';
5
+ import { ParsedQs } from 'qs';
6
+
7
+ /**
8
+ * Represents an application built on top of Hyper-Express and Forklaunch.
9
+ *
10
+ * @template SV - A type that extends AnySchemaValidator.
11
+ */
12
+ declare class Application<SV extends AnySchemaValidator> extends ForklaunchExpressLikeApplication<SV, Server, MiddlewareHandler> {
13
+ /**
14
+ * Creates an instance of the Application class.
15
+ *
16
+ * @param {SV} schemaValidator - The schema validator.
17
+ */
18
+ constructor(schemaValidator: SV);
19
+ /**
20
+ * Starts the server and sets up Swagger documentation.
21
+ *
22
+ * @param {string | number} arg0 - The port number or UNIX path to listen on.
23
+ * @param {...unknown[]} args - Additional arguments.
24
+ * @returns {Promise<uWebsockets.us_listen_socket>} - A promise that resolves with the listening socket.
25
+ */
26
+ listen(port: number, callback?: (listen_socket: uWebsockets.us_listen_socket) => void): Promise<uWebsockets.us_listen_socket>;
27
+ listen(port: number, host?: string, callback?: (listen_socket: uWebsockets.us_listen_socket) => void): Promise<uWebsockets.us_listen_socket>;
28
+ listen(unix_path: string, callback?: (listen_socket: uWebsockets.us_listen_socket) => void): Promise<uWebsockets.us_listen_socket>;
29
+ }
30
+
31
+ declare class Router<SV extends AnySchemaValidator, BasePath extends `/${string}`> extends ForklaunchExpressLikeRouter<SV, BasePath, MiddlewareHandler, Router$1> implements ForklaunchRouter<SV> {
32
+ basePath: BasePath;
33
+ constructor(basePath: BasePath, schemaValidator: SV);
34
+ route(path: string): this;
35
+ any: TypedMiddlewareDefinition<this, SV>;
36
+ }
37
+
38
+ /**
39
+ * Extends the Forklaunch request interface with properties from Hyper-Express's request interface.
40
+ *
41
+ * @template SV - A type that extends AnySchemaValidator.
42
+ * @template P - A type for request parameters, defaulting to ParamsDictionary.
43
+ * @template _ResBody - A type for the response body, defaulting to unknown.
44
+ * @template ReqBody - A type for the request body, defaulting to unknown.
45
+ * @template ReqQuery - A type for the request query, defaulting to ParsedQs.
46
+ * @template LocalsObj - A type for local variables, defaulting to an empty object.
47
+ */
48
+ interface Request<SV extends AnySchemaValidator, P extends ParamsDictionary, 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<Request$1<LocalsObj>, 'method' | 'params' | 'query' | 'headers'> {
49
+ /** The request body */
50
+ body: ReqBody;
51
+ /** The request query parameters */
52
+ query: ReqQuery;
53
+ /** The request parameters */
54
+ params: P;
55
+ }
56
+ /**
57
+ * Extends the Forklaunch response interface with properties from Hyper-Express's response interface.
58
+ *
59
+ * @template ResBody - A type for the response body, defaulting to unknown.
60
+ * @template LocalsObj - A type for local variables, defaulting to an empty object.
61
+ * @template StatusCode - A type for the status code, defaulting to number.
62
+ */
63
+ interface Response<ResBodyMap extends Record<number, unknown>, ResHeaders extends Record<string, string>, LocalsObj extends Record<string, unknown>> extends ForklaunchResponse<ResBodyMap, ResHeaders, LocalsObj>, Omit<Response$1<LocalsObj>, 'getHeaders' | 'setHeader' | 'headersSent' | 'send' | 'status' | 'statusCode' | 'json' | 'jsonp' | 'end'>, ForklaunchStatusResponse<ForklaunchSendableData> {
64
+ /** The body data of the response */
65
+ bodyData: unknown;
66
+ /** If cors are applied to the response */
67
+ cors: boolean;
68
+ /** The status code of the response */
69
+ _status_code: number;
70
+ /** Whether the response is corked */
71
+ _cork: boolean;
72
+ /** Whether the response is currently corked */
73
+ _corked: boolean;
74
+ }
75
+
76
+ type App<SV extends AnySchemaValidator> = Application<SV>;
77
+ /**
78
+ * Creates a new instance of Application with the given schema validator.
79
+ *
80
+ * @template SV - A type that extends AnySchemaValidator.
81
+ * @param {SV} schemaValidator - The schema validator.
82
+ * @returns {Application<SV>} - The new application instance.
83
+ */
84
+ declare function forklaunchExpress<SV extends AnySchemaValidator>(schemaValidator: SV): Application<SV>;
85
+ /**
86
+ * Creates a new instance of Router with the given base path and schema validator.
87
+ *
88
+ * @template SV - A type that extends AnySchemaValidator.
89
+ * @param {string} basePath - The base path for the router.
90
+ * @param {SV} schemaValidator - The schema validator.
91
+ * @returns {Router<SV>} - The new router instance.
92
+ */
93
+ declare function forklaunchRouter<SV extends AnySchemaValidator, BasePath extends `/${string}`>(basePath: BasePath, schemaValidator: SV): Router<SV, BasePath>;
94
+
95
+ export { type App, Application, type Request, type Response, Router, forklaunchExpress, forklaunchRouter };
package/lib/index.d.ts CHANGED
@@ -1,7 +1,79 @@
1
1
  import { AnySchemaValidator } from '@forklaunch/validator';
2
- import { Application } from './src/hyperExpressApplication';
3
- import { Router } from './src/hyperExpressRouter';
4
- export type App<SV extends AnySchemaValidator> = Application<SV>;
2
+ import { ForklaunchExpressLikeApplication, ForklaunchExpressLikeRouter, ForklaunchRouter, TypedMiddlewareDefinition, ParamsDictionary, ForklaunchRequest, ForklaunchResponse, ForklaunchStatusResponse, ForklaunchSendableData } from '@forklaunch/core/http';
3
+ import { Server, MiddlewareHandler, Router as Router$1, Request as Request$1, Response as Response$1 } from '@forklaunch/hyper-express-fork';
4
+ import * as uWebsockets from 'uWebSockets.js';
5
+ import { ParsedQs } from 'qs';
6
+
7
+ /**
8
+ * Represents an application built on top of Hyper-Express and Forklaunch.
9
+ *
10
+ * @template SV - A type that extends AnySchemaValidator.
11
+ */
12
+ declare class Application<SV extends AnySchemaValidator> extends ForklaunchExpressLikeApplication<SV, Server, MiddlewareHandler> {
13
+ /**
14
+ * Creates an instance of the Application class.
15
+ *
16
+ * @param {SV} schemaValidator - The schema validator.
17
+ */
18
+ constructor(schemaValidator: SV);
19
+ /**
20
+ * Starts the server and sets up Swagger documentation.
21
+ *
22
+ * @param {string | number} arg0 - The port number or UNIX path to listen on.
23
+ * @param {...unknown[]} args - Additional arguments.
24
+ * @returns {Promise<uWebsockets.us_listen_socket>} - A promise that resolves with the listening socket.
25
+ */
26
+ listen(port: number, callback?: (listen_socket: uWebsockets.us_listen_socket) => void): Promise<uWebsockets.us_listen_socket>;
27
+ listen(port: number, host?: string, callback?: (listen_socket: uWebsockets.us_listen_socket) => void): Promise<uWebsockets.us_listen_socket>;
28
+ listen(unix_path: string, callback?: (listen_socket: uWebsockets.us_listen_socket) => void): Promise<uWebsockets.us_listen_socket>;
29
+ }
30
+
31
+ declare class Router<SV extends AnySchemaValidator, BasePath extends `/${string}`> extends ForklaunchExpressLikeRouter<SV, BasePath, MiddlewareHandler, Router$1> implements ForklaunchRouter<SV> {
32
+ basePath: BasePath;
33
+ constructor(basePath: BasePath, schemaValidator: SV);
34
+ route(path: string): this;
35
+ any: TypedMiddlewareDefinition<this, SV>;
36
+ }
37
+
38
+ /**
39
+ * Extends the Forklaunch request interface with properties from Hyper-Express's request interface.
40
+ *
41
+ * @template SV - A type that extends AnySchemaValidator.
42
+ * @template P - A type for request parameters, defaulting to ParamsDictionary.
43
+ * @template _ResBody - A type for the response body, defaulting to unknown.
44
+ * @template ReqBody - A type for the request body, defaulting to unknown.
45
+ * @template ReqQuery - A type for the request query, defaulting to ParsedQs.
46
+ * @template LocalsObj - A type for local variables, defaulting to an empty object.
47
+ */
48
+ interface Request<SV extends AnySchemaValidator, P extends ParamsDictionary, 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<Request$1<LocalsObj>, 'method' | 'params' | 'query' | 'headers'> {
49
+ /** The request body */
50
+ body: ReqBody;
51
+ /** The request query parameters */
52
+ query: ReqQuery;
53
+ /** The request parameters */
54
+ params: P;
55
+ }
56
+ /**
57
+ * Extends the Forklaunch response interface with properties from Hyper-Express's response interface.
58
+ *
59
+ * @template ResBody - A type for the response body, defaulting to unknown.
60
+ * @template LocalsObj - A type for local variables, defaulting to an empty object.
61
+ * @template StatusCode - A type for the status code, defaulting to number.
62
+ */
63
+ interface Response<ResBodyMap extends Record<number, unknown>, ResHeaders extends Record<string, string>, LocalsObj extends Record<string, unknown>> extends ForklaunchResponse<ResBodyMap, ResHeaders, LocalsObj>, Omit<Response$1<LocalsObj>, 'getHeaders' | 'setHeader' | 'headersSent' | 'send' | 'status' | 'statusCode' | 'json' | 'jsonp' | 'end'>, ForklaunchStatusResponse<ForklaunchSendableData> {
64
+ /** The body data of the response */
65
+ bodyData: unknown;
66
+ /** If cors are applied to the response */
67
+ cors: boolean;
68
+ /** The status code of the response */
69
+ _status_code: number;
70
+ /** Whether the response is corked */
71
+ _cork: boolean;
72
+ /** Whether the response is currently corked */
73
+ _corked: boolean;
74
+ }
75
+
76
+ type App<SV extends AnySchemaValidator> = Application<SV>;
5
77
  /**
6
78
  * Creates a new instance of Application with the given schema validator.
7
79
  *
@@ -9,7 +81,7 @@ export type App<SV extends AnySchemaValidator> = Application<SV>;
9
81
  * @param {SV} schemaValidator - The schema validator.
10
82
  * @returns {Application<SV>} - The new application instance.
11
83
  */
12
- export declare function forklaunchExpress<SV extends AnySchemaValidator>(schemaValidator: SV): Application<SV>;
84
+ declare function forklaunchExpress<SV extends AnySchemaValidator>(schemaValidator: SV): Application<SV>;
13
85
  /**
14
86
  * Creates a new instance of Router with the given base path and schema validator.
15
87
  *
@@ -18,8 +90,6 @@ export declare function forklaunchExpress<SV extends AnySchemaValidator>(schemaV
18
90
  * @param {SV} schemaValidator - The schema validator.
19
91
  * @returns {Router<SV>} - The new router instance.
20
92
  */
21
- export declare function forklaunchRouter<SV extends AnySchemaValidator, BasePath extends `/${string}`>(basePath: BasePath, schemaValidator: SV): Router<SV, BasePath>;
22
- export type { Application } from './src/hyperExpressApplication';
23
- export type { Router } from './src/hyperExpressRouter';
24
- export * from './src/types/hyperExpress.types';
25
- //# sourceMappingURL=index.d.ts.map
93
+ declare function forklaunchRouter<SV extends AnySchemaValidator, BasePath extends `/${string}`>(basePath: BasePath, schemaValidator: SV): Router<SV, BasePath>;
94
+
95
+ export { type App, Application, type Request, type Response, Router, forklaunchExpress, forklaunchRouter };
package/lib/index.js CHANGED
@@ -1,25 +1,259 @@
1
- import { Application } from './src/hyperExpressApplication';
2
- import { Router } from './src/hyperExpressRouter';
3
- /**
4
- * Creates a new instance of Application with the given schema validator.
5
- *
6
- * @template SV - A type that extends AnySchemaValidator.
7
- * @param {SV} schemaValidator - The schema validator.
8
- * @returns {Application<SV>} - The new application instance.
9
- */
10
- export function forklaunchExpress(schemaValidator) {
11
- return new Application(schemaValidator);
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ forklaunchExpress: () => forklaunchExpress,
34
+ forklaunchRouter: () => forklaunchRouter
35
+ });
36
+ module.exports = __toCommonJS(index_exports);
37
+
38
+ // src/hyperExpressApplication.ts
39
+ var import_http = require("@forklaunch/core/http");
40
+ var import_hyper_express_fork = require("@forklaunch/hyper-express-fork");
41
+
42
+ // src/middleware/swagger.middleware.ts
43
+ var import_live_directory = __toESM(require("live-directory"));
44
+ var import_absolute_path = __toESM(require("swagger-ui-dist/absolute-path"));
45
+ var import_swagger_ui_express = __toESM(require("swagger-ui-express"));
46
+ function swaggerRedirect(path) {
47
+ return (req, res, next) => {
48
+ if (req.path === path) {
49
+ res.redirect(`${path}/`);
50
+ }
51
+ return next?.();
52
+ };
12
53
  }
13
- /**
14
- * Creates a new instance of Router with the given base path and schema validator.
15
- *
16
- * @template SV - A type that extends AnySchemaValidator.
17
- * @param {string} basePath - The base path for the router.
18
- * @param {SV} schemaValidator - The schema validator.
19
- * @returns {Router<SV>} - The new router instance.
20
- */
21
- export function forklaunchRouter(basePath, schemaValidator) {
22
- const router = new Router(basePath, schemaValidator);
23
- return router;
54
+ function swagger(path, document, opts, options, customCss, customfavIcon, swaggerUrl, customSiteTitle) {
55
+ const LiveAssets = new import_live_directory.default((0, import_absolute_path.default)(), {
56
+ filter: {
57
+ keep: {
58
+ names: [
59
+ "swagger-ui-bundle.js",
60
+ "swagger-ui-standalone-preset.js",
61
+ "swagger-ui-init.js",
62
+ "swagger-ui.css",
63
+ "favicon-32x32.png",
64
+ "favicon-16x16.png"
65
+ ]
66
+ }
67
+ },
68
+ cache: {
69
+ max_file_count: 10,
70
+ max_file_size: 1024 * 1024 * 1.5
71
+ }
72
+ });
73
+ const serve = import_swagger_ui_express.default.serve[0];
74
+ const staticAssets = (req, res, next) => {
75
+ const filePath = req.path.replace(path, "");
76
+ const file = LiveAssets.get(filePath);
77
+ if (file === void 0) {
78
+ if (next) {
79
+ return next();
80
+ }
81
+ return res.status(404).send();
82
+ }
83
+ const fileParts = file.path.split(".");
84
+ const extension = fileParts[fileParts.length - 1];
85
+ const content = file.content;
86
+ return res.type(extension).send(content);
87
+ };
88
+ const ui = import_swagger_ui_express.default.setup(
89
+ document,
90
+ opts,
91
+ options,
92
+ customCss,
93
+ customfavIcon,
94
+ swaggerUrl,
95
+ customSiteTitle
96
+ );
97
+ return [serve, staticAssets, ui];
24
98
  }
25
- export * from './src/types/hyperExpress.types';
99
+
100
+ // src/hyperExpressApplication.ts
101
+ var Application = class extends import_http.ForklaunchExpressLikeApplication {
102
+ /**
103
+ * Creates an instance of the Application class.
104
+ *
105
+ * @param {SV} schemaValidator - The schema validator.
106
+ */
107
+ constructor(schemaValidator) {
108
+ super(schemaValidator, new import_hyper_express_fork.Server());
109
+ }
110
+ listen(arg0, arg1, arg2) {
111
+ if (typeof arg0 === "number") {
112
+ const port = arg0 || Number(process.env.PORT);
113
+ this.internal.set_error_handler((_req, res, err) => {
114
+ res.locals.errorMessage = err.message;
115
+ console.error(err);
116
+ res.status(
117
+ res.statusCode && res.statusCode >= 400 ? res.statusCode : 500
118
+ ).send(`Internal server error:
119
+
120
+ ${err.message}`);
121
+ });
122
+ const swaggerPath = `/api${process.env.VERSION ?? "/v1"}${process.env.SWAGGER_PATH ?? "/swagger"}`;
123
+ this.internal.use(swaggerPath, swaggerRedirect(swaggerPath));
124
+ this.internal.get(
125
+ `${swaggerPath}/*`,
126
+ swagger(
127
+ swaggerPath,
128
+ (0, import_http.generateSwaggerDocument)(this.schemaValidator, port, this.routers)
129
+ )
130
+ );
131
+ if (arg1 && typeof arg1 === "string") {
132
+ return this.internal.listen(port, arg1, arg2);
133
+ } else if (arg1 && typeof arg1 === "function") {
134
+ return this.internal.listen(port, arg1);
135
+ }
136
+ }
137
+ return this.internal.listen(
138
+ arg0,
139
+ arg1
140
+ );
141
+ }
142
+ };
143
+
144
+ // src/hyperExpressRouter.ts
145
+ var import_http3 = require("@forklaunch/core/http");
146
+ var import_hyper_express_fork2 = require("@forklaunch/hyper-express-fork");
147
+
148
+ // src/middleware/contentParse.middleware.ts
149
+ async function contentParse(req) {
150
+ console.debug("[MIDDLEWARE] contentParse started");
151
+ switch (req.headers["content-type"] && req.headers["content-type"].split(";")[0]) {
152
+ case "application/json":
153
+ req.body = await req.json();
154
+ break;
155
+ case "application/x-www-form-urlencoded":
156
+ req.body = await req.urlencoded();
157
+ break;
158
+ case "text/plain":
159
+ req.body = await req.text();
160
+ break;
161
+ case "application/octet-stream":
162
+ req.body = await req.buffer();
163
+ break;
164
+ default:
165
+ req.body = await req.json();
166
+ break;
167
+ }
168
+ }
169
+
170
+ // src/middleware/enrichResponseTransmission.middleware.ts
171
+ var import_http2 = require("@forklaunch/core/http");
172
+ function enrichResponseTransmission(req, res, next) {
173
+ console.debug("[MIDDLEWARE] enrichResponseTransmission");
174
+ const originalSend = res.send;
175
+ const originalJson = res.json;
176
+ const originalSetHeader = res.setHeader;
177
+ res.json = function(data) {
178
+ res.bodyData = data;
179
+ const result = originalJson.call(this, data);
180
+ return result;
181
+ };
182
+ res.send = function(data) {
183
+ if (!res.bodyData) {
184
+ res.bodyData = data;
185
+ res.statusCode = res._status_code;
186
+ }
187
+ return (0, import_http2.enrichExpressLikeSend)(
188
+ this,
189
+ req,
190
+ res,
191
+ originalSend,
192
+ data,
193
+ !res.cors && (res._cork && !res._corked || !res._cork)
194
+ );
195
+ };
196
+ res.setHeader = function(name, value) {
197
+ let stringifiedValue;
198
+ if (Array.isArray(value)) {
199
+ stringifiedValue = value.map(
200
+ (v) => typeof v !== "string" ? JSON.stringify(v) : v
201
+ );
202
+ } else {
203
+ stringifiedValue = typeof value !== "string" ? JSON.stringify(value) : value;
204
+ }
205
+ return originalSetHeader.call(this, name, stringifiedValue);
206
+ };
207
+ next();
208
+ }
209
+
210
+ // src/middleware/polyfillGetHeaders.middleware.ts
211
+ function polyfillGetHeaders(_req, res, next) {
212
+ console.debug("[MIDDLEWARE] polyfillGetHeaders started");
213
+ res.getHeaders = () => {
214
+ return res._headers;
215
+ };
216
+ next?.();
217
+ }
218
+
219
+ // src/hyperExpressRouter.ts
220
+ var Router = class extends import_http3.ForklaunchExpressLikeRouter {
221
+ constructor(basePath, schemaValidator) {
222
+ super(basePath, schemaValidator, new import_hyper_express_fork2.Router());
223
+ this.basePath = basePath;
224
+ this.internal.use(polyfillGetHeaders);
225
+ this.internal.use(contentParse);
226
+ this.internal.use(
227
+ enrichResponseTransmission
228
+ );
229
+ }
230
+ route(path) {
231
+ this.internal.route(path);
232
+ return this;
233
+ }
234
+ any = (pathOrContractDetailsOrMiddlewareOrTypedHandler, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
235
+ return this.registerMiddlewareHandler(
236
+ this.internal.any,
237
+ pathOrContractDetailsOrMiddlewareOrTypedHandler,
238
+ contractDetailsOrMiddlewareOrTypedHandler,
239
+ ...middlewareOrMiddlewareWithTypedHandler
240
+ );
241
+ };
242
+ // TODO: Implement the rest of the methods
243
+ // upgrade
244
+ // ws
245
+ };
246
+
247
+ // index.ts
248
+ function forklaunchExpress(schemaValidator) {
249
+ return new Application(schemaValidator);
250
+ }
251
+ function forklaunchRouter(basePath, schemaValidator) {
252
+ const router = new Router(basePath, schemaValidator);
253
+ return router;
254
+ }
255
+ // Annotate the CommonJS export names for ESM import in node:
256
+ 0 && (module.exports = {
257
+ forklaunchExpress,
258
+ forklaunchRouter
259
+ });