@midwayjs/mikro 3.4.0-beta.4 → 3.4.0-beta.7
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/configuration.d.ts +2 -1
- package/dist/configuration.js +25 -4
- package/package.json +8 -8
package/dist/configuration.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { ILifeCycle, IMidwayApplication, IMidwayContainer, MidwayDecoratorService } from '@midwayjs/core';
|
|
1
|
+
import { ILifeCycle, IMidwayApplication, IMidwayContainer, MidwayApplicationManager, MidwayDecoratorService } from '@midwayjs/core';
|
|
2
2
|
import { MikroDataSourceManager } from './dataSourceManager';
|
|
3
3
|
export declare class MikroConfiguration implements ILifeCycle {
|
|
4
4
|
app: IMidwayApplication;
|
|
5
5
|
decoratorService: MidwayDecoratorService;
|
|
6
|
+
applicationManager: MidwayApplicationManager;
|
|
6
7
|
dataSourceManager: MikroDataSourceManager;
|
|
7
8
|
init(): Promise<void>;
|
|
8
9
|
onReady(container: IMidwayContainer): Promise<void>;
|
package/dist/configuration.js
CHANGED
|
@@ -14,17 +14,34 @@ const core_1 = require("@midwayjs/core");
|
|
|
14
14
|
const decorator_1 = require("@midwayjs/decorator");
|
|
15
15
|
const decorator_2 = require("./decorator");
|
|
16
16
|
const dataSourceManager_1 = require("./dataSourceManager");
|
|
17
|
+
const core_2 = require("@mikro-orm/core");
|
|
17
18
|
let MikroConfiguration = class MikroConfiguration {
|
|
18
19
|
async init() {
|
|
19
20
|
this.decoratorService.registerPropertyHandler(decorator_2.ENTITY_MODEL_KEY, (propertyName, meta) => {
|
|
20
|
-
|
|
21
|
-
.
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
if (core_2.RequestContext.getEntityManager()) {
|
|
22
|
+
return core_2.RequestContext.getEntityManager().getRepository(meta.modelKey);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
return this.dataSourceManager
|
|
26
|
+
.getDataSource(meta.connectionName ||
|
|
27
|
+
this.dataSourceManager.getDataSourceNameByModel(meta.modelKey))
|
|
28
|
+
.em.getRepository(meta.modelKey);
|
|
29
|
+
}
|
|
24
30
|
});
|
|
25
31
|
}
|
|
26
32
|
async onReady(container) {
|
|
27
33
|
this.dataSourceManager = await container.getAsync(dataSourceManager_1.MikroDataSourceManager);
|
|
34
|
+
const names = this.dataSourceManager.getDataSourceNames();
|
|
35
|
+
if (names.length === 1) {
|
|
36
|
+
// 多个的话,不知道用哪个数据源,所以这里无法判断出来
|
|
37
|
+
// create mikro request scope
|
|
38
|
+
// https://mikro-orm.io/docs/identity-map
|
|
39
|
+
this.applicationManager.getApplications().forEach(app => {
|
|
40
|
+
app.useMiddleware(async (ctx, next) => {
|
|
41
|
+
return await core_2.RequestContext.createAsync(this.dataSourceManager.getDataSource(names[0]).em, next);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
}
|
|
28
45
|
}
|
|
29
46
|
async onStop(container) {
|
|
30
47
|
if (this.dataSourceManager) {
|
|
@@ -40,6 +57,10 @@ __decorate([
|
|
|
40
57
|
(0, decorator_1.Inject)(),
|
|
41
58
|
__metadata("design:type", core_1.MidwayDecoratorService)
|
|
42
59
|
], MikroConfiguration.prototype, "decoratorService", void 0);
|
|
60
|
+
__decorate([
|
|
61
|
+
(0, decorator_1.Inject)(),
|
|
62
|
+
__metadata("design:type", core_1.MidwayApplicationManager)
|
|
63
|
+
], MikroConfiguration.prototype, "applicationManager", void 0);
|
|
43
64
|
__decorate([
|
|
44
65
|
(0, decorator_1.Init)(),
|
|
45
66
|
__metadata("design:type", Function),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/mikro",
|
|
3
|
-
"version": "3.4.0-beta.
|
|
3
|
+
"version": "3.4.0-beta.7",
|
|
4
4
|
"main": "dist/index",
|
|
5
5
|
"typings": "index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -9,13 +9,13 @@
|
|
|
9
9
|
"index.d.ts"
|
|
10
10
|
],
|
|
11
11
|
"devDependencies": {
|
|
12
|
-
"@midwayjs/core": "^3.4.0-beta.
|
|
13
|
-
"@midwayjs/decorator": "^3.4.0-beta.
|
|
14
|
-
"@midwayjs/mock": "^3.4.0-beta.
|
|
15
|
-
"@mikro-orm/core": "5.2.
|
|
16
|
-
"@mikro-orm/entity-generator": "5.2.
|
|
12
|
+
"@midwayjs/core": "^3.4.0-beta.7",
|
|
13
|
+
"@midwayjs/decorator": "^3.4.0-beta.7",
|
|
14
|
+
"@midwayjs/mock": "^3.4.0-beta.7",
|
|
15
|
+
"@mikro-orm/core": "5.2.2",
|
|
16
|
+
"@mikro-orm/entity-generator": "5.2.2",
|
|
17
17
|
"@mikro-orm/sql-highlighter": "1.0.1",
|
|
18
|
-
"@mikro-orm/sqlite": "5.2.
|
|
18
|
+
"@mikro-orm/sqlite": "5.2.2",
|
|
19
19
|
"sqlite3": "5.0.8"
|
|
20
20
|
},
|
|
21
21
|
"author": {
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"type": "git",
|
|
36
36
|
"url": "http://github.com/midwayjs/midway.git"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "4d5cc59a7a33e49beeaf20fcfaf766438649959c"
|
|
39
39
|
}
|