Skip to content

Commit

Permalink
fix: type error in validate when using min max (#413)
Browse files Browse the repository at this point in the history
* fix: type error in validate when using min max

* feat: add test case

* ci: remove 14.x pipeline

---------

Co-authored-by: JimmyDaddy <cjh269940@antgroup.com>
  • Loading branch information
chen201724 and JimmyDaddy authored Dec 5, 2023
1 parent 1e8a267 commit 55539b6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:

strategy:
matrix:
node-version: [14.x, 16.x, 18.x, 20.x]
node-version: [16.x, 18.x, 20.x]

steps:
- uses: actions/checkout@v2
Expand Down
1 change: 1 addition & 0 deletions src/drivers/sqljs/sqljs-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ function nest(rows: Record<string, Literal>[], fields: string[], spell: SpellMet
}

async function defaultInitSqlJs(options: SqljsConnectionOptions): Promise<Database> {
// sql.js don't compatible with nodejs 14
const { default: initSqlJs } = await import('sql.js');
const SQL = await initSqlJs();

Expand Down
2 changes: 1 addition & 1 deletion src/types/common.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { AbstractBone } from './abstract_bone';
export type Literal = null | undefined | boolean | number | bigint | string | Date | Record<string, any> | ArrayBuffer;

// eslint-disable-next-line @typescript-eslint/ban-types
type BaseValidateArgs = boolean | RegExp | Function | Array<Array<Literal>> | string | Array<Literal>;
type BaseValidateArgs = boolean | RegExp | Function | Array<Array<Literal>> | string | Array<Literal> | number;

export type Validator = BaseValidateArgs | {
args?: BaseValidateArgs,
Expand Down
14 changes: 14 additions & 0 deletions test/types/decorators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,15 @@ describe('=> Decorators (TypeScript)', function() {
},
})
status!: number;

@Column({
type: DataTypes.INTEGER,
validate: {
min: 0,
max: 10,
},
})
count!: number;
}
await Note.sync({ force: true });
let note = new Note({ name: '' });
Expand All @@ -204,6 +213,11 @@ describe('=> Decorators (TypeScript)', function() {
await assert.rejects(async () => {
await note.save();
}, /Error status/);

note = new Note({ name: 'Github', count: 11 });
await assert.rejects(async () => {
await note.save();
}, /Validation max on count failed/);
});

it('should work with other options', async () => {
Expand Down

0 comments on commit 55539b6

Please sign in to comment.