@midwayjs/core 3.0.0-alpha.6 → 3.0.0-beta.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +137 -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 +114 -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 +88 -317
- 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 +6 -6
- 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 +13 -0
- package/dist/error/base.js +19 -0
- package/dist/error/code.d.ts +60 -0
- package/dist/error/code.js +65 -0
- package/dist/error/framework.d.ts +24 -0
- package/dist/error/framework.js +58 -0
- package/dist/error/http.d.ts +58 -0
- package/dist/error/http.js +82 -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 +11 -0
- package/dist/service/middlewareService.js +127 -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 +19 -20
- 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 -9
- 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
package/dist/interface.d.ts
CHANGED
|
@@ -1,31 +1,75 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { ObjectIdentifier, IManagedInstance,
|
|
2
|
+
import { ObjectIdentifier, IManagedInstance, IMethodAspect, ScopeEnum, FrameworkType } from '@midwayjs/decorator';
|
|
3
3
|
import { ILogger, LoggerOptions } from '@midwayjs/logger';
|
|
4
|
+
import * as EventEmitter from 'events';
|
|
5
|
+
import { ContextMiddlewareManager } from './common/middlewareManager';
|
|
6
|
+
import _default from './config/config.default';
|
|
7
|
+
export declare type PowerPartial<T> = {
|
|
8
|
+
[U in keyof T]?: T[U] extends {} ? PowerPartial<T[U]> : T[U];
|
|
9
|
+
};
|
|
10
|
+
export declare type ServiceFactoryConfigOption<OPTIONS> = {
|
|
11
|
+
default?: PowerPartial<OPTIONS>;
|
|
12
|
+
client?: PowerPartial<OPTIONS>;
|
|
13
|
+
clients?: {
|
|
14
|
+
[key: string]: PowerPartial<OPTIONS>;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
declare type ConfigType<T> = T extends (...args: any[]) => any ? PowerPartial<ReturnType<T>> : PowerPartial<T>;
|
|
18
|
+
export declare type FileConfigOption<T, K = unknown> = K extends keyof ConfigType<T> ? Pick<ConfigType<T>, K> : ConfigType<T>;
|
|
4
19
|
/**
|
|
5
20
|
* 生命周期定义
|
|
6
21
|
*/
|
|
7
|
-
export interface ILifeCycle {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
get(code: string, args?: any[], defaultMessage?: string, locale?: Locale): string;
|
|
17
|
-
}
|
|
22
|
+
export interface ILifeCycle extends Partial<IObjectLifeCycle> {
|
|
23
|
+
onConfigLoad?(container: IMidwayContainer, mainApp?: IMidwayApplication): Promise<any>;
|
|
24
|
+
onReady?(container: IMidwayContainer, mainApp?: IMidwayApplication): Promise<void>;
|
|
25
|
+
onServerReady?(container: IMidwayContainer, mainApp?: IMidwayApplication): Promise<void>;
|
|
26
|
+
onStop?(container: IMidwayContainer, mainApp?: IMidwayApplication): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
export declare type ObjectContext = {
|
|
29
|
+
originName?: string;
|
|
30
|
+
};
|
|
18
31
|
/**
|
|
19
32
|
* 对象容器抽象
|
|
20
33
|
* 默认用Xml容器实现一个
|
|
21
34
|
*/
|
|
22
35
|
export interface IObjectFactory {
|
|
23
36
|
registry: IObjectDefinitionRegistry;
|
|
24
|
-
|
|
25
|
-
get<T>(identifier:
|
|
26
|
-
|
|
27
|
-
getAsync<T>(identifier:
|
|
28
|
-
|
|
37
|
+
get<T>(identifier: new (...args: any[]) => T, args?: any[], objectContext?: ObjectContext): T;
|
|
38
|
+
get<T>(identifier: ObjectIdentifier, args?: any[], objectContext?: ObjectContext): T;
|
|
39
|
+
getAsync<T>(identifier: new (...args: any[]) => T, args?: any[], objectContext?: ObjectContext): Promise<T>;
|
|
40
|
+
getAsync<T>(identifier: ObjectIdentifier, args?: any[], objectContext?: ObjectContext): Promise<T>;
|
|
41
|
+
}
|
|
42
|
+
export declare enum ObjectLifeCycleEvent {
|
|
43
|
+
BEFORE_BIND = "beforeBind",
|
|
44
|
+
BEFORE_CREATED = "beforeObjectCreated",
|
|
45
|
+
AFTER_CREATED = "afterObjectCreated",
|
|
46
|
+
AFTER_INIT = "afterObjectInit",
|
|
47
|
+
BEFORE_DESTROY = "beforeObjectDestroy"
|
|
48
|
+
}
|
|
49
|
+
export interface IObjectLifeCycle {
|
|
50
|
+
onBeforeBind(fn: (Clzz: any, options: {
|
|
51
|
+
context: IMidwayContainer;
|
|
52
|
+
definition: IObjectDefinition;
|
|
53
|
+
replaceCallback: (newDefinition: IObjectDefinition) => void;
|
|
54
|
+
}) => void): any;
|
|
55
|
+
onBeforeObjectCreated(fn: (Clzz: any, options: {
|
|
56
|
+
context: IMidwayContainer;
|
|
57
|
+
definition: IObjectDefinition;
|
|
58
|
+
constructorArgs: any[];
|
|
59
|
+
}) => void): any;
|
|
60
|
+
onObjectCreated<T>(fn: (ins: T, options: {
|
|
61
|
+
context: IMidwayContainer;
|
|
62
|
+
definition: IObjectDefinition;
|
|
63
|
+
replaceCallback: (ins: T) => void;
|
|
64
|
+
}) => void): any;
|
|
65
|
+
onObjectInit<T>(fn: (ins: T, options: {
|
|
66
|
+
context: IMidwayContainer;
|
|
67
|
+
definition: IObjectDefinition;
|
|
68
|
+
}) => void): any;
|
|
69
|
+
onBeforeObjectDestroy<T>(fn: (ins: T, options: {
|
|
70
|
+
context: IMidwayContainer;
|
|
71
|
+
definition: IObjectDefinition;
|
|
72
|
+
}) => void): any;
|
|
29
73
|
}
|
|
30
74
|
/**
|
|
31
75
|
* 对象描述定义
|
|
@@ -44,7 +88,7 @@ export interface IObjectDefinition {
|
|
|
44
88
|
dependsOn: ObjectIdentifier[];
|
|
45
89
|
constructorArgs: IManagedInstance[];
|
|
46
90
|
properties: IProperties;
|
|
47
|
-
|
|
91
|
+
scope: ScopeEnum;
|
|
48
92
|
isAsync(): boolean;
|
|
49
93
|
isSingletonScope(): boolean;
|
|
50
94
|
isRequestScope(): boolean;
|
|
@@ -53,47 +97,26 @@ export interface IObjectDefinition {
|
|
|
53
97
|
getAttr(key: ObjectIdentifier): any;
|
|
54
98
|
hasAttr(key: ObjectIdentifier): boolean;
|
|
55
99
|
setAttr(key: ObjectIdentifier, value: any): void;
|
|
56
|
-
handlerProps:
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
constructMethod: string;
|
|
72
|
-
scope: ScopeEnum;
|
|
73
|
-
autowire: boolean;
|
|
74
|
-
srcPath: string;
|
|
75
|
-
path: any;
|
|
76
|
-
export: string;
|
|
77
|
-
dependsOn: ObjectIdentifier[];
|
|
78
|
-
constructorArgs: Array<{
|
|
79
|
-
value?: string;
|
|
80
|
-
args?: any;
|
|
81
|
-
type: string;
|
|
82
|
-
} | undefined>;
|
|
83
|
-
asynchronous: boolean;
|
|
84
|
-
properties: any[];
|
|
85
|
-
definitionType: 'object' | 'function';
|
|
86
|
-
handlerProps: HandlerProp[];
|
|
87
|
-
}
|
|
88
|
-
export interface FrameworkDecoratorMetadata {
|
|
89
|
-
key: string;
|
|
90
|
-
propertyName: string;
|
|
91
|
-
meta: any;
|
|
100
|
+
handlerProps: Array<{
|
|
101
|
+
/**
|
|
102
|
+
* decorator property name set
|
|
103
|
+
*/
|
|
104
|
+
propertyName: string;
|
|
105
|
+
/**
|
|
106
|
+
* decorator uuid key
|
|
107
|
+
*/
|
|
108
|
+
key: string;
|
|
109
|
+
/**
|
|
110
|
+
* custom decorator set metadata
|
|
111
|
+
*/
|
|
112
|
+
metadata: any;
|
|
113
|
+
}>;
|
|
114
|
+
createFrom: 'framework' | 'file' | 'module';
|
|
92
115
|
}
|
|
93
116
|
export interface IObjectCreator {
|
|
94
117
|
load(): any;
|
|
95
|
-
doConstruct(Clzz: any, args?: any, context?:
|
|
96
|
-
doConstructAsync(Clzz: any, args?: any, context?:
|
|
118
|
+
doConstruct(Clzz: any, args?: any, context?: IMidwayContainer): any;
|
|
119
|
+
doConstructAsync(Clzz: any, args?: any, context?: IMidwayContainer): Promise<any>;
|
|
97
120
|
doInit(obj: any): void;
|
|
98
121
|
doInitAsync(obj: any): Promise<void>;
|
|
99
122
|
doDestroy(obj: any): void;
|
|
@@ -108,7 +131,6 @@ export interface IObjectDefinitionRegistry {
|
|
|
108
131
|
registerDefinition(identifier: ObjectIdentifier, definition: IObjectDefinition): any;
|
|
109
132
|
getSingletonDefinitionIds(): ObjectIdentifier[];
|
|
110
133
|
getDefinition(identifier: ObjectIdentifier): IObjectDefinition;
|
|
111
|
-
getDefinitionByPath(path: string): IObjectDefinition;
|
|
112
134
|
getDefinitionByName(name: string): IObjectDefinition[];
|
|
113
135
|
removeDefinition(identifier: ObjectIdentifier): void;
|
|
114
136
|
hasDefinition(identifier: ObjectIdentifier): boolean;
|
|
@@ -116,57 +138,16 @@ export interface IObjectDefinitionRegistry {
|
|
|
116
138
|
hasObject(identifier: ObjectIdentifier): boolean;
|
|
117
139
|
registerObject(identifier: ObjectIdentifier, target: any): any;
|
|
118
140
|
getObject(identifier: ObjectIdentifier): any;
|
|
141
|
+
getIdentifierRelation(): IIdentifierRelationShip;
|
|
142
|
+
setIdentifierRelation(identifierRelation: IIdentifierRelationShip): any;
|
|
119
143
|
}
|
|
120
144
|
/**
|
|
121
145
|
* 属性配置抽象
|
|
122
146
|
*/
|
|
123
|
-
export interface IProperties {
|
|
124
|
-
readonly size: number;
|
|
125
|
-
keys(): ObjectIdentifier[];
|
|
126
|
-
get(key: ObjectIdentifier, ...args: any[]): any;
|
|
127
|
-
dup(key: ObjectIdentifier): any;
|
|
128
|
-
has(key: ObjectIdentifier): boolean;
|
|
129
|
-
set(key: ObjectIdentifier, value: any): any;
|
|
130
|
-
putAll(props: IProperties): void;
|
|
131
|
-
toJSON(): object;
|
|
132
|
-
stringPropertyNames(): ObjectIdentifier[];
|
|
147
|
+
export interface IProperties extends Map<ObjectIdentifier, any> {
|
|
133
148
|
getProperty(key: ObjectIdentifier, defaultValue?: any): any;
|
|
134
|
-
addProperty(key: ObjectIdentifier, value: any): void;
|
|
135
149
|
setProperty(key: ObjectIdentifier, value: any): any;
|
|
136
|
-
|
|
137
|
-
clone(): IProperties;
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* 资源配置抽象
|
|
141
|
-
*/
|
|
142
|
-
export interface IResource {
|
|
143
|
-
readonly name: string;
|
|
144
|
-
readonly contentLength: number;
|
|
145
|
-
readonly lastModified: number;
|
|
146
|
-
encoding: string;
|
|
147
|
-
exists(): boolean;
|
|
148
|
-
isDir(): boolean;
|
|
149
|
-
isFile(): boolean;
|
|
150
|
-
isURL(): boolean;
|
|
151
|
-
getURL(): any;
|
|
152
|
-
getPath(): string;
|
|
153
|
-
getContent(): Buffer;
|
|
154
|
-
getContentAsJSON(): object;
|
|
155
|
-
getSubResources(): IResource[];
|
|
156
|
-
createRelative(path: string): IResource;
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* IoC上下文抽象
|
|
160
|
-
*/
|
|
161
|
-
export interface IApplicationContext extends IObjectFactory {
|
|
162
|
-
disableConflictCheck: boolean;
|
|
163
|
-
baseDir: string;
|
|
164
|
-
parent: IApplicationContext;
|
|
165
|
-
props: IProperties;
|
|
166
|
-
dependencyMap: Map<string, ObjectDependencyTree>;
|
|
167
|
-
ready(): any;
|
|
168
|
-
stop(): Promise<void>;
|
|
169
|
-
registerObject(identifier: ObjectIdentifier, target: any): any;
|
|
150
|
+
propertyKeys(): ObjectIdentifier[];
|
|
170
151
|
}
|
|
171
152
|
/**
|
|
172
153
|
* 解析内部管理的属性、json、ref等实例的解析器
|
|
@@ -182,56 +163,53 @@ export interface IManagedResolverFactoryCreateOptions {
|
|
|
182
163
|
args?: any;
|
|
183
164
|
namespace?: string;
|
|
184
165
|
}
|
|
185
|
-
export interface ObjectDependencyTree {
|
|
186
|
-
scope: ScopeEnum;
|
|
187
|
-
name: string;
|
|
188
|
-
constructorArgs: string[];
|
|
189
|
-
properties: string[];
|
|
190
|
-
}
|
|
191
166
|
export declare const REQUEST_CTX_KEY = "ctx";
|
|
192
167
|
export declare const REQUEST_OBJ_CTX_KEY = "_req_ctx";
|
|
193
168
|
export declare const HTTP_SERVER_KEY = "_midway_http_server";
|
|
194
|
-
export
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
208
|
-
export declare type
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
}
|
|
216
|
-
export interface
|
|
169
|
+
export declare type HandlerFunction = (
|
|
170
|
+
/**
|
|
171
|
+
* decorator uuid key
|
|
172
|
+
*/
|
|
173
|
+
key: string,
|
|
174
|
+
/**
|
|
175
|
+
* decorator set metadata
|
|
176
|
+
*/
|
|
177
|
+
meta: any, instance: any) => any;
|
|
178
|
+
export declare type MethodHandlerFunction = (options: {
|
|
179
|
+
target: new (...args: any[]) => any;
|
|
180
|
+
propertyName: string;
|
|
181
|
+
metadata: any;
|
|
182
|
+
}) => IMethodAspect;
|
|
183
|
+
export declare type ParameterHandlerFunction = (options: {
|
|
184
|
+
target: new (...args: any[]) => any;
|
|
185
|
+
propertyName: string;
|
|
186
|
+
metadata: any;
|
|
187
|
+
originArgs: Array<any>;
|
|
188
|
+
originParamType: any;
|
|
189
|
+
parameterIndex: number;
|
|
190
|
+
}) => IMethodAspect;
|
|
191
|
+
export interface IIdentifierRelationShip {
|
|
192
|
+
saveClassRelation(module: any, namespace?: string): any;
|
|
193
|
+
saveFunctionRelation(ObjectIdentifier: any, uuid: any): any;
|
|
194
|
+
hasRelation(id: ObjectIdentifier): boolean;
|
|
195
|
+
getRelation(id: ObjectIdentifier): string;
|
|
196
|
+
}
|
|
197
|
+
export interface IMidwayContainer extends IObjectFactory, IObjectLifeCycle {
|
|
198
|
+
parent: IMidwayContainer;
|
|
199
|
+
identifierMapping: IIdentifierRelationShip;
|
|
200
|
+
objectCreateEventTarget: EventEmitter;
|
|
201
|
+
ready(): any;
|
|
202
|
+
stop(): Promise<void>;
|
|
203
|
+
registerObject(identifier: ObjectIdentifier, target: any): any;
|
|
217
204
|
load(module?: any): any;
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
205
|
+
hasNamespace(namespace: string): boolean;
|
|
206
|
+
hasDefinition(identifier: ObjectIdentifier): any;
|
|
207
|
+
hasObject(identifier: ObjectIdentifier): any;
|
|
208
|
+
bind<T>(target: T, options?: Partial<IObjectDefinition>): void;
|
|
209
|
+
bind<T>(identifier: ObjectIdentifier, target: T, options?: Partial<IObjectDefinition>): void;
|
|
210
|
+
bindClass(exports: any, options?: Partial<IObjectDefinition>): any;
|
|
222
211
|
setFileDetector(fileDetector: IFileDetector): any;
|
|
223
|
-
registerDataHandler(handlerType: string, handler: (...args: any[]) => any): any;
|
|
224
212
|
createChild(): IMidwayContainer;
|
|
225
|
-
/**
|
|
226
|
-
* 默认不添加创建的 configuration 到 configurations 数组中
|
|
227
|
-
*/
|
|
228
|
-
getConfigService(): IConfigService;
|
|
229
|
-
getEnvironmentService(): IEnvironmentService;
|
|
230
|
-
getInformationService(): IInformationService;
|
|
231
|
-
setInformationService(service: IInformationService): void;
|
|
232
|
-
getAspectService(): IAspectService;
|
|
233
|
-
getCurrentEnv(): string;
|
|
234
|
-
getResolverHandler(): IResolverHandler;
|
|
235
213
|
/**
|
|
236
214
|
* Set value to app attribute map
|
|
237
215
|
* @param key
|
|
@@ -244,8 +222,12 @@ export interface IMidwayContainer extends IApplicationContext {
|
|
|
244
222
|
*/
|
|
245
223
|
getAttr<T>(key: string): T;
|
|
246
224
|
}
|
|
225
|
+
/**
|
|
226
|
+
* @deprecated
|
|
227
|
+
*/
|
|
228
|
+
export declare type IApplicationContext = IMidwayContainer;
|
|
247
229
|
export interface IFileDetector {
|
|
248
|
-
run(container:
|
|
230
|
+
run(container: IMidwayContainer): any;
|
|
249
231
|
}
|
|
250
232
|
export interface IConfigService {
|
|
251
233
|
add(configFilePaths: any[]): any;
|
|
@@ -267,24 +249,10 @@ export interface IEnvironmentService {
|
|
|
267
249
|
setCurrentEnvironment(environment: string): any;
|
|
268
250
|
isDevelopmentEnvironment(): boolean;
|
|
269
251
|
}
|
|
270
|
-
export interface IAspectService {
|
|
271
|
-
loadAspect(): any;
|
|
272
|
-
addAspect(aspectIns: IMethodAspect, aspectData: AspectMetadata): any;
|
|
273
|
-
wrapperAspectToInstance(ins: any): any;
|
|
274
|
-
hasAspect(module: any): boolean;
|
|
275
|
-
}
|
|
276
|
-
export interface IMiddleware<T> {
|
|
277
|
-
resolve: () => (context: T, next: () => Promise<any>) => any;
|
|
278
|
-
}
|
|
279
252
|
export declare enum MidwayProcessTypeEnum {
|
|
280
253
|
APPLICATION = "APPLICATION",
|
|
281
254
|
AGENT = "AGENT"
|
|
282
255
|
}
|
|
283
|
-
/**
|
|
284
|
-
* @deprecated use IMidwayLogger or ILogger from \@midwayjs/logger
|
|
285
|
-
*/
|
|
286
|
-
export interface IMidwayLogger extends ILogger {
|
|
287
|
-
}
|
|
288
256
|
export interface Context {
|
|
289
257
|
/**
|
|
290
258
|
* Custom properties.
|
|
@@ -293,22 +261,107 @@ export interface Context {
|
|
|
293
261
|
logger: ILogger;
|
|
294
262
|
getLogger(name?: string): ILogger;
|
|
295
263
|
startTime: number;
|
|
264
|
+
/**
|
|
265
|
+
* Set value to app attribute map
|
|
266
|
+
* @param key
|
|
267
|
+
* @param value
|
|
268
|
+
*/
|
|
269
|
+
setAttr(key: string, value: any): any;
|
|
270
|
+
/**
|
|
271
|
+
* Get value from app attribute map
|
|
272
|
+
* @param key
|
|
273
|
+
*/
|
|
274
|
+
getAttr<T>(key: string): T;
|
|
296
275
|
}
|
|
297
276
|
export declare type IMidwayContext<FrameworkContext = unknown> = Context & FrameworkContext;
|
|
298
|
-
export
|
|
277
|
+
export declare type NextFunction = () => Promise<any>;
|
|
278
|
+
/**
|
|
279
|
+
* Common middleware definition
|
|
280
|
+
*/
|
|
281
|
+
export interface IMiddleware<CTX, R, N = unknown> {
|
|
282
|
+
resolve: (app?: IMidwayApplication) => FunctionMiddleware<CTX, R, N>;
|
|
283
|
+
match?: (ctx?: CTX) => boolean;
|
|
284
|
+
ignore?: (ctx?: CTX) => boolean;
|
|
285
|
+
}
|
|
286
|
+
export declare type FunctionMiddleware<CTX, R, N = unknown> = N extends true ? (req: CTX, res: R, next: N) => any : (context: CTX, next: R, options?: any) => any;
|
|
287
|
+
export declare type ClassMiddleware<CTX, R, N> = new (...args: any[]) => IMiddleware<CTX, R, N>;
|
|
288
|
+
export declare type CommonMiddleware<CTX, R, N> = ClassMiddleware<CTX, R, N> | FunctionMiddleware<CTX, R, N>;
|
|
289
|
+
export declare type CommonMiddlewareUnion<CTX, R, N> = CommonMiddleware<CTX, R, N> | Array<CommonMiddleware<CTX, R, N>>;
|
|
290
|
+
export declare type MiddlewareRespond<CTX, R, N> = (context: CTX, nextOrRes?: N extends true ? R : NextFunction, next?: N) => Promise<{
|
|
291
|
+
result: any;
|
|
292
|
+
error: Error | undefined;
|
|
293
|
+
}>;
|
|
294
|
+
/**
|
|
295
|
+
* Common Exception Filter definition
|
|
296
|
+
*/
|
|
297
|
+
export interface IFilter<CTX, R, N> {
|
|
298
|
+
catch?(err: Error, ctx: CTX, res?: R, next?: N): any;
|
|
299
|
+
match?(result: any, ctx: CTX, res?: R, next?: N): any;
|
|
300
|
+
}
|
|
301
|
+
export declare type CommonFilterUnion<CTX, R, N> = (new (...args: any[]) => IFilter<CTX, R, N>) | Array<new (...args: any[]) => IFilter<CTX, R, N>>;
|
|
302
|
+
export interface IMidwayBaseApplication<CTX extends IMidwayContext> {
|
|
303
|
+
/**
|
|
304
|
+
* Get a base directory for project, with src or dist
|
|
305
|
+
*/
|
|
299
306
|
getBaseDir(): string;
|
|
307
|
+
/**
|
|
308
|
+
* Get a project root directory, without src or dist
|
|
309
|
+
*/
|
|
300
310
|
getAppDir(): string;
|
|
311
|
+
/**
|
|
312
|
+
* Get a environment value, read from MIDWAY_SERVER_ENV
|
|
313
|
+
*/
|
|
301
314
|
getEnv(): string;
|
|
302
|
-
|
|
315
|
+
/**
|
|
316
|
+
* Get current framework type in MidwayFrameworkType enum
|
|
317
|
+
*/
|
|
318
|
+
getFrameworkType(): FrameworkType;
|
|
319
|
+
/**
|
|
320
|
+
* Get current running process type, app or agent, just for egg
|
|
321
|
+
*/
|
|
303
322
|
getProcessType(): MidwayProcessTypeEnum;
|
|
323
|
+
/**
|
|
324
|
+
* Get global Midway IoC Container
|
|
325
|
+
*/
|
|
304
326
|
getApplicationContext(): IMidwayContainer;
|
|
327
|
+
/**
|
|
328
|
+
* Get all configuration values or get the specified configuration through parameters
|
|
329
|
+
* @param key config key
|
|
330
|
+
*/
|
|
305
331
|
getConfig(key?: string): any;
|
|
332
|
+
/**
|
|
333
|
+
* Get default logger object or get the specified logger through parameters
|
|
334
|
+
* @param name
|
|
335
|
+
*/
|
|
306
336
|
getLogger(name?: string): ILogger;
|
|
337
|
+
/**
|
|
338
|
+
* Get core logger
|
|
339
|
+
*/
|
|
307
340
|
getCoreLogger(): ILogger;
|
|
341
|
+
/**
|
|
342
|
+
* Create a logger by name and options
|
|
343
|
+
* @param name
|
|
344
|
+
* @param options
|
|
345
|
+
*/
|
|
308
346
|
createLogger(name: string, options: LoggerOptions): ILogger;
|
|
347
|
+
/**
|
|
348
|
+
* Get project name, just package.json name
|
|
349
|
+
*/
|
|
309
350
|
getProjectName(): string;
|
|
310
|
-
|
|
351
|
+
/**
|
|
352
|
+
* create a context with RequestContainer
|
|
353
|
+
* @param args
|
|
354
|
+
*/
|
|
355
|
+
createAnonymousContext(...args: any[]): CTX;
|
|
356
|
+
/**
|
|
357
|
+
* Set a context logger class to change default context logger format
|
|
358
|
+
* @param BaseContextLoggerClass
|
|
359
|
+
*/
|
|
311
360
|
setContextLoggerClass(BaseContextLoggerClass: any): void;
|
|
361
|
+
/**
|
|
362
|
+
* Add new value to current config
|
|
363
|
+
* @param obj
|
|
364
|
+
*/
|
|
312
365
|
addConfigObject(obj: any): any;
|
|
313
366
|
/**
|
|
314
367
|
* Set value to app attribute map
|
|
@@ -321,39 +374,47 @@ export interface IMidwayBaseApplication<T extends IMidwayContext = IMidwayContex
|
|
|
321
374
|
* @param key
|
|
322
375
|
*/
|
|
323
376
|
getAttr<T>(key: string): T;
|
|
377
|
+
/**
|
|
378
|
+
* add global filter to app
|
|
379
|
+
* @param Middleware
|
|
380
|
+
*/
|
|
381
|
+
useMiddleware<R, N>(Middleware: CommonMiddlewareUnion<CTX, R, N>): void;
|
|
382
|
+
/**
|
|
383
|
+
* get global middleware
|
|
384
|
+
*/
|
|
385
|
+
getMiddleware<R, N>(): ContextMiddlewareManager<CTX, R, N>;
|
|
386
|
+
/**
|
|
387
|
+
* add exception filter
|
|
388
|
+
* @param Filter
|
|
389
|
+
*/
|
|
390
|
+
useFilter<R, N>(Filter: CommonFilterUnion<CTX, R, N>): void;
|
|
324
391
|
}
|
|
325
392
|
export declare type IMidwayApplication<T extends IMidwayContext = IMidwayContext, FrameworkApplication = unknown> = IMidwayBaseApplication<T> & FrameworkApplication;
|
|
326
|
-
/**
|
|
327
|
-
* @deprecated
|
|
328
|
-
*/
|
|
329
|
-
export interface IMidwayCoreApplication extends IMidwayApplication {
|
|
330
|
-
}
|
|
331
393
|
export interface IMidwayBootstrapOptions {
|
|
332
|
-
|
|
394
|
+
[customPropertyKey: string]: any;
|
|
333
395
|
baseDir?: string;
|
|
334
396
|
appDir?: string;
|
|
397
|
+
applicationContext?: IMidwayContainer;
|
|
335
398
|
preloadModules?: any[];
|
|
336
|
-
|
|
337
|
-
|
|
399
|
+
configurationModule?: any | any[];
|
|
400
|
+
moduleDetector?: 'file' | IFileDetector | false;
|
|
401
|
+
logger?: boolean | ILogger;
|
|
338
402
|
ignore?: string[];
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
disableConflictCheck?: boolean;
|
|
343
|
-
applicationContext?: IMidwayContainer;
|
|
344
|
-
isMainFramework?: boolean;
|
|
345
|
-
globalApplicationHandler?: (type: MidwayFrameworkType) => IMidwayApplication;
|
|
346
|
-
globalConfig?: any;
|
|
403
|
+
globalConfig?: Array<{
|
|
404
|
+
[environmentName: string]: Record<string, any>;
|
|
405
|
+
}> | Record<string, any>;
|
|
347
406
|
}
|
|
348
407
|
export interface IConfigurationOptions {
|
|
349
408
|
logger?: ILogger;
|
|
350
409
|
appLogger?: ILogger;
|
|
351
410
|
ContextLoggerClass?: any;
|
|
411
|
+
ContextLoggerApplyLogger?: string;
|
|
352
412
|
}
|
|
353
|
-
export interface IMidwayFramework<APP extends IMidwayApplication,
|
|
413
|
+
export interface IMidwayFramework<APP extends IMidwayApplication<CTX>, CTX extends IMidwayContext, CONFIG extends IConfigurationOptions, ResOrNext = unknown, Next = unknown> {
|
|
354
414
|
app: APP;
|
|
355
|
-
configurationOptions:
|
|
356
|
-
configure(options
|
|
415
|
+
configurationOptions: CONFIG;
|
|
416
|
+
configure(options?: CONFIG): any;
|
|
417
|
+
isEnable(): boolean;
|
|
357
418
|
initialize(options: Partial<IMidwayBootstrapOptions>): Promise<void>;
|
|
358
419
|
run(): Promise<void>;
|
|
359
420
|
stop(): Promise<void>;
|
|
@@ -361,7 +422,7 @@ export interface IMidwayFramework<APP extends IMidwayApplication, T extends ICon
|
|
|
361
422
|
getApplicationContext(): IMidwayContainer;
|
|
362
423
|
getConfiguration(key?: string): any;
|
|
363
424
|
getCurrentEnvironment(): string;
|
|
364
|
-
getFrameworkType():
|
|
425
|
+
getFrameworkType(): FrameworkType;
|
|
365
426
|
getFrameworkName(): string;
|
|
366
427
|
getAppDir(): string;
|
|
367
428
|
getBaseDir(): string;
|
|
@@ -370,6 +431,31 @@ export interface IMidwayFramework<APP extends IMidwayApplication, T extends ICon
|
|
|
370
431
|
createLogger(name: string, options: LoggerOptions): ILogger;
|
|
371
432
|
getProjectName(): string;
|
|
372
433
|
getDefaultContextLoggerClass(): any;
|
|
434
|
+
useMiddleware(Middleware: CommonMiddlewareUnion<CTX, ResOrNext, Next>): void;
|
|
435
|
+
getMiddleware(): ContextMiddlewareManager<CTX, ResOrNext, Next>;
|
|
436
|
+
applyMiddleware(lastMiddleware?: CommonMiddleware<CTX, ResOrNext, Next>): Promise<MiddlewareRespond<CTX, ResOrNext, Next>>;
|
|
437
|
+
useFilter(Filter: CommonFilterUnion<CTX, ResOrNext, Next>): any;
|
|
373
438
|
}
|
|
374
439
|
export declare const MIDWAY_LOGGER_WRITEABLE_DIR = "MIDWAY_LOGGER_WRITEABLE_DIR";
|
|
440
|
+
export interface MidwayAppInfo {
|
|
441
|
+
pkg: Record<string, any>;
|
|
442
|
+
name: string;
|
|
443
|
+
baseDir: string;
|
|
444
|
+
appDir: string;
|
|
445
|
+
HOME: string;
|
|
446
|
+
root: string;
|
|
447
|
+
env: string;
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* midway global config definition
|
|
451
|
+
*/
|
|
452
|
+
export interface MidwayConfig extends FileConfigOption<typeof _default> {
|
|
453
|
+
[customConfigKey: string]: unknown;
|
|
454
|
+
}
|
|
455
|
+
export interface TranslateOptions {
|
|
456
|
+
lang?: string;
|
|
457
|
+
group?: string;
|
|
458
|
+
args?: any;
|
|
459
|
+
}
|
|
460
|
+
export {};
|
|
375
461
|
//# sourceMappingURL=interface.d.ts.map
|
package/dist/interface.js
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MIDWAY_LOGGER_WRITEABLE_DIR = exports.MidwayProcessTypeEnum = exports.HTTP_SERVER_KEY = exports.REQUEST_OBJ_CTX_KEY = exports.REQUEST_CTX_KEY = void 0;
|
|
3
|
+
exports.MIDWAY_LOGGER_WRITEABLE_DIR = exports.MidwayProcessTypeEnum = exports.HTTP_SERVER_KEY = exports.REQUEST_OBJ_CTX_KEY = exports.REQUEST_CTX_KEY = exports.ObjectLifeCycleEvent = void 0;
|
|
4
|
+
var ObjectLifeCycleEvent;
|
|
5
|
+
(function (ObjectLifeCycleEvent) {
|
|
6
|
+
ObjectLifeCycleEvent["BEFORE_BIND"] = "beforeBind";
|
|
7
|
+
ObjectLifeCycleEvent["BEFORE_CREATED"] = "beforeObjectCreated";
|
|
8
|
+
ObjectLifeCycleEvent["AFTER_CREATED"] = "afterObjectCreated";
|
|
9
|
+
ObjectLifeCycleEvent["AFTER_INIT"] = "afterObjectInit";
|
|
10
|
+
ObjectLifeCycleEvent["BEFORE_DESTROY"] = "beforeObjectDestroy";
|
|
11
|
+
})(ObjectLifeCycleEvent = exports.ObjectLifeCycleEvent || (exports.ObjectLifeCycleEvent = {}));
|
|
4
12
|
exports.REQUEST_CTX_KEY = 'ctx';
|
|
5
13
|
exports.REQUEST_OBJ_CTX_KEY = '_req_ctx';
|
|
6
14
|
exports.HTTP_SERVER_KEY = '_midway_http_server';
|
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export declare class MidwayAspectService
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
private container;
|
|
7
|
-
constructor(container: any);
|
|
1
|
+
import { IMethodAspect } from '@midwayjs/decorator';
|
|
2
|
+
import { IMidwayContainer } from '../interface';
|
|
3
|
+
export declare class MidwayAspectService {
|
|
4
|
+
readonly applicationContext: IMidwayContainer;
|
|
5
|
+
constructor(applicationContext: IMidwayContainer);
|
|
8
6
|
/**
|
|
9
7
|
* load aspect method for container
|
|
10
|
-
* @private
|
|
11
8
|
*/
|
|
12
9
|
loadAspect(): Promise<void>;
|
|
13
|
-
addAspect
|
|
10
|
+
private addAspect;
|
|
14
11
|
/**
|
|
15
|
-
*
|
|
16
|
-
* @param
|
|
17
|
-
* @
|
|
12
|
+
* intercept class method in prototype
|
|
13
|
+
* @param Clz class you want to intercept
|
|
14
|
+
* @param methodName method name you want to intercept
|
|
15
|
+
* @param aspectObject aspect object, before, round, etc.
|
|
18
16
|
*/
|
|
19
|
-
|
|
20
|
-
hasAspect(module: any): boolean;
|
|
17
|
+
interceptPrototypeMethod(Clz: new (...args: any[]) => any, methodName: string, aspectObject: IMethodAspect | (() => IMethodAspect)): void;
|
|
21
18
|
}
|
|
22
19
|
//# sourceMappingURL=aspectService.d.ts.map
|