@e22m4u/ts-rest-router 0.0.6 → 0.0.7
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/README-ru.md +204 -0
- package/README.md +206 -0
- package/dist/cjs/index.cjs +22 -31
- package/dist/esm/decorators/action/action-decorator.d.ts +7 -8
- package/dist/esm/decorators/action/action-decorator.js +1 -5
- package/dist/esm/decorators/action/action-decorator.spec.js +16 -16
- package/dist/esm/decorators/action/action-metadata.d.ts +0 -1
- package/dist/esm/decorators/controller/controller-decorator.js +1 -5
- package/dist/esm/decorators/controller/controller-decorator.spec.js +9 -15
- package/dist/esm/decorators/controller/controller-metadata.d.ts +0 -1
- package/dist/esm/decorators/request-context/request-context-decorator.d.ts +2 -3
- package/dist/esm/decorators/request-context/request-context-decorator.js +3 -6
- package/dist/esm/decorators/request-context/request-context-decorator.spec.js +2 -17
- package/dist/esm/decorators/request-context/request-context-metadata.d.ts +0 -1
- package/dist/esm/decorators/request-data/request-data-decorator.d.ts +6 -2
- package/dist/esm/decorators/request-data/request-data-decorator.js +16 -16
- package/dist/esm/decorators/request-data/request-data-decorator.spec.js +7 -5
- package/dist/esm/decorators/request-data/request-data-metadata.d.ts +0 -1
- package/package.json +17 -17
- package/src/decorators/action/action-decorator.spec.ts +16 -16
- package/src/decorators/action/action-decorator.ts +10 -12
- package/src/decorators/action/action-metadata.ts +0 -1
- package/src/decorators/controller/controller-decorator.spec.ts +11 -16
- package/src/decorators/controller/controller-decorator.ts +4 -5
- package/src/decorators/controller/controller-metadata.ts +0 -1
- package/src/decorators/request-context/request-context-decorator.spec.ts +2 -15
- package/src/decorators/request-context/request-context-decorator.ts +3 -8
- package/src/decorators/request-context/request-context-metadata.ts +0 -1
- package/src/decorators/request-data/request-data-decorator.spec.ts +7 -6
- package/src/decorators/request-data/request-data-decorator.ts +41 -16
- package/src/decorators/request-data/request-data-metadata.ts +0 -1
@@ -13,23 +13,24 @@ import {headers} from './request-data-decorator.js';
|
|
13
13
|
import {bodyParam} from './request-data-decorator.js';
|
14
14
|
import {requestData} from './request-data-decorator.js';
|
15
15
|
import {RequestDataSource} from './request-data-metadata.js';
|
16
|
-
import {RequestDataMetadata} from './request-data-metadata.js';
|
17
16
|
import {RequestDataReflector} from './request-data-reflector.js';
|
18
17
|
|
19
18
|
describe('requestData', function () {
|
20
|
-
it('sets
|
21
|
-
const
|
22
|
-
source: RequestDataSource.
|
19
|
+
it('sets given options to the target metadata', function () {
|
20
|
+
const options = {
|
21
|
+
source: RequestDataSource.BODY,
|
22
|
+
schema: {type: DataType.STRING},
|
23
|
+
property: 'prop',
|
23
24
|
customOption: 'myOption',
|
24
25
|
};
|
25
26
|
class Target {
|
26
27
|
myMethod(
|
27
|
-
@requestData(
|
28
|
+
@requestData(options)
|
28
29
|
prop: unknown,
|
29
30
|
) {}
|
30
31
|
}
|
31
32
|
const res = RequestDataReflector.getMetadata(Target, 'myMethod');
|
32
|
-
expect(res.get(0)).to.be.eql(
|
33
|
+
expect(res.get(0)).to.be.eql(options);
|
33
34
|
});
|
34
35
|
|
35
36
|
describe('request data by a given source', function () {
|
@@ -9,12 +9,17 @@ import {RequestDataSource} from './request-data-metadata.js';
|
|
9
9
|
import {RequestDataMetadata} from './request-data-metadata.js';
|
10
10
|
import {RequestDataReflector} from './request-data-reflector.js';
|
11
11
|
|
12
|
+
/**
|
13
|
+
* Request data options.
|
14
|
+
*/
|
15
|
+
export type RequestDataOptions = RequestDataMetadata;
|
16
|
+
|
12
17
|
/**
|
13
18
|
* Request data decorator.
|
14
19
|
*
|
15
|
-
* @param
|
20
|
+
* @param options
|
16
21
|
*/
|
17
|
-
export function requestData<T extends object>(
|
22
|
+
export function requestData<T extends object>(options: RequestDataOptions) {
|
18
23
|
return function (
|
19
24
|
target: Prototype<T>,
|
20
25
|
propertyKey: string,
|
@@ -31,7 +36,7 @@ export function requestData<T extends object>(metadata: RequestDataMetadata) {
|
|
31
36
|
'on an instance method parameter.',
|
32
37
|
);
|
33
38
|
RequestDataReflector.setMetadata(
|
34
|
-
|
39
|
+
options,
|
35
40
|
target.constructor as Constructor<T>,
|
36
41
|
indexOrDescriptor,
|
37
42
|
propertyKey,
|
@@ -40,11 +45,11 @@ export function requestData<T extends object>(metadata: RequestDataMetadata) {
|
|
40
45
|
}
|
41
46
|
|
42
47
|
/**
|
43
|
-
* Create data decorator.
|
48
|
+
* Create request data decorator with source.
|
44
49
|
*
|
45
50
|
* @param source
|
46
51
|
*/
|
47
|
-
function
|
52
|
+
function createRequestDataDecoratorWithSource(source: RequestDataSource) {
|
48
53
|
return function () {
|
49
54
|
const schema = {type: DataType.OBJECT};
|
50
55
|
return requestData({schema, source});
|
@@ -52,11 +57,13 @@ function createDataDecorator(source: RequestDataSource) {
|
|
52
57
|
}
|
53
58
|
|
54
59
|
/**
|
55
|
-
* Create property decorator.
|
60
|
+
* Create request data property decorator with source.
|
56
61
|
*
|
57
62
|
* @param source
|
58
63
|
*/
|
59
|
-
function
|
64
|
+
function createRequestDataPropertyDecoratorWithSource(
|
65
|
+
source: RequestDataSource,
|
66
|
+
) {
|
60
67
|
return function (propertyKey: string, schemaOrType?: DataSchema | DataType) {
|
61
68
|
const properties = {} as NoUndef<DataSchema['properties']>;
|
62
69
|
const rootSchema: DataSchema = {type: DataType.OBJECT};
|
@@ -78,15 +85,33 @@ function createPropertyDecorator(source: RequestDataSource) {
|
|
78
85
|
/**
|
79
86
|
* Decorator aliases.
|
80
87
|
*/
|
81
|
-
export const params =
|
82
|
-
|
83
|
-
|
84
|
-
export const
|
85
|
-
|
86
|
-
|
87
|
-
export const
|
88
|
-
|
89
|
-
|
88
|
+
export const params = createRequestDataDecoratorWithSource(
|
89
|
+
RequestDataSource.PARAMS,
|
90
|
+
);
|
91
|
+
export const param = createRequestDataPropertyDecoratorWithSource(
|
92
|
+
RequestDataSource.PARAMS,
|
93
|
+
);
|
94
|
+
export const queries = createRequestDataDecoratorWithSource(
|
95
|
+
RequestDataSource.QUERY,
|
96
|
+
);
|
97
|
+
export const query = createRequestDataPropertyDecoratorWithSource(
|
98
|
+
RequestDataSource.QUERY,
|
99
|
+
);
|
100
|
+
export const headers = createRequestDataDecoratorWithSource(
|
101
|
+
RequestDataSource.HEADERS,
|
102
|
+
);
|
103
|
+
export const header = createRequestDataPropertyDecoratorWithSource(
|
104
|
+
RequestDataSource.HEADERS,
|
105
|
+
);
|
106
|
+
export const cookies = createRequestDataDecoratorWithSource(
|
107
|
+
RequestDataSource.COOKIE,
|
108
|
+
);
|
109
|
+
export const cookie = createRequestDataPropertyDecoratorWithSource(
|
110
|
+
RequestDataSource.COOKIE,
|
111
|
+
);
|
112
|
+
export const bodyParam = createRequestDataPropertyDecoratorWithSource(
|
113
|
+
RequestDataSource.BODY,
|
114
|
+
);
|
90
115
|
|
91
116
|
/**
|
92
117
|
* Request body decorator.
|