@midwayjs/core 3.0.0-alpha.43 → 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 +129 -0
- package/README.md +1 -1
- package/dist/baseFramework.d.ts +56 -22
- package/dist/baseFramework.js +156 -204
- 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 +14 -8
- 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 +7 -5
- 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 +9 -4
- package/dist/{util → common}/webRouterCollector.js +56 -29
- package/dist/config/config.default.d.ts +7 -0
- package/dist/config/config.default.js +28 -0
- package/dist/context/container.d.ts +46 -40
- package/dist/context/container.js +125 -104
- package/dist/context/managedResolverFactory.d.ts +3 -16
- package/dist/context/managedResolverFactory.js +77 -77
- package/dist/context/requestContainer.d.ts +0 -2
- package/dist/context/requestContainer.js +4 -18
- package/dist/definitions/functionDefinition.d.ts +3 -2
- package/dist/definitions/objectDefinition.d.ts +3 -2
- package/dist/definitions/properties.d.ts +2 -13
- package/dist/definitions/properties.js +3 -56
- 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 +3 -3
- package/dist/functional/configuration.js +3 -3
- package/dist/index.d.ts +24 -11
- package/dist/index.js +36 -14
- package/dist/interface.d.ts +252 -157
- package/dist/interface.js +9 -1
- package/dist/service/aspectService.d.ts +11 -14
- package/dist/service/aspectService.js +114 -170
- package/dist/service/configService.d.ts +10 -8
- package/dist/service/configService.js +56 -33
- package/dist/service/decoratorService.d.ts +23 -0
- package/dist/service/decoratorService.js +149 -0
- package/dist/service/environmentService.js +13 -2
- 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 +39 -8
- 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 +1 -1
- package/dist/util/index.d.ts +64 -0
- package/dist/util/index.js +192 -4
- 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 +9 -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 -17
- package/dist/common/reflectTool.js +0 -83
- 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 -11
- 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 -15
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
2
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
9
|
exports.MidwayEnvironmentService = void 0;
|
|
4
10
|
const util_1 = require("../util");
|
|
5
|
-
|
|
11
|
+
const decorator_1 = require("@midwayjs/decorator");
|
|
12
|
+
let MidwayEnvironmentService = class MidwayEnvironmentService {
|
|
6
13
|
getCurrentEnvironment() {
|
|
7
14
|
if (!this.environment) {
|
|
8
15
|
this.environment = (0, util_1.getCurrentEnvironment)();
|
|
@@ -15,6 +22,10 @@ class MidwayEnvironmentService {
|
|
|
15
22
|
isDevelopmentEnvironment() {
|
|
16
23
|
return (0, util_1.isDevelopmentEnvironment)(this.environment);
|
|
17
24
|
}
|
|
18
|
-
}
|
|
25
|
+
};
|
|
26
|
+
MidwayEnvironmentService = __decorate([
|
|
27
|
+
(0, decorator_1.Provide)(),
|
|
28
|
+
(0, decorator_1.Scope)(decorator_1.ScopeEnum.Singleton)
|
|
29
|
+
], MidwayEnvironmentService);
|
|
19
30
|
exports.MidwayEnvironmentService = MidwayEnvironmentService;
|
|
20
31
|
//# sourceMappingURL=environmentService.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { MidwayFrameworkType } from '@midwayjs/decorator';
|
|
2
|
+
import { IMidwayContainer, IMidwayFramework } from '../interface';
|
|
3
|
+
import { MidwayConfigService } from './configService';
|
|
4
|
+
import { MidwayLoggerService } from './loggerService';
|
|
5
|
+
import { MidwayDecoratorService } from './decoratorService';
|
|
6
|
+
import { MidwayAspectService } from './aspectService';
|
|
7
|
+
import { MidwayApplicationManager } from '../common/applicationManager';
|
|
8
|
+
export declare class MidwayFrameworkService {
|
|
9
|
+
readonly applicationContext: IMidwayContainer;
|
|
10
|
+
readonly globalOptions: any;
|
|
11
|
+
configService: MidwayConfigService;
|
|
12
|
+
loggerService: MidwayLoggerService;
|
|
13
|
+
aspectService: MidwayAspectService;
|
|
14
|
+
decoratorService: MidwayDecoratorService;
|
|
15
|
+
applicationManager: MidwayApplicationManager;
|
|
16
|
+
constructor(applicationContext: IMidwayContainer, globalOptions: any);
|
|
17
|
+
private mainFramework;
|
|
18
|
+
private globalFrameworkList;
|
|
19
|
+
protected init(): Promise<void>;
|
|
20
|
+
getMainApp(): any;
|
|
21
|
+
getMainFramework(): IMidwayFramework<any, any, any, unknown, unknown>;
|
|
22
|
+
getFramework(namespaceOrFrameworkType: string | MidwayFrameworkType): IMidwayFramework<any, any, any, unknown, unknown>;
|
|
23
|
+
runFramework(): Promise<void>;
|
|
24
|
+
stopFramework(): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=frameworkService.d.ts.map
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.MidwayFrameworkService = void 0;
|
|
13
|
+
const decorator_1 = require("@midwayjs/decorator");
|
|
14
|
+
const interface_1 = require("../interface");
|
|
15
|
+
const configService_1 = require("./configService");
|
|
16
|
+
const loggerService_1 = require("./loggerService");
|
|
17
|
+
const baseFramework_1 = require("../baseFramework");
|
|
18
|
+
const pipelineService_1 = require("./pipelineService");
|
|
19
|
+
const decoratorService_1 = require("./decoratorService");
|
|
20
|
+
const aspectService_1 = require("./aspectService");
|
|
21
|
+
const applicationManager_1 = require("../common/applicationManager");
|
|
22
|
+
const util = require("util");
|
|
23
|
+
const error_1 = require("../error");
|
|
24
|
+
const debug = util.debuglog('midway:debug');
|
|
25
|
+
let MidwayFrameworkService = class MidwayFrameworkService {
|
|
26
|
+
constructor(applicationContext, globalOptions) {
|
|
27
|
+
this.applicationContext = applicationContext;
|
|
28
|
+
this.globalOptions = globalOptions;
|
|
29
|
+
this.globalFrameworkList = [];
|
|
30
|
+
}
|
|
31
|
+
async init() {
|
|
32
|
+
var _a;
|
|
33
|
+
// register base config hook
|
|
34
|
+
this.decoratorService.registerPropertyHandler(decorator_1.CONFIG_KEY, (propertyName, meta) => {
|
|
35
|
+
var _a;
|
|
36
|
+
if (meta.identifier === decorator_1.ALL) {
|
|
37
|
+
return this.configService.getConfiguration();
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
return this.configService.getConfiguration((_a = meta.identifier) !== null && _a !== void 0 ? _a : propertyName);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
// register @Logger decorator handler
|
|
44
|
+
this.decoratorService.registerPropertyHandler(decorator_1.LOGGER_KEY, (propertyName, meta) => {
|
|
45
|
+
var _a;
|
|
46
|
+
return this.loggerService.getLogger((_a = meta.identifier) !== null && _a !== void 0 ? _a : propertyName);
|
|
47
|
+
});
|
|
48
|
+
this.decoratorService.registerPropertyHandler(decorator_1.PIPELINE_IDENTIFIER, (key, meta, instance) => {
|
|
49
|
+
var _a, _b;
|
|
50
|
+
return new pipelineService_1.MidwayPipelineService((_b = (_a = instance[interface_1.REQUEST_OBJ_CTX_KEY]) === null || _a === void 0 ? void 0 : _a.requestContext) !== null && _b !== void 0 ? _b : this.applicationContext, meta.valves);
|
|
51
|
+
});
|
|
52
|
+
let frameworks = (0, decorator_1.listModule)(decorator_1.FRAMEWORK_KEY);
|
|
53
|
+
// filter proto
|
|
54
|
+
frameworks = filterProtoFramework(frameworks);
|
|
55
|
+
debug(`[core]: Found Framework length = ${frameworks.length}`);
|
|
56
|
+
if (frameworks.length) {
|
|
57
|
+
for (const frameworkClz of frameworks) {
|
|
58
|
+
const frameworkInstance = await this.applicationContext.getAsync(frameworkClz, [this.applicationContext]);
|
|
59
|
+
// if enable, just init framework
|
|
60
|
+
if (frameworkInstance.isEnable()) {
|
|
61
|
+
// app init
|
|
62
|
+
await frameworkInstance.initialize({
|
|
63
|
+
applicationContext: this.applicationContext,
|
|
64
|
+
...this.globalOptions,
|
|
65
|
+
});
|
|
66
|
+
debug(`[core]: Found Framework "${frameworkInstance.getFrameworkName()}" and initialize.`);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
debug(`[core]: Found Framework "${frameworkInstance.getFrameworkName()}" and delay initialize.`);
|
|
70
|
+
}
|
|
71
|
+
// app init
|
|
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);
|
|
74
|
+
this.globalFrameworkList.push(frameworkInstance);
|
|
75
|
+
}
|
|
76
|
+
// register @App decorator handler
|
|
77
|
+
this.decoratorService.registerPropertyHandler(decorator_1.APPLICATION_KEY, (propertyName, mete) => {
|
|
78
|
+
if (mete.type) {
|
|
79
|
+
const framework = this.applicationManager.getApplication(mete.type);
|
|
80
|
+
if (!framework) {
|
|
81
|
+
throw new error_1.MidwayCommonError(`Framework ${mete.type} not Found`);
|
|
82
|
+
}
|
|
83
|
+
return framework;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
return this.getMainApp();
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
this.decoratorService.registerPropertyHandler(decorator_1.PLUGIN_KEY, (key, target) => {
|
|
90
|
+
return this.getMainApp()[key];
|
|
91
|
+
});
|
|
92
|
+
global['MIDWAY_MAIN_FRAMEWORK'] = this.mainFramework =
|
|
93
|
+
this.globalFrameworkList[0];
|
|
94
|
+
}
|
|
95
|
+
// init aspect module
|
|
96
|
+
await this.aspectService.loadAspect();
|
|
97
|
+
// some preload module init
|
|
98
|
+
const modules = (0, decorator_1.listPreloadModule)();
|
|
99
|
+
for (const module of modules) {
|
|
100
|
+
// preload init context
|
|
101
|
+
await this.applicationContext.getAsync(module);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
getMainApp() {
|
|
105
|
+
var _a;
|
|
106
|
+
return (_a = this.mainFramework) === null || _a === void 0 ? void 0 : _a.getApplication();
|
|
107
|
+
}
|
|
108
|
+
getMainFramework() {
|
|
109
|
+
return this.mainFramework;
|
|
110
|
+
}
|
|
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
|
+
}
|
|
123
|
+
}
|
|
124
|
+
async stopFramework() {
|
|
125
|
+
await Promise.all(Array.from(this.globalFrameworkList).map(frameworkInstance => {
|
|
126
|
+
return frameworkInstance.stop();
|
|
127
|
+
}));
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
__decorate([
|
|
131
|
+
(0, decorator_1.Inject)(),
|
|
132
|
+
__metadata("design:type", configService_1.MidwayConfigService)
|
|
133
|
+
], MidwayFrameworkService.prototype, "configService", void 0);
|
|
134
|
+
__decorate([
|
|
135
|
+
(0, decorator_1.Inject)(),
|
|
136
|
+
__metadata("design:type", loggerService_1.MidwayLoggerService)
|
|
137
|
+
], MidwayFrameworkService.prototype, "loggerService", void 0);
|
|
138
|
+
__decorate([
|
|
139
|
+
(0, decorator_1.Inject)(),
|
|
140
|
+
__metadata("design:type", aspectService_1.MidwayAspectService)
|
|
141
|
+
], MidwayFrameworkService.prototype, "aspectService", void 0);
|
|
142
|
+
__decorate([
|
|
143
|
+
(0, decorator_1.Inject)(),
|
|
144
|
+
__metadata("design:type", decoratorService_1.MidwayDecoratorService)
|
|
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);
|
|
150
|
+
__decorate([
|
|
151
|
+
(0, decorator_1.Init)(),
|
|
152
|
+
__metadata("design:type", Function),
|
|
153
|
+
__metadata("design:paramtypes", []),
|
|
154
|
+
__metadata("design:returntype", Promise)
|
|
155
|
+
], MidwayFrameworkService.prototype, "init", null);
|
|
156
|
+
MidwayFrameworkService = __decorate([
|
|
157
|
+
(0, decorator_1.Provide)(),
|
|
158
|
+
(0, decorator_1.Scope)(decorator_1.ScopeEnum.Singleton),
|
|
159
|
+
__metadata("design:paramtypes", [Object, Object])
|
|
160
|
+
], MidwayFrameworkService);
|
|
161
|
+
exports.MidwayFrameworkService = MidwayFrameworkService;
|
|
162
|
+
function filterProtoFramework(frameworks) {
|
|
163
|
+
const frameworkProtoArr = [];
|
|
164
|
+
// 这里把继承的框架父类都找出来,然后排除掉,只取第一层
|
|
165
|
+
for (const framework of frameworks) {
|
|
166
|
+
let proto = Object.getPrototypeOf(framework);
|
|
167
|
+
while (proto.name && proto.name !== baseFramework_1.BaseFramework.name) {
|
|
168
|
+
frameworkProtoArr.push(proto);
|
|
169
|
+
proto = Object.getPrototypeOf(proto);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return frameworks.filter(framework => {
|
|
173
|
+
return !frameworkProtoArr.includes(framework);
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=frameworkService.js.map
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { IInformationService } from '../interface';
|
|
2
2
|
export declare class MidwayInformationService implements IInformationService {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
baseDir?: string;
|
|
8
|
-
appDir?: string;
|
|
9
|
-
});
|
|
3
|
+
private pkg;
|
|
4
|
+
protected appDir: string;
|
|
5
|
+
protected baseDir: string;
|
|
6
|
+
protected init(): void;
|
|
10
7
|
getAppDir(): string;
|
|
11
8
|
getBaseDir(): string;
|
|
12
9
|
getHome(): string;
|
|
@@ -1,16 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.MidwayInformationService = void 0;
|
|
4
13
|
const util_1 = require("../util");
|
|
5
14
|
const path_1 = require("path");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
this.
|
|
10
|
-
|
|
11
|
-
|
|
15
|
+
const decorator_1 = require("@midwayjs/decorator");
|
|
16
|
+
let MidwayInformationService = class MidwayInformationService {
|
|
17
|
+
init() {
|
|
18
|
+
if (this.baseDir) {
|
|
19
|
+
if (!this.appDir) {
|
|
20
|
+
this.appDir = (0, path_1.dirname)(this.baseDir);
|
|
21
|
+
}
|
|
22
|
+
this.pkg = (0, util_1.safeRequire)((0, path_1.join)(this.appDir, 'package.json')) || {};
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
this.pkg = {};
|
|
12
26
|
}
|
|
13
|
-
this.pkg = (0, util_1.safeRequire)((0, path_1.join)(this.appDir, 'package.json')) || {};
|
|
14
27
|
}
|
|
15
28
|
getAppDir() {
|
|
16
29
|
return this.appDir;
|
|
@@ -32,6 +45,24 @@ class MidwayInformationService {
|
|
|
32
45
|
const isDevelopmentEnv = (0, util_1.isDevelopmentEnvironment)((0, util_1.getCurrentEnvironment)());
|
|
33
46
|
return isDevelopmentEnv ? this.getAppDir() : this.getHome();
|
|
34
47
|
}
|
|
35
|
-
}
|
|
48
|
+
};
|
|
49
|
+
__decorate([
|
|
50
|
+
(0, decorator_1.Inject)(),
|
|
51
|
+
__metadata("design:type", String)
|
|
52
|
+
], MidwayInformationService.prototype, "appDir", void 0);
|
|
53
|
+
__decorate([
|
|
54
|
+
(0, decorator_1.Inject)(),
|
|
55
|
+
__metadata("design:type", String)
|
|
56
|
+
], MidwayInformationService.prototype, "baseDir", void 0);
|
|
57
|
+
__decorate([
|
|
58
|
+
(0, decorator_1.Init)(),
|
|
59
|
+
__metadata("design:type", Function),
|
|
60
|
+
__metadata("design:paramtypes", []),
|
|
61
|
+
__metadata("design:returntype", void 0)
|
|
62
|
+
], MidwayInformationService.prototype, "init", null);
|
|
63
|
+
MidwayInformationService = __decorate([
|
|
64
|
+
(0, decorator_1.Provide)(),
|
|
65
|
+
(0, decorator_1.Scope)(decorator_1.ScopeEnum.Singleton)
|
|
66
|
+
], MidwayInformationService);
|
|
36
67
|
exports.MidwayInformationService = MidwayInformationService;
|
|
37
68
|
//# sourceMappingURL=informationService.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { IMidwayContainer } from '../interface';
|
|
2
|
+
import { MidwayFrameworkService } from './frameworkService';
|
|
3
|
+
import { MidwayConfigService } from './configService';
|
|
4
|
+
export declare class MidwayLifeCycleService {
|
|
5
|
+
readonly applicationContext: IMidwayContainer;
|
|
6
|
+
protected frameworkService: MidwayFrameworkService;
|
|
7
|
+
protected configService: MidwayConfigService;
|
|
8
|
+
constructor(applicationContext: IMidwayContainer);
|
|
9
|
+
protected init(): Promise<void>;
|
|
10
|
+
stop(): Promise<void>;
|
|
11
|
+
private runContainerLifeCycle;
|
|
12
|
+
private runObjectLifeCycle;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=lifeCycleService.d.ts.map
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.MidwayLifeCycleService = void 0;
|
|
13
|
+
const decorator_1 = require("@midwayjs/decorator");
|
|
14
|
+
const configuration_1 = require("../functional/configuration");
|
|
15
|
+
const frameworkService_1 = require("./frameworkService");
|
|
16
|
+
const configService_1 = require("./configService");
|
|
17
|
+
const util_1 = require("util");
|
|
18
|
+
const debug = (0, util_1.debuglog)('midway:debug');
|
|
19
|
+
let MidwayLifeCycleService = class MidwayLifeCycleService {
|
|
20
|
+
constructor(applicationContext) {
|
|
21
|
+
this.applicationContext = applicationContext;
|
|
22
|
+
}
|
|
23
|
+
async init() {
|
|
24
|
+
// run lifecycle
|
|
25
|
+
const cycles = (0, decorator_1.listModule)(decorator_1.CONFIGURATION_KEY);
|
|
26
|
+
debug(`[core]: Found Configuration length = ${cycles.length}`);
|
|
27
|
+
const lifecycleInstanceList = [];
|
|
28
|
+
for (const cycle of cycles) {
|
|
29
|
+
if (cycle.target instanceof configuration_1.FunctionalConfiguration) {
|
|
30
|
+
// 函数式写法
|
|
31
|
+
cycle.instance = cycle.target;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
// 普通类写法
|
|
35
|
+
debug(`[core]: run ${cycle.target.name} init`);
|
|
36
|
+
cycle.instance = await this.applicationContext.getAsync(cycle.target);
|
|
37
|
+
}
|
|
38
|
+
cycle.instance && lifecycleInstanceList.push(cycle);
|
|
39
|
+
}
|
|
40
|
+
// bind object lifecycle
|
|
41
|
+
await Promise.all([
|
|
42
|
+
this.runObjectLifeCycle(lifecycleInstanceList, 'onBeforeObjectCreated'),
|
|
43
|
+
this.runObjectLifeCycle(lifecycleInstanceList, 'onObjectCreated'),
|
|
44
|
+
this.runObjectLifeCycle(lifecycleInstanceList, 'onObjectInit'),
|
|
45
|
+
this.runObjectLifeCycle(lifecycleInstanceList, 'onBeforeObjectDestroy'),
|
|
46
|
+
]);
|
|
47
|
+
// bind framework lifecycle
|
|
48
|
+
// onAppError
|
|
49
|
+
// exec onConfigLoad()
|
|
50
|
+
await this.runContainerLifeCycle(lifecycleInstanceList, 'onConfigLoad', configData => {
|
|
51
|
+
if (configData) {
|
|
52
|
+
this.configService.addObject(configData);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
// exec onReady()
|
|
56
|
+
await this.runContainerLifeCycle(lifecycleInstanceList, 'onReady');
|
|
57
|
+
// exec framework.run()
|
|
58
|
+
await this.frameworkService.runFramework();
|
|
59
|
+
// exec onServerReady()
|
|
60
|
+
await this.runContainerLifeCycle(lifecycleInstanceList, 'onServerReady');
|
|
61
|
+
}
|
|
62
|
+
async stop() {
|
|
63
|
+
// stop lifecycle
|
|
64
|
+
const cycles = (0, decorator_1.listModule)(decorator_1.CONFIGURATION_KEY);
|
|
65
|
+
for (const cycle of cycles) {
|
|
66
|
+
let inst;
|
|
67
|
+
if (cycle.target instanceof configuration_1.FunctionalConfiguration) {
|
|
68
|
+
// 函数式写法
|
|
69
|
+
inst = cycle.target;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
inst = await this.applicationContext.getAsync(cycle.target);
|
|
73
|
+
}
|
|
74
|
+
await this.runContainerLifeCycle(inst, 'onStop');
|
|
75
|
+
}
|
|
76
|
+
// stop framework
|
|
77
|
+
await this.frameworkService.stopFramework();
|
|
78
|
+
}
|
|
79
|
+
async runContainerLifeCycle(lifecycleInstanceOrList, lifecycle, resultHandler) {
|
|
80
|
+
if (Array.isArray(lifecycleInstanceOrList)) {
|
|
81
|
+
for (const cycle of lifecycleInstanceOrList) {
|
|
82
|
+
if (typeof cycle.instance[lifecycle] === 'function') {
|
|
83
|
+
debug(`[core]: run ${cycle.instance.constructor.name} ${lifecycle}`);
|
|
84
|
+
const result = await cycle.instance[lifecycle](this.applicationContext, this.frameworkService.getMainApp());
|
|
85
|
+
if (resultHandler) {
|
|
86
|
+
resultHandler(result);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
if (typeof lifecycleInstanceOrList[lifecycle] === 'function') {
|
|
93
|
+
debug(`[core]: run ${lifecycleInstanceOrList.constructor.name} ${lifecycle}`);
|
|
94
|
+
const result = await lifecycleInstanceOrList[lifecycle](this.applicationContext, this.frameworkService.getMainApp());
|
|
95
|
+
if (resultHandler) {
|
|
96
|
+
resultHandler(result);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
async runObjectLifeCycle(lifecycleInstanceList, lifecycle) {
|
|
102
|
+
for (const cycle of lifecycleInstanceList) {
|
|
103
|
+
if (typeof cycle.instance[lifecycle] === 'function') {
|
|
104
|
+
debug(`[core]: run ${cycle.instance.constructor.name} ${lifecycle}`);
|
|
105
|
+
return this.applicationContext[lifecycle](cycle.instance[lifecycle].bind(cycle.instance));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
__decorate([
|
|
111
|
+
(0, decorator_1.Inject)(),
|
|
112
|
+
__metadata("design:type", frameworkService_1.MidwayFrameworkService)
|
|
113
|
+
], MidwayLifeCycleService.prototype, "frameworkService", void 0);
|
|
114
|
+
__decorate([
|
|
115
|
+
(0, decorator_1.Inject)(),
|
|
116
|
+
__metadata("design:type", configService_1.MidwayConfigService)
|
|
117
|
+
], MidwayLifeCycleService.prototype, "configService", void 0);
|
|
118
|
+
__decorate([
|
|
119
|
+
(0, decorator_1.Init)(),
|
|
120
|
+
__metadata("design:type", Function),
|
|
121
|
+
__metadata("design:paramtypes", []),
|
|
122
|
+
__metadata("design:returntype", Promise)
|
|
123
|
+
], MidwayLifeCycleService.prototype, "init", null);
|
|
124
|
+
MidwayLifeCycleService = __decorate([
|
|
125
|
+
(0, decorator_1.Provide)(),
|
|
126
|
+
(0, decorator_1.Scope)(decorator_1.ScopeEnum.Singleton),
|
|
127
|
+
__metadata("design:paramtypes", [Object])
|
|
128
|
+
], MidwayLifeCycleService);
|
|
129
|
+
exports.MidwayLifeCycleService = MidwayLifeCycleService;
|
|
130
|
+
//# sourceMappingURL=lifeCycleService.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { MidwayConfigService } from './configService';
|
|
2
|
+
import { ServiceFactory } from '../common/serviceFactory';
|
|
3
|
+
import { ILogger } from '@midwayjs/logger';
|
|
4
|
+
import { IMidwayContainer } from '../interface';
|
|
5
|
+
export declare class MidwayLoggerService extends ServiceFactory<ILogger> {
|
|
6
|
+
readonly applicationContext: IMidwayContainer;
|
|
7
|
+
configService: MidwayConfigService;
|
|
8
|
+
constructor(applicationContext: IMidwayContainer);
|
|
9
|
+
protected init(): Promise<void>;
|
|
10
|
+
transformEggConfig(): {
|
|
11
|
+
midwayLogger: {
|
|
12
|
+
default: {};
|
|
13
|
+
clients: {};
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
protected createClient(config: any, name?: string): Promise<void>;
|
|
17
|
+
getName(): string;
|
|
18
|
+
createLogger(name: any, config: any): ILogger;
|
|
19
|
+
getLogger(name: string): ILogger;
|
|
20
|
+
transformEggLogger(options: any): {
|
|
21
|
+
midwayLogger: {
|
|
22
|
+
default: {};
|
|
23
|
+
clients: {};
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=loggerService.d.ts.map
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.MidwayLoggerService = void 0;
|
|
13
|
+
const decorator_1 = require("@midwayjs/decorator");
|
|
14
|
+
const configService_1 = require("./configService");
|
|
15
|
+
const serviceFactory_1 = require("../common/serviceFactory");
|
|
16
|
+
const logger_1 = require("@midwayjs/logger");
|
|
17
|
+
const levelTransform = level => {
|
|
18
|
+
if (!level) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
switch (level) {
|
|
22
|
+
case 'NONE':
|
|
23
|
+
case Infinity: // egg logger 的 none 是这个等级
|
|
24
|
+
return null;
|
|
25
|
+
case 0:
|
|
26
|
+
case 'DEBUG':
|
|
27
|
+
case 'debug':
|
|
28
|
+
return 'debug';
|
|
29
|
+
case 1:
|
|
30
|
+
case 'INFO':
|
|
31
|
+
case 'info':
|
|
32
|
+
return 'info';
|
|
33
|
+
case 2:
|
|
34
|
+
case 'WARN':
|
|
35
|
+
case 'warn':
|
|
36
|
+
return 'warn';
|
|
37
|
+
case 3:
|
|
38
|
+
case 'ERROR':
|
|
39
|
+
case 'error':
|
|
40
|
+
return 'error';
|
|
41
|
+
default:
|
|
42
|
+
return 'silly';
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
let MidwayLoggerService = class MidwayLoggerService extends serviceFactory_1.ServiceFactory {
|
|
46
|
+
constructor(applicationContext) {
|
|
47
|
+
super();
|
|
48
|
+
this.applicationContext = applicationContext;
|
|
49
|
+
}
|
|
50
|
+
async init() {
|
|
51
|
+
var _a;
|
|
52
|
+
const eggLoggerConfig = this.transformEggConfig();
|
|
53
|
+
if (eggLoggerConfig) {
|
|
54
|
+
this.configService.addObject(eggLoggerConfig);
|
|
55
|
+
}
|
|
56
|
+
await this.initClients(this.configService.getConfiguration('midwayLogger'));
|
|
57
|
+
// alias inject logger
|
|
58
|
+
(_a = this.applicationContext) === null || _a === void 0 ? void 0 : _a.registerObject('logger', this.getLogger('appLogger'));
|
|
59
|
+
}
|
|
60
|
+
transformEggConfig() {
|
|
61
|
+
if (this.configService.getConfiguration('customLogger')) {
|
|
62
|
+
// use egg module
|
|
63
|
+
return this.transformEggLogger(this.configService.getConfiguration());
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
// it will be use other logger
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async createClient(config, name) {
|
|
71
|
+
logger_1.loggers.createLogger(name, config);
|
|
72
|
+
}
|
|
73
|
+
getName() {
|
|
74
|
+
return 'logger';
|
|
75
|
+
}
|
|
76
|
+
createLogger(name, config) {
|
|
77
|
+
return logger_1.loggers.createLogger(name, config);
|
|
78
|
+
}
|
|
79
|
+
getLogger(name) {
|
|
80
|
+
return logger_1.loggers.getLogger(name);
|
|
81
|
+
}
|
|
82
|
+
transformEggLogger(options) {
|
|
83
|
+
var _a, _b, _c;
|
|
84
|
+
const transformLoggerConfig = {
|
|
85
|
+
midwayLogger: {
|
|
86
|
+
default: {},
|
|
87
|
+
clients: {},
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
if (options.midwayLogger && !options.midwayLogger.default) {
|
|
91
|
+
transformLoggerConfig.midwayLogger.default = {
|
|
92
|
+
dir: options.logger.dir,
|
|
93
|
+
level: levelTransform(options.logger.level),
|
|
94
|
+
consoleLevel: levelTransform(options.logger.consoleLevel),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
const eggCustomLogger = options['customLogger'];
|
|
98
|
+
for (const name in eggCustomLogger) {
|
|
99
|
+
transformLoggerConfig.midwayLogger.clients[name] = {
|
|
100
|
+
fileLogName: (_a = eggCustomLogger[name]) === null || _a === void 0 ? void 0 : _a.file,
|
|
101
|
+
level: levelTransform((_b = eggCustomLogger[name]) === null || _b === void 0 ? void 0 : _b.level),
|
|
102
|
+
consoleLevel: levelTransform((_c = eggCustomLogger[name]) === null || _c === void 0 ? void 0 : _c.consoleLevel),
|
|
103
|
+
};
|
|
104
|
+
cleanUndefinedProperty(transformLoggerConfig.midwayLogger.clients[name]);
|
|
105
|
+
}
|
|
106
|
+
return transformLoggerConfig;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
__decorate([
|
|
110
|
+
(0, decorator_1.Inject)(),
|
|
111
|
+
__metadata("design:type", configService_1.MidwayConfigService)
|
|
112
|
+
], MidwayLoggerService.prototype, "configService", void 0);
|
|
113
|
+
__decorate([
|
|
114
|
+
(0, decorator_1.Init)(),
|
|
115
|
+
__metadata("design:type", Function),
|
|
116
|
+
__metadata("design:paramtypes", []),
|
|
117
|
+
__metadata("design:returntype", Promise)
|
|
118
|
+
], MidwayLoggerService.prototype, "init", null);
|
|
119
|
+
MidwayLoggerService = __decorate([
|
|
120
|
+
(0, decorator_1.Provide)(),
|
|
121
|
+
(0, decorator_1.Scope)(decorator_1.ScopeEnum.Singleton),
|
|
122
|
+
__metadata("design:paramtypes", [Object])
|
|
123
|
+
], MidwayLoggerService);
|
|
124
|
+
exports.MidwayLoggerService = MidwayLoggerService;
|
|
125
|
+
function cleanUndefinedProperty(obj) {
|
|
126
|
+
Object.keys(obj).forEach(key => {
|
|
127
|
+
if (obj[key] === undefined) {
|
|
128
|
+
delete obj[key];
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=loggerService.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CommonMiddleware, IMidwayContainer, IMidwayApplication } from '../interface';
|
|
2
|
+
export declare class MidwayMiddlewareService<T, R, N = unknown> {
|
|
3
|
+
readonly applicationContext: IMidwayContainer;
|
|
4
|
+
constructor(applicationContext: IMidwayContainer);
|
|
5
|
+
compose(middleware: Array<CommonMiddleware<T, R, N> | string>, app: IMidwayApplication, name?: string): Promise<{
|
|
6
|
+
(context: any, next?: any): Promise<any>;
|
|
7
|
+
_name: string;
|
|
8
|
+
}>;
|
|
9
|
+
getMiddlewareName(mw: any): any;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=middlewareService.d.ts.map
|