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
Summary
Split
src/validator/factory/create-validator.tsinto internal factory modules organized by responsibility, while keepingcreateValidatoras the single public export.Recommendation
Refactor the factory internals into focused modules such as:
create-validator.ts: public factory onlyapply-field-schema.ts: recursive traversal, context building, nested schema executionnormalize-field-schema.ts: schema normalization into[constraintName, options]tuplesresolve-constraint.ts: registry lookup andUnknownConstraintErrorThe 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.tscurrently owns multiple responsibilities at once:That makes the file the main accumulation point for validator design drag and increases the chance of DSL drift over time.
Constraints
createValidatoras the only public factory exportsrc/validator/factory