@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,17 @@
1
+ import { ParamsDictionary, ForklaunchNextFunction } from '@forklaunch/core/http';
2
+ import { AnySchemaValidator } from '@forklaunch/validator';
3
+ import { ParsedQs } from 'qs';
4
+ import { Request, Response } from '../types/hyperExpress.types.mjs';
5
+ import 'hyper-express';
6
+
7
+ /**
8
+ * Middleware to enrich the response transmission by intercepting and parsing responses before they are sent.
9
+ *
10
+ * @template SV - A type that extends AnySchemaValidator.
11
+ * @param {Request<SV>} req - The request object.
12
+ * @param {Response} res - The response object.
13
+ * @param {MiddlewareNext} next - The next middleware function.
14
+ */
15
+ 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;
16
+
17
+ export { enrichResponseTransmission };
@@ -0,0 +1,17 @@
1
+ import { ParamsDictionary, ForklaunchNextFunction } from '@forklaunch/core/http';
2
+ import { AnySchemaValidator } from '@forklaunch/validator';
3
+ import { ParsedQs } from 'qs';
4
+ import { Request, Response } from '../types/hyperExpress.types.js';
5
+ import 'hyper-express';
6
+
7
+ /**
8
+ * Middleware to enrich the response transmission by intercepting and parsing responses before they are sent.
9
+ *
10
+ * @template SV - A type that extends AnySchemaValidator.
11
+ * @param {Request<SV>} req - The request object.
12
+ * @param {Response} res - The response object.
13
+ * @param {MiddlewareNext} next - The next middleware function.
14
+ */
15
+ 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;
16
+
17
+ export { enrichResponseTransmission };
@@ -0,0 +1,67 @@
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/enrichResponseTransmission.middleware.ts
21
+ var enrichResponseTransmission_middleware_exports = {};
22
+ __export(enrichResponseTransmission_middleware_exports, {
23
+ enrichResponseTransmission: () => enrichResponseTransmission
24
+ });
25
+ module.exports = __toCommonJS(enrichResponseTransmission_middleware_exports);
26
+ var import_http = require("@forklaunch/core/http");
27
+ function enrichResponseTransmission(req, res, next) {
28
+ console.debug("[MIDDLEWARE] enrichResponseTransmission");
29
+ const originalSend = res.send;
30
+ const originalJson = res.json;
31
+ const originalSetHeader = res.setHeader;
32
+ res.json = function(data) {
33
+ res.bodyData = data;
34
+ const result = originalJson.call(this, data);
35
+ return result;
36
+ };
37
+ res.send = function(data) {
38
+ if (!res.bodyData) {
39
+ res.bodyData = data;
40
+ res.statusCode = res._status_code;
41
+ }
42
+ return (0, import_http.enrichExpressLikeSend)(
43
+ this,
44
+ req,
45
+ res,
46
+ originalSend,
47
+ data,
48
+ !res.cors && (res._cork && !res._corked || !res._cork)
49
+ );
50
+ };
51
+ res.setHeader = function(name, value) {
52
+ let stringifiedValue;
53
+ if (Array.isArray(value)) {
54
+ stringifiedValue = value.map(
55
+ (v) => typeof v !== "string" ? JSON.stringify(v) : v
56
+ );
57
+ } else {
58
+ stringifiedValue = typeof value !== "string" ? JSON.stringify(value) : value;
59
+ }
60
+ return originalSetHeader.call(this, name, stringifiedValue);
61
+ };
62
+ next();
63
+ }
64
+ // Annotate the CommonJS export names for ESM import in node:
65
+ 0 && (module.exports = {
66
+ enrichResponseTransmission
67
+ });
@@ -0,0 +1,44 @@
1
+ // src/middleware/enrichResponseTransmission.middleware.ts
2
+ import {
3
+ enrichExpressLikeSend
4
+ } from "@forklaunch/core/http";
5
+ function enrichResponseTransmission(req, res, next) {
6
+ console.debug("[MIDDLEWARE] enrichResponseTransmission");
7
+ const originalSend = res.send;
8
+ const originalJson = res.json;
9
+ const originalSetHeader = res.setHeader;
10
+ res.json = function(data) {
11
+ res.bodyData = data;
12
+ const result = originalJson.call(this, data);
13
+ return result;
14
+ };
15
+ res.send = function(data) {
16
+ if (!res.bodyData) {
17
+ res.bodyData = data;
18
+ res.statusCode = res._status_code;
19
+ }
20
+ return enrichExpressLikeSend(
21
+ this,
22
+ req,
23
+ res,
24
+ originalSend,
25
+ data,
26
+ !res.cors && (res._cork && !res._corked || !res._cork)
27
+ );
28
+ };
29
+ res.setHeader = function(name, value) {
30
+ let stringifiedValue;
31
+ if (Array.isArray(value)) {
32
+ stringifiedValue = value.map(
33
+ (v) => typeof v !== "string" ? JSON.stringify(v) : v
34
+ );
35
+ } else {
36
+ stringifiedValue = typeof value !== "string" ? JSON.stringify(value) : value;
37
+ }
38
+ return originalSetHeader.call(this, name, stringifiedValue);
39
+ };
40
+ next();
41
+ }
42
+ export {
43
+ enrichResponseTransmission
44
+ };
@@ -0,0 +1,5 @@
1
+ import { Request, Response, MiddlewareNext } from 'hyper-express';
2
+
3
+ declare function polyfillGetHeaders(_req: Request, res: Response, next?: MiddlewareNext): void;
4
+
5
+ export { polyfillGetHeaders };
@@ -0,0 +1,5 @@
1
+ import { Request, Response, MiddlewareNext } from 'hyper-express';
2
+
3
+ declare function polyfillGetHeaders(_req: Request, res: Response, next?: MiddlewareNext): void;
4
+
5
+ export { polyfillGetHeaders };
@@ -0,0 +1,36 @@
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/polyfillGetHeaders.middleware.ts
21
+ var polyfillGetHeaders_middleware_exports = {};
22
+ __export(polyfillGetHeaders_middleware_exports, {
23
+ polyfillGetHeaders: () => polyfillGetHeaders
24
+ });
25
+ module.exports = __toCommonJS(polyfillGetHeaders_middleware_exports);
26
+ function polyfillGetHeaders(_req, res, next) {
27
+ console.debug("[MIDDLEWARE] polyfillGetHeaders started");
28
+ res.getHeaders = () => {
29
+ return res._headers;
30
+ };
31
+ next?.();
32
+ }
33
+ // Annotate the CommonJS export names for ESM import in node:
34
+ 0 && (module.exports = {
35
+ polyfillGetHeaders
36
+ });
@@ -0,0 +1,11 @@
1
+ // src/middleware/polyfillGetHeaders.middleware.ts
2
+ function polyfillGetHeaders(_req, res, next) {
3
+ console.debug("[MIDDLEWARE] polyfillGetHeaders started");
4
+ res.getHeaders = () => {
5
+ return res._headers;
6
+ };
7
+ next?.();
8
+ }
9
+ export {
10
+ polyfillGetHeaders
11
+ };
@@ -0,0 +1,27 @@
1
+ import { MiddlewareHandler } from 'hyper-express';
2
+ import { OpenAPIObject } from 'openapi3-ts/oas31';
3
+ import swaggerUi from 'swagger-ui-express';
4
+
5
+ /**
6
+ * Middleware to redirect requests to the Swagger UI base path.
7
+ *
8
+ * @param {string} path - The base path for the Swagger UI.
9
+ * @returns {MiddlewareHandler} - The middleware handler for redirecting requests.
10
+ */
11
+ declare function swaggerRedirect(path: string): MiddlewareHandler;
12
+ /**
13
+ * Sets up the Swagger UI middleware for serving API documentation.
14
+ *
15
+ * @param {string} path - The base path for the Swagger UI.
16
+ * @param {OpenAPIObject} document - The OpenAPI document to display.
17
+ * @param {swaggerUi.SwaggerUiOptions} [opts] - Optional Swagger UI options.
18
+ * @param {swaggerUi.SwaggerOptions} [options] - Optional Swagger options.
19
+ * @param {string} [customCss] - Custom CSS to apply to the Swagger UI.
20
+ * @param {string} [customfavIcon] - Custom favicon to use in the Swagger UI.
21
+ * @param {string} [swaggerUrl] - Custom Swagger URL.
22
+ * @param {string} [customSiteTitle] - Custom site title for the Swagger UI.
23
+ * @returns {MiddlewareHandler[]} - An array of middleware handlers for serving the Swagger UI.
24
+ */
25
+ declare function swagger(path: string, document: OpenAPIObject, opts?: swaggerUi.SwaggerUiOptions, options?: swaggerUi.SwaggerOptions, customCss?: string, customfavIcon?: string, swaggerUrl?: string, customSiteTitle?: string): MiddlewareHandler[];
26
+
27
+ export { swagger, swaggerRedirect };
@@ -1,13 +1,14 @@
1
1
  import { MiddlewareHandler } from 'hyper-express';
2
2
  import { OpenAPIObject } from 'openapi3-ts/oas31';
3
3
  import swaggerUi from 'swagger-ui-express';
4
+
4
5
  /**
5
6
  * Middleware to redirect requests to the Swagger UI base path.
6
7
  *
7
8
  * @param {string} path - The base path for the Swagger UI.
8
9
  * @returns {MiddlewareHandler} - The middleware handler for redirecting requests.
9
10
  */
10
- export declare function swaggerRedirect(path: string): MiddlewareHandler;
11
+ declare function swaggerRedirect(path: string): MiddlewareHandler;
11
12
  /**
12
13
  * Sets up the Swagger UI middleware for serving API documentation.
13
14
  *
@@ -21,5 +22,6 @@ export declare function swaggerRedirect(path: string): MiddlewareHandler;
21
22
  * @param {string} [customSiteTitle] - Custom site title for the Swagger UI.
22
23
  * @returns {MiddlewareHandler[]} - An array of middleware handlers for serving the Swagger UI.
23
24
  */
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
25
+ declare function swagger(path: string, document: OpenAPIObject, opts?: swaggerUi.SwaggerUiOptions, options?: swaggerUi.SwaggerOptions, customCss?: string, customfavIcon?: string, swaggerUrl?: string, customSiteTitle?: string): MiddlewareHandler[];
26
+
27
+ export { swagger, swaggerRedirect };
@@ -0,0 +1,97 @@
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/middleware/swagger.middleware.ts
31
+ var swagger_middleware_exports = {};
32
+ __export(swagger_middleware_exports, {
33
+ swagger: () => swagger,
34
+ swaggerRedirect: () => swaggerRedirect
35
+ });
36
+ module.exports = __toCommonJS(swagger_middleware_exports);
37
+ var import_live_directory = __toESM(require("live-directory"));
38
+ var import_absolute_path = __toESM(require("swagger-ui-dist/absolute-path"));
39
+ var import_swagger_ui_express = __toESM(require("swagger-ui-express"));
40
+ function swaggerRedirect(path) {
41
+ return (req, res, next) => {
42
+ if (req.path === path) {
43
+ res.redirect(`${path}/`);
44
+ }
45
+ return next?.();
46
+ };
47
+ }
48
+ function swagger(path, document, opts, options, customCss, customfavIcon, swaggerUrl, customSiteTitle) {
49
+ const LiveAssets = new import_live_directory.default((0, import_absolute_path.default)(), {
50
+ filter: {
51
+ keep: {
52
+ names: [
53
+ "swagger-ui-bundle.js",
54
+ "swagger-ui-standalone-preset.js",
55
+ "swagger-ui-init.js",
56
+ "swagger-ui.css",
57
+ "favicon-32x32.png",
58
+ "favicon-16x16.png"
59
+ ]
60
+ }
61
+ },
62
+ cache: {
63
+ max_file_count: 10,
64
+ max_file_size: 1024 * 1024 * 1.5
65
+ }
66
+ });
67
+ const serve = import_swagger_ui_express.default.serve[0];
68
+ const staticAssets = (req, res, next) => {
69
+ const filePath = req.path.replace(path, "");
70
+ const file = LiveAssets.get(filePath);
71
+ if (file === void 0) {
72
+ if (next) {
73
+ return next();
74
+ }
75
+ return res.status(404).send();
76
+ }
77
+ const fileParts = file.path.split(".");
78
+ const extension = fileParts[fileParts.length - 1];
79
+ const content = file.content;
80
+ return res.type(extension).send(content);
81
+ };
82
+ const ui = import_swagger_ui_express.default.setup(
83
+ document,
84
+ opts,
85
+ options,
86
+ customCss,
87
+ customfavIcon,
88
+ swaggerUrl,
89
+ customSiteTitle
90
+ );
91
+ return [serve, staticAssets, ui];
92
+ }
93
+ // Annotate the CommonJS export names for ESM import in node:
94
+ 0 && (module.exports = {
95
+ swagger,
96
+ swaggerRedirect
97
+ });
@@ -0,0 +1,61 @@
1
+ // src/middleware/swagger.middleware.ts
2
+ import LiveDirectory from "live-directory";
3
+ import getAbsoluteSwaggerFsPath from "swagger-ui-dist/absolute-path";
4
+ import swaggerUi from "swagger-ui-express";
5
+ function swaggerRedirect(path) {
6
+ return (req, res, next) => {
7
+ if (req.path === path) {
8
+ res.redirect(`${path}/`);
9
+ }
10
+ return next?.();
11
+ };
12
+ }
13
+ function swagger(path, document, opts, options, customCss, customfavIcon, swaggerUrl, customSiteTitle) {
14
+ const LiveAssets = new LiveDirectory(getAbsoluteSwaggerFsPath(), {
15
+ filter: {
16
+ keep: {
17
+ names: [
18
+ "swagger-ui-bundle.js",
19
+ "swagger-ui-standalone-preset.js",
20
+ "swagger-ui-init.js",
21
+ "swagger-ui.css",
22
+ "favicon-32x32.png",
23
+ "favicon-16x16.png"
24
+ ]
25
+ }
26
+ },
27
+ cache: {
28
+ max_file_count: 10,
29
+ max_file_size: 1024 * 1024 * 1.5
30
+ }
31
+ });
32
+ const serve = swaggerUi.serve[0];
33
+ const staticAssets = (req, res, next) => {
34
+ const filePath = req.path.replace(path, "");
35
+ const file = LiveAssets.get(filePath);
36
+ if (file === void 0) {
37
+ if (next) {
38
+ return next();
39
+ }
40
+ return res.status(404).send();
41
+ }
42
+ const fileParts = file.path.split(".");
43
+ const extension = fileParts[fileParts.length - 1];
44
+ const content = file.content;
45
+ return res.type(extension).send(content);
46
+ };
47
+ const ui = swaggerUi.setup(
48
+ document,
49
+ opts,
50
+ options,
51
+ customCss,
52
+ customfavIcon,
53
+ swaggerUrl,
54
+ customSiteTitle
55
+ );
56
+ return [serve, staticAssets, ui];
57
+ }
58
+ export {
59
+ swagger,
60
+ swaggerRedirect
61
+ };
@@ -0,0 +1,44 @@
1
+ import { ParamsDictionary, ForklaunchRequest, ForklaunchResponse, ForklaunchStatusResponse, ForklaunchSendableData } from '@forklaunch/core/http';
2
+ import { AnySchemaValidator } from '@forklaunch/validator';
3
+ import { Request as Request$1, Response as Response$1 } from 'hyper-express';
4
+ import { ParsedQs } from 'qs';
5
+
6
+ /**
7
+ * Extends the Forklaunch request interface with properties from Hyper-Express's request interface.
8
+ *
9
+ * @template SV - A type that extends AnySchemaValidator.
10
+ * @template P - A type for request parameters, defaulting to ParamsDictionary.
11
+ * @template _ResBody - A type for the response body, defaulting to unknown.
12
+ * @template ReqBody - A type for the request body, defaulting to unknown.
13
+ * @template ReqQuery - A type for the request query, defaulting to ParsedQs.
14
+ * @template LocalsObj - A type for local variables, defaulting to an empty object.
15
+ */
16
+ 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'> {
17
+ /** The request body */
18
+ body: ReqBody;
19
+ /** The request query parameters */
20
+ query: ReqQuery;
21
+ /** The request parameters */
22
+ params: P;
23
+ }
24
+ /**
25
+ * Extends the Forklaunch response interface with properties from Hyper-Express's response interface.
26
+ *
27
+ * @template ResBody - A type for the response body, defaulting to unknown.
28
+ * @template LocalsObj - A type for local variables, defaulting to an empty object.
29
+ * @template StatusCode - A type for the status code, defaulting to number.
30
+ */
31
+ 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> {
32
+ /** The body data of the response */
33
+ bodyData: unknown;
34
+ /** If cors are applied to the response */
35
+ cors: boolean;
36
+ /** The status code of the response */
37
+ _status_code: number;
38
+ /** Whether the response is corked */
39
+ _cork: boolean;
40
+ /** Whether the response is currently corked */
41
+ _corked: boolean;
42
+ }
43
+
44
+ export type { Request, Response };
@@ -1,7 +1,8 @@
1
- import { ForklaunchRequest, ForklaunchResponse, ForklaunchSendableData, ForklaunchStatusResponse, ParamsDictionary } from '@forklaunch/core/http';
1
+ import { ParamsDictionary, ForklaunchRequest, ForklaunchResponse, ForklaunchStatusResponse, ForklaunchSendableData } from '@forklaunch/core/http';
2
2
  import { AnySchemaValidator } from '@forklaunch/validator';
3
- import { Request as ExpressRequest, Response as ExpressResponse } from 'hyper-express';
3
+ import { Request as Request$1, Response as Response$1 } from 'hyper-express';
4
4
  import { ParsedQs } from 'qs';
5
+
5
6
  /**
6
7
  * Extends the Forklaunch request interface with properties from Hyper-Express's request interface.
7
8
  *
@@ -12,7 +13,7 @@ import { ParsedQs } from 'qs';
12
13
  * @template ReqQuery - A type for the request query, defaulting to ParsedQs.
13
14
  * @template LocalsObj - A type for local variables, defaulting to an empty object.
14
15
  */
15
- export 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<ExpressRequest<LocalsObj>, 'method' | 'params' | 'query' | 'headers'> {
16
+ 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'> {
16
17
  /** The request body */
17
18
  body: ReqBody;
18
19
  /** The request query parameters */
@@ -27,7 +28,7 @@ export interface Request<SV extends AnySchemaValidator, P extends ParamsDictiona
27
28
  * @template LocalsObj - A type for local variables, defaulting to an empty object.
28
29
  * @template StatusCode - A type for the status code, defaulting to number.
29
30
  */
30
- export interface Response<ResBodyMap extends Record<number, unknown>, ResHeaders extends Record<string, string>, LocalsObj extends Record<string, unknown>> extends ForklaunchResponse<ResBodyMap, ResHeaders, LocalsObj>, Omit<ExpressResponse<LocalsObj>, 'getHeaders' | 'setHeader' | 'headersSent' | 'send' | 'status' | 'statusCode' | 'json' | 'jsonp' | 'end'>, ForklaunchStatusResponse<ForklaunchSendableData> {
31
+ 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> {
31
32
  /** The body data of the response */
32
33
  bodyData: unknown;
33
34
  /** If cors are applied to the response */
@@ -39,4 +40,5 @@ export interface Response<ResBodyMap extends Record<number, unknown>, ResHeaders
39
40
  /** Whether the response is currently corked */
40
41
  _corked: boolean;
41
42
  }
42
- //# sourceMappingURL=hyperExpress.types.d.ts.map
43
+
44
+ export type { Request, Response };
@@ -0,0 +1,18 @@
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 __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+
16
+ // src/types/hyperExpress.types.ts
17
+ var hyperExpress_types_exports = {};
18
+ module.exports = __toCommonJS(hyperExpress_types_exports);
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forklaunch/hyper-express",
3
- "version": "0.1.33",
3
+ "version": "0.2.0",
4
4
  "description": "Forklaunch framework for hyper-express.",
5
5
  "files": [
6
6
  "lib/**"
@@ -18,19 +18,19 @@
18
18
  "homepage": "https://github.com/forklaunch/forklaunch-js#readme",
19
19
  "dependencies": {
20
20
  "cors": "^2.8.5",
21
- "hyper-express": "6.17.2",
21
+ "hyper-express": "6.17.3",
22
22
  "live-directory": "^3.0.3",
23
23
  "openapi3-ts": "^4.4.0",
24
24
  "qs": "^6.13.1",
25
25
  "swagger-ui-dist": "^5.18.2",
26
26
  "swagger-ui-express": "^5.0.1",
27
27
  "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"
28
+ "@forklaunch/common": "0.2.0",
29
+ "@forklaunch/core": "0.3.0",
30
+ "@forklaunch/validator": "0.4.0"
31
31
  },
32
32
  "devDependencies": {
33
- "@eslint/js": "^9.16.0",
33
+ "@eslint/js": "^9.17.0",
34
34
  "@types/cors": "^2.8.17",
35
35
  "@types/jest": "^29.5.14",
36
36
  "@types/qs": "^6.9.17",
@@ -38,22 +38,25 @@
38
38
  "@types/swagger-ui-express": "^4.1.7",
39
39
  "jest": "^29.7.0",
40
40
  "kill-port-process": "^3.2.1",
41
- "prettier": "^3.4.1",
41
+ "prettier": "^3.4.2",
42
42
  "ts-jest": "^29.2.5",
43
43
  "ts-node": "^10.9.2",
44
+ "tsup": "^8.3.5",
44
45
  "tsx": "^4.19.2",
45
- "typescript": "^5.7.2",
46
- "typescript-eslint": "^8.17.0"
46
+ "typescript": "^5.7.3",
47
+ "typescript-eslint": "^8.19.1"
47
48
  },
48
49
  "exports": {
49
50
  ".": {
50
51
  "types": "./lib/index.d.ts",
52
+ "import": "./lib/index.mjs",
53
+ "require": "./lib/index.js",
51
54
  "default": "./lib/index.js"
52
55
  }
53
56
  },
54
57
  "scripts": {
55
58
  "test": "vitest --passWithNoTests",
56
- "build": "tsc",
59
+ "build": "tsc --noEmit && tsup ./src --format cjs,esm --no-splitting --dts --tsconfig tsconfig.json --out-dir lib --clean",
57
60
  "clean": "rm -rf lib pnpm.lock.yaml node_modules",
58
61
  "docs": "typedoc --out docs *",
59
62
  "lint": "eslint . -c eslint.config.mjs",
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';
package/lib/index.d.ts DELETED
@@ -1,25 +0,0 @@
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>;
5
- /**
6
- * Creates a new instance of Application with the given schema validator.
7
- *
8
- * @template SV - A type that extends AnySchemaValidator.
9
- * @param {SV} schemaValidator - The schema validator.
10
- * @returns {Application<SV>} - The new application instance.
11
- */
12
- export declare function forklaunchExpress<SV extends AnySchemaValidator>(schemaValidator: SV): Application<SV>;
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 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
@@ -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"}