Skip to content

Require one

requireOne enforces that at least one of the specified fields must be present and accepted.

If none of the fields are accepted, the rule emits a single boundary‑level error. This rule is ideal for alternative identifiers, fallback options, or any scenario where multiple fields are acceptable but at least one must be provided.

Signature

export function requireOne(...keys: string[]): BoundaryRule

Parameters

Parameter Data type Description
keys string[] The fields of which at least one must be accepted.
Event code Description
boundary.does.require-one None of the specified fields were accepted.

Design rationale

  • Enforces minimum presence across a set of fields.
  • Emits one boundary‑level error regardless of how many fields are missing.
  • Evaluates fields strictly by acceptance (decision.code === "accept").
  • Does not modify field values or decisions — it only adds boundary‑level issues.
  • Ideal for “one‑of‑many” requirements where any valid option satisfies the rule.

Invoke

requireOne runs during the boundary decision phase. It is not affected by normalization mode or parsing rules.

The rule activates when none of the specified fields are present and accepted.

Examples

Valid: at least one field accepted

requireOne("email", "phone");

// email accepted → OK
// phone accepted → OK
// both accepted → OK

Invalid: none accepted

requireOne("email", "phone");

// email missing
// phone rejected
// → boundary.does.require-one at $

Partial input — still requires one accepted field

requireOne("a", "b");

// fields = { a: rejected }
// → boundary.does.require-one at $