Skip to content

greyllmmoder/zodrift

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

zodrift

npm version CI License: MIT

ESLint for TypeScript and Zod drift. Catch contract drift before it reaches runtime.

Built for teams that already have TS types and Zod schemas and want CI to fail when they drift.

import { z } from "zod";

export interface User {
  name: string;
  email?: string;
  age: number;
}

export const UserSchema = z.object({
  name: z.string(),
  email: z.string(),
  age: z.string(),
  role: z.string(),
});
npx zodrift check

zodrift fail-then-pass terminal demo

Fails CI on drift (exit 1), passes when synced (exit 0).

Example output:

✗ User ↔ UserSchema
  - optional mismatch for email: type=optional, schema=required
  - type mismatch for age: type=number, schema=string
  - extra in schema: role

What it catches:

  • missing fields
  • extra fields
  • required vs optional mismatch
  • basic type mismatch
  • semantic mismatch when your TS type is not assignable to z.input<typeof Schema> / z.output<typeof Schema> (optional mode)

Already supported:

  • nested object checks
  • arrays and tuples
  • union checks
  • JSON output and SARIF output

CI quick start:

- run: npx zodrift check --pattern "src/**/*.{ts,tsx}" --semantics both

Exit codes:

  • 0: no drift
  • 1: drift found
  • 2: parser/runtime error

Useful commands:

# Check current project
npx zodrift check --pattern "src/**/*.{ts,tsx}"

# Add semantic compatibility checks for z.input/z.output
npx zodrift check --pattern "src/**/*.{ts,tsx}" --semantics both

# Machine-readable report for CI artifacts
npx zodrift check --format json --out reports/zodrift.json

# SARIF for GitHub code scanning
npx zodrift check --format sarif --out reports/zodrift.sarif

# Safe autofix pass (dry-run first)
npx zodrift fix --pattern "src/**/*.ts" --dry-run

Roadmap:

  • deeper semantic coverage for Zod effects/refine/transform chains
  • strict bidirectional semantic mode
  • official GitHub Action wrapper with SARIF upload
  • config file support (.zodrift.json)
  • JUnit/Checkstyle reporters for enterprise CI

About

ESLint-style CI checker for TypeScript and Zod schema drift with semantic input/output checks.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors