clear-router 2.7.5 → 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 +5 -6
- package/dist/types/hono.d.cts +21 -0
- package/dist/types/hono.d.mts +5 -5
- package/dist/types/koa.d.cts +25 -0
- package/dist/types/koa.d.mts +5 -5
- package/package.json +1 -1
- package/dist/router-CYBshGMl.d.mts +0 -652
- package/dist/router-tpnSi_Y7.d.cts +0 -652
|
@@ -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
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
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 {
|
|
25
|
+
export { Bind, BindDecorator, BindFactory, BindToken, BindValue, Container };
|
|
@@ -22,4 +22,4 @@ declare class Container {
|
|
|
22
22
|
}
|
|
23
23
|
declare function Bind(...tokens: BindToken[]): BindDecorator;
|
|
24
24
|
//#endregion
|
|
25
|
-
export {
|
|
25
|
+
export { Bind, BindDecorator, BindFactory, BindToken, BindValue, Container };
|
|
@@ -1,113 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
//#region src/core/Request.ts
|
|
23
|
-
var Request = class extends ClearRequest {
|
|
24
|
-
original;
|
|
25
|
-
method = "GET";
|
|
26
|
-
path = "/";
|
|
27
|
-
url = "/";
|
|
28
|
-
headers = {};
|
|
29
|
-
constructor(init) {
|
|
30
|
-
super(init);
|
|
31
|
-
Object.assign(this, init);
|
|
32
|
-
}
|
|
33
|
-
getBody() {
|
|
34
|
-
return this.body ?? {};
|
|
35
|
-
}
|
|
36
|
-
header(name) {
|
|
37
|
-
if (typeof this.headers.get === "function") return this.headers.get(name) || "";
|
|
38
|
-
const headers = this.headers;
|
|
39
|
-
const value = headers[name] ?? headers[name.toLowerCase()];
|
|
40
|
-
return Array.isArray(value) ? String(value[0] ?? "") : String(value ?? "");
|
|
41
|
-
}
|
|
42
|
-
param(name) {
|
|
43
|
-
return this.params?.[name];
|
|
44
|
-
}
|
|
45
|
-
input(name) {
|
|
46
|
-
return this.body?.[name] ?? this.query?.[name] ?? this.params?.[name];
|
|
47
|
-
}
|
|
48
|
-
is(method) {
|
|
49
|
-
return this.method.toLowerCase() === String(method).toLowerCase();
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
//#endregion
|
|
54
|
-
//#region src/core/Response.ts
|
|
55
|
-
var Response = class {
|
|
56
|
-
body;
|
|
57
|
-
headers = new Headers();
|
|
58
|
-
sent = false;
|
|
59
|
-
statusCode = 200;
|
|
60
|
-
statusText = "OK";
|
|
61
|
-
constructor(init) {
|
|
62
|
-
const { status: _, ...rest } = init ?? {};
|
|
63
|
-
Object.assign(this, rest);
|
|
64
|
-
if (init?.headers && !(init.headers instanceof Headers)) this.headers = new Headers(init.headers);
|
|
65
|
-
if (init?.status && typeof init.status === "number") this.statusCode = init?.status;
|
|
66
|
-
}
|
|
67
|
-
status(code) {
|
|
68
|
-
this.statusCode = code;
|
|
69
|
-
return this;
|
|
70
|
-
}
|
|
71
|
-
setStatusText(text) {
|
|
72
|
-
this.statusText = text;
|
|
73
|
-
return this;
|
|
74
|
-
}
|
|
75
|
-
code(code) {
|
|
76
|
-
return this.status(code);
|
|
77
|
-
}
|
|
78
|
-
setHeader(name, value) {
|
|
79
|
-
this.headers.set(name, value);
|
|
80
|
-
return this;
|
|
81
|
-
}
|
|
82
|
-
header(name, value) {
|
|
83
|
-
return this.setHeader(name, value);
|
|
84
|
-
}
|
|
85
|
-
set(name, value) {
|
|
86
|
-
return this.setHeader(name, value);
|
|
87
|
-
}
|
|
88
|
-
type(contentType) {
|
|
89
|
-
return this.setHeader("Content-Type", contentType);
|
|
90
|
-
}
|
|
91
|
-
send(body) {
|
|
92
|
-
this.body = body;
|
|
93
|
-
this.sent = true;
|
|
94
|
-
return this;
|
|
95
|
-
}
|
|
96
|
-
json(body) {
|
|
97
|
-
return this.type("application/json; charset=utf-8").send(body);
|
|
98
|
-
}
|
|
99
|
-
html(body) {
|
|
100
|
-
return this.type("text/html; charset=utf-8").send(body);
|
|
101
|
-
}
|
|
102
|
-
text(body) {
|
|
103
|
-
return this.type("text/plain; charset=utf-8").send(body);
|
|
104
|
-
}
|
|
105
|
-
noContent() {
|
|
106
|
-
return this.status(204).send(null);
|
|
107
|
-
}
|
|
108
|
-
};
|
|
1
|
+
import { Request } from "./Request.mjs";
|
|
2
|
+
import { Response } from "./Response.mjs";
|
|
109
3
|
|
|
110
|
-
//#endregion
|
|
111
4
|
//#region src/core/bindings.ts
|
|
112
5
|
const metadataKey = Symbol.for("clear-router:binding-metadata");
|
|
113
6
|
const bindings = /* @__PURE__ */ new WeakMap();
|
|
@@ -258,4 +151,4 @@ function isClass(value) {
|
|
|
258
151
|
}
|
|
259
152
|
|
|
260
153
|
//#endregion
|
|
261
|
-
export {
|
|
154
|
+
export { Bind, Container, getBindingMetadataFromTargets, getDesignParamTypes, getStandardMetadata, isClass };
|
package/dist/core/index.cjs
CHANGED
|
@@ -1,20 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
//#region src/core/plugins.ts
|
|
6
|
-
/**
|
|
7
|
-
* Creates a new plugin
|
|
8
|
-
*
|
|
9
|
-
* @param plugin
|
|
10
|
-
* @returns
|
|
11
|
-
*/
|
|
12
|
-
function definePlugin(plugin) {
|
|
13
|
-
return plugin;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
//#endregion
|
|
17
|
-
exports.CoreRouter = require_router.CoreRouter;
|
|
18
|
-
exports.Request = require_bindings.Request;
|
|
19
|
-
exports.Response = require_bindings.Response;
|
|
20
|
-
exports.definePlugin = definePlugin;
|
|
1
|
+
const require_Request = require('./Request.cjs');
|
|
2
|
+
const require_Response = require('./Response.cjs');
|
|
3
|
+
const require_plugins = require('./plugins.cjs');
|
|
4
|
+
const require_router = require('./router.cjs');
|
package/dist/core/index.d.cts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Response } from "./Response.cjs";
|
|
2
|
+
import { Request } from "./Request.cjs";
|
|
3
|
+
import { ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, definePlugin } from "./plugins.cjs";
|
|
4
|
+
import { CoreRouter } from "./router.cjs";
|
|
2
5
|
export { ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, CoreRouter, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response, definePlugin };
|
package/dist/core/index.d.mts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Response } from "./Response.mjs";
|
|
2
|
+
import { Request } from "./Request.mjs";
|
|
3
|
+
import { ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, definePlugin } from "./plugins.mjs";
|
|
4
|
+
import { CoreRouter } from "./router.mjs";
|
|
2
5
|
export { ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, CoreRouter, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response, definePlugin };
|
package/dist/core/index.mjs
CHANGED
|
@@ -1,16 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Request } from "./Request.mjs";
|
|
2
|
+
import { Response } from "./Response.mjs";
|
|
3
|
+
import { definePlugin } from "./plugins.mjs";
|
|
4
|
+
import { CoreRouter } from "./router.mjs";
|
|
3
5
|
|
|
4
|
-
//#region src/core/plugins.ts
|
|
5
|
-
/**
|
|
6
|
-
* Creates a new plugin
|
|
7
|
-
*
|
|
8
|
-
* @param plugin
|
|
9
|
-
* @returns
|
|
10
|
-
*/
|
|
11
|
-
function definePlugin(plugin) {
|
|
12
|
-
return plugin;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
//#endregion
|
|
16
6
|
export { CoreRouter, Request, Response, definePlugin };
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { RouterConfig } from "../types/basic.cjs";
|
|
2
|
+
import { Response } from "./Response.cjs";
|
|
3
|
+
import { Request } from "./Request.cjs";
|
|
4
|
+
import { BindToken, BindValue, Container } from "./bindings.cjs";
|
|
5
|
+
|
|
6
|
+
//#region src/core/plugins.d.ts
|
|
7
|
+
type PluginSetupResult = void | Promise<void>;
|
|
8
|
+
interface ClearRouterPluginRequestContext<HttpContext = any> {
|
|
9
|
+
ctx: HttpContext;
|
|
10
|
+
request: Request;
|
|
11
|
+
response: Response;
|
|
12
|
+
getBindings: () => Record<string, BindValue>;
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
}
|
|
15
|
+
interface ClearRouterPluginArgumentsContext<X = any> extends ClearRouterPluginRequestContext<X> {
|
|
16
|
+
target?: object;
|
|
17
|
+
method?: PropertyKey;
|
|
18
|
+
handler?: object;
|
|
19
|
+
metadata?: object;
|
|
20
|
+
tokens: BindToken[];
|
|
21
|
+
designTokens: BindToken[];
|
|
22
|
+
}
|
|
23
|
+
type PluginBindFactory<T = any, X = any> = (ctx: ClearRouterPluginRequestContext<X>) => T | Promise<T>;
|
|
24
|
+
type PluginBindValue<T = any, X = any> = BindValue<T> | PluginBindFactory<T, X>;
|
|
25
|
+
type PluginBind<X = any> = <T>(token: BindToken<T>, value: PluginBindValue<T, X>) => void;
|
|
26
|
+
type PluginArgumentsResolver<HttpContext = any> = (ctx: ClearRouterPluginArgumentsContext<HttpContext>) => any[] | undefined | Promise<any[] | undefined>;
|
|
27
|
+
interface ClearRouterPluginContext<Options = any, HttpContext = any> {
|
|
28
|
+
/**
|
|
29
|
+
* The service container
|
|
30
|
+
*/
|
|
31
|
+
container: typeof Container;
|
|
32
|
+
/**
|
|
33
|
+
* Register service container bindings
|
|
34
|
+
*/
|
|
35
|
+
bind: PluginBind<HttpContext>;
|
|
36
|
+
/**
|
|
37
|
+
* Replace all controller method arguments
|
|
38
|
+
* @param resolver
|
|
39
|
+
* @returns
|
|
40
|
+
*/
|
|
41
|
+
resolveArguments: (resolver: PluginArgumentsResolver<HttpContext>) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Use the current http context
|
|
44
|
+
*/
|
|
45
|
+
useHttpContext: (resolver: PluginArgumentsResolver<HttpContext>) => void;
|
|
46
|
+
/**
|
|
47
|
+
* All registered service container bindings
|
|
48
|
+
*/
|
|
49
|
+
bindings: Record<string, BindValue>;
|
|
50
|
+
/**
|
|
51
|
+
* Configures the router with the given options, such as method override settings
|
|
52
|
+
*
|
|
53
|
+
* @param options
|
|
54
|
+
* @returns
|
|
55
|
+
*/
|
|
56
|
+
configure: (options: RouterConfig) => void;
|
|
57
|
+
/**
|
|
58
|
+
* Default configuration used for everytime the router is reset
|
|
59
|
+
*
|
|
60
|
+
* @param options
|
|
61
|
+
*/
|
|
62
|
+
configureDefaults: (options: RouterConfig) => void;
|
|
63
|
+
/**
|
|
64
|
+
* The current Request instance
|
|
65
|
+
*/
|
|
66
|
+
readonly request?: Request;
|
|
67
|
+
/**
|
|
68
|
+
* The current Response instance
|
|
69
|
+
* @returns
|
|
70
|
+
*/
|
|
71
|
+
readonly response?: Response;
|
|
72
|
+
/**
|
|
73
|
+
* Get the current Request instance
|
|
74
|
+
* @returns
|
|
75
|
+
*/
|
|
76
|
+
getRequest: () => Request | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* Get the current Response instance
|
|
79
|
+
* @returns
|
|
80
|
+
*/
|
|
81
|
+
getResponse: () => Response | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* Plugin configuration options
|
|
84
|
+
*/
|
|
85
|
+
options: Options;
|
|
86
|
+
}
|
|
87
|
+
interface ClearRouterPlugin<Options = any, HttpContext = any> {
|
|
88
|
+
/**
|
|
89
|
+
* The name of the plugin
|
|
90
|
+
*/
|
|
91
|
+
name?: string;
|
|
92
|
+
/**
|
|
93
|
+
* Plugin setup an implemnetation
|
|
94
|
+
*
|
|
95
|
+
* @param ctx
|
|
96
|
+
* @returns
|
|
97
|
+
*/
|
|
98
|
+
setup: (ctx: ClearRouterPluginContext<Options, HttpContext>) => PluginSetupResult;
|
|
99
|
+
}
|
|
100
|
+
type ClearRouterPluginInput<Options = any, HttpContext = any> = ClearRouterPlugin<Options> | ((ctx: ClearRouterPluginContext<Options, HttpContext>) => PluginSetupResult);
|
|
101
|
+
/**
|
|
102
|
+
* Creates a new plugin
|
|
103
|
+
*
|
|
104
|
+
* @param plugin
|
|
105
|
+
* @returns
|
|
106
|
+
*/
|
|
107
|
+
declare function definePlugin<Options = any, HttpContext = any>(plugin: ClearRouterPlugin<Options, HttpContext>): ClearRouterPlugin<Options, HttpContext>;
|
|
108
|
+
//#endregion
|
|
109
|
+
export { ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, definePlugin };
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { RouterConfig } from "../types/basic.mjs";
|
|
2
|
+
import { Response } from "./Response.mjs";
|
|
3
|
+
import { Request } from "./Request.mjs";
|
|
4
|
+
import { BindToken, BindValue, Container } from "./bindings.mjs";
|
|
5
|
+
|
|
6
|
+
//#region src/core/plugins.d.ts
|
|
7
|
+
type PluginSetupResult = void | Promise<void>;
|
|
8
|
+
interface ClearRouterPluginRequestContext<HttpContext = any> {
|
|
9
|
+
ctx: HttpContext;
|
|
10
|
+
request: Request;
|
|
11
|
+
response: Response;
|
|
12
|
+
getBindings: () => Record<string, BindValue>;
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
}
|
|
15
|
+
interface ClearRouterPluginArgumentsContext<X = any> extends ClearRouterPluginRequestContext<X> {
|
|
16
|
+
target?: object;
|
|
17
|
+
method?: PropertyKey;
|
|
18
|
+
handler?: object;
|
|
19
|
+
metadata?: object;
|
|
20
|
+
tokens: BindToken[];
|
|
21
|
+
designTokens: BindToken[];
|
|
22
|
+
}
|
|
23
|
+
type PluginBindFactory<T = any, X = any> = (ctx: ClearRouterPluginRequestContext<X>) => T | Promise<T>;
|
|
24
|
+
type PluginBindValue<T = any, X = any> = BindValue<T> | PluginBindFactory<T, X>;
|
|
25
|
+
type PluginBind<X = any> = <T>(token: BindToken<T>, value: PluginBindValue<T, X>) => void;
|
|
26
|
+
type PluginArgumentsResolver<HttpContext = any> = (ctx: ClearRouterPluginArgumentsContext<HttpContext>) => any[] | undefined | Promise<any[] | undefined>;
|
|
27
|
+
interface ClearRouterPluginContext<Options = any, HttpContext = any> {
|
|
28
|
+
/**
|
|
29
|
+
* The service container
|
|
30
|
+
*/
|
|
31
|
+
container: typeof Container;
|
|
32
|
+
/**
|
|
33
|
+
* Register service container bindings
|
|
34
|
+
*/
|
|
35
|
+
bind: PluginBind<HttpContext>;
|
|
36
|
+
/**
|
|
37
|
+
* Replace all controller method arguments
|
|
38
|
+
* @param resolver
|
|
39
|
+
* @returns
|
|
40
|
+
*/
|
|
41
|
+
resolveArguments: (resolver: PluginArgumentsResolver<HttpContext>) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Use the current http context
|
|
44
|
+
*/
|
|
45
|
+
useHttpContext: (resolver: PluginArgumentsResolver<HttpContext>) => void;
|
|
46
|
+
/**
|
|
47
|
+
* All registered service container bindings
|
|
48
|
+
*/
|
|
49
|
+
bindings: Record<string, BindValue>;
|
|
50
|
+
/**
|
|
51
|
+
* Configures the router with the given options, such as method override settings
|
|
52
|
+
*
|
|
53
|
+
* @param options
|
|
54
|
+
* @returns
|
|
55
|
+
*/
|
|
56
|
+
configure: (options: RouterConfig) => void;
|
|
57
|
+
/**
|
|
58
|
+
* Default configuration used for everytime the router is reset
|
|
59
|
+
*
|
|
60
|
+
* @param options
|
|
61
|
+
*/
|
|
62
|
+
configureDefaults: (options: RouterConfig) => void;
|
|
63
|
+
/**
|
|
64
|
+
* The current Request instance
|
|
65
|
+
*/
|
|
66
|
+
readonly request?: Request;
|
|
67
|
+
/**
|
|
68
|
+
* The current Response instance
|
|
69
|
+
* @returns
|
|
70
|
+
*/
|
|
71
|
+
readonly response?: Response;
|
|
72
|
+
/**
|
|
73
|
+
* Get the current Request instance
|
|
74
|
+
* @returns
|
|
75
|
+
*/
|
|
76
|
+
getRequest: () => Request | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* Get the current Response instance
|
|
79
|
+
* @returns
|
|
80
|
+
*/
|
|
81
|
+
getResponse: () => Response | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* Plugin configuration options
|
|
84
|
+
*/
|
|
85
|
+
options: Options;
|
|
86
|
+
}
|
|
87
|
+
interface ClearRouterPlugin<Options = any, HttpContext = any> {
|
|
88
|
+
/**
|
|
89
|
+
* The name of the plugin
|
|
90
|
+
*/
|
|
91
|
+
name?: string;
|
|
92
|
+
/**
|
|
93
|
+
* Plugin setup an implemnetation
|
|
94
|
+
*
|
|
95
|
+
* @param ctx
|
|
96
|
+
* @returns
|
|
97
|
+
*/
|
|
98
|
+
setup: (ctx: ClearRouterPluginContext<Options, HttpContext>) => PluginSetupResult;
|
|
99
|
+
}
|
|
100
|
+
type ClearRouterPluginInput<Options = any, HttpContext = any> = ClearRouterPlugin<Options> | ((ctx: ClearRouterPluginContext<Options, HttpContext>) => PluginSetupResult);
|
|
101
|
+
/**
|
|
102
|
+
* Creates a new plugin
|
|
103
|
+
*
|
|
104
|
+
* @param plugin
|
|
105
|
+
* @returns
|
|
106
|
+
*/
|
|
107
|
+
declare function definePlugin<Options = any, HttpContext = any>(plugin: ClearRouterPlugin<Options, HttpContext>): ClearRouterPlugin<Options, HttpContext>;
|
|
108
|
+
//#endregion
|
|
109
|
+
export { ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, definePlugin };
|