clear-router 2.7.6 → 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/dist/ClearRequest.cjs +23 -0
  2. package/dist/ClearRequest.d.cts +28 -0
  3. package/dist/ClearRequest.d.mts +28 -0
  4. package/dist/ClearRequest.mjs +22 -0
  5. package/dist/Contracts.d.cts +12 -0
  6. package/dist/Contracts.d.mts +12 -0
  7. package/dist/Controller.cjs +12 -0
  8. package/dist/Controller.d.cts +14 -0
  9. package/dist/Controller.d.mts +14 -0
  10. package/dist/Controller.mjs +11 -0
  11. package/dist/{Request-DKXwa_W0.d.mts → Request-Ci0UQ-Vl.d.mts} +32 -5
  12. package/dist/ResourceRouteSelection.cjs +26 -0
  13. package/dist/ResourceRouteSelection.d.cts +20 -0
  14. package/dist/ResourceRouteSelection.d.mts +20 -0
  15. package/dist/ResourceRouteSelection.mjs +25 -0
  16. package/dist/ResourceRoutes.cjs +60 -0
  17. package/dist/ResourceRoutes.d.cts +37 -0
  18. package/dist/ResourceRoutes.d.mts +37 -0
  19. package/dist/ResourceRoutes.mjs +60 -0
  20. package/dist/Route.cjs +90 -0
  21. package/dist/Route.d.cts +62 -0
  22. package/dist/Route.d.mts +62 -0
  23. package/dist/Route.mjs +89 -0
  24. package/dist/core/Request.cjs +35 -0
  25. package/dist/core/Request.d.cts +25 -0
  26. package/dist/core/Request.d.mts +25 -0
  27. package/dist/core/Request.mjs +35 -0
  28. package/dist/core/Response.cjs +59 -0
  29. package/dist/core/Response.d.cts +24 -0
  30. package/dist/core/Response.d.mts +24 -0
  31. package/dist/core/Response.mjs +58 -0
  32. package/dist/{bindings-CLsZjOEy.cjs → core/bindings.cjs} +10 -160
  33. package/dist/{bindings-CNL7bpz5.d.mts → core/bindings.d.cts} +1 -1
  34. package/dist/{bindings-CxvtC8XS.d.cts → core/bindings.d.mts} +1 -1
  35. package/dist/{bindings-XLDXFpHZ.mjs → core/bindings.mjs} +3 -110
  36. package/dist/core/index.cjs +7 -17
  37. package/dist/core/index.d.cts +4 -1
  38. package/dist/core/index.d.mts +4 -1
  39. package/dist/core/index.mjs +4 -14
  40. package/dist/core/plugins.cjs +14 -0
  41. package/dist/core/plugins.d.cts +109 -0
  42. package/dist/core/plugins.d.mts +109 -0
  43. package/dist/core/plugins.mjs +13 -0
  44. package/dist/{responses-Bvnk0uvc.cjs → core/responses.cjs} +5 -20
  45. package/dist/{responses-BvETUeDL.mjs → core/responses.mjs} +2 -2
  46. package/dist/{router-C6W-k6sS.cjs → core/router.cjs} +67 -72
  47. package/dist/core/router.d.cts +286 -0
  48. package/dist/core/router.d.mts +286 -0
  49. package/dist/{router-Dc9w86Wn.mjs → core/router.mjs} +62 -62
  50. package/dist/decorators/index.cjs +1 -1
  51. package/dist/decorators/index.d.cts +1 -1
  52. package/dist/decorators/index.d.mts +1 -1
  53. package/dist/decorators/index.mjs +1 -1
  54. package/dist/decorators/setup.cjs +2 -2
  55. package/dist/decorators/setup.d.cts +1 -1
  56. package/dist/decorators/setup.d.mts +1 -2
  57. package/dist/decorators/setup.mjs +2 -2
  58. package/dist/express/index.cjs +2 -265
  59. package/dist/express/index.d.cts +1 -127
  60. package/dist/express/index.d.mts +1 -127
  61. package/dist/express/index.mjs +1 -264
  62. package/dist/express/router.cjs +265 -0
  63. package/dist/express/router.d.cts +132 -0
  64. package/dist/express/router.d.mts +132 -0
  65. package/dist/express/router.mjs +265 -0
  66. package/dist/fastify/index.cjs +2 -254
  67. package/dist/fastify/index.d.cts +1 -125
  68. package/dist/fastify/index.d.mts +1 -125
  69. package/dist/fastify/index.mjs +1 -253
  70. package/dist/fastify/router.cjs +254 -0
  71. package/dist/fastify/router.d.cts +130 -0
  72. package/dist/fastify/router.d.mts +130 -0
  73. package/dist/fastify/router.mjs +254 -0
  74. package/dist/h3/index.cjs +2 -260
  75. package/dist/h3/index.d.cts +1 -128
  76. package/dist/h3/index.d.mts +1 -128
  77. package/dist/h3/index.mjs +1 -259
  78. package/dist/h3/router.cjs +260 -0
  79. package/dist/h3/router.d.cts +133 -0
  80. package/dist/h3/router.d.mts +133 -0
  81. package/dist/h3/router.mjs +260 -0
  82. package/dist/hono/index.cjs +2 -251
  83. package/dist/hono/index.d.cts +1 -130
  84. package/dist/hono/index.d.mts +1 -130
  85. package/dist/hono/index.mjs +1 -250
  86. package/dist/hono/router.cjs +251 -0
  87. package/dist/hono/router.d.cts +135 -0
  88. package/dist/hono/router.d.mts +135 -0
  89. package/dist/hono/router.mjs +251 -0
  90. package/dist/index.cjs +16 -1097
  91. package/dist/index.d.cts +9 -563
  92. package/dist/index.d.mts +9 -563
  93. package/dist/index.mjs +8 -1089
  94. package/dist/koa/index.cjs +2 -261
  95. package/dist/koa/index.d.cts +1 -131
  96. package/dist/koa/index.d.mts +1 -131
  97. package/dist/koa/index.mjs +1 -260
  98. package/dist/koa/router.cjs +261 -0
  99. package/dist/koa/router.d.cts +136 -0
  100. package/dist/koa/router.d.mts +136 -0
  101. package/dist/koa/router.mjs +261 -0
  102. package/dist/types/basic.d.cts +53 -0
  103. package/dist/types/basic.d.mts +11 -1
  104. package/dist/types/express.d.cts +48 -0
  105. package/dist/types/express.d.mts +10 -4
  106. package/dist/types/fastify.d.cts +24 -0
  107. package/dist/types/fastify.d.mts +7 -4
  108. package/dist/types/h3.d.cts +46 -0
  109. package/dist/types/h3.d.mts +10 -5
  110. package/dist/types/hono.d.cts +22 -0
  111. package/dist/types/hono.d.mts +8 -6
  112. package/dist/types/koa.d.cts +26 -0
  113. package/dist/types/koa.d.mts +7 -5
  114. package/package.json +1 -1
  115. package/dist/router-BEgAxp5A.d.cts +0 -649
  116. package/dist/router-DKKYx23P.d.mts +0 -649
@@ -0,0 +1,62 @@
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
+ /**
9
+ * @class clear-router Route
10
+ * @description A route describes a single enpoint on clear-router
11
+ * @author 3m1n3nc3
12
+ * @repository https://github.com/arkstack-tmp/clear-router
13
+ */
14
+ declare class Route<X = any, M = Middleware$1 | Middleware, H = any> {
15
+ ctx: X;
16
+ body: RequestData;
17
+ query: RequestData;
18
+ params: RequestData;
19
+ clearRequest: ClearRequest;
20
+ methods: HttpMethod[];
21
+ path: string;
22
+ registrationPaths: string[];
23
+ parameters: RouteParameter[];
24
+ routeName?: string;
25
+ handler: H;
26
+ middlewares: M[];
27
+ controllerName?: string;
28
+ actionName?: string;
29
+ handlerType: 'function' | 'controller';
30
+ middlewareCount: number;
31
+ constructor(methods: HttpMethod[], path: string, handler: H, middlewares?: M[], options?: {
32
+ registrationPaths?: string[];
33
+ parameters?: RouteParameter[];
34
+ onName?: (name: string, route: Route<X, M, H>, previousName?: string) => void;
35
+ normalizeMiddleware?: (middleware: M) => M;
36
+ });
37
+ private onName?;
38
+ private normalizeMiddleware?;
39
+ /**
40
+ * Set the route name
41
+ *
42
+ * @param name
43
+ * @returns
44
+ */
45
+ name(name: string): this;
46
+ /**
47
+ * Register one or more middleware that will be executed before the route.
48
+ *
49
+ * @param middlewares
50
+ * @returns
51
+ */
52
+ middleware(middlewares: M[] | M): this;
53
+ /**
54
+ * Get the path generated and accessible by this route
55
+ *
56
+ * @param params
57
+ * @returns
58
+ */
59
+ toPath(params?: RequestData): string;
60
+ }
61
+ //#endregion
62
+ export { Route };
@@ -0,0 +1,62 @@
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
+ /**
9
+ * @class clear-router Route
10
+ * @description A route describes a single enpoint on clear-router
11
+ * @author 3m1n3nc3
12
+ * @repository https://github.com/arkstack-tmp/clear-router
13
+ */
14
+ declare class Route<X = any, M = Middleware$1 | Middleware, H = any> {
15
+ ctx: X;
16
+ body: RequestData;
17
+ query: RequestData;
18
+ params: RequestData;
19
+ clearRequest: ClearRequest;
20
+ methods: HttpMethod[];
21
+ path: string;
22
+ registrationPaths: string[];
23
+ parameters: RouteParameter[];
24
+ routeName?: string;
25
+ handler: H;
26
+ middlewares: M[];
27
+ controllerName?: string;
28
+ actionName?: string;
29
+ handlerType: 'function' | 'controller';
30
+ middlewareCount: number;
31
+ constructor(methods: HttpMethod[], path: string, handler: H, middlewares?: M[], options?: {
32
+ registrationPaths?: string[];
33
+ parameters?: RouteParameter[];
34
+ onName?: (name: string, route: Route<X, M, H>, previousName?: string) => void;
35
+ normalizeMiddleware?: (middleware: M) => M;
36
+ });
37
+ private onName?;
38
+ private normalizeMiddleware?;
39
+ /**
40
+ * Set the route name
41
+ *
42
+ * @param name
43
+ * @returns
44
+ */
45
+ name(name: string): this;
46
+ /**
47
+ * Register one or more middleware that will be executed before the route.
48
+ *
49
+ * @param middlewares
50
+ * @returns
51
+ */
52
+ middleware(middlewares: M[] | M): this;
53
+ /**
54
+ * Get the path generated and accessible by this route
55
+ *
56
+ * @param params
57
+ * @returns
58
+ */
59
+ toPath(params?: RequestData): string;
60
+ }
61
+ //#endregion
62
+ export { Route };
package/dist/Route.mjs ADDED
@@ -0,0 +1,89 @@
1
+ //#region src/Route.ts
2
+ /**
3
+ * @class clear-router Route
4
+ * @description A route describes a single enpoint on clear-router
5
+ * @author 3m1n3nc3
6
+ * @repository https://github.com/arkstack-tmp/clear-router
7
+ */
8
+ var Route = class {
9
+ ctx;
10
+ body = {};
11
+ query = {};
12
+ params = {};
13
+ clearRequest;
14
+ methods;
15
+ path;
16
+ registrationPaths;
17
+ parameters;
18
+ routeName;
19
+ handler;
20
+ middlewares;
21
+ controllerName;
22
+ actionName;
23
+ handlerType;
24
+ middlewareCount;
25
+ constructor(methods, path, handler, middlewares = [], options = {}) {
26
+ this.methods = methods;
27
+ this.path = path;
28
+ this.registrationPaths = options.registrationPaths || [path];
29
+ this.parameters = options.parameters || [];
30
+ this.handler = handler;
31
+ this.middlewares = middlewares;
32
+ this.handlerType = Array.isArray(handler) ? "controller" : "function";
33
+ this.middlewareCount = middlewares.length;
34
+ this.controllerName = Array.isArray(handler) ? handler[0]?.name : void 0;
35
+ this.actionName = Array.isArray(handler) ? handler[1] : typeof handler === "function" ? handler.constructor.name ?? handler.name : void 0;
36
+ this.onName = options.onName;
37
+ this.normalizeMiddleware = options.normalizeMiddleware;
38
+ }
39
+ onName;
40
+ normalizeMiddleware;
41
+ /**
42
+ * Set the route name
43
+ *
44
+ * @param name
45
+ * @returns
46
+ */
47
+ name(name) {
48
+ const previousName = this.routeName;
49
+ this.routeName = name;
50
+ this.onName?.(name, this, previousName);
51
+ return this;
52
+ }
53
+ /**
54
+ * Register one or more middleware that will be executed before the route.
55
+ *
56
+ * @param middlewares
57
+ * @returns
58
+ */
59
+ middleware(middlewares) {
60
+ const normalized = (Array.isArray(middlewares) ? middlewares : [middlewares]).map((middleware) => this.normalizeMiddleware?.(middleware) ?? middleware);
61
+ this.middlewares.push(...normalized);
62
+ this.middlewareCount = this.middlewares.length;
63
+ return this;
64
+ }
65
+ /**
66
+ * Get the path generated and accessible by this route
67
+ *
68
+ * @param params
69
+ * @returns
70
+ */
71
+ toPath(params = {}) {
72
+ return this.path.replace(/\/?\{([^{}]+)\}/g, (segment, raw) => {
73
+ const optional = raw.endsWith("?");
74
+ const [rawName, rawField] = (optional ? raw.slice(0, -1) : raw).split(":", 2);
75
+ const name = rawName.trim();
76
+ const field = rawField?.trim();
77
+ const value = params[name];
78
+ const resolved = field && value && typeof value === "object" ? value[field] : value;
79
+ if (typeof resolved === "undefined" || resolved === null || resolved === "") {
80
+ if (optional) return "";
81
+ throw new Error(`Missing required route parameter: ${name}`);
82
+ }
83
+ return `${segment.startsWith("/") ? "/" : ""}${encodeURIComponent(String(resolved))}`;
84
+ }) || "/";
85
+ }
86
+ };
87
+
88
+ //#endregion
89
+ 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 };
@@ -0,0 +1,58 @@
1
+ //#region src/core/Response.ts
2
+ var Response = class {
3
+ body;
4
+ headers = new Headers();
5
+ sent = false;
6
+ statusCode = 200;
7
+ statusText = "OK";
8
+ constructor(init) {
9
+ const { status: _, ...rest } = init ?? {};
10
+ Object.assign(this, rest);
11
+ if (init?.headers && !(init.headers instanceof Headers)) this.headers = new Headers(init.headers);
12
+ if (init?.status && typeof init.status === "number") this.statusCode = init?.status;
13
+ }
14
+ status(code) {
15
+ this.statusCode = code;
16
+ return this;
17
+ }
18
+ setStatusText(text) {
19
+ this.statusText = text;
20
+ return this;
21
+ }
22
+ code(code) {
23
+ return this.status(code);
24
+ }
25
+ setHeader(name, value) {
26
+ this.headers.set(name, value);
27
+ return this;
28
+ }
29
+ header(name, value) {
30
+ return this.setHeader(name, value);
31
+ }
32
+ set(name, value) {
33
+ return this.setHeader(name, value);
34
+ }
35
+ type(contentType) {
36
+ return this.setHeader("Content-Type", contentType);
37
+ }
38
+ send(body) {
39
+ this.body = body;
40
+ this.sent = true;
41
+ return this;
42
+ }
43
+ json(body) {
44
+ return this.type("application/json; charset=utf-8").send(body);
45
+ }
46
+ html(body) {
47
+ return this.type("text/html; charset=utf-8").send(body);
48
+ }
49
+ text(body) {
50
+ return this.type("text/plain; charset=utf-8").send(body);
51
+ }
52
+ noContent() {
53
+ return this.status(204).send(null);
54
+ }
55
+ };
56
+
57
+ //#endregion
58
+ export { Response };
@@ -1,114 +1,6 @@
1
+ const require_Request = require('./Request.cjs');
2
+ const require_Response = require('./Response.cjs');
1
3
 
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
- //#region src/core/Request.ts
24
- var Request = class extends ClearRequest {
25
- original;
26
- method = "GET";
27
- path = "/";
28
- url = "/";
29
- headers = {};
30
- constructor(init) {
31
- super(init);
32
- Object.assign(this, init);
33
- }
34
- getBody() {
35
- return this.body ?? {};
36
- }
37
- header(name) {
38
- if (typeof this.headers.get === "function") return this.headers.get(name) || "";
39
- const headers = this.headers;
40
- const value = headers[name] ?? headers[name.toLowerCase()];
41
- return Array.isArray(value) ? String(value[0] ?? "") : String(value ?? "");
42
- }
43
- param(name) {
44
- return this.params?.[name];
45
- }
46
- input(name) {
47
- return this.body?.[name] ?? this.query?.[name] ?? this.params?.[name];
48
- }
49
- is(method) {
50
- return this.method.toLowerCase() === String(method).toLowerCase();
51
- }
52
- };
53
-
54
- //#endregion
55
- //#region src/core/Response.ts
56
- var Response = class {
57
- body;
58
- headers = new Headers();
59
- sent = false;
60
- statusCode = 200;
61
- statusText = "OK";
62
- constructor(init) {
63
- const { status: _, ...rest } = init ?? {};
64
- Object.assign(this, rest);
65
- if (init?.headers && !(init.headers instanceof Headers)) this.headers = new Headers(init.headers);
66
- if (init?.status && typeof init.status === "number") this.statusCode = init?.status;
67
- }
68
- status(code) {
69
- this.statusCode = code;
70
- return this;
71
- }
72
- setStatusText(text) {
73
- this.statusText = text;
74
- return this;
75
- }
76
- code(code) {
77
- return this.status(code);
78
- }
79
- setHeader(name, value) {
80
- this.headers.set(name, value);
81
- return this;
82
- }
83
- header(name, value) {
84
- return this.setHeader(name, value);
85
- }
86
- set(name, value) {
87
- return this.setHeader(name, value);
88
- }
89
- type(contentType) {
90
- return this.setHeader("Content-Type", contentType);
91
- }
92
- send(body) {
93
- this.body = body;
94
- this.sent = true;
95
- return this;
96
- }
97
- json(body) {
98
- return this.type("application/json; charset=utf-8").send(body);
99
- }
100
- html(body) {
101
- return this.type("text/html; charset=utf-8").send(body);
102
- }
103
- text(body) {
104
- return this.type("text/plain; charset=utf-8").send(body);
105
- }
106
- noContent() {
107
- return this.status(204).send(null);
108
- }
109
- };
110
-
111
- //#endregion
112
4
  //#region src/core/bindings.ts
113
5
  const metadataKey = Symbol.for("clear-router:binding-metadata");
114
6
  const bindings = /* @__PURE__ */ new WeakMap();
@@ -130,8 +22,8 @@ var Container = class {
130
22
  return Object.fromEntries(this.registry.entries());
131
23
  }
132
24
  static async resolve(token, ctx, autoDiscover = false) {
133
- if (token === Request) return ctx.clearRequest;
134
- if (token === Response) return ctx.clearResponse;
25
+ if (token === require_Request.Request) return ctx.clearRequest;
26
+ if (token === require_Response.Response) return ctx.clearResponse;
135
27
  const binding = this.getBinding(token);
136
28
  if (binding) return this.resolveBinding(binding, ctx, autoDiscover);
137
29
  if (autoDiscover && typeof token === "function") return new token();
@@ -259,51 +151,9 @@ function isClass(value) {
259
151
  }
260
152
 
261
153
  //#endregion
262
- Object.defineProperty(exports, 'Bind', {
263
- enumerable: true,
264
- get: function () {
265
- return Bind;
266
- }
267
- });
268
- Object.defineProperty(exports, 'Container', {
269
- enumerable: true,
270
- get: function () {
271
- return Container;
272
- }
273
- });
274
- Object.defineProperty(exports, 'Request', {
275
- enumerable: true,
276
- get: function () {
277
- return Request;
278
- }
279
- });
280
- Object.defineProperty(exports, 'Response', {
281
- enumerable: true,
282
- get: function () {
283
- return Response;
284
- }
285
- });
286
- Object.defineProperty(exports, 'getBindingMetadataFromTargets', {
287
- enumerable: true,
288
- get: function () {
289
- return getBindingMetadataFromTargets;
290
- }
291
- });
292
- Object.defineProperty(exports, 'getDesignParamTypes', {
293
- enumerable: true,
294
- get: function () {
295
- return getDesignParamTypes;
296
- }
297
- });
298
- Object.defineProperty(exports, 'getStandardMetadata', {
299
- enumerable: true,
300
- get: function () {
301
- return getStandardMetadata;
302
- }
303
- });
304
- Object.defineProperty(exports, 'isClass', {
305
- enumerable: true,
306
- get: function () {
307
- return isClass;
308
- }
309
- });
154
+ exports.Bind = Bind;
155
+ exports.Container = Container;
156
+ exports.getBindingMetadataFromTargets = getBindingMetadataFromTargets;
157
+ exports.getDesignParamTypes = getDesignParamTypes;
158
+ exports.getStandardMetadata = getStandardMetadata;
159
+ exports.isClass = isClass;
@@ -22,4 +22,4 @@ declare class Container {
22
22
  }
23
23
  declare function Bind(...tokens: BindToken[]): BindDecorator;
24
24
  //#endregion
25
- export { BindValue as a, BindToken as i, BindDecorator as n, Container as o, BindFactory as r, Bind as t };
25
+ export { Bind, BindDecorator, BindFactory, BindToken, BindValue, Container };