@midwayjs/core 3.4.7 → 3.4.9
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/baseFramework.d.ts +2 -2
- package/dist/baseFramework.js +17 -15
- package/dist/common/dataSourceManager.d.ts +4 -1
- package/dist/common/dataSourceManager.js +15 -10
- package/dist/common/fileDetector.d.ts +7 -8
- package/dist/common/fileDetector.js +11 -42
- package/dist/error/base.js +3 -0
- package/dist/interface.d.ts +1 -1
- package/package.json +2 -2
package/dist/baseFramework.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CommonMiddlewareUnion, IConfigurationOptions, IMidwayApplication, IMidwayBootstrapOptions, IMidwayContainer, IMidwayContext, IMidwayFramework, CommonFilterUnion,
|
|
1
|
+
import { CommonMiddlewareUnion, IConfigurationOptions, IMidwayApplication, IMidwayBootstrapOptions, IMidwayContainer, IMidwayContext, IMidwayFramework, CommonFilterUnion, MiddlewareRespond } from './interface';
|
|
2
2
|
import { ILogger, LoggerOptions, LoggerContextFormat } from '@midwayjs/logger';
|
|
3
3
|
import { MidwayEnvironmentService } from './service/environmentService';
|
|
4
4
|
import { MidwayConfigService } from './service/configService';
|
|
@@ -74,7 +74,7 @@ export declare abstract class BaseFramework<APP extends IMidwayApplication<CTX>,
|
|
|
74
74
|
* @deprecated
|
|
75
75
|
*/
|
|
76
76
|
protected afterContainerReady(options: Partial<IMidwayBootstrapOptions>): Promise<void>;
|
|
77
|
-
applyMiddleware<R, N>(lastMiddleware?:
|
|
77
|
+
applyMiddleware<R, N>(lastMiddleware?: CommonMiddlewareUnion<CTX, R, N>): Promise<MiddlewareRespond<CTX, R, N>>;
|
|
78
78
|
getLogger(name?: string): ILogger;
|
|
79
79
|
getCoreLogger(): ILogger;
|
|
80
80
|
createLogger(name: string, option?: LoggerOptions): ILogger;
|
package/dist/baseFramework.js
CHANGED
|
@@ -234,18 +234,19 @@ class BaseFramework {
|
|
|
234
234
|
async afterContainerReady(options) { }
|
|
235
235
|
async applyMiddleware(lastMiddleware) {
|
|
236
236
|
var _a;
|
|
237
|
-
if (!this.applicationContext.hasObject(interface_1.ASYNC_CONTEXT_MANAGER_KEY)) {
|
|
238
|
-
const asyncContextManagerEnabled = this.configService.getConfiguration('asyncContextManager.enable') ||
|
|
239
|
-
false;
|
|
240
|
-
const contextManager = asyncContextManagerEnabled
|
|
241
|
-
? ((_a = this.bootstrapOptions) === null || _a === void 0 ? void 0 : _a.asyncContextManager) || new asyncContextManager_1.NoopContextManager()
|
|
242
|
-
: new asyncContextManager_1.NoopContextManager();
|
|
243
|
-
if (asyncContextManagerEnabled) {
|
|
244
|
-
contextManager.enable();
|
|
245
|
-
}
|
|
246
|
-
this.applicationContext.registerObject(interface_1.ASYNC_CONTEXT_MANAGER_KEY, contextManager);
|
|
247
|
-
}
|
|
248
237
|
if (!this.composeMiddleware) {
|
|
238
|
+
if (!this.applicationContext.hasObject(interface_1.ASYNC_CONTEXT_MANAGER_KEY)) {
|
|
239
|
+
const asyncContextManagerEnabled = this.configService.getConfiguration('asyncContextManager.enable') ||
|
|
240
|
+
false;
|
|
241
|
+
const contextManager = asyncContextManagerEnabled
|
|
242
|
+
? ((_a = this.bootstrapOptions) === null || _a === void 0 ? void 0 : _a.asyncContextManager) ||
|
|
243
|
+
new asyncContextManager_1.NoopContextManager()
|
|
244
|
+
: new asyncContextManager_1.NoopContextManager();
|
|
245
|
+
if (asyncContextManagerEnabled) {
|
|
246
|
+
contextManager.enable();
|
|
247
|
+
}
|
|
248
|
+
this.applicationContext.registerObject(interface_1.ASYNC_CONTEXT_MANAGER_KEY, contextManager);
|
|
249
|
+
}
|
|
249
250
|
this.middlewareManager.insertFirst((async (ctx, next) => {
|
|
250
251
|
// warp with context manager
|
|
251
252
|
const rootContext = asyncContextManager_1.ASYNC_ROOT_CONTEXT.setValue(interface_1.ASYNC_CONTEXT_KEY, ctx);
|
|
@@ -271,11 +272,12 @@ class BaseFramework {
|
|
|
271
272
|
await this.filterManager.init(this.applicationContext);
|
|
272
273
|
}
|
|
273
274
|
if (lastMiddleware) {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
return this.composeMiddleware;
|
|
275
|
+
lastMiddleware = Array.isArray(lastMiddleware)
|
|
276
|
+
? lastMiddleware
|
|
277
|
+
: [lastMiddleware];
|
|
278
|
+
return await this.middlewareService.compose([this.composeMiddleware, ...lastMiddleware], this.app);
|
|
278
279
|
}
|
|
280
|
+
return this.composeMiddleware;
|
|
279
281
|
}
|
|
280
282
|
getLogger(name) {
|
|
281
283
|
var _a;
|
|
@@ -19,7 +19,7 @@ export declare abstract class DataSourceManager<T> {
|
|
|
19
19
|
* @param dataSourceName
|
|
20
20
|
*/
|
|
21
21
|
isConnected(dataSourceName: string): Promise<boolean>;
|
|
22
|
-
createInstance(config: any, clientName: any): Promise<T | void>;
|
|
22
|
+
createInstance(config: any, clientName: any, options?: CreateInstanceOptions): Promise<T | void>;
|
|
23
23
|
/**
|
|
24
24
|
* get data source name by model or repository
|
|
25
25
|
* @param modelOrRepository
|
|
@@ -32,4 +32,7 @@ export declare abstract class DataSourceManager<T> {
|
|
|
32
32
|
stop(): Promise<void>;
|
|
33
33
|
}
|
|
34
34
|
export declare function globModels(globString: string, appDir: string): any[];
|
|
35
|
+
export interface CreateInstanceOptions {
|
|
36
|
+
cacheInstance?: boolean | undefined;
|
|
37
|
+
}
|
|
35
38
|
//# sourceMappingURL=dataSourceManager.d.ts.map
|
|
@@ -42,7 +42,10 @@ class DataSourceManager {
|
|
|
42
42
|
dataSourceOptions['entities'] = Array.from(entities);
|
|
43
43
|
}
|
|
44
44
|
// create data source
|
|
45
|
-
|
|
45
|
+
const opts = {
|
|
46
|
+
cacheInstance: options.cacheInstance, // will default true
|
|
47
|
+
};
|
|
48
|
+
await this.createInstance(dataSourceOptions, dataSourceName, opts);
|
|
46
49
|
}
|
|
47
50
|
}
|
|
48
51
|
else {
|
|
@@ -71,18 +74,20 @@ class DataSourceManager {
|
|
|
71
74
|
* @param dataSourceName
|
|
72
75
|
*/
|
|
73
76
|
async isConnected(dataSourceName) {
|
|
74
|
-
|
|
77
|
+
const inst = this.getDataSource(dataSourceName);
|
|
78
|
+
return inst ? this.checkConnected(inst) : false;
|
|
75
79
|
}
|
|
76
|
-
async createInstance(config, clientName) {
|
|
80
|
+
async createInstance(config, clientName, options) {
|
|
81
|
+
const cache = options && typeof options.cacheInstance === 'boolean'
|
|
82
|
+
? options.cacheInstance
|
|
83
|
+
: true;
|
|
77
84
|
// options.default will be merge in to options.clients[id]
|
|
78
|
-
|
|
79
|
-
const client = await this.createDataSource(
|
|
80
|
-
if (client) {
|
|
81
|
-
|
|
82
|
-
this.dataSource.set(clientName, client);
|
|
83
|
-
}
|
|
84
|
-
return client;
|
|
85
|
+
const configNow = (0, extend_1.extend)(true, {}, this.options['default'], config);
|
|
86
|
+
const client = await this.createDataSource(configNow, clientName);
|
|
87
|
+
if (cache && clientName && client) {
|
|
88
|
+
this.dataSource.set(clientName, client);
|
|
85
89
|
}
|
|
90
|
+
return client;
|
|
86
91
|
}
|
|
87
92
|
/**
|
|
88
93
|
* get data source name by model or repository
|
|
@@ -7,19 +7,18 @@ export declare abstract class AbstractFileDetector<T> implements IFileDetector {
|
|
|
7
7
|
setExtraDetectorOptions(detectorOptions: T): void;
|
|
8
8
|
}
|
|
9
9
|
export declare class DirectoryFileDetector extends AbstractFileDetector<{
|
|
10
|
-
loadDir
|
|
11
|
-
pattern
|
|
12
|
-
ignore
|
|
13
|
-
namespace
|
|
14
|
-
conflictCheck
|
|
10
|
+
loadDir?: string | string[];
|
|
11
|
+
pattern?: string | string[];
|
|
12
|
+
ignore?: string | string[];
|
|
13
|
+
namespace?: string;
|
|
14
|
+
conflictCheck?: boolean;
|
|
15
15
|
}> {
|
|
16
|
-
private directoryFilterArray;
|
|
17
16
|
private duplicateModuleCheckSet;
|
|
18
17
|
run(container: any): void;
|
|
19
18
|
}
|
|
20
19
|
export declare class CustomModuleDetector extends AbstractFileDetector<{
|
|
21
|
-
modules
|
|
22
|
-
namespace
|
|
20
|
+
modules?: any[];
|
|
21
|
+
namespace?: string;
|
|
23
22
|
}> {
|
|
24
23
|
run(container: any): void;
|
|
25
24
|
}
|
|
@@ -31,7 +31,6 @@ const DEFAULT_IGNORE_PATTERN = [
|
|
|
31
31
|
class DirectoryFileDetector extends AbstractFileDetector {
|
|
32
32
|
constructor() {
|
|
33
33
|
super(...arguments);
|
|
34
|
-
this.directoryFilterArray = [];
|
|
35
34
|
this.duplicateModuleCheckSet = new Map();
|
|
36
35
|
}
|
|
37
36
|
run(container) {
|
|
@@ -45,7 +44,9 @@ class DirectoryFileDetector extends AbstractFileDetector {
|
|
|
45
44
|
});
|
|
46
45
|
// 检查重复模块
|
|
47
46
|
const checkDuplicatedHandler = (module, options) => {
|
|
48
|
-
if (this.
|
|
47
|
+
if ((this.options.conflictCheck ||
|
|
48
|
+
this.extraDetectorOptions.conflictCheck) &&
|
|
49
|
+
decorator_1.Types.isClass(module)) {
|
|
49
50
|
const name = (0, decorator_1.getProviderName)(module);
|
|
50
51
|
if (name) {
|
|
51
52
|
if (this.duplicateModuleCheckSet.has(name)) {
|
|
@@ -58,46 +59,14 @@ class DirectoryFileDetector extends AbstractFileDetector {
|
|
|
58
59
|
}
|
|
59
60
|
};
|
|
60
61
|
for (const file of fileResults) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
continue;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
else if (decorator_1.Types.isRegExp(resolveFilter.pattern)) {
|
|
73
|
-
if (resolveFilter.pattern.test(file)) {
|
|
74
|
-
const exports = resolveFilter.ignoreRequire
|
|
75
|
-
? undefined
|
|
76
|
-
: require(file);
|
|
77
|
-
resolveFilter.filter(exports, file, this);
|
|
78
|
-
continue;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
const exports = require(file);
|
|
82
|
-
// add module to set
|
|
83
|
-
container.bindClass(exports, {
|
|
84
|
-
namespace: this.options.namespace,
|
|
85
|
-
srcPath: file,
|
|
86
|
-
createFrom: 'file',
|
|
87
|
-
bindHook: checkDuplicatedHandler,
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
const exports = require(file);
|
|
93
|
-
// add module to set
|
|
94
|
-
container.bindClass(exports, {
|
|
95
|
-
namespace: this.options.namespace,
|
|
96
|
-
srcPath: file,
|
|
97
|
-
createFrom: 'file',
|
|
98
|
-
bindHook: checkDuplicatedHandler,
|
|
99
|
-
});
|
|
100
|
-
}
|
|
62
|
+
const exports = require(file);
|
|
63
|
+
// add module to set
|
|
64
|
+
container.bindClass(exports, {
|
|
65
|
+
namespace: this.options.namespace,
|
|
66
|
+
srcPath: file,
|
|
67
|
+
createFrom: 'file',
|
|
68
|
+
bindHook: checkDuplicatedHandler,
|
|
69
|
+
});
|
|
101
70
|
}
|
|
102
71
|
}
|
|
103
72
|
// check end
|
package/dist/error/base.js
CHANGED
|
@@ -46,6 +46,9 @@ class MidwayHttpError extends MidwayError {
|
|
|
46
46
|
? resOrMessage
|
|
47
47
|
: resOrMessage.message
|
|
48
48
|
: http_1.STATUS_CODES[status], code !== null && code !== void 0 ? code : String(status), options);
|
|
49
|
+
if (resOrMessage && resOrMessage['stack']) {
|
|
50
|
+
this.stack = resOrMessage['stack'];
|
|
51
|
+
}
|
|
49
52
|
this.status = status;
|
|
50
53
|
}
|
|
51
54
|
}
|
package/dist/interface.d.ts
CHANGED
|
@@ -462,7 +462,7 @@ export interface IMidwayFramework<APP extends IMidwayApplication<CTX>, CTX exten
|
|
|
462
462
|
getProjectName(): string;
|
|
463
463
|
useMiddleware(Middleware: CommonMiddlewareUnion<CTX, ResOrNext, Next>): void;
|
|
464
464
|
getMiddleware(): ContextMiddlewareManager<CTX, ResOrNext, Next>;
|
|
465
|
-
applyMiddleware(lastMiddleware?:
|
|
465
|
+
applyMiddleware(lastMiddleware?: CommonMiddlewareUnion<CTX, ResOrNext, Next>): Promise<MiddlewareRespond<CTX, ResOrNext, Next>>;
|
|
466
466
|
useFilter(Filter: CommonFilterUnion<CTX, ResOrNext, Next>): any;
|
|
467
467
|
}
|
|
468
468
|
export declare const MIDWAY_LOGGER_WRITEABLE_DIR = "MIDWAY_LOGGER_WRITEABLE_DIR";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/core",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.9",
|
|
4
4
|
"description": "midway core",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"engines": {
|
|
46
46
|
"node": ">=12"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "bc8113cff70d88a31e44bde69c395f61a7de2045"
|
|
49
49
|
}
|