fragment-ts 1.0.22 → 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.js +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/package.json +1 -1
- package/src/cli/commands/init.command.ts +1 -1
- 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
|
@@ -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;QA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G,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":""}
|
package/package.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { METADATA_KEYS } from "../metadata/metadata-keys";
|
|
2
|
+
import { MetadataStorage } from "../metadata/metadata-storage";
|
|
2
3
|
|
|
3
4
|
export interface ApplicationOptions {
|
|
4
5
|
port?: number;
|
|
@@ -8,19 +9,28 @@ export interface ApplicationOptions {
|
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
export function FragmentApplication(
|
|
11
|
-
options:
|
|
12
|
+
options: {
|
|
13
|
+
port?: number;
|
|
14
|
+
host?: string;
|
|
15
|
+
configPath?: string;
|
|
16
|
+
autoScan?: boolean;
|
|
17
|
+
} = {},
|
|
12
18
|
): ClassDecorator {
|
|
13
19
|
return (target: any) => {
|
|
14
20
|
Reflect.defineMetadata(
|
|
15
21
|
METADATA_KEYS.APPLICATION,
|
|
16
22
|
{
|
|
17
|
-
...options,
|
|
18
23
|
port: options.port || 3000,
|
|
19
24
|
host: options.host || "0.0.0.0",
|
|
20
25
|
configPath: options.configPath || "fragment.json",
|
|
21
|
-
autoScan: options.autoScan
|
|
26
|
+
autoScan: options.autoScan ?? true,
|
|
22
27
|
},
|
|
23
28
|
target,
|
|
24
29
|
);
|
|
30
|
+
MetadataStorage.getInstance().addClass({
|
|
31
|
+
target,
|
|
32
|
+
type: "injectable",
|
|
33
|
+
scope: "singleton",
|
|
34
|
+
});
|
|
25
35
|
};
|
|
26
36
|
}
|
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
import { Injectable } from
|
|
2
|
-
import { METADATA_KEYS } from
|
|
3
|
-
import { MetadataStorage } from
|
|
1
|
+
import { Injectable } from "./injectable.decorator";
|
|
2
|
+
import { METADATA_KEYS } from "../metadata/metadata-keys";
|
|
3
|
+
import { MetadataStorage } from "../metadata/metadata-storage";
|
|
4
4
|
|
|
5
5
|
export function AutoConfiguration(): ClassDecorator {
|
|
6
6
|
return (target: any) => {
|
|
7
|
-
Injectable(
|
|
7
|
+
Injectable("singleton")(target);
|
|
8
8
|
Reflect.defineMetadata(METADATA_KEYS.AUTO_CONFIGURATION, true, target);
|
|
9
|
-
|
|
10
|
-
const storage = MetadataStorage.getInstance();
|
|
11
|
-
storage.addClass({
|
|
9
|
+
MetadataStorage.getInstance().addClass({
|
|
12
10
|
target,
|
|
13
|
-
type:
|
|
14
|
-
scope:
|
|
11
|
+
type: "auto-configuration",
|
|
12
|
+
scope: "singleton",
|
|
15
13
|
});
|
|
16
14
|
};
|
|
17
|
-
}
|
|
15
|
+
}
|
|
@@ -1,19 +1,55 @@
|
|
|
1
|
-
import { METADATA_KEYS } from
|
|
1
|
+
import { METADATA_KEYS } from "../metadata/metadata-keys";
|
|
2
|
+
import { MetadataStorage } from "../metadata/metadata-storage";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Conditional decorators
|
|
6
|
+
* Ensures the class is registered in MetadataStorage
|
|
7
|
+
*/
|
|
2
8
|
|
|
3
9
|
export function ConditionalOnClass(classRef: any): ClassDecorator {
|
|
4
10
|
return (target: any) => {
|
|
5
11
|
Reflect.defineMetadata(METADATA_KEYS.CONDITIONAL_ON_CLASS, classRef, target);
|
|
12
|
+
|
|
13
|
+
// Register in MetadataStorage if not already
|
|
14
|
+
const storage = MetadataStorage.getInstance();
|
|
15
|
+
if (!storage.getClass(target)) {
|
|
16
|
+
storage.addClass({
|
|
17
|
+
target,
|
|
18
|
+
type: 'injectable', // default type
|
|
19
|
+
scope: 'singleton',
|
|
20
|
+
});
|
|
21
|
+
}
|
|
6
22
|
};
|
|
7
23
|
}
|
|
8
24
|
|
|
9
25
|
export function ConditionalOnMissingBean(token: any): ClassDecorator {
|
|
10
26
|
return (target: any) => {
|
|
11
27
|
Reflect.defineMetadata(METADATA_KEYS.CONDITIONAL_ON_MISSING_BEAN, token, target);
|
|
28
|
+
|
|
29
|
+
// Register in MetadataStorage if not already
|
|
30
|
+
const storage = MetadataStorage.getInstance();
|
|
31
|
+
if (!storage.getClass(target)) {
|
|
32
|
+
storage.addClass({
|
|
33
|
+
target,
|
|
34
|
+
type: 'injectable',
|
|
35
|
+
scope: 'singleton',
|
|
36
|
+
});
|
|
37
|
+
}
|
|
12
38
|
};
|
|
13
39
|
}
|
|
14
40
|
|
|
15
41
|
export function ConditionalOnProperty(key: string, expectedValue?: any): ClassDecorator {
|
|
16
42
|
return (target: any) => {
|
|
17
43
|
Reflect.defineMetadata(METADATA_KEYS.CONDITIONAL_ON_PROPERTY, { key, expectedValue }, target);
|
|
44
|
+
|
|
45
|
+
// Register in MetadataStorage if not already
|
|
46
|
+
const storage = MetadataStorage.getInstance();
|
|
47
|
+
if (!storage.getClass(target)) {
|
|
48
|
+
storage.addClass({
|
|
49
|
+
target,
|
|
50
|
+
type: 'injectable',
|
|
51
|
+
scope: 'singleton',
|
|
52
|
+
});
|
|
53
|
+
}
|
|
18
54
|
};
|
|
19
55
|
}
|
|
@@ -6,9 +6,7 @@ export function Controller(path: string = ""): ClassDecorator {
|
|
|
6
6
|
return (target: any) => {
|
|
7
7
|
Injectable("singleton")(target);
|
|
8
8
|
Reflect.defineMetadata(METADATA_KEYS.CONTROLLER, path, target);
|
|
9
|
-
|
|
10
|
-
const storage = MetadataStorage.getInstance();
|
|
11
|
-
storage.addClass({
|
|
9
|
+
MetadataStorage.getInstance().addClass({
|
|
12
10
|
target,
|
|
13
11
|
type: "controller",
|
|
14
12
|
scope: "singleton",
|
|
@@ -1,33 +1,20 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
1
2
|
import { METADATA_KEYS } from "../metadata/metadata-keys";
|
|
2
3
|
import { MetadataStorage } from "../metadata/metadata-storage";
|
|
3
4
|
|
|
4
5
|
function createHttpMethodDecorator(method: string) {
|
|
5
6
|
return (path: string = ""): MethodDecorator => {
|
|
6
|
-
return (
|
|
7
|
-
target
|
|
8
|
-
|
|
9
|
-
descriptor: PropertyDescriptor,
|
|
10
|
-
) => {
|
|
11
|
-
Reflect.defineMetadata(
|
|
12
|
-
METADATA_KEYS.HTTP_METHOD,
|
|
13
|
-
method,
|
|
14
|
-
target,
|
|
15
|
-
propertyKey,
|
|
16
|
-
);
|
|
17
|
-
Reflect.defineMetadata(
|
|
18
|
-
METADATA_KEYS.ROUTE_PATH,
|
|
19
|
-
path,
|
|
20
|
-
target,
|
|
21
|
-
propertyKey,
|
|
22
|
-
);
|
|
7
|
+
return (target: any, propertyKey: string | symbol) => {
|
|
8
|
+
Reflect.defineMetadata(METADATA_KEYS.HTTP_METHOD, method, target, propertyKey);
|
|
9
|
+
Reflect.defineMetadata(METADATA_KEYS.ROUTE_PATH, path, target, propertyKey);
|
|
23
10
|
|
|
24
11
|
const storage = MetadataStorage.getInstance();
|
|
25
12
|
storage.addMethod({
|
|
26
13
|
target: target.constructor,
|
|
27
|
-
propertyKey: propertyKey
|
|
14
|
+
propertyKey: propertyKey.toString(),
|
|
28
15
|
method,
|
|
29
16
|
path,
|
|
30
|
-
paramMetadata: storage.getParams(target, propertyKey
|
|
17
|
+
paramMetadata: storage.getParams(target, propertyKey.toString()),
|
|
31
18
|
});
|
|
32
19
|
};
|
|
33
20
|
};
|
|
@@ -39,23 +26,15 @@ export const Put = createHttpMethodDecorator("PUT");
|
|
|
39
26
|
export const Delete = createHttpMethodDecorator("DELETE");
|
|
40
27
|
export const Patch = createHttpMethodDecorator("PATCH");
|
|
41
28
|
|
|
29
|
+
// Parameter decorators
|
|
42
30
|
function createParamDecorator(type: string) {
|
|
43
31
|
return (paramName?: string): ParameterDecorator => {
|
|
44
|
-
return (
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
parameterIndex: number,
|
|
48
|
-
): void => {
|
|
49
|
-
if (!propertyKey) {
|
|
50
|
-
throw new Error(`@${type}() cannot be used on constructor parameters`);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const storage = MetadataStorage.getInstance();
|
|
54
|
-
|
|
55
|
-
storage.addParam({
|
|
32
|
+
return (target, propertyKey, index) => {
|
|
33
|
+
if (!propertyKey) throw new Error(`@${type} cannot be used on constructor params`);
|
|
34
|
+
MetadataStorage.getInstance().addParam({
|
|
56
35
|
target,
|
|
57
36
|
propertyKey: propertyKey.toString(),
|
|
58
|
-
index
|
|
37
|
+
index,
|
|
59
38
|
type: type as any,
|
|
60
39
|
paramName,
|
|
61
40
|
});
|
|
@@ -1,18 +1,25 @@
|
|
|
1
|
-
import { METADATA_KEYS } from
|
|
2
|
-
import { MetadataStorage } from
|
|
1
|
+
import { METADATA_KEYS } from "../metadata/metadata-keys";
|
|
2
|
+
import { MetadataStorage } from "../metadata/metadata-storage";
|
|
3
3
|
|
|
4
4
|
export type Scope = 'singleton' | 'request' | 'transient';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* @Injectable - Marks a class as injectable with a scope
|
|
8
|
+
*/
|
|
6
9
|
export function Injectable(scope: Scope = 'singleton'): ClassDecorator {
|
|
7
10
|
return (target: any) => {
|
|
11
|
+
// Define Reflect metadata
|
|
8
12
|
Reflect.defineMetadata(METADATA_KEYS.INJECTABLE, true, target);
|
|
9
13
|
Reflect.defineMetadata(METADATA_KEYS.SCOPE, scope, target);
|
|
10
|
-
|
|
14
|
+
|
|
15
|
+
// Register in MetadataStorage if not already
|
|
11
16
|
const storage = MetadataStorage.getInstance();
|
|
12
|
-
storage.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
if (!storage.getClass(target)) {
|
|
18
|
+
storage.addClass({
|
|
19
|
+
target,
|
|
20
|
+
type: 'injectable',
|
|
21
|
+
scope
|
|
22
|
+
});
|
|
23
|
+
}
|
|
17
24
|
};
|
|
18
25
|
}
|