@forklaunch/hyper-express 0.3.0 → 0.3.2
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/index.d.mts +23 -45
- package/lib/index.d.ts +23 -45
- package/lib/index.js +94 -31
- package/lib/index.mjs +111 -26
- package/package.json +8 -8
package/lib/index.d.mts
CHANGED
@@ -1,15 +1,18 @@
|
|
1
|
+
import * as _forklaunch_hyper_express_fork from '@forklaunch/hyper-express-fork';
|
2
|
+
import { Server, MiddlewareHandler, Request, Response, MiddlewareNext, Router as Router$1 } from '@forklaunch/hyper-express-fork';
|
3
|
+
export { MiddlewareNext as NextFunction, Request, Response } from '@forklaunch/hyper-express-fork';
|
4
|
+
import * as _forklaunch_core_http from '@forklaunch/core/http';
|
5
|
+
import { ForklaunchExpressLikeApplication, ForklaunchExpressLikeRouter, ForklaunchRouter, TypedMiddlewareDefinition } from '@forklaunch/core/http';
|
1
6
|
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
7
|
import * as uWebsockets from 'uWebSockets.js';
|
5
|
-
|
8
|
+
export { ParsedQs } from 'qs';
|
6
9
|
|
7
10
|
/**
|
8
11
|
* Represents an application built on top of Hyper-Express and Forklaunch.
|
9
12
|
*
|
10
13
|
* @template SV - A type that extends AnySchemaValidator.
|
11
14
|
*/
|
12
|
-
declare class Application<SV extends AnySchemaValidator> extends ForklaunchExpressLikeApplication<SV, Server, MiddlewareHandler> {
|
15
|
+
declare class Application<SV extends AnySchemaValidator> extends ForklaunchExpressLikeApplication<SV, Server, MiddlewareHandler, Request<Record<string, unknown>>, Response<Record<string, unknown>>, MiddlewareNext> {
|
13
16
|
/**
|
14
17
|
* Creates an instance of the Application class.
|
15
18
|
*
|
@@ -28,49 +31,11 @@ declare class Application<SV extends AnySchemaValidator> extends ForklaunchExpre
|
|
28
31
|
listen(unix_path: string, callback?: (listen_socket: uWebsockets.us_listen_socket) => void): Promise<uWebsockets.us_listen_socket>;
|
29
32
|
}
|
30
33
|
|
31
|
-
declare class Router<SV extends AnySchemaValidator, BasePath extends `/${string}`> extends ForklaunchExpressLikeRouter<SV, BasePath, MiddlewareHandler, Router$1> implements ForklaunchRouter<SV> {
|
34
|
+
declare class Router<SV extends AnySchemaValidator, BasePath extends `/${string}`> extends ForklaunchExpressLikeRouter<SV, BasePath, MiddlewareHandler, Router$1, Request<Record<string, unknown>>, Response<Record<string, unknown>>, MiddlewareNext> implements ForklaunchRouter<SV> {
|
32
35
|
basePath: BasePath;
|
33
36
|
constructor(basePath: BasePath, schemaValidator: SV);
|
34
37
|
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' | 'path'> {
|
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;
|
38
|
+
any: TypedMiddlewareDefinition<this, SV, Request<Record<string, unknown>>, Response<Record<string, unknown>>, MiddlewareNext>;
|
74
39
|
}
|
75
40
|
|
76
41
|
type App<SV extends AnySchemaValidator> = Application<SV>;
|
@@ -92,4 +57,17 @@ declare function forklaunchExpress<SV extends AnySchemaValidator>(schemaValidato
|
|
92
57
|
*/
|
93
58
|
declare function forklaunchRouter<SV extends AnySchemaValidator, BasePath extends `/${string}`>(basePath: BasePath, schemaValidator: SV): Router<SV, BasePath>;
|
94
59
|
|
95
|
-
|
60
|
+
declare const handlers: {
|
61
|
+
any: <SV extends AnySchemaValidator, Path extends `/${string}`, P extends _forklaunch_core_http.ParamsObject<SV>, ResBodyMap extends _forklaunch_core_http.ResponsesObject<SV>, ReqBody extends _forklaunch_core_http.Body<SV>, ReqQuery extends _forklaunch_core_http.QueryObject<SV>, ReqHeaders extends _forklaunch_core_http.HeadersObject<SV>, ResHeaders extends _forklaunch_core_http.HeadersObject<SV>, LocalsObj extends Record<string, unknown>>(schemaValidator: SV, path: Path, contractDetails: _forklaunch_core_http.ContractDetails<SV, "middleware", Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, _forklaunch_hyper_express_fork.Request<LocalsObj>>, ...handlers: _forklaunch_core_http.ExpressLikeSchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, _forklaunch_hyper_express_fork.Request<LocalsObj>, _forklaunch_hyper_express_fork.Response<LocalsObj>, _forklaunch_hyper_express_fork.MiddlewareNext>[]) => _forklaunch_core_http.ExpressLikeTypedHandler<SV, "middleware", Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, _forklaunch_hyper_express_fork.Request<LocalsObj>, _forklaunch_hyper_express_fork.Response<LocalsObj>, _forklaunch_hyper_express_fork.MiddlewareNext>;
|
62
|
+
delete: <SV extends AnySchemaValidator, Path extends `/${string}`, P extends _forklaunch_core_http.ParamsObject<SV>, ResBodyMap extends _forklaunch_core_http.ResponsesObject<SV>, ReqBody extends _forklaunch_core_http.Body<SV>, ReqQuery extends _forklaunch_core_http.QueryObject<SV>, ReqHeaders extends _forklaunch_core_http.HeadersObject<SV>, ResHeaders extends _forklaunch_core_http.HeadersObject<SV>, LocalsObj extends Record<string, unknown>>(schemaValidator: SV, path: Path, contractDetails: _forklaunch_core_http.ContractDetails<SV, "delete", Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, _forklaunch_hyper_express_fork.Request<LocalsObj>>, ...handlers: _forklaunch_core_http.ExpressLikeSchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, _forklaunch_hyper_express_fork.Request<LocalsObj>, _forklaunch_hyper_express_fork.Response<LocalsObj>, _forklaunch_hyper_express_fork.MiddlewareNext>[]) => _forklaunch_core_http.ExpressLikeTypedHandler<SV, "delete", Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, _forklaunch_hyper_express_fork.Request<LocalsObj>, _forklaunch_hyper_express_fork.Response<LocalsObj>, _forklaunch_hyper_express_fork.MiddlewareNext>;
|
63
|
+
get: <SV extends AnySchemaValidator, Path extends `/${string}`, P extends _forklaunch_core_http.ParamsObject<SV>, ResBodyMap extends _forklaunch_core_http.ResponsesObject<SV>, ReqBody extends _forklaunch_core_http.Body<SV>, ReqQuery extends _forklaunch_core_http.QueryObject<SV>, ReqHeaders extends _forklaunch_core_http.HeadersObject<SV>, ResHeaders extends _forklaunch_core_http.HeadersObject<SV>, LocalsObj extends Record<string, unknown>>(schemaValidator: SV, path: Path, contractDetails: _forklaunch_core_http.ContractDetails<SV, "get", Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, _forklaunch_hyper_express_fork.Request<LocalsObj>>, ...handlers: _forklaunch_core_http.ExpressLikeSchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, _forklaunch_hyper_express_fork.Request<LocalsObj>, _forklaunch_hyper_express_fork.Response<LocalsObj>, _forklaunch_hyper_express_fork.MiddlewareNext>[]) => _forklaunch_core_http.ExpressLikeTypedHandler<SV, "get", Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, _forklaunch_hyper_express_fork.Request<LocalsObj>, _forklaunch_hyper_express_fork.Response<LocalsObj>, _forklaunch_hyper_express_fork.MiddlewareNext>;
|
64
|
+
head: <SV extends AnySchemaValidator, Path extends `/${string}`, P extends _forklaunch_core_http.ParamsObject<SV>, ResBodyMap extends _forklaunch_core_http.ResponsesObject<SV>, ReqBody extends _forklaunch_core_http.Body<SV>, ReqQuery extends _forklaunch_core_http.QueryObject<SV>, ReqHeaders extends _forklaunch_core_http.HeadersObject<SV>, ResHeaders extends _forklaunch_core_http.HeadersObject<SV>, LocalsObj extends Record<string, unknown>>(schemaValidator: SV, path: Path, contractDetails: _forklaunch_core_http.ContractDetails<SV, "head", Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, _forklaunch_hyper_express_fork.Request<LocalsObj>>, ...handlers: _forklaunch_core_http.ExpressLikeSchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, _forklaunch_hyper_express_fork.Request<LocalsObj>, _forklaunch_hyper_express_fork.Response<LocalsObj>, _forklaunch_hyper_express_fork.MiddlewareNext>[]) => _forklaunch_core_http.ExpressLikeTypedHandler<SV, "head", Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, _forklaunch_hyper_express_fork.Request<LocalsObj>, _forklaunch_hyper_express_fork.Response<LocalsObj>, _forklaunch_hyper_express_fork.MiddlewareNext>;
|
65
|
+
middleware: <SV extends AnySchemaValidator, Path extends `/${string}`, P extends _forklaunch_core_http.ParamsObject<SV>, ResBodyMap extends _forklaunch_core_http.ResponsesObject<SV>, ReqBody extends _forklaunch_core_http.Body<SV>, ReqQuery extends _forklaunch_core_http.QueryObject<SV>, ReqHeaders extends _forklaunch_core_http.HeadersObject<SV>, ResHeaders extends _forklaunch_core_http.HeadersObject<SV>, LocalsObj extends Record<string, unknown>>(schemaValidator: SV, path: Path, contractDetails: _forklaunch_core_http.ContractDetails<SV, "middleware", Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, _forklaunch_hyper_express_fork.Request<LocalsObj>>, ...handlers: _forklaunch_core_http.ExpressLikeSchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, _forklaunch_hyper_express_fork.Request<LocalsObj>, _forklaunch_hyper_express_fork.Response<LocalsObj>, _forklaunch_hyper_express_fork.MiddlewareNext>[]) => _forklaunch_core_http.ExpressLikeTypedHandler<SV, "middleware", Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, _forklaunch_hyper_express_fork.Request<LocalsObj>, _forklaunch_hyper_express_fork.Response<LocalsObj>, _forklaunch_hyper_express_fork.MiddlewareNext>;
|
66
|
+
options: <SV extends AnySchemaValidator, Path extends `/${string}`, P extends _forklaunch_core_http.ParamsObject<SV>, ResBodyMap extends _forklaunch_core_http.ResponsesObject<SV>, ReqBody extends _forklaunch_core_http.Body<SV>, ReqQuery extends _forklaunch_core_http.QueryObject<SV>, ReqHeaders extends _forklaunch_core_http.HeadersObject<SV>, ResHeaders extends _forklaunch_core_http.HeadersObject<SV>, LocalsObj extends Record<string, unknown>>(schemaValidator: SV, path: Path, contractDetails: _forklaunch_core_http.ContractDetails<SV, "options", Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, _forklaunch_hyper_express_fork.Request<LocalsObj>>, ...handlers: _forklaunch_core_http.ExpressLikeSchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, _forklaunch_hyper_express_fork.Request<LocalsObj>, _forklaunch_hyper_express_fork.Response<LocalsObj>, _forklaunch_hyper_express_fork.MiddlewareNext>[]) => _forklaunch_core_http.ExpressLikeTypedHandler<SV, "options", Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, _forklaunch_hyper_express_fork.Request<LocalsObj>, _forklaunch_hyper_express_fork.Response<LocalsObj>, _forklaunch_hyper_express_fork.MiddlewareNext>;
|
67
|
+
patch: <SV extends AnySchemaValidator, Path extends `/${string}`, P extends _forklaunch_core_http.ParamsObject<SV>, ResBodyMap extends _forklaunch_core_http.ResponsesObject<SV>, ReqBody extends _forklaunch_core_http.Body<SV>, ReqQuery extends _forklaunch_core_http.QueryObject<SV>, ReqHeaders extends _forklaunch_core_http.HeadersObject<SV>, ResHeaders extends _forklaunch_core_http.HeadersObject<SV>, LocalsObj extends Record<string, unknown>>(schemaValidator: SV, path: Path, contractDetails: _forklaunch_core_http.ContractDetails<SV, "patch", Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, _forklaunch_hyper_express_fork.Request<LocalsObj>>, ...handlers: _forklaunch_core_http.ExpressLikeSchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, _forklaunch_hyper_express_fork.Request<LocalsObj>, _forklaunch_hyper_express_fork.Response<LocalsObj>, _forklaunch_hyper_express_fork.MiddlewareNext>[]) => _forklaunch_core_http.ExpressLikeTypedHandler<SV, "patch", Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, _forklaunch_hyper_express_fork.Request<LocalsObj>, _forklaunch_hyper_express_fork.Response<LocalsObj>, _forklaunch_hyper_express_fork.MiddlewareNext>;
|
68
|
+
post: <SV extends AnySchemaValidator, Path extends `/${string}`, P extends _forklaunch_core_http.ParamsObject<SV>, ResBodyMap extends _forklaunch_core_http.ResponsesObject<SV>, ReqBody extends _forklaunch_core_http.Body<SV>, ReqQuery extends _forklaunch_core_http.QueryObject<SV>, ReqHeaders extends _forklaunch_core_http.HeadersObject<SV>, ResHeaders extends _forklaunch_core_http.HeadersObject<SV>, LocalsObj extends Record<string, unknown>>(schemaValidator: SV, path: Path, contractDetails: _forklaunch_core_http.ContractDetails<SV, "post", Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, _forklaunch_hyper_express_fork.Request<LocalsObj>>, ...handlers: _forklaunch_core_http.ExpressLikeSchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, _forklaunch_hyper_express_fork.Request<LocalsObj>, _forklaunch_hyper_express_fork.Response<LocalsObj>, _forklaunch_hyper_express_fork.MiddlewareNext>[]) => _forklaunch_core_http.ExpressLikeTypedHandler<SV, "post", Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, _forklaunch_hyper_express_fork.Request<LocalsObj>, _forklaunch_hyper_express_fork.Response<LocalsObj>, _forklaunch_hyper_express_fork.MiddlewareNext>;
|
69
|
+
put: <SV extends AnySchemaValidator, Path extends `/${string}`, P extends _forklaunch_core_http.ParamsObject<SV>, ResBodyMap extends _forklaunch_core_http.ResponsesObject<SV>, ReqBody extends _forklaunch_core_http.Body<SV>, ReqQuery extends _forklaunch_core_http.QueryObject<SV>, ReqHeaders extends _forklaunch_core_http.HeadersObject<SV>, ResHeaders extends _forklaunch_core_http.HeadersObject<SV>, LocalsObj extends Record<string, unknown>>(schemaValidator: SV, path: Path, contractDetails: _forklaunch_core_http.ContractDetails<SV, "put", Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, _forklaunch_hyper_express_fork.Request<LocalsObj>>, ...handlers: _forklaunch_core_http.ExpressLikeSchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, _forklaunch_hyper_express_fork.Request<LocalsObj>, _forklaunch_hyper_express_fork.Response<LocalsObj>, _forklaunch_hyper_express_fork.MiddlewareNext>[]) => _forklaunch_core_http.ExpressLikeTypedHandler<SV, "put", Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, _forklaunch_hyper_express_fork.Request<LocalsObj>, _forklaunch_hyper_express_fork.Response<LocalsObj>, _forklaunch_hyper_express_fork.MiddlewareNext>;
|
70
|
+
trace: <SV extends AnySchemaValidator, Path extends `/${string}`, P extends _forklaunch_core_http.ParamsObject<SV>, ResBodyMap extends _forklaunch_core_http.ResponsesObject<SV>, ReqBody extends _forklaunch_core_http.Body<SV>, ReqQuery extends _forklaunch_core_http.QueryObject<SV>, ReqHeaders extends _forklaunch_core_http.HeadersObject<SV>, ResHeaders extends _forklaunch_core_http.HeadersObject<SV>, LocalsObj extends Record<string, unknown>>(schemaValidator: SV, path: Path, contractDetails: _forklaunch_core_http.ContractDetails<SV, "trace", Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, _forklaunch_hyper_express_fork.Request<LocalsObj>>, ...handlers: _forklaunch_core_http.ExpressLikeSchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, _forklaunch_hyper_express_fork.Request<LocalsObj>, _forklaunch_hyper_express_fork.Response<LocalsObj>, _forklaunch_hyper_express_fork.MiddlewareNext>[]) => _forklaunch_core_http.ExpressLikeTypedHandler<SV, "trace", Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, _forklaunch_hyper_express_fork.Request<LocalsObj>, _forklaunch_hyper_express_fork.Response<LocalsObj>, _forklaunch_hyper_express_fork.MiddlewareNext>;
|
71
|
+
};
|
72
|
+
|
73
|
+
export { type App, Application, Router, forklaunchExpress, forklaunchRouter, handlers };
|
package/lib/index.d.ts
CHANGED
@@ -1,15 +1,18 @@
|
|
1
|
+
import * as _forklaunch_hyper_express_fork from '@forklaunch/hyper-express-fork';
|
2
|
+
import { Server, MiddlewareHandler, Request, Response, MiddlewareNext, Router as Router$1 } from '@forklaunch/hyper-express-fork';
|
3
|
+
export { MiddlewareNext as NextFunction, Request, Response } from '@forklaunch/hyper-express-fork';
|
4
|
+
import * as _forklaunch_core_http from '@forklaunch/core/http';
|
5
|
+
import { ForklaunchExpressLikeApplication, ForklaunchExpressLikeRouter, ForklaunchRouter, TypedMiddlewareDefinition } from '@forklaunch/core/http';
|
1
6
|
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
7
|
import * as uWebsockets from 'uWebSockets.js';
|
5
|
-
|
8
|
+
export { ParsedQs } from 'qs';
|
6
9
|
|
7
10
|
/**
|
8
11
|
* Represents an application built on top of Hyper-Express and Forklaunch.
|
9
12
|
*
|
10
13
|
* @template SV - A type that extends AnySchemaValidator.
|
11
14
|
*/
|
12
|
-
declare class Application<SV extends AnySchemaValidator> extends ForklaunchExpressLikeApplication<SV, Server, MiddlewareHandler> {
|
15
|
+
declare class Application<SV extends AnySchemaValidator> extends ForklaunchExpressLikeApplication<SV, Server, MiddlewareHandler, Request<Record<string, unknown>>, Response<Record<string, unknown>>, MiddlewareNext> {
|
13
16
|
/**
|
14
17
|
* Creates an instance of the Application class.
|
15
18
|
*
|
@@ -28,49 +31,11 @@ declare class Application<SV extends AnySchemaValidator> extends ForklaunchExpre
|
|
28
31
|
listen(unix_path: string, callback?: (listen_socket: uWebsockets.us_listen_socket) => void): Promise<uWebsockets.us_listen_socket>;
|
29
32
|
}
|
30
33
|
|
31
|
-
declare class Router<SV extends AnySchemaValidator, BasePath extends `/${string}`> extends ForklaunchExpressLikeRouter<SV, BasePath, MiddlewareHandler, Router$1> implements ForklaunchRouter<SV> {
|
34
|
+
declare class Router<SV extends AnySchemaValidator, BasePath extends `/${string}`> extends ForklaunchExpressLikeRouter<SV, BasePath, MiddlewareHandler, Router$1, Request<Record<string, unknown>>, Response<Record<string, unknown>>, MiddlewareNext> implements ForklaunchRouter<SV> {
|
32
35
|
basePath: BasePath;
|
33
36
|
constructor(basePath: BasePath, schemaValidator: SV);
|
34
37
|
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' | 'path'> {
|
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;
|
38
|
+
any: TypedMiddlewareDefinition<this, SV, Request<Record<string, unknown>>, Response<Record<string, unknown>>, MiddlewareNext>;
|
74
39
|
}
|
75
40
|
|
76
41
|
type App<SV extends AnySchemaValidator> = Application<SV>;
|
@@ -92,4 +57,17 @@ declare function forklaunchExpress<SV extends AnySchemaValidator>(schemaValidato
|
|
92
57
|
*/
|
93
58
|
declare function forklaunchRouter<SV extends AnySchemaValidator, BasePath extends `/${string}`>(basePath: BasePath, schemaValidator: SV): Router<SV, BasePath>;
|
94
59
|
|
95
|
-
|
60
|
+
declare const handlers: {
|
61
|
+
any: <SV extends AnySchemaValidator, Path extends `/${string}`, P extends _forklaunch_core_http.ParamsObject<SV>, ResBodyMap extends _forklaunch_core_http.ResponsesObject<SV>, ReqBody extends _forklaunch_core_http.Body<SV>, ReqQuery extends _forklaunch_core_http.QueryObject<SV>, ReqHeaders extends _forklaunch_core_http.HeadersObject<SV>, ResHeaders extends _forklaunch_core_http.HeadersObject<SV>, LocalsObj extends Record<string, unknown>>(schemaValidator: SV, path: Path, contractDetails: _forklaunch_core_http.ContractDetails<SV, "middleware", Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, _forklaunch_hyper_express_fork.Request<LocalsObj>>, ...handlers: _forklaunch_core_http.ExpressLikeSchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, _forklaunch_hyper_express_fork.Request<LocalsObj>, _forklaunch_hyper_express_fork.Response<LocalsObj>, _forklaunch_hyper_express_fork.MiddlewareNext>[]) => _forklaunch_core_http.ExpressLikeTypedHandler<SV, "middleware", Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, _forklaunch_hyper_express_fork.Request<LocalsObj>, _forklaunch_hyper_express_fork.Response<LocalsObj>, _forklaunch_hyper_express_fork.MiddlewareNext>;
|
62
|
+
delete: <SV extends AnySchemaValidator, Path extends `/${string}`, P extends _forklaunch_core_http.ParamsObject<SV>, ResBodyMap extends _forklaunch_core_http.ResponsesObject<SV>, ReqBody extends _forklaunch_core_http.Body<SV>, ReqQuery extends _forklaunch_core_http.QueryObject<SV>, ReqHeaders extends _forklaunch_core_http.HeadersObject<SV>, ResHeaders extends _forklaunch_core_http.HeadersObject<SV>, LocalsObj extends Record<string, unknown>>(schemaValidator: SV, path: Path, contractDetails: _forklaunch_core_http.ContractDetails<SV, "delete", Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, _forklaunch_hyper_express_fork.Request<LocalsObj>>, ...handlers: _forklaunch_core_http.ExpressLikeSchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, _forklaunch_hyper_express_fork.Request<LocalsObj>, _forklaunch_hyper_express_fork.Response<LocalsObj>, _forklaunch_hyper_express_fork.MiddlewareNext>[]) => _forklaunch_core_http.ExpressLikeTypedHandler<SV, "delete", Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, _forklaunch_hyper_express_fork.Request<LocalsObj>, _forklaunch_hyper_express_fork.Response<LocalsObj>, _forklaunch_hyper_express_fork.MiddlewareNext>;
|
63
|
+
get: <SV extends AnySchemaValidator, Path extends `/${string}`, P extends _forklaunch_core_http.ParamsObject<SV>, ResBodyMap extends _forklaunch_core_http.ResponsesObject<SV>, ReqBody extends _forklaunch_core_http.Body<SV>, ReqQuery extends _forklaunch_core_http.QueryObject<SV>, ReqHeaders extends _forklaunch_core_http.HeadersObject<SV>, ResHeaders extends _forklaunch_core_http.HeadersObject<SV>, LocalsObj extends Record<string, unknown>>(schemaValidator: SV, path: Path, contractDetails: _forklaunch_core_http.ContractDetails<SV, "get", Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, _forklaunch_hyper_express_fork.Request<LocalsObj>>, ...handlers: _forklaunch_core_http.ExpressLikeSchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, _forklaunch_hyper_express_fork.Request<LocalsObj>, _forklaunch_hyper_express_fork.Response<LocalsObj>, _forklaunch_hyper_express_fork.MiddlewareNext>[]) => _forklaunch_core_http.ExpressLikeTypedHandler<SV, "get", Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, _forklaunch_hyper_express_fork.Request<LocalsObj>, _forklaunch_hyper_express_fork.Response<LocalsObj>, _forklaunch_hyper_express_fork.MiddlewareNext>;
|
64
|
+
head: <SV extends AnySchemaValidator, Path extends `/${string}`, P extends _forklaunch_core_http.ParamsObject<SV>, ResBodyMap extends _forklaunch_core_http.ResponsesObject<SV>, ReqBody extends _forklaunch_core_http.Body<SV>, ReqQuery extends _forklaunch_core_http.QueryObject<SV>, ReqHeaders extends _forklaunch_core_http.HeadersObject<SV>, ResHeaders extends _forklaunch_core_http.HeadersObject<SV>, LocalsObj extends Record<string, unknown>>(schemaValidator: SV, path: Path, contractDetails: _forklaunch_core_http.ContractDetails<SV, "head", Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, _forklaunch_hyper_express_fork.Request<LocalsObj>>, ...handlers: _forklaunch_core_http.ExpressLikeSchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, _forklaunch_hyper_express_fork.Request<LocalsObj>, _forklaunch_hyper_express_fork.Response<LocalsObj>, _forklaunch_hyper_express_fork.MiddlewareNext>[]) => _forklaunch_core_http.ExpressLikeTypedHandler<SV, "head", Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, _forklaunch_hyper_express_fork.Request<LocalsObj>, _forklaunch_hyper_express_fork.Response<LocalsObj>, _forklaunch_hyper_express_fork.MiddlewareNext>;
|
65
|
+
middleware: <SV extends AnySchemaValidator, Path extends `/${string}`, P extends _forklaunch_core_http.ParamsObject<SV>, ResBodyMap extends _forklaunch_core_http.ResponsesObject<SV>, ReqBody extends _forklaunch_core_http.Body<SV>, ReqQuery extends _forklaunch_core_http.QueryObject<SV>, ReqHeaders extends _forklaunch_core_http.HeadersObject<SV>, ResHeaders extends _forklaunch_core_http.HeadersObject<SV>, LocalsObj extends Record<string, unknown>>(schemaValidator: SV, path: Path, contractDetails: _forklaunch_core_http.ContractDetails<SV, "middleware", Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, _forklaunch_hyper_express_fork.Request<LocalsObj>>, ...handlers: _forklaunch_core_http.ExpressLikeSchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, _forklaunch_hyper_express_fork.Request<LocalsObj>, _forklaunch_hyper_express_fork.Response<LocalsObj>, _forklaunch_hyper_express_fork.MiddlewareNext>[]) => _forklaunch_core_http.ExpressLikeTypedHandler<SV, "middleware", Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, _forklaunch_hyper_express_fork.Request<LocalsObj>, _forklaunch_hyper_express_fork.Response<LocalsObj>, _forklaunch_hyper_express_fork.MiddlewareNext>;
|
66
|
+
options: <SV extends AnySchemaValidator, Path extends `/${string}`, P extends _forklaunch_core_http.ParamsObject<SV>, ResBodyMap extends _forklaunch_core_http.ResponsesObject<SV>, ReqBody extends _forklaunch_core_http.Body<SV>, ReqQuery extends _forklaunch_core_http.QueryObject<SV>, ReqHeaders extends _forklaunch_core_http.HeadersObject<SV>, ResHeaders extends _forklaunch_core_http.HeadersObject<SV>, LocalsObj extends Record<string, unknown>>(schemaValidator: SV, path: Path, contractDetails: _forklaunch_core_http.ContractDetails<SV, "options", Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, _forklaunch_hyper_express_fork.Request<LocalsObj>>, ...handlers: _forklaunch_core_http.ExpressLikeSchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, _forklaunch_hyper_express_fork.Request<LocalsObj>, _forklaunch_hyper_express_fork.Response<LocalsObj>, _forklaunch_hyper_express_fork.MiddlewareNext>[]) => _forklaunch_core_http.ExpressLikeTypedHandler<SV, "options", Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, _forklaunch_hyper_express_fork.Request<LocalsObj>, _forklaunch_hyper_express_fork.Response<LocalsObj>, _forklaunch_hyper_express_fork.MiddlewareNext>;
|
67
|
+
patch: <SV extends AnySchemaValidator, Path extends `/${string}`, P extends _forklaunch_core_http.ParamsObject<SV>, ResBodyMap extends _forklaunch_core_http.ResponsesObject<SV>, ReqBody extends _forklaunch_core_http.Body<SV>, ReqQuery extends _forklaunch_core_http.QueryObject<SV>, ReqHeaders extends _forklaunch_core_http.HeadersObject<SV>, ResHeaders extends _forklaunch_core_http.HeadersObject<SV>, LocalsObj extends Record<string, unknown>>(schemaValidator: SV, path: Path, contractDetails: _forklaunch_core_http.ContractDetails<SV, "patch", Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, _forklaunch_hyper_express_fork.Request<LocalsObj>>, ...handlers: _forklaunch_core_http.ExpressLikeSchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, _forklaunch_hyper_express_fork.Request<LocalsObj>, _forklaunch_hyper_express_fork.Response<LocalsObj>, _forklaunch_hyper_express_fork.MiddlewareNext>[]) => _forklaunch_core_http.ExpressLikeTypedHandler<SV, "patch", Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, _forklaunch_hyper_express_fork.Request<LocalsObj>, _forklaunch_hyper_express_fork.Response<LocalsObj>, _forklaunch_hyper_express_fork.MiddlewareNext>;
|
68
|
+
post: <SV extends AnySchemaValidator, Path extends `/${string}`, P extends _forklaunch_core_http.ParamsObject<SV>, ResBodyMap extends _forklaunch_core_http.ResponsesObject<SV>, ReqBody extends _forklaunch_core_http.Body<SV>, ReqQuery extends _forklaunch_core_http.QueryObject<SV>, ReqHeaders extends _forklaunch_core_http.HeadersObject<SV>, ResHeaders extends _forklaunch_core_http.HeadersObject<SV>, LocalsObj extends Record<string, unknown>>(schemaValidator: SV, path: Path, contractDetails: _forklaunch_core_http.ContractDetails<SV, "post", Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, _forklaunch_hyper_express_fork.Request<LocalsObj>>, ...handlers: _forklaunch_core_http.ExpressLikeSchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, _forklaunch_hyper_express_fork.Request<LocalsObj>, _forklaunch_hyper_express_fork.Response<LocalsObj>, _forklaunch_hyper_express_fork.MiddlewareNext>[]) => _forklaunch_core_http.ExpressLikeTypedHandler<SV, "post", Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, _forklaunch_hyper_express_fork.Request<LocalsObj>, _forklaunch_hyper_express_fork.Response<LocalsObj>, _forklaunch_hyper_express_fork.MiddlewareNext>;
|
69
|
+
put: <SV extends AnySchemaValidator, Path extends `/${string}`, P extends _forklaunch_core_http.ParamsObject<SV>, ResBodyMap extends _forklaunch_core_http.ResponsesObject<SV>, ReqBody extends _forklaunch_core_http.Body<SV>, ReqQuery extends _forklaunch_core_http.QueryObject<SV>, ReqHeaders extends _forklaunch_core_http.HeadersObject<SV>, ResHeaders extends _forklaunch_core_http.HeadersObject<SV>, LocalsObj extends Record<string, unknown>>(schemaValidator: SV, path: Path, contractDetails: _forklaunch_core_http.ContractDetails<SV, "put", Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, _forklaunch_hyper_express_fork.Request<LocalsObj>>, ...handlers: _forklaunch_core_http.ExpressLikeSchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, _forklaunch_hyper_express_fork.Request<LocalsObj>, _forklaunch_hyper_express_fork.Response<LocalsObj>, _forklaunch_hyper_express_fork.MiddlewareNext>[]) => _forklaunch_core_http.ExpressLikeTypedHandler<SV, "put", Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, _forklaunch_hyper_express_fork.Request<LocalsObj>, _forklaunch_hyper_express_fork.Response<LocalsObj>, _forklaunch_hyper_express_fork.MiddlewareNext>;
|
70
|
+
trace: <SV extends AnySchemaValidator, Path extends `/${string}`, P extends _forklaunch_core_http.ParamsObject<SV>, ResBodyMap extends _forklaunch_core_http.ResponsesObject<SV>, ReqBody extends _forklaunch_core_http.Body<SV>, ReqQuery extends _forklaunch_core_http.QueryObject<SV>, ReqHeaders extends _forklaunch_core_http.HeadersObject<SV>, ResHeaders extends _forklaunch_core_http.HeadersObject<SV>, LocalsObj extends Record<string, unknown>>(schemaValidator: SV, path: Path, contractDetails: _forklaunch_core_http.ContractDetails<SV, "trace", Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, _forklaunch_hyper_express_fork.Request<LocalsObj>>, ...handlers: _forklaunch_core_http.ExpressLikeSchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, _forklaunch_hyper_express_fork.Request<LocalsObj>, _forklaunch_hyper_express_fork.Response<LocalsObj>, _forklaunch_hyper_express_fork.MiddlewareNext>[]) => _forklaunch_core_http.ExpressLikeTypedHandler<SV, "trace", Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, _forklaunch_hyper_express_fork.Request<LocalsObj>, _forklaunch_hyper_express_fork.Response<LocalsObj>, _forklaunch_hyper_express_fork.MiddlewareNext>;
|
71
|
+
};
|
72
|
+
|
73
|
+
export { type App, Application, Router, forklaunchExpress, forklaunchRouter, handlers };
|
package/lib/index.js
CHANGED
@@ -31,12 +31,73 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
31
31
|
var index_exports = {};
|
32
32
|
__export(index_exports, {
|
33
33
|
forklaunchExpress: () => forklaunchExpress,
|
34
|
-
forklaunchRouter: () => forklaunchRouter
|
34
|
+
forklaunchRouter: () => forklaunchRouter,
|
35
|
+
handlers: () => handlers
|
35
36
|
});
|
36
37
|
module.exports = __toCommonJS(index_exports);
|
37
38
|
|
38
|
-
// src/
|
39
|
+
// src/handlers/any.ts
|
39
40
|
var import_http = require("@forklaunch/core/http");
|
41
|
+
var any = (schemaValidator, path, contractDetails, ...handlers2) => {
|
42
|
+
return (0, import_http.typedHandler)(schemaValidator, path, "middleware", contractDetails, ...handlers2);
|
43
|
+
};
|
44
|
+
|
45
|
+
// src/handlers/delete.ts
|
46
|
+
var import_http2 = require("@forklaunch/core/http");
|
47
|
+
var delete_ = (schemaValidator, path, contractDetails, ...handlers2) => {
|
48
|
+
return (0, import_http2.delete_)(schemaValidator, path, contractDetails, ...handlers2);
|
49
|
+
};
|
50
|
+
|
51
|
+
// src/handlers/get.ts
|
52
|
+
var import_http3 = require("@forklaunch/core/http");
|
53
|
+
var get = (schemaValidator, path, contractDetails, ...handlers2) => {
|
54
|
+
return (0, import_http3.get)(schemaValidator, path, contractDetails, ...handlers2);
|
55
|
+
};
|
56
|
+
|
57
|
+
// src/handlers/head.ts
|
58
|
+
var import_http4 = require("@forklaunch/core/http");
|
59
|
+
var head = (schemaValidator, path, contractDetails, ...handlers2) => {
|
60
|
+
return (0, import_http4.head)(schemaValidator, path, contractDetails, ...handlers2);
|
61
|
+
};
|
62
|
+
|
63
|
+
// src/handlers/middleware.ts
|
64
|
+
var import_http5 = require("@forklaunch/core/http");
|
65
|
+
var middleware = (schemaValidator, path, contractDetails, ...handlers2) => {
|
66
|
+
return (0, import_http5.middleware)(schemaValidator, path, contractDetails, ...handlers2);
|
67
|
+
};
|
68
|
+
|
69
|
+
// src/handlers/options.ts
|
70
|
+
var import_http6 = require("@forklaunch/core/http");
|
71
|
+
var options = (schemaValidator, path, contractDetails, ...handlers2) => {
|
72
|
+
return (0, import_http6.options)(schemaValidator, path, contractDetails, ...handlers2);
|
73
|
+
};
|
74
|
+
|
75
|
+
// src/handlers/patch.ts
|
76
|
+
var import_http7 = require("@forklaunch/core/http");
|
77
|
+
var patch = (schemaValidator, path, contractDetails, ...handlers2) => {
|
78
|
+
return (0, import_http7.patch)(schemaValidator, path, contractDetails, ...handlers2);
|
79
|
+
};
|
80
|
+
|
81
|
+
// src/handlers/post.ts
|
82
|
+
var import_http8 = require("@forklaunch/core/http");
|
83
|
+
var post = (schemaValidator, path, contractDetails, ...handlers2) => {
|
84
|
+
return (0, import_http8.post)(schemaValidator, path, contractDetails, ...handlers2);
|
85
|
+
};
|
86
|
+
|
87
|
+
// src/handlers/put.ts
|
88
|
+
var import_http9 = require("@forklaunch/core/http");
|
89
|
+
var put = (schemaValidator, path, contractDetails, ...handlers2) => {
|
90
|
+
return (0, import_http9.put)(schemaValidator, path, contractDetails, ...handlers2);
|
91
|
+
};
|
92
|
+
|
93
|
+
// src/handlers/trace.ts
|
94
|
+
var import_http10 = require("@forklaunch/core/http");
|
95
|
+
var trace = (schemaValidator, path, contractDetails, ...handlers2) => {
|
96
|
+
return (0, import_http10.trace)(schemaValidator, path, contractDetails, ...handlers2);
|
97
|
+
};
|
98
|
+
|
99
|
+
// src/hyperExpressApplication.ts
|
100
|
+
var import_http11 = require("@forklaunch/core/http");
|
40
101
|
var import_hyper_express_fork = require("@forklaunch/hyper-express-fork");
|
41
102
|
|
42
103
|
// src/middleware/swagger.middleware.ts
|
@@ -51,7 +112,7 @@ function swaggerRedirect(path) {
|
|
51
112
|
return next?.();
|
52
113
|
};
|
53
114
|
}
|
54
|
-
function swagger(path, document, opts,
|
115
|
+
function swagger(path, document, opts, options2, customCss, customfavIcon, swaggerUrl, customSiteTitle) {
|
55
116
|
const LiveAssets = new import_live_directory.default((0, import_absolute_path.default)(), {
|
56
117
|
filter: {
|
57
118
|
keep: {
|
@@ -88,7 +149,7 @@ function swagger(path, document, opts, options, customCss, customfavIcon, swagge
|
|
88
149
|
const ui = import_swagger_ui_express.default.setup(
|
89
150
|
document,
|
90
151
|
opts,
|
91
|
-
|
152
|
+
options2,
|
92
153
|
customCss,
|
93
154
|
customfavIcon,
|
94
155
|
swaggerUrl,
|
@@ -98,7 +159,7 @@ function swagger(path, document, opts, options, customCss, customfavIcon, swagge
|
|
98
159
|
}
|
99
160
|
|
100
161
|
// src/hyperExpressApplication.ts
|
101
|
-
var Application = class extends
|
162
|
+
var Application = class extends import_http11.ForklaunchExpressLikeApplication {
|
102
163
|
/**
|
103
164
|
* Creates an instance of the Application class.
|
104
165
|
*
|
@@ -114,29 +175,21 @@ var Application = class extends import_http.ForklaunchExpressLikeApplication {
|
|
114
175
|
res.locals.errorMessage = err.message;
|
115
176
|
res.status(
|
116
177
|
res.statusCode && res.statusCode >= 400 ? res.statusCode : 500
|
117
|
-
).send(
|
178
|
+
).send(
|
179
|
+
`Internal server error:
|
118
180
|
|
119
|
-
${
|
120
|
-
(0, import_http.emitLoggerError)(
|
121
|
-
{
|
122
|
-
contractDetails: { name: "unknown" },
|
123
|
-
originalPath: req.path,
|
124
|
-
...req,
|
125
|
-
method: req.method,
|
126
|
-
path: req.path
|
127
|
-
},
|
128
|
-
{
|
129
|
-
statusCode: res.statusCode ?? 500
|
130
|
-
},
|
131
|
-
err.stack ?? err.message
|
181
|
+
${(0, import_http11.isForklaunchRequest)(req) ? req.context.correlationId : "No correlation ID"}`
|
132
182
|
);
|
183
|
+
(0, import_http11.logger)("error").error(err.stack ?? err.message, {
|
184
|
+
[import_http11.ATTR_HTTP_RESPONSE_STATUS_CODE]: res.statusCode ?? 500
|
185
|
+
});
|
133
186
|
});
|
134
187
|
const { apiReference } = await import("@scalar/express-api-reference");
|
135
188
|
this.internal.use(
|
136
189
|
`/api/${process.env.VERSION ?? "v1"}${process.env.DOCS_PATH ?? "/docs"}`,
|
137
190
|
apiReference({
|
138
191
|
spec: {
|
139
|
-
content: (0,
|
192
|
+
content: (0, import_http11.generateSwaggerDocument)(
|
140
193
|
this.schemaValidator,
|
141
194
|
port,
|
142
195
|
this.routers
|
@@ -146,14 +199,13 @@ ${err.message}`);
|
|
146
199
|
layout: "modern"
|
147
200
|
})
|
148
201
|
);
|
149
|
-
const swaggerPath = `/api/${process.env.VERSION ?? "v1"}${
|
150
|
-
"/swagger"}`;
|
202
|
+
const swaggerPath = `/api/${process.env.VERSION ?? "v1"}${"/swagger"}`;
|
151
203
|
this.internal.use(swaggerPath, swaggerRedirect(swaggerPath));
|
152
204
|
this.internal.get(
|
153
205
|
`${swaggerPath}/*`,
|
154
206
|
swagger(
|
155
207
|
swaggerPath,
|
156
|
-
(0,
|
208
|
+
(0, import_http11.generateSwaggerDocument)(this.schemaValidator, port, this.routers)
|
157
209
|
)
|
158
210
|
);
|
159
211
|
if (arg1 && typeof arg1 === "string") {
|
@@ -170,7 +222,7 @@ ${err.message}`);
|
|
170
222
|
};
|
171
223
|
|
172
224
|
// src/hyperExpressRouter.ts
|
173
|
-
var
|
225
|
+
var import_http13 = require("@forklaunch/core/http");
|
174
226
|
var import_hyper_express_fork2 = require("@forklaunch/hyper-express-fork");
|
175
227
|
|
176
228
|
// src/middleware/contentParse.middleware.ts
|
@@ -213,7 +265,7 @@ async function contentParse(req) {
|
|
213
265
|
}
|
214
266
|
|
215
267
|
// src/middleware/enrichResponseTransmission.middleware.ts
|
216
|
-
var
|
268
|
+
var import_http12 = require("@forklaunch/core/http");
|
217
269
|
function enrichResponseTransmission(req, res, next) {
|
218
270
|
const originalSend = res.send;
|
219
271
|
const originalJson = res.json;
|
@@ -221,8 +273,7 @@ function enrichResponseTransmission(req, res, next) {
|
|
221
273
|
res.json = function(data) {
|
222
274
|
res.bodyData = data;
|
223
275
|
res.statusCode = res._status_code;
|
224
|
-
(0,
|
225
|
-
(0, import_http2.enrichExpressLikeSend)(
|
276
|
+
(0, import_http12.enrichExpressLikeSend)(
|
226
277
|
this,
|
227
278
|
req,
|
228
279
|
res,
|
@@ -237,8 +288,7 @@ function enrichResponseTransmission(req, res, next) {
|
|
237
288
|
res.bodyData = data;
|
238
289
|
res.statusCode = res._status_code;
|
239
290
|
}
|
240
|
-
(0,
|
241
|
-
return (0, import_http2.enrichExpressLikeSend)(
|
291
|
+
return (0, import_http12.enrichExpressLikeSend)(
|
242
292
|
this,
|
243
293
|
req,
|
244
294
|
res,
|
@@ -270,7 +320,7 @@ function polyfillGetHeaders(_req, res, next) {
|
|
270
320
|
}
|
271
321
|
|
272
322
|
// src/hyperExpressRouter.ts
|
273
|
-
var Router = class extends
|
323
|
+
var Router = class extends import_http13.ForklaunchExpressLikeRouter {
|
274
324
|
constructor(basePath, schemaValidator) {
|
275
325
|
super(basePath, schemaValidator, new import_hyper_express_fork2.Router());
|
276
326
|
this.basePath = basePath;
|
@@ -305,8 +355,21 @@ function forklaunchRouter(basePath, schemaValidator) {
|
|
305
355
|
const router = new Router(basePath, schemaValidator);
|
306
356
|
return router;
|
307
357
|
}
|
358
|
+
var handlers = {
|
359
|
+
any,
|
360
|
+
delete: delete_,
|
361
|
+
get,
|
362
|
+
head,
|
363
|
+
middleware,
|
364
|
+
options,
|
365
|
+
patch,
|
366
|
+
post,
|
367
|
+
put,
|
368
|
+
trace
|
369
|
+
};
|
308
370
|
// Annotate the CommonJS export names for ESM import in node:
|
309
371
|
0 && (module.exports = {
|
310
372
|
forklaunchExpress,
|
311
|
-
forklaunchRouter
|
373
|
+
forklaunchRouter,
|
374
|
+
handlers
|
312
375
|
});
|
package/lib/index.mjs
CHANGED
@@ -1,10 +1,94 @@
|
|
1
|
+
// src/handlers/any.ts
|
2
|
+
import {
|
3
|
+
typedHandler
|
4
|
+
} from "@forklaunch/core/http";
|
5
|
+
var any = (schemaValidator, path, contractDetails, ...handlers2) => {
|
6
|
+
return typedHandler(schemaValidator, path, "middleware", contractDetails, ...handlers2);
|
7
|
+
};
|
8
|
+
|
9
|
+
// src/handlers/delete.ts
|
10
|
+
import {
|
11
|
+
delete_ as innerDelete
|
12
|
+
} from "@forklaunch/core/http";
|
13
|
+
var delete_ = (schemaValidator, path, contractDetails, ...handlers2) => {
|
14
|
+
return innerDelete(schemaValidator, path, contractDetails, ...handlers2);
|
15
|
+
};
|
16
|
+
|
17
|
+
// src/handlers/get.ts
|
18
|
+
import {
|
19
|
+
get as innerGet
|
20
|
+
} from "@forklaunch/core/http";
|
21
|
+
var get = (schemaValidator, path, contractDetails, ...handlers2) => {
|
22
|
+
return innerGet(schemaValidator, path, contractDetails, ...handlers2);
|
23
|
+
};
|
24
|
+
|
25
|
+
// src/handlers/head.ts
|
26
|
+
import {
|
27
|
+
head as innerHead
|
28
|
+
} from "@forklaunch/core/http";
|
29
|
+
var head = (schemaValidator, path, contractDetails, ...handlers2) => {
|
30
|
+
return innerHead(schemaValidator, path, contractDetails, ...handlers2);
|
31
|
+
};
|
32
|
+
|
33
|
+
// src/handlers/middleware.ts
|
34
|
+
import {
|
35
|
+
middleware as innerMiddleware
|
36
|
+
} from "@forklaunch/core/http";
|
37
|
+
var middleware = (schemaValidator, path, contractDetails, ...handlers2) => {
|
38
|
+
return innerMiddleware(schemaValidator, path, contractDetails, ...handlers2);
|
39
|
+
};
|
40
|
+
|
41
|
+
// src/handlers/options.ts
|
42
|
+
import {
|
43
|
+
options as innerOptions
|
44
|
+
} from "@forklaunch/core/http";
|
45
|
+
var options = (schemaValidator, path, contractDetails, ...handlers2) => {
|
46
|
+
return innerOptions(schemaValidator, path, contractDetails, ...handlers2);
|
47
|
+
};
|
48
|
+
|
49
|
+
// src/handlers/patch.ts
|
50
|
+
import {
|
51
|
+
patch as innerPatch
|
52
|
+
} from "@forklaunch/core/http";
|
53
|
+
var patch = (schemaValidator, path, contractDetails, ...handlers2) => {
|
54
|
+
return innerPatch(schemaValidator, path, contractDetails, ...handlers2);
|
55
|
+
};
|
56
|
+
|
57
|
+
// src/handlers/post.ts
|
58
|
+
import {
|
59
|
+
post as innerPost
|
60
|
+
} from "@forklaunch/core/http";
|
61
|
+
var post = (schemaValidator, path, contractDetails, ...handlers2) => {
|
62
|
+
return innerPost(schemaValidator, path, contractDetails, ...handlers2);
|
63
|
+
};
|
64
|
+
|
65
|
+
// src/handlers/put.ts
|
66
|
+
import {
|
67
|
+
put as innerPut
|
68
|
+
} from "@forklaunch/core/http";
|
69
|
+
var put = (schemaValidator, path, contractDetails, ...handlers2) => {
|
70
|
+
return innerPut(schemaValidator, path, contractDetails, ...handlers2);
|
71
|
+
};
|
72
|
+
|
73
|
+
// src/handlers/trace.ts
|
74
|
+
import {
|
75
|
+
trace as innerTrace
|
76
|
+
} from "@forklaunch/core/http";
|
77
|
+
var trace = (schemaValidator, path, contractDetails, ...handlers2) => {
|
78
|
+
return innerTrace(schemaValidator, path, contractDetails, ...handlers2);
|
79
|
+
};
|
80
|
+
|
1
81
|
// src/hyperExpressApplication.ts
|
2
82
|
import {
|
3
|
-
|
83
|
+
ATTR_HTTP_RESPONSE_STATUS_CODE,
|
4
84
|
ForklaunchExpressLikeApplication,
|
5
|
-
generateSwaggerDocument
|
85
|
+
generateSwaggerDocument,
|
86
|
+
isForklaunchRequest,
|
87
|
+
logger
|
6
88
|
} from "@forklaunch/core/http";
|
7
|
-
import {
|
89
|
+
import {
|
90
|
+
Server
|
91
|
+
} from "@forklaunch/hyper-express-fork";
|
8
92
|
|
9
93
|
// src/middleware/swagger.middleware.ts
|
10
94
|
import LiveDirectory from "live-directory";
|
@@ -18,7 +102,7 @@ function swaggerRedirect(path) {
|
|
18
102
|
return next?.();
|
19
103
|
};
|
20
104
|
}
|
21
|
-
function swagger(path, document, opts,
|
105
|
+
function swagger(path, document, opts, options2, customCss, customfavIcon, swaggerUrl, customSiteTitle) {
|
22
106
|
const LiveAssets = new LiveDirectory(getAbsoluteSwaggerFsPath(), {
|
23
107
|
filter: {
|
24
108
|
keep: {
|
@@ -55,7 +139,7 @@ function swagger(path, document, opts, options, customCss, customfavIcon, swagge
|
|
55
139
|
const ui = swaggerUi.setup(
|
56
140
|
document,
|
57
141
|
opts,
|
58
|
-
|
142
|
+
options2,
|
59
143
|
customCss,
|
60
144
|
customfavIcon,
|
61
145
|
swaggerUrl,
|
@@ -81,22 +165,14 @@ var Application = class extends ForklaunchExpressLikeApplication {
|
|
81
165
|
res.locals.errorMessage = err.message;
|
82
166
|
res.status(
|
83
167
|
res.statusCode && res.statusCode >= 400 ? res.statusCode : 500
|
84
|
-
).send(
|
168
|
+
).send(
|
169
|
+
`Internal server error:
|
85
170
|
|
86
|
-
${
|
87
|
-
emitLoggerError(
|
88
|
-
{
|
89
|
-
contractDetails: { name: "unknown" },
|
90
|
-
originalPath: req.path,
|
91
|
-
...req,
|
92
|
-
method: req.method,
|
93
|
-
path: req.path
|
94
|
-
},
|
95
|
-
{
|
96
|
-
statusCode: res.statusCode ?? 500
|
97
|
-
},
|
98
|
-
err.stack ?? err.message
|
171
|
+
${isForklaunchRequest(req) ? req.context.correlationId : "No correlation ID"}`
|
99
172
|
);
|
173
|
+
logger("error").error(err.stack ?? err.message, {
|
174
|
+
[ATTR_HTTP_RESPONSE_STATUS_CODE]: res.statusCode ?? 500
|
175
|
+
});
|
100
176
|
});
|
101
177
|
const { apiReference } = await import("@scalar/express-api-reference");
|
102
178
|
this.internal.use(
|
@@ -113,8 +189,7 @@ ${err.message}`);
|
|
113
189
|
layout: "modern"
|
114
190
|
})
|
115
191
|
);
|
116
|
-
const swaggerPath = `/api/${process.env.VERSION ?? "v1"}${
|
117
|
-
"/swagger"}`;
|
192
|
+
const swaggerPath = `/api/${process.env.VERSION ?? "v1"}${"/swagger"}`;
|
118
193
|
this.internal.use(swaggerPath, swaggerRedirect(swaggerPath));
|
119
194
|
this.internal.get(
|
120
195
|
`${swaggerPath}/*`,
|
@@ -185,8 +260,7 @@ async function contentParse(req) {
|
|
185
260
|
|
186
261
|
// src/middleware/enrichResponseTransmission.middleware.ts
|
187
262
|
import {
|
188
|
-
enrichExpressLikeSend
|
189
|
-
recordMetric
|
263
|
+
enrichExpressLikeSend
|
190
264
|
} from "@forklaunch/core/http";
|
191
265
|
function enrichResponseTransmission(req, res, next) {
|
192
266
|
const originalSend = res.send;
|
@@ -195,7 +269,6 @@ function enrichResponseTransmission(req, res, next) {
|
|
195
269
|
res.json = function(data) {
|
196
270
|
res.bodyData = data;
|
197
271
|
res.statusCode = res._status_code;
|
198
|
-
recordMetric(req, res);
|
199
272
|
enrichExpressLikeSend(
|
200
273
|
this,
|
201
274
|
req,
|
@@ -211,7 +284,6 @@ function enrichResponseTransmission(req, res, next) {
|
|
211
284
|
res.bodyData = data;
|
212
285
|
res.statusCode = res._status_code;
|
213
286
|
}
|
214
|
-
recordMetric(req, res);
|
215
287
|
return enrichExpressLikeSend(
|
216
288
|
this,
|
217
289
|
req,
|
@@ -279,7 +351,20 @@ function forklaunchRouter(basePath, schemaValidator) {
|
|
279
351
|
const router = new Router(basePath, schemaValidator);
|
280
352
|
return router;
|
281
353
|
}
|
354
|
+
var handlers = {
|
355
|
+
any,
|
356
|
+
delete: delete_,
|
357
|
+
get,
|
358
|
+
head,
|
359
|
+
middleware,
|
360
|
+
options,
|
361
|
+
patch,
|
362
|
+
post,
|
363
|
+
put,
|
364
|
+
trace
|
365
|
+
};
|
282
366
|
export {
|
283
367
|
forklaunchExpress,
|
284
|
-
forklaunchRouter
|
368
|
+
forklaunchRouter,
|
369
|
+
handlers
|
285
370
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@forklaunch/hyper-express",
|
3
|
-
"version": "0.3.
|
3
|
+
"version": "0.3.2",
|
4
4
|
"description": "Forklaunch framework for hyper-express.",
|
5
5
|
"homepage": "https://github.com/forklaunch/forklaunch-js#readme",
|
6
6
|
"bugs": {
|
@@ -26,7 +26,7 @@
|
|
26
26
|
],
|
27
27
|
"dependencies": {
|
28
28
|
"@forklaunch/hyper-express-fork": "^6.17.30",
|
29
|
-
"@scalar/express-api-reference": "^0.4.
|
29
|
+
"@scalar/express-api-reference": "^0.4.192",
|
30
30
|
"cors": "^2.8.5",
|
31
31
|
"live-directory": "^3.0.3",
|
32
32
|
"openapi3-ts": "^4.4.0",
|
@@ -34,12 +34,12 @@
|
|
34
34
|
"swagger-ui-dist": "^5.20.0",
|
35
35
|
"swagger-ui-express": "^5.0.1",
|
36
36
|
"uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.44.0",
|
37
|
-
"@forklaunch/common": "0.2.
|
38
|
-
"@forklaunch/
|
39
|
-
"@forklaunch/
|
37
|
+
"@forklaunch/common": "0.2.2",
|
38
|
+
"@forklaunch/validator": "0.4.5",
|
39
|
+
"@forklaunch/core": "0.5.1"
|
40
40
|
},
|
41
41
|
"devDependencies": {
|
42
|
-
"@eslint/js": "^9.
|
42
|
+
"@eslint/js": "^9.22.0",
|
43
43
|
"@types/cors": "^2.8.17",
|
44
44
|
"@types/jest": "^29.5.14",
|
45
45
|
"@types/qs": "^6.9.18",
|
@@ -47,13 +47,13 @@
|
|
47
47
|
"@types/swagger-ui-express": "^4.1.8",
|
48
48
|
"jest": "^29.7.0",
|
49
49
|
"kill-port-process": "^3.2.1",
|
50
|
-
"prettier": "^3.5.
|
50
|
+
"prettier": "^3.5.3",
|
51
51
|
"ts-jest": "^29.2.6",
|
52
52
|
"ts-node": "^10.9.2",
|
53
53
|
"tsup": "^8.4.0",
|
54
54
|
"tsx": "^4.19.3",
|
55
55
|
"typescript": "^5.8.2",
|
56
|
-
"typescript-eslint": "^8.
|
56
|
+
"typescript-eslint": "^8.26.0"
|
57
57
|
},
|
58
58
|
"scripts": {
|
59
59
|
"build": "tsc --noEmit && tsup index.ts --format cjs,esm --no-splitting --dts --tsconfig tsconfig.json --out-dir lib --clean",
|