@schemashift/zod-superstruct
v0.14.0
Published
Zod ↔ Superstruct transformer for SchemaShift
Maintainers
Readme
@schemashift/zod-superstruct
Zod ↔ Superstruct transformer for SchemaShift. Supports both forward (Zod → Superstruct) and backward (Superstruct → Zod) migrations.
Tier: Pro+
Installation
npm install @schemashift/zod-superstructUsage
import { createZodToSuperstructHandler, createSuperstructToZodHandler } from '@schemashift/zod-superstruct';
import { TransformEngine } from '@schemashift/core';
const engine = new TransformEngine();
engine.registerHandler('zod', 'superstruct', createZodToSuperstructHandler());
engine.registerHandler('superstruct', 'zod', createSuperstructToZodHandler()); // Backward migration (Pro+)API Paradigm Difference
Zod uses a namespaced chain API:
z.object({ name: z.string().email(), age: z.number().int() })Superstruct uses bare function imports:
object({ name: refine(string(), "email", ...), age: integer() })Transformation Mappings
Imports
| Zod | Superstruct |
|-----|-------------|
| import { z } from 'zod' | import { object, string, ... } from 'superstruct' |
Factory Methods
| Zod | Superstruct |
|-----|-------------|
| z.string() | string() |
| z.number() | number() |
| z.boolean() | boolean() |
| z.date() | date() |
| z.bigint() | bigint() |
| z.any() | any() |
| z.unknown() | unknown() |
| z.never() | never() |
| z.object({...}) | object({...}) |
| z.array(s) | array(s) |
| z.enum(["a", "b"]) | enums(["a", "b"]) |
| z.literal(42) | literal(42) |
| z.union([a, b]) | union([a, b]) |
| z.record(k, v) | record(k, v) |
| z.tuple([a, b]) | tuple([a, b]) |
| z.number().int() | integer() |
Modifiers
| Zod | Superstruct |
|-----|-------------|
| .optional() | optional(X) |
| .nullable() | nullable(X) |
Type Helpers
| Zod | Superstruct |
|-----|-------------|
| z.infer<typeof s> | Infer<typeof s> |
Patterns Requiring Manual Review
.discriminatedUnion()
Superstruct has no discriminatedUnion. Use union() with explicit struct variants.
.transform() / .preprocess()
Superstruct uses coerce() for transforms:
// Zod
z.string().transform((s) => s.toUpperCase());
// Superstruct
coerce(string(), string(), (s) => s.toUpperCase());define() (Custom Validators)
// Superstruct
const Email = define('email', (v) => typeof v === 'string' && v.includes('@'));
// Zod
const Email = z.string().refine((v) => v.includes('@'));.brand()
Superstruct has no .brand() equivalent. Use define() with a branded type.
Related Packages
- schemashift-cli — CLI tool for running migrations
- @schemashift/core — Core analysis engine
- @schemashift/zod-valibot — Zod ↔ Valibot transformer
License
MIT
