routing-controllers
Advanced tools
Comparing version 0.6.0-alpha.5 to 0.6.0-alpha.6
@@ -48,2 +48,18 @@ import { ParamOptions } from "./options/ParamOptions"; | ||
/** | ||
* This decorator allows to inject "file" from a request to a given parameter of the controller action. | ||
* | ||
* @param name Parameter name | ||
* @param options Extra parameter options | ||
*/ | ||
export declare function FileParam(name: string, options: ParamOptions): Function; | ||
export declare function FileParam(name: string, required?: boolean, parseJson?: boolean): Function; | ||
/** | ||
* This decorator allows to inject "files" from a request to a given parameter of the controller action. | ||
* | ||
* @param name Parameter name | ||
* @param options Extra parameter options | ||
*/ | ||
export declare function FilesParam(name: string, options: ParamOptions): Function; | ||
export declare function FilesParam(name: string, required?: boolean, parseJson?: boolean): Function; | ||
/** | ||
* This decorator allows to inject a request body's value to the controller action parameter. | ||
@@ -50,0 +66,0 @@ * Applied to class method parameters. |
@@ -139,2 +139,52 @@ "use strict"; | ||
exports.HeaderParam = HeaderParam; | ||
function FileParam(name, requiredOrOptions, parseJson) { | ||
var required = false; | ||
if (typeof requiredOrOptions === "object") { | ||
required = requiredOrOptions.required; | ||
parseJson = requiredOrOptions.parseJson; | ||
} | ||
else { | ||
required = requiredOrOptions; | ||
} | ||
return function (object, methodName, index) { | ||
var format = Reflect.getMetadata("design:paramtypes", object, methodName)[index]; | ||
var metadata = { | ||
target: object.constructor, | ||
method: methodName, | ||
index: index, | ||
type: ParamTypes_1.ParamTypes.FILE, | ||
name: name, | ||
format: format, | ||
parseJson: parseJson, | ||
isRequired: required | ||
}; | ||
index_1.defaultMetadataArgsStorage().params.push(metadata); | ||
}; | ||
} | ||
exports.FileParam = FileParam; | ||
function FilesParam(name, requiredOrOptions, parseJson) { | ||
var required = false; | ||
if (typeof requiredOrOptions === "object") { | ||
required = requiredOrOptions.required; | ||
parseJson = requiredOrOptions.parseJson; | ||
} | ||
else { | ||
required = requiredOrOptions; | ||
} | ||
return function (object, methodName, index) { | ||
var format = Reflect.getMetadata("design:paramtypes", object, methodName)[index]; | ||
var metadata = { | ||
target: object.constructor, | ||
method: methodName, | ||
index: index, | ||
type: ParamTypes_1.ParamTypes.FILES, | ||
name: name, | ||
format: format, | ||
parseJson: parseJson, | ||
isRequired: required | ||
}; | ||
index_1.defaultMetadataArgsStorage().params.push(metadata); | ||
}; | ||
} | ||
exports.FilesParam = FilesParam; | ||
function BodyParam(name, requiredOrOptions, parseJson) { | ||
@@ -141,0 +191,0 @@ var required = false; |
@@ -73,2 +73,6 @@ "use strict"; | ||
return request.headers[param.name]; | ||
case ParamTypes_1.ParamTypes.FILE: | ||
return request.file[param.name]; | ||
case ParamTypes_1.ParamTypes.FILES: | ||
return request.files[param.name]; | ||
case ParamTypes_1.ParamTypes.BODY_PARAM: | ||
@@ -75,0 +79,0 @@ return request.body[param.name]; |
@@ -69,2 +69,6 @@ "use strict"; | ||
return context.query[param.name]; | ||
case ParamTypes_1.ParamTypes.FILE: | ||
return request.file[param.name]; | ||
case ParamTypes_1.ParamTypes.FILES: | ||
return request.files[param.name]; | ||
case ParamTypes_1.ParamTypes.HEADER: | ||
@@ -71,0 +75,0 @@ return context.headers[param.name]; |
/** | ||
* Controller action's parameter type. | ||
*/ | ||
export declare type ParamType = "body" | "query" | "header" | "body_param" | "param" | "cookie" | "request" | "response" | "custom_converter"; | ||
export declare type ParamType = "body" | "query" | "header" | "file" | "files" | "body_param" | "param" | "cookie" | "request" | "response" | "custom_converter"; | ||
/** | ||
@@ -12,2 +12,4 @@ * Controller action's parameter type. | ||
static HEADER: ParamType; | ||
static FILE: ParamType; | ||
static FILES: ParamType; | ||
static BODY_PARAM: ParamType; | ||
@@ -14,0 +16,0 @@ static PARAM: ParamType; |
@@ -11,2 +11,4 @@ "use strict"; | ||
ParamTypes.HEADER = "header"; | ||
ParamTypes.FILE = "file"; | ||
ParamTypes.FILES = "files"; | ||
ParamTypes.BODY_PARAM = "body_param"; | ||
@@ -13,0 +15,0 @@ ParamTypes.PARAM = "param"; |
{ | ||
"name": "routing-controllers", | ||
"private": false, | ||
"version": "0.6.0-alpha.5", | ||
"version": "0.6.0-alpha.6", | ||
"description": "Allows to use class-based controllers with express.js in Typescript", | ||
@@ -6,0 +6,0 @@ "license": "Apache-2.0", |
@@ -283,12 +283,14 @@ # routing-controllers | ||
| Signature | Example | Description | express.js analogue | | ||
|-----------------------------------------------------|--------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------| | ||
| `Req()` | `getAll(@Req() request: Request)` | Injects a Request object to a controller action parameter value | `function (request, response)` | | ||
| `Res()` | `getAll(@Res() response: Response)` | Injects a Reponse object to a controller action parameter value | `function (request, response)` | | ||
| `Body(options: ParamOptions)` | `save(@Body() body: any)` | Injects a body to a controller action parameter value. In options you can specify if body should be parsed into a json object or not. Also you can specify there if body is required and action cannot work without body being specified. | `request.body` | | ||
| `Param(name: string, options?: ParamOptions)` | `get(@Param("id") id: number)` | Injects a parameter to a controller action parameter value. In options you can specify if parameter should be parsed into a json object or not. Also you can specify there if parameter is required and action cannot work with empty parameter. | `request.params.id` | | ||
| `QueryParam(name: string, options?: ParamOptions)` | `get(@QueryParam("id") id: number)` | Injects a query string parameter to a controller action parameter value. In options you can specify if parameter should be parsed into a json object or not. Also you can specify there if query parameter is required and action cannot work with empty parameter. | `request.query.id` | | ||
| `HeaderParam(name: string, options?: ParamOptions)` | `get(@HeaderParam("token") token: string)` | Injects a parameter from response headers to a controller action parameter value. In options you can specify if parameter should be parsed into a json object or not. Also you can specify there if query parameter is required and action cannot work with empty parameter. | `request.headers.token` | | ||
| `BodyParam(name: string, options?: ParamOptions)` | `post(@BodyParam("name") name: string)` | Injects a body parameter to a controller action parameter value. In options you can specify if parameter should be parsed into a json object or not. Also you can specify there if body parameter is required and action cannot work with empty parameter. | `request.body.name` | | ||
| `CookieParam(name: string, options?: ParamOptions)` | `get(@CookieParam("username") username: string)` | Injects a cookie parameter to a controller action parameter value. In options you can specify if parameter should be parsed into a json object or not. Also you can specify there if cookie parameter is required and action cannot work with empty parameter. | `request.cookie("username")` | | ||
| Signature | Example | Description | express.js analogue | | ||
|-----------------------------------------------------|--------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------| | ||
| `Req()` | `getAll(@Req() request: Request)` | Injects a Request object to a controller action parameter value | `function (request, response)` | | ||
| `Res()` | `getAll(@Res() response: Response)` | Injects a Reponse object to a controller action parameter value | `function (request, response)` | | ||
| `Body(options: ParamOptions)` | `save(@Body() body: any)` | Injects a body to a controller action parameter value. In options you can specify if body should be parsed into a json object or not. Also you can specify there if body is required and action cannot work without body being specified. | `request.body` | | ||
| `Param(name: string, options?: ParamOptions)` | `get(@Param("id") id: number)` | Injects a parameter to a controller action parameter value. In options you can specify if parameter should be parsed into a json object or not. Also you can specify there if parameter is required and action cannot work with empty parameter. | `request.params.id` | | ||
| `QueryParam(name: string, options?: ParamOptions)` | `get(@QueryParam("id") id: number)` | Injects a query string parameter to a controller action parameter value. In options you can specify if parameter should be parsed into a json object or not. Also you can specify there if query parameter is required and action cannot work with empty parameter. | `request.query.id` | | ||
| `HeaderParam(name: string, options?: ParamOptions)` | `get(@HeaderParam("token") token: string)` | Injects a parameter from response headers to a controller action parameter value. In options you can specify if parameter should be parsed into a json object or not. Also you can specify there if query parameter is required and action cannot work with empty parameter. | `request.headers.token` | | ||
| `FileParam(name: string, options?: ParamOptions)` | `get(@FileParam("file") file: any)` | Injects a "file" from the response to a controller action parameter value. In parameter options you can specify if this is required parameter or not. parseJson option is ignored | `request.file.file` (when using multer) | | ||
| `FilesParam(name: string, options?: ParamOptions)` | `get(@FilesParam("files") files: any[])` | Injects a "files" from the response to a controller action parameter value. In parameter options you can specify if this is required parameter or not. parseJson option is ignored | `request.files.files` (when using multer) | | ||
| `BodyParam(name: string, options?: ParamOptions)` | `post(@BodyParam("name") name: string)` | Injects a body parameter to a controller action parameter value. In options you can specify if parameter should be parsed into a json object or not. Also you can specify there if body parameter is required and action cannot work with empty parameter. | `request.body.name` | | ||
| `CookieParam(name: string, options?: ParamOptions)` | `get(@CookieParam("username") username: string)` | Injects a cookie parameter to a controller action parameter value. In options you can specify if parameter should be parsed into a json object or not. Also you can specify there if cookie parameter is required and action cannot work with empty parameter. | `request.cookie("username")` | | ||
@@ -295,0 +297,0 @@ ## Samples |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
226153
3586
320