Repository navigation
Commit 25fea77
fix(spec): an array in an analytics filter slot is refused once, with the object form shown (#30599)
<!-- claude-projects-attribution: {"github_login":"os-sales"} -->
_Requested by **Sales** · [project
thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4UuTTv3aGs6wx6iRvoDi9ySQ1)_
domain:spec#2 · os-sales · session_01L6bhgUpxbGjLnXrKiVLZzp
Fixes #30124
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 改了什么:仪表盘组件的 `filter`(以及数据集、度量的 `filter`、报表的
`runtimeFilter`)若写成列表视图那种规则数组,`os validate`
原来报两句互相矛盾、不给修法的话;现在只报一句,说明这里要的是按字段写的条件对象,并给出写法 `{ status: { $in: ['new',
'in_progress'] } }`。
- 为什么改:开发者和 AI 在同一个项目里同时写视图和仪表盘,最自然的就是把视图的过滤写法照抄过来,原报错让人卡住。
- 风险与回滚:只改报错文字并去掉重复的那一条;原来接受的照样接受,原来拒绝的照样拒绝,发布的 JSON Schema 不变。回滚即
revert 本 PR。
- 先看:`packages/spec/src/ui/analytics-carrier-filter.ts`(新增的
`prescribeObjectFormForArrayFilter` 与文案常量)→
`packages/spec/src/data/filter-save-door-face-parity.test.ts`(§8)。
- 两分钟验证:`pnpm --filter @objectstack/spec exec vitest run
src/data/filter-save-door-face-parity.test.ts`,预期 185 条全过;把
`.check(prescribeObjectFormForArrayFilter())` 删掉后 §8 中 7 条转红。
- 需要你做的:无,席位落地。
## What changes
`FilterConditionSchema` is a record intersected with the `$and` / `$or`
/ `$not` object, and an array fails both arms: two `invalid_type` issues
at the slot, `expected: 'record'` and `expected: 'object'`. Through the
ObjectStack error map they print `Expected record but received object.`
and `Expected object but received object.` (an array's `typeof` is
`object`), which contradict each other and name no fix. The text comes
from the spec schema plus its error map, not from the CLI's formatter,
so the fix lives in the spec.
- **`packages/spec/src/ui/analytics-carrier-filter.ts`.**
`analyticsCarrierFilter()` gains one check,
`prescribeObjectFormForArrayFilter()`, a `$ZodCheck` with `when: () =>
true` (the mechanism the view filter element's claimed-branch check in
`view.zod.ts` already uses). It runs only when the value is an array and
the slot already failed. It keeps the record arm's issue (code
`invalid_type`, its `expected`, its path) with a new message, and drops
the object arm's twin. The message, exported as
`ANALYTICS_FILTER_ARRAY_MESSAGE` from this module (outside the `ui`
barrel, so not published API):
> This filter is an array, and an analytics filter — a dashboard
widget's `filter`, a dataset's or a measure's `filter`, a report's
`runtimeFilter` — is the condition OBJECT a query's `where` takes, keyed
by field: `{ status: { $in: ['new', 'in_progress'] } }`, not the rule
array `[{ field: 'status', operator: 'in', value: ['new', 'in_progress']
}]` a list view's `filter` takes. Write one key per field, holding an
operator map (`{ amount: { $gte: 100 } }`) or a bare value for equality
(`{ status: 'open' }`); sibling keys AND together, and `$or: [{ … }, { …
}]` ORs conditions.
- All five carriers of `analyticsCarrierFilter()` get it at once:
`DashboardWidgetSchema.filter`, `DatasetSchema.filter`,
`DatasetMeasureSchema.filter`, `ReportSchema.runtimeFilter` and
`JoinedReportBlockSchema.runtimeFilter`. Every other
`FilterConditionSchema` carrier keeps its current text.
- The accept set is unchanged: the check never adds an issue to a value
that parsed, and never removes the last issue from one that failed. The
published JSON Schema is unchanged (`check:generated` reports all 14
artifacts current; `dropped-refinements.baseline.json` already lists
each carrier's `filter` site).
## Tests
New top-level `describe` §8 in
`packages/spec/src/data/filter-save-door-face-parity.test.ts`, the
existing harness for the analytics carriers:
- For each of the five carriers, the card's rule array is refused with
exactly ONE issue at the slot: `code: 'invalid_type'`, the path
(`widgets.0.filter`, `filter`, `measures.0.filter`, `runtimeFilter`,
`blocks.0.runtimeFilter`), and the message, including the shown object
form.
- For each carrier, the object form `{ status: { $in: ['new',
'in_progress'] } }` is accepted.
- `formatZodError` prints the widget refusal as one issue with the
prescription and no `but received object` line.
- The message is the issue's own, so it holds with no error map too.
- An accept-set battery of 17 values (`undefined`, `null`, scalars,
`[]`, `[{}]`, the rule array, an AST tuple array, plain, `$or` / `$and`
/ `$not` and malformed conditions): the carrier's verdict equals the
bare `FilterConditionSchema.optional()` verdict for every one, and every
non-array refusal keeps byte-identical issues.
## Verification
All readings on head `f5eede77`, repository
`objectstack-ai/objectstack`, base `origin/main` `2ffdb649`.
<details><summary>Repro through os validate</summary>
`examples/app-crm`, the first widget of `pipeline.dashboard.ts` set to
the card's `filter: [{ field: 'status', operator: 'in', value: ['new',
'in_progress'] }]` (applied and restored with
`scripts/ablation-replace.mjs`; restored blob equals HEAD), `node
../../packages/cli/bin/run.js validate` against the rebuilt CLI closure:
```text
✗ defineStack validation failed (1 issue):
✗ dashboards.0.widgets.0.filter: This filter is an array, and an analytics filter — a dashboard widget's `filter`, a dataset's or a measure's `filter`, a report's `runtimeFilter` — is the condition OBJECT a query's `where` takes, keyed by field: `{ status: { $in: ['new', 'in_progress'] } }`, not the rule array `[{ field: 'status', operator: 'in', value: ['new', 'in_progress'] }]` a list view's `filter` takes. Write one key per field, holding an operator map (`{ amount: { $gte: 100 } }`) or a bare value for equality (`{ status: 'open' }`); sibling keys AND together, and `$or: [{ … }, { … }]` ORs conditions.
validate exit 1
```
Before (`origin/main`, and the ablation leg below), the same slot
printed:
```text
✗ widgets.0.filter: Expected record but received object.
✗ widgets.0.filter: Expected object but received object.
```
</details>
<details><summary>Tests and ablation</summary>
- `pnpm --filter @objectstack/spec test && pnpm --filter
@objectstack/spec typecheck` under `os-verify-lock.sh`: `Test Files 815
passed (815)`, `Tests 25672 passed | 1 todo (25673)`, `VERDICT
command-exit 0`.
- `filter-save-door-face-parity.test.ts`: `Tests 185 passed (185)`.
- Ablation (`scripts/ablation-replace.mjs`, the spec tests import `src`,
so no dist leg): `.check(prescribeObjectFormForArrayFilter());` replaced
by `;`, anchor 1 → 0, blob `a33a04aff58c` → `2122b69f7d5c`: `Tests 7
failed | 178 passed (185)`, the five per-carrier pins, the formatter pin
and the no-error-map pin; the accept-set battery stays green, as it
should. Restored: blob equals HEAD, `git diff HEAD` empty.
</details>
<details><summary>Gates</summary>
- `pnpm --filter @objectstack/spec build` (VERDICT command-exit 0), then
`pnpm --filter @objectstack/spec check:generated`: `All 14 generated
artifacts are up to date` (exit 0; the first try exited 1 because
`check:test-typecheck`'s tsc ran out of heap at 4096 MB, rerun with 8192
MB).
- `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` on `f5eede77`: 78 families, every one run
with its exit code captured. Two first runs exited 3 on prerequisites,
not verdicts: `check-plugin-teardown-shape --self-test` (pinned fixture
commit missing in the shallow clone; fetched, rerun exit 0) and
`check:dual-build-cjs-loads` (nine packages without `dist/`; built,
rerun exit 0). Every other family exit 0.
- `--ran` reconciliation: `78 derived, 78 run, 0 NOT-MEASURED, 0 UNRUN`
(a derived zero: all 78 recorded an exit code, none is 3).
- `eslint --no-inline-config` on both changed source files: exit 0.
`check:nul-bytes`: exit 0.
- CI families: this PR's check-runs.
</details>
## Acceptance notes
- Out of scope by the card: whether a view filter and an analytics
filter should take one shape.
- The error map's `invalid_type` branch prints `typeof` input, so any
OTHER slot that refuses an array still reads `received object`. Not
changed here; this PR only fixes the analytics filter slots.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01L6bhgUpxbGjLnXrKiVLZzp
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 1c5cee6 commit 25fea77
3 files changed
Lines changed: 173 additions & 4 deletions
File tree
- .changeset
- packages/spec/src
- data
- ui
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
| 54 | + | |
| 55 | + | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| |||
818 | 819 | | |
819 | 820 | | |
820 | 821 | | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
205 | 205 | | |
206 | 206 | | |
207 | 207 | | |
208 | | - | |
209 | | - | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
210 | 270 | | |
0 commit comments