Skip to content

Commit 0cd20b6

Browse files
Merge pull request #3944 from L-Mario564/export-internals
[Validators] Export `BuildSchema` type and simplify JSON schema
2 parents 3dff816 + 0e56bba commit 0cd20b6

File tree

9 files changed

+10
-11
lines changed

9 files changed

+10
-11
lines changed

drizzle-typebox/src/column.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ import { isColumnType, isWithEnum } from './utils.ts';
6060
import type { BufferSchema, JsonSchema } from './utils.ts';
6161

6262
export const literalSchema = t.Union([t.String(), t.Number(), t.Boolean(), t.Null()]);
63-
export const jsonSchema: JsonSchema = t.Recursive((self) =>
64-
t.Union([literalSchema, t.Array(self), t.Record(t.String(), self)])
65-
) as any;
63+
export const jsonSchema: JsonSchema = t.Union([literalSchema, t.Array(t.Any()), t.Record(t.String(), t.Any())]) as any;
6664
TypeRegistry.Set('Buffer', (_, value) => value instanceof Buffer); // eslint-disable-line no-instanceof/no-instanceof
6765
export const bufferSchema: BufferSchema = { [Kind]: 'Buffer', type: 'buffer' } as any;
6866

drizzle-typebox/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './schema.ts';
2+
export type { BuildSchema } from './schema.types.internal.ts';
23
export * from './schema.types.ts';

drizzle-typebox/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function isWithEnum(column: Column): column is typeof column & { enumValu
1414
export const isPgEnum: (entity: any) => entity is PgEnum<[string, ...string[]]> = isWithEnum as any;
1515

1616
type Literal = Static<typeof literalSchema>;
17-
export type Json = Literal | { [key: string]: Json } | Json[];
17+
export type Json = Literal | { [key: string]: any } | any[];
1818
export interface JsonSchema extends TSchema {
1919
[Kind]: 'Union';
2020
static: Json;

drizzle-valibot/src/column.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ import type { Json } from './utils.ts';
6161
export const literalSchema = v.union([v.string(), v.number(), v.boolean(), v.null()]);
6262
export const jsonSchema: v.GenericSchema<Json> = v.union([
6363
literalSchema,
64-
v.array(v.lazy(() => jsonSchema)),
65-
v.record(v.string(), v.lazy(() => jsonSchema)),
64+
v.array(v.any()),
65+
v.record(v.string(), v.any()),
6666
]);
6767
export const bufferSchema: v.GenericSchema<Buffer> = v.custom<Buffer>((v) => v instanceof Buffer); // eslint-disable-line no-instanceof/no-instanceof
6868

drizzle-valibot/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './schema.ts';
2+
export type { BuildSchema } from './schema.types.internal.ts';
23
export * from './schema.types.ts';

drizzle-valibot/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function isWithEnum(column: Column): column is typeof column & { enumValu
1414
export const isPgEnum: (entity: any) => entity is PgEnum<[string, ...string[]]> = isWithEnum as any;
1515

1616
type Literal = v.InferOutput<typeof literalSchema>;
17-
export type Json = Literal | { [key: string]: Json } | Json[];
17+
export type Json = Literal | { [key: string]: any } | any[];
1818

1919
export type IsNever<T> = [T] extends [never] ? true : false;
2020

drizzle-zod/src/column.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ import { isColumnType, isWithEnum } from './utils.ts';
6161
import type { Json } from './utils.ts';
6262

6363
export const literalSchema = z.union([z.string(), z.number(), z.boolean(), z.null()]);
64-
export const jsonSchema: z.ZodType<Json> = z.lazy(() =>
65-
z.union([literalSchema, z.array(jsonSchema), z.record(jsonSchema)])
66-
);
64+
export const jsonSchema: z.ZodType<Json> = z.union([literalSchema, z.record(z.any()), z.array(z.any())]);
6765
export const bufferSchema: z.ZodType<Buffer> = z.custom<Buffer>((v) => v instanceof Buffer); // eslint-disable-line no-instanceof/no-instanceof
6866

6967
export function columnToSchema(column: Column, factory: CreateSchemaFactoryOptions | undefined): z.ZodTypeAny {

drizzle-zod/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './schema.ts';
2+
export type { BuildSchema } from './schema.types.internal.ts';
23
export * from './schema.types.ts';

drizzle-zod/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function isWithEnum(column: Column): column is typeof column & { enumValu
1414
export const isPgEnum: (entity: any) => entity is PgEnum<[string, ...string[]]> = isWithEnum as any;
1515

1616
type Literal = z.infer<typeof literalSchema>;
17-
export type Json = Literal | { [key: string]: Json } | Json[];
17+
export type Json = Literal | { [key: string]: any } | any[];
1818

1919
export type IsNever<T> = [T] extends [never] ? true : false;
2020

0 commit comments

Comments
 (0)