@midwayjs/core 3.0.0 → 3.0.4
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.d.ts +3 -5
- package/dist/baseFramework.js +8 -17
- package/dist/context/container.js +1 -0
- package/dist/context/managedResolverFactory.d.ts +1 -0
- package/dist/context/managedResolverFactory.js +15 -7
- package/dist/error/framework.js +1 -1
- package/dist/interface.d.ts +4 -5
- package/dist/service/decoratorService.js +14 -8
- package/dist/service/lifeCycleService.js +4 -4
- package/dist/setup.js +1 -0
- package/package.json +5 -5
package/dist/baseFramework.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CommonMiddlewareUnion, IConfigurationOptions, IMidwayApplication, IMidwayBootstrapOptions, IMidwayContainer, IMidwayContext, IMidwayFramework, CommonFilterUnion, CommonMiddleware, MiddlewareRespond } from './interface';
|
|
2
2
|
import { FrameworkType } from '@midwayjs/decorator';
|
|
3
|
-
import { ILogger, LoggerOptions } from '@midwayjs/logger';
|
|
3
|
+
import { ILogger, LoggerOptions, LoggerContextFormat } from '@midwayjs/logger';
|
|
4
4
|
import { MidwayEnvironmentService } from './service/environmentService';
|
|
5
5
|
import { MidwayConfigService } from './service/configService';
|
|
6
6
|
import { MidwayInformationService } from './service/informationService';
|
|
@@ -15,8 +15,8 @@ export declare abstract class BaseFramework<APP extends IMidwayApplication<CTX>,
|
|
|
15
15
|
protected logger: ILogger;
|
|
16
16
|
protected appLogger: ILogger;
|
|
17
17
|
protected defaultContext: {};
|
|
18
|
-
protected
|
|
19
|
-
protected
|
|
18
|
+
protected contextLoggerApplyLogger: string;
|
|
19
|
+
protected contextLoggerFormat: LoggerContextFormat;
|
|
20
20
|
protected middlewareManager: ContextMiddlewareManager<CTX, ResOrNext, Next>;
|
|
21
21
|
protected filterManager: FilterManager<CTX, ResOrNext, Next>;
|
|
22
22
|
protected composeMiddleware: any;
|
|
@@ -49,7 +49,6 @@ export declare abstract class BaseFramework<APP extends IMidwayApplication<CTX>,
|
|
|
49
49
|
abstract applicationInitialize(options: IMidwayBootstrapOptions): any;
|
|
50
50
|
abstract getFrameworkType(): FrameworkType;
|
|
51
51
|
abstract run(): Promise<void>;
|
|
52
|
-
setContextLoggerClass(BaseContextLogger: any): void;
|
|
53
52
|
protected createContextLogger(ctx: CTX, name?: string): ILogger;
|
|
54
53
|
stop(): Promise<void>;
|
|
55
54
|
getAppDir(): string;
|
|
@@ -78,7 +77,6 @@ export declare abstract class BaseFramework<APP extends IMidwayApplication<CTX>,
|
|
|
78
77
|
createLogger(name: string, option?: LoggerOptions): ILogger;
|
|
79
78
|
getProjectName(): string;
|
|
80
79
|
getFrameworkName(): string;
|
|
81
|
-
getDefaultContextLoggerClass(): any;
|
|
82
80
|
useMiddleware(Middleware: CommonMiddlewareUnion<CTX, ResOrNext, Next>): void;
|
|
83
81
|
getMiddleware(): ContextMiddlewareManager<CTX, ResOrNext, Next>;
|
|
84
82
|
useFilter(Filter: CommonFilterUnion<CTX, ResOrNext, Next>): void;
|
package/dist/baseFramework.js
CHANGED
|
@@ -12,7 +12,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.BaseFramework = void 0;
|
|
13
13
|
const interface_1 = require("./interface");
|
|
14
14
|
const decorator_1 = require("@midwayjs/decorator");
|
|
15
|
-
const logger_1 = require("@midwayjs/logger");
|
|
16
15
|
const requestContainer_1 = require("./context/requestContainer");
|
|
17
16
|
const environmentService_1 = require("./service/environmentService");
|
|
18
17
|
const configService_1 = require("./service/configService");
|
|
@@ -32,12 +31,11 @@ class BaseFramework {
|
|
|
32
31
|
this.composeMiddleware = null;
|
|
33
32
|
}
|
|
34
33
|
async init() {
|
|
35
|
-
var _a, _b
|
|
34
|
+
var _a, _b;
|
|
36
35
|
this.configurationOptions = (_a = this.configure()) !== null && _a !== void 0 ? _a : {};
|
|
37
|
-
this.
|
|
38
|
-
(_b = this.configurationOptions.
|
|
39
|
-
this.
|
|
40
|
-
(_c = this.configurationOptions.ContextLoggerApplyLogger) !== null && _c !== void 0 ? _c : 'appLogger';
|
|
36
|
+
this.contextLoggerApplyLogger =
|
|
37
|
+
(_b = this.configurationOptions.contextLoggerApplyLogger) !== null && _b !== void 0 ? _b : 'appLogger';
|
|
38
|
+
this.contextLoggerFormat = this.configurationOptions.contextLoggerFormat;
|
|
41
39
|
this.logger = this.loggerService.getLogger('coreLogger');
|
|
42
40
|
this.appLogger = this.loggerService.getLogger('appLogger');
|
|
43
41
|
return this;
|
|
@@ -86,12 +84,11 @@ class BaseFramework {
|
|
|
86
84
|
getApplication() {
|
|
87
85
|
return this.app;
|
|
88
86
|
}
|
|
89
|
-
setContextLoggerClass(BaseContextLogger) {
|
|
90
|
-
this.BaseContextLoggerClass = BaseContextLogger;
|
|
91
|
-
}
|
|
92
87
|
createContextLogger(ctx, name) {
|
|
93
|
-
const appLogger = this.getLogger(name !== null && name !== void 0 ? name : this.
|
|
94
|
-
return
|
|
88
|
+
const appLogger = this.getLogger(name !== null && name !== void 0 ? name : this.contextLoggerApplyLogger);
|
|
89
|
+
return appLogger.createContextLogger(ctx, {
|
|
90
|
+
contextFormat: this.contextLoggerFormat,
|
|
91
|
+
});
|
|
95
92
|
}
|
|
96
93
|
async stop() {
|
|
97
94
|
await this.beforeStop();
|
|
@@ -162,9 +159,6 @@ class BaseFramework {
|
|
|
162
159
|
};
|
|
163
160
|
return ctx;
|
|
164
161
|
},
|
|
165
|
-
setContextLoggerClass: (BaseContextLogger) => {
|
|
166
|
-
return this.setContextLoggerClass(BaseContextLogger);
|
|
167
|
-
},
|
|
168
162
|
addConfigObject: (obj) => {
|
|
169
163
|
this.configService.addObject(obj);
|
|
170
164
|
},
|
|
@@ -249,9 +243,6 @@ class BaseFramework {
|
|
|
249
243
|
getFrameworkName() {
|
|
250
244
|
return this.getFrameworkType().name;
|
|
251
245
|
}
|
|
252
|
-
getDefaultContextLoggerClass() {
|
|
253
|
-
return logger_1.MidwayContextLogger;
|
|
254
|
-
}
|
|
255
246
|
useMiddleware(Middleware) {
|
|
256
247
|
this.middlewareManager.insertLast(Middleware);
|
|
257
248
|
}
|
|
@@ -52,5 +52,6 @@ export declare class ManagedResolverFactory {
|
|
|
52
52
|
*/
|
|
53
53
|
depthFirstSearch(identifier: string, definition: IObjectDefinition, depth?: string[]): boolean;
|
|
54
54
|
private getObjectEventTarget;
|
|
55
|
+
private checkSingletonInvokeRequest;
|
|
55
56
|
}
|
|
56
57
|
//# sourceMappingURL=managedResolverFactory.d.ts.map
|
|
@@ -113,6 +113,7 @@ class ManagedResolverFactory {
|
|
|
113
113
|
if (definition.properties) {
|
|
114
114
|
const keys = definition.properties.propertyKeys();
|
|
115
115
|
for (const key of keys) {
|
|
116
|
+
this.checkSingletonInvokeRequest(definition, key);
|
|
116
117
|
try {
|
|
117
118
|
inst[key] = this.resolveManaged(definition.properties.get(key), key);
|
|
118
119
|
}
|
|
@@ -202,13 +203,7 @@ class ManagedResolverFactory {
|
|
|
202
203
|
if (definition.properties) {
|
|
203
204
|
const keys = definition.properties.propertyKeys();
|
|
204
205
|
for (const key of keys) {
|
|
205
|
-
|
|
206
|
-
const propertyDefinition = this.context.registry.getDefinition(key);
|
|
207
|
-
if (propertyDefinition.isRequestScope() &&
|
|
208
|
-
!propertyDefinition.allowDowngrade) {
|
|
209
|
-
throw new error_1.MidwaySingletonInjectRequestError(definition.path.name, propertyDefinition.path.name);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
206
|
+
this.checkSingletonInvokeRequest(definition, key);
|
|
212
207
|
try {
|
|
213
208
|
inst[key] = await this.resolveManagedAsync(definition.properties.get(key), key);
|
|
214
209
|
}
|
|
@@ -378,6 +373,19 @@ class ManagedResolverFactory {
|
|
|
378
373
|
}
|
|
379
374
|
return this.context.objectCreateEventTarget;
|
|
380
375
|
}
|
|
376
|
+
checkSingletonInvokeRequest(definition, key) {
|
|
377
|
+
if (definition.isSingletonScope()) {
|
|
378
|
+
const managedRef = definition.properties.get(key);
|
|
379
|
+
if (this.context.hasDefinition(managedRef === null || managedRef === void 0 ? void 0 : managedRef.name)) {
|
|
380
|
+
const propertyDefinition = this.context.registry.getDefinition(managedRef.name);
|
|
381
|
+
if (propertyDefinition.isRequestScope() &&
|
|
382
|
+
!propertyDefinition.allowDowngrade) {
|
|
383
|
+
throw new error_1.MidwaySingletonInjectRequestError(definition.path.name, propertyDefinition.path.name);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
return true;
|
|
388
|
+
}
|
|
381
389
|
}
|
|
382
390
|
exports.ManagedResolverFactory = ManagedResolverFactory;
|
|
383
391
|
//# sourceMappingURL=managedResolverFactory.js.map
|
package/dist/error/framework.js
CHANGED
|
@@ -87,7 +87,7 @@ class MidwayUseWrongMethodError extends base_1.MidwayError {
|
|
|
87
87
|
exports.MidwayUseWrongMethodError = MidwayUseWrongMethodError;
|
|
88
88
|
class MidwaySingletonInjectRequestError extends base_1.MidwayError {
|
|
89
89
|
constructor(singletonScopeName, requestScopeName) {
|
|
90
|
-
const text = `${singletonScopeName} with singleton scope can't implicitly inject ${requestScopeName} with request scope directly, please add @Scope(ScopeEnum.Request, { allowDowngrade: true }) in ${requestScopeName}.`;
|
|
90
|
+
const text = `${singletonScopeName} with singleton scope can't implicitly inject ${requestScopeName} with request scope directly, please add "@Scope(ScopeEnum.Request, { allowDowngrade: true })" in ${requestScopeName} or use "ctx.requestContext.getAsync(${requestScopeName})".`;
|
|
91
91
|
super(text, exports.FrameworkErrorEnum.SINGLETON_INJECT_REQUEST);
|
|
92
92
|
}
|
|
93
93
|
}
|
package/dist/interface.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { ObjectIdentifier, IManagedInstance, IMethodAspect, ScopeEnum, FrameworkType } from '@midwayjs/decorator';
|
|
3
|
-
import { ILogger, LoggerOptions } from '@midwayjs/logger';
|
|
3
|
+
import { ILogger, LoggerOptions, LoggerContextFormat } from '@midwayjs/logger';
|
|
4
4
|
import * as EventEmitter from 'events';
|
|
5
5
|
import { ContextMiddlewareManager } from './common/middlewareManager';
|
|
6
6
|
import _default from './config/config.default';
|
|
@@ -203,7 +203,7 @@ export declare type ParameterHandlerFunction = (options: {
|
|
|
203
203
|
originArgs: Array<any>;
|
|
204
204
|
originParamType: any;
|
|
205
205
|
parameterIndex: number;
|
|
206
|
-
}) =>
|
|
206
|
+
}) => any;
|
|
207
207
|
export interface IIdentifierRelationShip {
|
|
208
208
|
saveClassRelation(module: any, namespace?: string): any;
|
|
209
209
|
saveFunctionRelation(ObjectIdentifier: any, uuid: any): any;
|
|
@@ -427,8 +427,8 @@ export interface IMidwayBootstrapOptions {
|
|
|
427
427
|
export interface IConfigurationOptions {
|
|
428
428
|
logger?: ILogger;
|
|
429
429
|
appLogger?: ILogger;
|
|
430
|
-
|
|
431
|
-
|
|
430
|
+
contextLoggerApplyLogger?: string;
|
|
431
|
+
contextLoggerFormat?: LoggerContextFormat;
|
|
432
432
|
}
|
|
433
433
|
export interface IMidwayFramework<APP extends IMidwayApplication<CTX>, CTX extends IMidwayContext, CONFIG extends IConfigurationOptions, ResOrNext = unknown, Next = unknown> {
|
|
434
434
|
app: APP;
|
|
@@ -450,7 +450,6 @@ export interface IMidwayFramework<APP extends IMidwayApplication<CTX>, CTX exten
|
|
|
450
450
|
getCoreLogger(): ILogger;
|
|
451
451
|
createLogger(name: string, options: LoggerOptions): ILogger;
|
|
452
452
|
getProjectName(): string;
|
|
453
|
-
getDefaultContextLoggerClass(): any;
|
|
454
453
|
useMiddleware(Middleware: CommonMiddlewareUnion<CTX, ResOrNext, Next>): void;
|
|
455
454
|
getMiddleware(): ContextMiddlewareManager<CTX, ResOrNext, Next>;
|
|
456
455
|
applyMiddleware(lastMiddleware?: CommonMiddleware<CTX, ResOrNext, Next>): Promise<MiddlewareRespond<CTX, ResOrNext, Next>>;
|
|
@@ -69,14 +69,20 @@ let MidwayDecoratorService = class MidwayDecoratorService {
|
|
|
69
69
|
throw new error_1.MidwayCommonError(`Parameter Decorator "${key}" handler not found, please register first.`);
|
|
70
70
|
}
|
|
71
71
|
const paramTypes = (0, decorator_1.getMethodParamTypes)(Clzz, propertyName);
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
72
|
+
try {
|
|
73
|
+
newArgs[parameterIndex] = await parameterDecoratorHandler({
|
|
74
|
+
metadata,
|
|
75
|
+
propertyName,
|
|
76
|
+
parameterIndex,
|
|
77
|
+
target: Clzz,
|
|
78
|
+
originArgs: joinPoint.args,
|
|
79
|
+
originParamType: paramTypes[parameterIndex],
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
// ignore
|
|
84
|
+
debug(`[core]: Parameter decorator throw error and use origin args, ${err.stack}`);
|
|
85
|
+
}
|
|
80
86
|
}
|
|
81
87
|
joinPoint.args = newArgs;
|
|
82
88
|
},
|
|
@@ -32,7 +32,7 @@ let MidwayLifeCycleService = class MidwayLifeCycleService {
|
|
|
32
32
|
}
|
|
33
33
|
else {
|
|
34
34
|
// 普通类写法
|
|
35
|
-
debug(`[core]: run ${cycle.target.name} init`);
|
|
35
|
+
debug(`[core]: Lifecycle run ${cycle.target.name} init`);
|
|
36
36
|
cycle.instance = await this.applicationContext.getAsync(cycle.target);
|
|
37
37
|
}
|
|
38
38
|
cycle.instance && lifecycleInstanceList.push(cycle);
|
|
@@ -80,7 +80,7 @@ let MidwayLifeCycleService = class MidwayLifeCycleService {
|
|
|
80
80
|
if (Array.isArray(lifecycleInstanceOrList)) {
|
|
81
81
|
for (const cycle of lifecycleInstanceOrList) {
|
|
82
82
|
if (typeof cycle.instance[lifecycle] === 'function') {
|
|
83
|
-
debug(`[core]: run ${cycle.instance.constructor.name} ${lifecycle}`);
|
|
83
|
+
debug(`[core]: Lifecycle run ${cycle.instance.constructor.name} ${lifecycle}`);
|
|
84
84
|
const result = await cycle.instance[lifecycle](this.applicationContext, this.frameworkService.getMainApp());
|
|
85
85
|
if (resultHandler) {
|
|
86
86
|
resultHandler(result);
|
|
@@ -90,7 +90,7 @@ let MidwayLifeCycleService = class MidwayLifeCycleService {
|
|
|
90
90
|
}
|
|
91
91
|
else {
|
|
92
92
|
if (typeof lifecycleInstanceOrList[lifecycle] === 'function') {
|
|
93
|
-
debug(`[core]: run ${lifecycleInstanceOrList.constructor.name} ${lifecycle}`);
|
|
93
|
+
debug(`[core]: Lifecycle run ${lifecycleInstanceOrList.constructor.name} ${lifecycle}`);
|
|
94
94
|
const result = await lifecycleInstanceOrList[lifecycle](this.applicationContext, this.frameworkService.getMainApp());
|
|
95
95
|
if (resultHandler) {
|
|
96
96
|
resultHandler(result);
|
|
@@ -101,7 +101,7 @@ let MidwayLifeCycleService = class MidwayLifeCycleService {
|
|
|
101
101
|
async runObjectLifeCycle(lifecycleInstanceList, lifecycle) {
|
|
102
102
|
for (const cycle of lifecycleInstanceList) {
|
|
103
103
|
if (typeof cycle.instance[lifecycle] === 'function') {
|
|
104
|
-
debug(`[core]: run ${cycle.instance.constructor.name} ${lifecycle}`);
|
|
104
|
+
debug(`[core]: Lifecycle run ${cycle.instance.constructor.name} ${lifecycle}`);
|
|
105
105
|
return this.applicationContext[lifecycle](cycle.instance[lifecycle].bind(cycle.instance));
|
|
106
106
|
}
|
|
107
107
|
}
|
package/dist/setup.js
CHANGED
|
@@ -11,6 +11,7 @@ const debug = util.debuglog('midway:debug');
|
|
|
11
11
|
async function initializeGlobalApplicationContext(globalOptions) {
|
|
12
12
|
var _a, _b, _c, _d;
|
|
13
13
|
debug('[core]: start "initializeGlobalApplicationContext"');
|
|
14
|
+
debug(`[core]: bootstrap options = ${util.inspect(globalOptions)}`);
|
|
14
15
|
const appDir = (_a = globalOptions.appDir) !== null && _a !== void 0 ? _a : '';
|
|
15
16
|
const baseDir = (_b = globalOptions.baseDir) !== null && _b !== void 0 ? _b : '';
|
|
16
17
|
// new container
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/core",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.4",
|
|
4
4
|
"description": "midway core",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -21,18 +21,18 @@
|
|
|
21
21
|
],
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@midwayjs/decorator": "^3.0.
|
|
24
|
+
"@midwayjs/decorator": "^3.0.4",
|
|
25
25
|
"koa": "2.13.4",
|
|
26
26
|
"midway-test-component": "*",
|
|
27
27
|
"mm": "3.2.0",
|
|
28
|
-
"sinon": "
|
|
28
|
+
"sinon": "13.0.1"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"@midwayjs/decorator": "*"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@midwayjs/glob": "^1.0.2",
|
|
35
|
-
"@midwayjs/logger": "2.
|
|
35
|
+
"@midwayjs/logger": "^2.15.0",
|
|
36
36
|
"class-transformer": "^0.5.1",
|
|
37
37
|
"picomatch": "2.3.1"
|
|
38
38
|
},
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"engines": {
|
|
45
45
|
"node": ">=12"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "c2a37dd026c7bf3e855f4498691f572ef61396e3"
|
|
48
48
|
}
|