@e22m4u/ts-rest-router 0.1.0 → 0.1.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/README-ru.md +4 -4
- package/README.md +4 -4
- package/dist/cjs/index.cjs +3 -3
- package/dist/esm/decorators/request-data/request-data-decorator.d.ts +1 -1
- package/dist/esm/decorators/request-data/request-data-decorator.js +1 -1
- package/dist/esm/decorators/request-data/request-data-decorator.spec.js +5 -5
- package/package.json +1 -1
- package/src/controller-registry.spec.ts +2 -6
- package/src/decorators/request-data/request-data-decorator.spec.ts +5 -5
- package/src/decorators/request-data/request-data-decorator.ts +1 -1
package/README-ru.md
CHANGED
@@ -37,7 +37,7 @@ npm install @e22m4u/ts-rest-router
|
|
37
37
|
```ts
|
38
38
|
import {get} from '@e22m4u/ts-rest-router';
|
39
39
|
import {post} from '@e22m4u/ts-rest-router';
|
40
|
-
import {
|
40
|
+
import {field} from '@e22m4u/ts-rest-router';
|
41
41
|
import {DataType} from '@e22m4u/ts-rest-router';
|
42
42
|
import {controller} from '@e22m4u/ts-rest-router';
|
43
43
|
|
@@ -45,12 +45,12 @@ import {controller} from '@e22m4u/ts-rest-router';
|
|
45
45
|
class UserController { // класс контроллера
|
46
46
|
@post('/login') // метод POST /users/login
|
47
47
|
async login(
|
48
|
-
@
|
48
|
+
@field('username', { // поле "username" в теле запроса
|
49
49
|
type: DataType.STRING, // тип параметра допускает только строки
|
50
50
|
required: true, // параметр является обязательным
|
51
51
|
})
|
52
52
|
username: string,
|
53
|
-
@
|
53
|
+
@field('password', { // поле "password" в теле запроса
|
54
54
|
type: DataType.STRING, // тип параметра допускает только строки
|
55
55
|
required: true, // параметр является обязательным
|
56
56
|
})
|
@@ -110,7 +110,7 @@ server.listen('8080', '0.0.0.0', () => {
|
|
110
110
|
- `@query` - один query параметр
|
111
111
|
- `@queries` - все query параметры как объект
|
112
112
|
- `@body` - тело запроса
|
113
|
-
- `@
|
113
|
+
- `@field` - поле в теле запроса
|
114
114
|
- `@header` - один заголовок
|
115
115
|
- `@headers` - все заголовки как объект
|
116
116
|
- `@cookie` - одна cookie
|
package/README.md
CHANGED
@@ -37,7 +37,7 @@ Creating a controller and methods.
|
|
37
37
|
```ts
|
38
38
|
import {get} from '@e22m4u/ts-rest-router';
|
39
39
|
import {post} from '@e22m4u/ts-rest-router';
|
40
|
-
import {
|
40
|
+
import {field} from '@e22m4u/ts-rest-router';
|
41
41
|
import {DataType} from '@e22m4u/ts-rest-router';
|
42
42
|
import {controller} from '@e22m4u/ts-rest-router';
|
43
43
|
|
@@ -45,12 +45,12 @@ import {controller} from '@e22m4u/ts-rest-router';
|
|
45
45
|
class UserController { // controller class
|
46
46
|
@post('/login') // POST /users/login method
|
47
47
|
async login(
|
48
|
-
@
|
48
|
+
@field('username', { // "username" is request body field
|
49
49
|
type: DataType.STRING, // parameter type allows only strings
|
50
50
|
required: true, // parameter is required
|
51
51
|
})
|
52
52
|
username: string,
|
53
|
-
@
|
53
|
+
@field('password', { // "password" is request body field
|
54
54
|
type: DataType.STRING, // parameter type allows only strings
|
55
55
|
required: true, // parameter is required
|
56
56
|
})
|
@@ -110,7 +110,7 @@ Request parameters:
|
|
110
110
|
- `@query` - single query parameter
|
111
111
|
- `@queries` - all query parameters as an object
|
112
112
|
- `@body` - request body
|
113
|
-
- `@
|
113
|
+
- `@field` - field in request body
|
114
114
|
- `@header` - single header
|
115
115
|
- `@headers` - all headers as an object
|
116
116
|
- `@cookie` - single cookie
|
package/dist/cjs/index.cjs
CHANGED
@@ -51,7 +51,6 @@ __export(index_exports, {
|
|
51
51
|
after: () => after,
|
52
52
|
before: () => before,
|
53
53
|
body: () => body,
|
54
|
-
bodyProp: () => bodyProp,
|
55
54
|
capitalize: () => capitalize,
|
56
55
|
controller: () => controller,
|
57
56
|
cookie: () => cookie,
|
@@ -59,6 +58,7 @@ __export(index_exports, {
|
|
59
58
|
createDebugger: () => createDebugger,
|
60
59
|
createError: () => createError,
|
61
60
|
del: () => del,
|
61
|
+
field: () => field,
|
62
62
|
get: () => get,
|
63
63
|
header: () => header,
|
64
64
|
headers: () => headers,
|
@@ -470,7 +470,7 @@ var headers = createRequestDataDecoratorWithSource(RequestDataSource.HEADERS);
|
|
470
470
|
var header = createRequestDataPropertyDecoratorWithSource(RequestDataSource.HEADERS);
|
471
471
|
var cookies = createRequestDataDecoratorWithSource(RequestDataSource.COOKIE);
|
472
472
|
var cookie = createRequestDataPropertyDecoratorWithSource(RequestDataSource.COOKIE);
|
473
|
-
var
|
473
|
+
var field = createRequestDataPropertyDecoratorWithSource(RequestDataSource.BODY);
|
474
474
|
function body(schemaOrType) {
|
475
475
|
let schema;
|
476
476
|
if (typeof schemaOrType === "object") {
|
@@ -959,7 +959,6 @@ var RestRouter = _RestRouter;
|
|
959
959
|
after,
|
960
960
|
before,
|
961
961
|
body,
|
962
|
-
bodyProp,
|
963
962
|
capitalize,
|
964
963
|
controller,
|
965
964
|
cookie,
|
@@ -967,6 +966,7 @@ var RestRouter = _RestRouter;
|
|
967
966
|
createDebugger,
|
968
967
|
createError,
|
969
968
|
del,
|
969
|
+
field,
|
970
970
|
get,
|
971
971
|
header,
|
972
972
|
headers,
|
@@ -23,7 +23,7 @@ export declare const headers: () => (target: Prototype<object>, propertyKey: str
|
|
23
23
|
export declare const header: (propertyKey: string, schemaOrType?: DataSchema | DataType) => (target: Prototype<object>, propertyKey: string, indexOrDescriptor: number) => void;
|
24
24
|
export declare const cookies: () => (target: Prototype<object>, propertyKey: string, indexOrDescriptor: number) => void;
|
25
25
|
export declare const cookie: (propertyKey: string, schemaOrType?: DataSchema | DataType) => (target: Prototype<object>, propertyKey: string, indexOrDescriptor: number) => void;
|
26
|
-
export declare const
|
26
|
+
export declare const field: (propertyKey: string, schemaOrType?: DataSchema | DataType) => (target: Prototype<object>, propertyKey: string, indexOrDescriptor: number) => void;
|
27
27
|
/**
|
28
28
|
* Request body decorator.
|
29
29
|
*
|
@@ -63,7 +63,7 @@ export const headers = createRequestDataDecoratorWithSource(RequestDataSource.HE
|
|
63
63
|
export const header = createRequestDataPropertyDecoratorWithSource(RequestDataSource.HEADERS);
|
64
64
|
export const cookies = createRequestDataDecoratorWithSource(RequestDataSource.COOKIE);
|
65
65
|
export const cookie = createRequestDataPropertyDecoratorWithSource(RequestDataSource.COOKIE);
|
66
|
-
export const
|
66
|
+
export const field = createRequestDataPropertyDecoratorWithSource(RequestDataSource.BODY);
|
67
67
|
/**
|
68
68
|
* Request body decorator.
|
69
69
|
*
|
@@ -16,13 +16,13 @@ import { DataType } from '@e22m4u/ts-data-schema';
|
|
16
16
|
import { body } from './request-data-decorator.js';
|
17
17
|
import { param } from './request-data-decorator.js';
|
18
18
|
import { query } from './request-data-decorator.js';
|
19
|
+
import { field } from './request-data-decorator.js';
|
19
20
|
import { cookie } from './request-data-decorator.js';
|
20
21
|
import { header } from './request-data-decorator.js';
|
21
22
|
import { params } from './request-data-decorator.js';
|
22
23
|
import { queries } from './request-data-decorator.js';
|
23
24
|
import { cookies } from './request-data-decorator.js';
|
24
25
|
import { headers } from './request-data-decorator.js';
|
25
|
-
import { bodyProp } from './request-data-decorator.js';
|
26
26
|
import { requestData } from './request-data-decorator.js';
|
27
27
|
import { RequestDataSource } from './request-data-metadata.js';
|
28
28
|
import { RequestDataReflector } from './request-data-reflector.js';
|
@@ -460,13 +460,13 @@ describe('requestData', function () {
|
|
460
460
|
});
|
461
461
|
});
|
462
462
|
});
|
463
|
-
describe('
|
463
|
+
describe('field', function () {
|
464
464
|
it('sets a given "propertyKey" to the target metadata', function () {
|
465
465
|
class Target {
|
466
466
|
myMethod(prop) { }
|
467
467
|
}
|
468
468
|
__decorate([
|
469
|
-
__param(0,
|
469
|
+
__param(0, field('myPropertyKey')),
|
470
470
|
__metadata("design:type", Function),
|
471
471
|
__metadata("design:paramtypes", [Object]),
|
472
472
|
__metadata("design:returntype", void 0)
|
@@ -485,7 +485,7 @@ describe('requestData', function () {
|
|
485
485
|
myMethod(prop) { }
|
486
486
|
}
|
487
487
|
__decorate([
|
488
|
-
__param(0,
|
488
|
+
__param(0, field(propertyKey, propertyType)),
|
489
489
|
__metadata("design:type", Function),
|
490
490
|
__metadata("design:paramtypes", [Object]),
|
491
491
|
__metadata("design:returntype", void 0)
|
@@ -514,7 +514,7 @@ describe('requestData', function () {
|
|
514
514
|
myMethod(prop) { }
|
515
515
|
}
|
516
516
|
__decorate([
|
517
|
-
__param(0,
|
517
|
+
__param(0, field(propertyKey, schema)),
|
518
518
|
__metadata("design:type", Function),
|
519
519
|
__metadata("design:paramtypes", [Object]),
|
520
520
|
__metadata("design:returntype", void 0)
|
package/package.json
CHANGED
@@ -6,6 +6,7 @@ import {body} from './decorators/index.js';
|
|
6
6
|
import {after} from './decorators/index.js';
|
7
7
|
import {query} from './decorators/index.js';
|
8
8
|
import {param} from './decorators/index.js';
|
9
|
+
import {field} from './decorators/index.js';
|
9
10
|
import {cookie} from './decorators/index.js';
|
10
11
|
import {params} from './decorators/index.js';
|
11
12
|
import {before} from './decorators/index.js';
|
@@ -13,7 +14,6 @@ import {header} from './decorators/index.js';
|
|
13
14
|
import {cookies} from './decorators/index.js';
|
14
15
|
import {queries} from './decorators/index.js';
|
15
16
|
import {headers} from './decorators/index.js';
|
16
|
-
import {bodyProp} from './decorators/index.js';
|
17
17
|
import {HookName} from '@e22m4u/js-trie-router';
|
18
18
|
import {controller} from './decorators/index.js';
|
19
19
|
import {TrieRouter} from '@e22m4u/js-trie-router';
|
@@ -31,13 +31,9 @@ import {ControllerRegistry} from './controller-registry.js';
|
|
31
31
|
|
32
32
|
const PRE_HANDLER_1 = () => undefined;
|
33
33
|
const PRE_HANDLER_2 = () => undefined;
|
34
|
-
// const PRE_HANDLER_3 = () => undefined;
|
35
|
-
// const PRE_HANDLER_4 = () => undefined;
|
36
34
|
|
37
35
|
const POST_HANDLER_1 = () => undefined;
|
38
36
|
const POST_HANDLER_2 = () => undefined;
|
39
|
-
// const POST_HANDLER_3 = () => undefined;
|
40
|
-
// const POST_HANDLER_4 = () => undefined;
|
41
37
|
|
42
38
|
describe('ControllerRegistry', function () {
|
43
39
|
it('has a public property with set of controllers', function () {
|
@@ -872,7 +868,7 @@ describe('ControllerRegistry', function () {
|
|
872
868
|
class MyController {
|
873
869
|
@post('/myAction')
|
874
870
|
myAction(
|
875
|
-
@
|
871
|
+
@field('foo')
|
876
872
|
foo: object,
|
877
873
|
) {
|
878
874
|
expect(foo).to.be.eq('bar');
|
@@ -4,13 +4,13 @@ import {DataType} from '@e22m4u/ts-data-schema';
|
|
4
4
|
import {body} from './request-data-decorator.js';
|
5
5
|
import {param} from './request-data-decorator.js';
|
6
6
|
import {query} from './request-data-decorator.js';
|
7
|
+
import {field} from './request-data-decorator.js';
|
7
8
|
import {cookie} from './request-data-decorator.js';
|
8
9
|
import {header} from './request-data-decorator.js';
|
9
10
|
import {params} from './request-data-decorator.js';
|
10
11
|
import {queries} from './request-data-decorator.js';
|
11
12
|
import {cookies} from './request-data-decorator.js';
|
12
13
|
import {headers} from './request-data-decorator.js';
|
13
|
-
import {bodyProp} from './request-data-decorator.js';
|
14
14
|
import {requestData} from './request-data-decorator.js';
|
15
15
|
import {RequestDataSource} from './request-data-metadata.js';
|
16
16
|
import {RequestDataReflector} from './request-data-reflector.js';
|
@@ -409,11 +409,11 @@ describe('requestData', function () {
|
|
409
409
|
});
|
410
410
|
});
|
411
411
|
|
412
|
-
describe('
|
412
|
+
describe('field', function () {
|
413
413
|
it('sets a given "propertyKey" to the target metadata', function () {
|
414
414
|
class Target {
|
415
415
|
myMethod(
|
416
|
-
@
|
416
|
+
@field('myPropertyKey')
|
417
417
|
prop: unknown,
|
418
418
|
) {}
|
419
419
|
}
|
@@ -430,7 +430,7 @@ describe('requestData', function () {
|
|
430
430
|
const propertyType = DataType.STRING;
|
431
431
|
class Target {
|
432
432
|
myMethod(
|
433
|
-
@
|
433
|
+
@field(propertyKey, propertyType)
|
434
434
|
prop: unknown,
|
435
435
|
) {}
|
436
436
|
}
|
@@ -457,7 +457,7 @@ describe('requestData', function () {
|
|
457
457
|
const propertyKey = 'myPropertyKey';
|
458
458
|
class Target {
|
459
459
|
myMethod(
|
460
|
-
@
|
460
|
+
@field(propertyKey, schema)
|
461
461
|
prop: unknown,
|
462
462
|
) {}
|
463
463
|
}
|
@@ -109,7 +109,7 @@ export const cookies = createRequestDataDecoratorWithSource(
|
|
109
109
|
export const cookie = createRequestDataPropertyDecoratorWithSource(
|
110
110
|
RequestDataSource.COOKIE,
|
111
111
|
);
|
112
|
-
export const
|
112
|
+
export const field = createRequestDataPropertyDecoratorWithSource(
|
113
113
|
RequestDataSource.BODY,
|
114
114
|
);
|
115
115
|
|