@forklaunch/hyper-express 0.1.32 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/hyperExpressApplication.d.mts +30 -0
- package/lib/{src/hyperExpressApplication.d.ts → hyperExpressApplication.d.ts} +5 -3
- package/lib/hyperExpressApplication.js +143 -0
- package/lib/hyperExpressApplication.mjs +111 -0
- package/lib/hyperExpressRouter.d.mts +12 -0
- package/lib/{src/hyperExpressRouter.d.ts → hyperExpressRouter.d.ts} +5 -3
- package/lib/hyperExpressRouter.js +130 -0
- package/lib/hyperExpressRouter.mjs +109 -0
- package/lib/middleware/contentParse.middleware.d.mts +10 -0
- package/lib/{src/middleware → middleware}/contentParse.middleware.d.ts +4 -2
- package/lib/middleware/contentParse.middleware.js +49 -0
- package/lib/middleware/contentParse.middleware.mjs +24 -0
- package/lib/middleware/enrichResponseTransmission.middleware.d.mts +17 -0
- package/lib/middleware/enrichResponseTransmission.middleware.d.ts +17 -0
- package/lib/middleware/enrichResponseTransmission.middleware.js +67 -0
- package/lib/middleware/enrichResponseTransmission.middleware.mjs +44 -0
- package/lib/middleware/polyfillGetHeaders.middleware.d.mts +5 -0
- package/lib/middleware/polyfillGetHeaders.middleware.d.ts +5 -0
- package/lib/middleware/polyfillGetHeaders.middleware.js +36 -0
- package/lib/middleware/polyfillGetHeaders.middleware.mjs +11 -0
- package/lib/middleware/swagger.middleware.d.mts +27 -0
- package/lib/{src/middleware → middleware}/swagger.middleware.d.ts +5 -3
- package/lib/middleware/swagger.middleware.js +97 -0
- package/lib/middleware/swagger.middleware.mjs +61 -0
- package/lib/types/hyperExpress.types.d.mts +44 -0
- package/lib/{src/types → types}/hyperExpress.types.d.ts +7 -5
- package/lib/types/hyperExpress.types.js +18 -0
- package/lib/types/hyperExpress.types.mjs +0 -0
- package/package.json +13 -10
- package/lib/config.d.ts +0 -2
- package/lib/config.d.ts.map +0 -1
- package/lib/config.js +0 -1
- package/lib/index.d.ts +0 -25
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -25
- package/lib/src/hyperExpressApplication.d.ts.map +0 -1
- package/lib/src/hyperExpressApplication.js +0 -41
- package/lib/src/hyperExpressRouter.d.ts.map +0 -1
- package/lib/src/hyperExpressRouter.js +0 -22
- package/lib/src/middleware/contentParse.middleware.d.ts.map +0 -1
- package/lib/src/middleware/contentParse.middleware.js +0 -26
- package/lib/src/middleware/enrichResponseTransmission.middleware.d.ts +0 -14
- package/lib/src/middleware/enrichResponseTransmission.middleware.d.ts.map +0 -1
- package/lib/src/middleware/enrichResponseTransmission.middleware.js +0 -56
- package/lib/src/middleware/polyfillGetHeaders.middleware.d.ts +0 -3
- package/lib/src/middleware/polyfillGetHeaders.middleware.d.ts.map +0 -1
- package/lib/src/middleware/polyfillGetHeaders.middleware.js +0 -8
- package/lib/src/middleware/swagger.middleware.d.ts.map +0 -1
- package/lib/src/middleware/swagger.middleware.js +0 -75
- package/lib/src/types/hyperExpress.types.d.ts.map +0 -1
- package/lib/src/types/hyperExpress.types.js +0 -1
- package/lib/tests/typebox.forklaunch.hyperExpress.test.d.ts +0 -2
- package/lib/tests/typebox.forklaunch.hyperExpress.test.d.ts.map +0 -1
- package/lib/tests/typebox.forklaunch.hyperExpress.test.js +0 -111
- package/lib/tests/zod.forklaunch.hyperExpress.test.d.ts +0 -2
- package/lib/tests/zod.forklaunch.hyperExpress.test.d.ts.map +0 -1
- package/lib/tests/zod.forklaunch.hyperExpress.test.js +0 -109
- package/lib/vitest.config.d.ts +0 -3
- package/lib/vitest.config.d.ts.map +0 -1
- package/lib/vitest.config.js +0 -7
package/lib/index.js
DELETED
@@ -1,25 +0,0 @@
|
|
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);
|
12
|
-
}
|
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;
|
24
|
-
}
|
25
|
-
export * from './src/types/hyperExpress.types';
|
@@ -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 +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 +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 +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 +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"}
|
@@ -1,75 +0,0 @@
|
|
1
|
-
import LiveDirectory from 'live-directory';
|
2
|
-
import getAbsoluteSwaggerFsPath from 'swagger-ui-dist/absolute-path';
|
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 function swaggerRedirect(path) {
|
11
|
-
return (req, res, next) => {
|
12
|
-
if (req.path === path) {
|
13
|
-
res.redirect(`${path}/`);
|
14
|
-
}
|
15
|
-
return next?.();
|
16
|
-
};
|
17
|
-
}
|
18
|
-
/**
|
19
|
-
* Sets up the Swagger UI middleware for serving API documentation.
|
20
|
-
*
|
21
|
-
* @param {string} path - The base path for the Swagger UI.
|
22
|
-
* @param {OpenAPIObject} document - The OpenAPI document to display.
|
23
|
-
* @param {swaggerUi.SwaggerUiOptions} [opts] - Optional Swagger UI options.
|
24
|
-
* @param {swaggerUi.SwaggerOptions} [options] - Optional Swagger options.
|
25
|
-
* @param {string} [customCss] - Custom CSS to apply to the Swagger UI.
|
26
|
-
* @param {string} [customfavIcon] - Custom favicon to use in the Swagger UI.
|
27
|
-
* @param {string} [swaggerUrl] - Custom Swagger URL.
|
28
|
-
* @param {string} [customSiteTitle] - Custom site title for the Swagger UI.
|
29
|
-
* @returns {MiddlewareHandler[]} - An array of middleware handlers for serving the Swagger UI.
|
30
|
-
*/
|
31
|
-
export function swagger(path, document, opts, options, customCss, customfavIcon, swaggerUrl, customSiteTitle) {
|
32
|
-
const LiveAssets = new LiveDirectory(getAbsoluteSwaggerFsPath(), {
|
33
|
-
filter: {
|
34
|
-
keep: {
|
35
|
-
names: [
|
36
|
-
'swagger-ui-bundle.js',
|
37
|
-
'swagger-ui-standalone-preset.js',
|
38
|
-
'swagger-ui-init.js',
|
39
|
-
'swagger-ui.css',
|
40
|
-
'favicon-32x32.png',
|
41
|
-
'favicon-16x16.png'
|
42
|
-
]
|
43
|
-
}
|
44
|
-
},
|
45
|
-
cache: {
|
46
|
-
max_file_count: 10,
|
47
|
-
max_file_size: 1024 * 1024 * 1.5
|
48
|
-
}
|
49
|
-
});
|
50
|
-
const serve = swaggerUi.serve[0];
|
51
|
-
/**
|
52
|
-
* Middleware to serve static assets for the Swagger UI.
|
53
|
-
*
|
54
|
-
* @param {Request} req - The request object.
|
55
|
-
* @param {Response} res - The response object.
|
56
|
-
* @param {MiddlewareNext} [next] - The next middleware function.
|
57
|
-
* @returns {void}
|
58
|
-
*/
|
59
|
-
const staticAssets = (req, res, next) => {
|
60
|
-
const filePath = req.path.replace(path, '');
|
61
|
-
const file = LiveAssets.get(filePath);
|
62
|
-
if (file === undefined) {
|
63
|
-
if (next) {
|
64
|
-
return next();
|
65
|
-
}
|
66
|
-
return res.status(404).send();
|
67
|
-
}
|
68
|
-
const fileParts = file.path.split('.');
|
69
|
-
const extension = fileParts[fileParts.length - 1];
|
70
|
-
const content = file.content;
|
71
|
-
return res.type(extension).send(content);
|
72
|
-
};
|
73
|
-
const ui = swaggerUi.setup(document, opts, options, customCss, customfavIcon, swaggerUrl, customSiteTitle);
|
74
|
-
return [serve, staticAssets, ui];
|
75
|
-
}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"hyperExpress.types.d.ts","sourceRoot":"","sources":["../../../src/types/hyperExpress.types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,EACtB,wBAAwB,EACxB,gBAAgB,EACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EACL,OAAO,IAAI,cAAc,EACzB,QAAQ,IAAI,eAAe,EAC5B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAE9B;;;;;;;;;GASG;AACH,MAAM,WAAW,OAAO,CACtB,EAAE,SAAS,kBAAkB,EAC7B,CAAC,SAAS,gBAAgB,EAC1B,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACvC,QAAQ,SAAS,QAAQ,EACzB,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACzC,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CACzC,SAAQ,iBAAiB,CAAC,EAAE,EAAE,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,CAAC,EAC7D,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,OAAO,GAAG,SAAS,CAAC;IAC5E,uBAAuB;IACvB,IAAI,EAAE,OAAO,CAAC;IACd,mCAAmC;IACnC,KAAK,EAAE,QAAQ,CAAC;IAChB,6BAA6B;IAC7B,MAAM,EAAE,CAAC,CAAC;CACX;AAED;;;;;;GAMG;AACH,MAAM,WAAW,QAAQ,CACvB,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC1C,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACzC,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CACzC,SAAQ,kBAAkB,CAAC,UAAU,EAAE,UAAU,EAAE,SAAS,CAAC,EAC3D,IAAI,CACF,eAAe,CAAC,SAAS,CAAC,EACxB,YAAY,GACZ,WAAW,GACX,aAAa,GACb,MAAM,GACN,QAAQ,GACR,YAAY,GACZ,MAAM,GACN,OAAO,GACP,KAAK,CACR,EACD,wBAAwB,CAAC,sBAAsB,CAAC;IAClD,oCAAoC;IACpC,QAAQ,EAAE,OAAO,CAAC;IAClB,0CAA0C;IAC1C,IAAI,EAAE,OAAO,CAAC;IACd,sCAAsC;IACtC,YAAY,EAAE,MAAM,CAAC;IACrB,qCAAqC;IACrC,KAAK,EAAE,OAAO,CAAC;IACf,+CAA+C;IAC/C,OAAO,EAAE,OAAO,CAAC;CAClB"}
|
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"typebox.forklaunch.hyperExpress.test.d.ts","sourceRoot":"","sources":["../../tests/typebox.forklaunch.hyperExpress.test.ts"],"names":[],"mappings":""}
|
@@ -1,111 +0,0 @@
|
|
1
|
-
import { SchemaValidator, string } from '@forklaunch/validator/typebox';
|
2
|
-
import { forklaunchExpress, forklaunchRouter } from '../index';
|
3
|
-
const typeboxSchemaValidator = SchemaValidator();
|
4
|
-
const forklaunchApplication = forklaunchExpress(typeboxSchemaValidator);
|
5
|
-
const forklaunchRouterInstance = forklaunchRouter('/testpath', typeboxSchemaValidator);
|
6
|
-
describe('Forklaunch Hyper-Express Tests', () => {
|
7
|
-
beforeAll(async () => {
|
8
|
-
forklaunchRouterInstance.get('/test', {
|
9
|
-
name: 'Test',
|
10
|
-
summary: 'Test Summary',
|
11
|
-
responses: {
|
12
|
-
200: string
|
13
|
-
}
|
14
|
-
}, (_req, res) => {
|
15
|
-
res.status(200).send('Hello World');
|
16
|
-
});
|
17
|
-
forklaunchRouterInstance.post('/test', {
|
18
|
-
name: 'Test',
|
19
|
-
summary: 'Test Summary',
|
20
|
-
body: {
|
21
|
-
test: string
|
22
|
-
},
|
23
|
-
responses: {
|
24
|
-
200: string
|
25
|
-
}
|
26
|
-
}, (req, res) => {
|
27
|
-
res.status(200).send(req.body.test);
|
28
|
-
});
|
29
|
-
forklaunchRouterInstance.put('/test', {
|
30
|
-
name: 'Test',
|
31
|
-
summary: 'Test Summary',
|
32
|
-
body: {
|
33
|
-
test: string
|
34
|
-
},
|
35
|
-
responses: {
|
36
|
-
200: string
|
37
|
-
}
|
38
|
-
}, (req, res) => {
|
39
|
-
res.status(200).send(req.body.test);
|
40
|
-
});
|
41
|
-
forklaunchRouterInstance.patch('/test', {
|
42
|
-
name: 'Test',
|
43
|
-
summary: 'Test Summary',
|
44
|
-
body: {
|
45
|
-
test: string
|
46
|
-
},
|
47
|
-
responses: {
|
48
|
-
200: string
|
49
|
-
}
|
50
|
-
}, (req, res) => {
|
51
|
-
res.status(200).send(req.body.test);
|
52
|
-
});
|
53
|
-
forklaunchRouterInstance.delete('/test', {
|
54
|
-
name: 'Test',
|
55
|
-
summary: 'Test Summary',
|
56
|
-
responses: {
|
57
|
-
200: string
|
58
|
-
}
|
59
|
-
}, (_req, res) => {
|
60
|
-
res.status(200).send('Hello World');
|
61
|
-
});
|
62
|
-
forklaunchApplication.use(forklaunchRouterInstance);
|
63
|
-
await forklaunchApplication.listen(6936, () => {
|
64
|
-
console.log('server started on 6936');
|
65
|
-
});
|
66
|
-
});
|
67
|
-
test('Get', async () => {
|
68
|
-
const testGet = await fetch('http://localhost:6936/testpath/test', {
|
69
|
-
method: 'GET'
|
70
|
-
});
|
71
|
-
expect(testGet.status).toBe(200);
|
72
|
-
expect(await testGet.text()).toBe('Hello World');
|
73
|
-
});
|
74
|
-
test('Post', async () => {
|
75
|
-
const testPost = await fetch('http://localhost:6936/testpath/test', {
|
76
|
-
method: 'POST',
|
77
|
-
body: JSON.stringify({ test: 'Hello World' }),
|
78
|
-
headers: { 'Content-Type': 'application/json' }
|
79
|
-
});
|
80
|
-
expect(testPost.status).toBe(200);
|
81
|
-
expect(await testPost.text()).toBe('Hello World');
|
82
|
-
});
|
83
|
-
test('Put', async () => {
|
84
|
-
const testPut = await fetch('http://localhost:6936/testpath/test', {
|
85
|
-
method: 'PUT',
|
86
|
-
body: JSON.stringify({ test: 'Hello World' }),
|
87
|
-
headers: { 'Content-Type': 'application/json' }
|
88
|
-
});
|
89
|
-
expect(testPut.status).toBe(200);
|
90
|
-
expect(await testPut.text()).toBe('Hello World');
|
91
|
-
});
|
92
|
-
test('Patch', async () => {
|
93
|
-
const testPatch = await fetch('http://localhost:6936/testpath/test', {
|
94
|
-
method: 'PATCH',
|
95
|
-
body: JSON.stringify({ test: 'Hello World' }),
|
96
|
-
headers: { 'Content-Type': 'application/json' }
|
97
|
-
});
|
98
|
-
expect(testPatch.status).toBe(200);
|
99
|
-
expect(await testPatch.text()).toBe('Hello World');
|
100
|
-
});
|
101
|
-
test('Delete', async () => {
|
102
|
-
const testDelete = await fetch('http://localhost:6936/testpath/test', {
|
103
|
-
method: 'DELETE'
|
104
|
-
});
|
105
|
-
expect(testDelete.status).toBe(200);
|
106
|
-
expect(await testDelete.text()).toBe('Hello World');
|
107
|
-
});
|
108
|
-
afterAll(async () => {
|
109
|
-
forklaunchApplication.internal.shutdown();
|
110
|
-
});
|
111
|
-
});
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"zod.forklaunch.hyperExpress.test.d.ts","sourceRoot":"","sources":["../../tests/zod.forklaunch.hyperExpress.test.ts"],"names":[],"mappings":""}
|
@@ -1,109 +0,0 @@
|
|
1
|
-
import { SchemaValidator, string } from '@forklaunch/validator/zod';
|
2
|
-
import { forklaunchExpress, forklaunchRouter } from '../index';
|
3
|
-
const zodSchemaValidator = SchemaValidator();
|
4
|
-
const forklaunchApplication = forklaunchExpress(zodSchemaValidator);
|
5
|
-
const forklaunchRouterInstance = forklaunchRouter('/testpath', zodSchemaValidator);
|
6
|
-
describe('Forklaunch Hyper-Express Tests', () => {
|
7
|
-
beforeAll(async () => {
|
8
|
-
forklaunchRouterInstance.get('/test', {
|
9
|
-
name: 'Test',
|
10
|
-
summary: 'Test Summary',
|
11
|
-
responses: {
|
12
|
-
200: string
|
13
|
-
}
|
14
|
-
}, (_req, res) => {
|
15
|
-
res.status(200).send('Hello World');
|
16
|
-
});
|
17
|
-
forklaunchRouterInstance.post('/test', {
|
18
|
-
name: 'Test',
|
19
|
-
summary: 'Test Summary',
|
20
|
-
body: {
|
21
|
-
test: string
|
22
|
-
},
|
23
|
-
responses: {
|
24
|
-
200: string
|
25
|
-
}
|
26
|
-
}, (req, res) => {
|
27
|
-
res.status(200).send(req.body.test);
|
28
|
-
});
|
29
|
-
forklaunchRouterInstance.put('/test', {
|
30
|
-
name: 'Test',
|
31
|
-
summary: 'Test Summary',
|
32
|
-
body: {
|
33
|
-
test: string
|
34
|
-
},
|
35
|
-
responses: {
|
36
|
-
200: string
|
37
|
-
}
|
38
|
-
}, (req, res) => {
|
39
|
-
res.status(200).send(req.body.test);
|
40
|
-
});
|
41
|
-
forklaunchRouterInstance.patch('/test', {
|
42
|
-
name: 'Test',
|
43
|
-
summary: 'Test Summary',
|
44
|
-
body: {
|
45
|
-
test: string
|
46
|
-
},
|
47
|
-
responses: {
|
48
|
-
200: string
|
49
|
-
}
|
50
|
-
}, (req, res) => {
|
51
|
-
res.status(200).send(req.body.test);
|
52
|
-
});
|
53
|
-
forklaunchRouterInstance.delete('/test', {
|
54
|
-
name: 'Test',
|
55
|
-
summary: 'Test Summary',
|
56
|
-
responses: {
|
57
|
-
200: string
|
58
|
-
}
|
59
|
-
}, (_req, res) => {
|
60
|
-
res.status(200).send('Hello World');
|
61
|
-
});
|
62
|
-
forklaunchApplication.use(forklaunchRouterInstance);
|
63
|
-
await forklaunchApplication.listen(6937, () => { });
|
64
|
-
});
|
65
|
-
test('Get', async () => {
|
66
|
-
const testGet = await fetch('http://localhost:6937/testpath/test', {
|
67
|
-
method: 'GET'
|
68
|
-
});
|
69
|
-
expect(testGet.status).toBe(200);
|
70
|
-
expect(await testGet.text()).toBe('Hello World');
|
71
|
-
});
|
72
|
-
test('Post', async () => {
|
73
|
-
const testPost = await fetch('http://localhost:6937/testpath/test', {
|
74
|
-
method: 'POST',
|
75
|
-
body: JSON.stringify({ test: 'Hello World' }),
|
76
|
-
headers: { 'Content-Type': 'application/json' }
|
77
|
-
});
|
78
|
-
expect(testPost.status).toBe(200);
|
79
|
-
expect(await testPost.text()).toBe('Hello World');
|
80
|
-
});
|
81
|
-
test('Put', async () => {
|
82
|
-
const testPut = await fetch('http://localhost:6937/testpath/test', {
|
83
|
-
method: 'PUT',
|
84
|
-
body: JSON.stringify({ test: 'Hello World' }),
|
85
|
-
headers: { 'Content-Type': 'application/json' }
|
86
|
-
});
|
87
|
-
expect(testPut.status).toBe(200);
|
88
|
-
expect(await testPut.text()).toBe('Hello World');
|
89
|
-
});
|
90
|
-
test('Patch', async () => {
|
91
|
-
const testPatch = await fetch('http://localhost:6937/testpath/test', {
|
92
|
-
method: 'PATCH',
|
93
|
-
body: JSON.stringify({ test: 'Hello World' }),
|
94
|
-
headers: { 'Content-Type': 'application/json' }
|
95
|
-
});
|
96
|
-
expect(testPatch.status).toBe(200);
|
97
|
-
expect(await testPatch.text()).toBe('Hello World');
|
98
|
-
});
|
99
|
-
test('Delete', async () => {
|
100
|
-
const testDelete = await fetch('http://localhost:6937/testpath/test', {
|
101
|
-
method: 'DELETE'
|
102
|
-
});
|
103
|
-
expect(testDelete.status).toBe(200);
|
104
|
-
expect(await testDelete.text()).toBe('Hello World');
|
105
|
-
});
|
106
|
-
afterAll(async () => {
|
107
|
-
forklaunchApplication.internal.shutdown();
|
108
|
-
});
|
109
|
-
});
|
package/lib/vitest.config.d.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"vitest.config.d.ts","sourceRoot":"","sources":["../vitest.config.ts"],"names":[],"mappings":";AAEA,wBAKG"}
|