Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/bindx-client/src/schema/SchemaRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class SchemaRegistry<TModels extends Record<string, object> = Record<stri

for (const [fieldName, field] of entity.fields) {
if (field.__typename === '_Column') {
fields[fieldName] = { type: 'scalar' }
fields[fieldName] = { type: 'scalar', columnType: field.type }
} else if (field.__typename === '_Relation') {
const inverse = field.side === 'owning' ? field.inversedBy ?? undefined : field.ownedBy
const isMany = field.type === 'OneHasMany' || field.type === 'ManyHasMany'
Expand Down Expand Up @@ -281,6 +281,8 @@ interface RawContemberFieldDef {
readonly entity?: string
readonly target?: string
readonly inverse?: string
readonly columnType?: string
readonly enumName?: string
}

/**
Expand All @@ -295,7 +297,7 @@ function normalizeEntityDef(entityDef: EntitySchemaDef): EntitySchemaDef {
const raw = fieldDef as RawContemberFieldDef

if (raw.type === 'column') {
fields[fieldName] = { type: 'scalar' }
fields[fieldName] = { type: 'scalar', columnType: raw.columnType }
needsNormalization = true
} else if (raw.type === 'one') {
fields[fieldName] = {
Expand Down
18 changes: 1 addition & 17 deletions packages/bindx-form/src/hooks/useFormInputHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,25 +148,9 @@ const defaultTypeHandlers: Partial<Record<ColumnType, HandlerFactory>> = {
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<string, ColumnType> = {
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
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/bindx-generator/src/NameSchemaGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
},
})

Expand Down
2 changes: 1 addition & 1 deletion packages/bindx-generator/tests/entityGenerator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
})
})
Expand Down