Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
1b6d8cc
test(service-analytics): pin the dataset query door refusing undeclar…
claude Nov 15, 2026
e146394
fix(service-analytics)!: the dataset query door refuses measures and …
claude Nov 15, 2026
7350096
test(service-analytics): triage the dataset-face pins the closed-memb…
claude Nov 15, 2026
484714e
chore(service-analytics): changeset for the dataset door closed-membe…
claude Nov 15, 2026
b263c8d
Merge remote-tracking branch 'origin/main' into claude/area-A3-34005
claude Nov 15, 2026
d9106e8
test(rest): move the dataset-door pins the closed-member rule reaches…
claude Nov 16, 2026
b25fa01
docs(api): say the cube query's inferred measure spellings stop at th…
claude Nov 16, 2026
8e358c3
test(rest): pay the objectql load at module top in two dataset-door pins
claude Nov 16, 2026
5a127a4
fix(service-analytics): word the source-field remedy for the dataset …
claude Nov 16, 2026
e2a0a9c
chore(service-analytics): note the dataset-door source-field remedy i…
claude Nov 16, 2026
73cf3b1
Merge origin/main into claude/area-A3-34005
claude Nov 16, 2026
1b9dac0
Merge remote-tracking branch 'origin/main' into claude/area-A3-34005
claude Nov 16, 2026
5c5966f
fix(service-analytics): name the compare widget's remedy, pin the ref…
claude Nov 16, 2026
8d7e39c
test(rest): load @objectstack/objectql at module top in the read-gate…
claude Nov 16, 2026
43b494b
docs(service-analytics): name the compare widget's date key in the ch…
claude Nov 16, 2026
7917a19
Merge remote-tracking branch 'origin/main' into claude/area-A3-34005
claude Nov 16, 2026
75e3e06
fix(service-analytics): name one remedy for an undeclared compare-win…
claude Nov 16, 2026
ab7c7ca
fix(service-analytics): a compare-window date key no dimension can be…
claude Nov 16, 2026
d782833
docs(service-analytics): a dotted compare-window date key is a break …
claude Nov 16, 2026
7a6aa7d
fix(service-analytics): a refusal whose only member is an unnameable …
claude Nov 16, 2026
29a15c0
Merge remote-tracking branch 'origin/main' into claude/area-A3-34005
claude Nov 16, 2026
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
19 changes: 19 additions & 0 deletions .changeset/34005-dataset-door-declared-members.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
'@objectstack/service-analytics': patch
---

fix(service-analytics)!: the dataset query door refuses measures and dimensions the dataset does not declare, as `query_dataset` does

Clause-②: no (narrowing)
Metadata-protocol: none
Skills-docs: follow-up #34328 — `skills/**` teach dataset selections by the dataset's declared measures and dimensions (objectstack-ui: a report selects `rows` and `values` "from that dataset"), which the door now enforces; they do not yet say that a compare widget's date key must be the name of a declared date dimension, and that teaching is carried by #34328; `content/docs/data-modeling/analytics.mdx` and `content/docs/ui/dashboards.mdx` state the rule in this change.

<!-- adr-0087: not-required (no-migration-prescription) a runtime request refusal: no metadata key, value or stored row changes shape, so `os migrate meta` has nothing to rewrite; authored and save-gated dashboards, reports and charts bind only declared members in their measures and dimensions (`widget-measure-unknown`, `chart-measure-unknown` and their dimension twins refuse anything else at build and at save); one class is not save-gated: a dashboard compare widget whose date-range field is not also the name of a declared dimension sends that field as an undeclared time dimension; when that field is the dataset object's own, its remedy is to declare a date dimension named after it, and when it is a related record's dotted field it is a break with no in-dataset remedy, because no dimension name can carry a dot -->

**BREAKING** for a caller of `POST /api/v1/analytics/dataset/query` (and each query of `/analytics/dataset/query/batch`), or of `AnalyticsService.queryDataset` in process, that names a measure or dimension the dataset does not declare. Such a selection used to be answered: the analytics service minted an aggregate for an undeclared measure (`count` counted rows, a raw field such as `amount` was summed, `amount_sum` likewise, a `<dataset>.revenue` spelling was resolved) and grouped by a raw field named as a dimension or a time dimension, so a dashboard tile could show a number labelled as a dataset metric that the dataset never defines. ADR-0021 makes the dataset a declarative, closed surface, and the AI tool `query_dataset` already refused these members; every face of a dataset query now reads the dataset the same way.

- A name in `selection.measures`, `selection.dimensions` or a `selection.timeDimensions` entry's `dimension` that is not one of the dataset's own `measures[].name` / `dimensions[].name`, spelled exactly so, is refused `400 INVALID_FIELD` before anything is read; the REST body is `{ code, message }`, and in process the thrown error also carries `member`, `param` and `cube` (the dataset's name). This applies to a saved `datasetName` and to an inline `dataset`, which is judged against its own `measures` and `dimensions`.
- The refusal names every undeclared member, the measures and dimensions THIS caller may use (never a withheld member or one over an `internal` field), and the fix: use one of those, or declare the member on the dataset and query it by that name. That fix is not offered for a compare window's date key that no dimension can be named (below), because it cannot apply to it.
- A declared member over a field the object does not have is still refused `400 INVALID_FIELD`; on the dataset door its message now points at the member's declared field (point it at one of the object's fields, or remove the member) instead of the cube door's hint that undeclared members are inferred or allowed. The cube door's message is unchanged.
- **A dashboard compare widget can be refused by this change, and no save gate catches it yet.** A widget with `compareTo` sends its date window, the dashboard's `dateRange` filter included, as a `timeDimensions` entry named after the filtered field (`dateRange.field`, `created_at` by default). The date-range field resolves against the object, not the dataset, so a dashboard that passes every save and publish check is refused when that field is not also the name of a date dimension the dataset declares. A census of the dashboards authored in this repository found none in this class; a dashboard saved at runtime or by a third party has no such guarantee. When the date-range field is a field of the dataset's own object, the refusal names the remedy in its message: declare a date dimension named after it (over that field). When it is a related record's field — a dotted `relationship.field` such as `account.signed_at`, which a dashboard filter may name and which a dataset query used to answer through the dataset's `include` — this is a break with no in-dataset remedy: a dimension name is a snake_case identifier with no dot, so no declaration can carry that key, and declaring a dimension over the path under another name does not help, because the widget still sends the window under the dotted name. The refusal says so, tells the author to declare nothing for that key, and names what the comparison needs: a date field of the dataset's own object that a declared date dimension names. The renderer mapping a dotted date key onto a declared dimension over that path is carried by #34350.
- Unchanged: a missing dataset is still `404 NOT_FOUND` first; a caller who may not read the dataset's object still gets the read refusal (`403`), never a member list; a declared member over a field the caller may not read is still `403 PERMISSION_DENIED`; `runtimeFilter` keys are fields, not members, and are judged as before. The cube query (`POST /api/v1/analytics/query`) is not a dataset and keeps its ad-hoc members.
6 changes: 6 additions & 0 deletions content/docs/api/data-api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,12 @@ Any other dotted spelling — `revenue.sum`, `owner.amount_sum` — is refused w
traverse relationships, only dimensions do, so there is no related column for a dotted
measure to aggregate. To aggregate a related column, declare a Cube whose measure names it
in its own `sql`.

These inferred spellings belong to the cube query only. The dataset query
(`POST /analytics/dataset/query`) answers only the measures and dimensions its dataset
declares, by their declared names, and refuses any other name — `count`, a raw field, a
suffix spelling — with `400 INVALID_FIELD` before anything is read; see
[Analytics](/docs/data-modeling/analytics).
</Callout>

<Callout type="info">
Expand Down
12 changes: 12 additions & 0 deletions content/docs/data-modeling/analytics.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,18 @@ with `400 VALIDATION_FAILED` naming it (a `runtimeFilter` beside `selection`
answers "did you mean `selection.runtimeFilter`?"), and so is a body naming
both `dataset` and `datasetName`.

A selection names only the members its dataset declares: each `measures` entry
is one of the dataset's `measures[].name`, and each `dimensions` entry and
`timeDimensions[].dimension` one of its `dimensions[].name`, spelled exactly so.
Anything else — the ad-hoc `count`, a raw field such as `amount`, a suffix
spelling such as `amount_sum`, a `<dataset>.revenue` spelling, a raw field named
as a dimension — is refused with `400 INVALID_FIELD` before anything is read.
The refusal's message names every undeclared member, lists the measures and
dimensions you may use, and the fix is to select one of them or declare the
member on the dataset. An inline `dataset` is judged against its own
`measures` and `dimensions`. The cube query (`POST {basePath}/analytics/query`)
is not a dataset and keeps its ad-hoc members.

A `datasetName` is read the way `GET /meta/dataset/:name` reads it: the
environment's own dataset, else the one package that holds the name. A name two
packages hold answers `409 RESOURCE_CONFLICT` naming both, and nothing runs. To
Expand Down
49 changes: 43 additions & 6 deletions content/docs/ui/dashboards.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ selects `dimensions` (X / group / split) and `values` (the measures to plot):
| `layout` | `object` | optional | Grid position and size (auto-flowed into the grid when omitted) |
| `chartConfig` | `object` | optional | Chart **appearance**: `title`, `subtitle`, `description`, `colors`, `height`, `showLegend`, `showDataLabels`, `annotations`, `interaction`. The bound dataset decides which series exist and which column each one reads, so `type`, `xAxis`, `yAxis` and `series` are refused here — see below |
| `colorVariant` | `enum` | optional | KPI/card accent color |
| `compareTo` | `object` | optional | Period-over-period comparison: `{ kind: 'previousPeriod' \| 'previousYear', dimension? }`. Omit `dimension` when the selection dates exactly one time dimension — the runtime resolves it, and errors naming the candidates rather than guessing when it cannot. The delta is coloured by the measure's `polarity`: `'lower'` draws a rise red and a fall green, `'neutral'` draws neither; undeclared, a rise is green. |
| `compareTo` | `object` | optional | Period-over-period comparison: `{ kind: 'previousPeriod' \| 'previousYear', dimension? }`. Omit `dimension` when the selection dates exactly one time dimension — the runtime resolves it, and errors naming the candidates rather than guessing when it cannot. The window's date key must be a dimension the dataset declares, so the date field it comes from must be a field of the dataset's own object — see [The Date Key of a Compare Widget](#the-date-key-of-a-compare-widget). The delta is coloured by the measure's `polarity`: `'lower'` draws a rise red and a fall green, `'neutral'` draws neither; undeclared, a rise is green. |
| `options` | `object` | optional | The query keys below. Presentation does not go here — see below |

### What `chartConfig` does **not** carry
Expand Down Expand Up @@ -494,11 +494,48 @@ both refuse the board rather than shipping it — see
Opt a single widget out with `filterBindings: { <name>: false }` (see
[Per-Widget Filter Bindings](#per-widget-filter-bindings) below).

This describes the **authorable surface** — what a dashboard may declare, and what
author-time validation accepts. It is not a claim about the analytics query API,
which does accept an object's own field as an ad-hoc dimension without the dataset
declaring it; `widget-dimension-unknown` is what holds the line for authored
dashboards.
The dataset query that renders a widget holds the same line at runtime: it
answers only the measures and dimensions its dataset declares, by their declared
names, and refuses an object's own field named as a dimension with
`400 INVALID_FIELD` (see [Datasets](/docs/data-modeling/analytics)).
`widget-dimension-unknown` refuses the same mistake at author time. Only the
cube query (`POST /analytics/query`), which is not a dataset, still groups by an
object's own field without a declaration.

### The Date Key of a Compare Widget

A widget with `compareTo` compares over a date window, and the runtime takes that
window from the widget's filter, the dashboard's `dateRange` filter included. The
window is sent to the dataset query as a time dimension named after the filtered
**field** (`dateRange.field`, `created_at` by default). A dataset query answers
only declared dimensions, so when that field is a field of the dataset's own
object, its name must also be the **name** of a date dimension the dataset
declares:

```typescript
dimensions: [
// The dashboard's dateRange filters `close_date`, so a compare widget's
// window arrives as the dimension "close_date".
{ name: 'close_date', label: 'Close date', field: 'close_date', type: 'date' },
],
```

Otherwise the widget's query is refused with `400 INVALID_FIELD`, and the message
names the remedy: declare a date dimension named after the date-range field.

A date field of a related record — a dotted `relationship.field` such as
`account.signed_at`, which a dashboard filter may otherwise name (see
[Filtering on a Related Record's Field](#filtering-on-a-related-records-field)) —
has no such remedy. A dimension name is a snake_case identifier with no dot, so
no dimension can carry that key, and the dataset query refuses the comparison
with `400 INVALID_FIELD`; the message offers no declaration for that key and
says the comparison needs a date field of the dataset's own object that a
declared date dimension names. Declaring a
dimension over the path under another name does not help, because the widget
still sends the window under the dotted field's name. A compare widget's date
window must therefore be a field of the dataset's own object.

No author-time rule checks a compare widget's date key yet.

### Filtering on a Related Record's Field

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
//
// END-TO-END gate: `POST /analytics/dataset/query` with a saved `datasetName`
// answers only the members the dataset declares (ADR-0021, ADR-0149 D1),
// proven on the stock showcase through the real stack (HTTP → REST → the
// dataset query door → AnalyticsService.queryDataset).
//
// Before, the door minted a member the dataset does not declare: the ad-hoc
// `count`, a raw field read as its `sum`, an `<field>_sum` suffix spelling, a
// `<dataset>.`-qualified spelling, and a raw field named as a dimension or a
// time dimension, each answered 200. Each now answers 400 INVALID_FIELD with
// the same refusal the AI tool `query_dataset` gives, on the single door and
// on each entry of the batch door.
//
// Controls: the declared members are served (200) on both doors; a missing
// dataset is still 404 first.

import { describe, it, expect, beforeAll, afterAll } from 'vitest';
import { type VerifyStack } from '@objectstack/verify';
import { bootShowcase } from './showcase-boot.js';

const DATASET = 'showcase_task_metrics';

describe('dogfood: the dataset query door refuses members the dataset does not declare', () => {
let stack: VerifyStack;
let token: string;

beforeAll(async () => {
stack = await bootShowcase();
token = await stack.signIn();
}, 180_000);

afterAll(async () => {
await stack?.stop?.();
});

async function datasetQuery(body: Record<string, unknown>): Promise<{ status: number; body: Record<string, any> }> {
const res = await stack.apiAs(token, 'POST', '/analytics/dataset/query', body);
return { status: res.status, body: (await res.json()) as Record<string, any> };
}
const codeOf = (body: Record<string, any>) => body.error?.code ?? body.code;
const messageOf = (body: Record<string, any>) => String(body.error?.message ?? body.message ?? '');

it('CONTROL: declared measures and dimensions, a declared time dimension included, are served', async () => {
const res = await datasetQuery({
datasetName: DATASET,
selection: {
measures: ['task_count', 'est_hours'],
dimensions: ['status'],
timeDimensions: [{ dimension: 'created_at', dateRange: ['2000-01-01', '2100-12-31'] }],
},
});
expect(res.status, JSON.stringify(res.body)).toBe(200);
expect(Array.isArray(res.body.rows)).toBe(true);
});

it.each([
['the ad-hoc count', { measures: ['count'] }, 'measure "count"'],
['a raw field as a measure', { measures: ['estimate_hours'] }, 'measure "estimate_hours"'],
['a suffix spelling', { measures: ['estimate_hours_sum'] }, 'measure "estimate_hours_sum"'],
['a dataset-qualified spelling', { measures: [`${DATASET}.task_count`] }, `measure "${DATASET}.task_count"`],
['a raw field as a dimension', { measures: ['task_count'], dimensions: ['estimate_hours'] }, 'dimension "estimate_hours"'],
[
'a raw field as a time dimension',
{ measures: ['task_count'], timeDimensions: [{ dimension: 'updated_at', granularity: 'month' }] },
'dimension "updated_at"',
],
])('%s → 400 INVALID_FIELD naming it and the declared members', async (_case, selection, named) => {
const res = await datasetQuery({ datasetName: DATASET, selection });
expect(res.status, JSON.stringify(res.body)).toBe(400);
expect(codeOf(res.body)).toBe('INVALID_FIELD');
expect(messageOf(res.body)).toContain(`The dataset "${DATASET}" does not declare the ${named}.`);
expect(messageOf(res.body)).toContain('task_count');
expect(messageOf(res.body)).toContain('declare the member on the dataset');
});

it('the batch door refuses the same entry with the same answer, and serves its declared sibling', async () => {
const res = await stack.apiAs(token, 'POST', '/analytics/dataset/query/batch', {
queries: [
{ datasetName: DATASET, selection: { measures: ['count'] } },
{ datasetName: DATASET, selection: { measures: ['task_count'] } },
],
});
expect(res.status).toBe(200);
const [refused, served] = ((await res.json()) as any).data.results;
expect([refused.status, refused.error.code]).toEqual([400, 'INVALID_FIELD']);
expect(refused.error.message).toContain(`The dataset "${DATASET}" does not declare the measure "count".`);
expect(Array.isArray(served.data?.rows)).toBe(true);
});

it('CONTROL: a missing dataset is still 404 first, whatever the members', async () => {
const res = await datasetQuery({ datasetName: 'no_such_dataset', selection: { measures: ['count'] } });
expect(res.status, JSON.stringify(res.body)).toBe(404);
});
});
Loading
Loading