clear-router 2.5.4 → 2.5.6
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/README.md +5 -0
- package/dist/bindings-CV1e5jho.d.mts +20 -0
- package/dist/bindings-DIanvIVd.mjs +211 -0
- package/dist/bindings-DvV2DXWi.cjs +253 -0
- package/dist/bindings-NV0CdqGl.d.cts +20 -0
- package/dist/core/index.cjs +12 -2
- package/dist/core/index.d.cts +2 -2
- package/dist/core/index.d.mts +2 -2
- package/dist/core/index.mjs +9 -2
- package/dist/decorators/index.cjs +5 -0
- package/dist/decorators/index.d.cts +2 -0
- package/dist/decorators/index.d.mts +2 -0
- package/dist/decorators/index.mjs +3 -0
- package/dist/decorators/setup.cjs +15 -0
- package/dist/decorators/setup.d.cts +2 -0
- package/dist/decorators/setup.d.mts +2 -0
- package/dist/decorators/setup.mjs +13 -0
- package/dist/express/index.cjs +26 -9
- package/dist/express/index.d.cts +1 -1
- package/dist/express/index.d.mts +1 -1
- package/dist/express/index.mjs +26 -9
- package/dist/fastify/index.cjs +24 -8
- package/dist/fastify/index.d.cts +4 -2
- package/dist/fastify/index.d.mts +4 -2
- package/dist/fastify/index.mjs +24 -8
- package/dist/h3/index.cjs +26 -9
- package/dist/h3/index.d.cts +1 -1
- package/dist/h3/index.d.mts +1 -1
- package/dist/h3/index.mjs +26 -9
- package/dist/hono/index.cjs +28 -11
- package/dist/hono/index.d.cts +4 -2
- package/dist/hono/index.d.mts +4 -2
- package/dist/hono/index.mjs +28 -11
- package/dist/index.cjs +308 -28
- package/dist/index.d.cts +112 -18
- package/dist/index.d.mts +112 -18
- package/dist/index.mjs +305 -28
- package/dist/koa/index.cjs +24 -8
- package/dist/koa/index.d.cts +4 -2
- package/dist/koa/index.d.mts +4 -2
- package/dist/koa/index.mjs +24 -8
- package/dist/{responses-B-UirWFf.cjs → responses-JzXstGU5.cjs} +18 -1
- package/dist/{responses-CJaD0ugv.mjs → responses-_II3dOJ5.mjs} +19 -1
- package/dist/{router-BReOXz-F.mjs → router-B3QjblRX.mjs} +159 -48
- package/dist/{router-CS_2XQ7I.d.cts → router-BYZmNzrZ.d.cts} +97 -12
- package/dist/{router-CHg0pZUO.cjs → router-CU4V1kX0.cjs} +159 -48
- package/dist/{router-_w2VzMQF.d.mts → router-DCMtQ_Xi.d.mts} +96 -11
- package/dist/types/basic.d.mts +7 -0
- package/dist/types/core/Request.d.mts +25 -0
- package/dist/types/core/Response.d.mts +21 -0
- package/dist/types/express.d.mts +5 -2
- package/dist/types/fastify.d.mts +5 -2
- package/dist/types/h3.d.mts +5 -2
- package/dist/types/hono.d.mts +5 -2
- package/dist/types/koa.d.mts +5 -2
- package/package.json +16 -2
package/README.md
CHANGED
|
@@ -50,6 +50,10 @@ yarn add clear-router express
|
|
|
50
50
|
- Controller handlers receive hydrated `this.body`, `this.query`, `this.params`, and `this.clearRequest`
|
|
51
51
|
- `clearRequest` is passed as second handler argument for controller handlers
|
|
52
52
|
- Route handlers can return response values directly across Express, Fastify, Hono, H3, and Koa
|
|
53
|
+
- Optional decorated container binding for controller method arguments
|
|
54
|
+
- Plugin API for registering container bindings from external packages
|
|
55
|
+
- Supports TS 5.2+ standard decorators with explicit `@Bind(...)` tokens
|
|
56
|
+
- Optional `clear-router/decorators/setup` entry imports `reflect-metadata` and enables container binding defaults
|
|
53
57
|
- Auto-binds controller methods
|
|
54
58
|
- Full CommonJS, ESM, and TypeScript support
|
|
55
59
|
- Error handling delegated to Express | H3 | Fastify | Hono | Koa
|
|
@@ -98,6 +102,7 @@ See [API.md](https://arkstack-hq.github.io/clear-router/api) for complete API do
|
|
|
98
102
|
- If [Controller, 'method']: auto-instantiated (if needed), method is called
|
|
99
103
|
- First handler arg is always context (`{ req, res, next }` for Express, H3 event for H3, Koa context for Koa)
|
|
100
104
|
- Second handler arg is `clearRequest` for controller handlers
|
|
105
|
+
- Decorated controller methods can opt into resolved arguments with `@Bind(...)`
|
|
101
106
|
|
|
102
107
|
## Testing
|
|
103
108
|
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/core/bindings.d.ts
|
|
2
|
+
type BindToken<T = any> = abstract new (...args: any[]) => T;
|
|
3
|
+
type BindFactory<T = any> = (ctx: any) => T | Promise<T>;
|
|
4
|
+
type BindValue<T = any> = T | BindFactory<T> | BindToken<T>;
|
|
5
|
+
type BindDecorator = MethodDecorator & ClassDecorator & {
|
|
6
|
+
<This, Value extends (this: This, ...args: any[]) => any>(value: Value, context: ClassMethodDecoratorContext<This, Value>): void | Value;
|
|
7
|
+
<Value extends abstract new (...args: any[]) => any>(value: Value, context: ClassDecoratorContext<Value>): void | Value;
|
|
8
|
+
};
|
|
9
|
+
declare class Container {
|
|
10
|
+
private static readonly registry;
|
|
11
|
+
static bind<T>(token: BindToken<T>, value: BindValue<T>): void;
|
|
12
|
+
static unbind<T>(token: BindToken<T>): void;
|
|
13
|
+
static clear(): void;
|
|
14
|
+
static has<T>(token: BindToken<T>): boolean;
|
|
15
|
+
static resolve<T>(token: BindToken<T>, ctx: any, autoDiscover?: boolean): Promise<T | undefined>;
|
|
16
|
+
private static resolveBinding;
|
|
17
|
+
}
|
|
18
|
+
declare function Bind(...tokens: BindToken[]): BindDecorator;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { BindValue as a, BindToken as i, BindDecorator as n, Container as o, BindFactory as r, Bind as t };
|
|
@@ -0,0 +1,211 @@
|
|
|
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
|
+
//#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
|
+
constructor(init) {
|
|
61
|
+
Object.assign(this, init);
|
|
62
|
+
if (init?.headers && !(init.headers instanceof Headers)) this.headers = new Headers(init.headers);
|
|
63
|
+
}
|
|
64
|
+
status(code) {
|
|
65
|
+
this.statusCode = code;
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
code(code) {
|
|
69
|
+
return this.status(code);
|
|
70
|
+
}
|
|
71
|
+
setHeader(name, value) {
|
|
72
|
+
this.headers.set(name, value);
|
|
73
|
+
return this;
|
|
74
|
+
}
|
|
75
|
+
header(name, value) {
|
|
76
|
+
return this.setHeader(name, value);
|
|
77
|
+
}
|
|
78
|
+
set(name, value) {
|
|
79
|
+
return this.setHeader(name, value);
|
|
80
|
+
}
|
|
81
|
+
type(contentType) {
|
|
82
|
+
return this.setHeader("Content-Type", contentType);
|
|
83
|
+
}
|
|
84
|
+
send(body) {
|
|
85
|
+
this.body = body;
|
|
86
|
+
this.sent = true;
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
json(body) {
|
|
90
|
+
return this.type("application/json; charset=utf-8").send(body);
|
|
91
|
+
}
|
|
92
|
+
html(body) {
|
|
93
|
+
return this.type("text/html; charset=utf-8").send(body);
|
|
94
|
+
}
|
|
95
|
+
text(body) {
|
|
96
|
+
return this.type("text/plain; charset=utf-8").send(body);
|
|
97
|
+
}
|
|
98
|
+
noContent() {
|
|
99
|
+
return this.status(204).send(null);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region src/core/bindings.ts
|
|
105
|
+
const metadataKey = Symbol.for("clear-router:binding-metadata");
|
|
106
|
+
const bindings = /* @__PURE__ */ new WeakMap();
|
|
107
|
+
var Container = class {
|
|
108
|
+
static registry = /* @__PURE__ */ new Map();
|
|
109
|
+
static bind(token, value) {
|
|
110
|
+
this.registry.set(token, value);
|
|
111
|
+
}
|
|
112
|
+
static unbind(token) {
|
|
113
|
+
this.registry.delete(token);
|
|
114
|
+
}
|
|
115
|
+
static clear() {
|
|
116
|
+
this.registry.clear();
|
|
117
|
+
}
|
|
118
|
+
static has(token) {
|
|
119
|
+
return this.registry.has(token);
|
|
120
|
+
}
|
|
121
|
+
static async resolve(token, ctx, autoDiscover = false) {
|
|
122
|
+
if (token === Request) return ctx.clearRequest;
|
|
123
|
+
if (token === Response) return ctx.clearResponse;
|
|
124
|
+
if (this.registry.has(token)) return this.resolveBinding(this.registry.get(token), ctx, autoDiscover);
|
|
125
|
+
if (autoDiscover && typeof token === "function") return new token();
|
|
126
|
+
}
|
|
127
|
+
static async resolveBinding(binding, ctx, autoDiscover) {
|
|
128
|
+
if (!binding) return void 0;
|
|
129
|
+
if (typeof binding !== "function") return binding;
|
|
130
|
+
if (isClass(binding)) return new binding();
|
|
131
|
+
const resolved = await binding(ctx);
|
|
132
|
+
if (typeof resolved === "function" && autoDiscover && isClass(resolved)) return new resolved();
|
|
133
|
+
return resolved;
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
function Bind(...tokens) {
|
|
137
|
+
return ((target, propertyKeyOrContext) => {
|
|
138
|
+
if (isStandardClassContext(propertyKeyOrContext)) {
|
|
139
|
+
setClassBindingMetadata(target, tokens);
|
|
140
|
+
setStandardMetadata(propertyKeyOrContext.metadata, "__class__", { tokens });
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (isStandardMethodContext(propertyKeyOrContext)) {
|
|
144
|
+
const method = propertyKeyOrContext.name;
|
|
145
|
+
const metadata = {
|
|
146
|
+
tokens,
|
|
147
|
+
method
|
|
148
|
+
};
|
|
149
|
+
setBindingMetadata(target, "__route_handler__", metadata);
|
|
150
|
+
setStandardMetadata(propertyKeyOrContext.metadata, method, metadata);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (typeof propertyKeyOrContext === "undefined") {
|
|
154
|
+
setClassBindingMetadata(target, tokens);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
setBindingMetadata(target, propertyKeyOrContext, {
|
|
158
|
+
tokens,
|
|
159
|
+
method: propertyKeyOrContext
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
function getStandardMetadata(metadata, propertyKey) {
|
|
164
|
+
const store = metadata && metadata[metadataKey];
|
|
165
|
+
if (!store) return void 0;
|
|
166
|
+
return propertyKey ? store[propertyKey] : void 0;
|
|
167
|
+
}
|
|
168
|
+
function setStandardMetadata(metadata, propertyKey, value) {
|
|
169
|
+
if (!metadata) return;
|
|
170
|
+
const record = metadata;
|
|
171
|
+
record[metadataKey] = record[metadataKey] ?? {};
|
|
172
|
+
record[metadataKey][propertyKey] = value;
|
|
173
|
+
}
|
|
174
|
+
function isStandardMethodContext(value) {
|
|
175
|
+
return Boolean(value && typeof value === "object" && value.kind === "method" && typeof value.name !== "undefined");
|
|
176
|
+
}
|
|
177
|
+
function isStandardClassContext(value) {
|
|
178
|
+
return Boolean(value && typeof value === "object" && value.kind === "class" && typeof value.name !== "undefined");
|
|
179
|
+
}
|
|
180
|
+
function setClassBindingMetadata(target, tokens) {
|
|
181
|
+
setBindingMetadata(target, "__class__", { tokens });
|
|
182
|
+
const prototype = target.prototype;
|
|
183
|
+
if (prototype) setBindingMetadata(prototype, "__class__", { tokens });
|
|
184
|
+
}
|
|
185
|
+
function getBindingMetadataFromTargets(targets) {
|
|
186
|
+
for (const { target, propertyKey } of targets) {
|
|
187
|
+
if (!target) continue;
|
|
188
|
+
const metadata = getBindingMetadata(target, propertyKey);
|
|
189
|
+
if (metadata) return metadata;
|
|
190
|
+
const standardMetadata = getStandardMetadata(target[Symbol.metadata], propertyKey);
|
|
191
|
+
if (standardMetadata) return standardMetadata;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
function getBindingMetadata(target, propertyKey) {
|
|
195
|
+
if (propertyKey) return bindings.get(target)?.get(propertyKey);
|
|
196
|
+
return bindings.get(target)?.get("__route_handler__");
|
|
197
|
+
}
|
|
198
|
+
function setBindingMetadata(target, propertyKey, metadata) {
|
|
199
|
+
const map = bindings.get(target) ?? /* @__PURE__ */ new Map();
|
|
200
|
+
map.set(propertyKey, metadata);
|
|
201
|
+
bindings.set(target, map);
|
|
202
|
+
}
|
|
203
|
+
function getDesignParamTypes(target, propertyKey) {
|
|
204
|
+
return Reflect.getMetadata?.("design:paramtypes", target, propertyKey) ?? [];
|
|
205
|
+
}
|
|
206
|
+
function isClass(value) {
|
|
207
|
+
return typeof value === "function" && /^class\s/.test(Function.prototype.toString.call(value));
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
//#endregion
|
|
211
|
+
export { getStandardMetadata as a, getDesignParamTypes as i, Container as n, Response as o, getBindingMetadataFromTargets as r, Request as s, Bind as t };
|
|
@@ -0,0 +1,253 @@
|
|
|
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
|
+
//#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
|
+
constructor(init) {
|
|
62
|
+
Object.assign(this, init);
|
|
63
|
+
if (init?.headers && !(init.headers instanceof Headers)) this.headers = new Headers(init.headers);
|
|
64
|
+
}
|
|
65
|
+
status(code) {
|
|
66
|
+
this.statusCode = code;
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
code(code) {
|
|
70
|
+
return this.status(code);
|
|
71
|
+
}
|
|
72
|
+
setHeader(name, value) {
|
|
73
|
+
this.headers.set(name, value);
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
header(name, value) {
|
|
77
|
+
return this.setHeader(name, value);
|
|
78
|
+
}
|
|
79
|
+
set(name, value) {
|
|
80
|
+
return this.setHeader(name, value);
|
|
81
|
+
}
|
|
82
|
+
type(contentType) {
|
|
83
|
+
return this.setHeader("Content-Type", contentType);
|
|
84
|
+
}
|
|
85
|
+
send(body) {
|
|
86
|
+
this.body = body;
|
|
87
|
+
this.sent = true;
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
json(body) {
|
|
91
|
+
return this.type("application/json; charset=utf-8").send(body);
|
|
92
|
+
}
|
|
93
|
+
html(body) {
|
|
94
|
+
return this.type("text/html; charset=utf-8").send(body);
|
|
95
|
+
}
|
|
96
|
+
text(body) {
|
|
97
|
+
return this.type("text/plain; charset=utf-8").send(body);
|
|
98
|
+
}
|
|
99
|
+
noContent() {
|
|
100
|
+
return this.status(204).send(null);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region src/core/bindings.ts
|
|
106
|
+
const metadataKey = Symbol.for("clear-router:binding-metadata");
|
|
107
|
+
const bindings = /* @__PURE__ */ new WeakMap();
|
|
108
|
+
var Container = class {
|
|
109
|
+
static registry = /* @__PURE__ */ new Map();
|
|
110
|
+
static bind(token, value) {
|
|
111
|
+
this.registry.set(token, value);
|
|
112
|
+
}
|
|
113
|
+
static unbind(token) {
|
|
114
|
+
this.registry.delete(token);
|
|
115
|
+
}
|
|
116
|
+
static clear() {
|
|
117
|
+
this.registry.clear();
|
|
118
|
+
}
|
|
119
|
+
static has(token) {
|
|
120
|
+
return this.registry.has(token);
|
|
121
|
+
}
|
|
122
|
+
static async resolve(token, ctx, autoDiscover = false) {
|
|
123
|
+
if (token === Request) return ctx.clearRequest;
|
|
124
|
+
if (token === Response) return ctx.clearResponse;
|
|
125
|
+
if (this.registry.has(token)) return this.resolveBinding(this.registry.get(token), ctx, autoDiscover);
|
|
126
|
+
if (autoDiscover && typeof token === "function") return new token();
|
|
127
|
+
}
|
|
128
|
+
static async resolveBinding(binding, ctx, autoDiscover) {
|
|
129
|
+
if (!binding) return void 0;
|
|
130
|
+
if (typeof binding !== "function") return binding;
|
|
131
|
+
if (isClass(binding)) return new binding();
|
|
132
|
+
const resolved = await binding(ctx);
|
|
133
|
+
if (typeof resolved === "function" && autoDiscover && isClass(resolved)) return new resolved();
|
|
134
|
+
return resolved;
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
function Bind(...tokens) {
|
|
138
|
+
return ((target, propertyKeyOrContext) => {
|
|
139
|
+
if (isStandardClassContext(propertyKeyOrContext)) {
|
|
140
|
+
setClassBindingMetadata(target, tokens);
|
|
141
|
+
setStandardMetadata(propertyKeyOrContext.metadata, "__class__", { tokens });
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
if (isStandardMethodContext(propertyKeyOrContext)) {
|
|
145
|
+
const method = propertyKeyOrContext.name;
|
|
146
|
+
const metadata = {
|
|
147
|
+
tokens,
|
|
148
|
+
method
|
|
149
|
+
};
|
|
150
|
+
setBindingMetadata(target, "__route_handler__", metadata);
|
|
151
|
+
setStandardMetadata(propertyKeyOrContext.metadata, method, metadata);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (typeof propertyKeyOrContext === "undefined") {
|
|
155
|
+
setClassBindingMetadata(target, tokens);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
setBindingMetadata(target, propertyKeyOrContext, {
|
|
159
|
+
tokens,
|
|
160
|
+
method: propertyKeyOrContext
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
function getStandardMetadata(metadata, propertyKey) {
|
|
165
|
+
const store = metadata && metadata[metadataKey];
|
|
166
|
+
if (!store) return void 0;
|
|
167
|
+
return propertyKey ? store[propertyKey] : void 0;
|
|
168
|
+
}
|
|
169
|
+
function setStandardMetadata(metadata, propertyKey, value) {
|
|
170
|
+
if (!metadata) return;
|
|
171
|
+
const record = metadata;
|
|
172
|
+
record[metadataKey] = record[metadataKey] ?? {};
|
|
173
|
+
record[metadataKey][propertyKey] = value;
|
|
174
|
+
}
|
|
175
|
+
function isStandardMethodContext(value) {
|
|
176
|
+
return Boolean(value && typeof value === "object" && value.kind === "method" && typeof value.name !== "undefined");
|
|
177
|
+
}
|
|
178
|
+
function isStandardClassContext(value) {
|
|
179
|
+
return Boolean(value && typeof value === "object" && value.kind === "class" && typeof value.name !== "undefined");
|
|
180
|
+
}
|
|
181
|
+
function setClassBindingMetadata(target, tokens) {
|
|
182
|
+
setBindingMetadata(target, "__class__", { tokens });
|
|
183
|
+
const prototype = target.prototype;
|
|
184
|
+
if (prototype) setBindingMetadata(prototype, "__class__", { tokens });
|
|
185
|
+
}
|
|
186
|
+
function getBindingMetadataFromTargets(targets) {
|
|
187
|
+
for (const { target, propertyKey } of targets) {
|
|
188
|
+
if (!target) continue;
|
|
189
|
+
const metadata = getBindingMetadata(target, propertyKey);
|
|
190
|
+
if (metadata) return metadata;
|
|
191
|
+
const standardMetadata = getStandardMetadata(target[Symbol.metadata], propertyKey);
|
|
192
|
+
if (standardMetadata) return standardMetadata;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function getBindingMetadata(target, propertyKey) {
|
|
196
|
+
if (propertyKey) return bindings.get(target)?.get(propertyKey);
|
|
197
|
+
return bindings.get(target)?.get("__route_handler__");
|
|
198
|
+
}
|
|
199
|
+
function setBindingMetadata(target, propertyKey, metadata) {
|
|
200
|
+
const map = bindings.get(target) ?? /* @__PURE__ */ new Map();
|
|
201
|
+
map.set(propertyKey, metadata);
|
|
202
|
+
bindings.set(target, map);
|
|
203
|
+
}
|
|
204
|
+
function getDesignParamTypes(target, propertyKey) {
|
|
205
|
+
return Reflect.getMetadata?.("design:paramtypes", target, propertyKey) ?? [];
|
|
206
|
+
}
|
|
207
|
+
function isClass(value) {
|
|
208
|
+
return typeof value === "function" && /^class\s/.test(Function.prototype.toString.call(value));
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
//#endregion
|
|
212
|
+
Object.defineProperty(exports, 'Bind', {
|
|
213
|
+
enumerable: true,
|
|
214
|
+
get: function () {
|
|
215
|
+
return Bind;
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
Object.defineProperty(exports, 'Container', {
|
|
219
|
+
enumerable: true,
|
|
220
|
+
get: function () {
|
|
221
|
+
return Container;
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
Object.defineProperty(exports, 'Request', {
|
|
225
|
+
enumerable: true,
|
|
226
|
+
get: function () {
|
|
227
|
+
return Request;
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
Object.defineProperty(exports, 'Response', {
|
|
231
|
+
enumerable: true,
|
|
232
|
+
get: function () {
|
|
233
|
+
return Response;
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
Object.defineProperty(exports, 'getBindingMetadataFromTargets', {
|
|
237
|
+
enumerable: true,
|
|
238
|
+
get: function () {
|
|
239
|
+
return getBindingMetadataFromTargets;
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
Object.defineProperty(exports, 'getDesignParamTypes', {
|
|
243
|
+
enumerable: true,
|
|
244
|
+
get: function () {
|
|
245
|
+
return getDesignParamTypes;
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
Object.defineProperty(exports, 'getStandardMetadata', {
|
|
249
|
+
enumerable: true,
|
|
250
|
+
get: function () {
|
|
251
|
+
return getStandardMetadata;
|
|
252
|
+
}
|
|
253
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/core/bindings.d.ts
|
|
2
|
+
type BindToken<T = any> = abstract new (...args: any[]) => T;
|
|
3
|
+
type BindFactory<T = any> = (ctx: any) => T | Promise<T>;
|
|
4
|
+
type BindValue<T = any> = T | BindFactory<T> | BindToken<T>;
|
|
5
|
+
type BindDecorator = MethodDecorator & ClassDecorator & {
|
|
6
|
+
<This, Value extends (this: This, ...args: any[]) => any>(value: Value, context: ClassMethodDecoratorContext<This, Value>): void | Value;
|
|
7
|
+
<Value extends abstract new (...args: any[]) => any>(value: Value, context: ClassDecoratorContext<Value>): void | Value;
|
|
8
|
+
};
|
|
9
|
+
declare class Container {
|
|
10
|
+
private static readonly registry;
|
|
11
|
+
static bind<T>(token: BindToken<T>, value: BindValue<T>): void;
|
|
12
|
+
static unbind<T>(token: BindToken<T>): void;
|
|
13
|
+
static clear(): void;
|
|
14
|
+
static has<T>(token: BindToken<T>): boolean;
|
|
15
|
+
static resolve<T>(token: BindToken<T>, ctx: any, autoDiscover?: boolean): Promise<T | undefined>;
|
|
16
|
+
private static resolveBinding;
|
|
17
|
+
}
|
|
18
|
+
declare function Bind(...tokens: BindToken[]): BindDecorator;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { BindValue as a, BindToken as i, BindDecorator as n, Container as o, BindFactory as r, Bind as t };
|
package/dist/core/index.cjs
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const
|
|
2
|
+
const require_bindings = require('../bindings-DvV2DXWi.cjs');
|
|
3
|
+
const require_router = require('../router-CU4V1kX0.cjs');
|
|
3
4
|
|
|
4
|
-
|
|
5
|
+
//#region src/core/plugins.ts
|
|
6
|
+
function definePlugin(plugin) {
|
|
7
|
+
return plugin;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
exports.CoreRouter = require_router.CoreRouter;
|
|
12
|
+
exports.Request = require_bindings.Request;
|
|
13
|
+
exports.Response = require_bindings.Response;
|
|
14
|
+
exports.definePlugin = definePlugin;
|
package/dist/core/index.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as CoreRouter } from "../router-
|
|
2
|
-
export { CoreRouter };
|
|
1
|
+
import { a as PluginBind, c as Request, i as ClearRouterPluginInput, n as ClearRouterPlugin, o as PluginSetupResult, r as ClearRouterPluginContext, s as definePlugin, t as CoreRouter, x as Response } from "../router-BYZmNzrZ.cjs";
|
|
2
|
+
export { ClearRouterPlugin, ClearRouterPluginContext, ClearRouterPluginInput, CoreRouter, PluginBind, PluginSetupResult, Request, Response, definePlugin };
|
package/dist/core/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as CoreRouter } from "../router-
|
|
2
|
-
export { CoreRouter };
|
|
1
|
+
import { a as PluginBind, c as Request, i as ClearRouterPluginInput, n as ClearRouterPlugin, o as PluginSetupResult, r as ClearRouterPluginContext, s as definePlugin, t as CoreRouter, x as Response } from "../router-DCMtQ_Xi.mjs";
|
|
2
|
+
export { ClearRouterPlugin, ClearRouterPluginContext, ClearRouterPluginInput, CoreRouter, PluginBind, PluginSetupResult, Request, Response, definePlugin };
|
package/dist/core/index.mjs
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { o as Response, s as Request } from "../bindings-DIanvIVd.mjs";
|
|
2
|
+
import { t as CoreRouter } from "../router-B3QjblRX.mjs";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
//#region src/core/plugins.ts
|
|
5
|
+
function definePlugin(plugin) {
|
|
6
|
+
return plugin;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
export { CoreRouter, Request, Response, definePlugin };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_bindings = require('../bindings-DvV2DXWi.cjs');
|
|
3
|
+
const require_router = require('../router-CU4V1kX0.cjs');
|
|
4
|
+
require('./index.cjs');
|
|
5
|
+
require("reflect-metadata");
|
|
6
|
+
|
|
7
|
+
//#region src/decorators/setup.ts
|
|
8
|
+
require_router.CoreRouter.configureDefaults({ container: {
|
|
9
|
+
enabled: true,
|
|
10
|
+
autoDiscover: true
|
|
11
|
+
} });
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
exports.Bind = require_bindings.Bind;
|
|
15
|
+
exports.Container = require_bindings.Container;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { n as Container, t as Bind } from "../bindings-DIanvIVd.mjs";
|
|
2
|
+
import { t as CoreRouter } from "../router-B3QjblRX.mjs";
|
|
3
|
+
import "./index.mjs";
|
|
4
|
+
import "reflect-metadata";
|
|
5
|
+
|
|
6
|
+
//#region src/decorators/setup.ts
|
|
7
|
+
CoreRouter.configureDefaults({ container: {
|
|
8
|
+
enabled: true,
|
|
9
|
+
autoDiscover: true
|
|
10
|
+
} });
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { Bind, Container };
|