@tsed/platform-params 8.11.1 → 8.12.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/esm/builder/PlatformParams.js +0 -1
- package/lib/esm/decorators/bodyParams.js +0 -1
- package/lib/esm/decorators/context.js +0 -1
- package/lib/esm/decorators/cookies.js +0 -1
- package/lib/esm/decorators/headerParams.js +0 -1
- package/lib/esm/decorators/locals.js +0 -1
- package/lib/esm/decorators/paramFn.js +0 -1
- package/lib/esm/decorators/pathParams.js +0 -1
- package/lib/esm/decorators/queryParams.js +0 -1
- package/lib/esm/decorators/session.js +0 -1
- package/lib/esm/decorators/useDeserialization.js +0 -1
- package/lib/esm/decorators/useParam.js +0 -1
- package/lib/esm/decorators/useParamExpression.js +0 -1
- package/lib/esm/decorators/useParamType.js +0 -1
- package/lib/esm/decorators/usePipe.js +0 -1
- package/lib/esm/decorators/useType.js +0 -1
- package/lib/esm/decorators/useValidation.js +0 -1
- package/lib/esm/domain/ParamMetadata.js +0 -1
- package/lib/esm/domain/ParamOptions.js +0 -1
- package/lib/esm/domain/ParamTypes.js +0 -1
- package/lib/esm/errors/ParamValidationError.js +0 -1
- package/lib/esm/errors/RequiredValidationError.js +0 -1
- package/lib/esm/errors/ValidationError.js +0 -1
- package/lib/esm/exports.js +0 -1
- package/lib/esm/index.js +0 -1
- package/lib/esm/pipes/DeserializerPipe.js +0 -1
- package/lib/esm/pipes/ParseExpressionPipe.js +0 -1
- package/lib/esm/pipes/ValidationPipe.js +0 -1
- package/lib/esm/utils/mapParamsOptions.js +0 -1
- package/package.json +12 -9
- package/lib/esm/builder/PlatformParams.js.map +0 -1
- package/lib/esm/decorators/bodyParams.js.map +0 -1
- package/lib/esm/decorators/context.js.map +0 -1
- package/lib/esm/decorators/cookies.js.map +0 -1
- package/lib/esm/decorators/headerParams.js.map +0 -1
- package/lib/esm/decorators/locals.js.map +0 -1
- package/lib/esm/decorators/paramFn.js.map +0 -1
- package/lib/esm/decorators/pathParams.js.map +0 -1
- package/lib/esm/decorators/queryParams.js.map +0 -1
- package/lib/esm/decorators/session.js.map +0 -1
- package/lib/esm/decorators/useDeserialization.js.map +0 -1
- package/lib/esm/decorators/useParam.js.map +0 -1
- package/lib/esm/decorators/useParamExpression.js.map +0 -1
- package/lib/esm/decorators/useParamType.js.map +0 -1
- package/lib/esm/decorators/usePipe.js.map +0 -1
- package/lib/esm/decorators/useType.js.map +0 -1
- package/lib/esm/decorators/useValidation.js.map +0 -1
- package/lib/esm/domain/ParamMetadata.js.map +0 -1
- package/lib/esm/domain/ParamOptions.js.map +0 -1
- package/lib/esm/domain/ParamTypes.js.map +0 -1
- package/lib/esm/errors/ParamValidationError.js.map +0 -1
- package/lib/esm/errors/RequiredValidationError.js.map +0 -1
- package/lib/esm/errors/ValidationError.js.map +0 -1
- package/lib/esm/exports.js.map +0 -1
- package/lib/esm/index.js.map +0 -1
- package/lib/esm/pipes/DeserializerPipe.js.map +0 -1
- package/lib/esm/pipes/ParseExpressionPipe.js.map +0 -1
- package/lib/esm/pipes/ValidationPipe.js.map +0 -1
- package/lib/esm/utils/mapParamsOptions.js.map +0 -1
- package/src/builder/PlatformParams.spec.ts +0 -431
- package/src/builder/PlatformParams.ts +0 -92
- package/src/decorators/__snapshots__/bodyParams.spec.ts.snap +0 -105
- package/src/decorators/bodyParams.spec.ts +0 -432
- package/src/decorators/bodyParams.ts +0 -93
- package/src/decorators/context.spec.ts +0 -16
- package/src/decorators/context.ts +0 -70
- package/src/decorators/cookies.spec.ts +0 -19
- package/src/decorators/cookies.ts +0 -102
- package/src/decorators/headerParams.spec.ts +0 -16
- package/src/decorators/headerParams.ts +0 -49
- package/src/decorators/locals.spec.ts +0 -16
- package/src/decorators/locals.ts +0 -57
- package/src/decorators/paramFn.ts +0 -14
- package/src/decorators/pathParams.spec.ts +0 -58
- package/src/decorators/pathParams.ts +0 -97
- package/src/decorators/queryParams.spec.ts +0 -58
- package/src/decorators/queryParams.ts +0 -102
- package/src/decorators/session.spec.ts +0 -47
- package/src/decorators/session.ts +0 -51
- package/src/decorators/useDeserialization.ts +0 -14
- package/src/decorators/useParam.spec.ts +0 -82
- package/src/decorators/useParam.ts +0 -38
- package/src/decorators/useParamExpression.ts +0 -16
- package/src/decorators/useParamType.ts +0 -36
- package/src/decorators/usePipe.ts +0 -21
- package/src/decorators/useType.ts +0 -35
- package/src/decorators/useValidation.ts +0 -18
- package/src/domain/ParamMetadata.ts +0 -1
- package/src/domain/ParamOptions.ts +0 -12
- package/src/domain/ParamTypes.ts +0 -37
- package/src/errors/ParamValidationError.spec.ts +0 -152
- package/src/errors/ParamValidationError.ts +0 -38
- package/src/errors/RequiredValidationError.spec.ts +0 -49
- package/src/errors/RequiredValidationError.ts +0 -30
- package/src/errors/ValidationError.spec.ts +0 -18
- package/src/errors/ValidationError.ts +0 -11
- package/src/exports.ts +0 -1
- package/src/index.ts +0 -31
- package/src/pipes/DeserializerPipe.spec.ts +0 -39
- package/src/pipes/DeserializerPipe.ts +0 -15
- package/src/pipes/ParseExpressionPipe.spec.ts +0 -242
- package/src/pipes/ParseExpressionPipe.ts +0 -33
- package/src/pipes/ValidationPipe.spec.ts +0 -645
- package/src/pipes/ValidationPipe.ts +0 -112
- package/src/utils/mapParamsOptions.spec.ts +0 -28
- package/src/utils/mapParamsOptions.ts +0 -34
- package/vitest.config.mts +0 -21
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import {Type} from "@tsed/core";
|
|
2
|
-
|
|
3
|
-
import {ParamOptions} from "../domain/ParamOptions.js";
|
|
4
|
-
import {ParamTypes} from "../domain/ParamTypes.js";
|
|
5
|
-
import {mapParamsOptions} from "../utils/mapParamsOptions.js";
|
|
6
|
-
import {UseParam} from "./useParam.js";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Cookies or CookiesParams return the value from [request.cookies](http://expressjs.com/en/4x/api.html#req.cookies) object.
|
|
10
|
-
*
|
|
11
|
-
* #### Example
|
|
12
|
-
*
|
|
13
|
-
* ```typescript
|
|
14
|
-
* @Controller('/')
|
|
15
|
-
* class MyCtrl {
|
|
16
|
-
* @Post('/')
|
|
17
|
-
* create(@Cookies() cookies: any) {
|
|
18
|
-
* console.log('Entire cookies', cookies);
|
|
19
|
-
* }
|
|
20
|
-
*
|
|
21
|
-
* @Post('/')
|
|
22
|
-
* create(@Cookies('id') id: string) {
|
|
23
|
-
* console.log('ID', id);
|
|
24
|
-
* }
|
|
25
|
-
*
|
|
26
|
-
* @Post('/')
|
|
27
|
-
* create(@Cookies('user') user: IUser) {
|
|
28
|
-
* console.log('user', user);
|
|
29
|
-
* }
|
|
30
|
-
* }
|
|
31
|
-
* ```
|
|
32
|
-
* > For more information on deserialization see [converters](/docs/json-mapper.md) page.
|
|
33
|
-
*
|
|
34
|
-
* @param expression The path of the property to get.
|
|
35
|
-
* @param useType The type of the class that to be used to deserialize the data.
|
|
36
|
-
* @decorator
|
|
37
|
-
* @operation
|
|
38
|
-
* @input
|
|
39
|
-
*/
|
|
40
|
-
export function CookiesParams(expression: string | any, useType: any): ParameterDecorator;
|
|
41
|
-
export function CookiesParams(): ParameterDecorator;
|
|
42
|
-
export function CookiesParams(expression: string | any): ParameterDecorator;
|
|
43
|
-
export function CookiesParams(options: ParamOptions<any>): ParameterDecorator;
|
|
44
|
-
export function CookiesParams(...args: any[]): ParameterDecorator {
|
|
45
|
-
const {expression, useType, useMapper = false, useValidation = false} = mapParamsOptions(args);
|
|
46
|
-
|
|
47
|
-
return UseParam({
|
|
48
|
-
paramType: ParamTypes.COOKIES,
|
|
49
|
-
expression,
|
|
50
|
-
useType,
|
|
51
|
-
useMapper,
|
|
52
|
-
useValidation
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Cookies or CookiesParams return the value from [request.cookies](http://expressjs.com/en/4x/api.html#req.cookies) object.
|
|
58
|
-
*
|
|
59
|
-
* #### Example
|
|
60
|
-
*
|
|
61
|
-
* ```typescript
|
|
62
|
-
* @Controller('/')
|
|
63
|
-
* class MyCtrl {
|
|
64
|
-
* @Post('/')
|
|
65
|
-
* create(@Cookies() body: any) {
|
|
66
|
-
* console.log('Entire body', body);
|
|
67
|
-
* }
|
|
68
|
-
*
|
|
69
|
-
* @Post('/')
|
|
70
|
-
* create(@Cookies('id') id: string) {
|
|
71
|
-
* console.log('ID', id);
|
|
72
|
-
* }
|
|
73
|
-
*
|
|
74
|
-
* @Post('/')
|
|
75
|
-
* create(@Cookies('user') user: User) { // with deserialization
|
|
76
|
-
* console.log('user', user);
|
|
77
|
-
* }
|
|
78
|
-
*
|
|
79
|
-
* @Post('/')
|
|
80
|
-
* create(@Cookies('users', User) users: User[]) { // with deserialization
|
|
81
|
-
* console.log('users', users);
|
|
82
|
-
* }
|
|
83
|
-
* }
|
|
84
|
-
* ```
|
|
85
|
-
* > For more information on deserialization see [converters](/docs/json-mapper.md) page.
|
|
86
|
-
*
|
|
87
|
-
* @param expression The path of the property to get.
|
|
88
|
-
* @param useType The type of the class that to be used to deserialize the data.
|
|
89
|
-
* @decorator
|
|
90
|
-
* @aliasof CookiesParams
|
|
91
|
-
* @operation
|
|
92
|
-
* @input
|
|
93
|
-
*/
|
|
94
|
-
export function Cookies(expression: string, useType: Type<any>): ParameterDecorator;
|
|
95
|
-
export function Cookies(expression: string): ParameterDecorator;
|
|
96
|
-
export function Cookies(useType: Type<any>): ParameterDecorator;
|
|
97
|
-
export function Cookies(options: Partial<ParamOptions>): ParameterDecorator;
|
|
98
|
-
export function Cookies(): ParameterDecorator;
|
|
99
|
-
export function Cookies(...args: any[]): ParameterDecorator {
|
|
100
|
-
// @ts-ignore
|
|
101
|
-
return CookiesParams(...args);
|
|
102
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import {JsonParameterStore} from "@tsed/schema";
|
|
2
|
-
|
|
3
|
-
import {ParamTypes} from "../domain/ParamTypes.js";
|
|
4
|
-
import {HeaderParams} from "./headerParams.js";
|
|
5
|
-
|
|
6
|
-
describe("@HeaderParams", () => {
|
|
7
|
-
it("should call ParamFilter.useParam method with the correct parameters", () => {
|
|
8
|
-
class Ctrl {
|
|
9
|
-
test(@HeaderParams("expression") header: string) {}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const param = JsonParameterStore.get(Ctrl, "test", 0);
|
|
13
|
-
expect(param.expression).toEqual("expression");
|
|
14
|
-
expect(param.paramType).toEqual(ParamTypes.HEADER);
|
|
15
|
-
});
|
|
16
|
-
});
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import {Type} from "@tsed/core";
|
|
2
|
-
|
|
3
|
-
import {ParamOptions} from "../domain/ParamOptions.js";
|
|
4
|
-
import {ParamTypes} from "../domain/ParamTypes.js";
|
|
5
|
-
import {mapParamsOptions} from "../utils/mapParamsOptions.js";
|
|
6
|
-
import {UseParam} from "./useParam.js";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* HeaderParams return the value from [`request.get()`](http://expressjs.com/en/4x/api.html#req.get) method.
|
|
10
|
-
*
|
|
11
|
-
* #### Example
|
|
12
|
-
*
|
|
13
|
-
* ```typescript
|
|
14
|
-
* @Controller('/')
|
|
15
|
-
* class MyCtrl {
|
|
16
|
-
* @Get('/')
|
|
17
|
-
* get(@HeaderParams() body: any) {
|
|
18
|
-
* console.log('Entire body', body);
|
|
19
|
-
* }
|
|
20
|
-
*
|
|
21
|
-
* @Get('/')
|
|
22
|
-
* get(@HeaderParams('x-token') token: string) {
|
|
23
|
-
* console.log('token', id);
|
|
24
|
-
* }
|
|
25
|
-
* }
|
|
26
|
-
* ```
|
|
27
|
-
*
|
|
28
|
-
* @param expression The path of the property to get.
|
|
29
|
-
* @param useType
|
|
30
|
-
* @decorator
|
|
31
|
-
* @operation
|
|
32
|
-
* @input
|
|
33
|
-
*/
|
|
34
|
-
export function HeaderParams(expression: string, useType: Type<any>): ParameterDecorator;
|
|
35
|
-
export function HeaderParams(expression: string): ParameterDecorator;
|
|
36
|
-
export function HeaderParams(useType: Type<any>): ParameterDecorator;
|
|
37
|
-
export function HeaderParams(options: Partial<ParamOptions>): ParameterDecorator;
|
|
38
|
-
export function HeaderParams(): ParameterDecorator;
|
|
39
|
-
export function HeaderParams(...args: any[]): ParameterDecorator {
|
|
40
|
-
const {expression, useType, useMapper = false, useValidation = false} = mapParamsOptions(args);
|
|
41
|
-
|
|
42
|
-
return UseParam({
|
|
43
|
-
paramType: ParamTypes.HEADER,
|
|
44
|
-
expression,
|
|
45
|
-
useType,
|
|
46
|
-
useMapper,
|
|
47
|
-
useValidation
|
|
48
|
-
});
|
|
49
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import {JsonParameterStore} from "@tsed/schema";
|
|
2
|
-
|
|
3
|
-
import {ParamTypes} from "../domain/ParamTypes.js";
|
|
4
|
-
import {Locals} from "./locals.js";
|
|
5
|
-
|
|
6
|
-
describe("@Locals", () => {
|
|
7
|
-
it("should call ParamFilter.useParam method with the correct parameters", () => {
|
|
8
|
-
class Ctrl {
|
|
9
|
-
test(@Locals("expression") test: any) {}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const param = JsonParameterStore.get(Ctrl, "test", 0);
|
|
13
|
-
expect(param.expression).toEqual("expression");
|
|
14
|
-
expect(param.paramType).toEqual(ParamTypes.LOCALS);
|
|
15
|
-
});
|
|
16
|
-
});
|
package/src/decorators/locals.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import {ParamTypes} from "../domain/ParamTypes.js";
|
|
2
|
-
import {mapParamsOptions} from "../utils/mapParamsOptions.js";
|
|
3
|
-
import {UseParam} from "./useParam.js";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Locals return the value from [response.locals](http://expressjs.com/en/4x/api.html#res.locals) object.
|
|
7
|
-
*
|
|
8
|
-
* ::: tip
|
|
9
|
-
* Locals are generally used by express and third-party like templating engine to render a page/template.
|
|
10
|
-
* See [Templating](https://tsed.dev/tutorials/templating.html) section for more details.
|
|
11
|
-
* :::
|
|
12
|
-
*
|
|
13
|
-
* #### Example
|
|
14
|
-
*
|
|
15
|
-
* ```typescript
|
|
16
|
-
* * @Middleware()
|
|
17
|
-
* class LocalsMiddleware {
|
|
18
|
-
* use(@Locals() locals: any) {
|
|
19
|
-
* // set some on locals
|
|
20
|
-
* locals.user = "user"
|
|
21
|
-
* }
|
|
22
|
-
* }
|
|
23
|
-
*
|
|
24
|
-
* @Controller('/')
|
|
25
|
-
* @UseBefore(LocalsMiddleware)
|
|
26
|
-
* class MyCtrl {
|
|
27
|
-
* @Get('/')
|
|
28
|
-
* @View('home.ejs') // will use locals and returned data to render the page
|
|
29
|
-
* get(@Locals('user') user: any) {
|
|
30
|
-
* console.log('user', user);
|
|
31
|
-
*
|
|
32
|
-
* return {
|
|
33
|
-
* description: 'Hello world'
|
|
34
|
-
* }
|
|
35
|
-
* }
|
|
36
|
-
* }
|
|
37
|
-
* ```
|
|
38
|
-
*
|
|
39
|
-
* @param expression The path of the property to get.
|
|
40
|
-
* @decorator
|
|
41
|
-
* @operation
|
|
42
|
-
* @input
|
|
43
|
-
* @response
|
|
44
|
-
*/
|
|
45
|
-
export function Locals(expression: string): ParameterDecorator;
|
|
46
|
-
export function Locals(): ParameterDecorator;
|
|
47
|
-
export function Locals(...args: any[]): ParameterDecorator {
|
|
48
|
-
const {expression, useType, useMapper = false, useValidation = false} = mapParamsOptions(args);
|
|
49
|
-
|
|
50
|
-
return UseParam({
|
|
51
|
-
paramType: ParamTypes.LOCALS,
|
|
52
|
-
expression,
|
|
53
|
-
useType,
|
|
54
|
-
useMapper,
|
|
55
|
-
useValidation
|
|
56
|
-
});
|
|
57
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import {DecoratorParameters} from "@tsed/core";
|
|
2
|
-
import {JsonEntityFn, JsonParameterStore} from "@tsed/schema";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Get the Param metadata. Use this decorator to compose your own decorator.
|
|
6
|
-
*
|
|
7
|
-
* @param fn
|
|
8
|
-
* @decorator
|
|
9
|
-
* @operation
|
|
10
|
-
* @input
|
|
11
|
-
*/
|
|
12
|
-
export function ParamFn(fn: (param: JsonParameterStore, parameters: DecoratorParameters) => void): ParameterDecorator {
|
|
13
|
-
return JsonEntityFn<JsonParameterStore>(fn);
|
|
14
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import {JsonParameterStore} from "@tsed/schema";
|
|
2
|
-
|
|
3
|
-
import {ParamTypes} from "../domain/ParamTypes.js";
|
|
4
|
-
import {PathParams, RawPathParams} from "./pathParams.js";
|
|
5
|
-
|
|
6
|
-
describe("@PathParams", () => {
|
|
7
|
-
it("should declare a path params", () => {
|
|
8
|
-
class Test {}
|
|
9
|
-
|
|
10
|
-
class Ctrl {
|
|
11
|
-
test(@PathParams("expression", Test) header: Test) {}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const param = JsonParameterStore.get(Ctrl, "test", 0);
|
|
15
|
-
expect(param.expression).toEqual("expression");
|
|
16
|
-
expect(param.paramType).toEqual(ParamTypes.PATH);
|
|
17
|
-
expect(param.type).toEqual(Test);
|
|
18
|
-
expect(param.pipes).toHaveLength(2);
|
|
19
|
-
});
|
|
20
|
-
it("should declara a path params with options", () => {
|
|
21
|
-
class Test {}
|
|
22
|
-
|
|
23
|
-
class Ctrl {
|
|
24
|
-
test(@PathParams({expression: "expression", useType: Test, useValidation: false}) param: Test) {}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const param = JsonParameterStore.get(Ctrl, "test", 0);
|
|
28
|
-
expect(param.expression).toEqual("expression");
|
|
29
|
-
expect(param.paramType).toEqual(ParamTypes.PATH);
|
|
30
|
-
expect(param.type).toEqual(Test);
|
|
31
|
-
expect(param.pipes).toHaveLength(1);
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
describe("@RawPathParams", () => {
|
|
36
|
-
it("should declare a raw path params", () => {
|
|
37
|
-
class Ctrl {
|
|
38
|
-
test(@RawPathParams("expression") header: string) {}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const param = JsonParameterStore.get(Ctrl, "test", 0);
|
|
42
|
-
expect(param.expression).toEqual("expression");
|
|
43
|
-
expect(param.paramType).toEqual(ParamTypes.PATH);
|
|
44
|
-
expect(param.type).toEqual(String);
|
|
45
|
-
expect(param.pipes).toHaveLength(0);
|
|
46
|
-
});
|
|
47
|
-
it("should declare a raw path params with options", () => {
|
|
48
|
-
class Ctrl {
|
|
49
|
-
test(@RawPathParams({expression: "expression", useValidation: true, useType: String}) param: Date) {}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const param = JsonParameterStore.get(Ctrl, "test", 0);
|
|
53
|
-
expect(param.expression).toEqual("expression");
|
|
54
|
-
expect(param.paramType).toEqual(ParamTypes.PATH);
|
|
55
|
-
expect(param.type).toEqual(String);
|
|
56
|
-
expect(param.pipes).toHaveLength(1);
|
|
57
|
-
});
|
|
58
|
-
});
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import {Type} from "@tsed/core";
|
|
2
|
-
|
|
3
|
-
import {ParamOptions} from "../domain/ParamOptions.js";
|
|
4
|
-
import {ParamTypes} from "../domain/ParamTypes.js";
|
|
5
|
-
import {mapParamsOptions} from "../utils/mapParamsOptions.js";
|
|
6
|
-
import {UseParam} from "./useParam.js";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* PathParams return the value from [request.params](http://expressjs.com/en/4x/api.html#req.params) object.
|
|
10
|
-
*
|
|
11
|
-
* #### Example
|
|
12
|
-
*
|
|
13
|
-
* ```typescript
|
|
14
|
-
* @Controller('/')
|
|
15
|
-
* class MyCtrl {
|
|
16
|
-
* @Get('/')
|
|
17
|
-
* get(@PathParams() params: any) {
|
|
18
|
-
* console.log('Entire params', params);
|
|
19
|
-
* }
|
|
20
|
-
*
|
|
21
|
-
* @Get('/')
|
|
22
|
-
* get(@PathParams('id') id: string) {
|
|
23
|
-
* console.log('ID', id);
|
|
24
|
-
* }
|
|
25
|
-
*
|
|
26
|
-
* @Get('/')
|
|
27
|
-
* get(@PathParams({expression: 'id', useType: () => new MyCustomModel() }) id: string) {
|
|
28
|
-
* console.log('ID', id);
|
|
29
|
-
* }
|
|
30
|
-
* }
|
|
31
|
-
* ```
|
|
32
|
-
* > For more information on deserialization see [converters](/docs/json-mapper.md) page.
|
|
33
|
-
*
|
|
34
|
-
* @param expression The path of the property to get.
|
|
35
|
-
* @param useType The type of the class that to be used to deserialize the data.
|
|
36
|
-
* @decorator
|
|
37
|
-
* @operation
|
|
38
|
-
* @input
|
|
39
|
-
*/
|
|
40
|
-
export function PathParams(expression: string, useType: Type<any>): ParameterDecorator;
|
|
41
|
-
export function PathParams(expression: string): ParameterDecorator;
|
|
42
|
-
export function PathParams(useType: Type<any>): ParameterDecorator;
|
|
43
|
-
export function PathParams(options: Partial<ParamOptions>): ParameterDecorator;
|
|
44
|
-
export function PathParams(): ParameterDecorator;
|
|
45
|
-
export function PathParams(...args: any[]): ParameterDecorator {
|
|
46
|
-
const {expression, useType, useMapper = true, useValidation = true} = mapParamsOptions(args);
|
|
47
|
-
|
|
48
|
-
return UseParam({
|
|
49
|
-
paramType: ParamTypes.PATH,
|
|
50
|
-
expression,
|
|
51
|
-
useType,
|
|
52
|
-
useMapper,
|
|
53
|
-
useValidation
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* RawPathParams return the raw value from [request.params](http://expressjs.com/en/4x/api.html#req.params) object.
|
|
59
|
-
*
|
|
60
|
-
* Any validation and transformation are performed on the value. Use [pipes](/docs/pipes.html) to validate and/or transform the value.
|
|
61
|
-
*
|
|
62
|
-
* #### Example
|
|
63
|
-
*
|
|
64
|
-
* ```typescript
|
|
65
|
-
* @Controller('/')
|
|
66
|
-
* class MyCtrl {
|
|
67
|
-
* @Get('/')
|
|
68
|
-
* get(@RawPathParams() params: string) {
|
|
69
|
-
* console.log('Entire params', params);
|
|
70
|
-
* }
|
|
71
|
-
*
|
|
72
|
-
* @Get('/')
|
|
73
|
-
* get(@RawPathParams('id') id: string) {
|
|
74
|
-
* console.log('ID', id);
|
|
75
|
-
* }
|
|
76
|
-
* }
|
|
77
|
-
* ```
|
|
78
|
-
* > For more information on deserialization see [converters](/docs/json-mapper.md) page.
|
|
79
|
-
*
|
|
80
|
-
* @param expression The path of the property to get.
|
|
81
|
-
* @decorator
|
|
82
|
-
* @operation
|
|
83
|
-
* @input
|
|
84
|
-
*/
|
|
85
|
-
export function RawPathParams(expression: string): ParameterDecorator;
|
|
86
|
-
export function RawPathParams(options: Partial<ParamOptions>): ParameterDecorator;
|
|
87
|
-
export function RawPathParams(): ParameterDecorator;
|
|
88
|
-
export function RawPathParams(...args: any[]): ParameterDecorator {
|
|
89
|
-
const {expression, useType, useMapper = false, useValidation = false} = mapParamsOptions(args);
|
|
90
|
-
|
|
91
|
-
return PathParams({
|
|
92
|
-
expression,
|
|
93
|
-
useValidation,
|
|
94
|
-
useMapper,
|
|
95
|
-
useType
|
|
96
|
-
});
|
|
97
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import {JsonParameterStore} from "@tsed/schema";
|
|
2
|
-
|
|
3
|
-
import {ParamTypes} from "../domain/ParamTypes.js";
|
|
4
|
-
import {QueryParams, RawQueryParams} from "./queryParams.js";
|
|
5
|
-
|
|
6
|
-
describe("@QueryParams", () => {
|
|
7
|
-
it("should declare query params", () => {
|
|
8
|
-
class Test {}
|
|
9
|
-
|
|
10
|
-
class Ctrl {
|
|
11
|
-
test(@QueryParams("expression", Test) header: Test) {}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const param = JsonParameterStore.get(Ctrl, "test", 0);
|
|
15
|
-
expect(param.expression).toEqual("expression");
|
|
16
|
-
expect(param.paramType).toEqual(ParamTypes.QUERY);
|
|
17
|
-
expect(param.type).toEqual(Test);
|
|
18
|
-
expect(param.pipes).toHaveLength(2);
|
|
19
|
-
});
|
|
20
|
-
it("should declare query params with options", () => {
|
|
21
|
-
class Test {}
|
|
22
|
-
|
|
23
|
-
class Ctrl {
|
|
24
|
-
test(@QueryParams({expression: "expression", useType: Test, useValidation: false}) param: Test) {}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const param = JsonParameterStore.get(Ctrl, "test", 0);
|
|
28
|
-
expect(param.expression).toEqual("expression");
|
|
29
|
-
expect(param.paramType).toEqual(ParamTypes.QUERY);
|
|
30
|
-
expect(param.type).toEqual(Test);
|
|
31
|
-
expect(param.pipes).toHaveLength(1);
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
describe("@RawQueryParams", () => {
|
|
36
|
-
it("should declare raw query params", () => {
|
|
37
|
-
class Ctrl {
|
|
38
|
-
test(@RawQueryParams("expression") header: string) {}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const param = JsonParameterStore.get(Ctrl, "test", 0);
|
|
42
|
-
expect(param.expression).toEqual("expression");
|
|
43
|
-
expect(param.paramType).toEqual(ParamTypes.QUERY);
|
|
44
|
-
expect(param.type).toEqual(String);
|
|
45
|
-
expect(param.pipes).toHaveLength(0);
|
|
46
|
-
});
|
|
47
|
-
it("should declare raw query params with options", () => {
|
|
48
|
-
class Ctrl {
|
|
49
|
-
test(@RawQueryParams({expression: "expression", useValidation: true, useType: String}) param: Date) {}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const param = JsonParameterStore.get(Ctrl, "test", 0);
|
|
53
|
-
expect(param.expression).toEqual("expression");
|
|
54
|
-
expect(param.paramType).toEqual(ParamTypes.QUERY);
|
|
55
|
-
expect(param.type).toEqual(String);
|
|
56
|
-
expect(param.pipes).toHaveLength(1);
|
|
57
|
-
});
|
|
58
|
-
});
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import {Type} from "@tsed/core";
|
|
2
|
-
|
|
3
|
-
import {ParamOptions} from "../domain/ParamOptions.js";
|
|
4
|
-
import {ParamTypes} from "../domain/ParamTypes.js";
|
|
5
|
-
import {mapParamsOptions} from "../utils/mapParamsOptions.js";
|
|
6
|
-
import {UseParam} from "./useParam.js";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* QueryParams return the value from [request.query](http://expressjs.com/en/4x/api.html#req.query) object.
|
|
10
|
-
*
|
|
11
|
-
* #### Example
|
|
12
|
-
*
|
|
13
|
-
* ```typescript
|
|
14
|
-
* @Controller('/')
|
|
15
|
-
* class MyCtrl {
|
|
16
|
-
* @Get('/')
|
|
17
|
-
* get(@QueryParams() query: any) {
|
|
18
|
-
* console.log('Entire query', query);
|
|
19
|
-
* }
|
|
20
|
-
*
|
|
21
|
-
* @Get('/')
|
|
22
|
-
* get(@QueryParams('id') id: string) {
|
|
23
|
-
* console.log('ID', id);
|
|
24
|
-
* }
|
|
25
|
-
*
|
|
26
|
-
* @Get('/')
|
|
27
|
-
* get(@QueryParams('user') user: User) { // with deserialization
|
|
28
|
-
* console.log('user', user);
|
|
29
|
-
* }
|
|
30
|
-
*
|
|
31
|
-
* @Get('/')
|
|
32
|
-
* get(@QueryParams('users', User) users: User[]) { // with deserialization
|
|
33
|
-
* console.log('users', users);
|
|
34
|
-
* }
|
|
35
|
-
* }
|
|
36
|
-
* ```
|
|
37
|
-
* > For more information on deserialization see [converters](/docs/json-mapper.md) page.
|
|
38
|
-
*
|
|
39
|
-
* @param expression The path of the property to get.
|
|
40
|
-
* @param useType The type of the class that to be used to deserialize the data.
|
|
41
|
-
* @decorator
|
|
42
|
-
* @operation
|
|
43
|
-
* @input
|
|
44
|
-
*/
|
|
45
|
-
export function QueryParams(expression: string, useType: Type<any>): ParameterDecorator;
|
|
46
|
-
export function QueryParams(expression: string): ParameterDecorator;
|
|
47
|
-
export function QueryParams(useType: Type<any>): ParameterDecorator;
|
|
48
|
-
export function QueryParams(options: Partial<ParamOptions>): ParameterDecorator;
|
|
49
|
-
export function QueryParams(): ParameterDecorator;
|
|
50
|
-
export function QueryParams(...args: any[]): ParameterDecorator {
|
|
51
|
-
const {expression, useType, useMapper = true, useValidation = true} = mapParamsOptions(args);
|
|
52
|
-
|
|
53
|
-
return UseParam({
|
|
54
|
-
paramType: ParamTypes.QUERY,
|
|
55
|
-
expression,
|
|
56
|
-
useType,
|
|
57
|
-
useMapper,
|
|
58
|
-
useValidation
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* RawQueryParams return the value from [request.query](http://expressjs.com/en/4x/api.html#req.query) object.
|
|
64
|
-
*
|
|
65
|
-
* Any validation and transformation are performed on the value. Use [pipes](/docs/pipes.html) to validate and/or transform the value.
|
|
66
|
-
*
|
|
67
|
-
* #### Example
|
|
68
|
-
*
|
|
69
|
-
* ```typescript
|
|
70
|
-
* @Controller('/')
|
|
71
|
-
* class MyCtrl {
|
|
72
|
-
* @Get('/')
|
|
73
|
-
* get(@RawPathParams() params: any) {
|
|
74
|
-
* console.log('Entire params', params);
|
|
75
|
-
* }
|
|
76
|
-
*
|
|
77
|
-
* @Get('/')
|
|
78
|
-
* get(@RawPathParams('id') id: string) {
|
|
79
|
-
* console.log('ID', id);
|
|
80
|
-
* }
|
|
81
|
-
* }
|
|
82
|
-
* ```
|
|
83
|
-
* > For more information on deserialization see [converters](/docs/json-mapper.md) page.
|
|
84
|
-
*
|
|
85
|
-
* @param expression The path of the property to get.
|
|
86
|
-
* @decorator
|
|
87
|
-
* @operation
|
|
88
|
-
* @input
|
|
89
|
-
*/
|
|
90
|
-
export function RawQueryParams(expression: string): ParameterDecorator;
|
|
91
|
-
export function RawQueryParams(options: Partial<ParamOptions>): ParameterDecorator;
|
|
92
|
-
export function RawQueryParams(): ParameterDecorator;
|
|
93
|
-
export function RawQueryParams(...args: any[]) {
|
|
94
|
-
const {expression, useType, useMapper = false, useValidation = false} = mapParamsOptions(args);
|
|
95
|
-
|
|
96
|
-
return QueryParams({
|
|
97
|
-
expression,
|
|
98
|
-
useType,
|
|
99
|
-
useMapper,
|
|
100
|
-
useValidation
|
|
101
|
-
});
|
|
102
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import {JsonParameterStore} from "@tsed/schema";
|
|
2
|
-
|
|
3
|
-
import {ParamTypes} from "../domain/ParamTypes.js";
|
|
4
|
-
import {Session} from "./session.js";
|
|
5
|
-
|
|
6
|
-
describe("@Session", () => {
|
|
7
|
-
it("should declare a session params", () => {
|
|
8
|
-
class Test {}
|
|
9
|
-
|
|
10
|
-
class Ctrl {
|
|
11
|
-
test(@Session() body: any) {}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const param = JsonParameterStore.get(Ctrl, "test", 0);
|
|
15
|
-
expect(param.expression).toEqual(undefined);
|
|
16
|
-
expect(param.paramType).toEqual(ParamTypes.SESSION);
|
|
17
|
-
expect(param.type).toEqual(Object);
|
|
18
|
-
expect(param.pipes).toHaveLength(0);
|
|
19
|
-
});
|
|
20
|
-
it("should declare a session params with options", () => {
|
|
21
|
-
class Test {}
|
|
22
|
-
|
|
23
|
-
class Ctrl {
|
|
24
|
-
test(@Session({expression: "expression", useType: Test}) body: Test) {}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const param = JsonParameterStore.get(Ctrl, "test", 0);
|
|
28
|
-
expect(param.expression).toEqual("expression");
|
|
29
|
-
expect(param.paramType).toEqual(ParamTypes.SESSION);
|
|
30
|
-
expect(param.type).toEqual(Test);
|
|
31
|
-
expect(param.pipes).toHaveLength(0);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it("should declare a session params with options (validation + mapping)", () => {
|
|
35
|
-
class Test {}
|
|
36
|
-
|
|
37
|
-
class Ctrl {
|
|
38
|
-
test(@Session({expression: "expression", useType: Test, useValidation: true, useMapper: true}) body: Test) {}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const param = JsonParameterStore.get(Ctrl, "test", 0);
|
|
42
|
-
expect(param.expression).toEqual("expression");
|
|
43
|
-
expect(param.paramType).toEqual(ParamTypes.SESSION);
|
|
44
|
-
expect(param.type).toEqual(Test);
|
|
45
|
-
expect(param.pipes).toHaveLength(2);
|
|
46
|
-
});
|
|
47
|
-
});
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import {ParamOptions} from "../domain/ParamOptions.js";
|
|
2
|
-
import {ParamTypes} from "../domain/ParamTypes.js";
|
|
3
|
-
import {mapParamsOptions} from "../utils/mapParamsOptions.js";
|
|
4
|
-
import {UseParam} from "./useParam.js";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Session return the value from [request.session](http://expressjs.com/en/4x/api.html#req.session) object.
|
|
8
|
-
*
|
|
9
|
-
* #### Example
|
|
10
|
-
*
|
|
11
|
-
* ```typescript
|
|
12
|
-
* @Controller('/')
|
|
13
|
-
* class MyCtrl {
|
|
14
|
-
* @Post('/')
|
|
15
|
-
* create(@Session() session: Express.Session) {
|
|
16
|
-
* console.log('Entire session', session);
|
|
17
|
-
* }
|
|
18
|
-
*
|
|
19
|
-
* @Post('/')
|
|
20
|
-
* create(@Session('id') id: string) {
|
|
21
|
-
* console.log('ID', id);
|
|
22
|
-
* }
|
|
23
|
-
*
|
|
24
|
-
* @Post('/') // Example to deserialize use from session
|
|
25
|
-
* create(@Session({expression: 'user', useMapper: true}) user: User) {
|
|
26
|
-
* console.log('user', user);
|
|
27
|
-
* console.log('instanceOf user', user instanceof User);
|
|
28
|
-
* }
|
|
29
|
-
* }
|
|
30
|
-
* ```
|
|
31
|
-
* > For more information on deserialization see [converters](/docs/json-mapper.md) page.
|
|
32
|
-
*
|
|
33
|
-
* @param expression The path of the property to get.
|
|
34
|
-
* @decorator
|
|
35
|
-
* @operation
|
|
36
|
-
* @input
|
|
37
|
-
*/
|
|
38
|
-
export function Session(expression: string): ParameterDecorator;
|
|
39
|
-
export function Session(options: Partial<ParamOptions>): ParameterDecorator;
|
|
40
|
-
export function Session(): ParameterDecorator;
|
|
41
|
-
export function Session(...args: any[]): ParameterDecorator {
|
|
42
|
-
const {expression, useType, useMapper = false, useValidation = false} = mapParamsOptions(args);
|
|
43
|
-
|
|
44
|
-
return UseParam({
|
|
45
|
-
paramType: ParamTypes.SESSION,
|
|
46
|
-
expression,
|
|
47
|
-
useType,
|
|
48
|
-
useMapper,
|
|
49
|
-
useValidation
|
|
50
|
-
});
|
|
51
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import {DeserializerPipe} from "../pipes/DeserializerPipe.js";
|
|
2
|
-
import {UsePipe} from "./usePipe.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Use JsonMapper to deserialize the data.
|
|
6
|
-
*
|
|
7
|
-
* @decorator
|
|
8
|
-
* @operation
|
|
9
|
-
* @input
|
|
10
|
-
* @pipe
|
|
11
|
-
*/
|
|
12
|
-
export function UseDeserialization(options: any = {}) {
|
|
13
|
-
return UsePipe(DeserializerPipe, options);
|
|
14
|
-
}
|