@midwayjs/core 3.0.0-beta.1 → 3.0.0-beta.10
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 +106 -0
- package/README.md +1 -1
- package/dist/baseFramework.d.ts +13 -10
- package/dist/baseFramework.js +32 -23
- 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 +0 -0
- 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/{util → common}/serviceFactory.d.ts +0 -0
- package/dist/{util → common}/serviceFactory.js +0 -0
- 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/{util → common}/webGenerator.js +34 -52
- package/dist/{util → common}/webRouterCollector.d.ts +9 -4
- package/dist/{util → common}/webRouterCollector.js +52 -28
- package/dist/config/config.default.d.ts +3 -17
- package/dist/context/container.js +13 -2
- package/dist/context/managedResolverFactory.js +2 -2
- package/dist/error/base.d.ts +3 -1
- package/dist/error/base.js +1 -0
- package/dist/error/code.d.ts +2 -1
- package/dist/error/code.js +2 -1
- package/dist/error/framework.d.ts +5 -2
- package/dist/error/framework.js +14 -5
- package/dist/error/http.d.ts +2 -1
- package/dist/error/http.js +3 -3
- package/dist/error/index.d.ts +1 -0
- package/dist/error/index.js +1 -0
- package/dist/index.d.ts +9 -9
- package/dist/index.js +13 -11
- package/dist/interface.d.ts +58 -30
- package/dist/service/configService.js +4 -5
- package/dist/service/decoratorService.js +26 -24
- package/dist/service/frameworkService.d.ts +6 -4
- package/dist/service/frameworkService.js +26 -11
- package/dist/service/lifeCycleService.js +7 -5
- package/dist/service/loggerService.d.ts +1 -2
- package/dist/service/loggerService.js +1 -10
- package/dist/service/middlewareService.d.ts +4 -4
- package/dist/service/middlewareService.js +32 -46
- package/dist/setup.js +10 -2
- package/dist/util/contextUtil.d.ts +1 -1
- package/dist/util/index.d.ts +46 -0
- package/dist/util/index.js +150 -1
- package/dist/util/webRouterParam.d.ts +2 -2
- package/dist/util/webRouterParam.js +17 -18
- package/package.json +7 -7
- package/dist/util/exceptionFilterManager.d.ts +0 -13
- package/dist/util/exceptionFilterManager.js +0 -53
- package/dist/util/middlewareManager.d.ts +0 -11
- package/dist/util/middlewareManager.js +0 -48
- package/dist/util/webGenerator.d.ts +0 -30
package/dist/error/base.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
interface ErrorOption {
|
|
2
|
-
cause
|
|
2
|
+
cause?: Error;
|
|
3
|
+
status?: number;
|
|
3
4
|
}
|
|
4
5
|
export declare class MidwayError extends Error {
|
|
5
6
|
code: number;
|
|
7
|
+
status: number;
|
|
6
8
|
cause: Error;
|
|
7
9
|
constructor(message: string, options?: ErrorOption);
|
|
8
10
|
constructor(message: string, code: number, options?: ErrorOption);
|
package/dist/error/base.js
CHANGED
|
@@ -12,6 +12,7 @@ class MidwayError extends Error {
|
|
|
12
12
|
this.name = this.constructor.name;
|
|
13
13
|
this.code = code;
|
|
14
14
|
this.cause = options === null || options === void 0 ? void 0 : options.cause;
|
|
15
|
+
this.status = options === null || options === void 0 ? void 0 : options.status;
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
18
|
exports.MidwayError = MidwayError;
|
package/dist/error/code.d.ts
CHANGED
|
@@ -54,6 +54,7 @@ export declare enum FrameworkErrorEnum {
|
|
|
54
54
|
PARAM_TYPE = 10002,
|
|
55
55
|
DEFINITION_NOT_FOUND = 10003,
|
|
56
56
|
FEATURE_NO_LONGER_SUPPORTED = 10004,
|
|
57
|
-
|
|
57
|
+
VALIDATE_FAIL = 10005,
|
|
58
|
+
MISSING_CONFIG = 10006
|
|
58
59
|
}
|
|
59
60
|
//# sourceMappingURL=code.d.ts.map
|
package/dist/error/code.js
CHANGED
|
@@ -59,6 +59,7 @@ var FrameworkErrorEnum;
|
|
|
59
59
|
FrameworkErrorEnum[FrameworkErrorEnum["PARAM_TYPE"] = 10002] = "PARAM_TYPE";
|
|
60
60
|
FrameworkErrorEnum[FrameworkErrorEnum["DEFINITION_NOT_FOUND"] = 10003] = "DEFINITION_NOT_FOUND";
|
|
61
61
|
FrameworkErrorEnum[FrameworkErrorEnum["FEATURE_NO_LONGER_SUPPORTED"] = 10004] = "FEATURE_NO_LONGER_SUPPORTED";
|
|
62
|
-
FrameworkErrorEnum[FrameworkErrorEnum["
|
|
62
|
+
FrameworkErrorEnum[FrameworkErrorEnum["VALIDATE_FAIL"] = 10005] = "VALIDATE_FAIL";
|
|
63
|
+
FrameworkErrorEnum[FrameworkErrorEnum["MISSING_CONFIG"] = 10006] = "MISSING_CONFIG";
|
|
63
64
|
})(FrameworkErrorEnum = exports.FrameworkErrorEnum || (exports.FrameworkErrorEnum = {}));
|
|
64
65
|
//# sourceMappingURL=code.js.map
|
|
@@ -15,7 +15,10 @@ export declare class MidwayDefinitionNotFoundError extends MidwayError {
|
|
|
15
15
|
export declare class MidwayFeatureNoLongerSupportedError extends MidwayError {
|
|
16
16
|
constructor(message?: string);
|
|
17
17
|
}
|
|
18
|
-
export declare class
|
|
19
|
-
constructor();
|
|
18
|
+
export declare class MidwayValidationError extends MidwayError {
|
|
19
|
+
constructor(message: any, status: any, cause: any);
|
|
20
|
+
}
|
|
21
|
+
export declare class MidwayConfigMissingError extends MidwayError {
|
|
22
|
+
constructor(configKey: string);
|
|
20
23
|
}
|
|
21
24
|
//# sourceMappingURL=framework.d.ts.map
|
package/dist/error/framework.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.MidwayConfigMissingError = exports.MidwayValidationError = exports.MidwayFeatureNoLongerSupportedError = exports.MidwayDefinitionNotFoundError = exports.MidwayParameterError = exports.MidwayCommonError = void 0;
|
|
4
4
|
const base_1 = require("./base");
|
|
5
5
|
const code_1 = require("./code");
|
|
6
6
|
class MidwayCommonError extends base_1.MidwayError {
|
|
@@ -40,10 +40,19 @@ class MidwayFeatureNoLongerSupportedError extends base_1.MidwayError {
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
exports.MidwayFeatureNoLongerSupportedError = MidwayFeatureNoLongerSupportedError;
|
|
43
|
-
class
|
|
44
|
-
constructor() {
|
|
45
|
-
super(
|
|
43
|
+
class MidwayValidationError extends base_1.MidwayError {
|
|
44
|
+
constructor(message, status, cause) {
|
|
45
|
+
super(message, code_1.FrameworkErrorEnum.VALIDATE_FAIL, {
|
|
46
|
+
status,
|
|
47
|
+
cause,
|
|
48
|
+
});
|
|
46
49
|
}
|
|
47
50
|
}
|
|
48
|
-
exports.
|
|
51
|
+
exports.MidwayValidationError = MidwayValidationError;
|
|
52
|
+
class MidwayConfigMissingError extends base_1.MidwayError {
|
|
53
|
+
constructor(configKey) {
|
|
54
|
+
super(`Can't found config key "${configKey}" in your config, please set it first`, code_1.FrameworkErrorEnum.MISSING_CONFIG);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.MidwayConfigMissingError = MidwayConfigMissingError;
|
|
49
58
|
//# sourceMappingURL=framework.js.map
|
package/dist/error/http.d.ts
CHANGED
package/dist/error/http.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.http = exports.GatewayTimeoutError = exports.ServiceUnavailableError = exports.BadGatewayError = exports.InternalServerErrorError = exports.UnprocessableError = exports.UnsupportedMediaTypeError = exports.PayloadTooLargeError = exports.GoneError = exports.ConflictError = exports.RequestTimeoutError = exports.NotAcceptableError = exports.ForbiddenError = exports.NotFoundError = exports.UnauthorizedError = exports.BadRequestError = exports.HttpError = void 0;
|
|
4
4
|
const code_1 = require("./code");
|
|
5
|
-
|
|
5
|
+
const base_1 = require("./base");
|
|
6
|
+
class HttpError extends base_1.MidwayError {
|
|
6
7
|
constructor(response, status) {
|
|
7
|
-
super();
|
|
8
|
-
this.message = typeof response === 'string' ? response : response.message;
|
|
8
|
+
super(typeof response === 'string' ? response : response.message);
|
|
9
9
|
this.status = status;
|
|
10
10
|
this.name = this.constructor.name;
|
|
11
11
|
}
|
package/dist/error/index.d.ts
CHANGED
package/dist/error/index.js
CHANGED
|
@@ -10,6 +10,7 @@ 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
|
+
__exportStar(require("./base"), exports);
|
|
13
14
|
__exportStar(require("./http"), exports);
|
|
14
15
|
__exportStar(require("./framework"), exports);
|
|
15
16
|
//# sourceMappingURL=index.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -4,12 +4,11 @@ export { MidwayRequestContainer } from './context/requestContainer';
|
|
|
4
4
|
export { BaseFramework } from './baseFramework';
|
|
5
5
|
export * from './context/providerWrapper';
|
|
6
6
|
export * from './common/constants';
|
|
7
|
-
export { safelyGet, safeRequire, delegateTargetPrototypeMethod, delegateTargetMethod, delegateTargetProperties, } from './util/';
|
|
7
|
+
export { safelyGet, safeRequire, delegateTargetPrototypeMethod, delegateTargetMethod, delegateTargetProperties, deprecatedOutput, transformRequestObjectByType, pathMatching, wrapMiddleware, } from './util/';
|
|
8
8
|
export * from './util/pathFileUtil';
|
|
9
9
|
export * from './util/webRouterParam';
|
|
10
|
-
export * from './
|
|
11
|
-
export * from './
|
|
12
|
-
export { plainToClass, classToPlain } from 'class-transformer';
|
|
10
|
+
export * from './common/webRouterCollector';
|
|
11
|
+
export * from './common/triggerCollector';
|
|
13
12
|
export { createConfiguration } from './functional/configuration';
|
|
14
13
|
export { MidwayConfigService } from './service/configService';
|
|
15
14
|
export { MidwayEnvironmentService } from './service/environmentService';
|
|
@@ -22,12 +21,13 @@ export { MidwayMiddlewareService } from './service/middlewareService';
|
|
|
22
21
|
export { MidwayDecoratorService } from './service/decoratorService';
|
|
23
22
|
export * from './service/pipelineService';
|
|
24
23
|
export * from './util/contextUtil';
|
|
25
|
-
export * from './
|
|
26
|
-
export * from './
|
|
27
|
-
export * from './
|
|
28
|
-
export * from './
|
|
24
|
+
export * from './common/serviceFactory';
|
|
25
|
+
export * from './common/fileDetector';
|
|
26
|
+
export * from './common/webGenerator';
|
|
27
|
+
export * from './common/middlewareManager';
|
|
29
28
|
export * from './util/pathToRegexp';
|
|
30
|
-
export * from './
|
|
29
|
+
export * from './common/filterManager';
|
|
30
|
+
export * from './common/applicationManager';
|
|
31
31
|
export * from './setup';
|
|
32
32
|
export * from './error';
|
|
33
33
|
/**
|
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@ 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.MidwayFrameworkType = exports.MidwayDecoratorService = exports.MidwayMiddlewareService = exports.MidwayLifeCycleService = exports.MidwayAspectService = exports.MidwayFrameworkService = exports.MidwayLoggerService = exports.MidwayInformationService = exports.MidwayEnvironmentService = exports.MidwayConfigService = exports.createConfiguration = exports.
|
|
13
|
+
exports.MidwayFrameworkType = exports.MidwayDecoratorService = exports.MidwayMiddlewareService = exports.MidwayLifeCycleService = exports.MidwayAspectService = exports.MidwayFrameworkService = exports.MidwayLoggerService = exports.MidwayInformationService = exports.MidwayEnvironmentService = exports.MidwayConfigService = exports.createConfiguration = exports.wrapMiddleware = exports.pathMatching = exports.transformRequestObjectByType = exports.deprecatedOutput = exports.delegateTargetProperties = exports.delegateTargetMethod = exports.delegateTargetPrototypeMethod = exports.safeRequire = exports.safelyGet = exports.BaseFramework = exports.MidwayRequestContainer = void 0;
|
|
14
14
|
__exportStar(require("./interface"), exports);
|
|
15
15
|
__exportStar(require("./context/container"), exports);
|
|
16
16
|
var requestContainer_1 = require("./context/requestContainer");
|
|
@@ -25,13 +25,14 @@ Object.defineProperty(exports, "safeRequire", { enumerable: true, get: function
|
|
|
25
25
|
Object.defineProperty(exports, "delegateTargetPrototypeMethod", { enumerable: true, get: function () { return util_1.delegateTargetPrototypeMethod; } });
|
|
26
26
|
Object.defineProperty(exports, "delegateTargetMethod", { enumerable: true, get: function () { return util_1.delegateTargetMethod; } });
|
|
27
27
|
Object.defineProperty(exports, "delegateTargetProperties", { enumerable: true, get: function () { return util_1.delegateTargetProperties; } });
|
|
28
|
+
Object.defineProperty(exports, "deprecatedOutput", { enumerable: true, get: function () { return util_1.deprecatedOutput; } });
|
|
29
|
+
Object.defineProperty(exports, "transformRequestObjectByType", { enumerable: true, get: function () { return util_1.transformRequestObjectByType; } });
|
|
30
|
+
Object.defineProperty(exports, "pathMatching", { enumerable: true, get: function () { return util_1.pathMatching; } });
|
|
31
|
+
Object.defineProperty(exports, "wrapMiddleware", { enumerable: true, get: function () { return util_1.wrapMiddleware; } });
|
|
28
32
|
__exportStar(require("./util/pathFileUtil"), exports);
|
|
29
33
|
__exportStar(require("./util/webRouterParam"), exports);
|
|
30
|
-
__exportStar(require("./
|
|
31
|
-
__exportStar(require("./
|
|
32
|
-
var class_transformer_1 = require("class-transformer");
|
|
33
|
-
Object.defineProperty(exports, "plainToClass", { enumerable: true, get: function () { return class_transformer_1.plainToClass; } });
|
|
34
|
-
Object.defineProperty(exports, "classToPlain", { enumerable: true, get: function () { return class_transformer_1.classToPlain; } });
|
|
34
|
+
__exportStar(require("./common/webRouterCollector"), exports);
|
|
35
|
+
__exportStar(require("./common/triggerCollector"), exports);
|
|
35
36
|
var configuration_1 = require("./functional/configuration");
|
|
36
37
|
Object.defineProperty(exports, "createConfiguration", { enumerable: true, get: function () { return configuration_1.createConfiguration; } });
|
|
37
38
|
var configService_1 = require("./service/configService");
|
|
@@ -54,12 +55,13 @@ var decoratorService_1 = require("./service/decoratorService");
|
|
|
54
55
|
Object.defineProperty(exports, "MidwayDecoratorService", { enumerable: true, get: function () { return decoratorService_1.MidwayDecoratorService; } });
|
|
55
56
|
__exportStar(require("./service/pipelineService"), exports);
|
|
56
57
|
__exportStar(require("./util/contextUtil"), exports);
|
|
57
|
-
__exportStar(require("./
|
|
58
|
-
__exportStar(require("./
|
|
59
|
-
__exportStar(require("./
|
|
60
|
-
__exportStar(require("./
|
|
58
|
+
__exportStar(require("./common/serviceFactory"), exports);
|
|
59
|
+
__exportStar(require("./common/fileDetector"), exports);
|
|
60
|
+
__exportStar(require("./common/webGenerator"), exports);
|
|
61
|
+
__exportStar(require("./common/middlewareManager"), exports);
|
|
61
62
|
__exportStar(require("./util/pathToRegexp"), exports);
|
|
62
|
-
__exportStar(require("./
|
|
63
|
+
__exportStar(require("./common/filterManager"), exports);
|
|
64
|
+
__exportStar(require("./common/applicationManager"), exports);
|
|
63
65
|
__exportStar(require("./setup"), exports);
|
|
64
66
|
__exportStar(require("./error"), exports);
|
|
65
67
|
/**
|
package/dist/interface.d.ts
CHANGED
|
@@ -2,15 +2,28 @@
|
|
|
2
2
|
import { ObjectIdentifier, IManagedInstance, IMethodAspect, ScopeEnum, FrameworkType } from '@midwayjs/decorator';
|
|
3
3
|
import { ILogger, LoggerOptions } from '@midwayjs/logger';
|
|
4
4
|
import * as EventEmitter from 'events';
|
|
5
|
-
import { ContextMiddlewareManager } from './
|
|
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>;
|
|
6
19
|
/**
|
|
7
20
|
* 生命周期定义
|
|
8
21
|
*/
|
|
9
22
|
export interface ILifeCycle extends Partial<IObjectLifeCycle> {
|
|
10
|
-
onConfigLoad?(container: IMidwayContainer,
|
|
11
|
-
onReady?(container: IMidwayContainer,
|
|
12
|
-
onServerReady?(container: IMidwayContainer,
|
|
13
|
-
onStop?(container: IMidwayContainer,
|
|
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>;
|
|
14
27
|
}
|
|
15
28
|
export declare type ObjectContext = {
|
|
16
29
|
originName?: string;
|
|
@@ -172,6 +185,7 @@ export declare type ParameterHandlerFunction = (options: {
|
|
|
172
185
|
propertyName: string;
|
|
173
186
|
metadata: any;
|
|
174
187
|
originArgs: Array<any>;
|
|
188
|
+
originParamType: any;
|
|
175
189
|
parameterIndex: number;
|
|
176
190
|
}) => IMethodAspect;
|
|
177
191
|
export interface IIdentifierRelationShip {
|
|
@@ -260,30 +274,32 @@ export interface Context {
|
|
|
260
274
|
getAttr<T>(key: string): T;
|
|
261
275
|
}
|
|
262
276
|
export declare type IMidwayContext<FrameworkContext = unknown> = Context & FrameworkContext;
|
|
277
|
+
export declare type NextFunction = () => Promise<any>;
|
|
263
278
|
/**
|
|
264
279
|
* Common middleware definition
|
|
265
280
|
*/
|
|
266
|
-
export interface IMiddleware<
|
|
267
|
-
resolve: () => FunctionMiddleware<
|
|
268
|
-
match?: () => boolean;
|
|
269
|
-
ignore?: () => boolean;
|
|
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;
|
|
270
285
|
}
|
|
271
|
-
export declare type FunctionMiddleware<
|
|
272
|
-
export declare type ClassMiddleware<
|
|
273
|
-
export declare type CommonMiddleware<
|
|
274
|
-
export declare type CommonMiddlewareUnion<
|
|
275
|
-
export declare type MiddlewareRespond<
|
|
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<{
|
|
276
291
|
result: any;
|
|
277
292
|
error: Error | undefined;
|
|
278
293
|
}>;
|
|
279
294
|
/**
|
|
280
295
|
* Common Exception Filter definition
|
|
281
296
|
*/
|
|
282
|
-
export interface
|
|
283
|
-
catch(err: Error, ctx:
|
|
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;
|
|
284
300
|
}
|
|
285
|
-
export declare type
|
|
286
|
-
export interface IMidwayBaseApplication<
|
|
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> {
|
|
287
303
|
/**
|
|
288
304
|
* Get a base directory for project, with src or dist
|
|
289
305
|
*/
|
|
@@ -336,7 +352,7 @@ export interface IMidwayBaseApplication<T extends IMidwayContext = IMidwayContex
|
|
|
336
352
|
* create a context with RequestContainer
|
|
337
353
|
* @param args
|
|
338
354
|
*/
|
|
339
|
-
createAnonymousContext(...args: any[]):
|
|
355
|
+
createAnonymousContext(...args: any[]): CTX;
|
|
340
356
|
/**
|
|
341
357
|
* Set a context logger class to change default context logger format
|
|
342
358
|
* @param BaseContextLoggerClass
|
|
@@ -362,16 +378,16 @@ export interface IMidwayBaseApplication<T extends IMidwayContext = IMidwayContex
|
|
|
362
378
|
* add global filter to app
|
|
363
379
|
* @param Middleware
|
|
364
380
|
*/
|
|
365
|
-
useMiddleware<R
|
|
381
|
+
useMiddleware<R, N>(Middleware: CommonMiddlewareUnion<CTX, R, N>): void;
|
|
366
382
|
/**
|
|
367
383
|
* get global middleware
|
|
368
384
|
*/
|
|
369
|
-
getMiddleware<R
|
|
385
|
+
getMiddleware<R, N>(): ContextMiddlewareManager<CTX, R, N>;
|
|
370
386
|
/**
|
|
371
387
|
* add exception filter
|
|
372
388
|
* @param Filter
|
|
373
389
|
*/
|
|
374
|
-
useFilter(Filter:
|
|
390
|
+
useFilter<R, N>(Filter: CommonFilterUnion<CTX, R, N>): void;
|
|
375
391
|
}
|
|
376
392
|
export declare type IMidwayApplication<T extends IMidwayContext = IMidwayContext, FrameworkApplication = unknown> = IMidwayBaseApplication<T> & FrameworkApplication;
|
|
377
393
|
export interface IMidwayBootstrapOptions {
|
|
@@ -384,9 +400,9 @@ export interface IMidwayBootstrapOptions {
|
|
|
384
400
|
moduleDetector?: 'file' | IFileDetector | false;
|
|
385
401
|
logger?: boolean | ILogger;
|
|
386
402
|
ignore?: string[];
|
|
387
|
-
globalConfig?: {
|
|
403
|
+
globalConfig?: Array<{
|
|
388
404
|
[environmentName: string]: Record<string, any>;
|
|
389
|
-
}
|
|
405
|
+
}> | Record<string, any>;
|
|
390
406
|
}
|
|
391
407
|
export interface IConfigurationOptions {
|
|
392
408
|
logger?: ILogger;
|
|
@@ -394,10 +410,10 @@ export interface IConfigurationOptions {
|
|
|
394
410
|
ContextLoggerClass?: any;
|
|
395
411
|
ContextLoggerApplyLogger?: string;
|
|
396
412
|
}
|
|
397
|
-
export interface IMidwayFramework<APP extends IMidwayApplication,
|
|
413
|
+
export interface IMidwayFramework<APP extends IMidwayApplication<CTX>, CTX extends IMidwayContext, CONFIG extends IConfigurationOptions, ResOrNext = unknown, Next = unknown> {
|
|
398
414
|
app: APP;
|
|
399
|
-
configurationOptions:
|
|
400
|
-
configure(options?:
|
|
415
|
+
configurationOptions: CONFIG;
|
|
416
|
+
configure(options?: CONFIG): any;
|
|
401
417
|
isEnable(): boolean;
|
|
402
418
|
initialize(options: Partial<IMidwayBootstrapOptions>): Promise<void>;
|
|
403
419
|
run(): Promise<void>;
|
|
@@ -415,9 +431,10 @@ export interface IMidwayFramework<APP extends IMidwayApplication, T extends ICon
|
|
|
415
431
|
createLogger(name: string, options: LoggerOptions): ILogger;
|
|
416
432
|
getProjectName(): string;
|
|
417
433
|
getDefaultContextLoggerClass(): any;
|
|
418
|
-
useMiddleware(Middleware: CommonMiddlewareUnion<
|
|
419
|
-
getMiddleware
|
|
420
|
-
|
|
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;
|
|
421
438
|
}
|
|
422
439
|
export declare const MIDWAY_LOGGER_WRITEABLE_DIR = "MIDWAY_LOGGER_WRITEABLE_DIR";
|
|
423
440
|
export interface MidwayAppInfo {
|
|
@@ -429,4 +446,15 @@ export interface MidwayAppInfo {
|
|
|
429
446
|
root: string;
|
|
430
447
|
env: string;
|
|
431
448
|
}
|
|
449
|
+
/**
|
|
450
|
+
* midway global config definition
|
|
451
|
+
*/
|
|
452
|
+
export interface MidwayConfig extends FileConfigOption<typeof _default> {
|
|
453
|
+
}
|
|
454
|
+
export interface TranslateOptions {
|
|
455
|
+
lang?: string;
|
|
456
|
+
group?: string;
|
|
457
|
+
args?: any;
|
|
458
|
+
}
|
|
459
|
+
export {};
|
|
432
460
|
//# sourceMappingURL=interface.d.ts.map
|
|
@@ -95,10 +95,7 @@ let MidwayConfigService = class MidwayConfigService {
|
|
|
95
95
|
// merge set
|
|
96
96
|
const target = {};
|
|
97
97
|
for (const filename of [...defaultSet, ...currentEnvSet]) {
|
|
98
|
-
let config = filename;
|
|
99
|
-
if (typeof filename === 'string') {
|
|
100
|
-
config = await this.loadConfig(filename);
|
|
101
|
-
}
|
|
98
|
+
let config = await this.loadConfig(filename);
|
|
102
99
|
if ((0, decorator_1.isFunction)(config)) {
|
|
103
100
|
// eslint-disable-next-line prefer-spread
|
|
104
101
|
config = config.apply(null, [
|
|
@@ -143,7 +140,9 @@ let MidwayConfigService = class MidwayConfigService {
|
|
|
143
140
|
return this.configuration;
|
|
144
141
|
}
|
|
145
142
|
async loadConfig(configFilename) {
|
|
146
|
-
let exports =
|
|
143
|
+
let exports = typeof configFilename === 'string'
|
|
144
|
+
? require(configFilename)
|
|
145
|
+
: configFilename;
|
|
147
146
|
if (exports && exports['default'] && Object.keys(exports).length === 1) {
|
|
148
147
|
exports = exports['default'];
|
|
149
148
|
}
|
|
@@ -24,7 +24,27 @@ let MidwayDecoratorService = class MidwayDecoratorService {
|
|
|
24
24
|
}
|
|
25
25
|
async init() {
|
|
26
26
|
// add custom method decorator listener
|
|
27
|
-
this.applicationContext.onBeforeBind(
|
|
27
|
+
this.applicationContext.onBeforeBind(Clzz => {
|
|
28
|
+
// find custom method decorator metadata, include method decorator information array
|
|
29
|
+
const methodDecoratorMetadataList = (0, decorator_1.getClassMetadata)(decorator_1.INJECT_CUSTOM_METHOD, Clzz);
|
|
30
|
+
if (methodDecoratorMetadataList) {
|
|
31
|
+
// loop it, save this order for decorator run
|
|
32
|
+
for (const meta of methodDecoratorMetadataList) {
|
|
33
|
+
const { propertyName, key, metadata } = meta;
|
|
34
|
+
// add aspect implementation first
|
|
35
|
+
this.aspectService.interceptPrototypeMethod(Clzz, propertyName, () => {
|
|
36
|
+
const methodDecoratorHandler = this.methodDecoratorMap.get(key);
|
|
37
|
+
if (!methodDecoratorHandler) {
|
|
38
|
+
throw new error_1.MidwayCommonError(`Method Decorator "${key}" handler not found, please register first.`);
|
|
39
|
+
}
|
|
40
|
+
return this.methodDecoratorMap.get(key)({
|
|
41
|
+
target: Clzz,
|
|
42
|
+
propertyName,
|
|
43
|
+
metadata,
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
28
48
|
// find custom param decorator metadata
|
|
29
49
|
const parameterDecoratorMetadata = (0, decorator_1.getClassMetadata)(decorator_1.INJECT_CUSTOM_PARAM, Clzz);
|
|
30
50
|
if (parameterDecoratorMetadata) {
|
|
@@ -42,12 +62,14 @@ let MidwayDecoratorService = class MidwayDecoratorService {
|
|
|
42
62
|
if (!parameterDecoratorHandler) {
|
|
43
63
|
throw new error_1.MidwayCommonError(`Parameter Decorator "${key}" handler not found, please register first.`);
|
|
44
64
|
}
|
|
65
|
+
const paramTypes = (0, decorator_1.getMethodParamTypes)(Clzz, propertyName);
|
|
45
66
|
newArgs[parameterIndex] = await parameterDecoratorHandler({
|
|
46
67
|
metadata,
|
|
47
68
|
propertyName,
|
|
48
69
|
parameterIndex,
|
|
49
70
|
target: Clzz,
|
|
50
71
|
originArgs: joinPoint.args,
|
|
72
|
+
originParamType: paramTypes[parameterIndex],
|
|
51
73
|
});
|
|
52
74
|
}
|
|
53
75
|
joinPoint.args = newArgs;
|
|
@@ -56,26 +78,6 @@ let MidwayDecoratorService = class MidwayDecoratorService {
|
|
|
56
78
|
});
|
|
57
79
|
}
|
|
58
80
|
}
|
|
59
|
-
// find custom method decorator metadata, include method decorator information array
|
|
60
|
-
const methodDecoratorMetadataList = (0, decorator_1.getClassMetadata)(decorator_1.INJECT_CUSTOM_METHOD, Clzz);
|
|
61
|
-
if (methodDecoratorMetadataList) {
|
|
62
|
-
// loop it, save this order for decorator run
|
|
63
|
-
for (const meta of methodDecoratorMetadataList) {
|
|
64
|
-
const { propertyName, key, metadata } = meta;
|
|
65
|
-
// add aspect implementation first
|
|
66
|
-
this.aspectService.interceptPrototypeMethod(Clzz, propertyName, () => {
|
|
67
|
-
const methodDecoratorHandler = this.methodDecoratorMap.get(key);
|
|
68
|
-
if (!methodDecoratorHandler) {
|
|
69
|
-
throw new error_1.MidwayCommonError(`Method Decorator "${key}" handler not found, please register first.`);
|
|
70
|
-
}
|
|
71
|
-
return this.methodDecoratorMap.get(key)({
|
|
72
|
-
target: Clzz,
|
|
73
|
-
propertyName,
|
|
74
|
-
metadata,
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
81
|
});
|
|
80
82
|
// add custom property decorator listener
|
|
81
83
|
this.applicationContext.onObjectCreated((instance, options) => {
|
|
@@ -93,15 +95,15 @@ let MidwayDecoratorService = class MidwayDecoratorService {
|
|
|
93
95
|
});
|
|
94
96
|
}
|
|
95
97
|
registerPropertyHandler(decoratorKey, fn) {
|
|
96
|
-
debug(`[core
|
|
98
|
+
debug(`[core]: Register property decorator key="${decoratorKey}"`);
|
|
97
99
|
this.propertyHandlerMap.set(decoratorKey, fn);
|
|
98
100
|
}
|
|
99
101
|
registerMethodHandler(decoratorKey, fn) {
|
|
100
|
-
debug(`[core
|
|
102
|
+
debug(`[core]: Register method decorator key="${decoratorKey}"`);
|
|
101
103
|
this.methodDecoratorMap.set(decoratorKey, fn);
|
|
102
104
|
}
|
|
103
105
|
registerParameterHandler(decoratorKey, fn) {
|
|
104
|
-
debug(`[core
|
|
106
|
+
debug(`[core]: Register parameter decorator key="${decoratorKey}"`);
|
|
105
107
|
this.parameterDecoratorMap.set(decoratorKey, fn);
|
|
106
108
|
}
|
|
107
109
|
/**
|
|
@@ -4,6 +4,7 @@ import { MidwayConfigService } from './configService';
|
|
|
4
4
|
import { MidwayLoggerService } from './loggerService';
|
|
5
5
|
import { MidwayDecoratorService } from './decoratorService';
|
|
6
6
|
import { MidwayAspectService } from './aspectService';
|
|
7
|
+
import { MidwayApplicationManager } from '../common/applicationManager';
|
|
7
8
|
export declare class MidwayFrameworkService {
|
|
8
9
|
readonly applicationContext: IMidwayContainer;
|
|
9
10
|
readonly globalOptions: any;
|
|
@@ -11,14 +12,15 @@ export declare class MidwayFrameworkService {
|
|
|
11
12
|
loggerService: MidwayLoggerService;
|
|
12
13
|
aspectService: MidwayAspectService;
|
|
13
14
|
decoratorService: MidwayDecoratorService;
|
|
15
|
+
applicationManager: MidwayApplicationManager;
|
|
14
16
|
constructor(applicationContext: IMidwayContainer, globalOptions: any);
|
|
15
17
|
private mainFramework;
|
|
16
|
-
private globalFrameworkMap;
|
|
17
18
|
private globalFrameworkList;
|
|
18
|
-
init(): Promise<void>;
|
|
19
|
+
protected init(): Promise<void>;
|
|
19
20
|
getMainApp(): any;
|
|
20
|
-
getMainFramework(): IMidwayFramework<any, any>;
|
|
21
|
-
getFramework(
|
|
21
|
+
getMainFramework(): IMidwayFramework<any, any, any, unknown, unknown>;
|
|
22
|
+
getFramework(namespaceOrFrameworkType: string | MidwayFrameworkType): IMidwayFramework<any, any, any, unknown, unknown>;
|
|
23
|
+
runFramework(): Promise<void>;
|
|
22
24
|
stopFramework(): Promise<void>;
|
|
23
25
|
}
|
|
24
26
|
//# sourceMappingURL=frameworkService.d.ts.map
|
|
@@ -18,6 +18,7 @@ const baseFramework_1 = require("../baseFramework");
|
|
|
18
18
|
const pipelineService_1 = require("./pipelineService");
|
|
19
19
|
const decoratorService_1 = require("./decoratorService");
|
|
20
20
|
const aspectService_1 = require("./aspectService");
|
|
21
|
+
const applicationManager_1 = require("../common/applicationManager");
|
|
21
22
|
const util = require("util");
|
|
22
23
|
const error_1 = require("../error");
|
|
23
24
|
const debug = util.debuglog('midway:debug');
|
|
@@ -25,10 +26,10 @@ let MidwayFrameworkService = class MidwayFrameworkService {
|
|
|
25
26
|
constructor(applicationContext, globalOptions) {
|
|
26
27
|
this.applicationContext = applicationContext;
|
|
27
28
|
this.globalOptions = globalOptions;
|
|
28
|
-
this.globalFrameworkMap = new WeakMap();
|
|
29
29
|
this.globalFrameworkList = [];
|
|
30
30
|
}
|
|
31
31
|
async init() {
|
|
32
|
+
var _a;
|
|
32
33
|
// register base config hook
|
|
33
34
|
this.decoratorService.registerPropertyHandler(decorator_1.CONFIG_KEY, (propertyName, meta) => {
|
|
34
35
|
var _a;
|
|
@@ -51,7 +52,7 @@ let MidwayFrameworkService = class MidwayFrameworkService {
|
|
|
51
52
|
let frameworks = (0, decorator_1.listModule)(decorator_1.FRAMEWORK_KEY);
|
|
52
53
|
// filter proto
|
|
53
54
|
frameworks = filterProtoFramework(frameworks);
|
|
54
|
-
debug(`[core
|
|
55
|
+
debug(`[core]: Found Framework length = ${frameworks.length}`);
|
|
55
56
|
if (frameworks.length) {
|
|
56
57
|
for (const frameworkClz of frameworks) {
|
|
57
58
|
const frameworkInstance = await this.applicationContext.getAsync(frameworkClz, [this.applicationContext]);
|
|
@@ -62,24 +63,24 @@ let MidwayFrameworkService = class MidwayFrameworkService {
|
|
|
62
63
|
applicationContext: this.applicationContext,
|
|
63
64
|
...this.globalOptions,
|
|
64
65
|
});
|
|
65
|
-
debug(`[core
|
|
66
|
+
debug(`[core]: Found Framework "${frameworkInstance.getFrameworkName()}" and initialize.`);
|
|
66
67
|
}
|
|
67
68
|
else {
|
|
68
|
-
debug(`[core
|
|
69
|
+
debug(`[core]: Found Framework "${frameworkInstance.getFrameworkName()}" and delay initialize.`);
|
|
69
70
|
}
|
|
70
71
|
// app init
|
|
71
|
-
this.
|
|
72
|
+
const definition = this.applicationContext.registry.getDefinition((0, decorator_1.getProviderUUId)(frameworkClz));
|
|
73
|
+
this.applicationManager.addFramework((_a = definition === null || definition === void 0 ? void 0 : definition.namespace) !== null && _a !== void 0 ? _a : frameworkInstance.getFrameworkName(), frameworkInstance);
|
|
72
74
|
this.globalFrameworkList.push(frameworkInstance);
|
|
73
75
|
}
|
|
74
76
|
// register @App decorator handler
|
|
75
77
|
this.decoratorService.registerPropertyHandler(decorator_1.APPLICATION_KEY, (propertyName, mete) => {
|
|
76
78
|
if (mete.type) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
79
|
+
const framework = this.applicationManager.getApplication(mete.type);
|
|
80
|
+
if (!framework) {
|
|
81
81
|
throw new error_1.MidwayCommonError(`Framework ${mete.type} not Found`);
|
|
82
82
|
}
|
|
83
|
+
return framework;
|
|
83
84
|
}
|
|
84
85
|
else {
|
|
85
86
|
return this.getMainApp();
|
|
@@ -107,8 +108,18 @@ let MidwayFrameworkService = class MidwayFrameworkService {
|
|
|
107
108
|
getMainFramework() {
|
|
108
109
|
return this.mainFramework;
|
|
109
110
|
}
|
|
110
|
-
getFramework(
|
|
111
|
-
return this.
|
|
111
|
+
getFramework(namespaceOrFrameworkType) {
|
|
112
|
+
return this.applicationManager.getFramework(namespaceOrFrameworkType);
|
|
113
|
+
}
|
|
114
|
+
async runFramework() {
|
|
115
|
+
for (const frameworkInstance of this.globalFrameworkList) {
|
|
116
|
+
// if enable, just init framework
|
|
117
|
+
if (frameworkInstance.isEnable()) {
|
|
118
|
+
// app init
|
|
119
|
+
await frameworkInstance.run();
|
|
120
|
+
debug(`[core]: Found Framework "${frameworkInstance.getFrameworkName()}" and run.`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
112
123
|
}
|
|
113
124
|
async stopFramework() {
|
|
114
125
|
await Promise.all(Array.from(this.globalFrameworkList).map(frameworkInstance => {
|
|
@@ -132,6 +143,10 @@ __decorate([
|
|
|
132
143
|
(0, decorator_1.Inject)(),
|
|
133
144
|
__metadata("design:type", decoratorService_1.MidwayDecoratorService)
|
|
134
145
|
], MidwayFrameworkService.prototype, "decoratorService", void 0);
|
|
146
|
+
__decorate([
|
|
147
|
+
(0, decorator_1.Inject)(),
|
|
148
|
+
__metadata("design:type", applicationManager_1.MidwayApplicationManager)
|
|
149
|
+
], MidwayFrameworkService.prototype, "applicationManager", void 0);
|
|
135
150
|
__decorate([
|
|
136
151
|
(0, decorator_1.Init)(),
|
|
137
152
|
__metadata("design:type", Function),
|