fragment-ts 1.0.21 → 1.0.23
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/cli/commands/init.command.d.ts +1 -0
- package/dist/cli/commands/init.command.d.ts.map +1 -1
- package/dist/cli/commands/init.command.js +56 -30
- package/dist/cli/commands/init.command.js.map +1 -1
- package/dist/core/decorators/application.decorator.d.ts +6 -1
- package/dist/core/decorators/application.decorator.d.ts.map +1 -1
- package/dist/core/decorators/application.decorator.js +7 -2
- package/dist/core/decorators/application.decorator.js.map +1 -1
- package/dist/core/decorators/auto-configuration.decorator.d.ts.map +1 -1
- package/dist/core/decorators/auto-configuration.decorator.js +4 -5
- package/dist/core/decorators/auto-configuration.decorator.js.map +1 -1
- package/dist/core/decorators/conditional.decorators.d.ts +4 -0
- package/dist/core/decorators/conditional.decorators.d.ts.map +1 -1
- package/dist/core/decorators/conditional.decorators.js +32 -0
- package/dist/core/decorators/conditional.decorators.js.map +1 -1
- package/dist/core/decorators/controller.decorator.d.ts.map +1 -1
- package/dist/core/decorators/controller.decorator.js +1 -2
- package/dist/core/decorators/controller.decorator.js.map +1 -1
- package/dist/core/decorators/http.decorators.d.ts +1 -0
- package/dist/core/decorators/http.decorators.d.ts.map +1 -1
- package/dist/core/decorators/http.decorators.js +10 -10
- package/dist/core/decorators/http.decorators.js.map +1 -1
- package/dist/core/decorators/injectable.decorator.d.ts +3 -0
- package/dist/core/decorators/injectable.decorator.d.ts.map +1 -1
- package/dist/core/decorators/injectable.decorator.js +12 -5
- package/dist/core/decorators/injectable.decorator.js.map +1 -1
- package/dist/core/decorators/injection.decorators.d.ts +2 -37
- package/dist/core/decorators/injection.decorators.d.ts.map +1 -1
- package/dist/core/decorators/injection.decorators.js +43 -75
- package/dist/core/decorators/injection.decorators.js.map +1 -1
- package/dist/core/decorators/repository.decorator.d.ts.map +1 -1
- package/dist/core/decorators/repository.decorator.js +4 -5
- package/dist/core/decorators/repository.decorator.js.map +1 -1
- package/dist/core/decorators/service.decorator.d.ts.map +1 -1
- package/dist/core/decorators/service.decorator.js +4 -5
- package/dist/core/decorators/service.decorator.js.map +1 -1
- package/dist/core/metadata/metadata-storage.d.ts +9 -20
- package/dist/core/metadata/metadata-storage.d.ts.map +1 -1
- package/dist/core/metadata/metadata-storage.js +58 -10
- package/dist/core/metadata/metadata-storage.js.map +1 -1
- package/dist/core/types/decoration.types.d.ts +21 -0
- package/dist/core/types/decoration.types.d.ts.map +1 -0
- package/dist/core/types/decoration.types.js +3 -0
- package/dist/core/types/decoration.types.js.map +1 -0
- package/examples/blog-api/package-lock.json +190 -6
- package/examples/blog-api/package.json +6 -3
- package/examples/blog-api/src/services/app.service.ts +2 -2
- package/examples/blog-api/src/test/app.spec.ts +23 -0
- package/package.json +1 -1
- package/src/cli/commands/init.command.ts +61 -31
- package/src/core/decorators/application.decorator.ts +13 -3
- package/src/core/decorators/auto-configuration.decorator.ts +8 -10
- package/src/core/decorators/conditional.decorators.ts +37 -1
- package/src/core/decorators/controller.decorator.ts +1 -3
- package/src/core/decorators/http.decorators.ts +11 -32
- package/src/core/decorators/injectable.decorator.ts +15 -8
- package/src/core/decorators/injection.decorators.ts +50 -103
- package/src/core/decorators/repository.decorator.ts +8 -10
- package/src/core/decorators/service.decorator.ts +8 -10
- package/src/core/metadata/metadata-storage.ts +75 -43
- package/src/core/types/decoration.types.ts +38 -0
|
@@ -3,46 +3,59 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Autowired = Autowired;
|
|
4
4
|
exports.Inject = Inject;
|
|
5
5
|
exports.InjectRepository = InjectRepository;
|
|
6
|
-
exports.Qualifier = Qualifier;
|
|
7
6
|
exports.Value = Value;
|
|
7
|
+
exports.Qualifier = Qualifier;
|
|
8
8
|
exports.Optional = Optional;
|
|
9
9
|
exports.Lazy = Lazy;
|
|
10
|
-
|
|
11
|
-
exports.PreDestroy = PreDestroy;
|
|
10
|
+
require("reflect-metadata");
|
|
12
11
|
const metadata_keys_1 = require("../metadata/metadata-keys");
|
|
13
|
-
|
|
14
|
-
* @Autowired - Automatically inject dependencies by type
|
|
15
|
-
* Usage: @Autowired() private myService: MyService;
|
|
16
|
-
*/
|
|
12
|
+
const metadata_storage_1 = require("../metadata/metadata-storage");
|
|
17
13
|
function Autowired() {
|
|
18
14
|
return (target, propertyKey) => {
|
|
19
|
-
// Get the design type from TypeScript metadata
|
|
20
15
|
const type = Reflect.getMetadata("design:type", target, propertyKey);
|
|
21
|
-
if (!type
|
|
22
|
-
throw new Error(`Cannot use @Autowired on
|
|
23
|
-
`Make sure TypeScript emitDecoratorMetadata is enabled and the type is explicitly declared.`);
|
|
24
|
-
}
|
|
25
|
-
// Store the type in metadata so DI container can resolve it
|
|
16
|
+
if (!type)
|
|
17
|
+
throw new Error(`Cannot use @Autowired on ${String(propertyKey)}`);
|
|
26
18
|
Reflect.defineMetadata(metadata_keys_1.METADATA_KEYS.AUTOWIRED, type, target, propertyKey);
|
|
19
|
+
metadata_storage_1.MetadataStorage.getInstance().addParam({
|
|
20
|
+
target,
|
|
21
|
+
propertyKey: propertyKey.toString(),
|
|
22
|
+
index: -1,
|
|
23
|
+
type: "autowired",
|
|
24
|
+
});
|
|
27
25
|
};
|
|
28
26
|
}
|
|
29
|
-
/**
|
|
30
|
-
* @Inject - Inject dependency by token (string or class)
|
|
31
|
-
* Usage: @Inject('MyService') private service: MyService;
|
|
32
|
-
* or: @Inject(MyService) private service: MyService;
|
|
33
|
-
*/
|
|
34
27
|
function Inject(token) {
|
|
35
28
|
return (target, propertyKey) => {
|
|
36
29
|
Reflect.defineMetadata(metadata_keys_1.METADATA_KEYS.INJECT, token, target, propertyKey);
|
|
30
|
+
metadata_storage_1.MetadataStorage.getInstance().addParam({
|
|
31
|
+
target,
|
|
32
|
+
propertyKey: propertyKey.toString(),
|
|
33
|
+
index: -1,
|
|
34
|
+
type: "inject",
|
|
35
|
+
paramName: typeof token === "string" ? token : undefined,
|
|
36
|
+
});
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
|
-
/**
|
|
40
|
-
* @InjectRepository - Inject TypeORM repository for an entity
|
|
41
|
-
* Usage: @InjectRepository(User) private userRepo: Repository<User>;
|
|
42
|
-
*/
|
|
43
39
|
function InjectRepository(entity) {
|
|
44
40
|
return (target, propertyKey) => {
|
|
45
41
|
Reflect.defineMetadata(metadata_keys_1.METADATA_KEYS.INJECT_REPOSITORY, entity, target, propertyKey);
|
|
42
|
+
metadata_storage_1.MetadataStorage.getInstance().addParam({
|
|
43
|
+
target,
|
|
44
|
+
propertyKey: propertyKey.toString(),
|
|
45
|
+
index: -1,
|
|
46
|
+
type: "inject-repo",
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function Value(expression) {
|
|
51
|
+
return (target, propertyKey) => {
|
|
52
|
+
Reflect.defineMetadata(metadata_keys_1.METADATA_KEYS.VALUE, expression, target, propertyKey);
|
|
53
|
+
metadata_storage_1.MetadataStorage.getInstance().addParam({
|
|
54
|
+
target,
|
|
55
|
+
propertyKey: propertyKey.toString(),
|
|
56
|
+
index: -1,
|
|
57
|
+
type: "value",
|
|
58
|
+
});
|
|
46
59
|
};
|
|
47
60
|
}
|
|
48
61
|
/**
|
|
@@ -51,70 +64,25 @@ function InjectRepository(entity) {
|
|
|
51
64
|
*/
|
|
52
65
|
function Qualifier(name) {
|
|
53
66
|
return (target, propertyKey) => {
|
|
67
|
+
if (!propertyKey)
|
|
68
|
+
return;
|
|
54
69
|
Reflect.defineMetadata(metadata_keys_1.METADATA_KEYS.QUALIFIER, name, target, propertyKey);
|
|
70
|
+
metadata_storage_1.MetadataStorage.getInstance().addParam({
|
|
71
|
+
target,
|
|
72
|
+
propertyKey: propertyKey.toString(),
|
|
73
|
+
index: -1,
|
|
74
|
+
type: "qualifier",
|
|
75
|
+
});
|
|
55
76
|
};
|
|
56
77
|
}
|
|
57
|
-
/**
|
|
58
|
-
* @Value - Inject configuration value from environment or config
|
|
59
|
-
* Usage: @Value('${PORT}') private port: number;
|
|
60
|
-
* or: @Value('${DB_HOST:localhost}') private host: string;
|
|
61
|
-
*/
|
|
62
|
-
function Value(expression) {
|
|
63
|
-
return (target, propertyKey) => {
|
|
64
|
-
Reflect.defineMetadata(metadata_keys_1.METADATA_KEYS.VALUE, expression, target, propertyKey);
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* @Optional - Mark dependency as optional (won't throw if not found)
|
|
69
|
-
* Usage: @Optional() @Autowired() private service?: MyService;
|
|
70
|
-
*/
|
|
71
78
|
function Optional() {
|
|
72
79
|
return (target, propertyKey) => {
|
|
73
80
|
Reflect.defineMetadata(metadata_keys_1.METADATA_KEYS.OPTIONAL, true, target, propertyKey);
|
|
74
81
|
};
|
|
75
82
|
}
|
|
76
|
-
/**
|
|
77
|
-
* @Lazy - Lazy load dependency (create on first access)
|
|
78
|
-
* Usage: @Lazy() @Autowired() private service: MyService;
|
|
79
|
-
*/
|
|
80
83
|
function Lazy() {
|
|
81
84
|
return (target, propertyKey) => {
|
|
82
85
|
Reflect.defineMetadata(metadata_keys_1.METADATA_KEYS.LAZY, true, target, propertyKey);
|
|
83
|
-
const type = Reflect.getMetadata("design:type", target, propertyKey);
|
|
84
|
-
// Create a getter that resolves on first access
|
|
85
|
-
let cached = null;
|
|
86
|
-
let resolved = false;
|
|
87
|
-
Object.defineProperty(target, propertyKey, {
|
|
88
|
-
get() {
|
|
89
|
-
if (!resolved) {
|
|
90
|
-
const { DIContainer } = require("../container/di-container");
|
|
91
|
-
const container = DIContainer.getInstance();
|
|
92
|
-
cached = container.resolve(type);
|
|
93
|
-
resolved = true;
|
|
94
|
-
}
|
|
95
|
-
return cached;
|
|
96
|
-
},
|
|
97
|
-
enumerable: true,
|
|
98
|
-
configurable: true,
|
|
99
|
-
});
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* @PostConstruct - Method called after dependency injection is complete
|
|
104
|
-
* Usage: @PostConstruct() init() { ... }
|
|
105
|
-
*/
|
|
106
|
-
function PostConstruct() {
|
|
107
|
-
return (target, propertyKey, descriptor) => {
|
|
108
|
-
Reflect.defineMetadata(metadata_keys_1.METADATA_KEYS.POST_CONSTRUCT, propertyKey, target.constructor);
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* @PreDestroy - Method called before bean is destroyed
|
|
113
|
-
* Usage: @PreDestroy() cleanup() { ... }
|
|
114
|
-
*/
|
|
115
|
-
function PreDestroy() {
|
|
116
|
-
return (target, propertyKey, descriptor) => {
|
|
117
|
-
Reflect.defineMetadata(metadata_keys_1.METADATA_KEYS.PRE_DESTROY, propertyKey, target.constructor);
|
|
118
86
|
};
|
|
119
87
|
}
|
|
120
88
|
//# sourceMappingURL=injection.decorators.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injection.decorators.js","sourceRoot":"","sources":["../../../src/core/decorators/injection.decorators.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"injection.decorators.js","sourceRoot":"","sources":["../../../src/core/decorators/injection.decorators.ts"],"names":[],"mappings":";;AAIA,8BAcC;AAED,wBAWC;AAED,4CAeC;AAED,sBAeC;AAMD,8BAaC;AAED,4BAIC;AAED,oBAIC;AAhGD,4BAA0B;AAC1B,6DAA0D;AAC1D,mEAA+D;AAE/D,SAAgB,SAAS;IACvB,OAAO,CAAC,MAAM,EAAE,WAAW,EAAE,EAAE;QAC7B,MAAM,IAAI,GAAG,OAAO,CAAC,WAAW,CAAC,aAAa,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;QACrE,IAAI,CAAC,IAAI;YACP,MAAM,IAAI,KAAK,CAAC,4BAA4B,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;QACrE,OAAO,CAAC,cAAc,CAAC,6BAAa,CAAC,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;QAE3E,kCAAe,CAAC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Ae,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC;YACrC,MAAM;YACN,WAAW,EAAE,WAAW,CAAC,QAAQ,EAAE;YACnC,KAAK,EAAE,CAAC,CAAC;YACT,IAAI,EAAE,OAAO;SACd,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,SAAgB,SAAS,CAAC,IAAY;IACpC,OAAO,CAAC,MAAW,EAAE,WAA4B,EAAE,EAAE;QACnD,IAAI,CAAC,WAAW;YAAE,OAAO;QAEzB,OAAO,CAAC,cAAc,CAAC,6BAAa,CAAC,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;QAE3E,kCAAe,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC;YACrC,MAAM;YACN,WAAW,EAAE,WAAW,CAAC,QAAQ,EAAE;YACnC,KAAK,EAAE,CAAC,CAAC;YACT,IAAI,EAAE,WAAW;SAClB,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAED,SAAgB,QAAQ;IACtB,OAAO,CAAC,MAAM,EAAE,WAAW,EAAE,EAAE;QAC7B,OAAO,CAAC,cAAc,CAAC,6BAAa,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;IAC5E,CAAC,CAAC;AACJ,CAAC;AAED,SAAgB,IAAI;IAClB,OAAO,CAAC,MAAM,EAAE,WAAW,EAAE,EAAE;QAC7B,OAAO,CAAC,cAAc,CAAC,6BAAa,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;IACxE,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repository.decorator.d.ts","sourceRoot":"","sources":["../../../src/core/decorators/repository.decorator.ts"],"names":[],"mappings":"AAIA,wBAAgB,UAAU,IAAI,cAAc,
|
|
1
|
+
{"version":3,"file":"repository.decorator.d.ts","sourceRoot":"","sources":["../../../src/core/decorators/repository.decorator.ts"],"names":[],"mappings":"AAIA,wBAAgB,UAAU,IAAI,cAAc,CAU3C"}
|
|
@@ -6,13 +6,12 @@ const metadata_keys_1 = require("../metadata/metadata-keys");
|
|
|
6
6
|
const metadata_storage_1 = require("../metadata/metadata-storage");
|
|
7
7
|
function Repository() {
|
|
8
8
|
return (target) => {
|
|
9
|
-
(0, injectable_decorator_1.Injectable)(
|
|
9
|
+
(0, injectable_decorator_1.Injectable)("singleton")(target);
|
|
10
10
|
Reflect.defineMetadata(metadata_keys_1.METADATA_KEYS.REPOSITORY, true, target);
|
|
11
|
-
|
|
12
|
-
storage.addClass({
|
|
11
|
+
metadata_storage_1.MetadataStorage.getInstance().addClass({
|
|
13
12
|
target,
|
|
14
|
-
type:
|
|
15
|
-
scope:
|
|
13
|
+
type: "repository",
|
|
14
|
+
scope: "singleton",
|
|
16
15
|
});
|
|
17
16
|
};
|
|
18
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repository.decorator.js","sourceRoot":"","sources":["../../../src/core/decorators/repository.decorator.ts"],"names":[],"mappings":";;AAIA,
|
|
1
|
+
{"version":3,"file":"repository.decorator.js","sourceRoot":"","sources":["../../../src/core/decorators/repository.decorator.ts"],"names":[],"mappings":";;AAIA,gCAUC;AAdD,iEAAoD;AACpD,6DAA0D;AAC1D,mEAA+D;AAE/D,SAAgB,UAAU;IACxB,OAAO,CAAC,MAAW,EAAE,EAAE;QACrB,IAAA,iCAAU,EAAC,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;QAChC,OAAO,CAAC,cAAc,CAAC,6BAAa,CAAC,UAAU,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QAC/D,kCAAe,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC;YACrC,MAAM;YACN,IAAI,EAAE,YAAY;YAClB,KAAK,EAAE,WAAW;SACnB,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.decorator.d.ts","sourceRoot":"","sources":["../../../src/core/decorators/service.decorator.ts"],"names":[],"mappings":"AAIA,wBAAgB,OAAO,IAAI,cAAc,
|
|
1
|
+
{"version":3,"file":"service.decorator.d.ts","sourceRoot":"","sources":["../../../src/core/decorators/service.decorator.ts"],"names":[],"mappings":"AAIA,wBAAgB,OAAO,IAAI,cAAc,CAUxC"}
|
|
@@ -6,13 +6,12 @@ const metadata_keys_1 = require("../metadata/metadata-keys");
|
|
|
6
6
|
const metadata_storage_1 = require("../metadata/metadata-storage");
|
|
7
7
|
function Service() {
|
|
8
8
|
return (target) => {
|
|
9
|
-
(0, injectable_decorator_1.Injectable)(
|
|
9
|
+
(0, injectable_decorator_1.Injectable)("singleton")(target);
|
|
10
10
|
Reflect.defineMetadata(metadata_keys_1.METADATA_KEYS.SERVICE, true, target);
|
|
11
|
-
|
|
12
|
-
storage.addClass({
|
|
11
|
+
metadata_storage_1.MetadataStorage.getInstance().addClass({
|
|
13
12
|
target,
|
|
14
|
-
type:
|
|
15
|
-
scope:
|
|
13
|
+
type: "service",
|
|
14
|
+
scope: "singleton",
|
|
16
15
|
});
|
|
17
16
|
};
|
|
18
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.decorator.js","sourceRoot":"","sources":["../../../src/core/decorators/service.decorator.ts"],"names":[],"mappings":";;AAIA,
|
|
1
|
+
{"version":3,"file":"service.decorator.js","sourceRoot":"","sources":["../../../src/core/decorators/service.decorator.ts"],"names":[],"mappings":";;AAIA,0BAUC;AAdD,iEAAoD;AACpD,6DAA0D;AAC1D,mEAA+D;AAE/D,SAAgB,OAAO;IACrB,OAAO,CAAC,MAAW,EAAE,EAAE;QACrB,IAAA,iCAAU,EAAC,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;QAChC,OAAO,CAAC,cAAc,CAAC,6BAAa,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QAC5D,kCAAe,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC;YACrC,MAAM;YACN,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,WAAW;SACnB,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1,23 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
path?: string;
|
|
6
|
-
}
|
|
7
|
-
export interface MethodMetadata {
|
|
8
|
-
target: any;
|
|
9
|
-
propertyKey: string;
|
|
10
|
-
method: string;
|
|
11
|
-
path: string;
|
|
12
|
-
paramMetadata: ParamMetadata[];
|
|
13
|
-
}
|
|
14
|
-
export interface ParamMetadata {
|
|
15
|
-
target: any;
|
|
16
|
-
propertyKey: string;
|
|
17
|
-
index: number;
|
|
18
|
-
type: "body" | "param" | "query" | "header" | "req" | "res";
|
|
19
|
-
paramName?: string;
|
|
20
|
-
}
|
|
1
|
+
import { ClassMetadata, MethodMetadata, ParamMetadata } from "../types/decoration.types";
|
|
2
|
+
/**
|
|
3
|
+
* Central storage for all metadata: classes, methods, parameters
|
|
4
|
+
*/
|
|
21
5
|
export declare class MetadataStorage {
|
|
22
6
|
private static instance;
|
|
23
7
|
private classes;
|
|
@@ -27,10 +11,15 @@ export declare class MetadataStorage {
|
|
|
27
11
|
addClass(metadata: ClassMetadata): void;
|
|
28
12
|
getClass(target: any): ClassMetadata | undefined;
|
|
29
13
|
getAllClasses(): ClassMetadata[];
|
|
14
|
+
hasClass(target: any): boolean;
|
|
15
|
+
private getMethodKey;
|
|
30
16
|
addMethod(metadata: MethodMetadata): void;
|
|
31
17
|
getMethod(target: any, propertyKey: string): MethodMetadata | undefined;
|
|
32
18
|
getAllMethods(): MethodMetadata[];
|
|
19
|
+
hasMethod(target: any, propertyKey: string): boolean;
|
|
20
|
+
private getParamKey;
|
|
33
21
|
addParam(metadata: ParamMetadata): void;
|
|
34
22
|
getParams(target: any, propertyKey: string): ParamMetadata[];
|
|
23
|
+
hasParam(target: any, propertyKey: string, index?: number): boolean;
|
|
35
24
|
}
|
|
36
25
|
//# sourceMappingURL=metadata-storage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata-storage.d.ts","sourceRoot":"","sources":["../../../src/core/metadata/metadata-storage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"metadata-storage.d.ts","sourceRoot":"","sources":["../../../src/core/metadata/metadata-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,cAAc,EACd,aAAa,EACd,MAAM,2BAA2B,CAAC;AAEnC;;GAEG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAkB;IAGzC,OAAO,CAAC,OAAO,CAA2C;IAC1D,OAAO,CAAC,OAAO,CAA0C;IACzD,OAAO,CAAC,MAAM,CAA2C;IAGzD,MAAM,CAAC,WAAW,IAAI,eAAe;IAQrC,QAAQ,CAAC,QAAQ,EAAE,aAAa,GAAG,IAAI;IAOvC,QAAQ,CAAC,MAAM,EAAE,GAAG,GAAG,aAAa,GAAG,SAAS;IAKhD,aAAa,IAAI,aAAa,EAAE;IAIhC,QAAQ,CAAC,MAAM,EAAE,GAAG,GAAG,OAAO;IAK9B,OAAO,CAAC,YAAY;IAIpB,SAAS,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI;IAiBzC,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS;IAMvE,aAAa,IAAI,cAAc,EAAE;IAIjC,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO;IAOpD,OAAO,CAAC,WAAW;IAInB,QAAQ,CAAC,QAAQ,EAAE,aAAa,GAAG,IAAI;IAmBvC,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,GAAG,aAAa,EAAE;IAM5D,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO;CAQpE"}
|
|
@@ -1,53 +1,101 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MetadataStorage = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Central storage for all metadata: classes, methods, parameters
|
|
6
|
+
*/
|
|
4
7
|
class MetadataStorage {
|
|
5
8
|
constructor() {
|
|
9
|
+
// Maps for storing metadata
|
|
6
10
|
this.classes = new Map();
|
|
7
11
|
this.methods = new Map();
|
|
8
12
|
this.params = new Map();
|
|
9
13
|
}
|
|
14
|
+
// Singleton instance
|
|
10
15
|
static getInstance() {
|
|
11
16
|
if (!MetadataStorage.instance) {
|
|
12
17
|
MetadataStorage.instance = new MetadataStorage();
|
|
13
18
|
}
|
|
14
19
|
return MetadataStorage.instance;
|
|
15
20
|
}
|
|
21
|
+
// ----- Classes -----
|
|
16
22
|
addClass(metadata) {
|
|
17
|
-
|
|
23
|
+
if (!metadata?.target)
|
|
24
|
+
return;
|
|
25
|
+
if (!this.classes.has(metadata.target)) {
|
|
26
|
+
this.classes.set(metadata.target, metadata);
|
|
27
|
+
}
|
|
18
28
|
}
|
|
19
29
|
getClass(target) {
|
|
30
|
+
if (!target)
|
|
31
|
+
return undefined;
|
|
20
32
|
return this.classes.get(target);
|
|
21
33
|
}
|
|
22
34
|
getAllClasses() {
|
|
23
35
|
return Array.from(this.classes.values());
|
|
24
36
|
}
|
|
37
|
+
hasClass(target) {
|
|
38
|
+
return !!target && this.classes.has(target);
|
|
39
|
+
}
|
|
40
|
+
// ----- Methods -----
|
|
41
|
+
getMethodKey(target, propertyKey) {
|
|
42
|
+
return `${target.name}_${propertyKey}`;
|
|
43
|
+
}
|
|
25
44
|
addMethod(metadata) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
45
|
+
if (!metadata?.target || !metadata.propertyKey)
|
|
46
|
+
return;
|
|
47
|
+
const targetForKey = metadata.target.prototype || metadata.target;
|
|
48
|
+
const key = this.getMethodKey(metadata.target, metadata.propertyKey);
|
|
49
|
+
// Attach existing params for this method
|
|
50
|
+
const existingParams = this.getParams(targetForKey, metadata.propertyKey).sort((a, b) => a.index - b.index);
|
|
51
|
+
metadata.paramMetadata = existingParams;
|
|
29
52
|
this.methods.set(key, metadata);
|
|
30
53
|
}
|
|
31
54
|
getMethod(target, propertyKey) {
|
|
32
|
-
|
|
55
|
+
if (!target || !propertyKey)
|
|
56
|
+
return undefined;
|
|
57
|
+
const key = this.getMethodKey(target.constructor || target, propertyKey);
|
|
33
58
|
return this.methods.get(key);
|
|
34
59
|
}
|
|
35
60
|
getAllMethods() {
|
|
36
61
|
return Array.from(this.methods.values());
|
|
37
62
|
}
|
|
63
|
+
hasMethod(target, propertyKey) {
|
|
64
|
+
if (!target || !propertyKey)
|
|
65
|
+
return false;
|
|
66
|
+
const key = this.getMethodKey(target.constructor || target, propertyKey);
|
|
67
|
+
return this.methods.has(key);
|
|
68
|
+
}
|
|
69
|
+
// ----- Params -----
|
|
70
|
+
getParamKey(target, propertyKey) {
|
|
71
|
+
return `${target.constructor.name}_${propertyKey}`;
|
|
72
|
+
}
|
|
38
73
|
addParam(metadata) {
|
|
39
|
-
|
|
74
|
+
if (!metadata?.target || !metadata.propertyKey)
|
|
75
|
+
return;
|
|
76
|
+
const key = this.getParamKey(metadata.target, metadata.propertyKey);
|
|
40
77
|
const existing = this.params.get(key) || [];
|
|
41
|
-
|
|
78
|
+
// Deduplicate by propertyKey + index
|
|
79
|
+
if (!existing.some((p) => p.index === metadata.index && p.propertyKey === metadata.propertyKey)) {
|
|
80
|
+
existing.push(metadata);
|
|
81
|
+
}
|
|
42
82
|
this.params.set(key, existing);
|
|
43
83
|
}
|
|
44
84
|
getParams(target, propertyKey) {
|
|
45
|
-
|
|
46
|
-
if (!targetName)
|
|
85
|
+
if (!target || !propertyKey)
|
|
47
86
|
return [];
|
|
48
|
-
const key =
|
|
87
|
+
const key = this.getParamKey(target, propertyKey);
|
|
49
88
|
return this.params.get(key) || [];
|
|
50
89
|
}
|
|
90
|
+
hasParam(target, propertyKey, index) {
|
|
91
|
+
if (!target || !propertyKey)
|
|
92
|
+
return false;
|
|
93
|
+
const key = this.getParamKey(target, propertyKey);
|
|
94
|
+
const existing = this.params.get(key) || [];
|
|
95
|
+
return index !== undefined
|
|
96
|
+
? existing.some((p) => p.index === index)
|
|
97
|
+
: existing.length > 0;
|
|
98
|
+
}
|
|
51
99
|
}
|
|
52
100
|
exports.MetadataStorage = MetadataStorage;
|
|
53
101
|
//# sourceMappingURL=metadata-storage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata-storage.js","sourceRoot":"","sources":["../../../src/core/metadata/metadata-storage.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"metadata-storage.js","sourceRoot":"","sources":["../../../src/core/metadata/metadata-storage.ts"],"names":[],"mappings":";;;AAMA;;GAEG;AACH,MAAa,eAAe;IAA5B;QAGE,4BAA4B;QACpB,YAAO,GAAiC,IAAI,GAAG,EAAE,CAAC;QAClD,YAAO,GAAgC,IAAI,GAAG,EAAE,CAAC;QACjD,WAAM,GAAiC,IAAI,GAAG,EAAE,CAAC;IA2G3D,CAAC;IAzGC,qBAAqB;IACrB,MAAM,CAAC,WAAW;QAChB,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE,CAAC;YAC9B,eAAe,CAAC,QAAQ,GAAG,IAAI,eAAe,EAAE,CAAC;QACnD,CAAC;QACD,OAAO,eAAe,CAAC,QAAQ,CAAC;IAClC,CAAC;IAED,sBAAsB;IACtB,QAAQ,CAAC,QAAuB;QAC9B,IAAI,CAAC,QAAQ,EAAE,MAAM;YAAE,OAAO;QAC9B,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YACvC,IAAI,CAAC,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KAAK,QAAQ,CAAC,KAAK,IAAI,CAAC,CAAC,WAAW,KAAK,QAAQ,CAAC,WAAW,CACvE,EACD,CAAC;YACD,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC1B,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IACjC,CAAC;IAED,SAAS,CAAC,MAAW,EAAE,WAAmB;QACxC,IAAI,CAAC,MAAM,IAAI,CAAC,WAAW;YAAE,OAAO,EAAE,CAAC;QACvC,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;QAClD,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;IACpC,CAAC;IAED,QAAQ,CAAC,MAAW,EAAE,WAAmB,EAAE,KAAc;QACvD,IAAI,CAAC,MAAM,IAAI,CAAC,WAAW;YAAE,OAAO,KAAK,CAAC;QAC1C,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;QAClD,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;QAC5C,OAAO,KAAK,KAAK,SAAS;YACxB,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC;YACzC,CAAC,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;IAC1B,CAAC;CACF;AAjHD,0CAiHC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface ClassMetadata {
|
|
2
|
+
target: Function;
|
|
3
|
+
type: "injectable" | "service" | "controller" | "repository" | "auto-configuration";
|
|
4
|
+
scope?: "singleton" | "request" | "transient";
|
|
5
|
+
path?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface MethodMetadata {
|
|
8
|
+
target: any;
|
|
9
|
+
propertyKey: string;
|
|
10
|
+
method: string;
|
|
11
|
+
path: string;
|
|
12
|
+
paramMetadata: ParamMetadata[];
|
|
13
|
+
}
|
|
14
|
+
export interface ParamMetadata {
|
|
15
|
+
target: any;
|
|
16
|
+
propertyKey: string;
|
|
17
|
+
index: number;
|
|
18
|
+
type: "body" | "param" | "query" | "header" | "req" | "res" | "autowired" | "inject" | "inject-repo" | "value" | "qualifier";
|
|
19
|
+
paramName?: string;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=decoration.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decoration.types.d.ts","sourceRoot":"","sources":["../../../src/core/types/decoration.types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,QAAQ,CAAC;IACjB,IAAI,EACA,YAAY,GACZ,SAAS,GACT,YAAY,GACZ,YAAY,GACZ,oBAAoB,CAAC;IACzB,KAAK,CAAC,EAAE,WAAW,GAAG,SAAS,GAAG,WAAW,CAAC;IAC9C,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,GAAG,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,aAAa,EAAE,CAAC;CAChC;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,GAAG,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EACA,MAAM,GACN,OAAO,GACP,OAAO,GACP,QAAQ,GACR,KAAK,GACL,KAAK,GACL,WAAW,GACX,QAAQ,GACR,aAAa,GACb,OAAO,GACP,WAAW,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decoration.types.js","sourceRoot":"","sources":["../../../src/core/types/decoration.types.ts"],"names":[],"mappings":""}
|