@@ -19,12 +19,7 @@ import {
1919 drizzleDataTypeToZeroType ,
2020 type ZeroTypeToTypescriptType ,
2121} from "./drizzle-to-zero" ;
22- import type {
23- ColumnNames ,
24- Columns ,
25- FindPrimaryKeyFromTable ,
26- HasCapital ,
27- } from "./types" ;
22+ import type { ColumnNames , Columns , FindPrimaryKeyFromTable } from "./types" ;
2823import { debugLog , typedEntries } from "./util" ;
2924
3025export type { ColumnBuilder , ReadonlyJSONValue , TableBuilderWithColumns } ;
@@ -72,9 +67,6 @@ export type ColumnsConfig<TTable extends Table> =
7267
7368/**
7469 * Maps a Drizzle column type to its corresponding Zero type.
75- * @template TTable The Drizzle table type
76- * @template KColumn The column name
77- * @template CD The column definition type
7870 */
7971type ZeroMappedColumnType <
8072 TTable extends Table ,
@@ -92,9 +84,6 @@ type ZeroMappedColumnType<
9284/**
9385 * Maps a Drizzle column to its corresponding TypeScript type in Zero.
9486 * Handles special cases like enums and custom types.
95- * @template TTable The Drizzle table type
96- * @template KColumn The column name
97- * @template CD The column definition type
9887 */
9988type ZeroMappedCustomType <
10089 TTable extends Table ,
@@ -118,63 +107,29 @@ type ZeroMappedCustomType<
118107
119108/**
120109 * Defines the structure of a column in the Zero schema.
121- * @template TTable The Drizzle table type
122- * @template KColumn The column name
123- * @template CD The column definition type
124110 */
125111type ZeroColumnDefinition <
126112 TTable extends Table ,
127113 KColumn extends ColumnNames < TTable > ,
128- TCasing extends ZeroTableCasing ,
129- CD extends ColumnDefinition < TTable , KColumn > [ "_" ] = ColumnDefinition <
130- TTable ,
131- KColumn
132- > [ "_" ] ,
133- BaseDefinition extends {
134- optional : false ;
135- type : ZeroMappedColumnType < TTable , KColumn > ;
136- customType : ZeroMappedCustomType < TTable , KColumn > ;
137- } = {
138- optional : false ;
139- type : ZeroMappedColumnType < TTable , KColumn > ;
140- customType : ZeroMappedCustomType < TTable , KColumn > ;
141- } ,
142- BaseOptional extends Omit < BaseDefinition , "optional" > & {
143- optional : true ;
144- } = Omit < BaseDefinition , "optional" > & { optional : true } ,
145- > = ( CD extends {
146- hasDefault : true ;
147- hasRuntimeDefault : false ;
148- }
149- ? BaseOptional
150- : CD extends { notNull : true }
151- ? BaseDefinition
152- : Omit < BaseDefinition , "optional" > & { optional : true } ) &
153- ( CD extends { name : KColumn }
154- ? TCasing extends "snake_case"
155- ? HasCapital < CD [ "name" ] > extends true
156- ? { serverName : string }
157- : { }
158- : TCasing extends "camelCase"
159- ? HasCapital < CD [ "name" ] > extends false
160- ? { serverName : string }
161- : { }
162- : { }
163- : { serverName : string } ) ;
114+ > = {
115+ optional : boolean ;
116+ type : ZeroMappedColumnType < TTable , KColumn > ;
117+ customType : ZeroMappedCustomType < TTable , KColumn > ;
118+ serverName ?: string ;
119+ } ;
164120
165121/**
166122 * Maps the columns configuration to their Zero schema definitions.
167123 */
168124export type ZeroColumns <
169125 TTable extends Table ,
170126 TColumnConfig extends ColumnsConfig < TTable > | undefined ,
171- TCasing extends ZeroTableCasing ,
172127> = {
173128 [ KColumn in ColumnNames < TTable > ] : KColumn extends keyof TColumnConfig
174129 ? TColumnConfig [ KColumn & keyof TColumnConfig ] extends ColumnBuilder < any >
175130 ? TColumnConfig [ KColumn & keyof TColumnConfig ] [ "schema" ]
176- : ZeroColumnDefinition < TTable , KColumn , TCasing >
177- : ZeroColumnDefinition < TTable , KColumn , TCasing > ;
131+ : ZeroColumnDefinition < TTable , KColumn >
132+ : ZeroColumnDefinition < TTable , KColumn > ;
178133} ;
179134
180135/**
@@ -184,13 +139,12 @@ export type ZeroTableBuilderSchema<
184139 TTableName extends string ,
185140 TTable extends Table ,
186141 TColumnConfig extends ColumnsConfig < TTable > | undefined ,
187- TCasing extends ZeroTableCasing ,
188142> = {
189143 name : TTableName ;
190144 primaryKey : FindPrimaryKeyFromTable < TTable > extends [ never ]
191145 ? readonly [ string , ...string [ ] ]
192146 : readonly [ string , ...string [ ] ] & FindPrimaryKeyFromTable < TTable > ;
193- columns : ZeroColumns < TTable , TColumnConfig , TCasing > ;
147+ columns : ZeroColumns < TTable , TColumnConfig > ;
194148} ; // Zero does not support this properly yet: & (TTable['_']['name'] extends TTableName ? {} : { serverName: string });
195149
196150/**
@@ -200,9 +154,8 @@ type ZeroTableBuilder<
200154 TTableName extends string ,
201155 TTable extends Table ,
202156 TColumnConfig extends ColumnsConfig < TTable > ,
203- TCasing extends ZeroTableCasing ,
204157> = TableBuilderWithColumns <
205- Readonly < ZeroTableBuilderSchema < TTableName , TTable , TColumnConfig , TCasing > >
158+ Readonly < ZeroTableBuilderSchema < TTableName , TTable , TColumnConfig > >
206159> ;
207160
208161/**
@@ -242,7 +195,7 @@ const createZeroTableBuilder = <
242195 * The casing to use for the table name.
243196 */
244197 casing ?: TCasing ,
245- ) : ZeroTableBuilder < TTableName , TTable , TColumnConfig , TCasing > => {
198+ ) : ZeroTableBuilder < TTableName , TTable , TColumnConfig > => {
246199 const actualTableName = getTableName ( table ) ;
247200 const tableColumns = getTableColumns ( table ) ;
248201 const tableConfig = getTableConfigForDatabase ( table ) ;
@@ -316,10 +269,10 @@ const createZeroTableBuilder = <
316269
317270 const type =
318271 drizzleColumnTypeToZeroType [
319- column . columnType as keyof DrizzleColumnTypeToZeroType
272+ column . columnType as keyof typeof drizzleColumnTypeToZeroType
320273 ] ??
321274 drizzleDataTypeToZeroType [
322- column . dataType as keyof DrizzleDataTypeToZeroType
275+ column . dataType as keyof typeof drizzleDataTypeToZeroType
323276 ] ??
324277 null ;
325278
@@ -394,8 +347,7 @@ const createZeroTableBuilder = <
394347 . primaryKey ( ...primaryKeys ) as ZeroTableBuilder <
395348 TTableName ,
396349 TTable ,
397- TColumnConfig ,
398- TCasing
350+ TColumnConfig
399351 > ;
400352} ;
401353
0 commit comments