Architecture decision record · ADR-0010

The class form is the main form; the JSON form has equal power

The class form is the main form: class Address extends Shape with @field.

Status
Accepted
Deciders
Joe Gaudet
Created
Updated
PRD
PRD
Related
None

Context

Plan decision 7 has two declaration forms: a class with decorated fields, and a JSON schema. Open question 1 asks which form is the source of truth. Open question 2 asks if a value class needs with({...}).

Decision drivers

Not recorded in the original ADR.

Options considered

Not recorded in the original ADR.

Decision

  • The class form is the main form: class Address extends Shape with @field. The JSON form shape({ type, fields }) and value({ type, fields }) gives a class with the same power.
  • Both forms make the same internal definition. A test compares them with definitionOf.
  • @field works with standard decorators (@field accessor city!: string) and with the legacy decorators that Ember compiles (@field declare city: string). Standard decorators keep the fields in Symbol.metadata. Core sets Symbol.metadata to Symbol.for('Symbol.metadata') when the runtime has none (the same key as esbuild and Babel), so tsc output works too.
  • Each class has a static type name. Minifiers rename classes, so the name is not taken from the class.
  • A Value is immutable: a write throws a TypeError. with({...}) gives a copy. A value class is also a codec (Price.codec), so valueField('price', Price) and the legacy transforms use it with no extra code.
  • equals compares field by field with each codec equals.
  • shapeSchema(Class) gives the Standard Schema of a shape or value class, with each issue path. toStandardSchema(codec) stays for codecs. The codec function and its signature did not change.
  • A polymorphic field takes a map of discriminator values to classes. The key is $type by default, and the discriminator option changes it. The discriminator stays in the raw value.

Consequences

  • An app can declare shapes in JSON (for example from a server schema) with no loss.
  • The plan used toStandardSchema(Address). The name is shapeSchema(Address).

Confirmation

Evidence

  • packages/core/tests/shapes/shape.test.ts, packages/core/tests/shapes/schema.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/0010-declaration-forms.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/0010-declaration-forms.md

Changelog

DateAuthorChange
2026-12-01Joe GaudetStatus in the Markdown file: Accepted (M3). This answers open questions 1 and 2 of the plan.
2026-12-01Joe GaudetCommit 0a16254: Build Millwork 1.0 (#1)
2026-12-04Joe Gaudet (agent)Converted from docs/adr/0010-declaration-forms.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.