@midwayjs/casbin 3.8.0 → 3.9.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.
@@ -17,7 +17,13 @@ let CasbinEnforcerService = class CasbinEnforcerService {
17
17
  if (typeof this.casbinConfig.policyAdapter === 'function') {
18
18
  this.casbinConfig.policyAdapter = await this.casbinConfig.policyAdapter(this.applicationContext);
19
19
  }
20
+ if (typeof this.casbinConfig.policyWatcher === 'function') {
21
+ this.casbinConfig.policyWatcher = await this.casbinConfig.policyWatcher(this.applicationContext);
22
+ }
20
23
  this.instance = await (0, casbin_1.newEnforcer)(this.casbinConfig.modelPath, this.casbinConfig.policyAdapter);
24
+ if (this.casbinConfig.policyWatcher) {
25
+ this.instance.setWatcher(this.casbinConfig.policyWatcher);
26
+ }
21
27
  }
22
28
  getEnforcer() {
23
29
  return this.instance;
@@ -1,9 +1,10 @@
1
- import { Adapter } from 'casbin';
1
+ import { Adapter, Watcher } from 'casbin';
2
2
  import { AuthActionVerb, AuthPossession } from './constants';
3
3
  import { IMidwayContainer, IMidwayContext } from '@midwayjs/core';
4
4
  export interface CasbinConfigOptions {
5
5
  modelPath: string;
6
6
  policyAdapter: string | ((applicationContext: IMidwayContainer) => Promise<Adapter>) | Adapter;
7
+ policyWatcher?: ((applicationContext: IMidwayContainer) => Promise<Watcher>) | Watcher;
7
8
  usernameFromContext: (ctx: IMidwayContext) => string;
8
9
  }
9
10
  export interface Permission {
@@ -0,0 +1,12 @@
1
+ import { Watcher } from 'casbin';
2
+ export declare abstract class BaseWatcher<Client> implements Watcher {
3
+ private client;
4
+ private keyName;
5
+ private callback;
6
+ init(): Promise<void>;
7
+ setUpdateCallback(callback: () => void): void;
8
+ update(): Promise<boolean>;
9
+ abstract publishData(client: Client, keyName: string): any;
10
+ abstract subscribeData(client: Client, keyName: string, callback: any): any;
11
+ }
12
+ //# sourceMappingURL=watcher.d.ts.map
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseWatcher = void 0;
4
+ class BaseWatcher {
5
+ async init() {
6
+ this.subscribeData(this.client, this.keyName, () => {
7
+ if (this.callback) {
8
+ this.callback();
9
+ }
10
+ });
11
+ }
12
+ setUpdateCallback(callback) {
13
+ this.callback = callback;
14
+ }
15
+ async update() {
16
+ try {
17
+ await this.publishData(this.client, this.keyName);
18
+ return true;
19
+ }
20
+ catch (err) {
21
+ return false;
22
+ }
23
+ }
24
+ }
25
+ exports.BaseWatcher = BaseWatcher;
26
+ //# sourceMappingURL=watcher.js.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@midwayjs/casbin",
3
3
  "description": "midway casbin component",
4
- "version": "3.8.0",
4
+ "version": "3.9.9",
5
5
  "main": "dist/index",
6
6
  "typings": "index.d.ts",
7
7
  "files": [
@@ -10,12 +10,12 @@
10
10
  "index.d.ts"
11
11
  ],
12
12
  "devDependencies": {
13
- "@midwayjs/core": "^3.8.0",
14
- "@midwayjs/koa": "^3.8.0",
15
- "@midwayjs/mock": "^3.8.0"
13
+ "@midwayjs/core": "^3.9.0",
14
+ "@midwayjs/koa": "^3.9.9",
15
+ "@midwayjs/mock": "^3.9.0"
16
16
  },
17
17
  "dependencies": {
18
- "casbin": "5.19.1"
18
+ "casbin": "5.20.1"
19
19
  },
20
20
  "keywords": [
21
21
  "midway",
@@ -38,5 +38,5 @@
38
38
  "type": "git",
39
39
  "url": "https://github.com/midwayjs/midway.git"
40
40
  },
41
- "gitHead": "5c640c7182923587139f9f9c0aecf50585798e1e"
41
+ "gitHead": "95bb5b3f23b41f685372c45d1c3bb12a3e31b4e0"
42
42
  }