@e22m4u/ts-rest-router 0.2.4 → 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.
@@ -293,8 +293,15 @@ function requestData(options) {
293
293
  }
294
294
  __name(requestData, "requestData");
295
295
  function createRequestDataDecoratorWithSource(source) {
296
- return function() {
297
- const schema = { type: import_ts_data_schema.DataType.OBJECT };
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
  }
@@ -329,19 +336,8 @@ var requestHeaders = createRequestDataDecoratorWithSource(RequestDataSource.HEAD
329
336
  var requestHeader = createRequestDataPropertyDecoratorWithSource(RequestDataSource.HEADERS);
330
337
  var requestCookies = createRequestDataDecoratorWithSource(RequestDataSource.COOKIE);
331
338
  var requestCookie = createRequestDataPropertyDecoratorWithSource(RequestDataSource.COOKIE);
339
+ var requestBody = createRequestDataDecoratorWithSource(RequestDataSource.BODY);
332
340
  var requestField = createRequestDataPropertyDecoratorWithSource(RequestDataSource.BODY);
333
- function requestBody(schemaOrType) {
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");
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
- const schema = { type: DataType.OBJECT };
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
  }
@@ -67,22 +76,5 @@ export const requestHeaders = createRequestDataDecoratorWithSource(RequestDataSo
67
76
  export const requestHeader = createRequestDataPropertyDecoratorWithSource(RequestDataSource.HEADERS);
68
77
  export const requestCookies = createRequestDataDecoratorWithSource(RequestDataSource.COOKIE);
69
78
  export const requestCookie = createRequestDataPropertyDecoratorWithSource(RequestDataSource.COOKIE);
79
+ export const requestBody = createRequestDataDecoratorWithSource(RequestDataSource.BODY);
70
80
  export const requestField = createRequestDataPropertyDecoratorWithSource(RequestDataSource.BODY);
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
- }
@@ -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.OBJECT },
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.OBJECT },
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.OBJECT },
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.OBJECT },
130
+ schema: { type: DataType.ANY },
131
131
  });
132
132
  });
133
133
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e22m4u/ts-rest-router",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "description": "REST маршрутизатор на основе контроллеров для TypeScript",
5
5
  "author": "e22m4u <e22m4u@yandex.ru>",
6
6
  "license": "MIT",
@@ -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.OBJECT},
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.OBJECT},
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.OBJECT},
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.OBJECT},
109
+ schema: {type: DataType.ANY},
110
110
  });
111
111
  });
112
112
  });
@@ -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
- const schema = {type: DataType.OBJECT};
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
  }
@@ -104,23 +111,9 @@ export const requestCookies = createRequestDataDecoratorWithSource(
104
111
  export const requestCookie = createRequestDataPropertyDecoratorWithSource(
105
112
  RequestDataSource.COOKIE,
106
113
  );
114
+ export const requestBody = createRequestDataDecoratorWithSource(
115
+ RequestDataSource.BODY,
116
+ );
107
117
  export const requestField = createRequestDataPropertyDecoratorWithSource(
108
118
  RequestDataSource.BODY,
109
119
  );
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
- }