#577 Measures: declarations, exact values, validation and formats (#572)
–
- github
- github/openchronology/timeline-app
- github/openchronology/timeline-app#577
- pull request
- state:merged
Closes #572, part 1 of #570. Moments and durations can carry **measures**: named, exact quantities such as a cost in cents or hours worked. This PR adds the declarations, values, validation and formats. Totals, the editor fields and presentation come in #573–#576. ## Format ```json "measures": { "cost": { "type": "mpz", "label": "Cost (cents)" }, "hours": { "type": "mpq" } } ``` An event gives its values in `metadata.measures`, as text: `{"cost": "123456", "hours": "3/2"}`. - **Types:** `mpz` holds whole numbers and `mpq` holds fractions. Both are unbounded and exact. - **Values:** integers, fractions or decimals, always as text. They're stored canonically (`6/4` becomes `3/2`, `12.50` becomes `25/2`), and zeros are left out. - **Size:** values are bounded like times, by length and by the server's digit limit, which moves to `numeric.ts`. - **Refused:** values for measures the timeline doesn't declare, and fractions for `mpz` measures. Errors name the entity. ## Changing declarations - **Plain saves:** a save may add measures, relabel them, or widen `mpz` to `mpq`. - **Rewrites:** renaming, removing or narrowing a measure rewrites values with `remeasuredEntities`: - renamed values move to the new name; - removed values are dropped; - narrowing is refused while any value is a fraction. - **On a server:** these go through `POST /api/timelines/{id}/measures` (`server/measure-change.mjs`). It's one save, streamed like `map-times`. A plain sparse save that tries one gets a 409. ## Where it goes - **Server:** - `oc_timelines.measures`, written by saves, rebuilds and sparse saves; - kept by forks, history settings, merges, retention, log writers, metadata, documents and `.ochx` exports; - documented in OpenAPI. - **Desktop:** `timeline_extras` in `.och` files, patches and `och-convert`. - **Editor:** - the index, drafts and server metadata; - settings conflicts and pull-request summaries. ## Tests - `test/measures.test.mjs` (unit). - `test/measures-postgres.mjs`, added to CI: saves, sparse saves, the 409 guard, `POST /measures` (renames, removals, narrowing), sliced patches, copies. - Locally, these also pass: `npm test` (apart from `contents.test`'s known local ENOBUFS; it passes in a clean worktree), Rust `cargo test --lib`, `incremental-postgres`, and `default-view-live-postgres`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_011fFY8eruEi1xAkkMBni13B https://github.com/circagraph/timeline-app/pull/577
Related
- #570 Measures: typed quantities on moments and durations, totalled in every summary
- #572 Measures 1: declarations, values, validation and formats
- #573 Measures 2: presentation and parsing per measure, with editor fields
- #576 Measures 5: durations' measures counted where they start
- #578 Measures: presentation and parsing per measure, and editor fields (#573)
- #579 Measures: totals in the editor's index and its overview groups (#574)
- #580 Measures: totals in the PostgreSQL moment tree and its overviews (#574)
- #581 Measures: totals in the desktop file's SQLite index (#574)
- #582 Measures: totals on summaries, values on hover cards, and plugins (#575)
- #583 Measures: durations count where they start (#576)
- Merge pull request #577 from openchronology/feat/572-measure-values
Open #577 Measures: declarations, exact values, validation and formats (#572) in the timeline