Schemas
zod
"TypeScript-first schema validation with static type inference"
Dependencies
npm install zodpnpm add zodyarn add zodImporting the schema
Generate your types
If you generate your types before writing validation, they will be available to help you define the constraint.
import { config } from "fatima";
import { z, ZodType } from "zod";
import { EnvKeys } from "env";
type Constraint = Partial<Record<EnvKeys, ZodType>>
const schema = z.object<Constraint>({
NODE_ENV: z.enum(["development", "production", "test"]),
TZ: z.string()
});
export default config({
schema
});Validate
To validate, just run the validate command:
npm fatima validatepnpm fatima validateyarn fatima validate