@midwayjs/core 3.0.0-alpha.41 → 3.0.0-alpha.42
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.js +33 -4
- package/dist/common/reflectTool.d.ts +1 -3
- package/dist/context/applicationContext.d.ts +81 -0
- package/dist/context/applicationContext.js +263 -0
- package/dist/context/container.d.ts +23 -45
- package/dist/context/container.js +202 -199
- package/dist/context/managed.d.ts +45 -0
- package/dist/context/managed.js +69 -0
- package/dist/context/managedResolverFactory.d.ts +19 -15
- package/dist/context/managedResolverFactory.js +256 -27
- package/dist/context/providerWrapper.d.ts +3 -2
- package/dist/context/requestContainer.js +10 -7
- package/dist/context/resolverHandler.d.ts +2 -2
- package/dist/context/resolverHandler.js +1 -1
- package/dist/definitions/functionDefinition.d.ts +2 -0
- package/dist/definitions/functionDefinition.js +6 -0
- package/dist/definitions/objectDefinition.d.ts +4 -1
- package/dist/definitions/objectDefinition.js +8 -0
- package/dist/definitions/properties.d.ts +2 -0
- package/dist/definitions/properties.js +21 -5
- package/dist/features/pipeline.d.ts +3 -3
- package/dist/functional/configuration.d.ts +0 -2
- package/dist/functional/configuration.js +0 -10
- package/dist/index.d.ts +1 -1
- package/dist/index.js +23 -1
- package/dist/interface.d.ts +32 -21
- package/dist/util/containerUtil.js +1 -1
- package/dist/util/staticConfig.d.ts +10 -0
- package/dist/util/staticConfig.js +67 -0
- package/dist/util/webRouterCollector.d.ts +0 -8
- package/dist/util/webRouterCollector.js +119 -63
- package/package.json +4 -5
- package/dist/context/definitionRegistry.d.ts +0 -26
- package/dist/context/definitionRegistry.js +0 -124
|
@@ -5,7 +5,7 @@ const _ = require("../common/lodashWrap");
|
|
|
5
5
|
const util_1 = require("util");
|
|
6
6
|
class ObjectProperties {
|
|
7
7
|
constructor() {
|
|
8
|
-
this.innerConfig =
|
|
8
|
+
this.innerConfig = {};
|
|
9
9
|
}
|
|
10
10
|
get size() {
|
|
11
11
|
return this.keys().length;
|
|
@@ -28,7 +28,7 @@ class ObjectProperties {
|
|
|
28
28
|
return JSON.parse(JSON.stringify(_.get(this.innerConfig, key)));
|
|
29
29
|
}
|
|
30
30
|
has(key) {
|
|
31
|
-
return this.innerConfig
|
|
31
|
+
return this.innerConfig[key] !== undefined;
|
|
32
32
|
}
|
|
33
33
|
set(key, value) {
|
|
34
34
|
const origin = this.get(key);
|
|
@@ -38,14 +38,25 @@ class ObjectProperties {
|
|
|
38
38
|
putAll(props) {
|
|
39
39
|
const keys = props.keys();
|
|
40
40
|
for (const key of keys) {
|
|
41
|
-
if (typeof this.innerConfig
|
|
42
|
-
this.set(key, _.defaultsDeep(props.get(key), this.innerConfig
|
|
41
|
+
if (typeof this.innerConfig[key] === 'object') {
|
|
42
|
+
this.set(key, _.defaultsDeep(props.get(key), this.innerConfig[key]));
|
|
43
43
|
}
|
|
44
44
|
else {
|
|
45
45
|
this.set(key, props.get(key));
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
+
putObject(props, needClone = false) {
|
|
50
|
+
if (needClone) {
|
|
51
|
+
const tmp = _.cloneDeep(props);
|
|
52
|
+
_.defaultsDeep(tmp, this.innerConfig);
|
|
53
|
+
this.innerConfig = tmp;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
_.defaultsDeep(props, this.innerConfig);
|
|
57
|
+
this.innerConfig = props;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
49
60
|
stringPropertyNames() {
|
|
50
61
|
return this.keys();
|
|
51
62
|
}
|
|
@@ -62,11 +73,16 @@ class ObjectProperties {
|
|
|
62
73
|
return this.set(key, value);
|
|
63
74
|
}
|
|
64
75
|
clear() {
|
|
65
|
-
this.innerConfig
|
|
76
|
+
this.innerConfig = {};
|
|
66
77
|
}
|
|
67
78
|
toJSON() {
|
|
68
79
|
return JSON.parse(JSON.stringify(this.innerConfig));
|
|
69
80
|
}
|
|
81
|
+
clone() {
|
|
82
|
+
const cfg = new ObjectProperties();
|
|
83
|
+
cfg.putObject(this.toJSON());
|
|
84
|
+
return cfg;
|
|
85
|
+
}
|
|
70
86
|
}
|
|
71
87
|
exports.ObjectProperties = ObjectProperties;
|
|
72
88
|
//# sourceMappingURL=properties.js.map
|
|
@@ -127,7 +127,7 @@ export interface IPipelineHandler {
|
|
|
127
127
|
*/
|
|
128
128
|
waterfall<T>(opts: IPipelineOptions): Promise<IPipelineResult<T>>;
|
|
129
129
|
}
|
|
130
|
-
import {
|
|
130
|
+
import { IApplicationContext } from '../interface';
|
|
131
131
|
export declare class PipelineContext implements IPipelineContext {
|
|
132
132
|
args: any;
|
|
133
133
|
info: {
|
|
@@ -145,7 +145,7 @@ export declare class PipelineContext implements IPipelineContext {
|
|
|
145
145
|
export declare class PipelineHandler implements IPipelineHandler {
|
|
146
146
|
private applicationContext;
|
|
147
147
|
private valves;
|
|
148
|
-
constructor(applicationContext:
|
|
148
|
+
constructor(applicationContext: IApplicationContext, valves?: string[]);
|
|
149
149
|
parallel<T>(opts: IPipelineOptions): Promise<IPipelineResult<T>>;
|
|
150
150
|
concat<T>(opts: IPipelineOptions): Promise<IPipelineResult<T>>;
|
|
151
151
|
series<T>(opts: IPipelineOptions): Promise<IPipelineResult<T>>;
|
|
@@ -155,5 +155,5 @@ export declare class PipelineHandler implements IPipelineHandler {
|
|
|
155
155
|
private prepareParallelValves;
|
|
156
156
|
private packResult;
|
|
157
157
|
}
|
|
158
|
-
export declare function pipelineFactory(applicationContext:
|
|
158
|
+
export declare function pipelineFactory(applicationContext: IApplicationContext, valves?: string[]): PipelineHandler;
|
|
159
159
|
//# sourceMappingURL=pipeline.d.ts.map
|
|
@@ -3,10 +3,8 @@ import { InjectionConfigurationOptions } from '@midwayjs/decorator';
|
|
|
3
3
|
export declare class FunctionalConfiguration {
|
|
4
4
|
private readyHandler;
|
|
5
5
|
private stopHandler;
|
|
6
|
-
private configLoadHandler;
|
|
7
6
|
private options;
|
|
8
7
|
constructor(options: InjectionConfigurationOptions);
|
|
9
|
-
onConfigLoad(configLoadHandler: ((container: IMidwayContainer, app: IMidwayApplication) => any) | IMidwayContainer, app?: IMidwayApplication): this;
|
|
10
8
|
onReady(readyHandler: ((container: IMidwayContainer, app: IMidwayApplication) => void) | IMidwayContainer, app?: IMidwayApplication): this;
|
|
11
9
|
onStop(stopHandler: ((container: IMidwayContainer, app: IMidwayApplication) => void) | IMidwayContainer, app?: IMidwayApplication): this;
|
|
12
10
|
getConfigurationOptions(): InjectionConfigurationOptions;
|
|
@@ -6,16 +6,6 @@ class FunctionalConfiguration {
|
|
|
6
6
|
this.options = options;
|
|
7
7
|
this.readyHandler = () => { };
|
|
8
8
|
this.stopHandler = () => { };
|
|
9
|
-
this.configLoadHandler = () => { };
|
|
10
|
-
}
|
|
11
|
-
onConfigLoad(configLoadHandler, app) {
|
|
12
|
-
if (typeof configLoadHandler === 'function') {
|
|
13
|
-
this.configLoadHandler = configLoadHandler;
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
this.configLoadHandler(configLoadHandler, app);
|
|
17
|
-
}
|
|
18
|
-
return this;
|
|
19
9
|
}
|
|
20
10
|
onReady(readyHandler, app) {
|
|
21
11
|
if (typeof readyHandler === 'function') {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { MidwayFrameworkType } from '@midwayjs/decorator';
|
|
1
|
+
export { ObjectIdentifier, ObjectDefinitionOptions, IManagedInstance, ScopeEnum, MidwayFrameworkType, saveClassMetadata, attachClassMetadata, getClassMetadata, savePropertyDataToClass, attachPropertyDataToClass, getPropertyDataFromClass, listPropertyDataFromClass, savePropertyMetadata, attachPropertyMetadata, getPropertyMetadata, savePreloadModule, listPreloadModule, saveModule, listModule, resetModule, clearAllModule, getParamNames, getProviderId, getObjectDefinition, classNamed, generateProvideId, } from '@midwayjs/decorator';
|
|
2
2
|
export * from './interface';
|
|
3
3
|
export * from './context/container';
|
|
4
4
|
export { MidwayRequestContainer } from './context/requestContainer';
|
package/dist/index.js
CHANGED
|
@@ -10,9 +10,31 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.MidwayInformationService = exports.MidwayEnvironmentService = exports.MidwayConfigService = exports.createConfiguration = exports.classToPlain = exports.plainToClass = exports.delegateTargetPrototypeMethod = exports.safeRequire = exports.safelyGet = exports.BaseFramework = exports.MidwayRequestContainer = exports.MidwayFrameworkType = void 0;
|
|
13
|
+
exports.MidwayInformationService = exports.MidwayEnvironmentService = exports.MidwayConfigService = exports.createConfiguration = exports.classToPlain = exports.plainToClass = exports.delegateTargetPrototypeMethod = exports.safeRequire = exports.safelyGet = exports.BaseFramework = exports.MidwayRequestContainer = exports.generateProvideId = exports.classNamed = exports.getObjectDefinition = exports.getProviderId = exports.getParamNames = exports.clearAllModule = exports.resetModule = exports.listModule = exports.saveModule = exports.listPreloadModule = exports.savePreloadModule = exports.getPropertyMetadata = exports.attachPropertyMetadata = exports.savePropertyMetadata = exports.listPropertyDataFromClass = exports.getPropertyDataFromClass = exports.attachPropertyDataToClass = exports.savePropertyDataToClass = exports.getClassMetadata = exports.attachClassMetadata = exports.saveClassMetadata = exports.MidwayFrameworkType = exports.ScopeEnum = void 0;
|
|
14
14
|
var decorator_1 = require("@midwayjs/decorator");
|
|
15
|
+
Object.defineProperty(exports, "ScopeEnum", { enumerable: true, get: function () { return decorator_1.ScopeEnum; } });
|
|
15
16
|
Object.defineProperty(exports, "MidwayFrameworkType", { enumerable: true, get: function () { return decorator_1.MidwayFrameworkType; } });
|
|
17
|
+
Object.defineProperty(exports, "saveClassMetadata", { enumerable: true, get: function () { return decorator_1.saveClassMetadata; } });
|
|
18
|
+
Object.defineProperty(exports, "attachClassMetadata", { enumerable: true, get: function () { return decorator_1.attachClassMetadata; } });
|
|
19
|
+
Object.defineProperty(exports, "getClassMetadata", { enumerable: true, get: function () { return decorator_1.getClassMetadata; } });
|
|
20
|
+
Object.defineProperty(exports, "savePropertyDataToClass", { enumerable: true, get: function () { return decorator_1.savePropertyDataToClass; } });
|
|
21
|
+
Object.defineProperty(exports, "attachPropertyDataToClass", { enumerable: true, get: function () { return decorator_1.attachPropertyDataToClass; } });
|
|
22
|
+
Object.defineProperty(exports, "getPropertyDataFromClass", { enumerable: true, get: function () { return decorator_1.getPropertyDataFromClass; } });
|
|
23
|
+
Object.defineProperty(exports, "listPropertyDataFromClass", { enumerable: true, get: function () { return decorator_1.listPropertyDataFromClass; } });
|
|
24
|
+
Object.defineProperty(exports, "savePropertyMetadata", { enumerable: true, get: function () { return decorator_1.savePropertyMetadata; } });
|
|
25
|
+
Object.defineProperty(exports, "attachPropertyMetadata", { enumerable: true, get: function () { return decorator_1.attachPropertyMetadata; } });
|
|
26
|
+
Object.defineProperty(exports, "getPropertyMetadata", { enumerable: true, get: function () { return decorator_1.getPropertyMetadata; } });
|
|
27
|
+
Object.defineProperty(exports, "savePreloadModule", { enumerable: true, get: function () { return decorator_1.savePreloadModule; } });
|
|
28
|
+
Object.defineProperty(exports, "listPreloadModule", { enumerable: true, get: function () { return decorator_1.listPreloadModule; } });
|
|
29
|
+
Object.defineProperty(exports, "saveModule", { enumerable: true, get: function () { return decorator_1.saveModule; } });
|
|
30
|
+
Object.defineProperty(exports, "listModule", { enumerable: true, get: function () { return decorator_1.listModule; } });
|
|
31
|
+
Object.defineProperty(exports, "resetModule", { enumerable: true, get: function () { return decorator_1.resetModule; } });
|
|
32
|
+
Object.defineProperty(exports, "clearAllModule", { enumerable: true, get: function () { return decorator_1.clearAllModule; } });
|
|
33
|
+
Object.defineProperty(exports, "getParamNames", { enumerable: true, get: function () { return decorator_1.getParamNames; } });
|
|
34
|
+
Object.defineProperty(exports, "getProviderId", { enumerable: true, get: function () { return decorator_1.getProviderId; } });
|
|
35
|
+
Object.defineProperty(exports, "getObjectDefinition", { enumerable: true, get: function () { return decorator_1.getObjectDefinition; } });
|
|
36
|
+
Object.defineProperty(exports, "classNamed", { enumerable: true, get: function () { return decorator_1.classNamed; } });
|
|
37
|
+
Object.defineProperty(exports, "generateProvideId", { enumerable: true, get: function () { return decorator_1.generateProvideId; } });
|
|
16
38
|
__exportStar(require("./interface"), exports);
|
|
17
39
|
__exportStar(require("./context/container"), exports);
|
|
18
40
|
var requestContainer_1 = require("./context/requestContainer");
|
package/dist/interface.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { ILogger, LoggerOptions } from '@midwayjs/logger';
|
|
|
5
5
|
* 生命周期定义
|
|
6
6
|
*/
|
|
7
7
|
export interface ILifeCycle {
|
|
8
|
-
onConfigLoad?(container: IMidwayContainer, app?: IMidwayApplication): Promise<
|
|
8
|
+
onConfigLoad?(container: IMidwayContainer, app?: IMidwayApplication): Promise<void>;
|
|
9
9
|
onReady(container: IMidwayContainer, app?: IMidwayApplication): Promise<void>;
|
|
10
10
|
onStop?(container: IMidwayContainer, app?: IMidwayApplication): Promise<void>;
|
|
11
11
|
}
|
|
@@ -22,6 +22,7 @@ export interface IMessageSource {
|
|
|
22
22
|
*/
|
|
23
23
|
export interface IObjectFactory {
|
|
24
24
|
registry: IObjectDefinitionRegistry;
|
|
25
|
+
isAsync(identifier: ObjectIdentifier): boolean;
|
|
25
26
|
get<T>(identifier: new () => T, args?: any): T;
|
|
26
27
|
get<T>(identifier: ObjectIdentifier, args?: any): T;
|
|
27
28
|
getAsync<T>(identifier: new () => T, args?: any): Promise<T>;
|
|
@@ -44,6 +45,7 @@ export interface IObjectDefinition {
|
|
|
44
45
|
dependsOn: ObjectIdentifier[];
|
|
45
46
|
constructorArgs: IManagedInstance[];
|
|
46
47
|
properties: IProperties;
|
|
48
|
+
isAutowire(): boolean;
|
|
47
49
|
isAsync(): boolean;
|
|
48
50
|
isSingletonScope(): boolean;
|
|
49
51
|
isRequestScope(): boolean;
|
|
@@ -63,12 +65,13 @@ export interface HandlerProp {
|
|
|
63
65
|
*/
|
|
64
66
|
export interface IObjectDefinitionMetadata {
|
|
65
67
|
namespace?: string;
|
|
66
|
-
id:
|
|
68
|
+
id: string;
|
|
67
69
|
name: string;
|
|
68
70
|
initMethod: string;
|
|
69
71
|
destroyMethod: string;
|
|
70
72
|
constructMethod: string;
|
|
71
73
|
scope: ScopeEnum;
|
|
74
|
+
autowire: boolean;
|
|
72
75
|
srcPath: string;
|
|
73
76
|
path: any;
|
|
74
77
|
export: string;
|
|
@@ -85,14 +88,13 @@ export interface IObjectDefinitionMetadata {
|
|
|
85
88
|
}
|
|
86
89
|
export interface FrameworkDecoratorMetadata {
|
|
87
90
|
key: string;
|
|
88
|
-
targetKey: string;
|
|
89
91
|
propertyName: string;
|
|
90
92
|
meta: any;
|
|
91
93
|
}
|
|
92
94
|
export interface IObjectCreator {
|
|
93
95
|
load(): any;
|
|
94
|
-
doConstruct(Clzz: any, args?: any, context?:
|
|
95
|
-
doConstructAsync(Clzz: any, args?: any, context?:
|
|
96
|
+
doConstruct(Clzz: any, args?: any, context?: IApplicationContext): any;
|
|
97
|
+
doConstructAsync(Clzz: any, args?: any, context?: IApplicationContext): Promise<any>;
|
|
96
98
|
doInit(obj: any): void;
|
|
97
99
|
doInitAsync(obj: any): Promise<void>;
|
|
98
100
|
doDestroy(obj: any): void;
|
|
@@ -107,6 +109,7 @@ export interface IObjectDefinitionRegistry {
|
|
|
107
109
|
registerDefinition(identifier: ObjectIdentifier, definition: IObjectDefinition): any;
|
|
108
110
|
getSingletonDefinitionIds(): ObjectIdentifier[];
|
|
109
111
|
getDefinition(identifier: ObjectIdentifier): IObjectDefinition;
|
|
112
|
+
getDefinitionByPath(path: string): IObjectDefinition;
|
|
110
113
|
getDefinitionByName(name: string): IObjectDefinition[];
|
|
111
114
|
removeDefinition(identifier: ObjectIdentifier): void;
|
|
112
115
|
hasDefinition(identifier: ObjectIdentifier): boolean;
|
|
@@ -114,8 +117,6 @@ export interface IObjectDefinitionRegistry {
|
|
|
114
117
|
hasObject(identifier: ObjectIdentifier): boolean;
|
|
115
118
|
registerObject(identifier: ObjectIdentifier, target: any): any;
|
|
116
119
|
getObject(identifier: ObjectIdentifier): any;
|
|
117
|
-
getIdentifierRelation(): IIdentifierRelationShip;
|
|
118
|
-
setIdentifierRelation(identifierRelation: IIdentifierRelationShip): any;
|
|
119
120
|
}
|
|
120
121
|
/**
|
|
121
122
|
* 属性配置抽象
|
|
@@ -134,6 +135,7 @@ export interface IProperties {
|
|
|
134
135
|
addProperty(key: ObjectIdentifier, value: any): void;
|
|
135
136
|
setProperty(key: ObjectIdentifier, value: any): any;
|
|
136
137
|
clear(): void;
|
|
138
|
+
clone(): IProperties;
|
|
137
139
|
}
|
|
138
140
|
/**
|
|
139
141
|
* 资源配置抽象
|
|
@@ -154,6 +156,19 @@ export interface IResource {
|
|
|
154
156
|
getSubResources(): IResource[];
|
|
155
157
|
createRelative(path: string): IResource;
|
|
156
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* IoC上下文抽象
|
|
161
|
+
*/
|
|
162
|
+
export interface IApplicationContext extends IObjectFactory {
|
|
163
|
+
disableConflictCheck: boolean;
|
|
164
|
+
baseDir: string;
|
|
165
|
+
parent: IApplicationContext;
|
|
166
|
+
props: IProperties;
|
|
167
|
+
dependencyMap: Map<string, ObjectDependencyTree>;
|
|
168
|
+
ready(): any;
|
|
169
|
+
stop(): Promise<void>;
|
|
170
|
+
registerObject(identifier: ObjectIdentifier, target: any): any;
|
|
171
|
+
}
|
|
157
172
|
/**
|
|
158
173
|
* 解析内部管理的属性、json、ref等实例的解析器
|
|
159
174
|
* 同时创建这些对象的实际使用的对象
|
|
@@ -199,18 +214,7 @@ export interface IResolverHandler {
|
|
|
199
214
|
hasHandler(key: string): boolean;
|
|
200
215
|
getHandler(key: string): any;
|
|
201
216
|
}
|
|
202
|
-
export interface
|
|
203
|
-
saveClassRelation(module: any, namespace?: string): any;
|
|
204
|
-
saveFunctionRelation(ObjectIdentifier: any, uuid: any): any;
|
|
205
|
-
hasRelation(id: ObjectIdentifier): boolean;
|
|
206
|
-
getRelation(id: ObjectIdentifier): string;
|
|
207
|
-
}
|
|
208
|
-
export interface IMidwayContainer extends IObjectFactory {
|
|
209
|
-
parent: IMidwayContainer;
|
|
210
|
-
identifierMapping: IIdentifierRelationShip;
|
|
211
|
-
ready(): any;
|
|
212
|
-
stop(): Promise<void>;
|
|
213
|
-
registerObject(identifier: ObjectIdentifier, target: any): any;
|
|
217
|
+
export interface IMidwayContainer extends IApplicationContext {
|
|
214
218
|
load(module?: any): any;
|
|
215
219
|
bind<T>(target: T, options?: ObjectDefinitionOptions): void;
|
|
216
220
|
bind<T>(identifier: ObjectIdentifier, target: T, options?: ObjectDefinitionOptions): void;
|
|
@@ -219,6 +223,9 @@ export interface IMidwayContainer extends IObjectFactory {
|
|
|
219
223
|
setFileDetector(fileDetector: IFileDetector): any;
|
|
220
224
|
registerDataHandler(handlerType: string, handler: (...args: any[]) => any): any;
|
|
221
225
|
createChild(): IMidwayContainer;
|
|
226
|
+
/**
|
|
227
|
+
* 默认不添加创建的 configuration 到 configurations 数组中
|
|
228
|
+
*/
|
|
222
229
|
getConfigService(): IConfigService;
|
|
223
230
|
getEnvironmentService(): IEnvironmentService;
|
|
224
231
|
getInformationService(): IInformationService;
|
|
@@ -239,7 +246,7 @@ export interface IMidwayContainer extends IObjectFactory {
|
|
|
239
246
|
getAttr<T>(key: string): T;
|
|
240
247
|
}
|
|
241
248
|
export interface IFileDetector {
|
|
242
|
-
run(container:
|
|
249
|
+
run(container: IApplicationContext): any;
|
|
243
250
|
}
|
|
244
251
|
export interface IConfigService {
|
|
245
252
|
add(configFilePaths: any[]): any;
|
|
@@ -317,6 +324,11 @@ export interface IMidwayBaseApplication<T extends IMidwayContext = IMidwayContex
|
|
|
317
324
|
getAttr<T>(key: string): T;
|
|
318
325
|
}
|
|
319
326
|
export declare type IMidwayApplication<T extends IMidwayContext = IMidwayContext, FrameworkApplication = unknown> = IMidwayBaseApplication<T> & FrameworkApplication;
|
|
327
|
+
/**
|
|
328
|
+
* @deprecated
|
|
329
|
+
*/
|
|
330
|
+
export interface IMidwayCoreApplication extends IMidwayApplication {
|
|
331
|
+
}
|
|
320
332
|
export interface IMidwayBootstrapOptions {
|
|
321
333
|
logger?: ILogger | boolean;
|
|
322
334
|
baseDir?: string;
|
|
@@ -330,7 +342,6 @@ export interface IMidwayBootstrapOptions {
|
|
|
330
342
|
loadDir?: string[];
|
|
331
343
|
disableConflictCheck?: boolean;
|
|
332
344
|
applicationContext?: IMidwayContainer;
|
|
333
|
-
configurationModule?: any;
|
|
334
345
|
isMainFramework?: boolean;
|
|
335
346
|
globalApplicationHandler?: (type: MidwayFrameworkType) => IMidwayApplication;
|
|
336
347
|
globalConfig?: any;
|
|
@@ -15,7 +15,7 @@ const createModuleContainer = (options) => {
|
|
|
15
15
|
};
|
|
16
16
|
exports.createModuleContainer = createModuleContainer;
|
|
17
17
|
const createDirectoryGlobContainer = options => {
|
|
18
|
-
const applicationContext = new container_1.MidwayContainer();
|
|
18
|
+
const applicationContext = new container_1.MidwayContainer(options.baseDir, undefined);
|
|
19
19
|
applicationContext.setFileDetector(new fileDetector_1.DirectoryFileDetector({
|
|
20
20
|
loadDir: options.baseDir,
|
|
21
21
|
}));
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { IConfigService } from '..';
|
|
2
|
+
export declare class StaticConfigLoader {
|
|
3
|
+
baseDir: string;
|
|
4
|
+
configService: IConfigService;
|
|
5
|
+
constructor(baseDir: string, currentEnvironment: string);
|
|
6
|
+
getSerializeConfig(): Promise<string>;
|
|
7
|
+
analyzeConfiguration(configurationModule: any): void;
|
|
8
|
+
private getConfigurationExport;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=staticConfig.d.ts.map
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StaticConfigLoader = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const decorator_1 = require("@midwayjs/decorator");
|
|
6
|
+
const __1 = require("..");
|
|
7
|
+
const configService_1 = require("../service/configService");
|
|
8
|
+
class StaticConfigLoader {
|
|
9
|
+
constructor(baseDir, currentEnvironment) {
|
|
10
|
+
this.baseDir = baseDir;
|
|
11
|
+
this.configService = new configService_1.MidwayConfigService({
|
|
12
|
+
getCurrentEnv() {
|
|
13
|
+
return currentEnvironment;
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
async getSerializeConfig() {
|
|
18
|
+
const mainModule = (0, __1.safeRequire)(this.baseDir);
|
|
19
|
+
let mainConfiguration;
|
|
20
|
+
if (mainModule && mainModule['Configuration']) {
|
|
21
|
+
mainConfiguration = mainModule['Configuration'];
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
mainConfiguration = (0, __1.safeRequire)((0, path_1.join)(this.baseDir, 'src', 'configuration.ts'));
|
|
25
|
+
}
|
|
26
|
+
const modules = this.getConfigurationExport(mainConfiguration);
|
|
27
|
+
for (const module of modules) {
|
|
28
|
+
this.analyzeConfiguration(module);
|
|
29
|
+
}
|
|
30
|
+
this.configService.load();
|
|
31
|
+
return this.configService.getConfiguration();
|
|
32
|
+
}
|
|
33
|
+
analyzeConfiguration(configurationModule) {
|
|
34
|
+
if (!configurationModule)
|
|
35
|
+
return;
|
|
36
|
+
const configurationOptions = (0, decorator_1.getClassMetadata)(decorator_1.CONFIGURATION_KEY, configurationModule);
|
|
37
|
+
if (!configurationOptions)
|
|
38
|
+
return;
|
|
39
|
+
if (configurationOptions.imports) {
|
|
40
|
+
for (const importModule of configurationOptions.imports) {
|
|
41
|
+
if (typeof importModule !== 'string') {
|
|
42
|
+
this.analyzeConfiguration(importModule['Configuration']);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (configurationOptions === null || configurationOptions === void 0 ? void 0 : configurationOptions.importConfigs) {
|
|
47
|
+
this.configService.add(configurationOptions.importConfigs);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
getConfigurationExport(exports) {
|
|
51
|
+
const mods = [];
|
|
52
|
+
if ((0, decorator_1.isClass)(exports) || (0, decorator_1.isFunction)(exports)) {
|
|
53
|
+
mods.push(exports);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
for (const m in exports) {
|
|
57
|
+
const module = exports[m];
|
|
58
|
+
if ((0, decorator_1.isClass)(module) || (0, decorator_1.isFunction)(module)) {
|
|
59
|
+
mods.push(module);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return mods;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.StaticConfigLoader = StaticConfigLoader;
|
|
67
|
+
//# sourceMappingURL=staticConfig.js.map
|
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
export interface RouterInfo {
|
|
2
|
-
/**
|
|
3
|
-
* uuid
|
|
4
|
-
*/
|
|
5
|
-
id: string;
|
|
6
2
|
/**
|
|
7
3
|
* router prefix
|
|
8
4
|
*/
|
|
@@ -96,10 +92,6 @@ export declare class WebRouterCollector {
|
|
|
96
92
|
_paramString: string;
|
|
97
93
|
_category: number;
|
|
98
94
|
_weight: number;
|
|
99
|
-
/**
|
|
100
|
-
* uuid
|
|
101
|
-
*/
|
|
102
|
-
id: string;
|
|
103
95
|
/**
|
|
104
96
|
* router prefix
|
|
105
97
|
*/
|
|
@@ -42,10 +42,10 @@ class WebRouterCollector {
|
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
44
|
collectRoute(module, functionMeta = false) {
|
|
45
|
-
const controllerId = (0, decorator_1.
|
|
46
|
-
const id = (0, decorator_1.getProviderUUId)(module);
|
|
45
|
+
const controllerId = (0, decorator_1.getProviderId)(module);
|
|
47
46
|
const controllerOption = (0, decorator_1.getClassMetadata)(decorator_1.CONTROLLER_KEY, module);
|
|
48
|
-
|
|
47
|
+
// sort for priority
|
|
48
|
+
let priority = (0, decorator_1.getClassMetadata)(decorator_1.PRIORITY_KEY, module);
|
|
49
49
|
// implement middleware in controller
|
|
50
50
|
const middleware = controllerOption.routerOptions.middleware;
|
|
51
51
|
const prefix = controllerOption.prefix || '/';
|
|
@@ -68,7 +68,6 @@ class WebRouterCollector {
|
|
|
68
68
|
const routeArgsInfo = (0, decorator_1.getPropertyDataFromClass)(decorator_1.WEB_ROUTER_PARAM_KEY, module, webRouter.method) || [];
|
|
69
69
|
const routerResponseData = (0, decorator_1.getPropertyMetadata)(decorator_1.WEB_RESPONSE_KEY, module, webRouter.method) || [];
|
|
70
70
|
const data = {
|
|
71
|
-
id,
|
|
72
71
|
prefix,
|
|
73
72
|
routerName: webRouter.routerName || '',
|
|
74
73
|
url: webRouter.path,
|
|
@@ -101,11 +100,10 @@ class WebRouterCollector {
|
|
|
101
100
|
}
|
|
102
101
|
}
|
|
103
102
|
collectFunctionRoute(module, functionMeta = false) {
|
|
104
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
105
|
-
//
|
|
103
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
104
|
+
// 老的函数路由
|
|
106
105
|
const webRouterInfo = (0, decorator_1.getClassMetadata)(decorator_1.FUNC_KEY, module);
|
|
107
|
-
const controllerId = (0, decorator_1.
|
|
108
|
-
const id = (0, decorator_1.getProviderUUId)(module);
|
|
106
|
+
const controllerId = (0, decorator_1.getProviderId)(module);
|
|
109
107
|
const prefix = '/';
|
|
110
108
|
if (!this.routes.has(prefix)) {
|
|
111
109
|
this.routes.set(prefix, []);
|
|
@@ -118,70 +116,131 @@ class WebRouterCollector {
|
|
|
118
116
|
});
|
|
119
117
|
}
|
|
120
118
|
for (const webRouter of webRouterInfo) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
};
|
|
143
|
-
if (functionMeta) {
|
|
144
|
-
const functionMeta = (0, decorator_1.getPropertyMetadata)(decorator_1.SERVERLESS_FUNC_KEY, module, webRouter['methodName']) || {};
|
|
145
|
-
const functionName = (_f = (_e = functionMeta['functionName']) !== null && _e !== void 0 ? _e : webRouter['functionName']) !== null && _f !== void 0 ? _f : createFunctionName(module, webRouter['methodName']);
|
|
146
|
-
data.functionName = functionName;
|
|
147
|
-
data.functionTriggerName = webRouter['type'];
|
|
148
|
-
data.functionTriggerMetadata = webRouter['metadata'];
|
|
149
|
-
data.functionMetadata = {
|
|
150
|
-
functionName,
|
|
151
|
-
...functionMeta,
|
|
119
|
+
if (webRouter['type']) {
|
|
120
|
+
// 新的 @ServerlessTrigger 写法
|
|
121
|
+
if ((_a = webRouter['metadata']) === null || _a === void 0 ? void 0 : _a['path']) {
|
|
122
|
+
const routeArgsInfo = (0, decorator_1.getPropertyDataFromClass)(decorator_1.WEB_ROUTER_PARAM_KEY, module, webRouter['methodName']) || [];
|
|
123
|
+
const routerResponseData = (0, decorator_1.getPropertyMetadata)(decorator_1.WEB_RESPONSE_KEY, module, webRouter['methodName']) || [];
|
|
124
|
+
// 新 http/api gateway 函数
|
|
125
|
+
const data = {
|
|
126
|
+
prefix,
|
|
127
|
+
routerName: '',
|
|
128
|
+
url: webRouter['metadata']['path'],
|
|
129
|
+
requestMethod: (_c = (_b = webRouter['metadata']) === null || _b === void 0 ? void 0 : _b['method']) !== null && _c !== void 0 ? _c : 'get',
|
|
130
|
+
method: webRouter['methodName'],
|
|
131
|
+
description: '',
|
|
132
|
+
summary: '',
|
|
133
|
+
handlerName: `${controllerId}.${webRouter['methodName']}`,
|
|
134
|
+
funcHandlerName: `${controllerId}.${webRouter['methodName']}`,
|
|
135
|
+
controllerId,
|
|
136
|
+
middleware: ((_d = webRouter['metadata']) === null || _d === void 0 ? void 0 : _d['middleware']) || [],
|
|
137
|
+
controllerMiddleware: [],
|
|
138
|
+
requestMetadata: routeArgsInfo,
|
|
139
|
+
responseMetadata: routerResponseData,
|
|
152
140
|
};
|
|
141
|
+
if (functionMeta) {
|
|
142
|
+
data.functionName = webRouter['functionName'];
|
|
143
|
+
data.functionTriggerName = webRouter['type'];
|
|
144
|
+
data.functionTriggerMetadata = webRouter['metadata'];
|
|
145
|
+
const functionMeta = (0, decorator_1.getPropertyMetadata)(decorator_1.SERVERLESS_FUNC_KEY, module, webRouter['methodName']) || {};
|
|
146
|
+
data.functionMetadata = {
|
|
147
|
+
functionName: webRouter['functionName'],
|
|
148
|
+
...functionMeta,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
this.checkDuplicateAndPush(prefix, data);
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
if (functionMeta) {
|
|
155
|
+
const functionMeta = (0, decorator_1.getPropertyMetadata)(decorator_1.SERVERLESS_FUNC_KEY, module, webRouter['methodName']) || {};
|
|
156
|
+
// 其他类型的函数
|
|
157
|
+
this.checkDuplicateAndPush(prefix, {
|
|
158
|
+
prefix,
|
|
159
|
+
routerName: '',
|
|
160
|
+
url: '',
|
|
161
|
+
requestMethod: '',
|
|
162
|
+
method: webRouter['methodName'],
|
|
163
|
+
description: '',
|
|
164
|
+
summary: '',
|
|
165
|
+
handlerName: `${controllerId}.${webRouter['methodName']}`,
|
|
166
|
+
funcHandlerName: `${controllerId}.${webRouter['methodName']}`,
|
|
167
|
+
controllerId,
|
|
168
|
+
middleware: [],
|
|
169
|
+
controllerMiddleware: [],
|
|
170
|
+
requestMetadata: [],
|
|
171
|
+
responseMetadata: [],
|
|
172
|
+
functionName: webRouter['functionName'],
|
|
173
|
+
functionTriggerName: webRouter['type'],
|
|
174
|
+
functionTriggerMetadata: webRouter['metadata'],
|
|
175
|
+
functionMetadata: {
|
|
176
|
+
functionName: webRouter['functionName'],
|
|
177
|
+
...functionMeta,
|
|
178
|
+
},
|
|
179
|
+
});
|
|
180
|
+
}
|
|
153
181
|
}
|
|
154
|
-
this.checkDuplicateAndPush(prefix, data);
|
|
155
182
|
}
|
|
156
183
|
else {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
const
|
|
160
|
-
// 其他类型的函数
|
|
161
|
-
this.checkDuplicateAndPush(prefix, {
|
|
162
|
-
id,
|
|
184
|
+
// 老的 @Func 写法
|
|
185
|
+
if (webRouter['path'] || webRouter['middleware']) {
|
|
186
|
+
const data = {
|
|
163
187
|
prefix,
|
|
164
188
|
routerName: '',
|
|
165
|
-
url: '',
|
|
166
|
-
requestMethod: '',
|
|
167
|
-
method: webRouter['
|
|
189
|
+
url: (_e = webRouter['path']) !== null && _e !== void 0 ? _e : '',
|
|
190
|
+
requestMethod: (_f = webRouter['method']) !== null && _f !== void 0 ? _f : 'get',
|
|
191
|
+
method: (_g = webRouter['key']) !== null && _g !== void 0 ? _g : '',
|
|
168
192
|
description: '',
|
|
169
193
|
summary: '',
|
|
170
|
-
handlerName: `${controllerId}.${webRouter['
|
|
171
|
-
funcHandlerName: `${controllerId}.${webRouter['
|
|
194
|
+
handlerName: `${controllerId}.${webRouter['key']}`,
|
|
195
|
+
funcHandlerName: webRouter['funHandler'] || `${controllerId}.${webRouter['key']}`,
|
|
172
196
|
controllerId,
|
|
173
|
-
middleware: [],
|
|
197
|
+
middleware: webRouter['middleware'] || [],
|
|
174
198
|
controllerMiddleware: [],
|
|
175
199
|
requestMetadata: [],
|
|
176
200
|
responseMetadata: [],
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
201
|
+
};
|
|
202
|
+
if (functionMeta) {
|
|
203
|
+
// get function information
|
|
204
|
+
data.functionName = controllerId + '-' + ((_h = webRouter['key']) !== null && _h !== void 0 ? _h : '');
|
|
205
|
+
data.functionTriggerName = decorator_1.ServerlessTriggerType.HTTP;
|
|
206
|
+
data.functionTriggerMetadata = {
|
|
207
|
+
path: (_j = webRouter['path']) !== null && _j !== void 0 ? _j : '/',
|
|
208
|
+
method: (_k = webRouter['method']) !== null && _k !== void 0 ? _k : 'get',
|
|
209
|
+
};
|
|
210
|
+
data.functionMetadata = {
|
|
211
|
+
functionName: data.functionName,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
// 老函数的 http
|
|
215
|
+
this.checkDuplicateAndPush(prefix, data);
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
if (functionMeta) {
|
|
219
|
+
// 非 http
|
|
220
|
+
this.checkDuplicateAndPush(prefix, {
|
|
221
|
+
prefix,
|
|
222
|
+
routerName: '',
|
|
223
|
+
url: '',
|
|
224
|
+
requestMethod: '',
|
|
225
|
+
method: webRouter['key'],
|
|
226
|
+
description: '',
|
|
227
|
+
summary: '',
|
|
228
|
+
handlerName: `${controllerId}.${webRouter['key']}`,
|
|
229
|
+
funcHandlerName: webRouter['funHandler'] ||
|
|
230
|
+
`${controllerId}.${webRouter['key']}`,
|
|
231
|
+
controllerId,
|
|
232
|
+
middleware: webRouter['middleware'] || [],
|
|
233
|
+
controllerMiddleware: [],
|
|
234
|
+
requestMetadata: [],
|
|
235
|
+
responseMetadata: [],
|
|
236
|
+
functionName: webRouter['functionName'],
|
|
237
|
+
functionTriggerName: webRouter['type'],
|
|
238
|
+
functionTriggerMetadata: webRouter['metadata'],
|
|
239
|
+
functionMetadata: {
|
|
240
|
+
functionName: webRouter['functionName'],
|
|
241
|
+
},
|
|
242
|
+
});
|
|
243
|
+
}
|
|
185
244
|
}
|
|
186
245
|
}
|
|
187
246
|
}
|
|
@@ -286,7 +345,4 @@ class WebRouterCollector {
|
|
|
286
345
|
}
|
|
287
346
|
}
|
|
288
347
|
exports.WebRouterCollector = WebRouterCollector;
|
|
289
|
-
function createFunctionName(target, functionName) {
|
|
290
|
-
return (0, decorator_1.getProviderName)(target).replace(/[:#]/g, '-') + '-' + functionName;
|
|
291
|
-
}
|
|
292
348
|
//# sourceMappingURL=webRouterCollector.js.map
|