@tsed/platform-params 8.11.1 → 8.11.2-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,432 +0,0 @@
|
|
|
1
|
-
import {Controller} from "@tsed/di";
|
|
2
|
-
import {Description, getJsonSchema, getSpec, JsonParameterStore, MaxLength, MinItems, Post, Required, SpecTypes} from "@tsed/schema";
|
|
3
|
-
|
|
4
|
-
import {ParamTypes} from "../domain/ParamTypes.js";
|
|
5
|
-
import {BodyParams, RawBodyParams} from "./bodyParams.js";
|
|
6
|
-
|
|
7
|
-
describe("@BodyParams", () => {
|
|
8
|
-
it("should call useParam method with the correct parameters", () => {
|
|
9
|
-
class Test {}
|
|
10
|
-
|
|
11
|
-
class Ctrl {
|
|
12
|
-
test(@BodyParams("expression", Test) body: Test) {}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const param = JsonParameterStore.get(Ctrl, "test", 0);
|
|
16
|
-
expect(param.expression).toEqual("expression");
|
|
17
|
-
expect(param.paramType).toEqual(ParamTypes.BODY);
|
|
18
|
-
expect(param.type).toEqual(Test);
|
|
19
|
-
});
|
|
20
|
-
it("should create params with Buffer type", () => {
|
|
21
|
-
@Controller("/")
|
|
22
|
-
class MyCtrl {
|
|
23
|
-
@Post()
|
|
24
|
-
test(@BodyParams() body: Buffer) {}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const spec = getSpec(MyCtrl, {specType: SpecTypes.OPENAPI});
|
|
28
|
-
|
|
29
|
-
expect(spec).toEqual({
|
|
30
|
-
paths: {
|
|
31
|
-
"/": {
|
|
32
|
-
post: {
|
|
33
|
-
operationId: "myCtrlTest",
|
|
34
|
-
parameters: [],
|
|
35
|
-
requestBody: {
|
|
36
|
-
content: {
|
|
37
|
-
"*/*": {
|
|
38
|
-
schema: {
|
|
39
|
-
type: "string"
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
required: false
|
|
44
|
-
},
|
|
45
|
-
responses: {
|
|
46
|
-
"200": {
|
|
47
|
-
description: "Success"
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
tags: ["MyCtrl"]
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
tags: [
|
|
55
|
-
{
|
|
56
|
-
name: "MyCtrl"
|
|
57
|
-
}
|
|
58
|
-
]
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
it("should generate the correct spec for BodyParams from metadata (string)", () => {
|
|
62
|
-
class TestModel {
|
|
63
|
-
@Required()
|
|
64
|
-
name: string;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
@Controller("/")
|
|
68
|
-
class MyCtrl {
|
|
69
|
-
@Post()
|
|
70
|
-
test(@BodyParams() @Required() @MaxLength(10) @Description("Description") body: string) {}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const spec = getSpec(MyCtrl, {specType: SpecTypes.OPENAPI});
|
|
74
|
-
|
|
75
|
-
expect(spec).toEqual({
|
|
76
|
-
paths: {
|
|
77
|
-
"/": {
|
|
78
|
-
post: {
|
|
79
|
-
operationId: "myCtrlTest",
|
|
80
|
-
parameters: [],
|
|
81
|
-
requestBody: {
|
|
82
|
-
description: "Description",
|
|
83
|
-
content: {
|
|
84
|
-
"application/json": {
|
|
85
|
-
schema: {
|
|
86
|
-
minLength: 1,
|
|
87
|
-
maxLength: 10,
|
|
88
|
-
type: "string"
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
},
|
|
92
|
-
required: true
|
|
93
|
-
},
|
|
94
|
-
responses: {
|
|
95
|
-
"200": {
|
|
96
|
-
description: "Success"
|
|
97
|
-
}
|
|
98
|
-
},
|
|
99
|
-
tags: ["MyCtrl"]
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
},
|
|
103
|
-
tags: [
|
|
104
|
-
{
|
|
105
|
-
name: "MyCtrl"
|
|
106
|
-
}
|
|
107
|
-
]
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
it("should generate the correct spec for BodyParams from metadata (string[])", () => {
|
|
111
|
-
class TestModel {
|
|
112
|
-
@Required()
|
|
113
|
-
name: string;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
@Controller("/")
|
|
117
|
-
class MyCtrl {
|
|
118
|
-
@Post()
|
|
119
|
-
test(@BodyParams(String) @Required() @MaxLength(10) @MinItems(3) @Description("Description") body: string[]) {}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const spec = getSpec(MyCtrl, {specType: SpecTypes.OPENAPI});
|
|
123
|
-
|
|
124
|
-
expect(spec).toEqual({
|
|
125
|
-
paths: {
|
|
126
|
-
"/": {
|
|
127
|
-
post: {
|
|
128
|
-
operationId: "myCtrlTest",
|
|
129
|
-
parameters: [],
|
|
130
|
-
requestBody: {
|
|
131
|
-
description: "Description",
|
|
132
|
-
content: {
|
|
133
|
-
"application/json": {
|
|
134
|
-
schema: {
|
|
135
|
-
items: {
|
|
136
|
-
maxLength: 10,
|
|
137
|
-
type: "string"
|
|
138
|
-
},
|
|
139
|
-
minItems: 3,
|
|
140
|
-
type: "array"
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
},
|
|
144
|
-
required: true
|
|
145
|
-
},
|
|
146
|
-
responses: {
|
|
147
|
-
"200": {
|
|
148
|
-
description: "Success"
|
|
149
|
-
}
|
|
150
|
-
},
|
|
151
|
-
tags: ["MyCtrl"]
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
},
|
|
155
|
-
tags: [
|
|
156
|
-
{
|
|
157
|
-
name: "MyCtrl"
|
|
158
|
-
}
|
|
159
|
-
]
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
it("should generate the correct spec for BodyParams from metadata (TestModel)", () => {
|
|
163
|
-
class TestModel {
|
|
164
|
-
@Required()
|
|
165
|
-
name: string;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
@Controller("/")
|
|
169
|
-
class MyCtrl {
|
|
170
|
-
@Post()
|
|
171
|
-
test(@BodyParams() @Required() @Description("Description") body: TestModel) {}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
const spec = getSpec(MyCtrl, {specType: SpecTypes.OPENAPI});
|
|
175
|
-
|
|
176
|
-
expect(spec).toEqual({
|
|
177
|
-
components: {
|
|
178
|
-
schemas: {
|
|
179
|
-
TestModel: {
|
|
180
|
-
properties: {
|
|
181
|
-
name: {
|
|
182
|
-
minLength: 1,
|
|
183
|
-
type: "string"
|
|
184
|
-
}
|
|
185
|
-
},
|
|
186
|
-
required: ["name"],
|
|
187
|
-
type: "object"
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
},
|
|
191
|
-
paths: {
|
|
192
|
-
"/": {
|
|
193
|
-
post: {
|
|
194
|
-
operationId: "myCtrlTest",
|
|
195
|
-
parameters: [],
|
|
196
|
-
requestBody: {
|
|
197
|
-
description: "Description",
|
|
198
|
-
content: {
|
|
199
|
-
"application/json": {
|
|
200
|
-
schema: {$ref: "#/components/schemas/TestModel"}
|
|
201
|
-
}
|
|
202
|
-
},
|
|
203
|
-
required: true
|
|
204
|
-
},
|
|
205
|
-
responses: {
|
|
206
|
-
"200": {
|
|
207
|
-
description: "Success"
|
|
208
|
-
}
|
|
209
|
-
},
|
|
210
|
-
tags: ["MyCtrl"]
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
},
|
|
214
|
-
tags: [
|
|
215
|
-
{
|
|
216
|
-
name: "MyCtrl"
|
|
217
|
-
}
|
|
218
|
-
]
|
|
219
|
-
});
|
|
220
|
-
const param = JsonParameterStore.get(MyCtrl, "test", 0);
|
|
221
|
-
const schema = getJsonSchema(param);
|
|
222
|
-
|
|
223
|
-
expect(schema).toEqual({
|
|
224
|
-
properties: {
|
|
225
|
-
name: {
|
|
226
|
-
minLength: 1,
|
|
227
|
-
type: "string"
|
|
228
|
-
}
|
|
229
|
-
},
|
|
230
|
-
required: ["name"],
|
|
231
|
-
type: "object"
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
it("should generate the correct spec for BodyParams from metadata (TestModel[])", () => {
|
|
235
|
-
class TestModel {
|
|
236
|
-
@Required()
|
|
237
|
-
name: string;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
@Controller("/")
|
|
241
|
-
class MyCtrl {
|
|
242
|
-
@Post()
|
|
243
|
-
test(@BodyParams(TestModel) @MinItems(2) @Required() @Description("Description") body: TestModel[]) {}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
const spec = getSpec(MyCtrl, {specType: SpecTypes.OPENAPI});
|
|
247
|
-
|
|
248
|
-
expect(spec).toEqual({
|
|
249
|
-
components: {
|
|
250
|
-
schemas: {
|
|
251
|
-
TestModel: {
|
|
252
|
-
properties: {
|
|
253
|
-
name: {
|
|
254
|
-
minLength: 1,
|
|
255
|
-
type: "string"
|
|
256
|
-
}
|
|
257
|
-
},
|
|
258
|
-
required: ["name"],
|
|
259
|
-
type: "object"
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
},
|
|
263
|
-
paths: {
|
|
264
|
-
"/": {
|
|
265
|
-
post: {
|
|
266
|
-
operationId: "myCtrlTest",
|
|
267
|
-
parameters: [],
|
|
268
|
-
requestBody: {
|
|
269
|
-
content: {
|
|
270
|
-
"application/json": {
|
|
271
|
-
schema: {
|
|
272
|
-
items: {
|
|
273
|
-
$ref: "#/components/schemas/TestModel"
|
|
274
|
-
},
|
|
275
|
-
minItems: 2,
|
|
276
|
-
type: "array"
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
},
|
|
280
|
-
description: "Description",
|
|
281
|
-
required: true
|
|
282
|
-
},
|
|
283
|
-
responses: {
|
|
284
|
-
"200": {
|
|
285
|
-
description: "Success"
|
|
286
|
-
}
|
|
287
|
-
},
|
|
288
|
-
tags: ["MyCtrl"]
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
},
|
|
292
|
-
tags: [
|
|
293
|
-
{
|
|
294
|
-
name: "MyCtrl"
|
|
295
|
-
}
|
|
296
|
-
]
|
|
297
|
-
});
|
|
298
|
-
});
|
|
299
|
-
it("should generate the correct spec for BodyParams from given type (TestModel)", () => {
|
|
300
|
-
class TestModel {
|
|
301
|
-
@Required()
|
|
302
|
-
name: string;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
@Controller("/")
|
|
306
|
-
class MyCtrl {
|
|
307
|
-
@Post()
|
|
308
|
-
test(@BodyParams(TestModel) @Required() @Description("Description") body: any) {}
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
const spec = getSpec(MyCtrl, {specType: SpecTypes.OPENAPI});
|
|
312
|
-
|
|
313
|
-
expect(spec).toEqual({
|
|
314
|
-
components: {
|
|
315
|
-
schemas: {
|
|
316
|
-
TestModel: {
|
|
317
|
-
properties: {
|
|
318
|
-
name: {
|
|
319
|
-
minLength: 1,
|
|
320
|
-
type: "string"
|
|
321
|
-
}
|
|
322
|
-
},
|
|
323
|
-
required: ["name"],
|
|
324
|
-
type: "object"
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
},
|
|
328
|
-
paths: {
|
|
329
|
-
"/": {
|
|
330
|
-
post: {
|
|
331
|
-
operationId: "myCtrlTest",
|
|
332
|
-
parameters: [],
|
|
333
|
-
requestBody: {
|
|
334
|
-
description: "Description",
|
|
335
|
-
content: {
|
|
336
|
-
"application/json": {
|
|
337
|
-
schema: {$ref: "#/components/schemas/TestModel"}
|
|
338
|
-
}
|
|
339
|
-
},
|
|
340
|
-
required: true
|
|
341
|
-
},
|
|
342
|
-
responses: {
|
|
343
|
-
"200": {
|
|
344
|
-
description: "Success"
|
|
345
|
-
}
|
|
346
|
-
},
|
|
347
|
-
tags: ["MyCtrl"]
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
},
|
|
351
|
-
tags: [
|
|
352
|
-
{
|
|
353
|
-
name: "MyCtrl"
|
|
354
|
-
}
|
|
355
|
-
]
|
|
356
|
-
});
|
|
357
|
-
|
|
358
|
-
const param = JsonParameterStore.get(MyCtrl, "test", 0);
|
|
359
|
-
const schema = getJsonSchema(param);
|
|
360
|
-
|
|
361
|
-
expect(schema).toEqual({
|
|
362
|
-
properties: {
|
|
363
|
-
name: {
|
|
364
|
-
minLength: 1,
|
|
365
|
-
type: "string"
|
|
366
|
-
}
|
|
367
|
-
},
|
|
368
|
-
required: ["name"],
|
|
369
|
-
type: "object"
|
|
370
|
-
});
|
|
371
|
-
});
|
|
372
|
-
});
|
|
373
|
-
|
|
374
|
-
describe("RawBodyParams()", () => {
|
|
375
|
-
it("should declare a RawBodyParams", () => {
|
|
376
|
-
@Controller("/")
|
|
377
|
-
class MyCtrl {
|
|
378
|
-
@Post()
|
|
379
|
-
test(@RawBodyParams() body: Buffer) {}
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
const spec = getSpec(MyCtrl, {specType: SpecTypes.OPENAPI});
|
|
383
|
-
|
|
384
|
-
expect(spec).toEqual({
|
|
385
|
-
paths: {
|
|
386
|
-
"/": {
|
|
387
|
-
post: {
|
|
388
|
-
operationId: "myCtrlTest",
|
|
389
|
-
parameters: [],
|
|
390
|
-
requestBody: {
|
|
391
|
-
content: {
|
|
392
|
-
"*/*": {
|
|
393
|
-
schema: {
|
|
394
|
-
type: "string"
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
},
|
|
398
|
-
required: false
|
|
399
|
-
},
|
|
400
|
-
responses: {
|
|
401
|
-
"200": {
|
|
402
|
-
description: "Success"
|
|
403
|
-
}
|
|
404
|
-
},
|
|
405
|
-
tags: ["MyCtrl"]
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
},
|
|
409
|
-
tags: [
|
|
410
|
-
{
|
|
411
|
-
name: "MyCtrl"
|
|
412
|
-
}
|
|
413
|
-
]
|
|
414
|
-
});
|
|
415
|
-
|
|
416
|
-
const param = JsonParameterStore.get(MyCtrl, "test", 0);
|
|
417
|
-
expect(param.paramType).toEqual(ParamTypes.RAW_BODY);
|
|
418
|
-
expect(param.type).toEqual(Buffer);
|
|
419
|
-
expect(param.pipes).toHaveLength(0);
|
|
420
|
-
});
|
|
421
|
-
it("should declare RawBodyParams with options", () => {
|
|
422
|
-
class Ctrl {
|
|
423
|
-
test(@RawBodyParams({useValidation: true, useType: String}) param: Date) {}
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
const param = JsonParameterStore.get(Ctrl, "test", 0);
|
|
427
|
-
expect(param.expression).toEqual(undefined);
|
|
428
|
-
expect(param.paramType).toEqual(ParamTypes.RAW_BODY);
|
|
429
|
-
expect(param.type).toEqual(String);
|
|
430
|
-
expect(param.pipes).toHaveLength(1);
|
|
431
|
-
});
|
|
432
|
-
});
|
|
@@ -1,93 +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
|
-
* BodyParams return the value from [request.body](http://expressjs.com/en/4x/api.html#req.body) object.
|
|
10
|
-
*
|
|
11
|
-
* #### Example
|
|
12
|
-
*
|
|
13
|
-
* ```typescript
|
|
14
|
-
* @Controller('/')
|
|
15
|
-
* class MyCtrl {
|
|
16
|
-
* @Post('/')
|
|
17
|
-
* create(@BodyParams() body: any) {
|
|
18
|
-
* console.log('Entire body', body);
|
|
19
|
-
* }
|
|
20
|
-
*
|
|
21
|
-
* @Post('/')
|
|
22
|
-
* create(@BodyParams('id') id: string) {
|
|
23
|
-
* console.log('ID', id);
|
|
24
|
-
* }
|
|
25
|
-
*
|
|
26
|
-
* @Post('/')
|
|
27
|
-
* create(@BodyParams('user') user: User) { // with deserialization
|
|
28
|
-
* console.log('user', user);
|
|
29
|
-
* }
|
|
30
|
-
*
|
|
31
|
-
* @Post('/')
|
|
32
|
-
* create(@BodyParams('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 BodyParams(expression: string, useType: Type<any>): ParameterDecorator;
|
|
46
|
-
export function BodyParams(expression: string): ParameterDecorator;
|
|
47
|
-
export function BodyParams(useType: Type<any>): ParameterDecorator;
|
|
48
|
-
export function BodyParams(options: Partial<ParamOptions>): ParameterDecorator;
|
|
49
|
-
export function BodyParams(): ParameterDecorator;
|
|
50
|
-
export function BodyParams(...args: any[]): ParameterDecorator {
|
|
51
|
-
const {expression, useType, useMapper = true, useValidation = true} = mapParamsOptions(args);
|
|
52
|
-
|
|
53
|
-
return UseParam({
|
|
54
|
-
paramType: ParamTypes.BODY,
|
|
55
|
-
expression,
|
|
56
|
-
useType,
|
|
57
|
-
useMapper,
|
|
58
|
-
useValidation
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* RawBodyParams return the value from [request.body](http://expressjs.com/en/4x/api.html#req.body) as a Buffer.
|
|
64
|
-
*
|
|
65
|
-
* #### Example
|
|
66
|
-
*
|
|
67
|
-
* ```typescript
|
|
68
|
-
* @Controller('/')
|
|
69
|
-
* class MyCtrl {
|
|
70
|
-
* @Post('/')
|
|
71
|
-
* create(@RawBodyParams() body: Buffer) {
|
|
72
|
-
* console.log('Entire body', body.toString("utf8"));
|
|
73
|
-
* }
|
|
74
|
-
* }
|
|
75
|
-
* ```
|
|
76
|
-
*
|
|
77
|
-
* @decorator
|
|
78
|
-
* @operation
|
|
79
|
-
* @input
|
|
80
|
-
* @alias BodyParams Example: @BodyParams() payload: Buffer
|
|
81
|
-
*/
|
|
82
|
-
export function RawBodyParams(options: Partial<Omit<ParamOptions, "expression">>): ParameterDecorator;
|
|
83
|
-
export function RawBodyParams(): ParameterDecorator;
|
|
84
|
-
export function RawBodyParams(...args: any[]): ParameterDecorator {
|
|
85
|
-
const {useType, useMapper = false, useValidation = false} = mapParamsOptions(args);
|
|
86
|
-
|
|
87
|
-
return UseParam({
|
|
88
|
-
paramType: ParamTypes.RAW_BODY,
|
|
89
|
-
useType,
|
|
90
|
-
useMapper,
|
|
91
|
-
useValidation
|
|
92
|
-
});
|
|
93
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import {JsonParameterStore} from "@tsed/schema";
|
|
2
|
-
|
|
3
|
-
import {ParamTypes} from "../domain/ParamTypes.js";
|
|
4
|
-
import {Context} from "./context.js";
|
|
5
|
-
|
|
6
|
-
describe("@Context", () => {
|
|
7
|
-
it("should call ParamFilter.useParam method with the correct parameters", () => {
|
|
8
|
-
class Ctrl {
|
|
9
|
-
test(@Context("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.$CTX);
|
|
15
|
-
});
|
|
16
|
-
});
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import {BaseContext} from "@tsed/di";
|
|
2
|
-
|
|
3
|
-
import {ParamTypes} from "../domain/ParamTypes.js";
|
|
4
|
-
import {mapParamsOptions} from "../utils/mapParamsOptions.js";
|
|
5
|
-
import {UseParam} from "./useParam.js";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Context decorator return the @@PlatformContext@@ created by Ts.ED when request is handled by the server.
|
|
9
|
-
*
|
|
10
|
-
* It contains some information as following:
|
|
11
|
-
*
|
|
12
|
-
* - The request id,
|
|
13
|
-
* - The request container used by the Ts.ED DI. It contain all services annotated with `@Scope(ProviderScope.REQUEST)`,
|
|
14
|
-
* - The current @@EndpointMetadata@@ resolved by Ts.ED during the request,
|
|
15
|
-
* - The data return by the previous endpoint if you use multiple handler on the same route. By default data is empty.
|
|
16
|
-
*
|
|
17
|
-
* ::: tip
|
|
18
|
-
* The @@PlatformContext@@ inherit from Map class. So you can store any information with.
|
|
19
|
-
* :::
|
|
20
|
-
*
|
|
21
|
-
* #### Example
|
|
22
|
-
*
|
|
23
|
-
* ```typescript
|
|
24
|
-
* @Middleware()
|
|
25
|
-
* class AuthTokenMiddleware {
|
|
26
|
-
* use(@Req() request: Req, @Context() context: PlatformContext) {
|
|
27
|
-
* if (!context.has("auth")){
|
|
28
|
-
* context.set('auth', new AuthToken(request))
|
|
29
|
-
* }
|
|
30
|
-
*
|
|
31
|
-
* try {
|
|
32
|
-
* context.get("auth").claims() // check token
|
|
33
|
-
* } catch(er){
|
|
34
|
-
* throw new Forbidden("Access forbidden - Bad token")
|
|
35
|
-
* }
|
|
36
|
-
* }
|
|
37
|
-
* }
|
|
38
|
-
*
|
|
39
|
-
* @Controller('/')
|
|
40
|
-
* @UseBefore(AuthTokenMiddleware) // protect all routes for this controller
|
|
41
|
-
* class MyCtrl {
|
|
42
|
-
* @Get('/')
|
|
43
|
-
* get(@Context('auth') auth: AuthToken) {
|
|
44
|
-
* console.log('auth', auth);
|
|
45
|
-
* console.log('auth.accessToken', auth.accessToken);
|
|
46
|
-
* console.log('auth.idToken', auth.idToken);
|
|
47
|
-
* }
|
|
48
|
-
* }
|
|
49
|
-
* ```
|
|
50
|
-
*
|
|
51
|
-
* @param expression The path of the property to get.
|
|
52
|
-
* @decorator
|
|
53
|
-
* @operation
|
|
54
|
-
* @input
|
|
55
|
-
*/
|
|
56
|
-
export function Context(expression: string): ParameterDecorator;
|
|
57
|
-
export function Context(): ParameterDecorator;
|
|
58
|
-
export function Context(...args: any[]): ParameterDecorator {
|
|
59
|
-
const {expression, useType, useMapper = false, useValidation = false} = mapParamsOptions(args);
|
|
60
|
-
|
|
61
|
-
return UseParam({
|
|
62
|
-
paramType: ParamTypes.$CTX,
|
|
63
|
-
expression,
|
|
64
|
-
useType,
|
|
65
|
-
useMapper,
|
|
66
|
-
useValidation
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export type Context = BaseContext;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import {JsonParameterStore} from "@tsed/schema";
|
|
2
|
-
|
|
3
|
-
import {ParamTypes} from "../domain/ParamTypes.js";
|
|
4
|
-
import {Cookies} from "./cookies.js";
|
|
5
|
-
|
|
6
|
-
describe("@Cookies", () => {
|
|
7
|
-
it("should call ParamFilter.useParam method with the correct parameters", () => {
|
|
8
|
-
class Test {}
|
|
9
|
-
|
|
10
|
-
class Ctrl {
|
|
11
|
-
test(@Cookies("expression", Test) body: Test) {}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const param = JsonParameterStore.get(Ctrl, "test", 0);
|
|
15
|
-
expect(param.expression).toEqual("expression");
|
|
16
|
-
expect(param.paramType).toEqual(ParamTypes.COOKIES);
|
|
17
|
-
expect(param.type).toEqual(Test);
|
|
18
|
-
});
|
|
19
|
-
});
|