npm package: @schemashift/zod-arktype
Description: Zod ↔ ArkType bidirectional transformer for SchemaShift
Author: Joseph May
Latest version: 0.14.0

# @schemashift/zod-arktype

Zod ↔ ArkType transformer for SchemaShift. Supports both forward (Zod → ArkType) and backward (ArkType → Zod) migrations.

[![npm version](https://img.shields.io/npm/v/@schemashift/zod-arktype.svg)](https://www.npmjs.com/package/@schemashift/zod-arktype)
[![npm downloads](https://img.shields.io/npm/dm/@schemashift/zod-arktype.svg)](https://www.npmjs.com/package/@schemashift/zod-arktype)
[![CI](https://github.com/jdmay2/schemashift/actions/workflows/ci.yml/badge.svg)](https://github.com/jdmay2/schemashift/actions/workflows/ci.yml)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)

**Tier:** Pro+

## Installation

```bash
npm install @schemashift/zod-arktype
```

## Usage

```typescript
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:

```typescript
z.object({ name: z.string().email(), age: z.number().int() })
```

ArkType uses a **TypeScript-like string** API:

```typescript
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:

```typescript
// Zod
z.string().refine((s) => s.length > 0, "Required");

// ArkType
type("string").narrow((s) => s.length > 0);
```

### `.transform()`

ArkType uses morphs via `.pipe()`:

```typescript
// Zod
z.string().transform((s) => s.toUpperCase());

// ArkType
type("string").pipe((s) => s.toUpperCase());
```

### Recursive Types

ArkType uses `scope()` for recursive definitions:

```typescript
// 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](https://www.npmjs.com/package/schemashift-cli) — CLI tool for running migrations
- [@schemashift/core](https://www.npmjs.com/package/@schemashift/core) — Core analysis engine
- [@schemashift/zod-valibot](https://www.npmjs.com/package/@schemashift/zod-valibot) — Zod ↔ Valibot transformer

## License

MIT