Skip to content

Commit

Permalink
feat: Update typescript to v5, use eslint, fix ObjectId issue, fix de…
Browse files Browse the repository at this point in the history
…pendency lock
  • Loading branch information
hsluoyz committed Sep 14, 2023
1 parent 0f51e24 commit 7b02c6d
Show file tree
Hide file tree
Showing 8 changed files with 4,971 additions and 4,430 deletions.
26 changes: 26 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
],
env: {
node: true,
},
rules: {
'max-classes-per-file': 'off',
'@typescript-eslint/no-empty-interface': 'off',
'no-console': 'off',
'arrow-parens': 'off',
'ordered-imports': 'off',
'object-literal-sort-keys': 'off',
'no-empty': 'off',
'quotes': ['error', 'single'],
'comma-dangle': 'off',
'max-len': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
},
};
24 changes: 14 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,32 @@
"prepublish": "yarn run lint && yarn build",
"build": "rimraf lib && tsc",
"coverage": "jest --coverage --runInBand",
"lint": "tslint \"src/**/*.ts\"",
"fix": "tslint \"src/**/*.ts\" --fix",
"lint": "eslint src/**/*.{ts,tsx,js,jsx}",
"fix": "eslint src/**/*.{ts,tsx,js,jsx} --fix",
"test": "jest --runInBand",
"release": "npx -p semantic-release -p @semantic-release/git -p @semantic-release/changelog semantic-release",
"prepare": "npm run build"
},
"devDependencies": {
"@types/jest": "^23.3.5",
"@types/node": "^10.11.7",
"@types/node": "^20.6.0",
"@typescript-eslint/eslint-plugin": "^6.7.0",
"@typescript-eslint/parser": "^6.7.0",
"coveralls": "^3.0.2",
"eslint": "^8.49.0",
"husky": "^1.1.2",
"jest": "^28.1.3",
"lint-staged": "^7.3.0",
"mysql2": "^2.1.0",
"pg": "^8.4.2",
"rimraf": "^2.6.2",
"ts-jest": "28.0.7",
"tslint": "^5.11.0",
"typescript": "^4.7.3"
"typescript": "^5.2.2"
},
"dependencies": {
"casbin": "^5.11.5",
"casbin": "^5.27.0",
"reflect-metadata": "^0.1.13",
"typeorm": "^0.3.6"
"typeorm": "^0.3.17"
},
"files": [
"lib",
Expand Down Expand Up @@ -68,13 +70,15 @@
"url": "https://github.com/node-casbin/typeorm-adapter/issues"
},
"lint-staged": {
"*.{ts,js}": [
"tslint --fix",
"*.{ts,tsx,js,jsx}": [
"eslint --fix",
"git add"
]
},
"jest": {
"testURL": "http://localhost",
"testEnvironmentOptions": {
"url": "http://localhost"
},
"transform": {
"^.+\\.(ts|tsx)$": "ts-jest"
},
Expand Down
3 changes: 2 additions & 1 deletion src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,9 @@ export default class TypeORMAdapter implements FilteredAdapter {

/**
* 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.
* This switch is required as the normal {@link CasbinRule} does not work when using MongoDB as a backend (due to a missing ObjectID field).
* This switch is required as the normal {@link CasbinRule} does not work when using MongoDB as a backend (due to a missing ObjectId field).
* @param type
* @param adapterConfig
*/
private static getCasbinRuleType(
type: string,
Expand Down
4 changes: 2 additions & 2 deletions src/casbinMongoRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import { BaseEntity, Column, Entity, ObjectID, ObjectIdColumn } from 'typeorm';
import { BaseEntity, Column, Entity, ObjectId, ObjectIdColumn } from 'typeorm';

@Entity()
export class CasbinMongoRule extends BaseEntity {
@ObjectIdColumn()
public id!: ObjectID;
public id!: ObjectId;

@Column({
nullable: true,
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'reflect-metadata';
export { TypeORMAdapterOptions } from './adapter';
export * from './casbinMongoRule';
export * from './casbinRule';
Expand Down
28 changes: 21 additions & 7 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"module": "esnext",
"target": "es5",
"jsx": "react",
"moduleResolution": "node",
"declaration": true,
"declarationDir": "lib",
"experimentalDecorators": true,
"esModuleInterop": true,
"strict": true,
"outDir": "lib",
"resolveJsonModule": true,
"strictNullChecks": true,
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": false,
"strictPropertyInitialization": false,
"experimentalDecorators": true,
"noEmit": true,
"emitDecoratorMetadata": true
},
"include": ["src/**/*.ts"]
"include": [
"src"
]
}
21 changes: 0 additions & 21 deletions tslint.json

This file was deleted.

Loading

0 comments on commit 7b02c6d

Please sign in to comment.