{"id":31029034,"url":"https://github.com/formkit/zodown","last_synced_at":"2025-09-13T21:58:13.491Z","repository":{"id":313260048,"uuid":"1050700208","full_name":"formkit/zodown","owner":"formkit","description":"Zod 4 to Zod 3 runtime converter","archived":false,"fork":false,"pushed_at":"2025-09-04T22:11:14.000Z","size":100,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-04T22:25:33.828Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/formkit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-04T19:58:11.000Z","updated_at":"2025-09-04T22:11:16.000Z","dependencies_parsed_at":"2025-09-04T22:25:36.563Z","dependency_job_id":"6699bb4b-0156-4e7b-86e5-d768438a0096","html_url":"https://github.com/formkit/zodown","commit_stats":null,"previous_names":["formkit/zodown"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/formkit/zodown","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/formkit%2Fzodown","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/formkit%2Fzodown/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/formkit%2Fzodown/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/formkit%2Fzodown/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/formkit","download_url":"https://codeload.github.com/formkit/zodown/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/formkit%2Fzodown/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275032803,"owners_count":25393761,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-13T02:00:10.085Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-09-13T21:58:11.636Z","updated_at":"2025-09-13T21:58:13.464Z","avatar_url":"https://github.com/formkit.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# zodown\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://www.npmjs.com/package/zodown\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/zodown.svg?style=flat-square\" alt=\"npm version\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/formkit/zodown/actions\"\u003e\u003cimg src=\"https://img.shields.io/github/actions/workflow/status/formkit/zodown/ci.yml?branch=main\u0026style=flat-square\" alt=\"build status\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/zodown\"\u003e\u003cimg src=\"https://img.shields.io/npm/dm/zodown.svg?style=flat-square\" alt=\"npm downloads\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/formkit/zodown/blob/main/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/npm/l/zodown.svg?style=flat-square\" alt=\"license\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003e Write Zod v4 schemas, run them in Zod v3 environments\n\n## The Problem\n\nMany popular libraries still depend on Zod v3 (like `@modelcontextprotocol/sdk`), but you want to use the latest Zod v4 features and stay current with the ecosystem. Version conflicts force you to choose between modern schemas and library compatibility.\n\n## The Solution\n\n`zodown` converts Zod v4 schemas to functionally equivalent Zod v3 schemas at runtime, preserving all validations, refinements, and type safety. Write modern code, maintain compatibility.\n\n## Installation\n\n```bash\nnpm install zodown\n# or\npnpm add zodown\n# or\nyarn add zodown\n```\n\n**Note:** zodown includes Zod v4 built-in and handles Zod v3 conversion internally. You don't need to install Zod separately!\n\n## Usage\n\n```typescript\nimport { z, zodown } from 'zodown' // Includes Zod v4!\n\n// Write modern Zod v4 schemas\nconst UserSchema = z.object({\n  email: z.string().email(),\n  age: z.number().int().positive(),\n  role: z.enum(['admin', 'user']),\n  metadata: z.record(z.unknown()).optional(),\n})\n\n// Convert for Zod v3 compatibility\nconst v3Schema = zodown(UserSchema)\n\n// Use with libraries that require Zod v3\nimport { Client } from '@modelcontextprotocol/sdk'\nconst client = new Client({\n  schema: v3Schema, // Works perfectly!\n})\n```\n\n## Features\n\n✅ **Complete Type Support** - All Zod types including primitives, objects, arrays, unions, intersections, and more  \n✅ **Validation Preservation** - All refinements, transforms, and custom validations are maintained  \n✅ **Type Safety** - Full TypeScript support with proper type inference  \n✅ **Circular References** - Handles recursive schemas with WeakMap caching  \n✅ **Zero Configuration** - Just wrap your schema with `zodown()`  \n✅ **Lightweight** - ~1.3KB gzipped converter logic\n\n## Supported Types\n\n`zodown` supports all Zod v4 types:\n\n- **Primitives**: string, number, boolean, date, bigint, symbol, undefined, null, void, any, unknown, never\n- **Literals**: literal values, enums, native enums\n- **Strings**: with all refinements (email, url, uuid, regex, length constraints, etc.)\n- **Numbers**: with all refinements (int, positive, min/max, multipleOf, finite)\n- **Complex Types**: objects, arrays, tuples, records, maps, sets\n- **Compositions**: unions, intersections, optional, nullable, default\n- **Advanced**: lazy (recursive), promise, function, transform, refine, preprocess\n- **Effects**: Custom refinements and transformations\n\n## Examples\n\n### Basic Schema\n\n```typescript\nimport { z, zodown } from 'zodown'\n\nconst ProductSchema = z.object({\n  id: z.string().uuid(),\n  name: z.string().min(1).max(100),\n  price: z.number().positive(),\n  tags: z.array(z.string()),\n})\n\nconst v3Product = zodown(ProductSchema)\n```\n\n### With Refinements\n\n```typescript\nimport { z, zodown } from 'zodown'\n\nconst PasswordSchema = z\n  .string()\n  .min(8)\n  .regex(/[A-Z]/, 'Must contain uppercase')\n  .regex(/[0-9]/, 'Must contain number')\n  .refine((val) =\u003e !commonPasswords.includes(val), 'Too common')\n\nconst v3Password = zodown(PasswordSchema)\n```\n\n### Recursive Schema\n\n```typescript\nimport { z, zodown, ZodType } from 'zodown'\n\nconst CategorySchema: ZodType\u003cCategory\u003e = z.lazy(() =\u003e\n  z.object({\n    name: z.string(),\n    subcategories: z.array(CategorySchema).optional(),\n  })\n)\n\nconst v3Category = zodown(CategorySchema)\n```\n\n### With Transform\n\n```typescript\nimport { z, zodown } from 'zodown'\n\nconst DateSchema = z\n  .string()\n  .transform((str) =\u003e new Date(str))\n  .refine((date) =\u003e !isNaN(date.getTime()), 'Invalid date')\n\nconst v3Date = zodown(DateSchema)\n```\n\n## API\n\n### `zodown(schema)`\n\nConverts a Zod v4 schema to a Zod v3 schema.\n\n- **Parameters**: `schema` - Any Zod v4 schema\n- **Returns**: Equivalent Zod v3 schema\n- **Type Safety**: Preserves full type inference\n\n### `InferDowngraded\u003cT\u003e`\n\nType helper for extracting the inferred type from a downgraded schema.\n\n```typescript\nimport type { InferDowngraded } from 'zodown'\n\nconst Schema = z.object({ name: z.string() })\ntype User = InferDowngraded\u003ctypeof Schema\u003e // { name: string }\n```\n\n## Limitations\n\nWhile `zodown` handles most Zod v4 features, there are some limitations due to architectural differences between v3 and v4:\n\n### Features That Cannot Be Converted\n\n1. **`.refine()` and `.superRefine()` on base types** - In Zod v4, these are compiled into internal check functions that cannot be reverse-engineered. The base schema is returned without the refinement.\n\n2. **Branded types** - Zod v4 implements branding as a compile-time TypeScript feature with no runtime representation, while v3 expects runtime `ZodBranded` instances. Branded schemas are returned as their base type.\n\n3. **Variable-length tuples with optional elements** - Zod v4 allows tuples like `[string, number?]` to have variable length, but v3 requires fixed length with `undefined` for optional elements.\n\n### Workarounds\n\nIf you need these features, consider:\n\n- Using transforms instead of refinements where possible\n- Implementing validation logic outside of Zod\n- Using v3-compatible patterns from the start\n\n### Example of Limitations\n\n```typescript\n// These v4 features have limitations:\n\n// ❌ Refinements are lost\nconst v4Refined = z.number().refine((n) =\u003e n % 2 === 0)\nconst v3Refined = zodown(v4Refined) // Returns ZodNumber without refinement\n\n// ❌ Brands become base types\nconst v4Branded = z.string().brand\u003c'UserId'\u003e()\nconst v3Branded = zodown(v4Branded) // Returns ZodString, not ZodBranded\n\n// ❌ Optional tuple elements need all positions\nconst v4Tuple = z.tuple([z.string(), z.number().optional()])\nconst v3Tuple = zodown(v4Tuple)\nv3Tuple.parse(['hi', undefined]) // ✅ Works\nv3Tuple.parse(['hi']) // ❌ Fails - v3 needs fixed length\n```\n\n## Use Cases\n\n- 📦 Using `@modelcontextprotocol/sdk` with modern Zod schemas\n- 🔄 Gradually migrating large codebases from Zod v3 to v4\n- 📚 Maintaining libraries that need to support both versions\n- 🛠️ Working with tools that haven't updated to Zod v4 yet\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request. See [CONTRIBUTING.md](./CONTRIBUTING.md) for details.\n\n## License\n\nMIT © Justin Schroeder\n\n## Acknowledgments\n\nBuilt with necessity for the [Model Context Protocol SDK](https://github.com/anthropics/model-context-protocol) and the many other libraries still on Zod v3.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fformkit%2Fzodown","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fformkit%2Fzodown","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fformkit%2Fzodown/lists"}