Skip to content

Investigate Zod 4 API integration opportunities #8

@brainkim

Description

@brainkim

Summary

Survey Zod 4 APIs for potential integration or documentation with zen.

APIs to Investigate

Potentially Useful

  • z.codec() - Bidirectional transforms. Works with .db.type() but requires manual null handling. May be worth documenting as advanced pattern.

  • z.instanceof() - For class instances (e.g., z.instanceof(Date)). Could be relevant for custom types.

  • z.json() - Explicit JSON schema type. Currently we infer JSON from z.object()/z.array().

  • .brand() - Typed IDs (UserId vs PostId). Already works, just undocumented.

  • .readonly() - Freeze objects. Could auto-apply to query results.

  • z.stringbool() - String to boolean coercion. Relevant for form inputs.

  • z.file() - File/Blob handling. Could map to BLOB columns.

  • z.iso.datetime() - ISO string dates. Works already (it's just a string with validation).

Already Evaluated

  • .default() - Banned intentionally. Applies at parse-time, not write-time. Use .db.inserted() instead.

Current Conclusions

  • .db.encode()/.db.decode() is simpler than codecs for database use cases (auto-handles null)
  • No breaking changes needed
  • Some features may warrant documentation

Questions

  1. Should we document codec usage as an advanced pattern?
  2. Any utility in explicit z.json() support vs inference?
  3. Worth documenting .brand() for typed IDs?

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions