@midwayjs/core 3.20.4 → 4.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/baseFramework.d.ts +14 -39
- package/dist/baseFramework.js +19 -59
- package/dist/common/applicationManager.d.ts +6 -6
- package/dist/common/applicationManager.js +18 -35
- package/dist/common/asyncContextManager.d.ts +15 -0
- package/dist/common/asyncContextManager.js +51 -2
- package/dist/common/dataListener.d.ts +5 -3
- package/dist/common/dataListener.js +13 -4
- package/dist/common/dataSourceManager.d.ts +18 -9
- package/dist/common/dataSourceManager.js +121 -72
- package/dist/common/fileDetector.d.ts +9 -9
- package/dist/common/fileDetector.js +30 -28
- package/dist/common/filterManager.js +5 -4
- package/dist/common/guardManager.js +3 -2
- package/dist/common/middlewareManager.js +4 -3
- package/dist/common/performanceManager.js +1 -1
- package/dist/common/priorityManager.js +2 -2
- package/dist/common/serviceDiscovery/healthCheck.d.ts +66 -0
- package/dist/common/serviceDiscovery/healthCheck.js +207 -0
- package/dist/common/serviceDiscovery/loadBalancer.d.ts +21 -0
- package/dist/common/serviceDiscovery/loadBalancer.js +51 -0
- package/dist/common/serviceDiscovery/serviceDiscovery.d.ts +59 -0
- package/dist/common/serviceDiscovery/serviceDiscovery.js +104 -0
- package/dist/common/serviceFactory.d.ts +5 -2
- package/dist/common/serviceFactory.js +44 -9
- package/dist/common/webGenerator.js +4 -6
- package/dist/config/config.default.js +4 -1
- package/dist/constants.d.ts +2 -32
- package/dist/constants.js +3 -33
- package/dist/context/componentLoader.d.ts +20 -0
- package/dist/context/componentLoader.js +193 -0
- package/dist/context/container.d.ts +18 -32
- package/dist/context/container.js +74 -308
- package/dist/context/definitionRegistry.d.ts +5 -0
- package/dist/context/definitionRegistry.js +17 -26
- package/dist/context/dynamicContainer.d.ts +17 -0
- package/dist/context/dynamicContainer.js +202 -0
- package/dist/context/managedResolverFactory.d.ts +15 -41
- package/dist/context/managedResolverFactory.js +271 -349
- package/dist/context/requestContainer.d.ts +23 -12
- package/dist/context/requestContainer.js +46 -51
- package/dist/decorator/common/aspect.js +4 -4
- package/dist/decorator/common/autoload.js +1 -1
- package/dist/decorator/common/configuration.d.ts +1 -24
- package/dist/decorator/common/configuration.js +6 -1
- package/dist/decorator/common/filter.js +6 -6
- package/dist/decorator/common/framework.d.ts +46 -3
- package/dist/decorator/common/framework.js +43 -9
- package/dist/decorator/common/guard.js +4 -9
- package/dist/decorator/common/inject.d.ts +4 -2
- package/dist/decorator/common/inject.js +87 -4
- package/dist/decorator/common/mock.js +1 -1
- package/dist/decorator/common/objectDef.d.ts +0 -5
- package/dist/decorator/common/objectDef.js +8 -20
- package/dist/decorator/common/provide.d.ts +1 -1
- package/dist/decorator/common/provide.js +1 -1
- package/dist/decorator/common/scope.d.ts +6 -0
- package/dist/decorator/common/scope.js +21 -0
- package/dist/decorator/constant.d.ts +14 -17
- package/dist/decorator/constant.js +23 -35
- package/dist/decorator/decoratorManager.d.ts +21 -294
- package/dist/decorator/decoratorManager.js +127 -694
- package/dist/decorator/faas/serverlessTrigger.js +5 -5
- package/dist/decorator/index.d.ts +2 -3
- package/dist/decorator/index.js +6 -4
- package/dist/decorator/metadataManager.d.ts +131 -0
- package/dist/decorator/metadataManager.js +465 -0
- package/dist/decorator/microservice/consumer.js +3 -2
- package/dist/decorator/microservice/kafkaListener.js +2 -1
- package/dist/decorator/microservice/provider.js +6 -5
- package/dist/decorator/microservice/rabbitmqListener.js +2 -1
- package/dist/decorator/task/queue.js +3 -2
- package/dist/decorator/task/schedule.js +3 -2
- package/dist/decorator/task/task.js +4 -3
- package/dist/decorator/task/taskLocal.js +4 -3
- package/dist/decorator/web/controller.js +3 -2
- package/dist/decorator/web/paramMapping.js +2 -2
- package/dist/decorator/web/requestMapping.js +5 -5
- package/dist/decorator/web/response.js +6 -5
- package/dist/decorator/ws/webSocketController.js +3 -2
- package/dist/decorator/ws/webSocketEvent.js +7 -6
- package/dist/definitions/functionDefinition.d.ts +3 -3
- package/dist/definitions/functionDefinition.js +12 -11
- package/dist/definitions/objectCreator.d.ts +5 -11
- package/dist/definitions/objectCreator.js +6 -28
- package/dist/definitions/objectDefinition.d.ts +2 -3
- package/dist/definitions/objectDefinition.js +1 -3
- package/dist/error/base.js +2 -2
- package/dist/error/framework.d.ts +2 -9
- package/dist/error/framework.js +13 -27
- package/dist/error/http.js +1 -1
- package/dist/functional/configuration.d.ts +14 -15
- package/dist/functional/configuration.js +37 -47
- package/dist/functional/hooks.d.ts +12 -0
- package/dist/functional/hooks.js +78 -0
- package/dist/functional/index.d.ts +3 -0
- package/dist/functional/index.js +22 -0
- package/dist/index.d.ts +8 -4
- package/dist/index.js +10 -7
- package/dist/interface.d.ts +261 -137
- package/dist/interface.js +23 -33
- package/dist/legacy/constants.d.ts +29 -0
- package/dist/legacy/constants.js +33 -0
- package/dist/legacy/decorator.d.ts +255 -0
- package/dist/legacy/decorator.js +468 -0
- package/dist/legacy/index.d.ts +3 -0
- package/dist/legacy/index.js +19 -0
- package/dist/legacy/types.d.ts +2 -0
- package/dist/legacy/types.js +3 -0
- package/dist/service/aspectService.js +11 -12
- package/dist/service/configService.d.ts +1 -1
- package/dist/service/configService.js +5 -4
- package/dist/service/decoratorService.d.ts +3 -3
- package/dist/service/decoratorService.js +14 -10
- package/dist/service/environmentService.js +2 -2
- package/dist/service/frameworkService.d.ts +5 -4
- package/dist/service/frameworkService.js +30 -28
- package/dist/service/healthService.d.ts +2 -0
- package/dist/service/healthService.js +19 -8
- package/dist/service/informationService.d.ts +3 -0
- package/dist/service/informationService.js +13 -4
- package/dist/service/lifeCycleService.d.ts +13 -7
- package/dist/service/lifeCycleService.js +54 -48
- package/dist/service/loggerService.js +3 -4
- package/dist/service/middlewareService.js +7 -8
- package/dist/service/mockService.js +9 -15
- package/dist/service/slsFunctionService.d.ts +1 -14
- package/dist/service/slsFunctionService.js +33 -81
- package/dist/service/webRouterService.js +11 -11
- package/dist/setup.d.ts +5 -5
- package/dist/setup.js +83 -94
- package/dist/util/contextUtil.d.ts +2 -2
- package/dist/util/httpclient.d.ts +2 -2
- package/dist/util/index.d.ts +16 -17
- package/dist/util/index.js +153 -78
- package/dist/util/network.d.ts +10 -0
- package/dist/util/network.js +40 -0
- package/dist/util/pathFileUtil.d.ts +15 -2
- package/dist/util/pathFileUtil.js +27 -6
- package/dist/util/timeout.d.ts +57 -0
- package/dist/util/timeout.js +144 -0
- package/dist/util/webRouterParam.js +2 -2
- package/package.json +24 -6
- package/dist/decorator/common/pipeline.d.ts +0 -3
- package/dist/decorator/common/pipeline.js +0 -12
- package/dist/decorator/rpc/hsf.d.ts +0 -13
- package/dist/decorator/rpc/hsf.js +0 -20
- package/dist/definitions/properties.d.ts +0 -7
- package/dist/definitions/properties.js +0 -19
- package/dist/service/pipelineService.d.ts +0 -168
- package/dist/service/pipelineService.js +0 -254
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DynamicMidwayContainer = void 0;
|
|
4
|
+
const container_1 = require("./container");
|
|
5
|
+
const environmentService_1 = require("../service/environmentService");
|
|
6
|
+
const util_1 = require("../util");
|
|
7
|
+
const types_1 = require("../util/types");
|
|
8
|
+
const decorator_1 = require("../decorator");
|
|
9
|
+
const util_2 = require("util");
|
|
10
|
+
const debug = (0, util_2.debuglog)('midway:container');
|
|
11
|
+
/**
|
|
12
|
+
* 尝试用于开发时动态更新的 IoC 容器
|
|
13
|
+
*/
|
|
14
|
+
class DynamicMidwayContainer extends container_1.MidwayContainer {
|
|
15
|
+
constructor() {
|
|
16
|
+
super();
|
|
17
|
+
this.modifyClassMapping = new Map();
|
|
18
|
+
this.idRefMapping = new Map();
|
|
19
|
+
this.onBeforeBind((Clzz, options) => {
|
|
20
|
+
const definition = options.definition;
|
|
21
|
+
if (definition) {
|
|
22
|
+
if (definition.properties) {
|
|
23
|
+
// 处理属性
|
|
24
|
+
for (const propMetas of definition.properties.values()) {
|
|
25
|
+
// 这里未处理懒加载依赖
|
|
26
|
+
if (typeof propMetas.id === 'string') {
|
|
27
|
+
if (this.idRefMapping.has(propMetas.id)) {
|
|
28
|
+
this.idRefMapping.get(propMetas.id).push(definition.id);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
this.idRefMapping.set(propMetas.id, [definition.id]);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (definition.constructorArgs) {
|
|
37
|
+
// 处理构造器
|
|
38
|
+
for (const constructMeta of definition.constructorArgs) {
|
|
39
|
+
if (typeof constructMeta.id === 'string') {
|
|
40
|
+
if (this.idRefMapping.has(constructMeta.id)) {
|
|
41
|
+
this.idRefMapping.get(constructMeta.id).push(definition.id);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
this.idRefMapping.set(constructMeta.id, [definition.id]);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
async updateDefinition(modifyFilePath) {
|
|
53
|
+
debug('updateDefinition %s', modifyFilePath);
|
|
54
|
+
if (!this.moduleType) {
|
|
55
|
+
const environmentService = await this.getAsync(environmentService_1.MidwayEnvironmentService);
|
|
56
|
+
this.moduleType = environmentService.getModuleLoadType();
|
|
57
|
+
}
|
|
58
|
+
// 根据文件路径找到老的类
|
|
59
|
+
const oldDefinitionList = this.findDefinitionByPath(modifyFilePath);
|
|
60
|
+
debug('oldDefinitionList size %s', oldDefinitionList.length);
|
|
61
|
+
if (!oldDefinitionList.length) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
// 一个文件可能对应多个不同的 ObjectDefinition,但是导出的类名可能是不同的,所以可以使用类名作为 key
|
|
65
|
+
const nameList = {};
|
|
66
|
+
// 拿到旧的标识符
|
|
67
|
+
for (const oldDefinition of oldDefinitionList) {
|
|
68
|
+
nameList[oldDefinition.name] = oldDefinition.id;
|
|
69
|
+
}
|
|
70
|
+
debug('nameList %j', nameList);
|
|
71
|
+
// 清除 require cache
|
|
72
|
+
const requireCacheCleaned = this.findRequireCacheAndClear(modifyFilePath);
|
|
73
|
+
// 清理历史 context 缓存
|
|
74
|
+
for (const oldDefinition of oldDefinitionList) {
|
|
75
|
+
// 清理依赖的缓存
|
|
76
|
+
if (this.idRefMapping.has(oldDefinition.id)) {
|
|
77
|
+
for (const refId of this.idRefMapping.get(oldDefinition.id)) {
|
|
78
|
+
if (this.hasObject(refId)) {
|
|
79
|
+
this.removeObject(refId);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else if (this.idRefMapping.has(oldDefinition.name)) {
|
|
84
|
+
for (const refId of this.idRefMapping.get(oldDefinition.name)) {
|
|
85
|
+
if (this.hasObject(refId)) {
|
|
86
|
+
this.removeObject(refId);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// 清理自身
|
|
91
|
+
this.removeObject(oldDefinition.id);
|
|
92
|
+
}
|
|
93
|
+
debug('ready to load module %s', modifyFilePath);
|
|
94
|
+
// 重新加载新的文件
|
|
95
|
+
const modLoaded = await (0, util_1.loadModule)(modifyFilePath, {
|
|
96
|
+
loadMode: this.moduleType,
|
|
97
|
+
});
|
|
98
|
+
const newClassList = [];
|
|
99
|
+
if (types_1.Types.isClass(modLoaded) || types_1.Types.isFunction(modLoaded)) {
|
|
100
|
+
newClassList.push(modLoaded);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
for (const m in modLoaded) {
|
|
104
|
+
const module = modLoaded[m];
|
|
105
|
+
newClassList.push(module);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
debug('newClassList size %s', newClassList.length);
|
|
109
|
+
let remapping = false;
|
|
110
|
+
if (types_1.Types.isClass(modLoaded) || types_1.Types.isFunction(modLoaded)) {
|
|
111
|
+
const newId = decorator_1.DecoratorManager.getProviderUUId(modLoaded);
|
|
112
|
+
const name = decorator_1.DecoratorManager.getProviderName(modLoaded);
|
|
113
|
+
if (nameList[name]) {
|
|
114
|
+
debug('find old class name %s and will be remapping', name);
|
|
115
|
+
this.remapping(nameList[name], newId);
|
|
116
|
+
}
|
|
117
|
+
debug('bindModule %s', newId);
|
|
118
|
+
remapping = true;
|
|
119
|
+
this.bindModule(modLoaded, {
|
|
120
|
+
namespace: decorator_1.MAIN_MODULE_KEY,
|
|
121
|
+
srcPath: modifyFilePath,
|
|
122
|
+
createFrom: 'file',
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
for (const m in modLoaded) {
|
|
127
|
+
const module = modLoaded[m];
|
|
128
|
+
if (types_1.Types.isClass(module) || types_1.Types.isFunction(module)) {
|
|
129
|
+
const newId = decorator_1.DecoratorManager.getProviderUUId(module);
|
|
130
|
+
const name = decorator_1.DecoratorManager.getProviderName(module);
|
|
131
|
+
if (nameList[name] !== newId) {
|
|
132
|
+
if (nameList[name]) {
|
|
133
|
+
debug('find old class name %s and will be remapping', name);
|
|
134
|
+
this.remapping(nameList[name], newId);
|
|
135
|
+
}
|
|
136
|
+
debug('bindModule %s', newId);
|
|
137
|
+
remapping = true;
|
|
138
|
+
this.bindModule(module, {
|
|
139
|
+
namespace: decorator_1.MAIN_MODULE_KEY,
|
|
140
|
+
srcPath: modifyFilePath,
|
|
141
|
+
createFrom: 'file',
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return (requireCacheCleaned &&
|
|
148
|
+
oldDefinitionList.length > 0 &&
|
|
149
|
+
newClassList.length > 0 &&
|
|
150
|
+
remapping);
|
|
151
|
+
}
|
|
152
|
+
getIdentifier(identifier) {
|
|
153
|
+
// 从老的 id 映射成新的 id
|
|
154
|
+
let name = 'unknown';
|
|
155
|
+
if (typeof identifier !== 'string') {
|
|
156
|
+
name = decorator_1.DecoratorManager.getProviderName(identifier);
|
|
157
|
+
identifier = decorator_1.DecoratorManager.getProviderUUId(identifier);
|
|
158
|
+
}
|
|
159
|
+
debug('check identifier from %s %s', name, identifier);
|
|
160
|
+
if (this.modifyClassMapping.has(identifier)) {
|
|
161
|
+
debug('getIdentifier from modifyClassMapping %s -> %s', identifier, this.modifyClassMapping.get(identifier));
|
|
162
|
+
return this.modifyClassMapping.get(identifier);
|
|
163
|
+
}
|
|
164
|
+
return identifier;
|
|
165
|
+
}
|
|
166
|
+
findDefinitionByPath(filePath) {
|
|
167
|
+
const results = [];
|
|
168
|
+
// 遍历 registry
|
|
169
|
+
for (const definition of this.registry.values()) {
|
|
170
|
+
if (definition.srcPath === filePath) {
|
|
171
|
+
results.push(definition);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return results;
|
|
175
|
+
}
|
|
176
|
+
findRequireCacheAndClear(absolutePath) {
|
|
177
|
+
let cleaned = false;
|
|
178
|
+
const cacheKey = require.resolve(absolutePath);
|
|
179
|
+
const cache = require.cache[cacheKey];
|
|
180
|
+
if (cache) {
|
|
181
|
+
debug('clear cache %s', cacheKey);
|
|
182
|
+
delete require.cache[cacheKey];
|
|
183
|
+
cleaned = true;
|
|
184
|
+
}
|
|
185
|
+
return cleaned;
|
|
186
|
+
}
|
|
187
|
+
remapping(oldId, newId) {
|
|
188
|
+
// 新老 id 做个重新映射,如果第一次 1 -> 2, 第二次输入 2 -> 3,那么要变成 1 -> 3
|
|
189
|
+
for (const [key, value] of this.modifyClassMapping.entries()) {
|
|
190
|
+
if (value === oldId) {
|
|
191
|
+
debug('remapping key = %s, %s -> %s', key, oldId, newId);
|
|
192
|
+
// Update the mapping to the new newId
|
|
193
|
+
this.modifyClassMapping.set(key, newId);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
debug('new remapping key = %s, value = %s', oldId, newId);
|
|
197
|
+
// Set the new mapping
|
|
198
|
+
this.modifyClassMapping.set(oldId, newId);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
exports.DynamicMidwayContainer = DynamicMidwayContainer;
|
|
202
|
+
//# sourceMappingURL=dynamicContainer.js.map
|
|
@@ -1,55 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare class ManagedReference implements IManagedInstance {
|
|
3
|
-
type: string;
|
|
4
|
-
name: string;
|
|
5
|
-
injectMode: InjectModeEnum;
|
|
6
|
-
args?: any;
|
|
7
|
-
}
|
|
1
|
+
import { ClassType, IMidwayContainer, IMidwayGlobalContainer } from '../interface';
|
|
8
2
|
/**
|
|
9
3
|
* 解析工厂
|
|
10
4
|
*/
|
|
11
5
|
export declare class ManagedResolverFactory {
|
|
12
|
-
private resolvers;
|
|
13
6
|
private creating;
|
|
14
|
-
|
|
15
|
-
context:
|
|
16
|
-
constructor(context: IMidwayContainer);
|
|
17
|
-
registerResolver(resolver: IManagedResolver): void;
|
|
18
|
-
resolveManaged(managed: IManagedInstance, originPropertyName: string): any;
|
|
19
|
-
resolveManagedAsync(managed: IManagedInstance, originPropertyName: string): Promise<any>;
|
|
7
|
+
context: IMidwayGlobalContainer;
|
|
8
|
+
constructor(context: IMidwayGlobalContainer);
|
|
20
9
|
/**
|
|
21
10
|
* 同步创建对象
|
|
22
|
-
* @param
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* 异步创建对象
|
|
27
|
-
* @param opt
|
|
11
|
+
* @param identifier
|
|
12
|
+
* @param args
|
|
13
|
+
* @param currentContext
|
|
28
14
|
*/
|
|
29
|
-
|
|
15
|
+
create<T = any>(identifier: ClassType<T> | string, args: any[], currentContext: IMidwayContainer): T;
|
|
16
|
+
createAsync<T = any>(identifier: ClassType<T> | string, args: any[], currentContext: IMidwayContainer): Promise<T>;
|
|
30
17
|
destroyCache(): Promise<void>;
|
|
31
|
-
/**
|
|
32
|
-
* 触发单例初始化结束事件
|
|
33
|
-
* @param definition 单例定义
|
|
34
|
-
* @param success 成功 or 失败
|
|
35
|
-
*/
|
|
36
|
-
private removeCreateStatus;
|
|
37
|
-
isCreating(definition: IObjectDefinition): boolean;
|
|
38
|
-
private compareAndSetCreateStatus;
|
|
39
|
-
/**
|
|
40
|
-
* 创建对象定义的代理访问逻辑
|
|
41
|
-
* @param definition 对象定义
|
|
42
|
-
*/
|
|
43
|
-
private createProxyReference;
|
|
44
|
-
/**
|
|
45
|
-
* 遍历依赖树判断是否循环依赖
|
|
46
|
-
* @param identifier 目标id
|
|
47
|
-
* @param definition 定义描述
|
|
48
|
-
* @param depth
|
|
49
|
-
*/
|
|
50
|
-
depthFirstSearch(identifier: string, definition: IObjectDefinition, depth?: string[]): boolean;
|
|
51
18
|
private getObjectEventTarget;
|
|
52
19
|
private checkSingletonInvokeRequest;
|
|
53
20
|
private setInstanceScope;
|
|
21
|
+
private createInstance;
|
|
22
|
+
private initializeInstance;
|
|
23
|
+
private initializeInstanceAsync;
|
|
24
|
+
private storeInstanceScope;
|
|
25
|
+
private getObjectDefinition;
|
|
26
|
+
private getCurrentMatchedContext;
|
|
27
|
+
private translateIdentifiers;
|
|
54
28
|
}
|
|
55
29
|
//# sourceMappingURL=managedResolverFactory.d.ts.map
|