refactor(i18n,kitchen): read every ingredient quantity through a single term model #151

Merged
abiwab merged 1 commit from refactor/quantity-terms into dev/1.5 2026-11-15 13:28:56 +01:00
Owner

PR 0 of the compound-quantities plan (1.5): a neutral refactor that puts every ingredient amount through one internal term model, before any syntax change.

Acceptance: no visible change. After conformance:update and bun test --update-snapshots, the conformance goldens and the snapshots are byte-identical; the legacy 1.3.0 digests pass unchanged. No changeset.

Added

  • packages/i18n/src/quantity.ts: pure, neutral term model (Term, termsTotal, mergeTerms(terms, "unit"), scaleTerms / scaleTermValue, formatTerm / formatTerms, round2). Invariants tested: added terms always before subtracted ones; a range total stays a range.
  • packages/kitchen/src/terms.ts: adapters termsOfUsage, termsOfQuantity, termsOfAst, usageFromTerms, numericTotal, scaleUsageTerms (overflow → InvalidFactorError).

Migrated (same output)

  • kitchen: section aggregation, shopping list (terms per key instead of otherUnits), applyScale and scaleAst through one helper; scaleQty / getNumericQty delegate to i18n (kept as public API).
  • analyzer: mass standardization, nutrition, diff.
  • modules: yield.ts. language-server: nutrition hover, "Convert to grams".
  • renderer: aggToRendererItem.

Deviations from the plan

  • TermValue is number | QuantityValue (the parser's single / fraction / range shape, redeclared in i18n) rather than { value, min, max, text }: needed to keep fractions' numerator / denominator / text byte-identical.
  • round2 moved to i18n, re-exported by kitchen.
  • Left for later PRs (migrating them now would change output or belongs elsewhere): run-sheet kitIngredients own aggregation (PR 4/6), aligning nutrition.ts on overrides / lang (behavior change), display reads in views and CLI (PR 6 formatUsageQuantity), processor.ts (PR 3).
PR 0 of the compound-quantities plan (1.5): a neutral refactor that puts every ingredient amount through one internal term model, before any syntax change. **Acceptance: no visible change.** After `conformance:update` and `bun test --update-snapshots`, the conformance goldens and the snapshots are byte-identical; the legacy 1.3.0 digests pass unchanged. No changeset. ### Added - `packages/i18n/src/quantity.ts`: pure, neutral term model (`Term`, `termsTotal`, `mergeTerms(terms, "unit")`, `scaleTerms` / `scaleTermValue`, `formatTerm` / `formatTerms`, `round2`). Invariants tested: added terms always before subtracted ones; a range total stays a range. - `packages/kitchen/src/terms.ts`: adapters `termsOfUsage`, `termsOfQuantity`, `termsOfAst`, `usageFromTerms`, `numericTotal`, `scaleUsageTerms` (overflow → `InvalidFactorError`). ### Migrated (same output) - kitchen: section aggregation, shopping list (terms per key instead of `otherUnits`), `applyScale` and `scaleAst` through one helper; `scaleQty` / `getNumericQty` delegate to i18n (kept as public API). - analyzer: mass standardization, nutrition, diff. - modules: `yield.ts`. language-server: nutrition hover, "Convert to grams". - renderer: `aggToRendererItem`. ### Deviations from the plan - `TermValue` is `number | QuantityValue` (the parser's single / fraction / range shape, redeclared in i18n) rather than `{ value, min, max, text }`: needed to keep fractions' `numerator` / `denominator` / `text` byte-identical. - `round2` moved to i18n, re-exported by kitchen. - Left for later PRs (migrating them now would change output or belongs elsewhere): run-sheet `kitIngredients` own aggregation (PR 4/6), aligning `nutrition.ts` on overrides / `lang` (behavior change), display reads in views and CLI (PR 6 `formatUsageQuantity`), `processor.ts` (PR 3).
refactor(i18n,kitchen): read every ingredient quantity through a single term model
All checks were successful
CI / Build & Test (pull_request) Successful in 4m17s
f71a6c637e
abiwab merged commit 561245d38a into dev/1.5 2026-11-15 13:28:56 +01:00
abiwab deleted branch refactor/quantity-terms 2026-11-15 13:28:58 +01:00
Sign in to join this conversation.
No description provided.