@midwayjs/leoric 3.13.7 → 3.13.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.
@@ -20,10 +20,28 @@ function getModelName(model) {
20
20
  }
21
21
  let LeoricConfiguration = class LeoricConfiguration {
22
22
  async init() {
23
- this.decoratorService.registerPropertyHandler(decorator_1.MODEL_KEY, (propertyName, meta) => {
24
- return this.dataSourceManager.getDataSource(meta.connectionName ||
23
+ this.decoratorService.registerPropertyHandler(decorator_1.MODEL_KEY, (propertyName, meta, instance) => {
24
+ const dataSource = this.dataSourceManager.getDataSource(meta.connectionName ||
25
25
  this.dataSourceManager.getDataSourceNameByModel(meta.modelName) ||
26
- this.dataSourceManager.getDefaultDataSourceName()).models[getModelName(meta.modelName)];
26
+ this.dataSourceManager.getDefaultDataSourceName());
27
+ const model = dataSource.models[getModelName(meta.modelName)];
28
+ const ctx = instance[core_1.REQUEST_OBJ_CTX_KEY];
29
+ const app = instance[core_1.APPLICATION_KEY];
30
+ if (ctx) {
31
+ return class extends model {
32
+ static get ctx() {
33
+ return ctx;
34
+ }
35
+ static get app() {
36
+ return ctx.getApp();
37
+ }
38
+ };
39
+ }
40
+ return class extends model {
41
+ static get app() {
42
+ return app;
43
+ }
44
+ };
27
45
  });
28
46
  this.decoratorService.registerPropertyHandler(decorator_1.DATA_SOURCE_KEY, (propertyName, meta) => {
29
47
  return this.dataSourceManager.getDataSource(meta.dataSourceName ||
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/leoric",
3
- "version": "3.13.7",
3
+ "version": "3.13.9",
4
4
  "description": "Leoric as a Midway model component",
5
5
  "main": "dist/index.js",
6
6
  "typings": "index.d.ts",
@@ -22,7 +22,8 @@
22
22
  },
23
23
  "devDependencies": {
24
24
  "@midwayjs/core": "^3.13.7",
25
- "@midwayjs/mock": "^3.13.7",
25
+ "@midwayjs/koa": "^3.13.9",
26
+ "@midwayjs/mock": "^3.13.9",
26
27
  "sqlite3": "5.1.6"
27
28
  },
28
29
  "scripts": {
@@ -35,5 +36,5 @@
35
36
  "type": "git",
36
37
  "url": "https://github.com/midwayjs/midway.git"
37
38
  },
38
- "gitHead": "8a239c69f8a711a5e71fae63148bc5f3daf95828"
39
+ "gitHead": "00750219506f4e3ad0e1dbb167d295610005b328"
39
40
  }