@spinajs/http 2.0.179 → 2.0.181
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/lib/cjs/bootstrap.d.ts +4 -4
- package/lib/cjs/bootstrap.js +29 -29
- package/lib/cjs/bootstrap.js.map +1 -1
- package/lib/cjs/config/http.d.ts +58 -58
- package/lib/cjs/config/http.js +86 -86
- package/lib/cjs/controllers.d.ts +48 -48
- package/lib/cjs/controllers.d.ts.map +1 -1
- package/lib/cjs/controllers.js +307 -312
- package/lib/cjs/controllers.js.map +1 -1
- package/lib/cjs/decorators.d.ts +183 -183
- package/lib/cjs/decorators.js +441 -441
- package/lib/cjs/hydrators/DateTimeHydrator.d.ts +5 -5
- package/lib/cjs/hydrators/DateTimeHydrator.js +36 -36
- package/lib/cjs/hydrators/DateTimeHydrator.js.map +1 -1
- package/lib/cjs/index.d.ts +9 -9
- package/lib/cjs/index.js +25 -25
- package/lib/cjs/interfaces.d.ts +569 -550
- package/lib/cjs/interfaces.d.ts.map +1 -1
- package/lib/cjs/interfaces.js +266 -259
- package/lib/cjs/interfaces.js.map +1 -1
- package/lib/cjs/middlewares/RealIp.d.ts +8 -8
- package/lib/cjs/middlewares/RealIp.js +34 -34
- package/lib/cjs/middlewares/RealIp.js.map +1 -1
- package/lib/cjs/middlewares/RequestId.d.ts +8 -8
- package/lib/cjs/middlewares/RequestId.js +35 -35
- package/lib/cjs/middlewares/RequestId.js.map +1 -1
- package/lib/cjs/middlewares/ResponseTime.d.ts +10 -10
- package/lib/cjs/middlewares/ResponseTime.js +41 -41
- package/lib/cjs/middlewares/ResponseTime.js.map +1 -1
- package/lib/cjs/response-methods/badRequest.d.ts +12 -12
- package/lib/cjs/response-methods/badRequest.js +20 -20
- package/lib/cjs/response-methods/conflict.d.ts +12 -12
- package/lib/cjs/response-methods/conflict.js +20 -20
- package/lib/cjs/response-methods/cookieResponse.d.ts +19 -19
- package/lib/cjs/response-methods/cookieResponse.js +73 -73
- package/lib/cjs/response-methods/created.d.ts +12 -12
- package/lib/cjs/response-methods/created.js +19 -19
- package/lib/cjs/response-methods/errorResponse.d.ts +7 -7
- package/lib/cjs/response-methods/errorResponse.js +24 -24
- package/lib/cjs/response-methods/file.d.ts +26 -26
- package/lib/cjs/response-methods/file.d.ts.map +1 -1
- package/lib/cjs/response-methods/file.js +112 -133
- package/lib/cjs/response-methods/file.js.map +1 -1
- package/lib/cjs/response-methods/forbidden.d.ts +12 -12
- package/lib/cjs/response-methods/forbidden.js +20 -20
- package/lib/cjs/response-methods/index.d.ts +13 -13
- package/lib/cjs/response-methods/index.js +29 -29
- package/lib/cjs/response-methods/noContent.d.ts +12 -12
- package/lib/cjs/response-methods/noContent.js +20 -20
- package/lib/cjs/response-methods/notAcceptable.d.ts +13 -13
- package/lib/cjs/response-methods/notAcceptable.js +21 -21
- package/lib/cjs/response-methods/notAllowed.d.ts +12 -12
- package/lib/cjs/response-methods/notAllowed.js +20 -20
- package/lib/cjs/response-methods/notFound.d.ts +12 -12
- package/lib/cjs/response-methods/notFound.js +20 -20
- package/lib/cjs/response-methods/ok.d.ts +12 -12
- package/lib/cjs/response-methods/ok.js +19 -19
- package/lib/cjs/response-methods/redirect.d.ts +12 -12
- package/lib/cjs/response-methods/redirect.js +19 -19
- package/lib/cjs/response-methods/serverError.d.ts +12 -12
- package/lib/cjs/response-methods/serverError.js +20 -20
- package/lib/cjs/response-methods/template.d.ts +15 -15
- package/lib/cjs/response-methods/template.js +36 -36
- package/lib/cjs/response-methods/unauthorized.d.ts +12 -12
- package/lib/cjs/response-methods/unauthorized.js +20 -20
- package/lib/cjs/response-methods/validationError.d.ts +12 -12
- package/lib/cjs/response-methods/validationError.js +20 -20
- package/lib/cjs/responses.d.ts +34 -34
- package/lib/cjs/responses.js +173 -173
- package/lib/cjs/route-args/ArgAsRequest.d.ts +11 -11
- package/lib/cjs/route-args/ArgAsRequest.js +24 -24
- package/lib/cjs/route-args/ArgAsRequest.js.map +1 -1
- package/lib/cjs/route-args/ArgAsResponse.d.ts +10 -10
- package/lib/cjs/route-args/ArgAsResponse.js +24 -24
- package/lib/cjs/route-args/ArgAsResponse.js.map +1 -1
- package/lib/cjs/route-args/ArgHydrator.d.ts +4 -4
- package/lib/cjs/route-args/ArgHydrator.js +6 -6
- package/lib/cjs/route-args/FromBody.d.ts +10 -10
- package/lib/cjs/route-args/FromBody.js +26 -26
- package/lib/cjs/route-args/FromBody.js.map +1 -1
- package/lib/cjs/route-args/FromCookie.d.ts +13 -13
- package/lib/cjs/route-args/FromCookie.js +72 -72
- package/lib/cjs/route-args/FromCookie.js.map +1 -1
- package/lib/cjs/route-args/FromDi.d.ts +13 -13
- package/lib/cjs/route-args/FromDi.js +35 -35
- package/lib/cjs/route-args/FromDi.js.map +1 -1
- package/lib/cjs/route-args/FromForm.d.ts +66 -92
- package/lib/cjs/route-args/FromForm.d.ts.map +1 -1
- package/lib/cjs/route-args/FromForm.js +214 -291
- package/lib/cjs/route-args/FromForm.js.map +1 -1
- package/lib/cjs/route-args/FromHeaderArg.d.ts +10 -10
- package/lib/cjs/route-args/FromHeaderArg.js +25 -25
- package/lib/cjs/route-args/FromHeaderArg.js.map +1 -1
- package/lib/cjs/route-args/FromParams.d.ts +10 -10
- package/lib/cjs/route-args/FromParams.js +27 -27
- package/lib/cjs/route-args/FromParams.js.map +1 -1
- package/lib/cjs/route-args/FromQuery.d.ts +10 -10
- package/lib/cjs/route-args/FromQuery.js +27 -27
- package/lib/cjs/route-args/FromQuery.js.map +1 -1
- package/lib/cjs/route-args/RequestFields.d.ts +40 -40
- package/lib/cjs/route-args/RequestFields.js +110 -110
- package/lib/cjs/route-args/RequestFields.js.map +1 -1
- package/lib/cjs/route-args/RouteArgs.d.ts +22 -22
- package/lib/cjs/route-args/RouteArgs.js +114 -114
- package/lib/cjs/route-args/RouteArgs.js.map +1 -1
- package/lib/cjs/route-args/index.d.ts +12 -12
- package/lib/cjs/route-args/index.js +28 -28
- package/lib/cjs/schemas/RouteArgsSchemas.d.ts +36 -36
- package/lib/cjs/schemas/RouteArgsSchemas.js +26 -26
- package/lib/cjs/server.d.ts +50 -50
- package/lib/cjs/server.js +272 -272
- package/lib/cjs/server.js.map +1 -1
- package/lib/cjs/transformers/PureTransformer.d.ts +9 -9
- package/lib/cjs/transformers/PureTransformer.js +27 -27
- package/lib/cjs/transformers/PureTransformer.js.map +1 -1
- package/lib/cjs/transformers/index.d.ts +1 -1
- package/lib/cjs/transformers/index.js +17 -17
- package/lib/cjs/uploaders/ImmediateFileUploader.d.ts +19 -0
- package/lib/cjs/uploaders/ImmediateFileUploader.d.ts.map +1 -0
- package/lib/cjs/uploaders/ImmediateFileUploader.js +69 -0
- package/lib/cjs/uploaders/ImmediateFileUploader.js.map +1 -0
- package/lib/mjs/bootstrap.d.ts +4 -4
- package/lib/mjs/bootstrap.js +26 -26
- package/lib/mjs/bootstrap.js.map +1 -1
- package/lib/mjs/config/http.d.ts +58 -58
- package/lib/mjs/config/http.js +81 -81
- package/lib/mjs/controllers.d.ts +48 -48
- package/lib/mjs/controllers.d.ts.map +1 -1
- package/lib/mjs/controllers.js +276 -281
- package/lib/mjs/controllers.js.map +1 -1
- package/lib/mjs/decorators.d.ts +183 -183
- package/lib/mjs/decorators.js +404 -404
- package/lib/mjs/exceptions.d.ts +1 -1
- package/lib/mjs/exceptions.js +1 -1
- package/lib/mjs/hydrators/DateTimeHydrator.d.ts +5 -5
- package/lib/mjs/hydrators/DateTimeHydrator.js +30 -30
- package/lib/mjs/hydrators/DateTimeHydrator.js.map +1 -1
- package/lib/mjs/index.d.ts +9 -9
- package/lib/mjs/index.js +9 -9
- package/lib/mjs/interfaces.d.ts +569 -550
- package/lib/mjs/interfaces.d.ts.map +1 -1
- package/lib/mjs/interfaces.js +257 -251
- package/lib/mjs/interfaces.js.map +1 -1
- package/lib/mjs/middlewares/RealIp.d.ts +8 -8
- package/lib/mjs/middlewares/RealIp.js +31 -31
- package/lib/mjs/middlewares/RealIp.js.map +1 -1
- package/lib/mjs/middlewares/RequestId.d.ts +8 -8
- package/lib/mjs/middlewares/RequestId.js +32 -32
- package/lib/mjs/middlewares/RequestId.js.map +1 -1
- package/lib/mjs/middlewares/ResponseTime.d.ts +10 -10
- package/lib/mjs/middlewares/ResponseTime.js +38 -38
- package/lib/mjs/middlewares/ResponseTime.js.map +1 -1
- package/lib/mjs/response-methods/badRequest.d.ts +12 -12
- package/lib/mjs/response-methods/badRequest.js +16 -16
- package/lib/mjs/response-methods/conflict.d.ts +12 -12
- package/lib/mjs/response-methods/conflict.js +16 -16
- package/lib/mjs/response-methods/cookieResponse.d.ts +19 -19
- package/lib/mjs/response-methods/cookieResponse.js +46 -46
- package/lib/mjs/response-methods/created.d.ts +12 -12
- package/lib/mjs/response-methods/created.js +15 -15
- package/lib/mjs/response-methods/errorResponse.d.ts +7 -7
- package/lib/mjs/response-methods/errorResponse.js +17 -17
- package/lib/mjs/response-methods/file.d.ts +26 -26
- package/lib/mjs/response-methods/file.d.ts.map +1 -1
- package/lib/mjs/response-methods/file.js +103 -124
- package/lib/mjs/response-methods/file.js.map +1 -1
- package/lib/mjs/response-methods/forbidden.d.ts +12 -12
- package/lib/mjs/response-methods/forbidden.js +16 -16
- package/lib/mjs/response-methods/index.d.ts +13 -13
- package/lib/mjs/response-methods/index.js +13 -13
- package/lib/mjs/response-methods/noContent.d.ts +12 -12
- package/lib/mjs/response-methods/noContent.js +16 -16
- package/lib/mjs/response-methods/notAcceptable.d.ts +13 -13
- package/lib/mjs/response-methods/notAcceptable.js +17 -17
- package/lib/mjs/response-methods/notAllowed.d.ts +12 -12
- package/lib/mjs/response-methods/notAllowed.js +16 -16
- package/lib/mjs/response-methods/notFound.d.ts +12 -12
- package/lib/mjs/response-methods/notFound.js +16 -16
- package/lib/mjs/response-methods/ok.d.ts +12 -12
- package/lib/mjs/response-methods/ok.js +15 -15
- package/lib/mjs/response-methods/redirect.d.ts +12 -12
- package/lib/mjs/response-methods/redirect.js +15 -15
- package/lib/mjs/response-methods/serverError.d.ts +12 -12
- package/lib/mjs/response-methods/serverError.js +16 -16
- package/lib/mjs/response-methods/template.d.ts +15 -15
- package/lib/mjs/response-methods/template.js +29 -29
- package/lib/mjs/response-methods/unauthorized.d.ts +12 -12
- package/lib/mjs/response-methods/unauthorized.js +16 -16
- package/lib/mjs/response-methods/validationError.d.ts +12 -12
- package/lib/mjs/response-methods/validationError.js +16 -16
- package/lib/mjs/responses.d.ts +34 -34
- package/lib/mjs/responses.js +143 -143
- package/lib/mjs/route-args/ArgAsRequest.d.ts +11 -11
- package/lib/mjs/route-args/ArgAsRequest.js +21 -21
- package/lib/mjs/route-args/ArgAsRequest.js.map +1 -1
- package/lib/mjs/route-args/ArgAsResponse.d.ts +10 -10
- package/lib/mjs/route-args/ArgAsResponse.js +21 -21
- package/lib/mjs/route-args/ArgAsResponse.js.map +1 -1
- package/lib/mjs/route-args/ArgHydrator.d.ts +4 -4
- package/lib/mjs/route-args/ArgHydrator.js +2 -2
- package/lib/mjs/route-args/FromBody.d.ts +10 -10
- package/lib/mjs/route-args/FromBody.js +23 -23
- package/lib/mjs/route-args/FromBody.js.map +1 -1
- package/lib/mjs/route-args/FromCookie.d.ts +13 -13
- package/lib/mjs/route-args/FromCookie.js +46 -46
- package/lib/mjs/route-args/FromCookie.js.map +1 -1
- package/lib/mjs/route-args/FromDi.d.ts +13 -13
- package/lib/mjs/route-args/FromDi.js +32 -32
- package/lib/mjs/route-args/FromDi.js.map +1 -1
- package/lib/mjs/route-args/FromForm.d.ts +66 -92
- package/lib/mjs/route-args/FromForm.d.ts.map +1 -1
- package/lib/mjs/route-args/FromForm.js +210 -284
- package/lib/mjs/route-args/FromForm.js.map +1 -1
- package/lib/mjs/route-args/FromHeaderArg.d.ts +10 -10
- package/lib/mjs/route-args/FromHeaderArg.js +22 -22
- package/lib/mjs/route-args/FromHeaderArg.js.map +1 -1
- package/lib/mjs/route-args/FromParams.d.ts +10 -10
- package/lib/mjs/route-args/FromParams.js +24 -24
- package/lib/mjs/route-args/FromParams.js.map +1 -1
- package/lib/mjs/route-args/FromQuery.d.ts +10 -10
- package/lib/mjs/route-args/FromQuery.js +24 -24
- package/lib/mjs/route-args/FromQuery.js.map +1 -1
- package/lib/mjs/route-args/RequestFields.d.ts +40 -40
- package/lib/mjs/route-args/RequestFields.js +107 -107
- package/lib/mjs/route-args/RequestFields.js.map +1 -1
- package/lib/mjs/route-args/RouteArgs.d.ts +22 -22
- package/lib/mjs/route-args/RouteArgs.js +107 -107
- package/lib/mjs/route-args/RouteArgs.js.map +1 -1
- package/lib/mjs/route-args/index.d.ts +12 -12
- package/lib/mjs/route-args/index.js +12 -12
- package/lib/mjs/schemas/RouteArgsSchemas.d.ts +36 -36
- package/lib/mjs/schemas/RouteArgsSchemas.js +23 -23
- package/lib/mjs/server.d.ts +50 -50
- package/lib/mjs/server.js +266 -266
- package/lib/mjs/server.js.map +1 -1
- package/lib/mjs/transformers/PureTransformer.d.ts +9 -9
- package/lib/mjs/transformers/PureTransformer.js +24 -24
- package/lib/mjs/transformers/PureTransformer.js.map +1 -1
- package/lib/mjs/transformers/index.d.ts +1 -1
- package/lib/mjs/transformers/index.js +1 -1
- package/lib/mjs/uploaders/ImmediateFileUploader.d.ts +19 -0
- package/lib/mjs/uploaders/ImmediateFileUploader.d.ts.map +1 -0
- package/lib/mjs/uploaders/ImmediateFileUploader.js +66 -0
- package/lib/mjs/uploaders/ImmediateFileUploader.js.map +1 -0
- package/lib/tsconfig.cjs.tsbuildinfo +1 -1
- package/lib/tsconfig.mjs.tsbuildinfo +1 -1
- package/package.json +17 -17
package/lib/cjs/decorators.js
CHANGED
|
@@ -1,442 +1,442 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Post = exports.Get = exports.Put = exports.Del = exports.Patch = exports.Head = exports.Cookie = exports.Model = exports.Res = exports.Req = exports.Uuid = exports.PKey = exports.FormField = exports.Form = exports.JsonFile = exports.CsvFile = exports.File = exports.Header = exports.Param = exports.Body = exports.Query = exports.ParamField = exports.QueryField = exports.HeadersField = exports.AcceptType = exports.BodyField = exports.FromDI = exports.BasePath = exports.Middleware = exports.Policy = exports.Hydrator = exports.Parameter = exports.Type = exports.Route = exports.CONTROLLED_DESCRIPTOR_SYMBOL = void 0;
|
|
4
|
-
const interfaces_js_1 = require("./interfaces.js");
|
|
5
|
-
const RouteArgsSchemas_js_1 = require("./schemas/RouteArgsSchemas.js");
|
|
6
|
-
exports.CONTROLLED_DESCRIPTOR_SYMBOL = Symbol('CONTROLLER_SYMBOL');
|
|
7
|
-
function Controller(callback) {
|
|
8
|
-
return (target, propertyKey, indexOrDescriptor) => {
|
|
9
|
-
let metadata = Reflect.getMetadata(exports.CONTROLLED_DESCRIPTOR_SYMBOL, target.prototype || target);
|
|
10
|
-
if (!metadata) {
|
|
11
|
-
metadata = {
|
|
12
|
-
BasePath: null,
|
|
13
|
-
Middlewares: [],
|
|
14
|
-
Policies: [],
|
|
15
|
-
Routes: new Map(),
|
|
16
|
-
};
|
|
17
|
-
Reflect.defineMetadata(exports.CONTROLLED_DESCRIPTOR_SYMBOL, metadata, target.prototype || target);
|
|
18
|
-
}
|
|
19
|
-
if (callback) {
|
|
20
|
-
callback(metadata, target, propertyKey, indexOrDescriptor);
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
function Route(callback) {
|
|
25
|
-
return Controller((metadata, target, propertyKey, indexOrDescriptor) => {
|
|
26
|
-
let route = null;
|
|
27
|
-
if (propertyKey) {
|
|
28
|
-
if (metadata.Routes.has(propertyKey)) {
|
|
29
|
-
route = metadata.Routes.get(propertyKey);
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
route = {
|
|
33
|
-
InternalType: interfaces_js_1.RouteType.UNKNOWN,
|
|
34
|
-
Method: propertyKey,
|
|
35
|
-
Middlewares: [],
|
|
36
|
-
Parameters: new Map(),
|
|
37
|
-
Path: '',
|
|
38
|
-
Policies: [],
|
|
39
|
-
Type: interfaces_js_1.RouteType.UNKNOWN,
|
|
40
|
-
Options: null,
|
|
41
|
-
Schema: null,
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
metadata.Routes.set(propertyKey, route);
|
|
45
|
-
}
|
|
46
|
-
if (callback) {
|
|
47
|
-
callback(metadata, route, target, propertyKey, indexOrDescriptor);
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
exports.Route = Route;
|
|
52
|
-
/**
|
|
53
|
-
* Ugly hack to specify type for route args. Mostly used to define type of array, becouse typescript does not
|
|
54
|
-
* have information about this.
|
|
55
|
-
*/
|
|
56
|
-
function Type(type) {
|
|
57
|
-
return Route((_, route, _target, _propertyKey, index) => {
|
|
58
|
-
if (route.Parameters.has(index)) {
|
|
59
|
-
route.Parameters.get(index).RuntimeType = type;
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
const param = {
|
|
63
|
-
Index: index,
|
|
64
|
-
Name: '',
|
|
65
|
-
RuntimeType: type,
|
|
66
|
-
RouteParamSchema: '',
|
|
67
|
-
Options: null,
|
|
68
|
-
Type: null,
|
|
69
|
-
};
|
|
70
|
-
route.Parameters.set(index, param);
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
exports.Type = Type;
|
|
75
|
-
function Parameter(type, schema, options) {
|
|
76
|
-
return (_, route, target, propertyKey, index) => {
|
|
77
|
-
const rType = Reflect.getMetadata('design:paramtypes', target.prototype || target, propertyKey)[index];
|
|
78
|
-
let tSchema = null;
|
|
79
|
-
switch (rType.name) {
|
|
80
|
-
case 'Number':
|
|
81
|
-
tSchema = RouteArgsSchemas_js_1.ROUTE_ARG_SCHEMA.Number;
|
|
82
|
-
break;
|
|
83
|
-
case 'String':
|
|
84
|
-
tSchema = RouteArgsSchemas_js_1.ROUTE_ARG_SCHEMA.String;
|
|
85
|
-
break;
|
|
86
|
-
case 'Boolean':
|
|
87
|
-
tSchema = RouteArgsSchemas_js_1.ROUTE_ARG_SCHEMA.Boolean;
|
|
88
|
-
}
|
|
89
|
-
if (route.Parameters.has(index)) {
|
|
90
|
-
const p = route.Parameters.get(index);
|
|
91
|
-
p.Type = type;
|
|
92
|
-
p.Options = options;
|
|
93
|
-
p.RouteParamSchema = tSchema;
|
|
94
|
-
p.Schema = schema;
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
const param = {
|
|
98
|
-
Index: index,
|
|
99
|
-
Name: '',
|
|
100
|
-
RuntimeType: rType,
|
|
101
|
-
RouteParamSchema: tSchema,
|
|
102
|
-
Schema: schema,
|
|
103
|
-
Options: options,
|
|
104
|
-
Type: type,
|
|
105
|
-
};
|
|
106
|
-
route.Parameters.set(index, param);
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
exports.Parameter = Parameter;
|
|
111
|
-
/**
|
|
112
|
-
* Tells controller how to fill up incoming parameters in controller actions
|
|
113
|
-
*
|
|
114
|
-
* @param hydrator - hydrator class that will fill up incoming argument
|
|
115
|
-
* @param options - additional options passed to hydrator
|
|
116
|
-
*/
|
|
117
|
-
function Hydrator(hydrator, ...options) {
|
|
118
|
-
return (target) => {
|
|
119
|
-
if (!Reflect.getMetadata('custom:arg_hydrator', target)) {
|
|
120
|
-
Reflect.defineMetadata('custom:arg_hydrator', {
|
|
121
|
-
hydrator,
|
|
122
|
-
options,
|
|
123
|
-
}, target);
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
exports.Hydrator = Hydrator;
|
|
128
|
-
/**
|
|
129
|
-
*
|
|
130
|
-
* @param policy - policy to set. Could be type or path in configuration to with policy to inject ( eg. metrics.auth.policy )
|
|
131
|
-
* @param options
|
|
132
|
-
* @returns
|
|
133
|
-
*/
|
|
134
|
-
function Policy(policy, ...options) {
|
|
135
|
-
return Route((controller, route, _, _1, _2) => {
|
|
136
|
-
const pDesc = {
|
|
137
|
-
Options: options,
|
|
138
|
-
Type: policy,
|
|
139
|
-
};
|
|
140
|
-
if (route) {
|
|
141
|
-
route.Policies.push(pDesc);
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
controller.Policies.push(pDesc);
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
exports.Policy = Policy;
|
|
149
|
-
function Middleware(policy, ...options) {
|
|
150
|
-
return Route((controller, route, _, _1, _2) => {
|
|
151
|
-
const pDesc = {
|
|
152
|
-
Options: options,
|
|
153
|
-
Type: policy,
|
|
154
|
-
};
|
|
155
|
-
if (route) {
|
|
156
|
-
route.Middlewares.push(pDesc);
|
|
157
|
-
}
|
|
158
|
-
else {
|
|
159
|
-
controller.Middlewares.push(pDesc);
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
exports.Middleware = Middleware;
|
|
164
|
-
function BasePath(path) {
|
|
165
|
-
return Controller((metadata) => {
|
|
166
|
-
metadata.BasePath = path;
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
exports.BasePath = BasePath;
|
|
170
|
-
function FromDI() {
|
|
171
|
-
return Route(Parameter(interfaces_js_1.ParameterType.FromDi));
|
|
172
|
-
}
|
|
173
|
-
exports.FromDI = FromDI;
|
|
174
|
-
/**
|
|
175
|
-
* Gets whole body field
|
|
176
|
-
* @returns body field of request
|
|
177
|
-
*/
|
|
178
|
-
function BodyField() {
|
|
179
|
-
return Route(Parameter(interfaces_js_1.ParameterType.BodyField));
|
|
180
|
-
}
|
|
181
|
-
exports.BodyField = BodyField;
|
|
182
|
-
function AcceptType() {
|
|
183
|
-
return Route(Parameter(interfaces_js_1.ParameterType.RequestType));
|
|
184
|
-
}
|
|
185
|
-
exports.AcceptType = AcceptType;
|
|
186
|
-
/**
|
|
187
|
-
* Gets all headers field ot type express.IncommingHttpHeaders
|
|
188
|
-
* @returns headers field of request
|
|
189
|
-
*/
|
|
190
|
-
function HeadersField() {
|
|
191
|
-
return Route(Parameter(interfaces_js_1.ParameterType.Headers));
|
|
192
|
-
}
|
|
193
|
-
exports.HeadersField = HeadersField;
|
|
194
|
-
/**
|
|
195
|
-
* Get whole query field from request.
|
|
196
|
-
*
|
|
197
|
-
* @returns whole request field of request
|
|
198
|
-
*/
|
|
199
|
-
function QueryField() {
|
|
200
|
-
return Route(Parameter(interfaces_js_1.ParameterType.QueryField));
|
|
201
|
-
}
|
|
202
|
-
exports.QueryField = QueryField;
|
|
203
|
-
/**
|
|
204
|
-
* Get whole params field from request.
|
|
205
|
-
* @returns whole request field of request
|
|
206
|
-
*/
|
|
207
|
-
function ParamField() {
|
|
208
|
-
return Route(Parameter(interfaces_js_1.ParameterType.ParamField));
|
|
209
|
-
}
|
|
210
|
-
exports.ParamField = ParamField;
|
|
211
|
-
/**
|
|
212
|
-
* Route parameter taken from query string eg. route?id=1
|
|
213
|
-
*
|
|
214
|
-
* @param schema - parameter json schema for optional validation
|
|
215
|
-
*/
|
|
216
|
-
function Query(schema) {
|
|
217
|
-
return Route(Parameter(interfaces_js_1.ParameterType.FromQuery, schema));
|
|
218
|
-
}
|
|
219
|
-
exports.Query = Query;
|
|
220
|
-
/**
|
|
221
|
-
* Route parameter taken from message body (POST)
|
|
222
|
-
*
|
|
223
|
-
* @param schema - parameter json schema for optional validation
|
|
224
|
-
*/
|
|
225
|
-
function Body() {
|
|
226
|
-
return Route(Parameter(interfaces_js_1.ParameterType.FromBody, null));
|
|
227
|
-
}
|
|
228
|
-
exports.Body = Body;
|
|
229
|
-
/**
|
|
230
|
-
* Route parameter taken from url parameters eg. route/:id
|
|
231
|
-
*
|
|
232
|
-
* @param schema - parameter json schema for optional validation
|
|
233
|
-
*/
|
|
234
|
-
function Param(schema) {
|
|
235
|
-
return Route(Parameter(interfaces_js_1.ParameterType.FromParams, schema));
|
|
236
|
-
}
|
|
237
|
-
exports.Param = Param;
|
|
238
|
-
/**
|
|
239
|
-
* Gets parameter from request header. If not keyname is provided
|
|
240
|
-
* variable name is used as header key name
|
|
241
|
-
*
|
|
242
|
-
* @param keyName - header key name ( optional )
|
|
243
|
-
* @param schema - schema for validation ( optional )
|
|
244
|
-
* @returns
|
|
245
|
-
*/
|
|
246
|
-
function Header(keyName, schema) {
|
|
247
|
-
return Route(Parameter(interfaces_js_1.ParameterType.FromHeader, schema, { key: keyName }));
|
|
248
|
-
}
|
|
249
|
-
exports.Header = Header;
|
|
250
|
-
/**
|
|
251
|
-
*
|
|
252
|
-
* Parameter as file
|
|
253
|
-
*
|
|
254
|
-
* @param options - upload options
|
|
255
|
-
*/
|
|
256
|
-
function File(options) {
|
|
257
|
-
return Route(Parameter(interfaces_js_1.ParameterType.FromFile, null, options));
|
|
258
|
-
}
|
|
259
|
-
exports.File = File;
|
|
260
|
-
/**
|
|
261
|
-
* Data taken from cvs file that is uploaded. Actions receives parsed data
|
|
262
|
-
*
|
|
263
|
-
* @param options - upload options
|
|
264
|
-
* @param cvsParseOptions - cvs parser options
|
|
265
|
-
* @param schema - optional schema for data validation
|
|
266
|
-
*/
|
|
267
|
-
function CsvFile(options, cvsParseOptions) {
|
|
268
|
-
return Route(Parameter(interfaces_js_1.ParameterType.FromCSV, null, {
|
|
269
|
-
uploadOptions: options,
|
|
270
|
-
cvsOptions: cvsParseOptions,
|
|
271
|
-
}));
|
|
272
|
-
}
|
|
273
|
-
exports.CsvFile = CsvFile;
|
|
274
|
-
/**
|
|
275
|
-
* Data taken from cvs file that is uploaded. Actions receives parsed data
|
|
276
|
-
*
|
|
277
|
-
* @param options - upload options
|
|
278
|
-
* @param schema - optional schema for data validation
|
|
279
|
-
*/
|
|
280
|
-
function JsonFile(options) {
|
|
281
|
-
return Route(Parameter(interfaces_js_1.ParameterType.FromJSONFile, null, options));
|
|
282
|
-
}
|
|
283
|
-
exports.JsonFile = JsonFile;
|
|
284
|
-
/**
|
|
285
|
-
*
|
|
286
|
-
* Parameter taken from form data (multipart-form)
|
|
287
|
-
*
|
|
288
|
-
* @param options - upload options
|
|
289
|
-
*/
|
|
290
|
-
function Form(options) {
|
|
291
|
-
return Route(Parameter(interfaces_js_1.ParameterType.FromForm, options));
|
|
292
|
-
}
|
|
293
|
-
exports.Form = Form;
|
|
294
|
-
/**
|
|
295
|
-
*
|
|
296
|
-
* Parameter taken from form data (multipart-form)
|
|
297
|
-
*
|
|
298
|
-
* @param options - upload options
|
|
299
|
-
*/
|
|
300
|
-
function FormField(schema, options) {
|
|
301
|
-
return Route(Parameter(interfaces_js_1.ParameterType.FormField, schema, options));
|
|
302
|
-
}
|
|
303
|
-
exports.FormField = FormField;
|
|
304
|
-
/**
|
|
305
|
-
*
|
|
306
|
-
* Shortcut for parameter as autoincrement primary key ( number greater than 0)
|
|
307
|
-
*
|
|
308
|
-
*/
|
|
309
|
-
function PKey(type) {
|
|
310
|
-
return Route(Parameter(type ? type : interfaces_js_1.ParameterType.FromParams, { type: 'number', minimum: 0 }));
|
|
311
|
-
}
|
|
312
|
-
exports.PKey = PKey;
|
|
313
|
-
/**
|
|
314
|
-
*
|
|
315
|
-
* Shortcut for parameter as uuid primary key ( string with 32 length )
|
|
316
|
-
*
|
|
317
|
-
*/
|
|
318
|
-
function Uuid(type, version) {
|
|
319
|
-
return Route(Parameter(type ? type : interfaces_js_1.ParameterType.FromParams, { type: 'string', minLength: 36, maxLength: 36, pattern: '^[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}$' }, {
|
|
320
|
-
version: version ?? interfaces_js_1.UuidVersion.v4,
|
|
321
|
-
}));
|
|
322
|
-
}
|
|
323
|
-
exports.Uuid = Uuid;
|
|
324
|
-
/**
|
|
325
|
-
*
|
|
326
|
-
* Express request
|
|
327
|
-
*
|
|
328
|
-
*/
|
|
329
|
-
function Req() {
|
|
330
|
-
return Route(Parameter(interfaces_js_1.ParameterType.Req, null));
|
|
331
|
-
}
|
|
332
|
-
exports.Req = Req;
|
|
333
|
-
/**
|
|
334
|
-
*
|
|
335
|
-
* Express res
|
|
336
|
-
*
|
|
337
|
-
*/
|
|
338
|
-
function Res() {
|
|
339
|
-
return Route(Parameter(interfaces_js_1.ParameterType.Res, null));
|
|
340
|
-
}
|
|
341
|
-
exports.Res = Res;
|
|
342
|
-
/**
|
|
343
|
-
*
|
|
344
|
-
* Parameter taken from model
|
|
345
|
-
*
|
|
346
|
-
* @param options - upload options
|
|
347
|
-
*/
|
|
348
|
-
function Model(model) {
|
|
349
|
-
return Route(Parameter(interfaces_js_1.ParameterType.FromModel, null, { type: model }));
|
|
350
|
-
}
|
|
351
|
-
exports.Model = Model;
|
|
352
|
-
/**
|
|
353
|
-
*
|
|
354
|
-
* Parameter taken from coockie
|
|
355
|
-
*
|
|
356
|
-
* @param options - upload options
|
|
357
|
-
*/
|
|
358
|
-
function Cookie() {
|
|
359
|
-
return Route(Parameter(interfaces_js_1.ParameterType.FromCookie, { type: 'string' }));
|
|
360
|
-
}
|
|
361
|
-
exports.Cookie = Cookie;
|
|
362
|
-
/**
|
|
363
|
-
* Creates HEAD http request method
|
|
364
|
-
* @param path - url path to method eg. /foo/bar/:id
|
|
365
|
-
*/
|
|
366
|
-
function Head(path, schema) {
|
|
367
|
-
return Route((_, route) => {
|
|
368
|
-
route.Type = interfaces_js_1.RouteType.HEAD;
|
|
369
|
-
route.InternalType = interfaces_js_1.RouteType.HEAD;
|
|
370
|
-
route.Path = path;
|
|
371
|
-
route.Schema = schema;
|
|
372
|
-
});
|
|
373
|
-
}
|
|
374
|
-
exports.Head = Head;
|
|
375
|
-
/**
|
|
376
|
-
* Creates PATCH http request method
|
|
377
|
-
* @param path - url path to method eg. /foo/bar/:id
|
|
378
|
-
*/
|
|
379
|
-
function Patch(path, schema) {
|
|
380
|
-
return Route((_, route) => {
|
|
381
|
-
route.Type = interfaces_js_1.RouteType.PATCH;
|
|
382
|
-
route.InternalType = interfaces_js_1.RouteType.PATCH;
|
|
383
|
-
route.Path = path;
|
|
384
|
-
route.Schema = schema;
|
|
385
|
-
});
|
|
386
|
-
}
|
|
387
|
-
exports.Patch = Patch;
|
|
388
|
-
/**
|
|
389
|
-
* Creates DELETE http request method
|
|
390
|
-
* @param path - url path to method eg. /foo/bar/:id
|
|
391
|
-
* @param routeName - route name visible in api. If undefined, method name is taken
|
|
392
|
-
*/
|
|
393
|
-
function Del(path, schema) {
|
|
394
|
-
return Route((_, route) => {
|
|
395
|
-
route.Type = interfaces_js_1.RouteType.DELETE;
|
|
396
|
-
route.InternalType = interfaces_js_1.RouteType.DELETE;
|
|
397
|
-
route.Path = path;
|
|
398
|
-
route.Schema = schema;
|
|
399
|
-
});
|
|
400
|
-
}
|
|
401
|
-
exports.Del = Del;
|
|
402
|
-
/**
|
|
403
|
-
* Creates PUT http request method
|
|
404
|
-
* @param path - url path to method eg. /foo/bar/:id
|
|
405
|
-
*/
|
|
406
|
-
function Put(path, schema) {
|
|
407
|
-
return Route((_, route) => {
|
|
408
|
-
route.Type = interfaces_js_1.RouteType.PUT;
|
|
409
|
-
route.InternalType = interfaces_js_1.RouteType.PUT;
|
|
410
|
-
route.Path = path;
|
|
411
|
-
route.Schema = schema;
|
|
412
|
-
});
|
|
413
|
-
}
|
|
414
|
-
exports.Put = Put;
|
|
415
|
-
/**
|
|
416
|
-
* Creates GET http request method
|
|
417
|
-
* @param path - url path to method eg. /foo/bar/:id
|
|
418
|
-
*/
|
|
419
|
-
function Get(path, schema) {
|
|
420
|
-
return Route((_, route) => {
|
|
421
|
-
route.Type = interfaces_js_1.RouteType.GET;
|
|
422
|
-
route.InternalType = interfaces_js_1.RouteType.GET;
|
|
423
|
-
route.Path = path;
|
|
424
|
-
route.Schema = schema;
|
|
425
|
-
});
|
|
426
|
-
}
|
|
427
|
-
exports.Get = Get;
|
|
428
|
-
/**
|
|
429
|
-
* Creates POST http request method
|
|
430
|
-
*
|
|
431
|
-
* @param path - url path to method eg. /foo/bar
|
|
432
|
-
*/
|
|
433
|
-
function Post(path, schema) {
|
|
434
|
-
return Route((_, route) => {
|
|
435
|
-
route.Type = interfaces_js_1.RouteType.POST;
|
|
436
|
-
route.InternalType = interfaces_js_1.RouteType.POST;
|
|
437
|
-
route.Path = path;
|
|
438
|
-
route.Schema = schema;
|
|
439
|
-
});
|
|
440
|
-
}
|
|
441
|
-
exports.Post = Post;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Post = exports.Get = exports.Put = exports.Del = exports.Patch = exports.Head = exports.Cookie = exports.Model = exports.Res = exports.Req = exports.Uuid = exports.PKey = exports.FormField = exports.Form = exports.JsonFile = exports.CsvFile = exports.File = exports.Header = exports.Param = exports.Body = exports.Query = exports.ParamField = exports.QueryField = exports.HeadersField = exports.AcceptType = exports.BodyField = exports.FromDI = exports.BasePath = exports.Middleware = exports.Policy = exports.Hydrator = exports.Parameter = exports.Type = exports.Route = exports.CONTROLLED_DESCRIPTOR_SYMBOL = void 0;
|
|
4
|
+
const interfaces_js_1 = require("./interfaces.js");
|
|
5
|
+
const RouteArgsSchemas_js_1 = require("./schemas/RouteArgsSchemas.js");
|
|
6
|
+
exports.CONTROLLED_DESCRIPTOR_SYMBOL = Symbol('CONTROLLER_SYMBOL');
|
|
7
|
+
function Controller(callback) {
|
|
8
|
+
return (target, propertyKey, indexOrDescriptor) => {
|
|
9
|
+
let metadata = Reflect.getMetadata(exports.CONTROLLED_DESCRIPTOR_SYMBOL, target.prototype || target);
|
|
10
|
+
if (!metadata) {
|
|
11
|
+
metadata = {
|
|
12
|
+
BasePath: null,
|
|
13
|
+
Middlewares: [],
|
|
14
|
+
Policies: [],
|
|
15
|
+
Routes: new Map(),
|
|
16
|
+
};
|
|
17
|
+
Reflect.defineMetadata(exports.CONTROLLED_DESCRIPTOR_SYMBOL, metadata, target.prototype || target);
|
|
18
|
+
}
|
|
19
|
+
if (callback) {
|
|
20
|
+
callback(metadata, target, propertyKey, indexOrDescriptor);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function Route(callback) {
|
|
25
|
+
return Controller((metadata, target, propertyKey, indexOrDescriptor) => {
|
|
26
|
+
let route = null;
|
|
27
|
+
if (propertyKey) {
|
|
28
|
+
if (metadata.Routes.has(propertyKey)) {
|
|
29
|
+
route = metadata.Routes.get(propertyKey);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
route = {
|
|
33
|
+
InternalType: interfaces_js_1.RouteType.UNKNOWN,
|
|
34
|
+
Method: propertyKey,
|
|
35
|
+
Middlewares: [],
|
|
36
|
+
Parameters: new Map(),
|
|
37
|
+
Path: '',
|
|
38
|
+
Policies: [],
|
|
39
|
+
Type: interfaces_js_1.RouteType.UNKNOWN,
|
|
40
|
+
Options: null,
|
|
41
|
+
Schema: null,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
metadata.Routes.set(propertyKey, route);
|
|
45
|
+
}
|
|
46
|
+
if (callback) {
|
|
47
|
+
callback(metadata, route, target, propertyKey, indexOrDescriptor);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
exports.Route = Route;
|
|
52
|
+
/**
|
|
53
|
+
* Ugly hack to specify type for route args. Mostly used to define type of array, becouse typescript does not
|
|
54
|
+
* have information about this.
|
|
55
|
+
*/
|
|
56
|
+
function Type(type) {
|
|
57
|
+
return Route((_, route, _target, _propertyKey, index) => {
|
|
58
|
+
if (route.Parameters.has(index)) {
|
|
59
|
+
route.Parameters.get(index).RuntimeType = type;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
const param = {
|
|
63
|
+
Index: index,
|
|
64
|
+
Name: '',
|
|
65
|
+
RuntimeType: type,
|
|
66
|
+
RouteParamSchema: '',
|
|
67
|
+
Options: null,
|
|
68
|
+
Type: null,
|
|
69
|
+
};
|
|
70
|
+
route.Parameters.set(index, param);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
exports.Type = Type;
|
|
75
|
+
function Parameter(type, schema, options) {
|
|
76
|
+
return (_, route, target, propertyKey, index) => {
|
|
77
|
+
const rType = Reflect.getMetadata('design:paramtypes', target.prototype || target, propertyKey)[index];
|
|
78
|
+
let tSchema = null;
|
|
79
|
+
switch (rType.name) {
|
|
80
|
+
case 'Number':
|
|
81
|
+
tSchema = RouteArgsSchemas_js_1.ROUTE_ARG_SCHEMA.Number;
|
|
82
|
+
break;
|
|
83
|
+
case 'String':
|
|
84
|
+
tSchema = RouteArgsSchemas_js_1.ROUTE_ARG_SCHEMA.String;
|
|
85
|
+
break;
|
|
86
|
+
case 'Boolean':
|
|
87
|
+
tSchema = RouteArgsSchemas_js_1.ROUTE_ARG_SCHEMA.Boolean;
|
|
88
|
+
}
|
|
89
|
+
if (route.Parameters.has(index)) {
|
|
90
|
+
const p = route.Parameters.get(index);
|
|
91
|
+
p.Type = type;
|
|
92
|
+
p.Options = options;
|
|
93
|
+
p.RouteParamSchema = tSchema;
|
|
94
|
+
p.Schema = schema;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
const param = {
|
|
98
|
+
Index: index,
|
|
99
|
+
Name: '',
|
|
100
|
+
RuntimeType: rType,
|
|
101
|
+
RouteParamSchema: tSchema,
|
|
102
|
+
Schema: schema,
|
|
103
|
+
Options: options,
|
|
104
|
+
Type: type,
|
|
105
|
+
};
|
|
106
|
+
route.Parameters.set(index, param);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
exports.Parameter = Parameter;
|
|
111
|
+
/**
|
|
112
|
+
* Tells controller how to fill up incoming parameters in controller actions
|
|
113
|
+
*
|
|
114
|
+
* @param hydrator - hydrator class that will fill up incoming argument
|
|
115
|
+
* @param options - additional options passed to hydrator
|
|
116
|
+
*/
|
|
117
|
+
function Hydrator(hydrator, ...options) {
|
|
118
|
+
return (target) => {
|
|
119
|
+
if (!Reflect.getMetadata('custom:arg_hydrator', target)) {
|
|
120
|
+
Reflect.defineMetadata('custom:arg_hydrator', {
|
|
121
|
+
hydrator,
|
|
122
|
+
options,
|
|
123
|
+
}, target);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
exports.Hydrator = Hydrator;
|
|
128
|
+
/**
|
|
129
|
+
*
|
|
130
|
+
* @param policy - policy to set. Could be type or path in configuration to with policy to inject ( eg. metrics.auth.policy )
|
|
131
|
+
* @param options
|
|
132
|
+
* @returns
|
|
133
|
+
*/
|
|
134
|
+
function Policy(policy, ...options) {
|
|
135
|
+
return Route((controller, route, _, _1, _2) => {
|
|
136
|
+
const pDesc = {
|
|
137
|
+
Options: options,
|
|
138
|
+
Type: policy,
|
|
139
|
+
};
|
|
140
|
+
if (route) {
|
|
141
|
+
route.Policies.push(pDesc);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
controller.Policies.push(pDesc);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
exports.Policy = Policy;
|
|
149
|
+
function Middleware(policy, ...options) {
|
|
150
|
+
return Route((controller, route, _, _1, _2) => {
|
|
151
|
+
const pDesc = {
|
|
152
|
+
Options: options,
|
|
153
|
+
Type: policy,
|
|
154
|
+
};
|
|
155
|
+
if (route) {
|
|
156
|
+
route.Middlewares.push(pDesc);
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
controller.Middlewares.push(pDesc);
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
exports.Middleware = Middleware;
|
|
164
|
+
function BasePath(path) {
|
|
165
|
+
return Controller((metadata) => {
|
|
166
|
+
metadata.BasePath = path;
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
exports.BasePath = BasePath;
|
|
170
|
+
function FromDI() {
|
|
171
|
+
return Route(Parameter(interfaces_js_1.ParameterType.FromDi));
|
|
172
|
+
}
|
|
173
|
+
exports.FromDI = FromDI;
|
|
174
|
+
/**
|
|
175
|
+
* Gets whole body field
|
|
176
|
+
* @returns body field of request
|
|
177
|
+
*/
|
|
178
|
+
function BodyField() {
|
|
179
|
+
return Route(Parameter(interfaces_js_1.ParameterType.BodyField));
|
|
180
|
+
}
|
|
181
|
+
exports.BodyField = BodyField;
|
|
182
|
+
function AcceptType() {
|
|
183
|
+
return Route(Parameter(interfaces_js_1.ParameterType.RequestType));
|
|
184
|
+
}
|
|
185
|
+
exports.AcceptType = AcceptType;
|
|
186
|
+
/**
|
|
187
|
+
* Gets all headers field ot type express.IncommingHttpHeaders
|
|
188
|
+
* @returns headers field of request
|
|
189
|
+
*/
|
|
190
|
+
function HeadersField() {
|
|
191
|
+
return Route(Parameter(interfaces_js_1.ParameterType.Headers));
|
|
192
|
+
}
|
|
193
|
+
exports.HeadersField = HeadersField;
|
|
194
|
+
/**
|
|
195
|
+
* Get whole query field from request.
|
|
196
|
+
*
|
|
197
|
+
* @returns whole request field of request
|
|
198
|
+
*/
|
|
199
|
+
function QueryField() {
|
|
200
|
+
return Route(Parameter(interfaces_js_1.ParameterType.QueryField));
|
|
201
|
+
}
|
|
202
|
+
exports.QueryField = QueryField;
|
|
203
|
+
/**
|
|
204
|
+
* Get whole params field from request.
|
|
205
|
+
* @returns whole request field of request
|
|
206
|
+
*/
|
|
207
|
+
function ParamField() {
|
|
208
|
+
return Route(Parameter(interfaces_js_1.ParameterType.ParamField));
|
|
209
|
+
}
|
|
210
|
+
exports.ParamField = ParamField;
|
|
211
|
+
/**
|
|
212
|
+
* Route parameter taken from query string eg. route?id=1
|
|
213
|
+
*
|
|
214
|
+
* @param schema - parameter json schema for optional validation
|
|
215
|
+
*/
|
|
216
|
+
function Query(schema) {
|
|
217
|
+
return Route(Parameter(interfaces_js_1.ParameterType.FromQuery, schema));
|
|
218
|
+
}
|
|
219
|
+
exports.Query = Query;
|
|
220
|
+
/**
|
|
221
|
+
* Route parameter taken from message body (POST)
|
|
222
|
+
*
|
|
223
|
+
* @param schema - parameter json schema for optional validation
|
|
224
|
+
*/
|
|
225
|
+
function Body() {
|
|
226
|
+
return Route(Parameter(interfaces_js_1.ParameterType.FromBody, null));
|
|
227
|
+
}
|
|
228
|
+
exports.Body = Body;
|
|
229
|
+
/**
|
|
230
|
+
* Route parameter taken from url parameters eg. route/:id
|
|
231
|
+
*
|
|
232
|
+
* @param schema - parameter json schema for optional validation
|
|
233
|
+
*/
|
|
234
|
+
function Param(schema) {
|
|
235
|
+
return Route(Parameter(interfaces_js_1.ParameterType.FromParams, schema));
|
|
236
|
+
}
|
|
237
|
+
exports.Param = Param;
|
|
238
|
+
/**
|
|
239
|
+
* Gets parameter from request header. If not keyname is provided
|
|
240
|
+
* variable name is used as header key name
|
|
241
|
+
*
|
|
242
|
+
* @param keyName - header key name ( optional )
|
|
243
|
+
* @param schema - schema for validation ( optional )
|
|
244
|
+
* @returns
|
|
245
|
+
*/
|
|
246
|
+
function Header(keyName, schema) {
|
|
247
|
+
return Route(Parameter(interfaces_js_1.ParameterType.FromHeader, schema, { key: keyName }));
|
|
248
|
+
}
|
|
249
|
+
exports.Header = Header;
|
|
250
|
+
/**
|
|
251
|
+
*
|
|
252
|
+
* Parameter as file
|
|
253
|
+
*
|
|
254
|
+
* @param options - upload options
|
|
255
|
+
*/
|
|
256
|
+
function File(options) {
|
|
257
|
+
return Route(Parameter(interfaces_js_1.ParameterType.FromFile, null, options));
|
|
258
|
+
}
|
|
259
|
+
exports.File = File;
|
|
260
|
+
/**
|
|
261
|
+
* Data taken from cvs file that is uploaded. Actions receives parsed data
|
|
262
|
+
*
|
|
263
|
+
* @param options - upload options
|
|
264
|
+
* @param cvsParseOptions - cvs parser options
|
|
265
|
+
* @param schema - optional schema for data validation
|
|
266
|
+
*/
|
|
267
|
+
function CsvFile(options, cvsParseOptions) {
|
|
268
|
+
return Route(Parameter(interfaces_js_1.ParameterType.FromCSV, null, {
|
|
269
|
+
uploadOptions: options,
|
|
270
|
+
cvsOptions: cvsParseOptions,
|
|
271
|
+
}));
|
|
272
|
+
}
|
|
273
|
+
exports.CsvFile = CsvFile;
|
|
274
|
+
/**
|
|
275
|
+
* Data taken from cvs file that is uploaded. Actions receives parsed data
|
|
276
|
+
*
|
|
277
|
+
* @param options - upload options
|
|
278
|
+
* @param schema - optional schema for data validation
|
|
279
|
+
*/
|
|
280
|
+
function JsonFile(options) {
|
|
281
|
+
return Route(Parameter(interfaces_js_1.ParameterType.FromJSONFile, null, options));
|
|
282
|
+
}
|
|
283
|
+
exports.JsonFile = JsonFile;
|
|
284
|
+
/**
|
|
285
|
+
*
|
|
286
|
+
* Parameter taken from form data (multipart-form)
|
|
287
|
+
*
|
|
288
|
+
* @param options - upload options
|
|
289
|
+
*/
|
|
290
|
+
function Form(options) {
|
|
291
|
+
return Route(Parameter(interfaces_js_1.ParameterType.FromForm, options));
|
|
292
|
+
}
|
|
293
|
+
exports.Form = Form;
|
|
294
|
+
/**
|
|
295
|
+
*
|
|
296
|
+
* Parameter taken from form data (multipart-form)
|
|
297
|
+
*
|
|
298
|
+
* @param options - upload options
|
|
299
|
+
*/
|
|
300
|
+
function FormField(schema, options) {
|
|
301
|
+
return Route(Parameter(interfaces_js_1.ParameterType.FormField, schema, options));
|
|
302
|
+
}
|
|
303
|
+
exports.FormField = FormField;
|
|
304
|
+
/**
|
|
305
|
+
*
|
|
306
|
+
* Shortcut for parameter as autoincrement primary key ( number greater than 0)
|
|
307
|
+
*
|
|
308
|
+
*/
|
|
309
|
+
function PKey(type) {
|
|
310
|
+
return Route(Parameter(type ? type : interfaces_js_1.ParameterType.FromParams, { type: 'number', minimum: 0 }));
|
|
311
|
+
}
|
|
312
|
+
exports.PKey = PKey;
|
|
313
|
+
/**
|
|
314
|
+
*
|
|
315
|
+
* Shortcut for parameter as uuid primary key ( string with 32 length )
|
|
316
|
+
*
|
|
317
|
+
*/
|
|
318
|
+
function Uuid(type, version) {
|
|
319
|
+
return Route(Parameter(type ? type : interfaces_js_1.ParameterType.FromParams, { type: 'string', minLength: 36, maxLength: 36, pattern: '^[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}$' }, {
|
|
320
|
+
version: version ?? interfaces_js_1.UuidVersion.v4,
|
|
321
|
+
}));
|
|
322
|
+
}
|
|
323
|
+
exports.Uuid = Uuid;
|
|
324
|
+
/**
|
|
325
|
+
*
|
|
326
|
+
* Express request
|
|
327
|
+
*
|
|
328
|
+
*/
|
|
329
|
+
function Req() {
|
|
330
|
+
return Route(Parameter(interfaces_js_1.ParameterType.Req, null));
|
|
331
|
+
}
|
|
332
|
+
exports.Req = Req;
|
|
333
|
+
/**
|
|
334
|
+
*
|
|
335
|
+
* Express res
|
|
336
|
+
*
|
|
337
|
+
*/
|
|
338
|
+
function Res() {
|
|
339
|
+
return Route(Parameter(interfaces_js_1.ParameterType.Res, null));
|
|
340
|
+
}
|
|
341
|
+
exports.Res = Res;
|
|
342
|
+
/**
|
|
343
|
+
*
|
|
344
|
+
* Parameter taken from model
|
|
345
|
+
*
|
|
346
|
+
* @param options - upload options
|
|
347
|
+
*/
|
|
348
|
+
function Model(model) {
|
|
349
|
+
return Route(Parameter(interfaces_js_1.ParameterType.FromModel, null, { type: model }));
|
|
350
|
+
}
|
|
351
|
+
exports.Model = Model;
|
|
352
|
+
/**
|
|
353
|
+
*
|
|
354
|
+
* Parameter taken from coockie
|
|
355
|
+
*
|
|
356
|
+
* @param options - upload options
|
|
357
|
+
*/
|
|
358
|
+
function Cookie() {
|
|
359
|
+
return Route(Parameter(interfaces_js_1.ParameterType.FromCookie, { type: 'string' }));
|
|
360
|
+
}
|
|
361
|
+
exports.Cookie = Cookie;
|
|
362
|
+
/**
|
|
363
|
+
* Creates HEAD http request method
|
|
364
|
+
* @param path - url path to method eg. /foo/bar/:id
|
|
365
|
+
*/
|
|
366
|
+
function Head(path, schema) {
|
|
367
|
+
return Route((_, route) => {
|
|
368
|
+
route.Type = interfaces_js_1.RouteType.HEAD;
|
|
369
|
+
route.InternalType = interfaces_js_1.RouteType.HEAD;
|
|
370
|
+
route.Path = path;
|
|
371
|
+
route.Schema = schema;
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
exports.Head = Head;
|
|
375
|
+
/**
|
|
376
|
+
* Creates PATCH http request method
|
|
377
|
+
* @param path - url path to method eg. /foo/bar/:id
|
|
378
|
+
*/
|
|
379
|
+
function Patch(path, schema) {
|
|
380
|
+
return Route((_, route) => {
|
|
381
|
+
route.Type = interfaces_js_1.RouteType.PATCH;
|
|
382
|
+
route.InternalType = interfaces_js_1.RouteType.PATCH;
|
|
383
|
+
route.Path = path;
|
|
384
|
+
route.Schema = schema;
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
exports.Patch = Patch;
|
|
388
|
+
/**
|
|
389
|
+
* Creates DELETE http request method
|
|
390
|
+
* @param path - url path to method eg. /foo/bar/:id
|
|
391
|
+
* @param routeName - route name visible in api. If undefined, method name is taken
|
|
392
|
+
*/
|
|
393
|
+
function Del(path, schema) {
|
|
394
|
+
return Route((_, route) => {
|
|
395
|
+
route.Type = interfaces_js_1.RouteType.DELETE;
|
|
396
|
+
route.InternalType = interfaces_js_1.RouteType.DELETE;
|
|
397
|
+
route.Path = path;
|
|
398
|
+
route.Schema = schema;
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
exports.Del = Del;
|
|
402
|
+
/**
|
|
403
|
+
* Creates PUT http request method
|
|
404
|
+
* @param path - url path to method eg. /foo/bar/:id
|
|
405
|
+
*/
|
|
406
|
+
function Put(path, schema) {
|
|
407
|
+
return Route((_, route) => {
|
|
408
|
+
route.Type = interfaces_js_1.RouteType.PUT;
|
|
409
|
+
route.InternalType = interfaces_js_1.RouteType.PUT;
|
|
410
|
+
route.Path = path;
|
|
411
|
+
route.Schema = schema;
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
exports.Put = Put;
|
|
415
|
+
/**
|
|
416
|
+
* Creates GET http request method
|
|
417
|
+
* @param path - url path to method eg. /foo/bar/:id
|
|
418
|
+
*/
|
|
419
|
+
function Get(path, schema) {
|
|
420
|
+
return Route((_, route) => {
|
|
421
|
+
route.Type = interfaces_js_1.RouteType.GET;
|
|
422
|
+
route.InternalType = interfaces_js_1.RouteType.GET;
|
|
423
|
+
route.Path = path;
|
|
424
|
+
route.Schema = schema;
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
exports.Get = Get;
|
|
428
|
+
/**
|
|
429
|
+
* Creates POST http request method
|
|
430
|
+
*
|
|
431
|
+
* @param path - url path to method eg. /foo/bar
|
|
432
|
+
*/
|
|
433
|
+
function Post(path, schema) {
|
|
434
|
+
return Route((_, route) => {
|
|
435
|
+
route.Type = interfaces_js_1.RouteType.POST;
|
|
436
|
+
route.InternalType = interfaces_js_1.RouteType.POST;
|
|
437
|
+
route.Path = path;
|
|
438
|
+
route.Schema = schema;
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
exports.Post = Post;
|
|
442
442
|
//# sourceMappingURL=decorators.js.map
|