@midwayjs/core 3.12.2 → 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.
|
@@ -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.js
CHANGED
|
@@ -142,6 +142,9 @@ async function prepareGlobalApplicationContextAsync(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([
|
|
@@ -196,6 +199,9 @@ function prepareGlobalApplicationContext(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({
|
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
|
}
|