clear-router 2.7.6 → 2.7.7
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/dist/ClearRequest.cjs +23 -0
- package/dist/ClearRequest.d.cts +28 -0
- package/dist/ClearRequest.d.mts +28 -0
- package/dist/ClearRequest.mjs +22 -0
- package/dist/Contracts.d.cts +12 -0
- package/dist/Contracts.d.mts +12 -0
- package/dist/Controller.cjs +12 -0
- package/dist/Controller.d.cts +14 -0
- package/dist/Controller.d.mts +14 -0
- package/dist/Controller.mjs +11 -0
- package/dist/{Request-DKXwa_W0.d.mts → Request-BhTJDR_5.d.mts} +5 -5
- package/dist/Route.cjs +58 -0
- package/dist/Route.d.cts +35 -0
- package/dist/Route.d.mts +35 -0
- package/dist/Route.mjs +57 -0
- package/dist/core/Request.cjs +35 -0
- package/dist/core/Request.d.cts +25 -0
- package/dist/core/Request.d.mts +25 -0
- package/dist/core/Request.mjs +35 -0
- package/dist/core/Response.cjs +59 -0
- package/dist/core/Response.d.cts +24 -0
- package/dist/core/Response.d.mts +24 -0
- package/dist/core/Response.mjs +58 -0
- package/dist/{bindings-CLsZjOEy.cjs → core/bindings.cjs} +10 -160
- package/dist/{bindings-CNL7bpz5.d.mts → core/bindings.d.cts} +1 -1
- package/dist/{bindings-CxvtC8XS.d.cts → core/bindings.d.mts} +1 -1
- package/dist/{bindings-XLDXFpHZ.mjs → core/bindings.mjs} +3 -110
- package/dist/core/index.cjs +4 -20
- package/dist/core/index.d.cts +4 -1
- package/dist/core/index.d.mts +4 -1
- package/dist/core/index.mjs +4 -14
- package/dist/core/plugins.cjs +14 -0
- package/dist/core/plugins.d.cts +109 -0
- package/dist/core/plugins.d.mts +109 -0
- package/dist/core/plugins.mjs +13 -0
- package/dist/{responses-Bvnk0uvc.cjs → core/responses.cjs} +5 -20
- package/dist/{responses-BvETUeDL.mjs → core/responses.mjs} +2 -2
- package/dist/{router-C6W-k6sS.cjs → core/router.cjs} +11 -69
- package/dist/core/router.d.cts +274 -0
- package/dist/core/router.d.mts +274 -0
- package/dist/{router-Dc9w86Wn.mjs → core/router.mjs} +5 -58
- package/dist/decorators/index.cjs +1 -1
- package/dist/decorators/index.d.cts +1 -1
- package/dist/decorators/index.d.mts +1 -1
- package/dist/decorators/index.mjs +1 -1
- package/dist/decorators/setup.cjs +2 -2
- package/dist/decorators/setup.d.cts +1 -1
- package/dist/decorators/setup.d.mts +1 -1
- package/dist/decorators/setup.mjs +2 -2
- package/dist/express/index.cjs +2 -265
- package/dist/express/index.d.cts +1 -127
- package/dist/express/index.d.mts +1 -127
- package/dist/express/index.mjs +1 -264
- package/dist/express/router.cjs +265 -0
- package/dist/express/router.d.cts +131 -0
- package/dist/express/router.d.mts +131 -0
- package/dist/express/router.mjs +265 -0
- package/dist/fastify/index.cjs +2 -254
- package/dist/fastify/index.d.cts +1 -125
- package/dist/fastify/index.d.mts +1 -125
- package/dist/fastify/index.mjs +1 -253
- package/dist/fastify/router.cjs +254 -0
- package/dist/fastify/router.d.cts +129 -0
- package/dist/fastify/router.d.mts +129 -0
- package/dist/fastify/router.mjs +254 -0
- package/dist/h3/index.cjs +2 -260
- package/dist/h3/index.d.cts +1 -128
- package/dist/h3/index.d.mts +1 -128
- package/dist/h3/index.mjs +1 -259
- package/dist/h3/router.cjs +260 -0
- package/dist/h3/router.d.cts +132 -0
- package/dist/h3/router.d.mts +132 -0
- package/dist/h3/router.mjs +260 -0
- package/dist/hono/index.cjs +2 -251
- package/dist/hono/index.d.cts +1 -130
- package/dist/hono/index.d.mts +1 -130
- package/dist/hono/index.mjs +1 -250
- package/dist/hono/router.cjs +251 -0
- package/dist/hono/router.d.cts +134 -0
- package/dist/hono/router.d.mts +134 -0
- package/dist/hono/router.mjs +251 -0
- package/dist/index.cjs +16 -1097
- package/dist/index.d.cts +9 -563
- package/dist/index.d.mts +9 -563
- package/dist/index.mjs +8 -1089
- package/dist/koa/index.cjs +2 -261
- package/dist/koa/index.d.cts +1 -131
- package/dist/koa/index.d.mts +1 -131
- package/dist/koa/index.mjs +1 -260
- package/dist/koa/router.cjs +261 -0
- package/dist/koa/router.d.cts +135 -0
- package/dist/koa/router.d.mts +135 -0
- package/dist/koa/router.mjs +261 -0
- package/dist/types/basic.d.cts +43 -0
- package/dist/types/express.d.cts +44 -0
- package/dist/types/express.d.mts +4 -2
- package/dist/types/fastify.d.cts +23 -0
- package/dist/types/fastify.d.mts +4 -2
- package/dist/types/h3.d.cts +41 -0
- package/dist/types/h3.d.mts +4 -4
- package/dist/types/hono.d.cts +21 -0
- package/dist/types/hono.d.mts +4 -3
- package/dist/types/koa.d.cts +25 -0
- package/dist/types/koa.d.mts +4 -3
- package/package.json +1 -1
- package/dist/router-BEgAxp5A.d.cts +0 -649
- package/dist/router-DKKYx23P.d.mts +0 -649
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/ClearRequest.ts
|
|
3
|
+
var ClearRequest = class {
|
|
4
|
+
/**
|
|
5
|
+
* @param body - Parsed request body
|
|
6
|
+
*/
|
|
7
|
+
body;
|
|
8
|
+
/**
|
|
9
|
+
* @param query - Parsed query parameters
|
|
10
|
+
*/
|
|
11
|
+
query;
|
|
12
|
+
/**
|
|
13
|
+
* @param params - Parsed route parameters
|
|
14
|
+
*/
|
|
15
|
+
params;
|
|
16
|
+
route;
|
|
17
|
+
constructor(init) {
|
|
18
|
+
Object.assign(this, init);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
exports.ClearRequest = ClearRequest;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { RequestData } from "./types/basic.cjs";
|
|
2
|
+
import { Middleware } from "./types/express.cjs";
|
|
3
|
+
import { Middleware as Middleware$1 } from "./types/fastify.cjs";
|
|
4
|
+
import { Middleware as Middleware$2 } from "./types/h3.cjs";
|
|
5
|
+
import { Middleware as Middleware$3 } from "./types/hono.cjs";
|
|
6
|
+
import { Middleware as Middleware$4 } from "./types/koa.cjs";
|
|
7
|
+
import { Route } from "./Route.cjs";
|
|
8
|
+
|
|
9
|
+
//#region src/ClearRequest.d.ts
|
|
10
|
+
declare class ClearRequest<X = any, M = Middleware$2 | Middleware | Middleware$1 | Middleware$3 | Middleware$4> {
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
/**
|
|
13
|
+
* @param body - Parsed request body
|
|
14
|
+
*/
|
|
15
|
+
body: RequestData;
|
|
16
|
+
/**
|
|
17
|
+
* @param query - Parsed query parameters
|
|
18
|
+
*/
|
|
19
|
+
query: RequestData;
|
|
20
|
+
/**
|
|
21
|
+
* @param params - Parsed route parameters
|
|
22
|
+
*/
|
|
23
|
+
params: RequestData;
|
|
24
|
+
route: Route<X, M>;
|
|
25
|
+
constructor(init?: Partial<ClearRequest>);
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { ClearRequest };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { RequestData } from "./types/basic.mjs";
|
|
2
|
+
import { Middleware } from "./types/express.mjs";
|
|
3
|
+
import { Middleware as Middleware$1 } from "./types/fastify.mjs";
|
|
4
|
+
import { Middleware as Middleware$2 } from "./types/h3.mjs";
|
|
5
|
+
import { Middleware as Middleware$3 } from "./types/hono.mjs";
|
|
6
|
+
import { Middleware as Middleware$4 } from "./types/koa.mjs";
|
|
7
|
+
import { Route } from "./Route.mjs";
|
|
8
|
+
|
|
9
|
+
//#region src/ClearRequest.d.ts
|
|
10
|
+
declare class ClearRequest<X = any, M = Middleware$2 | Middleware | Middleware$1 | Middleware$3 | Middleware$4> {
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
/**
|
|
13
|
+
* @param body - Parsed request body
|
|
14
|
+
*/
|
|
15
|
+
body: RequestData;
|
|
16
|
+
/**
|
|
17
|
+
* @param query - Parsed query parameters
|
|
18
|
+
*/
|
|
19
|
+
query: RequestData;
|
|
20
|
+
/**
|
|
21
|
+
* @param params - Parsed route parameters
|
|
22
|
+
*/
|
|
23
|
+
params: RequestData;
|
|
24
|
+
route: Route<X, M>;
|
|
25
|
+
constructor(init?: Partial<ClearRequest>);
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { ClearRequest };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//#region src/ClearRequest.ts
|
|
2
|
+
var ClearRequest = class {
|
|
3
|
+
/**
|
|
4
|
+
* @param body - Parsed request body
|
|
5
|
+
*/
|
|
6
|
+
body;
|
|
7
|
+
/**
|
|
8
|
+
* @param query - Parsed query parameters
|
|
9
|
+
*/
|
|
10
|
+
query;
|
|
11
|
+
/**
|
|
12
|
+
* @param params - Parsed route parameters
|
|
13
|
+
*/
|
|
14
|
+
params;
|
|
15
|
+
route;
|
|
16
|
+
constructor(init) {
|
|
17
|
+
Object.assign(this, init);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
export { ClearRequest };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/Contracts.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* HTTP context passed to route handlers
|
|
4
|
+
*/
|
|
5
|
+
interface ClearHttpContext {}
|
|
6
|
+
interface RouteParameter {
|
|
7
|
+
name: string;
|
|
8
|
+
field?: string;
|
|
9
|
+
optional: boolean;
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { ClearHttpContext, RouteParameter };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/Contracts.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* HTTP context passed to route handlers
|
|
4
|
+
*/
|
|
5
|
+
interface ClearHttpContext {}
|
|
6
|
+
interface RouteParameter {
|
|
7
|
+
name: string;
|
|
8
|
+
field?: string;
|
|
9
|
+
optional: boolean;
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { ClearHttpContext, RouteParameter };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { RequestData } from "./types/basic.cjs";
|
|
2
|
+
import { ClearRequest } from "./ClearRequest.cjs";
|
|
3
|
+
|
|
4
|
+
//#region src/Controller.d.ts
|
|
5
|
+
declare abstract class Controller<X = any> {
|
|
6
|
+
[x: string]: any;
|
|
7
|
+
ctx: X;
|
|
8
|
+
body: RequestData;
|
|
9
|
+
query: RequestData;
|
|
10
|
+
params: RequestData;
|
|
11
|
+
clearRequest: ClearRequest;
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
export { Controller };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { RequestData } from "./types/basic.mjs";
|
|
2
|
+
import { ClearRequest } from "./ClearRequest.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/Controller.d.ts
|
|
5
|
+
declare abstract class Controller<X = any> {
|
|
6
|
+
[x: string]: any;
|
|
7
|
+
ctx: X;
|
|
8
|
+
body: RequestData;
|
|
9
|
+
query: RequestData;
|
|
10
|
+
params: RequestData;
|
|
11
|
+
clearRequest: ClearRequest;
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
export { Controller };
|
|
@@ -10,6 +10,11 @@ import { Middleware as Middleware$4 } from "./types/express.mjs";
|
|
|
10
10
|
* HTTP context passed to route handlers
|
|
11
11
|
*/
|
|
12
12
|
interface ClearHttpContext {}
|
|
13
|
+
interface RouteParameter {
|
|
14
|
+
name: string;
|
|
15
|
+
field?: string;
|
|
16
|
+
optional: boolean;
|
|
17
|
+
}
|
|
13
18
|
//#endregion
|
|
14
19
|
//#region src/core/Response.d.ts
|
|
15
20
|
declare class Response {
|
|
@@ -35,11 +40,6 @@ declare class Response {
|
|
|
35
40
|
}
|
|
36
41
|
//#endregion
|
|
37
42
|
//#region src/Route.d.ts
|
|
38
|
-
interface RouteParameter {
|
|
39
|
-
name: string;
|
|
40
|
-
field?: string;
|
|
41
|
-
optional: boolean;
|
|
42
|
-
}
|
|
43
43
|
declare class Route<X = any, M = Middleware$1 | Middleware$4, H = any> {
|
|
44
44
|
ctx: X;
|
|
45
45
|
body: RequestData;
|
package/dist/Route.cjs
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/Route.ts
|
|
3
|
+
var Route = class {
|
|
4
|
+
ctx;
|
|
5
|
+
body = {};
|
|
6
|
+
query = {};
|
|
7
|
+
params = {};
|
|
8
|
+
clearRequest;
|
|
9
|
+
methods;
|
|
10
|
+
path;
|
|
11
|
+
registrationPaths;
|
|
12
|
+
parameters;
|
|
13
|
+
routeName;
|
|
14
|
+
handler;
|
|
15
|
+
middlewares;
|
|
16
|
+
controllerName;
|
|
17
|
+
actionName;
|
|
18
|
+
handlerType;
|
|
19
|
+
middlewareCount;
|
|
20
|
+
constructor(methods, path, handler, middlewares = [], options = {}) {
|
|
21
|
+
this.methods = methods;
|
|
22
|
+
this.path = path;
|
|
23
|
+
this.registrationPaths = options.registrationPaths || [path];
|
|
24
|
+
this.parameters = options.parameters || [];
|
|
25
|
+
this.handler = handler;
|
|
26
|
+
this.middlewares = middlewares;
|
|
27
|
+
this.handlerType = Array.isArray(handler) ? "controller" : "function";
|
|
28
|
+
this.middlewareCount = middlewares.length;
|
|
29
|
+
this.controllerName = Array.isArray(handler) ? handler[0]?.name : void 0;
|
|
30
|
+
this.actionName = Array.isArray(handler) ? handler[1] : typeof handler === "function" ? handler.constructor.name ?? handler.name : void 0;
|
|
31
|
+
this.onName = options.onName;
|
|
32
|
+
}
|
|
33
|
+
onName;
|
|
34
|
+
name(name) {
|
|
35
|
+
const previousName = this.routeName;
|
|
36
|
+
this.routeName = name;
|
|
37
|
+
this.onName?.(name, this, previousName);
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
toPath(params = {}) {
|
|
41
|
+
return this.path.replace(/\/?\{([^{}]+)\}/g, (segment, raw) => {
|
|
42
|
+
const optional = raw.endsWith("?");
|
|
43
|
+
const [rawName, rawField] = (optional ? raw.slice(0, -1) : raw).split(":", 2);
|
|
44
|
+
const name = rawName.trim();
|
|
45
|
+
const field = rawField?.trim();
|
|
46
|
+
const value = params[name];
|
|
47
|
+
const resolved = field && value && typeof value === "object" ? value[field] : value;
|
|
48
|
+
if (typeof resolved === "undefined" || resolved === null || resolved === "") {
|
|
49
|
+
if (optional) return "";
|
|
50
|
+
throw new Error(`Missing required route parameter: ${name}`);
|
|
51
|
+
}
|
|
52
|
+
return `${segment.startsWith("/") ? "/" : ""}${encodeURIComponent(String(resolved))}`;
|
|
53
|
+
}) || "/";
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
58
|
+
exports.Route = Route;
|
package/dist/Route.d.cts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { HttpMethod, RequestData } from "./types/basic.cjs";
|
|
2
|
+
import { RouteParameter } from "./Contracts.cjs";
|
|
3
|
+
import { Middleware } from "./types/express.cjs";
|
|
4
|
+
import { Middleware as Middleware$1 } from "./types/h3.cjs";
|
|
5
|
+
import { ClearRequest } from "./ClearRequest.cjs";
|
|
6
|
+
|
|
7
|
+
//#region src/Route.d.ts
|
|
8
|
+
declare class Route<X = any, M = Middleware$1 | Middleware, H = any> {
|
|
9
|
+
ctx: X;
|
|
10
|
+
body: RequestData;
|
|
11
|
+
query: RequestData;
|
|
12
|
+
params: RequestData;
|
|
13
|
+
clearRequest: ClearRequest;
|
|
14
|
+
methods: HttpMethod[];
|
|
15
|
+
path: string;
|
|
16
|
+
registrationPaths: string[];
|
|
17
|
+
parameters: RouteParameter[];
|
|
18
|
+
routeName?: string;
|
|
19
|
+
handler: H;
|
|
20
|
+
middlewares: M[];
|
|
21
|
+
controllerName?: string;
|
|
22
|
+
actionName?: string;
|
|
23
|
+
handlerType: 'function' | 'controller';
|
|
24
|
+
middlewareCount: number;
|
|
25
|
+
constructor(methods: HttpMethod[], path: string, handler: H, middlewares?: M[], options?: {
|
|
26
|
+
registrationPaths?: string[];
|
|
27
|
+
parameters?: RouteParameter[];
|
|
28
|
+
onName?: (name: string, route: Route<X, M, H>, previousName?: string) => void;
|
|
29
|
+
});
|
|
30
|
+
private onName?;
|
|
31
|
+
name(name: string): this;
|
|
32
|
+
toPath(params?: RequestData): string;
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
export { Route };
|
package/dist/Route.d.mts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { HttpMethod, RequestData } from "./types/basic.mjs";
|
|
2
|
+
import { RouteParameter } from "./Contracts.mjs";
|
|
3
|
+
import { Middleware } from "./types/express.mjs";
|
|
4
|
+
import { Middleware as Middleware$1 } from "./types/h3.mjs";
|
|
5
|
+
import { ClearRequest } from "./ClearRequest.mjs";
|
|
6
|
+
|
|
7
|
+
//#region src/Route.d.ts
|
|
8
|
+
declare class Route<X = any, M = Middleware$1 | Middleware, H = any> {
|
|
9
|
+
ctx: X;
|
|
10
|
+
body: RequestData;
|
|
11
|
+
query: RequestData;
|
|
12
|
+
params: RequestData;
|
|
13
|
+
clearRequest: ClearRequest;
|
|
14
|
+
methods: HttpMethod[];
|
|
15
|
+
path: string;
|
|
16
|
+
registrationPaths: string[];
|
|
17
|
+
parameters: RouteParameter[];
|
|
18
|
+
routeName?: string;
|
|
19
|
+
handler: H;
|
|
20
|
+
middlewares: M[];
|
|
21
|
+
controllerName?: string;
|
|
22
|
+
actionName?: string;
|
|
23
|
+
handlerType: 'function' | 'controller';
|
|
24
|
+
middlewareCount: number;
|
|
25
|
+
constructor(methods: HttpMethod[], path: string, handler: H, middlewares?: M[], options?: {
|
|
26
|
+
registrationPaths?: string[];
|
|
27
|
+
parameters?: RouteParameter[];
|
|
28
|
+
onName?: (name: string, route: Route<X, M, H>, previousName?: string) => void;
|
|
29
|
+
});
|
|
30
|
+
private onName?;
|
|
31
|
+
name(name: string): this;
|
|
32
|
+
toPath(params?: RequestData): string;
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
export { Route };
|
package/dist/Route.mjs
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
//#region src/Route.ts
|
|
2
|
+
var Route = class {
|
|
3
|
+
ctx;
|
|
4
|
+
body = {};
|
|
5
|
+
query = {};
|
|
6
|
+
params = {};
|
|
7
|
+
clearRequest;
|
|
8
|
+
methods;
|
|
9
|
+
path;
|
|
10
|
+
registrationPaths;
|
|
11
|
+
parameters;
|
|
12
|
+
routeName;
|
|
13
|
+
handler;
|
|
14
|
+
middlewares;
|
|
15
|
+
controllerName;
|
|
16
|
+
actionName;
|
|
17
|
+
handlerType;
|
|
18
|
+
middlewareCount;
|
|
19
|
+
constructor(methods, path, handler, middlewares = [], options = {}) {
|
|
20
|
+
this.methods = methods;
|
|
21
|
+
this.path = path;
|
|
22
|
+
this.registrationPaths = options.registrationPaths || [path];
|
|
23
|
+
this.parameters = options.parameters || [];
|
|
24
|
+
this.handler = handler;
|
|
25
|
+
this.middlewares = middlewares;
|
|
26
|
+
this.handlerType = Array.isArray(handler) ? "controller" : "function";
|
|
27
|
+
this.middlewareCount = middlewares.length;
|
|
28
|
+
this.controllerName = Array.isArray(handler) ? handler[0]?.name : void 0;
|
|
29
|
+
this.actionName = Array.isArray(handler) ? handler[1] : typeof handler === "function" ? handler.constructor.name ?? handler.name : void 0;
|
|
30
|
+
this.onName = options.onName;
|
|
31
|
+
}
|
|
32
|
+
onName;
|
|
33
|
+
name(name) {
|
|
34
|
+
const previousName = this.routeName;
|
|
35
|
+
this.routeName = name;
|
|
36
|
+
this.onName?.(name, this, previousName);
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
toPath(params = {}) {
|
|
40
|
+
return this.path.replace(/\/?\{([^{}]+)\}/g, (segment, raw) => {
|
|
41
|
+
const optional = raw.endsWith("?");
|
|
42
|
+
const [rawName, rawField] = (optional ? raw.slice(0, -1) : raw).split(":", 2);
|
|
43
|
+
const name = rawName.trim();
|
|
44
|
+
const field = rawField?.trim();
|
|
45
|
+
const value = params[name];
|
|
46
|
+
const resolved = field && value && typeof value === "object" ? value[field] : value;
|
|
47
|
+
if (typeof resolved === "undefined" || resolved === null || resolved === "") {
|
|
48
|
+
if (optional) return "";
|
|
49
|
+
throw new Error(`Missing required route parameter: ${name}`);
|
|
50
|
+
}
|
|
51
|
+
return `${segment.startsWith("/") ? "/" : ""}${encodeURIComponent(String(resolved))}`;
|
|
52
|
+
}) || "/";
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
//#endregion
|
|
57
|
+
export { Route };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const require_ClearRequest = require('../ClearRequest.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/core/Request.ts
|
|
4
|
+
var Request = class extends require_ClearRequest.ClearRequest {
|
|
5
|
+
original;
|
|
6
|
+
method = "GET";
|
|
7
|
+
path = "/";
|
|
8
|
+
url = "/";
|
|
9
|
+
headers = {};
|
|
10
|
+
constructor(init) {
|
|
11
|
+
super(init);
|
|
12
|
+
Object.assign(this, init);
|
|
13
|
+
}
|
|
14
|
+
getBody() {
|
|
15
|
+
return this.body ?? {};
|
|
16
|
+
}
|
|
17
|
+
header(name) {
|
|
18
|
+
if (typeof this.headers.get === "function") return this.headers.get(name) || "";
|
|
19
|
+
const headers = this.headers;
|
|
20
|
+
const value = headers[name] ?? headers[name.toLowerCase()];
|
|
21
|
+
return Array.isArray(value) ? String(value[0] ?? "") : String(value ?? "");
|
|
22
|
+
}
|
|
23
|
+
param(name) {
|
|
24
|
+
return this.params?.[name];
|
|
25
|
+
}
|
|
26
|
+
input(name) {
|
|
27
|
+
return this.body?.[name] ?? this.query?.[name] ?? this.params?.[name];
|
|
28
|
+
}
|
|
29
|
+
is(method) {
|
|
30
|
+
return this.method.toLowerCase() === String(method).toLowerCase();
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
exports.Request = Request;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { HttpMethod, RequestData } from "../types/basic.cjs";
|
|
2
|
+
import { Route } from "../Route.cjs";
|
|
3
|
+
import { ClearRequest } from "../ClearRequest.cjs";
|
|
4
|
+
|
|
5
|
+
//#region src/core/Request.d.ts
|
|
6
|
+
declare class Request<X = any, M = any> extends ClearRequest<X, M> {
|
|
7
|
+
original?: any;
|
|
8
|
+
method: string;
|
|
9
|
+
path: string;
|
|
10
|
+
url: string;
|
|
11
|
+
headers: Headers | Record<string, any>;
|
|
12
|
+
constructor(init?: Partial<Request<X, M>> & {
|
|
13
|
+
body?: RequestData;
|
|
14
|
+
query?: RequestData;
|
|
15
|
+
params?: RequestData;
|
|
16
|
+
route?: Route<X, M>;
|
|
17
|
+
});
|
|
18
|
+
getBody(): RequestData;
|
|
19
|
+
header(name: string): string;
|
|
20
|
+
param(name: string): any;
|
|
21
|
+
input(name: string): any;
|
|
22
|
+
is(method: HttpMethod | string): boolean;
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { Request };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { HttpMethod, RequestData } from "../types/basic.mjs";
|
|
2
|
+
import { Route } from "../Route.mjs";
|
|
3
|
+
import { ClearRequest } from "../ClearRequest.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/core/Request.d.ts
|
|
6
|
+
declare class Request<X = any, M = any> extends ClearRequest<X, M> {
|
|
7
|
+
original?: any;
|
|
8
|
+
method: string;
|
|
9
|
+
path: string;
|
|
10
|
+
url: string;
|
|
11
|
+
headers: Headers | Record<string, any>;
|
|
12
|
+
constructor(init?: Partial<Request<X, M>> & {
|
|
13
|
+
body?: RequestData;
|
|
14
|
+
query?: RequestData;
|
|
15
|
+
params?: RequestData;
|
|
16
|
+
route?: Route<X, M>;
|
|
17
|
+
});
|
|
18
|
+
getBody(): RequestData;
|
|
19
|
+
header(name: string): string;
|
|
20
|
+
param(name: string): any;
|
|
21
|
+
input(name: string): any;
|
|
22
|
+
is(method: HttpMethod | string): boolean;
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { Request };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ClearRequest } from "../ClearRequest.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/core/Request.ts
|
|
4
|
+
var Request = class extends ClearRequest {
|
|
5
|
+
original;
|
|
6
|
+
method = "GET";
|
|
7
|
+
path = "/";
|
|
8
|
+
url = "/";
|
|
9
|
+
headers = {};
|
|
10
|
+
constructor(init) {
|
|
11
|
+
super(init);
|
|
12
|
+
Object.assign(this, init);
|
|
13
|
+
}
|
|
14
|
+
getBody() {
|
|
15
|
+
return this.body ?? {};
|
|
16
|
+
}
|
|
17
|
+
header(name) {
|
|
18
|
+
if (typeof this.headers.get === "function") return this.headers.get(name) || "";
|
|
19
|
+
const headers = this.headers;
|
|
20
|
+
const value = headers[name] ?? headers[name.toLowerCase()];
|
|
21
|
+
return Array.isArray(value) ? String(value[0] ?? "") : String(value ?? "");
|
|
22
|
+
}
|
|
23
|
+
param(name) {
|
|
24
|
+
return this.params?.[name];
|
|
25
|
+
}
|
|
26
|
+
input(name) {
|
|
27
|
+
return this.body?.[name] ?? this.query?.[name] ?? this.params?.[name];
|
|
28
|
+
}
|
|
29
|
+
is(method) {
|
|
30
|
+
return this.method.toLowerCase() === String(method).toLowerCase();
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
export { Request };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/core/Response.ts
|
|
3
|
+
var Response = class {
|
|
4
|
+
body;
|
|
5
|
+
headers = new Headers();
|
|
6
|
+
sent = false;
|
|
7
|
+
statusCode = 200;
|
|
8
|
+
statusText = "OK";
|
|
9
|
+
constructor(init) {
|
|
10
|
+
const { status: _, ...rest } = init ?? {};
|
|
11
|
+
Object.assign(this, rest);
|
|
12
|
+
if (init?.headers && !(init.headers instanceof Headers)) this.headers = new Headers(init.headers);
|
|
13
|
+
if (init?.status && typeof init.status === "number") this.statusCode = init?.status;
|
|
14
|
+
}
|
|
15
|
+
status(code) {
|
|
16
|
+
this.statusCode = code;
|
|
17
|
+
return this;
|
|
18
|
+
}
|
|
19
|
+
setStatusText(text) {
|
|
20
|
+
this.statusText = text;
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
code(code) {
|
|
24
|
+
return this.status(code);
|
|
25
|
+
}
|
|
26
|
+
setHeader(name, value) {
|
|
27
|
+
this.headers.set(name, value);
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
header(name, value) {
|
|
31
|
+
return this.setHeader(name, value);
|
|
32
|
+
}
|
|
33
|
+
set(name, value) {
|
|
34
|
+
return this.setHeader(name, value);
|
|
35
|
+
}
|
|
36
|
+
type(contentType) {
|
|
37
|
+
return this.setHeader("Content-Type", contentType);
|
|
38
|
+
}
|
|
39
|
+
send(body) {
|
|
40
|
+
this.body = body;
|
|
41
|
+
this.sent = true;
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
json(body) {
|
|
45
|
+
return this.type("application/json; charset=utf-8").send(body);
|
|
46
|
+
}
|
|
47
|
+
html(body) {
|
|
48
|
+
return this.type("text/html; charset=utf-8").send(body);
|
|
49
|
+
}
|
|
50
|
+
text(body) {
|
|
51
|
+
return this.type("text/plain; charset=utf-8").send(body);
|
|
52
|
+
}
|
|
53
|
+
noContent() {
|
|
54
|
+
return this.status(204).send(null);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
//#endregion
|
|
59
|
+
exports.Response = Response;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/core/Response.d.ts
|
|
2
|
+
declare class Response {
|
|
3
|
+
[key: string]: any;
|
|
4
|
+
body: any;
|
|
5
|
+
headers: Headers;
|
|
6
|
+
sent: boolean;
|
|
7
|
+
statusCode: number;
|
|
8
|
+
statusText: string;
|
|
9
|
+
constructor(init?: Partial<Response | globalThis.Response>);
|
|
10
|
+
status(code: number): this;
|
|
11
|
+
setStatusText(text: string): this;
|
|
12
|
+
code(code: number): this;
|
|
13
|
+
setHeader(name: string, value: string): this;
|
|
14
|
+
header(name: string, value: string): this;
|
|
15
|
+
set(name: string, value: string): this;
|
|
16
|
+
type(contentType: string): this;
|
|
17
|
+
send(body?: any): this;
|
|
18
|
+
json(body: any): this;
|
|
19
|
+
html(body: string): this;
|
|
20
|
+
text(body: string): this;
|
|
21
|
+
noContent(): this;
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { Response };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/core/Response.d.ts
|
|
2
|
+
declare class Response {
|
|
3
|
+
[key: string]: any;
|
|
4
|
+
body: any;
|
|
5
|
+
headers: Headers;
|
|
6
|
+
sent: boolean;
|
|
7
|
+
statusCode: number;
|
|
8
|
+
statusText: string;
|
|
9
|
+
constructor(init?: Partial<Response | globalThis.Response>);
|
|
10
|
+
status(code: number): this;
|
|
11
|
+
setStatusText(text: string): this;
|
|
12
|
+
code(code: number): this;
|
|
13
|
+
setHeader(name: string, value: string): this;
|
|
14
|
+
header(name: string, value: string): this;
|
|
15
|
+
set(name: string, value: string): this;
|
|
16
|
+
type(contentType: string): this;
|
|
17
|
+
send(body?: any): this;
|
|
18
|
+
json(body: any): this;
|
|
19
|
+
html(body: string): this;
|
|
20
|
+
text(body: string): this;
|
|
21
|
+
noContent(): this;
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { Response };
|