@midwayjs/decorator 2.12.9 → 2.14.0
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/CHANGELOG.md +40 -0
- package/README.md +1 -1
- package/dist/annotation/aspect.js +3 -3
- package/dist/annotation/autoload.js +1 -1
- package/dist/annotation/configuration.js +1 -1
- package/dist/annotation/inject.js +2 -2
- package/dist/annotation/objectDef.js +5 -5
- package/dist/annotation/pipeline.js +2 -2
- package/dist/annotation/priority.js +1 -1
- package/dist/annotation/provide.js +1 -1
- package/dist/annotation/queue.js +2 -2
- package/dist/annotation/rule.d.ts +2 -0
- package/dist/annotation/rule.js +14 -9
- package/dist/annotation/schedule.js +3 -3
- package/dist/annotation/task.js +2 -2
- package/dist/annotation/taskLocal.js +2 -2
- package/dist/annotation/validate.d.ts +7 -1
- package/dist/annotation/validate.js +20 -8
- package/dist/common/decoratorManager.d.ts +8 -0
- package/dist/common/decoratorManager.js +58 -9
- package/dist/faas/fun.js +9 -9
- package/dist/faas/handler.js +2 -2
- package/dist/framework/app.js +2 -2
- package/dist/framework/config.js +2 -2
- package/dist/framework/logger.js +2 -2
- package/dist/framework/plugin.js +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/microservice/consumer.js +3 -3
- package/dist/microservice/provider.js +6 -6
- package/dist/microservice/rabbitmqListener.js +1 -1
- package/dist/rpc/hsf.js +3 -3
- package/dist/util/dtoHelper.d.ts +6 -0
- package/dist/util/dtoHelper.js +32 -0
- package/dist/util/index.d.ts +4 -0
- package/dist/util/index.js +10 -1
- package/dist/web/controller.js +3 -3
- package/dist/web/paramMapping.js +2 -2
- package/dist/web/requestMapping.js +2 -2
- package/dist/web/response.js +5 -5
- package/dist/ws/webSocketController.js +3 -3
- package/dist/ws/webSocketEvent.js +5 -5
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,46 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [2.14.0](https://github.com/midwayjs/midway/compare/v2.13.5...v2.14.0) (2021-12-06)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* express routing middleware takes effect at the controller level ([#1364](https://github.com/midwayjs/midway/issues/1364)) ([5d5f299](https://github.com/midwayjs/midway/commit/5d5f2992be116ca71b21f01fd782e3a2ac072496))
|
|
12
|
+
* throws http code 422 when validation failed ([#1374](https://github.com/midwayjs/midway/issues/1374)) ([960d259](https://github.com/midwayjs/midway/commit/960d25909191558a4509632333d425be10a04813))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
## [2.13.2](https://github.com/midwayjs/midway/compare/v2.13.1...v2.13.2) (2021-09-09)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Bug Fixes
|
|
22
|
+
|
|
23
|
+
* remove testKeyMap in testKeyMap ([901dad1](https://github.com/midwayjs/midway/commit/901dad177e07732748d169868a38a9c5813a82a7))
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### Features
|
|
27
|
+
|
|
28
|
+
* dto helper ([9f64ec1](https://github.com/midwayjs/midway/commit/9f64ec110b16371dc2e9492601d04e9fdd95082b))
|
|
29
|
+
* dto helper support extend method ([5f32bd5](https://github.com/midwayjs/midway/commit/5f32bd55c23e76d5edbef6c2f07a900bd304573a))
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
# [2.13.0](https://github.com/midwayjs/midway/compare/v2.12.9...v2.13.0) (2021-09-07)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
### Bug Fixes
|
|
39
|
+
|
|
40
|
+
* can't found id in test case ([#1274](https://github.com/midwayjs/midway/issues/1274)) ([9bd1b96](https://github.com/midwayjs/midway/commit/9bd1b96d02ea08f6f1c80f5cef9f68a605cea2ca))
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
6
46
|
## [2.12.9](https://github.com/midwayjs/midway/compare/v2.12.8...v2.12.9) (2021-09-01)
|
|
7
47
|
|
|
8
48
|
**Note:** Version bump only for package @midwayjs/decorator
|
package/README.md
CHANGED
|
@@ -5,16 +5,16 @@ const __1 = require("..");
|
|
|
5
5
|
const objectDef_1 = require("./objectDef");
|
|
6
6
|
function Aspect(aspectTarget, match, priority) {
|
|
7
7
|
return function (target) {
|
|
8
|
-
__1.saveModule(__1.ASPECT_KEY, target);
|
|
8
|
+
(0, __1.saveModule)(__1.ASPECT_KEY, target);
|
|
9
9
|
const aspectTargets = [].concat(aspectTarget);
|
|
10
10
|
for (const aspectTarget of aspectTargets) {
|
|
11
|
-
__1.attachClassMetadata(__1.ASPECT_KEY, {
|
|
11
|
+
(0, __1.attachClassMetadata)(__1.ASPECT_KEY, {
|
|
12
12
|
aspectTarget,
|
|
13
13
|
match,
|
|
14
14
|
priority,
|
|
15
15
|
}, target);
|
|
16
16
|
}
|
|
17
|
-
objectDef_1.Scope(__1.ScopeEnum.Singleton);
|
|
17
|
+
(0, objectDef_1.Scope)(__1.ScopeEnum.Singleton);
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
exports.Aspect = Aspect;
|
|
@@ -4,7 +4,7 @@ exports.Autoload = void 0;
|
|
|
4
4
|
const decoratorManager_1 = require("../common/decoratorManager");
|
|
5
5
|
function Autoload() {
|
|
6
6
|
return function (target) {
|
|
7
|
-
decoratorManager_1.savePreloadModule(target);
|
|
7
|
+
(0, decoratorManager_1.savePreloadModule)(target);
|
|
8
8
|
};
|
|
9
9
|
}
|
|
10
10
|
exports.Autoload = Autoload;
|
|
@@ -4,7 +4,7 @@ exports.Configuration = void 0;
|
|
|
4
4
|
const __1 = require("../");
|
|
5
5
|
function Configuration(options = {}) {
|
|
6
6
|
return (target) => {
|
|
7
|
-
__1.saveClassMetadata(__1.CONFIGURATION_KEY, options, target);
|
|
7
|
+
(0, __1.saveClassMetadata)(__1.CONFIGURATION_KEY, options, target);
|
|
8
8
|
};
|
|
9
9
|
}
|
|
10
10
|
exports.Configuration = Configuration;
|
|
@@ -5,10 +5,10 @@ const __1 = require("../");
|
|
|
5
5
|
function Inject(identifier) {
|
|
6
6
|
return function (target, targetKey, index) {
|
|
7
7
|
if (typeof index === 'number') {
|
|
8
|
-
__1.saveConstructorInject({ target, targetKey, identifier, index });
|
|
8
|
+
(0, __1.saveConstructorInject)({ target, targetKey, identifier, index });
|
|
9
9
|
}
|
|
10
10
|
else {
|
|
11
|
-
__1.savePropertyInject({ target, targetKey, identifier });
|
|
11
|
+
(0, __1.savePropertyInject)({ target, targetKey, identifier });
|
|
12
12
|
}
|
|
13
13
|
};
|
|
14
14
|
}
|
|
@@ -6,21 +6,21 @@ const debug = require('util').debuglog('decorator:context:obj_def');
|
|
|
6
6
|
function Async() {
|
|
7
7
|
return function (target) {
|
|
8
8
|
debug(`set [async] property in [${target.name}]`);
|
|
9
|
-
return __1.saveObjectDefProps(target, { isAsync: true });
|
|
9
|
+
return (0, __1.saveObjectDefProps)(target, { isAsync: true });
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
12
|
exports.Async = Async;
|
|
13
13
|
function Init() {
|
|
14
14
|
return function (target, propertyKey) {
|
|
15
15
|
debug(`set [init] property in [${target.constructor.name}]`);
|
|
16
|
-
return __1.saveObjectDefProps(target.constructor, { initMethod: propertyKey });
|
|
16
|
+
return (0, __1.saveObjectDefProps)(target.constructor, { initMethod: propertyKey });
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
exports.Init = Init;
|
|
20
20
|
function Destroy() {
|
|
21
21
|
return function (target, propertyKey) {
|
|
22
22
|
debug(`set [destroy] property in [${target.constructor.name}]`);
|
|
23
|
-
return __1.saveObjectDefProps(target.constructor, {
|
|
23
|
+
return (0, __1.saveObjectDefProps)(target.constructor, {
|
|
24
24
|
destroyMethod: propertyKey,
|
|
25
25
|
});
|
|
26
26
|
};
|
|
@@ -29,14 +29,14 @@ exports.Destroy = Destroy;
|
|
|
29
29
|
function Scope(scope = __1.ScopeEnum.Singleton) {
|
|
30
30
|
return function (target) {
|
|
31
31
|
debug(`set [scope] property in [${target.name}]`);
|
|
32
|
-
return __1.saveObjectDefProps(target, { scope });
|
|
32
|
+
return (0, __1.saveObjectDefProps)(target, { scope });
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
35
|
exports.Scope = Scope;
|
|
36
36
|
function Autowire(isAutowire = true) {
|
|
37
37
|
return function (target) {
|
|
38
38
|
debug(`set [autowire] property in [${target.name}]`);
|
|
39
|
-
return __1.saveObjectDefProps(target, { isAutowire });
|
|
39
|
+
return (0, __1.saveObjectDefProps)(target, { isAutowire });
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
42
|
exports.Autowire = Autowire;
|
|
@@ -5,7 +5,7 @@ const __1 = require("../");
|
|
|
5
5
|
function Pipeline(valves) {
|
|
6
6
|
return function (target, targetKey, index) {
|
|
7
7
|
if (typeof index === 'number') {
|
|
8
|
-
__1.saveConstructorInject({
|
|
8
|
+
(0, __1.saveConstructorInject)({
|
|
9
9
|
target,
|
|
10
10
|
targetKey,
|
|
11
11
|
identifier: __1.PIPELINE_IDENTIFIER,
|
|
@@ -14,7 +14,7 @@ function Pipeline(valves) {
|
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
16
|
else {
|
|
17
|
-
__1.savePropertyInject({
|
|
17
|
+
(0, __1.savePropertyInject)({
|
|
18
18
|
target,
|
|
19
19
|
targetKey,
|
|
20
20
|
identifier: __1.PIPELINE_IDENTIFIER,
|
|
@@ -4,7 +4,7 @@ exports.Priority = void 0;
|
|
|
4
4
|
const __1 = require("../");
|
|
5
5
|
function Priority(priority) {
|
|
6
6
|
return (target) => {
|
|
7
|
-
__1.saveClassMetadata(__1.PRIORITY_KEY, priority, target);
|
|
7
|
+
(0, __1.saveClassMetadata)(__1.PRIORITY_KEY, priority, target);
|
|
8
8
|
};
|
|
9
9
|
}
|
|
10
10
|
exports.Priority = Priority;
|
package/dist/annotation/queue.js
CHANGED
|
@@ -5,8 +5,8 @@ const __1 = require("../");
|
|
|
5
5
|
const constant_1 = require("../constant");
|
|
6
6
|
function Queue(options) {
|
|
7
7
|
return function (target) {
|
|
8
|
-
__1.saveModule(constant_1.MODULE_TASK_QUEUE_KEY, target);
|
|
9
|
-
__1.saveClassMetadata(constant_1.MODULE_TASK_QUEUE_OPTIONS, {
|
|
8
|
+
(0, __1.saveModule)(constant_1.MODULE_TASK_QUEUE_KEY, target);
|
|
9
|
+
(0, __1.saveClassMetadata)(constant_1.MODULE_TASK_QUEUE_OPTIONS, {
|
|
10
10
|
options,
|
|
11
11
|
name: target.name,
|
|
12
12
|
}, target);
|
package/dist/annotation/rule.js
CHANGED
|
@@ -10,31 +10,36 @@ function Rule(rule, options = { required: true }) {
|
|
|
10
10
|
// 函数装饰器
|
|
11
11
|
const [target, propertyKey] = args;
|
|
12
12
|
if (!joi.isSchema(rule)) {
|
|
13
|
-
rule =
|
|
14
|
-
|
|
13
|
+
rule = joi
|
|
14
|
+
.object((0, __1.getClassMetadata)(__1.RULES_KEY, rule))
|
|
15
|
+
.meta({ id: rule.name });
|
|
16
|
+
if ((0, __1.getPropertyType)(target, propertyKey).name === 'Array') {
|
|
15
17
|
rule = joi.array().items(rule);
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
if (options.min) {
|
|
19
|
+
rule = rule.min(options.min);
|
|
20
|
+
}
|
|
21
|
+
if (options.max) {
|
|
22
|
+
rule = rule.max(options.max);
|
|
23
|
+
}
|
|
19
24
|
}
|
|
20
25
|
if (options.required) {
|
|
21
26
|
rule = rule.required();
|
|
22
27
|
}
|
|
23
28
|
}
|
|
24
|
-
__1.attachClassMetadata(__1.RULES_KEY, rule, target, propertyKey);
|
|
29
|
+
(0, __1.attachClassMetadata)(__1.RULES_KEY, rule, target, propertyKey);
|
|
25
30
|
}
|
|
26
31
|
else {
|
|
27
32
|
//类的装饰器
|
|
28
|
-
const rules = __1.getClassMetadata(__1.RULES_KEY, rule);
|
|
33
|
+
const rules = (0, __1.getClassMetadata)(__1.RULES_KEY, rule);
|
|
29
34
|
if (rules) {
|
|
30
|
-
let currentRule = __1.getClassMetadata(__1.RULES_KEY, args[0]);
|
|
35
|
+
let currentRule = (0, __1.getClassMetadata)(__1.RULES_KEY, args[0]);
|
|
31
36
|
currentRule = currentRule !== null && currentRule !== void 0 ? currentRule : {};
|
|
32
37
|
Object.keys(rules).map(item => {
|
|
33
38
|
if (!currentRule[item]) {
|
|
34
39
|
currentRule[item] = rules[item];
|
|
35
40
|
}
|
|
36
41
|
});
|
|
37
|
-
__1.saveClassMetadata(__1.RULES_KEY, currentRule, args[0]);
|
|
42
|
+
(0, __1.saveClassMetadata)(__1.RULES_KEY, currentRule, args[0]);
|
|
38
43
|
}
|
|
39
44
|
}
|
|
40
45
|
};
|
|
@@ -5,9 +5,9 @@ const __1 = require("../");
|
|
|
5
5
|
const objectDef_1 = require("./objectDef");
|
|
6
6
|
function Schedule(scheduleOpts) {
|
|
7
7
|
return function (target) {
|
|
8
|
-
__1.saveModule(__1.SCHEDULE_KEY, target);
|
|
9
|
-
__1.saveClassMetadata(__1.SCHEDULE_KEY, scheduleOpts, target);
|
|
10
|
-
objectDef_1.Scope(__1.ScopeEnum.Request)(target);
|
|
8
|
+
(0, __1.saveModule)(__1.SCHEDULE_KEY, target);
|
|
9
|
+
(0, __1.saveClassMetadata)(__1.SCHEDULE_KEY, scheduleOpts, target);
|
|
10
|
+
(0, objectDef_1.Scope)(__1.ScopeEnum.Request)(target);
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
13
|
exports.Schedule = Schedule;
|
package/dist/annotation/task.js
CHANGED
|
@@ -5,8 +5,8 @@ const __1 = require("../");
|
|
|
5
5
|
const constant_1 = require("../constant");
|
|
6
6
|
function Task(options) {
|
|
7
7
|
return function (target, propertyKey, descriptor) {
|
|
8
|
-
__1.saveModule(constant_1.MODULE_TASK_KEY, target.constructor);
|
|
9
|
-
__1.attachClassMetadata(constant_1.MODULE_TASK_METADATA, {
|
|
8
|
+
(0, __1.saveModule)(constant_1.MODULE_TASK_KEY, target.constructor);
|
|
9
|
+
(0, __1.attachClassMetadata)(constant_1.MODULE_TASK_METADATA, {
|
|
10
10
|
options,
|
|
11
11
|
propertyKey,
|
|
12
12
|
value: descriptor.value,
|
|
@@ -5,8 +5,8 @@ const __1 = require("../");
|
|
|
5
5
|
const constant_1 = require("../constant");
|
|
6
6
|
function TaskLocal(options) {
|
|
7
7
|
return function (target, propertyKey, descriptor) {
|
|
8
|
-
__1.saveModule(constant_1.MODULE_TASK_TASK_LOCAL_KEY, target.constructor);
|
|
9
|
-
__1.attachClassMetadata(constant_1.MODULE_TASK_TASK_LOCAL_OPTIONS, {
|
|
8
|
+
(0, __1.saveModule)(constant_1.MODULE_TASK_TASK_LOCAL_KEY, target.constructor);
|
|
9
|
+
(0, __1.attachClassMetadata)(constant_1.MODULE_TASK_TASK_LOCAL_OPTIONS, {
|
|
10
10
|
options,
|
|
11
11
|
propertyKey,
|
|
12
12
|
value: descriptor.value,
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
interface ValidateOptions {
|
|
2
|
+
isTransform?: boolean;
|
|
3
|
+
errorStatus?: number;
|
|
4
|
+
}
|
|
5
|
+
export declare function CustomValidate(opt: ValidateOptions): (customOpt?: ValidateOptions) => (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => void;
|
|
6
|
+
export declare function Validate(opt?: boolean | ValidateOptions): (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => void;
|
|
7
|
+
export {};
|
|
2
8
|
//# sourceMappingURL=validate.d.ts.map
|
|
@@ -1,29 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Validate = void 0;
|
|
3
|
+
exports.Validate = exports.CustomValidate = void 0;
|
|
4
4
|
const __1 = require("..");
|
|
5
5
|
const class_transformer_1 = require("class-transformer");
|
|
6
|
-
const
|
|
7
|
-
function
|
|
6
|
+
const joi = require("joi");
|
|
7
|
+
function CustomValidate(opt) {
|
|
8
|
+
return (customOpt = {}) => Validate({ ...opt, ...customOpt });
|
|
9
|
+
}
|
|
10
|
+
exports.CustomValidate = CustomValidate;
|
|
11
|
+
function Validate(opt = true) {
|
|
8
12
|
return function (target, propertyKey, descriptor) {
|
|
9
13
|
const origin = descriptor.value;
|
|
10
|
-
const paramTypes = __1.getMethodParamTypes(target, propertyKey);
|
|
14
|
+
const paramTypes = (0, __1.getMethodParamTypes)(target, propertyKey);
|
|
15
|
+
const options = typeof opt === 'boolean' ? { isTransform: opt } : opt;
|
|
16
|
+
if (!('isTransform' in options)) {
|
|
17
|
+
options.isTransform = true;
|
|
18
|
+
}
|
|
11
19
|
descriptor.value = function (...args) {
|
|
12
20
|
for (let i = 0; i < paramTypes.length; i++) {
|
|
13
21
|
const item = paramTypes[i];
|
|
14
|
-
const rules = __1.
|
|
22
|
+
const rules = (0, __1.getClassExtendedMetadata)(__1.RULES_KEY, item);
|
|
15
23
|
if (rules) {
|
|
16
|
-
const schema =
|
|
24
|
+
const schema = joi.object(rules);
|
|
17
25
|
const result = schema.validate(args[i]);
|
|
18
26
|
if (result.error) {
|
|
27
|
+
if (options.errorStatus) {
|
|
28
|
+
result.error.status =
|
|
29
|
+
options.errorStatus;
|
|
30
|
+
}
|
|
19
31
|
throw result.error;
|
|
20
32
|
}
|
|
21
33
|
else {
|
|
22
34
|
args[i] = result.value;
|
|
23
35
|
}
|
|
24
36
|
// passed
|
|
25
|
-
if (isTransform) {
|
|
26
|
-
args[i] = class_transformer_1.plainToClass(item, args[i]);
|
|
37
|
+
if (options.isTransform) {
|
|
38
|
+
args[i] = (0, class_transformer_1.plainToClass)(item, args[i]);
|
|
27
39
|
}
|
|
28
40
|
}
|
|
29
41
|
}
|
|
@@ -21,6 +21,7 @@ export declare class DecoratorManager extends Map {
|
|
|
21
21
|
static getDecoratorClassKey(decoratorNameKey: DecoratorKey): string;
|
|
22
22
|
static removeDecoratorClassKeySuffix(decoratorNameKey: DecoratorKey): string;
|
|
23
23
|
static getDecoratorMethodKey(decoratorNameKey: DecoratorKey): string;
|
|
24
|
+
static getDecoratorClsExtendedKey(decoratorNameKey: DecoratorKey): string;
|
|
24
25
|
static getDecoratorClsMethodPrefix(decoratorNameKey: DecoratorKey): string;
|
|
25
26
|
static getDecoratorClsMethodKey(decoratorNameKey: DecoratorKey, methodKey: DecoratorKey): string;
|
|
26
27
|
static getDecoratorMethod(decoratorNameKey: DecoratorKey, methodKey: DecoratorKey): string;
|
|
@@ -97,6 +98,12 @@ export declare function saveClassMetadata(decoratorNameKey: DecoratorKey, data:
|
|
|
97
98
|
* @param groupBy
|
|
98
99
|
*/
|
|
99
100
|
export declare function attachClassMetadata(decoratorNameKey: DecoratorKey, data: any, target: any, groupBy?: string): void;
|
|
101
|
+
/**
|
|
102
|
+
* get data from class assign
|
|
103
|
+
* @param decoratorNameKey
|
|
104
|
+
* @param target
|
|
105
|
+
*/
|
|
106
|
+
export declare function getClassExtendedMetadata(decoratorNameKey: DecoratorKey, target: any): any;
|
|
100
107
|
/**
|
|
101
108
|
* get data from class
|
|
102
109
|
* @param decoratorNameKey
|
|
@@ -314,5 +321,6 @@ export declare function saveProviderId(identifier: ObjectIdentifier, target: any
|
|
|
314
321
|
* @param target class
|
|
315
322
|
*/
|
|
316
323
|
export declare function isProvide(target: any): boolean;
|
|
324
|
+
export declare function getProviderUUId(module: any): string;
|
|
317
325
|
export {};
|
|
318
326
|
//# sourceMappingURL=decoratorManager.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isProvide = exports.saveProviderId = exports.getObjectDefProps = exports.saveObjectDefProps = exports.getPropertyInject = exports.savePropertyInject = exports.getConstructorInject = exports.saveConstructorInject = exports.attachConstructorDataOnClass = exports.getMethodReturnTypes = exports.getPropertyType = exports.getMethodParamTypes = exports.getObjectDefinition = exports.generateProvideId = exports.getProviderId = exports.clearAllModule = exports.resetModule = exports.listModule = exports.saveModule = exports.listPreloadModule = exports.savePreloadModule = exports.getPropertyMetadata = exports.attachPropertyMetadata = exports.savePropertyMetadata = exports.listPropertyDataFromClass = exports.getPropertyDataFromClass = exports.attachPropertyDataToClass = exports.savePropertyDataToClass = exports.getMethodMetadata = exports.attachMethodMetadata = exports.saveMethodMetadata = exports.listMethodDataFromClass = exports.getMethodDataFromClass = exports.attachMethodDataToClass = exports.saveMethodDataToClass = exports.throwErrorForTest = exports.getClassMetadata = exports.attachClassMetadata = exports.saveClassMetadata = exports.DecoratorManager = exports.INJECT_CLASS_KEY_PREFIX = exports.PRELOAD_MODULE_KEY = void 0;
|
|
3
|
+
exports.getProviderUUId = exports.isProvide = exports.saveProviderId = exports.getObjectDefProps = exports.saveObjectDefProps = exports.getPropertyInject = exports.savePropertyInject = exports.getConstructorInject = exports.saveConstructorInject = exports.attachConstructorDataOnClass = exports.getMethodReturnTypes = exports.getPropertyType = exports.getMethodParamTypes = exports.getObjectDefinition = exports.generateProvideId = exports.getProviderId = exports.clearAllModule = exports.resetModule = exports.listModule = exports.saveModule = exports.listPreloadModule = exports.savePreloadModule = exports.getPropertyMetadata = exports.attachPropertyMetadata = exports.savePropertyMetadata = exports.listPropertyDataFromClass = exports.getPropertyDataFromClass = exports.attachPropertyDataToClass = exports.savePropertyDataToClass = exports.getMethodMetadata = exports.attachMethodMetadata = exports.saveMethodMetadata = exports.listMethodDataFromClass = exports.getMethodDataFromClass = exports.attachMethodDataToClass = exports.saveMethodDataToClass = exports.throwErrorForTest = exports.getClassMetadata = exports.getClassExtendedMetadata = exports.attachClassMetadata = exports.saveClassMetadata = exports.DecoratorManager = exports.INJECT_CLASS_KEY_PREFIX = exports.PRELOAD_MODULE_KEY = void 0;
|
|
4
4
|
require("reflect-metadata");
|
|
5
5
|
const constant_1 = require("../constant");
|
|
6
6
|
const errMsg_1 = require("./errMsg");
|
|
@@ -43,6 +43,9 @@ class DecoratorManager extends Map {
|
|
|
43
43
|
static getDecoratorMethodKey(decoratorNameKey) {
|
|
44
44
|
return decoratorNameKey.toString() + '_METHOD';
|
|
45
45
|
}
|
|
46
|
+
static getDecoratorClsExtendedKey(decoratorNameKey) {
|
|
47
|
+
return decoratorNameKey.toString() + '_EXT';
|
|
48
|
+
}
|
|
46
49
|
static getDecoratorClsMethodPrefix(decoratorNameKey) {
|
|
47
50
|
return decoratorNameKey.toString() + '_CLS_METHOD';
|
|
48
51
|
}
|
|
@@ -253,6 +256,41 @@ function attachClassMetadata(decoratorNameKey, data, target, groupBy) {
|
|
|
253
256
|
}
|
|
254
257
|
exports.attachClassMetadata = attachClassMetadata;
|
|
255
258
|
const testKeyMap = new Map();
|
|
259
|
+
/**
|
|
260
|
+
* get data from class assign
|
|
261
|
+
* @param decoratorNameKey
|
|
262
|
+
* @param target
|
|
263
|
+
*/
|
|
264
|
+
function getClassExtendedMetadata(decoratorNameKey, target) {
|
|
265
|
+
const extKey = DecoratorManager.getDecoratorClsExtendedKey(decoratorNameKey);
|
|
266
|
+
let metadata = manager.getMetadata(extKey, target);
|
|
267
|
+
if (metadata !== undefined) {
|
|
268
|
+
return metadata;
|
|
269
|
+
}
|
|
270
|
+
const father = Reflect.getPrototypeOf(target);
|
|
271
|
+
if (father.constructor !== Object) {
|
|
272
|
+
metadata = mergeMeta(getClassExtendedMetadata(decoratorNameKey, father), manager.getMetadata(decoratorNameKey, target));
|
|
273
|
+
}
|
|
274
|
+
manager.saveMetadata(extKey, metadata || null, target);
|
|
275
|
+
return metadata;
|
|
276
|
+
}
|
|
277
|
+
exports.getClassExtendedMetadata = getClassExtendedMetadata;
|
|
278
|
+
function mergeMeta(target, src) {
|
|
279
|
+
if (!target) {
|
|
280
|
+
target = src;
|
|
281
|
+
src = null;
|
|
282
|
+
}
|
|
283
|
+
if (!target) {
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
286
|
+
if (Array.isArray(target)) {
|
|
287
|
+
return target.concat(src || []);
|
|
288
|
+
}
|
|
289
|
+
if (typeof target === 'object') {
|
|
290
|
+
return Object.assign({}, target, src);
|
|
291
|
+
}
|
|
292
|
+
throw new Error('can not merge meta that type of ' + typeof target);
|
|
293
|
+
}
|
|
256
294
|
/**
|
|
257
295
|
* get data from class
|
|
258
296
|
* @param decoratorNameKey
|
|
@@ -496,7 +534,7 @@ function getProviderId(module) {
|
|
|
496
534
|
providerId = metaData.id;
|
|
497
535
|
}
|
|
498
536
|
else {
|
|
499
|
-
providerId = util_1.classNamed(module.name);
|
|
537
|
+
providerId = (0, util_1.classNamed)(module.name);
|
|
500
538
|
}
|
|
501
539
|
const meta = getClassMetadata(constant_1.PRIVATE_META_DATA_KEY, module);
|
|
502
540
|
if (providerId && meta) {
|
|
@@ -535,7 +573,7 @@ function getObjectDefinition(module) {
|
|
|
535
573
|
}
|
|
536
574
|
exports.getObjectDefinition = getObjectDefinition;
|
|
537
575
|
function transformTypeFromTSDesign(designFn) {
|
|
538
|
-
if (util_1.isNullOrUndefined(designFn)) {
|
|
576
|
+
if ((0, util_1.isNullOrUndefined)(designFn)) {
|
|
539
577
|
return { name: 'undefined', isBaseType: true, originDesign: designFn };
|
|
540
578
|
}
|
|
541
579
|
switch (designFn.name) {
|
|
@@ -607,7 +645,7 @@ function _tagParameterOrProperty(metadataKey, annotationTarget, propertyName, me
|
|
|
607
645
|
}
|
|
608
646
|
function attachConstructorDataOnClass(identifier, clz, type, index) {
|
|
609
647
|
if (!identifier) {
|
|
610
|
-
const args = util_1.getParamNames(clz);
|
|
648
|
+
const args = (0, util_1.getParamNames)(clz);
|
|
611
649
|
if (clz.length === args.length && index < clz.length) {
|
|
612
650
|
identifier = args[index];
|
|
613
651
|
}
|
|
@@ -631,13 +669,13 @@ exports.attachConstructorDataOnClass = attachConstructorDataOnClass;
|
|
|
631
669
|
function saveConstructorInject(opts) {
|
|
632
670
|
let identifier = opts.identifier;
|
|
633
671
|
if (!identifier) {
|
|
634
|
-
const args = util_1.getParamNames(opts.target);
|
|
672
|
+
const args = (0, util_1.getParamNames)(opts.target);
|
|
635
673
|
if (opts.target.length === args.length && opts.index < opts.target.length) {
|
|
636
674
|
identifier = args[opts.index];
|
|
637
675
|
}
|
|
638
676
|
}
|
|
639
677
|
else if (identifier.includes('@') && !identifier.includes(':')) {
|
|
640
|
-
const args = util_1.getParamNames(opts.target);
|
|
678
|
+
const args = (0, util_1.getParamNames)(opts.target);
|
|
641
679
|
if (opts.target.length === args.length && opts.index < opts.target.length) {
|
|
642
680
|
identifier = `${identifier}:${args[opts.index]}`;
|
|
643
681
|
}
|
|
@@ -656,13 +694,15 @@ exports.getConstructorInject = getConstructorInject;
|
|
|
656
694
|
* @param opts 参数
|
|
657
695
|
*/
|
|
658
696
|
function savePropertyInject(opts) {
|
|
697
|
+
var _a;
|
|
659
698
|
let identifier = opts.identifier;
|
|
660
699
|
if (!identifier) {
|
|
661
700
|
const type = getPropertyType(opts.target, opts.targetKey);
|
|
662
701
|
if (!type.isBaseType &&
|
|
663
|
-
util_1.isClass(type.originDesign) &&
|
|
702
|
+
(0, util_1.isClass)(type.originDesign) &&
|
|
664
703
|
isProvide(type.originDesign)) {
|
|
665
|
-
identifier =
|
|
704
|
+
identifier =
|
|
705
|
+
(_a = getProviderUUId(type.originDesign)) !== null && _a !== void 0 ? _a : getProviderId(type.originDesign);
|
|
666
706
|
}
|
|
667
707
|
if (!identifier) {
|
|
668
708
|
identifier = opts.targetKey;
|
|
@@ -711,11 +751,13 @@ function saveProviderId(identifier, target, override) {
|
|
|
711
751
|
throw new Error(errMsg_1.DUPLICATED_INJECTABLE_DECORATOR);
|
|
712
752
|
}
|
|
713
753
|
if (!identifier) {
|
|
714
|
-
identifier = util_1.classNamed(target.name);
|
|
754
|
+
identifier = (0, util_1.classNamed)(target.name);
|
|
715
755
|
}
|
|
756
|
+
const uuid = (0, util_1.generateRandomId)();
|
|
716
757
|
Reflect.defineMetadata(constant_1.TAGGED_CLS, {
|
|
717
758
|
id: identifier,
|
|
718
759
|
originName: target.name,
|
|
760
|
+
uuid,
|
|
719
761
|
}, target);
|
|
720
762
|
if (!Reflect.hasMetadata(constant_1.OBJ_DEF_CLS, target)) {
|
|
721
763
|
Reflect.defineMetadata(constant_1.OBJ_DEF_CLS, {}, target);
|
|
@@ -731,4 +773,11 @@ function isProvide(target) {
|
|
|
731
773
|
return Reflect.hasOwnMetadata(constant_1.TAGGED_CLS, target);
|
|
732
774
|
}
|
|
733
775
|
exports.isProvide = isProvide;
|
|
776
|
+
function getProviderUUId(module) {
|
|
777
|
+
const metaData = Reflect.getMetadata(constant_1.TAGGED_CLS, module);
|
|
778
|
+
if (metaData && metaData.uuid) {
|
|
779
|
+
return metaData.uuid;
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
exports.getProviderUUId = getProviderUUId;
|
|
734
783
|
//# sourceMappingURL=decoratorManager.js.map
|
package/dist/faas/fun.js
CHANGED
|
@@ -13,15 +13,15 @@ function Func(funHandler, functionOptions) {
|
|
|
13
13
|
// If target is function, @Func annotate class
|
|
14
14
|
if (typeof target === 'function') {
|
|
15
15
|
// save target
|
|
16
|
-
__1.saveModule(__1.FUNC_KEY, target);
|
|
17
|
-
__1.attachClassMetadata(__1.FUNC_KEY, Object.assign({ funHandler }, functionOptions), target);
|
|
16
|
+
(0, __1.saveModule)(__1.FUNC_KEY, target);
|
|
17
|
+
(0, __1.attachClassMetadata)(__1.FUNC_KEY, Object.assign({ funHandler }, functionOptions), target);
|
|
18
18
|
// register data
|
|
19
|
-
annotation_1.Scope(__1.ScopeEnum.Request)(target);
|
|
19
|
+
(0, annotation_1.Scope)(__1.ScopeEnum.Request)(target);
|
|
20
20
|
}
|
|
21
21
|
else {
|
|
22
22
|
// If target is instance, @Func annotate class member method
|
|
23
|
-
__1.saveModule(__1.FUNC_KEY, target.constructor);
|
|
24
|
-
__1.attachClassMetadata(__1.FUNC_KEY, Object.assign({
|
|
23
|
+
(0, __1.saveModule)(__1.FUNC_KEY, target.constructor);
|
|
24
|
+
(0, __1.attachClassMetadata)(__1.FUNC_KEY, Object.assign({
|
|
25
25
|
funHandler,
|
|
26
26
|
key,
|
|
27
27
|
descriptor,
|
|
@@ -32,7 +32,7 @@ function Func(funHandler, functionOptions) {
|
|
|
32
32
|
exports.Func = Func;
|
|
33
33
|
function ServerlessFunction(options) {
|
|
34
34
|
return (target, key, descriptor) => {
|
|
35
|
-
__1.savePropertyMetadata(__1.SERVERLESS_FUNC_KEY, options, target, key);
|
|
35
|
+
(0, __1.savePropertyMetadata)(__1.SERVERLESS_FUNC_KEY, options, target, key);
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
38
|
exports.ServerlessFunction = ServerlessFunction;
|
|
@@ -44,13 +44,13 @@ function ServerlessTrigger(type, metadata = {}) {
|
|
|
44
44
|
metadata['method'] = (_a = metadata['method']) !== null && _a !== void 0 ? _a : 'get';
|
|
45
45
|
}
|
|
46
46
|
metadata['functionName'] =
|
|
47
|
-
(_b = metadata['functionName']) !== null && _b !== void 0 ? _b : __1.getProviderId(target.constructor).replace(/[:#]/g, '-') +
|
|
47
|
+
(_b = metadata['functionName']) !== null && _b !== void 0 ? _b : (0, __1.getProviderId)(target.constructor).replace(/[:#]/g, '-') +
|
|
48
48
|
'-' +
|
|
49
49
|
functionName;
|
|
50
|
-
__1.saveModule(__1.FUNC_KEY, target.constructor);
|
|
50
|
+
(0, __1.saveModule)(__1.FUNC_KEY, target.constructor);
|
|
51
51
|
// new method decorator
|
|
52
52
|
metadata = metadata || {};
|
|
53
|
-
__1.attachClassMetadata(__1.FUNC_KEY, {
|
|
53
|
+
(0, __1.attachClassMetadata)(__1.FUNC_KEY, {
|
|
54
54
|
type,
|
|
55
55
|
methodName: functionName,
|
|
56
56
|
functionName: metadata.functionName,
|
package/dist/faas/handler.js
CHANGED
|
@@ -9,8 +9,8 @@ function Handler(funHandler, functionOptions) {
|
|
|
9
9
|
}
|
|
10
10
|
return (target, propertyKey, descriptor) => {
|
|
11
11
|
// If target is instance, @Func annotate class member method
|
|
12
|
-
__1.saveModule(__1.FUNC_KEY, target.constructor);
|
|
13
|
-
__1.attachClassMetadata(__1.FUNC_KEY, Object.assign({
|
|
12
|
+
(0, __1.saveModule)(__1.FUNC_KEY, target.constructor);
|
|
13
|
+
(0, __1.attachClassMetadata)(__1.FUNC_KEY, Object.assign({
|
|
14
14
|
funHandler,
|
|
15
15
|
key: propertyKey,
|
|
16
16
|
descriptor,
|
package/dist/framework/app.js
CHANGED
|
@@ -5,10 +5,10 @@ const __1 = require("../");
|
|
|
5
5
|
function App(type) {
|
|
6
6
|
return function (target, targetKey, index) {
|
|
7
7
|
if (typeof index === 'number') {
|
|
8
|
-
__1.attachConstructorDataOnClass(targetKey, target, __1.APPLICATION_KEY, index);
|
|
8
|
+
(0, __1.attachConstructorDataOnClass)(targetKey, target, __1.APPLICATION_KEY, index);
|
|
9
9
|
}
|
|
10
10
|
else {
|
|
11
|
-
__1.attachClassMetadata(__1.APPLICATION_KEY, {
|
|
11
|
+
(0, __1.attachClassMetadata)(__1.APPLICATION_KEY, {
|
|
12
12
|
key: __1.APPLICATION_KEY,
|
|
13
13
|
propertyName: targetKey,
|
|
14
14
|
meta: {
|
package/dist/framework/config.js
CHANGED
|
@@ -5,7 +5,7 @@ const __1 = require("../");
|
|
|
5
5
|
function Config(identifier) {
|
|
6
6
|
return function (target, targetKey, index) {
|
|
7
7
|
if (typeof index === 'number') {
|
|
8
|
-
__1.attachConstructorDataOnClass(identifier, target, __1.CONFIG_KEY, index);
|
|
8
|
+
(0, __1.attachConstructorDataOnClass)(identifier, target, __1.CONFIG_KEY, index);
|
|
9
9
|
}
|
|
10
10
|
else {
|
|
11
11
|
if (!identifier) {
|
|
@@ -14,7 +14,7 @@ function Config(identifier) {
|
|
|
14
14
|
if (identifier === __1.ALL) {
|
|
15
15
|
identifier = '';
|
|
16
16
|
}
|
|
17
|
-
__1.attachClassMetadata(__1.CONFIG_KEY, {
|
|
17
|
+
(0, __1.attachClassMetadata)(__1.CONFIG_KEY, {
|
|
18
18
|
key: identifier,
|
|
19
19
|
propertyName: targetKey,
|
|
20
20
|
}, target);
|
package/dist/framework/logger.js
CHANGED
|
@@ -5,13 +5,13 @@ const __1 = require("../");
|
|
|
5
5
|
function Logger(identifier) {
|
|
6
6
|
return function (target, targetKey, index) {
|
|
7
7
|
if (typeof index === 'number') {
|
|
8
|
-
__1.attachConstructorDataOnClass(identifier, target, __1.LOGGER_KEY, index);
|
|
8
|
+
(0, __1.attachConstructorDataOnClass)(identifier, target, __1.LOGGER_KEY, index);
|
|
9
9
|
}
|
|
10
10
|
else {
|
|
11
11
|
if (!identifier) {
|
|
12
12
|
identifier = targetKey;
|
|
13
13
|
}
|
|
14
|
-
__1.attachClassMetadata(__1.LOGGER_KEY, {
|
|
14
|
+
(0, __1.attachClassMetadata)(__1.LOGGER_KEY, {
|
|
15
15
|
key: identifier,
|
|
16
16
|
propertyName: targetKey,
|
|
17
17
|
}, target);
|
package/dist/framework/plugin.js
CHANGED
|
@@ -5,13 +5,13 @@ const __1 = require("../");
|
|
|
5
5
|
function Plugin(identifier) {
|
|
6
6
|
return function (target, targetKey, index) {
|
|
7
7
|
if (typeof index === 'number') {
|
|
8
|
-
__1.attachConstructorDataOnClass(identifier, target, __1.PLUGIN_KEY, index);
|
|
8
|
+
(0, __1.attachConstructorDataOnClass)(identifier, target, __1.PLUGIN_KEY, index);
|
|
9
9
|
}
|
|
10
10
|
else {
|
|
11
11
|
if (!identifier) {
|
|
12
12
|
identifier = targetKey;
|
|
13
13
|
}
|
|
14
|
-
__1.attachClassMetadata(__1.PLUGIN_KEY, {
|
|
14
|
+
(0, __1.attachClassMetadata)(__1.PLUGIN_KEY, {
|
|
15
15
|
key: identifier,
|
|
16
16
|
propertyName: targetKey,
|
|
17
17
|
}, target);
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -34,4 +34,5 @@ __exportStar(require("./microservice/provider"), exports);
|
|
|
34
34
|
__exportStar(require("./microservice/consumer"), exports);
|
|
35
35
|
__exportStar(require("./microservice/rabbitmqListener"), exports);
|
|
36
36
|
__exportStar(require("./util/index"), exports);
|
|
37
|
+
__exportStar(require("./util/dtoHelper"), exports);
|
|
37
38
|
//# sourceMappingURL=index.js.map
|
|
@@ -5,12 +5,12 @@ const __1 = require("../");
|
|
|
5
5
|
const annotation_1 = require("../annotation");
|
|
6
6
|
function Consumer(type, options = {}) {
|
|
7
7
|
return (target) => {
|
|
8
|
-
__1.saveModule(__1.MS_CONSUMER_KEY, target);
|
|
9
|
-
__1.saveClassMetadata(__1.MS_CONSUMER_KEY, {
|
|
8
|
+
(0, __1.saveModule)(__1.MS_CONSUMER_KEY, target);
|
|
9
|
+
(0, __1.saveClassMetadata)(__1.MS_CONSUMER_KEY, {
|
|
10
10
|
type,
|
|
11
11
|
metadata: options,
|
|
12
12
|
}, target);
|
|
13
|
-
annotation_1.Scope(__1.ScopeEnum.Request)(target);
|
|
13
|
+
(0, annotation_1.Scope)(__1.ScopeEnum.Request)(target);
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
16
|
exports.Consumer = Consumer;
|
|
@@ -5,12 +5,12 @@ const __1 = require("../");
|
|
|
5
5
|
const annotation_1 = require("../annotation");
|
|
6
6
|
function Provider(type, metadata = {}) {
|
|
7
7
|
return (target) => {
|
|
8
|
-
__1.saveModule(__1.MS_PROVIDER_KEY, target);
|
|
9
|
-
__1.saveClassMetadata(__1.MS_PROVIDER_KEY, {
|
|
8
|
+
(0, __1.saveModule)(__1.MS_PROVIDER_KEY, target);
|
|
9
|
+
(0, __1.saveClassMetadata)(__1.MS_PROVIDER_KEY, {
|
|
10
10
|
type,
|
|
11
11
|
metadata,
|
|
12
12
|
}, target);
|
|
13
|
-
annotation_1.Scope(__1.ScopeEnum.Request)(target);
|
|
13
|
+
(0, annotation_1.Scope)(__1.ScopeEnum.Request)(target);
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
16
|
exports.Provider = Provider;
|
|
@@ -26,7 +26,7 @@ function GrpcMethod(methodOptions = {}) {
|
|
|
26
26
|
if (!methodOptions.type) {
|
|
27
27
|
methodOptions.type = GrpcStreamTypeEnum.BASE;
|
|
28
28
|
}
|
|
29
|
-
__1.savePropertyMetadata(__1.MS_GRPC_METHOD_KEY, {
|
|
29
|
+
(0, __1.savePropertyMetadata)(__1.MS_GRPC_METHOD_KEY, {
|
|
30
30
|
methodName: methodOptions.methodName || propertyName,
|
|
31
31
|
type: methodOptions.type,
|
|
32
32
|
onEnd: methodOptions.onEnd,
|
|
@@ -37,7 +37,7 @@ function GrpcMethod(methodOptions = {}) {
|
|
|
37
37
|
exports.GrpcMethod = GrpcMethod;
|
|
38
38
|
function DubboMethod(methodName) {
|
|
39
39
|
return (target, propertyName, descriptor) => {
|
|
40
|
-
__1.attachClassMetadata(__1.MS_DUBBO_METHOD_KEY, {
|
|
40
|
+
(0, __1.attachClassMetadata)(__1.MS_DUBBO_METHOD_KEY, {
|
|
41
41
|
methodName: methodName || propertyName,
|
|
42
42
|
}, target);
|
|
43
43
|
return descriptor;
|
|
@@ -46,7 +46,7 @@ function DubboMethod(methodName) {
|
|
|
46
46
|
exports.DubboMethod = DubboMethod;
|
|
47
47
|
function HSFMethod(methodName) {
|
|
48
48
|
return (target, propertyName, descriptor) => {
|
|
49
|
-
__1.attachClassMetadata(__1.MS_HSF_METHOD_KEY, {
|
|
49
|
+
(0, __1.attachClassMetadata)(__1.MS_HSF_METHOD_KEY, {
|
|
50
50
|
methodName: methodName || propertyName,
|
|
51
51
|
}, target);
|
|
52
52
|
return descriptor;
|
|
@@ -6,7 +6,7 @@ function RabbitMQListener(queueName, options = {}) {
|
|
|
6
6
|
return (target, propertyKey) => {
|
|
7
7
|
options.queueName = queueName;
|
|
8
8
|
options.propertyKey = propertyKey;
|
|
9
|
-
__1.attachPropertyDataToClass(__1.MS_CONSUMER_KEY, options, target, propertyKey);
|
|
9
|
+
(0, __1.attachPropertyDataToClass)(__1.MS_CONSUMER_KEY, options, target, propertyKey);
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
12
|
exports.RabbitMQListener = RabbitMQListener;
|
package/dist/rpc/hsf.js
CHANGED
|
@@ -9,9 +9,9 @@ const annotation_1 = require("../annotation");
|
|
|
9
9
|
*/
|
|
10
10
|
function HSF(hsfOption = {}) {
|
|
11
11
|
return (target) => {
|
|
12
|
-
__1.saveModule(__1.HSF_KEY, target);
|
|
13
|
-
__1.saveClassMetadata(__1.HSF_KEY, hsfOption, target);
|
|
14
|
-
annotation_1.Scope(__1.ScopeEnum.Request)(target);
|
|
12
|
+
(0, __1.saveModule)(__1.HSF_KEY, target);
|
|
13
|
+
(0, __1.saveClassMetadata)(__1.HSF_KEY, hsfOption, target);
|
|
14
|
+
(0, annotation_1.Scope)(__1.ScopeEnum.Request)(target);
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
17
|
exports.HSF = HSF;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export interface Dto<T> extends Function {
|
|
2
|
+
new (): T;
|
|
3
|
+
}
|
|
4
|
+
export declare function PickDto<T, K extends keyof T>(dto: Dto<T>, keys: K[]): Dto<Pick<T, typeof keys[number]>>;
|
|
5
|
+
export declare function OmitDto<T, K extends keyof T>(dto: Dto<T>, keys: K[]): Dto<Omit<T, typeof keys[number]>>;
|
|
6
|
+
//# sourceMappingURL=dtoHelper.d.ts.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OmitDto = exports.PickDto = void 0;
|
|
4
|
+
const decoratorManager_1 = require("../common/decoratorManager");
|
|
5
|
+
const constant_1 = require("../constant");
|
|
6
|
+
function PickDto(dto, keys) {
|
|
7
|
+
const pickedDto = function () { };
|
|
8
|
+
pickedDto.prototype = dto.prototype;
|
|
9
|
+
const fatherRule = (0, decoratorManager_1.getClassExtendedMetadata)(constant_1.RULES_KEY, dto);
|
|
10
|
+
const pickedRule = {};
|
|
11
|
+
for (const key of keys) {
|
|
12
|
+
if (fatherRule[key]) {
|
|
13
|
+
pickedRule[key] = fatherRule[key];
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
(0, decoratorManager_1.saveClassMetadata)(constant_1.RULES_KEY, pickedRule, pickedDto);
|
|
17
|
+
return pickedDto;
|
|
18
|
+
}
|
|
19
|
+
exports.PickDto = PickDto;
|
|
20
|
+
function OmitDto(dto, keys) {
|
|
21
|
+
const pickedDto = function () { };
|
|
22
|
+
pickedDto.prototype = dto.prototype;
|
|
23
|
+
const fatherRule = (0, decoratorManager_1.getClassExtendedMetadata)(constant_1.RULES_KEY, dto);
|
|
24
|
+
const pickedRule = Object.assign({}, fatherRule);
|
|
25
|
+
for (const key of keys) {
|
|
26
|
+
delete pickedRule[key];
|
|
27
|
+
}
|
|
28
|
+
(0, decoratorManager_1.saveClassMetadata)(constant_1.RULES_KEY, pickedRule, pickedDto);
|
|
29
|
+
return pickedDto;
|
|
30
|
+
}
|
|
31
|
+
exports.OmitDto = OmitDto;
|
|
32
|
+
//# sourceMappingURL=dtoHelper.js.map
|
package/dist/util/index.d.ts
CHANGED
|
@@ -23,4 +23,8 @@ export declare function getParamNames(func: any): string[];
|
|
|
23
23
|
* @param name 类名称
|
|
24
24
|
*/
|
|
25
25
|
export declare function classNamed(name: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* generate a lightweight random id, enough for ioc container
|
|
28
|
+
*/
|
|
29
|
+
export declare function generateRandomId(): string;
|
|
26
30
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/util/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.classNamed = exports.getParamNames = exports.sleep = exports.isNullOrUndefined = exports.isNull = exports.isUndefined = exports.isRegExp = exports.isSet = exports.isMap = exports.isProxy = exports.isNumber = exports.isObject = exports.isFunction = exports.isPromise = exports.isGeneratorFunction = exports.isAsyncFunction = exports.isClass = void 0;
|
|
3
|
+
exports.generateRandomId = exports.classNamed = exports.getParamNames = exports.sleep = exports.isNullOrUndefined = exports.isNull = exports.isUndefined = exports.isRegExp = exports.isSet = exports.isMap = exports.isProxy = exports.isNumber = exports.isObject = exports.isFunction = exports.isPromise = exports.isGeneratorFunction = exports.isAsyncFunction = exports.isClass = void 0;
|
|
4
4
|
const util = require("util");
|
|
5
5
|
const camelcase = require("camelcase");
|
|
6
|
+
const crypto = require("crypto");
|
|
6
7
|
const ToString = Function.prototype.toString;
|
|
7
8
|
function fnBody(fn) {
|
|
8
9
|
return ToString.call(fn)
|
|
@@ -109,4 +110,12 @@ function classNamed(name) {
|
|
|
109
110
|
return camelcase(name);
|
|
110
111
|
}
|
|
111
112
|
exports.classNamed = classNamed;
|
|
113
|
+
/**
|
|
114
|
+
* generate a lightweight random id, enough for ioc container
|
|
115
|
+
*/
|
|
116
|
+
function generateRandomId() {
|
|
117
|
+
// => f9b327e70bbcf42494ccb28b2d98e00e
|
|
118
|
+
return crypto.randomBytes(16).toString('hex');
|
|
119
|
+
}
|
|
120
|
+
exports.generateRandomId = generateRandomId;
|
|
112
121
|
//# sourceMappingURL=index.js.map
|
package/dist/web/controller.js
CHANGED
|
@@ -5,13 +5,13 @@ const annotation_1 = require("../annotation");
|
|
|
5
5
|
const __1 = require("../");
|
|
6
6
|
function Controller(prefix = '/', routerOptions = { middleware: [], sensitive: true }) {
|
|
7
7
|
return (target) => {
|
|
8
|
-
__1.saveModule(__1.CONTROLLER_KEY, target);
|
|
8
|
+
(0, __1.saveModule)(__1.CONTROLLER_KEY, target);
|
|
9
9
|
if (prefix)
|
|
10
|
-
__1.saveClassMetadata(__1.CONTROLLER_KEY, {
|
|
10
|
+
(0, __1.saveClassMetadata)(__1.CONTROLLER_KEY, {
|
|
11
11
|
prefix,
|
|
12
12
|
routerOptions,
|
|
13
13
|
}, target);
|
|
14
|
-
annotation_1.Scope(__1.ScopeEnum.Request)(target);
|
|
14
|
+
(0, annotation_1.Scope)(__1.ScopeEnum.Request)(target);
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
17
|
exports.Controller = Controller;
|
package/dist/web/paramMapping.js
CHANGED
|
@@ -19,9 +19,9 @@ var RouteParamTypes;
|
|
|
19
19
|
const createParamMapping = function (type) {
|
|
20
20
|
return (propertyData) => (target, propertyName, index) => {
|
|
21
21
|
if (propertyData === undefined) {
|
|
22
|
-
propertyData = __1.getParamNames(target[propertyName])[index];
|
|
22
|
+
propertyData = (0, __1.getParamNames)(target[propertyName])[index];
|
|
23
23
|
}
|
|
24
|
-
__1.attachPropertyDataToClass(__1.WEB_ROUTER_PARAM_KEY, {
|
|
24
|
+
(0, __1.attachPropertyDataToClass)(__1.WEB_ROUTER_PARAM_KEY, {
|
|
25
25
|
index,
|
|
26
26
|
type,
|
|
27
27
|
propertyData,
|
|
@@ -27,7 +27,7 @@ const RequestMapping = (metadata = defaultMetadata) => {
|
|
|
27
27
|
const routerName = metadata.routerName;
|
|
28
28
|
const middleware = metadata.middleware;
|
|
29
29
|
return (target, key, descriptor) => {
|
|
30
|
-
__1.attachClassMetadata(__1.WEB_ROUTER_KEY, {
|
|
30
|
+
(0, __1.attachClassMetadata)(__1.WEB_ROUTER_KEY, {
|
|
31
31
|
path,
|
|
32
32
|
requestMethod,
|
|
33
33
|
routerName,
|
|
@@ -41,7 +41,7 @@ const RequestMapping = (metadata = defaultMetadata) => {
|
|
|
41
41
|
};
|
|
42
42
|
exports.RequestMapping = RequestMapping;
|
|
43
43
|
const createMappingDecorator = (method) => (path, routerOptions = { middleware: [] }) => {
|
|
44
|
-
return exports.RequestMapping(Object.assign(routerOptions, {
|
|
44
|
+
return (0, exports.RequestMapping)(Object.assign(routerOptions, {
|
|
45
45
|
requestMethod: method,
|
|
46
46
|
path,
|
|
47
47
|
}));
|
package/dist/web/response.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.createRender = exports.ContentType = exports.SetHeader = exports.HttpCod
|
|
|
4
4
|
const __1 = require("..");
|
|
5
5
|
function Redirect(url, code = 302) {
|
|
6
6
|
return (target, key, descriptor) => {
|
|
7
|
-
__1.attachPropertyMetadata(__1.WEB_RESPONSE_KEY, {
|
|
7
|
+
(0, __1.attachPropertyMetadata)(__1.WEB_RESPONSE_KEY, {
|
|
8
8
|
type: __1.WEB_RESPONSE_REDIRECT,
|
|
9
9
|
url,
|
|
10
10
|
code,
|
|
@@ -15,7 +15,7 @@ function Redirect(url, code = 302) {
|
|
|
15
15
|
exports.Redirect = Redirect;
|
|
16
16
|
function HttpCode(code) {
|
|
17
17
|
return (target, key, descriptor) => {
|
|
18
|
-
__1.attachPropertyMetadata(__1.WEB_RESPONSE_KEY, {
|
|
18
|
+
(0, __1.attachPropertyMetadata)(__1.WEB_RESPONSE_KEY, {
|
|
19
19
|
type: __1.WEB_RESPONSE_HTTP_CODE,
|
|
20
20
|
code,
|
|
21
21
|
}, target, key);
|
|
@@ -32,7 +32,7 @@ function SetHeader(headerKey, value) {
|
|
|
32
32
|
else {
|
|
33
33
|
headerObject = headerKey;
|
|
34
34
|
}
|
|
35
|
-
__1.attachPropertyMetadata(__1.WEB_RESPONSE_KEY, {
|
|
35
|
+
(0, __1.attachPropertyMetadata)(__1.WEB_RESPONSE_KEY, {
|
|
36
36
|
type: __1.WEB_RESPONSE_HEADER,
|
|
37
37
|
setHeaders: headerObject,
|
|
38
38
|
}, target, key);
|
|
@@ -42,7 +42,7 @@ function SetHeader(headerKey, value) {
|
|
|
42
42
|
exports.SetHeader = SetHeader;
|
|
43
43
|
function ContentType(contentType) {
|
|
44
44
|
return (target, key, descriptor) => {
|
|
45
|
-
__1.attachPropertyMetadata(__1.WEB_RESPONSE_KEY, {
|
|
45
|
+
(0, __1.attachPropertyMetadata)(__1.WEB_RESPONSE_KEY, {
|
|
46
46
|
type: __1.WEB_RESPONSE_CONTENT_TYPE,
|
|
47
47
|
contentType,
|
|
48
48
|
}, target, key);
|
|
@@ -53,7 +53,7 @@ exports.ContentType = ContentType;
|
|
|
53
53
|
function createRender(RenderEngine) {
|
|
54
54
|
return (templateName) => {
|
|
55
55
|
return (target, key, descriptor) => {
|
|
56
|
-
__1.attachPropertyMetadata(__1.WEB_RESPONSE_KEY, {
|
|
56
|
+
(0, __1.attachPropertyMetadata)(__1.WEB_RESPONSE_KEY, {
|
|
57
57
|
type: __1.WEB_RESPONSE_RENDER,
|
|
58
58
|
templateName,
|
|
59
59
|
}, target, key);
|
|
@@ -5,12 +5,12 @@ const annotation_1 = require("../annotation");
|
|
|
5
5
|
const __1 = require("../");
|
|
6
6
|
function WSController(namespace = '/', routerOptions = { middleware: [] }) {
|
|
7
7
|
return (target) => {
|
|
8
|
-
__1.saveModule(__1.WS_CONTROLLER_KEY, target);
|
|
9
|
-
__1.saveClassMetadata(__1.WS_CONTROLLER_KEY, {
|
|
8
|
+
(0, __1.saveModule)(__1.WS_CONTROLLER_KEY, target);
|
|
9
|
+
(0, __1.saveClassMetadata)(__1.WS_CONTROLLER_KEY, {
|
|
10
10
|
namespace,
|
|
11
11
|
routerOptions,
|
|
12
12
|
}, target);
|
|
13
|
-
annotation_1.Scope(__1.ScopeEnum.Request)(target);
|
|
13
|
+
(0, annotation_1.Scope)(__1.ScopeEnum.Request)(target);
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
16
|
exports.WSController = WSController;
|
|
@@ -13,7 +13,7 @@ var WSEventTypeEnum;
|
|
|
13
13
|
})(WSEventTypeEnum = exports.WSEventTypeEnum || (exports.WSEventTypeEnum = {}));
|
|
14
14
|
function OnWSConnection() {
|
|
15
15
|
return (target, propertyKey, descriptor) => {
|
|
16
|
-
__1.attachClassMetadata(__1.WS_EVENT_KEY, {
|
|
16
|
+
(0, __1.attachClassMetadata)(__1.WS_EVENT_KEY, {
|
|
17
17
|
eventType: WSEventTypeEnum.ON_CONNECTION,
|
|
18
18
|
propertyName: propertyKey,
|
|
19
19
|
descriptor,
|
|
@@ -23,7 +23,7 @@ function OnWSConnection() {
|
|
|
23
23
|
exports.OnWSConnection = OnWSConnection;
|
|
24
24
|
function OnWSDisConnection() {
|
|
25
25
|
return (target, propertyKey, descriptor) => {
|
|
26
|
-
__1.attachClassMetadata(__1.WS_EVENT_KEY, {
|
|
26
|
+
(0, __1.attachClassMetadata)(__1.WS_EVENT_KEY, {
|
|
27
27
|
eventType: WSEventTypeEnum.ON_DISCONNECTION,
|
|
28
28
|
propertyName: propertyKey,
|
|
29
29
|
descriptor,
|
|
@@ -33,7 +33,7 @@ function OnWSDisConnection() {
|
|
|
33
33
|
exports.OnWSDisConnection = OnWSDisConnection;
|
|
34
34
|
function OnWSMessage(eventName) {
|
|
35
35
|
return (target, propertyKey, descriptor) => {
|
|
36
|
-
__1.attachClassMetadata(__1.WS_EVENT_KEY, {
|
|
36
|
+
(0, __1.attachClassMetadata)(__1.WS_EVENT_KEY, {
|
|
37
37
|
eventType: WSEventTypeEnum.ON_MESSAGE,
|
|
38
38
|
messageEventName: eventName,
|
|
39
39
|
propertyName: propertyKey,
|
|
@@ -44,7 +44,7 @@ function OnWSMessage(eventName) {
|
|
|
44
44
|
exports.OnWSMessage = OnWSMessage;
|
|
45
45
|
function WSEmit(messageName, roomName = []) {
|
|
46
46
|
return (target, propertyKey, descriptor) => {
|
|
47
|
-
__1.attachClassMetadata(__1.WS_EVENT_KEY, {
|
|
47
|
+
(0, __1.attachClassMetadata)(__1.WS_EVENT_KEY, {
|
|
48
48
|
eventType: WSEventTypeEnum.EMIT,
|
|
49
49
|
propertyName: propertyKey,
|
|
50
50
|
messageEventName: messageName,
|
|
@@ -56,7 +56,7 @@ function WSEmit(messageName, roomName = []) {
|
|
|
56
56
|
exports.WSEmit = WSEmit;
|
|
57
57
|
function WSBroadCast(messageName = '', roomName = []) {
|
|
58
58
|
return (target, propertyKey, descriptor) => {
|
|
59
|
-
__1.attachClassMetadata(__1.WS_EVENT_KEY, {
|
|
59
|
+
(0, __1.attachClassMetadata)(__1.WS_EVENT_KEY, {
|
|
60
60
|
eventType: WSEventTypeEnum.BROADCAST,
|
|
61
61
|
propertyName: propertyKey,
|
|
62
62
|
messageEventName: messageName,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/decorator",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.14.0",
|
|
4
4
|
"description": "definition decorator for midway project",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"publishConfig": {
|
|
42
42
|
"access": "public"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "5fd716b0e731162d8e9f0931790fde7402fb83de"
|
|
45
45
|
}
|