From 29740ad5b48a5121ac6b03d52d1e7632cb02c7fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20P=C3=A1rys?= Date: Wed, 8 Apr 2026 13:30:21 +0200 Subject: [PATCH] fix(bindx-form): use Contember ColumnType enum instead of PostgreSQL type strings Generator now emits normalized ColumnType values ('String', 'Integer', 'Double', etc.) instead of raw PostgreSQL types ('text', 'double precision', 'boolean'). This removes the need for the columnTypeAliases map in useFormInputHandler and prevents the class of bugs where a PostgreSQL alias was missing. --- .../bindx-client/src/schema/SchemaRegistry.ts | 6 ++++-- .../src/hooks/useFormInputHandler.ts | 18 +----------------- .../bindx-generator/src/NameSchemaGenerator.ts | 4 ++-- .../tests/entityGenerator.test.ts | 2 +- 4 files changed, 8 insertions(+), 22 deletions(-) diff --git a/packages/bindx-client/src/schema/SchemaRegistry.ts b/packages/bindx-client/src/schema/SchemaRegistry.ts index a3d68a4..17c19e7 100644 --- a/packages/bindx-client/src/schema/SchemaRegistry.ts +++ b/packages/bindx-client/src/schema/SchemaRegistry.ts @@ -38,7 +38,7 @@ export class SchemaRegistry = Record> = { Enum: createStringHandler, } -/** - * Maps Contember DB column types (lowercase) to ColumnType (PascalCase). - * Handles both formats so the handler works with schema-provided types. - */ -const columnTypeAliases: Record = { - text: 'String', - integer: 'Integer', - double: 'Double', - date: 'Date', - timestamptz: 'DateTime', - time: 'Time', - bool: 'Bool', - uuid: 'Uuid', - jsonb: 'Json', -} - function resolveColumnType(columnType: string | undefined): ColumnType | undefined { if (!columnType) return undefined - return (columnTypeAliases[columnType] ?? columnType) as ColumnType + return columnType as ColumnType } /** diff --git a/packages/bindx-generator/src/NameSchemaGenerator.ts b/packages/bindx-generator/src/NameSchemaGenerator.ts index fe03fff..cd511ea 100644 --- a/packages/bindx-generator/src/NameSchemaGenerator.ts +++ b/packages/bindx-generator/src/NameSchemaGenerator.ts @@ -54,8 +54,8 @@ export class NameSchemaGenerator { visitColumn: ctx => { scalars.push(ctx.column.name) fields[ctx.column.name] = ctx.column.type === Model.ColumnType.Enum - ? { type: 'column', columnType: ctx.column.columnType, enumName: ctx.column.columnType } - : { type: 'column', columnType: ctx.column.columnType } + ? { type: 'column', columnType: ctx.column.type, enumName: ctx.column.columnType } + : { type: 'column', columnType: ctx.column.type } }, }) diff --git a/packages/bindx-generator/tests/entityGenerator.test.ts b/packages/bindx-generator/tests/entityGenerator.test.ts index 3008218..49b4475 100644 --- a/packages/bindx-generator/tests/entityGenerator.test.ts +++ b/packages/bindx-generator/tests/entityGenerator.test.ts @@ -17,7 +17,7 @@ describe('NameSchemaGenerator', () => { expect(schema.entities['Post']?.fields['author']).toEqual({ type: 'one', entity: 'Author', nullable: false }) expect(schema.entities['Post']?.fields['tags']).toEqual({ type: 'many', entity: 'Tag', relationKind: 'manyHasMany', nullable: undefined }) - expect(schema.entities['Post']?.fields['title']).toEqual({ type: 'column', columnType: 'text' }) + expect(schema.entities['Post']?.fields['title']).toEqual({ type: 'column', columnType: 'String' }) expect(schema.enums['PostStatus']).toEqual(['draft', 'published', 'archived']) }) })