@midwayjs/core 3.0.0-alpha.2 → 3.0.0-alpha.40
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 +3 -17
- package/dist/baseFramework.d.ts +0 -1
- package/dist/baseFramework.js +36 -80
- package/dist/common/reflectTool.d.ts +3 -1
- package/dist/context/container.d.ts +49 -24
- package/dist/context/container.js +245 -224
- package/dist/context/definitionRegistry.d.ts +26 -0
- package/dist/context/definitionRegistry.js +124 -0
- package/dist/context/managedResolverFactory.d.ts +15 -19
- package/dist/context/managedResolverFactory.js +27 -256
- package/dist/context/providerWrapper.d.ts +2 -3
- package/dist/context/requestContainer.d.ts +1 -2
- package/dist/context/requestContainer.js +5 -12
- package/dist/context/resolverHandler.d.ts +3 -2
- package/dist/context/resolverHandler.js +5 -2
- package/dist/definitions/functionDefinition.d.ts +0 -2
- package/dist/definitions/functionDefinition.js +0 -6
- package/dist/definitions/objectCreator.js +6 -6
- package/dist/definitions/objectDefinition.d.ts +1 -4
- package/dist/definitions/objectDefinition.js +0 -8
- package/dist/definitions/properties.d.ts +0 -2
- package/dist/definitions/properties.js +5 -21
- package/dist/definitions/resource.js +13 -13
- package/dist/features/pipeline.d.ts +3 -3
- package/dist/features/pipeline.js +1 -1
- package/dist/functional/configuration.d.ts +2 -0
- package/dist/functional/configuration.js +10 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -23
- package/dist/interface.d.ts +24 -32
- package/dist/logger.js +4 -4
- package/dist/service/aspectService.js +9 -4
- package/dist/service/configService.d.ts +2 -2
- package/dist/service/configService.js +30 -18
- package/dist/service/environmentService.js +2 -2
- package/dist/service/informationService.js +4 -4
- package/dist/util/containerUtil.d.ts +11 -0
- package/dist/util/containerUtil.js +26 -0
- package/dist/util/contextUtil.js +2 -2
- package/dist/util/fileDetector.js +2 -2
- package/dist/util/index.js +3 -3
- package/dist/util/pathFileUtil.js +2 -2
- package/dist/util/serviceFactory.d.ts +4 -2
- package/dist/util/serviceFactory.js +11 -3
- package/dist/util/webRouterCollector.d.ts +9 -4
- package/dist/util/webRouterCollector.js +83 -132
- package/package.json +5 -4
- package/dist/context/applicationContext.d.ts +0 -81
- package/dist/context/applicationContext.js +0 -247
- package/dist/context/configuration.d.ts +0 -1
- package/dist/context/configuration.js +0 -370
- package/dist/context/managed.d.ts +0 -45
- package/dist/context/managed.js +0 -69
- package/dist/context/midwayContainer.d.ts +0 -1
- package/dist/context/midwayContainer.js +0 -695
- package/dist/util/staticConfig.d.ts +0 -10
- package/dist/util/staticConfig.js +0 -67
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ObjectDefinitionRegistry = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Object Definition Registry 实现
|
|
6
|
+
*/
|
|
7
|
+
const decorator_1 = require("@midwayjs/decorator");
|
|
8
|
+
const PREFIX = '_id_default_';
|
|
9
|
+
class LegacyIdentifierRelation extends Map {
|
|
10
|
+
saveClassRelation(module, namespace) {
|
|
11
|
+
const providerId = (0, decorator_1.getProviderUUId)(module);
|
|
12
|
+
// save uuid
|
|
13
|
+
this.set(providerId, providerId);
|
|
14
|
+
if (providerId) {
|
|
15
|
+
// save alias id
|
|
16
|
+
const aliasId = (0, decorator_1.getProviderId)(module);
|
|
17
|
+
if (aliasId) {
|
|
18
|
+
// save alias Id
|
|
19
|
+
this.set(aliasId, providerId);
|
|
20
|
+
}
|
|
21
|
+
// save className alias
|
|
22
|
+
this.set((0, decorator_1.getProviderName)(module), providerId);
|
|
23
|
+
// save namespace alias
|
|
24
|
+
if (namespace) {
|
|
25
|
+
this.set(namespace + ':' + (0, decorator_1.getProviderName)(module), providerId);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
saveFunctionRelation(id, uuid) {
|
|
30
|
+
this.set(uuid, uuid);
|
|
31
|
+
this.set(id, uuid);
|
|
32
|
+
}
|
|
33
|
+
hasRelation(id) {
|
|
34
|
+
return this.has(id);
|
|
35
|
+
}
|
|
36
|
+
getRelation(id) {
|
|
37
|
+
return this.get(id);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
class ObjectDefinitionRegistry extends Map {
|
|
41
|
+
constructor() {
|
|
42
|
+
super(...arguments);
|
|
43
|
+
this.singletonIds = [];
|
|
44
|
+
this._identifierRelation = new LegacyIdentifierRelation();
|
|
45
|
+
}
|
|
46
|
+
get identifierRelation() {
|
|
47
|
+
if (!this._identifierRelation) {
|
|
48
|
+
this._identifierRelation = new LegacyIdentifierRelation();
|
|
49
|
+
}
|
|
50
|
+
return this._identifierRelation;
|
|
51
|
+
}
|
|
52
|
+
set identifierRelation(identifierRelation) {
|
|
53
|
+
this._identifierRelation = identifierRelation;
|
|
54
|
+
}
|
|
55
|
+
get identifiers() {
|
|
56
|
+
const ids = [];
|
|
57
|
+
for (const key of this.keys()) {
|
|
58
|
+
if (key.indexOf(PREFIX) === -1) {
|
|
59
|
+
ids.push(key);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return ids;
|
|
63
|
+
}
|
|
64
|
+
get count() {
|
|
65
|
+
return this.size;
|
|
66
|
+
}
|
|
67
|
+
getSingletonDefinitionIds() {
|
|
68
|
+
return this.singletonIds;
|
|
69
|
+
}
|
|
70
|
+
getDefinitionByName(name) {
|
|
71
|
+
const definitions = [];
|
|
72
|
+
for (const v of this.values()) {
|
|
73
|
+
const definition = v;
|
|
74
|
+
if (definition.name === name) {
|
|
75
|
+
definitions.push(definition);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return definitions;
|
|
79
|
+
}
|
|
80
|
+
registerDefinition(identifier, definition) {
|
|
81
|
+
if (definition.isSingletonScope()) {
|
|
82
|
+
this.singletonIds.push(identifier);
|
|
83
|
+
}
|
|
84
|
+
this.set(identifier, definition);
|
|
85
|
+
}
|
|
86
|
+
getDefinition(identifier) {
|
|
87
|
+
var _a;
|
|
88
|
+
identifier = (_a = this.identifierRelation.getRelation(identifier)) !== null && _a !== void 0 ? _a : identifier;
|
|
89
|
+
return this.get(identifier);
|
|
90
|
+
}
|
|
91
|
+
removeDefinition(identifier) {
|
|
92
|
+
this.delete(identifier);
|
|
93
|
+
}
|
|
94
|
+
hasDefinition(identifier) {
|
|
95
|
+
var _a;
|
|
96
|
+
identifier = (_a = this.identifierRelation.getRelation(identifier)) !== null && _a !== void 0 ? _a : identifier;
|
|
97
|
+
return this.has(identifier);
|
|
98
|
+
}
|
|
99
|
+
clearAll() {
|
|
100
|
+
this.singletonIds = [];
|
|
101
|
+
this.clear();
|
|
102
|
+
}
|
|
103
|
+
hasObject(identifier) {
|
|
104
|
+
var _a;
|
|
105
|
+
identifier = (_a = this.identifierRelation.getRelation(identifier)) !== null && _a !== void 0 ? _a : identifier;
|
|
106
|
+
return this.has(PREFIX + identifier);
|
|
107
|
+
}
|
|
108
|
+
registerObject(identifier, target) {
|
|
109
|
+
this.set(PREFIX + identifier, target);
|
|
110
|
+
}
|
|
111
|
+
getObject(identifier) {
|
|
112
|
+
var _a;
|
|
113
|
+
identifier = (_a = this.identifierRelation.getRelation(identifier)) !== null && _a !== void 0 ? _a : identifier;
|
|
114
|
+
return this.get(PREFIX + identifier);
|
|
115
|
+
}
|
|
116
|
+
getIdentifierRelation() {
|
|
117
|
+
return this.identifierRelation;
|
|
118
|
+
}
|
|
119
|
+
setIdentifierRelation(identifierRelation) {
|
|
120
|
+
this.identifierRelation = identifierRelation;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
exports.ObjectDefinitionRegistry = ObjectDefinitionRegistry;
|
|
124
|
+
//# sourceMappingURL=definitionRegistry.js.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 管理对象解析构建
|
|
3
3
|
*/
|
|
4
|
-
import { IManagedInstance } from '@midwayjs/decorator';
|
|
5
|
-
import {
|
|
4
|
+
import { IManagedInstance, ObjectIdentifier } from '@midwayjs/decorator';
|
|
5
|
+
import { IManagedResolver, IObjectDefinition, IManagedResolverFactoryCreateOptions, IMidwayContainer } from '../interface';
|
|
6
6
|
/**
|
|
7
7
|
* 所有解析器基类
|
|
8
8
|
*/
|
|
@@ -13,43 +13,38 @@ export declare class BaseManagedResolver implements IManagedResolver {
|
|
|
13
13
|
resolve(managed: IManagedInstance): any;
|
|
14
14
|
resolveAsync(managed: IManagedInstance): Promise<any>;
|
|
15
15
|
}
|
|
16
|
+
export declare class ManagedReference implements IManagedInstance {
|
|
17
|
+
type: string;
|
|
18
|
+
name: string;
|
|
19
|
+
args?: any;
|
|
20
|
+
}
|
|
16
21
|
/**
|
|
17
22
|
* 解析工厂
|
|
18
23
|
*/
|
|
19
24
|
export declare class ManagedResolverFactory {
|
|
20
25
|
private resolvers;
|
|
21
|
-
private _props;
|
|
22
26
|
private creating;
|
|
23
|
-
singletonCache: Map<
|
|
24
|
-
context:
|
|
27
|
+
singletonCache: Map<ObjectIdentifier, any>;
|
|
28
|
+
context: IMidwayContainer;
|
|
25
29
|
afterCreateHandler: any[];
|
|
26
30
|
beforeCreateHandler: any[];
|
|
27
|
-
constructor(context:
|
|
28
|
-
get props(): any;
|
|
29
|
-
/**
|
|
30
|
-
* 用于解析模版化的值
|
|
31
|
-
* example: {{aaa.bbb.ccc}}
|
|
32
|
-
* @param value 配置的模版值
|
|
33
|
-
*/
|
|
34
|
-
tpl(value: any): any;
|
|
31
|
+
constructor(context: IMidwayContainer);
|
|
35
32
|
registerResolver(resolver: IManagedResolver): void;
|
|
36
33
|
resolveManaged(managed: IManagedInstance): any;
|
|
37
34
|
resolveManagedAsync(managed: IManagedInstance): Promise<any>;
|
|
38
35
|
/**
|
|
39
36
|
* 同步创建对象
|
|
40
|
-
* @param
|
|
41
|
-
* @param args 参数
|
|
37
|
+
* @param opt
|
|
42
38
|
*/
|
|
43
39
|
create(opt: IManagedResolverFactoryCreateOptions): any;
|
|
44
40
|
/**
|
|
45
41
|
* 异步创建对象
|
|
46
|
-
* @param
|
|
47
|
-
* @param args 参数
|
|
42
|
+
* @param opt
|
|
48
43
|
*/
|
|
49
44
|
createAsync(opt: IManagedResolverFactoryCreateOptions): Promise<any>;
|
|
50
45
|
destroyCache(): Promise<void>;
|
|
51
|
-
beforeEachCreated(fn: (Clzz: any, constructorArgs: [], context:
|
|
52
|
-
afterEachCreated(fn: (ins: any, context:
|
|
46
|
+
beforeEachCreated(fn: (Clzz: any, constructorArgs: [], context: IMidwayContainer) => void): void;
|
|
47
|
+
afterEachCreated(fn: (ins: any, context: IMidwayContainer, definition?: IObjectDefinition) => void): void;
|
|
53
48
|
/**
|
|
54
49
|
* 触发单例初始化结束事件
|
|
55
50
|
* @param definition 单例定义
|
|
@@ -67,6 +62,7 @@ export declare class ManagedResolverFactory {
|
|
|
67
62
|
* 遍历依赖树判断是否循环依赖
|
|
68
63
|
* @param identifier 目标id
|
|
69
64
|
* @param definition 定义描述
|
|
65
|
+
* @param depth
|
|
70
66
|
*/
|
|
71
67
|
depthFirstSearch(identifier: string, definition: IObjectDefinition, depth?: string[]): boolean;
|
|
72
68
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ManagedResolverFactory = exports.BaseManagedResolver = void 0;
|
|
3
|
+
exports.ManagedResolverFactory = exports.ManagedReference = exports.BaseManagedResolver = void 0;
|
|
4
4
|
const _ = require("../common/lodashWrap");
|
|
5
5
|
const constants_1 = require("../common/constants");
|
|
6
6
|
const interface_1 = require("../interface");
|
|
7
|
-
const properties_1 = require("../definitions/properties");
|
|
8
7
|
const notFoundError_1 = require("../common/notFoundError");
|
|
9
8
|
const util = require("util");
|
|
10
9
|
const debug = util.debuglog('midway:managedresolver');
|
|
@@ -26,69 +25,12 @@ class BaseManagedResolver {
|
|
|
26
25
|
}
|
|
27
26
|
}
|
|
28
27
|
exports.BaseManagedResolver = BaseManagedResolver;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
class JSONResolver extends BaseManagedResolver {
|
|
33
|
-
get type() {
|
|
34
|
-
return constants_1.KEYS.JSON_ELEMENT;
|
|
35
|
-
}
|
|
36
|
-
resolve(managed) {
|
|
37
|
-
const mjson = managed;
|
|
38
|
-
return JSON.parse(this._factory.tpl(mjson.value));
|
|
39
|
-
}
|
|
40
|
-
async resolveAsync(managed) {
|
|
41
|
-
return this.resolve(managed);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* 解析值
|
|
46
|
-
*/
|
|
47
|
-
class ValueResolver extends BaseManagedResolver {
|
|
48
|
-
get type() {
|
|
49
|
-
return constants_1.KEYS.VALUE_ELEMENT;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* 解析不通类型的值
|
|
53
|
-
* @param managed 类型接口
|
|
54
|
-
* @param props 注入的属性值
|
|
55
|
-
*/
|
|
56
|
-
_resolveCommon(managed) {
|
|
57
|
-
const mv = managed;
|
|
58
|
-
switch (mv.valueType) {
|
|
59
|
-
case constants_1.VALUE_TYPE.STRING:
|
|
60
|
-
case constants_1.VALUE_TYPE.TEMPLATE:
|
|
61
|
-
return this._factory.tpl(mv.value);
|
|
62
|
-
case constants_1.VALUE_TYPE.NUMBER:
|
|
63
|
-
return Number(this._factory.tpl(mv.value));
|
|
64
|
-
case constants_1.VALUE_TYPE.INTEGER:
|
|
65
|
-
return parseInt(this._factory.tpl(mv.value), 10);
|
|
66
|
-
case constants_1.VALUE_TYPE.DATE:
|
|
67
|
-
return new Date(this._factory.tpl(mv.value));
|
|
68
|
-
case constants_1.VALUE_TYPE.BOOLEAN:
|
|
69
|
-
return mv.value === 'true';
|
|
70
|
-
}
|
|
71
|
-
return mv.value;
|
|
72
|
-
}
|
|
73
|
-
resolve(managed) {
|
|
74
|
-
const mv = managed;
|
|
75
|
-
if (mv.valueType === constants_1.VALUE_TYPE.MANAGED) {
|
|
76
|
-
return this._factory.resolveManaged(mv.value);
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
return this._resolveCommon(managed);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
async resolveAsync(managed) {
|
|
83
|
-
const mv = managed;
|
|
84
|
-
if (mv.valueType === constants_1.VALUE_TYPE.MANAGED) {
|
|
85
|
-
return this._factory.resolveManagedAsync(mv.value);
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
return this._resolveCommon(managed);
|
|
89
|
-
}
|
|
28
|
+
class ManagedReference {
|
|
29
|
+
constructor() {
|
|
30
|
+
this.type = constants_1.KEYS.REF_ELEMENT;
|
|
90
31
|
}
|
|
91
32
|
}
|
|
33
|
+
exports.ManagedReference = ManagedReference;
|
|
92
34
|
/**
|
|
93
35
|
* 解析ref
|
|
94
36
|
*/
|
|
@@ -105,143 +47,12 @@ class RefResolver extends BaseManagedResolver {
|
|
|
105
47
|
return this._factory.context.getAsync(mr.name, mr.args);
|
|
106
48
|
}
|
|
107
49
|
}
|
|
108
|
-
/**
|
|
109
|
-
* 解析 list
|
|
110
|
-
*/
|
|
111
|
-
class ListResolver extends BaseManagedResolver {
|
|
112
|
-
get type() {
|
|
113
|
-
return constants_1.KEYS.LIST_ELEMENT;
|
|
114
|
-
}
|
|
115
|
-
resolve(managed) {
|
|
116
|
-
const ml = managed;
|
|
117
|
-
const arr = [];
|
|
118
|
-
for (const item of ml) {
|
|
119
|
-
arr.push(this._factory.resolveManaged(item));
|
|
120
|
-
}
|
|
121
|
-
return arr;
|
|
122
|
-
}
|
|
123
|
-
async resolveAsync(managed) {
|
|
124
|
-
const ml = managed;
|
|
125
|
-
const arr = [];
|
|
126
|
-
for (const item of ml) {
|
|
127
|
-
arr.push(await this._factory.resolveManagedAsync(item));
|
|
128
|
-
}
|
|
129
|
-
return arr;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* 解析set
|
|
134
|
-
*/
|
|
135
|
-
class SetResolver extends BaseManagedResolver {
|
|
136
|
-
get type() {
|
|
137
|
-
return constants_1.KEYS.SET_ELEMENT;
|
|
138
|
-
}
|
|
139
|
-
resolve(managed) {
|
|
140
|
-
const ms = managed;
|
|
141
|
-
const s = new Set();
|
|
142
|
-
for (const item of ms) {
|
|
143
|
-
s.add(this._factory.resolveManaged(item));
|
|
144
|
-
}
|
|
145
|
-
return s;
|
|
146
|
-
}
|
|
147
|
-
async resolveAsync(managed) {
|
|
148
|
-
const ms = managed;
|
|
149
|
-
const s = new Set();
|
|
150
|
-
for (const item of ms) {
|
|
151
|
-
s.add(await this._factory.resolveManagedAsync(item));
|
|
152
|
-
}
|
|
153
|
-
return s;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* 解析map
|
|
158
|
-
*/
|
|
159
|
-
class MapResolver extends BaseManagedResolver {
|
|
160
|
-
get type() {
|
|
161
|
-
return constants_1.KEYS.MAP_ELEMENT;
|
|
162
|
-
}
|
|
163
|
-
resolve(managed) {
|
|
164
|
-
const mm = managed;
|
|
165
|
-
const m = new Map();
|
|
166
|
-
for (const key of mm.keys()) {
|
|
167
|
-
m.set(key, this._factory.resolveManaged(mm.get(key)));
|
|
168
|
-
}
|
|
169
|
-
return m;
|
|
170
|
-
}
|
|
171
|
-
async resolveAsync(managed) {
|
|
172
|
-
const mm = managed;
|
|
173
|
-
const m = new Map();
|
|
174
|
-
for (const key of mm.keys()) {
|
|
175
|
-
m.set(key, await this._factory.resolveManagedAsync(mm.get(key)));
|
|
176
|
-
}
|
|
177
|
-
return m;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* 解析properties
|
|
182
|
-
*/
|
|
183
|
-
class PropertiesResolver extends BaseManagedResolver {
|
|
184
|
-
get type() {
|
|
185
|
-
return constants_1.KEYS.PROPS_ELEMENT;
|
|
186
|
-
}
|
|
187
|
-
resolve(managed) {
|
|
188
|
-
const m = managed;
|
|
189
|
-
const cfg = new properties_1.ObjectProperties();
|
|
190
|
-
const keys = m.keys();
|
|
191
|
-
for (const key of keys) {
|
|
192
|
-
cfg.setProperty(key, this._factory.resolveManaged(m.getProperty(key)));
|
|
193
|
-
}
|
|
194
|
-
return cfg;
|
|
195
|
-
}
|
|
196
|
-
async resolveAsync(managed) {
|
|
197
|
-
const m = managed;
|
|
198
|
-
const cfg = new properties_1.ObjectProperties();
|
|
199
|
-
const keys = m.keys();
|
|
200
|
-
for (const key of keys) {
|
|
201
|
-
cfg.setProperty(key, await this._factory.resolveManagedAsync(m.getProperty(key)));
|
|
202
|
-
}
|
|
203
|
-
return cfg;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* 解析property
|
|
208
|
-
*/
|
|
209
|
-
class PropertyResolver extends BaseManagedResolver {
|
|
210
|
-
get type() {
|
|
211
|
-
return constants_1.KEYS.PROPERTY_ELEMENT;
|
|
212
|
-
}
|
|
213
|
-
resolve(managed) {
|
|
214
|
-
const mp = managed;
|
|
215
|
-
return this._factory.resolveManaged(mp.value);
|
|
216
|
-
}
|
|
217
|
-
async resolveAsync(managed) {
|
|
218
|
-
const mp = managed;
|
|
219
|
-
return this._factory.resolveManagedAsync(mp.value);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* 解析 object
|
|
224
|
-
*/
|
|
225
|
-
class ObjectResolver extends BaseManagedResolver {
|
|
226
|
-
get type() {
|
|
227
|
-
return constants_1.KEYS.OBJECT_ELEMENT;
|
|
228
|
-
}
|
|
229
|
-
resolve(managed) {
|
|
230
|
-
const mo = managed;
|
|
231
|
-
return this._factory.create({ definition: mo.definition });
|
|
232
|
-
}
|
|
233
|
-
async resolveAsync(managed) {
|
|
234
|
-
const mo = managed;
|
|
235
|
-
return this._factory.createAsync({ definition: mo.definition });
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
50
|
/**
|
|
239
51
|
* 解析工厂
|
|
240
52
|
*/
|
|
241
53
|
class ManagedResolverFactory {
|
|
242
54
|
constructor(context) {
|
|
243
55
|
this.resolvers = {};
|
|
244
|
-
this._props = null;
|
|
245
56
|
this.creating = new Map();
|
|
246
57
|
this.singletonCache = new Map();
|
|
247
58
|
this.afterCreateHandler = [];
|
|
@@ -249,37 +60,9 @@ class ManagedResolverFactory {
|
|
|
249
60
|
this.context = context;
|
|
250
61
|
// 初始化解析器
|
|
251
62
|
this.resolvers = {
|
|
252
|
-
json: new JSONResolver(this),
|
|
253
|
-
value: new ValueResolver(this),
|
|
254
|
-
list: new ListResolver(this),
|
|
255
|
-
set: new SetResolver(this),
|
|
256
|
-
map: new MapResolver(this),
|
|
257
|
-
props: new PropertiesResolver(this),
|
|
258
|
-
property: new PropertyResolver(this),
|
|
259
|
-
object: new ObjectResolver(this),
|
|
260
63
|
ref: new RefResolver(this),
|
|
261
64
|
};
|
|
262
65
|
}
|
|
263
|
-
get props() {
|
|
264
|
-
if (!this._props) {
|
|
265
|
-
this._props = this.context.props.toJSON();
|
|
266
|
-
}
|
|
267
|
-
return this._props;
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* 用于解析模版化的值
|
|
271
|
-
* example: {{aaa.bbb.ccc}}
|
|
272
|
-
* @param value 配置的模版值
|
|
273
|
-
*/
|
|
274
|
-
tpl(value) {
|
|
275
|
-
if (typeof value === 'string' && value.indexOf('{{') > -1) {
|
|
276
|
-
return _.template(value, {
|
|
277
|
-
// use `{{` and `}}` as delimiters
|
|
278
|
-
interpolate: /{{([\s\S]+?)}}/g,
|
|
279
|
-
})(this.props);
|
|
280
|
-
}
|
|
281
|
-
return value;
|
|
282
|
-
}
|
|
283
66
|
registerResolver(resolver) {
|
|
284
67
|
this.resolvers[resolver.type] = resolver;
|
|
285
68
|
}
|
|
@@ -299,8 +82,7 @@ class ManagedResolverFactory {
|
|
|
299
82
|
}
|
|
300
83
|
/**
|
|
301
84
|
* 同步创建对象
|
|
302
|
-
* @param
|
|
303
|
-
* @param args 参数
|
|
85
|
+
* @param opt
|
|
304
86
|
*/
|
|
305
87
|
create(opt) {
|
|
306
88
|
const { definition, args } = opt;
|
|
@@ -325,13 +107,6 @@ class ManagedResolverFactory {
|
|
|
325
107
|
if (args && _.isArray(args) && args.length > 0) {
|
|
326
108
|
constructorArgs = args;
|
|
327
109
|
}
|
|
328
|
-
else {
|
|
329
|
-
if (definition.constructorArgs) {
|
|
330
|
-
for (const arg of definition.constructorArgs) {
|
|
331
|
-
constructorArgs.push(this.resolveManaged(arg));
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
110
|
for (const handler of this.beforeCreateHandler) {
|
|
336
111
|
handler.call(this, Clzz, constructorArgs, this.context);
|
|
337
112
|
}
|
|
@@ -348,9 +123,8 @@ class ManagedResolverFactory {
|
|
|
348
123
|
if (definition.properties) {
|
|
349
124
|
const keys = definition.properties.keys();
|
|
350
125
|
for (const key of keys) {
|
|
351
|
-
const identifier = definition.properties.getProperty(key);
|
|
352
126
|
try {
|
|
353
|
-
inst[key] = this.resolveManaged(
|
|
127
|
+
inst[key] = this.resolveManaged(definition.properties.get(key));
|
|
354
128
|
}
|
|
355
129
|
catch (error) {
|
|
356
130
|
if (notFoundError_1.NotFoundError.isClosePrototypeOf(error)) {
|
|
@@ -379,8 +153,7 @@ class ManagedResolverFactory {
|
|
|
379
153
|
}
|
|
380
154
|
/**
|
|
381
155
|
* 异步创建对象
|
|
382
|
-
* @param
|
|
383
|
-
* @param args 参数
|
|
156
|
+
* @param opt
|
|
384
157
|
*/
|
|
385
158
|
async createAsync(opt) {
|
|
386
159
|
const { definition, args } = opt;
|
|
@@ -404,19 +177,10 @@ class ManagedResolverFactory {
|
|
|
404
177
|
}
|
|
405
178
|
}
|
|
406
179
|
const Clzz = definition.creator.load();
|
|
407
|
-
let constructorArgs;
|
|
180
|
+
let constructorArgs = [];
|
|
408
181
|
if (args && _.isArray(args) && args.length > 0) {
|
|
409
182
|
constructorArgs = args;
|
|
410
183
|
}
|
|
411
|
-
else {
|
|
412
|
-
if (definition.constructorArgs) {
|
|
413
|
-
constructorArgs = [];
|
|
414
|
-
for (const arg of definition.constructorArgs) {
|
|
415
|
-
debug('id = %s resolve constructor arg %s.', definition.id, arg);
|
|
416
|
-
constructorArgs.push(await this.resolveManagedAsync(arg));
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
184
|
for (const handler of this.beforeCreateHandler) {
|
|
421
185
|
handler.call(this, Clzz, constructorArgs, this.context);
|
|
422
186
|
}
|
|
@@ -438,10 +202,8 @@ class ManagedResolverFactory {
|
|
|
438
202
|
if (definition.properties) {
|
|
439
203
|
const keys = definition.properties.keys();
|
|
440
204
|
for (const key of keys) {
|
|
441
|
-
const identifier = definition.properties.getProperty(key);
|
|
442
205
|
try {
|
|
443
|
-
|
|
444
|
-
inst[key] = await this.resolveManagedAsync(identifier);
|
|
206
|
+
inst[key] = await this.resolveManagedAsync(definition.properties.get(key));
|
|
445
207
|
}
|
|
446
208
|
catch (error) {
|
|
447
209
|
if (notFoundError_1.NotFoundError.isClosePrototypeOf(error)) {
|
|
@@ -548,17 +310,25 @@ class ManagedResolverFactory {
|
|
|
548
310
|
* 遍历依赖树判断是否循环依赖
|
|
549
311
|
* @param identifier 目标id
|
|
550
312
|
* @param definition 定义描述
|
|
313
|
+
* @param depth
|
|
551
314
|
*/
|
|
552
315
|
depthFirstSearch(identifier, definition, depth) {
|
|
316
|
+
var _a;
|
|
553
317
|
if (definition) {
|
|
554
318
|
debug('dfs for %s == %s start.', identifier, definition.id);
|
|
555
|
-
if (definition.constructorArgs) {
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
319
|
+
// if (definition.constructorArgs) {
|
|
320
|
+
// const args = definition.constructorArgs.map(
|
|
321
|
+
// val => (val as ManagedReference).name
|
|
322
|
+
// );
|
|
323
|
+
// if (args.indexOf(identifier) > -1) {
|
|
324
|
+
// debug(
|
|
325
|
+
// 'dfs exist in constructor %s == %s.',
|
|
326
|
+
// identifier,
|
|
327
|
+
// definition.id
|
|
328
|
+
// );
|
|
329
|
+
// return true;
|
|
330
|
+
// }
|
|
331
|
+
// }
|
|
562
332
|
if (definition.properties) {
|
|
563
333
|
const keys = definition.properties.keys();
|
|
564
334
|
if (keys.indexOf(identifier) > -1) {
|
|
@@ -572,7 +342,8 @@ class ManagedResolverFactory {
|
|
|
572
342
|
let iden = key;
|
|
573
343
|
const ref = definition.properties.get(key);
|
|
574
344
|
if (ref && ref.name) {
|
|
575
|
-
iden =
|
|
345
|
+
iden =
|
|
346
|
+
(_a = this.context.identifierMapping.getRelation(ref.name)) !== null && _a !== void 0 ? _a : ref.name;
|
|
576
347
|
}
|
|
577
348
|
if (iden === identifier) {
|
|
578
349
|
debug('dfs exist in properties key %s == %s.', identifier, definition.id);
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { ObjectIdentifier, ScopeEnum } from '@midwayjs/decorator';
|
|
2
|
-
import {
|
|
2
|
+
import { IMidwayContainer } from '../interface';
|
|
3
3
|
export declare function providerWrapper(wrapperInfo: Array<{
|
|
4
4
|
id: ObjectIdentifier;
|
|
5
|
-
provider: (context:
|
|
5
|
+
provider: (context: IMidwayContainer, args?: any) => any;
|
|
6
6
|
scope?: ScopeEnum;
|
|
7
|
-
isAutowire?: boolean;
|
|
8
7
|
}>): void;
|
|
9
8
|
//# sourceMappingURL=providerWrapper.d.ts.map
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { MidwayContainer } from './container';
|
|
2
2
|
import { IMidwayContainer } from '../interface';
|
|
3
3
|
export declare class MidwayRequestContainer extends MidwayContainer {
|
|
4
|
-
private applicationContext;
|
|
4
|
+
private readonly applicationContext;
|
|
5
5
|
constructor(ctx: any, applicationContext: IMidwayContainer);
|
|
6
|
-
protected createContainerIdx(): number;
|
|
7
6
|
init(): void;
|
|
8
7
|
get<T = any>(identifier: any, args?: any): T;
|
|
9
8
|
getAsync<T = any>(identifier: any, args?: any): Promise<T>;
|
|
@@ -3,15 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.MidwayRequestContainer = void 0;
|
|
4
4
|
const container_1 = require("./container");
|
|
5
5
|
const interface_1 = require("../interface");
|
|
6
|
-
const util_1 = require("../util/");
|
|
7
6
|
const decorator_1 = require("@midwayjs/decorator");
|
|
8
7
|
class MidwayRequestContainer extends container_1.MidwayContainer {
|
|
9
8
|
constructor(ctx, applicationContext) {
|
|
10
|
-
super(
|
|
9
|
+
super(applicationContext);
|
|
11
10
|
this.applicationContext = applicationContext;
|
|
12
11
|
this.configService = this.applicationContext.getConfigService();
|
|
13
12
|
this.environmentService = this.applicationContext.getEnvironmentService();
|
|
14
13
|
this.aspectService = this.applicationContext.getAspectService();
|
|
14
|
+
// update legacy relationship
|
|
15
|
+
this.registry.setIdentifierRelation(this.applicationContext.registry.getIdentifierRelation());
|
|
15
16
|
this.ctx = ctx;
|
|
16
17
|
// register ctx
|
|
17
18
|
this.registerObject(interface_1.REQUEST_CTX_KEY, ctx);
|
|
@@ -23,10 +24,6 @@ class MidwayRequestContainer extends container_1.MidwayContainer {
|
|
|
23
24
|
this.beforeEachCreated(resolverHandler.beforeEachCreated.bind(resolverHandler));
|
|
24
25
|
this.afterEachCreated(resolverHandler.afterEachCreated.bind(resolverHandler));
|
|
25
26
|
}
|
|
26
|
-
createContainerIdx() {
|
|
27
|
-
// requestContainer id = -1;
|
|
28
|
-
return -1;
|
|
29
|
-
}
|
|
30
27
|
init() {
|
|
31
28
|
// do nothing
|
|
32
29
|
}
|
|
@@ -35,8 +32,7 @@ class MidwayRequestContainer extends container_1.MidwayContainer {
|
|
|
35
32
|
identifier = this.getIdentifier(identifier);
|
|
36
33
|
}
|
|
37
34
|
if (this.registry.hasObject(identifier)) {
|
|
38
|
-
|
|
39
|
-
return this.aspectService.wrapperAspectToInstance(ins);
|
|
35
|
+
return this.findRegisterObject(identifier);
|
|
40
36
|
}
|
|
41
37
|
const definition = this.applicationContext.registry.getDefinition(identifier);
|
|
42
38
|
if (definition) {
|
|
@@ -58,10 +54,8 @@ class MidwayRequestContainer extends container_1.MidwayContainer {
|
|
|
58
54
|
if (typeof identifier !== 'string') {
|
|
59
55
|
identifier = this.getIdentifier(identifier);
|
|
60
56
|
}
|
|
61
|
-
identifier = util_1.parsePrefix(identifier);
|
|
62
57
|
if (this.registry.hasObject(identifier)) {
|
|
63
|
-
|
|
64
|
-
return this.aspectService.wrapperAspectToInstance(ins);
|
|
58
|
+
return this.findRegisterObject(identifier);
|
|
65
59
|
}
|
|
66
60
|
const definition = this.applicationContext.registry.getDefinition(identifier);
|
|
67
61
|
if (definition) {
|
|
@@ -80,7 +74,6 @@ class MidwayRequestContainer extends container_1.MidwayContainer {
|
|
|
80
74
|
}
|
|
81
75
|
}
|
|
82
76
|
async ready() {
|
|
83
|
-
this.readied = true;
|
|
84
77
|
// ignore other things
|
|
85
78
|
}
|
|
86
79
|
getConfigService() {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ManagedResolverFactory } from './managedResolverFactory';
|
|
2
|
-
import { HandlerFunction, IResolverHandler, IObjectDefinition,
|
|
2
|
+
import { HandlerFunction, IResolverHandler, IObjectDefinition, IMidwayContainer } from '../interface';
|
|
3
3
|
export declare class ResolverHandler implements IResolverHandler {
|
|
4
4
|
private handlerMap;
|
|
5
5
|
private resolverFactory;
|
|
6
|
-
constructor(container:
|
|
6
|
+
constructor(container: IMidwayContainer, factory: ManagedResolverFactory);
|
|
7
7
|
bindCreatedHook(): void;
|
|
8
8
|
/**
|
|
9
9
|
* 创建对象前
|
|
@@ -28,6 +28,7 @@ export declare class ResolverHandler implements IResolverHandler {
|
|
|
28
28
|
*/
|
|
29
29
|
private defineGetterPropertyValue;
|
|
30
30
|
registerHandler(key: string, fn: HandlerFunction): void;
|
|
31
|
+
hasHandler(key: string): boolean;
|
|
31
32
|
getHandler(key: string): HandlerFunction;
|
|
32
33
|
}
|
|
33
34
|
//# sourceMappingURL=resolverHandler.d.ts.map
|