Skip to content

Commit 9dfa7c8

Browse files
committed
feat: Update typescript to v5, use eslint, fix ObjectId issue, fix dependency lock
1 parent 0f51e24 commit 9dfa7c8

13 files changed

+4988
-4435
lines changed

.eslintrc.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module.exports = {
2+
root: true,
3+
parser: '@typescript-eslint/parser',
4+
plugins: ['@typescript-eslint'],
5+
extends: [
6+
'eslint:recommended',
7+
'plugin:@typescript-eslint/recommended',
8+
],
9+
env: {
10+
node: true,
11+
},
12+
rules: {
13+
'max-classes-per-file': 'off',
14+
'@typescript-eslint/no-empty-interface': 'off',
15+
'no-console': 'off',
16+
'arrow-parens': 'off',
17+
'ordered-imports': 'off',
18+
'object-literal-sort-keys': 'off',
19+
'no-empty': 'off',
20+
'quotes': ['error', 'single'],
21+
'comma-dangle': 'off',
22+
'max-len': 'off',
23+
'@typescript-eslint/no-explicit-any': 'off',
24+
'@typescript-eslint/ban-ts-comment': 'off',
25+
},
26+
};

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
- name: Set up Node.js
3636
uses: actions/[email protected]
3737
with:
38-
node-version: ^14
38+
node-version: ^18
3939

4040
- name: Install Dependency
4141
run: yarn install
@@ -54,7 +54,7 @@ jobs:
5454
runs-on: ubuntu-latest
5555
strategy:
5656
matrix:
57-
node: [^16, ^17, ^18]
57+
node: [^16, ^18]
5858
steps:
5959
- uses: actions/checkout@v2
6060

package.json

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,32 @@
99
"prepublish": "yarn run lint && yarn build",
1010
"build": "rimraf lib && tsc",
1111
"coverage": "jest --coverage --runInBand",
12-
"lint": "tslint \"src/**/*.ts\"",
13-
"fix": "tslint \"src/**/*.ts\" --fix",
12+
"lint": "eslint src/**/*.{ts,tsx,js,jsx}",
13+
"fix": "eslint src/**/*.{ts,tsx,js,jsx} --fix",
1414
"test": "jest --runInBand",
1515
"release": "npx -p semantic-release -p @semantic-release/git -p @semantic-release/changelog semantic-release",
1616
"prepare": "npm run build"
1717
},
1818
"devDependencies": {
1919
"@types/jest": "^23.3.5",
20-
"@types/node": "^10.11.7",
20+
"@types/node": "^20.6.0",
21+
"@typescript-eslint/eslint-plugin": "^6.7.0",
22+
"@typescript-eslint/parser": "^6.7.0",
2123
"coveralls": "^3.0.2",
24+
"eslint": "^8.49.0",
2225
"husky": "^1.1.2",
2326
"jest": "^28.1.3",
2427
"lint-staged": "^7.3.0",
2528
"mysql2": "^2.1.0",
2629
"pg": "^8.4.2",
2730
"rimraf": "^2.6.2",
2831
"ts-jest": "28.0.7",
29-
"tslint": "^5.11.0",
30-
"typescript": "^4.7.3"
32+
"typescript": "^5.2.2"
3133
},
3234
"dependencies": {
33-
"casbin": "^5.11.5",
35+
"casbin": "^5.27.0",
3436
"reflect-metadata": "^0.1.13",
35-
"typeorm": "^0.3.6"
37+
"typeorm": "^0.3.17"
3638
},
3739
"files": [
3840
"lib",
@@ -68,13 +70,15 @@
6870
"url": "https://github.com/node-casbin/typeorm-adapter/issues"
6971
},
7072
"lint-staged": {
71-
"*.{ts,js}": [
72-
"tslint --fix",
73+
"*.{ts,tsx,js,jsx}": [
74+
"eslint --fix",
7375
"git add"
7476
]
7577
},
7678
"jest": {
77-
"testURL": "http://localhost",
79+
"testEnvironmentOptions": {
80+
"url": "http://localhost"
81+
},
7882
"transform": {
7983
"^.+\\.(ts|tsx)$": "ts-jest"
8084
},

src/adapter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,9 @@ export default class TypeORMAdapter implements FilteredAdapter {
359359

360360
/**
361361
* Returns either a {@link CasbinRule} or a {@link CasbinMongoRule}, depending on the type. If passed a custom entity through the adapter config it will use that entity type.
362-
* This switch is required as the normal {@link CasbinRule} does not work when using MongoDB as a backend (due to a missing ObjectID field).
362+
* This switch is required as the normal {@link CasbinRule} does not work when using MongoDB as a backend (due to a missing ObjectId field).
363363
* @param type
364+
* @param adapterConfig
364365
*/
365366
private static getCasbinRuleType(
366367
type: string,

src/casbinMongoRule.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import { BaseEntity, Column, Entity, ObjectID, ObjectIdColumn } from 'typeorm';
15+
import { BaseEntity, Column, Entity, ObjectId, ObjectIdColumn } from 'typeorm';
1616

1717
@Entity()
1818
export class CasbinMongoRule extends BaseEntity {
1919
@ObjectIdColumn()
20-
public id!: ObjectID;
20+
public id!: ObjectId;
2121

2222
@Column({
2323
nullable: true,

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'reflect-metadata';
12
export { TypeORMAdapterOptions } from './adapter';
23
export * from './casbinMongoRule';
34
export * from './casbinRule';

test/adapter-config.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import { Enforcer } from 'casbin';
15+
import {Enforcer, setDefaultFileSystem} from 'casbin';
1616
import {
1717
CreateDateColumn,
1818
DataSource,
@@ -22,6 +22,9 @@ import {
2222
import TypeORMAdapter, { CasbinRule } from '../src/index';
2323
import { connectionConfig } from './config';
2424

25+
import * as fs from 'fs';
26+
setDefaultFileSystem(fs as any);
27+
2528
@Entity('custom_rule')
2629
class CustomCasbinRule extends CasbinRule {
2730
@CreateDateColumn()

test/adapter-with-acl-model.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import { Enforcer, Util } from 'casbin';
15+
import {Enforcer, setDefaultFileSystem} from 'casbin';
1616
import TypeORMAdapter from '../src/index';
1717
import { connectionConfig } from './config';
1818

19+
import * as fs from 'fs';
20+
setDefaultFileSystem(fs as any);
21+
1922
test(
2023
'TestAdapter',
2124
async () => {

test/adapter-with-rbac-model.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import { Enforcer, Util } from 'casbin';
15+
import {Enforcer, setDefaultFileSystem} from 'casbin';
1616
import TypeORMAdapter from '../src/index';
1717
import { connectionConfig } from './config';
1818

19+
import * as fs from 'fs';
20+
setDefaultFileSystem(fs as any);
21+
1922
test(
2023
'TestAdapter',
2124
async () => {

test/existent-connection-adapter.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import { Enforcer, Util } from 'casbin';
15+
import {Enforcer, setDefaultFileSystem, Util} from 'casbin';
1616
import { DataSource } from 'typeorm';
1717
import TypeORMAdapter, { CasbinRule } from '../src/index';
1818
import { connectionConfig } from './config';
1919

20+
import * as fs from 'fs';
21+
setDefaultFileSystem(fs as any);
22+
2023
async function testGetPolicy(e: Enforcer, res: string[][]) {
2124
const myRes = await e.getPolicy();
2225

0 commit comments

Comments
 (0)