Skip to content

fix: remove validation on reads, matching documented behavior#16

Merged
brainkim merged 2 commits intomainfrom
fix/no-validation-on-reads
Jan 3, 2026
Merged

fix: remove validation on reads, matching documented behavior#16
brainkim merged 2 commits intomainfrom
fix/no-validation-on-reads

Conversation

@brainkim
Copy link
Copy Markdown
Member

@brainkim brainkim commented Jan 3, 2026

Summary

  • Remove validateWithStandardSchema call during reads in buildEntityMap
  • Update tests to use z.date()/z.boolean()/z.number() instead of z.coerce.*
  • Zen's decodeData handles DB→JS type conversion (dates, booleans, JSON)
  • Zod coerce/transform only runs on writes, not reads

Background

The README states "Zod validation happens on writes, never on reads" but validation was running during normalize() via buildEntityMap(). This caused ValidationError when reading data written with an older schema version.

Data flow:

  • Writes: App → Zod parse (validate + coerce/transform) → Zen encode → DB
  • Reads: DB → Zen decode → App (no Zod)

Zen's decodeData handles all DB→JS conversions:

  • Date strings → Date objects
  • 0/1 → booleans
  • JSON strings → objects/arrays

Users should use z.date() not z.coerce.date() — Zen handles the conversion.

Test plan

  • All 584 tests pass
  • Type checking passes

Fixes #14

🤖 Generated with Claude Code

brainkim and others added 2 commits January 3, 2026 16:58
The README states "Zod validation happens on writes, never on reads" but
validation was running during normalize() via buildEntityMap().

This caused ValidationError when reading data written with an older schema
version, breaking the forward-only migration pattern.

Changes:
- Remove validateWithStandardSchema call in buildEntityMap
- Update tests to use z.date()/z.boolean()/z.number() instead of z.coerce.*
- Zen's decodeData handles DB→JS type conversion (dates, booleans, JSON)
- Zod coerce/transform only runs on writes, not reads

Fixes #14

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@brainkim brainkim merged commit 24a1777 into main Jan 3, 2026
1 check passed
@brainkim brainkim deleted the fix/no-validation-on-reads branch January 3, 2026 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Validation runs on read despite documentation stating otherwise

1 participant