vld-ts
Generate TypeScript Zod and Valibot schemas directly from vld schemas and types.
Overview
vld-ts is vld-first: use your vld schemas/types as the source of truth and generate frontend Zod/Valibot from them.
Installation
[]
= "0.1"
Quick start
use ;
schema!
schema!
impl_to_zod!;
impl_to_valibot!;
impl_to_openapi!;
impl_to_openapi!;
// From schema instance
let zod = to_zod;
assert!;
// From vld type (single schema expression, no imports/exports)
let order_zod = to_zod;
assert!;
assert!;
assert!;
// Valibot from schema instance
let single_valibot = to_valibot;
assert!;
assert!;
// Valibot from vld type (single schema expression, no imports/exports)
let order_valibot = to_valibot;
assert!;
assert!;
assert!;
// OpenAPI schema object from schema instance
let email_schema = to_openapi;
assert_eq!;
// OpenAPI schema object from vld type
let openapi_schema = to_openapi;
assert_eq!;
let refs = openapi_refs;
assert!;
let refs2 = to_refs;
assert!;
Generated output
// Auto-generated by vld-ts — do not edit manually
import { z } from "zod";
export const UserSchema = z.object({
name: z.string().min(2).max(50),
email: z.string().email(),
age: z.number().int().min(0).optional()
});
export type User = z.infer<typeof UserSchema>;
export const EmailSchema = z.string().email();
export type Email = z.infer<typeof EmailSchema>;
// Auto-generated by vld-ts — do not edit manually
import * as v from "valibot";
export const UserSchema = v.objectWithRest({
name: v.pipe(v.string(), v.minLength(2), v.maxLength(50)),
email: v.pipe(v.string(), v.email())
}, v.unknown());
export type User = v.InferOutput<typeof UserSchema>;
Supported output features
| JSON Schema | Zod output |
|---|---|
type: "string" |
z.string() |
type: "number" |
z.number() |
type: "integer" |
z.number().int() |
type: "boolean" |
z.boolean() |
type: "null" |
z.null() |
type: "array" |
z.array(...) |
type: "object" |
z.object({...}) |
oneOf |
z.union([...]) |
allOf |
z.intersection(...) |
anyOf |
z.union([...]) |
enum |
z.literal(...) / z.union() |
format: "email" |
.email() |
format: "uuid" |
.uuid() |
format: "date"/"date-time" |
.date() / .datetime() |
minLength/maxLength |
.min()/.max() |
minimum/maximum |
.min()/.max() |
pattern |
.regex() |
description |
.describe() |
nullable (oneOf + null) |
.nullable() |
$ref to named schemas |
z.lazy(() => NameSchema) |
Examples
License
MIT