@e22m4u/ts-rest-router 0.2.3 → 0.2.5
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/dist/cjs/index.cjs +13 -14
- package/dist/esm/decorators/request-data/request-data-decorator.d.ts +5 -10
- package/dist/esm/decorators/request-data/request-data-decorator.js +16 -20
- package/dist/esm/decorators/request-data/request-data-decorator.spec.js +59 -19
- package/package.json +1 -1
- package/src/decorators/request-data/request-data-decorator.spec.ts +59 -19
- package/src/decorators/request-data/request-data-decorator.ts +15 -19
package/dist/cjs/index.cjs
CHANGED
@@ -293,8 +293,15 @@ function requestData(options) {
|
|
293
293
|
}
|
294
294
|
__name(requestData, "requestData");
|
295
295
|
function createRequestDataDecoratorWithSource(source) {
|
296
|
-
return function() {
|
297
|
-
|
296
|
+
return function(schemaOrType) {
|
297
|
+
let schema;
|
298
|
+
if (typeof schemaOrType === "object") {
|
299
|
+
schema = schemaOrType;
|
300
|
+
} else if (typeof schemaOrType === "string") {
|
301
|
+
schema = { type: schemaOrType };
|
302
|
+
} else {
|
303
|
+
schema = { type: import_ts_data_schema.DataType.ANY };
|
304
|
+
}
|
298
305
|
return requestData({ schema, source });
|
299
306
|
};
|
300
307
|
}
|
@@ -309,6 +316,9 @@ function createRequestDataPropertyDecoratorWithSource(source) {
|
|
309
316
|
} else if (typeof schemaOrType === "string") {
|
310
317
|
properties[propertyKey] = { type: schemaOrType };
|
311
318
|
rootSchema.properties = properties;
|
319
|
+
} else {
|
320
|
+
properties[propertyKey] = { type: import_ts_data_schema.DataType.ANY };
|
321
|
+
rootSchema.properties = properties;
|
312
322
|
}
|
313
323
|
return requestData({
|
314
324
|
source,
|
@@ -326,19 +336,8 @@ var requestHeaders = createRequestDataDecoratorWithSource(RequestDataSource.HEAD
|
|
326
336
|
var requestHeader = createRequestDataPropertyDecoratorWithSource(RequestDataSource.HEADERS);
|
327
337
|
var requestCookies = createRequestDataDecoratorWithSource(RequestDataSource.COOKIE);
|
328
338
|
var requestCookie = createRequestDataPropertyDecoratorWithSource(RequestDataSource.COOKIE);
|
339
|
+
var requestBody = createRequestDataDecoratorWithSource(RequestDataSource.BODY);
|
329
340
|
var requestField = createRequestDataPropertyDecoratorWithSource(RequestDataSource.BODY);
|
330
|
-
function requestBody(schemaOrType) {
|
331
|
-
let schema;
|
332
|
-
if (typeof schemaOrType === "object") {
|
333
|
-
schema = schemaOrType;
|
334
|
-
} else if (typeof schemaOrType === "string") {
|
335
|
-
schema = { type: schemaOrType };
|
336
|
-
} else {
|
337
|
-
schema = { type: import_ts_data_schema.DataType.ANY };
|
338
|
-
}
|
339
|
-
return requestData({ schema, source: RequestDataSource.BODY });
|
340
|
-
}
|
341
|
-
__name(requestBody, "requestBody");
|
342
341
|
|
343
342
|
// dist/esm/decorators/after-action/after-action-metadata.js
|
344
343
|
var import_ts_reflector9 = require("@e22m4u/ts-reflector");
|
@@ -15,18 +15,13 @@ export declare function requestData<T extends object>(options: RequestDataOption
|
|
15
15
|
/**
|
16
16
|
* Decorator aliases.
|
17
17
|
*/
|
18
|
-
export declare const requestParams: () => (target: Prototype<object>, propertyKey: string, index: number) => void;
|
18
|
+
export declare const requestParams: (schemaOrType?: DataSchema | DataType) => (target: Prototype<object>, propertyKey: string, index: number) => void;
|
19
19
|
export declare const requestParam: (propertyKey: string, schemaOrType?: DataSchema | DataType) => (target: Prototype<object>, propertyKey: string, index: number) => void;
|
20
|
-
export declare const requestQueries: () => (target: Prototype<object>, propertyKey: string, index: number) => void;
|
20
|
+
export declare const requestQueries: (schemaOrType?: DataSchema | DataType) => (target: Prototype<object>, propertyKey: string, index: number) => void;
|
21
21
|
export declare const requestQuery: (propertyKey: string, schemaOrType?: DataSchema | DataType) => (target: Prototype<object>, propertyKey: string, index: number) => void;
|
22
|
-
export declare const requestHeaders: () => (target: Prototype<object>, propertyKey: string, index: number) => void;
|
22
|
+
export declare const requestHeaders: (schemaOrType?: DataSchema | DataType) => (target: Prototype<object>, propertyKey: string, index: number) => void;
|
23
23
|
export declare const requestHeader: (propertyKey: string, schemaOrType?: DataSchema | DataType) => (target: Prototype<object>, propertyKey: string, index: number) => void;
|
24
|
-
export declare const requestCookies: () => (target: Prototype<object>, propertyKey: string, index: number) => void;
|
24
|
+
export declare const requestCookies: (schemaOrType?: DataSchema | DataType) => (target: Prototype<object>, propertyKey: string, index: number) => void;
|
25
25
|
export declare const requestCookie: (propertyKey: string, schemaOrType?: DataSchema | DataType) => (target: Prototype<object>, propertyKey: string, index: number) => void;
|
26
|
+
export declare const requestBody: (schemaOrType?: DataSchema | DataType) => (target: Prototype<object>, propertyKey: string, index: number) => void;
|
26
27
|
export declare const requestField: (propertyKey: string, schemaOrType?: DataSchema | DataType) => (target: Prototype<object>, propertyKey: string, index: number) => void;
|
27
|
-
/**
|
28
|
-
* Request body decorator.
|
29
|
-
*
|
30
|
-
* @param schemaOrType
|
31
|
-
*/
|
32
|
-
export declare function requestBody(schemaOrType?: DataSchema | DataType): (target: Prototype<object>, propertyKey: string, index: number) => void;
|
@@ -23,8 +23,17 @@ export function requestData(options) {
|
|
23
23
|
* @param source
|
24
24
|
*/
|
25
25
|
function createRequestDataDecoratorWithSource(source) {
|
26
|
-
return function () {
|
27
|
-
|
26
|
+
return function (schemaOrType) {
|
27
|
+
let schema;
|
28
|
+
if (typeof schemaOrType === 'object') {
|
29
|
+
schema = schemaOrType;
|
30
|
+
}
|
31
|
+
else if (typeof schemaOrType === 'string') {
|
32
|
+
schema = { type: schemaOrType };
|
33
|
+
}
|
34
|
+
else {
|
35
|
+
schema = { type: DataType.ANY };
|
36
|
+
}
|
28
37
|
return requestData({ schema, source });
|
29
38
|
};
|
30
39
|
}
|
@@ -45,6 +54,10 @@ function createRequestDataPropertyDecoratorWithSource(source) {
|
|
45
54
|
properties[propertyKey] = { type: schemaOrType };
|
46
55
|
rootSchema.properties = properties;
|
47
56
|
}
|
57
|
+
else {
|
58
|
+
properties[propertyKey] = { type: DataType.ANY };
|
59
|
+
rootSchema.properties = properties;
|
60
|
+
}
|
48
61
|
return requestData({
|
49
62
|
source: source,
|
50
63
|
schema: rootSchema,
|
@@ -63,22 +76,5 @@ export const requestHeaders = createRequestDataDecoratorWithSource(RequestDataSo
|
|
63
76
|
export const requestHeader = createRequestDataPropertyDecoratorWithSource(RequestDataSource.HEADERS);
|
64
77
|
export const requestCookies = createRequestDataDecoratorWithSource(RequestDataSource.COOKIE);
|
65
78
|
export const requestCookie = createRequestDataPropertyDecoratorWithSource(RequestDataSource.COOKIE);
|
79
|
+
export const requestBody = createRequestDataDecoratorWithSource(RequestDataSource.BODY);
|
66
80
|
export const requestField = createRequestDataPropertyDecoratorWithSource(RequestDataSource.BODY);
|
67
|
-
/**
|
68
|
-
* Request body decorator.
|
69
|
-
*
|
70
|
-
* @param schemaOrType
|
71
|
-
*/
|
72
|
-
export function requestBody(schemaOrType) {
|
73
|
-
let schema;
|
74
|
-
if (typeof schemaOrType === 'object') {
|
75
|
-
schema = schemaOrType;
|
76
|
-
}
|
77
|
-
else if (typeof schemaOrType === 'string') {
|
78
|
-
schema = { type: schemaOrType };
|
79
|
-
}
|
80
|
-
else {
|
81
|
-
schema = { type: DataType.ANY };
|
82
|
-
}
|
83
|
-
return requestData({ schema, source: RequestDataSource.BODY });
|
84
|
-
}
|
@@ -73,7 +73,7 @@ describe('requestData', function () {
|
|
73
73
|
const res = RequestDataReflector.getMetadata(Target, 'myMethod');
|
74
74
|
expect(res.get(0)).to.be.eql({
|
75
75
|
source: RequestDataSource.PARAMS,
|
76
|
-
schema: { type: DataType.
|
76
|
+
schema: { type: DataType.ANY },
|
77
77
|
});
|
78
78
|
});
|
79
79
|
});
|
@@ -91,7 +91,7 @@ describe('requestData', function () {
|
|
91
91
|
const res = RequestDataReflector.getMetadata(Target, 'myMethod');
|
92
92
|
expect(res.get(0)).to.be.eql({
|
93
93
|
source: RequestDataSource.QUERY,
|
94
|
-
schema: { type: DataType.
|
94
|
+
schema: { type: DataType.ANY },
|
95
95
|
});
|
96
96
|
});
|
97
97
|
});
|
@@ -109,7 +109,7 @@ describe('requestData', function () {
|
|
109
109
|
const res = RequestDataReflector.getMetadata(Target, 'myMethod');
|
110
110
|
expect(res.get(0)).to.be.eql({
|
111
111
|
source: RequestDataSource.HEADERS,
|
112
|
-
schema: { type: DataType.
|
112
|
+
schema: { type: DataType.ANY },
|
113
113
|
});
|
114
114
|
});
|
115
115
|
});
|
@@ -127,7 +127,7 @@ describe('requestData', function () {
|
|
127
127
|
const res = RequestDataReflector.getMetadata(Target, 'myMethod');
|
128
128
|
expect(res.get(0)).to.be.eql({
|
129
129
|
source: RequestDataSource.COOKIE,
|
130
|
-
schema: { type: DataType.
|
130
|
+
schema: { type: DataType.ANY },
|
131
131
|
});
|
132
132
|
});
|
133
133
|
});
|
@@ -186,11 +186,12 @@ describe('requestData', function () {
|
|
186
186
|
describe('request data piece by a given property key', function () {
|
187
187
|
describe('param', function () {
|
188
188
|
it('sets a given "propertyKey" to the target metadata', function () {
|
189
|
+
const propertyKey = 'myPropertyKey';
|
189
190
|
class Target {
|
190
191
|
myMethod(prop) { }
|
191
192
|
}
|
192
193
|
__decorate([
|
193
|
-
__param(0, requestParam(
|
194
|
+
__param(0, requestParam(propertyKey)),
|
194
195
|
__metadata("design:type", Function),
|
195
196
|
__metadata("design:paramtypes", [Object]),
|
196
197
|
__metadata("design:returntype", void 0)
|
@@ -198,8 +199,15 @@ describe('requestData', function () {
|
|
198
199
|
const res = RequestDataReflector.getMetadata(Target, 'myMethod');
|
199
200
|
expect(res.get(0)).to.be.eql({
|
200
201
|
source: RequestDataSource.PARAMS,
|
201
|
-
schema: {
|
202
|
-
|
202
|
+
schema: {
|
203
|
+
type: DataType.OBJECT,
|
204
|
+
properties: {
|
205
|
+
[propertyKey]: {
|
206
|
+
type: DataType.ANY,
|
207
|
+
},
|
208
|
+
},
|
209
|
+
},
|
210
|
+
property: propertyKey,
|
203
211
|
});
|
204
212
|
});
|
205
213
|
it('sets a given DataType as property type', function () {
|
@@ -258,11 +266,12 @@ describe('requestData', function () {
|
|
258
266
|
});
|
259
267
|
describe('query', function () {
|
260
268
|
it('sets a given "propertyKey" to the target metadata', function () {
|
269
|
+
const propertyKey = 'myPropertyKey';
|
261
270
|
class Target {
|
262
271
|
myMethod(prop) { }
|
263
272
|
}
|
264
273
|
__decorate([
|
265
|
-
__param(0, requestQuery(
|
274
|
+
__param(0, requestQuery(propertyKey)),
|
266
275
|
__metadata("design:type", Function),
|
267
276
|
__metadata("design:paramtypes", [Object]),
|
268
277
|
__metadata("design:returntype", void 0)
|
@@ -270,8 +279,15 @@ describe('requestData', function () {
|
|
270
279
|
const res = RequestDataReflector.getMetadata(Target, 'myMethod');
|
271
280
|
expect(res.get(0)).to.be.eql({
|
272
281
|
source: RequestDataSource.QUERY,
|
273
|
-
schema: {
|
274
|
-
|
282
|
+
schema: {
|
283
|
+
type: DataType.OBJECT,
|
284
|
+
properties: {
|
285
|
+
[propertyKey]: {
|
286
|
+
type: DataType.ANY,
|
287
|
+
},
|
288
|
+
},
|
289
|
+
},
|
290
|
+
property: propertyKey,
|
275
291
|
});
|
276
292
|
});
|
277
293
|
it('sets a given DataType as property type', function () {
|
@@ -330,11 +346,12 @@ describe('requestData', function () {
|
|
330
346
|
});
|
331
347
|
describe('header', function () {
|
332
348
|
it('sets a given "propertyKey" to the target metadata', function () {
|
349
|
+
const propertyKey = 'myPropertyKey';
|
333
350
|
class Target {
|
334
351
|
myMethod(prop) { }
|
335
352
|
}
|
336
353
|
__decorate([
|
337
|
-
__param(0, requestHeader(
|
354
|
+
__param(0, requestHeader(propertyKey)),
|
338
355
|
__metadata("design:type", Function),
|
339
356
|
__metadata("design:paramtypes", [Object]),
|
340
357
|
__metadata("design:returntype", void 0)
|
@@ -342,8 +359,15 @@ describe('requestData', function () {
|
|
342
359
|
const res = RequestDataReflector.getMetadata(Target, 'myMethod');
|
343
360
|
expect(res.get(0)).to.be.eql({
|
344
361
|
source: RequestDataSource.HEADERS,
|
345
|
-
schema: {
|
346
|
-
|
362
|
+
schema: {
|
363
|
+
type: DataType.OBJECT,
|
364
|
+
properties: {
|
365
|
+
[propertyKey]: {
|
366
|
+
type: DataType.ANY,
|
367
|
+
},
|
368
|
+
},
|
369
|
+
},
|
370
|
+
property: propertyKey,
|
347
371
|
});
|
348
372
|
});
|
349
373
|
it('sets a given DataType as property type', function () {
|
@@ -402,11 +426,12 @@ describe('requestData', function () {
|
|
402
426
|
});
|
403
427
|
describe('cookie', function () {
|
404
428
|
it('sets a given "propertyKey" to the target metadata', function () {
|
429
|
+
const propertyKey = 'myPropertyKey';
|
405
430
|
class Target {
|
406
431
|
myMethod(prop) { }
|
407
432
|
}
|
408
433
|
__decorate([
|
409
|
-
__param(0, requestCookie(
|
434
|
+
__param(0, requestCookie(propertyKey)),
|
410
435
|
__metadata("design:type", Function),
|
411
436
|
__metadata("design:paramtypes", [Object]),
|
412
437
|
__metadata("design:returntype", void 0)
|
@@ -414,8 +439,15 @@ describe('requestData', function () {
|
|
414
439
|
const res = RequestDataReflector.getMetadata(Target, 'myMethod');
|
415
440
|
expect(res.get(0)).to.be.eql({
|
416
441
|
source: RequestDataSource.COOKIE,
|
417
|
-
schema: {
|
418
|
-
|
442
|
+
schema: {
|
443
|
+
type: DataType.OBJECT,
|
444
|
+
properties: {
|
445
|
+
[propertyKey]: {
|
446
|
+
type: DataType.ANY,
|
447
|
+
},
|
448
|
+
},
|
449
|
+
},
|
450
|
+
property: propertyKey,
|
419
451
|
});
|
420
452
|
});
|
421
453
|
it('sets a given DataType as property type', function () {
|
@@ -474,11 +506,12 @@ describe('requestData', function () {
|
|
474
506
|
});
|
475
507
|
describe('field', function () {
|
476
508
|
it('sets a given "propertyKey" to the target metadata', function () {
|
509
|
+
const propertyKey = 'myPropertyKey';
|
477
510
|
class Target {
|
478
511
|
myMethod(prop) { }
|
479
512
|
}
|
480
513
|
__decorate([
|
481
|
-
__param(0, requestField(
|
514
|
+
__param(0, requestField(propertyKey)),
|
482
515
|
__metadata("design:type", Function),
|
483
516
|
__metadata("design:paramtypes", [Object]),
|
484
517
|
__metadata("design:returntype", void 0)
|
@@ -486,8 +519,15 @@ describe('requestData', function () {
|
|
486
519
|
const res = RequestDataReflector.getMetadata(Target, 'myMethod');
|
487
520
|
expect(res.get(0)).to.be.eql({
|
488
521
|
source: RequestDataSource.BODY,
|
489
|
-
schema: {
|
490
|
-
|
522
|
+
schema: {
|
523
|
+
type: DataType.OBJECT,
|
524
|
+
properties: {
|
525
|
+
[propertyKey]: {
|
526
|
+
type: DataType.ANY,
|
527
|
+
},
|
528
|
+
},
|
529
|
+
},
|
530
|
+
property: propertyKey,
|
491
531
|
});
|
492
532
|
});
|
493
533
|
it('sets a given DataType as property type', function () {
|
package/package.json
CHANGED
@@ -58,7 +58,7 @@ describe('requestData', function () {
|
|
58
58
|
const res = RequestDataReflector.getMetadata(Target, 'myMethod');
|
59
59
|
expect(res.get(0)).to.be.eql({
|
60
60
|
source: RequestDataSource.PARAMS,
|
61
|
-
schema: {type: DataType.
|
61
|
+
schema: {type: DataType.ANY},
|
62
62
|
});
|
63
63
|
});
|
64
64
|
});
|
@@ -74,7 +74,7 @@ describe('requestData', function () {
|
|
74
74
|
const res = RequestDataReflector.getMetadata(Target, 'myMethod');
|
75
75
|
expect(res.get(0)).to.be.eql({
|
76
76
|
source: RequestDataSource.QUERY,
|
77
|
-
schema: {type: DataType.
|
77
|
+
schema: {type: DataType.ANY},
|
78
78
|
});
|
79
79
|
});
|
80
80
|
});
|
@@ -90,7 +90,7 @@ describe('requestData', function () {
|
|
90
90
|
const res = RequestDataReflector.getMetadata(Target, 'myMethod');
|
91
91
|
expect(res.get(0)).to.be.eql({
|
92
92
|
source: RequestDataSource.HEADERS,
|
93
|
-
schema: {type: DataType.
|
93
|
+
schema: {type: DataType.ANY},
|
94
94
|
});
|
95
95
|
});
|
96
96
|
});
|
@@ -106,7 +106,7 @@ describe('requestData', function () {
|
|
106
106
|
const res = RequestDataReflector.getMetadata(Target, 'myMethod');
|
107
107
|
expect(res.get(0)).to.be.eql({
|
108
108
|
source: RequestDataSource.COOKIE,
|
109
|
-
schema: {type: DataType.
|
109
|
+
schema: {type: DataType.ANY},
|
110
110
|
});
|
111
111
|
});
|
112
112
|
});
|
@@ -160,17 +160,25 @@ describe('requestData', function () {
|
|
160
160
|
describe('request data piece by a given property key', function () {
|
161
161
|
describe('param', function () {
|
162
162
|
it('sets a given "propertyKey" to the target metadata', function () {
|
163
|
+
const propertyKey = 'myPropertyKey';
|
163
164
|
class Target {
|
164
165
|
myMethod(
|
165
|
-
@requestParam(
|
166
|
+
@requestParam(propertyKey)
|
166
167
|
prop: unknown,
|
167
168
|
) {}
|
168
169
|
}
|
169
170
|
const res = RequestDataReflector.getMetadata(Target, 'myMethod');
|
170
171
|
expect(res.get(0)).to.be.eql({
|
171
172
|
source: RequestDataSource.PARAMS,
|
172
|
-
schema: {
|
173
|
-
|
173
|
+
schema: {
|
174
|
+
type: DataType.OBJECT,
|
175
|
+
properties: {
|
176
|
+
[propertyKey]: {
|
177
|
+
type: DataType.ANY,
|
178
|
+
},
|
179
|
+
},
|
180
|
+
},
|
181
|
+
property: propertyKey,
|
174
182
|
});
|
175
183
|
});
|
176
184
|
|
@@ -226,17 +234,25 @@ describe('requestData', function () {
|
|
226
234
|
|
227
235
|
describe('query', function () {
|
228
236
|
it('sets a given "propertyKey" to the target metadata', function () {
|
237
|
+
const propertyKey = 'myPropertyKey';
|
229
238
|
class Target {
|
230
239
|
myMethod(
|
231
|
-
@requestQuery(
|
240
|
+
@requestQuery(propertyKey)
|
232
241
|
prop: unknown,
|
233
242
|
) {}
|
234
243
|
}
|
235
244
|
const res = RequestDataReflector.getMetadata(Target, 'myMethod');
|
236
245
|
expect(res.get(0)).to.be.eql({
|
237
246
|
source: RequestDataSource.QUERY,
|
238
|
-
schema: {
|
239
|
-
|
247
|
+
schema: {
|
248
|
+
type: DataType.OBJECT,
|
249
|
+
properties: {
|
250
|
+
[propertyKey]: {
|
251
|
+
type: DataType.ANY,
|
252
|
+
},
|
253
|
+
},
|
254
|
+
},
|
255
|
+
property: propertyKey,
|
240
256
|
});
|
241
257
|
});
|
242
258
|
|
@@ -292,17 +308,25 @@ describe('requestData', function () {
|
|
292
308
|
|
293
309
|
describe('header', function () {
|
294
310
|
it('sets a given "propertyKey" to the target metadata', function () {
|
311
|
+
const propertyKey = 'myPropertyKey';
|
295
312
|
class Target {
|
296
313
|
myMethod(
|
297
|
-
@requestHeader(
|
314
|
+
@requestHeader(propertyKey)
|
298
315
|
prop: unknown,
|
299
316
|
) {}
|
300
317
|
}
|
301
318
|
const res = RequestDataReflector.getMetadata(Target, 'myMethod');
|
302
319
|
expect(res.get(0)).to.be.eql({
|
303
320
|
source: RequestDataSource.HEADERS,
|
304
|
-
schema: {
|
305
|
-
|
321
|
+
schema: {
|
322
|
+
type: DataType.OBJECT,
|
323
|
+
properties: {
|
324
|
+
[propertyKey]: {
|
325
|
+
type: DataType.ANY,
|
326
|
+
},
|
327
|
+
},
|
328
|
+
},
|
329
|
+
property: propertyKey,
|
306
330
|
});
|
307
331
|
});
|
308
332
|
|
@@ -358,17 +382,25 @@ describe('requestData', function () {
|
|
358
382
|
|
359
383
|
describe('cookie', function () {
|
360
384
|
it('sets a given "propertyKey" to the target metadata', function () {
|
385
|
+
const propertyKey = 'myPropertyKey';
|
361
386
|
class Target {
|
362
387
|
myMethod(
|
363
|
-
@requestCookie(
|
388
|
+
@requestCookie(propertyKey)
|
364
389
|
prop: unknown,
|
365
390
|
) {}
|
366
391
|
}
|
367
392
|
const res = RequestDataReflector.getMetadata(Target, 'myMethod');
|
368
393
|
expect(res.get(0)).to.be.eql({
|
369
394
|
source: RequestDataSource.COOKIE,
|
370
|
-
schema: {
|
371
|
-
|
395
|
+
schema: {
|
396
|
+
type: DataType.OBJECT,
|
397
|
+
properties: {
|
398
|
+
[propertyKey]: {
|
399
|
+
type: DataType.ANY,
|
400
|
+
},
|
401
|
+
},
|
402
|
+
},
|
403
|
+
property: propertyKey,
|
372
404
|
});
|
373
405
|
});
|
374
406
|
|
@@ -424,17 +456,25 @@ describe('requestData', function () {
|
|
424
456
|
|
425
457
|
describe('field', function () {
|
426
458
|
it('sets a given "propertyKey" to the target metadata', function () {
|
459
|
+
const propertyKey = 'myPropertyKey';
|
427
460
|
class Target {
|
428
461
|
myMethod(
|
429
|
-
@requestField(
|
462
|
+
@requestField(propertyKey)
|
430
463
|
prop: unknown,
|
431
464
|
) {}
|
432
465
|
}
|
433
466
|
const res = RequestDataReflector.getMetadata(Target, 'myMethod');
|
434
467
|
expect(res.get(0)).to.be.eql({
|
435
468
|
source: RequestDataSource.BODY,
|
436
|
-
schema: {
|
437
|
-
|
469
|
+
schema: {
|
470
|
+
type: DataType.OBJECT,
|
471
|
+
properties: {
|
472
|
+
[propertyKey]: {
|
473
|
+
type: DataType.ANY,
|
474
|
+
},
|
475
|
+
},
|
476
|
+
},
|
477
|
+
property: propertyKey,
|
438
478
|
});
|
439
479
|
});
|
440
480
|
|
@@ -42,8 +42,15 @@ export function requestData<T extends object>(options: RequestDataOptions) {
|
|
42
42
|
* @param source
|
43
43
|
*/
|
44
44
|
function createRequestDataDecoratorWithSource(source: RequestDataSource) {
|
45
|
-
return function () {
|
46
|
-
|
45
|
+
return function (schemaOrType?: DataSchema | DataType) {
|
46
|
+
let schema: DataSchema;
|
47
|
+
if (typeof schemaOrType === 'object') {
|
48
|
+
schema = schemaOrType;
|
49
|
+
} else if (typeof schemaOrType === 'string') {
|
50
|
+
schema = {type: schemaOrType};
|
51
|
+
} else {
|
52
|
+
schema = {type: DataType.ANY};
|
53
|
+
}
|
47
54
|
return requestData({schema, source});
|
48
55
|
};
|
49
56
|
}
|
@@ -65,6 +72,9 @@ function createRequestDataPropertyDecoratorWithSource(
|
|
65
72
|
} else if (typeof schemaOrType === 'string') {
|
66
73
|
properties[propertyKey] = {type: schemaOrType};
|
67
74
|
rootSchema.properties = properties;
|
75
|
+
} else {
|
76
|
+
properties[propertyKey] = {type: DataType.ANY};
|
77
|
+
rootSchema.properties = properties;
|
68
78
|
}
|
69
79
|
return requestData({
|
70
80
|
source: source,
|
@@ -101,23 +111,9 @@ export const requestCookies = createRequestDataDecoratorWithSource(
|
|
101
111
|
export const requestCookie = createRequestDataPropertyDecoratorWithSource(
|
102
112
|
RequestDataSource.COOKIE,
|
103
113
|
);
|
114
|
+
export const requestBody = createRequestDataDecoratorWithSource(
|
115
|
+
RequestDataSource.BODY,
|
116
|
+
);
|
104
117
|
export const requestField = createRequestDataPropertyDecoratorWithSource(
|
105
118
|
RequestDataSource.BODY,
|
106
119
|
);
|
107
|
-
|
108
|
-
/**
|
109
|
-
* Request body decorator.
|
110
|
-
*
|
111
|
-
* @param schemaOrType
|
112
|
-
*/
|
113
|
-
export function requestBody(schemaOrType?: DataSchema | DataType) {
|
114
|
-
let schema: DataSchema;
|
115
|
-
if (typeof schemaOrType === 'object') {
|
116
|
-
schema = schemaOrType;
|
117
|
-
} else if (typeof schemaOrType === 'string') {
|
118
|
-
schema = {type: schemaOrType};
|
119
|
-
} else {
|
120
|
-
schema = {type: DataType.ANY};
|
121
|
-
}
|
122
|
-
return requestData({schema, source: RequestDataSource.BODY});
|
123
|
-
}
|