@midwayjs/core 3.14.0 → 3.14.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/common/dataSourceManager.d.ts +10 -2
- package/dist/common/dataSourceManager.js +20 -0
- package/dist/common/priorityManager.d.ts +16 -0
- package/dist/common/priorityManager.js +46 -0
- package/dist/common/serviceFactory.d.ts +7 -10
- package/dist/common/serviceFactory.js +25 -19
- package/dist/index.d.ts +2 -0
- package/dist/index.js +6 -1
- package/dist/interface.d.ts +2 -3
- package/dist/service/healthService.d.ts +5 -3
- package/dist/service/healthService.js +2 -13
- package/dist/service/lifeCycleService.d.ts +2 -0
- package/dist/service/lifeCycleService.js +7 -0
- package/dist/setup.js +2 -0
- package/package.json +2 -2
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { ModuleLoadType, DataSourceManagerConfigOption } from '../interface';
|
|
2
2
|
import { MidwayEnvironmentService } from '../service/environmentService';
|
|
3
|
+
import { MidwayPriorityManager } from './priorityManager';
|
|
3
4
|
export declare abstract class DataSourceManager<T, ConnectionOpts extends Record<string, any> = Record<string, any>> {
|
|
4
5
|
protected dataSource: Map<string, T>;
|
|
5
6
|
protected options: DataSourceManagerConfigOption<ConnectionOpts>;
|
|
6
7
|
protected modelMapping: WeakMap<object, any>;
|
|
7
8
|
private innerDefaultDataSourceName;
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
protected dataSourcePriority: Record<string, string>;
|
|
10
|
+
protected appDir: string;
|
|
11
|
+
protected environmentService: MidwayEnvironmentService;
|
|
12
|
+
protected priorityManager: MidwayPriorityManager;
|
|
10
13
|
protected initDataSource(dataSourceConfig: DataSourceManagerConfigOption<ConnectionOpts>, baseDirOrOptions: {
|
|
11
14
|
baseDir: string;
|
|
12
15
|
entitiesConfigKey?: string;
|
|
@@ -22,6 +25,7 @@ export declare abstract class DataSourceManager<T, ConnectionOpts extends Record
|
|
|
22
25
|
*/
|
|
23
26
|
hasDataSource(dataSourceName: string): boolean;
|
|
24
27
|
getDataSourceNames(): string[];
|
|
28
|
+
getAllDataSources(): Map<string, T>;
|
|
25
29
|
/**
|
|
26
30
|
* check the data source is connected
|
|
27
31
|
* @param dataSourceName
|
|
@@ -42,6 +46,10 @@ export declare abstract class DataSourceManager<T, ConnectionOpts extends Record
|
|
|
42
46
|
protected abstract destroyDataSource(dataSource: T): Promise<void>;
|
|
43
47
|
stop(): Promise<void>;
|
|
44
48
|
getDefaultDataSourceName(): string;
|
|
49
|
+
getDataSourcePriority(name: string): string;
|
|
50
|
+
isHighPriority(name: string): boolean;
|
|
51
|
+
isMediumPriority(name: string): boolean;
|
|
52
|
+
isLowPriority(name: string): boolean;
|
|
45
53
|
}
|
|
46
54
|
export declare function formatGlobString(globString: string): string[];
|
|
47
55
|
export declare function globModels(globString: string, appDir: string, loadMode?: ModuleLoadType): Promise<any[]>;
|
|
@@ -23,6 +23,7 @@ const util_1 = require("util");
|
|
|
23
23
|
const util_2 = require("../util");
|
|
24
24
|
const decorator_1 = require("../decorator");
|
|
25
25
|
const environmentService_1 = require("../service/environmentService");
|
|
26
|
+
const priorityManager_1 = require("./priorityManager");
|
|
26
27
|
const debug = (0, util_1.debuglog)('midway:debug');
|
|
27
28
|
class DataSourceManager {
|
|
28
29
|
constructor() {
|
|
@@ -92,6 +93,9 @@ class DataSourceManager {
|
|
|
92
93
|
getDataSourceNames() {
|
|
93
94
|
return Array.from(this.dataSource.keys());
|
|
94
95
|
}
|
|
96
|
+
getAllDataSources() {
|
|
97
|
+
return this.dataSource;
|
|
98
|
+
}
|
|
95
99
|
/**
|
|
96
100
|
* check the data source is connected
|
|
97
101
|
* @param dataSourceName
|
|
@@ -152,6 +156,18 @@ class DataSourceManager {
|
|
|
152
156
|
}
|
|
153
157
|
return this.innerDefaultDataSourceName;
|
|
154
158
|
}
|
|
159
|
+
getDataSourcePriority(name) {
|
|
160
|
+
return this.priorityManager.getPriority(this.dataSourcePriority[name]);
|
|
161
|
+
}
|
|
162
|
+
isHighPriority(name) {
|
|
163
|
+
return this.priorityManager.isHighPriority(this.dataSourcePriority[name]);
|
|
164
|
+
}
|
|
165
|
+
isMediumPriority(name) {
|
|
166
|
+
return this.priorityManager.isMediumPriority(this.dataSourcePriority[name]);
|
|
167
|
+
}
|
|
168
|
+
isLowPriority(name) {
|
|
169
|
+
return this.priorityManager.isLowPriority(this.dataSourcePriority[name]);
|
|
170
|
+
}
|
|
155
171
|
}
|
|
156
172
|
__decorate([
|
|
157
173
|
(0, decorator_1.Inject)(),
|
|
@@ -161,6 +177,10 @@ __decorate([
|
|
|
161
177
|
(0, decorator_1.Inject)(),
|
|
162
178
|
__metadata("design:type", environmentService_1.MidwayEnvironmentService)
|
|
163
179
|
], DataSourceManager.prototype, "environmentService", void 0);
|
|
180
|
+
__decorate([
|
|
181
|
+
(0, decorator_1.Inject)(),
|
|
182
|
+
__metadata("design:type", priorityManager_1.MidwayPriorityManager)
|
|
183
|
+
], DataSourceManager.prototype, "priorityManager", void 0);
|
|
164
184
|
exports.DataSourceManager = DataSourceManager;
|
|
165
185
|
function formatGlobString(globString) {
|
|
166
186
|
let pattern;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const DEFAULT_PRIORITY: {
|
|
2
|
+
L1: string;
|
|
3
|
+
L2: string;
|
|
4
|
+
L3: string;
|
|
5
|
+
};
|
|
6
|
+
export declare class MidwayPriorityManager {
|
|
7
|
+
private priorityList;
|
|
8
|
+
private defaultPriority;
|
|
9
|
+
getCurrentPriorityList(): Record<string, string>;
|
|
10
|
+
getDefaultPriority(): string;
|
|
11
|
+
isHighPriority(priority?: string): boolean;
|
|
12
|
+
isMediumPriority(priority?: string): boolean;
|
|
13
|
+
isLowPriority(priority?: string): boolean;
|
|
14
|
+
getPriority(priority: string): string;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=priorityManager.d.ts.map
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.MidwayPriorityManager = exports.DEFAULT_PRIORITY = void 0;
|
|
10
|
+
const decorator_1 = require("../decorator");
|
|
11
|
+
const interface_1 = require("../interface");
|
|
12
|
+
exports.DEFAULT_PRIORITY = {
|
|
13
|
+
L1: 'High',
|
|
14
|
+
L2: 'Medium',
|
|
15
|
+
L3: 'Low',
|
|
16
|
+
};
|
|
17
|
+
let MidwayPriorityManager = class MidwayPriorityManager {
|
|
18
|
+
constructor() {
|
|
19
|
+
this.priorityList = exports.DEFAULT_PRIORITY;
|
|
20
|
+
this.defaultPriority = exports.DEFAULT_PRIORITY.L2;
|
|
21
|
+
}
|
|
22
|
+
getCurrentPriorityList() {
|
|
23
|
+
return this.priorityList;
|
|
24
|
+
}
|
|
25
|
+
getDefaultPriority() {
|
|
26
|
+
return this.defaultPriority;
|
|
27
|
+
}
|
|
28
|
+
isHighPriority(priority = exports.DEFAULT_PRIORITY.L2) {
|
|
29
|
+
return priority === exports.DEFAULT_PRIORITY.L1;
|
|
30
|
+
}
|
|
31
|
+
isMediumPriority(priority = exports.DEFAULT_PRIORITY.L2) {
|
|
32
|
+
return priority === exports.DEFAULT_PRIORITY.L2;
|
|
33
|
+
}
|
|
34
|
+
isLowPriority(priority = exports.DEFAULT_PRIORITY.L2) {
|
|
35
|
+
return priority === exports.DEFAULT_PRIORITY.L3;
|
|
36
|
+
}
|
|
37
|
+
getPriority(priority) {
|
|
38
|
+
return priority || this.getDefaultPriority();
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
MidwayPriorityManager = __decorate([
|
|
42
|
+
(0, decorator_1.Provide)(),
|
|
43
|
+
(0, decorator_1.Scope)(interface_1.ScopeEnum.Singleton)
|
|
44
|
+
], MidwayPriorityManager);
|
|
45
|
+
exports.MidwayPriorityManager = MidwayPriorityManager;
|
|
46
|
+
//# sourceMappingURL=priorityManager.js.map
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import { IServiceFactory } from '../interface';
|
|
2
|
-
|
|
3
|
-
L1: string;
|
|
4
|
-
L2: string;
|
|
5
|
-
L3: string;
|
|
6
|
-
};
|
|
2
|
+
import { MidwayPriorityManager } from './priorityManager';
|
|
7
3
|
/**
|
|
8
4
|
* 多客户端工厂实现
|
|
9
5
|
*/
|
|
10
6
|
export declare abstract class ServiceFactory<T> implements IServiceFactory<T> {
|
|
11
7
|
protected clients: Map<string, T>;
|
|
12
|
-
protected
|
|
8
|
+
protected clientPriority: Record<string, string>;
|
|
13
9
|
protected options: {};
|
|
10
|
+
protected priorityManager: MidwayPriorityManager;
|
|
14
11
|
protected initClients(options?: any): Promise<void>;
|
|
15
12
|
get<U = T>(id?: string): U;
|
|
16
13
|
has(id: string): boolean;
|
|
@@ -22,9 +19,9 @@ export declare abstract class ServiceFactory<T> implements IServiceFactory<T> {
|
|
|
22
19
|
getDefaultClientName(): string;
|
|
23
20
|
getClients(): Map<string, T>;
|
|
24
21
|
getClientKeys(): string[];
|
|
25
|
-
getClientPriority(
|
|
26
|
-
isHighPriority(
|
|
27
|
-
isMediumPriority(
|
|
28
|
-
isLowPriority(
|
|
22
|
+
getClientPriority(name: string): string;
|
|
23
|
+
isHighPriority(name: string): boolean;
|
|
24
|
+
isMediumPriority(name: string): boolean;
|
|
25
|
+
isLowPriority(name: string): boolean;
|
|
29
26
|
}
|
|
30
27
|
//# sourceMappingURL=serviceFactory.d.ts.map
|
|
@@ -1,12 +1,18 @@
|
|
|
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
|
-
exports.ServiceFactory =
|
|
12
|
+
exports.ServiceFactory = void 0;
|
|
4
13
|
const extend_1 = require("../util/extend");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
L2: 'Medium',
|
|
8
|
-
L3: 'Low',
|
|
9
|
-
};
|
|
14
|
+
const priorityManager_1 = require("./priorityManager");
|
|
15
|
+
const decorator_1 = require("../decorator");
|
|
10
16
|
/**
|
|
11
17
|
* 多客户端工厂实现
|
|
12
18
|
*/
|
|
@@ -30,11 +36,7 @@ class ServiceFactory {
|
|
|
30
36
|
}
|
|
31
37
|
}
|
|
32
38
|
// set priority
|
|
33
|
-
this.
|
|
34
|
-
...Array.from(this.clients.keys()).map(name => ({
|
|
35
|
-
[name]: exports.DEFAULT_PRIORITY.L2,
|
|
36
|
-
})),
|
|
37
|
-
};
|
|
39
|
+
this.clientPriority = options.priority || {};
|
|
38
40
|
}
|
|
39
41
|
get(id = 'default') {
|
|
40
42
|
return this.clients.get(id);
|
|
@@ -68,18 +70,22 @@ class ServiceFactory {
|
|
|
68
70
|
getClientKeys() {
|
|
69
71
|
return Array.from(this.clients.keys());
|
|
70
72
|
}
|
|
71
|
-
getClientPriority(
|
|
72
|
-
return this.
|
|
73
|
+
getClientPriority(name) {
|
|
74
|
+
return this.priorityManager.getPriority(this.clientPriority[name]);
|
|
73
75
|
}
|
|
74
|
-
isHighPriority(
|
|
75
|
-
return this.
|
|
76
|
+
isHighPriority(name) {
|
|
77
|
+
return this.priorityManager.isHighPriority(this.clientPriority[name]);
|
|
76
78
|
}
|
|
77
|
-
isMediumPriority(
|
|
78
|
-
return this.
|
|
79
|
+
isMediumPriority(name) {
|
|
80
|
+
return this.priorityManager.isMediumPriority(this.clientPriority[name]);
|
|
79
81
|
}
|
|
80
|
-
isLowPriority(
|
|
81
|
-
return this.
|
|
82
|
+
isLowPriority(name) {
|
|
83
|
+
return this.priorityManager.isLowPriority(this.clientPriority[name]);
|
|
82
84
|
}
|
|
83
85
|
}
|
|
86
|
+
__decorate([
|
|
87
|
+
(0, decorator_1.Inject)(),
|
|
88
|
+
__metadata("design:type", priorityManager_1.MidwayPriorityManager)
|
|
89
|
+
], ServiceFactory.prototype, "priorityManager", void 0);
|
|
84
90
|
exports.ServiceFactory = ServiceFactory;
|
|
85
91
|
//# sourceMappingURL=serviceFactory.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -15,9 +15,11 @@ export { MidwayLifeCycleService } from './service/lifeCycleService';
|
|
|
15
15
|
export { MidwayMiddlewareService } from './service/middlewareService';
|
|
16
16
|
export { MidwayDecoratorService } from './service/decoratorService';
|
|
17
17
|
export { MidwayMockService } from './service/mockService';
|
|
18
|
+
export { MidwayHealthService } from './service/healthService';
|
|
18
19
|
export { RouterInfo, DynamicRouterInfo, RouterPriority, RouterCollectorOptions, MidwayWebRouterService, } from './service/webRouterService';
|
|
19
20
|
export { MidwayServerlessFunctionService, WebRouterCollector, } from './service/slsFunctionService';
|
|
20
21
|
export { DataSourceManager } from './common/dataSourceManager';
|
|
22
|
+
export { DEFAULT_PRIORITY, MidwayPriorityManager, } from './common/priorityManager';
|
|
21
23
|
export * from './service/pipelineService';
|
|
22
24
|
export * from './common/loggerFactory';
|
|
23
25
|
export * from './common/serviceFactory';
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.FORMAT = exports.FileUtils = exports.PathFileUtil = exports.Types = exports.retryWith = exports.retryWithAsync = exports.extend = exports.Utils = exports.sleep = exports.isTypeScriptEnvironment = exports.wrapAsync = exports.wrapMiddleware = exports.pathMatching = exports.transformRequestObjectByType = exports.deprecatedOutput = exports.delegateTargetAllPrototypeMethod = exports.delegateTargetProperties = exports.delegateTargetMethod = exports.delegateTargetPrototypeMethod = exports.loadModule = exports.safeRequire = exports.safelyGet = exports.ASYNC_ROOT_CONTEXT = exports.DataSourceManager = exports.WebRouterCollector = exports.MidwayServerlessFunctionService = exports.MidwayWebRouterService = exports.MidwayMockService = exports.MidwayDecoratorService = exports.MidwayMiddlewareService = exports.MidwayLifeCycleService = exports.MidwayAspectService = exports.MidwayFrameworkService = exports.MidwayLoggerService = exports.MidwayInformationService = exports.MidwayEnvironmentService = exports.MidwayConfigService = exports.FunctionalConfiguration = exports.createConfiguration = exports.BaseFramework = exports.MidwayRequestContainer = void 0;
|
|
17
|
+
exports.FORMAT = exports.FileUtils = exports.PathFileUtil = exports.Types = exports.retryWith = exports.retryWithAsync = exports.extend = exports.Utils = exports.sleep = exports.isTypeScriptEnvironment = exports.wrapAsync = exports.wrapMiddleware = exports.pathMatching = exports.transformRequestObjectByType = exports.deprecatedOutput = exports.delegateTargetAllPrototypeMethod = exports.delegateTargetProperties = exports.delegateTargetMethod = exports.delegateTargetPrototypeMethod = exports.loadModule = exports.safeRequire = exports.safelyGet = exports.ASYNC_ROOT_CONTEXT = exports.MidwayPriorityManager = exports.DEFAULT_PRIORITY = exports.DataSourceManager = exports.WebRouterCollector = exports.MidwayServerlessFunctionService = exports.MidwayWebRouterService = exports.MidwayHealthService = exports.MidwayMockService = exports.MidwayDecoratorService = exports.MidwayMiddlewareService = exports.MidwayLifeCycleService = exports.MidwayAspectService = exports.MidwayFrameworkService = exports.MidwayLoggerService = exports.MidwayInformationService = exports.MidwayEnvironmentService = exports.MidwayConfigService = exports.FunctionalConfiguration = exports.createConfiguration = exports.BaseFramework = exports.MidwayRequestContainer = void 0;
|
|
18
18
|
__exportStar(require("./interface"), exports);
|
|
19
19
|
__exportStar(require("./context/container"), exports);
|
|
20
20
|
var requestContainer_1 = require("./context/requestContainer");
|
|
@@ -46,6 +46,8 @@ var decoratorService_1 = require("./service/decoratorService");
|
|
|
46
46
|
Object.defineProperty(exports, "MidwayDecoratorService", { enumerable: true, get: function () { return decoratorService_1.MidwayDecoratorService; } });
|
|
47
47
|
var mockService_1 = require("./service/mockService");
|
|
48
48
|
Object.defineProperty(exports, "MidwayMockService", { enumerable: true, get: function () { return mockService_1.MidwayMockService; } });
|
|
49
|
+
var healthService_1 = require("./service/healthService");
|
|
50
|
+
Object.defineProperty(exports, "MidwayHealthService", { enumerable: true, get: function () { return healthService_1.MidwayHealthService; } });
|
|
49
51
|
var webRouterService_1 = require("./service/webRouterService");
|
|
50
52
|
Object.defineProperty(exports, "MidwayWebRouterService", { enumerable: true, get: function () { return webRouterService_1.MidwayWebRouterService; } });
|
|
51
53
|
var slsFunctionService_1 = require("./service/slsFunctionService");
|
|
@@ -53,6 +55,9 @@ Object.defineProperty(exports, "MidwayServerlessFunctionService", { enumerable:
|
|
|
53
55
|
Object.defineProperty(exports, "WebRouterCollector", { enumerable: true, get: function () { return slsFunctionService_1.WebRouterCollector; } });
|
|
54
56
|
var dataSourceManager_1 = require("./common/dataSourceManager");
|
|
55
57
|
Object.defineProperty(exports, "DataSourceManager", { enumerable: true, get: function () { return dataSourceManager_1.DataSourceManager; } });
|
|
58
|
+
var priorityManager_1 = require("./common/priorityManager");
|
|
59
|
+
Object.defineProperty(exports, "DEFAULT_PRIORITY", { enumerable: true, get: function () { return priorityManager_1.DEFAULT_PRIORITY; } });
|
|
60
|
+
Object.defineProperty(exports, "MidwayPriorityManager", { enumerable: true, get: function () { return priorityManager_1.MidwayPriorityManager; } });
|
|
56
61
|
__exportStar(require("./service/pipelineService"), exports);
|
|
57
62
|
__exportStar(require("./common/loggerFactory"), exports);
|
|
58
63
|
__exportStar(require("./common/serviceFactory"), exports);
|
package/dist/interface.d.ts
CHANGED
|
@@ -399,7 +399,6 @@ export interface MidwayCoreDefaultConfig {
|
|
|
399
399
|
healthCheckTimeout?: number;
|
|
400
400
|
};
|
|
401
401
|
}
|
|
402
|
-
export type ClientPriorityValue = 'High' | 'Medium' | 'Low';
|
|
403
402
|
export type ServiceFactoryConfigOption<OPTIONS> = {
|
|
404
403
|
default?: PowerPartial<OPTIONS>;
|
|
405
404
|
client?: PowerPartial<OPTIONS>;
|
|
@@ -408,7 +407,7 @@ export type ServiceFactoryConfigOption<OPTIONS> = {
|
|
|
408
407
|
};
|
|
409
408
|
defaultClientName?: string;
|
|
410
409
|
clientPriority?: {
|
|
411
|
-
[key: string]:
|
|
410
|
+
[key: string]: number;
|
|
412
411
|
};
|
|
413
412
|
};
|
|
414
413
|
export type CreateDataSourceInstanceOptions = {
|
|
@@ -945,7 +944,7 @@ export interface IServiceFactory<Client> {
|
|
|
945
944
|
getDefaultClientName(): string;
|
|
946
945
|
getClients(): Map<string, Client>;
|
|
947
946
|
getClientKeys(): string[];
|
|
948
|
-
getClientPriority(clientName: string):
|
|
947
|
+
getClientPriority(clientName: string): string;
|
|
949
948
|
isHighPriority(clientName: string): boolean;
|
|
950
949
|
isMediumPriority(clientName: string): boolean;
|
|
951
950
|
isLowPriority(clientName: string): boolean;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { HealthResults, IMidwayContainer } from '../interface';
|
|
2
2
|
import { MidwayConfigService } from './configService';
|
|
3
|
-
import { MidwayLifeCycleService } from './lifeCycleService';
|
|
4
3
|
export declare class MidwayHealthService {
|
|
5
4
|
protected configService: MidwayConfigService;
|
|
6
|
-
protected lifeCycleService: MidwayLifeCycleService;
|
|
7
5
|
protected applicationContext: IMidwayContainer;
|
|
8
6
|
private healthCheckTimeout;
|
|
9
7
|
private healthCheckMethods;
|
|
10
|
-
|
|
8
|
+
init(lifeCycleInstanceList: Array<{
|
|
9
|
+
target: any;
|
|
10
|
+
namespace: string;
|
|
11
|
+
instance?: any;
|
|
12
|
+
}>): Promise<void>;
|
|
11
13
|
getStatus(): Promise<HealthResults>;
|
|
12
14
|
setCheckTimeout(timeout: number): void;
|
|
13
15
|
}
|
|
@@ -13,17 +13,16 @@ exports.MidwayHealthService = void 0;
|
|
|
13
13
|
const decorator_1 = require("../decorator");
|
|
14
14
|
const interface_1 = require("../interface");
|
|
15
15
|
const configService_1 = require("./configService");
|
|
16
|
-
const lifeCycleService_1 = require("./lifeCycleService");
|
|
17
16
|
const util_1 = require("../util");
|
|
18
17
|
let MidwayHealthService = class MidwayHealthService {
|
|
19
18
|
constructor() {
|
|
20
19
|
this.healthCheckTimeout = 1000;
|
|
21
20
|
this.healthCheckMethods = [];
|
|
22
21
|
}
|
|
23
|
-
async init() {
|
|
22
|
+
async init(lifeCycleInstanceList) {
|
|
24
23
|
const healthCheckTimeout = this.configService.getConfiguration('core.healthCheckTimeout') || 1000;
|
|
25
24
|
this.setCheckTimeout(healthCheckTimeout);
|
|
26
|
-
for (const lifecycleInstance of
|
|
25
|
+
for (const lifecycleInstance of lifeCycleInstanceList) {
|
|
27
26
|
if (lifecycleInstance.instance &&
|
|
28
27
|
lifecycleInstance.instance['onHealthCheck']) {
|
|
29
28
|
this.healthCheckMethods.push({
|
|
@@ -84,20 +83,10 @@ __decorate([
|
|
|
84
83
|
(0, decorator_1.Inject)(),
|
|
85
84
|
__metadata("design:type", configService_1.MidwayConfigService)
|
|
86
85
|
], MidwayHealthService.prototype, "configService", void 0);
|
|
87
|
-
__decorate([
|
|
88
|
-
(0, decorator_1.Inject)(),
|
|
89
|
-
__metadata("design:type", lifeCycleService_1.MidwayLifeCycleService)
|
|
90
|
-
], MidwayHealthService.prototype, "lifeCycleService", void 0);
|
|
91
86
|
__decorate([
|
|
92
87
|
(0, decorator_1.ApplicationContext)(),
|
|
93
88
|
__metadata("design:type", Object)
|
|
94
89
|
], MidwayHealthService.prototype, "applicationContext", void 0);
|
|
95
|
-
__decorate([
|
|
96
|
-
(0, decorator_1.Init)(),
|
|
97
|
-
__metadata("design:type", Function),
|
|
98
|
-
__metadata("design:paramtypes", []),
|
|
99
|
-
__metadata("design:returntype", Promise)
|
|
100
|
-
], MidwayHealthService.prototype, "init", null);
|
|
101
90
|
MidwayHealthService = __decorate([
|
|
102
91
|
(0, decorator_1.Provide)(),
|
|
103
92
|
(0, decorator_1.Scope)(interface_1.ScopeEnum.Singleton)
|
|
@@ -2,11 +2,13 @@ import { IMidwayContainer } from '../interface';
|
|
|
2
2
|
import { MidwayFrameworkService } from './frameworkService';
|
|
3
3
|
import { MidwayConfigService } from './configService';
|
|
4
4
|
import { MidwayMockService } from './mockService';
|
|
5
|
+
import { MidwayHealthService } from './healthService';
|
|
5
6
|
export declare class MidwayLifeCycleService {
|
|
6
7
|
readonly applicationContext: IMidwayContainer;
|
|
7
8
|
protected frameworkService: MidwayFrameworkService;
|
|
8
9
|
protected configService: MidwayConfigService;
|
|
9
10
|
protected mockService: MidwayMockService;
|
|
11
|
+
protected healthService: MidwayHealthService;
|
|
10
12
|
private lifecycleInstanceList;
|
|
11
13
|
constructor(applicationContext: IMidwayContainer);
|
|
12
14
|
protected init(): Promise<void>;
|
|
@@ -17,6 +17,7 @@ const frameworkService_1 = require("./frameworkService");
|
|
|
17
17
|
const configService_1 = require("./configService");
|
|
18
18
|
const util_1 = require("util");
|
|
19
19
|
const mockService_1 = require("./mockService");
|
|
20
|
+
const healthService_1 = require("./healthService");
|
|
20
21
|
const debug = (0, util_1.debuglog)('midway:debug');
|
|
21
22
|
let MidwayLifeCycleService = class MidwayLifeCycleService {
|
|
22
23
|
constructor(applicationContext) {
|
|
@@ -41,6 +42,8 @@ let MidwayLifeCycleService = class MidwayLifeCycleService {
|
|
|
41
42
|
}
|
|
42
43
|
cycle.instance && this.lifecycleInstanceList.push(cycle);
|
|
43
44
|
}
|
|
45
|
+
// init health check service
|
|
46
|
+
await this.healthService.init(this.lifecycleInstanceList);
|
|
44
47
|
// bind object lifecycle
|
|
45
48
|
await Promise.all([
|
|
46
49
|
this.runObjectLifeCycle(this.lifecycleInstanceList, 'onBeforeObjectCreated'),
|
|
@@ -143,6 +146,10 @@ __decorate([
|
|
|
143
146
|
(0, decorator_1.Inject)(),
|
|
144
147
|
__metadata("design:type", mockService_1.MidwayMockService)
|
|
145
148
|
], MidwayLifeCycleService.prototype, "mockService", void 0);
|
|
149
|
+
__decorate([
|
|
150
|
+
(0, decorator_1.Inject)(),
|
|
151
|
+
__metadata("design:type", healthService_1.MidwayHealthService)
|
|
152
|
+
], MidwayLifeCycleService.prototype, "healthService", void 0);
|
|
146
153
|
__decorate([
|
|
147
154
|
(0, decorator_1.Init)(),
|
|
148
155
|
__metadata("design:type", Function),
|
package/dist/setup.js
CHANGED
|
@@ -136,6 +136,7 @@ async function prepareGlobalApplicationContextAsync(globalOptions) {
|
|
|
136
136
|
applicationContext.bindClass(_1.MidwayWebRouterService);
|
|
137
137
|
applicationContext.bindClass(slsFunctionService_1.MidwayServerlessFunctionService);
|
|
138
138
|
applicationContext.bindClass(healthService_1.MidwayHealthService);
|
|
139
|
+
applicationContext.bindClass(_1.MidwayPriorityManager);
|
|
139
140
|
printStepDebugInfo('Binding preload module');
|
|
140
141
|
// bind preload module
|
|
141
142
|
if (globalOptions.preloadModules && globalOptions.preloadModules.length) {
|
|
@@ -230,6 +231,7 @@ function prepareGlobalApplicationContext(globalOptions) {
|
|
|
230
231
|
applicationContext.bindClass(_1.MidwayWebRouterService);
|
|
231
232
|
applicationContext.bindClass(slsFunctionService_1.MidwayServerlessFunctionService);
|
|
232
233
|
applicationContext.bindClass(healthService_1.MidwayHealthService);
|
|
234
|
+
applicationContext.bindClass(_1.MidwayPriorityManager);
|
|
233
235
|
printStepDebugInfo('Binding preload module');
|
|
234
236
|
// bind preload module
|
|
235
237
|
if (globalOptions.preloadModules && globalOptions.preloadModules.length) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/core",
|
|
3
|
-
"version": "3.14.
|
|
3
|
+
"version": "3.14.4",
|
|
4
4
|
"description": "midway core",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"engines": {
|
|
43
43
|
"node": ">=12"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "72aacdfd87ef730f100690557de48dcbd4d806a7"
|
|
46
46
|
}
|