casbin 5.48.0 → 5.50.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/README.md +23 -22
  2. package/lib/cjs/cachedEnforcer.js +1 -1
  3. package/lib/cjs/config.js +1 -1
  4. package/lib/cjs/coreEnforcer.js +25 -25
  5. package/lib/cjs/effect/defaultEffectorStream.js +5 -5
  6. package/lib/cjs/effect/index.js +6 -2
  7. package/lib/cjs/enforceContext.js +2 -1
  8. package/lib/cjs/enforcer.js +17 -13
  9. package/lib/cjs/frontend.js +2 -2
  10. package/lib/cjs/index.js +7 -3
  11. package/lib/cjs/internalEnforcer.js +7 -7
  12. package/lib/cjs/log/index.js +6 -2
  13. package/lib/cjs/model/assertion.js +7 -3
  14. package/lib/cjs/model/functionMap.d.ts +1 -1
  15. package/lib/cjs/model/functionMap.js +6 -2
  16. package/lib/cjs/model/index.js +6 -2
  17. package/lib/cjs/model/model.js +17 -13
  18. package/lib/cjs/persist/defaultFilteredAdapter.js +2 -3
  19. package/lib/cjs/persist/fileAdapter.js +18 -20
  20. package/lib/cjs/persist/fileSystem.d.ts +1 -1
  21. package/lib/cjs/persist/fileSystem.js +6 -3
  22. package/lib/cjs/persist/helper.js +1 -1
  23. package/lib/cjs/persist/index.js +6 -2
  24. package/lib/cjs/rbac/defaultRoleManager.d.ts +1 -1
  25. package/lib/cjs/rbac/defaultRoleManager.js +2 -2
  26. package/lib/cjs/rbac/index.js +6 -2
  27. package/lib/cjs/syncedEnforcer.js +1 -1
  28. package/lib/cjs/util/builtinOperators.js +1 -1
  29. package/lib/cjs/util/index.js +6 -2
  30. package/lib/cjs/util/ip.d.ts +3 -3
  31. package/lib/cjs/util/ip.js +20 -8
  32. package/lib/cjs/util/util.d.ts +2 -2
  33. package/lib/cjs/util/util.js +4 -4
  34. package/lib/esm/constants.js +1 -0
  35. package/lib/esm/effect/defaultEffectorStream.js +5 -5
  36. package/lib/esm/effect/effectorStream.js +1 -0
  37. package/lib/esm/enforcer.js +5 -5
  38. package/lib/esm/internalEnforcer.js +7 -7
  39. package/lib/esm/log/logger.js +1 -0
  40. package/lib/esm/model/functionMap.d.ts +1 -1
  41. package/lib/esm/model/model.js +6 -6
  42. package/lib/esm/persist/adapter.js +1 -0
  43. package/lib/esm/persist/batchAdapter.js +1 -0
  44. package/lib/esm/persist/defaultFilteredAdapter.js +1 -2
  45. package/lib/esm/persist/fileAdapter.js +16 -18
  46. package/lib/esm/persist/fileSystem.d.ts +1 -1
  47. package/lib/esm/persist/filteredAdapter.js +1 -0
  48. package/lib/esm/persist/updatableAdapter.js +1 -0
  49. package/lib/esm/persist/watcher.js +1 -0
  50. package/lib/esm/persist/watcherEx.js +1 -0
  51. package/lib/esm/rbac/defaultRoleManager.d.ts +1 -1
  52. package/lib/esm/rbac/roleManager.js +1 -0
  53. package/lib/esm/util/ip.d.ts +3 -3
  54. package/lib/esm/util/ip.js +20 -8
  55. package/lib/esm/util/util.d.ts +2 -2
  56. package/lib/esm/util/util.js +2 -2
  57. package/package.json +5 -6
  58. package/CHANGELOG.md +0 -812
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Node-Casbin
2
2
 
3
- [![GitHub Actions](https://github.com/casbin/node-casbin/workflows/main/badge.svg)](https://github.com/casbin/node-casbin/actions)
4
- [![Coverage Status](https://coveralls.io/repos/github/casbin/node-casbin/badge.svg?branch=master)](https://coveralls.io/github/casbin/node-casbin?branch=master)
5
- [![Release](https://img.shields.io/github/release/casbin/node-casbin.svg)](https://github.com/casbin/node-casbin/releases/latest)
3
+ [![GitHub Actions](https://github.com/apache/casbin-node-casbin/workflows/main/badge.svg)](https://github.com/apache/casbin-node-casbin/actions)
4
+ [![Coverage Status](https://codecov.io/gh/apache/casbin-node-casbin/branch/master/graph/badge.svg)](https://codecov.io/gh/apache/casbin-node-casbin)
5
+ [![Release](https://img.shields.io/github/release/apache/casbin-node-casbin.svg)](https://github.com/apache/casbin-node-casbin/releases/latest)
6
6
  [![NPM version][npm-image]][npm-url]
7
7
  [![NPM download][download-image]][download-url]
8
8
  [![install size](https://packagephobia.now.sh/badge?p=casbin)](https://packagephobia.now.sh/result?p=casbin)
@@ -13,7 +13,7 @@
13
13
  [download-image]: https://img.shields.io/npm/dm/casbin.svg?style=flat-square
14
14
  [download-url]: https://npmjs.org/package/casbin
15
15
 
16
- **News**: still worry about how to write the correct `node-casbin` policy? [Casbin online editor](http://casbin.org/editor) is coming to help!
16
+ **News**: still worry about how to write the correct `node-casbin` policy? [Casbin online editor](https://casbin.apache.org/editor) is coming to help!
17
17
 
18
18
  ![casbin Logo](casbin-logo.png)
19
19
 
@@ -21,19 +21,19 @@
21
21
 
22
22
  ## All the languages supported by Casbin:
23
23
 
24
- | [![golang](https://casbin.org/img/langs/golang.png)](https://github.com/casbin/casbin) | [![java](https://casbin.org/img/langs/java.png)](https://github.com/casbin/jcasbin) | [![nodejs](https://casbin.org/img/langs/nodejs.png)](https://github.com/casbin/node-casbin) | [![php](https://casbin.org/img/langs/php.png)](https://github.com/php-casbin/php-casbin) |
25
- | -------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
26
- | [Casbin](https://github.com/casbin/casbin) | [jCasbin](https://github.com/casbin/jcasbin) | [node-Casbin](https://github.com/casbin/node-casbin) | [PHP-Casbin](https://github.com/php-casbin/php-casbin) |
27
- | production-ready | production-ready | production-ready | production-ready |
24
+ | [![golang](https://casbin.apache.org/img/langs/golang.png)](https://github.com/casbin/casbin) | [![java](https://casbin.apache.org/img/langs/java.png)](https://github.com/casbin/jcasbin) | [![nodejs](https://casbin.apache.org/img/langs/nodejs.png)](https://github.com/apache/casbin-node-casbin) | [![php](https://casbin.apache.org/img/langs/php.png)](https://github.com/php-casbin/php-casbin) |
25
+ | --------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
26
+ | [Casbin](https://github.com/casbin/casbin) | [jCasbin](https://github.com/casbin/jcasbin) | [node-Casbin](https://github.com/apache/casbin-node-casbin) | [PHP-Casbin](https://github.com/php-casbin/php-casbin) |
27
+ | production-ready | production-ready | production-ready | production-ready |
28
28
 
29
- | [![python](https://casbin.org/img/langs/python.png)](https://github.com/casbin/pycasbin) | [![dotnet](https://casbin.org/img/langs/dotnet.png)](https://github.com/casbin-net/Casbin.NET) | [![c++](https://casbin.org/img/langs/cpp.png)](https://github.com/casbin/casbin-cpp) | [![rust](https://casbin.org/img/langs/rust.png)](https://github.com/casbin/casbin-rs) |
30
- | ---------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------- |
31
- | [PyCasbin](https://github.com/casbin/pycasbin) | [Casbin.NET](https://github.com/casbin-net/Casbin.NET) | [Casbin-CPP](https://github.com/casbin/casbin-cpp) | [Casbin-RS](https://github.com/casbin/casbin-rs) |
32
- | production-ready | production-ready | beta-test | production-ready |
29
+ | [![python](https://casbin.apache.org/img/langs/python.png)](https://github.com/casbin/pycasbin) | [![dotnet](https://casbin.apache.org/img/langs/dotnet.png)](https://github.com/casbin-net/Casbin.NET) | [![c++](https://casbin.apache.org/img/langs/cpp.png)](https://github.com/casbin/casbin-cpp) | [![rust](https://casbin.apache.org/img/langs/rust.png)](https://github.com/casbin/casbin-rs) |
30
+ | ----------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
31
+ | [PyCasbin](https://github.com/casbin/pycasbin) | [Casbin.NET](https://github.com/casbin-net/Casbin.NET) | [Casbin-CPP](https://github.com/casbin/casbin-cpp) | [Casbin-RS](https://github.com/casbin/casbin-rs) |
32
+ | production-ready | production-ready | beta-test | production-ready |
33
33
 
34
34
  ## Documentation
35
35
 
36
- https://casbin.org/docs/overview
36
+ https://casbin.apache.org/docs/overview
37
37
 
38
38
  ## Installation
39
39
 
@@ -92,33 +92,33 @@ See [Policy management APIs](#policy-management) for more usage.
92
92
 
93
93
  Casbin provides two sets of APIs to manage permissions:
94
94
 
95
- - [Management API](https://casbin.org/docs/management-api): the primitive API that provides full support for Casbin policy management.
96
- - [RBAC API](https://casbin.org/docs/rbac-api): a more friendly API for RBAC. This API is a subset of Management API. The RBAC users could use this API to simplify the code.
95
+ - [Management API](https://casbin.apache.org/docs/management-api): the primitive API that provides full support for Casbin policy management.
96
+ - [RBAC API](https://casbin.apache.org/docs/rbac-api): a more friendly API for RBAC. This API is a subset of Management API. The RBAC users could use this API to simplify the code.
97
97
 
98
98
  ## Official Model
99
99
 
100
- https://casbin.org/docs/supported-models
100
+ https://casbin.apache.org/docs/supported-models
101
101
 
102
102
  ## Policy persistence
103
103
 
104
- https://casbin.org/docs/adapters
104
+ https://casbin.apache.org/docs/adapters
105
105
 
106
106
  ## Policy consistence between multiple nodes
107
107
 
108
- https://casbin.org/docs/watchers
108
+ https://casbin.apache.org/docs/watchers
109
109
 
110
110
  ## Role manager
111
111
 
112
- https://casbin.org/docs/role-managers
112
+ https://casbin.apache.org/docs/role-managers
113
113
 
114
114
  ## Contributors
115
115
 
116
116
  This project exists thanks to all the people who contribute.
117
- <a href="https://github.com/casbin/node-casbin/graphs/contributors"><img src="https://opencollective.com/node-casbin/contributors.svg?width=890&button=false" /></a>
117
+ <a href="https://github.com/apache/casbin-node-casbin/graphs/contributors"><img src="https://opencollective.com/node-casbin/contributors.svg?width=890&button=false" /></a>
118
118
 
119
119
  ## Star History
120
120
 
121
- [![Star History Chart](https://api.star-history.com/svg?repos=casbin/node-casbin&type=Date)](https://star-history.com/#casbin/node-casbin&Date)
121
+ [![Star History Chart](https://api.star-history.com/svg?repos=apache/casbin-node-casbin&type=Date)](https://star-history.com/#apache/casbin-node-casbin&Date)
122
122
 
123
123
  ## License
124
124
 
@@ -127,5 +127,6 @@ This project is licensed under the [Apache 2.0 license](LICENSE).
127
127
  ## Contact
128
128
 
129
129
  If you have any issues or feature requests, please contact us. PR is welcomed.
130
- - https://github.com/casbin/node-casbin/issues
130
+
131
+ - https://github.com/apache/casbin-node-casbin/issues
131
132
  - https://discord.gg/S5UjpzGZjN
@@ -67,6 +67,6 @@ class CachedEnforcer extends enforcer_1.Enforcer {
67
67
  exports.CachedEnforcer = CachedEnforcer;
68
68
  // newCachedEnforcer creates a cached enforcer via file or DB.
69
69
  async function newCachedEnforcer(...params) {
70
- return enforcer_1.newEnforcerWithClass(CachedEnforcer, ...params);
70
+ return (0, enforcer_1.newEnforcerWithClass)(CachedEnforcer, ...params);
71
71
  }
72
72
  exports.newCachedEnforcer = newCachedEnforcer;
package/lib/cjs/config.js CHANGED
@@ -74,7 +74,7 @@ class Config {
74
74
  }
75
75
  }
76
76
  parse(path) {
77
- const body = (this.fs ? this.fs : persist_1.mustGetDefaultFileSystem()).readFileSync(path);
77
+ const body = (this.fs ? this.fs : (0, persist_1.mustGetDefaultFileSystem)()).readFileSync(path);
78
78
  this.parseBuffer(Buffer.isBuffer(body) ? body : Buffer.from(body));
79
79
  }
80
80
  parseBuffer(buf) {
@@ -53,11 +53,11 @@ class CoreEnforcer {
53
53
  }
54
54
  getExpression(asyncCompile, exp) {
55
55
  const matcherKey = `${asyncCompile ? 'ASYNC[' : 'SYNC['}${exp}]`;
56
- expression_eval_1.addBinaryOp('in', 1, util_1.customIn);
56
+ (0, expression_eval_1.addBinaryOp)('in', 1, util_1.customIn);
57
57
  let expression = this.matcherMap.get(matcherKey);
58
58
  if (!expression) {
59
- exp = util_1.bracketCompatible(exp);
60
- expression = asyncCompile ? expression_eval_1.compileAsync(exp) : expression_eval_1.compile(exp);
59
+ exp = (0, util_1.bracketCompatible)(exp);
60
+ expression = asyncCompile ? (0, expression_eval_1.compileAsync)(exp) : (0, expression_eval_1.compile)(exp);
61
61
  this.matcherMap.set(matcherKey, expression);
62
62
  }
63
63
  return expression;
@@ -68,7 +68,7 @@ class CoreEnforcer {
68
68
  * so the policy is invalidated and needs to be reloaded by calling LoadPolicy().
69
69
  */
70
70
  loadModel() {
71
- this.model = model_1.newModelFromFile(this.modelPath, this.fs);
71
+ this.model = (0, model_1.newModelFromFile)(this.modelPath, this.fs);
72
72
  this.model.printModel();
73
73
  }
74
74
  /**
@@ -276,7 +276,7 @@ class CoreEnforcer {
276
276
  * @param enable whether to enable Casbin's log.
277
277
  */
278
278
  enableLog(enable) {
279
- log_1.getLogger().enableLog(enable);
279
+ (0, log_1.getLogger)().enableLog(enable);
280
280
  }
281
281
  /**
282
282
  * enableAutoSave controls whether to save a policy rule automatically to
@@ -373,14 +373,14 @@ class CoreEnforcer {
373
373
  const astMap = this.model.model.get('g');
374
374
  astMap === null || astMap === void 0 ? void 0 : astMap.forEach((value, key) => {
375
375
  const rm = value.rm;
376
- functions[key] = asyncCompile ? util_1.generateGFunction(rm) : util_1.generateSyncedGFunction(rm);
376
+ functions[key] = asyncCompile ? (0, util_1.generateGFunction)(rm) : (0, util_1.generateSyncedGFunction)(rm);
377
377
  });
378
378
  let expString;
379
379
  if (!matcher) {
380
380
  expString = (_b = (_a = this.model.model.get('m')) === null || _a === void 0 ? void 0 : _a.get(enforceContext.mType)) === null || _b === void 0 ? void 0 : _b.value;
381
381
  }
382
382
  else {
383
- expString = util_1.removeComments(util_1.escapeAssertion(matcher));
383
+ expString = (0, util_1.removeComments)((0, util_1.escapeAssertion)(matcher));
384
384
  }
385
385
  if (!expString) {
386
386
  throw new Error('Unable to find matchers in model');
@@ -389,7 +389,7 @@ class CoreEnforcer {
389
389
  if (!effectExpr) {
390
390
  throw new Error('Unable to find policy_effect in model');
391
391
  }
392
- const HasEval = util_1.hasEval(expString);
392
+ const HasEval = (0, util_1.hasEval)(expString);
393
393
  let expression = undefined;
394
394
  const p = (_e = this.model.model.get('p')) === null || _e === void 0 ? void 0 : _e.get(enforceContext.pType);
395
395
  const policyLen = (_f = p === null || p === void 0 ? void 0 : p.policy) === null || _f === void 0 ? void 0 : _f.length;
@@ -422,12 +422,12 @@ class CoreEnforcer {
422
422
  parameters[token] = p === null || p === void 0 ? void 0 : p.policy[i][j];
423
423
  });
424
424
  if (HasEval) {
425
- const ruleNames = util_1.getEvalValue(expString);
425
+ const ruleNames = (0, util_1.getEvalValue)(expString);
426
426
  let expWithRule = expString;
427
427
  for (const ruleName of ruleNames) {
428
428
  if (ruleName in parameters) {
429
- const rule = util_1.escapeAssertion(parameters[ruleName]);
430
- expWithRule = util_1.replaceEval(expWithRule, ruleName, rule);
429
+ const rule = (0, util_1.escapeAssertion)(parameters[ruleName]);
430
+ expWithRule = (0, util_1.replaceEval)(expWithRule, ruleName, rule);
431
431
  }
432
432
  else {
433
433
  throw new Error(`${ruleName} not in ${parameters}`);
@@ -509,7 +509,7 @@ class CoreEnforcer {
509
509
  const res = effectStream.current();
510
510
  // only generate the request --> result string if the message
511
511
  // is going to be logged.
512
- if (log_1.getLogger().isEnable()) {
512
+ if ((0, log_1.getLogger)().isEnable()) {
513
513
  let reqStr = 'Request: ';
514
514
  for (let i = 0; i < rvals.length; i++) {
515
515
  if (i !== rvals.length - 1) {
@@ -520,7 +520,7 @@ class CoreEnforcer {
520
520
  }
521
521
  }
522
522
  reqStr += ` ---> ${res}`;
523
- log_1.logPrint(reqStr);
523
+ (0, log_1.logPrint)(reqStr);
524
524
  }
525
525
  if (explain) {
526
526
  if (explainIndex === -1) {
@@ -543,9 +543,9 @@ class CoreEnforcer {
543
543
  enforceSync(...rvals) {
544
544
  if (rvals[0] instanceof enforceContext_1.EnforceContext) {
545
545
  const enforceContext = rvals.shift();
546
- return util_1.generatorRunSync(this.privateEnforce(false, false, '', enforceContext, ...rvals));
546
+ return (0, util_1.generatorRunSync)(this.privateEnforce(false, false, '', enforceContext, ...rvals));
547
547
  }
548
- return util_1.generatorRunSync(this.privateEnforce(false, false, '', this.defaultEnforceContext, ...rvals));
548
+ return (0, util_1.generatorRunSync)(this.privateEnforce(false, false, '', this.defaultEnforceContext, ...rvals));
549
549
  }
550
550
  /**
551
551
  * If the matchers does not contain an asynchronous method, call it faster.
@@ -560,9 +560,9 @@ class CoreEnforcer {
560
560
  enforceExSync(...rvals) {
561
561
  if (rvals[0] instanceof enforceContext_1.EnforceContext) {
562
562
  const enforceContext = rvals.shift();
563
- return util_1.generatorRunSync(this.privateEnforce(false, true, '', enforceContext, ...rvals));
563
+ return (0, util_1.generatorRunSync)(this.privateEnforce(false, true, '', enforceContext, ...rvals));
564
564
  }
565
- return util_1.generatorRunSync(this.privateEnforce(false, true, '', this.defaultEnforceContext, ...rvals));
565
+ return (0, util_1.generatorRunSync)(this.privateEnforce(false, true, '', this.defaultEnforceContext, ...rvals));
566
566
  }
567
567
  /**
568
568
  * Same as enforceSync. To be removed.
@@ -581,9 +581,9 @@ class CoreEnforcer {
581
581
  async enforce(...rvals) {
582
582
  if (rvals[0] instanceof enforceContext_1.EnforceContext) {
583
583
  const enforceContext = rvals.shift();
584
- return util_1.generatorRunAsync(this.privateEnforce(true, false, '', enforceContext, ...rvals));
584
+ return (0, util_1.generatorRunAsync)(this.privateEnforce(true, false, '', enforceContext, ...rvals));
585
585
  }
586
- return util_1.generatorRunAsync(this.privateEnforce(true, false, '', this.defaultEnforceContext, ...rvals));
586
+ return (0, util_1.generatorRunAsync)(this.privateEnforce(true, false, '', this.defaultEnforceContext, ...rvals));
587
587
  }
588
588
  /**
589
589
  * enforceWithMatcher decides whether a "subject" can access a "object" with
@@ -598,9 +598,9 @@ class CoreEnforcer {
598
598
  async enforceWithMatcher(matcher, ...rvals) {
599
599
  if (rvals[0] instanceof enforceContext_1.EnforceContext) {
600
600
  const enforceContext = rvals.shift();
601
- return util_1.generatorRunAsync(this.privateEnforce(true, false, matcher, enforceContext, ...rvals));
601
+ return (0, util_1.generatorRunAsync)(this.privateEnforce(true, false, matcher, enforceContext, ...rvals));
602
602
  }
603
- return util_1.generatorRunAsync(this.privateEnforce(true, false, matcher, this.defaultEnforceContext, ...rvals));
603
+ return (0, util_1.generatorRunAsync)(this.privateEnforce(true, false, matcher, this.defaultEnforceContext, ...rvals));
604
604
  }
605
605
  /**
606
606
  * enforce decides whether a "subject" can access a "object" with
@@ -613,9 +613,9 @@ class CoreEnforcer {
613
613
  async enforceEx(...rvals) {
614
614
  if (rvals[0] instanceof enforceContext_1.EnforceContext) {
615
615
  const enforceContext = rvals.shift();
616
- return util_1.generatorRunAsync(this.privateEnforce(true, true, '', enforceContext, ...rvals));
616
+ return (0, util_1.generatorRunAsync)(this.privateEnforce(true, true, '', enforceContext, ...rvals));
617
617
  }
618
- return util_1.generatorRunAsync(this.privateEnforce(true, true, '', this.defaultEnforceContext, ...rvals));
618
+ return (0, util_1.generatorRunAsync)(this.privateEnforce(true, true, '', this.defaultEnforceContext, ...rvals));
619
619
  }
620
620
  /**
621
621
  * enforceExWithMatcher decides whether a "subject" can access a "object" with
@@ -630,9 +630,9 @@ class CoreEnforcer {
630
630
  async enforceExWithMatcher(matcher, ...rvals) {
631
631
  if (rvals[0] instanceof enforceContext_1.EnforceContext) {
632
632
  const enforceContext = rvals.shift();
633
- return util_1.generatorRunAsync(this.privateEnforce(true, true, matcher, enforceContext, ...rvals));
633
+ return (0, util_1.generatorRunAsync)(this.privateEnforce(true, true, matcher, enforceContext, ...rvals));
634
634
  }
635
- return util_1.generatorRunAsync(this.privateEnforce(true, true, matcher, this.defaultEnforceContext, ...rvals));
635
+ return (0, util_1.generatorRunAsync)(this.privateEnforce(true, true, matcher, this.defaultEnforceContext, ...rvals));
636
636
  }
637
637
  /**
638
638
  * batchEnforce enforces each request and returns result in a bool array.
@@ -30,14 +30,14 @@ class DefaultEffectorStream {
30
30
  }
31
31
  pushEffect(eft) {
32
32
  switch (this.expr) {
33
- case "some(where (p_eft == allow))" /* ALLOW */:
33
+ case "some(where (p_eft == allow))" /* EffectExpress.ALLOW */:
34
34
  if (eft === effector_1.Effect.Allow) {
35
35
  this.res = true;
36
36
  this.done = true;
37
37
  this.rec = true;
38
38
  }
39
39
  break;
40
- case "!some(where (p_eft == deny))" /* DENY */:
40
+ case "!some(where (p_eft == deny))" /* EffectExpress.DENY */:
41
41
  this.res = true;
42
42
  if (eft === effector_1.Effect.Deny) {
43
43
  this.res = false;
@@ -45,7 +45,7 @@ class DefaultEffectorStream {
45
45
  this.rec = true;
46
46
  }
47
47
  break;
48
- case "some(where (p_eft == allow)) && !some(where (p_eft == deny))" /* ALLOW_AND_DENY */:
48
+ case "some(where (p_eft == allow)) && !some(where (p_eft == deny))" /* EffectExpress.ALLOW_AND_DENY */:
49
49
  if (eft === effector_1.Effect.Allow) {
50
50
  this.res = true;
51
51
  this.rec = true;
@@ -59,8 +59,8 @@ class DefaultEffectorStream {
59
59
  this.rec = false;
60
60
  }
61
61
  break;
62
- case "priority(p_eft) || deny" /* PRIORITY */:
63
- case "subjectPriority(p_eft) || deny" /* SUBJECT_PRIORITY */:
62
+ case "priority(p_eft) || deny" /* EffectExpress.PRIORITY */:
63
+ case "subjectPriority(p_eft) || deny" /* EffectExpress.SUBJECT_PRIORITY */:
64
64
  if (eft !== effector_1.Effect.Indeterminate) {
65
65
  this.res = eft === effector_1.Effect.Allow;
66
66
  this.done = true;
@@ -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("./effector"), exports);
@@ -23,6 +23,7 @@ class EnforceContext {
23
23
  }
24
24
  }
25
25
  exports.EnforceContext = EnforceContext;
26
- exports.newEnforceContext = (index) => {
26
+ const newEnforceContext = (index) => {
27
27
  return new EnforceContext('r' + index, 'p' + index, 'e' + index, 'm' + index);
28
28
  };
29
+ exports.newEnforceContext = newEnforceContext;
@@ -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
  };
@@ -69,7 +73,7 @@ class Enforcer extends managementEnforcer_1.ManagementEnforcer {
69
73
  * @param lazyLoad whether to load policy at initial time
70
74
  */
71
75
  async initWithAdapter(modelPath, adapter, lazyLoad = false) {
72
- const m = model_1.newModelFromFile(modelPath, this.fs);
76
+ const m = (0, model_1.newModelFromFile)(modelPath, this.fs);
73
77
  await this.initWithModelAndAdapter(m, adapter, lazyLoad);
74
78
  this.modelPath = modelPath;
75
79
  }
@@ -200,7 +204,7 @@ class Enforcer extends managementEnforcer_1.ManagementEnforcer {
200
204
  throw new Error('user must not be empty');
201
205
  }
202
206
  if (domain === undefined) {
203
- const subIndex = this.getFieldIndex('p', "sub" /* Subject */);
207
+ const subIndex = this.getFieldIndex('p', "sub" /* FieldIndex.Subject */);
204
208
  return this.removeFilteredGroupingPolicy(subIndex, user);
205
209
  }
206
210
  else {
@@ -218,7 +222,7 @@ class Enforcer extends managementEnforcer_1.ManagementEnforcer {
218
222
  if (!user) {
219
223
  throw new Error('user must not be empty');
220
224
  }
221
- const subIndex = this.getFieldIndex('p', "sub" /* Subject */);
225
+ const subIndex = this.getFieldIndex('p', "sub" /* FieldIndex.Subject */);
222
226
  const res1 = await this.removeFilteredGroupingPolicy(subIndex, user);
223
227
  const res2 = await this.removeFilteredPolicy(subIndex, user);
224
228
  return res1 || res2;
@@ -234,7 +238,7 @@ class Enforcer extends managementEnforcer_1.ManagementEnforcer {
234
238
  if (!role) {
235
239
  throw new Error('role must not be empty');
236
240
  }
237
- const subIndex = this.getFieldIndex('p', "sub" /* Subject */);
241
+ const subIndex = this.getFieldIndex('p', "sub" /* FieldIndex.Subject */);
238
242
  const res1 = await this.removeFilteredGroupingPolicy(subIndex, role);
239
243
  const res2 = await this.removeFilteredPolicy(subIndex, role);
240
244
  return res1 || res2;
@@ -290,7 +294,7 @@ class Enforcer extends managementEnforcer_1.ManagementEnforcer {
290
294
  if (!user) {
291
295
  throw new Error('user must not be empty');
292
296
  }
293
- const subIndex = this.getFieldIndex('p', "sub" /* Subject */);
297
+ const subIndex = this.getFieldIndex('p', "sub" /* FieldIndex.Subject */);
294
298
  return this.removeFilteredPolicy(subIndex, user);
295
299
  }
296
300
  /**
@@ -300,7 +304,7 @@ class Enforcer extends managementEnforcer_1.ManagementEnforcer {
300
304
  * @return the permissions, a permission is usually like (obj, act). It is actually the rule without the subject.
301
305
  */
302
306
  async getPermissionsForUser(user) {
303
- const subIndex = this.getFieldIndex('p', "sub" /* Subject */);
307
+ const subIndex = this.getFieldIndex('p', "sub" /* FieldIndex.Subject */);
304
308
  return this.getFilteredPolicy(subIndex, user);
305
309
  }
306
310
  /**
@@ -468,7 +472,7 @@ class Enforcer extends managementEnforcer_1.ManagementEnforcer {
468
472
  async getImplicitUsersForPermission(...permission) {
469
473
  const res = [];
470
474
  const policySubjects = await this.getAllSubjects();
471
- const subjects = util_1.arrayRemoveDuplicates([...policySubjects, ...this.model.getValuesForFieldInPolicyAllTypes('g', 0)]);
475
+ const subjects = (0, util_1.arrayRemoveDuplicates)([...policySubjects, ...this.model.getValuesForFieldInPolicyAllTypes('g', 0)]);
472
476
  const inherits = this.model.getValuesForFieldInPolicyAllTypes('g', 1);
473
477
  for (const user of subjects) {
474
478
  const allowed = await this.enforce(user, ...permission);
@@ -498,14 +502,14 @@ class Enforcer extends managementEnforcer_1.ManagementEnforcer {
498
502
  const domain = await rm.getAllDomains();
499
503
  domains.push(...domain);
500
504
  }
501
- return util_1.arrayRemoveDuplicates(domains);
505
+ return (0, util_1.arrayRemoveDuplicates)(domains);
502
506
  }
503
507
  }
504
508
  exports.Enforcer = Enforcer;
505
509
  async function newEnforcerWithClass(enforcer, ...params) {
506
510
  var _a;
507
511
  // inject the FS
508
- if (!persist_1.getDefaultFileSystem()) {
512
+ if (!(0, persist_1.getDefaultFileSystem)()) {
509
513
  try {
510
514
  if (typeof process !== 'undefined' && ((_a = process === null || process === void 0 ? void 0 : process.versions) === null || _a === void 0 ? void 0 : _a.node)) {
511
515
  const fs = await Promise.resolve().then(() => __importStar(require('fs')));
@@ -517,7 +521,7 @@ async function newEnforcerWithClass(enforcer, ...params) {
517
521
  return fs.writeFileSync(path, text, encoding);
518
522
  },
519
523
  };
520
- persist_1.setDefaultFileSystem(defaultFileSystem);
524
+ (0, persist_1.setDefaultFileSystem)(defaultFileSystem);
521
525
  }
522
526
  }
523
527
  catch (ignored) { }
@@ -527,7 +531,7 @@ async function newEnforcerWithClass(enforcer, ...params) {
527
531
  if (params.length >= 1) {
528
532
  const enableLog = params[params.length - 1];
529
533
  if (typeof enableLog === 'boolean') {
530
- log_1.getLogger().enableLog(enableLog);
534
+ (0, log_1.getLogger)().enableLog(enableLog);
531
535
  parsedParamLen++;
532
536
  }
533
537
  }
@@ -40,8 +40,8 @@ async function casbinJsGetPermissionForUser(e, user) {
40
40
  s += '[matchers]\n';
41
41
  s += `m = ${(_l = (_k = m.get('m')) === null || _k === void 0 ? void 0 : _k.get('m')) === null || _l === void 0 ? void 0 : _l.value.replace(/_/g, '.')}`;
42
42
  obj['m'] = s;
43
- const policy = util_1.deepCopy(await e.getPolicy());
44
- const groupPolicy = util_1.deepCopy(await e.getGroupingPolicy());
43
+ const policy = (0, util_1.deepCopy)(await e.getPolicy());
44
+ const groupPolicy = (0, util_1.deepCopy)(await e.getGroupingPolicy());
45
45
  policy.forEach((item) => {
46
46
  item.unshift('p');
47
47
  });
package/lib/cjs/index.js CHANGED
@@ -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,12 +31,12 @@ 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
  };
34
38
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
35
- for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
39
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
36
40
  };
37
41
  Object.defineProperty(exports, "__esModule", { value: true });
38
42
  exports.Util = void 0;
@@ -33,7 +33,7 @@ class InternalEnforcer extends coreEnforcer_1.CoreEnforcer {
33
33
  await this.adapter.addPolicy(sec, ptype, rule);
34
34
  }
35
35
  catch (e) {
36
- if (e.message !== 'not implemented') {
36
+ if (e instanceof Error && e.message !== 'not implemented') {
37
37
  throw e;
38
38
  }
39
39
  }
@@ -70,7 +70,7 @@ class InternalEnforcer extends coreEnforcer_1.CoreEnforcer {
70
70
  await this.adapter.addPolicies(sec, ptype, rules);
71
71
  }
72
72
  catch (e) {
73
- if (e.message !== 'not implemented') {
73
+ if (e instanceof Error && e.message !== 'not implemented') {
74
74
  throw e;
75
75
  }
76
76
  }
@@ -115,7 +115,7 @@ class InternalEnforcer extends coreEnforcer_1.CoreEnforcer {
115
115
  await this.adapter.addPolicies(sec, ptype, newRules);
116
116
  }
117
117
  catch (e) {
118
- if (e.message !== 'not implemented') {
118
+ if (e instanceof Error && e.message !== 'not implemented') {
119
119
  throw e;
120
120
  }
121
121
  }
@@ -155,7 +155,7 @@ class InternalEnforcer extends coreEnforcer_1.CoreEnforcer {
155
155
  await this.adapter.updatePolicy(sec, ptype, oldRule, newRule);
156
156
  }
157
157
  catch (e) {
158
- if (e.message !== 'not implemented') {
158
+ if (e instanceof Error && e.message !== 'not implemented') {
159
159
  throw e;
160
160
  }
161
161
  }
@@ -193,7 +193,7 @@ class InternalEnforcer extends coreEnforcer_1.CoreEnforcer {
193
193
  await this.adapter.removePolicy(sec, ptype, rule);
194
194
  }
195
195
  catch (e) {
196
- if (e.message !== 'not implemented') {
196
+ if (e instanceof Error && e.message !== 'not implemented') {
197
197
  throw e;
198
198
  }
199
199
  }
@@ -229,7 +229,7 @@ class InternalEnforcer extends coreEnforcer_1.CoreEnforcer {
229
229
  await this.adapter.removePolicies(sec, ptype, rules);
230
230
  }
231
231
  catch (e) {
232
- if (e.message !== 'not implemented') {
232
+ if (e instanceof Error && e.message !== 'not implemented') {
233
233
  throw e;
234
234
  }
235
235
  }
@@ -265,7 +265,7 @@ class InternalEnforcer extends coreEnforcer_1.CoreEnforcer {
265
265
  await this.adapter.removeFilteredPolicy(sec, ptype, fieldIndex, ...fieldValues);
266
266
  }
267
267
  catch (e) {
268
- if (e.message !== 'not implemented') {
268
+ if (e instanceof Error && e.message !== 'not implemented') {
269
269
  throw e;
270
270
  }
271
271
  }
@@ -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("./defaultLogger"), 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
  };
@@ -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
  /**