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 }).
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
shapeSchemareads 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.
rulesis a new key of the codec options object. A codec option namedrulescannot 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.
| Question | Answer | Source |
|---|---|---|
| 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
| Date | Author | Change |
|---|---|---|
| 2026-12-03 | Joe Gaudet | Status in the Markdown file: Accepted (codegen C0). Adds to ADR 0010. |
| 2026-12-03 | Joe Gaudet | Commit 7b66d71: Add codegen: one contract gives WarpDrive, Millwork, real-enums, Formwright and harnessed code (#7) |
| 2026-12-04 | Joe 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.