-
Notifications
You must be signed in to change notification settings - Fork 392
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Umed Khudoiberdiev
committed
Apr 24, 2017
1 parent
45e6c7f
commit 906fe8d
Showing
73 changed files
with
562 additions
and
580 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
build/ | ||
node_modules/ | ||
typings/ | ||
coverage/ | ||
npm-debug.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,22 @@ | ||
import {defaultMetadataArgsStorage} from "../index"; | ||
import {ParamMetadataArgs} from "../metadata/args/ParamMetadataArgs"; | ||
import {BodyOptions} from "../decorator-options/BodyOptions"; | ||
import {defaultMetadataArgsStorage} from "../metadata-builder/MetadataArgsStorage"; | ||
|
||
/** | ||
* Allows to inject a request body value to the controller action parameter. | ||
* Must be applied on a controller action parameters. | ||
* Must be applied on a controller action parameter. | ||
*/ | ||
export function Body(options?: BodyOptions): Function { | ||
return function (object: Object, methodName: string, index: number) { | ||
const format = (Reflect as any).getMetadata("design:paramtypes", object, methodName)[index]; | ||
const metadata: ParamMetadataArgs = { | ||
target: object.constructor, | ||
defaultMetadataArgsStorage.params.push({ | ||
type: "body", | ||
object: object, | ||
method: methodName, | ||
index: index, | ||
type: "body", | ||
targetType: format, | ||
parse: false, | ||
required: options ? options.required : false, | ||
classTransform: options ? options.transform : undefined, | ||
validate: options ? options.validate : undefined, | ||
}; | ||
defaultMetadataArgsStorage().params.push(metadata); | ||
extraOptions: options ? options.options : undefined | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,22 @@ | ||
import {defaultMetadataArgsStorage} from "../index"; | ||
import {ParamMetadataArgs} from "../metadata/args/ParamMetadataArgs"; | ||
import {defaultMetadataArgsStorage} from "../metadata-builder/MetadataArgsStorage"; | ||
import {ParamOptions} from "../decorator-options/ParamOptions"; | ||
|
||
/** | ||
* Takes partial data of the request body. | ||
* Must be applied on a controller action parameters. | ||
* Must be applied on a controller action parameter. | ||
*/ | ||
export function BodyParam(name: string, options?: ParamOptions): Function { | ||
return function (object: Object, methodName: string, index: number) { | ||
const format = (Reflect as any).getMetadata("design:paramtypes", object, methodName)[index]; | ||
const metadata: ParamMetadataArgs = { | ||
target: object.constructor, | ||
defaultMetadataArgsStorage.params.push({ | ||
type: "body", | ||
object: object, | ||
method: methodName, | ||
index: index, | ||
type: "body", | ||
name: name, | ||
targetType: format, | ||
parse: options ? options.parse : false, | ||
required: options ? options.required : false, | ||
classTransform: options ? options.transform : undefined, | ||
validate: options ? options.validate : undefined, | ||
}; | ||
defaultMetadataArgsStorage().params.push(metadata); | ||
validate: options ? options.validate : undefined | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,16 @@ | ||
import {defaultMetadataArgsStorage} from "../index"; | ||
import {ResponseHandlerMetadataArgs} from "../metadata/args/ResponseHandleMetadataArgs"; | ||
import {defaultMetadataArgsStorage} from "../metadata-builder/MetadataArgsStorage"; | ||
|
||
/** | ||
* Sets response Content-Type. | ||
* Must be applied on a controller action. | ||
*/ | ||
export function ContentType(contentType: string): Function { | ||
return function (object: Object, methodName: string) { | ||
const metadata: ResponseHandlerMetadataArgs = { | ||
value: contentType, | ||
defaultMetadataArgsStorage.responseHandlers.push({ | ||
type: "content-type", | ||
target: object.constructor, | ||
method: methodName, | ||
type: "content-type" | ||
}; | ||
defaultMetadataArgsStorage().responseHandlers.push(metadata); | ||
value: contentType | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
import {defaultMetadataArgsStorage} from "../index"; | ||
import {ControllerMetadataArgs} from "../metadata/args/ControllerMetadataArgs"; | ||
import {defaultMetadataArgsStorage} from "../metadata-builder/MetadataArgsStorage"; | ||
|
||
/** | ||
* Defines a class as a controller. | ||
* Each decorated controller method is served as a controller action. | ||
* Controller actions are executed when request come. | ||
* | ||
* @param baseRoute Extra path you can apply as a base route to all controller actions | ||
*/ | ||
export function Controller(baseRoute?: string): Function { | ||
return function (object: Function) { | ||
const metadata: ControllerMetadataArgs = { | ||
route: baseRoute, | ||
defaultMetadataArgsStorage.controllers.push({ | ||
type: "default", | ||
target: object, | ||
type: "default" | ||
}; | ||
defaultMetadataArgsStorage().controllers.push(metadata); | ||
route: baseRoute | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,22 @@ | ||
import {defaultMetadataArgsStorage} from "../index"; | ||
import {defaultMetadataArgsStorage} from "../metadata-builder/MetadataArgsStorage"; | ||
import {ParamOptions} from "../decorator-options/ParamOptions"; | ||
import {ParamMetadataArgs} from "../metadata/args/ParamMetadataArgs"; | ||
|
||
/** | ||
* Injects a request's cookie value to the controller action parameter. | ||
* Must be applied on a controller action parameters. | ||
* Must be applied on a controller action parameter. | ||
*/ | ||
export function CookieParam(name: string, options?: ParamOptions) { | ||
return function (object: Object, methodName: string, index: number) { | ||
const format = (Reflect as any).getMetadata("design:paramtypes", object, methodName)[index]; | ||
const metadata: ParamMetadataArgs = { | ||
target: object.constructor, | ||
defaultMetadataArgsStorage.params.push({ | ||
type: "cookie", | ||
object: object, | ||
method: methodName, | ||
index: index, | ||
type: "cookie", | ||
name: name, | ||
targetType: format, | ||
parse: options ? options.parse : false, | ||
required: options ? options.required : false, | ||
classTransform: options ? options.transform : undefined, | ||
validate: options ? options.validate : undefined, | ||
}; | ||
defaultMetadataArgsStorage().params.push(metadata); | ||
validate: options ? options.validate : undefined | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,18 @@ | ||
import {defaultMetadataArgsStorage} from "../index"; | ||
import {ParamMetadataArgs} from "../metadata/args/ParamMetadataArgs"; | ||
import {defaultMetadataArgsStorage} from "../metadata-builder/MetadataArgsStorage"; | ||
|
||
/** | ||
* Injects all request's cookies to the controller action parameter. | ||
* Must be applied on a controller action parameters. | ||
* Must be applied on a controller action parameter. | ||
*/ | ||
export function CookieParams() { | ||
return function (object: Object, methodName: string, index: number) { | ||
const format = (Reflect as any).getMetadata("design:paramtypes", object, methodName)[index]; | ||
const metadata: ParamMetadataArgs = { | ||
target: object.constructor, | ||
defaultMetadataArgsStorage.params.push({ | ||
type: "cookie", | ||
object: object, | ||
method: methodName, | ||
index: index, | ||
type: "cookie", | ||
targetType: format, | ||
parse: false, | ||
required: false, | ||
}; | ||
defaultMetadataArgsStorage().params.push(metadata); | ||
required: false | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
import {defaultMetadataArgsStorage} from "../index"; | ||
import {ResponseHandlerMetadataArgs} from "../metadata/args/ResponseHandleMetadataArgs"; | ||
import {defaultMetadataArgsStorage} from "../metadata-builder/MetadataArgsStorage"; | ||
|
||
/** | ||
* Sets response header. | ||
* Must be applied on a controller action. | ||
*/ | ||
export function Header(name: string, value: string): Function { | ||
return function (object: Object, methodName: string) { | ||
const metadata: ResponseHandlerMetadataArgs = { | ||
value: name, | ||
secondaryValue: value, | ||
defaultMetadataArgsStorage.responseHandlers.push({ | ||
type: "header", | ||
target: object.constructor, | ||
method: methodName, | ||
type: "header" | ||
}; | ||
defaultMetadataArgsStorage().responseHandlers.push(metadata); | ||
value: name, | ||
secondaryValue: value | ||
}); | ||
}; | ||
} |
Oops, something went wrong.