From ed02de9c0be3ee73e83b6c4d50ef430204c28d28 Mon Sep 17 00:00:00 2001 From: Christopher Chudzicki Date: Wed, 12 Jan 2022 22:06:26 -0500 Subject: [PATCH 1/8] fix(types): fix type for bulkInsert 4th arg --- types/lib/query-interface.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/lib/query-interface.d.ts b/types/lib/query-interface.d.ts index ebbe9f138928..01c8eef3ca7e 100644 --- a/types/lib/query-interface.d.ts +++ b/types/lib/query-interface.d.ts @@ -497,7 +497,7 @@ export class QueryInterface { tableName: TableName, records: object[], options?: QueryOptions, - attributes?: string[] | string + attributes?: Record ): Promise; /** From 138c125bd08bb6af6200743cd04640cde9006a65 Mon Sep 17 00:00:00 2001 From: Christopher Chudzicki Date: Wed, 12 Jan 2022 22:28:33 -0500 Subject: [PATCH 2/8] fix(types): make JSON and JSONB constructable An alternative to this might be to give `AbstractDataTypeConstructor` a constructor method, along the lines of: ```ts interface AbstractDataTypeConstructor { new (): AbstractDataType; key: string; warn(link: string, text: string): void; } ``` Then all the types would become constructable. Is that desirable? --- types/lib/data-types.d.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/types/lib/data-types.d.ts b/types/lib/data-types.d.ts index dd0eed60172d..ef8668263f86 100644 --- a/types/lib/data-types.d.ts +++ b/types/lib/data-types.d.ts @@ -366,13 +366,15 @@ export const HSTORE: AbstractDataTypeConstructor; /** * A JSON string column. Only available in postgres. */ -export const JSON: AbstractDataTypeConstructor; - + export interface JSON extends AbstractDataTypeConstructor { + new (): JSON; +} /** * A pre-processed JSON data column. Only available in postgres. */ -export const JSONB: AbstractDataTypeConstructor; - +export interface JSONB extends AbstractDataTypeConstructor { + new (): JSONB; +} /** * A default value of the current timestamp */ From 7ff90cbeb77d204eac717fa2dd9d1d4d070c971c Mon Sep 17 00:00:00 2001 From: Christopher Chudzicki Date: Thu, 13 Jan 2022 12:28:26 -0500 Subject: [PATCH 3/8] fix(types): fix JSON type constuctor to return AbstractDataType not AbstractDataTypeConstructor --- types/lib/data-types.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/lib/data-types.d.ts b/types/lib/data-types.d.ts index ef8668263f86..7b44c96642a1 100644 --- a/types/lib/data-types.d.ts +++ b/types/lib/data-types.d.ts @@ -367,13 +367,13 @@ export const HSTORE: AbstractDataTypeConstructor; * A JSON string column. Only available in postgres. */ export interface JSON extends AbstractDataTypeConstructor { - new (): JSON; + new (): AbstractDataType; } /** * A pre-processed JSON data column. Only available in postgres. */ export interface JSONB extends AbstractDataTypeConstructor { - new (): JSONB; + new (): AbstractDataType; } /** * A default value of the current timestamp From 52c2200c4f2397736a19434f2ea644b9e122d6f6 Mon Sep 17 00:00:00 2001 From: Christopher Chudzicki Date: Thu, 13 Jan 2022 12:44:20 -0500 Subject: [PATCH 4/8] fix(types): more JSON type fixes + tests --- types/lib/data-types.d.ts | 10 ++++++---- types/test/data-types.ts | 10 +++++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/types/lib/data-types.d.ts b/types/lib/data-types.d.ts index 7b44c96642a1..8fb0f3484ecc 100644 --- a/types/lib/data-types.d.ts +++ b/types/lib/data-types.d.ts @@ -366,15 +366,17 @@ export const HSTORE: AbstractDataTypeConstructor; /** * A JSON string column. Only available in postgres. */ - export interface JSON extends AbstractDataTypeConstructor { - new (): AbstractDataType; -} +export const JSON: JSONDataTypeConstructor; /** * A pre-processed JSON data column. Only available in postgres. */ -export interface JSONB extends AbstractDataTypeConstructor { +export const JSONB: JSONDataTypeConstructor; + +interface JSONDataTypeConstructor extends AbstractDataTypeConstructor { new (): AbstractDataType; + (): AbstractDataType; } + /** * A default value of the current timestamp */ diff --git a/types/test/data-types.ts b/types/test/data-types.ts index 01d463f2135b..821111910838 100644 --- a/types/test/data-types.ts +++ b/types/test/data-types.ts @@ -1,7 +1,7 @@ import { expectTypeOf } from 'expect-type'; import { DataTypes } from 'sequelize'; -const { TINYINT, SMALLINT, MEDIUMINT, BIGINT, INTEGER } = DataTypes; +const { TINYINT, SMALLINT, MEDIUMINT, BIGINT, INTEGER, JSON, JSONB } = DataTypes; // TINYINT expectTypeOf(TINYINT()).toEqualTypeOf(); @@ -32,3 +32,11 @@ expectTypeOf(INTEGER()).toEqualTypeOf(); expectTypeOf(new INTEGER()).toEqualTypeOf(); expectTypeOf(INTEGER.UNSIGNED.ZEROFILL()).toEqualTypeOf(); expectTypeOf(new INTEGER.UNSIGNED.ZEROFILL()).toEqualTypeOf(); + +// JSON +expectTypeOf(new JSON()).toEqualTypeOf(); +expectTypeOf(JSON()).toEqualTypeOf(); + +// JSONB +expectTypeOf(new JSONB()).toEqualTypeOf(); +expectTypeOf(JSONB()).toEqualTypeOf(); \ No newline at end of file From 6a1c3e5d0f3b02fb89c063b2d1b452e46ab563f1 Mon Sep 17 00:00:00 2001 From: Christopher Chudzicki Date: Thu, 13 Jan 2022 12:52:40 -0500 Subject: [PATCH 5/8] fix(types): add test for queryInterface.bulkInsert --- types/test/query-interface.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/types/test/query-interface.ts b/types/test/query-interface.ts index 25454db082ff..58408c298add 100644 --- a/types/test/query-interface.ts +++ b/types/test/query-interface.ts @@ -67,6 +67,8 @@ async function test() { const bulkInsertRes: Promise = queryInterface.bulkInsert({ tableName: 'foo', as: 'bar', name: 'as' }, [{}], {}); + const bulkInsertResWithAttrs: Promise = queryInterface.bulkInsert('foo', [{}], {}, { bar: { type: DataTypes.JSON } }); + await queryInterface.bulkUpdate({ tableName: 'foo', delimiter: 'bar', as: 'baz', name: 'quz' }, {}, {}); await queryInterface.dropTrigger({ tableName: 'foo', as: 'bar', name: 'baz' }, 'foo', {}); From fc32704aeeba36344ff147a7a74f7b010640dc12 Mon Sep 17 00:00:00 2001 From: Christopher Chudzicki Date: Thu, 13 Jan 2022 17:31:01 -0500 Subject: [PATCH 6/8] fix(types): date data type interface should extend AbstractDataType not AbstractDataTypeConstructor --- types/lib/data-types.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/lib/data-types.d.ts b/types/lib/data-types.d.ts index 8fb0f3484ecc..ed7f2d95b0d0 100644 --- a/types/lib/data-types.d.ts +++ b/types/lib/data-types.d.ts @@ -336,7 +336,7 @@ interface DateDataTypeConstructor extends AbstractDataTypeConstructor { (options?: DateDataTypeOptions): DateDataType; } -export interface DateDataType extends AbstractDataTypeConstructor { +export interface DateDataType extends AbstractDataType { options: DateDataTypeOptions; } From 4676a8d901460d33eb27c984c0890016f67471da Mon Sep 17 00:00:00 2001 From: Christopher Chudzicki Date: Thu, 13 Jan 2022 17:34:12 -0500 Subject: [PATCH 7/8] fix(types): make abstract data type constructable --- types/lib/data-types.d.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/types/lib/data-types.d.ts b/types/lib/data-types.d.ts index ed7f2d95b0d0..2eb62626a331 100644 --- a/types/lib/data-types.d.ts +++ b/types/lib/data-types.d.ts @@ -52,6 +52,8 @@ export const ABSTRACT: AbstractDataTypeConstructor; interface AbstractDataTypeConstructor { key: string; warn(link: string, text: string): void; + new (): AbstractDataType; + (): AbstractDataType; } export interface AbstractDataType { @@ -366,16 +368,11 @@ export const HSTORE: AbstractDataTypeConstructor; /** * A JSON string column. Only available in postgres. */ -export const JSON: JSONDataTypeConstructor; +export const JSON: AbstractDataTypeConstructor; /** * A pre-processed JSON data column. Only available in postgres. */ -export const JSONB: JSONDataTypeConstructor; - -interface JSONDataTypeConstructor extends AbstractDataTypeConstructor { - new (): AbstractDataType; - (): AbstractDataType; -} +export const JSONB: AbstractDataTypeConstructor; /** * A default value of the current timestamp From 6d4587518bc5c637dc250d85545b41da7f40b111 Mon Sep 17 00:00:00 2001 From: Christopher Chudzicki Date: Thu, 13 Jan 2022 17:37:07 -0500 Subject: [PATCH 8/8] fix(types): add a few more type tests for the types affected by new constructor signature on AbstractDataType --- types/test/data-types.ts | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/types/test/data-types.ts b/types/test/data-types.ts index 821111910838..e3d43c75877a 100644 --- a/types/test/data-types.ts +++ b/types/test/data-types.ts @@ -1,7 +1,7 @@ import { expectTypeOf } from 'expect-type'; import { DataTypes } from 'sequelize'; -const { TINYINT, SMALLINT, MEDIUMINT, BIGINT, INTEGER, JSON, JSONB } = DataTypes; +const { TINYINT, SMALLINT, MEDIUMINT, BIGINT, INTEGER, JSON, JSONB, CITEXT, MACADDR, TSVECTOR, CIDR, INET } = DataTypes; // TINYINT expectTypeOf(TINYINT()).toEqualTypeOf(); @@ -39,4 +39,24 @@ expectTypeOf(JSON()).toEqualTypeOf(); // JSONB expectTypeOf(new JSONB()).toEqualTypeOf(); -expectTypeOf(JSONB()).toEqualTypeOf(); \ No newline at end of file +expectTypeOf(JSONB()).toEqualTypeOf(); + +// CITEXT +expectTypeOf(new CITEXT()).toEqualTypeOf(); +expectTypeOf(CITEXT()).toEqualTypeOf(); + +// MACADDR +expectTypeOf(new MACADDR()).toEqualTypeOf(); +expectTypeOf(MACADDR()).toEqualTypeOf(); + +// TSVECTOR +expectTypeOf(new TSVECTOR()).toEqualTypeOf(); +expectTypeOf(TSVECTOR()).toEqualTypeOf(); + +// CIDR +expectTypeOf(new CIDR()).toEqualTypeOf(); +expectTypeOf(CIDR()).toEqualTypeOf(); + +// INET +expectTypeOf(new INET()).toEqualTypeOf(); +expectTypeOf(INET()).toEqualTypeOf();