Repository navigation
feat(formula): publish the home-amount conversion arithmetic - #31631
Conversation
Move toScaledDecimal, divideToPlaces (with divideRoundHalfAwayFromZero), formatScaledDecimal, documentDateOf (with calendarDayIn) and the ScaledDecimal type out of objectql's home-amount projection into @objectstack/formula, byte-identical, and export them from its index. objectql imports them back and re-exports them from the projection module, so its callers and tests keep their import site. A new formula test pins the exports on the engine's samples: JPY 0, USD 2 and KWD 3 digits, the half-away-from-zero tie, a datetime's calendar day in a non-UTC zone, and UTC when the zone is unset. Claude-Session: https://claude.ai/code/session_01ADHkmQeo8gpywkDhZJu9nP Co-authored-by: Claude <noreply@anthropic.com>
The home-amount arithmetic moved unchanged into @objectstack/formula; the D5 settlement notes now anchor documentDateOf, divideToPlaces, divideRoundHalfAwayFromZero and toScaledDecimal there, so check:adr-symbol-anchors resolves them again. Claude-Session: https://claude.ai/code/session_01ADHkmQeo8gpywkDhZJu9nP Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift Check9 anchor(s) derived from 2 changed package(s); no hand-written page names any of them. What this run could not see
Coarse fallback — 29 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 4cc190191dc30f403527cb34bc25b93e0341eeae && git checkout 4cc190191dc30f403527cb34bc25b93e0341eeae
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 69244406b7e93b8856f3a5991ec18433a7e96dc4 cc6ea750a12b616c7c77867e1d419b1c45059733 && git checkout -B drift-repro 69244406b7e93b8856f3a5991ec18433a7e96dc4 && git merge --no-ff cc6ea750a12b616c7c77867e1d419b1c45059733
node scripts/docs-audit/affected-docs.mjs --json 69244406b7e93b8856f3a5991ec18433a7e96dc4 |
|
domain:server#2 · os-steve · session_01ADHkmQKZzp4DLtqiCkZZRM Contract reviewServed-tier: Inputs read: card #31609 (body and all five comments: triage 6724150397, claim 6724336691, triage H14 6724444852, claim amendment 6724651755, ① Derived judgments
② Semver level
③ Boundary flagsDev report 6724915226 (
Open questions:
No flag is escalated; none needs the maintainer beyond the Tier H approval the PR already waits on. ④ Design judgmentThe ADR hit, sentence by sentence. Both hunks sit under
Anything moved that the card did not name? No. The diff touches six files; the private helpers that moved ( Attempts to break it, all held: a dependency cycle (none: formula depends on spec and cel-js only); a Node-only import reaching the browser through formula (none in the new module or anywhere in formula Findings: must-fix 0; should-fix 0; nit 3 (ADR provenance cites the card number, index comment's present tense, orphaned section heading in objectql). None affects correctness or the contract. Implemented-by: VERDICT: PASS |
|
domain:server#2 · os-steve · session_01ADHkmQKZzp4DLtqiCkZZRM 维护者速读
席位核对 — ACCEPT · domain:server#2 · Head-sha
|
Requested by Steve · project thread
Fixes #31609
Clause-②: yes (widening)
Metadata-protocol: none
维护者速读
toScaledDecimal、divideToPlaces、formatScaledDecimal、documentDateOf)和ScaledDecimal类型原样从objectql内部文件搬到已发布包@objectstack/formula并导出;objectql改为导入回来,行为不变。homeAmount(multi-currency M3-2, epic #8345; the read-only display is released with M2) #27196 要在发票表单上实时预览「≈ 本位币金额」,数字必须与保存时引擎算出的一致;前端已依赖formula、不依赖objectql,不允许复制第二份。packages/formula/src/home-amount-arithmetic.ts(搬来的函数),packages/objectql/src/home-amount-projection.ts顶部的导入/再导出,ADR-0144 第 387、402 行附近的锚点改动。pnpm --filter @objectstack/formula exec vitest run src/home-amount-arithmetic.test.ts,预期 5 个用例全绿(JPY 0 位、USD 2 位、KWD 3 位、平分远离零、时区取日)。docs/adr/**,需 GOVERNED_APPROVERS 批准后由席位落地)。What changes
packages/formula/src/home-amount-arithmetic.ts.toScaledDecimal,divideToPlaces(with its privatedivideRoundHalfAwayFromZeroandabs),formatScaledDecimal,documentDateOf(with its privatecalendarDayIn,CALENDAR_DATE) and theScaledDecimaltype, moved byte-identical out ofpackages/objectql/src/home-amount-projection.ts, under a new module header. The module imports nothing.packages/formula/src/index.tsexports the four functions and theScaledDecimaltype under their engine names. No clash in formula's index (git grepfor each name onorigin/mainhits only objectql and ADR-0144).packages/objectql/src/home-amount-projection.tsimports them from@objectstack/formulaand re-exports them, sohome-amount-recompute.tsand the projection test keep their import site.toStoredNumber(a projection-only step) stays.CURRENCY_FRACTION_DIGITSstays in@objectstack/spec. No new dependency edge: objectql,ui/packages/coreandui/packages/app-shellalready depend on@objectstack/formula, which depends only on@objectstack/spec.docs/adr/0144-…-write-time-home-projection.md(+4/−2, seat claim amendment on formula: export the home-amount conversion arithmetic (scaled-decimal divide, rounding, document date) so the ui preview reuses the engine rule (blocks #27196 PR 2) #31609). Two anchor parentheticals pointed atpackages/objectql/src/home-amount-projection.ts#documentDateOfand#divideToPlaces,#divideRoundHalfAwayFromZero,#toScaledDecimal.divideRoundHalfAwayFromZerois private and moves, sopnpm check:adr-symbol-anchors(required,Lint & Repo Gates) reds on any move-only diff. Both now point atpackages/formula/src/home-amount-arithmetic.ts, and the 402 parenthetical says the arithmetic moved there unchanged on 2026-11-08 in formula: export the home-amount conversion arithmetic (scaled-decimal divide, rounding, document date) so the ui preview reuses the engine rule (blocks #27196 PR 2) #31609. No decision text changed..changeset/31609-home-amount-arithmetic-formula.md:@objectstack/formulapatch,@objectstack/objectqlpatch (see Acceptance notes on the level).Tests
packages/formula/src/home-amount-arithmetic.test.ts(5 cases), imported through formula's index: exact-decimal reading (number, string, bigint; non-numbers spell none); the CLDR digits read fromCURRENCY_FRACTION_DIGITS— JPY100 ÷ 0.0065 → 15385, USD100 ÷ 1.0857 → 92.11, KWD100 ÷ 3.2468 → 30.800, CNY10000 ÷ 0.1389 → 71994.24(the ui: home field read-only with "converted at RATE on DATE"; live preview when a rate exists; Studio editor forhomeAmount(multi-currency M3-2, epic #8345; the read-only display is released with M2) #27196 sample); the half-away-from-zero tie on both signs (0.125 → 0.13,-0.125 → -0.13, JPY0.5 → 1, KWD-0.0005 → -0.001,1.005 → 1.01); adatetimetaken as its calendar day in Asia/Shanghai and America/New_York; UTC when the zone is unset,UTCor unknown.home-amount-projection.test.ts,engine-home-amount-projection.test.ts,home-amount-write-paths.test.ts(0 lines changed). No other test file is edited.Acceptance notes
minoron formula.scripts/check-changeset-no-major.mjs(the level axis, maintainer ruling A) requires a declaredMetadata-protocol: noneto grade every entry it introducespatch, so both entries arepatch. Raised with the seat in the report.toScaledDecimal,divideToPlaces,formatScaledDecimal,documentDateOf,ScaledDecimal) keep the engine's names; listed for the seat's ruling at ACCEPT.Verification
Head
cc6ea750a, worktree merged withorigin/main133f75ae.Red first: the new test on main's source (before the move)
Move-only: both blocks byte-identical
A script compared
git show 95df3459:packages/objectql/src/home-amount-projection.tsagainst the new module:git diff --color-moved=zebra 95df3459 f3715fe6over the two files colours every changed line as moved except: in objectql, the 8 added import/re-export lines and one removed blank line; in formula, the 20-line module header (copyright, docblock, theExact decimal arithmeticsection heading, blank lines). No line of a function body is outside the moved set.Package runs (os-verify-lock, VERDICT 0)
@objectstack/formulabuild + test + typecheck: Test Files 66 passed (66), Tests 1708 passed (1708);check:test-typecheckOK.@objectstack/objectqlbuild; the three projection suites: Test Files 3 passed (3), Tests 76 passed (76); full test: Test Files 570 passed (570), Tests 11571 passed (11571); typecheck (tsc --noEmit+check:test-typecheckOK).turbo run build --filter='./packages/**': 81 successful, 81 total.eslint packages/formula packages/objectql --no-inline-configexit 0.ADR anchor gate, red then green
Move commit
f3715fe6, before the ADR edit:After
cc6ea750a:Derived gates (dispatch-gates --commands, reconciled with --ran)
node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstackoncc6ea750a: 73 commands (the ADR hunk addscheck-adr-links×2,check:adr-anchors,check:adr-index,check:pm-governed-merges,check:pm-prior-rulingsand lint'scheck:doc-formula-expressionsto the 66 the move derived).pnpm check:dts-closureandpnpm check:dual-build-cjs-loadsexit 1 on that pass: six packages this diff does not touch (cloud-connection,connector-mcp,connector-openapi,connector-rest,trigger-record-change,trigger-schedule) had no.d.tsin this worktree'sdist/while a second gate sweep ran in the same tree. Afterturbo run build --forceof those six (44/44), both exit 0:256/256 declared declaration file(s) present across 80 package(s);122/72/2525/1entries over floors90/58/520/1.node scripts/check-plugin-teardown-shape.mjs --self-testneeded its pinned fixture commit fetched (exit 3 →git fetch origin 621a4876…→ exit 0, 48 cases).--ranreconciliation:73 derived famil(ies) accounted for — 73 run, 0 NOT-MEASURED.node scripts/check-platform-checklist.mjs --changed-from origin/mainexit 0 (no anchored file in the change set).!in the title and no(narrowing)arm.Generated by Claude Code