@midwayjs/core 3.18.0 → 3.19.0-beta.1
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/performanceManager.d.ts +44 -0
- package/dist/common/performanceManager.js +128 -0
- package/dist/common/typedResourceManager.d.ts +37 -0
- package/dist/common/typedResourceManager.js +55 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/dist/service/frameworkService.js +3 -0
- package/dist/service/lifeCycleService.js +5 -1
- package/dist/setup.js +29 -0
- package/package.json +2 -2
- package/LICENSE +0 -21
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { PerformanceObserver, PerformanceObserverEntryList } from 'perf_hooks';
|
|
3
|
+
export declare class MidwayPerformanceManager {
|
|
4
|
+
private readonly group;
|
|
5
|
+
private static instances;
|
|
6
|
+
static DEFAULT_GROUP: {
|
|
7
|
+
INITIALIZE: string;
|
|
8
|
+
};
|
|
9
|
+
private observer;
|
|
10
|
+
private marks;
|
|
11
|
+
private measures;
|
|
12
|
+
private constructor();
|
|
13
|
+
static getInstance(group: string): MidwayPerformanceManager;
|
|
14
|
+
private formatKey;
|
|
15
|
+
markStart(key: string): void;
|
|
16
|
+
markEnd(key: string): void;
|
|
17
|
+
observeMeasure(callback: (list: PerformanceObserverEntryList) => void): PerformanceObserver;
|
|
18
|
+
disconnect(): void;
|
|
19
|
+
getGroup(): string;
|
|
20
|
+
clean(): void;
|
|
21
|
+
static cleanAll(): void;
|
|
22
|
+
}
|
|
23
|
+
export declare class MidwayInitializerPerformanceManager {
|
|
24
|
+
static MEASURE_KEYS: {
|
|
25
|
+
INITIALIZE: string;
|
|
26
|
+
METADATA_PREPARE: string;
|
|
27
|
+
DETECTOR_PREPARE: string;
|
|
28
|
+
DEFINITION_PREPARE: string;
|
|
29
|
+
CONFIG_LOAD: string;
|
|
30
|
+
LOGGER_PREPARE: string;
|
|
31
|
+
FRAMEWORK_PREPARE: string;
|
|
32
|
+
CUSTOM_FRAMEWORK_PREPARE: string;
|
|
33
|
+
LIFECYCLE_PREPARE: string;
|
|
34
|
+
CUSTOM_LIFECYCLE_PREPARE: string;
|
|
35
|
+
PRELOAD_MODULE_PREPARE: string;
|
|
36
|
+
};
|
|
37
|
+
static markStart(key: string): void;
|
|
38
|
+
static markEnd(key: string): void;
|
|
39
|
+
static frameworkInitializeStart(frameworkName: string): void;
|
|
40
|
+
static frameworkInitializeEnd(frameworkName: string): void;
|
|
41
|
+
static lifecycleStart(namespace: string, lifecycleName: string): void;
|
|
42
|
+
static lifecycleEnd(namespace: string, lifecycleName: string): void;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=performanceManager.d.ts.map
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MidwayInitializerPerformanceManager = exports.MidwayPerformanceManager = void 0;
|
|
4
|
+
const perf_hooks_1 = require("perf_hooks");
|
|
5
|
+
class MidwayPerformanceManager {
|
|
6
|
+
constructor(group) {
|
|
7
|
+
this.group = group;
|
|
8
|
+
this.observer = null;
|
|
9
|
+
this.marks = new Set();
|
|
10
|
+
this.measures = new Set();
|
|
11
|
+
}
|
|
12
|
+
static getInstance(group) {
|
|
13
|
+
if (!this.instances.has(group)) {
|
|
14
|
+
this.instances.set(group, new MidwayPerformanceManager(group));
|
|
15
|
+
}
|
|
16
|
+
return this.instances.get(group);
|
|
17
|
+
}
|
|
18
|
+
formatKey(key, step) {
|
|
19
|
+
return `${this.group}:${key}-${step}`;
|
|
20
|
+
}
|
|
21
|
+
markStart(key) {
|
|
22
|
+
const markKey = this.formatKey(key, 'start');
|
|
23
|
+
perf_hooks_1.performance.mark(markKey);
|
|
24
|
+
this.marks.add(markKey);
|
|
25
|
+
}
|
|
26
|
+
markEnd(key) {
|
|
27
|
+
const startKey = this.formatKey(key, 'start');
|
|
28
|
+
const endKey = this.formatKey(key, 'end');
|
|
29
|
+
const measureKey = `${this.group}:${key}`;
|
|
30
|
+
perf_hooks_1.performance.mark(endKey);
|
|
31
|
+
this.marks.add(endKey);
|
|
32
|
+
perf_hooks_1.performance.measure(measureKey, startKey, endKey);
|
|
33
|
+
this.measures.add(measureKey);
|
|
34
|
+
}
|
|
35
|
+
observeMeasure(callback) {
|
|
36
|
+
if (this.observer) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
this.observer = new perf_hooks_1.PerformanceObserver(list => {
|
|
40
|
+
const filteredEntries = list
|
|
41
|
+
.getEntries()
|
|
42
|
+
.filter(entry => entry.name.startsWith(`${this.group}:`));
|
|
43
|
+
if (filteredEntries.length > 0) {
|
|
44
|
+
callback({
|
|
45
|
+
getEntries: () => filteredEntries,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
this.observer.observe({ entryTypes: ['measure'] });
|
|
50
|
+
return this.observer;
|
|
51
|
+
}
|
|
52
|
+
disconnect() {
|
|
53
|
+
if (this.observer) {
|
|
54
|
+
this.observer.disconnect();
|
|
55
|
+
this.observer = null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
getGroup() {
|
|
59
|
+
return this.group;
|
|
60
|
+
}
|
|
61
|
+
clean() {
|
|
62
|
+
this.marks.forEach(mark => {
|
|
63
|
+
try {
|
|
64
|
+
perf_hooks_1.performance.clearMarks(mark);
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
console.warn(`Failed to clear mark ${mark}: ${error}`);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
this.marks.clear();
|
|
71
|
+
this.measures.forEach(measure => {
|
|
72
|
+
try {
|
|
73
|
+
perf_hooks_1.performance.clearMeasures(measure);
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
console.warn(`Failed to clear measure ${measure}: ${error}`);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
this.measures.clear();
|
|
80
|
+
this.disconnect();
|
|
81
|
+
}
|
|
82
|
+
static cleanAll() {
|
|
83
|
+
this.instances.forEach(instance => instance.clean());
|
|
84
|
+
this.instances.clear();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.MidwayPerformanceManager = MidwayPerformanceManager;
|
|
88
|
+
MidwayPerformanceManager.instances = new Map();
|
|
89
|
+
MidwayPerformanceManager.DEFAULT_GROUP = {
|
|
90
|
+
INITIALIZE: 'MidwayInitialize',
|
|
91
|
+
};
|
|
92
|
+
class MidwayInitializerPerformanceManager {
|
|
93
|
+
static markStart(key) {
|
|
94
|
+
const manager = MidwayPerformanceManager.getInstance(MidwayPerformanceManager.DEFAULT_GROUP.INITIALIZE);
|
|
95
|
+
manager.markStart(key);
|
|
96
|
+
}
|
|
97
|
+
static markEnd(key) {
|
|
98
|
+
const manager = MidwayPerformanceManager.getInstance(MidwayPerformanceManager.DEFAULT_GROUP.INITIALIZE);
|
|
99
|
+
manager.markEnd(key);
|
|
100
|
+
}
|
|
101
|
+
static frameworkInitializeStart(frameworkName) {
|
|
102
|
+
this.markStart(`${this.MEASURE_KEYS.CUSTOM_FRAMEWORK_PREPARE}:${frameworkName}`);
|
|
103
|
+
}
|
|
104
|
+
static frameworkInitializeEnd(frameworkName) {
|
|
105
|
+
this.markEnd(`${this.MEASURE_KEYS.CUSTOM_FRAMEWORK_PREPARE}:${frameworkName}`);
|
|
106
|
+
}
|
|
107
|
+
static lifecycleStart(namespace, lifecycleName) {
|
|
108
|
+
this.markStart(`${this.MEASURE_KEYS.CUSTOM_LIFECYCLE_PREPARE}:${namespace}:${lifecycleName}`);
|
|
109
|
+
}
|
|
110
|
+
static lifecycleEnd(namespace, lifecycleName) {
|
|
111
|
+
this.markEnd(`${this.MEASURE_KEYS.CUSTOM_LIFECYCLE_PREPARE}:${namespace}:${lifecycleName}`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
exports.MidwayInitializerPerformanceManager = MidwayInitializerPerformanceManager;
|
|
115
|
+
MidwayInitializerPerformanceManager.MEASURE_KEYS = {
|
|
116
|
+
INITIALIZE: 'Initialize',
|
|
117
|
+
METADATA_PREPARE: 'MetadataPrepare',
|
|
118
|
+
DETECTOR_PREPARE: 'DetectorPrepare',
|
|
119
|
+
DEFINITION_PREPARE: 'DefinitionPrepare',
|
|
120
|
+
CONFIG_LOAD: 'ConfigLoad',
|
|
121
|
+
LOGGER_PREPARE: 'LoggerPrepare',
|
|
122
|
+
FRAMEWORK_PREPARE: 'FrameworkPrepare',
|
|
123
|
+
CUSTOM_FRAMEWORK_PREPARE: 'CustomFrameworkPrepare',
|
|
124
|
+
LIFECYCLE_PREPARE: 'LifecyclePrepare',
|
|
125
|
+
CUSTOM_LIFECYCLE_PREPARE: 'CustomLifecyclePrepare',
|
|
126
|
+
PRELOAD_MODULE_PREPARE: 'PreloadModulePrepare',
|
|
127
|
+
};
|
|
128
|
+
//# sourceMappingURL=performanceManager.js.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ClassType } from '../interface';
|
|
2
|
+
export declare class TypedResourceManager<Resource = any, ResourceInitializeConfig = any, ResourceProviderType = any> {
|
|
3
|
+
protected typedResourceInitializerOptions: {
|
|
4
|
+
initializeValue: {
|
|
5
|
+
[resourceName: string]: ResourceInitializeConfig;
|
|
6
|
+
};
|
|
7
|
+
initializeClzProvider: {
|
|
8
|
+
[resourceName: string]: ClassType<ResourceProviderType>;
|
|
9
|
+
};
|
|
10
|
+
resourceInitialize: (resourceInitializeConfig: ResourceInitializeConfig, resourceName: string) => Promise<Resource>;
|
|
11
|
+
resourceBinding: (ClzProvider: ClassType<ResourceProviderType>, resourceInitializeConfig: ResourceInitializeConfig, resource: Resource, resourceName: string) => Promise<any>;
|
|
12
|
+
resourceStart: (resource: Resource, resourceInitializeConfig: ResourceInitializeConfig, resourceBindingResult?: any) => Promise<void>;
|
|
13
|
+
resourceDestroy: (resource: Resource, resourceInitializeConfig: ResourceInitializeConfig) => Promise<void>;
|
|
14
|
+
};
|
|
15
|
+
private resourceMap;
|
|
16
|
+
private resourceBindingMap;
|
|
17
|
+
constructor(typedResourceInitializerOptions: {
|
|
18
|
+
initializeValue: {
|
|
19
|
+
[resourceName: string]: ResourceInitializeConfig;
|
|
20
|
+
};
|
|
21
|
+
initializeClzProvider: {
|
|
22
|
+
[resourceName: string]: ClassType<ResourceProviderType>;
|
|
23
|
+
};
|
|
24
|
+
resourceInitialize: (resourceInitializeConfig: ResourceInitializeConfig, resourceName: string) => Promise<Resource>;
|
|
25
|
+
resourceBinding: (ClzProvider: ClassType<ResourceProviderType>, resourceInitializeConfig: ResourceInitializeConfig, resource: Resource, resourceName: string) => Promise<any>;
|
|
26
|
+
resourceStart: (resource: Resource, resourceInitializeConfig: ResourceInitializeConfig, resourceBindingResult?: any) => Promise<void>;
|
|
27
|
+
resourceDestroy: (resource: Resource, resourceInitializeConfig: ResourceInitializeConfig) => Promise<void>;
|
|
28
|
+
});
|
|
29
|
+
createResource(resourceName: string, resourceInitializeConfig: ResourceInitializeConfig): Promise<Resource>;
|
|
30
|
+
init(): Promise<void>;
|
|
31
|
+
startParallel(): Promise<void>;
|
|
32
|
+
start(): Promise<void>;
|
|
33
|
+
destroyParallel(): Promise<void>;
|
|
34
|
+
destroy(): Promise<void>;
|
|
35
|
+
getResource(resourceName: string): any;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=typedResourceManager.d.ts.map
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypedResourceManager = void 0;
|
|
4
|
+
class TypedResourceManager {
|
|
5
|
+
constructor(typedResourceInitializerOptions) {
|
|
6
|
+
this.typedResourceInitializerOptions = typedResourceInitializerOptions;
|
|
7
|
+
this.resourceMap = new Map();
|
|
8
|
+
this.resourceBindingMap = new Map();
|
|
9
|
+
}
|
|
10
|
+
async createResource(resourceName, resourceInitializeConfig) {
|
|
11
|
+
const resource = await this.typedResourceInitializerOptions.resourceInitialize(resourceInitializeConfig, resourceName);
|
|
12
|
+
this.resourceMap.set(resourceName, resource);
|
|
13
|
+
return resource;
|
|
14
|
+
}
|
|
15
|
+
async init() {
|
|
16
|
+
for (const resourceName of Object.keys(this.typedResourceInitializerOptions.initializeValue)) {
|
|
17
|
+
const resourceInitializeConfig = this.typedResourceInitializerOptions.initializeValue[resourceName];
|
|
18
|
+
const ClzProvider = this.typedResourceInitializerOptions.initializeClzProvider[resourceName];
|
|
19
|
+
const resource = await this.createResource(resourceName, resourceInitializeConfig);
|
|
20
|
+
const bindingResult = await this.typedResourceInitializerOptions.resourceBinding(ClzProvider, resourceInitializeConfig, resource, resourceName);
|
|
21
|
+
if (bindingResult) {
|
|
22
|
+
this.resourceBindingMap.set(resourceName, bindingResult);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
async startParallel() {
|
|
27
|
+
const startPromises = [];
|
|
28
|
+
for (const [resourceName, resource] of this.resourceMap.entries()) {
|
|
29
|
+
startPromises.push(this.typedResourceInitializerOptions.resourceStart(resource, this.typedResourceInitializerOptions.initializeValue[resourceName], this.resourceBindingMap.get(resourceName)));
|
|
30
|
+
}
|
|
31
|
+
await Promise.all(startPromises);
|
|
32
|
+
}
|
|
33
|
+
async start() {
|
|
34
|
+
for (const [resourceName, resource] of this.resourceMap.entries()) {
|
|
35
|
+
await this.typedResourceInitializerOptions.resourceStart(resource, this.typedResourceInitializerOptions.initializeValue[resourceName], this.resourceBindingMap.get(resourceName));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async destroyParallel() {
|
|
39
|
+
const destroyPromises = [];
|
|
40
|
+
for (const [resourceName, resource] of this.resourceMap.entries()) {
|
|
41
|
+
destroyPromises.push(this.typedResourceInitializerOptions.resourceDestroy(resource, this.typedResourceInitializerOptions.initializeValue[resourceName]));
|
|
42
|
+
}
|
|
43
|
+
await Promise.all(destroyPromises);
|
|
44
|
+
}
|
|
45
|
+
async destroy() {
|
|
46
|
+
for (const [resourceName, resource] of this.resourceMap.entries()) {
|
|
47
|
+
await this.typedResourceInitializerOptions.resourceDestroy(resource, this.typedResourceInitializerOptions.initializeValue[resourceName]);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
getResource(resourceName) {
|
|
51
|
+
return this.resourceMap.get(resourceName);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.TypedResourceManager = TypedResourceManager;
|
|
55
|
+
//# sourceMappingURL=typedResourceManager.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -47,4 +47,5 @@ export { PathFileUtil } from './util/pathFileUtil';
|
|
|
47
47
|
export { FileUtils } from './util/fs';
|
|
48
48
|
export { FORMAT } from './util/format';
|
|
49
49
|
export { ServerResponse, HttpServerResponse } from './response/index';
|
|
50
|
+
export { MidwayPerformanceManager } from './common/performanceManager';
|
|
50
51
|
//# sourceMappingURL=index.d.ts.map
|
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.HttpServerResponse = exports.ServerResponse = 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;
|
|
17
|
+
exports.MidwayPerformanceManager = exports.HttpServerResponse = exports.ServerResponse = 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");
|
|
@@ -112,4 +112,6 @@ Object.defineProperty(exports, "FORMAT", { enumerable: true, get: function () {
|
|
|
112
112
|
var index_1 = require("./response/index");
|
|
113
113
|
Object.defineProperty(exports, "ServerResponse", { enumerable: true, get: function () { return index_1.ServerResponse; } });
|
|
114
114
|
Object.defineProperty(exports, "HttpServerResponse", { enumerable: true, get: function () { return index_1.HttpServerResponse; } });
|
|
115
|
+
var performanceManager_1 = require("./common/performanceManager");
|
|
116
|
+
Object.defineProperty(exports, "MidwayPerformanceManager", { enumerable: true, get: function () { return performanceManager_1.MidwayPerformanceManager; } });
|
|
115
117
|
//# sourceMappingURL=index.js.map
|
|
@@ -22,6 +22,7 @@ const applicationManager_1 = require("../common/applicationManager");
|
|
|
22
22
|
const util = require("util");
|
|
23
23
|
const error_1 = require("../error");
|
|
24
24
|
const constants_1 = require("../constants");
|
|
25
|
+
const performanceManager_1 = require("../common/performanceManager");
|
|
25
26
|
const debug = util.debuglog('midway:debug');
|
|
26
27
|
let MidwayFrameworkService = class MidwayFrameworkService {
|
|
27
28
|
constructor(applicationContext, globalOptions) {
|
|
@@ -95,12 +96,14 @@ let MidwayFrameworkService = class MidwayFrameworkService {
|
|
|
95
96
|
const frameworkInstance = await this.applicationContext.getAsync(frameworkClz, [this.applicationContext]);
|
|
96
97
|
// if enable, just init framework
|
|
97
98
|
if (frameworkInstance.isEnable()) {
|
|
99
|
+
performanceManager_1.MidwayInitializerPerformanceManager.frameworkInitializeStart(frameworkInstance.getFrameworkName());
|
|
98
100
|
// app init
|
|
99
101
|
await frameworkInstance.initialize({
|
|
100
102
|
applicationContext: this.applicationContext,
|
|
101
103
|
namespace: frameworkInstance.getNamespace(),
|
|
102
104
|
...this.globalOptions,
|
|
103
105
|
});
|
|
106
|
+
performanceManager_1.MidwayInitializerPerformanceManager.frameworkInitializeEnd(frameworkInstance.getFrameworkName());
|
|
104
107
|
debug(`[core]: Found Framework "${frameworkInstance.getFrameworkName()}" and initialize.`);
|
|
105
108
|
}
|
|
106
109
|
else {
|
|
@@ -18,6 +18,7 @@ const configService_1 = require("./configService");
|
|
|
18
18
|
const util_1 = require("util");
|
|
19
19
|
const mockService_1 = require("./mockService");
|
|
20
20
|
const healthService_1 = require("./healthService");
|
|
21
|
+
const performanceManager_1 = require("../common/performanceManager");
|
|
21
22
|
const debug = (0, util_1.debuglog)('midway:debug');
|
|
22
23
|
let MidwayLifeCycleService = class MidwayLifeCycleService {
|
|
23
24
|
constructor(applicationContext) {
|
|
@@ -126,7 +127,10 @@ let MidwayLifeCycleService = class MidwayLifeCycleService {
|
|
|
126
127
|
for (const cycle of lifecycleInstanceList) {
|
|
127
128
|
if (typeof cycle.instance[lifecycle] === 'function') {
|
|
128
129
|
debug(`[core]: Lifecycle run ${cycle.instance.constructor.name} ${lifecycle}`);
|
|
129
|
-
|
|
130
|
+
performanceManager_1.MidwayInitializerPerformanceManager.lifecycleStart(cycle.namespace, lifecycle);
|
|
131
|
+
const result = await this.applicationContext[lifecycle](cycle.instance[lifecycle].bind(cycle.instance));
|
|
132
|
+
performanceManager_1.MidwayInitializerPerformanceManager.lifecycleEnd(cycle.namespace, lifecycle);
|
|
133
|
+
return result;
|
|
130
134
|
}
|
|
131
135
|
}
|
|
132
136
|
}
|
package/dist/setup.js
CHANGED
|
@@ -8,6 +8,7 @@ const util = require("util");
|
|
|
8
8
|
const slsFunctionService_1 = require("./service/slsFunctionService");
|
|
9
9
|
const path_1 = require("path");
|
|
10
10
|
const healthService_1 = require("./service/healthService");
|
|
11
|
+
const performanceManager_1 = require("./common/performanceManager");
|
|
11
12
|
const debug = util.debuglog('midway:debug');
|
|
12
13
|
let stepIdx = 1;
|
|
13
14
|
function printStepDebugInfo(stepInfo) {
|
|
@@ -18,8 +19,10 @@ function printStepDebugInfo(stepInfo) {
|
|
|
18
19
|
* @param globalOptions
|
|
19
20
|
*/
|
|
20
21
|
async function initializeGlobalApplicationContext(globalOptions) {
|
|
22
|
+
performanceManager_1.MidwayInitializerPerformanceManager.markStart(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.INITIALIZE);
|
|
21
23
|
const applicationContext = await prepareGlobalApplicationContextAsync(globalOptions);
|
|
22
24
|
printStepDebugInfo('Init logger');
|
|
25
|
+
performanceManager_1.MidwayInitializerPerformanceManager.markStart(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.LOGGER_PREPARE);
|
|
23
26
|
// init logger
|
|
24
27
|
const loggerService = await applicationContext.getAsync(_1.MidwayLoggerService, [
|
|
25
28
|
applicationContext,
|
|
@@ -29,28 +32,36 @@ async function initializeGlobalApplicationContext(globalOptions) {
|
|
|
29
32
|
// register global logger
|
|
30
33
|
applicationContext.registerObject('logger', loggerService.getLogger('appLogger'));
|
|
31
34
|
}
|
|
35
|
+
performanceManager_1.MidwayInitializerPerformanceManager.markEnd(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.LOGGER_PREPARE);
|
|
32
36
|
printStepDebugInfo('Init MidwayMockService');
|
|
33
37
|
// mock support
|
|
34
38
|
await applicationContext.getAsync(_1.MidwayMockService, [applicationContext]);
|
|
35
39
|
printStepDebugInfo('Init framework');
|
|
40
|
+
performanceManager_1.MidwayInitializerPerformanceManager.markStart(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.FRAMEWORK_PREPARE);
|
|
36
41
|
// framework/config/plugin/logger/app decorator support
|
|
37
42
|
await applicationContext.getAsync(_1.MidwayFrameworkService, [
|
|
38
43
|
applicationContext,
|
|
39
44
|
globalOptions,
|
|
40
45
|
]);
|
|
46
|
+
performanceManager_1.MidwayInitializerPerformanceManager.markEnd(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.FRAMEWORK_PREPARE);
|
|
41
47
|
printStepDebugInfo('Init lifecycle');
|
|
48
|
+
performanceManager_1.MidwayInitializerPerformanceManager.markStart(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.LIFECYCLE_PREPARE);
|
|
42
49
|
// lifecycle support
|
|
43
50
|
await applicationContext.getAsync(_1.MidwayLifeCycleService, [
|
|
44
51
|
applicationContext,
|
|
45
52
|
]);
|
|
53
|
+
performanceManager_1.MidwayInitializerPerformanceManager.markEnd(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.LIFECYCLE_PREPARE);
|
|
46
54
|
printStepDebugInfo('Init preload modules');
|
|
55
|
+
performanceManager_1.MidwayInitializerPerformanceManager.markStart(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.PRELOAD_MODULE_PREPARE);
|
|
47
56
|
// some preload module init
|
|
48
57
|
const modules = (0, decorator_1.listPreloadModule)();
|
|
49
58
|
for (const module of modules) {
|
|
50
59
|
// preload init context
|
|
51
60
|
await applicationContext.getAsync(module);
|
|
52
61
|
}
|
|
62
|
+
performanceManager_1.MidwayInitializerPerformanceManager.markEnd(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.PRELOAD_MODULE_PREPARE);
|
|
53
63
|
printStepDebugInfo('End of initialize and start');
|
|
64
|
+
performanceManager_1.MidwayInitializerPerformanceManager.markEnd(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.INITIALIZE);
|
|
54
65
|
return applicationContext;
|
|
55
66
|
}
|
|
56
67
|
exports.initializeGlobalApplicationContext = initializeGlobalApplicationContext;
|
|
@@ -64,6 +75,7 @@ async function destroyGlobalApplicationContext(applicationContext) {
|
|
|
64
75
|
await applicationContext.stop();
|
|
65
76
|
(0, decorator_1.clearBindContainer)();
|
|
66
77
|
loggerFactory.close();
|
|
78
|
+
performanceManager_1.MidwayPerformanceManager.cleanAll();
|
|
67
79
|
global['MIDWAY_APPLICATION_CONTEXT'] = undefined;
|
|
68
80
|
global['MIDWAY_MAIN_FRAMEWORK'] = undefined;
|
|
69
81
|
}
|
|
@@ -79,6 +91,7 @@ async function prepareGlobalApplicationContextAsync(globalOptions) {
|
|
|
79
91
|
debug(`[core]: bootstrap options = ${util.inspect(globalOptions)}`);
|
|
80
92
|
const appDir = (_a = globalOptions.appDir) !== null && _a !== void 0 ? _a : '';
|
|
81
93
|
const baseDir = (_b = globalOptions.baseDir) !== null && _b !== void 0 ? _b : '';
|
|
94
|
+
performanceManager_1.MidwayInitializerPerformanceManager.markStart(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.METADATA_PREPARE);
|
|
82
95
|
// new container
|
|
83
96
|
const applicationContext = (_c = globalOptions.applicationContext) !== null && _c !== void 0 ? _c : new _1.MidwayContainer();
|
|
84
97
|
// bind container to decoratorManager
|
|
@@ -88,7 +101,10 @@ async function prepareGlobalApplicationContextAsync(globalOptions) {
|
|
|
88
101
|
// register baseDir and appDir
|
|
89
102
|
applicationContext.registerObject('baseDir', baseDir);
|
|
90
103
|
applicationContext.registerObject('appDir', appDir);
|
|
104
|
+
performanceManager_1.MidwayInitializerPerformanceManager.markEnd(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.METADATA_PREPARE);
|
|
91
105
|
debug('[core]: set default file detector');
|
|
106
|
+
performanceManager_1.MidwayInitializerPerformanceManager.markStart(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.DETECTOR_PREPARE);
|
|
107
|
+
printStepDebugInfo('Ready module detector');
|
|
92
108
|
if (!globalOptions.moduleLoadType) {
|
|
93
109
|
globalOptions.moduleLoadType = 'commonjs';
|
|
94
110
|
}
|
|
@@ -120,6 +136,7 @@ async function prepareGlobalApplicationContextAsync(globalOptions) {
|
|
|
120
136
|
}
|
|
121
137
|
}
|
|
122
138
|
}
|
|
139
|
+
performanceManager_1.MidwayInitializerPerformanceManager.markEnd(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.DETECTOR_PREPARE);
|
|
123
140
|
printStepDebugInfo('Binding inner service');
|
|
124
141
|
// bind inner service
|
|
125
142
|
applicationContext.bindClass(_1.MidwayEnvironmentService);
|
|
@@ -162,8 +179,11 @@ async function prepareGlobalApplicationContextAsync(globalOptions) {
|
|
|
162
179
|
printStepDebugInfo('Load imports(component) and user code configuration module');
|
|
163
180
|
applicationContext.load([].concat(globalOptions.imports).concat(globalOptions.configurationModule));
|
|
164
181
|
printStepDebugInfo('Run applicationContext ready method');
|
|
182
|
+
performanceManager_1.MidwayInitializerPerformanceManager.markStart(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.DEFINITION_PREPARE);
|
|
165
183
|
// bind user code module
|
|
166
184
|
await applicationContext.ready();
|
|
185
|
+
performanceManager_1.MidwayInitializerPerformanceManager.markEnd(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.DEFINITION_PREPARE);
|
|
186
|
+
performanceManager_1.MidwayInitializerPerformanceManager.markStart(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.CONFIG_LOAD);
|
|
167
187
|
if (globalOptions.globalConfig) {
|
|
168
188
|
if (Array.isArray(globalOptions.globalConfig)) {
|
|
169
189
|
configService.add(globalOptions.globalConfig);
|
|
@@ -176,6 +196,7 @@ async function prepareGlobalApplicationContextAsync(globalOptions) {
|
|
|
176
196
|
// merge config
|
|
177
197
|
configService.load();
|
|
178
198
|
debug('[core]: Current config = %j', configService.getConfiguration());
|
|
199
|
+
performanceManager_1.MidwayInitializerPerformanceManager.markEnd(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.CONFIG_LOAD);
|
|
179
200
|
// middleware support
|
|
180
201
|
applicationContext.get(_1.MidwayMiddlewareService, [applicationContext]);
|
|
181
202
|
return applicationContext;
|
|
@@ -192,6 +213,7 @@ function prepareGlobalApplicationContext(globalOptions) {
|
|
|
192
213
|
debug(`[core]: bootstrap options = ${util.inspect(globalOptions)}`);
|
|
193
214
|
const appDir = (_a = globalOptions.appDir) !== null && _a !== void 0 ? _a : '';
|
|
194
215
|
const baseDir = (_b = globalOptions.baseDir) !== null && _b !== void 0 ? _b : '';
|
|
216
|
+
performanceManager_1.MidwayInitializerPerformanceManager.markStart(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.METADATA_PREPARE);
|
|
195
217
|
// new container
|
|
196
218
|
const applicationContext = (_c = globalOptions.applicationContext) !== null && _c !== void 0 ? _c : new _1.MidwayContainer();
|
|
197
219
|
// bind container to decoratorManager
|
|
@@ -201,7 +223,9 @@ function prepareGlobalApplicationContext(globalOptions) {
|
|
|
201
223
|
// register baseDir and appDir
|
|
202
224
|
applicationContext.registerObject('baseDir', baseDir);
|
|
203
225
|
applicationContext.registerObject('appDir', appDir);
|
|
226
|
+
performanceManager_1.MidwayInitializerPerformanceManager.markEnd(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.METADATA_PREPARE);
|
|
204
227
|
printStepDebugInfo('Ready module detector');
|
|
228
|
+
performanceManager_1.MidwayInitializerPerformanceManager.markStart(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.DETECTOR_PREPARE);
|
|
205
229
|
if (!globalOptions.moduleLoadType) {
|
|
206
230
|
globalOptions.moduleLoadType = 'commonjs';
|
|
207
231
|
}
|
|
@@ -215,6 +239,7 @@ function prepareGlobalApplicationContext(globalOptions) {
|
|
|
215
239
|
applicationContext.setFileDetector(globalOptions.moduleDetector);
|
|
216
240
|
}
|
|
217
241
|
}
|
|
242
|
+
performanceManager_1.MidwayInitializerPerformanceManager.markEnd(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.DETECTOR_PREPARE);
|
|
218
243
|
printStepDebugInfo('Binding inner service');
|
|
219
244
|
// bind inner service
|
|
220
245
|
applicationContext.bindClass(_1.MidwayEnvironmentService);
|
|
@@ -262,8 +287,11 @@ function prepareGlobalApplicationContext(globalOptions) {
|
|
|
262
287
|
}
|
|
263
288
|
applicationContext.load([].concat(globalOptions.imports).concat(globalOptions.configurationModule));
|
|
264
289
|
printStepDebugInfo('Run applicationContext ready method');
|
|
290
|
+
performanceManager_1.MidwayInitializerPerformanceManager.markStart(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.DEFINITION_PREPARE);
|
|
265
291
|
// bind user code module
|
|
266
292
|
applicationContext.ready();
|
|
293
|
+
performanceManager_1.MidwayInitializerPerformanceManager.markEnd(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.DEFINITION_PREPARE);
|
|
294
|
+
performanceManager_1.MidwayInitializerPerformanceManager.markStart(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.CONFIG_LOAD);
|
|
267
295
|
if (globalOptions.globalConfig) {
|
|
268
296
|
if (Array.isArray(globalOptions.globalConfig)) {
|
|
269
297
|
configService.add(globalOptions.globalConfig);
|
|
@@ -276,6 +304,7 @@ function prepareGlobalApplicationContext(globalOptions) {
|
|
|
276
304
|
// merge config
|
|
277
305
|
configService.load();
|
|
278
306
|
debug('[core]: Current config = %j', configService.getConfiguration());
|
|
307
|
+
performanceManager_1.MidwayInitializerPerformanceManager.markEnd(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.CONFIG_LOAD);
|
|
279
308
|
// middleware support
|
|
280
309
|
applicationContext.get(_1.MidwayMiddlewareService, [applicationContext]);
|
|
281
310
|
return applicationContext;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.19.0-beta.1",
|
|
4
4
|
"description": "midway core",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"engines": {
|
|
44
44
|
"node": ">=12"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "a603d2348d6141f8f723901498f03a162a037708"
|
|
47
47
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2013 - Now midwayjs
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|