@forklaunch/hyper-express 0.1.33 → 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.
Files changed (60) hide show
  1. package/lib/hyperExpressApplication.d.mts +30 -0
  2. package/lib/{src/hyperExpressApplication.d.ts → hyperExpressApplication.d.ts} +5 -3
  3. package/lib/hyperExpressApplication.js +143 -0
  4. package/lib/hyperExpressApplication.mjs +111 -0
  5. package/lib/hyperExpressRouter.d.mts +12 -0
  6. package/lib/{src/hyperExpressRouter.d.ts → hyperExpressRouter.d.ts} +5 -3
  7. package/lib/hyperExpressRouter.js +130 -0
  8. package/lib/hyperExpressRouter.mjs +109 -0
  9. package/lib/middleware/contentParse.middleware.d.mts +10 -0
  10. package/lib/{src/middleware → middleware}/contentParse.middleware.d.ts +4 -2
  11. package/lib/middleware/contentParse.middleware.js +49 -0
  12. package/lib/middleware/contentParse.middleware.mjs +24 -0
  13. package/lib/middleware/enrichResponseTransmission.middleware.d.mts +17 -0
  14. package/lib/middleware/enrichResponseTransmission.middleware.d.ts +17 -0
  15. package/lib/middleware/enrichResponseTransmission.middleware.js +67 -0
  16. package/lib/middleware/enrichResponseTransmission.middleware.mjs +44 -0
  17. package/lib/middleware/polyfillGetHeaders.middleware.d.mts +5 -0
  18. package/lib/middleware/polyfillGetHeaders.middleware.d.ts +5 -0
  19. package/lib/middleware/polyfillGetHeaders.middleware.js +36 -0
  20. package/lib/middleware/polyfillGetHeaders.middleware.mjs +11 -0
  21. package/lib/middleware/swagger.middleware.d.mts +27 -0
  22. package/lib/{src/middleware → middleware}/swagger.middleware.d.ts +5 -3
  23. package/lib/middleware/swagger.middleware.js +97 -0
  24. package/lib/middleware/swagger.middleware.mjs +61 -0
  25. package/lib/types/hyperExpress.types.d.mts +44 -0
  26. package/lib/{src/types → types}/hyperExpress.types.d.ts +7 -5
  27. package/lib/types/hyperExpress.types.js +18 -0
  28. package/lib/types/hyperExpress.types.mjs +0 -0
  29. package/package.json +13 -10
  30. package/lib/config.d.ts +0 -2
  31. package/lib/config.d.ts.map +0 -1
  32. package/lib/config.js +0 -1
  33. package/lib/index.d.ts +0 -25
  34. package/lib/index.d.ts.map +0 -1
  35. package/lib/index.js +0 -25
  36. package/lib/src/hyperExpressApplication.d.ts.map +0 -1
  37. package/lib/src/hyperExpressApplication.js +0 -41
  38. package/lib/src/hyperExpressRouter.d.ts.map +0 -1
  39. package/lib/src/hyperExpressRouter.js +0 -22
  40. package/lib/src/middleware/contentParse.middleware.d.ts.map +0 -1
  41. package/lib/src/middleware/contentParse.middleware.js +0 -26
  42. package/lib/src/middleware/enrichResponseTransmission.middleware.d.ts +0 -14
  43. package/lib/src/middleware/enrichResponseTransmission.middleware.d.ts.map +0 -1
  44. package/lib/src/middleware/enrichResponseTransmission.middleware.js +0 -56
  45. package/lib/src/middleware/polyfillGetHeaders.middleware.d.ts +0 -3
  46. package/lib/src/middleware/polyfillGetHeaders.middleware.d.ts.map +0 -1
  47. package/lib/src/middleware/polyfillGetHeaders.middleware.js +0 -8
  48. package/lib/src/middleware/swagger.middleware.d.ts.map +0 -1
  49. package/lib/src/middleware/swagger.middleware.js +0 -75
  50. package/lib/src/types/hyperExpress.types.d.ts.map +0 -1
  51. package/lib/src/types/hyperExpress.types.js +0 -1
  52. package/lib/tests/typebox.forklaunch.hyperExpress.test.d.ts +0 -2
  53. package/lib/tests/typebox.forklaunch.hyperExpress.test.d.ts.map +0 -1
  54. package/lib/tests/typebox.forklaunch.hyperExpress.test.js +0 -111
  55. package/lib/tests/zod.forklaunch.hyperExpress.test.d.ts +0 -2
  56. package/lib/tests/zod.forklaunch.hyperExpress.test.d.ts.map +0 -1
  57. package/lib/tests/zod.forklaunch.hyperExpress.test.js +0 -109
  58. package/lib/vitest.config.d.ts +0 -3
  59. package/lib/vitest.config.d.ts.map +0 -1
  60. package/lib/vitest.config.js +0 -7
@@ -0,0 +1,30 @@
1
+ import { ForklaunchExpressLikeApplication } from '@forklaunch/core/http';
2
+ import { AnySchemaValidator } from '@forklaunch/validator';
3
+ import { Server, MiddlewareHandler } from 'hyper-express';
4
+ import * as uWebsockets from 'uWebSockets.js';
5
+
6
+ /**
7
+ * Represents an application built on top of Hyper-Express and Forklaunch.
8
+ *
9
+ * @template SV - A type that extends AnySchemaValidator.
10
+ */
11
+ declare class Application<SV extends AnySchemaValidator> extends ForklaunchExpressLikeApplication<SV, Server, MiddlewareHandler> {
12
+ /**
13
+ * Creates an instance of the Application class.
14
+ *
15
+ * @param {SV} schemaValidator - The schema validator.
16
+ */
17
+ constructor(schemaValidator: SV);
18
+ /**
19
+ * Starts the server and sets up Swagger documentation.
20
+ *
21
+ * @param {string | number} arg0 - The port number or UNIX path to listen on.
22
+ * @param {...unknown[]} args - Additional arguments.
23
+ * @returns {Promise<uWebsockets.us_listen_socket>} - A promise that resolves with the listening socket.
24
+ */
25
+ listen(port: number, callback?: (listen_socket: uWebsockets.us_listen_socket) => void): Promise<uWebsockets.us_listen_socket>;
26
+ listen(port: number, host?: string, callback?: (listen_socket: uWebsockets.us_listen_socket) => void): Promise<uWebsockets.us_listen_socket>;
27
+ listen(unix_path: string, callback?: (listen_socket: uWebsockets.us_listen_socket) => void): Promise<uWebsockets.us_listen_socket>;
28
+ }
29
+
30
+ export { Application };
@@ -1,13 +1,14 @@
1
1
  import { ForklaunchExpressLikeApplication } from '@forklaunch/core/http';
2
2
  import { AnySchemaValidator } from '@forklaunch/validator';
3
- import { MiddlewareHandler, Server } from 'hyper-express';
3
+ import { Server, MiddlewareHandler } from 'hyper-express';
4
4
  import * as uWebsockets from 'uWebSockets.js';
5
+
5
6
  /**
6
7
  * Represents an application built on top of Hyper-Express and Forklaunch.
7
8
  *
8
9
  * @template SV - A type that extends AnySchemaValidator.
9
10
  */
10
- export declare class Application<SV extends AnySchemaValidator> extends ForklaunchExpressLikeApplication<SV, Server, MiddlewareHandler> {
11
+ declare class Application<SV extends AnySchemaValidator> extends ForklaunchExpressLikeApplication<SV, Server, MiddlewareHandler> {
11
12
  /**
12
13
  * Creates an instance of the Application class.
13
14
  *
@@ -25,4 +26,5 @@ export declare class Application<SV extends AnySchemaValidator> extends Forklaun
25
26
  listen(port: number, host?: string, callback?: (listen_socket: uWebsockets.us_listen_socket) => void): Promise<uWebsockets.us_listen_socket>;
26
27
  listen(unix_path: string, callback?: (listen_socket: uWebsockets.us_listen_socket) => void): Promise<uWebsockets.us_listen_socket>;
27
28
  }
28
- //# sourceMappingURL=hyperExpressApplication.d.ts.map
29
+
30
+ export { Application };
@@ -0,0 +1,143 @@
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
+ // src/hyperExpressApplication.ts
31
+ var hyperExpressApplication_exports = {};
32
+ __export(hyperExpressApplication_exports, {
33
+ Application: () => Application
34
+ });
35
+ module.exports = __toCommonJS(hyperExpressApplication_exports);
36
+ var import_http = require("@forklaunch/core/http");
37
+ var import_hyper_express = require("hyper-express");
38
+
39
+ // src/middleware/swagger.middleware.ts
40
+ var import_live_directory = __toESM(require("live-directory"));
41
+ var import_absolute_path = __toESM(require("swagger-ui-dist/absolute-path"));
42
+ var import_swagger_ui_express = __toESM(require("swagger-ui-express"));
43
+ function swaggerRedirect(path) {
44
+ return (req, res, next) => {
45
+ if (req.path === path) {
46
+ res.redirect(`${path}/`);
47
+ }
48
+ return next?.();
49
+ };
50
+ }
51
+ function swagger(path, document, opts, options, customCss, customfavIcon, swaggerUrl, customSiteTitle) {
52
+ const LiveAssets = new import_live_directory.default((0, import_absolute_path.default)(), {
53
+ filter: {
54
+ keep: {
55
+ names: [
56
+ "swagger-ui-bundle.js",
57
+ "swagger-ui-standalone-preset.js",
58
+ "swagger-ui-init.js",
59
+ "swagger-ui.css",
60
+ "favicon-32x32.png",
61
+ "favicon-16x16.png"
62
+ ]
63
+ }
64
+ },
65
+ cache: {
66
+ max_file_count: 10,
67
+ max_file_size: 1024 * 1024 * 1.5
68
+ }
69
+ });
70
+ const serve = import_swagger_ui_express.default.serve[0];
71
+ const staticAssets = (req, res, next) => {
72
+ const filePath = req.path.replace(path, "");
73
+ const file = LiveAssets.get(filePath);
74
+ if (file === void 0) {
75
+ if (next) {
76
+ return next();
77
+ }
78
+ return res.status(404).send();
79
+ }
80
+ const fileParts = file.path.split(".");
81
+ const extension = fileParts[fileParts.length - 1];
82
+ const content = file.content;
83
+ return res.type(extension).send(content);
84
+ };
85
+ const ui = import_swagger_ui_express.default.setup(
86
+ document,
87
+ opts,
88
+ options,
89
+ customCss,
90
+ customfavIcon,
91
+ swaggerUrl,
92
+ customSiteTitle
93
+ );
94
+ return [serve, staticAssets, ui];
95
+ }
96
+
97
+ // src/hyperExpressApplication.ts
98
+ var Application = class extends import_http.ForklaunchExpressLikeApplication {
99
+ /**
100
+ * Creates an instance of the Application class.
101
+ *
102
+ * @param {SV} schemaValidator - The schema validator.
103
+ */
104
+ constructor(schemaValidator) {
105
+ super(schemaValidator, new import_hyper_express.Server());
106
+ }
107
+ listen(arg0, arg1, arg2) {
108
+ if (typeof arg0 === "number") {
109
+ const port = arg0 || Number(process.env.PORT);
110
+ this.internal.set_error_handler((_req, res, err) => {
111
+ res.locals.errorMessage = err.message;
112
+ console.error(err);
113
+ res.status(
114
+ res.statusCode && res.statusCode >= 400 ? res.statusCode : 500
115
+ ).send(`Internal server error:
116
+
117
+ ${err.message}`);
118
+ });
119
+ const swaggerPath = `/api${process.env.VERSION ?? "/v1"}${process.env.SWAGGER_PATH ?? "/swagger"}`;
120
+ this.internal.use(swaggerPath, swaggerRedirect(swaggerPath));
121
+ this.internal.get(
122
+ `${swaggerPath}/*`,
123
+ swagger(
124
+ swaggerPath,
125
+ (0, import_http.generateSwaggerDocument)(this.schemaValidator, port, this.routers)
126
+ )
127
+ );
128
+ if (arg1 && typeof arg1 === "string") {
129
+ return this.internal.listen(port, arg1, arg2);
130
+ } else if (arg1 && typeof arg1 === "function") {
131
+ return this.internal.listen(port, arg1);
132
+ }
133
+ }
134
+ return this.internal.listen(
135
+ arg0,
136
+ arg1
137
+ );
138
+ }
139
+ };
140
+ // Annotate the CommonJS export names for ESM import in node:
141
+ 0 && (module.exports = {
142
+ Application
143
+ });
@@ -0,0 +1,111 @@
1
+ // src/hyperExpressApplication.ts
2
+ import {
3
+ ForklaunchExpressLikeApplication,
4
+ generateSwaggerDocument
5
+ } from "@forklaunch/core/http";
6
+ import { Server } from "hyper-express";
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
+ export {
110
+ Application
111
+ };
@@ -0,0 +1,12 @@
1
+ import { ForklaunchExpressLikeRouter, ForklaunchRouter, TypedMiddlewareDefinition } from '@forklaunch/core/http';
2
+ import { AnySchemaValidator } from '@forklaunch/validator';
3
+ import { MiddlewareHandler, Router as Router$1 } from 'hyper-express';
4
+
5
+ declare class Router<SV extends AnySchemaValidator, BasePath extends `/${string}`> extends ForklaunchExpressLikeRouter<SV, BasePath, MiddlewareHandler, Router$1> implements ForklaunchRouter<SV> {
6
+ basePath: BasePath;
7
+ constructor(basePath: BasePath, schemaValidator: SV);
8
+ route(path: string): this;
9
+ any: TypedMiddlewareDefinition<this, SV>;
10
+ }
11
+
12
+ export { Router };
@@ -1,10 +1,12 @@
1
1
  import { ForklaunchExpressLikeRouter, ForklaunchRouter, TypedMiddlewareDefinition } from '@forklaunch/core/http';
2
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> {
3
+ import { MiddlewareHandler, Router as Router$1 } from 'hyper-express';
4
+
5
+ declare class Router<SV extends AnySchemaValidator, BasePath extends `/${string}`> extends ForklaunchExpressLikeRouter<SV, BasePath, MiddlewareHandler, Router$1> implements ForklaunchRouter<SV> {
5
6
  basePath: BasePath;
6
7
  constructor(basePath: BasePath, schemaValidator: SV);
7
8
  route(path: string): this;
8
9
  any: TypedMiddlewareDefinition<this, SV>;
9
10
  }
10
- //# sourceMappingURL=hyperExpressRouter.d.ts.map
11
+
12
+ export { Router };
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/hyperExpressRouter.ts
21
+ var hyperExpressRouter_exports = {};
22
+ __export(hyperExpressRouter_exports, {
23
+ Router: () => Router
24
+ });
25
+ module.exports = __toCommonJS(hyperExpressRouter_exports);
26
+ var import_http2 = require("@forklaunch/core/http");
27
+ var import_hyper_express = require("hyper-express");
28
+
29
+ // src/middleware/contentParse.middleware.ts
30
+ async function contentParse(req) {
31
+ console.debug("[MIDDLEWARE] contentParse started");
32
+ switch (req.headers["content-type"] && req.headers["content-type"].split(";")[0]) {
33
+ case "application/json":
34
+ req.body = await req.json();
35
+ break;
36
+ case "application/x-www-form-urlencoded":
37
+ req.body = await req.urlencoded();
38
+ break;
39
+ case "text/plain":
40
+ req.body = await req.text();
41
+ break;
42
+ case "application/octet-stream":
43
+ req.body = await req.buffer();
44
+ break;
45
+ default:
46
+ req.body = await req.json();
47
+ break;
48
+ }
49
+ }
50
+
51
+ // src/middleware/enrichResponseTransmission.middleware.ts
52
+ var import_http = require("@forklaunch/core/http");
53
+ function enrichResponseTransmission(req, res, next) {
54
+ console.debug("[MIDDLEWARE] enrichResponseTransmission");
55
+ const originalSend = res.send;
56
+ const originalJson = res.json;
57
+ const originalSetHeader = res.setHeader;
58
+ res.json = function(data) {
59
+ res.bodyData = data;
60
+ const result = originalJson.call(this, data);
61
+ return result;
62
+ };
63
+ res.send = function(data) {
64
+ if (!res.bodyData) {
65
+ res.bodyData = data;
66
+ res.statusCode = res._status_code;
67
+ }
68
+ return (0, import_http.enrichExpressLikeSend)(
69
+ this,
70
+ req,
71
+ res,
72
+ originalSend,
73
+ data,
74
+ !res.cors && (res._cork && !res._corked || !res._cork)
75
+ );
76
+ };
77
+ res.setHeader = function(name, value) {
78
+ let stringifiedValue;
79
+ if (Array.isArray(value)) {
80
+ stringifiedValue = value.map(
81
+ (v) => typeof v !== "string" ? JSON.stringify(v) : v
82
+ );
83
+ } else {
84
+ stringifiedValue = typeof value !== "string" ? JSON.stringify(value) : value;
85
+ }
86
+ return originalSetHeader.call(this, name, stringifiedValue);
87
+ };
88
+ next();
89
+ }
90
+
91
+ // src/middleware/polyfillGetHeaders.middleware.ts
92
+ function polyfillGetHeaders(_req, res, next) {
93
+ console.debug("[MIDDLEWARE] polyfillGetHeaders started");
94
+ res.getHeaders = () => {
95
+ return res._headers;
96
+ };
97
+ next?.();
98
+ }
99
+
100
+ // src/hyperExpressRouter.ts
101
+ var Router = class extends import_http2.ForklaunchExpressLikeRouter {
102
+ constructor(basePath, schemaValidator) {
103
+ super(basePath, schemaValidator, new import_hyper_express.Router());
104
+ this.basePath = basePath;
105
+ this.internal.use(polyfillGetHeaders);
106
+ this.internal.use(contentParse);
107
+ this.internal.use(
108
+ enrichResponseTransmission
109
+ );
110
+ }
111
+ route(path) {
112
+ this.internal.route(path);
113
+ return this;
114
+ }
115
+ any = (pathOrContractDetailsOrMiddlewareOrTypedHandler, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
116
+ return this.registerMiddlewareHandler(
117
+ this.internal.any,
118
+ pathOrContractDetailsOrMiddlewareOrTypedHandler,
119
+ contractDetailsOrMiddlewareOrTypedHandler,
120
+ ...middlewareOrMiddlewareWithTypedHandler
121
+ );
122
+ };
123
+ // TODO: Implement the rest of the methods
124
+ // upgrade
125
+ // ws
126
+ };
127
+ // Annotate the CommonJS export names for ESM import in node:
128
+ 0 && (module.exports = {
129
+ Router
130
+ });
@@ -0,0 +1,109 @@
1
+ // src/hyperExpressRouter.ts
2
+ import {
3
+ ForklaunchExpressLikeRouter
4
+ } from "@forklaunch/core/http";
5
+ import { Router as ExpressRouter } from "hyper-express";
6
+
7
+ // src/middleware/contentParse.middleware.ts
8
+ async function contentParse(req) {
9
+ console.debug("[MIDDLEWARE] contentParse started");
10
+ switch (req.headers["content-type"] && req.headers["content-type"].split(";")[0]) {
11
+ case "application/json":
12
+ req.body = await req.json();
13
+ break;
14
+ case "application/x-www-form-urlencoded":
15
+ req.body = await req.urlencoded();
16
+ break;
17
+ case "text/plain":
18
+ req.body = await req.text();
19
+ break;
20
+ case "application/octet-stream":
21
+ req.body = await req.buffer();
22
+ break;
23
+ default:
24
+ req.body = await req.json();
25
+ break;
26
+ }
27
+ }
28
+
29
+ // src/middleware/enrichResponseTransmission.middleware.ts
30
+ import {
31
+ enrichExpressLikeSend
32
+ } from "@forklaunch/core/http";
33
+ function enrichResponseTransmission(req, res, next) {
34
+ console.debug("[MIDDLEWARE] enrichResponseTransmission");
35
+ const originalSend = res.send;
36
+ const originalJson = res.json;
37
+ const originalSetHeader = res.setHeader;
38
+ res.json = function(data) {
39
+ res.bodyData = data;
40
+ const result = originalJson.call(this, data);
41
+ return result;
42
+ };
43
+ res.send = function(data) {
44
+ if (!res.bodyData) {
45
+ res.bodyData = data;
46
+ res.statusCode = res._status_code;
47
+ }
48
+ return enrichExpressLikeSend(
49
+ this,
50
+ req,
51
+ res,
52
+ originalSend,
53
+ data,
54
+ !res.cors && (res._cork && !res._corked || !res._cork)
55
+ );
56
+ };
57
+ res.setHeader = function(name, value) {
58
+ let stringifiedValue;
59
+ if (Array.isArray(value)) {
60
+ stringifiedValue = value.map(
61
+ (v) => typeof v !== "string" ? JSON.stringify(v) : v
62
+ );
63
+ } else {
64
+ stringifiedValue = typeof value !== "string" ? JSON.stringify(value) : value;
65
+ }
66
+ return originalSetHeader.call(this, name, stringifiedValue);
67
+ };
68
+ next();
69
+ }
70
+
71
+ // src/middleware/polyfillGetHeaders.middleware.ts
72
+ function polyfillGetHeaders(_req, res, next) {
73
+ console.debug("[MIDDLEWARE] polyfillGetHeaders started");
74
+ res.getHeaders = () => {
75
+ return res._headers;
76
+ };
77
+ next?.();
78
+ }
79
+
80
+ // src/hyperExpressRouter.ts
81
+ var Router = class extends ForklaunchExpressLikeRouter {
82
+ constructor(basePath, schemaValidator) {
83
+ super(basePath, schemaValidator, new ExpressRouter());
84
+ this.basePath = basePath;
85
+ this.internal.use(polyfillGetHeaders);
86
+ this.internal.use(contentParse);
87
+ this.internal.use(
88
+ enrichResponseTransmission
89
+ );
90
+ }
91
+ route(path) {
92
+ this.internal.route(path);
93
+ return this;
94
+ }
95
+ any = (pathOrContractDetailsOrMiddlewareOrTypedHandler, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
96
+ return this.registerMiddlewareHandler(
97
+ this.internal.any,
98
+ pathOrContractDetailsOrMiddlewareOrTypedHandler,
99
+ contractDetailsOrMiddlewareOrTypedHandler,
100
+ ...middlewareOrMiddlewareWithTypedHandler
101
+ );
102
+ };
103
+ // TODO: Implement the rest of the methods
104
+ // upgrade
105
+ // ws
106
+ };
107
+ export {
108
+ Router
109
+ };
@@ -0,0 +1,10 @@
1
+ import { Request } from 'hyper-express';
2
+
3
+ /**
4
+ * Middleware function to parse the request body based on the content type.
5
+ *
6
+ * @returns {Function} - The middleware function.
7
+ */
8
+ declare function contentParse(req: Request): Promise<void>;
9
+
10
+ export { contentParse };
@@ -1,8 +1,10 @@
1
1
  import { Request } from 'hyper-express';
2
+
2
3
  /**
3
4
  * Middleware function to parse the request body based on the content type.
4
5
  *
5
6
  * @returns {Function} - The middleware function.
6
7
  */
7
- export declare function contentParse(req: Request): Promise<void>;
8
- //# sourceMappingURL=contentParse.middleware.d.ts.map
8
+ declare function contentParse(req: Request): Promise<void>;
9
+
10
+ export { contentParse };
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/middleware/contentParse.middleware.ts
21
+ var contentParse_middleware_exports = {};
22
+ __export(contentParse_middleware_exports, {
23
+ contentParse: () => contentParse
24
+ });
25
+ module.exports = __toCommonJS(contentParse_middleware_exports);
26
+ async function contentParse(req) {
27
+ console.debug("[MIDDLEWARE] contentParse started");
28
+ switch (req.headers["content-type"] && req.headers["content-type"].split(";")[0]) {
29
+ case "application/json":
30
+ req.body = await req.json();
31
+ break;
32
+ case "application/x-www-form-urlencoded":
33
+ req.body = await req.urlencoded();
34
+ break;
35
+ case "text/plain":
36
+ req.body = await req.text();
37
+ break;
38
+ case "application/octet-stream":
39
+ req.body = await req.buffer();
40
+ break;
41
+ default:
42
+ req.body = await req.json();
43
+ break;
44
+ }
45
+ }
46
+ // Annotate the CommonJS export names for ESM import in node:
47
+ 0 && (module.exports = {
48
+ contentParse
49
+ });
@@ -0,0 +1,24 @@
1
+ // src/middleware/contentParse.middleware.ts
2
+ async function contentParse(req) {
3
+ console.debug("[MIDDLEWARE] contentParse started");
4
+ switch (req.headers["content-type"] && req.headers["content-type"].split(";")[0]) {
5
+ case "application/json":
6
+ req.body = await req.json();
7
+ break;
8
+ case "application/x-www-form-urlencoded":
9
+ req.body = await req.urlencoded();
10
+ break;
11
+ case "text/plain":
12
+ req.body = await req.text();
13
+ break;
14
+ case "application/octet-stream":
15
+ req.body = await req.buffer();
16
+ break;
17
+ default:
18
+ req.body = await req.json();
19
+ break;
20
+ }
21
+ }
22
+ export {
23
+ contentParse
24
+ };