2022-04-01 21:03:03 +00:00
|
|
|
import { z } from "zod";
|
|
|
|
|
|
|
|
// Helper schema for JSON fields
|
|
|
|
type Literal = boolean | number | string;
|
|
|
|
type Json = Literal | { [key: string]: Json } | Json[];
|
|
|
|
const literalSchema = z.union([z.string(), z.number(), z.boolean()]);
|
|
|
|
export const jsonSchema: z.ZodSchema<Json> = z.lazy(() =>
|
2022-05-18 15:46:22 +00:00
|
|
|
z.union([literalSchema, z.array(jsonSchema), z.record(jsonSchema)]).or(z.null())
|
2022-04-01 21:03:03 +00:00
|
|
|
);
|