@schemashift/zod-arktype
v0.14.0
Published
Zod ↔ ArkType bidirectional transformer for SchemaShift
Maintainers
Readme
@schemashift/zod-arktype
Zod ↔ ArkType transformer for SchemaShift. Supports both forward (Zod → ArkType) and backward (ArkType → Zod) migrations.
Tier: Pro+
Installation
npm install @schemashift/zod-arktypeUsage
import { createZodToArktypeHandler, createArktypeToZodHandler } from '@schemashift/zod-arktype';
import { TransformEngine } from '@schemashift/core';
const engine = new TransformEngine();
engine.registerHandler('zod', 'arktype', createZodToArktypeHandler());
engine.registerHandler('arktype', 'zod', createArktypeToZodHandler()); // Backward migration (Pro+)API Paradigm Difference
Zod uses a method chain API:
z.object({ name: z.string().email(), age: z.number().int() })ArkType uses a TypeScript-like string API:
type({ name: "string.email", age: "number.integer" })Transformation Mappings
Imports
| Zod | ArkType |
|-----|---------|
| import { z } from 'zod' | import { type } from 'arktype' |
Factory Methods
| Zod | ArkType |
|-----|---------|
| z.string() | "string" |
| z.number() | "number" |
| z.boolean() | "boolean" |
| z.bigint() | "bigint" |
| z.date() | "Date" |
| z.unknown() | "unknown" |
| z.never() | "never" |
| z.null() | "null" |
| z.void() | "void" |
| z.any() | "unknown" |
| z.object({...}) | type({...}) |
| z.array(s) | "s[]" |
| z.enum(["a", "b"]) | type("'a' \| 'b'") |
| z.literal(42) | type("=== 42") |
| z.union([a, b]) | type("a \| b") |
| z.record(k, v) | type("Record<k, v>") |
Validations
| Zod | ArkType |
|-----|---------|
| z.string().email() | "string.email" |
| z.string().url() | "string.url" |
| z.string().uuid() | "string.uuid" |
| z.string().ip() | "string.ip" |
| z.number().int() | "number.integer" |
Modifiers
| Zod | ArkType |
|-----|---------|
| .optional() | "type?" |
| .nullable() | "type \| null" |
Type Helpers
| Zod | ArkType |
|-----|---------|
| z.infer<typeof s> | typeof s.infer |
| z.input<typeof s> | typeof s.in |
| z.output<typeof s> | typeof s.infer |
Patterns Requiring Manual Review
.superRefine() / .refine()
ArkType uses .narrow() for refinements:
// Zod
z.string().refine((s) => s.length > 0, "Required");
// ArkType
type("string").narrow((s) => s.length > 0);.transform()
ArkType uses morphs via .pipe():
// Zod
z.string().transform((s) => s.toUpperCase());
// ArkType
type("string").pipe((s) => s.toUpperCase());Recursive Types
ArkType uses scope() for recursive definitions:
// Zod
const node: z.ZodType<Node> = z.lazy(() => z.object({ children: z.array(node) }));
// ArkType
const types = scope({ node: { children: "node[]" } }).export();.brand()
ArkType has no .brand() equivalent. Use nominal types or tagged unions instead.
Related Packages
- schemashift-cli — CLI tool for running migrations
- @schemashift/core — Core analysis engine
- @schemashift/zod-valibot — Zod ↔ Valibot transformer
License
MIT
