Skip to content

Commit

Permalink
Merge pull request #48 from anthrax63/feature/new-typeorm
Browse files Browse the repository at this point in the history
feat: update TypeORM version
  • Loading branch information
Zxilly authored Jun 15, 2022
2 parents 4fc9bd0 + b54f5e0 commit db31e4e
Show file tree
Hide file tree
Showing 6 changed files with 5,037 additions and 4,965 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
"rimraf": "^2.6.2",
"ts-jest": "22.4.6",
"tslint": "^5.11.0",
"typescript": "^3.1.3"
"typescript": "^4.7.3"
},
"dependencies": {
"casbin": "^5.11.5",
"typeorm": "^0.2.29"
"typeorm": "^0.3.6"
},
"files": [
"lib",
Expand Down Expand Up @@ -78,7 +78,7 @@
"^.+\\.(ts|tsx)$": "ts-jest"
},
"testMatch": [
"**/test/*.+(ts|tsx)"
"**/test/*.test.+(ts|tsx)"
],
"moduleFileExtensions": [
"ts",
Expand Down
8 changes: 6 additions & 2 deletions src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@ export default class TypeORMAdapter implements FilteredAdapter {
await getRepository(
this.getCasbinRuleConstructor(),
this.option.name,
).delete(line);
).delete({
...line,
});
}

/**
Expand Down Expand Up @@ -314,7 +316,9 @@ export default class TypeORMAdapter implements FilteredAdapter {
await getRepository(
this.getCasbinRuleConstructor(),
this.option.name,
).delete(line);
).delete({
...line,
});
}

private getCasbinRuleConstructor(): CasbinRuleConstructor {
Expand Down
11 changes: 2 additions & 9 deletions test/adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import { Enforcer, Util } from 'casbin';
import TypeORMAdapter from '../src/index';
import { connectionConfig } from './config';

async function testGetPolicy(e: Enforcer, res: string[][]) {
const myRes = await e.getPolicy();
Expand All @@ -31,15 +32,7 @@ async function testGetFilteredPolicy(e: Enforcer, res: string[]) {
test(
'TestAdapter',
async () => {
const a = await TypeORMAdapter.newAdapter({
type: 'mysql',
host: 'localhost',
port: 3306,
username: 'root',
password: 'password',
database: 'casbin',
dropSchema: true,
});
const a = await TypeORMAdapter.newAdapter(connectionConfig);
try {
// Because the DB is empty at first,
// so we need to load the policy from the file adapter (.CSV) first.
Expand Down
11 changes: 11 additions & 0 deletions test/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { DataSourceOptions } from 'typeorm';

export const connectionConfig: DataSourceOptions = {
type: 'mysql',
host: 'localhost',
port: parseInt(process.env.MYSQL_PORT, 10) || 3306,
username: process.env.MYSQL_USER || 'root',
password: process.env.MYSQL_PASSWORD !== undefined ? process.env.MYSQL_PASSWORD === '' ? undefined : process.env.MYSQL_PASSWORD : 'password',
database: process.env.MYSQL_DB || 'casbin',
dropSchema: true,
};
9 changes: 2 additions & 7 deletions test/existent-connection-adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import { Enforcer, Util } from 'casbin';
import { createConnection } from 'typeorm';
import TypeORMAdapter, { CasbinRule } from '../src/index';
import { connectionConfig } from './config';

async function testGetPolicy(e: Enforcer, res: string[][]) {
const myRes = await e.getPolicy();
Expand All @@ -33,15 +34,9 @@ test(
'TestAdapter',
async () => {
const connection = await createConnection({
type: 'mysql',
host: 'localhost',
port: 3306,
username: 'root',
password: 'password',
database: 'casbin',
...connectionConfig,
entities: [CasbinRule],
synchronize: true,
dropSchema: true,
});
const a = await TypeORMAdapter.newAdapter({ connection });
try {
Expand Down
Loading

0 comments on commit db31e4e

Please sign in to comment.