From 16ea92bde497426fcffe7f588a023ce222a3eb5b Mon Sep 17 00:00:00 2001 From: Max Polsky Date: Wed, 6 Dec 2023 00:15:41 -0800 Subject: [PATCH] Refactor SQL schema translation for text and object fields (#482) * Refactor mysql schema translation for text and object fields * Refactor postgres schema translator & schema utils * Refactor Postgres schema column translation * Fix translation of date type in schemaTranslator * Add support for time and date columns in BigQuery, MSSQL, MySQL, and Postgres capabilities * Refactor columnToDbColumnSql method in spanner schema Column Translator * Fix translation of DATE type in schemaTranslator * updated supportedFieldTypes --- .../src/bigquery_capabilities.ts | 2 + .../src/sql_schema_translator.spec.ts | 50 +++++++++------- .../src/sql_schema_translator.ts | 18 +++--- .../src/sql_schema_translator.spec.ts | 33 +++++++---- .../src/sql_schema_translator.ts | 14 ++++- .../src/mysql_capabilities.ts | 2 + .../src/sql_schema_translator.spec.ts | 57 ++++++++++--------- .../src/sql_schema_translator.ts | 19 ++++--- .../src/postgres_capabilities.ts | 2 + .../src/sql_schema_translator.spec.ts | 45 +++++++++------ .../src/sql_schema_translator.ts | 17 +++--- .../src/sql_schema_translator.spec.ts | 37 ++++++------ .../src/sql_schema_translator.ts | 12 ++-- libs/velo-external-db-core/src/router.ts | 4 +- .../src/utils/schema_utils.spec.ts | 20 ++++--- .../src/utils/schema_utils.ts | 25 ++++---- .../src/collection_types.ts | 2 + 17 files changed, 218 insertions(+), 141 deletions(-) diff --git a/libs/external-db-bigquery/src/bigquery_capabilities.ts b/libs/external-db-bigquery/src/bigquery_capabilities.ts index 72c1f55de..69782a418 100644 --- a/libs/external-db-bigquery/src/bigquery_capabilities.ts +++ b/libs/external-db-bigquery/src/bigquery_capabilities.ts @@ -18,4 +18,6 @@ export const ColumnsCapabilities = { image: { sortable: false, columnQueryOperators: [] }, object: { sortable: false, columnQueryOperators: [] }, datetime: { sortable: true, columnQueryOperators: [eq, ne, gt, gte, lt, lte] }, + time: { sortable: true, columnQueryOperators: [eq, ne, gt, gte, lt, lte] }, + date: { sortable: true, columnQueryOperators: [eq, ne, gt, gte, lt, lte] }, } diff --git a/libs/external-db-bigquery/src/sql_schema_translator.spec.ts b/libs/external-db-bigquery/src/sql_schema_translator.spec.ts index 29075f444..44579a787 100644 --- a/libs/external-db-bigquery/src/sql_schema_translator.spec.ts +++ b/libs/external-db-bigquery/src/sql_schema_translator.spec.ts @@ -70,9 +70,17 @@ describe('Sql Schema Column Translator', () => { }) describe('string fields', () => { - test('string', () => { - expect( env.schemaTranslator.columnToDbColumnSql({ name: ctx.fieldName, type: 'text', subtype: 'string' }) ).toEqual({ mode: '', name: escapeId(ctx.fieldName), type: 'STRING' }) - }) + test.each([ + 'string', + 'richcontent', + 'image', + 'video', + 'audio', + 'document', + 'language', + ])('%s', (subtype) => { + expect( env.schemaTranslator.columnToDbColumnSql({ name: ctx.fieldName, type: 'text', subtype }) ).toEqual({ mode: '', name: escapeId(ctx.fieldName), type: 'STRING' }) + }) test('string with length', () => { expect( env.schemaTranslator.columnToDbColumnSql({ name: ctx.fieldName, type: 'text', subtype: 'string', precision: '50' }) ).toEqual({ mode: '', name: escapeId(ctx.fieldName), type: 'STRING(50)' }) @@ -108,20 +116,15 @@ describe('Sql Schema Column Translator', () => { describe('JSON fields', () => { test.each([ - ['object'], - ['image'], - ['document'], - ['video'], - ['audio'], - ['any'], - ['mediaGallery'], - ['address'], - ['pageLink'], - ['reference'], - ['multiReference'], - ['arrayString'], - ['arrayDocument'], - ['richContent'], + 'object', + 'any', + 'mediaGallery', + 'address', + 'pageLink', + 'reference', + 'multiReference', + 'arrayDocument', + 'arrayString', ])('%s', (subtype) => { expect(env.schemaTranslator.columnToDbColumnSql({ name: ctx.fieldName, type: 'object', subtype })).toEqual({ mode: '', name: escapeId(ctx.fieldName), type: 'JSON' }) }) @@ -154,10 +157,17 @@ describe('Sql Schema Column Translator', () => { }) describe('date time fields', () => { + + test.each(['DATETIME', 'TIMESTAMP'])('%s', (t) => { + expect( env.schemaTranslator.translateType(t) ).toEqual('datetime') + }) + + test('time', () => { + expect( env.schemaTranslator.translateType('TIME') ).toEqual('time') + }) + test('date', () => { - ['DATE', 'DATETIME', 'TIME', 'TIMESTAMP'].forEach(t => { - expect( env.schemaTranslator.translateType(t) ).toEqual('datetime') - }) + expect( env.schemaTranslator.translateType('DATE') ).toEqual('date') }) }) diff --git a/libs/external-db-bigquery/src/sql_schema_translator.ts b/libs/external-db-bigquery/src/sql_schema_translator.ts index a5204c60a..23efd25d6 100644 --- a/libs/external-db-bigquery/src/sql_schema_translator.ts +++ b/libs/external-db-bigquery/src/sql_schema_translator.ts @@ -20,10 +20,13 @@ export default class SchemaColumnTranslator { case 'bigdecimal': return 'number' - case 'timestamp': - case 'datetime': case 'time': + return 'time' case 'date': + return 'date' + + case 'timestamp': + case 'datetime': return 'datetime' case 'string': @@ -90,6 +93,11 @@ export default class SchemaColumnTranslator { case 'text_medium': case 'text_large': case 'text_language': + case 'text_richcontent': + case 'text_image': + case 'text_video': + case 'text_audio': + case 'text_document': return 'STRING' case 'boolean_': @@ -98,11 +106,7 @@ export default class SchemaColumnTranslator { case 'object_': case 'object_object': - case 'object_image': - case 'object_document': - case 'object_video': case 'object_any': - case 'object_audio': case 'object_mediagallery': case 'object_address': case 'object_pagelink': @@ -110,7 +114,7 @@ export default class SchemaColumnTranslator { case 'object_multireference': case 'object_arraystring': case 'object_arraydocument': - case 'object_richcontent': + case 'object_array': return 'JSON' default: diff --git a/libs/external-db-mssql/src/sql_schema_translator.spec.ts b/libs/external-db-mssql/src/sql_schema_translator.spec.ts index 311142309..c876138bc 100644 --- a/libs/external-db-mssql/src/sql_schema_translator.spec.ts +++ b/libs/external-db-mssql/src/sql_schema_translator.spec.ts @@ -67,9 +67,18 @@ describe('Sql Schema Column Translator', () => { }) describe('string fields', () => { - test('string', () => { - expect( env.schemaTranslator.columnToDbColumnSql({ name: ctx.fieldName, type: 'text', subtype: 'string' }) ).toEqual(`${escapeId(ctx.fieldName)} VARCHAR(2048)`) - }) + + test.each([ + 'string', + 'richcontent', + 'image', + 'video', + 'audio', + 'document', + 'language', + ])('text %s', (subtype) => { + expect( env.schemaTranslator.columnToDbColumnSql({ name: ctx.fieldName, type: 'text', subtype }) ).toEqual(`${escapeId(ctx.fieldName)} VARCHAR(2048)`) + }) test('string with length', () => { expect( env.schemaTranslator.columnToDbColumnSql({ name: ctx.fieldName, type: 'text', subtype: 'string', precision: '2055' }) ).toEqual(`${escapeId(ctx.fieldName)} VARCHAR(2055)`) @@ -86,12 +95,6 @@ describe('Sql Schema Column Translator', () => { test('text large', () => { expect( env.schemaTranslator.columnToDbColumnSql({ name: ctx.fieldName, type: 'text', subtype: 'large' }) ).toEqual(`${escapeId(ctx.fieldName)} TEXT`) }) - - test('text language', () => { - expect( env.schemaTranslator.columnToDbColumnSql({ name: ctx.fieldName, type: 'text', subtype: 'language' }) ).toEqual(`${escapeId(ctx.fieldName)} TEXT`) - }) - - }) describe('other fields', () => { @@ -127,10 +130,16 @@ describe('Sql Schema Column Translator', () => { }) describe('date time fields', () => { + test('time', () => { + expect( env.schemaTranslator.translateType('TIME') ).toEqual('time') + }) + test('date', () => { - ['DATE', 'DATETIME', 'DATETIME2', 'TIME', 'DATETIMEOFFSET', 'SMALLDATETIME'].forEach(t => { - expect( env.schemaTranslator.translateType(t) ).toEqual('datetime') - }) + expect( env.schemaTranslator.translateType('DATE') ).toEqual('date') + }) + + test.each([ 'DATETIME', 'DATETIME2', 'DATETIMEOFFSET', 'SMALLDATETIME'])('%s', (t) => { + expect( env.schemaTranslator.translateType(t) ).toEqual('datetime') }) }) diff --git a/libs/external-db-mssql/src/sql_schema_translator.ts b/libs/external-db-mssql/src/sql_schema_translator.ts index 0f268f426..ddf26cd35 100644 --- a/libs/external-db-mssql/src/sql_schema_translator.ts +++ b/libs/external-db-mssql/src/sql_schema_translator.ts @@ -18,11 +18,14 @@ export default class SchemaColumnTranslator { case 'decimal': case 'numeric': return 'number' - + + case 'time': + return 'time' case 'date': + return 'date' + case 'datetime': case 'datetime2': - case 'time': case 'datetimeoffset': case 'smalldatetime': return 'datetime' @@ -83,12 +86,17 @@ export default class SchemaColumnTranslator { return 'SMALLDATETIME' case 'text_string': + case 'text_richcontent': + case 'text_image': + case 'text_video': + case 'text_audio': + case 'text_document': + case 'text_language': return `VARCHAR${this.parseLength(precision)}` case 'text_small': case 'text_medium': case 'text_large': - case 'text_language': return 'TEXT' diff --git a/libs/external-db-mysql/src/mysql_capabilities.ts b/libs/external-db-mysql/src/mysql_capabilities.ts index 7b22111e9..7250e9510 100644 --- a/libs/external-db-mysql/src/mysql_capabilities.ts +++ b/libs/external-db-mysql/src/mysql_capabilities.ts @@ -18,4 +18,6 @@ export const ColumnsCapabilities = { image: { sortable: false, columnQueryOperators: [] }, object: { sortable: false, columnQueryOperators: [eq, ne, string_contains, string_begins, string_ends, include, gt, gte, lt, lte] }, datetime: { sortable: true, columnQueryOperators: [eq, ne, gt, gte, lt, lte] }, + time: { sortable: true, columnQueryOperators: [eq, ne, gt, gte, lt, lte] }, + date: { sortable: true, columnQueryOperators: [eq, ne, gt, gte, lt, lte] }, } diff --git a/libs/external-db-mysql/src/sql_schema_translator.spec.ts b/libs/external-db-mysql/src/sql_schema_translator.spec.ts index 28c0e29d3..3a0727e96 100644 --- a/libs/external-db-mysql/src/sql_schema_translator.spec.ts +++ b/libs/external-db-mysql/src/sql_schema_translator.spec.ts @@ -67,9 +67,17 @@ describe('Sql Schema Column Translator', () => { }) describe('string fields', () => { - test('string', () => { - expect( env.schemaTranslator.columnToDbColumnSql({ name: ctx.fieldName, type: 'text', subtype: 'string' }) ).toEqual(`${escapeId(ctx.fieldName)} TEXT`) - }) + test.each([ + 'string', + 'richcontent', + 'image', + 'video', + 'audio', + 'document', + 'language', + ])('%s', (subtype) => { + expect(env.schemaTranslator.columnToDbColumnSql({ name: ctx.fieldName, type: 'text', subtype })).toEqual(`${escapeId(ctx.fieldName)} TEXT`) + }) test('string with length', () => { expect( env.schemaTranslator.columnToDbColumnSql({ name: ctx.fieldName, type: 'text', subtype: 'string', precision: '2055' }) ).toEqual(`${escapeId(ctx.fieldName)} VARCHAR(2055)`) @@ -86,29 +94,19 @@ describe('Sql Schema Column Translator', () => { test('text large', () => { expect( env.schemaTranslator.columnToDbColumnSql({ name: ctx.fieldName, type: 'text', subtype: 'large' }) ).toEqual(`${escapeId(ctx.fieldName)} LONGTEXT`) }) - - test('text language', () => { - - expect( env.schemaTranslator.columnToDbColumnSql({ name: ctx.fieldName, type: 'text', subtype: 'language' }) ).toEqual(`${escapeId(ctx.fieldName)} TEXT`) - }) }) describe('JSON fields', () => { test.each([ - ['object'], - ['image'], - ['document'], - ['video'], - ['audio'], - ['any'], - ['mediaGallery'], - ['address'], - ['pageLink'], - ['reference'], - ['multiReference'], - ['arrayString'], - ['arrayDocument'], - ['richContent'], + 'object', + 'any', + 'mediaGallery', + 'address', + 'pageLink', + 'reference', + 'multiReference', + 'arrayDocument', + 'arrayString', ])('%s', (subtype) => { expect(env.schemaTranslator.columnToDbColumnSql({ name: ctx.fieldName, type: 'object', subtype })).toEqual(`${escapeId(ctx.fieldName)} JSON`) }) @@ -141,11 +139,18 @@ describe('Sql Schema Column Translator', () => { }) describe('date time fields', () => { - test('date', () => { - ['DATE', 'DATETIME', 'TIMESTAMP', 'TIME', 'YEAR'].forEach(t => { - expect( env.schemaTranslator.translateType(t) ).toEqual('datetime') - }) + test.each([ 'DATETIME', 'TIMESTAMP' ])('%s', (t) => { + expect( env.schemaTranslator.translateType(t) ).toEqual('datetime') }) + + + test('time', () => { + expect( env.schemaTranslator.translateType('TIME') ).toEqual('time') + }) + + test('date', () => { + expect( env.schemaTranslator.translateType('DATE') ).toEqual('date') + }) }) describe('json fields', () => { diff --git a/libs/external-db-mysql/src/sql_schema_translator.ts b/libs/external-db-mysql/src/sql_schema_translator.ts index a38fbe100..368165d10 100644 --- a/libs/external-db-mysql/src/sql_schema_translator.ts +++ b/libs/external-db-mysql/src/sql_schema_translator.ts @@ -18,14 +18,18 @@ export default class SchemaColumnTranslato { case 'float': case 'double': case 'decimal': + case 'year': return 'number' case 'date': + return 'date' + case 'datetime': case 'timestamp': - case 'time': - case 'year': return 'datetime' + + case 'time': + return 'time' case 'varchar': case 'text': @@ -90,6 +94,11 @@ export default class SchemaColumnTranslato { return 'TIMESTAMP DEFAULT CURRENT_TIMESTAMP' case 'text_string': + case 'text_richcontent': + case 'text_image': + case 'text_video': + case 'text_audio': + case 'text_document': return precision ? `VARCHAR${this.parseLength(precision)}` : 'TEXT' case 'text_small': @@ -108,11 +117,7 @@ export default class SchemaColumnTranslato { case 'object_': case 'object_object': - case 'object_image': - case 'object_document': - case 'object_video': case 'object_any': - case 'object_audio': case 'object_mediagallery': case 'object_address': case 'object_pagelink': @@ -120,7 +125,7 @@ export default class SchemaColumnTranslato { case 'object_multireference': case 'object_arraystring': case 'object_arraydocument': - case 'object_richcontent': + case 'object_array': return 'JSON' default: diff --git a/libs/external-db-postgres/src/postgres_capabilities.ts b/libs/external-db-postgres/src/postgres_capabilities.ts index 04a414516..9ae7f2a7c 100644 --- a/libs/external-db-postgres/src/postgres_capabilities.ts +++ b/libs/external-db-postgres/src/postgres_capabilities.ts @@ -16,4 +16,6 @@ export const ColumnsCapabilities = { image: { sortable: false, columnQueryOperators: [] }, object: { sortable: false, columnQueryOperators: [eq, ne, string_contains, string_begins, string_ends, include, gt, gte, lt, lte] }, datetime: { sortable: true, columnQueryOperators: [eq, ne, gt, gte, lt, lte] }, + time: { sortable: true, columnQueryOperators: [eq, ne, gt, gte, lt, lte] }, + date: { sortable: true, columnQueryOperators: [eq, ne, gt, gte, lt, lte] }, } diff --git a/libs/external-db-postgres/src/sql_schema_translator.spec.ts b/libs/external-db-postgres/src/sql_schema_translator.spec.ts index 637c0e038..65fd323ac 100644 --- a/libs/external-db-postgres/src/sql_schema_translator.spec.ts +++ b/libs/external-db-postgres/src/sql_schema_translator.spec.ts @@ -53,9 +53,17 @@ describe('Sql Schema Column Translator', () => { }) describe('string fields', () => { - test('string', () => { - expect( env.schemaTranslator.columnToDbColumnSql({ name: ctx.fieldName, type: 'text', subtype: 'string' }) ).toEqual(`${escapeIdentifier(ctx.fieldName)} text`) - }) + test.each([ + 'string', + 'richcontent', + 'image', + 'video', + 'audio', + 'document', + 'language', + ])('%s', (subtype) => { + expect(env.schemaTranslator.columnToDbColumnSql({ name: ctx.fieldName, type: 'text', subtype })).toEqual(`${escapeIdentifier(ctx.fieldName)} text`) + }) test('string with length', () => { expect( env.schemaTranslator.columnToDbColumnSql({ name: ctx.fieldName, type: 'text', subtype: 'string', precision: '2055' }) ).toEqual(`${escapeIdentifier(ctx.fieldName)} varchar(2055)`) @@ -86,20 +94,15 @@ describe('Sql Schema Column Translator', () => { describe('json fields', () => { test.each([ - ['object'], - ['image'], - ['document'], - ['video'], - ['audio'], - ['any'], - ['mediaGallery'], - ['address'], - ['pageLink'], - ['reference'], - ['multiReference'], - ['arrayString'], - ['arrayDocument'], - ['richContent'], + 'object', + 'any', + 'mediaGallery', + 'address', + 'pageLink', + 'reference', + 'multiReference', + 'arrayDocument', + 'arrayString', ])('%s', (subtype) => { expect(env.schemaTranslator.columnToDbColumnSql({ name: ctx.fieldName, type: 'object', subtype })).toEqual(`${escapeIdentifier(ctx.fieldName)} json`) }) @@ -133,7 +136,13 @@ describe('Sql Schema Column Translator', () => { describe('date time fields', () => { test('date', () => { - ['date', 'time', 'timez', 'timestamp', 'timestamptz'].forEach(t => { + expect( env.schemaTranslator.translateType('date') ).toEqual('date') + }) + test('time', () => { + expect( env.schemaTranslator.translateType('time') ).toEqual('time') + }) + test('datetime', () => { + ['timez', 'timestamp', 'timestamptz'].forEach(t => { expect( env.schemaTranslator.translateType(t) ).toEqual('datetime') }) }) diff --git a/libs/external-db-postgres/src/sql_schema_translator.ts b/libs/external-db-postgres/src/sql_schema_translator.ts index d26421acc..732bf75d3 100644 --- a/libs/external-db-postgres/src/sql_schema_translator.ts +++ b/libs/external-db-postgres/src/sql_schema_translator.ts @@ -34,9 +34,12 @@ export default class SchemaColumnTranslator { return 'number' case 'date': + return 'date' case 'time': - case 'timez': + return 'time' + case 'timestamp': + case 'timez': case 'timestamptz': return 'datetime' @@ -97,6 +100,11 @@ export default class SchemaColumnTranslator { return 'timestamp' case 'text_string': + case 'text_richcontent': + case 'text_image': + case 'text_video': + case 'text_audio': + case 'text_document': return precision ? `varchar${this.parseLength(precision)}` : 'text' case 'text_small': @@ -109,14 +117,9 @@ export default class SchemaColumnTranslator { case 'boolean_boolean': return 'boolean' - case 'object': case 'object_': case 'object_object': - case 'object_image': - case 'object_document': - case 'object_video': case 'object_any': - case 'object_audio': case 'object_mediagallery': case 'object_address': case 'object_pagelink': @@ -124,7 +127,7 @@ export default class SchemaColumnTranslator { case 'object_multireference': case 'object_arraystring': case 'object_arraydocument': - case 'object_richcontent': + case 'object_array': return 'json' default: diff --git a/libs/external-db-spanner/src/sql_schema_translator.spec.ts b/libs/external-db-spanner/src/sql_schema_translator.spec.ts index f931b34d9..4f4d94b0e 100644 --- a/libs/external-db-spanner/src/sql_schema_translator.spec.ts +++ b/libs/external-db-spanner/src/sql_schema_translator.spec.ts @@ -55,9 +55,17 @@ describe('Sql Schema Column Translator', () => { }) describe('string fields', () => { - test('string', () => { - expect( env.schemaTranslator.columnToDbColumnSql({ name: ctx.fieldName, type: 'text', subtype: 'string' }) ).toEqual(`${escapeId(ctx.fieldName)} STRING(2048)`) - }) + test.each([ + 'string', + 'richcontent', + 'image', + 'video', + 'audio', + 'document', + 'language', + ])('%s', (subtype) => { + expect( env.schemaTranslator.columnToDbColumnSql({ name: ctx.fieldName, type: 'text', subtype }) ).toEqual(`${escapeId(ctx.fieldName)} STRING(2048)`) + }) test('string with length', () => { expect( env.schemaTranslator.columnToDbColumnSql({ name: ctx.fieldName, type: 'text', subtype: 'string', precision: '2055' }) ).toEqual(`${escapeId(ctx.fieldName)} STRING(2055)`) @@ -88,20 +96,15 @@ describe('Sql Schema Column Translator', () => { describe('JSON fields', () => { test.each([ - ['object'], - ['image'], - ['document'], - ['video'], - ['audio'], - ['any'], - ['mediaGallery'], - ['address'], - ['pageLink'], - ['reference'], - ['multiReference'], - ['arrayString'], - ['arrayDocument'], - ['richContent'], + 'object', + 'any', + 'mediaGallery', + 'address', + 'pageLink', + 'reference', + 'multiReference', + 'arrayDocument', + 'arrayString', ])('%s', (subtype) => { expect(env.schemaTranslator.columnToDbColumnSql({ name: ctx.fieldName, type: 'object', subtype })).toEqual(`${escapeId(ctx.fieldName)} JSON`) }) diff --git a/libs/external-db-spanner/src/sql_schema_translator.ts b/libs/external-db-spanner/src/sql_schema_translator.ts index f47d61422..207547242 100644 --- a/libs/external-db-spanner/src/sql_schema_translator.ts +++ b/libs/external-db-spanner/src/sql_schema_translator.ts @@ -82,6 +82,11 @@ export default class SchemaColumnTranslator implements ISpannerSchemaColumnTrans return 'TIMESTAMP' case 'text_string': + case 'text_richcontent': + case 'text_image': + case 'text_video': + case 'text_audio': + case 'text_document': case 'text_language': return `STRING${this.parseLength(precision)}` @@ -92,7 +97,6 @@ export default class SchemaColumnTranslator implements ISpannerSchemaColumnTrans return `STRING${this.parseLength(2 ** 16)}` case 'text_large': - return `STRING${this.parseLength(2 ** 32)}` case 'boolean_': @@ -101,11 +105,7 @@ export default class SchemaColumnTranslator implements ISpannerSchemaColumnTrans case 'object_': case 'object_object': - case 'object_image': - case 'object_document': - case 'object_video': case 'object_any': - case 'object_audio': case 'object_mediagallery': case 'object_address': case 'object_pagelink': @@ -113,7 +113,7 @@ export default class SchemaColumnTranslator implements ISpannerSchemaColumnTrans case 'object_multireference': case 'object_arraystring': case 'object_arraydocument': - case 'object_richcontent': + case 'object_array': return 'JSON' default: diff --git a/libs/velo-external-db-core/src/router.ts b/libs/velo-external-db-core/src/router.ts index 820f2993f..bc7724679 100644 --- a/libs/velo-external-db-core/src/router.ts +++ b/libs/velo-external-db-core/src/router.ts @@ -101,9 +101,11 @@ export const createRouter = () => { }) router.post('/v3/capabilities/get', async(req, res) => { + const unsupportedFieldTypes = [ schemaSource.FieldType.arrayString, schemaSource.FieldType.reference, schemaSource.FieldType.multiReference, + schemaSource.FieldType.arrayDocument, schemaSource.FieldType.array ] const capabilitiesResponse = { supportsCollectionModifications: true, - supportedFieldTypes: ['TEXT', 'NUMBER', 'DATE', 'DATETIME', 'BOOLEAN'], + supportedFieldTypes: Object.values(schemaSource.FieldType).filter(t => !unsupportedFieldTypes.includes(t)), supportsCollectionDisplayName: false, supportsCollectionDisplayField: false, supportsCollectionPermissions: false, diff --git a/libs/velo-external-db-core/src/utils/schema_utils.spec.ts b/libs/velo-external-db-core/src/utils/schema_utils.spec.ts index 922be3657..176eca569 100644 --- a/libs/velo-external-db-core/src/utils/schema_utils.spec.ts +++ b/libs/velo-external-db-core/src/utils/schema_utils.spec.ts @@ -31,6 +31,12 @@ describe('Schema utils functions', () => { test('datetime type', () => { expect(fieldTypeToWixDataEnum('datetime')).toBe(VeloFieldTypeEnum.dataTime) }) + test('date type', () => { + expect(fieldTypeToWixDataEnum('date')).toBe(VeloFieldTypeEnum.date) + }) + test('time type', () => { + expect(fieldTypeToWixDataEnum('time')).toBe(VeloFieldTypeEnum.time) + }) test('unsupported type will throw an error', () => { expect(() => fieldTypeToWixDataEnum('unsupported-type')).toThrowError() @@ -47,15 +53,15 @@ describe('Schema utils functions', () => { [VeloFieldTypeEnum.dataTime, FieldType.datetime], [VeloFieldTypeEnum.time, FieldType.datetime], [VeloFieldTypeEnum.boolean, FieldType.boolean], - [VeloFieldTypeEnum.image, FieldType.object], - [VeloFieldTypeEnum.document, FieldType.object], - [VeloFieldTypeEnum.video, FieldType.object], + [VeloFieldTypeEnum.image, FieldType.text], + [VeloFieldTypeEnum.document, FieldType.text], + [VeloFieldTypeEnum.video, FieldType.text], [VeloFieldTypeEnum.any, FieldType.object], [VeloFieldTypeEnum.arrayString, FieldType.object], [VeloFieldTypeEnum.arrayDocument, FieldType.object], - [VeloFieldTypeEnum.audio, FieldType.object], + [VeloFieldTypeEnum.audio, FieldType.text], [VeloFieldTypeEnum.language, FieldType.text], - [VeloFieldTypeEnum.richContent, FieldType.object], + [VeloFieldTypeEnum.richContent, FieldType.text], [VeloFieldTypeEnum.mediaGallery, FieldType.object], [VeloFieldTypeEnum.address, FieldType.object], [VeloFieldTypeEnum.pageLink, FieldType.object], @@ -78,9 +84,9 @@ describe('Schema utils functions', () => { [VeloFieldTypeEnum.url, 'string'], [VeloFieldTypeEnum.richText, 'string'], [VeloFieldTypeEnum.number, 'float'], - [VeloFieldTypeEnum.date, 'datetime'], + [VeloFieldTypeEnum.date, 'date'], [VeloFieldTypeEnum.dataTime, 'datetime'], - [VeloFieldTypeEnum.time, 'datetime'], + [VeloFieldTypeEnum.time, 'time'], [VeloFieldTypeEnum.boolean, 'boolean'], [VeloFieldTypeEnum.image, 'image'], [VeloFieldTypeEnum.document, 'document'], diff --git a/libs/velo-external-db-core/src/utils/schema_utils.ts b/libs/velo-external-db-core/src/utils/schema_utils.ts index 97b4a823e..2ab45173b 100644 --- a/libs/velo-external-db-core/src/utils/schema_utils.ts +++ b/libs/velo-external-db-core/src/utils/schema_utils.ts @@ -20,7 +20,11 @@ export const fieldTypeToWixDataEnum = ( fieldType: string ): collectionSpi.Field return collectionSpi.FieldType.singleReference case FieldType.multiReference: return collectionSpi.FieldType.multiReference - + case FieldType.time: + return collectionSpi.FieldType.time + case FieldType.date: + return collectionSpi.FieldType.date + default: throw new Error(`${fieldType} - Unsupported field type`) } @@ -32,27 +36,27 @@ export const wixDataEnumToFieldType = (fieldEnum: collectionSpi.FieldType): stri case collectionSpi.FieldType.url: case collectionSpi.FieldType.richText: case collectionSpi.FieldType.language: + case collectionSpi.FieldType.richContent: + case collectionSpi.FieldType.image: + case collectionSpi.FieldType.video: + case collectionSpi.FieldType.document: + case collectionSpi.FieldType.audio: return FieldType.text case collectionSpi.FieldType.number: return FieldType.number + case collectionSpi.FieldType.time: case collectionSpi.FieldType.date: case collectionSpi.FieldType.dataTime: - case collectionSpi.FieldType.time: return FieldType.datetime case collectionSpi.FieldType.boolean: return FieldType.boolean - case collectionSpi.FieldType.image: - case collectionSpi.FieldType.document: - case collectionSpi.FieldType.video: case collectionSpi.FieldType.any: case collectionSpi.FieldType.arrayString: case collectionSpi.FieldType.arrayDocument: - case collectionSpi.FieldType.audio: - case collectionSpi.FieldType.richContent: case collectionSpi.FieldType.mediaGallery: case collectionSpi.FieldType.address: case collectionSpi.FieldType.pageLink: @@ -73,7 +77,7 @@ export const fieldTypeToSubtype = (fieldEnum: collectionSpi.FieldType): string = case collectionSpi.FieldType.url: case collectionSpi.FieldType.richText: return 'string' - + case collectionSpi.FieldType.language: return 'language' @@ -81,13 +85,14 @@ export const fieldTypeToSubtype = (fieldEnum: collectionSpi.FieldType): string = case collectionSpi.FieldType.number: return 'float' case collectionSpi.FieldType.date: + return 'date' case collectionSpi.FieldType.dataTime: - case collectionSpi.FieldType.time: return 'datetime' + case collectionSpi.FieldType.time: + return 'time' case collectionSpi.FieldType.boolean: return 'boolean' - // Object subtypes case collectionSpi.FieldType.image: return 'image' case collectionSpi.FieldType.document: diff --git a/libs/velo-external-db-types/src/collection_types.ts b/libs/velo-external-db-types/src/collection_types.ts index 7f16c03a6..524311bdc 100644 --- a/libs/velo-external-db-types/src/collection_types.ts +++ b/libs/velo-external-db-types/src/collection_types.ts @@ -20,6 +20,8 @@ export enum CollectionOperationSPI { // rename it export enum FieldType { text = 'text', + time = 'time', + date = 'date', number = 'number', boolean = 'boolean', datetime = 'datetime',