CodeVetter · Repo Unpack · Extension points
colinhacks/zod
Zod is extensible primarily through schema constructors, structural internals, checks, registries, callbacks, and JSON Schema processors rather than a separately loaded plugin system. Classic and mini are examples of alternate facades over the same core factory and trait machinery. Public extension hooks coexist with internal hooks such as the global construction post-processor, so consumers should distinguish supported APIs from implementation seams. The documentation site has an independent content-extension model through Fumadocs collections and MDX component mappings.
- `core.$constructor(name, initializer, proto, params)` is the foundational schema-type extension point: it composes traits, installs prototype members, handles subclasses, runs deferred initialization, and defines trait-based `instanceof` behavior.
- Core factory helpers accept a schema class parameter, allowing classic and mini constructors to share identical definition creation without importing either facade into core.
- New schema behavior is represented by `$ZodTypeDef.type`, a constructor that supplies `_zod.parse`, and structural fields such as `values`, `pattern`, `propValues`, `optin`, and `optout` consumed by shared algorithms.
- Checks are an extension seam: schema definitions carry a check array, each check may run attachment hooks, and classic `check`, `with`, `refine`, `superRefine`, and `overwrite` clone the schema with additional checks.
- Typed metadata registries can be created with `registry()`, attach metadata through `schema.register`, inherit metadata through parent clones, and index schemas by metadata `id` for multi-schema JSON Schema output.
- JSON Schema generation is extensible through a processor table keyed by schema type, per-schema `_zod.processJSONSchema` or `_zod.toJSONSchema` overrides, a global `override` callback, and an `unrepresentable` handler.
- `withParser` is an explicit bridge for build-time or native compilers: a caller may install a synchronous parser returning either a fresh output or the shared `INVALID` sentinel while retaining interpreter fallback.
- `globalConfig.postProcessor` is an internal construction hook used by `zod/compile`; `customError`, `localeError`, `jitless`, and `memoizer` are the supported global behavior knobs.
- User callbacks extend runtime behavior through custom predicates, refinements, transforms, preprocessors, catches, codecs, lazy getters, and function-schema implementations.
- Standard Schema properties provide an ecosystem integration point that does not require consumers to depend on concrete Zod classes.
- Documentation is extended by adding MDX to the docs or blog collection and, when needed, mapping React components into the catch-all docs and blog renderers.