Registry / storage / verzod

verzod

JSON →
library0.5.1jsnpmunverified

A versioning and migration library for TypeScript/JavaScript based on Zod schemas. Current stable version is 0.5.1. Release cadence is irregular (v0.4.0 to v0.5.1 over several months). Key differentiator: defines versioned entities with Zod schemas and automatic migration, similar to SQL migrations but for arbitrary data.

npm install verzod
INSTALL
IMPORT
SIG · VERZOD
V
verzod
storagejavascriptv0.5.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createVersionedEntity
import { createVersionedEntity } from 'verzod'
const createVersionedEntity = require('verzod').createVersionedEntity
ESM-only; CommonJS require will fail. Use import statement.
InferredEntity
import { InferredEntity } from 'verzod'
import { InferredEntity } from 'verzod/InferredEntity'
Not a default export; named import only.
defineVersion
import { defineVersion } from 'verzod'
import { defineVersion } from 'verzod' is correct, but some may try 'verzod/defineVersion'
Named export from main package.

Demonstrates defining a versioned entity with two versions, an up-migration, and parsing/migrating old data.

import { createVersionedEntity, defineVersion, InferredEntity } from 'verzod' import { z } from 'zod' const V1 = z.object({ v: z.literal(1), name: z.string() }) const V2 = z.object({ v: z.literal(2), name: z.string(), count: z.number() }) const Entity = createVersionedEntity({ latestVersion: 2, versionMap: { 1: defineVersion({ initial: true, schema: V1 }), 2: defineVersion({ initial: false, schema: V2, up: (old: z.infer<typeof V1>) => ({ ...old, v: 2, count: 0 }) }) }, getVersion: (data: unknown) => (typeof data === 'object' && data !== null && 'v' in data && typeof (data as any).v === 'number') ? (data as any).v : null }) const data = { v: 1, name: 'test' } const parsed = Entity.safeParse(data) if (parsed.type === 'ok') { console.log(parsed.value) // Migrated to V2: { v: 2, name: 'test', count: 0 } } else { console.error('Parse error:', parsed.error) }
Debug
Known issues
breakingESM-only package: cannot use require() in Node.js.
fix
Use import syntax or set "type": "module" in package.json.
affects: >=0.0.0
gotchagetVersion must return a number or null; string or other types cause runtime errors.
fix
Ensure getVersion returns number | null.
affects: >=0.0.0
gotchaIf you do not provide an up migration for a non-initial version, safeParse will fail on old data.
fix
Always define `up` for non-initial versions.
affects: >=0.0.0
deprecatedVersions before 0.5.0 used different API for versionMap keys.
fix
Upgrade to >=0.5.0 and follow new API.
affects: <0.5.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module
Using CommonJS require() on ESM-only package.
fix
Switch to import syntax or use dynamic import().
TypeError: Entity.safeParse is not a function
Importing wrong export or using older version without safeParse.
fix
Ensure you import createVersionedEntity (not default export) and call it correctly.
ZodError: Expected number, received string
getVersion returns a string (e.g., '1') but versionMap keys are numbers.
fix
Return number from getVersion, e.g., Number(data.v) or parseInt(data.v, 10).
Upgrade
Version history
0.5.1latest on npm
Audit
Dependencies
zodrequiredPeer dependency: required to define schemas and validate data.
Agent activity
29 hits · last 30 days
node
26
OpenAI (training)
1
Resources
packageverzod
verzod — npm install verzod · libregistry