Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .changeset/37214-chart-series-measure-format-refused.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
'@object-ui/types': minor
'@objectstack/spec': minor
---

feat(types)!: a static chart node's series refuses the renderer-internal `measureFormat` carrier by name

Clause-②: yes (narrowing)
Metadata-protocol: narrowed

<!-- adr-0087: registered chart-series-measure-format-carrier-refused -->

**BREAKING** accept-set narrowing on the static SDUI `chart` node: `ChartDataSeriesSchema` refuses `series[].measureFormat`, and the `ChartDataSeries` TS twin types it `?: never`.

`measureFormat` (`{ format, currency, percentScale }`) is the chart renderer's internal carrier of a dataset measure's display facts. The report and dashboard chart producers fill it from the dataset answer so a value axis prints the measure's units; it is not meant to be authored. Until now the non-strict series schema refused only its sibling `aggregate` by name, so a hand-written `measureFormat` on a static chart node was kept and honoured, and could claim a currency or a percent scale the data does not have.

| FROM | TO |
|:--|:--|
| `{ type: 'chart', series: [{ name: 'amount', measureFormat: { format: '0,0.00', currency: 'CNY' } }] }` | delete `measureFormat`; to print the value axis in a unit, write the axis `format` on the chart: `yAxis: [{ field: 'amount', format: '$0,0' }]` |

The one-line fix: delete `measureFormat` from every authored chart series. The parse now refuses it with one issue at `series.N.measureFormat` naming the key (a series that also writes `aggregate` is refused at both), and a typed `ChartDataSeries` literal that writes it fails `tsc`. Report and dashboard charts are unchanged: their producers keep filling the carrier past this schema. The D3 entry `chart-series-measure-format-carrier-refused` (`@objectstack/spec` migration registry) records the narrowing; there is no D2 conversion, because the carrier has no authored equivalent to rewrite into.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

import type { SemanticMigration } from '../../types.js';

// The static chart node's series refuses the renderer-internal `measureFormat`
// carrier by name, in the posture its `aggregate` sibling already has. A D3
// entry with no D2 conversion: the carrier has no authored equivalent to
// rewrite into, because what it carries is the dataset's own fact.
export const entry: SemanticMigration = {
id: 'chart-series-measure-format-carrier-refused',
surface: 'static SDUI `chart` node series — `series[].measureFormat` (`{ format, currency, percentScale }`) '
+ 'on `@object-ui/types` `ChartDataSeriesSchema` and its TS twin `ChartDataSeries`',
replacement: 'Delete the key. To print a static chart\'s value axis in a unit, write the axis `format` on the '
+ 'chart (`yAxis: [{ field: \'amount\', format: \'$0,0\' }]`), which takes precedence over the carrier. A '
+ 'report or dashboard chart bound to a dataset needs nothing: its producer fills the carrier from the '
+ 'measure the chart plots.',
reason: 'The report and dashboard chart producers hand the chart renderer each series\' `measureFormat`, '
+ 'copied from the dataset answer\'s field, so a value axis over a dataset measure prints the measure\'s '
+ 'units. The key is internal by declaration, but the static chart node\'s series schema is non-strict and '
+ 'refused only `aggregate` by name, so a hand-written `measureFormat` was kept and honoured: an author, or '
+ 'an AI writing page metadata, could claim a currency or a percent scale the data does not have. It is '
+ 'now a `never` key on both faces: the zod mirror refuses it at `series.N.measureFormat`, and a typed '
+ 'literal fails `tsc`.',
acceptanceCriteria: 'No static `chart` node carries `measureFormat` on a series; the parse refuses it with one '
+ 'issue at `series.N.measureFormat` naming the key, and a series that also writes `aggregate` is refused '
+ 'at both keys. A chart whose axis must print a unit declares `yAxis[].format`. Report and dashboard '
+ 'charts keep their axis units unchanged, because their producers fill the carrier past this schema.',
};
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,58 @@ describe('objectui#11681 — the two faces agree: `aggregate` is unwritable on b
expect(authored.name).toBe('task_count');
});
});

/**
* `measureFormat` on a chart series is renderer-internal too, and refused by
* name in the same posture as `aggregate`: the report and dashboard producers
* fill `{ format, currency, percentScale }` from the dataset answer, and an
* authored carrier on a static chart node would be kept by this NON-STRICT
* object and honoured by the renderer.
*/
describe('an authored series `measureFormat` is refused by name', () => {
const CARRIERS = [
{ format: '0.0%', percentScale: 'whole' },
{ format: '0,0.00', currency: 'CNY' },
{},
];

it.each(CARRIERS)('`measureFormat: %j` refuses with one `invalid_type` issue at `measureFormat`, naming the key', (carrier) => {
const issues = issuesOf(ChartDataSeriesSchema, { name: 'amount', measureFormat: carrier });
expect(issues).toHaveLength(1);
expect(issues![0]).toMatchObject({ code: 'invalid_type', path: 'measureFormat' });
expect(issues![0].message).toContain('`measureFormat`');
});

it('the chart node carries the refusal to its series path', () => {
expect(issuesOf(ChartSchema, NODE), 'the control node must parse, or the refusal below measures nothing').toBeNull();
const issues = issuesOf(ChartSchema, { ...NODE, series: [{ name: 'task_count', measureFormat: CARRIERS[0] }] });
expect(issues?.map((i) => i.path)).toEqual(['series.0.measureFormat']);
});

it('a series that authors both internal keys is refused at both, so the `aggregate` refusal stays', () => {
const issues = issuesOf(ChartSchema, {
...NODE,
series: [{ name: 'task_count', aggregate: 'count', measureFormat: CARRIERS[1] }],
});
expect(issues?.map((i) => i.path).sort()).toEqual(['series.0.aggregate', 'series.0.measureFormat']);
});

it('CONTROL — the authored channel for the axis units, `yAxis[].format`, still parses', () => {
expect(issuesOf(ChartSchema, { ...NODE, yAxis: [{ field: 'task_count', format: '0.0%' }] })).toBeNull();
});
});

describe('the two faces agree: `measureFormat` is unwritable on both', () => {
it('the zod arm\'s input type is exactly `undefined`, and the TS twin declares `never`', () => {
type ArmInput = z.input<typeof ChartDataSeriesSchema>['measureFormat'];
const zodArmIsUndefined: Eq<ArmInput, undefined> = true;
const tsTwinIsNever: Eq<ChartDataSeries['measureFormat'], undefined> = true;
expect(zodArmIsUndefined && tsTwinIsNever).toBe(true);
});

it('a typed literal refuses it at the authoring site', () => {
// @ts-expect-error — `measureFormat` is `?: never` on the authoring face.
const authored: ChartDataSeries = { name: 'amount', measureFormat: { format: '0,0.00', currency: 'CNY' } };
expect(authored.name).toBe('amount');
});
});
14 changes: 14 additions & 0 deletions ui/packages/types/src/data-display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2555,6 +2555,20 @@ export interface ChartDataSeries {
* site. Declare the aggregate on the dataset measure instead.
*/
aggregate?: never;
/**
* NOT A KEY OF THIS SERIES — refused by name, beside {@link aggregate}.
*
* `measureFormat` is the renderer-internal carrier of a dataset measure's
* display facts (`{ format, currency, percentScale }`): the report and
* dashboard producers fill it from the dataset answer's field, and a value
* axis whose series share one prints its ticks in the measure's units. A
* hand-written carrier could contradict the dataset's own facts, so
* `ChartDataSeriesSchema.measureFormat` refuses it by name and this
* `?: never` is a `tsc` error at the authoring site. Write the value axis'
* `format` on the chart (`yAxis: [{ field, format }]`) instead; it takes precedence
* over the carrier.
*/
measureFormat?: never;
}

/**
Expand Down
15 changes: 15 additions & 0 deletions ui/packages/types/src/zod/data-display.zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,21 @@ export const ChartDataSeriesSchema = z.looseObject({
+ 'axis ticks for a count. It is not authored: declare the aggregate on the dataset measure, '
+ 'and the chart takes it from there. Delete the key.',
),
// INTERNAL-ONLY REFUSAL, the `aggregate` posture. `measureFormat` is the
// renderer-internal carrier of a dataset measure's display facts
// (`{ format, currency, percentScale }`): the report and dashboard producers
// fill it from the dataset answer's field, and a value axis whose series share
// one prints its ticks in the measure's units. Nothing on this face may write
// it — a hand-written carrier can contradict the dataset's own facts — and this
// object is NON-STRICT, so an undeclared key would be kept and handed to the
// renderer. Declared and unwritable, it is refused by name instead.
measureFormat: retirementTombstone(
'REFUSED — `measureFormat` is the renderer\'s INTERNAL carrier of a dataset measure\'s display '
+ 'facts (`format`, `currency`, `percentScale`), which a report or dashboard chart fills from the '
+ 'dataset answer so its value axis prints in the measure\'s units. It is not authored: to format '
+ 'this chart\'s value axis, write the axis `format` (`yAxis: [{ field: \'total\', format: \'$0,0\' }]`), which '
+ 'takes precedence over the carrier anyway. Delete the key.',
),
// THE SIX KEYS THE RENDERER READS (objectui#7546). Each was undeclared, and
// because this object is NON-STRICT the mirror STRIPPED it in silence while
// `safeParse` reported success — the card's own measurement:
Expand Down
Loading