Skip to content

Commit cc2ca82

Browse files
committed
Add fix for latest zod version
1 parent e338ccb commit cc2ca82

5 files changed

Lines changed: 203 additions & 101 deletions

File tree

drizzle-zod/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "drizzle-zod",
3-
"version": "0.8.0",
3+
"version": "0.8.1",
44
"description": "Generate Zod schemas from Drizzle ORM schemas",
55
"type": "module",
66
"scripts": {
@@ -65,7 +65,7 @@
6565
"license": "Apache-2.0",
6666
"peerDependencies": {
6767
"drizzle-orm": ">=0.36.0",
68-
"zod": "^3.25.0"
68+
"zod": "^3.25.1"
6969
},
7070
"devDependencies": {
7171
"@rollup/plugin-typescript": "^11.1.0",
@@ -77,7 +77,7 @@
7777
"rollup": "^3.29.5",
7878
"vite-tsconfig-paths": "^4.3.2",
7979
"vitest": "^3.1.3",
80-
"zod": "3.25.0-beta.20250516T044623",
80+
"zod": "3.25.1",
8181
"zx": "^7.2.2"
8282
}
8383
}

drizzle-zod/src/column.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,19 @@ import type {
5353
SingleStoreYear,
5454
} from 'drizzle-orm/singlestore-core';
5555
import type { SQLiteInteger, SQLiteReal, SQLiteText } from 'drizzle-orm/sqlite-core';
56-
import { z } from 'zod/v4';
5756
import { z as zod } from 'zod/v4';
5857
import { CONSTANTS } from './constants.ts';
5958
import type { CreateSchemaFactoryOptions } from './schema.types.ts';
6059
import { isColumnType, isWithEnum } from './utils.ts';
6160
import 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

6770
export 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
}

drizzle-zod/src/column.types.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ export type GetZodType<
2828
? z.ZodType<TColumn['_']['data'], TColumn['_']['data']>
2929
: z.ZodObject<
3030
{ [K in keyof TColumn['_']['data']]: GetZodPrimitiveType<TColumn['_']['data'][K], '', TCoerce> },
31-
{},
32-
{}
31+
{ out: {}; in: {} }
3332
>
3433
: TColumn['_']['dataType'] extends 'json' ? z.ZodType<Json>
3534
: GetZodPrimitiveType<TColumn['_']['data'], TColumn['_']['columnType'], TCoerce>;

drizzle-zod/src/schema.types.internal.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ export type BuildSchema<
5959
: z.ZodAny;
6060
}
6161
>,
62-
{},
63-
{}
62+
{ out: {}; in: {} }
6463
>;
6564

6665
export type NoUnknownKeys<

0 commit comments

Comments
 (0)