@forklaunch/express 0.1.32 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.mts +118 -0
- package/lib/index.d.ts +103 -9
- package/lib/index.js +301 -23
- package/lib/index.mjs +270 -0
- package/package.json +30 -27
- package/lib/index.d.ts.map +0 -1
- package/lib/src/expressApplication.d.ts +0 -30
- package/lib/src/expressApplication.d.ts.map +0 -1
- package/lib/src/expressApplication.js +0 -32
- package/lib/src/expressRouter.d.ts +0 -46
- package/lib/src/expressRouter.d.ts.map +0 -1
- package/lib/src/expressRouter.js +0 -92
- package/lib/src/middleware/async.middleware.d.ts +0 -16
- package/lib/src/middleware/async.middleware.d.ts.map +0 -1
- package/lib/src/middleware/async.middleware.js +0 -19
- package/lib/src/middleware/response.middleware.d.ts +0 -15
- package/lib/src/middleware/response.middleware.d.ts.map +0 -1
- package/lib/src/middleware/response.middleware.js +0 -54
- package/lib/src/types/express.types.d.ts +0 -28
- package/lib/src/types/express.types.d.ts.map +0 -1
- package/lib/src/types/express.types.js +0 -1
- package/lib/tests/typebox.forklaunch.express.test.d.ts +0 -2
- package/lib/tests/typebox.forklaunch.express.test.d.ts.map +0 -1
- package/lib/tests/typebox.forklaunch.express.test.js +0 -110
- package/lib/tests/zod.forklaunch.express.test.d.ts +0 -2
- package/lib/tests/zod.forklaunch.express.test.d.ts.map +0 -1
- package/lib/tests/zod.forklaunch.express.test.js +0 -110
- 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.d.mts
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
import { AnySchemaValidator, LiteralSchema, IdiomaticSchema, SchemaResolve } from '@forklaunch/validator';
|
2
|
+
import { ForklaunchExpressLikeApplication, ForklaunchExpressLikeRouter, TypedMiddlewareDefinition, ParamsDictionary, ForklaunchRequest, ForklaunchResponse, ForklaunchStatusResponse, ForklaunchSendableData } from '@forklaunch/core/http';
|
3
|
+
import { Express, RequestHandler, Router as Router$1, NextFunction, Request as Request$1, Response as Response$1 } from 'express';
|
4
|
+
import { Server } from 'http';
|
5
|
+
import { ParsedQs } from 'qs';
|
6
|
+
|
7
|
+
/**
|
8
|
+
* Application class that sets up an Express server with Forklaunch routers and middleware.
|
9
|
+
*
|
10
|
+
* @template SV - A type that extends AnySchemaValidator.
|
11
|
+
*/
|
12
|
+
declare class Application<SV extends AnySchemaValidator> extends ForklaunchExpressLikeApplication<SV, Express, RequestHandler> {
|
13
|
+
/**
|
14
|
+
* Creates an instance of Application.
|
15
|
+
*
|
16
|
+
* @param {SV} schemaValidator - The schema validator.
|
17
|
+
*/
|
18
|
+
constructor(schemaValidator: SV);
|
19
|
+
/**
|
20
|
+
* Starts the server and sets up Swagger documentation.
|
21
|
+
*
|
22
|
+
* @param {...unknown[]} args - The arguments to pass to the listen method.
|
23
|
+
* @returns {Server} - The HTTP server.
|
24
|
+
*/
|
25
|
+
listen(port: number, hostname: string, backlog: number, callback?: () => void): Server;
|
26
|
+
listen(port: number, hostname: string, callback?: () => void): Server;
|
27
|
+
listen(port: number, callback?: () => void): Server;
|
28
|
+
listen(callback?: () => void): Server;
|
29
|
+
listen(path: string, callback?: () => void): Server;
|
30
|
+
listen(handle: unknown, listeningListener?: () => void): Server;
|
31
|
+
}
|
32
|
+
|
33
|
+
/**
|
34
|
+
* Router class that sets up routes and middleware for an Express router.
|
35
|
+
*
|
36
|
+
* @template SV - A type that extends AnySchemaValidator.
|
37
|
+
* @implements {ForklaunchRouter<SV>}
|
38
|
+
*/
|
39
|
+
declare class Router<SV extends AnySchemaValidator, BasePath extends `/${string}`> extends ForklaunchExpressLikeRouter<SV, BasePath, RequestHandler, Router$1> {
|
40
|
+
basePath: BasePath;
|
41
|
+
/**
|
42
|
+
* Creates an instance of Router.
|
43
|
+
*
|
44
|
+
* @param {string} basePath - The base path for the router.
|
45
|
+
* @param {SV} schemaValidator - The schema validator.
|
46
|
+
*/
|
47
|
+
constructor(basePath: BasePath, schemaValidator: SV);
|
48
|
+
route(path: string): this;
|
49
|
+
param<ParamName extends string, Types extends {
|
50
|
+
req?: LiteralSchema | SV['_SchemaCatchall'];
|
51
|
+
res?: IdiomaticSchema<SV>;
|
52
|
+
} & {
|
53
|
+
[K in ParamName]: IdiomaticSchema<SV>;
|
54
|
+
}>(name: ParamName, types: Types, handler: (req: SchemaResolve<Types['req']>, res: SchemaResolve<Types['res']>, next: NextFunction, value: SchemaResolve<Types[ParamName]>, name: ParamName) => void): this;
|
55
|
+
checkout: TypedMiddlewareDefinition<this, SV>;
|
56
|
+
copy: TypedMiddlewareDefinition<this, SV>;
|
57
|
+
lock: TypedMiddlewareDefinition<this, SV>;
|
58
|
+
merge: TypedMiddlewareDefinition<this, SV>;
|
59
|
+
mkcactivity: TypedMiddlewareDefinition<this, SV>;
|
60
|
+
mkcol: TypedMiddlewareDefinition<this, SV>;
|
61
|
+
move: TypedMiddlewareDefinition<this, SV>;
|
62
|
+
'm-search': TypedMiddlewareDefinition<this, SV>;
|
63
|
+
notify: TypedMiddlewareDefinition<this, SV>;
|
64
|
+
propfind: TypedMiddlewareDefinition<this, SV>;
|
65
|
+
proppatch: TypedMiddlewareDefinition<this, SV>;
|
66
|
+
purge: TypedMiddlewareDefinition<this, SV>;
|
67
|
+
report: TypedMiddlewareDefinition<this, SV>;
|
68
|
+
search: TypedMiddlewareDefinition<this, SV>;
|
69
|
+
subscribe: TypedMiddlewareDefinition<this, SV>;
|
70
|
+
unlock: TypedMiddlewareDefinition<this, SV>;
|
71
|
+
unsubscribe: TypedMiddlewareDefinition<this, SV>;
|
72
|
+
link: TypedMiddlewareDefinition<this, SV>;
|
73
|
+
unlink: TypedMiddlewareDefinition<this, SV>;
|
74
|
+
}
|
75
|
+
|
76
|
+
/**
|
77
|
+
* Extends the Forklaunch request interface with properties from Express's request interface.
|
78
|
+
*
|
79
|
+
* @template SV - A type that extends AnySchemaValidator.
|
80
|
+
* @template P - A type for request parameters, defaulting to ParamsDictionary.
|
81
|
+
* @template ResBodyMap - A type for the response body, defaulting to unknown.
|
82
|
+
* @template ReqBody - A type for the request body, defaulting to unknown.
|
83
|
+
* @template ReqQuery - A type for the request query, defaulting to ParsedQs.
|
84
|
+
* @template LocalsObj - A type for local variables, defaulting to an empty object.
|
85
|
+
*/
|
86
|
+
interface Request<SV extends AnySchemaValidator, P extends ParamsDictionary, ResBodyMap extends Record<number, unknown>, 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<P, ResBodyMap, ReqBody, ReqQuery, LocalsObj>, 'method' | 'body' | 'params' | 'query' | 'headers'> {
|
87
|
+
}
|
88
|
+
/**
|
89
|
+
* Extends the Forklaunch response interface with properties from Express's response interface.
|
90
|
+
*
|
91
|
+
* @template ResBodyMap - A type for the response body, defaulting to unknown.
|
92
|
+
* @template LocalsObj - A type for local variables, defaulting to an empty object.
|
93
|
+
* @template StatusCode - A type for the status code, defaulting to number.
|
94
|
+
*/
|
95
|
+
interface Response<ResBodyMap extends Record<number, unknown>, ResHeaders extends Record<string, string>, LocalsObj extends Record<string, unknown> = Record<string, unknown>> extends ForklaunchResponse<ResBodyMap, ResHeaders, LocalsObj>, Omit<Response$1<ResBodyMap, LocalsObj>, 'status' | 'statusCode' | 'sendStatus' | 'getHeaders' | 'setHeader' | 'send' | 'json' | 'jsonp' | 'end' | 'locals'>, ForklaunchStatusResponse<ForklaunchSendableData> {
|
96
|
+
/** If cors are applied to the response */
|
97
|
+
cors: boolean;
|
98
|
+
}
|
99
|
+
|
100
|
+
/**
|
101
|
+
* Creates a new instance of Application with the given schema validator.
|
102
|
+
*
|
103
|
+
* @template SV - A type that extends AnySchemaValidator.
|
104
|
+
* @param {SV} schemaValidator - The schema validator.
|
105
|
+
* @returns {Application<SV>} - The new application instance.
|
106
|
+
*/
|
107
|
+
declare function forklaunchExpress<SV extends AnySchemaValidator>(schemaValidator: SV): Application<SV>;
|
108
|
+
/**
|
109
|
+
* Creates a new instance of Router with the given base path and schema validator.
|
110
|
+
*
|
111
|
+
* @template SV - A type that extends AnySchemaValidator.
|
112
|
+
* @param {string} basePath - The base path for the router.
|
113
|
+
* @param {SV} schemaValidator - The schema validator.
|
114
|
+
* @returns {Router<SV>} - The new router instance.
|
115
|
+
*/
|
116
|
+
declare function forklaunchRouter<SV extends AnySchemaValidator, BasePath extends `/${string}`>(basePath: BasePath, schemaValidator: SV): Router<SV, BasePath>;
|
117
|
+
|
118
|
+
export { Application, type Request, type Response, Router, forklaunchExpress, forklaunchRouter };
|
package/lib/index.d.ts
CHANGED
@@ -1,6 +1,102 @@
|
|
1
|
-
import { AnySchemaValidator } from '@forklaunch/validator';
|
2
|
-
import {
|
3
|
-
import { Router } from '
|
1
|
+
import { AnySchemaValidator, LiteralSchema, IdiomaticSchema, SchemaResolve } from '@forklaunch/validator';
|
2
|
+
import { ForklaunchExpressLikeApplication, ForklaunchExpressLikeRouter, TypedMiddlewareDefinition, ParamsDictionary, ForklaunchRequest, ForklaunchResponse, ForklaunchStatusResponse, ForklaunchSendableData } from '@forklaunch/core/http';
|
3
|
+
import { Express, RequestHandler, Router as Router$1, NextFunction, Request as Request$1, Response as Response$1 } from 'express';
|
4
|
+
import { Server } from 'http';
|
5
|
+
import { ParsedQs } from 'qs';
|
6
|
+
|
7
|
+
/**
|
8
|
+
* Application class that sets up an Express server with Forklaunch routers and middleware.
|
9
|
+
*
|
10
|
+
* @template SV - A type that extends AnySchemaValidator.
|
11
|
+
*/
|
12
|
+
declare class Application<SV extends AnySchemaValidator> extends ForklaunchExpressLikeApplication<SV, Express, RequestHandler> {
|
13
|
+
/**
|
14
|
+
* Creates an instance of Application.
|
15
|
+
*
|
16
|
+
* @param {SV} schemaValidator - The schema validator.
|
17
|
+
*/
|
18
|
+
constructor(schemaValidator: SV);
|
19
|
+
/**
|
20
|
+
* Starts the server and sets up Swagger documentation.
|
21
|
+
*
|
22
|
+
* @param {...unknown[]} args - The arguments to pass to the listen method.
|
23
|
+
* @returns {Server} - The HTTP server.
|
24
|
+
*/
|
25
|
+
listen(port: number, hostname: string, backlog: number, callback?: () => void): Server;
|
26
|
+
listen(port: number, hostname: string, callback?: () => void): Server;
|
27
|
+
listen(port: number, callback?: () => void): Server;
|
28
|
+
listen(callback?: () => void): Server;
|
29
|
+
listen(path: string, callback?: () => void): Server;
|
30
|
+
listen(handle: unknown, listeningListener?: () => void): Server;
|
31
|
+
}
|
32
|
+
|
33
|
+
/**
|
34
|
+
* Router class that sets up routes and middleware for an Express router.
|
35
|
+
*
|
36
|
+
* @template SV - A type that extends AnySchemaValidator.
|
37
|
+
* @implements {ForklaunchRouter<SV>}
|
38
|
+
*/
|
39
|
+
declare class Router<SV extends AnySchemaValidator, BasePath extends `/${string}`> extends ForklaunchExpressLikeRouter<SV, BasePath, RequestHandler, Router$1> {
|
40
|
+
basePath: BasePath;
|
41
|
+
/**
|
42
|
+
* Creates an instance of Router.
|
43
|
+
*
|
44
|
+
* @param {string} basePath - The base path for the router.
|
45
|
+
* @param {SV} schemaValidator - The schema validator.
|
46
|
+
*/
|
47
|
+
constructor(basePath: BasePath, schemaValidator: SV);
|
48
|
+
route(path: string): this;
|
49
|
+
param<ParamName extends string, Types extends {
|
50
|
+
req?: LiteralSchema | SV['_SchemaCatchall'];
|
51
|
+
res?: IdiomaticSchema<SV>;
|
52
|
+
} & {
|
53
|
+
[K in ParamName]: IdiomaticSchema<SV>;
|
54
|
+
}>(name: ParamName, types: Types, handler: (req: SchemaResolve<Types['req']>, res: SchemaResolve<Types['res']>, next: NextFunction, value: SchemaResolve<Types[ParamName]>, name: ParamName) => void): this;
|
55
|
+
checkout: TypedMiddlewareDefinition<this, SV>;
|
56
|
+
copy: TypedMiddlewareDefinition<this, SV>;
|
57
|
+
lock: TypedMiddlewareDefinition<this, SV>;
|
58
|
+
merge: TypedMiddlewareDefinition<this, SV>;
|
59
|
+
mkcactivity: TypedMiddlewareDefinition<this, SV>;
|
60
|
+
mkcol: TypedMiddlewareDefinition<this, SV>;
|
61
|
+
move: TypedMiddlewareDefinition<this, SV>;
|
62
|
+
'm-search': TypedMiddlewareDefinition<this, SV>;
|
63
|
+
notify: TypedMiddlewareDefinition<this, SV>;
|
64
|
+
propfind: TypedMiddlewareDefinition<this, SV>;
|
65
|
+
proppatch: TypedMiddlewareDefinition<this, SV>;
|
66
|
+
purge: TypedMiddlewareDefinition<this, SV>;
|
67
|
+
report: TypedMiddlewareDefinition<this, SV>;
|
68
|
+
search: TypedMiddlewareDefinition<this, SV>;
|
69
|
+
subscribe: TypedMiddlewareDefinition<this, SV>;
|
70
|
+
unlock: TypedMiddlewareDefinition<this, SV>;
|
71
|
+
unsubscribe: TypedMiddlewareDefinition<this, SV>;
|
72
|
+
link: TypedMiddlewareDefinition<this, SV>;
|
73
|
+
unlink: TypedMiddlewareDefinition<this, SV>;
|
74
|
+
}
|
75
|
+
|
76
|
+
/**
|
77
|
+
* Extends the Forklaunch request interface with properties from Express's request interface.
|
78
|
+
*
|
79
|
+
* @template SV - A type that extends AnySchemaValidator.
|
80
|
+
* @template P - A type for request parameters, defaulting to ParamsDictionary.
|
81
|
+
* @template ResBodyMap - A type for the response body, defaulting to unknown.
|
82
|
+
* @template ReqBody - A type for the request body, defaulting to unknown.
|
83
|
+
* @template ReqQuery - A type for the request query, defaulting to ParsedQs.
|
84
|
+
* @template LocalsObj - A type for local variables, defaulting to an empty object.
|
85
|
+
*/
|
86
|
+
interface Request<SV extends AnySchemaValidator, P extends ParamsDictionary, ResBodyMap extends Record<number, unknown>, 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<P, ResBodyMap, ReqBody, ReqQuery, LocalsObj>, 'method' | 'body' | 'params' | 'query' | 'headers'> {
|
87
|
+
}
|
88
|
+
/**
|
89
|
+
* Extends the Forklaunch response interface with properties from Express's response interface.
|
90
|
+
*
|
91
|
+
* @template ResBodyMap - A type for the response body, defaulting to unknown.
|
92
|
+
* @template LocalsObj - A type for local variables, defaulting to an empty object.
|
93
|
+
* @template StatusCode - A type for the status code, defaulting to number.
|
94
|
+
*/
|
95
|
+
interface Response<ResBodyMap extends Record<number, unknown>, ResHeaders extends Record<string, string>, LocalsObj extends Record<string, unknown> = Record<string, unknown>> extends ForklaunchResponse<ResBodyMap, ResHeaders, LocalsObj>, Omit<Response$1<ResBodyMap, LocalsObj>, 'status' | 'statusCode' | 'sendStatus' | 'getHeaders' | 'setHeader' | 'send' | 'json' | 'jsonp' | 'end' | 'locals'>, ForklaunchStatusResponse<ForklaunchSendableData> {
|
96
|
+
/** If cors are applied to the response */
|
97
|
+
cors: boolean;
|
98
|
+
}
|
99
|
+
|
4
100
|
/**
|
5
101
|
* Creates a new instance of Application with the given schema validator.
|
6
102
|
*
|
@@ -8,7 +104,7 @@ import { Router } from './src/expressRouter';
|
|
8
104
|
* @param {SV} schemaValidator - The schema validator.
|
9
105
|
* @returns {Application<SV>} - The new application instance.
|
10
106
|
*/
|
11
|
-
|
107
|
+
declare function forklaunchExpress<SV extends AnySchemaValidator>(schemaValidator: SV): Application<SV>;
|
12
108
|
/**
|
13
109
|
* Creates a new instance of Router with the given base path and schema validator.
|
14
110
|
*
|
@@ -17,8 +113,6 @@ export declare function forklaunchExpress<SV extends AnySchemaValidator>(schemaV
|
|
17
113
|
* @param {SV} schemaValidator - The schema validator.
|
18
114
|
* @returns {Router<SV>} - The new router instance.
|
19
115
|
*/
|
20
|
-
|
21
|
-
|
22
|
-
export type
|
23
|
-
export * from './src/types/express.types';
|
24
|
-
//# sourceMappingURL=index.d.ts.map
|
116
|
+
declare function forklaunchRouter<SV extends AnySchemaValidator, BasePath extends `/${string}`>(basePath: BasePath, schemaValidator: SV): Router<SV, BasePath>;
|
117
|
+
|
118
|
+
export { Application, type Request, type Response, Router, forklaunchExpress, forklaunchRouter };
|
package/lib/index.js
CHANGED
@@ -1,25 +1,303 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
1
|
+
"use strict";
|
2
|
+
var __create = Object.create;
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __export = (target, all) => {
|
9
|
+
for (var name in all)
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
+
};
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
+
for (let key of __getOwnPropNames(from))
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
+
}
|
18
|
+
return to;
|
19
|
+
};
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
+
mod
|
27
|
+
));
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
+
|
30
|
+
// index.ts
|
31
|
+
var index_exports = {};
|
32
|
+
__export(index_exports, {
|
33
|
+
forklaunchExpress: () => forklaunchExpress,
|
34
|
+
forklaunchRouter: () => forklaunchRouter
|
35
|
+
});
|
36
|
+
module.exports = __toCommonJS(index_exports);
|
37
|
+
|
38
|
+
// src/expressApplication.ts
|
39
|
+
var import_http = require("@forklaunch/core/http");
|
40
|
+
var import_express = __toESM(require("express"));
|
41
|
+
var import_swagger_ui_express = __toESM(require("swagger-ui-express"));
|
42
|
+
var Application = class extends import_http.ForklaunchExpressLikeApplication {
|
43
|
+
/**
|
44
|
+
* Creates an instance of Application.
|
45
|
+
*
|
46
|
+
* @param {SV} schemaValidator - The schema validator.
|
47
|
+
*/
|
48
|
+
constructor(schemaValidator) {
|
49
|
+
super(schemaValidator, (0, import_express.default)());
|
50
|
+
}
|
51
|
+
listen(...args) {
|
52
|
+
const port = typeof args[0] === "number" ? args[0] : Number(process.env.PORT);
|
53
|
+
this.internal.use(
|
54
|
+
`/api${process.env.VERSION ?? "/v1"}${process.env.SWAGGER_PATH ?? "/swagger"}`,
|
55
|
+
import_swagger_ui_express.default.serve,
|
56
|
+
import_swagger_ui_express.default.setup(
|
57
|
+
(0, import_http.generateSwaggerDocument)(this.schemaValidator, port, this.routers)
|
58
|
+
)
|
59
|
+
);
|
60
|
+
const errorHandler = (err, _req, res, _next) => {
|
61
|
+
console.error(err);
|
62
|
+
res.locals.errorMessage = err.message;
|
63
|
+
res.status(res.statusCode && res.statusCode >= 400 ? res.statusCode : 500).send(`Internal server error:
|
64
|
+
|
65
|
+
${err.message}`);
|
66
|
+
};
|
67
|
+
this.internal.use(errorHandler);
|
68
|
+
return this.internal.listen(...args);
|
69
|
+
}
|
70
|
+
};
|
71
|
+
|
72
|
+
// src/expressRouter.ts
|
73
|
+
var import_http3 = require("@forklaunch/core/http");
|
74
|
+
var import_express2 = __toESM(require("express"));
|
75
|
+
|
76
|
+
// src/middleware/response.middleware.ts
|
77
|
+
var import_http2 = require("@forklaunch/core/http");
|
78
|
+
function enrichResponseTransmission(req, res, next) {
|
79
|
+
const originalSend = res.send;
|
80
|
+
const originalJson = res.json;
|
81
|
+
const originalSetHeader = res.setHeader;
|
82
|
+
res.json = function(data) {
|
83
|
+
res.bodyData = data;
|
84
|
+
return originalJson.call(this, data);
|
85
|
+
};
|
86
|
+
res.send = function(data) {
|
87
|
+
if (!res.bodyData) {
|
88
|
+
res.bodyData = data;
|
89
|
+
}
|
90
|
+
return (0, import_http2.enrichExpressLikeSend)(this, req, res, originalSend, data, !res.cors);
|
91
|
+
};
|
92
|
+
res.setHeader = function(name, value) {
|
93
|
+
let stringifiedValue;
|
94
|
+
if (Array.isArray(value)) {
|
95
|
+
stringifiedValue = value.map(
|
96
|
+
(v) => typeof v !== "string" ? JSON.stringify(v) : v
|
97
|
+
);
|
98
|
+
} else {
|
99
|
+
stringifiedValue = typeof value !== "string" ? JSON.stringify(value) : value;
|
100
|
+
}
|
101
|
+
return originalSetHeader.call(this, name, stringifiedValue);
|
102
|
+
};
|
103
|
+
next?.();
|
12
104
|
}
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
105
|
+
|
106
|
+
// src/expressRouter.ts
|
107
|
+
var Router = class extends import_http3.ForklaunchExpressLikeRouter {
|
108
|
+
// implements ForklaunchRouter<SV>
|
109
|
+
/**
|
110
|
+
* Creates an instance of Router.
|
111
|
+
*
|
112
|
+
* @param {string} basePath - The base path for the router.
|
113
|
+
* @param {SV} schemaValidator - The schema validator.
|
114
|
+
*/
|
115
|
+
constructor(basePath, schemaValidator) {
|
116
|
+
super(basePath, schemaValidator, import_express2.default.Router());
|
117
|
+
this.basePath = basePath;
|
118
|
+
this.internal.use(import_express2.default.json());
|
119
|
+
this.internal.use(enrichResponseTransmission);
|
120
|
+
}
|
121
|
+
route(path) {
|
122
|
+
this.internal.route(path);
|
123
|
+
return this;
|
124
|
+
}
|
125
|
+
param(name, types, handler) {
|
126
|
+
this.internal.param(name, (req, res, next, value, name2) => {
|
127
|
+
handler(
|
128
|
+
req,
|
129
|
+
res,
|
130
|
+
next,
|
131
|
+
value,
|
132
|
+
name2
|
133
|
+
);
|
134
|
+
});
|
135
|
+
return this;
|
136
|
+
}
|
137
|
+
checkout = (pathOrContractDetailsOrMiddlewareOrTypedHandler, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
|
138
|
+
return this.registerMiddlewareHandler(
|
139
|
+
this.internal.checkout,
|
140
|
+
pathOrContractDetailsOrMiddlewareOrTypedHandler,
|
141
|
+
contractDetailsOrMiddlewareOrTypedHandler,
|
142
|
+
...middlewareOrMiddlewareWithTypedHandler
|
143
|
+
);
|
144
|
+
};
|
145
|
+
copy = (pathOrContractDetailsOrMiddlewareOrTypedHandler, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
|
146
|
+
return this.registerMiddlewareHandler(
|
147
|
+
this.internal.copy,
|
148
|
+
pathOrContractDetailsOrMiddlewareOrTypedHandler,
|
149
|
+
contractDetailsOrMiddlewareOrTypedHandler,
|
150
|
+
...middlewareOrMiddlewareWithTypedHandler
|
151
|
+
);
|
152
|
+
};
|
153
|
+
lock = (pathOrContractDetailsOrMiddlewareOrTypedHandler, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
|
154
|
+
return this.registerMiddlewareHandler(
|
155
|
+
this.internal.lock,
|
156
|
+
pathOrContractDetailsOrMiddlewareOrTypedHandler,
|
157
|
+
contractDetailsOrMiddlewareOrTypedHandler,
|
158
|
+
...middlewareOrMiddlewareWithTypedHandler
|
159
|
+
);
|
160
|
+
};
|
161
|
+
merge = (pathOrContractDetailsOrMiddlewareOrTypedHandler, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
|
162
|
+
return this.registerMiddlewareHandler(
|
163
|
+
this.internal.merge,
|
164
|
+
pathOrContractDetailsOrMiddlewareOrTypedHandler,
|
165
|
+
contractDetailsOrMiddlewareOrTypedHandler,
|
166
|
+
...middlewareOrMiddlewareWithTypedHandler
|
167
|
+
);
|
168
|
+
};
|
169
|
+
mkcactivity = (pathOrContractDetailsOrMiddlewareOrTypedHandler, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
|
170
|
+
return this.registerMiddlewareHandler(
|
171
|
+
this.internal.mkactivity,
|
172
|
+
pathOrContractDetailsOrMiddlewareOrTypedHandler,
|
173
|
+
contractDetailsOrMiddlewareOrTypedHandler,
|
174
|
+
...middlewareOrMiddlewareWithTypedHandler
|
175
|
+
);
|
176
|
+
};
|
177
|
+
mkcol = (pathOrContractDetailsOrMiddlewareOrTypedHandler, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
|
178
|
+
return this.registerMiddlewareHandler(
|
179
|
+
this.internal.mkcol,
|
180
|
+
pathOrContractDetailsOrMiddlewareOrTypedHandler,
|
181
|
+
contractDetailsOrMiddlewareOrTypedHandler,
|
182
|
+
...middlewareOrMiddlewareWithTypedHandler
|
183
|
+
);
|
184
|
+
};
|
185
|
+
move = (pathOrContractDetailsOrMiddlewareOrTypedHandler, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
|
186
|
+
return this.registerMiddlewareHandler(
|
187
|
+
this.internal.move,
|
188
|
+
pathOrContractDetailsOrMiddlewareOrTypedHandler,
|
189
|
+
contractDetailsOrMiddlewareOrTypedHandler,
|
190
|
+
...middlewareOrMiddlewareWithTypedHandler
|
191
|
+
);
|
192
|
+
};
|
193
|
+
"m-search" = (pathOrContractDetailsOrMiddlewareOrTypedHandler, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
|
194
|
+
return this.registerMiddlewareHandler(
|
195
|
+
this.internal["m-search"],
|
196
|
+
pathOrContractDetailsOrMiddlewareOrTypedHandler,
|
197
|
+
contractDetailsOrMiddlewareOrTypedHandler,
|
198
|
+
...middlewareOrMiddlewareWithTypedHandler
|
199
|
+
);
|
200
|
+
};
|
201
|
+
notify = (pathOrContractDetailsOrMiddlewareOrTypedHandler, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
|
202
|
+
return this.registerMiddlewareHandler(
|
203
|
+
this.internal.notify,
|
204
|
+
pathOrContractDetailsOrMiddlewareOrTypedHandler,
|
205
|
+
contractDetailsOrMiddlewareOrTypedHandler,
|
206
|
+
...middlewareOrMiddlewareWithTypedHandler
|
207
|
+
);
|
208
|
+
};
|
209
|
+
propfind = (pathOrContractDetailsOrMiddlewareOrTypedHandler, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
|
210
|
+
return this.registerMiddlewareHandler(
|
211
|
+
this.internal.propfind,
|
212
|
+
pathOrContractDetailsOrMiddlewareOrTypedHandler,
|
213
|
+
contractDetailsOrMiddlewareOrTypedHandler,
|
214
|
+
...middlewareOrMiddlewareWithTypedHandler
|
215
|
+
);
|
216
|
+
};
|
217
|
+
proppatch = (pathOrContractDetailsOrMiddlewareOrTypedHandler, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
|
218
|
+
return this.registerMiddlewareHandler(
|
219
|
+
this.internal.proppatch,
|
220
|
+
pathOrContractDetailsOrMiddlewareOrTypedHandler,
|
221
|
+
contractDetailsOrMiddlewareOrTypedHandler,
|
222
|
+
...middlewareOrMiddlewareWithTypedHandler
|
223
|
+
);
|
224
|
+
};
|
225
|
+
purge = (pathOrContractDetailsOrMiddlewareOrTypedHandler, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
|
226
|
+
return this.registerMiddlewareHandler(
|
227
|
+
this.internal.purge,
|
228
|
+
pathOrContractDetailsOrMiddlewareOrTypedHandler,
|
229
|
+
contractDetailsOrMiddlewareOrTypedHandler,
|
230
|
+
...middlewareOrMiddlewareWithTypedHandler
|
231
|
+
);
|
232
|
+
};
|
233
|
+
report = (pathOrContractDetailsOrMiddlewareOrTypedHandler, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
|
234
|
+
return this.registerMiddlewareHandler(
|
235
|
+
this.internal.report,
|
236
|
+
pathOrContractDetailsOrMiddlewareOrTypedHandler,
|
237
|
+
contractDetailsOrMiddlewareOrTypedHandler,
|
238
|
+
...middlewareOrMiddlewareWithTypedHandler
|
239
|
+
);
|
240
|
+
};
|
241
|
+
search = (pathOrContractDetailsOrMiddlewareOrTypedHandler, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
|
242
|
+
return this.registerMiddlewareHandler(
|
243
|
+
this.internal.search,
|
244
|
+
pathOrContractDetailsOrMiddlewareOrTypedHandler,
|
245
|
+
contractDetailsOrMiddlewareOrTypedHandler,
|
246
|
+
...middlewareOrMiddlewareWithTypedHandler
|
247
|
+
);
|
248
|
+
};
|
249
|
+
subscribe = (pathOrContractDetailsOrMiddlewareOrTypedHandler, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
|
250
|
+
return this.registerMiddlewareHandler(
|
251
|
+
this.internal.subscribe,
|
252
|
+
pathOrContractDetailsOrMiddlewareOrTypedHandler,
|
253
|
+
contractDetailsOrMiddlewareOrTypedHandler,
|
254
|
+
...middlewareOrMiddlewareWithTypedHandler
|
255
|
+
);
|
256
|
+
};
|
257
|
+
unlock = (pathOrContractDetailsOrMiddlewareOrTypedHandler, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
|
258
|
+
return this.registerMiddlewareHandler(
|
259
|
+
this.internal.unlock,
|
260
|
+
pathOrContractDetailsOrMiddlewareOrTypedHandler,
|
261
|
+
contractDetailsOrMiddlewareOrTypedHandler,
|
262
|
+
...middlewareOrMiddlewareWithTypedHandler
|
263
|
+
);
|
264
|
+
};
|
265
|
+
unsubscribe = (pathOrContractDetailsOrMiddlewareOrTypedHandler, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
|
266
|
+
return this.registerMiddlewareHandler(
|
267
|
+
this.internal.unsubscribe,
|
268
|
+
pathOrContractDetailsOrMiddlewareOrTypedHandler,
|
269
|
+
contractDetailsOrMiddlewareOrTypedHandler,
|
270
|
+
...middlewareOrMiddlewareWithTypedHandler
|
271
|
+
);
|
272
|
+
};
|
273
|
+
link = (pathOrContractDetailsOrMiddlewareOrTypedHandler, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
|
274
|
+
return this.registerMiddlewareHandler(
|
275
|
+
this.internal.link,
|
276
|
+
pathOrContractDetailsOrMiddlewareOrTypedHandler,
|
277
|
+
contractDetailsOrMiddlewareOrTypedHandler,
|
278
|
+
...middlewareOrMiddlewareWithTypedHandler
|
279
|
+
);
|
280
|
+
};
|
281
|
+
unlink = (pathOrContractDetailsOrMiddlewareOrTypedHandler, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
|
282
|
+
return this.registerMiddlewareHandler(
|
283
|
+
this.internal.unlink,
|
284
|
+
pathOrContractDetailsOrMiddlewareOrTypedHandler,
|
285
|
+
contractDetailsOrMiddlewareOrTypedHandler,
|
286
|
+
...middlewareOrMiddlewareWithTypedHandler
|
287
|
+
);
|
288
|
+
};
|
289
|
+
};
|
290
|
+
|
291
|
+
// index.ts
|
292
|
+
function forklaunchExpress(schemaValidator) {
|
293
|
+
return new Application(schemaValidator);
|
24
294
|
}
|
25
|
-
|
295
|
+
function forklaunchRouter(basePath, schemaValidator) {
|
296
|
+
const router = new Router(basePath, schemaValidator);
|
297
|
+
return router;
|
298
|
+
}
|
299
|
+
// Annotate the CommonJS export names for ESM import in node:
|
300
|
+
0 && (module.exports = {
|
301
|
+
forklaunchExpress,
|
302
|
+
forklaunchRouter
|
303
|
+
});
|