@midwayjs/typegoose 3.3.4 → 3.4.0-beta.10

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,4 +1,4 @@
1
- import { IMidwayApplication, MidwayDecoratorService } from '@midwayjs/core';
1
+ import { IMidwayApplication, IMidwayContainer, MidwayDecoratorService } from '@midwayjs/core';
2
2
  export declare class TypegooseConfiguration {
3
3
  oldMongooseConfig: any;
4
4
  legacyMode: boolean;
@@ -6,7 +6,7 @@ export declare class TypegooseConfiguration {
6
6
  decoratorService: MidwayDecoratorService;
7
7
  modelMap: WeakMap<object, any>;
8
8
  init(): Promise<void>;
9
- onReady(container: any): Promise<void>;
9
+ onReady(container: IMidwayContainer): Promise<void>;
10
10
  onStop(): Promise<void>;
11
11
  }
12
12
  //# sourceMappingURL=configuration.d.ts.map
@@ -28,12 +28,22 @@ let TypegooseConfiguration = class TypegooseConfiguration {
28
28
  }
29
29
  async onReady(container) {
30
30
  var _a, _b;
31
- const connectionFactory = await container.getAsync(mongoose.MongooseConnectionServiceFactory);
31
+ const connectionFactory = await container.getAsync(mongoose.MongooseDataSourceManager);
32
+ for (const dataSourceName of connectionFactory.getDataSourceNames()) {
33
+ const conn = connectionFactory.getDataSource(dataSourceName);
34
+ if (conn && conn.entities) {
35
+ for (const Model of conn.entities) {
36
+ const model = (0, typegoose_1.getModelForClass)(Model, { existingConnection: conn });
37
+ this.modelMap.set(Model, model);
38
+ }
39
+ }
40
+ }
32
41
  const Models = (0, decorator_1.listModule)(interface_1.ENTITY_MODEL_KEY);
42
+ // 兼容老代码
33
43
  for (const Model of Models) {
34
44
  const metadata = (_a = (0, decorator_1.getClassMetadata)(interface_1.ENTITY_MODEL_KEY, Model)) !== null && _a !== void 0 ? _a : {};
35
45
  const connectionName = (_b = metadata.connectionName) !== null && _b !== void 0 ? _b : 'default';
36
- const conn = connectionFactory.get(connectionName);
46
+ const conn = connectionFactory.getDataSource(connectionName);
37
47
  if (conn) {
38
48
  const model = (0, typegoose_1.getModelForClass)(Model, { existingConnection: conn });
39
49
  this.modelMap.set(Model, model);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/typegoose",
3
- "version": "3.3.4",
3
+ "version": "3.4.0-beta.10",
4
4
  "description": "Midway Component for typegoose",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -21,14 +21,14 @@
21
21
  },
22
22
  "license": "MIT",
23
23
  "dependencies": {
24
- "@midwayjs/mongoose": "^3.3.4"
24
+ "@midwayjs/mongoose": "^3.4.0-beta.10"
25
25
  },
26
26
  "devDependencies": {
27
- "@midwayjs/core": "^3.3.4",
28
- "@midwayjs/decorator": "^3.3.4",
29
- "@midwayjs/mock": "^3.3.4",
30
- "@typegoose/typegoose": "9.7.1",
31
- "mongoose": "6.2.10"
27
+ "@midwayjs/core": "^3.4.0-beta.10",
28
+ "@midwayjs/decorator": "^3.4.0-beta.10",
29
+ "@midwayjs/mock": "^3.4.0-beta.10",
30
+ "@typegoose/typegoose": "9.10.1",
31
+ "mongoose": "6.4.4"
32
32
  },
33
- "gitHead": "0c2785a87217f57a184a661c71b1d9562af02242"
33
+ "gitHead": "560a5fa311605e4008c55f31c31bc4e12eeff2a5"
34
34
  }