Architecture decision record · ADR-0016

Field rules in core

A field takes rules (FieldRules) in the class form (@field(ref, { rules })) and in the JSON form ({ name, rules }).

Status
Accepted
Deciders
Joe Gaudet
Created
Updated
PRD
PRD
Related
ADR-0010

Context

shapeSchema checked required fields and codec reads only. An OpenAPI or GraphQL contract also gives minLength, pattern, minimum and other constraints, and Formwright forms need them. Two options were: rules in core, or a wrapper outside core.

Decision drivers

Not recorded in the original ADR.

Options considered

Not recorded in the original ADR.

Decision

  • A field takes rules (FieldRules) in the class form (@field(ref, { rules })) and in the JSON form ({ name, rules }). The names and the meaning are the JSON Schema keywords: minLength, maxLength, pattern, minimum, maximum, exclusiveMinimum, exclusiveMaximum, multipleOf, minItems, maxItems.
  • Only shapeSchema reads the rules. Hydrate does not, so plan decision 14 stays true.
  • A rule skips a raw value of another JSON type. A missing optional field skips all its rules.
  • The issue message is [millwork] <path>: <rule> <limit>.
  • The rules are frozen JSON in the definition.

Consequences

  • Hand-written shapes get the same checks as generated shapes.
  • rules is a new key of the codec options object. A codec option named rules cannot exist.

Confirmation

Evidence

  • packages/core/tests/shapes/rules.test.ts

Interview record

Each question of the interview with its answer and its source. A fact from the code or a document, a question that the author did not ask, and an assumption are rows too.

QuestionAnswerSource
Where does the text of this page come from?From the Markdown file docs/adr/0016-field-rules.md at commit c8154b0. The text of each section is the text of the Markdown file. A section that the Markdown file does not have says so.Document: docs/adr/0016-field-rules.md

Changelog

DateAuthorChange
2026-12-03Joe GaudetStatus in the Markdown file: Accepted (codegen C0). Adds to ADR 0010.
2026-12-03Joe GaudetCommit 7b66d71: Add codegen: one contract gives WarpDrive, Millwork, real-enums, Formwright and harnessed code (#7)
2026-12-04Joe Gaudet (agent)Converted from docs/adr/0016-field-rules.md to this page. The text is the text of the Markdown file.

The adr skill of skillsaw wrote this page. The HTML in this file is the source of truth. The diagrams are the Mermaid sources in it.