casbin 5.16.0 → 5.17.0
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/CHANGELOG.md +7 -0
- package/lib/cjs/coreEnforcer.d.ts +8 -1
- package/lib/cjs/coreEnforcer.js +13 -1
- package/lib/cjs/internalEnforcer.js +22 -7
- package/lib/cjs/persist/index.d.ts +1 -0
- package/lib/cjs/persist/index.js +1 -0
- package/lib/cjs/persist/watcherEx.d.ts +9 -0
- package/lib/cjs/persist/watcherEx.js +15 -0
- package/lib/esm/coreEnforcer.d.ts +8 -1
- package/lib/esm/coreEnforcer.js +13 -1
- package/lib/esm/internalEnforcer.js +22 -7
- package/lib/esm/persist/index.d.ts +1 -0
- package/lib/esm/persist/index.js +1 -0
- package/lib/esm/persist/watcherEx.d.ts +9 -0
- package/lib/esm/persist/watcherEx.js +13 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [5.17.0](https://github.com/casbin/node-casbin/compare/v5.16.0...v5.17.0) (2022-08-18)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* add WatcherEx ([#381](https://github.com/casbin/node-casbin/issues/381)) ([10d7086](https://github.com/casbin/node-casbin/commit/10d7086c810ff18d9a3c792a3ec1173744bceeef))
|
|
7
|
+
|
|
1
8
|
# [5.16.0](https://github.com/casbin/node-casbin/compare/v5.15.2...v5.16.0) (2022-08-11)
|
|
2
9
|
|
|
3
10
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Effector } from './effect';
|
|
2
2
|
import { FunctionMap, Model, PolicyOp } from './model';
|
|
3
|
-
import { Adapter, FilteredAdapter, Watcher, BatchAdapter, UpdatableAdapter } from './persist';
|
|
3
|
+
import { Adapter, FilteredAdapter, Watcher, BatchAdapter, UpdatableAdapter, WatcherEx } from './persist';
|
|
4
4
|
import { RoleManager } from './rbac';
|
|
5
5
|
import { MatchingFunc } from './rbac';
|
|
6
6
|
/**
|
|
@@ -14,6 +14,7 @@ export declare class CoreEnforcer {
|
|
|
14
14
|
private matcherMap;
|
|
15
15
|
protected adapter: UpdatableAdapter | FilteredAdapter | Adapter | BatchAdapter;
|
|
16
16
|
protected watcher: Watcher | null;
|
|
17
|
+
protected watcherEx: WatcherEx | null;
|
|
17
18
|
protected rmMap: Map<string, RoleManager>;
|
|
18
19
|
protected enabled: boolean;
|
|
19
20
|
protected autoSave: boolean;
|
|
@@ -56,6 +57,12 @@ export declare class CoreEnforcer {
|
|
|
56
57
|
* @param watcher the watcher.
|
|
57
58
|
*/
|
|
58
59
|
setWatcher(watcher: Watcher): void;
|
|
60
|
+
/**
|
|
61
|
+
* setWatcherEx sets the current watcherEx.
|
|
62
|
+
*
|
|
63
|
+
* @param watcherEx the watcherEx.
|
|
64
|
+
*/
|
|
65
|
+
setWatcherEx(watcherEx: WatcherEx): void;
|
|
59
66
|
/**
|
|
60
67
|
* setRoleManager sets the current role manager.
|
|
61
68
|
*
|
package/lib/cjs/coreEnforcer.js
CHANGED
|
@@ -29,6 +29,7 @@ class CoreEnforcer {
|
|
|
29
29
|
this.eft = new effect_1.DefaultEffector();
|
|
30
30
|
this.matcherMap = new Map();
|
|
31
31
|
this.watcher = null;
|
|
32
|
+
this.watcherEx = null;
|
|
32
33
|
this.enabled = true;
|
|
33
34
|
this.autoSave = true;
|
|
34
35
|
this.autoBuildRoleLinks = true;
|
|
@@ -96,6 +97,14 @@ class CoreEnforcer {
|
|
|
96
97
|
this.watcher = watcher;
|
|
97
98
|
watcher.setUpdateCallback(async () => await this.loadPolicy());
|
|
98
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* setWatcherEx sets the current watcherEx.
|
|
102
|
+
*
|
|
103
|
+
* @param watcherEx the watcherEx.
|
|
104
|
+
*/
|
|
105
|
+
setWatcherEx(watcherEx) {
|
|
106
|
+
this.watcherEx = watcherEx;
|
|
107
|
+
}
|
|
99
108
|
/**
|
|
100
109
|
* setRoleManager sets the current role manager.
|
|
101
110
|
*
|
|
@@ -215,7 +224,10 @@ class CoreEnforcer {
|
|
|
215
224
|
if (!flag) {
|
|
216
225
|
return false;
|
|
217
226
|
}
|
|
218
|
-
if (this.
|
|
227
|
+
if (this.watcherEx) {
|
|
228
|
+
return await this.watcherEx.updateForSavePolicy(this.model);
|
|
229
|
+
}
|
|
230
|
+
else if (this.watcher) {
|
|
219
231
|
return await this.watcher.update();
|
|
220
232
|
}
|
|
221
233
|
return true;
|
|
@@ -37,9 +37,12 @@ class InternalEnforcer extends coreEnforcer_1.CoreEnforcer {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
-
if (this.
|
|
40
|
+
if (this.autoNotifyWatcher) {
|
|
41
41
|
// error intentionally ignored
|
|
42
|
-
this.
|
|
42
|
+
if (this.watcherEx)
|
|
43
|
+
await this.watcherEx.updateForAddPolicy(sec, ptype, ...rule);
|
|
44
|
+
else if (this.watcher)
|
|
45
|
+
await this.watcher.update();
|
|
43
46
|
}
|
|
44
47
|
const ok = this.model.addPolicy(sec, ptype, rule);
|
|
45
48
|
if (sec === 'g' && ok) {
|
|
@@ -70,9 +73,12 @@ class InternalEnforcer extends coreEnforcer_1.CoreEnforcer {
|
|
|
70
73
|
throw new Error('cannot to save policy, the adapter does not implement the BatchAdapter');
|
|
71
74
|
}
|
|
72
75
|
}
|
|
73
|
-
if (this.
|
|
76
|
+
if (this.autoNotifyWatcher) {
|
|
74
77
|
// error intentionally ignored
|
|
75
|
-
this.
|
|
78
|
+
if (this.watcherEx)
|
|
79
|
+
await this.watcherEx.updateForAddPolicies(sec, ptype, ...rules);
|
|
80
|
+
else if (this.watcher)
|
|
81
|
+
this.watcher.update();
|
|
76
82
|
}
|
|
77
83
|
const [ok, effects] = await this.model.addPolicies(sec, ptype, rules);
|
|
78
84
|
if (sec === 'g' && ok && (effects === null || effects === void 0 ? void 0 : effects.length)) {
|
|
@@ -133,7 +139,10 @@ class InternalEnforcer extends coreEnforcer_1.CoreEnforcer {
|
|
|
133
139
|
}
|
|
134
140
|
if (this.watcher && this.autoNotifyWatcher) {
|
|
135
141
|
// error intentionally ignored
|
|
136
|
-
this.
|
|
142
|
+
if (this.watcherEx)
|
|
143
|
+
await this.watcherEx.updateForRemovePolicy(sec, ptype, ...rule);
|
|
144
|
+
else if (this.watcher)
|
|
145
|
+
await this.watcher.update();
|
|
137
146
|
}
|
|
138
147
|
const ok = await this.model.removePolicy(sec, ptype, rule);
|
|
139
148
|
if (sec === 'g' && ok) {
|
|
@@ -165,7 +174,10 @@ class InternalEnforcer extends coreEnforcer_1.CoreEnforcer {
|
|
|
165
174
|
}
|
|
166
175
|
if (this.watcher && this.autoNotifyWatcher) {
|
|
167
176
|
// error intentionally ignored
|
|
168
|
-
this.
|
|
177
|
+
if (this.watcherEx)
|
|
178
|
+
await this.watcherEx.updateForRemovePolicies(sec, ptype, ...rules);
|
|
179
|
+
else if (this.watcher)
|
|
180
|
+
await this.watcher.update();
|
|
169
181
|
}
|
|
170
182
|
const [ok, effects] = this.model.removePolicies(sec, ptype, rules);
|
|
171
183
|
if (sec === 'g' && ok && (effects === null || effects === void 0 ? void 0 : effects.length)) {
|
|
@@ -189,7 +201,10 @@ class InternalEnforcer extends coreEnforcer_1.CoreEnforcer {
|
|
|
189
201
|
}
|
|
190
202
|
if (this.watcher && this.autoNotifyWatcher) {
|
|
191
203
|
// error intentionally ignored
|
|
192
|
-
this.
|
|
204
|
+
if (this.watcherEx)
|
|
205
|
+
await this.watcherEx.updateForRemoveFilteredPolicy(sec, ptype, fieldIndex, ...fieldValues);
|
|
206
|
+
else if (this.watcher)
|
|
207
|
+
await this.watcher.update();
|
|
193
208
|
}
|
|
194
209
|
const [ok, effects] = this.model.removeFilteredPolicy(sec, ptype, fieldIndex, ...fieldValues);
|
|
195
210
|
if (sec === 'g' && ok && (effects === null || effects === void 0 ? void 0 : effects.length)) {
|
package/lib/cjs/persist/index.js
CHANGED
|
@@ -15,6 +15,7 @@ __exportStar(require("./fileAdapter"), exports);
|
|
|
15
15
|
__exportStar(require("./stringAdapter"), exports);
|
|
16
16
|
__exportStar(require("./helper"), exports);
|
|
17
17
|
__exportStar(require("./watcher"), exports);
|
|
18
|
+
__exportStar(require("./watcherEx"), exports);
|
|
18
19
|
__exportStar(require("./filteredAdapter"), exports);
|
|
19
20
|
__exportStar(require("./defaultFilteredAdapter"), exports);
|
|
20
21
|
__exportStar(require("./batchAdapter"), exports);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Model } from '../model';
|
|
2
|
+
export interface WatcherEx {
|
|
3
|
+
updateForAddPolicy(sec: string, ptype: string, ...params: string[]): Promise<void>;
|
|
4
|
+
updateForRemovePolicy(sec: string, ptype: string, ...params: string[]): Promise<void>;
|
|
5
|
+
updateForRemoveFilteredPolicy(sec: string, ptype: string, fieldIndex: number, ...fieldValues: string[]): Promise<void>;
|
|
6
|
+
updateForSavePolicy(model: Model): Promise<boolean>;
|
|
7
|
+
updateForAddPolicies(sec: string, ptype: string, ...rules: string[][]): Promise<void>;
|
|
8
|
+
updateForRemovePolicies(sec: string, ptype: string, ...rules: string[][]): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2022 The Casbin Authors. All Rights Reserved.
|
|
3
|
+
//
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
// you may not use this file except in compliance with the License.
|
|
6
|
+
// You may obtain a copy of the License at
|
|
7
|
+
//
|
|
8
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
//
|
|
10
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
// See the License for the specific language governing permissions and
|
|
14
|
+
// limitations under the License.
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Effector } from './effect';
|
|
2
2
|
import { FunctionMap, Model, PolicyOp } from './model';
|
|
3
|
-
import { Adapter, FilteredAdapter, Watcher, BatchAdapter, UpdatableAdapter } from './persist';
|
|
3
|
+
import { Adapter, FilteredAdapter, Watcher, BatchAdapter, UpdatableAdapter, WatcherEx } from './persist';
|
|
4
4
|
import { RoleManager } from './rbac';
|
|
5
5
|
import { MatchingFunc } from './rbac';
|
|
6
6
|
/**
|
|
@@ -14,6 +14,7 @@ export declare class CoreEnforcer {
|
|
|
14
14
|
private matcherMap;
|
|
15
15
|
protected adapter: UpdatableAdapter | FilteredAdapter | Adapter | BatchAdapter;
|
|
16
16
|
protected watcher: Watcher | null;
|
|
17
|
+
protected watcherEx: WatcherEx | null;
|
|
17
18
|
protected rmMap: Map<string, RoleManager>;
|
|
18
19
|
protected enabled: boolean;
|
|
19
20
|
protected autoSave: boolean;
|
|
@@ -56,6 +57,12 @@ export declare class CoreEnforcer {
|
|
|
56
57
|
* @param watcher the watcher.
|
|
57
58
|
*/
|
|
58
59
|
setWatcher(watcher: Watcher): void;
|
|
60
|
+
/**
|
|
61
|
+
* setWatcherEx sets the current watcherEx.
|
|
62
|
+
*
|
|
63
|
+
* @param watcherEx the watcherEx.
|
|
64
|
+
*/
|
|
65
|
+
setWatcherEx(watcherEx: WatcherEx): void;
|
|
59
66
|
/**
|
|
60
67
|
* setRoleManager sets the current role manager.
|
|
61
68
|
*
|
package/lib/esm/coreEnforcer.js
CHANGED
|
@@ -26,6 +26,7 @@ export class CoreEnforcer {
|
|
|
26
26
|
this.eft = new DefaultEffector();
|
|
27
27
|
this.matcherMap = new Map();
|
|
28
28
|
this.watcher = null;
|
|
29
|
+
this.watcherEx = null;
|
|
29
30
|
this.enabled = true;
|
|
30
31
|
this.autoSave = true;
|
|
31
32
|
this.autoBuildRoleLinks = true;
|
|
@@ -93,6 +94,14 @@ export class CoreEnforcer {
|
|
|
93
94
|
this.watcher = watcher;
|
|
94
95
|
watcher.setUpdateCallback(async () => await this.loadPolicy());
|
|
95
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* setWatcherEx sets the current watcherEx.
|
|
99
|
+
*
|
|
100
|
+
* @param watcherEx the watcherEx.
|
|
101
|
+
*/
|
|
102
|
+
setWatcherEx(watcherEx) {
|
|
103
|
+
this.watcherEx = watcherEx;
|
|
104
|
+
}
|
|
96
105
|
/**
|
|
97
106
|
* setRoleManager sets the current role manager.
|
|
98
107
|
*
|
|
@@ -212,7 +221,10 @@ export class CoreEnforcer {
|
|
|
212
221
|
if (!flag) {
|
|
213
222
|
return false;
|
|
214
223
|
}
|
|
215
|
-
if (this.
|
|
224
|
+
if (this.watcherEx) {
|
|
225
|
+
return await this.watcherEx.updateForSavePolicy(this.model);
|
|
226
|
+
}
|
|
227
|
+
else if (this.watcher) {
|
|
216
228
|
return await this.watcher.update();
|
|
217
229
|
}
|
|
218
230
|
return true;
|
|
@@ -34,9 +34,12 @@ export class InternalEnforcer extends CoreEnforcer {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
if (this.
|
|
37
|
+
if (this.autoNotifyWatcher) {
|
|
38
38
|
// error intentionally ignored
|
|
39
|
-
this.
|
|
39
|
+
if (this.watcherEx)
|
|
40
|
+
await this.watcherEx.updateForAddPolicy(sec, ptype, ...rule);
|
|
41
|
+
else if (this.watcher)
|
|
42
|
+
await this.watcher.update();
|
|
40
43
|
}
|
|
41
44
|
const ok = this.model.addPolicy(sec, ptype, rule);
|
|
42
45
|
if (sec === 'g' && ok) {
|
|
@@ -67,9 +70,12 @@ export class InternalEnforcer extends CoreEnforcer {
|
|
|
67
70
|
throw new Error('cannot to save policy, the adapter does not implement the BatchAdapter');
|
|
68
71
|
}
|
|
69
72
|
}
|
|
70
|
-
if (this.
|
|
73
|
+
if (this.autoNotifyWatcher) {
|
|
71
74
|
// error intentionally ignored
|
|
72
|
-
this.
|
|
75
|
+
if (this.watcherEx)
|
|
76
|
+
await this.watcherEx.updateForAddPolicies(sec, ptype, ...rules);
|
|
77
|
+
else if (this.watcher)
|
|
78
|
+
this.watcher.update();
|
|
73
79
|
}
|
|
74
80
|
const [ok, effects] = await this.model.addPolicies(sec, ptype, rules);
|
|
75
81
|
if (sec === 'g' && ok && (effects === null || effects === void 0 ? void 0 : effects.length)) {
|
|
@@ -130,7 +136,10 @@ export class InternalEnforcer extends CoreEnforcer {
|
|
|
130
136
|
}
|
|
131
137
|
if (this.watcher && this.autoNotifyWatcher) {
|
|
132
138
|
// error intentionally ignored
|
|
133
|
-
this.
|
|
139
|
+
if (this.watcherEx)
|
|
140
|
+
await this.watcherEx.updateForRemovePolicy(sec, ptype, ...rule);
|
|
141
|
+
else if (this.watcher)
|
|
142
|
+
await this.watcher.update();
|
|
134
143
|
}
|
|
135
144
|
const ok = await this.model.removePolicy(sec, ptype, rule);
|
|
136
145
|
if (sec === 'g' && ok) {
|
|
@@ -162,7 +171,10 @@ export class InternalEnforcer extends CoreEnforcer {
|
|
|
162
171
|
}
|
|
163
172
|
if (this.watcher && this.autoNotifyWatcher) {
|
|
164
173
|
// error intentionally ignored
|
|
165
|
-
this.
|
|
174
|
+
if (this.watcherEx)
|
|
175
|
+
await this.watcherEx.updateForRemovePolicies(sec, ptype, ...rules);
|
|
176
|
+
else if (this.watcher)
|
|
177
|
+
await this.watcher.update();
|
|
166
178
|
}
|
|
167
179
|
const [ok, effects] = this.model.removePolicies(sec, ptype, rules);
|
|
168
180
|
if (sec === 'g' && ok && (effects === null || effects === void 0 ? void 0 : effects.length)) {
|
|
@@ -186,7 +198,10 @@ export class InternalEnforcer extends CoreEnforcer {
|
|
|
186
198
|
}
|
|
187
199
|
if (this.watcher && this.autoNotifyWatcher) {
|
|
188
200
|
// error intentionally ignored
|
|
189
|
-
this.
|
|
201
|
+
if (this.watcherEx)
|
|
202
|
+
await this.watcherEx.updateForRemoveFilteredPolicy(sec, ptype, fieldIndex, ...fieldValues);
|
|
203
|
+
else if (this.watcher)
|
|
204
|
+
await this.watcher.update();
|
|
190
205
|
}
|
|
191
206
|
const [ok, effects] = this.model.removeFilteredPolicy(sec, ptype, fieldIndex, ...fieldValues);
|
|
192
207
|
if (sec === 'g' && ok && (effects === null || effects === void 0 ? void 0 : effects.length)) {
|
package/lib/esm/persist/index.js
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Model } from '../model';
|
|
2
|
+
export interface WatcherEx {
|
|
3
|
+
updateForAddPolicy(sec: string, ptype: string, ...params: string[]): Promise<void>;
|
|
4
|
+
updateForRemovePolicy(sec: string, ptype: string, ...params: string[]): Promise<void>;
|
|
5
|
+
updateForRemoveFilteredPolicy(sec: string, ptype: string, fieldIndex: number, ...fieldValues: string[]): Promise<void>;
|
|
6
|
+
updateForSavePolicy(model: Model): Promise<boolean>;
|
|
7
|
+
updateForAddPolicies(sec: string, ptype: string, ...rules: string[][]): Promise<void>;
|
|
8
|
+
updateForRemovePolicies(sec: string, ptype: string, ...rules: string[][]): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Copyright 2022 The Casbin Authors. All Rights Reserved.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
package/package.json
CHANGED