From 9cfad467e2112725264ca2d3e15a3766eb266e0c Mon Sep 17 00:00:00 2001 From: Guillem Puche <3519924+guillempuche@users.noreply.github.com> Date: Tue, 18 Jun 2024 18:01:15 +0200 Subject: [PATCH] fix(core): solve TupleType when converting Powersync types --- packages/core/src/to_schema.effect.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/core/src/to_schema.effect.ts b/packages/core/src/to_schema.effect.ts index 57ec224..8fa1245 100644 --- a/packages/core/src/to_schema.effect.ts +++ b/packages/core/src/to_schema.effect.ts @@ -71,21 +71,22 @@ export function toPowerSyncColumnType(ast: AST.AST): ColumnType { throw new Error(`Unsupported union of column types: ${types.join(', ')}`) } case 'TupleType': { - if (ast.elements.length === 0) { - // throw new Error('Empty tuple types are not supported') + const allTypes = [ + ...ast.elements.map(e => toPowerSyncColumnType(e.type)), + ...ast.rest.map(a => toPowerSyncColumnType(a)), + ] + if (allTypes.length === 0) { + throw new Error('Empty tuple types are not supported') } - // Map each element's type and determine the column type accordingly - const elementTypes = ast.elements.map(e => toPowerSyncColumnType(e.type)) - const uniqueTypes = Array.from(new Set(elementTypes)) + const uniqueTypes = Array.from(new Set(allTypes)) if (uniqueTypes.length === 1) { return uniqueTypes[0] } - // throw new Error( - // `Unsupported tuple of mixed column types: ${uniqueTypes.join(', ')}`, - // ) - return ColumnType.TEXT + throw new Error( + `Unsupported tuple of mixed column types: ${uniqueTypes.join(', ')}`, + ) } default: return unknownColumnTypeError(ast)