casbin 5.24.0 → 5.24.2

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 CHANGED
@@ -1,3 +1,17 @@
1
+ ## [5.24.2](https://github.com/casbin/node-casbin/compare/v5.24.1...v5.24.2) (2023-02-24)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * using import() to load the fs ([#435](https://github.com/casbin/node-casbin/issues/435)) ([e90a8bf](https://github.com/casbin/node-casbin/commit/e90a8bf064963dd448cfa67da5af0f9aad957999))
7
+
8
+ ## [5.24.1](https://github.com/casbin/node-casbin/compare/v5.24.0...v5.24.1) (2023-02-17)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * remove lodash usage and types ([#432](https://github.com/casbin/node-casbin/issues/432)) ([9c227d5](https://github.com/casbin/node-casbin/commit/9c227d51ef3feb6f6a3d30705d2784921d85dece))
14
+
1
15
  # [5.24.0](https://github.com/casbin/node-casbin/compare/v5.23.2...v5.24.0) (2023-02-17)
2
16
 
3
17
 
@@ -12,6 +12,25 @@
12
12
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  // See the License for the specific language governing permissions and
14
14
  // limitations under the License.
15
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
18
+ }) : (function(o, m, k, k2) {
19
+ if (k2 === undefined) k2 = k;
20
+ o[k2] = m[k];
21
+ }));
22
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
23
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
24
+ }) : function(o, v) {
25
+ o["default"] = v;
26
+ });
27
+ var __importStar = (this && this.__importStar) || function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
15
34
  Object.defineProperty(exports, "__esModule", { value: true });
16
35
  exports.newEnforcer = exports.newEnforcerWithClass = exports.Enforcer = void 0;
17
36
  const managementEnforcer_1 = require("./managementEnforcer");
@@ -438,6 +457,25 @@ class Enforcer extends managementEnforcer_1.ManagementEnforcer {
438
457
  }
439
458
  exports.Enforcer = Enforcer;
440
459
  async function newEnforcerWithClass(enforcer, ...params) {
460
+ var _a;
461
+ // inject the FS
462
+ if (!persist_1.getDefaultFileSystem()) {
463
+ try {
464
+ if (typeof process !== 'undefined' && ((_a = process === null || process === void 0 ? void 0 : process.versions) === null || _a === void 0 ? void 0 : _a.node)) {
465
+ const fs = await Promise.resolve().then(() => __importStar(require('fs')));
466
+ const defaultFileSystem = {
467
+ readFileSync(path, encoding) {
468
+ return fs.readFileSync(path, { encoding });
469
+ },
470
+ writeFileSync(path, text, encoding) {
471
+ return fs.writeFileSync(path, text, encoding);
472
+ },
473
+ };
474
+ persist_1.setDefaultFileSystem(defaultFileSystem);
475
+ }
476
+ }
477
+ catch (ignored) { }
478
+ }
441
479
  const e = new enforcer();
442
480
  let parsedParamLen = 0;
443
481
  if (params.length >= 1) {
@@ -14,7 +14,6 @@
14
14
  // limitations under the License.
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
16
  exports.casbinJsGetPermissionForUser = void 0;
17
- const lodash_1 = require("lodash");
18
17
  const util_1 = require("./util");
19
18
  /**
20
19
  * Experiment!
@@ -49,7 +48,7 @@ async function casbinJsGetPermissionForUser(e, user) {
49
48
  groupPolicy.forEach((item) => {
50
49
  item.unshift('g');
51
50
  });
52
- obj['p'] = lodash_1.concat(policy, groupPolicy);
51
+ obj['p'] = [...policy, ...groupPolicy];
53
52
  return JSON.stringify(obj);
54
53
  }
55
54
  exports.casbinJsGetPermissionForUser = casbinJsGetPermissionForUser;
package/lib/cjs/index.js CHANGED
@@ -34,12 +34,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
34
34
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
35
35
  for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
36
36
  };
37
- var _a;
38
37
  Object.defineProperty(exports, "__esModule", { value: true });
39
38
  exports.Util = void 0;
40
39
  const Util = __importStar(require("./util"));
41
40
  exports.Util = Util;
42
- const persist_1 = require("./persist");
43
41
  __exportStar(require("./config"), exports);
44
42
  __exportStar(require("./enforcer"), exports);
45
43
  __exportStar(require("./cachedEnforcer"), exports);
@@ -50,16 +48,3 @@ __exportStar(require("./persist"), exports);
50
48
  __exportStar(require("./rbac"), exports);
51
49
  __exportStar(require("./log"), exports);
52
50
  __exportStar(require("./frontend"), exports);
53
- if (typeof process !== 'undefined' && ((_a = process === null || process === void 0 ? void 0 : process.versions) === null || _a === void 0 ? void 0 : _a.node)) {
54
- const requireFunc = typeof __non_webpack_require__ === 'function' ? __non_webpack_require__ : require;
55
- const fs = requireFunc('fs');
56
- const defaultFileSystem = {
57
- readFileSync(path, encoding) {
58
- return fs.readFileSync(path, { encoding });
59
- },
60
- writeFileSync(path, text, encoding) {
61
- return fs.writeFileSync(path, text, encoding);
62
- },
63
- };
64
- persist_1.setDefaultFileSystem(defaultFileSystem);
65
- }
@@ -13,7 +13,7 @@
13
13
  // limitations under the License.
14
14
  import { ManagementEnforcer } from './managementEnforcer';
15
15
  import { newModelFromFile } from './model';
16
- import { FileAdapter, StringAdapter } from './persist';
16
+ import { FileAdapter, getDefaultFileSystem, setDefaultFileSystem, StringAdapter } from './persist';
17
17
  import { getLogger } from './log';
18
18
  import { arrayRemoveDuplicates } from './util';
19
19
  /**
@@ -434,6 +434,25 @@ export class Enforcer extends ManagementEnforcer {
434
434
  }
435
435
  }
436
436
  export async function newEnforcerWithClass(enforcer, ...params) {
437
+ var _a;
438
+ // inject the FS
439
+ if (!getDefaultFileSystem()) {
440
+ try {
441
+ if (typeof process !== 'undefined' && ((_a = process === null || process === void 0 ? void 0 : process.versions) === null || _a === void 0 ? void 0 : _a.node)) {
442
+ const fs = await import('fs');
443
+ const defaultFileSystem = {
444
+ readFileSync(path, encoding) {
445
+ return fs.readFileSync(path, { encoding });
446
+ },
447
+ writeFileSync(path, text, encoding) {
448
+ return fs.writeFileSync(path, text, encoding);
449
+ },
450
+ };
451
+ setDefaultFileSystem(defaultFileSystem);
452
+ }
453
+ }
454
+ catch (ignored) { }
455
+ }
437
456
  const e = new enforcer();
438
457
  let parsedParamLen = 0;
439
458
  if (params.length >= 1) {
@@ -11,7 +11,6 @@
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
- import { concat } from 'lodash';
15
14
  import { deepCopy } from './util';
16
15
  /**
17
16
  * Experiment!
@@ -46,6 +45,6 @@ export async function casbinJsGetPermissionForUser(e, user) {
46
45
  groupPolicy.forEach((item) => {
47
46
  item.unshift('g');
48
47
  });
49
- obj['p'] = concat(policy, groupPolicy);
48
+ obj['p'] = [...policy, ...groupPolicy];
50
49
  return JSON.stringify(obj);
51
50
  }
package/lib/esm/index.js CHANGED
@@ -11,9 +11,7 @@
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
- var _a;
15
14
  import * as Util from './util';
16
- import { setDefaultFileSystem } from './persist';
17
15
  export * from './config';
18
16
  export * from './enforcer';
19
17
  export * from './cachedEnforcer';
@@ -25,16 +23,3 @@ export * from './rbac';
25
23
  export * from './log';
26
24
  export * from './frontend';
27
25
  export { Util };
28
- if (typeof process !== 'undefined' && ((_a = process === null || process === void 0 ? void 0 : process.versions) === null || _a === void 0 ? void 0 : _a.node)) {
29
- const requireFunc = typeof __non_webpack_require__ === 'function' ? __non_webpack_require__ : require;
30
- const fs = requireFunc('fs');
31
- const defaultFileSystem = {
32
- readFileSync(path, encoding) {
33
- return fs.readFileSync(path, { encoding });
34
- },
35
- writeFileSync(path, text, encoding) {
36
- return fs.writeFileSync(path, text, encoding);
37
- },
38
- };
39
- setDefaultFileSystem(defaultFileSystem);
40
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "casbin",
3
- "version": "5.24.0",
3
+ "version": "5.24.2",
4
4
  "description": "An authorization library that supports access control models like ACL, RBAC, ABAC in Node.JS",
5
5
  "main": "lib/cjs/index.js",
6
6
  "typings": "lib/cjs/index.d.ts",
@@ -27,7 +27,6 @@
27
27
  "@semantic-release/npm": "^7.1.3",
28
28
  "@semantic-release/release-notes-generator": "^9.0.3",
29
29
  "@types/jest": "^26.0.20",
30
- "@types/lodash": "^4.14.168",
31
30
  "@types/node": "^10.5.3",
32
31
  "@types/picomatch": "^2.2.2",
33
32
  "@typescript-eslint/eslint-plugin": "^4.17.0",