@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,15 +0,0 @@
|
|
|
1
|
-
import {Injectable, injectable} from "@tsed/di";
|
|
2
|
-
import {deserialize} from "@tsed/json-mapper";
|
|
3
|
-
import {JsonParameterStore, PipeMethods} from "@tsed/schema";
|
|
4
|
-
|
|
5
|
-
export class DeserializerPipe implements PipeMethods {
|
|
6
|
-
transform(value: any, param: JsonParameterStore) {
|
|
7
|
-
return deserialize(value, {
|
|
8
|
-
useAlias: true,
|
|
9
|
-
store: param,
|
|
10
|
-
...(param.store.get(DeserializerPipe) || {})
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
injectable(DeserializerPipe);
|
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
import {DecoratorTypes} from "@tsed/core";
|
|
2
|
-
import {PlatformTest} from "@tsed/platform-http/testing";
|
|
3
|
-
import {JsonParameterStore} from "@tsed/schema";
|
|
4
|
-
|
|
5
|
-
import {ParamTypes} from "../../src/index.js";
|
|
6
|
-
import {ParseExpressionPipe} from "./ParseExpressionPipe.js";
|
|
7
|
-
|
|
8
|
-
describe("ParseExpressionPipe", () => {
|
|
9
|
-
beforeEach(PlatformTest.create);
|
|
10
|
-
beforeEach(PlatformTest.reset);
|
|
11
|
-
it(
|
|
12
|
-
"should parse expression",
|
|
13
|
-
PlatformTest.inject([ParseExpressionPipe], (pipe: ParseExpressionPipe) => {
|
|
14
|
-
// @ts-ignore
|
|
15
|
-
class Test {}
|
|
16
|
-
|
|
17
|
-
const param: any = new JsonParameterStore({
|
|
18
|
-
index: 0,
|
|
19
|
-
target: Test,
|
|
20
|
-
propertyKey: "test",
|
|
21
|
-
expression: "test",
|
|
22
|
-
paramType: ParamTypes.REQUEST,
|
|
23
|
-
dataPath: "$ctx.request",
|
|
24
|
-
decoratorType: DecoratorTypes.PARAM
|
|
25
|
-
});
|
|
26
|
-
// @ts-ignore
|
|
27
|
-
param._type = String;
|
|
28
|
-
param.collectionType = Array;
|
|
29
|
-
|
|
30
|
-
const scope: any = {
|
|
31
|
-
$ctx: {
|
|
32
|
-
request: {
|
|
33
|
-
test: "value"
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
// WHEN
|
|
39
|
-
const value = pipe.transform(scope, param);
|
|
40
|
-
|
|
41
|
-
expect(value).toEqual("value");
|
|
42
|
-
})
|
|
43
|
-
);
|
|
44
|
-
it(
|
|
45
|
-
"should return empty value",
|
|
46
|
-
PlatformTest.inject([ParseExpressionPipe], (pipe: ParseExpressionPipe) => {
|
|
47
|
-
// @ts-ignore
|
|
48
|
-
class Test {}
|
|
49
|
-
|
|
50
|
-
const param: any = new JsonParameterStore({
|
|
51
|
-
index: 0,
|
|
52
|
-
target: Test,
|
|
53
|
-
propertyKey: "test",
|
|
54
|
-
expression: "test",
|
|
55
|
-
paramType: ParamTypes.REQUEST,
|
|
56
|
-
dataPath: "$ctx.request",
|
|
57
|
-
decoratorType: DecoratorTypes.PARAM
|
|
58
|
-
});
|
|
59
|
-
// @ts-ignore
|
|
60
|
-
param._type = String;
|
|
61
|
-
param.collectionType = Array;
|
|
62
|
-
|
|
63
|
-
const scope: any = {
|
|
64
|
-
$ctx: {
|
|
65
|
-
request: {}
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
// WHEN
|
|
70
|
-
const value = pipe.transform(scope, param);
|
|
71
|
-
|
|
72
|
-
expect(value).toEqual(undefined);
|
|
73
|
-
})
|
|
74
|
-
);
|
|
75
|
-
it(
|
|
76
|
-
"should parse expression (for HEADER)",
|
|
77
|
-
PlatformTest.inject([ParseExpressionPipe], (pipe: ParseExpressionPipe) => {
|
|
78
|
-
// @ts-ignore
|
|
79
|
-
class Test {}
|
|
80
|
-
|
|
81
|
-
const param: any = new JsonParameterStore({
|
|
82
|
-
index: 0,
|
|
83
|
-
target: Test,
|
|
84
|
-
propertyKey: "test",
|
|
85
|
-
expression: "Content-Type",
|
|
86
|
-
paramType: ParamTypes.HEADER,
|
|
87
|
-
dataPath: "$ctx.request.headers",
|
|
88
|
-
decoratorType: DecoratorTypes.PARAM
|
|
89
|
-
});
|
|
90
|
-
// @ts-ignore
|
|
91
|
-
param._type = String;
|
|
92
|
-
param.collectionType = Array;
|
|
93
|
-
|
|
94
|
-
const scope: any = {
|
|
95
|
-
$ctx: {
|
|
96
|
-
request: {
|
|
97
|
-
headers: {
|
|
98
|
-
"content-type": "application/json"
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
// WHEN
|
|
104
|
-
const value = pipe.transform(scope, param);
|
|
105
|
-
|
|
106
|
-
expect(value).toEqual("application/json");
|
|
107
|
-
})
|
|
108
|
-
);
|
|
109
|
-
it(
|
|
110
|
-
"should return undefined when value is empty and Boolean (for QUERY)",
|
|
111
|
-
PlatformTest.inject([ParseExpressionPipe], (pipe: ParseExpressionPipe) => {
|
|
112
|
-
// @ts-ignore
|
|
113
|
-
class Test {}
|
|
114
|
-
|
|
115
|
-
const param = new JsonParameterStore({
|
|
116
|
-
index: 0,
|
|
117
|
-
target: Test,
|
|
118
|
-
propertyKey: "test",
|
|
119
|
-
expression: "test",
|
|
120
|
-
paramType: ParamTypes.QUERY,
|
|
121
|
-
dataPath: "$ctx.request.query",
|
|
122
|
-
decoratorType: DecoratorTypes.PARAM
|
|
123
|
-
});
|
|
124
|
-
// @ts-ignore
|
|
125
|
-
param._type = Boolean;
|
|
126
|
-
|
|
127
|
-
const scope: any = {
|
|
128
|
-
$ctx: {
|
|
129
|
-
request: {
|
|
130
|
-
query: {
|
|
131
|
-
test: ""
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
// WHEN
|
|
138
|
-
const value = pipe.transform(scope, param);
|
|
139
|
-
|
|
140
|
-
expect(value).toEqual(undefined);
|
|
141
|
-
})
|
|
142
|
-
);
|
|
143
|
-
it(
|
|
144
|
-
"should return empty when value is empty and String (for QUERY)",
|
|
145
|
-
PlatformTest.inject([ParseExpressionPipe], (pipe: ParseExpressionPipe) => {
|
|
146
|
-
// @ts-ignore
|
|
147
|
-
class Test {}
|
|
148
|
-
|
|
149
|
-
const param = new JsonParameterStore({
|
|
150
|
-
index: 0,
|
|
151
|
-
target: Test,
|
|
152
|
-
propertyKey: "test",
|
|
153
|
-
expression: "test",
|
|
154
|
-
paramType: ParamTypes.QUERY,
|
|
155
|
-
dataPath: "$ctx.request.query",
|
|
156
|
-
decoratorType: DecoratorTypes.PARAM
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
const scope: any = {
|
|
160
|
-
$ctx: {
|
|
161
|
-
request: {
|
|
162
|
-
query: {
|
|
163
|
-
test: ""
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
// @ts-ignore
|
|
169
|
-
param._type = String;
|
|
170
|
-
// WHEN
|
|
171
|
-
const value = pipe.transform(scope, param);
|
|
172
|
-
|
|
173
|
-
expect(value).toEqual("");
|
|
174
|
-
})
|
|
175
|
-
);
|
|
176
|
-
it(
|
|
177
|
-
"should return undefined when value is empty and Boolean (for PATH)",
|
|
178
|
-
PlatformTest.inject([ParseExpressionPipe], (pipe: ParseExpressionPipe) => {
|
|
179
|
-
// @ts-ignore
|
|
180
|
-
class Test {}
|
|
181
|
-
|
|
182
|
-
const param = new JsonParameterStore({
|
|
183
|
-
index: 0,
|
|
184
|
-
target: Test,
|
|
185
|
-
propertyKey: "test",
|
|
186
|
-
expression: "test",
|
|
187
|
-
paramType: ParamTypes.PATH,
|
|
188
|
-
dataPath: "$ctx.request.params",
|
|
189
|
-
decoratorType: DecoratorTypes.PARAM
|
|
190
|
-
});
|
|
191
|
-
// @ts-ignore
|
|
192
|
-
param._type = Boolean;
|
|
193
|
-
|
|
194
|
-
const scope: any = {
|
|
195
|
-
$ctx: {
|
|
196
|
-
request: {
|
|
197
|
-
params: {
|
|
198
|
-
test: ""
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
// WHEN
|
|
204
|
-
const value = pipe.transform(scope, param);
|
|
205
|
-
|
|
206
|
-
expect(value).toEqual(undefined);
|
|
207
|
-
})
|
|
208
|
-
);
|
|
209
|
-
it(
|
|
210
|
-
"should return empty when value is empty and String (for PATH)",
|
|
211
|
-
PlatformTest.inject([ParseExpressionPipe], (pipe: ParseExpressionPipe) => {
|
|
212
|
-
// @ts-ignore
|
|
213
|
-
class Test {}
|
|
214
|
-
|
|
215
|
-
const param = new JsonParameterStore({
|
|
216
|
-
index: 0,
|
|
217
|
-
target: Test,
|
|
218
|
-
propertyKey: "test",
|
|
219
|
-
expression: "test",
|
|
220
|
-
paramType: ParamTypes.PATH,
|
|
221
|
-
dataPath: "$ctx.request.params",
|
|
222
|
-
decoratorType: DecoratorTypes.PARAM
|
|
223
|
-
});
|
|
224
|
-
// @ts-ignore
|
|
225
|
-
param._type = String;
|
|
226
|
-
|
|
227
|
-
const scope: any = {
|
|
228
|
-
$ctx: {
|
|
229
|
-
request: {
|
|
230
|
-
params: {
|
|
231
|
-
test: ""
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
};
|
|
236
|
-
// WHEN
|
|
237
|
-
const value = pipe.transform(scope, param);
|
|
238
|
-
|
|
239
|
-
expect(value).toEqual("");
|
|
240
|
-
})
|
|
241
|
-
);
|
|
242
|
-
});
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import {getValue} from "@tsed/core";
|
|
2
|
-
import {Injectable, injectable} from "@tsed/di";
|
|
3
|
-
import {JsonParameterStore, PipeMethods} from "@tsed/schema";
|
|
4
|
-
|
|
5
|
-
import {PlatformParamsScope} from "../builder/PlatformParams.js";
|
|
6
|
-
import {ParamTypes} from "../domain/ParamTypes.js";
|
|
7
|
-
|
|
8
|
-
export class ParseExpressionPipe implements PipeMethods {
|
|
9
|
-
transform(scope: PlatformParamsScope, param: JsonParameterStore) {
|
|
10
|
-
const {paramType, type} = param;
|
|
11
|
-
|
|
12
|
-
const value = getValue(scope, this.getKey(param));
|
|
13
|
-
|
|
14
|
-
if ([ParamTypes.QUERY, ParamTypes.PATH].includes(paramType as ParamTypes) && value === "" && type !== String) {
|
|
15
|
-
return undefined;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return value;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
protected getKey(param: JsonParameterStore) {
|
|
22
|
-
let {expression, paramType, dataPath} = param;
|
|
23
|
-
paramType = paramType || param.parameter.get("in").toUpperCase();
|
|
24
|
-
|
|
25
|
-
if (expression && paramType === ParamTypes.HEADER) {
|
|
26
|
-
expression = String(expression).toLowerCase();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return [dataPath, expression].filter(Boolean).join(".");
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
injectable(ParseExpressionPipe).priority(-1000);
|