Millwork: plan
Millwork turns rough wire data into finished, typed parts for WarpDrive (ember-data 5.8+).
Summary
Date: 2026-12-01. Status: draft plan, no code yet.
Millwork turns rough wire data into finished, typed parts for WarpDrive (ember-data 5.8+). It gives two things:
- Nested structures in a record:
shape(mutable) andvalue(immutable). - Codecs that turn wire primitives into rich objects and back: money, dates, decimals, phone numbers, colors, and more.
The full catalog of wire types and the WarpDrive source findings are in
millwork-research.md. Labels there show what is confirmed and what is
not.
3. Name: Millwork
The bench uses woodworking names: Formwright, Joinery, Marquetry, Jig. A mill takes rough stock and makes finished parts to a known profile. Millwork takes rough wire data and makes typed shapes and values.
- Repo:
joegaudet/millwork. - npm scope:
@millwork-ts(the same pattern as@harnessed-tsand@switchyard-ts). Create the npm org before the first release. - Docs:
https://joegaudet.com/millwork/. - Words for the docs, used with care: "stock" (raw wire value), "profile" (a codec), "mill"
(hydrate), "finish" (the rich value). Code names stay plain:
codec,hydrate,serialize.
Glossary
1. Terms
These terms come from the 20 answers. They are the contract for the rest of the plan.
| Term | Identity | Mutable | Dirty and rollback | Equality | Example |
|---|---|---|---|---|---|
| entity | yes (id) | yes | yes | by id | Order, a WarpDrive record |
| shape | no | yes | yes, per path | structural, field by field | Address that a form edits in place |
| value | no | no | the app replaces it whole; the field is dirty when equals is false |
codec equals(a, b) |
Money, DateTime, LatLng |
- A
shapeis a nested structure that the app edits in place. It tracks changes and rolls back. - A
valueis a value object in the DDD sense. To change it, the app sets a new one. - The docs must explain this difference on the first page, with a link to the entity vs value object article.
- The word "fragment" is not in the public API, the docs, or the type names.
- A codec is the pure function pair that turns a raw wire value into a
valueand back.
Problem and context
Not recorded in the original plan.
Goals and non-goals
Not recorded in the original plan.
Customers
Not recorded in the original plan.
Internal stakeholders
Not recorded in the original plan.
Users and scenarios
Not recorded in the original plan.
Landscape and constraints
Not recorded in the original plan.
Proposed design
4. Architecture
4.1 Packages
| Package | Contents | Peer deps |
|---|---|---|
@millwork-ts/core |
Codec contract, shape and value definitions, change tracking, Standard Schema, built-in codecs with no peer |
none |
@millwork-ts/warp-drive |
SchemaRecord Transformations, schema helpers, memo cache. /legacy entry for @attr transforms. |
@warp-drive/core >= 5.8 |
@millwork-ts/temporal |
PlainDate, PlainTime, PlainDateTime, ZonedDateTime, Instant, Duration, PlainYearMonth |
temporal-polyfill (optional) |
@millwork-ts/luxon |
DateTime, Duration, Interval |
luxon |
@millwork-ts/date-fns |
Date and TZDate |
date-fns, @date-fns/tz |
@millwork-ts/dayjs |
Dayjs, duration |
dayjs |
@millwork-ts/dinero |
dinero.js v2 money, all three wire shapes | dinero.js ^2 |
@millwork-ts/decimal |
One factory for decimal.js, big.js or bignumber.js |
one of those |
@millwork-ts/phone |
E.164 and national numbers | libphonenumber-js |
@millwork-ts/color |
hex, rgb, hsl, oklch | culori |
@millwork-ts/quantity |
units of measure | js-quantities |
@millwork-ts/semver |
versions | semver |
@millwork-ts/ip |
IP and CIDR | ipaddr.js |
@millwork-ts/rrule |
recurrence rules | rrule |
@millwork-ts/cron |
cron expressions | croner |
@millwork-ts/geo |
WKT, geohash. H3 in its own package later, because it is WASM. | betterknown, ngeohash |
Rules:
- Core and every codec package import nothing from Ember or WarpDrive.
- The
/legacyentry imports nothing from WarpDrive at runtime, only types. This is the real-enums rule: two copies of@warp-drive/corestop the app from booting. - Each package is a v2 Ember addon only where it must give
transform:<name>to the app. Only@millwork-ts/warp-driveneeds that.
4.2 The codec contract
interface Codec<Raw, Value, Options = void> {
name: string // registry and schema name, e.g. 'money'
hydrate(raw: Raw, options: Options): Value | undefined
serialize(value: Value, options: Options): Raw
equals(a: Value, b: Value): boolean
isValue(input: unknown): input is Value // guards the setter
schema?: StandardSchemaV1<Raw, Value> // decision 16
}
hydrateis forgiving: bad input givesundefinedand one dev warning per field (decision 14).serializeis strict and throws on a wrong type.- Helpers in core:
nullable(codec),arrayOf(codec),setOf(codec),mapOf(codec),rangeOf(codec),pipe(a, b),defineCodec(...). - Adapter for Zod 4 codecs (
z.codec): an optional peer, type import only.
4.3 Shapes and values
Both declaration forms make the same internal definition (decision 7).
// Class form
class Address extends Shape {
@field declare line1: string
@field declare city: string
@field('country') declare country: string
@value('latlng') declare location?: LatLng
}
class Price extends Value {
@field('money', { wire: 'minor' }) declare amount: Money
@field declare label: string
}
// JSON form
const AddressShape = shape({
type: 'address',
fields: [{ name: 'line1' }, { name: 'city' }, { name: 'location', codec: 'latlng' }],
})
Record use:
// Legacy Model
class Order extends Model {
@shape(Address) declare shipTo: Address
@shapeArray(LineItem, { key: 'sku' }) declare items: LineItem[]
@value('money', { wire: 'decimal' }) declare total: Money
@shape({ PaymentCard, BankAccount }, { discriminator: '$type' }) declare payment: Payment
}
// SchemaRecord
fields: [
shapeField('shipTo', Address),
shapeArrayField('items', LineItem, { key: 'sku' }),
valueField('total', 'money', { wire: 'decimal' }),
shapeField('payment', { PaymentCard, BankAccount }, { discriminator: '$type' }),
]
Open question 1 (see section 9): which form is the source of truth, and how the two relate.
4.4 How it maps onto WarpDrive
Facts from the research (WarpDrive 5.9.1 source):
- Every codec uses
kind: 'field'.kind: 'object'spreads the value and removes the prototype, so aDineroorDateTimearrives as a plain object. - Every codec registers also as
array:<name>, sokind: 'array'can run it on each item. hydrateruns on every read with no memo. The adapter keeps aWeakMap<record, Map<field, { raw, value }>>and reuses the value while the raw value is the same. Test:record.total === record.total.- A shape uses
schema-object. A shape array usesschema-arraywithoptions.key. - Polymorphic shapes use
options.polymorphicwith the discriminator key. The discriminator stays in the raw data, so it goes back to the server. - Dirty state in the cache is per top-level field only. Millwork adds per-path dirty state on
top: it compares the local and remote raw values at each path with the codec
equals. - Legacy records are editable. Polaris records need
checkout. Millwork supports both.
4.5 Change tracking (the Formwright seam)
One small API on every shape, so that Formwright can bind to nested paths later (decision 15):
interface Tracked {
readonly isDirty: boolean
changes(): Array<{ path: string[]; from: unknown; to: unknown }>
rollback(path?: string[]): void
subscribe?(path: string[], fn: () => void): () => void // tracked through signals
}
rollback()with no path rolls back the whole shape. With a path, it rolls back one leaf.- A shape array tracks add, remove and move, not only member edits. The research found that the WarpDrive legacy layer does not restore removed or reordered members.
4.6 Validation
toStandardSchema(Address)gives aStandardSchemaV1for a shape or value type.- Each codec schema checks the raw form. The shape schema adds required fields and nested paths.
- No validation runs by default on read (decision 14 stays true). The app or Formwright calls the schema.
5. Codecs in v1
All four families are in v1 (decision 9). To ship in steps, v1 has milestones (section 7). "Core" means no peer dependency.
5.1 Dates and times (no default, decision 11)
Core gives the contract and the parsers for the wire shapes. Each adapter package gives the rich type.
| Codec | Wire shapes | Adapters |
|---|---|---|
date |
"2026-12-01" |
temporal PlainDate, luxon, date-fns, dayjs |
time |
"14:30", "14:30:00.000" |
temporal PlainTime, luxon |
local-datetime |
"2026-12-01T14:30:00" |
temporal PlainDateTime, luxon |
datetime |
RFC 3339 with offset or Z; option keepOffset |
temporal Instant, luxon, date-fns, dayjs |
zoned-datetime |
RFC 9557 ...[America/Toronto], or { at, zone } |
temporal ZonedDateTime, luxon |
epoch |
seconds, ms, µs, ns (option unit) |
all |
year-month |
"2026-12" |
temporal, luxon |
duration |
ISO 8601, seconds, ms, Postgres interval | temporal, luxon, dayjs |
interval |
"a/b", "a/PT1H", { start, end } |
luxon Interval, core Range |
Rules:
- Never parse a date-only string with
new Date(...). It gives UTC midnight and the wrong day in western zones. - Do not turn months or years in a duration into milliseconds.
equalsfor luxon compares the instant (+a === +b), not zone and locale. An option can make it strict.
5.2 Money and decimals
| Codec | Wire shapes | Package |
|---|---|---|
money |
wire: 'minor' { amount: 1999, currency: 'USD' }; 'decimal' { amount: '19.99', currency }; 'snapshot' dinero v2; 'minor-scaled' { amount, currency, scale }; bare amount with currency option |
core Money (bigint plus ISO 4217 table), @millwork-ts/dinero |
decimal |
"123.4500"; option scale |
core Decimal (string-backed), @millwork-ts/decimal |
bigint |
"9007199254740993" |
core |
number-string |
"42", "NaN", "Infinity" |
core |
percent |
unit: 'fraction' | 'percent' | 'bps' |
core |
ratio |
"16:9", { num, den } |
core |
- Money
equalsnormalizes the scale and compares the currency. - A number amount (
19.99) is accepted on read. Serialize never writes a float. - A currency in another field is a derived value, not a codec. Document the pattern.
5.3 Identity and contact
| Codec | Wire | Package |
|---|---|---|
uuid, ulid |
strings; lower-case for equals; ULID gives time |
core (brand plus helpers) |
snowflake |
64-bit string → bigint, option epoch |
core |
url |
string → frozen URL, option base |
core |
email |
string, domain lower-cased | core |
phone |
E.164; national with defaultCountry |
@millwork-ts/phone |
country, currency-code, language, locale, time-zone |
ISO and BCP 47 codes, IANA IDs | core, through Intl. Point to real-enums for closed lists. |
PostalAddress |
a built-in shape, not a codec | core |
5.4 Geo, color, units and misc
| Codec | Wire | Package |
|---|---|---|
latlng |
{ lat, lng }, { latitude, longitude }, [lng, lat], "lat,lng"; option order |
core |
geojson |
RFC 7946 | core (typed pass-through, frozen) |
wkt, geohash |
strings | @millwork-ts/geo |
color |
hex, rgb, hsl, oklch; option format keeps the server form |
@millwork-ts/color |
quantity |
{ value, unit }, "12.5 kg" |
@millwork-ts/quantity |
semver |
"1.2.3-beta.1" |
@millwork-ts/semver |
ip, cidr |
strings | @millwork-ts/ip |
rrule |
RFC 5545 | @millwork-ts/rrule |
cron |
5 or 6 fields; option dialect |
@millwork-ts/cron |
range |
{ start, end }, [a, b], ISO a/b, Postgres "[a,b)"; option of |
core |
set, map |
array → frozen Set; object or entries → frozen Map; option of |
core |
boolean-ish |
"true", "1", "Y", 1 |
core |
bytes |
base64, base64url, hex → Uint8Array |
core |
byte-size |
1048576, "1 MiB" |
core |
bitflags |
integer → ReadonlySet of names |
core |
i18n-text |
{ en, fr } → .for(locale) with a fallback chain |
core |
mime-type |
"text/html; charset=utf-8" |
core |
5.5 Not in v1
- Encrypted values. Decryption is async, so it cannot be a Transformation.
- Rich text documents (ProseMirror, Lexical, Slate, Portable Text). They need the editor schema.
- Regex from the wire. It is a ReDoS risk.
- JSON Patch and JSON Pointer. They are already plain JSON.
- moment, mathjs units, H3 (WASM). H3 can come later as its own package.
- Enums. They stay in
@real-enums/warp-drive.
User interface and prior art
8. Marketing site update
The Ember Workbench page is in the wt-site-workbench worktree. That branch has not merged
into joegaudet.github.io yet, so make these changes on top of it.
8.1 Now: bench card
- In
_tests/tools.mjs, add this entry afterreal-enums:{ id: 'millwork', name: 'Millwork', group: 'data', status: 'bench', links: {} }, - In
ember-workbench/index.html, add a Millwork card in the "Domain values" group (near line 409, "The words your app is built from."). Proposed copy: "Money, dates and nested shapes, milled from the wire into real objects." No links while the status isbench. - In the same file, update the stack diagram:
- The
<desc>near line 253 says "domain values are real-enums". Change it to name both tools. - The two SVG rows for "Domain values" (near lines 283 and 326) show only real-enums. Add Millwork, or change the note to "real-enums + Millwork".
- The
- The "One layer each, one bench" section says each layer has one tool. With two tools in Domain values, edit that copy. Proposed: "real-enums names the words; Millwork shapes the values."
- Add a card source in
ember-workbench/_src/tools/and runember-workbench/_src/render-cards.sh. - Run the gates in
_tests/:npm test,npm run links,npm run lighthouse(95 or more),npm run screenshots. Check the screenshots in light, dark, desktop and phone.
8.2 At v1 release
- In
tools.mjs, setstatus: 'shipped'and adddocs,githubandnpmlinks. - Add links to the card.
- Add
/millwork/tositemap.xml, and add Millwork to the open source section of the homepageindex.html. - Publish the docs site at
joegaudet.com/millwork/, with the same layout as/real-enums/. - Add a cross-link from the real-enums docs and README to Millwork, and back.
Requirements
Not recorded in the original plan.
Data model and API changes
Not recorded in the original plan.
Security and permissions
Not recorded in the original plan.
Observability and success metrics
Not recorded in the original plan.
Rollout and migration
Not recorded in the original plan.
Work items
7. Milestones
| M | Scope | Done when |
|---|---|---|
| M0 | Repo from the real-enums template. Spikes S1 to S6. ADRs. | The spikes have tests and ADRs. CI is green. |
| M1 | Core: codec contract, helpers, Money, Decimal, Standard Schema. Codecs with no peers. |
Unit tests per codec: round trip, bad input, equals. |
| M2 | @millwork-ts/warp-drive: Transformations, /legacy transforms, memo cache, valueField. |
A test app runs on 5.8 and latest with both doors. |
| M3 | Shapes: class and JSON forms, shape, shapeArray, polymorphic, Tracked, rollback per path. |
Dirty and rollback tests pass for legacy and Polaris records. |
| M4 | Date packages: temporal, luxon, date-fns, dayjs. | One shared conformance suite passes for each adapter. |
| M5 | Money and number packages: dinero, decimal. | Conformance suite passes for each wire shape. |
| M6 | Contact, geo, color, units, misc packages. | Conformance suite passes. |
| M7 | Docs site at /millwork/, examples, Jig stories. Release 1.0 with oss-release. |
The site is live and packages are on npm. |
- A shared codec conformance suite (
@millwork-ts/conformance, private) runs the same tests on each codec: round trip,undefinedon bad input,equalsis reflexive and symmetric, the value is frozen, raw is JSON-safe. - Tests use harnessed where they touch the UI.
Future work and research
Not recorded in the original plan.
Alternatives considered
2. Decisions (from the 20 answers)
| # | Topic | Decision |
|---|---|---|
| 1 | Storage paths | Both doors: legacy Model (@attr, transforms) and SchemaRecord (Transformations, schema-objects). |
| 2 | Version floor | @warp-drive/core and ember-data 5.8+. |
| 3 | model-fragments | Design from scratch. No compatible API, no codemod. |
| 4 | Mutability | Shapes are mutable with dirty tracking. Values are immutable. |
| 5 | Names | shape (mutable) and value (immutable), both in the API. |
| 6 | Equality | Each codec defines equals(a, b). A shape compares field by field with those functions. |
| 7 | Declaration | Two forms: a class with decorated attributes, and a JSON schema. |
| 8 | Polymorphic | In v1. A discriminator key maps to a shape or value class. |
| 9 | Codec families | All four in v1: dates and times; money and decimals; identity and contact; geo, color, units and misc. |
| 10 | Packaging | @millwork-ts/core has no peer deps. One package per peer library. |
| 11 | Dates | Pluggable, no default. Core holds the contract only. |
| 12 | Money wire | Configurable: minor units, decimal string, dinero snapshot. |
| 13 | Reach | Framework-free core. WarpDrive is the first adapter. |
| 14 | Bad data | Hydrate gives undefined and a dev-mode warning. It does not fail the response. |
| 15 | Formwright | Design the change-tracking seam now. Build the glue after v1. |
| 16 | Validation | Each shape and value type exposes a Standard Schema. |
| 17 | Name | Millwork. npm millwork and @millwork-ts/* are free (checked 2026-12-01). |
| 18 | Site group | Domain values, beside real-enums. |
| 19 | Site state | bench card now. shipped at v1. |
| 20 | Repo | New monorepo, the same template as real-enums (pnpm, changesets, oss-release). |
Risks
6. Risks and spikes
Each spike starts with a failing test (TDD rule). The result goes in an ADR in the repo.
| # | Spike | Why | If it fails |
|---|---|---|---|
| S1 | Run the WarpDrive mechanics tests on 5.8 and on 5.9 | The research read only 5.9.1. Confirm schema-object, polymorphic, schema-array options.key, @hash on 5.8. |
Move the floor up, or add a 5.8 compat path. Ask before you move it. |
| S2 | Nested setAttr loses sibling edits; nested write with no remote value throws |
Suspected bug in @warp-drive/json-api 5.9.1. Shape tracking depends on it. |
Report upstream with the failing test. Millwork writes the whole top-level value until a fix ships. |
| S3 | record.x === record.x for object codecs |
hydrate has no memo. |
The memo cache in section 4.4 is the fix. |
| S4 | Legacy door: wrap @warp-drive/legacy/model-fragments internally, or write on schema-object directly |
The legacy layer exists, but its names and per-field dirty state do not match the plan. | Decide in an ADR. The public API stays in Millwork terms in both cases. |
| S5 | Temporal in Safari | Safari stable support is unconfirmed. | Document temporal-polyfill as an optional peer. |
| S6 | structuredClone of the raw cache |
Raw values must be JSON-safe. A bigint raw breaks JSON. |
Keep every raw as a JSON primitive or object. |
6.1 Spike results (M0, 2026-12-01)
The tests are in packages/warp-drive/tests/spikes/. They use a real store. The results are
the same on 5.8.0 and 5.9.1.
- S1: all the field kinds work on 5.8.0. The floor stays at 5.8 (ADR 0004).
- S2: both suspected bugs are real. A whole-object write to a polymorphic
schema-objectalso throws. Shapes write the whole top-level value through their own setter (ADR 0005). The draft upstream issue is upstream-nested-setattr.md. It is not filed. - S3: there is no memo. A memo keyed by record and field gives identity (ADR 0002). A key for primitive array elements is open for M2.
- S4: the legacy door uses
withDefaultsand plainschema-object, not model-fragments (ADR 0003). - S5:
temporal-polyfillis an optional peer (ADR 0006). There is no test. - S6:
kind: 'object'removes the prototype, and abigintraw value breaks JSON (ADR 0001). valueFieldputs the field name inoptions.field, becausehydratedoes not get it.- Not tested yet: reactivity (the signal hooks are no-ops in the tests) and dev-mode asserts.
Open questions
- Declaration source of truth. Both forms are in scope. Is the class the main form, with the JSON form for SchemaRecord only? Or are the two forms equal, with a test that they make the same definition?
- Value classes and the decorator.
@fieldon aValueclass makes an immutable composite value. Does it needwith({...})(copy with changes), likeactive_record_value_objectscopy_with? - Codec registration. Register by name in the store (like
enumTransformations), or pass the codec object in the field options? Names are needed for JSON schemas. Objects give better types. - Money scope. Does the core
Moneytype do arithmetic and allocation, or only hold the amount and leave math to dinero? - Floor of 5.8. If spike S1 shows a missing feature on 5.8, is 5.9 an acceptable floor?
- real-enums link. Should
@millwork-ts/warp-drivere-export the real-enums Transformations, so one registry holds both?
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/plan.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/plan.md |
Changelog
| Date | Author | Change |
|---|---|---|
| 2026-12-01 | Joe Gaudet | Commit 0a16254: Build Millwork 1.0 (#1) |
| 2026-12-04 | Joe Gaudet (agent) | Converted from docs/plan.md to this page. The text is the text of the Markdown file. |
| 2026-12-04 | Joe Gaudet (agent) | Status Shipped: the packages of Millwork are at version 1.1.0 (packages/core/package.json). The Markdown file says "draft plan, no code yet" (2026-12-01). |
The prd skill of skillsaw wrote this page. The HTML in this file is the source of truth. The diagrams are the Mermaid sources in it.