@aponiajs/common 0.3.19 → 0.3.21
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/index.mjs +18 -17
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
2
|
import { inspect } from "node:util";
|
|
3
3
|
//#region src/decorators.ts
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
4
|
+
const moduleMetadataKey = Symbol.for("aponia.module.metadata");
|
|
5
|
+
const controllerMetadataKey = Symbol.for("aponia.controller.metadata");
|
|
6
|
+
const routeMetadataKey = Symbol.for("aponia.route.metadata");
|
|
7
|
+
const injectedTokensMetadataKey = Symbol.for("aponia.injected-tokens.metadata");
|
|
8
8
|
function Module(metadata) {
|
|
9
9
|
const normalized = Object.freeze({
|
|
10
10
|
imports: Object.freeze([...metadata.imports ?? []]),
|
|
@@ -13,7 +13,7 @@ function Module(metadata) {
|
|
|
13
13
|
exports: Object.freeze([...metadata.exports ?? []])
|
|
14
14
|
});
|
|
15
15
|
return (target) => {
|
|
16
|
-
|
|
16
|
+
Reflect.defineMetadata(moduleMetadataKey, normalized, target);
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
function Injectable() {
|
|
@@ -21,15 +21,16 @@ function Injectable() {
|
|
|
21
21
|
}
|
|
22
22
|
function Controller(path = "") {
|
|
23
23
|
return (target) => {
|
|
24
|
-
|
|
24
|
+
Reflect.defineMetadata(controllerMetadataKey, Object.freeze({ path }), target);
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
27
|
function Inject(token) {
|
|
28
28
|
return (target, _propertyKey, parameterIndex) => {
|
|
29
29
|
const constructor = typeof target === "function" ? target : target.constructor;
|
|
30
|
-
const parameters =
|
|
31
|
-
parameters
|
|
32
|
-
|
|
30
|
+
const parameters = Reflect.getOwnMetadata(injectedTokensMetadataKey, constructor) ?? /* @__PURE__ */ new Map();
|
|
31
|
+
const updatedParameters = new Map(parameters);
|
|
32
|
+
updatedParameters.set(parameterIndex, token);
|
|
33
|
+
Reflect.defineMetadata(injectedTokensMetadataKey, updatedParameters, constructor);
|
|
33
34
|
};
|
|
34
35
|
}
|
|
35
36
|
const Delete = createRouteDecorator("DELETE");
|
|
@@ -38,30 +39,30 @@ const Patch = createRouteDecorator("PATCH");
|
|
|
38
39
|
const Post = createRouteDecorator("POST");
|
|
39
40
|
const Put = createRouteDecorator("PUT");
|
|
40
41
|
function getModuleMetadata(target) {
|
|
41
|
-
return
|
|
42
|
+
return Reflect.getOwnMetadata(moduleMetadataKey, target);
|
|
42
43
|
}
|
|
43
44
|
function getControllerMetadata(target) {
|
|
44
|
-
return
|
|
45
|
+
return Reflect.getOwnMetadata(controllerMetadataKey, target);
|
|
45
46
|
}
|
|
46
47
|
function getRouteMetadata(target) {
|
|
47
|
-
|
|
48
|
+
const routes = Reflect.getOwnMetadata(routeMetadataKey, target.prototype) ?? [];
|
|
49
|
+
return Object.freeze([...routes]);
|
|
48
50
|
}
|
|
49
51
|
function getConstructorDependencies(target) {
|
|
50
52
|
const reflected = Reflect.getMetadata("design:paramtypes", target) ?? [];
|
|
51
|
-
const explicit =
|
|
53
|
+
const explicit = Reflect.getOwnMetadata(injectedTokensMetadataKey, target);
|
|
52
54
|
const explicitLength = explicit ? Math.max(0, ...[...explicit.keys()].map((index) => index + 1)) : 0;
|
|
53
55
|
const length = Math.max(reflected.length, explicitLength);
|
|
54
56
|
return Object.freeze(Array.from({ length }, (_, index) => explicit?.get(index) ?? asToken(reflected[index], target)));
|
|
55
57
|
}
|
|
56
58
|
function createRouteDecorator(method) {
|
|
57
59
|
return (path = "") => (target, propertyKey) => {
|
|
58
|
-
const controllerRoutes =
|
|
59
|
-
|
|
60
|
+
const controllerRoutes = Reflect.getOwnMetadata(routeMetadataKey, target) ?? [];
|
|
61
|
+
Reflect.defineMetadata(routeMetadataKey, Object.freeze([...controllerRoutes, Object.freeze({
|
|
60
62
|
method,
|
|
61
63
|
path,
|
|
62
64
|
propertyKey
|
|
63
|
-
}));
|
|
64
|
-
routes.set(target, controllerRoutes);
|
|
65
|
+
})]), target);
|
|
65
66
|
};
|
|
66
67
|
}
|
|
67
68
|
function asToken(value, target) {
|
package/package.json
CHANGED