@e22m4u/ts-rest-router 0.6.1 → 0.6.3
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 +16 -4
- package/dist/esm/data-schema-types.d.ts +2 -2
- package/dist/esm/decorators/request-data/request-data-decorator.d.ts +11 -11
- package/dist/esm/decorators/response-body/response-body-decorator.d.ts +2 -2
- package/dist/esm/index.d.ts +4 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/rest-router.d.ts +9 -0
- package/dist/esm/rest-router.js +10 -0
- package/package.json +2 -2
- package/src/data-schema-types.ts +2 -2
- package/src/decorators/request-data/request-data-decorator.ts +6 -3
- package/src/decorators/response-body/response-body-decorator.ts +4 -2
- package/src/index.ts +5 -2
- package/src/rest-router.ts +13 -0
package/dist/cjs/index.cjs
CHANGED
@@ -16,7 +16,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
16
16
|
}
|
17
17
|
return to;
|
18
18
|
};
|
19
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
20
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
21
20
|
|
22
21
|
// dist/esm/index.js
|
@@ -33,6 +32,7 @@ __export(index_exports, {
|
|
33
32
|
RESPONSE_BODY_METADATA_KEY: () => RESPONSE_BODY_METADATA_KEY,
|
34
33
|
REST_ACTIONS_METADATA_KEY: () => REST_ACTIONS_METADATA_KEY,
|
35
34
|
REST_CONTROLLER_METADATA_KEY: () => REST_CONTROLLER_METADATA_KEY,
|
35
|
+
RequestContext: () => import_js_trie_router4.RequestContext,
|
36
36
|
RequestContextReflector: () => RequestContextReflector,
|
37
37
|
RequestDataReflector: () => RequestDataReflector,
|
38
38
|
RequestDataSource: () => RequestDataSource,
|
@@ -67,7 +67,6 @@ __export(index_exports, {
|
|
67
67
|
restController: () => restController
|
68
68
|
});
|
69
69
|
module.exports = __toCommonJS(index_exports);
|
70
|
-
__reExport(index_exports, require("@e22m4u/js-trie-router"), module.exports);
|
71
70
|
|
72
71
|
// dist/esm/rest-router.js
|
73
72
|
var import_js_trie_router3 = require("@e22m4u/js-trie-router");
|
@@ -965,9 +964,22 @@ var _RestRouter = class _RestRouter extends DebuggableService {
|
|
965
964
|
this.getService(ControllerRegistry).addController(ctor, options);
|
966
965
|
return this;
|
967
966
|
}
|
967
|
+
/**
|
968
|
+
* Add hook.
|
969
|
+
*
|
970
|
+
* @param type
|
971
|
+
* @param hook
|
972
|
+
*/
|
973
|
+
addHook(type, hook) {
|
974
|
+
this.getService(import_js_trie_router3.TrieRouter).addHook(type, hook);
|
975
|
+
return this;
|
976
|
+
}
|
968
977
|
};
|
969
978
|
__name(_RestRouter, "RestRouter");
|
970
979
|
var RestRouter = _RestRouter;
|
980
|
+
|
981
|
+
// dist/esm/index.js
|
982
|
+
var import_js_trie_router4 = require("@e22m4u/js-trie-router");
|
971
983
|
// Annotate the CommonJS export names for ESM import in node:
|
972
984
|
0 && (module.exports = {
|
973
985
|
AFTER_ACTION_METADATA_KEY,
|
@@ -981,6 +993,7 @@ var RestRouter = _RestRouter;
|
|
981
993
|
RESPONSE_BODY_METADATA_KEY,
|
982
994
|
REST_ACTIONS_METADATA_KEY,
|
983
995
|
REST_CONTROLLER_METADATA_KEY,
|
996
|
+
RequestContext,
|
984
997
|
RequestContextReflector,
|
985
998
|
RequestDataReflector,
|
986
999
|
RequestDataSource,
|
@@ -1012,6 +1025,5 @@ var RestRouter = _RestRouter;
|
|
1012
1025
|
requestQuery,
|
1013
1026
|
responseBody,
|
1014
1027
|
restAction,
|
1015
|
-
restController
|
1016
|
-
...require("@e22m4u/js-trie-router")
|
1028
|
+
restController
|
1017
1029
|
});
|
@@ -10,6 +10,6 @@ export type DataSchemaFactory = (container: ServiceContainer) => DataSchema;
|
|
10
10
|
*/
|
11
11
|
export type DataSchemaOrFactory = DataSchema | DataSchemaFactory;
|
12
12
|
/**
|
13
|
-
* Data schema input.
|
13
|
+
* Data schema decorator input.
|
14
14
|
*/
|
15
|
-
export type
|
15
|
+
export type DataSchemaDecoratorInput = DataSchemaOrFactory | DataType;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Prototype } from '../../types.js';
|
2
|
-
import { DataSchemaInput } from '../../data-schema-types.js';
|
3
2
|
import { RequestDataMetadata } from './request-data-metadata.js';
|
3
|
+
import { DataSchemaDecoratorInput } from '../../data-schema-types.js';
|
4
4
|
/**
|
5
5
|
* Request data options.
|
6
6
|
*/
|
@@ -14,13 +14,13 @@ export declare function requestData<T extends object>(options: RequestDataOption
|
|
14
14
|
/**
|
15
15
|
* Decorator aliases.
|
16
16
|
*/
|
17
|
-
export declare const requestParams: (schemaInput?:
|
18
|
-
export declare const requestParam: (propertyKey: string, schemaInput?:
|
19
|
-
export declare const requestQueries: (schemaInput?:
|
20
|
-
export declare const requestQuery: (propertyKey: string, schemaInput?:
|
21
|
-
export declare const requestHeaders: (schemaInput?:
|
22
|
-
export declare const requestHeader: (propertyKey: string, schemaInput?:
|
23
|
-
export declare const requestCookies: (schemaInput?:
|
24
|
-
export declare const requestCookie: (propertyKey: string, schemaInput?:
|
25
|
-
export declare const requestBody: (schemaInput?:
|
26
|
-
export declare const requestField: (propertyKey: string, schemaInput?:
|
17
|
+
export declare const requestParams: (schemaInput?: DataSchemaDecoratorInput) => (target: Prototype<object>, propertyKey: string, index: number) => void;
|
18
|
+
export declare const requestParam: (propertyKey: string, schemaInput?: DataSchemaDecoratorInput) => (target: Prototype<object>, propertyKey: string, index: number) => void;
|
19
|
+
export declare const requestQueries: (schemaInput?: DataSchemaDecoratorInput) => (target: Prototype<object>, propertyKey: string, index: number) => void;
|
20
|
+
export declare const requestQuery: (propertyKey: string, schemaInput?: DataSchemaDecoratorInput) => (target: Prototype<object>, propertyKey: string, index: number) => void;
|
21
|
+
export declare const requestHeaders: (schemaInput?: DataSchemaDecoratorInput) => (target: Prototype<object>, propertyKey: string, index: number) => void;
|
22
|
+
export declare const requestHeader: (propertyKey: string, schemaInput?: DataSchemaDecoratorInput) => (target: Prototype<object>, propertyKey: string, index: number) => void;
|
23
|
+
export declare const requestCookies: (schemaInput?: DataSchemaDecoratorInput) => (target: Prototype<object>, propertyKey: string, index: number) => void;
|
24
|
+
export declare const requestCookie: (propertyKey: string, schemaInput?: DataSchemaDecoratorInput) => (target: Prototype<object>, propertyKey: string, index: number) => void;
|
25
|
+
export declare const requestBody: (schemaInput?: DataSchemaDecoratorInput) => (target: Prototype<object>, propertyKey: string, index: number) => void;
|
26
|
+
export declare const requestField: (propertyKey: string, schemaInput?: DataSchemaDecoratorInput) => (target: Prototype<object>, propertyKey: string, index: number) => void;
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import { Prototype } from '../../types.js';
|
2
|
-
import {
|
2
|
+
import { DataSchemaDecoratorInput } from '../../data-schema-types.js';
|
3
3
|
/**
|
4
4
|
* Response body decorator.
|
5
5
|
*
|
6
6
|
* @param schemaOrType
|
7
7
|
*/
|
8
|
-
export declare function responseBody<T extends object>(schemaInput?:
|
8
|
+
export declare function responseBody<T extends object>(schemaInput?: DataSchemaDecoratorInput): (target: Prototype<T>, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
package/dist/esm/index.d.ts
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
-
export * from '@e22m4u/js-trie-router';
|
2
1
|
export * from './rest-router.js';
|
3
2
|
export * from './errors/index.js';
|
4
3
|
export * from './decorators/index.js';
|
5
4
|
export * from './data-schema-types.js';
|
6
5
|
export * from './controller-registry.js';
|
6
|
+
export { RouteHandler } from '@e22m4u/js-trie-router';
|
7
|
+
export { RequestContext } from '@e22m4u/js-trie-router';
|
8
|
+
export { RoutePreHandler } from '@e22m4u/js-trie-router';
|
9
|
+
export { RoutePostHandler } from '@e22m4u/js-trie-router';
|
package/dist/esm/index.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
export * from '@e22m4u/js-trie-router';
|
2
1
|
export * from './rest-router.js';
|
3
2
|
export * from './errors/index.js';
|
4
3
|
export * from './decorators/index.js';
|
5
4
|
export * from './data-schema-types.js';
|
6
5
|
export * from './controller-registry.js';
|
6
|
+
export { RequestContext } from '@e22m4u/js-trie-router';
|
@@ -1,4 +1,6 @@
|
|
1
1
|
import { Constructor } from './types.js';
|
2
|
+
import { HookType } from '@e22m4u/js-trie-router';
|
3
|
+
import { RouterHook } from '@e22m4u/js-trie-router';
|
2
4
|
import { DebuggableService } from './debuggable-service.js';
|
3
5
|
import { ControllerRootOptions } from './controller-registry.js';
|
4
6
|
/**
|
@@ -16,4 +18,11 @@ export declare class RestRouter extends DebuggableService {
|
|
16
18
|
* @param options
|
17
19
|
*/
|
18
20
|
addController<T extends object>(ctor: Constructor<T>, options?: ControllerRootOptions): this;
|
21
|
+
/**
|
22
|
+
* Add hook.
|
23
|
+
*
|
24
|
+
* @param type
|
25
|
+
* @param hook
|
26
|
+
*/
|
27
|
+
addHook(type: HookType, hook: RouterHook): this;
|
19
28
|
}
|
package/dist/esm/rest-router.js
CHANGED
@@ -21,4 +21,14 @@ export class RestRouter extends DebuggableService {
|
|
21
21
|
this.getService(ControllerRegistry).addController(ctor, options);
|
22
22
|
return this;
|
23
23
|
}
|
24
|
+
/**
|
25
|
+
* Add hook.
|
26
|
+
*
|
27
|
+
* @param type
|
28
|
+
* @param hook
|
29
|
+
*/
|
30
|
+
addHook(type, hook) {
|
31
|
+
this.getService(TrieRouter).addHook(type, hook);
|
32
|
+
return this;
|
33
|
+
}
|
24
34
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@e22m4u/ts-rest-router",
|
3
|
-
"version": "0.6.
|
3
|
+
"version": "0.6.3",
|
4
4
|
"description": "Декларативный REST-маршрутизатор на основе контроллеров для TypeScript",
|
5
5
|
"author": "Mikhail Evstropov <e22m4u@yandex.ru>",
|
6
6
|
"license": "MIT",
|
@@ -45,7 +45,7 @@
|
|
45
45
|
"@e22m4u/js-format": "~0.2.0",
|
46
46
|
"@e22m4u/js-service": "~0.4.2",
|
47
47
|
"@e22m4u/js-trie-router": "~0.3.1",
|
48
|
-
"@e22m4u/ts-data-schema": "~0.4.
|
48
|
+
"@e22m4u/ts-data-schema": "~0.4.5",
|
49
49
|
"@e22m4u/ts-reflector": "~0.1.8",
|
50
50
|
"http-errors": "~2.0.0"
|
51
51
|
},
|
package/src/data-schema-types.ts
CHANGED
@@ -13,6 +13,6 @@ export type DataSchemaFactory = (container: ServiceContainer) => DataSchema;
|
|
13
13
|
export type DataSchemaOrFactory = DataSchema | DataSchemaFactory;
|
14
14
|
|
15
15
|
/**
|
16
|
-
* Data schema input.
|
16
|
+
* Data schema decorator input.
|
17
17
|
*/
|
18
|
-
export type
|
18
|
+
export type DataSchemaDecoratorInput = DataSchemaOrFactory | DataType;
|
@@ -4,12 +4,12 @@ import {Constructor} from '../../types.js';
|
|
4
4
|
import {DataType} from '@e22m4u/ts-data-schema';
|
5
5
|
import {DataSchema} from '@e22m4u/ts-data-schema';
|
6
6
|
import {DecoratorTargetType} from '@e22m4u/ts-reflector';
|
7
|
-
import {DataSchemaInput} from '../../data-schema-types.js';
|
8
7
|
import {getDecoratorTargetType} from '@e22m4u/ts-reflector';
|
9
8
|
import {RequestDataSource} from './request-data-metadata.js';
|
10
9
|
import {RequestDataMetadata} from './request-data-metadata.js';
|
11
10
|
import {DataSchemaOrFactory} from '../../data-schema-types.js';
|
12
11
|
import {RequestDataReflector} from './request-data-reflector.js';
|
12
|
+
import {DataSchemaDecoratorInput} from '../../data-schema-types.js';
|
13
13
|
|
14
14
|
/**
|
15
15
|
* Request data options.
|
@@ -44,7 +44,7 @@ export function requestData<T extends object>(options: RequestDataOptions) {
|
|
44
44
|
* @param source
|
45
45
|
*/
|
46
46
|
function createRequestDataDecoratorWithSource(source: RequestDataSource) {
|
47
|
-
return function (schemaInput?:
|
47
|
+
return function (schemaInput?: DataSchemaDecoratorInput) {
|
48
48
|
let schema: DataSchemaOrFactory;
|
49
49
|
if (typeof schemaInput === 'function' || typeof schemaInput === 'object') {
|
50
50
|
schema = schemaInput;
|
@@ -65,7 +65,10 @@ function createRequestDataDecoratorWithSource(source: RequestDataSource) {
|
|
65
65
|
function createRequestDataPropertyDecoratorWithSource(
|
66
66
|
source: RequestDataSource,
|
67
67
|
) {
|
68
|
-
return function (
|
68
|
+
return function (
|
69
|
+
propertyKey: string,
|
70
|
+
schemaInput?: DataSchemaDecoratorInput,
|
71
|
+
) {
|
69
72
|
const rootSchema: DataSchema = {type: DataType.OBJECT};
|
70
73
|
const properties = {} as NoUndef<DataSchema['properties']>;
|
71
74
|
let schemaOrFactory: DataSchemaOrFactory = rootSchema;
|
@@ -1,17 +1,19 @@
|
|
1
1
|
import {Prototype} from '../../types.js';
|
2
2
|
import {Constructor} from '../../types.js';
|
3
3
|
import {DecoratorTargetType} from '@e22m4u/ts-reflector';
|
4
|
-
import {DataSchemaInput} from '../../data-schema-types.js';
|
5
4
|
import {getDecoratorTargetType} from '@e22m4u/ts-reflector';
|
6
5
|
import {DataSchemaOrFactory} from '../../data-schema-types.js';
|
7
6
|
import {ResponseBodyReflector} from './response-body-reflector.js';
|
7
|
+
import {DataSchemaDecoratorInput} from '../../data-schema-types.js';
|
8
8
|
|
9
9
|
/**
|
10
10
|
* Response body decorator.
|
11
11
|
*
|
12
12
|
* @param schemaOrType
|
13
13
|
*/
|
14
|
-
export function responseBody<T extends object>(
|
14
|
+
export function responseBody<T extends object>(
|
15
|
+
schemaInput?: DataSchemaDecoratorInput,
|
16
|
+
) {
|
15
17
|
return function (
|
16
18
|
target: Prototype<T>,
|
17
19
|
propertyKey: string,
|
package/src/index.ts
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
-
export * from '@e22m4u/js-trie-router';
|
2
|
-
|
3
1
|
export * from './rest-router.js';
|
4
2
|
export * from './errors/index.js';
|
5
3
|
export * from './decorators/index.js';
|
6
4
|
export * from './data-schema-types.js';
|
7
5
|
export * from './controller-registry.js';
|
6
|
+
|
7
|
+
export {RouteHandler} from '@e22m4u/js-trie-router';
|
8
|
+
export {RequestContext} from '@e22m4u/js-trie-router';
|
9
|
+
export {RoutePreHandler} from '@e22m4u/js-trie-router';
|
10
|
+
export {RoutePostHandler} from '@e22m4u/js-trie-router';
|
package/src/rest-router.ts
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
import {Constructor} from './types.js';
|
2
|
+
import {HookType} from '@e22m4u/js-trie-router';
|
3
|
+
import {RouterHook} from '@e22m4u/js-trie-router';
|
2
4
|
import {TrieRouter} from '@e22m4u/js-trie-router';
|
3
5
|
import {DebuggableService} from './debuggable-service.js';
|
4
6
|
import {ControllerRegistry} from './controller-registry.js';
|
@@ -28,4 +30,15 @@ export class RestRouter extends DebuggableService {
|
|
28
30
|
this.getService(ControllerRegistry).addController(ctor, options);
|
29
31
|
return this;
|
30
32
|
}
|
33
|
+
|
34
|
+
/**
|
35
|
+
* Add hook.
|
36
|
+
*
|
37
|
+
* @param type
|
38
|
+
* @param hook
|
39
|
+
*/
|
40
|
+
addHook(type: HookType, hook: RouterHook) {
|
41
|
+
this.getService(TrieRouter).addHook(type, hook);
|
42
|
+
return this;
|
43
|
+
}
|
31
44
|
}
|