casbin-basic-adapter
Advanced tools
Comparing version 0.1.0 to 1.0.0
@@ -6,7 +6,8 @@ import type { Adapter, Model } from 'casbin'; | ||
import type * as sqlite3 from 'sqlite3'; | ||
import type * as mssql from 'mssql'; | ||
import * as Knex from 'knex'; | ||
export declare type Config = Knex.Config & { | ||
export type Config = Knex.Knex.Config & { | ||
client: keyof Instance; | ||
}; | ||
export declare type Instance = { | ||
export type Instance = { | ||
pg: pg.Client; | ||
@@ -16,2 +17,3 @@ mysql: mysql.Connection; | ||
sqlite3: sqlite3.Database; | ||
mssql: mssql.ConnectionPool; | ||
}; | ||
@@ -18,0 +20,0 @@ export declare class BasicAdapter<T extends keyof Instance> implements Adapter { |
@@ -27,3 +27,2 @@ "use strict"; | ||
// import type * as oracledb from 'oracledb'; | ||
// import type * as mssql from 'mssql'; | ||
const casbin_1 = require("casbin"); | ||
@@ -34,4 +33,8 @@ const Knex = require("knex"); | ||
constructor(drive, client) { | ||
this.config = { client: drive, useNullAsDefault: drive === 'sqlite3' }; | ||
this.knex = Knex(this.config); | ||
this.config = { | ||
client: drive, | ||
useNullAsDefault: drive === 'sqlite3', | ||
log: { warn: () => { } }, | ||
}; | ||
this.knex = Knex.knex(this.config); | ||
this.drive = drive; | ||
@@ -162,2 +165,6 @@ this.client = client; | ||
} | ||
case 'mssql': { | ||
yield this.client.close(); | ||
break; | ||
} | ||
} | ||
@@ -235,2 +242,6 @@ }); | ||
} | ||
case 'mssql': { | ||
yield this.client.connect(); | ||
break; | ||
} | ||
} | ||
@@ -269,3 +280,9 @@ }); | ||
}); | ||
break; | ||
} | ||
case 'mssql': { | ||
result = (yield this.client.query(sql)) | ||
.recordset; | ||
break; | ||
} | ||
} | ||
@@ -272,0 +289,0 @@ return result !== null && result !== void 0 ? result : []; |
@@ -0,0 +0,0 @@ export interface CasbinRule { |
@@ -0,0 +0,0 @@ "use strict"; |
{ | ||
"name": "casbin-basic-adapter", | ||
"version": "0.1.0", | ||
"version": "1.0.0", | ||
"description": "A basic adapter supports pg, sqlite3, mysql, mysql2, oracledb and mssql", | ||
@@ -15,32 +15,33 @@ "main": "lib/adapter.js", | ||
"dependencies": { | ||
"knex": "^0.21.1" | ||
"knex": "^2.5.1" | ||
}, | ||
"devDependencies": { | ||
"@semantic-release/git": "^9.0.0", | ||
"@types/jest": "^26.0.0", | ||
"@types/mssql": "^6.0.2", | ||
"@types/mysql": "^2.15.14", | ||
"@semantic-release/git": "^10.0.1", | ||
"@types/jest": "^29.5.3", | ||
"@types/mssql": "^8.1.2", | ||
"@types/mysql": "^2.15.21", | ||
"@types/mysql2": "git+https://git@github.com/types/mysql2.git", | ||
"@types/node": "^14.0.13", | ||
"@types/oracledb": "^4.2.2", | ||
"@types/pg": "^7.14.3", | ||
"@types/sqlite3": "^3.1.6", | ||
"@typescript-eslint/eslint-plugin": "^3.4.0", | ||
"@typescript-eslint/parser": "^3.4.0", | ||
"casbin": "^5.1.2", | ||
"eslint": "^7.3.1", | ||
"eslint-config-prettier": "^6.11.0", | ||
"jest": "^26.1.0", | ||
"mssql": "^6.2.0", | ||
"@types/node": "^20.5.0", | ||
"@types/oracledb": "^5.3.0", | ||
"@types/pg": "^8.10.2", | ||
"@types/sqlite3": "^3.1.8", | ||
"@typescript-eslint/eslint-plugin": "^6.4.0", | ||
"@typescript-eslint/parser": "^6.4.0", | ||
"casbin": "^5.26.2", | ||
"eslint": "^8.47.0", | ||
"eslint-config-prettier": "^9.0.0", | ||
"eslint-plugin-prettier": "^5.0.0", | ||
"jest": "^29.6.2", | ||
"mssql": "^9.1.3", | ||
"mysql": "^2.18.1", | ||
"mysql2": "^2.1.0", | ||
"oracledb": "^5.0.0", | ||
"pg": "^8.2.1", | ||
"prettier": "^2.0.5", | ||
"rimraf": "^3.0.2", | ||
"semantic-release": "^17.1.1", | ||
"sqlite3": "^5.0.0", | ||
"ts-jest": "^26.1.1", | ||
"ts-node": "^8.10.2", | ||
"typescript": "^3.9.6" | ||
"mysql2": "^3.6.0", | ||
"oracledb": "^6.0.3", | ||
"pg": "^8.11.2", | ||
"prettier": "^3.0.1", | ||
"rimraf": "^5.0.1", | ||
"semantic-release": "^21.0.7", | ||
"sqlite3": "^5.1.6", | ||
"ts-jest": "^29.1.1", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^5.1.6" | ||
}, | ||
@@ -56,3 +57,2 @@ "peerDependencies": { | ||
"jest": { | ||
"testURL": "http://localhost", | ||
"transform": { | ||
@@ -62,4 +62,7 @@ "^.+\\.(ts|tsx)$": "ts-jest" | ||
"testMatch": [ | ||
"**/test/*.+(ts|tsx)" | ||
"**/test/*test.+(ts|tsx)" | ||
], | ||
"testEnvironmentOptions": { | ||
"url": "http://localhost" | ||
}, | ||
"moduleFileExtensions": [ | ||
@@ -66,0 +69,0 @@ "ts", |
# Basic Adapter | ||
[![ci](https://github.com/node-casbin/basic-adapter/actions/workflows/ci.yml/badge.svg)](https://github.com/node-casbin/basic-adapter/actions/workflows/ci.yml) | ||
[![NPM version][npm-image]][npm-url] | ||
[![NPM download][download-image]][download-url] | ||
[![Build Status][ci-image]][ci-url] | ||
@@ -11,10 +11,8 @@ [npm-image]: https://img.shields.io/npm/v/casbin-basic-adapter.svg | ||
[download-url]: https://npmjs.org/package/casbin-basic-adapter | ||
[ci-image]: https://github.com/node-casbin/basic-adapter/workflows/ci/badge.svg?branch=master | ||
[ci-url]: https://github.com/node-casbin/basic-adapter/actions | ||
Basic Adapter is a basic drives adapter for `Node-Casbin` supports `pg`, `sqlite3`, `mysql`, `mysql2`, `oracledb` and `mssql`. With this library, `Node-Casbin` can load policy from supported drives or save policy to it. | ||
Basic Adapter is a basic driver adapter for `Node-Casbin` which supports `pg`, `sqlite3`, `mysql`, `mysql2`, and `mssql`. With this library, `Node-Casbin` can load policy from or save policy to supported persistence systems. | ||
## Drives | ||
we currently supports the following SQL drives: | ||
We currently support the following SQL systems: | ||
@@ -26,3 +24,3 @@ - [x] pg | ||
- [ ] oracledb | ||
- [ ] mssql | ||
- [x] mssql | ||
@@ -29,0 +27,0 @@ ## Installation |
@@ -26,5 +26,5 @@ // Copyright 2020 The Casbin Authors. All Rights Reserved. | ||
database: 'casbin', | ||
}) | ||
}), | ||
), | ||
60 * 1000 | ||
60 * 1000, | ||
); |
@@ -26,5 +26,5 @@ // Copyright 2020 The Casbin Authors. All Rights Reserved. | ||
database: 'casbin', | ||
}) | ||
}), | ||
), | ||
60 * 1000 | ||
60 * 1000, | ||
); |
@@ -26,5 +26,5 @@ // Copyright 2020 The Casbin Authors. All Rights Reserved. | ||
password: 'postgres', | ||
}) | ||
}), | ||
), | ||
60 * 1000 | ||
60 * 1000, | ||
); |
@@ -31,3 +31,3 @@ // Copyright 2020 The Casbin Authors. All Rights Reserved. | ||
e: Enforcer, | ||
res: string[][] | ||
res: string[][], | ||
): Promise<void> { | ||
@@ -40,3 +40,3 @@ const myRes = await e.getGroupingPolicy(); | ||
drive: T, | ||
client: Instance[T] | ||
client: Instance[T], | ||
) { | ||
@@ -51,3 +51,3 @@ return async function (): Promise<void> { | ||
'examples/rbac_model.conf', | ||
'examples/rbac_policy.csv' | ||
'examples/rbac_policy.csv', | ||
); | ||
@@ -54,0 +54,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
38256
16
605
1
28
69
1
+ Addedcasbin@5.36.0(transitive)
+ Addedcolorette@2.0.19(transitive)
+ Addedcommander@10.0.1(transitive)
+ Addeddebug@4.3.4(transitive)
+ Addedescalade@3.2.0(transitive)
+ Addedget-package-type@0.1.0(transitive)
+ Addedgetopts@2.3.0(transitive)
+ Addedknex@2.5.1(transitive)
+ Addedpg-connection-string@2.6.1(transitive)
+ Addedrechoir@0.8.0(transitive)
+ Addedresolve-from@5.0.0(transitive)
- Removedarr-diff@4.0.0(transitive)
- Removedarr-flatten@1.1.0(transitive)
- Removedarr-union@3.1.0(transitive)
- Removedarray-each@1.0.1(transitive)
- Removedarray-slice@1.1.0(transitive)
- Removedarray-unique@0.3.2(transitive)
- Removedassign-symbols@1.0.0(transitive)
- Removedatob@2.1.2(transitive)
- Removedbase@0.11.2(transitive)
- Removedbraces@2.3.2(transitive)
- Removedcache-base@1.0.1(transitive)
- Removedcasbin@5.35.0(transitive)
- Removedclass-utils@0.3.6(transitive)
- Removedcollection-visit@1.0.0(transitive)
- Removedcolorette@1.2.1(transitive)
- Removedcommander@6.2.1(transitive)
- Removedcomponent-emitter@1.3.1(transitive)
- Removedcopy-descriptor@0.1.1(transitive)
- Removeddebug@2.6.94.3.1(transitive)
- Removeddecode-uri-component@0.2.2(transitive)
- Removeddefine-property@0.2.51.0.02.0.2(transitive)
- Removeddetect-file@1.0.0(transitive)
- Removedexpand-brackets@2.1.4(transitive)
- Removedexpand-tilde@2.0.2(transitive)
- Removedextend@3.0.2(transitive)
- Removedextend-shallow@2.0.13.0.2(transitive)
- Removedextglob@2.0.4(transitive)
- Removedfill-range@4.0.0(transitive)
- Removedfindup-sync@3.0.0(transitive)
- Removedfined@1.2.0(transitive)
- Removedflagged-respawn@1.0.1(transitive)
- Removedfor-in@1.0.2(transitive)
- Removedfor-own@1.0.0(transitive)
- Removedfragment-cache@0.2.1(transitive)
- Removedget-value@2.0.6(transitive)
- Removedgetopts@2.2.5(transitive)
- Removedglobal-modules@1.0.0(transitive)
- Removedglobal-prefix@1.0.2(transitive)
- Removedhas-value@0.3.11.0.0(transitive)
- Removedhas-values@0.1.41.0.0(transitive)
- Removedhomedir-polyfill@1.0.3(transitive)
- Removedini@1.3.8(transitive)
- Removedis-absolute@1.0.0(transitive)
- Removedis-accessor-descriptor@1.0.1(transitive)
- Removedis-buffer@1.1.6(transitive)
- Removedis-data-descriptor@1.0.1(transitive)
- Removedis-descriptor@0.1.71.0.3(transitive)
- Removedis-extendable@0.1.11.0.1(transitive)
- Removedis-extglob@2.1.1(transitive)
- Removedis-glob@4.0.3(transitive)
- Removedis-number@3.0.0(transitive)
- Removedis-plain-object@2.0.4(transitive)
- Removedis-relative@1.0.0(transitive)
- Removedis-unc-path@1.0.0(transitive)
- Removedis-windows@1.0.2(transitive)
- Removedisarray@1.0.0(transitive)
- Removedisexe@2.0.0(transitive)
- Removedisobject@2.1.03.0.1(transitive)
- Removedkind-of@3.2.24.0.06.0.3(transitive)
- Removedknex@0.21.21(transitive)
- Removedliftoff@3.1.0(transitive)
- Removedmake-iterator@1.0.1(transitive)
- Removedmap-cache@0.2.2(transitive)
- Removedmap-visit@1.0.0(transitive)
- Removedmicromatch@3.1.10(transitive)
- Removedmixin-deep@1.3.2(transitive)
- Removedms@2.0.0(transitive)
- Removednanomatch@1.2.13(transitive)
- Removedobject-copy@0.1.0(transitive)
- Removedobject-visit@1.0.1(transitive)
- Removedobject.defaults@1.1.0(transitive)
- Removedobject.map@1.0.1(transitive)
- Removedobject.pick@1.3.0(transitive)
- Removedparse-filepath@1.0.2(transitive)
- Removedparse-passwd@1.0.0(transitive)
- Removedpascalcase@0.1.1(transitive)
- Removedpath-root@0.1.1(transitive)
- Removedpath-root-regex@0.1.2(transitive)
- Removedpg-connection-string@2.4.0(transitive)
- Removedposix-character-classes@0.1.1(transitive)
- Removedrechoir@0.6.2(transitive)
- Removedregex-not@1.0.2(transitive)
- Removedrepeat-element@1.1.4(transitive)
- Removedrepeat-string@1.6.1(transitive)
- Removedresolve-dir@1.0.1(transitive)
- Removedresolve-url@0.2.1(transitive)
- Removedret@0.1.15(transitive)
- Removedsafe-regex@1.1.0(transitive)
- Removedset-value@2.0.1(transitive)
- Removedsnapdragon@0.8.2(transitive)
- Removedsnapdragon-node@2.1.1(transitive)
- Removedsnapdragon-util@3.0.1(transitive)
- Removedsource-map@0.5.7(transitive)
- Removedsource-map-resolve@0.5.3(transitive)
- Removedsource-map-url@0.4.1(transitive)
- Removedsplit-string@3.1.0(transitive)
- Removedstatic-extend@0.1.2(transitive)
- Removedto-object-path@0.3.0(transitive)
- Removedto-regex@3.0.2(transitive)
- Removedto-regex-range@2.1.1(transitive)
- Removedunc-path-regex@0.1.2(transitive)
- Removedunion-value@1.0.1(transitive)
- Removedunset-value@1.0.0(transitive)
- Removedurix@0.1.0(transitive)
- Removeduse@3.1.1(transitive)
- Removedv8flags@3.2.0(transitive)
- Removedwhich@1.3.1(transitive)
Updatedknex@^2.5.1