At most one¶
atMostOne enforces that no more than one of the specified fields may be accepted.
If multiple fields are accepted simultaneously, the rule emits a boundary‑level error. This rule is useful for mutually exclusive configuration options, alternative identifiers, or any scenario where only one field should be present at a time.
Signature¶
export function atMostOne(...keys: string[]): BoundaryRule
Parameters¶
| Parameter | Data type | Description |
|---|---|---|
keys |
string[] |
The field names that must not appear together. |
Events¶
| Event code | Description |
|---|---|
boundary.does.at-most-one |
More than one of the specified fields was present. |
Design rationale¶
- Ensures exclusive presence among a set of fields.
- Evaluates only fields whose decision code is accept.
- Emits a single boundary‑level error when more than one field is accepted.
- Does not modify field values or decisions — it only adds boundary‑level issues.
- Keeps contributor expectations clear by enforcing explicit exclusivity rules.
Invoke¶
atMostOne runs during the boundary decision phase.
It is not affected by normalization mode or parsing rules. The rule activates when:
- Two or more of the specified fields have a decision code of accept.
Examples¶
Valid: zero or one field present¶
atMostOne("email", "phone");
// email accepted, phone absent → OK
// phone accepted, email absent → OK
// neither accepted → OK
Invalid: multiple fields present¶
atMostOne("email", "phone");
// both email and phone accepted → boundary error
// → JaneEvent {
// phase: "decide",
// kind: "error",
// code: "boundary.does.at-most-one",
// message: "At most one of [email, phone] may be present",
// path: "$"
// }