casbin 5.47.0 → 5.49.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.
Files changed (58) hide show
  1. package/lib/cjs/cachedEnforcer.js +1 -1
  2. package/lib/cjs/config.js +1 -1
  3. package/lib/cjs/coreEnforcer.js +25 -25
  4. package/lib/cjs/effect/defaultEffectorStream.js +5 -5
  5. package/lib/cjs/effect/index.js +6 -2
  6. package/lib/cjs/enforceContext.js +2 -1
  7. package/lib/cjs/enforcer.js +17 -13
  8. package/lib/cjs/frontend.js +2 -2
  9. package/lib/cjs/index.js +7 -3
  10. package/lib/cjs/internalEnforcer.d.ts +8 -0
  11. package/lib/cjs/internalEnforcer.js +105 -11
  12. package/lib/cjs/log/index.js +6 -2
  13. package/lib/cjs/managementEnforcer.d.ts +4 -3
  14. package/lib/cjs/managementEnforcer.js +13 -10
  15. package/lib/cjs/model/assertion.js +7 -3
  16. package/lib/cjs/model/functionMap.d.ts +1 -1
  17. package/lib/cjs/model/functionMap.js +6 -2
  18. package/lib/cjs/model/index.js +6 -2
  19. package/lib/cjs/model/model.js +17 -13
  20. package/lib/cjs/persist/defaultFilteredAdapter.js +1 -1
  21. package/lib/cjs/persist/fileAdapter.js +4 -4
  22. package/lib/cjs/persist/fileSystem.d.ts +1 -1
  23. package/lib/cjs/persist/fileSystem.js +6 -3
  24. package/lib/cjs/persist/helper.js +1 -1
  25. package/lib/cjs/persist/index.js +6 -2
  26. package/lib/cjs/rbac/defaultRoleManager.d.ts +1 -1
  27. package/lib/cjs/rbac/defaultRoleManager.js +2 -2
  28. package/lib/cjs/rbac/index.js +6 -2
  29. package/lib/cjs/syncedEnforcer.js +1 -1
  30. package/lib/cjs/util/builtinOperators.js +1 -1
  31. package/lib/cjs/util/index.js +6 -2
  32. package/lib/cjs/util/ip.d.ts +3 -3
  33. package/lib/cjs/util/util.d.ts +2 -2
  34. package/lib/cjs/util/util.js +4 -4
  35. package/lib/esm/constants.js +1 -0
  36. package/lib/esm/effect/defaultEffectorStream.js +5 -5
  37. package/lib/esm/effect/effectorStream.js +1 -0
  38. package/lib/esm/enforcer.js +5 -5
  39. package/lib/esm/internalEnforcer.d.ts +8 -0
  40. package/lib/esm/internalEnforcer.js +105 -11
  41. package/lib/esm/log/logger.js +1 -0
  42. package/lib/esm/managementEnforcer.d.ts +4 -3
  43. package/lib/esm/managementEnforcer.js +13 -10
  44. package/lib/esm/model/functionMap.d.ts +1 -1
  45. package/lib/esm/model/model.js +6 -6
  46. package/lib/esm/persist/adapter.js +1 -0
  47. package/lib/esm/persist/batchAdapter.js +1 -0
  48. package/lib/esm/persist/fileSystem.d.ts +1 -1
  49. package/lib/esm/persist/filteredAdapter.js +1 -0
  50. package/lib/esm/persist/updatableAdapter.js +1 -0
  51. package/lib/esm/persist/watcher.js +1 -0
  52. package/lib/esm/persist/watcherEx.js +1 -0
  53. package/lib/esm/rbac/defaultRoleManager.d.ts +1 -1
  54. package/lib/esm/rbac/roleManager.js +1 -0
  55. package/lib/esm/util/ip.d.ts +3 -3
  56. package/lib/esm/util/util.d.ts +2 -2
  57. package/lib/esm/util/util.js +2 -2
  58. package/package.json +3 -3
@@ -429,9 +429,10 @@ export declare class ManagementEnforcer extends InternalEnforcer {
429
429
  */
430
430
  addFunction(name: string, func: MatchingFunction): Promise<void>;
431
431
  selfAddPolicy(sec: string, ptype: string, rule: string[]): Promise<boolean>;
432
+ selfAddPolicies(sec: string, ptype: string, rules: string[][]): Promise<boolean>;
432
433
  selfRemovePolicy(sec: string, ptype: string, rule: string[]): Promise<boolean>;
433
- selfRemoveFilteredPolicy(sec: string, ptype: string, fieldIndex: number, fieldValues: string[]): Promise<boolean>;
434
+ selfRemovePolicies(sec: string, ptype: string, rules: string[][]): Promise<boolean>;
435
+ selfRemoveFilteredPolicy(sec: string, ptype: string, fieldIndex: number, ...fieldValues: string[]): Promise<boolean>;
434
436
  selfUpdatePolicy(sec: string, ptype: string, oldRule: string[], newRule: string[]): Promise<boolean>;
435
- selfAddPolicies(sec: string, ptype: string, rule: string[][]): Promise<boolean>;
436
- selfRemovePolicies(sec: string, ptype: string, rule: string[][]): Promise<boolean>;
437
+ selfUpdatePolicies(sec: string, ptype: string, oldRules: string[][], newRules: string[][]): Promise<boolean>;
437
438
  }
@@ -542,22 +542,25 @@ class ManagementEnforcer extends internalEnforcer_1.InternalEnforcer {
542
542
  this.fm.addFunction(name, func);
543
543
  }
544
544
  async selfAddPolicy(sec, ptype, rule) {
545
- return this.addPolicyInternal(sec, ptype, rule, false);
545
+ return this.addPolicyWithoutNotify(sec, ptype, rule);
546
+ }
547
+ async selfAddPolicies(sec, ptype, rules) {
548
+ return this.addPoliciesWithoutNotify(sec, ptype, rules);
546
549
  }
547
550
  async selfRemovePolicy(sec, ptype, rule) {
548
- return this.removePolicyInternal(sec, ptype, rule, false);
551
+ return this.removePolicyWithoutNotify(sec, ptype, rule);
549
552
  }
550
- async selfRemoveFilteredPolicy(sec, ptype, fieldIndex, fieldValues) {
551
- return this.removeFilteredPolicyInternal(sec, ptype, fieldIndex, fieldValues, false);
553
+ async selfRemovePolicies(sec, ptype, rules) {
554
+ return this.removePoliciesWithoutNotify(sec, ptype, rules);
552
555
  }
553
- async selfUpdatePolicy(sec, ptype, oldRule, newRule) {
554
- return this.updatePolicyInternal(sec, ptype, oldRule, newRule, false);
556
+ async selfRemoveFilteredPolicy(sec, ptype, fieldIndex, ...fieldValues) {
557
+ return this.removeFilteredPolicyWithoutNotify(sec, ptype, fieldIndex, fieldValues);
555
558
  }
556
- async selfAddPolicies(sec, ptype, rule) {
557
- return this.addPoliciesInternal(sec, ptype, rule, false);
559
+ async selfUpdatePolicy(sec, ptype, oldRule, newRule) {
560
+ return this.updatePolicyWithoutNotify(sec, ptype, oldRule, newRule);
558
561
  }
559
- async selfRemovePolicies(sec, ptype, rule) {
560
- return this.removePoliciesInternal(sec, ptype, rule, false);
562
+ async selfUpdatePolicies(sec, ptype, oldRules, newRules) {
563
+ return this.updatePoliciesWithoutNotify(sec, ptype, oldRules, newRules);
561
564
  }
562
565
  }
563
566
  exports.ManagementEnforcer = ManagementEnforcer;
@@ -14,7 +14,11 @@
14
14
  // limitations under the License.
15
15
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
16
16
  if (k2 === undefined) k2 = k;
17
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
17
+ var desc = Object.getOwnPropertyDescriptor(m, k);
18
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
19
+ desc = { enumerable: true, get: function() { return m[k]; } };
20
+ }
21
+ Object.defineProperty(o, k2, desc);
18
22
  }) : (function(o, m, k, k2) {
19
23
  if (k2 === undefined) k2 = k;
20
24
  o[k2] = m[k];
@@ -27,7 +31,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
27
31
  var __importStar = (this && this.__importStar) || function (mod) {
28
32
  if (mod && mod.__esModule) return mod;
29
33
  var result = {};
30
- if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
34
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
31
35
  __setModuleDefault(result, mod);
32
36
  return result;
33
37
  };
@@ -87,7 +91,7 @@ class Assertion {
87
91
  }
88
92
  await this.rm.addLink(rule[0], rule[1], ...rule.slice(2));
89
93
  }
90
- log_1.logPrint(`Role links for: ${this.key}`);
94
+ (0, log_1.logPrint)(`Role links for: ${this.key}`);
91
95
  await this.rm.printRoles();
92
96
  }
93
97
  }
@@ -1,4 +1,4 @@
1
- export declare type MatchingFunction = (...arg: any[]) => boolean | number | string | Promise<boolean> | Promise<number> | Promise<string>;
1
+ export type MatchingFunction = (...arg: any[]) => boolean | number | string | Promise<boolean> | Promise<number> | Promise<string>;
2
2
  export declare class FunctionMap {
3
3
  private functions;
4
4
  /**
@@ -14,7 +14,11 @@
14
14
  // limitations under the License.
15
15
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
16
16
  if (k2 === undefined) k2 = k;
17
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
17
+ var desc = Object.getOwnPropertyDescriptor(m, k);
18
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
19
+ desc = { enumerable: true, get: function() { return m[k]; } };
20
+ }
21
+ Object.defineProperty(o, k2, desc);
18
22
  }) : (function(o, m, k, k2) {
19
23
  if (k2 === undefined) k2 = k;
20
24
  o[k2] = m[k];
@@ -27,7 +31,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
27
31
  var __importStar = (this && this.__importStar) || function (mod) {
28
32
  if (mod && mod.__esModule) return mod;
29
33
  var result = {};
30
- if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
34
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
31
35
  __setModuleDefault(result, mod);
32
36
  return result;
33
37
  };
@@ -14,13 +14,17 @@
14
14
  // limitations under the License.
15
15
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
16
16
  if (k2 === undefined) k2 = k;
17
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
17
+ var desc = Object.getOwnPropertyDescriptor(m, k);
18
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
19
+ desc = { enumerable: true, get: function() { return m[k]; } };
20
+ }
21
+ Object.defineProperty(o, k2, desc);
18
22
  }) : (function(o, m, k, k2) {
19
23
  if (k2 === undefined) k2 = k;
20
24
  o[k2] = m[k];
21
25
  }));
22
26
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
23
- for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
27
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
24
28
  };
25
29
  Object.defineProperty(exports, "__esModule", { value: true });
26
30
  __exportStar(require("./assertion"), exports);
@@ -14,7 +14,11 @@
14
14
  // limitations under the License.
15
15
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
16
16
  if (k2 === undefined) k2 = k;
17
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
17
+ var desc = Object.getOwnPropertyDescriptor(m, k);
18
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
19
+ desc = { enumerable: true, get: function() { return m[k]; } };
20
+ }
21
+ Object.defineProperty(o, k2, desc);
18
22
  }) : (function(o, m, k, k2) {
19
23
  if (k2 === undefined) k2 = k;
20
24
  o[k2] = m[k];
@@ -27,7 +31,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
27
31
  var __importStar = (this && this.__importStar) || function (mod) {
28
32
  if (mod && mod.__esModule) return mod;
29
33
  var result = {};
30
- if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
34
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
31
35
  __setModuleDefault(result, mod);
32
36
  return result;
33
37
  };
@@ -169,10 +173,10 @@ class Model {
169
173
  }
170
174
  // printModel prints the model to the log.
171
175
  printModel() {
172
- log_1.logPrint('Model:');
176
+ (0, log_1.logPrint)('Model:');
173
177
  this.model.forEach((value, key) => {
174
178
  value.forEach((ast, astKey) => {
175
- log_1.logPrint(`${key}.${astKey}: ${ast.value}`);
179
+ (0, log_1.logPrint)(`${key}.${astKey}: ${ast.value}`);
176
180
  });
177
181
  });
178
182
  }
@@ -425,14 +429,14 @@ class Model {
425
429
  }
426
430
  // printPolicy prints the policy to log.
427
431
  printPolicy() {
428
- if (!log_1.getLogger().isEnable()) {
432
+ if (!(0, log_1.getLogger)().isEnable()) {
429
433
  return;
430
434
  }
431
- log_1.logPrint('Policy:');
435
+ (0, log_1.logPrint)('Policy:');
432
436
  this.model.forEach((map, key) => {
433
437
  if (key === 'p' || key === 'g') {
434
438
  map.forEach((ast) => {
435
- log_1.logPrint(`key, : ${ast.value}, : , ${ast.policy}`);
439
+ (0, log_1.logPrint)(`key, : ${ast.value}, : , ${ast.policy}`);
436
440
  });
437
441
  }
438
442
  });
@@ -469,12 +473,12 @@ class Model {
469
473
  */
470
474
  sortPoliciesBySubjectHierarchy() {
471
475
  var _a, _b, _c;
472
- if (((_b = (_a = this.model.get('e')) === null || _a === void 0 ? void 0 : _a.get('e')) === null || _b === void 0 ? void 0 : _b.value) !== "subjectPriority(p_eft) || deny" /* SUBJECT_PRIORITY */) {
476
+ if (((_b = (_a = this.model.get('e')) === null || _a === void 0 ? void 0 : _a.get('e')) === null || _b === void 0 ? void 0 : _b.value) !== "subjectPriority(p_eft) || deny" /* EffectExpress.SUBJECT_PRIORITY */) {
473
477
  return;
474
478
  }
475
479
  (_c = this.model.get('p')) === null || _c === void 0 ? void 0 : _c.forEach((assertion, ptype) => {
476
- const domainIndex = this.getFieldIndex(ptype, "dom" /* Domain */);
477
- const subIndex = this.getFieldIndex(ptype, "sub" /* Subject */);
480
+ const domainIndex = this.getFieldIndex(ptype, "dom" /* FieldIndex.Domain */);
481
+ const subIndex = this.getFieldIndex(ptype, "sub" /* FieldIndex.Subject */);
478
482
  // eslint-disable-next-line
479
483
  const subjectHierarchyMap = this.getSubjectHierarchyMap(this.model.get('g').get('g').policy);
480
484
  assertion.policy.sort((policyA, policyB) => {
@@ -500,9 +504,9 @@ class Model {
500
504
  let domain = defaultDomain;
501
505
  groupPolicies.forEach((policy) => {
502
506
  if (policy.length !== 2)
503
- domain = policy[this.getFieldIndex('p', "dom" /* Domain */)];
504
- const child = this.getNameWithDomain(domain, policy[this.getFieldIndex('p', "sub" /* Subject */)]);
505
- const parent = this.getNameWithDomain(domain, policy[this.getFieldIndex('p', "obj" /* Object */)]);
507
+ domain = policy[this.getFieldIndex('p', "dom" /* FieldIndex.Domain */)];
508
+ const child = this.getNameWithDomain(domain, policy[this.getFieldIndex('p', "sub" /* FieldIndex.Subject */)]);
509
+ const parent = this.getNameWithDomain(domain, policy[this.getFieldIndex('p', "obj" /* FieldIndex.Object */)]);
506
510
  policyMap.set(child, parent);
507
511
  if (!subjectHierarchyMap.has(child)) {
508
512
  subjectHierarchyMap.set(child, 0);
@@ -33,7 +33,7 @@ class DefaultFilteredAdapter extends fileAdapter_1.FileAdapter {
33
33
  this.filtered = true;
34
34
  }
35
35
  async loadFilteredPolicyFile(model, filter, handler) {
36
- const bodyBuf = await util_1.readFile(this.filePath);
36
+ const bodyBuf = await (0, util_1.readFile)(this.filePath);
37
37
  const lines = bodyBuf.toString().split('\n');
38
38
  lines.forEach((n, index) => {
39
39
  const line = n;
@@ -27,7 +27,7 @@ class FileAdapter {
27
27
  await this.loadPolicyFile(model, helper_1.Helper.loadPolicyLine);
28
28
  }
29
29
  async loadPolicyFile(model, handler) {
30
- const bodyBuf = await (this.fs ? this.fs : fileSystem_1.mustGetDefaultFileSystem()).readFileSync(this.filePath);
30
+ const bodyBuf = await (this.fs ? this.fs : (0, fileSystem_1.mustGetDefaultFileSystem)()).readFileSync(this.filePath);
31
31
  const lines = bodyBuf.toString().split('\n');
32
32
  lines.forEach((line) => {
33
33
  if (!line || line.trim().startsWith('#')) {
@@ -52,7 +52,7 @@ class FileAdapter {
52
52
  pList.forEach((n) => {
53
53
  n.policy.forEach((m) => {
54
54
  result += n.key + ', ';
55
- result += util_1.arrayToString(m);
55
+ result += (0, util_1.arrayToString)(m);
56
56
  result += '\n';
57
57
  });
58
58
  });
@@ -63,7 +63,7 @@ class FileAdapter {
63
63
  gList.forEach((n) => {
64
64
  n.policy.forEach((m) => {
65
65
  result += n.key + ', ';
66
- result += util_1.arrayToString(m.map((element) => this.escapeCsv(element)));
66
+ result += (0, util_1.arrayToString)(m.map((element) => this.escapeCsv(element)));
67
67
  result += '\n';
68
68
  });
69
69
  });
@@ -78,7 +78,7 @@ class FileAdapter {
78
78
  return value;
79
79
  }
80
80
  async savePolicyFile(text) {
81
- (this.fs ? this.fs : fileSystem_1.mustGetDefaultFileSystem()).writeFileSync(this.filePath, text);
81
+ (this.fs ? this.fs : (0, fileSystem_1.mustGetDefaultFileSystem)()).writeFileSync(this.filePath, text);
82
82
  }
83
83
  /**
84
84
  * addPolicy adds a policy rule to the storage.
@@ -3,6 +3,6 @@ export interface FileSystem {
3
3
  readFileSync(path: string, encoding?: string): Buffer | string;
4
4
  writeFileSync(path: string, text: string, encoding?: string): void;
5
5
  }
6
- export declare const setDefaultFileSystem: (fs?: FileSystem | undefined) => void;
6
+ export declare const setDefaultFileSystem: (fs?: FileSystem) => void;
7
7
  export declare const getDefaultFileSystem: () => FileSystem | undefined;
8
8
  export declare const mustGetDefaultFileSystem: () => FileSystem;
@@ -3,13 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.mustGetDefaultFileSystem = exports.getDefaultFileSystem = exports.setDefaultFileSystem = void 0;
4
4
  let defaultFileSystem = undefined;
5
5
  const ErrorNoFileSystem = new Error('please set the default FileSystem by call the setDefaultFileSystem');
6
- exports.setDefaultFileSystem = (fs) => {
6
+ const setDefaultFileSystem = (fs) => {
7
7
  defaultFileSystem = fs;
8
8
  };
9
- exports.getDefaultFileSystem = () => defaultFileSystem;
10
- exports.mustGetDefaultFileSystem = () => {
9
+ exports.setDefaultFileSystem = setDefaultFileSystem;
10
+ const getDefaultFileSystem = () => defaultFileSystem;
11
+ exports.getDefaultFileSystem = getDefaultFileSystem;
12
+ const mustGetDefaultFileSystem = () => {
11
13
  if (defaultFileSystem) {
12
14
  return defaultFileSystem;
13
15
  }
14
16
  throw ErrorNoFileSystem;
15
17
  };
18
+ exports.mustGetDefaultFileSystem = mustGetDefaultFileSystem;
@@ -7,7 +7,7 @@ class BasicCsvParser {
7
7
  if (!line || line.trimStart().charAt(0) === '#') {
8
8
  return null;
9
9
  }
10
- return sync_1.parse(line, {
10
+ return (0, sync_1.parse)(line, {
11
11
  delimiter: ',',
12
12
  skip_empty_lines: true,
13
13
  trim: true,
@@ -1,13 +1,17 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
8
12
  }));
9
13
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
15
  };
12
16
  Object.defineProperty(exports, "__esModule", { value: true });
13
17
  __exportStar(require("./adapter"), exports);
@@ -1,5 +1,5 @@
1
1
  import { RoleManager } from './roleManager';
2
- export declare type MatchingFunc = (arg1: string, arg2: string) => boolean;
2
+ export type MatchingFunc = (arg1: string, arg2: string) => boolean;
3
3
  export declare class DefaultRoleManager implements RoleManager {
4
4
  private allDomains;
5
5
  private maxHierarchyLevel;
@@ -289,9 +289,9 @@ class DefaultRoleManager {
289
289
  * printRoles prints all the roles to log.
290
290
  */
291
291
  async printRoles() {
292
- if (log_1.getLogger().isEnable()) {
292
+ if ((0, log_1.getLogger)().isEnable()) {
293
293
  [...this.allDomains.values()].forEach((n) => {
294
- log_1.logPrint(n.toString());
294
+ (0, log_1.logPrint)(n.toString());
295
295
  });
296
296
  }
297
297
  }
@@ -14,13 +14,17 @@
14
14
  // limitations under the License.
15
15
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
16
16
  if (k2 === undefined) k2 = k;
17
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
17
+ var desc = Object.getOwnPropertyDescriptor(m, k);
18
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
19
+ desc = { enumerable: true, get: function() { return m[k]; } };
20
+ }
21
+ Object.defineProperty(o, k2, desc);
18
22
  }) : (function(o, m, k, k2) {
19
23
  if (k2 === undefined) k2 = k;
20
24
  o[k2] = m[k];
21
25
  }));
22
26
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
23
- for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
27
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
24
28
  };
25
29
  Object.defineProperty(exports, "__esModule", { value: true });
26
30
  __exportStar(require("./defaultRoleManager"), exports);
@@ -488,6 +488,6 @@ class SyncedEnforcer extends enforcer_1.Enforcer {
488
488
  exports.SyncedEnforcer = SyncedEnforcer;
489
489
  // newSyncedEnforcer creates a synchronized enforcer via file or DB.
490
490
  async function newSyncedEnforcer(...params) {
491
- return enforcer_1.newEnforcerWithClass(SyncedEnforcer, ...params);
491
+ return (0, enforcer_1.newEnforcerWithClass)(SyncedEnforcer, ...params);
492
492
  }
493
493
  exports.newSyncedEnforcer = newSyncedEnforcer;
@@ -284,7 +284,7 @@ function globMatch(string, pattern) {
284
284
  if (pattern[0] === '*' && pattern[1] === '/') {
285
285
  pattern = pattern.substring(1);
286
286
  }
287
- return minimatch_1.minimatch(string, pattern);
287
+ return (0, minimatch_1.minimatch)(string, pattern);
288
288
  }
289
289
  exports.globMatch = globMatch;
290
290
  // generateGFunction is the factory method of the g(_, _) function.
@@ -14,13 +14,17 @@
14
14
  // limitations under the License.
15
15
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
16
16
  if (k2 === undefined) k2 = k;
17
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
17
+ var desc = Object.getOwnPropertyDescriptor(m, k);
18
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
19
+ desc = { enumerable: true, get: function() { return m[k]; } };
20
+ }
21
+ Object.defineProperty(o, k2, desc);
18
22
  }) : (function(o, m, k, k2) {
19
23
  if (k2 === undefined) k2 = k;
20
24
  o[k2] = m[k];
21
25
  }));
22
26
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
23
- for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
27
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
24
28
  };
25
29
  Object.defineProperty(exports, "__esModule", { value: true });
26
30
  __exportStar(require("./builtinOperators"), exports);
@@ -1,10 +1,10 @@
1
1
  import { Buffer } from 'buffer/';
2
2
  export declare const ip: {
3
- toBuffer: (ip: string, buff?: Buffer | undefined, offset?: number | undefined) => Buffer;
4
- toString: (buff: Buffer, offset?: number | undefined, length?: number | undefined) => string;
3
+ toBuffer: (ip: string, buff?: Buffer, offset?: number) => Buffer;
4
+ toString: (buff: Buffer, offset?: number, length?: number) => string;
5
5
  isV4Format: (ip: string) => boolean;
6
6
  isV6Format: (ip: string) => boolean;
7
- fromPrefixLen: (prefixlen: number, family?: string | undefined) => string;
7
+ fromPrefixLen: (prefixlen: number, family?: string) => string;
8
8
  mask: (addr: string, mask: string) => string;
9
9
  subnet: (addr: string, mask: string) => any;
10
10
  cidrSubnet: (cidrString: string) => any;
@@ -6,8 +6,8 @@ declare function arrayRemoveDuplicates(s: string[]): string[];
6
6
  declare function arrayToString(a: string[]): string;
7
7
  declare function paramsToString(...v: string[]): string;
8
8
  declare function setEquals(a: string[], b: string[]): boolean;
9
- declare function readFile(path: string, encoding?: string): any;
10
- declare function writeFile(path: string, file: string, encoding?: string): any;
9
+ declare function readFile(path: string, encoding?: string): Promise<string>;
10
+ declare function writeFile(path: string, file: string, encoding?: string): Promise<void>;
11
11
  declare function hasEval(s: string): boolean;
12
12
  declare function replaceEval(s: string, ruleName: string, rule: string): string;
13
13
  declare function getEvalValue(s: string): string[];
@@ -88,11 +88,11 @@ function setEquals(a, b) {
88
88
  exports.setEquals = setEquals;
89
89
  // readFile return a promise for readFile.
90
90
  function readFile(path, encoding) {
91
- const fs = persist_1.mustGetDefaultFileSystem();
91
+ const fs = (0, persist_1.mustGetDefaultFileSystem)();
92
92
  return new Promise((resolve, reject) => {
93
93
  try {
94
- fs.readFileSync(path, encoding || 'utf8');
95
- resolve();
94
+ const content = fs.readFileSync(path, encoding || 'utf8');
95
+ resolve(content);
96
96
  }
97
97
  catch (e) {
98
98
  reject(e);
@@ -102,7 +102,7 @@ function readFile(path, encoding) {
102
102
  exports.readFile = readFile;
103
103
  // writeFile return a promise for writeFile.
104
104
  function writeFile(path, file, encoding) {
105
- const fs = persist_1.mustGetDefaultFileSystem();
105
+ const fs = (0, persist_1.mustGetDefaultFileSystem)();
106
106
  return new Promise((resolve, reject) => {
107
107
  try {
108
108
  fs.writeFileSync(path, file, encoding || 'utf-8');
@@ -11,3 +11,4 @@
11
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
+ export {};
@@ -27,14 +27,14 @@ export class DefaultEffectorStream {
27
27
  }
28
28
  pushEffect(eft) {
29
29
  switch (this.expr) {
30
- case "some(where (p_eft == allow))" /* ALLOW */:
30
+ case "some(where (p_eft == allow))" /* EffectExpress.ALLOW */:
31
31
  if (eft === Effect.Allow) {
32
32
  this.res = true;
33
33
  this.done = true;
34
34
  this.rec = true;
35
35
  }
36
36
  break;
37
- case "!some(where (p_eft == deny))" /* DENY */:
37
+ case "!some(where (p_eft == deny))" /* EffectExpress.DENY */:
38
38
  this.res = true;
39
39
  if (eft === Effect.Deny) {
40
40
  this.res = false;
@@ -42,7 +42,7 @@ export class DefaultEffectorStream {
42
42
  this.rec = true;
43
43
  }
44
44
  break;
45
- case "some(where (p_eft == allow)) && !some(where (p_eft == deny))" /* ALLOW_AND_DENY */:
45
+ case "some(where (p_eft == allow)) && !some(where (p_eft == deny))" /* EffectExpress.ALLOW_AND_DENY */:
46
46
  if (eft === Effect.Allow) {
47
47
  this.res = true;
48
48
  this.rec = true;
@@ -56,8 +56,8 @@ export class DefaultEffectorStream {
56
56
  this.rec = false;
57
57
  }
58
58
  break;
59
- case "priority(p_eft) || deny" /* PRIORITY */:
60
- case "subjectPriority(p_eft) || deny" /* SUBJECT_PRIORITY */:
59
+ case "priority(p_eft) || deny" /* EffectExpress.PRIORITY */:
60
+ case "subjectPriority(p_eft) || deny" /* EffectExpress.SUBJECT_PRIORITY */:
61
61
  if (eft !== Effect.Indeterminate) {
62
62
  this.res = eft === Effect.Allow;
63
63
  this.done = true;
@@ -11,3 +11,4 @@
11
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
+ export {};
@@ -178,7 +178,7 @@ export class Enforcer extends ManagementEnforcer {
178
178
  throw new Error('user must not be empty');
179
179
  }
180
180
  if (domain === undefined) {
181
- const subIndex = this.getFieldIndex('p', "sub" /* Subject */);
181
+ const subIndex = this.getFieldIndex('p', "sub" /* FieldIndex.Subject */);
182
182
  return this.removeFilteredGroupingPolicy(subIndex, user);
183
183
  }
184
184
  else {
@@ -196,7 +196,7 @@ export class Enforcer extends ManagementEnforcer {
196
196
  if (!user) {
197
197
  throw new Error('user must not be empty');
198
198
  }
199
- const subIndex = this.getFieldIndex('p', "sub" /* Subject */);
199
+ const subIndex = this.getFieldIndex('p', "sub" /* FieldIndex.Subject */);
200
200
  const res1 = await this.removeFilteredGroupingPolicy(subIndex, user);
201
201
  const res2 = await this.removeFilteredPolicy(subIndex, user);
202
202
  return res1 || res2;
@@ -212,7 +212,7 @@ export class Enforcer extends ManagementEnforcer {
212
212
  if (!role) {
213
213
  throw new Error('role must not be empty');
214
214
  }
215
- const subIndex = this.getFieldIndex('p', "sub" /* Subject */);
215
+ const subIndex = this.getFieldIndex('p', "sub" /* FieldIndex.Subject */);
216
216
  const res1 = await this.removeFilteredGroupingPolicy(subIndex, role);
217
217
  const res2 = await this.removeFilteredPolicy(subIndex, role);
218
218
  return res1 || res2;
@@ -268,7 +268,7 @@ export class Enforcer extends ManagementEnforcer {
268
268
  if (!user) {
269
269
  throw new Error('user must not be empty');
270
270
  }
271
- const subIndex = this.getFieldIndex('p', "sub" /* Subject */);
271
+ const subIndex = this.getFieldIndex('p', "sub" /* FieldIndex.Subject */);
272
272
  return this.removeFilteredPolicy(subIndex, user);
273
273
  }
274
274
  /**
@@ -278,7 +278,7 @@ export class Enforcer extends ManagementEnforcer {
278
278
  * @return the permissions, a permission is usually like (obj, act). It is actually the rule without the subject.
279
279
  */
280
280
  async getPermissionsForUser(user) {
281
- const subIndex = this.getFieldIndex('p', "sub" /* Subject */);
281
+ const subIndex = this.getFieldIndex('p', "sub" /* FieldIndex.Subject */);
282
282
  return this.getFilteredPolicy(subIndex, user);
283
283
  }
284
284
  /**
@@ -35,4 +35,12 @@ export declare class InternalEnforcer extends CoreEnforcer {
35
35
  * set index of field
36
36
  */
37
37
  setFieldIndex(ptype: string, field: string, index: number): void;
38
+ protected addPolicyWithoutNotify(sec: string, ptype: string, rule: string[]): Promise<boolean>;
39
+ protected addPoliciesWithoutNotify(sec: string, ptype: string, rules: string[][]): Promise<boolean>;
40
+ protected addPoliciesWithoutNotifyEx(sec: string, ptype: string, rules: string[][]): Promise<boolean>;
41
+ protected updatePolicyWithoutNotify(sec: string, ptype: string, oldRule: string[], newRule: string[]): Promise<boolean>;
42
+ protected removePolicyWithoutNotify(sec: string, ptype: string, rule: string[]): Promise<boolean>;
43
+ protected removePoliciesWithoutNotify(sec: string, ptype: string, rules: string[][]): Promise<boolean>;
44
+ protected removeFilteredPolicyWithoutNotify(sec: string, ptype: string, fieldIndex: number, fieldValues: string[]): Promise<boolean>;
45
+ protected updatePoliciesWithoutNotify(sec: string, ptype: string, oldRules: string[][], newRules: string[][]): Promise<boolean>;
38
46
  }