Skip to content

Refactor validator factory internals by responsibility #177

@imdhemy

Description

@imdhemy

Summary

Split src/validator/factory/create-validator.ts into internal factory modules organized by responsibility, while keeping createValidator as the single public export.

Recommendation

Refactor the factory internals into focused modules such as:

  • create-validator.ts: public factory only
  • apply-field-schema.ts: recursive traversal, context building, nested schema execution
  • normalize-field-schema.ts: schema normalization into [constraintName, options] tuples
  • resolve-constraint.ts: registry lookup and UnknownConstraintError

The goal is to sharpen separation of concerns without changing runtime behavior or expanding the public API surface. Helper modules should remain internal to src/validator/factory.

Why

create-validator.ts currently owns multiple responsibilities at once:

  • validator construction
  • field schema traversal
  • constraint resolution
  • schema normalization

That makes the file the main accumulation point for validator design drag and increases the chance of DSL drift over time.

Constraints

  • Keep createValidator as the only public factory export
  • Keep helper modules internal to src/validator/factory
  • Preserve runtime behavior
  • Include cleanup only where it removes duplication or clarifies ownership
  • Avoid opportunistic public API changes during the refactor

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No fields configured for Task.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions