Skip to content

Commit

Permalink
feat: upgrade to Objection 3.x
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Major changes for both Knex and Objection. See their
changelogs for more info

Signed-off-by: Will Soto <willsoto@users.noreply.github.com>
  • Loading branch information
willsoto committed Oct 21, 2021
1 parent d089f0c commit 801b4df
Show file tree
Hide file tree
Showing 9 changed files with 2,295 additions and 5,660 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pnpm add @willsoto/casbin-objection-adapter
See [the Casbin adapters documentation](https://casbin.org/docs/en/adapters) for more information.

```js
import Knex from "knex";
import { Knex } from "knex";
import { newEnforcer } from "casbin";
import { ObjectionAdapter } from "@willsoto/casbin-objection-adapter";

Expand Down
7,879 changes: 2,258 additions & 5,621 deletions package-lock.json

Large diffs are not rendered by default.

52 changes: 26 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
"prebuild": "npm run clean",
"build": "tsc --project tsconfig.build.json",
"clean": "rimraf dist coverage .nyc_output",
"lint": "eslint . --ext ts,js --fix",
"lint": "eslint . --fix --ignore-path=.gitignore",
"prepare": "husky install",
"prerelease": "npm run build",
"release": "standard-version --sign",
"test": "mocha",
"pretest:cov": "rimraf coverage .nyc_output",
"test:cov": "nyc mocha",
"test:watch": "mocha --watch",
"prepare": "husky install"
"test:watch": "mocha --watch"
},
"commitlint": {
"extends": [
Expand Down Expand Up @@ -87,48 +87,48 @@
"statements": 85
},
"devDependencies": {
"@commitlint/cli": "~13.2.0",
"@commitlint/cli": "~13.2.1",
"@commitlint/config-conventional": "~13.2.0",
"@istanbuljs/nyc-config-typescript": "~1.0.1",
"@types/chai": "~4.2.17",
"@types/chai-as-promised": "~7.1.3",
"@types/chai": "~4.2.22",
"@types/chai-as-promised": "~7.1.4",
"@types/mocha": "~9.0.0",
"@types/node": "~16.11.0",
"@types/sinon": "~10.0.0",
"@types/node": "~16.11.2",
"@types/sinon": "~10.0.4",
"@types/sinon-chai": "~3.2.5",
"@typescript-eslint/eslint-plugin": "~4.33.0",
"@typescript-eslint/parser": "~4.33.0",
"casbin": "~5.11.0",
"@typescript-eslint/eslint-plugin": "~5.1.0",
"@typescript-eslint/parser": "~5.1.0",
"casbin": "~5.11.5",
"chai": "~4.3.4",
"chai-as-promised": "~7.1.1",
"eslint": "~7.32.0",
"eslint": "~8.0.1",
"eslint-config-prettier": "~8.3.0",
"eslint-plugin-mocha": "~9.0.0",
"husky": "~7.0.0",
"knex": "~0.21.5",
"lint-staged": "~11.2.0",
"husky": "~7.0.4",
"knex": "~0.95.11",
"lint-staged": "~11.2.3",
"markdown-toc": "~1.2.0",
"mocha": "~9.1.0",
"mocha": "~9.1.3",
"nyc": "~15.1.0",
"objection": "~2.2.3",
"prettier": "~2.4.0",
"prettier-plugin-organize-imports": "~2.3.3",
"prettier-plugin-packagejson": "~2.2.11",
"objection": "~3.0.0-alpha.5",
"prettier": "~2.4.1",
"prettier-plugin-organize-imports": "~2.3.4",
"prettier-plugin-packagejson": "~2.2.13",
"reflect-metadata": "~0.1.13",
"rimraf": "~3.0.2",
"rxjs": "~7.4.0",
"sinon": "~11.1.1",
"sinon": "~11.1.2",
"sinon-chai": "~3.7.0",
"source-map-support": "~0.5.19",
"source-map-support": "~0.5.20",
"sqlite3": "~5.0.2",
"standard-version": "~9.3.0",
"ts-node": "~10.3.0",
"typescript": "~4.4.2"
"standard-version": "~9.3.2",
"ts-node": "~10.3.1",
"typescript": "~4.4.4"
},
"peerDependencies": {
"casbin": "^5.4.2",
"knex": "^0.95.2",
"objection": "^2.2.14"
"objection": "^3.0.0"
},
"volta": {
"node": "14.16.0",
Expand Down
8 changes: 4 additions & 4 deletions src/adapter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-empty-function */
import { Adapter, Helper, Model } from "casbin";
import Knex from "knex";
import { Adapter, Assertion, Helper, Model } from "casbin";
import { Knex } from "knex";
import { CasbinRule } from "./model";
import { Logger, ObjectionAdapterOptions, Policy } from "./types";

Expand Down Expand Up @@ -99,8 +99,8 @@ export class ObjectionAdapter implements Adapter {

const policies: Policy[] = [];

const p = model.model.get("p") ?? new Map();
const g = model.model.get("g") ?? new Map();
const p = model.model.get("p") ?? new Map<string, Assertion>();
const g = model.model.get("g") ?? new Map<string, Assertion>();

for (const [ptype, ast] of p) {
for (const rule of ast.policy) {
Expand Down
2 changes: 1 addition & 1 deletion test/abac/adapter.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Enforcer, newEnforcer } from "casbin";
import { expect } from "chai";
import Knex from "knex";
import { Knex } from "knex";
import path from "path";
import { ObjectionAdapter } from "../../src";
import { makeAndConfigureDatabase } from "../utils";
Expand Down
2 changes: 1 addition & 1 deletion test/acl/adapter.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Enforcer, newEnforcer } from "casbin";
import { expect } from "chai";
import Knex from "knex";
import { Knex } from "knex";
import path from "path";
import { CasbinRule, ObjectionAdapter } from "../../src";
import { makeAndConfigureDatabase } from "../utils";
Expand Down
2 changes: 1 addition & 1 deletion test/adapter.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Enforcer, newEnforcer } from "casbin";
import { expect } from "chai";
import Knex from "knex";
import { Knex } from "knex";
import objection from "objection";
import path from "path";
import { CasbinRule, ObjectionAdapter } from "../src";
Expand Down
2 changes: 1 addition & 1 deletion test/rbac/adapter.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Enforcer, newEnforcer } from "casbin";
import { expect } from "chai";
import Knex from "knex";
import { Knex } from "knex";
import path from "path";
import { CasbinRule, ObjectionAdapter } from "../../src";
import { makeAndConfigureDatabase } from "../utils";
Expand Down
6 changes: 2 additions & 4 deletions test/utils.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import Knex from "knex";
import knex, { Knex } from "knex";
import path from "path";

export function makeAndConfigureDatabase(dirname: string): Knex {
const knex = Knex({
return knex({
client: "sqlite3",
useNullAsDefault: true,
asyncStackTraces: true,
connection: {
filename: path.join(dirname, "casbin.sqlite"),
},
});

return knex;
}

0 comments on commit 801b4df

Please sign in to comment.