Skip to content

Collapse validate() into a single generalised method threading mode and options #29

Description

@knoan

Observation

Every per-kind shape validator now handles the same three modes (see validateValue in src/value.core.ts):

  1. state — validate an instance value against the shape
  2. state against model — validate a retrieval result narrowed by a projection template
  3. model — validate a retrieval template (placeholder)

The mode is currently threaded piecemeal: validateValue takes a model?: boolean flag and forks per kind
(validateText/validateLocale, validateResource/validateTemplate, etc.), while the public validate() in
src/index.ts carries a four-branch dispatch (union, non-resource value, model === true template, keyed-model
result, plain resource) with a separate seal/idempotence check in each branch.

Idea

Generalise the mode into a single parameter carried end to end:

  • Pass model: boolean | Template (or a richer descriptor X) uniformly, matching the union already declared on the
    merged validate() options (src/index.ts model?: boolean | Template).
  • Thread the remaining options (entry, plain, depth, limit) through validateValue
    (src/value.core.ts L511-554) so each leaf validator receives the full context rather than re-deriving it at the
    index.ts layer.
  • With the mode and options unified, the four validate() overload bodies (src/index.ts L179-573) should collapse
    to a single generalised method dispatching once on shape kind and mode.

Scope / risks

  • Public validate() overload signatures stay as-is (state / result / template / value); only the shared
    implementation body collapses.
  • Idempotence sealing currently differs per branch (Validated seal payload varies by mode); a unified path must
    preserve those distinctions.
  • Behaviour-preserving refactor: existing test suite must stay green throughout.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    Status
    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions