web_api_base 3.0.0 → 3.2.1
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/Application.js +81 -7
- package/dist/Application.js.map +1 -1
- package/dist/decorators/controllers/ControllerDecorators.d.ts +22 -18
- package/dist/decorators/controllers/ControllerDecorators.js +66 -50
- package/dist/decorators/controllers/ControllerDecorators.js.map +1 -1
- package/dist/decorators/validations/ValidationDecorators.d.ts +50 -0
- package/dist/decorators/validations/ValidationDecorators.js +181 -0
- package/dist/decorators/validations/ValidationDecorators.js.map +1 -0
- package/dist/index.d.ts +10 -4
- package/dist/index.js +41 -4
- package/dist/index.js.map +1 -1
- package/dist/metadata/OwnMetaDataContainer.d.ts +12 -0
- package/dist/metadata/OwnMetaDataContainer.js +33 -0
- package/dist/metadata/OwnMetaDataContainer.js.map +1 -0
- package/dist/temp/Application.d.ts +5 -0
- package/dist/temp/Application.js +27 -0
- package/dist/temp/Application.js.map +1 -0
- package/dist/temp/Index.d.ts +1 -0
- package/dist/temp/Index.js +8 -0
- package/dist/temp/Index.js.map +1 -0
- package/dist/temp/controllers/StatusController.d.ts +8 -0
- package/dist/temp/controllers/StatusController.js +58 -0
- package/dist/temp/controllers/StatusController.js.map +1 -0
- package/dist/temp/service/SampleService.d.ts +9 -0
- package/dist/temp/service/SampleService.js +19 -0
- package/dist/temp/service/SampleService.js.map +1 -0
- package/package.json +1 -1
- package/readme.md +223 -7
package/dist/Application.js
CHANGED
|
@@ -42,6 +42,7 @@ const DependecyService_1 = __importDefault(require("./dependencyInjection/Depend
|
|
|
42
42
|
const HttpVerbs_1 = require("./enums/httpVerbs/HttpVerbs");
|
|
43
43
|
const fs_1 = __importDefault(require("fs"));
|
|
44
44
|
const path_1 = __importDefault(require("path"));
|
|
45
|
+
const ValidationDecorators_1 = __importDefault(require("./decorators/validations/ValidationDecorators"));
|
|
45
46
|
class Application {
|
|
46
47
|
constructor() {
|
|
47
48
|
this.ApplicationConfiguration = new ApplicationConfiguration_1.default();
|
|
@@ -86,6 +87,7 @@ class Application {
|
|
|
86
87
|
return typeof empty[m] == "function";
|
|
87
88
|
});
|
|
88
89
|
let route = ControllerDecorators_1.default.GetRoute(empty);
|
|
90
|
+
let validateBody = ControllerDecorators_1.default.IsToValidate(empty);
|
|
89
91
|
if (!route)
|
|
90
92
|
return;
|
|
91
93
|
for (let method of methods) {
|
|
@@ -94,6 +96,8 @@ class Application {
|
|
|
94
96
|
continue;
|
|
95
97
|
}
|
|
96
98
|
let verb = ControllerDecorators_1.default.GetVerb(empty, method.toString());
|
|
99
|
+
let fromBody = ControllerDecorators_1.default.GetFromBodyArgs(empty.constructor, method.toString());
|
|
100
|
+
let fromQuery = ControllerDecorators_1.default.GetFromQueryArgs(empty.constructor, method.toString());
|
|
97
101
|
if (!verb)
|
|
98
102
|
verb = HttpVerbs_1.HTTPVerbs.GET;
|
|
99
103
|
console.debug("appended : ", verb, `${route}${action}`);
|
|
@@ -101,14 +105,84 @@ class Application {
|
|
|
101
105
|
let midlewares = ControllerDecorators_1.default.GetMidlewares(empty).reverse();
|
|
102
106
|
midlewares.push(...ControllerDecorators_1.default.GetBefores(empty, method.toString()).reverse());
|
|
103
107
|
let handler = (context) => {
|
|
104
|
-
|
|
108
|
+
var _a;
|
|
105
109
|
let params = [];
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
110
|
+
let ts = (_a = Reflect.getMetadata("design:paramtypes", empty, method.toString())) !== null && _a !== void 0 ? _a : Reflect.getMetadata("design:paramtypes", empty.constructor, method.toString());
|
|
111
|
+
let fromBodyParams = [];
|
|
112
|
+
if (fromBody.length > 0) {
|
|
113
|
+
fromBody.forEach(f => {
|
|
114
|
+
let obj = undefined;
|
|
115
|
+
if (!f.Field)
|
|
116
|
+
obj = request.body;
|
|
117
|
+
else
|
|
118
|
+
obj = request.body[f.Field];
|
|
119
|
+
try {
|
|
120
|
+
obj.__proto__ = ts[f.Index];
|
|
121
|
+
}
|
|
122
|
+
catch (_a) { }
|
|
123
|
+
let t = Reflect.construct(ts[f.Index], []);
|
|
124
|
+
Object.assign(t, obj);
|
|
125
|
+
fromBodyParams.push(t);
|
|
126
|
+
params.push(t);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
let fromQueryParams = [];
|
|
130
|
+
if (fromQuery.length > 0) {
|
|
131
|
+
fromQuery.forEach(f => {
|
|
132
|
+
var _a, _b;
|
|
133
|
+
let obj;
|
|
134
|
+
if (!f.Field) {
|
|
135
|
+
let keys = Object.keys(request.query);
|
|
136
|
+
if (keys.length > 0) {
|
|
137
|
+
obj = (_a = request.query[keys[0]]) === null || _a === void 0 ? void 0 : _a.toString();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
obj = (_b = request.query[f.Field]) === null || _b === void 0 ? void 0 : _b.toString();
|
|
142
|
+
}
|
|
143
|
+
if (obj && ts[f.Index].name.toLocaleLowerCase() == "number") {
|
|
144
|
+
let number = Number.parseFloat(obj.toString());
|
|
145
|
+
if (number != Number.NaN) {
|
|
146
|
+
fromQueryParams.push(number);
|
|
147
|
+
params.push(number);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
fromQueryParams.push(obj);
|
|
152
|
+
params.push(obj);
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
if (params.length > 0) {
|
|
157
|
+
if (validateBody) {
|
|
158
|
+
let erros = [];
|
|
159
|
+
if (fromBody.length > fromBodyParams.filter(s => s != undefined).length) {
|
|
160
|
+
response.status(400);
|
|
161
|
+
response.json({
|
|
162
|
+
Message: "Model binding fail",
|
|
163
|
+
Detailts: ["Some expected body parameter was not provided"]
|
|
164
|
+
});
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
if (fromQuery.length > fromQueryParams.filter(s => s != undefined).length) {
|
|
168
|
+
response.status(400);
|
|
169
|
+
response.json({
|
|
170
|
+
Message: "Model binding fail",
|
|
171
|
+
Detailts: ["Some expected url query string parameter was not provided"]
|
|
172
|
+
});
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
for (let a of fromBodyParams) {
|
|
176
|
+
erros.push(...ValidationDecorators_1.default.Validate(a));
|
|
177
|
+
}
|
|
178
|
+
if (erros.length > 0) {
|
|
179
|
+
response.status(400);
|
|
180
|
+
response.json({
|
|
181
|
+
Message: "Validation fail",
|
|
182
|
+
Detailts: erros
|
|
183
|
+
});
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
112
186
|
}
|
|
113
187
|
}
|
|
114
188
|
let controller = DependecyService_1.default.ResolveCtor(empty.constructor);
|
package/dist/Application.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Application.js","sourceRoot":"","sources":["../Application.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,sDAAoC;AACpC,0FAAiE;AAIjE,yGAAkF;AAClF,8FAAsE;AACtE,2DAAwD;AAGxD,4CAAsB;AACtB,gDAAwB;
|
|
1
|
+
{"version":3,"file":"Application.js","sourceRoot":"","sources":["../Application.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,sDAAoC;AACpC,0FAAiE;AAIjE,yGAAkF;AAClF,8FAAsE;AACtE,2DAAwD;AAGxD,4CAAsB;AACtB,gDAAwB;AAExB,yGAAiF;AAEjF,MAA8B,WAAW;IAQrC;QAEI,IAAI,CAAC,wBAAwB,GAAG,IAAI,kCAAwB,EAAE,CAAC;QAE/D,IAAI,CAAC,OAAO,GAAG,IAAA,iBAAa,GAAE,CAAC;IAEnC,CAAC;IAGY,UAAU;;YAEnB,MAAO,IAAI,CAAC,wBAAqD,CAAC,UAAU,EAAE,CAAC;YAE/E,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAa,CAAC,IAAI,CAAC,EAAC,K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,OAAO,EAAG,GAAG,EAAE;gCAEX,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;4BAEvH,CAAC;yBACJ,CAAC,CAAC;qBACV;oBAED,KAAI,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EACvC;wBACI,mBAAmB,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAE,EAAE,GAAC,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;qBACrG;oBAED,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;iBACzB;qBACG;oBAEA,OAAO,CAAC;wBACJ,OAAO,EAAG,OAAO;wBACjB,QAAQ,EAAG,QAAQ;wBACnB,IAAI,EAAG,GAAG,EAAE,GAAE,CAAC;qBAClB,CAAC,CAAC;iBACN;YAGL,CAAC,CAAC,CAAA;SACL;IAEL,CAAC;CAMJ;AAjTD,8BAiTC"}
|
|
@@ -4,33 +4,37 @@ import IController from '../../interfaces/IController';
|
|
|
4
4
|
import IMidleware from '../../midlewares/IMidleware';
|
|
5
5
|
export default class ControllersDecorators {
|
|
6
6
|
constructor();
|
|
7
|
-
private static
|
|
8
|
-
private static
|
|
9
|
-
private static
|
|
10
|
-
private static
|
|
11
|
-
private static
|
|
12
|
-
private static
|
|
7
|
+
private static _routeKeyMetadata;
|
|
8
|
+
private static _actionVerbKeyMetadata;
|
|
9
|
+
private static _actionNameKeyMetadata;
|
|
10
|
+
private static _argumentsHandlerKeyMetadata;
|
|
11
|
+
private static _controllerMidlewaresKeyMetadata;
|
|
12
|
+
private static _actionsMidlewaresKeyMetadata;
|
|
13
|
+
private static _validateBodyKeyMetadata;
|
|
14
|
+
private static _fromQueryKeyMetadata;
|
|
15
|
+
private static _fromBodyKeyMetadata;
|
|
13
16
|
static Route(route?: string): (target: Function) => void;
|
|
17
|
+
static GetRoute(controller: IController): string | undefined;
|
|
18
|
+
static Validate(): (target: Function) => void;
|
|
19
|
+
static IsToValidate(controller: IController): boolean;
|
|
14
20
|
static Use(midleware: IMidleware): (target: Function) => void;
|
|
15
21
|
static GetMidlewares(controller: IController): IMidleware[];
|
|
16
22
|
static Before(midleware: IMidleware): (target: Object, methodName: string, propertyDescriptor: PropertyDescriptor) => void;
|
|
17
23
|
static GetBefores(controller: IController, methodName: string): IMidleware[];
|
|
18
|
-
static GetRoute(controller: IController): string | undefined;
|
|
19
24
|
static Verb(verb: HTTPVerbs, actionName?: String): (target: Object, methodName: string, propertyDescriptor: PropertyDescriptor) => void;
|
|
20
25
|
static GetVerb(target: IController, methodName: string): HTTPVerbs | undefined;
|
|
21
26
|
static Action(actionName?: String): (target: Object, methodName: string, propertyDescriptor: PropertyDescriptor) => void;
|
|
22
27
|
static GetAction(target: IController, methodName: string): string | undefined;
|
|
23
|
-
static
|
|
24
|
-
static
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
static
|
|
28
|
+
static FromBody(bodyPropName?: string): (target: Object, methodName: string, parameterIndex: number) => void;
|
|
29
|
+
static GetFromBodyArgs(target: Function, method: string): {
|
|
30
|
+
Index: number;
|
|
31
|
+
Field?: string;
|
|
32
|
+
}[];
|
|
33
|
+
static FromQuery(bodyPropName?: string): (target: Object, methodName: string, parameterIndex: number) => void;
|
|
34
|
+
static GetFromQueryArgs(target: Function, method: string): {
|
|
35
|
+
Index: number;
|
|
36
|
+
Field?: string;
|
|
37
|
+
}[];
|
|
29
38
|
private static SetMetaData;
|
|
30
39
|
private static GetMetaData;
|
|
31
40
|
}
|
|
32
|
-
interface IArgumentResolverHandler {
|
|
33
|
-
Arguments: string[];
|
|
34
|
-
CreateArgumentsList: (args: any) => any[];
|
|
35
|
-
}
|
|
36
|
-
export {};
|
|
@@ -7,89 +7,102 @@ class ControllersDecorators {
|
|
|
7
7
|
static Route(route) {
|
|
8
8
|
return function (target) {
|
|
9
9
|
let value = route !== null && route !== void 0 ? route : target.name.toLocaleLowerCase().replace("controller", "");
|
|
10
|
-
Reflect.defineMetadata(ControllersDecorators.
|
|
10
|
+
Reflect.defineMetadata(ControllersDecorators._routeKeyMetadata, value, target);
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
|
+
static GetRoute(controller) {
|
|
14
|
+
let meta = Reflect.getMetadata(ControllersDecorators._routeKeyMetadata, controller.constructor);
|
|
15
|
+
if (meta && meta[0] != '/') {
|
|
16
|
+
return `/${meta}`.toLocaleLowerCase();
|
|
17
|
+
}
|
|
18
|
+
return meta === null || meta === void 0 ? void 0 : meta.toLocaleLowerCase();
|
|
19
|
+
}
|
|
20
|
+
static Validate() {
|
|
21
|
+
return function (target) {
|
|
22
|
+
Reflect.defineMetadata(ControllersDecorators._validateBodyKeyMetadata, true, target);
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
static IsToValidate(controller) {
|
|
26
|
+
var _a;
|
|
27
|
+
return (_a = Reflect.getMetadata(ControllersDecorators._validateBodyKeyMetadata, controller.constructor)) !== null && _a !== void 0 ? _a : false;
|
|
28
|
+
}
|
|
13
29
|
static Use(midleware) {
|
|
14
30
|
return function (target) {
|
|
15
31
|
var _a;
|
|
16
|
-
let current = (_a = Reflect.getMetadata(ControllersDecorators.
|
|
32
|
+
let current = (_a = Reflect.getMetadata(ControllersDecorators._controllerMidlewaresKeyMetadata, target)) !== null && _a !== void 0 ? _a : [];
|
|
17
33
|
current.push(midleware);
|
|
18
|
-
Reflect.defineMetadata(ControllersDecorators.
|
|
34
|
+
Reflect.defineMetadata(ControllersDecorators._controllerMidlewaresKeyMetadata, current, target);
|
|
19
35
|
};
|
|
20
36
|
}
|
|
21
37
|
static GetMidlewares(controller) {
|
|
22
38
|
var _a;
|
|
23
|
-
return (_a = Reflect.getMetadata(ControllersDecorators.
|
|
39
|
+
return (_a = Reflect.getMetadata(ControllersDecorators._controllerMidlewaresKeyMetadata, controller.constructor)) !== null && _a !== void 0 ? _a : [];
|
|
24
40
|
}
|
|
25
41
|
static Before(midleware) {
|
|
26
42
|
return function (target, methodName, propertyDescriptor) {
|
|
27
43
|
var _a;
|
|
28
|
-
let current = (_a = Reflect.getMetadata(ControllersDecorators.
|
|
44
|
+
let current = (_a = Reflect.getMetadata(ControllersDecorators._actionsMidlewaresKeyMetadata, target, methodName)) !== null && _a !== void 0 ? _a : [];
|
|
29
45
|
current.push(midleware);
|
|
30
|
-
ControllersDecorators.SetMetaData(ControllersDecorators.
|
|
46
|
+
ControllersDecorators.SetMetaData(ControllersDecorators._actionsMidlewaresKeyMetadata, target, methodName, current);
|
|
31
47
|
};
|
|
32
48
|
}
|
|
33
49
|
static GetBefores(controller, methodName) {
|
|
34
50
|
var _a;
|
|
35
|
-
return (_a = this.GetMetaData(ControllersDecorators.
|
|
36
|
-
}
|
|
37
|
-
static GetRoute(controller) {
|
|
38
|
-
let meta = Reflect.getMetadata(ControllersDecorators.RouteKeyMetadata, controller.constructor);
|
|
39
|
-
if (meta && meta[0] != '/') {
|
|
40
|
-
return `/${meta}`.toLocaleLowerCase();
|
|
41
|
-
}
|
|
42
|
-
return meta === null || meta === void 0 ? void 0 : meta.toLocaleLowerCase();
|
|
51
|
+
return (_a = this.GetMetaData(ControllersDecorators._actionsMidlewaresKeyMetadata, controller, methodName)) !== null && _a !== void 0 ? _a : [];
|
|
43
52
|
}
|
|
44
53
|
static Verb(verb, actionName) {
|
|
45
54
|
return function (target, methodName, propertyDescriptor) {
|
|
46
|
-
ControllersDecorators.SetMetaData(ControllersDecorators.
|
|
47
|
-
ControllersDecorators.SetMetaData(ControllersDecorators.
|
|
55
|
+
ControllersDecorators.SetMetaData(ControllersDecorators._actionNameKeyMetadata, target, methodName, actionName !== null && actionName !== void 0 ? actionName : methodName.toLocaleLowerCase());
|
|
56
|
+
ControllersDecorators.SetMetaData(ControllersDecorators._actionVerbKeyMetadata, target, methodName, verb);
|
|
48
57
|
};
|
|
49
58
|
}
|
|
50
59
|
static GetVerb(target, methodName) {
|
|
51
|
-
let meta = this.GetMetaData(ControllersDecorators.
|
|
60
|
+
let meta = this.GetMetaData(ControllersDecorators._actionVerbKeyMetadata, target, methodName);
|
|
52
61
|
return meta;
|
|
53
62
|
}
|
|
54
63
|
static Action(actionName) {
|
|
55
64
|
return function (target, methodName, propertyDescriptor) {
|
|
56
|
-
ControllersDecorators.SetMetaData(ControllersDecorators.
|
|
65
|
+
ControllersDecorators.SetMetaData(ControllersDecorators._actionNameKeyMetadata, target, methodName, actionName !== null && actionName !== void 0 ? actionName : methodName.toLocaleLowerCase());
|
|
57
66
|
};
|
|
58
67
|
}
|
|
59
68
|
static GetAction(target, methodName) {
|
|
60
|
-
let meta = this.GetMetaData(ControllersDecorators.
|
|
69
|
+
let meta = this.GetMetaData(ControllersDecorators._actionNameKeyMetadata, target, methodName);
|
|
61
70
|
if (meta && meta[0] != '/') {
|
|
62
71
|
return `/${meta}`.toLocaleLowerCase();
|
|
63
72
|
}
|
|
64
73
|
return meta === null || meta === void 0 ? void 0 : meta.toLocaleLowerCase();
|
|
65
74
|
}
|
|
66
|
-
static
|
|
67
|
-
return function (target, methodName,
|
|
68
|
-
ControllersDecorators.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
results[1] = args[argName2];
|
|
77
|
-
if (argName3 && args[argName3] != undefined)
|
|
78
|
-
results[2] = args[argName3];
|
|
79
|
-
if (argName4 && args[argName4] != undefined)
|
|
80
|
-
results[3] = args[argName4];
|
|
81
|
-
if (argName5 && args[argName5] != undefined)
|
|
82
|
-
results[4] = args[argName5];
|
|
83
|
-
if (argName6 && args[argName6] != undefined)
|
|
84
|
-
results[5] = args[argName6];
|
|
85
|
-
return results;
|
|
86
|
-
}
|
|
87
|
-
});
|
|
75
|
+
static FromBody(bodyPropName) {
|
|
76
|
+
return function (target, methodName, parameterIndex) {
|
|
77
|
+
let meta = ControllersDecorators.GetFromBodyArgs(target.constructor, methodName);
|
|
78
|
+
let item = meta.filter(x => x.Index == parameterIndex);
|
|
79
|
+
if (item.length == 0)
|
|
80
|
+
meta.push({ Index: parameterIndex, Field: bodyPropName });
|
|
81
|
+
else {
|
|
82
|
+
item[0].Field = bodyPropName;
|
|
83
|
+
}
|
|
84
|
+
Reflect.defineMetadata(ControllersDecorators._fromBodyKeyMetadata, meta, target.constructor, methodName);
|
|
88
85
|
};
|
|
89
86
|
}
|
|
90
|
-
static
|
|
91
|
-
|
|
92
|
-
return
|
|
87
|
+
static GetFromBodyArgs(target, method) {
|
|
88
|
+
var _a;
|
|
89
|
+
return (_a = Reflect.getMetadata(ControllersDecorators._fromBodyKeyMetadata, target, method)) !== null && _a !== void 0 ? _a : [];
|
|
90
|
+
}
|
|
91
|
+
static FromQuery(bodyPropName) {
|
|
92
|
+
return function (target, methodName, parameterIndex) {
|
|
93
|
+
let meta = ControllersDecorators.GetFromQueryArgs(target.constructor, methodName);
|
|
94
|
+
let item = meta.filter(x => x.Index == parameterIndex);
|
|
95
|
+
if (item.length == 0)
|
|
96
|
+
meta.push({ Index: parameterIndex, Field: bodyPropName });
|
|
97
|
+
else {
|
|
98
|
+
item[0].Field = bodyPropName;
|
|
99
|
+
}
|
|
100
|
+
Reflect.defineMetadata(ControllersDecorators._fromQueryKeyMetadata, meta, target.constructor, methodName);
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
static GetFromQueryArgs(target, method) {
|
|
104
|
+
var _a;
|
|
105
|
+
return (_a = Reflect.getMetadata(ControllersDecorators._fromQueryKeyMetadata, target, method)) !== null && _a !== void 0 ? _a : [];
|
|
93
106
|
}
|
|
94
107
|
static SetMetaData(key, target, methodName, value) {
|
|
95
108
|
var meta = Reflect.getOwnMetadata(key, target, methodName);
|
|
@@ -105,10 +118,13 @@ class ControllersDecorators {
|
|
|
105
118
|
}
|
|
106
119
|
}
|
|
107
120
|
exports.default = ControllersDecorators;
|
|
108
|
-
ControllersDecorators.
|
|
109
|
-
ControllersDecorators.
|
|
110
|
-
ControllersDecorators.
|
|
111
|
-
ControllersDecorators.
|
|
112
|
-
ControllersDecorators.
|
|
113
|
-
ControllersDecorators.
|
|
121
|
+
ControllersDecorators._routeKeyMetadata = "meta:controllerRoute";
|
|
122
|
+
ControllersDecorators._actionVerbKeyMetadata = "meta:actionVerb";
|
|
123
|
+
ControllersDecorators._actionNameKeyMetadata = "meta:actionName";
|
|
124
|
+
ControllersDecorators._argumentsHandlerKeyMetadata = "meta:argHandler";
|
|
125
|
+
ControllersDecorators._controllerMidlewaresKeyMetadata = "meta:controllerMidlewaresKey";
|
|
126
|
+
ControllersDecorators._actionsMidlewaresKeyMetadata = "meta:actionMidlewaresKey";
|
|
127
|
+
ControllersDecorators._validateBodyKeyMetadata = "meta:validateBodyKey";
|
|
128
|
+
ControllersDecorators._fromQueryKeyMetadata = "meta:fromQueryKey";
|
|
129
|
+
ControllersDecorators._fromBodyKeyMetadata = "meta:fromBodyKey";
|
|
114
130
|
//# sourceMappingURL=ControllerDecorators.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ControllerDecorators.js","sourceRoot":"","sources":["../../../decorators/controllers/ControllerDecorators.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"ControllerDecorators.js","sourceRoot":"","sources":["../../../decorators/controllers/ControllerDecorators.ts"],"names":[],"mappings":";;AAAA,4BAA0B;AAM1B,MAAqB,qBAAqB;IAEtC;IAGA,CAAC;IAaM,MAAM,CAAC,KAAK,CAAC,KAAe;QAE/B,O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qBAAqB,EAAE,MAAM,EAAE,MAAM,CAAC,mCAAI,EAAE,CAAC;IAClG,CAAC;IAGO,MAAM,CAAC,WAAW,CAAI,GAAW,EAAE,MAAe,EAAE,UAAmB,EAAE,KAAS;QAEtF,IAAI,IAAI,GAAG,OAAO,CAAC,cAAc,CAAC,GAAG,EAAE,MAAgB,EAAE,UAAU,CAAC,CAAC;QAErE,IAAG,CAAC,IAAI;YACJ,OAAO,CAAC,cAAc,CAAC,GAAG,EAAE,KAAK,EAAE,MAAgB,EAAE,UAAU,CAAC,CAAC;IACzE,CAAC;IAGO,MAAM,CAAC,WAAW,CAAI,GAAW,EAAE,MAAe,EAAE,UAAmB;QAE3E,IAAI,IAAI,GAAG,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;QAExD,IAAG,IAAI,IAAI,SAAS;YAChB,OAAO,IAAS,CAAC;;YAEjB,OAAO,SAAS,CAAC;IACzB,CAAC;;AAnML,wCAqMC;AA9LkB,uCAAiB,GAAG,sBAAsB,CAAC;AAC3C,4CAAsB,GAAG,iBAAiB,CAAC;AAC3C,4CAAsB,GAAG,iBAAiB,CAAC;AAC3C,kDAA4B,GAAG,iBAAiB,CAAC;AACjD,sDAAgC,GAAG,8BAA8B,CAAC;AAClE,mDAA6B,GAAG,0BAA0B,CAAC;AAC3D,8CAAwB,GAAG,sBAAsB,CAAC;AAClD,2CAAqB,GAAG,mBAAmB,CAAC;AAC5C,0CAAoB,GAAG,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
export default class ValidationDecorators {
|
|
3
|
+
constructor();
|
|
4
|
+
private static _requiredKeyMetadata;
|
|
5
|
+
private static _maxlenghtKeyMetadata;
|
|
6
|
+
private static _minlenghtKeyMetadata;
|
|
7
|
+
private static _regexKeyMetadata;
|
|
8
|
+
private static _ruleKeyMetadata;
|
|
9
|
+
private static _maxValueKeyMetadata;
|
|
10
|
+
private static _minValueKeyMetadata;
|
|
11
|
+
private static _keysToValidateKeyMetada;
|
|
12
|
+
static AddField(target: Object, property: string): void;
|
|
13
|
+
static GetFields(target: Object): string[];
|
|
14
|
+
static Required(message?: string): (target: Object, property: string) => void;
|
|
15
|
+
static IsRequired(target: Object, property: string): {
|
|
16
|
+
Message: string;
|
|
17
|
+
} | undefined;
|
|
18
|
+
static MaxLenght(max: number, message?: string): (target: Object, property: string) => void;
|
|
19
|
+
static GetMaxlenght(target: Object, property: string): {
|
|
20
|
+
Message: string;
|
|
21
|
+
Max: number;
|
|
22
|
+
} | undefined;
|
|
23
|
+
static MinLenght(min: number, message?: string): (target: Object, property: string) => void;
|
|
24
|
+
static GetMinlenght(target: Object, property: string): {
|
|
25
|
+
Message: string;
|
|
26
|
+
Min: number;
|
|
27
|
+
} | undefined;
|
|
28
|
+
static MinValue(min: number, message?: string): (target: Object, property: string) => void;
|
|
29
|
+
static GetMinValue(target: Object, property: string): {
|
|
30
|
+
Message: string;
|
|
31
|
+
Min: number;
|
|
32
|
+
} | undefined;
|
|
33
|
+
static MaxValue(max: number, message?: string): (target: Object, property: string) => void;
|
|
34
|
+
static GetMaxValue(target: Object, property: string): {
|
|
35
|
+
Message: string;
|
|
36
|
+
Max: number;
|
|
37
|
+
} | undefined;
|
|
38
|
+
static Regex(regex: RegExp, message?: string): (target: Object, property: string) => void;
|
|
39
|
+
static GetRegex(target: Object, property: string): {
|
|
40
|
+
Message: string;
|
|
41
|
+
RegExp: RegExp;
|
|
42
|
+
} | undefined;
|
|
43
|
+
static Rule<T>(validationFunction: (arg: T) => boolean, message?: string): (target: Object, property: string) => void;
|
|
44
|
+
static GetRule<T>(target: Object, property: string): {
|
|
45
|
+
Message: string;
|
|
46
|
+
Function: (arg: T) => boolean;
|
|
47
|
+
} | undefined;
|
|
48
|
+
static Validate<T>(object: T): string[];
|
|
49
|
+
private static TryGetValue;
|
|
50
|
+
}
|