@tsed/platform-params 7.79.3 → 7.80.0

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.
Files changed (35) hide show
  1. package/lib/types-esm/builder/PlatformParams.d.ts +25 -0
  2. package/lib/types-esm/decorators/bodyParams.d.ts +66 -0
  3. package/lib/types-esm/decorators/context.d.ts +53 -0
  4. package/lib/types-esm/decorators/cookies.d.ts +81 -0
  5. package/lib/types-esm/decorators/headerParams.d.ts +33 -0
  6. package/lib/types-esm/decorators/locals.d.ts +42 -0
  7. package/lib/types-esm/decorators/paramFn.d.ts +11 -0
  8. package/lib/types-esm/decorators/pathParams.d.ts +70 -0
  9. package/lib/types-esm/decorators/queryParams.d.ts +75 -0
  10. package/lib/types-esm/decorators/session.d.ts +36 -0
  11. package/lib/types-esm/decorators/useDeserialization.d.ts +9 -0
  12. package/lib/types-esm/decorators/useParam.d.ts +18 -0
  13. package/lib/types-esm/decorators/useParamExpression.d.ts +10 -0
  14. package/lib/types-esm/decorators/useParamType.d.ts +10 -0
  15. package/lib/types-esm/decorators/usePipe.d.ts +13 -0
  16. package/lib/types-esm/decorators/useType.d.ts +13 -0
  17. package/lib/types-esm/decorators/useValidation.d.ts +9 -0
  18. package/lib/types-esm/domain/ParamMetadata.d.ts +1 -0
  19. package/lib/types-esm/domain/ParamOptions.d.ts +10 -0
  20. package/lib/types-esm/domain/ParamTypes.d.ts +25 -0
  21. package/lib/types-esm/errors/ParamValidationError.d.ts +8 -0
  22. package/lib/types-esm/errors/RequiredValidationError.d.ts +6 -0
  23. package/lib/types-esm/errors/ValidationError.d.ts +6 -0
  24. package/lib/types-esm/exports.d.ts +1 -0
  25. package/lib/types-esm/index.d.ts +31 -0
  26. package/lib/types-esm/pipes/DeserializerPipe.d.ts +4 -0
  27. package/lib/types-esm/pipes/ParseExpressionPipe.d.ts +6 -0
  28. package/lib/types-esm/pipes/ValidationPipe.d.ts +12 -0
  29. package/lib/types-esm/utils/mapParamsOptions.d.ts +5 -0
  30. package/package.json +24 -20
  31. package/vitest.config.mts +21 -0
  32. package/jest.config.js +0 -14
  33. package/lib/cjs/package.json +0 -3
  34. package/lib/esm/package.json +0 -3
  35. package/tsconfig.esm.json +0 -45
@@ -0,0 +1,25 @@
1
+ import { DIContext, InjectorService } from "@tsed/di";
2
+ import { JsonMethodStore, JsonParameterStore, PipeMethods } from "@tsed/schema";
3
+ export type PlatformParamsScope<Context extends DIContext = DIContext> = {
4
+ $ctx: Context;
5
+ } & Record<string, any>;
6
+ export type PlatformParamsCallback<Context extends DIContext = DIContext> = (scope: PlatformParamsScope<Context>) => Promise<any>;
7
+ /**
8
+ * Platform Params abstraction layer.
9
+ * @platform
10
+ */
11
+ export declare class PlatformParams {
12
+ protected injector: InjectorService;
13
+ getPipes(param: JsonParameterStore): PipeMethods<any, any>[];
14
+ /**
15
+ * Return a handler with injectable parameters
16
+ * @param handlerMetadata
17
+ */
18
+ compileHandler<Context extends DIContext = DIContext>({ propertyKey, token, handler }: {
19
+ propertyKey?: string | symbol;
20
+ token?: any;
21
+ handler?: any;
22
+ }): PlatformParamsCallback<Context>;
23
+ compile<Context extends DIContext = DIContext>(entity: JsonMethodStore): PlatformParamsCallback<Context>;
24
+ getArg<Context extends DIContext = DIContext>(scope: PlatformParamsScope, pipes: PipeMethods[], param: JsonParameterStore): Promise<any>;
25
+ }
@@ -0,0 +1,66 @@
1
+ import { Type } from "@tsed/core";
2
+ import { ParamOptions } from "../domain/ParamOptions.js";
3
+ /**
4
+ * BodyParams return the value from [request.body](http://expressjs.com/en/4x/api.html#req.body) object.
5
+ *
6
+ * #### Example
7
+ *
8
+ * ```typescript
9
+ * @Controller('/')
10
+ * class MyCtrl {
11
+ * @Post('/')
12
+ * create(@BodyParams() body: any) {
13
+ * console.log('Entire body', body);
14
+ * }
15
+ *
16
+ * @Post('/')
17
+ * create(@BodyParams('id') id: string) {
18
+ * console.log('ID', id);
19
+ * }
20
+ *
21
+ * @Post('/')
22
+ * create(@BodyParams('user') user: User) { // with deserialization
23
+ * console.log('user', user);
24
+ * }
25
+ *
26
+ * @Post('/')
27
+ * create(@BodyParams('users', User) users: User[]) { // with deserialization
28
+ * console.log('users', users);
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 declare function BodyParams(expression: string, useType: Type<any>): ParameterDecorator;
41
+ export declare function BodyParams(expression: string): ParameterDecorator;
42
+ export declare function BodyParams(useType: Type<any>): ParameterDecorator;
43
+ export declare function BodyParams(options: Partial<ParamOptions>): ParameterDecorator;
44
+ export declare function BodyParams(): ParameterDecorator;
45
+ /**
46
+ * RawBodyParams return the value from [request.body](http://expressjs.com/en/4x/api.html#req.body) as a Buffer.
47
+ *
48
+ * #### Example
49
+ *
50
+ * ```typescript
51
+ * @Controller('/')
52
+ * class MyCtrl {
53
+ * @Post('/')
54
+ * create(@RawBodyParams() body: Buffer) {
55
+ * console.log('Entire body', body.toString("utf8"));
56
+ * }
57
+ * }
58
+ * ```
59
+ *
60
+ * @decorator
61
+ * @operation
62
+ * @input
63
+ * @alias BodyParams Example: @BodyParams() payload: Buffer
64
+ */
65
+ export declare function RawBodyParams(options: Partial<Omit<ParamOptions, "expression">>): ParameterDecorator;
66
+ export declare function RawBodyParams(): ParameterDecorator;
@@ -0,0 +1,53 @@
1
+ import { BaseContext } from "@tsed/di";
2
+ /**
3
+ * Context decorator return the @@PlatformContext@@ created by Ts.ED when request is handled by the server.
4
+ *
5
+ * It contains some information as following:
6
+ *
7
+ * - The request id,
8
+ * - The request container used by the Ts.ED DI. It contain all services annotated with `@Scope(ProviderScope.REQUEST)`,
9
+ * - The current @@EndpointMetadata@@ resolved by Ts.ED during the request,
10
+ * - The data return by the previous endpoint if you use multiple handler on the same route. By default data is empty.
11
+ *
12
+ * ::: tip
13
+ * The @@PlatformContext@@ inherit from Map class. So you can store any information with.
14
+ * :::
15
+ *
16
+ * #### Example
17
+ *
18
+ * ```typescript
19
+ * @Middleware()
20
+ * class AuthTokenMiddleware {
21
+ * use(@Req() request: Req, @Context() context: PlatformContext) {
22
+ * if (!context.has("auth")){
23
+ * context.set('auth', new AuthToken(request))
24
+ * }
25
+ *
26
+ * try {
27
+ * context.get("auth").claims() // check token
28
+ * } catch(er){
29
+ * throw new Forbidden("Access forbidden - Bad token")
30
+ * }
31
+ * }
32
+ * }
33
+ *
34
+ * @Controller('/')
35
+ * @UseBefore(AuthTokenMiddleware) // protect all routes for this controller
36
+ * class MyCtrl {
37
+ * @Get('/')
38
+ * get(@Context('auth') auth: AuthToken) {
39
+ * console.log('auth', auth);
40
+ * console.log('auth.accessToken', auth.accessToken);
41
+ * console.log('auth.idToken', auth.idToken);
42
+ * }
43
+ * }
44
+ * ```
45
+ *
46
+ * @param expression The path of the property to get.
47
+ * @decorator
48
+ * @operation
49
+ * @input
50
+ */
51
+ export declare function Context(expression: string): ParameterDecorator;
52
+ export declare function Context(): ParameterDecorator;
53
+ export type Context = BaseContext;
@@ -0,0 +1,81 @@
1
+ import { Type } from "@tsed/core";
2
+ import { ParamOptions } from "../domain/ParamOptions.js";
3
+ /**
4
+ * Cookies or CookiesParams return the value from [request.cookies](http://expressjs.com/en/4x/api.html#req.cookies) object.
5
+ *
6
+ * #### Example
7
+ *
8
+ * ```typescript
9
+ * @Controller('/')
10
+ * class MyCtrl {
11
+ * @Post('/')
12
+ * create(@Cookies() cookies: any) {
13
+ * console.log('Entire cookies', cookies);
14
+ * }
15
+ *
16
+ * @Post('/')
17
+ * create(@Cookies('id') id: string) {
18
+ * console.log('ID', id);
19
+ * }
20
+ *
21
+ * @Post('/')
22
+ * create(@Cookies('user') user: IUser) {
23
+ * console.log('user', user);
24
+ * }
25
+ * }
26
+ * ```
27
+ * > For more information on deserialization see [converters](/docs/json-mapper.md) page.
28
+ *
29
+ * @param expression The path of the property to get.
30
+ * @param useType The type of the class that to be used to deserialize the data.
31
+ * @decorator
32
+ * @operation
33
+ * @input
34
+ */
35
+ export declare function CookiesParams(expression: string | any, useType: any): ParameterDecorator;
36
+ export declare function CookiesParams(): ParameterDecorator;
37
+ export declare function CookiesParams(expression: string | any): ParameterDecorator;
38
+ export declare function CookiesParams(options: ParamOptions<any>): ParameterDecorator;
39
+ /**
40
+ * Cookies or CookiesParams return the value from [request.cookies](http://expressjs.com/en/4x/api.html#req.cookies) object.
41
+ *
42
+ * #### Example
43
+ *
44
+ * ```typescript
45
+ * @Controller('/')
46
+ * class MyCtrl {
47
+ * @Post('/')
48
+ * create(@Cookies() body: any) {
49
+ * console.log('Entire body', body);
50
+ * }
51
+ *
52
+ * @Post('/')
53
+ * create(@Cookies('id') id: string) {
54
+ * console.log('ID', id);
55
+ * }
56
+ *
57
+ * @Post('/')
58
+ * create(@Cookies('user') user: User) { // with deserialization
59
+ * console.log('user', user);
60
+ * }
61
+ *
62
+ * @Post('/')
63
+ * create(@Cookies('users', User) users: User[]) { // with deserialization
64
+ * console.log('users', users);
65
+ * }
66
+ * }
67
+ * ```
68
+ * > For more information on deserialization see [converters](/docs/json-mapper.md) page.
69
+ *
70
+ * @param expression The path of the property to get.
71
+ * @param useType The type of the class that to be used to deserialize the data.
72
+ * @decorator
73
+ * @aliasof CookiesParams
74
+ * @operation
75
+ * @input
76
+ */
77
+ export declare function Cookies(expression: string, useType: Type<any>): ParameterDecorator;
78
+ export declare function Cookies(expression: string): ParameterDecorator;
79
+ export declare function Cookies(useType: Type<any>): ParameterDecorator;
80
+ export declare function Cookies(options: Partial<ParamOptions>): ParameterDecorator;
81
+ export declare function Cookies(): ParameterDecorator;
@@ -0,0 +1,33 @@
1
+ import { Type } from "@tsed/core";
2
+ import { ParamOptions } from "../domain/ParamOptions.js";
3
+ /**
4
+ * HeaderParams return the value from [`request.get()`](http://expressjs.com/en/4x/api.html#req.get) method.
5
+ *
6
+ * #### Example
7
+ *
8
+ * ```typescript
9
+ * @Controller('/')
10
+ * class MyCtrl {
11
+ * @Get('/')
12
+ * get(@HeaderParams() body: any) {
13
+ * console.log('Entire body', body);
14
+ * }
15
+ *
16
+ * @Get('/')
17
+ * get(@HeaderParams('x-token') token: string) {
18
+ * console.log('token', id);
19
+ * }
20
+ * }
21
+ * ```
22
+ *
23
+ * @param expression The path of the property to get.
24
+ * @param useType
25
+ * @decorator
26
+ * @operation
27
+ * @input
28
+ */
29
+ export declare function HeaderParams(expression: string, useType: Type<any>): ParameterDecorator;
30
+ export declare function HeaderParams(expression: string): ParameterDecorator;
31
+ export declare function HeaderParams(useType: Type<any>): ParameterDecorator;
32
+ export declare function HeaderParams(options: Partial<ParamOptions>): ParameterDecorator;
33
+ export declare function HeaderParams(): ParameterDecorator;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Locals return the value from [response.locals](http://expressjs.com/en/4x/api.html#res.locals) object.
3
+ *
4
+ * ::: tip
5
+ * Locals are generally used by express and third-party like templating engine to render a page/template.
6
+ * See [Templating](http://tsed.io/tutorials/templating.html) section for more details.
7
+ * :::
8
+ *
9
+ * #### Example
10
+ *
11
+ * ```typescript
12
+ * * @Middleware()
13
+ * class LocalsMiddleware {
14
+ * use(@Locals() locals: any) {
15
+ * // set some on locals
16
+ * locals.user = "user"
17
+ * }
18
+ * }
19
+ *
20
+ * @Controller('/')
21
+ * @UseBefore(LocalsMiddleware)
22
+ * class MyCtrl {
23
+ * @Get('/')
24
+ * @View('home.ejs') // will use locals and returned data to render the page
25
+ * get(@Locals('user') user: any) {
26
+ * console.log('user', user);
27
+ *
28
+ * return {
29
+ * description: 'Hello world'
30
+ * }
31
+ * }
32
+ * }
33
+ * ```
34
+ *
35
+ * @param expression The path of the property to get.
36
+ * @decorator
37
+ * @operation
38
+ * @input
39
+ * @response
40
+ */
41
+ export declare function Locals(expression: string): ParameterDecorator;
42
+ export declare function Locals(): ParameterDecorator;
@@ -0,0 +1,11 @@
1
+ import { DecoratorParameters } from "@tsed/core";
2
+ import { JsonParameterStore } from "@tsed/schema";
3
+ /**
4
+ * Get the Param metadata. Use this decorator to compose your own decorator.
5
+ *
6
+ * @param fn
7
+ * @decorator
8
+ * @operation
9
+ * @input
10
+ */
11
+ export declare function ParamFn(fn: (param: JsonParameterStore, parameters: DecoratorParameters) => void): ParameterDecorator;
@@ -0,0 +1,70 @@
1
+ import { Type } from "@tsed/core";
2
+ import { ParamOptions } from "../domain/ParamOptions.js";
3
+ /**
4
+ * PathParams return the value from [request.params](http://expressjs.com/en/4x/api.html#req.params) object.
5
+ *
6
+ * #### Example
7
+ *
8
+ * ```typescript
9
+ * @Controller('/')
10
+ * class MyCtrl {
11
+ * @Get('/')
12
+ * get(@PathParams() params: any) {
13
+ * console.log('Entire params', params);
14
+ * }
15
+ *
16
+ * @Get('/')
17
+ * get(@PathParams('id') id: string) {
18
+ * console.log('ID', id);
19
+ * }
20
+ *
21
+ * @Get('/')
22
+ * get(@PathParams({expression: 'id', useType: () => new MyCustomModel() }) id: string) {
23
+ * console.log('ID', id);
24
+ * }
25
+ * }
26
+ * ```
27
+ * > For more information on deserialization see [converters](/docs/json-mapper.md) page.
28
+ *
29
+ * @param expression The path of the property to get.
30
+ * @param useType The type of the class that to be used to deserialize the data.
31
+ * @decorator
32
+ * @operation
33
+ * @input
34
+ */
35
+ export declare function PathParams(expression: string, useType: Type<any>): ParameterDecorator;
36
+ export declare function PathParams(expression: string): ParameterDecorator;
37
+ export declare function PathParams(useType: Type<any>): ParameterDecorator;
38
+ export declare function PathParams(options: Partial<ParamOptions>): ParameterDecorator;
39
+ export declare function PathParams(): ParameterDecorator;
40
+ /**
41
+ * RawPathParams return the raw value from [request.params](http://expressjs.com/en/4x/api.html#req.params) object.
42
+ *
43
+ * Any validation and transformation are performed on the value. Use [pipes](/docs/pipes.html) to validate and/or transform the value.
44
+ *
45
+ * #### Example
46
+ *
47
+ * ```typescript
48
+ * @Controller('/')
49
+ * class MyCtrl {
50
+ * @Get('/')
51
+ * get(@RawPathParams() params: string) {
52
+ * console.log('Entire params', params);
53
+ * }
54
+ *
55
+ * @Get('/')
56
+ * get(@RawPathParams('id') id: string) {
57
+ * console.log('ID', id);
58
+ * }
59
+ * }
60
+ * ```
61
+ * > For more information on deserialization see [converters](/docs/json-mapper.md) page.
62
+ *
63
+ * @param expression The path of the property to get.
64
+ * @decorator
65
+ * @operation
66
+ * @input
67
+ */
68
+ export declare function RawPathParams(expression: string): ParameterDecorator;
69
+ export declare function RawPathParams(options: Partial<ParamOptions>): ParameterDecorator;
70
+ export declare function RawPathParams(): ParameterDecorator;
@@ -0,0 +1,75 @@
1
+ import { Type } from "@tsed/core";
2
+ import { ParamOptions } from "../domain/ParamOptions.js";
3
+ /**
4
+ * QueryParams return the value from [request.query](http://expressjs.com/en/4x/api.html#req.query) object.
5
+ *
6
+ * #### Example
7
+ *
8
+ * ```typescript
9
+ * @Controller('/')
10
+ * class MyCtrl {
11
+ * @Get('/')
12
+ * get(@QueryParams() query: any) {
13
+ * console.log('Entire query', query);
14
+ * }
15
+ *
16
+ * @Get('/')
17
+ * get(@QueryParams('id') id: string) {
18
+ * console.log('ID', id);
19
+ * }
20
+ *
21
+ * @Get('/')
22
+ * get(@QueryParams('user') user: User) { // with deserialization
23
+ * console.log('user', user);
24
+ * }
25
+ *
26
+ * @Get('/')
27
+ * get(@QueryParams('users', User) users: User[]) { // with deserialization
28
+ * console.log('users', users);
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 declare function QueryParams(expression: string, useType: Type<any>): ParameterDecorator;
41
+ export declare function QueryParams(expression: string): ParameterDecorator;
42
+ export declare function QueryParams(useType: Type<any>): ParameterDecorator;
43
+ export declare function QueryParams(options: Partial<ParamOptions>): ParameterDecorator;
44
+ export declare function QueryParams(): ParameterDecorator;
45
+ /**
46
+ * RawQueryParams return the value from [request.query](http://expressjs.com/en/4x/api.html#req.query) object.
47
+ *
48
+ * Any validation and transformation are performed on the value. Use [pipes](/docs/pipes.html) to validate and/or transform the value.
49
+ *
50
+ * #### Example
51
+ *
52
+ * ```typescript
53
+ * @Controller('/')
54
+ * class MyCtrl {
55
+ * @Get('/')
56
+ * get(@RawPathParams() params: any) {
57
+ * console.log('Entire params', params);
58
+ * }
59
+ *
60
+ * @Get('/')
61
+ * get(@RawPathParams('id') id: string) {
62
+ * console.log('ID', id);
63
+ * }
64
+ * }
65
+ * ```
66
+ * > For more information on deserialization see [converters](/docs/json-mapper.md) page.
67
+ *
68
+ * @param expression The path of the property to get.
69
+ * @decorator
70
+ * @operation
71
+ * @input
72
+ */
73
+ export declare function RawQueryParams(expression: string): ParameterDecorator;
74
+ export declare function RawQueryParams(options: Partial<ParamOptions>): ParameterDecorator;
75
+ export declare function RawQueryParams(): ParameterDecorator;
@@ -0,0 +1,36 @@
1
+ import { ParamOptions } from "../domain/ParamOptions.js";
2
+ /**
3
+ * Session return the value from [request.session](http://expressjs.com/en/4x/api.html#req.session) object.
4
+ *
5
+ * #### Example
6
+ *
7
+ * ```typescript
8
+ * @Controller('/')
9
+ * class MyCtrl {
10
+ * @Post('/')
11
+ * create(@Session() session: Express.Session) {
12
+ * console.log('Entire session', session);
13
+ * }
14
+ *
15
+ * @Post('/')
16
+ * create(@Session('id') id: string) {
17
+ * console.log('ID', id);
18
+ * }
19
+ *
20
+ * @Post('/') // Example to deserialize use from session
21
+ * create(@Session({expression: 'user', useMapper: true}) user: User) {
22
+ * console.log('user', user);
23
+ * console.log('instanceOf user', user instanceof User);
24
+ * }
25
+ * }
26
+ * ```
27
+ * > For more information on deserialization see [converters](/docs/json-mapper.md) page.
28
+ *
29
+ * @param expression The path of the property to get.
30
+ * @decorator
31
+ * @operation
32
+ * @input
33
+ */
34
+ export declare function Session(expression: string): ParameterDecorator;
35
+ export declare function Session(options: Partial<ParamOptions>): ParameterDecorator;
36
+ export declare function Session(): ParameterDecorator;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Use JsonMapper to deserialize the data.
3
+ *
4
+ * @decorator
5
+ * @operation
6
+ * @input
7
+ * @pipe
8
+ */
9
+ export declare function UseDeserialization(options?: any): ParameterDecorator;
@@ -0,0 +1,18 @@
1
+ import { ParamOptions } from "../domain/ParamOptions.js";
2
+ /**
3
+ * Register a new param. It uses the paramType to extract value and give it to the next pipe.
4
+ *
5
+ * Given options allow to enable or disable following pipes:
6
+ *
7
+ * - useType: Add extra type for the json mapper,
8
+ * - expression: Get property from the returned value by the previous pipe.
9
+ * - useValidation: Apply validation from the returned value by the previous pipe.
10
+ * - useMapper: Apply json mapper from the returned value by the previous pipe.
11
+ *
12
+ * @param options
13
+ * @decorator
14
+ * @operation
15
+ * @input
16
+ * @pipe
17
+ */
18
+ export declare function UseParam(options: Partial<ParamOptions>): ParameterDecorator;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Get data from a path inside the given object
3
+ *
4
+ * @param expression
5
+ * @decorator
6
+ * @operation
7
+ * @input
8
+ * @pipe
9
+ */
10
+ export declare function UseParamExpression(expression?: string): ParameterDecorator;
@@ -0,0 +1,10 @@
1
+ import { ParamOptions } from "../domain/ParamOptions.js";
2
+ /**
3
+ * Get the object from request (like body, params, query, etc...).
4
+ *
5
+ * @decorator
6
+ * @operation
7
+ * @input
8
+ * @pipe
9
+ */
10
+ export declare function UseParamType(options: ParamOptions): any;
@@ -0,0 +1,13 @@
1
+ import { Type } from "@tsed/core";
2
+ import { PipeMethods } from "@tsed/schema";
3
+ /**
4
+ * Register a Pipe to be used with the current decorated param.
5
+ *
6
+ * @param token
7
+ * @param options
8
+ * @decorator
9
+ * @operation
10
+ * @input
11
+ * @pipe
12
+ */
13
+ export declare function UsePipe(token: Type<PipeMethods>, options?: any): ParameterDecorator;
@@ -0,0 +1,13 @@
1
+ import { Type } from "@tsed/core";
2
+ /**
3
+ * Set the type of the item collection.
4
+ *
5
+ * Prefer @@CollectionOf@@ usage.
6
+ *
7
+ * @param useType
8
+ * @decorator
9
+ * @operation
10
+ * @input
11
+ * @alias CollectionOf
12
+ */
13
+ export declare function UseType(useType: undefined | any | Type<any>): ParameterDecorator;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Enable validation on the decoratored parameter.
3
+ *
4
+ * @decorator
5
+ * @operation
6
+ * @input
7
+ * @pipe
8
+ */
9
+ export declare function UseValidation(): ParameterDecorator;
@@ -0,0 +1 @@
1
+ export { ParamMetadata } from "@tsed/schema";
@@ -0,0 +1,10 @@
1
+ import { Type } from "@tsed/core";
2
+ export interface ParamOptions<T = any> {
3
+ dataPath: string;
4
+ paramType: string;
5
+ expression?: string;
6
+ useType?: Type<T>;
7
+ useMapper?: boolean;
8
+ useValidation?: boolean;
9
+ [key: string]: any;
10
+ }
@@ -0,0 +1,25 @@
1
+ export declare enum ParamTypes {
2
+ $CTX = "$CTX",
3
+ BODY = "BODY",
4
+ PATH = "PATH",
5
+ QUERY = "QUERY",
6
+ HEADER = "HEADER",
7
+ RAW_BODY = "RAW_BODY",
8
+ COOKIES = "COOKIES",
9
+ LOCALS = "LOCALS",
10
+ SESSION = "SESSION",
11
+ FILES = "FILES",
12
+ NEXT_FN = "NEXT_FN",
13
+ ERR = "ERR",
14
+ REQUEST = "REQUEST",
15
+ PLATFORM_REQUEST = "PLATFORM_REQUEST",
16
+ NODE_REQUEST = "NODE_REQUEST",
17
+ RESPONSE = "RESPONSE",
18
+ PLATFORM_RESPONSE = "PLATFORM_RESPONSE",
19
+ NODE_RESPONSE = "NODE_RESPONSE",
20
+ RESPONSE_DATA = "RESPONSE_DATA",
21
+ ENDPOINT_INFO = "ENDPOINT_INFO",
22
+ RES = "RES",
23
+ REQ = "REQ"
24
+ }
25
+ export declare const PARAM_TYPES_DATA_PATH: Record<string, string>;
@@ -0,0 +1,8 @@
1
+ import { BadRequest } from "@tsed/exceptions";
2
+ import { JsonParameterStore } from "@tsed/schema";
3
+ export declare class ParamValidationError extends BadRequest {
4
+ name: string;
5
+ dataPath: string;
6
+ requestType: string;
7
+ static from(metadata: JsonParameterStore, origin?: any): any;
8
+ }
@@ -0,0 +1,6 @@
1
+ import { ValidationError } from "./ValidationError.js";
2
+ import { JsonParameterStore } from "@tsed/schema";
3
+ export declare class RequiredValidationError extends ValidationError {
4
+ name: string;
5
+ static from(metadata: JsonParameterStore): RequiredValidationError;
6
+ }
@@ -0,0 +1,6 @@
1
+ import { BadRequest } from "@tsed/exceptions";
2
+ export declare class ValidationError extends BadRequest {
3
+ name: string;
4
+ errors: any[];
5
+ constructor(message: string, errors?: any[]);
6
+ }
@@ -0,0 +1 @@
1
+ export { PipeMethods } from "@tsed/schema";
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @file Automatically generated by @tsed/barrels.
3
+ */
4
+ export * from "./builder/PlatformParams.js";
5
+ export * from "./decorators/bodyParams.js";
6
+ export * from "./decorators/context.js";
7
+ export * from "./decorators/cookies.js";
8
+ export * from "./decorators/headerParams.js";
9
+ export * from "./decorators/locals.js";
10
+ export * from "./decorators/paramFn.js";
11
+ export * from "./decorators/pathParams.js";
12
+ export * from "./decorators/queryParams.js";
13
+ export * from "./decorators/session.js";
14
+ export * from "./decorators/useDeserialization.js";
15
+ export * from "./decorators/useParam.js";
16
+ export * from "./decorators/useParamExpression.js";
17
+ export * from "./decorators/useParamType.js";
18
+ export * from "./decorators/usePipe.js";
19
+ export * from "./decorators/useType.js";
20
+ export * from "./decorators/useValidation.js";
21
+ export * from "./domain/ParamMetadata.js";
22
+ export * from "./domain/ParamOptions.js";
23
+ export * from "./domain/ParamTypes.js";
24
+ export * from "./errors/ParamValidationError.js";
25
+ export * from "./errors/RequiredValidationError.js";
26
+ export * from "./errors/ValidationError.js";
27
+ export * from "./exports.js";
28
+ export * from "./pipes/DeserializerPipe.js";
29
+ export * from "./pipes/ParseExpressionPipe.js";
30
+ export * from "./pipes/ValidationPipe.js";
31
+ export * from "./utils/mapParamsOptions.js";
@@ -0,0 +1,4 @@
1
+ import { JsonParameterStore, PipeMethods } from "@tsed/schema";
2
+ export declare class DeserializerPipe implements PipeMethods {
3
+ transform(value: any, param: JsonParameterStore): any;
4
+ }
@@ -0,0 +1,6 @@
1
+ import { JsonParameterStore, PipeMethods } from "@tsed/schema";
2
+ import { PlatformParamsScope } from "../builder/PlatformParams.js";
3
+ export declare class ParseExpressionPipe implements PipeMethods {
4
+ transform(scope: PlatformParamsScope, param: JsonParameterStore): any;
5
+ protected getKey(param: JsonParameterStore): string;
6
+ }
@@ -0,0 +1,12 @@
1
+ import { JsonParameterStore, PipeMethods } from "@tsed/schema";
2
+ export type ValidatorServiceMethods = {
3
+ validate(value: any, options: any): Promise<any>;
4
+ };
5
+ export declare class ValidationPipe implements PipeMethods {
6
+ private validator;
7
+ constructor(validators: ValidatorServiceMethods[]);
8
+ coerceTypes(value: any, metadata: JsonParameterStore): any;
9
+ skip(value: any, metadata: JsonParameterStore): boolean;
10
+ transform(value: any, metadata: JsonParameterStore): Promise<any>;
11
+ protected checkIsRequired(value: any, metadata: JsonParameterStore): boolean;
12
+ }
@@ -0,0 +1,5 @@
1
+ import { ParamOptions } from "../domain/ParamOptions.js";
2
+ /**
3
+ * @ignore
4
+ */
5
+ export declare function mapParamsOptions(args: any[]): Partial<ParamOptions<any>>;
package/package.json CHANGED
@@ -1,43 +1,47 @@
1
1
  {
2
2
  "name": "@tsed/platform-params",
3
- "version": "7.79.3",
4
3
  "description": "Params module for Ts.ED Framework",
4
+ "type": "commonjs",
5
+ "version": "7.80.0",
5
6
  "source": "./src/index.ts",
6
7
  "main": "./lib/cjs/index.js",
7
8
  "module": "./lib/esm/index.js",
8
9
  "typings": "./lib/types/index.d.ts",
9
10
  "exports": {
10
- "types": "./lib/types/index.d.ts",
11
- "import": "./lib/esm/index.js",
12
- "require": "./lib/cjs/index.js",
13
- "default": "./lib/esm/index.js"
11
+ ".": {
12
+ "types": "./lib/types/index.d.ts",
13
+ "import": "./lib/esm/index.js",
14
+ "default": "./lib/cjs/index.js"
15
+ }
14
16
  },
15
17
  "scripts": {
16
18
  "build": "yarn barrels && yarn build:ts",
17
19
  "barrels": "barrels",
18
- "test": "jest --max-workers=2 && jest-coverage-thresholds-bumper",
19
- "build:ts": "tsc --build tsconfig.json && tsc --build tsconfig.esm.json"
20
+ "test": "vitest run",
21
+ "build:ts": "tsc --build tsconfig.json",
22
+ "test:ci": "vitest run --coverage.thresholds.autoUpdate=true"
20
23
  },
21
24
  "dependencies": {
22
25
  "tslib": "2.6.1"
23
26
  },
24
27
  "devDependencies": {
25
- "@tsed/barrels": "7.79.3",
26
- "@tsed/core": "7.79.3",
27
- "@tsed/di": "7.79.3",
28
- "@tsed/exceptions": "7.79.3",
29
- "@tsed/json-mapper": "7.79.3",
30
- "@tsed/schema": "7.79.3",
31
- "@tsed/typescript": "7.79.3",
28
+ "@tsed/barrels": "7.80.0",
29
+ "@tsed/core": "7.80.0",
30
+ "@tsed/di": "7.80.0",
31
+ "@tsed/exceptions": "7.80.0",
32
+ "@tsed/json-mapper": "7.80.0",
33
+ "@tsed/schema": "7.80.0",
34
+ "@tsed/typescript": "7.80.0",
32
35
  "eslint": "^8.57.0",
33
- "jest": "^29.7.0"
36
+ "typescript": "4.9.5",
37
+ "vitest": "2.0.4"
34
38
  },
35
39
  "peerDependencies": {
36
- "@tsed/core": "7.79.3",
37
- "@tsed/di": "7.79.3",
38
- "@tsed/exceptions": "7.79.3",
39
- "@tsed/json-mapper": "7.79.3",
40
- "@tsed/schema": "7.79.3"
40
+ "@tsed/core": "7.80.0",
41
+ "@tsed/di": "7.80.0",
42
+ "@tsed/exceptions": "7.80.0",
43
+ "@tsed/json-mapper": "7.80.0",
44
+ "@tsed/schema": "7.80.0"
41
45
  },
42
46
  "peerDependenciesMeta": {
43
47
  "@tsed/core": {
@@ -0,0 +1,21 @@
1
+ // @ts-ignore
2
+ import {presets} from "@tsed/vitest/presets";
3
+ import {defineConfig} from "vitest/config";
4
+
5
+ export default defineConfig(
6
+ {
7
+ ...presets,
8
+ test: {
9
+ ...presets.test,
10
+ coverage: {
11
+ ...presets.test.coverage,
12
+ thresholds: {
13
+ statements: 0,
14
+ branches: 0,
15
+ functions: 0,
16
+ lines: 0
17
+ }
18
+ }
19
+ }
20
+ }
21
+ );
package/jest.config.js DELETED
@@ -1,14 +0,0 @@
1
- // For a detailed explanation regarding each configuration property, visit:
2
- // https://jestjs.io/docs/en/configuration.html
3
-
4
- module.exports = {
5
- ...require("@tsed/jest-config"),
6
- coverageThreshold: {
7
- global: {
8
- statements: 99.81,
9
- branches: 92.37,
10
- functions: 100,
11
- lines: 99.81
12
- }
13
- }
14
- };
@@ -1,3 +0,0 @@
1
- {
2
- "type": "commonjs"
3
- }
@@ -1,3 +0,0 @@
1
- {
2
- "type": "module"
3
- }
package/tsconfig.esm.json DELETED
@@ -1,45 +0,0 @@
1
- {
2
- "extends": "@tsed/typescript/tsconfig.node.json",
3
- "compilerOptions": {
4
- "baseUrl": ".",
5
- "module": "ES2020",
6
- "rootDir": "src",
7
- "outDir": "./lib/esm",
8
- "declaration": true,
9
- "declarationDir": "./lib/types",
10
- "composite": true,
11
- "noEmit": false
12
- },
13
- "include": ["src", "src/**/*.json"],
14
- "exclude": [
15
- "node_modules",
16
- "test",
17
- "lib",
18
- "benchmark",
19
- "coverage",
20
- "spec",
21
- "**/*.benchmark.ts",
22
- "**/*.spec.ts",
23
- "keys",
24
- "jest.config.js",
25
- "**/__mock__/**",
26
- "webpack.config.js"
27
- ],
28
- "references": [
29
- {
30
- "path": "../../core"
31
- },
32
- {
33
- "path": "../../di"
34
- },
35
- {
36
- "path": "../../specs/exceptions"
37
- },
38
- {
39
- "path": "../../specs/json-mapper"
40
- },
41
- {
42
- "path": "../../specs/schema"
43
- }
44
- ]
45
- }