From 55539b635834eba4a483bb316ff35f3753fa061b Mon Sep 17 00:00:00 2001 From: cwg <1227646458@qq.com> Date: Tue, 5 Dec 2023 17:16:40 +0800 Subject: [PATCH] fix: type error in validate when using min max (#413) * fix: type error in validate when using min max * feat: add test case * ci: remove 14.x pipeline --------- Co-authored-by: JimmyDaddy --- .github/workflows/nodejs.yml | 2 +- src/drivers/sqljs/sqljs-connection.ts | 1 + src/types/common.d.ts | 2 +- test/types/decorators.test.ts | 14 ++++++++++++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 1f523689..e539bc90 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -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 diff --git a/src/drivers/sqljs/sqljs-connection.ts b/src/drivers/sqljs/sqljs-connection.ts index 261f91eb..09d290cd 100644 --- a/src/drivers/sqljs/sqljs-connection.ts +++ b/src/drivers/sqljs/sqljs-connection.ts @@ -60,6 +60,7 @@ function nest(rows: Record[], fields: string[], spell: SpellMet } async function defaultInitSqlJs(options: SqljsConnectionOptions): Promise { + // sql.js don't compatible with nodejs 14 const { default: initSqlJs } = await import('sql.js'); const SQL = await initSqlJs(); diff --git a/src/types/common.d.ts b/src/types/common.d.ts index 13ac6a33..78fe6537 100644 --- a/src/types/common.d.ts +++ b/src/types/common.d.ts @@ -6,7 +6,7 @@ import { AbstractBone } from './abstract_bone'; export type Literal = null | undefined | boolean | number | bigint | string | Date | Record | ArrayBuffer; // eslint-disable-next-line @typescript-eslint/ban-types -type BaseValidateArgs = boolean | RegExp | Function | Array> | string | Array; +type BaseValidateArgs = boolean | RegExp | Function | Array> | string | Array | number; export type Validator = BaseValidateArgs | { args?: BaseValidateArgs, diff --git a/test/types/decorators.test.ts b/test/types/decorators.test.ts index 870e2dd6..9033613d 100644 --- a/test/types/decorators.test.ts +++ b/test/types/decorators.test.ts @@ -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: '' }); @@ -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 () => {