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