@midwayjs/core 3.0.0-alpha.9 → 3.0.0-beta.12
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 +149 -0
- package/README.md +1 -1
- package/dist/baseFramework.d.ts +56 -22
- package/dist/baseFramework.js +157 -232
- package/dist/common/applicationManager.d.ts +12 -0
- package/dist/common/applicationManager.js +66 -0
- package/dist/{util → common}/fileDetector.d.ts +0 -0
- package/dist/{util → common}/fileDetector.js +16 -10
- package/dist/common/filterManager.d.ts +19 -0
- package/dist/common/filterManager.js +85 -0
- package/dist/common/middlewareManager.d.ts +68 -0
- package/dist/common/middlewareManager.js +183 -0
- package/dist/common/serviceFactory.d.ts +15 -0
- package/dist/{util → common}/serviceFactory.js +16 -6
- package/dist/{util → common}/triggerCollector.d.ts +0 -0
- package/dist/{util → common}/triggerCollector.js +0 -0
- package/dist/common/webGenerator.d.ts +16 -0
- package/dist/common/webGenerator.js +117 -0
- package/dist/{util → common}/webRouterCollector.d.ts +21 -2
- package/dist/common/webRouterCollector.js +331 -0
- package/dist/config/config.default.d.ts +7 -0
- package/dist/config/config.default.js +28 -0
- package/dist/context/container.d.ts +73 -43
- package/dist/context/container.js +289 -271
- package/dist/context/definitionRegistry.d.ts +26 -0
- package/dist/context/definitionRegistry.js +124 -0
- package/dist/context/managedResolverFactory.d.ts +15 -32
- package/dist/context/managedResolverFactory.js +91 -320
- package/dist/context/providerWrapper.d.ts +2 -3
- package/dist/context/requestContainer.d.ts +0 -2
- package/dist/context/requestContainer.js +9 -26
- package/dist/definitions/functionDefinition.d.ts +3 -4
- package/dist/definitions/functionDefinition.js +0 -6
- package/dist/definitions/objectCreator.js +9 -8
- package/dist/definitions/objectDefinition.d.ts +4 -6
- package/dist/definitions/objectDefinition.js +0 -8
- package/dist/definitions/properties.d.ts +2 -15
- package/dist/definitions/properties.js +3 -72
- package/dist/error/base.d.ts +32 -0
- package/dist/error/base.js +48 -0
- package/dist/error/framework.d.ts +45 -0
- package/dist/error/framework.js +87 -0
- package/dist/error/http.d.ts +119 -0
- package/dist/error/http.js +169 -0
- package/dist/error/index.d.ts +4 -0
- package/dist/error/index.js +16 -0
- package/dist/functional/configuration.d.ts +4 -2
- package/dist/functional/configuration.js +12 -2
- package/dist/index.d.ts +24 -11
- package/dist/index.js +36 -36
- package/dist/interface.d.ts +270 -184
- package/dist/interface.js +9 -1
- package/dist/service/aspectService.d.ts +11 -14
- package/dist/service/aspectService.js +116 -172
- package/dist/service/configService.d.ts +10 -8
- package/dist/service/configService.js +61 -38
- package/dist/service/decoratorService.d.ts +23 -0
- package/dist/service/decoratorService.js +149 -0
- package/dist/service/environmentService.js +15 -4
- package/dist/service/frameworkService.d.ts +26 -0
- package/dist/service/frameworkService.js +176 -0
- package/dist/service/informationService.d.ts +4 -7
- package/dist/service/informationService.js +41 -10
- package/dist/service/lifeCycleService.d.ts +14 -0
- package/dist/service/lifeCycleService.js +130 -0
- package/dist/service/loggerService.d.ts +27 -0
- package/dist/service/loggerService.js +132 -0
- package/dist/service/middlewareService.d.ts +10 -0
- package/dist/service/middlewareService.js +123 -0
- package/dist/{features/pipeline.d.ts → service/pipelineService.d.ts} +56 -46
- package/dist/{features/pipeline.js → service/pipelineService.js} +54 -19
- package/dist/setup.d.ts +4 -0
- package/dist/setup.js +119 -0
- package/dist/util/contextUtil.d.ts +1 -1
- package/dist/util/contextUtil.js +2 -2
- package/dist/util/index.d.ts +64 -0
- package/dist/util/index.js +195 -7
- package/dist/util/pathFileUtil.js +2 -2
- package/dist/util/pathToRegexp.d.ts +17 -0
- package/dist/util/pathToRegexp.js +280 -0
- package/dist/util/webRouterParam.d.ts +2 -2
- package/dist/util/webRouterParam.js +43 -24
- package/package.json +10 -15
- package/dist/common/lodashWrap.d.ts +0 -9
- package/dist/common/lodashWrap.js +0 -18
- package/dist/common/notFoundError.d.ts +0 -8
- package/dist/common/notFoundError.js +0 -20
- package/dist/common/reflectTool.d.ts +0 -15
- package/dist/common/reflectTool.js +0 -83
- package/dist/context/applicationContext.d.ts +0 -81
- package/dist/context/applicationContext.js +0 -263
- package/dist/context/managed.d.ts +0 -45
- package/dist/context/managed.js +0 -69
- package/dist/context/resolverHandler.d.ts +0 -34
- package/dist/context/resolverHandler.js +0 -88
- package/dist/definitions/messageSource.d.ts +0 -13
- package/dist/definitions/messageSource.js +0 -74
- package/dist/definitions/resource.d.ts +0 -27
- package/dist/definitions/resource.js +0 -116
- package/dist/features/index.d.ts +0 -2
- package/dist/features/index.js +0 -3
- package/dist/logger.d.ts +0 -4
- package/dist/logger.js +0 -20
- package/dist/util/containerUtil.d.ts +0 -11
- package/dist/util/containerUtil.js +0 -26
- package/dist/util/emptyFramework.d.ts +0 -62
- package/dist/util/emptyFramework.js +0 -72
- package/dist/util/serviceFactory.d.ts +0 -13
- package/dist/util/staticConfig.d.ts +0 -10
- package/dist/util/staticConfig.js +0 -67
- package/dist/util/webRouterCollector.js +0 -348
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 基础的ObjectFactory和ApplicationContext实现
|
|
3
|
-
*/
|
|
4
|
-
import { ObjectIdentifier } from '@midwayjs/decorator';
|
|
5
|
-
import { IApplicationContext, IObjectDefinition, IObjectDefinitionRegistry, IObjectFactory, ObjectDependencyTree } from '../interface';
|
|
6
|
-
import { ObjectProperties } from '../definitions/properties';
|
|
7
|
-
import { ManagedResolverFactory } from './managedResolverFactory';
|
|
8
|
-
export declare class ObjectDefinitionRegistry extends Map implements IObjectDefinitionRegistry {
|
|
9
|
-
private singletonIds;
|
|
10
|
-
get identifiers(): any[];
|
|
11
|
-
get count(): number;
|
|
12
|
-
getSingletonDefinitionIds(): ObjectIdentifier[];
|
|
13
|
-
getDefinitionByName(name: string): IObjectDefinition[];
|
|
14
|
-
registerDefinition(identifier: ObjectIdentifier, definition: IObjectDefinition): void;
|
|
15
|
-
getDefinition(identifier: ObjectIdentifier): IObjectDefinition;
|
|
16
|
-
getDefinitionByPath(path: string): IObjectDefinition;
|
|
17
|
-
removeDefinition(identifier: ObjectIdentifier): void;
|
|
18
|
-
hasDefinition(identifier: ObjectIdentifier): boolean;
|
|
19
|
-
clearAll(): void;
|
|
20
|
-
hasObject(identifier: ObjectIdentifier): boolean;
|
|
21
|
-
registerObject(identifier: ObjectIdentifier, target: any): void;
|
|
22
|
-
getObject(identifier: ObjectIdentifier): any;
|
|
23
|
-
}
|
|
24
|
-
export declare class BaseApplicationContext implements IApplicationContext, IObjectFactory {
|
|
25
|
-
protected readied: boolean;
|
|
26
|
-
protected midwayIdentifiers: string[];
|
|
27
|
-
private _resolverFactory;
|
|
28
|
-
private _registry;
|
|
29
|
-
private _props;
|
|
30
|
-
private _dependencyMap;
|
|
31
|
-
baseDir: string;
|
|
32
|
-
parent: IApplicationContext;
|
|
33
|
-
disableConflictCheck: boolean;
|
|
34
|
-
constructor(baseDir?: string, parent?: IApplicationContext);
|
|
35
|
-
get dependencyMap(): Map<string, ObjectDependencyTree>;
|
|
36
|
-
get props(): ObjectProperties;
|
|
37
|
-
get registry(): IObjectDefinitionRegistry;
|
|
38
|
-
set registry(registry: IObjectDefinitionRegistry);
|
|
39
|
-
protected getManagedResolverFactory(): ManagedResolverFactory;
|
|
40
|
-
/**
|
|
41
|
-
* 继承实现时需要调用super
|
|
42
|
-
*/
|
|
43
|
-
protected init(): void;
|
|
44
|
-
stop(): Promise<void>;
|
|
45
|
-
ready(): void;
|
|
46
|
-
protected loadDefinitions(): void;
|
|
47
|
-
isAsync(identifier: ObjectIdentifier): boolean;
|
|
48
|
-
get<T>(identifier: {
|
|
49
|
-
new (...args: any[]): T;
|
|
50
|
-
}, args?: any): T;
|
|
51
|
-
get<T>(identifier: ObjectIdentifier, args?: any): T;
|
|
52
|
-
getAsync<T>(identifier: {
|
|
53
|
-
new (...args: any[]): T;
|
|
54
|
-
}, args?: any): Promise<T>;
|
|
55
|
-
getAsync<T>(identifier: ObjectIdentifier, args?: any): Promise<T>;
|
|
56
|
-
get isReady(): boolean;
|
|
57
|
-
/**
|
|
58
|
-
* proxy registry.registerDefinition
|
|
59
|
-
* @param {ObjectIdentifier} identifier
|
|
60
|
-
* @param {IObjectDefinition} definition
|
|
61
|
-
*/
|
|
62
|
-
registerDefinition(identifier: ObjectIdentifier, definition: IObjectDefinition): void;
|
|
63
|
-
/**
|
|
64
|
-
* proxy registry.registerObject
|
|
65
|
-
* @param {ObjectIdentifier} identifier
|
|
66
|
-
* @param target
|
|
67
|
-
*/
|
|
68
|
-
registerObject(identifier: ObjectIdentifier, target: any): void;
|
|
69
|
-
/**
|
|
70
|
-
* register handler after instance create
|
|
71
|
-
* @param fn
|
|
72
|
-
*/
|
|
73
|
-
afterEachCreated(fn: (ins: any, context: IApplicationContext, definition?: IObjectDefinition) => void): void;
|
|
74
|
-
/**
|
|
75
|
-
* register handler before instance create
|
|
76
|
-
* @param fn
|
|
77
|
-
*/
|
|
78
|
-
beforeEachCreated(fn: (Clzz: any, constructorArgs: any[], context: IApplicationContext) => void): void;
|
|
79
|
-
protected createObjectDependencyTree(identifier: any, definition: any): void;
|
|
80
|
-
}
|
|
81
|
-
//# sourceMappingURL=applicationContext.d.ts.map
|
|
@@ -1,263 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseApplicationContext = exports.ObjectDefinitionRegistry = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* 基础的ObjectFactory和ApplicationContext实现
|
|
6
|
-
*/
|
|
7
|
-
const decorator_1 = require("@midwayjs/decorator");
|
|
8
|
-
const properties_1 = require("../definitions/properties");
|
|
9
|
-
const managedResolverFactory_1 = require("./managedResolverFactory");
|
|
10
|
-
const notFoundError_1 = require("../common/notFoundError");
|
|
11
|
-
const util_1 = require("../util/");
|
|
12
|
-
const pathFileUtil_1 = require("../util/pathFileUtil");
|
|
13
|
-
const PREFIX = '_id_default_';
|
|
14
|
-
class ObjectDefinitionRegistry extends Map {
|
|
15
|
-
constructor() {
|
|
16
|
-
super(...arguments);
|
|
17
|
-
this.singletonIds = [];
|
|
18
|
-
}
|
|
19
|
-
get identifiers() {
|
|
20
|
-
const ids = [];
|
|
21
|
-
for (const key of this.keys()) {
|
|
22
|
-
if (key.indexOf(PREFIX) === -1) {
|
|
23
|
-
ids.push(key);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return ids;
|
|
27
|
-
}
|
|
28
|
-
get count() {
|
|
29
|
-
return this.size;
|
|
30
|
-
}
|
|
31
|
-
getSingletonDefinitionIds() {
|
|
32
|
-
return this.singletonIds;
|
|
33
|
-
}
|
|
34
|
-
getDefinitionByName(name) {
|
|
35
|
-
const definitions = [];
|
|
36
|
-
for (const v of this.values()) {
|
|
37
|
-
const definition = v;
|
|
38
|
-
if (definition.name === name) {
|
|
39
|
-
definitions.push(definition);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return definitions;
|
|
43
|
-
}
|
|
44
|
-
registerDefinition(identifier, definition) {
|
|
45
|
-
if (definition.isSingletonScope()) {
|
|
46
|
-
this.singletonIds.push(identifier);
|
|
47
|
-
}
|
|
48
|
-
this.set(identifier, definition);
|
|
49
|
-
}
|
|
50
|
-
getDefinition(identifier) {
|
|
51
|
-
return this.get(identifier);
|
|
52
|
-
}
|
|
53
|
-
getDefinitionByPath(path) {
|
|
54
|
-
for (const v of this.values()) {
|
|
55
|
-
const definition = v;
|
|
56
|
-
if (definition.path === path) {
|
|
57
|
-
return definition;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return null;
|
|
61
|
-
}
|
|
62
|
-
removeDefinition(identifier) {
|
|
63
|
-
this.delete(identifier);
|
|
64
|
-
}
|
|
65
|
-
hasDefinition(identifier) {
|
|
66
|
-
return this.has(identifier);
|
|
67
|
-
}
|
|
68
|
-
clearAll() {
|
|
69
|
-
this.singletonIds = [];
|
|
70
|
-
this.clear();
|
|
71
|
-
}
|
|
72
|
-
hasObject(identifier) {
|
|
73
|
-
return this.has(PREFIX + identifier);
|
|
74
|
-
}
|
|
75
|
-
registerObject(identifier, target) {
|
|
76
|
-
this.set(PREFIX + identifier, target);
|
|
77
|
-
}
|
|
78
|
-
getObject(identifier) {
|
|
79
|
-
return this.get(PREFIX + identifier);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
exports.ObjectDefinitionRegistry = ObjectDefinitionRegistry;
|
|
83
|
-
class BaseApplicationContext {
|
|
84
|
-
constructor(baseDir = '', parent) {
|
|
85
|
-
this.readied = false;
|
|
86
|
-
// 自己内部实现的,可注入的 feature(见 features)
|
|
87
|
-
this.midwayIdentifiers = [];
|
|
88
|
-
this._resolverFactory = null;
|
|
89
|
-
this._registry = null;
|
|
90
|
-
this._props = null;
|
|
91
|
-
this._dependencyMap = null;
|
|
92
|
-
this.baseDir = null;
|
|
93
|
-
this.parent = null;
|
|
94
|
-
this.disableConflictCheck = false;
|
|
95
|
-
this.parent = parent;
|
|
96
|
-
this.baseDir = baseDir;
|
|
97
|
-
this.init();
|
|
98
|
-
}
|
|
99
|
-
get dependencyMap() {
|
|
100
|
-
if (!this._dependencyMap) {
|
|
101
|
-
this._dependencyMap = new Map();
|
|
102
|
-
}
|
|
103
|
-
return this._dependencyMap;
|
|
104
|
-
}
|
|
105
|
-
get props() {
|
|
106
|
-
if (!this._props) {
|
|
107
|
-
this._props = new properties_1.ObjectProperties();
|
|
108
|
-
}
|
|
109
|
-
return this._props;
|
|
110
|
-
}
|
|
111
|
-
get registry() {
|
|
112
|
-
if (!this._registry) {
|
|
113
|
-
this._registry = new ObjectDefinitionRegistry();
|
|
114
|
-
}
|
|
115
|
-
return this._registry;
|
|
116
|
-
}
|
|
117
|
-
set registry(registry) {
|
|
118
|
-
this._registry = registry;
|
|
119
|
-
}
|
|
120
|
-
getManagedResolverFactory() {
|
|
121
|
-
if (!this._resolverFactory) {
|
|
122
|
-
this._resolverFactory = new managedResolverFactory_1.ManagedResolverFactory(this);
|
|
123
|
-
}
|
|
124
|
-
return this._resolverFactory;
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* 继承实现时需要调用super
|
|
128
|
-
*/
|
|
129
|
-
init() { }
|
|
130
|
-
async stop() {
|
|
131
|
-
await this.getManagedResolverFactory().destroyCache();
|
|
132
|
-
this.registry.clearAll();
|
|
133
|
-
this.readied = false;
|
|
134
|
-
}
|
|
135
|
-
ready() {
|
|
136
|
-
this.loadDefinitions();
|
|
137
|
-
this.readied = true;
|
|
138
|
-
}
|
|
139
|
-
loadDefinitions() { }
|
|
140
|
-
isAsync(identifier) {
|
|
141
|
-
if (this.registry.hasDefinition(identifier)) {
|
|
142
|
-
return this.registry.getDefinition(identifier).isAsync();
|
|
143
|
-
}
|
|
144
|
-
return false;
|
|
145
|
-
}
|
|
146
|
-
get(identifier, args) {
|
|
147
|
-
if (!this.readied) {
|
|
148
|
-
this.ready();
|
|
149
|
-
}
|
|
150
|
-
if (typeof identifier !== 'string') {
|
|
151
|
-
identifier = decorator_1.getProviderId(identifier);
|
|
152
|
-
}
|
|
153
|
-
// 因为在这里拿不到类名, NotFoundError 类的错误信息在 ManagedResolverFactory.ts createAsync 方法中增加错误类名
|
|
154
|
-
identifier = util_1.parsePrefix(identifier);
|
|
155
|
-
if (this.registry.hasObject(identifier)) {
|
|
156
|
-
return this.registry.getObject(identifier);
|
|
157
|
-
}
|
|
158
|
-
if (this.isAsync(identifier)) {
|
|
159
|
-
throw new Error(`${identifier} must use getAsync`);
|
|
160
|
-
}
|
|
161
|
-
const definition = this.registry.getDefinition(identifier);
|
|
162
|
-
if (!definition && this.parent) {
|
|
163
|
-
if (this.parent.isAsync(identifier)) {
|
|
164
|
-
throw new Error(`${identifier} must use getAsync`);
|
|
165
|
-
}
|
|
166
|
-
return this.parent.get(identifier, args);
|
|
167
|
-
}
|
|
168
|
-
if (!definition) {
|
|
169
|
-
throw new notFoundError_1.NotFoundError(identifier);
|
|
170
|
-
}
|
|
171
|
-
return this.getManagedResolverFactory().create({ definition, args });
|
|
172
|
-
}
|
|
173
|
-
async getAsync(identifier, args) {
|
|
174
|
-
if (!this.readied) {
|
|
175
|
-
this.ready();
|
|
176
|
-
}
|
|
177
|
-
if (typeof identifier !== 'string') {
|
|
178
|
-
identifier = decorator_1.getProviderId(identifier);
|
|
179
|
-
}
|
|
180
|
-
// 因为在这里拿不到类名, NotFoundError 类的错误信息在 ManagedResolverFactory.ts createAsync 方法中增加错误类名
|
|
181
|
-
identifier = util_1.parsePrefix(identifier);
|
|
182
|
-
if (this.registry.hasObject(identifier)) {
|
|
183
|
-
return this.registry.getObject(identifier);
|
|
184
|
-
}
|
|
185
|
-
const definition = this.registry.getDefinition(identifier);
|
|
186
|
-
if (!definition && this.parent) {
|
|
187
|
-
return this.parent.getAsync(identifier, args);
|
|
188
|
-
}
|
|
189
|
-
if (!definition) {
|
|
190
|
-
throw new notFoundError_1.NotFoundError(identifier);
|
|
191
|
-
}
|
|
192
|
-
return this.getManagedResolverFactory().createAsync({ definition, args });
|
|
193
|
-
}
|
|
194
|
-
get isReady() {
|
|
195
|
-
return this.readied;
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* proxy registry.registerDefinition
|
|
199
|
-
* @param {ObjectIdentifier} identifier
|
|
200
|
-
* @param {IObjectDefinition} definition
|
|
201
|
-
*/
|
|
202
|
-
registerDefinition(identifier, definition) {
|
|
203
|
-
if (!this.disableConflictCheck && this.registry.hasDefinition(identifier)) {
|
|
204
|
-
const def = this.registry.getDefinition(identifier);
|
|
205
|
-
if (definition.srcPath && def.srcPath) {
|
|
206
|
-
if (!pathFileUtil_1.PathFileUtil.isPathEqual(definition.srcPath, def.srcPath)) {
|
|
207
|
-
throw new Error(`${identifier} path = ${definition.srcPath} already exist (${def.srcPath})!`);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
this.registry.registerDefinition(identifier, definition);
|
|
212
|
-
this.createObjectDependencyTree(identifier, definition);
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* proxy registry.registerObject
|
|
216
|
-
* @param {ObjectIdentifier} identifier
|
|
217
|
-
* @param target
|
|
218
|
-
*/
|
|
219
|
-
registerObject(identifier, target) {
|
|
220
|
-
this.registry.registerObject(identifier, target);
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* register handler after instance create
|
|
224
|
-
* @param fn
|
|
225
|
-
*/
|
|
226
|
-
afterEachCreated(fn) {
|
|
227
|
-
this.getManagedResolverFactory().afterEachCreated(fn);
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* register handler before instance create
|
|
231
|
-
* @param fn
|
|
232
|
-
*/
|
|
233
|
-
beforeEachCreated(fn) {
|
|
234
|
-
this.getManagedResolverFactory().beforeEachCreated(fn);
|
|
235
|
-
}
|
|
236
|
-
createObjectDependencyTree(identifier, definition) {
|
|
237
|
-
if (!this.dependencyMap.has(identifier)) {
|
|
238
|
-
let constructorArgs = definition.constructorArgs || [];
|
|
239
|
-
constructorArgs = constructorArgs
|
|
240
|
-
.map(ref => {
|
|
241
|
-
return ref.name;
|
|
242
|
-
})
|
|
243
|
-
.filter(name => {
|
|
244
|
-
return !!name;
|
|
245
|
-
});
|
|
246
|
-
const properties = (definition.properties &&
|
|
247
|
-
definition.properties.keys().map(key => {
|
|
248
|
-
return definition.properties.get(key).name;
|
|
249
|
-
})) ||
|
|
250
|
-
[];
|
|
251
|
-
this.dependencyMap.set(identifier, {
|
|
252
|
-
name: typeof definition.path !== 'string'
|
|
253
|
-
? definition.path.name
|
|
254
|
-
: identifier,
|
|
255
|
-
scope: definition.scope,
|
|
256
|
-
constructorArgs,
|
|
257
|
-
properties,
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
exports.BaseApplicationContext = BaseApplicationContext;
|
|
263
|
-
//# sourceMappingURL=applicationContext.js.map
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 用于抽象描述的属性、json、ref、set、map等内容
|
|
3
|
-
*/
|
|
4
|
-
import { IManagedInstance } from '@midwayjs/decorator';
|
|
5
|
-
import { IObjectDefinition } from '../interface';
|
|
6
|
-
import { ObjectProperties } from '../definitions/properties';
|
|
7
|
-
export declare class ManagedValue implements IManagedInstance {
|
|
8
|
-
type: string;
|
|
9
|
-
value: any;
|
|
10
|
-
valueType: string;
|
|
11
|
-
constructor(value?: any, valueType?: string);
|
|
12
|
-
}
|
|
13
|
-
export declare class ManagedReference implements IManagedInstance {
|
|
14
|
-
type: string;
|
|
15
|
-
name: string;
|
|
16
|
-
args?: any;
|
|
17
|
-
}
|
|
18
|
-
export declare class ManagedJSON implements IManagedInstance {
|
|
19
|
-
type: string;
|
|
20
|
-
value: string;
|
|
21
|
-
}
|
|
22
|
-
export declare class ManagedList extends Array implements IManagedInstance {
|
|
23
|
-
type: string;
|
|
24
|
-
}
|
|
25
|
-
export declare class ManagedSet extends Set implements IManagedInstance {
|
|
26
|
-
type: string;
|
|
27
|
-
}
|
|
28
|
-
export declare class ManagedMap extends Map implements IManagedInstance {
|
|
29
|
-
type: string;
|
|
30
|
-
}
|
|
31
|
-
export declare class ManagedProperties extends ObjectProperties implements IManagedInstance {
|
|
32
|
-
type: string;
|
|
33
|
-
}
|
|
34
|
-
export declare class ManagedProperty implements IManagedInstance {
|
|
35
|
-
type: string;
|
|
36
|
-
name: string;
|
|
37
|
-
value: any;
|
|
38
|
-
valueType: string;
|
|
39
|
-
}
|
|
40
|
-
export declare class ManagedObject implements IManagedInstance {
|
|
41
|
-
type: string;
|
|
42
|
-
name: string;
|
|
43
|
-
definition: IObjectDefinition;
|
|
44
|
-
}
|
|
45
|
-
//# sourceMappingURL=managed.d.ts.map
|
package/dist/context/managed.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* 用于抽象描述的属性、json、ref、set、map等内容
|
|
4
|
-
*/
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ManagedObject = exports.ManagedProperty = exports.ManagedProperties = exports.ManagedMap = exports.ManagedSet = exports.ManagedList = exports.ManagedJSON = exports.ManagedReference = exports.ManagedValue = void 0;
|
|
7
|
-
const properties_1 = require("../definitions/properties");
|
|
8
|
-
const constants_1 = require("../common/constants");
|
|
9
|
-
class ManagedValue {
|
|
10
|
-
constructor(value, valueType) {
|
|
11
|
-
this.type = constants_1.KEYS.VALUE_ELEMENT;
|
|
12
|
-
this.value = value;
|
|
13
|
-
this.valueType = valueType || constants_1.VALUE_TYPE.STRING;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
exports.ManagedValue = ManagedValue;
|
|
17
|
-
class ManagedReference {
|
|
18
|
-
constructor() {
|
|
19
|
-
this.type = constants_1.KEYS.REF_ELEMENT;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
exports.ManagedReference = ManagedReference;
|
|
23
|
-
class ManagedJSON {
|
|
24
|
-
constructor() {
|
|
25
|
-
this.type = constants_1.KEYS.JSON_ELEMENT;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
exports.ManagedJSON = ManagedJSON;
|
|
29
|
-
class ManagedList extends Array {
|
|
30
|
-
constructor() {
|
|
31
|
-
super(...arguments);
|
|
32
|
-
this.type = constants_1.KEYS.LIST_ELEMENT;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
exports.ManagedList = ManagedList;
|
|
36
|
-
class ManagedSet extends Set {
|
|
37
|
-
constructor() {
|
|
38
|
-
super(...arguments);
|
|
39
|
-
this.type = constants_1.KEYS.SET_ELEMENT;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
exports.ManagedSet = ManagedSet;
|
|
43
|
-
class ManagedMap extends Map {
|
|
44
|
-
constructor() {
|
|
45
|
-
super(...arguments);
|
|
46
|
-
this.type = constants_1.KEYS.MAP_ELEMENT;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
exports.ManagedMap = ManagedMap;
|
|
50
|
-
class ManagedProperties extends properties_1.ObjectProperties {
|
|
51
|
-
constructor() {
|
|
52
|
-
super(...arguments);
|
|
53
|
-
this.type = constants_1.KEYS.PROPS_ELEMENT;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
exports.ManagedProperties = ManagedProperties;
|
|
57
|
-
class ManagedProperty {
|
|
58
|
-
constructor() {
|
|
59
|
-
this.type = constants_1.KEYS.PROPERTY_ELEMENT;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
exports.ManagedProperty = ManagedProperty;
|
|
63
|
-
class ManagedObject {
|
|
64
|
-
constructor() {
|
|
65
|
-
this.type = constants_1.KEYS.OBJECT_ELEMENT;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
exports.ManagedObject = ManagedObject;
|
|
69
|
-
//# sourceMappingURL=managed.js.map
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { ManagedResolverFactory } from './managedResolverFactory';
|
|
2
|
-
import { HandlerFunction, IResolverHandler, IObjectDefinition, IApplicationContext } from '../interface';
|
|
3
|
-
export declare class ResolverHandler implements IResolverHandler {
|
|
4
|
-
private handlerMap;
|
|
5
|
-
private resolverFactory;
|
|
6
|
-
constructor(container: IApplicationContext, factory: ManagedResolverFactory);
|
|
7
|
-
bindCreatedHook(): void;
|
|
8
|
-
/**
|
|
9
|
-
* 创建对象前
|
|
10
|
-
* @param target 当前对象
|
|
11
|
-
* @param constructorArgs 构造参数
|
|
12
|
-
* @param context 上下文
|
|
13
|
-
*/
|
|
14
|
-
beforeEachCreated(target: any, constructorArgs: any[], context: any): void;
|
|
15
|
-
/**
|
|
16
|
-
* 创建对象后
|
|
17
|
-
* @param instance 对象
|
|
18
|
-
* @param context 上下文
|
|
19
|
-
* @param definition 定义
|
|
20
|
-
*/
|
|
21
|
-
afterEachCreated(instance: any, context: any, definition: IObjectDefinition): void;
|
|
22
|
-
/**
|
|
23
|
-
* binding getter method for decorator
|
|
24
|
-
*
|
|
25
|
-
* @param setterProps
|
|
26
|
-
* @param instance
|
|
27
|
-
* @param getterHandler
|
|
28
|
-
*/
|
|
29
|
-
private defineGetterPropertyValue;
|
|
30
|
-
registerHandler(key: string, fn: HandlerFunction): void;
|
|
31
|
-
hasHandler(key: string): boolean;
|
|
32
|
-
getHandler(key: string): HandlerFunction;
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=resolverHandler.d.ts.map
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ResolverHandler = void 0;
|
|
4
|
-
const decorator_1 = require("@midwayjs/decorator");
|
|
5
|
-
const util = require("util");
|
|
6
|
-
const debug = util.debuglog('midway:container');
|
|
7
|
-
class ResolverHandler {
|
|
8
|
-
constructor(container, factory) {
|
|
9
|
-
this.resolverFactory = factory;
|
|
10
|
-
this.handlerMap = new Map();
|
|
11
|
-
this.bindCreatedHook();
|
|
12
|
-
}
|
|
13
|
-
bindCreatedHook() {
|
|
14
|
-
this.resolverFactory.beforeEachCreated(this.beforeEachCreated.bind(this));
|
|
15
|
-
this.resolverFactory.afterEachCreated(this.afterEachCreated.bind(this));
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* 创建对象前
|
|
19
|
-
* @param target 当前对象
|
|
20
|
-
* @param constructorArgs 构造参数
|
|
21
|
-
* @param context 上下文
|
|
22
|
-
*/
|
|
23
|
-
beforeEachCreated(target, constructorArgs, context) {
|
|
24
|
-
let constructorMetaData;
|
|
25
|
-
try {
|
|
26
|
-
constructorMetaData = decorator_1.getClassMetadata(decorator_1.CLASS_KEY_CONSTRUCTOR, target);
|
|
27
|
-
}
|
|
28
|
-
catch (e) {
|
|
29
|
-
debug(`beforeEachCreated error ${e.stack}`);
|
|
30
|
-
}
|
|
31
|
-
// lack of field
|
|
32
|
-
if (constructorMetaData && constructorArgs) {
|
|
33
|
-
for (const idx in constructorMetaData) {
|
|
34
|
-
const index = parseInt(idx, 10);
|
|
35
|
-
const propertyMeta = constructorMetaData[index];
|
|
36
|
-
const hook = this.getHandler(propertyMeta.type);
|
|
37
|
-
if (hook) {
|
|
38
|
-
constructorArgs[index] = hook(propertyMeta.key);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* 创建对象后
|
|
45
|
-
* @param instance 对象
|
|
46
|
-
* @param context 上下文
|
|
47
|
-
* @param definition 定义
|
|
48
|
-
*/
|
|
49
|
-
afterEachCreated(instance, context, definition) {
|
|
50
|
-
if (this.handlerMap.size > 0 && Array.isArray(definition.handlerProps)) {
|
|
51
|
-
// 已经预先在 bind 时处理
|
|
52
|
-
for (const item of definition.handlerProps) {
|
|
53
|
-
this.defineGetterPropertyValue(item.prop, instance, this.getHandler(item.handlerKey));
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* binding getter method for decorator
|
|
59
|
-
*
|
|
60
|
-
* @param setterProps
|
|
61
|
-
* @param instance
|
|
62
|
-
* @param getterHandler
|
|
63
|
-
*/
|
|
64
|
-
defineGetterPropertyValue(prop, instance, getterHandler) {
|
|
65
|
-
if (prop && getterHandler) {
|
|
66
|
-
if (prop.propertyName) {
|
|
67
|
-
Object.defineProperty(instance, prop.propertyName, {
|
|
68
|
-
get: () => getterHandler(prop.key, prop.meta, instance),
|
|
69
|
-
configurable: true,
|
|
70
|
-
enumerable: true,
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
registerHandler(key, fn) {
|
|
76
|
-
this.handlerMap.set(key, fn);
|
|
77
|
-
}
|
|
78
|
-
hasHandler(key) {
|
|
79
|
-
return this.handlerMap.has(key);
|
|
80
|
-
}
|
|
81
|
-
getHandler(key) {
|
|
82
|
-
if (this.handlerMap.has(key)) {
|
|
83
|
-
return this.handlerMap.get(key);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
exports.ResolverHandler = ResolverHandler;
|
|
88
|
-
//# sourceMappingURL=resolverHandler.js.map
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { IMessageSource, IResource, Locale } from '../interface';
|
|
2
|
-
/**
|
|
3
|
-
* 多语言支持实现
|
|
4
|
-
* 支持文件夹载入以及文件载入
|
|
5
|
-
*/
|
|
6
|
-
export declare class MessageSource extends Map implements IMessageSource {
|
|
7
|
-
private defaultLocale;
|
|
8
|
-
constructor(defaultLocale: Locale);
|
|
9
|
-
load(locale: Locale, res: IResource): Promise<void>;
|
|
10
|
-
loadUseFileName(res: IResource): Promise<void>;
|
|
11
|
-
getMessage(code: string, args?: any[], defaultMessage?: string, locale?: Locale): string;
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=messageSource.d.ts.map
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MessageSource = void 0;
|
|
4
|
-
const _ = require("../common/lodashWrap");
|
|
5
|
-
const util_1 = require("util");
|
|
6
|
-
/**
|
|
7
|
-
* 多语言支持实现
|
|
8
|
-
* 支持文件夹载入以及文件载入
|
|
9
|
-
*/
|
|
10
|
-
class MessageSource extends Map {
|
|
11
|
-
constructor(defaultLocale) {
|
|
12
|
-
super();
|
|
13
|
-
this.defaultLocale = null;
|
|
14
|
-
this.defaultLocale = defaultLocale;
|
|
15
|
-
}
|
|
16
|
-
async load(locale, res) {
|
|
17
|
-
if (res.isFile()) {
|
|
18
|
-
const messages = await res.getContentAsJSON();
|
|
19
|
-
if (this.has(locale)) {
|
|
20
|
-
_.assign(this.get(locale), messages);
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
this.set(locale, messages);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
if (res.isDir()) {
|
|
27
|
-
const resources = await res.getSubResources();
|
|
28
|
-
for (const resource of resources) {
|
|
29
|
-
await this.load(locale, resource);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
async loadUseFileName(res) {
|
|
34
|
-
if (res.isFile()) {
|
|
35
|
-
const messages = await res.getContentAsJSON();
|
|
36
|
-
const locale = res.name;
|
|
37
|
-
if (this.has(locale)) {
|
|
38
|
-
_.assign(this.get(locale), messages);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
this.set(locale, messages);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
if (res.isDir()) {
|
|
45
|
-
const resources = await res.getSubResources();
|
|
46
|
-
for (const resource of resources) {
|
|
47
|
-
await this.loadUseFileName(resource);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
getMessage(code, args, defaultMessage, locale) {
|
|
52
|
-
let messages;
|
|
53
|
-
if (locale) {
|
|
54
|
-
messages = this.get(locale);
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
messages = this.get(this.defaultLocale);
|
|
58
|
-
}
|
|
59
|
-
if (!messages) {
|
|
60
|
-
return null;
|
|
61
|
-
}
|
|
62
|
-
if (!messages[code]) {
|
|
63
|
-
return defaultMessage;
|
|
64
|
-
}
|
|
65
|
-
if (args && args.length > 0) {
|
|
66
|
-
args.unshift(messages[code]);
|
|
67
|
-
// eslint-disable-next-line prefer-spread
|
|
68
|
-
return util_1.format.apply(null, args);
|
|
69
|
-
}
|
|
70
|
-
return messages[code];
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
exports.MessageSource = MessageSource;
|
|
74
|
-
//# sourceMappingURL=messageSource.js.map
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { IResource } from '../interface';
|
|
3
|
-
export declare class Resource implements IResource {
|
|
4
|
-
private _baseDir;
|
|
5
|
-
private _path;
|
|
6
|
-
encoding: string;
|
|
7
|
-
constructor(baseDir: string, path?: string);
|
|
8
|
-
getPath(): string;
|
|
9
|
-
exists(): boolean;
|
|
10
|
-
isFile(): boolean;
|
|
11
|
-
isDir(): boolean;
|
|
12
|
-
isURL(): boolean;
|
|
13
|
-
getURL(): any;
|
|
14
|
-
/**
|
|
15
|
-
* 如果是文件则获取当前文件夹路径
|
|
16
|
-
* 如果是文件夹则直接作为路径
|
|
17
|
-
* @param path 相对路径
|
|
18
|
-
*/
|
|
19
|
-
createRelative(path: string): IResource;
|
|
20
|
-
getSubResources(): IResource[];
|
|
21
|
-
getContent(): Buffer;
|
|
22
|
-
getContentAsJSON(): Record<string, unknown>;
|
|
23
|
-
get name(): string;
|
|
24
|
-
get contentLength(): number;
|
|
25
|
-
get lastModified(): number;
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=resource.d.ts.map
|