@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.
Files changed (113) hide show
  1. package/CHANGELOG.md +137 -0
  2. package/README.md +1 -1
  3. package/dist/baseFramework.d.ts +56 -22
  4. package/dist/baseFramework.js +157 -232
  5. package/dist/common/applicationManager.d.ts +12 -0
  6. package/dist/common/applicationManager.js +66 -0
  7. package/dist/{util → common}/fileDetector.d.ts +0 -0
  8. package/dist/{util → common}/fileDetector.js +16 -10
  9. package/dist/common/filterManager.d.ts +19 -0
  10. package/dist/common/filterManager.js +85 -0
  11. package/dist/common/middlewareManager.d.ts +68 -0
  12. package/dist/common/middlewareManager.js +183 -0
  13. package/dist/common/serviceFactory.d.ts +15 -0
  14. package/dist/{util → common}/serviceFactory.js +16 -6
  15. package/dist/{util → common}/triggerCollector.d.ts +0 -0
  16. package/dist/{util → common}/triggerCollector.js +0 -0
  17. package/dist/common/webGenerator.d.ts +16 -0
  18. package/dist/common/webGenerator.js +114 -0
  19. package/dist/{util → common}/webRouterCollector.d.ts +21 -2
  20. package/dist/common/webRouterCollector.js +331 -0
  21. package/dist/config/config.default.d.ts +7 -0
  22. package/dist/config/config.default.js +28 -0
  23. package/dist/context/container.d.ts +73 -43
  24. package/dist/context/container.js +289 -271
  25. package/dist/context/definitionRegistry.d.ts +26 -0
  26. package/dist/context/definitionRegistry.js +124 -0
  27. package/dist/context/managedResolverFactory.d.ts +15 -32
  28. package/dist/context/managedResolverFactory.js +88 -317
  29. package/dist/context/providerWrapper.d.ts +2 -3
  30. package/dist/context/requestContainer.d.ts +0 -2
  31. package/dist/context/requestContainer.js +9 -26
  32. package/dist/definitions/functionDefinition.d.ts +3 -4
  33. package/dist/definitions/functionDefinition.js +0 -6
  34. package/dist/definitions/objectCreator.js +6 -6
  35. package/dist/definitions/objectDefinition.d.ts +4 -6
  36. package/dist/definitions/objectDefinition.js +0 -8
  37. package/dist/definitions/properties.d.ts +2 -15
  38. package/dist/definitions/properties.js +3 -72
  39. package/dist/error/base.d.ts +13 -0
  40. package/dist/error/base.js +19 -0
  41. package/dist/error/code.d.ts +60 -0
  42. package/dist/error/code.js +65 -0
  43. package/dist/error/framework.d.ts +24 -0
  44. package/dist/error/framework.js +58 -0
  45. package/dist/error/http.d.ts +58 -0
  46. package/dist/error/http.js +82 -0
  47. package/dist/error/index.d.ts +4 -0
  48. package/dist/error/index.js +16 -0
  49. package/dist/functional/configuration.d.ts +4 -2
  50. package/dist/functional/configuration.js +12 -2
  51. package/dist/index.d.ts +24 -11
  52. package/dist/index.js +36 -36
  53. package/dist/interface.d.ts +270 -184
  54. package/dist/interface.js +9 -1
  55. package/dist/service/aspectService.d.ts +11 -14
  56. package/dist/service/aspectService.js +116 -172
  57. package/dist/service/configService.d.ts +10 -8
  58. package/dist/service/configService.js +61 -38
  59. package/dist/service/decoratorService.d.ts +23 -0
  60. package/dist/service/decoratorService.js +149 -0
  61. package/dist/service/environmentService.js +15 -4
  62. package/dist/service/frameworkService.d.ts +26 -0
  63. package/dist/service/frameworkService.js +176 -0
  64. package/dist/service/informationService.d.ts +4 -7
  65. package/dist/service/informationService.js +41 -10
  66. package/dist/service/lifeCycleService.d.ts +14 -0
  67. package/dist/service/lifeCycleService.js +130 -0
  68. package/dist/service/loggerService.d.ts +27 -0
  69. package/dist/service/loggerService.js +132 -0
  70. package/dist/service/middlewareService.d.ts +11 -0
  71. package/dist/service/middlewareService.js +127 -0
  72. package/dist/{features/pipeline.d.ts → service/pipelineService.d.ts} +56 -46
  73. package/dist/{features/pipeline.js → service/pipelineService.js} +54 -19
  74. package/dist/setup.d.ts +4 -0
  75. package/dist/setup.js +119 -0
  76. package/dist/util/contextUtil.d.ts +1 -1
  77. package/dist/util/contextUtil.js +2 -2
  78. package/dist/util/index.d.ts +64 -0
  79. package/dist/util/index.js +195 -7
  80. package/dist/util/pathFileUtil.js +2 -2
  81. package/dist/util/pathToRegexp.d.ts +17 -0
  82. package/dist/util/pathToRegexp.js +280 -0
  83. package/dist/util/webRouterParam.d.ts +2 -2
  84. package/dist/util/webRouterParam.js +19 -20
  85. package/package.json +10 -15
  86. package/dist/common/lodashWrap.d.ts +0 -9
  87. package/dist/common/lodashWrap.js +0 -18
  88. package/dist/common/notFoundError.d.ts +0 -8
  89. package/dist/common/notFoundError.js +0 -20
  90. package/dist/common/reflectTool.d.ts +0 -15
  91. package/dist/common/reflectTool.js +0 -83
  92. package/dist/context/applicationContext.d.ts +0 -81
  93. package/dist/context/applicationContext.js +0 -263
  94. package/dist/context/managed.d.ts +0 -45
  95. package/dist/context/managed.js +0 -69
  96. package/dist/context/resolverHandler.d.ts +0 -34
  97. package/dist/context/resolverHandler.js +0 -88
  98. package/dist/definitions/messageSource.d.ts +0 -13
  99. package/dist/definitions/messageSource.js +0 -74
  100. package/dist/definitions/resource.d.ts +0 -27
  101. package/dist/definitions/resource.js +0 -116
  102. package/dist/features/index.d.ts +0 -2
  103. package/dist/features/index.js +0 -3
  104. package/dist/logger.d.ts +0 -4
  105. package/dist/logger.js +0 -20
  106. package/dist/util/containerUtil.d.ts +0 -9
  107. package/dist/util/containerUtil.js +0 -26
  108. package/dist/util/emptyFramework.d.ts +0 -62
  109. package/dist/util/emptyFramework.js +0 -72
  110. package/dist/util/serviceFactory.d.ts +0 -13
  111. package/dist/util/staticConfig.d.ts +0 -10
  112. package/dist/util/staticConfig.js +0 -67
  113. package/dist/util/webRouterCollector.js +0 -348
@@ -1,31 +1,75 @@
1
1
  /// <reference types="node" />
2
- import { ObjectIdentifier, IManagedInstance, ScopeEnum, ObjectDefinitionOptions, IMethodAspect, AspectMetadata, MidwayFrameworkType } from '@midwayjs/decorator';
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
- onReady(container: IMidwayContainer, app?: IMidwayApplication): Promise<void>;
9
- onStop?(container: IMidwayContainer, app?: IMidwayApplication): Promise<void>;
10
- }
11
- export declare type Locale = string;
12
- /**
13
- * 多语言支持接口
14
- */
15
- export interface IMessageSource {
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
- isAsync(identifier: ObjectIdentifier): boolean;
25
- get<T>(identifier: new () => T, args?: any): T;
26
- get<T>(identifier: ObjectIdentifier, args?: any): T;
27
- getAsync<T>(identifier: new () => T, args?: any): Promise<T>;
28
- getAsync<T>(identifier: ObjectIdentifier, args?: any): Promise<T>;
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
- isAutowire(): boolean;
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: HandlerProp[];
57
- }
58
- export interface HandlerProp {
59
- handlerKey: string;
60
- prop: FrameworkDecoratorMetadata;
61
- }
62
- /**
63
- * 对象描述元数据,用于生成对象定义
64
- */
65
- export interface IObjectDefinitionMetadata {
66
- namespace?: string;
67
- id: string;
68
- name: string;
69
- initMethod: string;
70
- destroyMethod: string;
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?: IApplicationContext): any;
96
- doConstructAsync(Clzz: any, args?: any, context?: IApplicationContext): Promise<any>;
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
- clear(): void;
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 interface IContainerConfiguration {
195
- namespace: string;
196
- packageName: string;
197
- addLoadDir(dir: string): any;
198
- addImports(imports: string[], baseDir?: string): any;
199
- addImportObjects(importObjects: Record<string, unknown>): any;
200
- addImportConfigs(importConfigs: string[], baseDir: string): any;
201
- load(packageName: string): any;
202
- loadComponentObject(componentObject: any): any;
203
- loadConfiguration(configuration: IContainerConfiguration, baseDir: string, filePath?: string): any;
204
- getImportDirectory(): string[];
205
- getImportObjects(): any;
206
- bindConfigurationClass(clzz: any, filePath?: string): any;
207
- }
208
- export declare type HandlerFunction = (handlerKey: string, instance?: any) => any;
209
- export interface IResolverHandler {
210
- beforeEachCreated(target: any, constructorArgs: any[], context: any): any;
211
- afterEachCreated(instance: any, context: any, definition: any): any;
212
- registerHandler(key: string, fn: HandlerFunction): any;
213
- hasHandler(key: string): boolean;
214
- getHandler(key: string): any;
215
- }
216
- export interface IMidwayContainer extends IApplicationContext {
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
- bind<T>(target: T, options?: ObjectDefinitionOptions): void;
219
- bind<T>(identifier: ObjectIdentifier, target: T, options?: ObjectDefinitionOptions): void;
220
- bindClass(exports: any, namespace?: string, filePath?: string): any;
221
- getDebugLogger(): any;
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: IApplicationContext): any;
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 interface IMidwayBaseApplication<T extends IMidwayContext = IMidwayContext> {
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
- getFrameworkType(): MidwayFrameworkType;
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
- createAnonymousContext(...args: any[]): T;
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
- logger?: ILogger | boolean;
394
+ [customPropertyKey: string]: any;
333
395
  baseDir?: string;
334
396
  appDir?: string;
397
+ applicationContext?: IMidwayContainer;
335
398
  preloadModules?: any[];
336
- disableAutoLoad?: boolean;
337
- pattern?: string[];
399
+ configurationModule?: any | any[];
400
+ moduleDetector?: 'file' | IFileDetector | false;
401
+ logger?: boolean | ILogger;
338
402
  ignore?: string[];
339
- isTsMode?: boolean;
340
- middleware?: string[];
341
- loadDir?: string[];
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, T extends IConfigurationOptions> {
413
+ export interface IMidwayFramework<APP extends IMidwayApplication<CTX>, CTX extends IMidwayContext, CONFIG extends IConfigurationOptions, ResOrNext = unknown, Next = unknown> {
354
414
  app: APP;
355
- configurationOptions: T;
356
- configure(options: T): IMidwayFramework<APP, T>;
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(): MidwayFrameworkType;
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 { AspectMetadata, IMethodAspect } from '@midwayjs/decorator';
2
- import { IAspectService } from '../interface';
3
- export declare class MidwayAspectService implements IAspectService {
4
- protected aspectMappingMap: WeakMap<any, Map<string, any[]>>;
5
- private aspectModuleSet;
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(aspectIns: IMethodAspect, aspectData: AspectMetadata): Promise<void>;
10
+ private addAspect;
14
11
  /**
15
- * wrapper aspect method before instance return
16
- * @param ins
17
- * @protected
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
- wrapperAspectToInstance(ins: any): any;
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