@midwayjs/core 3.3.2 → 3.4.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/dataSourceManager.d.ts +28 -0
- package/dist/common/dataSourceManager.js +69 -0
- package/dist/common/fileDetector.d.ts +1 -0
- package/dist/common/fileDetector.js +20 -0
- package/dist/common/filterManager.d.ts +1 -0
- package/dist/common/filterManager.js +37 -5
- package/dist/common/serviceFactory.js +2 -1
- package/dist/common/triggerCollector.d.ts +2 -2
- package/dist/context/container.js +3 -0
- package/dist/error/framework.d.ts +8 -0
- package/dist/error/framework.js +15 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -1
- package/dist/interface.d.ts +9 -0
- package/dist/service/configService.js +6 -2
- package/dist/service/frameworkService.js +16 -16
- package/dist/util/index.d.ts +1 -0
- package/dist/util/index.js +22 -1
- package/package.json +4 -4
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export declare abstract class DataSourceManager<T> {
|
|
2
|
+
protected dataSource: Map<string, T>;
|
|
3
|
+
protected options: {};
|
|
4
|
+
protected initDataSource(options?: any): Promise<void>;
|
|
5
|
+
/**
|
|
6
|
+
* get a data source instance
|
|
7
|
+
* @param dataSourceName
|
|
8
|
+
*/
|
|
9
|
+
getDataSource(dataSourceName: string): T;
|
|
10
|
+
/**
|
|
11
|
+
* check data source has exists
|
|
12
|
+
* @param dataSourceName
|
|
13
|
+
*/
|
|
14
|
+
hasDataSource(dataSourceName: string): boolean;
|
|
15
|
+
getDataSourceNames(): string[];
|
|
16
|
+
/**
|
|
17
|
+
* check the data source is connected
|
|
18
|
+
* @param dataSourceName
|
|
19
|
+
*/
|
|
20
|
+
isConnected(dataSourceName: string): Promise<boolean>;
|
|
21
|
+
createInstance(config: any, clientName: any): Promise<T | void>;
|
|
22
|
+
abstract getName(): string;
|
|
23
|
+
protected abstract createDataSource(config: any, dataSourceName: string): Promise<T | void> | (T | void);
|
|
24
|
+
protected abstract checkConnected(dataSource: T): Promise<boolean>;
|
|
25
|
+
protected destroyDataSource(dataSource: T): Promise<void>;
|
|
26
|
+
stop(): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=dataSourceManager.d.ts.map
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DataSourceManager = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* 数据源管理器实现
|
|
6
|
+
*/
|
|
7
|
+
const extend_1 = require("../util/extend");
|
|
8
|
+
const error_1 = require("../error");
|
|
9
|
+
class DataSourceManager {
|
|
10
|
+
constructor() {
|
|
11
|
+
this.dataSource = new Map();
|
|
12
|
+
this.options = {};
|
|
13
|
+
}
|
|
14
|
+
async initDataSource(options = {}) {
|
|
15
|
+
this.options = options;
|
|
16
|
+
if (options.dataSource) {
|
|
17
|
+
for (const dataSourceName in options.dataSource) {
|
|
18
|
+
// create data source
|
|
19
|
+
await this.createInstance(options.dataSource[dataSourceName], dataSourceName);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
throw new error_1.MidwayParameterError('DataSourceManager must set options.dataSource.');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* get a data source instance
|
|
28
|
+
* @param dataSourceName
|
|
29
|
+
*/
|
|
30
|
+
getDataSource(dataSourceName) {
|
|
31
|
+
return this.dataSource.get(dataSourceName);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* check data source has exists
|
|
35
|
+
* @param dataSourceName
|
|
36
|
+
*/
|
|
37
|
+
hasDataSource(dataSourceName) {
|
|
38
|
+
return this.dataSource.has(dataSourceName);
|
|
39
|
+
}
|
|
40
|
+
getDataSourceNames() {
|
|
41
|
+
return Array.from(this.dataSource.keys());
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* check the data source is connected
|
|
45
|
+
* @param dataSourceName
|
|
46
|
+
*/
|
|
47
|
+
async isConnected(dataSourceName) {
|
|
48
|
+
return this.checkConnected(this.getDataSource(dataSourceName));
|
|
49
|
+
}
|
|
50
|
+
async createInstance(config, clientName) {
|
|
51
|
+
// options.default will be merge in to options.clients[id]
|
|
52
|
+
config = (0, extend_1.extend)(true, {}, this.options['default'], config);
|
|
53
|
+
const client = await this.createDataSource(config, clientName);
|
|
54
|
+
if (client) {
|
|
55
|
+
if (clientName) {
|
|
56
|
+
this.dataSource.set(clientName, client);
|
|
57
|
+
}
|
|
58
|
+
return client;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
async destroyDataSource(dataSource) { }
|
|
62
|
+
async stop() {
|
|
63
|
+
for (const value of this.dataSource.values()) {
|
|
64
|
+
await this.destroyDataSource(value);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.DataSourceManager = DataSourceManager;
|
|
69
|
+
//# sourceMappingURL=dataSourceManager.js.map
|
|
@@ -13,6 +13,7 @@ export declare class DirectoryFileDetector extends AbstractFileDetector<{
|
|
|
13
13
|
namespace: string;
|
|
14
14
|
}> {
|
|
15
15
|
private directoryFilterArray;
|
|
16
|
+
private duplicateModuleCheckSet;
|
|
16
17
|
run(container: any): void;
|
|
17
18
|
}
|
|
18
19
|
export declare class CustomModuleDetector extends AbstractFileDetector<{
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.CustomModuleDetector = exports.DirectoryFileDetector = exports.AbstractFileDetector = void 0;
|
|
4
4
|
const decorator_1 = require("@midwayjs/decorator");
|
|
5
5
|
const glob_1 = require("@midwayjs/glob");
|
|
6
|
+
const error_1 = require("../error");
|
|
6
7
|
class AbstractFileDetector {
|
|
7
8
|
constructor(options) {
|
|
8
9
|
this.options = options;
|
|
@@ -31,6 +32,7 @@ class DirectoryFileDetector extends AbstractFileDetector {
|
|
|
31
32
|
constructor() {
|
|
32
33
|
super(...arguments);
|
|
33
34
|
this.directoryFilterArray = [];
|
|
35
|
+
this.duplicateModuleCheckSet = new Map();
|
|
34
36
|
}
|
|
35
37
|
run(container) {
|
|
36
38
|
const loadDirs = []
|
|
@@ -41,6 +43,20 @@ class DirectoryFileDetector extends AbstractFileDetector {
|
|
|
41
43
|
cwd: dir,
|
|
42
44
|
ignore: DEFAULT_IGNORE_PATTERN.concat(this.options.ignore || []).concat(this.extraDetectorOptions.ignore || []),
|
|
43
45
|
});
|
|
46
|
+
// 检查重复模块
|
|
47
|
+
const checkDuplicatedHandler = (module, options) => {
|
|
48
|
+
if (decorator_1.Types.isClass(module)) {
|
|
49
|
+
const name = (0, decorator_1.getProviderName)(module);
|
|
50
|
+
if (name) {
|
|
51
|
+
if (this.duplicateModuleCheckSet.has(name)) {
|
|
52
|
+
throw new error_1.MidwayDuplicateClassNameError(name, options.srcPath, this.duplicateModuleCheckSet.get(name));
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
this.duplicateModuleCheckSet.set(name, options.srcPath);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
44
60
|
for (const file of fileResults) {
|
|
45
61
|
if (this.directoryFilterArray.length) {
|
|
46
62
|
for (const resolveFilter of this.directoryFilterArray) {
|
|
@@ -68,6 +84,7 @@ class DirectoryFileDetector extends AbstractFileDetector {
|
|
|
68
84
|
namespace: this.options.namespace,
|
|
69
85
|
srcPath: file,
|
|
70
86
|
createFrom: 'file',
|
|
87
|
+
bindHook: checkDuplicatedHandler,
|
|
71
88
|
});
|
|
72
89
|
}
|
|
73
90
|
}
|
|
@@ -78,10 +95,13 @@ class DirectoryFileDetector extends AbstractFileDetector {
|
|
|
78
95
|
namespace: this.options.namespace,
|
|
79
96
|
srcPath: file,
|
|
80
97
|
createFrom: 'file',
|
|
98
|
+
bindHook: checkDuplicatedHandler,
|
|
81
99
|
});
|
|
82
100
|
}
|
|
83
101
|
}
|
|
84
102
|
}
|
|
103
|
+
// check end
|
|
104
|
+
this.duplicateModuleCheckSet.clear();
|
|
85
105
|
}
|
|
86
106
|
}
|
|
87
107
|
exports.DirectoryFileDetector = DirectoryFileDetector;
|
|
@@ -5,6 +5,7 @@ export declare class FilterManager<CTX extends IMidwayContext = IMidwayContext,
|
|
|
5
5
|
private exceptionMap;
|
|
6
6
|
private defaultErrFilter;
|
|
7
7
|
private matchFnList;
|
|
8
|
+
private protoMatchList;
|
|
8
9
|
useFilter(Filters: CommonFilterUnion<CTX, R, N>): void;
|
|
9
10
|
init(applicationContext: IMidwayContainer): Promise<void>;
|
|
10
11
|
runErrorFilter(err: Error, ctx: CTX, res?: R, next?: N): Promise<{
|
|
@@ -10,6 +10,7 @@ class FilterManager {
|
|
|
10
10
|
this.exceptionMap = new WeakMap();
|
|
11
11
|
this.defaultErrFilter = undefined;
|
|
12
12
|
this.matchFnList = [];
|
|
13
|
+
this.protoMatchList = [];
|
|
13
14
|
}
|
|
14
15
|
useFilter(Filters) {
|
|
15
16
|
if (!Array.isArray(Filters)) {
|
|
@@ -31,7 +32,20 @@ class FilterManager {
|
|
|
31
32
|
const exceptionMetadata = (0, decorator_1.getClassMetadata)(decorator_1.CATCH_KEY, FilterClass);
|
|
32
33
|
if (exceptionMetadata && exceptionMetadata.catchTargets) {
|
|
33
34
|
for (const Exception of exceptionMetadata.catchTargets) {
|
|
34
|
-
this.exceptionMap.set(Exception,
|
|
35
|
+
this.exceptionMap.set(Exception, {
|
|
36
|
+
filter,
|
|
37
|
+
catchOptions: exceptionMetadata.catchOptions || {},
|
|
38
|
+
});
|
|
39
|
+
if (exceptionMetadata.catchOptions['matchPrototype']) {
|
|
40
|
+
this.protoMatchList.push(err => {
|
|
41
|
+
if (err instanceof Exception) {
|
|
42
|
+
return Exception;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
35
49
|
}
|
|
36
50
|
}
|
|
37
51
|
else {
|
|
@@ -53,14 +67,32 @@ class FilterManager {
|
|
|
53
67
|
}
|
|
54
68
|
async runErrorFilter(err, ctx, res, next) {
|
|
55
69
|
let result, error;
|
|
70
|
+
let matched = false;
|
|
56
71
|
if (this.exceptionMap.has(err.constructor)) {
|
|
57
|
-
|
|
58
|
-
|
|
72
|
+
matched = true;
|
|
73
|
+
const filterData = this.exceptionMap.get(err.constructor);
|
|
74
|
+
result = await filterData.filter.catch(err, ctx, res, next);
|
|
59
75
|
}
|
|
60
|
-
|
|
76
|
+
// match with prototype
|
|
77
|
+
if (!matched && this.protoMatchList.length) {
|
|
78
|
+
let protoException;
|
|
79
|
+
for (const matchPattern of this.protoMatchList) {
|
|
80
|
+
protoException = matchPattern(err);
|
|
81
|
+
if (protoException) {
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (protoException) {
|
|
86
|
+
matched = true;
|
|
87
|
+
const filterData = this.exceptionMap.get(protoException);
|
|
88
|
+
result = await filterData.filter.catch(err, ctx, res, next);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (!matched && this.defaultErrFilter) {
|
|
92
|
+
matched = true;
|
|
61
93
|
result = await this.defaultErrFilter.catch(err, ctx, res, next);
|
|
62
94
|
}
|
|
63
|
-
|
|
95
|
+
if (!matched) {
|
|
64
96
|
error = err;
|
|
65
97
|
}
|
|
66
98
|
return {
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ServiceFactory = void 0;
|
|
4
4
|
const assert = require("assert");
|
|
5
|
+
const extend_1 = require("../util/extend");
|
|
5
6
|
/**
|
|
6
7
|
* 多客户端工厂实现
|
|
7
8
|
*/
|
|
@@ -33,7 +34,7 @@ class ServiceFactory {
|
|
|
33
34
|
}
|
|
34
35
|
async createInstance(config, clientName) {
|
|
35
36
|
// options.default will be merge in to options.clients[id]
|
|
36
|
-
config =
|
|
37
|
+
config = (0, extend_1.extend)(true, {}, this.options['default'], config);
|
|
37
38
|
const client = await this.createClient(config, clientName);
|
|
38
39
|
if (client) {
|
|
39
40
|
if (clientName) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { WebRouterCollector } from './webRouterCollector';
|
|
1
|
+
import { RouterInfo, WebRouterCollector } from './webRouterCollector';
|
|
2
2
|
export declare class ServerlessTriggerCollector extends WebRouterCollector {
|
|
3
3
|
protected analyze(): Promise<void>;
|
|
4
4
|
protected collectRoute(module: any): void;
|
|
5
5
|
protected collectFunctionRoute(module: any): void;
|
|
6
|
-
getFunctionList(): Promise<
|
|
6
|
+
getFunctionList(): Promise<RouterInfo[]>;
|
|
7
7
|
}
|
|
8
8
|
//# sourceMappingURL=triggerCollector.d.ts.map
|
|
@@ -274,6 +274,9 @@ class MidwayContainer {
|
|
|
274
274
|
// 如果 definition 存在就不再重复 bind
|
|
275
275
|
return;
|
|
276
276
|
}
|
|
277
|
+
if (options === null || options === void 0 ? void 0 : options.bindHook) {
|
|
278
|
+
options.bindHook(target, options);
|
|
279
|
+
}
|
|
277
280
|
let definition;
|
|
278
281
|
if (decorator_1.Types.isClass(target)) {
|
|
279
282
|
definition = new objectDefinition_1.ObjectDefinition();
|
|
@@ -15,6 +15,8 @@ export declare const FrameworkErrorEnum: {
|
|
|
15
15
|
readonly MISSING_IMPORTS: "MIDWAY_10011";
|
|
16
16
|
readonly UTIL_HTTP_TIMEOUT: "MIDWAY_10012";
|
|
17
17
|
readonly INCONSISTENT_VERSION: "MIDWAY_10013";
|
|
18
|
+
readonly INVALID_CONFIG: "MIDWAY_10014";
|
|
19
|
+
readonly DUPLICATE_CLASS_NAME: "MIDWAY_10015";
|
|
18
20
|
};
|
|
19
21
|
export declare class MidwayCommonError extends MidwayError {
|
|
20
22
|
constructor(message: string);
|
|
@@ -37,6 +39,9 @@ export declare class MidwayFeatureNotImplementedError extends MidwayError {
|
|
|
37
39
|
export declare class MidwayConfigMissingError extends MidwayError {
|
|
38
40
|
constructor(configKey: string);
|
|
39
41
|
}
|
|
42
|
+
export declare class MidwayInvalidConfigError extends MidwayError {
|
|
43
|
+
constructor(message?: string);
|
|
44
|
+
}
|
|
40
45
|
export declare class MidwayResolverMissingError extends MidwayError {
|
|
41
46
|
constructor(type: string);
|
|
42
47
|
}
|
|
@@ -58,4 +63,7 @@ export declare class MidwayUtilHttpClientTimeoutError extends MidwayError {
|
|
|
58
63
|
export declare class MidwayInconsistentVersionError extends MidwayError {
|
|
59
64
|
constructor();
|
|
60
65
|
}
|
|
66
|
+
export declare class MidwayDuplicateClassNameError extends MidwayError {
|
|
67
|
+
constructor(className: string, existPath: string, existPathOther: string);
|
|
68
|
+
}
|
|
61
69
|
//# sourceMappingURL=framework.d.ts.map
|
package/dist/error/framework.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MidwayInconsistentVersionError = exports.MidwayUtilHttpClientTimeoutError = exports.MidwayMissingImportComponentError = exports.MidwaySingletonInjectRequestError = exports.MidwayUseWrongMethodError = exports.MidwayDuplicateRouteError = exports.MidwayResolverMissingError = exports.MidwayConfigMissingError = exports.MidwayFeatureNotImplementedError = exports.MidwayFeatureNoLongerSupportedError = exports.MidwayDefinitionNotFoundError = exports.MidwayParameterError = exports.MidwayCommonError = exports.FrameworkErrorEnum = void 0;
|
|
3
|
+
exports.MidwayDuplicateClassNameError = exports.MidwayInconsistentVersionError = exports.MidwayUtilHttpClientTimeoutError = exports.MidwayMissingImportComponentError = exports.MidwaySingletonInjectRequestError = exports.MidwayUseWrongMethodError = exports.MidwayDuplicateRouteError = exports.MidwayResolverMissingError = exports.MidwayInvalidConfigError = exports.MidwayConfigMissingError = exports.MidwayFeatureNotImplementedError = exports.MidwayFeatureNoLongerSupportedError = exports.MidwayDefinitionNotFoundError = exports.MidwayParameterError = exports.MidwayCommonError = exports.FrameworkErrorEnum = void 0;
|
|
4
4
|
const base_1 = require("./base");
|
|
5
5
|
exports.FrameworkErrorEnum = (0, base_1.registerErrorCode)('midway', {
|
|
6
6
|
UNKNOWN: 10000,
|
|
@@ -17,6 +17,8 @@ exports.FrameworkErrorEnum = (0, base_1.registerErrorCode)('midway', {
|
|
|
17
17
|
MISSING_IMPORTS: 10011,
|
|
18
18
|
UTIL_HTTP_TIMEOUT: 10012,
|
|
19
19
|
INCONSISTENT_VERSION: 10013,
|
|
20
|
+
INVALID_CONFIG: 10014,
|
|
21
|
+
DUPLICATE_CLASS_NAME: 10015,
|
|
20
22
|
});
|
|
21
23
|
class MidwayCommonError extends base_1.MidwayError {
|
|
22
24
|
constructor(message) {
|
|
@@ -67,6 +69,12 @@ class MidwayConfigMissingError extends base_1.MidwayError {
|
|
|
67
69
|
}
|
|
68
70
|
}
|
|
69
71
|
exports.MidwayConfigMissingError = MidwayConfigMissingError;
|
|
72
|
+
class MidwayInvalidConfigError extends base_1.MidwayError {
|
|
73
|
+
constructor(message) {
|
|
74
|
+
super('Invalid config file \n' + message, exports.FrameworkErrorEnum.INVALID_CONFIG);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.MidwayInvalidConfigError = MidwayInvalidConfigError;
|
|
70
78
|
class MidwayResolverMissingError extends base_1.MidwayError {
|
|
71
79
|
constructor(type) {
|
|
72
80
|
super(`${type} resolver is not exists!`, exports.FrameworkErrorEnum.MISSING_RESOLVER);
|
|
@@ -115,4 +123,10 @@ class MidwayInconsistentVersionError extends base_1.MidwayError {
|
|
|
115
123
|
}
|
|
116
124
|
}
|
|
117
125
|
exports.MidwayInconsistentVersionError = MidwayInconsistentVersionError;
|
|
126
|
+
class MidwayDuplicateClassNameError extends base_1.MidwayError {
|
|
127
|
+
constructor(className, existPath, existPathOther) {
|
|
128
|
+
super(`"${className}" duplicated between "${existPath}" and "${existPathOther}"`, exports.FrameworkErrorEnum.DUPLICATE_CLASS_NAME);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
exports.MidwayDuplicateClassNameError = MidwayDuplicateClassNameError;
|
|
118
132
|
//# sourceMappingURL=framework.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { MidwayRequestContainer } from './context/requestContainer';
|
|
|
4
4
|
export { BaseFramework } from './baseFramework';
|
|
5
5
|
export * from './context/providerWrapper';
|
|
6
6
|
export * from './common/constants';
|
|
7
|
-
export { safelyGet, safeRequire, delegateTargetPrototypeMethod, delegateTargetMethod, delegateTargetProperties, delegateTargetAllPrototypeMethod, deprecatedOutput, transformRequestObjectByType, pathMatching, wrapMiddleware, } from './util/';
|
|
7
|
+
export { safelyGet, safeRequire, delegateTargetPrototypeMethod, delegateTargetMethod, delegateTargetProperties, delegateTargetAllPrototypeMethod, deprecatedOutput, transformRequestObjectByType, pathMatching, wrapMiddleware, wrapAsync, } from './util/';
|
|
8
8
|
export { extend } from './util/extend';
|
|
9
9
|
export * from './util/pathFileUtil';
|
|
10
10
|
export * from './util/webRouterParam';
|
|
@@ -24,6 +24,7 @@ export { MidwayMockService } from './service/mockService';
|
|
|
24
24
|
export * from './service/pipelineService';
|
|
25
25
|
export * from './util/contextUtil';
|
|
26
26
|
export * from './common/serviceFactory';
|
|
27
|
+
export * from './common/dataSourceManager';
|
|
27
28
|
export * from './common/dataListener';
|
|
28
29
|
export * from './common/fileDetector';
|
|
29
30
|
export * from './common/webGenerator';
|
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.MidwayFrameworkType = exports.MidwayMockService = exports.MidwayDecoratorService = exports.MidwayMiddlewareService = exports.MidwayLifeCycleService = exports.MidwayAspectService = exports.MidwayFrameworkService = exports.MidwayLoggerService = exports.MidwayInformationService = exports.MidwayEnvironmentService = exports.MidwayConfigService = exports.createConfiguration = exports.extend = exports.wrapMiddleware = exports.pathMatching = exports.transformRequestObjectByType = exports.deprecatedOutput = exports.delegateTargetAllPrototypeMethod = exports.delegateTargetProperties = exports.delegateTargetMethod = exports.delegateTargetPrototypeMethod = exports.safeRequire = exports.safelyGet = exports.BaseFramework = exports.MidwayRequestContainer = void 0;
|
|
17
|
+
exports.MidwayFrameworkType = exports.MidwayMockService = exports.MidwayDecoratorService = exports.MidwayMiddlewareService = exports.MidwayLifeCycleService = exports.MidwayAspectService = exports.MidwayFrameworkService = exports.MidwayLoggerService = exports.MidwayInformationService = exports.MidwayEnvironmentService = exports.MidwayConfigService = exports.createConfiguration = exports.extend = exports.wrapAsync = exports.wrapMiddleware = exports.pathMatching = exports.transformRequestObjectByType = exports.deprecatedOutput = exports.delegateTargetAllPrototypeMethod = exports.delegateTargetProperties = exports.delegateTargetMethod = exports.delegateTargetPrototypeMethod = exports.safeRequire = exports.safelyGet = 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");
|
|
@@ -34,6 +34,7 @@ Object.defineProperty(exports, "deprecatedOutput", { enumerable: true, get: func
|
|
|
34
34
|
Object.defineProperty(exports, "transformRequestObjectByType", { enumerable: true, get: function () { return util_1.transformRequestObjectByType; } });
|
|
35
35
|
Object.defineProperty(exports, "pathMatching", { enumerable: true, get: function () { return util_1.pathMatching; } });
|
|
36
36
|
Object.defineProperty(exports, "wrapMiddleware", { enumerable: true, get: function () { return util_1.wrapMiddleware; } });
|
|
37
|
+
Object.defineProperty(exports, "wrapAsync", { enumerable: true, get: function () { return util_1.wrapAsync; } });
|
|
37
38
|
var extend_1 = require("./util/extend");
|
|
38
39
|
Object.defineProperty(exports, "extend", { enumerable: true, get: function () { return extend_1.extend; } });
|
|
39
40
|
__exportStar(require("./util/pathFileUtil"), exports);
|
|
@@ -65,6 +66,7 @@ Object.defineProperty(exports, "MidwayMockService", { enumerable: true, get: fun
|
|
|
65
66
|
__exportStar(require("./service/pipelineService"), exports);
|
|
66
67
|
__exportStar(require("./util/contextUtil"), exports);
|
|
67
68
|
__exportStar(require("./common/serviceFactory"), exports);
|
|
69
|
+
__exportStar(require("./common/dataSourceManager"), exports);
|
|
68
70
|
__exportStar(require("./common/dataListener"), exports);
|
|
69
71
|
__exportStar(require("./common/fileDetector"), exports);
|
|
70
72
|
__exportStar(require("./common/webGenerator"), exports);
|
package/dist/interface.d.ts
CHANGED
|
@@ -14,6 +14,14 @@ export declare type ServiceFactoryConfigOption<OPTIONS> = {
|
|
|
14
14
|
[key: string]: PowerPartial<OPTIONS>;
|
|
15
15
|
};
|
|
16
16
|
};
|
|
17
|
+
export declare type DataSourceManagerConfigOption<OPTIONS> = {
|
|
18
|
+
default?: PowerPartial<OPTIONS>;
|
|
19
|
+
dataSource?: {
|
|
20
|
+
[key: string]: PowerPartial<{
|
|
21
|
+
entities: any[];
|
|
22
|
+
} & OPTIONS>;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
17
25
|
declare type ConfigType<T> = T extends (...args: any[]) => any ? Writable<PowerPartial<ReturnType<T>>> : Writable<PowerPartial<T>>;
|
|
18
26
|
/**
|
|
19
27
|
* Get definition from config
|
|
@@ -127,6 +135,7 @@ export interface IObjectDefinition {
|
|
|
127
135
|
}>;
|
|
128
136
|
createFrom: 'framework' | 'file' | 'module';
|
|
129
137
|
allowDowngrade: boolean;
|
|
138
|
+
bindHook?: (module: any, options?: IObjectDefinition) => void;
|
|
130
139
|
}
|
|
131
140
|
export interface IObjectCreator {
|
|
132
141
|
load(): any;
|
|
@@ -18,6 +18,7 @@ const util = require("util");
|
|
|
18
18
|
const environmentService_1 = require("./environmentService");
|
|
19
19
|
const informationService_1 = require("./informationService");
|
|
20
20
|
const extend_1 = require("../util/extend");
|
|
21
|
+
const error_1 = require("../error");
|
|
21
22
|
const debug = util.debuglog('midway:debug');
|
|
22
23
|
let MidwayConfigService = class MidwayConfigService {
|
|
23
24
|
constructor() {
|
|
@@ -174,8 +175,11 @@ let MidwayConfigService = class MidwayConfigService {
|
|
|
174
175
|
let exports = typeof configFilename === 'string'
|
|
175
176
|
? require(configFilename)
|
|
176
177
|
: configFilename;
|
|
177
|
-
if (exports && exports
|
|
178
|
-
exports
|
|
178
|
+
if (exports && exports.default) {
|
|
179
|
+
if (Object.keys(exports).length > 1) {
|
|
180
|
+
throw new error_1.MidwayInvalidConfigError(`${configFilename} should not have both a default export and named export`);
|
|
181
|
+
}
|
|
182
|
+
exports = exports.default;
|
|
179
183
|
}
|
|
180
184
|
return exports;
|
|
181
185
|
}
|
|
@@ -49,6 +49,22 @@ let MidwayFrameworkService = class MidwayFrameworkService {
|
|
|
49
49
|
var _a, _b;
|
|
50
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
51
|
});
|
|
52
|
+
// register @App decorator handler
|
|
53
|
+
this.decoratorService.registerPropertyHandler(decorator_1.APPLICATION_KEY, (propertyName, mete) => {
|
|
54
|
+
if (mete.type) {
|
|
55
|
+
const framework = this.applicationManager.getApplication(mete.type);
|
|
56
|
+
if (!framework) {
|
|
57
|
+
throw new error_1.MidwayCommonError(`Framework ${mete.type} not Found`);
|
|
58
|
+
}
|
|
59
|
+
return framework;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
return this.getMainApp();
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
this.decoratorService.registerPropertyHandler(decorator_1.PLUGIN_KEY, (key, target) => {
|
|
66
|
+
return this.getMainApp()[key];
|
|
67
|
+
});
|
|
52
68
|
let frameworks = (0, decorator_1.listModule)(decorator_1.FRAMEWORK_KEY);
|
|
53
69
|
// filter proto
|
|
54
70
|
frameworks = filterProtoFramework(frameworks);
|
|
@@ -77,22 +93,6 @@ let MidwayFrameworkService = class MidwayFrameworkService {
|
|
|
77
93
|
this.applicationManager.addFramework((_a = definition === null || definition === void 0 ? void 0 : definition.namespace) !== null && _a !== void 0 ? _a : frameworkInstance.getFrameworkName(), frameworkInstance);
|
|
78
94
|
this.globalFrameworkList.push(frameworkInstance);
|
|
79
95
|
}
|
|
80
|
-
// register @App decorator handler
|
|
81
|
-
this.decoratorService.registerPropertyHandler(decorator_1.APPLICATION_KEY, (propertyName, mete) => {
|
|
82
|
-
if (mete.type) {
|
|
83
|
-
const framework = this.applicationManager.getApplication(mete.type);
|
|
84
|
-
if (!framework) {
|
|
85
|
-
throw new error_1.MidwayCommonError(`Framework ${mete.type} not Found`);
|
|
86
|
-
}
|
|
87
|
-
return framework;
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
return this.getMainApp();
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
this.decoratorService.registerPropertyHandler(decorator_1.PLUGIN_KEY, (key, target) => {
|
|
94
|
-
return this.getMainApp()[key];
|
|
95
|
-
});
|
|
96
96
|
const nsSet = this.applicationContext['namespaceSet'];
|
|
97
97
|
let mainNs;
|
|
98
98
|
if (nsSet.size > 0) {
|
package/dist/util/index.d.ts
CHANGED
|
@@ -90,4 +90,5 @@ export declare function pathMatching(options: any): (ctx?: any) => any;
|
|
|
90
90
|
*/
|
|
91
91
|
export declare function wrapMiddleware(mw: FunctionMiddleware<any, any>, options: any): (context: any, next: any, options?: any) => any;
|
|
92
92
|
export declare function isIncludeProperty(obj: any, prop: string): boolean;
|
|
93
|
+
export declare function wrapAsync(handler: any): (...args: any[]) => any;
|
|
93
94
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/util/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isIncludeProperty = exports.wrapMiddleware = exports.pathMatching = exports.toPathMatch = exports.transformRequestObjectByType = exports.deprecatedOutput = exports.getCurrentDateString = exports.delegateTargetProperties = exports.delegateTargetMethod = exports.delegateTargetAllPrototypeMethod = exports.delegateTargetPrototypeMethod = exports.joinURLPath = exports.getUserHome = exports.parsePrefix = exports.safelyGet = exports.safeRequire = exports.getCurrentEnvironment = exports.isDevelopmentEnvironment = void 0;
|
|
3
|
+
exports.wrapAsync = exports.isIncludeProperty = exports.wrapMiddleware = exports.pathMatching = exports.toPathMatch = exports.transformRequestObjectByType = exports.deprecatedOutput = exports.getCurrentDateString = exports.delegateTargetProperties = exports.delegateTargetMethod = exports.delegateTargetAllPrototypeMethod = exports.delegateTargetPrototypeMethod = exports.joinURLPath = exports.getUserHome = exports.parsePrefix = exports.safelyGet = exports.safeRequire = exports.getCurrentEnvironment = exports.isDevelopmentEnvironment = void 0;
|
|
4
4
|
const path_1 = require("path");
|
|
5
5
|
const fs_1 = require("fs");
|
|
6
6
|
const util_1 = require("util");
|
|
@@ -313,4 +313,25 @@ function isIncludeProperty(obj, prop) {
|
|
|
313
313
|
return false;
|
|
314
314
|
}
|
|
315
315
|
exports.isIncludeProperty = isIncludeProperty;
|
|
316
|
+
function wrapAsync(handler) {
|
|
317
|
+
return (...args) => {
|
|
318
|
+
if (typeof args[args.length - 1] === 'function') {
|
|
319
|
+
const callback = args.pop();
|
|
320
|
+
if (handler.constructor.name !== 'AsyncFunction') {
|
|
321
|
+
const err = new TypeError('Must be an AsyncFunction');
|
|
322
|
+
return callback(err);
|
|
323
|
+
}
|
|
324
|
+
// 其他事件场景
|
|
325
|
+
return handler.apply(handler, args).then(result => {
|
|
326
|
+
callback(null, result);
|
|
327
|
+
}, err => {
|
|
328
|
+
callback(err);
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
else {
|
|
332
|
+
return handler.apply(handler, args);
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
exports.wrapAsync = wrapAsync;
|
|
316
337
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0-beta.1",
|
|
4
4
|
"description": "midway core",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
],
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@midwayjs/decorator": "^3.1
|
|
24
|
+
"@midwayjs/decorator": "^3.4.0-beta.1",
|
|
25
25
|
"koa": "2.13.4",
|
|
26
26
|
"midway-test-component": "*",
|
|
27
27
|
"mm": "3.2.0",
|
|
28
28
|
"raw-body": "2.5.1",
|
|
29
|
-
"sinon": "13.0.
|
|
29
|
+
"sinon": "13.0.2"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"@midwayjs/decorator": "*"
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"engines": {
|
|
46
46
|
"node": ">=12"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "14d8440f20978426184c988808343cc24bcf6e20"
|
|
49
49
|
}
|