@e22m4u/ts-rest-router 0.2.4 → 0.2.6
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 +17 -21
- package/dist/esm/decorators/request-data/request-data-decorator.d.ts +5 -10
- package/dist/esm/decorators/request-data/request-data-decorator.js +19 -27
- package/dist/esm/decorators/request-data/request-data-decorator.spec.js +8 -8
- package/package.json +1 -1
- package/src/decorators/request-data/request-data-decorator.spec.ts +8 -8
- package/src/decorators/request-data/request-data-decorator.ts +19 -20
package/dist/cjs/index.cjs
CHANGED
@@ -293,13 +293,20 @@ 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
|
}
|
301
308
|
__name(createRequestDataDecoratorWithSource, "createRequestDataDecoratorWithSource");
|
302
|
-
function createRequestDataPropertyDecoratorWithSource(source) {
|
309
|
+
function createRequestDataPropertyDecoratorWithSource(source, defaultType) {
|
303
310
|
return function(propertyKey, schemaOrType) {
|
304
311
|
const properties = {};
|
305
312
|
const rootSchema = { type: import_ts_data_schema.DataType.OBJECT };
|
@@ -310,7 +317,7 @@ function createRequestDataPropertyDecoratorWithSource(source) {
|
|
310
317
|
properties[propertyKey] = { type: schemaOrType };
|
311
318
|
rootSchema.properties = properties;
|
312
319
|
} else {
|
313
|
-
properties[propertyKey] = { type:
|
320
|
+
properties[propertyKey] = { type: defaultType };
|
314
321
|
rootSchema.properties = properties;
|
315
322
|
}
|
316
323
|
return requestData({
|
@@ -322,26 +329,15 @@ function createRequestDataPropertyDecoratorWithSource(source) {
|
|
322
329
|
}
|
323
330
|
__name(createRequestDataPropertyDecoratorWithSource, "createRequestDataPropertyDecoratorWithSource");
|
324
331
|
var requestParams = createRequestDataDecoratorWithSource(RequestDataSource.PARAMS);
|
325
|
-
var requestParam = createRequestDataPropertyDecoratorWithSource(RequestDataSource.PARAMS);
|
332
|
+
var requestParam = createRequestDataPropertyDecoratorWithSource(RequestDataSource.PARAMS, import_ts_data_schema.DataType.STRING);
|
326
333
|
var requestQueries = createRequestDataDecoratorWithSource(RequestDataSource.QUERY);
|
327
|
-
var requestQuery = createRequestDataPropertyDecoratorWithSource(RequestDataSource.QUERY);
|
334
|
+
var requestQuery = createRequestDataPropertyDecoratorWithSource(RequestDataSource.QUERY, import_ts_data_schema.DataType.STRING);
|
328
335
|
var requestHeaders = createRequestDataDecoratorWithSource(RequestDataSource.HEADERS);
|
329
|
-
var requestHeader = createRequestDataPropertyDecoratorWithSource(RequestDataSource.HEADERS);
|
336
|
+
var requestHeader = createRequestDataPropertyDecoratorWithSource(RequestDataSource.HEADERS, import_ts_data_schema.DataType.STRING);
|
330
337
|
var requestCookies = createRequestDataDecoratorWithSource(RequestDataSource.COOKIE);
|
331
|
-
var requestCookie = createRequestDataPropertyDecoratorWithSource(RequestDataSource.COOKIE);
|
332
|
-
var
|
333
|
-
|
334
|
-
let schema;
|
335
|
-
if (typeof schemaOrType === "object") {
|
336
|
-
schema = schemaOrType;
|
337
|
-
} else if (typeof schemaOrType === "string") {
|
338
|
-
schema = { type: schemaOrType };
|
339
|
-
} else {
|
340
|
-
schema = { type: import_ts_data_schema.DataType.ANY };
|
341
|
-
}
|
342
|
-
return requestData({ schema, source: RequestDataSource.BODY });
|
343
|
-
}
|
344
|
-
__name(requestBody, "requestBody");
|
338
|
+
var requestCookie = createRequestDataPropertyDecoratorWithSource(RequestDataSource.COOKIE, import_ts_data_schema.DataType.STRING);
|
339
|
+
var requestBody = createRequestDataDecoratorWithSource(RequestDataSource.BODY);
|
340
|
+
var requestField = createRequestDataPropertyDecoratorWithSource(RequestDataSource.BODY, import_ts_data_schema.DataType.ANY);
|
345
341
|
|
346
342
|
// dist/esm/decorators/after-action/after-action-metadata.js
|
347
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
|
}
|
@@ -33,7 +42,7 @@ function createRequestDataDecoratorWithSource(source) {
|
|
33
42
|
*
|
34
43
|
* @param source
|
35
44
|
*/
|
36
|
-
function createRequestDataPropertyDecoratorWithSource(source) {
|
45
|
+
function createRequestDataPropertyDecoratorWithSource(source, defaultType) {
|
37
46
|
return function (propertyKey, schemaOrType) {
|
38
47
|
const properties = {};
|
39
48
|
const rootSchema = { type: DataType.OBJECT };
|
@@ -46,7 +55,7 @@ function createRequestDataPropertyDecoratorWithSource(source) {
|
|
46
55
|
rootSchema.properties = properties;
|
47
56
|
}
|
48
57
|
else {
|
49
|
-
properties[propertyKey] = { type:
|
58
|
+
properties[propertyKey] = { type: defaultType };
|
50
59
|
rootSchema.properties = properties;
|
51
60
|
}
|
52
61
|
return requestData({
|
@@ -60,29 +69,12 @@ function createRequestDataPropertyDecoratorWithSource(source) {
|
|
60
69
|
* Decorator aliases.
|
61
70
|
*/
|
62
71
|
export const requestParams = createRequestDataDecoratorWithSource(RequestDataSource.PARAMS);
|
63
|
-
export const requestParam = createRequestDataPropertyDecoratorWithSource(RequestDataSource.PARAMS);
|
72
|
+
export const requestParam = createRequestDataPropertyDecoratorWithSource(RequestDataSource.PARAMS, DataType.STRING);
|
64
73
|
export const requestQueries = createRequestDataDecoratorWithSource(RequestDataSource.QUERY);
|
65
|
-
export const requestQuery = createRequestDataPropertyDecoratorWithSource(RequestDataSource.QUERY);
|
74
|
+
export const requestQuery = createRequestDataPropertyDecoratorWithSource(RequestDataSource.QUERY, DataType.STRING);
|
66
75
|
export const requestHeaders = createRequestDataDecoratorWithSource(RequestDataSource.HEADERS);
|
67
|
-
export const requestHeader = createRequestDataPropertyDecoratorWithSource(RequestDataSource.HEADERS);
|
76
|
+
export const requestHeader = createRequestDataPropertyDecoratorWithSource(RequestDataSource.HEADERS, DataType.STRING);
|
68
77
|
export const requestCookies = createRequestDataDecoratorWithSource(RequestDataSource.COOKIE);
|
69
|
-
export const requestCookie = createRequestDataPropertyDecoratorWithSource(RequestDataSource.COOKIE);
|
70
|
-
export const
|
71
|
-
|
72
|
-
* Request body decorator.
|
73
|
-
*
|
74
|
-
* @param schemaOrType
|
75
|
-
*/
|
76
|
-
export function requestBody(schemaOrType) {
|
77
|
-
let schema;
|
78
|
-
if (typeof schemaOrType === 'object') {
|
79
|
-
schema = schemaOrType;
|
80
|
-
}
|
81
|
-
else if (typeof schemaOrType === 'string') {
|
82
|
-
schema = { type: schemaOrType };
|
83
|
-
}
|
84
|
-
else {
|
85
|
-
schema = { type: DataType.ANY };
|
86
|
-
}
|
87
|
-
return requestData({ schema, source: RequestDataSource.BODY });
|
88
|
-
}
|
78
|
+
export const requestCookie = createRequestDataPropertyDecoratorWithSource(RequestDataSource.COOKIE, DataType.STRING);
|
79
|
+
export const requestBody = createRequestDataDecoratorWithSource(RequestDataSource.BODY);
|
80
|
+
export const requestField = createRequestDataPropertyDecoratorWithSource(RequestDataSource.BODY, DataType.ANY);
|
@@ -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
|
});
|
@@ -203,7 +203,7 @@ describe('requestData', function () {
|
|
203
203
|
type: DataType.OBJECT,
|
204
204
|
properties: {
|
205
205
|
[propertyKey]: {
|
206
|
-
type: DataType.
|
206
|
+
type: DataType.STRING,
|
207
207
|
},
|
208
208
|
},
|
209
209
|
},
|
@@ -283,7 +283,7 @@ describe('requestData', function () {
|
|
283
283
|
type: DataType.OBJECT,
|
284
284
|
properties: {
|
285
285
|
[propertyKey]: {
|
286
|
-
type: DataType.
|
286
|
+
type: DataType.STRING,
|
287
287
|
},
|
288
288
|
},
|
289
289
|
},
|
@@ -363,7 +363,7 @@ describe('requestData', function () {
|
|
363
363
|
type: DataType.OBJECT,
|
364
364
|
properties: {
|
365
365
|
[propertyKey]: {
|
366
|
-
type: DataType.
|
366
|
+
type: DataType.STRING,
|
367
367
|
},
|
368
368
|
},
|
369
369
|
},
|
@@ -443,7 +443,7 @@ describe('requestData', function () {
|
|
443
443
|
type: DataType.OBJECT,
|
444
444
|
properties: {
|
445
445
|
[propertyKey]: {
|
446
|
-
type: DataType.
|
446
|
+
type: DataType.STRING,
|
447
447
|
},
|
448
448
|
},
|
449
449
|
},
|
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
|
});
|
@@ -174,7 +174,7 @@ describe('requestData', function () {
|
|
174
174
|
type: DataType.OBJECT,
|
175
175
|
properties: {
|
176
176
|
[propertyKey]: {
|
177
|
-
type: DataType.
|
177
|
+
type: DataType.STRING,
|
178
178
|
},
|
179
179
|
},
|
180
180
|
},
|
@@ -248,7 +248,7 @@ describe('requestData', function () {
|
|
248
248
|
type: DataType.OBJECT,
|
249
249
|
properties: {
|
250
250
|
[propertyKey]: {
|
251
|
-
type: DataType.
|
251
|
+
type: DataType.STRING,
|
252
252
|
},
|
253
253
|
},
|
254
254
|
},
|
@@ -322,7 +322,7 @@ describe('requestData', function () {
|
|
322
322
|
type: DataType.OBJECT,
|
323
323
|
properties: {
|
324
324
|
[propertyKey]: {
|
325
|
-
type: DataType.
|
325
|
+
type: DataType.STRING,
|
326
326
|
},
|
327
327
|
},
|
328
328
|
},
|
@@ -396,7 +396,7 @@ describe('requestData', function () {
|
|
396
396
|
type: DataType.OBJECT,
|
397
397
|
properties: {
|
398
398
|
[propertyKey]: {
|
399
|
-
type: DataType.
|
399
|
+
type: DataType.STRING,
|
400
400
|
},
|
401
401
|
},
|
402
402
|
},
|
@@ -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
|
}
|
@@ -55,6 +62,7 @@ function createRequestDataDecoratorWithSource(source: RequestDataSource) {
|
|
55
62
|
*/
|
56
63
|
function createRequestDataPropertyDecoratorWithSource(
|
57
64
|
source: RequestDataSource,
|
65
|
+
defaultType: DataType,
|
58
66
|
) {
|
59
67
|
return function (propertyKey: string, schemaOrType?: DataSchema | DataType) {
|
60
68
|
const properties = {} as NoUndef<DataSchema['properties']>;
|
@@ -66,7 +74,7 @@ function createRequestDataPropertyDecoratorWithSource(
|
|
66
74
|
properties[propertyKey] = {type: schemaOrType};
|
67
75
|
rootSchema.properties = properties;
|
68
76
|
} else {
|
69
|
-
properties[propertyKey] = {type:
|
77
|
+
properties[propertyKey] = {type: defaultType};
|
70
78
|
rootSchema.properties = properties;
|
71
79
|
}
|
72
80
|
return requestData({
|
@@ -85,42 +93,33 @@ export const requestParams = createRequestDataDecoratorWithSource(
|
|
85
93
|
);
|
86
94
|
export const requestParam = createRequestDataPropertyDecoratorWithSource(
|
87
95
|
RequestDataSource.PARAMS,
|
96
|
+
DataType.STRING,
|
88
97
|
);
|
89
98
|
export const requestQueries = createRequestDataDecoratorWithSource(
|
90
99
|
RequestDataSource.QUERY,
|
91
100
|
);
|
92
101
|
export const requestQuery = createRequestDataPropertyDecoratorWithSource(
|
93
102
|
RequestDataSource.QUERY,
|
103
|
+
DataType.STRING,
|
94
104
|
);
|
95
105
|
export const requestHeaders = createRequestDataDecoratorWithSource(
|
96
106
|
RequestDataSource.HEADERS,
|
97
107
|
);
|
98
108
|
export const requestHeader = createRequestDataPropertyDecoratorWithSource(
|
99
109
|
RequestDataSource.HEADERS,
|
110
|
+
DataType.STRING,
|
100
111
|
);
|
101
112
|
export const requestCookies = createRequestDataDecoratorWithSource(
|
102
113
|
RequestDataSource.COOKIE,
|
103
114
|
);
|
104
115
|
export const requestCookie = createRequestDataPropertyDecoratorWithSource(
|
105
116
|
RequestDataSource.COOKIE,
|
117
|
+
DataType.STRING,
|
118
|
+
);
|
119
|
+
export const requestBody = createRequestDataDecoratorWithSource(
|
120
|
+
RequestDataSource.BODY,
|
106
121
|
);
|
107
122
|
export const requestField = createRequestDataPropertyDecoratorWithSource(
|
108
123
|
RequestDataSource.BODY,
|
124
|
+
DataType.ANY,
|
109
125
|
);
|
110
|
-
|
111
|
-
/**
|
112
|
-
* Request body decorator.
|
113
|
-
*
|
114
|
-
* @param schemaOrType
|
115
|
-
*/
|
116
|
-
export function requestBody(schemaOrType?: DataSchema | DataType) {
|
117
|
-
let schema: DataSchema;
|
118
|
-
if (typeof schemaOrType === 'object') {
|
119
|
-
schema = schemaOrType;
|
120
|
-
} else if (typeof schemaOrType === 'string') {
|
121
|
-
schema = {type: schemaOrType};
|
122
|
-
} else {
|
123
|
-
schema = {type: DataType.ANY};
|
124
|
-
}
|
125
|
-
return requestData({schema, source: RequestDataSource.BODY});
|
126
|
-
}
|