@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.
Files changed (107) hide show
  1. package/lib/esm/builder/PlatformParams.js +0 -1
  2. package/lib/esm/decorators/bodyParams.js +0 -1
  3. package/lib/esm/decorators/context.js +0 -1
  4. package/lib/esm/decorators/cookies.js +0 -1
  5. package/lib/esm/decorators/headerParams.js +0 -1
  6. package/lib/esm/decorators/locals.js +0 -1
  7. package/lib/esm/decorators/paramFn.js +0 -1
  8. package/lib/esm/decorators/pathParams.js +0 -1
  9. package/lib/esm/decorators/queryParams.js +0 -1
  10. package/lib/esm/decorators/session.js +0 -1
  11. package/lib/esm/decorators/useDeserialization.js +0 -1
  12. package/lib/esm/decorators/useParam.js +0 -1
  13. package/lib/esm/decorators/useParamExpression.js +0 -1
  14. package/lib/esm/decorators/useParamType.js +0 -1
  15. package/lib/esm/decorators/usePipe.js +0 -1
  16. package/lib/esm/decorators/useType.js +0 -1
  17. package/lib/esm/decorators/useValidation.js +0 -1
  18. package/lib/esm/domain/ParamMetadata.js +0 -1
  19. package/lib/esm/domain/ParamOptions.js +0 -1
  20. package/lib/esm/domain/ParamTypes.js +0 -1
  21. package/lib/esm/errors/ParamValidationError.js +0 -1
  22. package/lib/esm/errors/RequiredValidationError.js +0 -1
  23. package/lib/esm/errors/ValidationError.js +0 -1
  24. package/lib/esm/exports.js +0 -1
  25. package/lib/esm/index.js +0 -1
  26. package/lib/esm/pipes/DeserializerPipe.js +0 -1
  27. package/lib/esm/pipes/ParseExpressionPipe.js +0 -1
  28. package/lib/esm/pipes/ValidationPipe.js +0 -1
  29. package/lib/esm/utils/mapParamsOptions.js +0 -1
  30. package/package.json +12 -9
  31. package/lib/esm/builder/PlatformParams.js.map +0 -1
  32. package/lib/esm/decorators/bodyParams.js.map +0 -1
  33. package/lib/esm/decorators/context.js.map +0 -1
  34. package/lib/esm/decorators/cookies.js.map +0 -1
  35. package/lib/esm/decorators/headerParams.js.map +0 -1
  36. package/lib/esm/decorators/locals.js.map +0 -1
  37. package/lib/esm/decorators/paramFn.js.map +0 -1
  38. package/lib/esm/decorators/pathParams.js.map +0 -1
  39. package/lib/esm/decorators/queryParams.js.map +0 -1
  40. package/lib/esm/decorators/session.js.map +0 -1
  41. package/lib/esm/decorators/useDeserialization.js.map +0 -1
  42. package/lib/esm/decorators/useParam.js.map +0 -1
  43. package/lib/esm/decorators/useParamExpression.js.map +0 -1
  44. package/lib/esm/decorators/useParamType.js.map +0 -1
  45. package/lib/esm/decorators/usePipe.js.map +0 -1
  46. package/lib/esm/decorators/useType.js.map +0 -1
  47. package/lib/esm/decorators/useValidation.js.map +0 -1
  48. package/lib/esm/domain/ParamMetadata.js.map +0 -1
  49. package/lib/esm/domain/ParamOptions.js.map +0 -1
  50. package/lib/esm/domain/ParamTypes.js.map +0 -1
  51. package/lib/esm/errors/ParamValidationError.js.map +0 -1
  52. package/lib/esm/errors/RequiredValidationError.js.map +0 -1
  53. package/lib/esm/errors/ValidationError.js.map +0 -1
  54. package/lib/esm/exports.js.map +0 -1
  55. package/lib/esm/index.js.map +0 -1
  56. package/lib/esm/pipes/DeserializerPipe.js.map +0 -1
  57. package/lib/esm/pipes/ParseExpressionPipe.js.map +0 -1
  58. package/lib/esm/pipes/ValidationPipe.js.map +0 -1
  59. package/lib/esm/utils/mapParamsOptions.js.map +0 -1
  60. package/src/builder/PlatformParams.spec.ts +0 -431
  61. package/src/builder/PlatformParams.ts +0 -92
  62. package/src/decorators/__snapshots__/bodyParams.spec.ts.snap +0 -105
  63. package/src/decorators/bodyParams.spec.ts +0 -432
  64. package/src/decorators/bodyParams.ts +0 -93
  65. package/src/decorators/context.spec.ts +0 -16
  66. package/src/decorators/context.ts +0 -70
  67. package/src/decorators/cookies.spec.ts +0 -19
  68. package/src/decorators/cookies.ts +0 -102
  69. package/src/decorators/headerParams.spec.ts +0 -16
  70. package/src/decorators/headerParams.ts +0 -49
  71. package/src/decorators/locals.spec.ts +0 -16
  72. package/src/decorators/locals.ts +0 -57
  73. package/src/decorators/paramFn.ts +0 -14
  74. package/src/decorators/pathParams.spec.ts +0 -58
  75. package/src/decorators/pathParams.ts +0 -97
  76. package/src/decorators/queryParams.spec.ts +0 -58
  77. package/src/decorators/queryParams.ts +0 -102
  78. package/src/decorators/session.spec.ts +0 -47
  79. package/src/decorators/session.ts +0 -51
  80. package/src/decorators/useDeserialization.ts +0 -14
  81. package/src/decorators/useParam.spec.ts +0 -82
  82. package/src/decorators/useParam.ts +0 -38
  83. package/src/decorators/useParamExpression.ts +0 -16
  84. package/src/decorators/useParamType.ts +0 -36
  85. package/src/decorators/usePipe.ts +0 -21
  86. package/src/decorators/useType.ts +0 -35
  87. package/src/decorators/useValidation.ts +0 -18
  88. package/src/domain/ParamMetadata.ts +0 -1
  89. package/src/domain/ParamOptions.ts +0 -12
  90. package/src/domain/ParamTypes.ts +0 -37
  91. package/src/errors/ParamValidationError.spec.ts +0 -152
  92. package/src/errors/ParamValidationError.ts +0 -38
  93. package/src/errors/RequiredValidationError.spec.ts +0 -49
  94. package/src/errors/RequiredValidationError.ts +0 -30
  95. package/src/errors/ValidationError.spec.ts +0 -18
  96. package/src/errors/ValidationError.ts +0 -11
  97. package/src/exports.ts +0 -1
  98. package/src/index.ts +0 -31
  99. package/src/pipes/DeserializerPipe.spec.ts +0 -39
  100. package/src/pipes/DeserializerPipe.ts +0 -15
  101. package/src/pipes/ParseExpressionPipe.spec.ts +0 -242
  102. package/src/pipes/ParseExpressionPipe.ts +0 -33
  103. package/src/pipes/ValidationPipe.spec.ts +0 -645
  104. package/src/pipes/ValidationPipe.ts +0 -112
  105. package/src/utils/mapParamsOptions.spec.ts +0 -28
  106. package/src/utils/mapParamsOptions.ts +0 -34
  107. package/vitest.config.mts +0 -21
@@ -1,82 +0,0 @@
1
- import {Description, Example, Get, getSpec, JsonParameterStore, Property, Required, SpecTypes, Title} from "@tsed/schema";
2
-
3
- import {ParamTypes} from "../domain/ParamTypes.js";
4
- import {QueryParams} from "./queryParams.js";
5
- import {UseParam} from "./useParam.js";
6
-
7
- export class MyModel {
8
- @Title("iD")
9
- @Description("Description of calendar model id")
10
- @Example("Description example")
11
- @Property()
12
- public id: string;
13
-
14
- @Property()
15
- @Required()
16
- public name: string;
17
- }
18
-
19
- describe("@UseParam", () => {
20
- describe("when use a param", () => {
21
- it("should create useParam", () => {
22
- class Test {}
23
-
24
- class Ctrl {
25
- test(
26
- @UseParam({
27
- expression: "expression",
28
- useMapper: true,
29
- useValidation: true,
30
- paramType: ParamTypes.BODY,
31
- useType: Test
32
- })
33
- body: Test
34
- ) {}
35
- }
36
-
37
- const param = JsonParameterStore.get(Ctrl, "test", 0);
38
- expect(param.expression).toEqual("expression");
39
- expect(param.paramType).toEqual(ParamTypes.BODY);
40
- expect(param.type).toEqual(Test);
41
- });
42
- });
43
- describe("when is a Query param with boolean", () => {
44
- it("should return the right spec", () => {
45
- class Ctrl {
46
- @Get("/")
47
- get(@QueryParams("test") value: boolean) {}
48
- }
49
-
50
- const spec = getSpec(Ctrl, {specType: SpecTypes.OPENAPI});
51
-
52
- expect(spec).toEqual({
53
- paths: {
54
- "/": {
55
- get: {
56
- operationId: "ctrlGet",
57
- parameters: [
58
- {
59
- in: "query",
60
- name: "test",
61
- required: false,
62
- schema: {type: "boolean"}
63
- }
64
- ],
65
- responses: {
66
- "200": {
67
- description: "Success"
68
- }
69
- },
70
- tags: ["Ctrl"]
71
- }
72
- }
73
- },
74
- tags: [
75
- {
76
- name: "Ctrl"
77
- }
78
- ]
79
- });
80
- });
81
- });
82
- });
@@ -1,38 +0,0 @@
1
- import {useDecorators} from "@tsed/core";
2
-
3
- import {ParamOptions} from "../domain/ParamOptions.js";
4
- import {ParamTypes} from "../domain/ParamTypes.js";
5
- import {UseDeserialization} from "./useDeserialization.js";
6
- import {UseParamType} from "./useParamType.js";
7
- import {UseType} from "./useType.js";
8
- import {UseValidation} from "./useValidation.js";
9
-
10
- /**
11
- * @ignore
12
- * @param options
13
- */
14
- function mapPipes(options: Partial<ParamOptions>) {
15
- const {paramType, useType, expression, useValidation, useMapper, ...props} = options;
16
-
17
- return [paramType !== ParamTypes.FILES && UseType(useType), useValidation && UseValidation(), useMapper && UseDeserialization(props)];
18
- }
19
-
20
- /**
21
- * Register a new param. It uses the paramType to extract value and give it to the next pipe.
22
- *
23
- * Given options allow to enable or disable following pipes:
24
- *
25
- * - useType: Add extra type for the json mapper,
26
- * - expression: Get property from the returned value by the previous pipe.
27
- * - useValidation: Apply validation from the returned value by the previous pipe.
28
- * - useMapper: Apply json mapper from the returned value by the previous pipe.
29
- *
30
- * @param options
31
- * @decorator
32
- * @operation
33
- * @input
34
- * @pipe
35
- */
36
- export function UseParam(options: Partial<ParamOptions>): ParameterDecorator {
37
- return useDecorators(UseParamType(options as any), ...mapPipes(options)) as ParameterDecorator;
38
- }
@@ -1,16 +0,0 @@
1
- import {ParamFn} from "./paramFn.js";
2
-
3
- /**
4
- * Get data from a path inside the given object
5
- *
6
- * @param expression
7
- * @decorator
8
- * @operation
9
- * @input
10
- * @pipe
11
- */
12
- export function UseParamExpression(expression?: string) {
13
- return ParamFn((param) => {
14
- param.expression = expression || "";
15
- });
16
- }
@@ -1,36 +0,0 @@
1
- import {isBuffer, useDecorators} from "@tsed/core";
2
- import {isParameterType, Name} from "@tsed/schema";
3
-
4
- import {ParamOptions} from "../domain/ParamOptions.js";
5
- import {PARAM_TYPES_DATA_PATH, ParamTypes} from "../domain/ParamTypes.js";
6
- import {ParamFn} from "./paramFn.js";
7
- import {UseParamExpression} from "./useParamExpression.js";
8
-
9
- /**
10
- * Get the object from request (like body, params, query, etc...).
11
- *
12
- * @decorator
13
- * @operation
14
- * @input
15
- * @pipe
16
- */
17
- export function UseParamType(options: ParamOptions) {
18
- return useDecorators(
19
- ParamFn((param) => {
20
- if (isParameterType(options.paramType)) {
21
- param.parameter!.in(options.paramType);
22
- }
23
-
24
- param.paramType = options.paramType;
25
-
26
- if (isBuffer(param.type) || isBuffer(options.useType) || options.paramType === ParamTypes.RAW_BODY) {
27
- param.paramType = ParamTypes.RAW_BODY;
28
- param.parent.operation?.consumes(["*/*"]);
29
- }
30
-
31
- param.dataPath = options.dataPath || PARAM_TYPES_DATA_PATH[param.paramType] || "$ctx";
32
- }),
33
- options.expression && UseParamExpression(options.expression),
34
- options.expression && Name(options.expression)
35
- );
36
- }
@@ -1,21 +0,0 @@
1
- import {Type} from "@tsed/core";
2
- import {PipeMethods} from "@tsed/schema";
3
-
4
- import {ParamFn} from "./paramFn.js";
5
-
6
- /**
7
- * Register a Pipe to be used with the current decorated param.
8
- *
9
- * @param token
10
- * @param options
11
- * @decorator
12
- * @operation
13
- * @input
14
- * @pipe
15
- */
16
- export function UsePipe(token: Type<PipeMethods>, options: any = {}) {
17
- return ParamFn((param) => {
18
- param.store.set(token, options);
19
- param.pipes.push(token);
20
- });
21
- }
@@ -1,35 +0,0 @@
1
- import {Type} from "@tsed/core";
2
- import {Any, CollectionOf, type JsonParameterStore} from "@tsed/schema";
3
-
4
- import {ParamFn} from "./paramFn.js";
5
-
6
- function shouldFallBackToAny(entity: JsonParameterStore) {
7
- if (entity.itemSchema.has("allOf") || entity.itemSchema.has("anyOf") || entity.itemSchema.has("oneOf")) {
8
- return false;
9
- }
10
-
11
- return entity.isCollection && entity.type === Object && [undefined, "object"].includes(entity.itemSchema.get("type"));
12
- }
13
-
14
- /**
15
- * Set the type of the item collection.
16
- *
17
- * Prefer @@CollectionOf@@ usage.
18
- *
19
- * @param useType
20
- * @decorator
21
- * @operation
22
- * @input
23
- * @alias CollectionOf
24
- */
25
- export function UseType(useType: undefined | any | Type<any>) {
26
- return ParamFn((entity, parameters) => {
27
- if (useType) {
28
- return CollectionOf(useType);
29
- }
30
-
31
- if (shouldFallBackToAny(entity)) {
32
- Any()(...parameters);
33
- }
34
- });
35
- }
@@ -1,18 +0,0 @@
1
- import {ValidationPipe} from "../pipes/ValidationPipe.js";
2
- import {ParamFn} from "./paramFn.js";
3
-
4
- /**
5
- * Enable validation on the decoratored parameter.
6
- *
7
- * @decorator
8
- * @operation
9
- * @input
10
- * @pipe
11
- */
12
- export function UseValidation() {
13
- return ParamFn((param) => {
14
- if (param.type || param.collectionType) {
15
- param.pipes.push(ValidationPipe);
16
- }
17
- });
18
- }
@@ -1 +0,0 @@
1
- export {ParamMetadata} from "@tsed/schema";
@@ -1,12 +0,0 @@
1
- import {Type} from "@tsed/core";
2
-
3
- export interface ParamOptions<T = any> {
4
- dataPath: string;
5
- paramType: string;
6
- expression?: string;
7
- useType?: Type<T>;
8
- useMapper?: boolean;
9
- useValidation?: boolean;
10
-
11
- [key: string]: any;
12
- }
@@ -1,37 +0,0 @@
1
- export 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
-
13
- /// NOT STD
14
- NEXT_FN = "NEXT_FN",
15
- ERR = "ERR",
16
- REQUEST = "REQUEST",
17
- PLATFORM_REQUEST = "PLATFORM_REQUEST",
18
- NODE_REQUEST = "NODE_REQUEST",
19
- RESPONSE = "RESPONSE",
20
- PLATFORM_RESPONSE = "PLATFORM_RESPONSE",
21
- NODE_RESPONSE = "NODE_RESPONSE",
22
- RESPONSE_DATA = "RESPONSE_DATA",
23
- ENDPOINT_INFO = "ENDPOINT_INFO",
24
- RES = "RES",
25
- REQ = "REQ"
26
- }
27
-
28
- export const PARAM_TYPES_DATA_PATH: Record<string, string> = {
29
- [ParamTypes.HEADER]: "$ctx.request.headers",
30
- [ParamTypes.RAW_BODY]: "$ctx.request.rawBody",
31
- [ParamTypes.BODY]: "$ctx.request.body",
32
- [ParamTypes.QUERY]: "$ctx.request.query",
33
- [ParamTypes.PATH]: "$ctx.request.params",
34
- [ParamTypes.COOKIES]: "$ctx.request.cookies",
35
- [ParamTypes.SESSION]: "$ctx.request.session",
36
- [ParamTypes.LOCALS]: "$ctx.response.locals"
37
- };
@@ -1,152 +0,0 @@
1
- import {ParamValidationError} from "./ParamValidationError.js";
2
- import {RequiredValidationError} from "./RequiredValidationError.js";
3
- import {ValidationError} from "./ValidationError.js";
4
-
5
- describe("ParseExpressionError", () => {
6
- it("should return error without transformation", () => {
7
- expect(ParamValidationError.from({} as any, new Error("error")).message).toEqual("error");
8
- });
9
- it("should return error", () => {
10
- const validationError = new ValidationError("message");
11
-
12
- const error = ParamValidationError.from(
13
- {
14
- paramType: "name",
15
- expression: "expression"
16
- } as any,
17
- validationError
18
- );
19
- expect(error.message).toEqual('Bad request on parameter "request.name.expression".\nmessage');
20
- expect(error.name).toEqual("PARAM_VALIDATION_ERROR");
21
- expect(error.dataPath).toEqual("expression");
22
- expect(error.requestType).toEqual("name");
23
- expect({
24
- name: error.name,
25
- status: error.status,
26
- headers: error.headers,
27
- type: error.type,
28
- message: error.message,
29
- dataPath: error.dataPath,
30
- requestType: error.requestType,
31
- origin: {
32
- name: error.origin.name,
33
- status: error.origin.status,
34
- headers: error.origin.headers,
35
- type: error.origin.type,
36
- message: error.origin.message,
37
- errors: error.origin.errors
38
- }
39
- }).toEqual({
40
- dataPath: "expression",
41
- headers: {},
42
- name: "PARAM_VALIDATION_ERROR",
43
- requestType: "name",
44
- status: 400,
45
- type: "HTTP_EXCEPTION",
46
- message: 'Bad request on parameter "request.name.expression".\nmessage',
47
- origin: {
48
- errors: [],
49
- headers: {},
50
- message: "message",
51
- name: "VALIDATION_ERROR",
52
- status: 400,
53
- type: "HTTP_EXCEPTION"
54
- }
55
- });
56
- });
57
- it("should throw error from origin error (RequiredValidationError)", () => {
58
- const metadata = {
59
- paramType: "name",
60
- expression: "expression"
61
- } as any;
62
- const origin = RequiredValidationError.from(metadata);
63
-
64
- const error = ParamValidationError.from(metadata, origin);
65
- expect(error.message).toEqual("Bad request on parameter \"request.name.expression\".\nIt should have required parameter 'expression'");
66
- expect(error.dataPath).toEqual("expression");
67
- expect(error.requestType).toEqual("name");
68
-
69
- expect({
70
- ...error,
71
- message: error.message,
72
- origin: {
73
- ...error.origin,
74
- message: error.origin.message
75
- }
76
- }).toEqual({
77
- dataPath: "expression",
78
- headers: {},
79
- name: "PARAM_VALIDATION_ERROR",
80
- message: "Bad request on parameter \"request.name.expression\".\nIt should have required parameter 'expression'",
81
- origin: {
82
- errors: [
83
- {
84
- requestPath: "name",
85
- dataPath: ".expression",
86
- keyword: "required",
87
- message: "It should have required parameter 'expression'",
88
- modelName: "name",
89
- params: {
90
- missingProperty: "expression"
91
- },
92
- schemaPath: "#/required"
93
- }
94
- ],
95
- headers: {},
96
- name: "REQUIRED_VALIDATION_ERROR",
97
- message: "It should have required parameter 'expression'",
98
- status: 400,
99
- type: "HTTP_EXCEPTION"
100
- },
101
- requestType: "name",
102
- status: 400,
103
- type: "HTTP_EXCEPTION"
104
- });
105
- });
106
- it("should throw error from origin error (ValidationError)", () => {
107
- const metadata = {
108
- paramType: "name",
109
- expression: "expression"
110
- } as any;
111
- const origin = new ValidationError("It should have 1 item", [
112
- {
113
- dataPath: "hello"
114
- }
115
- ]);
116
-
117
- const error = ParamValidationError.from(metadata, origin);
118
- expect(error.message).toEqual('Bad request on parameter "request.name.expression".\nIt should have 1 item');
119
- expect(error.dataPath).toEqual("expression");
120
- expect(error.requestType).toEqual("name");
121
-
122
- expect({
123
- ...error,
124
- message: error.message,
125
- origin: {
126
- ...error.origin,
127
- message: error.origin.message
128
- }
129
- }).toEqual({
130
- dataPath: "expression",
131
- headers: {},
132
- name: "PARAM_VALIDATION_ERROR",
133
- origin: {
134
- errors: [
135
- {
136
- requestPath: "name",
137
- dataPath: "hello"
138
- }
139
- ],
140
- headers: {},
141
- message: "It should have 1 item",
142
- name: "VALIDATION_ERROR",
143
- status: 400,
144
- type: "HTTP_EXCEPTION"
145
- },
146
- message: 'Bad request on parameter "request.name.expression".\nIt should have 1 item',
147
- requestType: "name",
148
- status: 400,
149
- type: "HTTP_EXCEPTION"
150
- });
151
- });
152
- });
@@ -1,38 +0,0 @@
1
- import {nameOf} from "@tsed/core";
2
- import {BadRequest} from "@tsed/exceptions";
3
- import {JsonParameterStore} from "@tsed/schema";
4
-
5
- import {ValidationError} from "./ValidationError.js";
6
-
7
- export class ParamValidationError extends BadRequest {
8
- public name: string = "PARAM_VALIDATION_ERROR";
9
- public dataPath: string;
10
- public requestType: string;
11
-
12
- static from(metadata: JsonParameterStore, origin: any = {}) {
13
- if (origin instanceof ValidationError || origin instanceof BadRequest) {
14
- const name = nameOf(metadata.paramType)
15
- .toLowerCase()
16
- .replace(/parse|params|filter/gi, "");
17
- const expression = metadata.expression;
18
- const dataPath = `${name}${expression ? "." + expression : ""}`;
19
- const message = `Bad request on parameter "request.${dataPath}".\n${origin.message}`.trim();
20
-
21
- const error = new ParamValidationError(message);
22
- error.dataPath = String(metadata.expression) || "";
23
- error.requestType = nameOf(metadata.paramType);
24
- error.origin = origin.origin || origin;
25
-
26
- if (error.origin?.errors) {
27
- error.origin?.errors.forEach((error: any) => {
28
- error.requestPath = name;
29
- error.dataPath = error.dataPath || (expression ? `.${expression}` : "");
30
- });
31
- }
32
-
33
- return error;
34
- }
35
-
36
- return origin;
37
- }
38
- }
@@ -1,49 +0,0 @@
1
- import {RequiredValidationError} from "./RequiredValidationError.js";
2
-
3
- describe("RequiredValidationError", () => {
4
- it("should have a message", () => {
5
- const error = RequiredValidationError.from({
6
- paramType: "name",
7
- expression: "expression"
8
- } as any);
9
- expect(error.message).toEqual("It should have required parameter 'expression'");
10
- expect(error.name).toEqual("REQUIRED_VALIDATION_ERROR");
11
- expect({
12
- name: error.name,
13
- status: error.status,
14
- headers: error.headers,
15
- type: error.type,
16
- message: error.message,
17
- errors: [
18
- {
19
- dataPath: error.errors[0].dataPath,
20
- keyword: error.errors[0].keyword,
21
- message: error.errors[0].message,
22
- modelName: error.errors[0].modelName,
23
- params: {
24
- missingProperty: error.errors[0].params.missingProperty
25
- },
26
- schemaPath: error.errors[0].schemaPath
27
- }
28
- ]
29
- }).toEqual({
30
- name: "REQUIRED_VALIDATION_ERROR",
31
- status: 400,
32
- headers: {},
33
- type: "HTTP_EXCEPTION",
34
- message: "It should have required parameter 'expression'",
35
- errors: [
36
- {
37
- dataPath: "",
38
- keyword: "required",
39
- message: "It should have required parameter 'expression'",
40
- modelName: "name",
41
- params: {
42
- missingProperty: "expression"
43
- },
44
- schemaPath: "#/required"
45
- }
46
- ]
47
- });
48
- });
49
- });
@@ -1,30 +0,0 @@
1
- import {nameOf} from "@tsed/core";
2
- import {JsonParameterStore} from "@tsed/schema";
3
-
4
- import {ValidationError} from "./ValidationError.js";
5
-
6
- export class RequiredValidationError extends ValidationError {
7
- public name: string = "REQUIRED_VALIDATION_ERROR";
8
-
9
- static from(metadata: JsonParameterStore) {
10
- const name = nameOf(metadata.paramType);
11
- const expression = metadata.expression;
12
- const type = name.toLowerCase().replace(/parse|params|filter/gi, "");
13
- const message = `It should have required parameter '${expression}'`;
14
-
15
- const errors = [
16
- {
17
- dataPath: "",
18
- keyword: "required",
19
- message,
20
- modelName: type,
21
- params: {
22
- missingProperty: expression
23
- },
24
- schemaPath: "#/required"
25
- }
26
- ];
27
-
28
- return new RequiredValidationError(message, errors);
29
- }
30
- }
@@ -1,18 +0,0 @@
1
- import {ValidationError} from "./ValidationError.js";
2
-
3
- describe("ValidationError", () => {
4
- it("should return error", () => {
5
- const error = new ValidationError("should have required property", [
6
- {
7
- dataPath: "hello"
8
- }
9
- ]);
10
-
11
- expect(error.errors).toEqual([
12
- {
13
- dataPath: "hello"
14
- }
15
- ]);
16
- expect(error.message).toEqual("should have required property");
17
- });
18
- });
@@ -1,11 +0,0 @@
1
- import {BadRequest} from "@tsed/exceptions";
2
-
3
- export class ValidationError extends BadRequest {
4
- public name: string = "VALIDATION_ERROR";
5
- public errors: any[];
6
-
7
- constructor(message: string, errors: any[] = []) {
8
- super(message);
9
- this.errors = errors;
10
- }
11
- }
package/src/exports.ts DELETED
@@ -1 +0,0 @@
1
- export {PipeMethods} from "@tsed/schema";
package/src/index.ts DELETED
@@ -1,31 +0,0 @@
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";
@@ -1,39 +0,0 @@
1
- import {PlatformTest} from "@tsed/platform-http/testing";
2
- import {JsonParameterStore} from "@tsed/schema";
3
-
4
- import {BodyParams} from "../decorators/bodyParams.js";
5
- import {QueryParams} from "../decorators/queryParams.js";
6
- import {DeserializerPipe} from "./DeserializerPipe.js";
7
-
8
- describe("DeserializerPipe", () => {
9
- beforeEach(PlatformTest.create);
10
- afterEach(PlatformTest.reset);
11
- it("should transform an object to a model", async () => {
12
- const pipe = await PlatformTest.get<DeserializerPipe>(DeserializerPipe);
13
-
14
- class Test {
15
- test(@BodyParams(String) input: string[]) {}
16
- }
17
-
18
- const param = JsonParameterStore.get(Test, "test", 0);
19
-
20
- // WHEN
21
- const result = pipe.transform(["test"], param);
22
-
23
- expect(result).toEqual(["test"]);
24
- });
25
- it("should transform an object to a model (Query)", async () => {
26
- const pipe = await PlatformTest.get<DeserializerPipe>(DeserializerPipe);
27
-
28
- class Test {
29
- test(@QueryParams("test", String) input: string[]) {}
30
- }
31
-
32
- const param = JsonParameterStore.get(Test, "test", 0);
33
-
34
- // WHEN
35
- const result = pipe.transform(["test"], param);
36
-
37
- expect(result).toEqual(["test"]);
38
- });
39
- });