@@ -53,16 +53,19 @@ import type {
5353 SingleStoreYear ,
5454} from 'drizzle-orm/singlestore-core' ;
5555import type { SQLiteInteger , SQLiteReal , SQLiteText } from 'drizzle-orm/sqlite-core' ;
56- import { z } from 'zod/v4' ;
5756import { z as zod } from 'zod/v4' ;
5857import { CONSTANTS } from './constants.ts' ;
5958import type { CreateSchemaFactoryOptions } from './schema.types.ts' ;
6059import { isColumnType , isWithEnum } from './utils.ts' ;
6160import type { Json } from './utils.ts' ;
6261
63- export const literalSchema = z . union ( [ z . string ( ) , z . number ( ) , z . boolean ( ) , z . null ( ) ] ) ;
64- export const jsonSchema : z . ZodType < Json > = z . union ( [ literalSchema , z . record ( z . string ( ) , z . any ( ) ) , z . array ( z . any ( ) ) ] ) ;
65- export const bufferSchema : z . ZodType < Buffer > = z . custom < Buffer > ( ( v ) => v instanceof Buffer ) ; // eslint-disable-line no-instanceof/no-instanceof
62+ export const literalSchema = zod . union ( [ zod . string ( ) , zod . number ( ) , zod . boolean ( ) , zod . null ( ) ] ) ;
63+ export const jsonSchema : zod . ZodType < Json > = zod . union ( [
64+ literalSchema ,
65+ zod . record ( zod . string ( ) , zod . any ( ) ) ,
66+ zod . array ( zod . any ( ) ) ,
67+ ] ) ;
68+ export const bufferSchema : zod . ZodType < Buffer > = zod . custom < Buffer > ( ( v ) => v instanceof Buffer ) ; // eslint-disable-line no-instanceof/no-instanceof
6669
6770export function columnToSchema (
6871 column : Column ,
@@ -71,10 +74,10 @@ export function columnToSchema(
7174 Partial < Record < 'bigint' | 'boolean' | 'date' | 'number' | 'string' , true > > | true | undefined
7275 >
7376 | undefined ,
74- ) : z . ZodType {
77+ ) : zod . ZodType {
7578 const z : typeof zod = factory ?. zodInstance ?? zod ;
7679 const coerce = factory ?. coerce ?? { } ;
77- let schema ! : z . ZodType ;
80+ let schema ! : zod . ZodType ;
7881
7982 if ( isWithEnum ( column ) ) {
8083 schema = column . enumValues . length ? z . enum ( column . enumValues ) : z . string ( ) ;
@@ -90,7 +93,7 @@ export function columnToSchema(
9093 schema = z . object ( { x : z . number ( ) , y : z . number ( ) } ) ;
9194 } else if ( isColumnType < PgHalfVector < any > | PgVector < any > > ( column , [ 'PgHalfVector' , 'PgVector' ] ) ) {
9295 schema = z . array ( z . number ( ) ) ;
93- schema = column . dimensions ? ( schema as z . ZodArray < any > ) . length ( column . dimensions ) : schema ;
96+ schema = column . dimensions ? ( schema as zod . ZodArray < any > ) . length ( column . dimensions ) : schema ;
9497 } else if ( isColumnType < PgLineTuple < any > > ( column , [ 'PgLine' ] ) ) {
9598 schema = z . tuple ( [ z . number ( ) , z . number ( ) , z . number ( ) ] ) ;
9699 } else if ( isColumnType < PgLineABC < any > > ( column , [ 'PgLineABC' ] ) ) {
@@ -102,7 +105,7 @@ export function columnToSchema(
102105 } // Handle other types
103106 else if ( isColumnType < PgArray < any , any > > ( column , [ 'PgArray' ] ) ) {
104107 schema = z . array ( columnToSchema ( column . baseColumn , factory ) ) ;
105- schema = column . size ? ( schema as z . ZodArray < any > ) . length ( column . size ) : schema ;
108+ schema = column . size ? ( schema as zod . ZodArray < any > ) . length ( column . size ) : schema ;
106109 } else if ( column . dataType === 'array' ) {
107110 schema = z . array ( z . any ( ) ) ;
108111 } else if ( column . dataType === 'number' ) {
@@ -137,7 +140,7 @@ function numberColumnToSchema(
137140 coerce : CreateSchemaFactoryOptions <
138141 Partial < Record < 'bigint' | 'boolean' | 'date' | 'number' | 'string' , true > > | true | undefined
139142 > [ 'coerce' ] ,
140- ) : z . ZodType {
143+ ) : zod . ZodType {
141144 let unsigned = column . getSQLType ( ) . includes ( 'unsigned' ) ;
142145 let min ! : number ;
143146 let max ! : number ;
@@ -252,7 +255,7 @@ function bigintColumnToSchema(
252255 coerce : CreateSchemaFactoryOptions <
253256 Partial < Record < 'bigint' | 'boolean' | 'date' | 'number' | 'string' , true > > | true | undefined
254257 > [ 'coerce' ] ,
255- ) : z . ZodType {
258+ ) : zod . ZodType {
256259 const unsigned = column . getSQLType ( ) . includes ( 'unsigned' ) ;
257260 const min = unsigned ? 0n : CONSTANTS . INT64_MIN ;
258261 const max = unsigned ? CONSTANTS . INT64_UNSIGNED_MAX : CONSTANTS . INT64_MAX ;
@@ -267,7 +270,7 @@ function stringColumnToSchema(
267270 coerce : CreateSchemaFactoryOptions <
268271 Partial < Record < 'bigint' | 'boolean' | 'date' | 'number' | 'string' , true > > | true | undefined
269272 > [ 'coerce' ] ,
270- ) : z . ZodType {
273+ ) : zod . ZodType {
271274 if ( isColumnType < PgUUID < ColumnBaseConfig < 'string' , 'PgUUID' > > > ( column , [ 'PgUUID' ] ) ) {
272275 return z . uuid ( ) ;
273276 }
0 commit comments