Skip to content

Commit dc86f2a

Browse files
committed
fix(service-analytics): the derived-measure refusal prescribes what the column really carries
A derived column takes no currency code from its operands on the wire, so deleting the measure's currency leaves it unlabelled. The message now prescribes restating the operands' code, or deleting it with that consequence named. Changeset Clause-② reads no (narrowing). Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4d1Np3hU7RQnA13YZcL
1 parent 890ec13 commit dc86f2a

3 files changed

Lines changed: 7 additions & 6 deletions

File tree

‎.changeset/28019-derived-measure-fixed-currency.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
fix(service-analytics): a dataset refuses a derived measure `currency` that contradicts the one `fixed` code its operands resolve to
66

7-
Clause-②: yes (narrowing)
7+
Clause-②: no (narrowing) — not a widening; a dataset that compiled before is refused now
88
Metadata-protocol: narrowed
99

1010
**BREAKING** (`@objectstack/service-analytics`): one more compile-time refusal, `DATASET_INVALID` / 400, for dataset metadata that compiled before and printed a wrong label. It reaches boot registration, `queryDataset` and the Studio draft preview, which compile through the one `compileDataset` call.
1111

12-
- A derived `sum` / `difference` whose monetary operands all resolve to one `fixed` code, directly or through a derived measure built on them, and which declares its own `currency` with another code. The column printed the operands' amounts under the declared code, such as `{ derived: { op: 'sum', of: ['eur_a', 'eur_b'] }, currency: 'USD' }` over two EUR-fixed measures printing euros labelled `USD`. The message names the dataset, the measure, its operands and their code, and the fix: delete the measure's `currency`, and the column takes the operands' code.
12+
- A derived `sum` / `difference` whose monetary operands all resolve to one `fixed` code, directly or through a derived measure built on them, and which declares its own `currency` with another code. The column printed the operands' amounts under the declared code, such as `{ derived: { op: 'sum', of: ['eur_a', 'eur_b'] }, currency: 'USD' }` over two EUR-fixed measures printing euros labelled `USD`. The message names the dataset, the measure, its operands and their code, and the fix: restate the operands' code as the measure's `currency`, or delete it (the column then carries no currency code; a derived column takes no code from its operands on the wire).
1313
- A derived measure `currency` that restates the operands' `fixed` code is still accepted.
1414

1515
Not judged, unchanged: a derived measure whose operands resolve to no one `fixed` code (a `fixed` amount with a tenant-currency one, a `ratio` or `product`), and the record-mode and mixed-code refusals of both guards.

‎packages/services/service-analytics/src/__tests__/record-currency-analytics.test.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
* column-description seam.
2222
* - The two compile-time guards (`measure-currency-coherence.ts`):
2323
* `DATASET_INVALID` / 400 for a measure `currency` over a record-mode amount
24-
* or contradicting a `fixed` field's code, and for a derived measure
24+
* or contradicting a `fixed` field's code or a derived measure's operands'
25+
* one `fixed` code, and for a derived measure
2526
* combining a record-mode amount with another currency or two different
2627
* `fixed` codes. The `fixed` arms reach boot registration, `queryDataset`
2728
* and the draft preview alike (ruling 6486427200 on #8345).
@@ -383,7 +384,7 @@ describe('[ADR-0144 M0-3] analytics over a record-currency amount', () => {
383384
+ 'measures "eur", "eur_restated", whose amounts are fixed to EUR.',
384385
);
385386
expect(compileRefusal(measures)?.message)
386-
.toContain("delete the measure's `currency` (the column takes the operands' EUR)");
387+
.toContain("restate the operands' EUR as the measure's `currency`, or delete it (the column then carries no currency code)");
387388
});
388389
}
389390

‎packages/services/service-analytics/src/measure-currency-coherence.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ export function assertMeasureCurrenciesCoherent(
185185
throw datasetInvalidError(
186186
`[dataset-compiler] dataset "${dataset.name}" derived measure "${m.name}" declares currency `
187187
+ `"${m.currency}" over measures ${operands}, whose amounts are fixed to ${resolved.code}. The amounts are `
188-
+ `${resolved.code}, so the column would print them as ${m.currency}: delete the measure's \`currency\` `
189-
+ `(the column takes the operands' ${resolved.code}).`,
188+
+ `${resolved.code}, so the column would print them as ${m.currency}: restate the operands' `
189+
+ `${resolved.code} as the measure's \`currency\`, or delete it (the column then carries no currency code).`,
190190
);
191191
}
192192
}

0 commit comments

Comments
 (0)