@midwayjs/core 4.0.0-beta.1 → 4.0.0-beta.11
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.md +1 -1
- package/dist/baseFramework.d.ts +6 -6
- package/dist/baseFramework.js +19 -6
- package/dist/common/applicationManager.js +1 -3
- package/dist/common/asyncContextManager.js +23 -0
- package/dist/common/dataListener.js +2 -3
- package/dist/common/dataSourceManager.js +10 -8
- package/dist/common/fileDetector.js +2 -4
- package/dist/common/filterManager.js +6 -8
- package/dist/common/loggerFactory.js +1 -3
- package/dist/common/middlewareManager.js +2 -2
- package/dist/common/performanceManager.d.ts +0 -1
- package/dist/common/performanceManager.js +21 -20
- package/dist/common/priorityManager.js +2 -4
- package/dist/common/serviceDiscovery/healthCheck.js +10 -2
- package/dist/common/serviceDiscovery/loadBalancer.js +1 -3
- package/dist/common/serviceDiscovery/serviceDiscovery.js +6 -3
- package/dist/common/serviceFactory.js +6 -6
- package/dist/common/typedResourceManager.js +3 -2
- package/dist/common/webGenerator.js +2 -0
- package/dist/config/config.default.js +4 -4
- package/dist/context/componentLoader.js +3 -2
- package/dist/context/container.d.ts +0 -1
- package/dist/context/container.js +9 -8
- package/dist/context/definitionRegistry.js +3 -6
- package/dist/context/dynamicContainer.js +3 -2
- package/dist/context/managedResolverFactory.js +2 -1
- package/dist/context/providerWrapper.js +1 -2
- package/dist/context/requestContainer.js +5 -2
- package/dist/decorator/common/aspect.js +1 -2
- package/dist/decorator/common/autoload.js +1 -2
- package/dist/decorator/common/configuration.js +1 -2
- package/dist/decorator/common/filter.js +2 -3
- package/dist/decorator/common/framework.js +8 -9
- package/dist/decorator/common/guard.js +2 -3
- package/dist/decorator/common/inject.js +4 -5
- package/dist/decorator/common/middleware.js +1 -2
- package/dist/decorator/common/mock.js +1 -2
- package/dist/decorator/common/objectDef.js +2 -3
- package/dist/decorator/common/pipe.js +1 -2
- package/dist/decorator/common/provide.js +1 -2
- package/dist/decorator/common/scope.js +2 -3
- package/dist/decorator/decoratorManager.js +4 -4
- package/dist/decorator/faas/serverlessTrigger.js +2 -3
- package/dist/decorator/metadataManager.d.ts +8 -4
- package/dist/decorator/metadataManager.js +49 -63
- package/dist/decorator/microservice/consumer.js +1 -2
- package/dist/decorator/microservice/kafkaListener.js +1 -2
- package/dist/decorator/microservice/provider.js +4 -4
- package/dist/decorator/microservice/rabbitmqListener.js +1 -2
- package/dist/decorator/task/queue.js +1 -2
- package/dist/decorator/task/schedule.js +1 -2
- package/dist/decorator/task/task.js +1 -2
- package/dist/decorator/task/taskLocal.js +1 -2
- package/dist/decorator/web/controller.d.ts +6 -0
- package/dist/decorator/web/controller.js +1 -2
- package/dist/decorator/web/response.js +5 -6
- package/dist/decorator/ws/webSocketController.js +1 -2
- package/dist/decorator/ws/webSocketEvent.js +6 -6
- package/dist/definitions/functionDefinition.js +21 -12
- package/dist/definitions/objectCreator.js +2 -1
- package/dist/definitions/objectDefinition.js +19 -17
- package/dist/error/base.js +5 -2
- package/dist/functional/configuration.js +1 -0
- package/dist/functional/hooks.js +10 -11
- package/dist/interface.d.ts +0 -2
- package/dist/legacy/decorator.js +31 -32
- package/dist/response/base.d.ts +3 -5
- package/dist/response/base.js +22 -21
- package/dist/response/http.d.ts +4 -7
- package/dist/response/http.js +12 -12
- package/dist/response/sse.d.ts +0 -1
- package/dist/response/sse.js +4 -1
- package/dist/response/stream.d.ts +0 -1
- package/dist/response/stream.js +3 -1
- package/dist/service/aspectService.js +1 -0
- package/dist/service/configService.js +13 -12
- package/dist/service/decoratorService.js +6 -4
- package/dist/service/environmentService.js +2 -3
- package/dist/service/frameworkService.js +9 -1
- package/dist/service/healthService.js +5 -4
- package/dist/service/informationService.js +3 -0
- package/dist/service/lifeCycleService.js +6 -1
- package/dist/service/loggerService.js +6 -2
- package/dist/service/middlewareService.js +1 -0
- package/dist/service/mockService.js +17 -15
- package/dist/service/slsFunctionService.js +1 -0
- package/dist/service/webRouterService.d.ts +25 -1
- package/dist/service/webRouterService.js +20 -3
- package/dist/setup.js +4 -5
- package/dist/util/camelCase.js +2 -3
- package/dist/util/contextUtil.d.ts +3 -3
- package/dist/util/extend.js +1 -2
- package/dist/util/flatted.js +2 -3
- package/dist/util/fs.js +2 -2
- package/dist/util/httpclient.d.ts +0 -4
- package/dist/util/httpclient.js +3 -2
- package/dist/util/index.d.ts +2 -2
- package/dist/util/index.js +42 -37
- package/dist/util/pathFileUtil.d.ts +0 -1
- package/dist/util/pathFileUtil.js +6 -6
- package/dist/util/retry.js +2 -3
- package/dist/util/timeout.d.ts +0 -1
- package/dist/util/timeout.js +1 -2
- package/dist/util/types.d.ts +7 -7
- package/dist/util/types.js +17 -17
- package/dist/util/uuid.js +1 -2
- package/package.json +5 -5
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.Framework = Framework;
|
|
4
|
+
exports.Plugin = Plugin;
|
|
5
|
+
exports.Config = Config;
|
|
6
|
+
exports.AllConfig = AllConfig;
|
|
7
|
+
exports.App = App;
|
|
8
|
+
exports.MainApp = MainApp;
|
|
9
|
+
exports.Logger = Logger;
|
|
10
|
+
exports.ApplicationContext = ApplicationContext;
|
|
4
11
|
const __1 = require("../");
|
|
5
12
|
const interface_1 = require("../../interface");
|
|
6
13
|
/**
|
|
@@ -14,7 +21,6 @@ function Framework() {
|
|
|
14
21
|
(0, __1.Provide)()(target);
|
|
15
22
|
};
|
|
16
23
|
}
|
|
17
|
-
exports.Framework = Framework;
|
|
18
24
|
/**
|
|
19
25
|
* Plugin decorator, use to get egg plugin instance
|
|
20
26
|
* @since 2.0.0
|
|
@@ -24,13 +30,11 @@ function Plugin(identifier) {
|
|
|
24
30
|
identifier,
|
|
25
31
|
});
|
|
26
32
|
}
|
|
27
|
-
exports.Plugin = Plugin;
|
|
28
33
|
function Config(identifier) {
|
|
29
34
|
return __1.DecoratorManager.createCustomPropertyDecorator(__1.CONFIG_KEY, {
|
|
30
35
|
identifier,
|
|
31
36
|
});
|
|
32
37
|
}
|
|
33
|
-
exports.Config = Config;
|
|
34
38
|
/**
|
|
35
39
|
* Config decorator, use to get all config
|
|
36
40
|
* @since 4.0.0
|
|
@@ -40,13 +44,11 @@ function AllConfig() {
|
|
|
40
44
|
identifier: __1.ALL_VALUE_KEY,
|
|
41
45
|
});
|
|
42
46
|
}
|
|
43
|
-
exports.AllConfig = AllConfig;
|
|
44
47
|
function App(namespace) {
|
|
45
48
|
return __1.DecoratorManager.createCustomPropertyDecorator(__1.APPLICATION_KEY, {
|
|
46
49
|
type: namespace,
|
|
47
50
|
});
|
|
48
51
|
}
|
|
49
|
-
exports.App = App;
|
|
50
52
|
/**
|
|
51
53
|
* Get the main application instance
|
|
52
54
|
* @since 4.0.0
|
|
@@ -54,7 +56,6 @@ exports.App = App;
|
|
|
54
56
|
function MainApp() {
|
|
55
57
|
return __1.DecoratorManager.createCustomPropertyDecorator(__1.MAIN_APPLICATION_KEY, {});
|
|
56
58
|
}
|
|
57
|
-
exports.MainApp = MainApp;
|
|
58
59
|
/**
|
|
59
60
|
* Logger decorator, use to get logger instance
|
|
60
61
|
* @since 2.0.0
|
|
@@ -64,7 +65,6 @@ function Logger(identifier) {
|
|
|
64
65
|
identifier,
|
|
65
66
|
});
|
|
66
67
|
}
|
|
67
|
-
exports.Logger = Logger;
|
|
68
68
|
/**
|
|
69
69
|
* ApplicationContext decorator, use to get global IoC container instance
|
|
70
70
|
* @since 3.0.0
|
|
@@ -72,5 +72,4 @@ exports.Logger = Logger;
|
|
|
72
72
|
function ApplicationContext() {
|
|
73
73
|
return __1.DecoratorManager.createCustomPropertyDecorator(__1.APPLICATION_CONTEXT_KEY, {});
|
|
74
74
|
}
|
|
75
|
-
exports.ApplicationContext = ApplicationContext;
|
|
76
75
|
//# sourceMappingURL=framework.js.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.UseGuard = UseGuard;
|
|
4
|
+
exports.Guard = Guard;
|
|
4
5
|
const interface_1 = require("../../interface");
|
|
5
6
|
const constant_1 = require("../constant");
|
|
6
7
|
const provide_1 = require("./provide");
|
|
@@ -14,12 +15,10 @@ function UseGuard(guardOrArr) {
|
|
|
14
15
|
metadataManager_1.MetadataManager.defineMetadata(constant_1.GUARD_KEY, guardOrArr, target, propertyKey);
|
|
15
16
|
};
|
|
16
17
|
}
|
|
17
|
-
exports.UseGuard = UseGuard;
|
|
18
18
|
function Guard() {
|
|
19
19
|
return target => {
|
|
20
20
|
(0, provide_1.Provide)()(target);
|
|
21
21
|
(0, scope_1.Scope)(interface_1.ScopeEnum.Singleton)(target);
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
-
exports.Guard = Guard;
|
|
25
24
|
//# sourceMappingURL=guard.js.map
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.saveInjectMetadata = saveInjectMetadata;
|
|
4
|
+
exports.Inject = Inject;
|
|
5
|
+
exports.LazyInject = LazyInject;
|
|
6
|
+
exports.InjectClient = InjectClient;
|
|
4
7
|
const decoratorManager_1 = require("../decoratorManager");
|
|
5
8
|
const interface_1 = require("../../interface");
|
|
6
9
|
const constant_1 = require("../constant");
|
|
@@ -73,13 +76,11 @@ function saveInjectMetadata(identifier, target, targetKey, isLazyInject = false,
|
|
|
73
76
|
}, target, targetKey);
|
|
74
77
|
}
|
|
75
78
|
}
|
|
76
|
-
exports.saveInjectMetadata = saveInjectMetadata;
|
|
77
79
|
function Inject(identifier) {
|
|
78
80
|
return function (target, targetKey, parameterIndex) {
|
|
79
81
|
return saveInjectMetadata(identifier, target, targetKey, false, parameterIndex);
|
|
80
82
|
};
|
|
81
83
|
}
|
|
82
|
-
exports.Inject = Inject;
|
|
83
84
|
function LazyInject(identifier) {
|
|
84
85
|
let id = identifier;
|
|
85
86
|
if (id && typeof id !== 'function') {
|
|
@@ -91,12 +92,10 @@ function LazyInject(identifier) {
|
|
|
91
92
|
return saveInjectMetadata(id, target, targetKey, true, parameterIndex);
|
|
92
93
|
};
|
|
93
94
|
}
|
|
94
|
-
exports.LazyInject = LazyInject;
|
|
95
95
|
function InjectClient(serviceFactoryClz, clientName) {
|
|
96
96
|
return decoratorManager_1.DecoratorManager.createCustomPropertyDecorator(constant_1.FACTORY_SERVICE_CLIENT_KEY, {
|
|
97
97
|
serviceFactoryClz,
|
|
98
98
|
clientName,
|
|
99
99
|
});
|
|
100
100
|
}
|
|
101
|
-
exports.InjectClient = InjectClient;
|
|
102
101
|
//# sourceMappingURL=inject.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Middleware =
|
|
3
|
+
exports.Middleware = Middleware;
|
|
4
4
|
const __1 = require("../");
|
|
5
5
|
const interface_1 = require("../../interface");
|
|
6
6
|
function Middleware() {
|
|
@@ -9,5 +9,4 @@ function Middleware() {
|
|
|
9
9
|
(0, __1.Provide)()(target);
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
|
-
exports.Middleware = Middleware;
|
|
13
12
|
//# sourceMappingURL=middleware.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Mock =
|
|
3
|
+
exports.Mock = Mock;
|
|
4
4
|
const __1 = require("../");
|
|
5
5
|
const interface_1 = require("../../interface");
|
|
6
6
|
function Mock() {
|
|
@@ -10,5 +10,4 @@ function Mock() {
|
|
|
10
10
|
(0, __1.Provide)()(target);
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
|
-
exports.Mock = Mock;
|
|
14
13
|
//# sourceMappingURL=mock.js.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.Init = Init;
|
|
4
|
+
exports.Destroy = Destroy;
|
|
4
5
|
const metadataManager_1 = require("../metadataManager");
|
|
5
6
|
const constant_1 = require("../constant");
|
|
6
7
|
function Init() {
|
|
@@ -10,7 +11,6 @@ function Init() {
|
|
|
10
11
|
}, target, propertyKey);
|
|
11
12
|
};
|
|
12
13
|
}
|
|
13
|
-
exports.Init = Init;
|
|
14
14
|
function Destroy() {
|
|
15
15
|
return function (target, propertyKey) {
|
|
16
16
|
metadataManager_1.MetadataManager.attachMetadata(constant_1.OBJECT_DEFINITION_KEY, {
|
|
@@ -18,5 +18,4 @@ function Destroy() {
|
|
|
18
18
|
}, target, propertyKey);
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
|
-
exports.Destroy = Destroy;
|
|
22
21
|
//# sourceMappingURL=objectDef.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Pipe =
|
|
3
|
+
exports.Pipe = Pipe;
|
|
4
4
|
const __1 = require("../");
|
|
5
5
|
const interface_1 = require("../../interface");
|
|
6
6
|
function Pipe() {
|
|
@@ -9,5 +9,4 @@ function Pipe() {
|
|
|
9
9
|
(0, __1.Provide)()(target);
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
|
-
exports.Pipe = Pipe;
|
|
13
12
|
//# sourceMappingURL=pipe.js.map
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Provide =
|
|
3
|
+
exports.Provide = Provide;
|
|
4
4
|
const decoratorManager_1 = require("../decoratorManager");
|
|
5
5
|
function Provide(identifier) {
|
|
6
6
|
return function (target) {
|
|
7
7
|
decoratorManager_1.DecoratorManager.saveProviderId(identifier, target);
|
|
8
8
|
};
|
|
9
9
|
}
|
|
10
|
-
exports.Provide = Provide;
|
|
11
10
|
//# sourceMappingURL=provide.js.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.Scope = Scope;
|
|
4
|
+
exports.Singleton = Singleton;
|
|
4
5
|
const constant_1 = require("../constant");
|
|
5
6
|
const interface_1 = require("../../interface");
|
|
6
7
|
const metadataManager_1 = require("../metadataManager");
|
|
@@ -10,12 +11,10 @@ function Scope(scope, scopeOptions) {
|
|
|
10
11
|
metadataManager_1.MetadataManager.defineMetadata(constant_1.SCOPE_KEY, { scope, ...scopeOptions }, target);
|
|
11
12
|
};
|
|
12
13
|
}
|
|
13
|
-
exports.Scope = Scope;
|
|
14
14
|
function Singleton() {
|
|
15
15
|
return function (target) {
|
|
16
16
|
Scope(interface_1.ScopeEnum.Singleton)(target);
|
|
17
17
|
(0, provide_1.Provide)()(target);
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
|
-
exports.Singleton = Singleton;
|
|
21
20
|
//# sourceMappingURL=scope.js.map
|
|
@@ -8,13 +8,14 @@ const pathFileUtil_1 = require("../util/pathFileUtil");
|
|
|
8
8
|
const metadataManager_1 = require("./metadataManager");
|
|
9
9
|
const types_1 = require("../util/types");
|
|
10
10
|
const error_1 = require("../error");
|
|
11
|
-
const debug = require('util').debuglog('midway:
|
|
11
|
+
const debug = require('util').debuglog('midway:debug');
|
|
12
12
|
/**
|
|
13
13
|
* This class is used to manage the decorator data of the class
|
|
14
14
|
*
|
|
15
15
|
* @since 3.0.0
|
|
16
16
|
*/
|
|
17
17
|
class DecoratorManager {
|
|
18
|
+
static moduleStore = new Map();
|
|
18
19
|
static saveModule(key, module) {
|
|
19
20
|
if ((0, types_1.isClass)(module)) {
|
|
20
21
|
this.saveProviderId(undefined, module);
|
|
@@ -53,7 +54,7 @@ class DecoratorManager {
|
|
|
53
54
|
meta.id = identifier;
|
|
54
55
|
// save class id and uuid
|
|
55
56
|
metadataManager_1.MetadataManager.defineMetadata(constant_1.PROVIDE_KEY, meta, target);
|
|
56
|
-
debug(`
|
|
57
|
+
debug(`[core]: Update provide: ${target.name} -> ${meta.uuid}`);
|
|
57
58
|
}
|
|
58
59
|
}
|
|
59
60
|
}
|
|
@@ -67,7 +68,7 @@ class DecoratorManager {
|
|
|
67
68
|
uuid,
|
|
68
69
|
name: (0, camelCase_1.camelCase)(target.name),
|
|
69
70
|
}, target);
|
|
70
|
-
debug(`
|
|
71
|
+
debug(`[core]: Save provide: ${target.name} -> ${uuid}`);
|
|
71
72
|
}
|
|
72
73
|
return target;
|
|
73
74
|
}
|
|
@@ -143,7 +144,6 @@ class DecoratorManager {
|
|
|
143
144
|
}
|
|
144
145
|
}
|
|
145
146
|
exports.DecoratorManager = DecoratorManager;
|
|
146
|
-
DecoratorManager.moduleStore = new Map();
|
|
147
147
|
if (typeof globalThis === 'object' &&
|
|
148
148
|
globalThis['MIDWAY_GLOBAL_DECORATOR_MANAGER']) {
|
|
149
149
|
console.warn('DecoratorManager not singleton and please check @midwayjs/core version by "npm ls @midwayjs/core"');
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.ServerlessFunction = ServerlessFunction;
|
|
4
|
+
exports.ServerlessTrigger = ServerlessTrigger;
|
|
4
5
|
const __1 = require("../");
|
|
5
6
|
const interface_1 = require("../../interface");
|
|
6
7
|
const metadataManager_1 = require("../metadataManager");
|
|
@@ -9,7 +10,6 @@ function ServerlessFunction(options) {
|
|
|
9
10
|
metadataManager_1.MetadataManager.defineMetadata(__1.SERVERLESS_FUNC_KEY, options, target, key);
|
|
10
11
|
};
|
|
11
12
|
}
|
|
12
|
-
exports.ServerlessFunction = ServerlessFunction;
|
|
13
13
|
function ServerlessTrigger(type, metadata = {}) {
|
|
14
14
|
return (target, functionName, descriptor) => {
|
|
15
15
|
if (type === interface_1.ServerlessTriggerType.HTTP ||
|
|
@@ -26,5 +26,4 @@ function ServerlessTrigger(type, metadata = {}) {
|
|
|
26
26
|
}, target);
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
|
-
exports.ServerlessTrigger = ServerlessTrigger;
|
|
30
29
|
//# sourceMappingURL=serverlessTrigger.js.map
|
|
@@ -13,7 +13,7 @@ declare enum ObjectType {
|
|
|
13
13
|
* @since 4.0.0
|
|
14
14
|
*/
|
|
15
15
|
export declare class MetadataManager {
|
|
16
|
-
|
|
16
|
+
private static _metadataStore;
|
|
17
17
|
protected static readonly metadataClassSymbol: unique symbol;
|
|
18
18
|
protected static readonly metadataPropertySymbol: unique symbol;
|
|
19
19
|
protected static readonly cacheSymbol: unique symbol;
|
|
@@ -45,15 +45,15 @@ export declare class MetadataManager {
|
|
|
45
45
|
/**
|
|
46
46
|
* Checks if metadata exists for a target class or property
|
|
47
47
|
*/
|
|
48
|
-
static hasMetadata(metadataKey: string | symbol, target: ClassType, propertyKey?: string | symbol): boolean;
|
|
48
|
+
static hasMetadata(metadataKey: string | symbol, target: ClassType | object, propertyKey?: string | symbol): boolean;
|
|
49
49
|
/**
|
|
50
50
|
* Checks if own metadata exists for a target class or property
|
|
51
51
|
*/
|
|
52
|
-
static hasOwnMetadata(metadataKey: string | symbol, target: ClassType, propertyKey?: string | symbol): boolean;
|
|
52
|
+
static hasOwnMetadata(metadataKey: string | symbol, target: ClassType | object, propertyKey?: string | symbol): boolean;
|
|
53
53
|
/**
|
|
54
54
|
* Deletes metadata for a target class or property
|
|
55
55
|
*/
|
|
56
|
-
static deleteMetadata(metadataKey: string | symbol, target: ClassType, propertyKey?: string | symbol): void;
|
|
56
|
+
static deleteMetadata(metadataKey: string | symbol, target: ClassType | object, propertyKey?: string | symbol): void;
|
|
57
57
|
/**
|
|
58
58
|
* Get all metadata keys on the entire prototype chain
|
|
59
59
|
* Because we need to get metadata on the entire prototype chain, we do not use cache here, so the performance is poor
|
|
@@ -126,6 +126,10 @@ export declare class MetadataManager {
|
|
|
126
126
|
private static getUnionKey;
|
|
127
127
|
private static formatTarget;
|
|
128
128
|
static ensureTargetType(target: any, type: ObjectType): void;
|
|
129
|
+
private static getOwnProperty;
|
|
130
|
+
private static hasOwnProperty;
|
|
131
|
+
private static setOwnProperty;
|
|
132
|
+
static clear(): void;
|
|
129
133
|
}
|
|
130
134
|
export {};
|
|
131
135
|
//# sourceMappingURL=metadataManager.d.ts.map
|
|
@@ -18,6 +18,17 @@ var ObjectType;
|
|
|
18
18
|
* @since 4.0.0
|
|
19
19
|
*/
|
|
20
20
|
class MetadataManager {
|
|
21
|
+
static _metadataStore = new WeakMap();
|
|
22
|
+
static metadataClassSymbol = Symbol.for('midway.metadata.class');
|
|
23
|
+
static metadataPropertySymbol = Symbol.for('midway.metadata.property');
|
|
24
|
+
static cacheSymbol = Symbol.for('midway.metadata.cache');
|
|
25
|
+
static cleanHooksSymbol = Symbol.for('midway.clean.hooks');
|
|
26
|
+
static isClassSymbol = Symbol.for('midway.metadata.isClass');
|
|
27
|
+
static ObjectType = ObjectType;
|
|
28
|
+
/**
|
|
29
|
+
* A symbol that represents an empty value
|
|
30
|
+
*/
|
|
31
|
+
static emptyValueSymbol = Symbol.for('midway.metadata.empty');
|
|
21
32
|
/**
|
|
22
33
|
* Defines metadata for a target class or property
|
|
23
34
|
* Value will replace the existing metadata
|
|
@@ -335,33 +346,26 @@ class MetadataManager {
|
|
|
335
346
|
* }
|
|
336
347
|
* }
|
|
337
348
|
*/
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
const _metadata = {
|
|
349
|
+
if (!this._metadataStore.has(target)) {
|
|
350
|
+
this._metadataStore.set(target, {
|
|
341
351
|
[this.metadataClassSymbol]: Object.create(null),
|
|
342
352
|
[this.metadataPropertySymbol]: Object.create(null),
|
|
343
|
-
};
|
|
344
|
-
Object.defineProperty(target, this.metadataSymbol, {
|
|
345
|
-
value: _metadata,
|
|
346
|
-
enumerable: false,
|
|
347
|
-
configurable: false,
|
|
348
353
|
});
|
|
349
|
-
return _metadata;
|
|
350
354
|
}
|
|
351
|
-
return
|
|
355
|
+
return this._metadataStore.get(target);
|
|
352
356
|
}
|
|
353
357
|
static invalidateCache(metadataKey, target, propertyKey) {
|
|
354
358
|
// remove current cache
|
|
355
359
|
const unionKey = this.getUnionKey(metadataKey, propertyKey);
|
|
356
360
|
// Remove the specific cache
|
|
357
361
|
// eslint-disable-next-line no-prototype-builtins
|
|
358
|
-
if (
|
|
359
|
-
delete target
|
|
362
|
+
if (this.hasOwnProperty(target, this.cacheSymbol)) {
|
|
363
|
+
delete this.getOwnProperty(target, this.cacheSymbol)?.[unionKey];
|
|
360
364
|
}
|
|
361
365
|
// Execute hooks, passing the unionKey to clear
|
|
362
|
-
const cleanHooks = target
|
|
366
|
+
const cleanHooks = this.getOwnProperty(target, this.cleanHooksSymbol);
|
|
363
367
|
if (cleanHooks) {
|
|
364
|
-
target
|
|
368
|
+
this.setOwnProperty(target, this.cleanHooksSymbol, cleanHooks.filter(hook => !hook(unionKey)));
|
|
365
369
|
}
|
|
366
370
|
}
|
|
367
371
|
static setCache(metadataKey, target, protoTarget, value, propertyKey) {
|
|
@@ -370,42 +374,30 @@ class MetadataManager {
|
|
|
370
374
|
if (target !== protoTarget) {
|
|
371
375
|
this.validCacheConstruct(protoTarget);
|
|
372
376
|
// Register a clean hook to the prototype target and clean the cache when the prototype target value is changed
|
|
373
|
-
protoTarget
|
|
377
|
+
this.getOwnProperty(protoTarget, this.cleanHooksSymbol).push((keyToClear) => {
|
|
374
378
|
// Only delete cache if the key matches
|
|
375
379
|
if (keyToClear === unionKey) {
|
|
376
|
-
delete target
|
|
380
|
+
delete this.getOwnProperty(target, this.cacheSymbol)?.[unionKey];
|
|
377
381
|
// Indicates that this hook can be removed
|
|
378
382
|
return true;
|
|
379
383
|
}
|
|
380
384
|
return false;
|
|
381
385
|
});
|
|
382
386
|
}
|
|
383
|
-
target
|
|
387
|
+
this.getOwnProperty(target, this.cacheSymbol)[unionKey] = value;
|
|
384
388
|
}
|
|
385
389
|
static validCacheConstruct(target) {
|
|
390
|
+
const metadata = this.getOrCreateMetaObject(target);
|
|
386
391
|
// eslint-disable-next-line no-prototype-builtins
|
|
387
|
-
if (!
|
|
388
|
-
|
|
389
|
-
value: Object.create(null),
|
|
390
|
-
enumerable: false,
|
|
391
|
-
configurable: false,
|
|
392
|
-
});
|
|
392
|
+
if (!metadata[this.cacheSymbol]) {
|
|
393
|
+
metadata[this.cacheSymbol] = Object.create(null);
|
|
393
394
|
}
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
Object.defineProperty(target, this.cleanHooksSymbol, {
|
|
397
|
-
value: [],
|
|
398
|
-
enumerable: false,
|
|
399
|
-
configurable: false,
|
|
400
|
-
writable: true,
|
|
401
|
-
});
|
|
395
|
+
if (!metadata[this.cleanHooksSymbol]) {
|
|
396
|
+
metadata[this.cleanHooksSymbol] = [];
|
|
402
397
|
}
|
|
403
398
|
}
|
|
404
399
|
static getCache(metadataKey, target, propertyKey) {
|
|
405
|
-
|
|
406
|
-
if (target.hasOwnProperty(this.cacheSymbol)) {
|
|
407
|
-
return target[this.cacheSymbol]?.[this.getUnionKey(metadataKey, propertyKey)];
|
|
408
|
-
}
|
|
400
|
+
return this.getOwnProperty(target, this.cacheSymbol)?.[this.getUnionKey(metadataKey, propertyKey)];
|
|
409
401
|
}
|
|
410
402
|
static getUnionKey(metadataKey, propertyKey) {
|
|
411
403
|
return propertyKey
|
|
@@ -413,10 +405,7 @@ class MetadataManager {
|
|
|
413
405
|
: metadataKey.toString();
|
|
414
406
|
}
|
|
415
407
|
static formatTarget(target) {
|
|
416
|
-
|
|
417
|
-
let ret = target.hasOwnProperty(this.isClassSymbol)
|
|
418
|
-
? target[this.isClassSymbol]
|
|
419
|
-
: undefined;
|
|
408
|
+
let ret = this.getOwnProperty(target, this.isClassSymbol);
|
|
420
409
|
if (!ret) {
|
|
421
410
|
const isClassRet = (0, types_1.isClass)(target);
|
|
422
411
|
if (isClassRet) {
|
|
@@ -428,38 +417,35 @@ class MetadataManager {
|
|
|
428
417
|
else {
|
|
429
418
|
ret = ObjectType.Object;
|
|
430
419
|
}
|
|
431
|
-
|
|
432
|
-
value: ret,
|
|
433
|
-
enumerable: false,
|
|
434
|
-
configurable: false,
|
|
435
|
-
});
|
|
420
|
+
this.setOwnProperty(target, this.isClassSymbol, ret);
|
|
436
421
|
}
|
|
437
422
|
return ret === ObjectType.Instance ? target.constructor : target;
|
|
438
423
|
}
|
|
439
424
|
static ensureTargetType(target, type) {
|
|
440
425
|
// eslint-disable-next-line no-prototype-builtins
|
|
441
|
-
const ret =
|
|
442
|
-
? target[this.isClassSymbol]
|
|
443
|
-
: undefined;
|
|
426
|
+
const ret = this.getOwnProperty(target, this.isClassSymbol);
|
|
444
427
|
if (!ret) {
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
428
|
+
this.setOwnProperty(target, this.isClassSymbol, type);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
static getOwnProperty(target, propertyKey) {
|
|
432
|
+
const _metadata = this.getOrCreateMetaObject(target);
|
|
433
|
+
return _metadata[propertyKey] ?? undefined;
|
|
434
|
+
}
|
|
435
|
+
static hasOwnProperty(target, propertyKey) {
|
|
436
|
+
if (!this._metadataStore.has(target)) {
|
|
437
|
+
return false;
|
|
450
438
|
}
|
|
439
|
+
const _metadata = this._metadataStore.get(target);
|
|
440
|
+
return _metadata[propertyKey] !== undefined;
|
|
441
|
+
}
|
|
442
|
+
static setOwnProperty(target, propertyKey, value) {
|
|
443
|
+
const _metadata = this.getOrCreateMetaObject(target);
|
|
444
|
+
_metadata[propertyKey] = value;
|
|
445
|
+
}
|
|
446
|
+
static clear() {
|
|
447
|
+
this._metadataStore = new WeakMap();
|
|
451
448
|
}
|
|
452
449
|
}
|
|
453
450
|
exports.MetadataManager = MetadataManager;
|
|
454
|
-
MetadataManager.metadataSymbol = Symbol.for('midway.metadata');
|
|
455
|
-
MetadataManager.metadataClassSymbol = Symbol.for('midway.metadata.class');
|
|
456
|
-
MetadataManager.metadataPropertySymbol = Symbol.for('midway.metadata.property');
|
|
457
|
-
MetadataManager.cacheSymbol = Symbol.for('midway.metadata.cache');
|
|
458
|
-
MetadataManager.cleanHooksSymbol = Symbol.for('midway.clean.hooks');
|
|
459
|
-
MetadataManager.isClassSymbol = Symbol.for('midway.metadata.isClass');
|
|
460
|
-
MetadataManager.ObjectType = ObjectType;
|
|
461
|
-
/**
|
|
462
|
-
* A symbol that represents an empty value
|
|
463
|
-
*/
|
|
464
|
-
MetadataManager.emptyValueSymbol = Symbol.for('midway.metadata.empty');
|
|
465
451
|
//# sourceMappingURL=metadataManager.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Consumer =
|
|
3
|
+
exports.Consumer = Consumer;
|
|
4
4
|
const __1 = require("../");
|
|
5
5
|
const interface_1 = require("../../interface");
|
|
6
6
|
const metadataManager_1 = require("../metadataManager");
|
|
@@ -15,5 +15,4 @@ function Consumer(type, options = {}) {
|
|
|
15
15
|
(0, __1.Provide)()(target);
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
|
-
exports.Consumer = Consumer;
|
|
19
18
|
//# sourceMappingURL=consumer.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.KafkaListener =
|
|
3
|
+
exports.KafkaListener = KafkaListener;
|
|
4
4
|
const __1 = require("../");
|
|
5
5
|
const legacy_1 = require("../../legacy");
|
|
6
6
|
function KafkaListener(topic, options = {}) {
|
|
@@ -10,5 +10,4 @@ function KafkaListener(topic, options = {}) {
|
|
|
10
10
|
(0, legacy_1.attachPropertyDataToClass)(__1.MS_CONSUMER_KEY, options, target, propertyKey);
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
|
-
exports.KafkaListener = KafkaListener;
|
|
14
13
|
//# sourceMappingURL=kafkaListener.js.map
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.GrpcStreamTypeEnum = void 0;
|
|
4
|
+
exports.Provider = Provider;
|
|
5
|
+
exports.GrpcMethod = GrpcMethod;
|
|
6
|
+
exports.DubboMethod = DubboMethod;
|
|
4
7
|
const __1 = require("../");
|
|
5
8
|
const interface_1 = require("../../interface");
|
|
6
9
|
const metadataManager_1 = require("../metadataManager");
|
|
@@ -15,7 +18,6 @@ function Provider(type, metadata = {}) {
|
|
|
15
18
|
(0, __1.Provide)()(target);
|
|
16
19
|
};
|
|
17
20
|
}
|
|
18
|
-
exports.Provider = Provider;
|
|
19
21
|
var GrpcStreamTypeEnum;
|
|
20
22
|
(function (GrpcStreamTypeEnum) {
|
|
21
23
|
GrpcStreamTypeEnum["BASE"] = "base";
|
|
@@ -36,7 +38,6 @@ function GrpcMethod(methodOptions = {}) {
|
|
|
36
38
|
return descriptor;
|
|
37
39
|
};
|
|
38
40
|
}
|
|
39
|
-
exports.GrpcMethod = GrpcMethod;
|
|
40
41
|
function DubboMethod(methodName) {
|
|
41
42
|
return (target, propertyName, descriptor) => {
|
|
42
43
|
metadataManager_1.MetadataManager.attachMetadata(__1.MS_DUBBO_METHOD_KEY, {
|
|
@@ -45,5 +46,4 @@ function DubboMethod(methodName) {
|
|
|
45
46
|
return descriptor;
|
|
46
47
|
};
|
|
47
48
|
}
|
|
48
|
-
exports.DubboMethod = DubboMethod;
|
|
49
49
|
//# sourceMappingURL=provider.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RabbitMQListener =
|
|
3
|
+
exports.RabbitMQListener = RabbitMQListener;
|
|
4
4
|
const __1 = require("../");
|
|
5
5
|
const legacy_1 = require("../../legacy");
|
|
6
6
|
function RabbitMQListener(queueName, options = {}) {
|
|
@@ -10,5 +10,4 @@ function RabbitMQListener(queueName, options = {}) {
|
|
|
10
10
|
(0, legacy_1.attachPropertyDataToClass)(__1.MS_CONSUMER_KEY, options, target, propertyKey);
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
|
-
exports.RabbitMQListener = RabbitMQListener;
|
|
14
13
|
//# sourceMappingURL=rabbitmqListener.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Queue =
|
|
3
|
+
exports.Queue = Queue;
|
|
4
4
|
const __1 = require("../");
|
|
5
5
|
const constant_1 = require("../constant");
|
|
6
6
|
const metadataManager_1 = require("../metadataManager");
|
|
@@ -14,5 +14,4 @@ function Queue(options) {
|
|
|
14
14
|
(0, __1.Provide)()(target);
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
|
-
exports.Queue = Queue;
|
|
18
17
|
//# sourceMappingURL=queue.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Schedule =
|
|
3
|
+
exports.Schedule = Schedule;
|
|
4
4
|
const __1 = require("../");
|
|
5
5
|
const interface_1 = require("../../interface");
|
|
6
6
|
const metadataManager_1 = require("../metadataManager");
|
|
@@ -12,5 +12,4 @@ function Schedule(scheduleOpts) {
|
|
|
12
12
|
(0, __1.Provide)()(target);
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
|
-
exports.Schedule = Schedule;
|
|
16
15
|
//# sourceMappingURL=schedule.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Task =
|
|
3
|
+
exports.Task = Task;
|
|
4
4
|
const constant_1 = require("../constant");
|
|
5
5
|
const decoratorManager_1 = require("../decoratorManager");
|
|
6
6
|
const metadataManager_1 = require("../metadataManager");
|
|
@@ -15,5 +15,4 @@ function Task(options) {
|
|
|
15
15
|
}, target);
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
|
-
exports.Task = Task;
|
|
19
18
|
//# sourceMappingURL=task.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TaskLocal =
|
|
3
|
+
exports.TaskLocal = TaskLocal;
|
|
4
4
|
const constant_1 = require("../constant");
|
|
5
5
|
const decoratorManager_1 = require("../decoratorManager");
|
|
6
6
|
const metadataManager_1 = require("../metadataManager");
|
|
@@ -14,5 +14,4 @@ function TaskLocal(options) {
|
|
|
14
14
|
}, target);
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
|
-
exports.TaskLocal = TaskLocal;
|
|
18
17
|
//# sourceMappingURL=taskLocal.js.map
|