@midwayjs/core 3.12.1 → 3.12.3
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 +3 -0
- package/dist/common/dataSourceManager.js +21 -1
- package/dist/setup.d.ts +3 -3
- package/dist/setup.js +13 -7
- package/dist/util/index.js +3 -1
- package/package.json +2 -2
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { ModuleLoadType, DataSourceManagerConfigOption } from '../interface';
|
|
2
|
+
import { MidwayEnvironmentService } from '../service/environmentService';
|
|
2
3
|
export declare abstract class DataSourceManager<T, ConnectionOpts extends Record<string, any> = Record<string, any>> {
|
|
3
4
|
protected dataSource: Map<string, T>;
|
|
4
5
|
protected options: DataSourceManagerConfigOption<ConnectionOpts>;
|
|
5
6
|
protected modelMapping: WeakMap<object, any>;
|
|
6
7
|
private innerDefaultDataSourceName;
|
|
8
|
+
appDir: string;
|
|
9
|
+
environmentService: MidwayEnvironmentService;
|
|
7
10
|
protected initDataSource(dataSourceConfig: DataSourceManagerConfigOption<ConnectionOpts>, baseDirOrOptions: {
|
|
8
11
|
baseDir: string;
|
|
9
12
|
entitiesConfigKey?: string;
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.globModels = exports.formatGlobString = exports.DataSourceManager = void 0;
|
|
4
13
|
/**
|
|
@@ -12,6 +21,8 @@ const types_1 = require("../util/types");
|
|
|
12
21
|
const constants_1 = require("../constants");
|
|
13
22
|
const util_1 = require("util");
|
|
14
23
|
const util_2 = require("../util");
|
|
24
|
+
const decorator_1 = require("../decorator");
|
|
25
|
+
const environmentService_1 = require("../service/environmentService");
|
|
15
26
|
const debug = (0, util_1.debuglog)('midway:debug');
|
|
16
27
|
class DataSourceManager {
|
|
17
28
|
constructor() {
|
|
@@ -20,6 +31,7 @@ class DataSourceManager {
|
|
|
20
31
|
this.modelMapping = new WeakMap();
|
|
21
32
|
}
|
|
22
33
|
async initDataSource(dataSourceConfig, baseDirOrOptions) {
|
|
34
|
+
var _a;
|
|
23
35
|
this.options = dataSourceConfig;
|
|
24
36
|
if (!this.options.dataSource) {
|
|
25
37
|
throw new error_1.MidwayParameterError('[DataSourceManager] must set options.dataSource.');
|
|
@@ -39,7 +51,7 @@ class DataSourceManager {
|
|
|
39
51
|
for (const entity of userEntities) {
|
|
40
52
|
if (typeof entity === 'string') {
|
|
41
53
|
// string will be glob file
|
|
42
|
-
const models = await globModels(entity, baseDirOrOptions.baseDir);
|
|
54
|
+
const models = await globModels(entity, baseDirOrOptions.baseDir, (_a = this.environmentService) === null || _a === void 0 ? void 0 : _a.getModuleLoadType());
|
|
43
55
|
for (const model of models) {
|
|
44
56
|
entities.add(model);
|
|
45
57
|
this.modelMapping.set(model, dataSourceName);
|
|
@@ -141,6 +153,14 @@ class DataSourceManager {
|
|
|
141
153
|
return this.innerDefaultDataSourceName;
|
|
142
154
|
}
|
|
143
155
|
}
|
|
156
|
+
__decorate([
|
|
157
|
+
(0, decorator_1.Inject)(),
|
|
158
|
+
__metadata("design:type", String)
|
|
159
|
+
], DataSourceManager.prototype, "appDir", void 0);
|
|
160
|
+
__decorate([
|
|
161
|
+
(0, decorator_1.Inject)(),
|
|
162
|
+
__metadata("design:type", environmentService_1.MidwayEnvironmentService)
|
|
163
|
+
], DataSourceManager.prototype, "environmentService", void 0);
|
|
144
164
|
exports.DataSourceManager = DataSourceManager;
|
|
145
165
|
function formatGlobString(globString) {
|
|
146
166
|
let pattern;
|
package/dist/setup.d.ts
CHANGED
|
@@ -9,10 +9,10 @@ export declare function destroyGlobalApplicationContext(applicationContext: IMid
|
|
|
9
9
|
* prepare applicationContext
|
|
10
10
|
* @param globalOptions
|
|
11
11
|
*/
|
|
12
|
-
export declare function
|
|
12
|
+
export declare function prepareGlobalApplicationContextAsync(globalOptions: IMidwayBootstrapOptions): Promise<IMidwayContainer | MidwayContainer>;
|
|
13
13
|
/**
|
|
14
|
-
* prepare applicationContext, it use in egg framework
|
|
14
|
+
* prepare applicationContext, it use in egg framework, hooks and serverless function generator
|
|
15
15
|
* @param globalOptions
|
|
16
16
|
*/
|
|
17
|
-
export declare function
|
|
17
|
+
export declare function prepareGlobalApplicationContext(globalOptions: IMidwayBootstrapOptions): IMidwayContainer | MidwayContainer;
|
|
18
18
|
//# sourceMappingURL=setup.d.ts.map
|
package/dist/setup.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.prepareGlobalApplicationContext = exports.prepareGlobalApplicationContextAsync = exports.destroyGlobalApplicationContext = exports.initializeGlobalApplicationContext = void 0;
|
|
4
4
|
const _1 = require("./");
|
|
5
5
|
const config_default_1 = require("./config/config.default");
|
|
6
6
|
const decorator_1 = require("./decorator");
|
|
@@ -17,7 +17,7 @@ function printStepDebugInfo(stepInfo) {
|
|
|
17
17
|
* @param globalOptions
|
|
18
18
|
*/
|
|
19
19
|
async function initializeGlobalApplicationContext(globalOptions) {
|
|
20
|
-
const applicationContext = await
|
|
20
|
+
const applicationContext = await prepareGlobalApplicationContextAsync(globalOptions);
|
|
21
21
|
printStepDebugInfo('Init logger');
|
|
22
22
|
// init logger
|
|
23
23
|
const loggerService = await applicationContext.getAsync(_1.MidwayLoggerService, [
|
|
@@ -71,7 +71,7 @@ exports.destroyGlobalApplicationContext = destroyGlobalApplicationContext;
|
|
|
71
71
|
* prepare applicationContext
|
|
72
72
|
* @param globalOptions
|
|
73
73
|
*/
|
|
74
|
-
async function
|
|
74
|
+
async function prepareGlobalApplicationContextAsync(globalOptions) {
|
|
75
75
|
var _a, _b, _c, _d, _e;
|
|
76
76
|
printStepDebugInfo('Ready to create applicationContext');
|
|
77
77
|
debug('[core]: start "initializeGlobalApplicationContext"');
|
|
@@ -142,6 +142,9 @@ async function prepareGlobalApplicationContext(globalOptions) {
|
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
printStepDebugInfo('Init MidwayConfigService, MidwayAspectService and MidwayDecoratorService');
|
|
145
|
+
// init default environment
|
|
146
|
+
const environmentService = applicationContext.get(_1.MidwayEnvironmentService);
|
|
147
|
+
environmentService.setModuleLoadType(globalOptions.moduleLoadType);
|
|
145
148
|
// init default config
|
|
146
149
|
const configService = applicationContext.get(_1.MidwayConfigService);
|
|
147
150
|
configService.add([
|
|
@@ -174,12 +177,12 @@ async function prepareGlobalApplicationContext(globalOptions) {
|
|
|
174
177
|
applicationContext.get(_1.MidwayMiddlewareService, [applicationContext]);
|
|
175
178
|
return applicationContext;
|
|
176
179
|
}
|
|
177
|
-
exports.
|
|
180
|
+
exports.prepareGlobalApplicationContextAsync = prepareGlobalApplicationContextAsync;
|
|
178
181
|
/**
|
|
179
|
-
* prepare applicationContext, it use in egg framework
|
|
182
|
+
* prepare applicationContext, it use in egg framework, hooks and serverless function generator
|
|
180
183
|
* @param globalOptions
|
|
181
184
|
*/
|
|
182
|
-
function
|
|
185
|
+
function prepareGlobalApplicationContext(globalOptions) {
|
|
183
186
|
var _a, _b, _c, _d;
|
|
184
187
|
printStepDebugInfo('Ready to create applicationContext');
|
|
185
188
|
debug('[core]: start "initializeGlobalApplicationContext"');
|
|
@@ -196,6 +199,9 @@ function prepareGlobalApplicationContextSync(globalOptions) {
|
|
|
196
199
|
applicationContext.registerObject('baseDir', baseDir);
|
|
197
200
|
applicationContext.registerObject('appDir', appDir);
|
|
198
201
|
printStepDebugInfo('Ready module detector');
|
|
202
|
+
if (!globalOptions.moduleLoadType) {
|
|
203
|
+
globalOptions.moduleLoadType = 'commonjs';
|
|
204
|
+
}
|
|
199
205
|
if (globalOptions.moduleDetector !== false) {
|
|
200
206
|
if (globalOptions.moduleDetector === undefined) {
|
|
201
207
|
applicationContext.setFileDetector(new _1.CommonJSFileDetector({
|
|
@@ -269,5 +275,5 @@ function prepareGlobalApplicationContextSync(globalOptions) {
|
|
|
269
275
|
applicationContext.get(_1.MidwayMiddlewareService, [applicationContext]);
|
|
270
276
|
return applicationContext;
|
|
271
277
|
}
|
|
272
|
-
exports.
|
|
278
|
+
exports.prepareGlobalApplicationContext = prepareGlobalApplicationContext;
|
|
273
279
|
//# sourceMappingURL=setup.js.map
|
package/dist/util/index.js
CHANGED
|
@@ -12,6 +12,7 @@ const uuid_1 = require("./uuid");
|
|
|
12
12
|
const flatted_1 = require("./flatted");
|
|
13
13
|
const crypto = require("crypto");
|
|
14
14
|
const types_1 = require("./types");
|
|
15
|
+
const url_1 = require("url");
|
|
15
16
|
const debug = (0, util_1.debuglog)('midway:debug');
|
|
16
17
|
/**
|
|
17
18
|
* @since 2.0.0
|
|
@@ -69,6 +70,7 @@ const loadModule = async (p, options = {}) => {
|
|
|
69
70
|
if (p.startsWith(`.${path_1.sep}`) || p.startsWith(`..${path_1.sep}`)) {
|
|
70
71
|
p = (0, path_1.resolve)((0, path_1.dirname)(module.parent.filename), p);
|
|
71
72
|
}
|
|
73
|
+
debug(`[core]: load module ${p}, cache: ${options.enableCache}, mode: ${options.loadMode}, safeLoad: ${options.safeLoad}`);
|
|
72
74
|
try {
|
|
73
75
|
if (options.enableCache) {
|
|
74
76
|
if (options.loadMode === 'commonjs') {
|
|
@@ -91,7 +93,7 @@ const loadModule = async (p, options = {}) => {
|
|
|
91
93
|
return innerLoadModuleCache[p];
|
|
92
94
|
}
|
|
93
95
|
else {
|
|
94
|
-
return await import(p);
|
|
96
|
+
return await import((0, url_1.pathToFileURL)(p).href);
|
|
95
97
|
}
|
|
96
98
|
}
|
|
97
99
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/core",
|
|
3
|
-
"version": "3.12.
|
|
3
|
+
"version": "3.12.3",
|
|
4
4
|
"description": "midway core",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"engines": {
|
|
43
43
|
"node": ">=12"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "0b6638726c4722d5a6ee8075fea0a0b68378452c"
|
|
46
46
|
}
|