Repository navigation
Commit aab8b31
feat(spec)!: a lookupFilters value may read the record being edited ($record) and an entry may match an empty column (orEmpty) (#34078)
<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi99sMrzgLeLs3XZDMAJhAyrC)_
Fixes #34009
Clause-②: yes (narrowing) — widened: a field's `lookupFilters` entry (a
lookup, master_detail or user field) gains `orEmpty` and a declared `{
$record: "path" }` value, and `@objectstack/spec/data` gains
`LookupFilterRecordReferenceSchema` / `LookupFilterRecordReference` /
`LookupFilterRecordReferenceParsed`. Narrowed: an entry whose `value` is
an object carrying `$record` in any other shape (two or more hops,
non-snake_case names, another key beside `$record`, or operator `in` /
`notIn` / `contains`), or a list value holding such an object, parsed
before, as any value did, and is now refused.
Metadata-protocol: narrowed
Skills-docs: follow-up owed —
content/docs/data-modeling/relationships.mdx,
content/docs/data-modeling/fields.mdx,
skills/objectstack-data/rules/field-types.md — not taught yet on
purpose: the console picker resolves neither `{ $record }` nor `orEmpty`
in this release (both describes carry `[PLANNED — not enforced]`); the
docs move with the picker change.
## 维护者速读
1. **改了什么**:lookup 字段的 `lookupFilters` 条目可以写 `{ $record: "字段" }` 或 `{
$record: "lookup字段.字段" }`(读正在编辑的这条记录,最多跨一跳),并新增 `orEmpty:
true`(候选列为空也算匹配);两者只配 eq/ne/gt/lt/gte/lte。「今天」直接用已有的 `{today}` / `{
$now: true, addDays }`,不新增写法。
2. **为什么改**:下游 CRM 报价单的价目表选择器要只列「报价日期在有效期内、市场与客户一致或为通用」的价目表,现有
`lookupFilters` 只能写字面量,做不到。
3. **风险与回滚**:本 PR 只改 spec 契约;控制台选择器尚未解析 `$record`/`orEmpty`(已标 `[PLANNED
— not enforced]`,作者现在写了 `$record` 选择器会报错而不是给错结果)。唯一收窄:以前能解析但从来不能用的畸形
`$record` 值现在保存即拒,已登记语义迁移条目。回滚即撤销本 PR。
4.
**先看**:`packages/spec/src/data/field.zod.ts`(`refuseMalformedLookupFilterEntry`
与 `lookupFilters` 的 describe)、`packages/spec/src/data/field.test.ts`(末尾新
describe,含 2027-01-05
报价单场景)、`.changeset/34009-lookup-filters-record-reference.md`。
5. **两分钟验证**:`pnpm --filter @objectstack/spec exec vitest run
src/data/field.test.ts -t 'comparand and orEmpty'`,预期 14 个用例全绿。
6. **需要你做的**:无,席位落地。
## What changes
- **`FieldSchema.lookupFilters[]`**
(`packages/spec/src/data/field.zod.ts`): each entry gains `orEmpty?:
boolean` and a declared `{ $record: "path" }` value, judged by one
entry-level refinement (`refuseMalformedLookupFilterEntry`):
- `$record` path: a field of the record being edited, or one lookup hop
(`account.cb_market`), snake_case names, at most one dot; refused at
`value.$record` otherwise.
- A `{ $record }` value pairs only with `eq` / `ne` / `gt` / `lt` /
`gte` / `lte` (the six a filter `{ $field }` or `$now` anchor may be the
whole comparand of); refused at `value` under `in` / `notIn` /
`contains`, and at `value.I` as a member of a list.
- `orEmpty` pairs only with the same six; refused at `orEmpty`
otherwise.
- The `{ $record }` object is a closed `strictObject`
(`LookupFilterRecordReferenceSchema`, exported with its type so the
picker and server follow-ups import one declaration): a key beside
`$record` is refused with the strict-object guidance (`addDays` and
`$field` carry pointed prescriptions).
- The entry's strict-object aliases name `orEmpty` for `orNull` /
`orBlank` / `allowEmpty` / `allowNull` / `includeEmpty` / `includeNull`.
- **The rules stated in the describe and JSDoc** (the contract the ui
and server follow-ups are written against): the picker sends the
referenced value in place of `{ $record }`; it re-queries when a
referenced field changes, the first path segment, which is implied and
must not be listed in `dependsOn` for that purpose (a `dependsOn` entry
also scopes the candidate query by equality, `param = value`, so
`dependsOn: ['date']` would add `date = …` to the Price Book query); it
leaves the entry out while the value is empty, and on a picker with no
single record being edited (bulk-action bar, filter panel); a `{ $record
}` that reaches a server unresolved is refused, never read as null.
- **Reuse, measured**: no `$today` / `$now` twin. `'{today}'` (date
macro) and `{ $now: true, addDays }` already ride a `lookupFilters`
value: the picker passes the value through (`lookupFiltersToRecord`,
objectui `RecordPickerDialog.tsx`) and the engine resolves both on every
read (`resolveFilterTokens`, `packages/objectql/src/engine-find.ts`);
`sys-approval-delegation.object.ts` already ships `{current_user_id}` in
a `lookupFilters` value the same way.
- **Name check**: `$record` has no meaning in the filter DSL today; it
is the flow engine's variable for the record a run acts on
(`flow-text-slot-template.ts`), the same idea in a different namespace.
- **Narrowing, registered**: semantic entry
`lookup-filter-record-reference-shape-refused` (ADR-0087), changeset
`registered`.
- **Ledgers**: `dropped-refinements.baseline.json` +12 sites (the new
entry refinement, `lookupFilters.element` on Field and the 11 schemas
that embed it; printed by the build), `liveness/field.json`
`lookupFilters` row note dated (declared ahead of its reader),
regenerated references, api-surface, export-origins, declaration-map,
strictness-ledger counts.
- No forced test edit: no existing test changed.
- Not in this PR (named follow-ups, the seat files them): the console
picker resolving `{ $record }` / `orEmpty` (ui lane); a server refusal
of an unresolved `{ $record }` by name (server lane); the
`readonlyWhen`-reads-a-related-record gap (its own card).
## Tests
- `packages/spec/src/data/field.test.ts`, new top-level describe
"FieldSchema.lookupFilters — { $record } comparand and orEmpty" (14
cases): the card's four-entry example parses with every key kept;
controls (bare literal, `in` list, `{today}`, `$now` anchor, `{ $field
}`, `{current_user_id}`) keep parsing; two hops, non-snake_case paths,
`in`/`notIn`/`contains` + `$record`, a `{ $record }` member of an
`in`/`notIn` list, `orEmpty` on those three, and a key beside `$record`
are each refused at the named path; `orNull` is pointed at `orEmpty`; `{
$field }` and `{ $record }` stay distinct; an unresolved `{ $record }`
under each of the six operators is refused by the shared filter door
with `INVALID_FILTER` / 400, and the `eq` shorthand the picker sends for
the market entry passes the door unchanged (pinned, refused later by the
driver; flips with the server follow-up); the 2027-01-05 quote vs 2026
Q4 book fixture (what the picker is told to send) offers the 2027 export
and generic books, never the Q4 one, and drops the market entry while
the account has no market.
- Ablation (one-shot, `scripts/ablation-replace.mjs`): removing
`.superRefine(refuseMalformedLookupFilterEntry)` turns 6 of the 14 red
(re-run at 3ff6dc9).
## Acceptance notes
- Measured, not changed: with the eq shorthand the picker's flat
lowering produces (`{ cb_market: { $record: "…" } }`) the shared spec
door reads the object as filter structure and lets it through;
`driver-memory` then refuses it as `Unsupported filter operator
"$record"` (`INVALID_FILTER` / 400). The ordering forms are refused at
the door itself. So an unresolved `{ $record }` is refused on the
picker's server path either way, by a generic sentence; the by-name
refusal is the server follow-up.
- `@objectstack/lint` runs clean on the card's stack (tokens, preset
comparands, object field refs, empty combinators: zero findings). No
lint rule reads a `$record` path yet (`git grep` finds none under
`packages/lint/src`), so a misspelt path such as `"acount.cb_market"` is
not caught before the picker meets it: worth carrying with the picker
follow-up.
## Verification
Readings are in the report comment on the card; the gate list was
derived after the final commit with `dispatch-gates --commands` and
reconciled with `--ran`.
<!-- signed: domain:spec#2 · os-steve · session_01ADHkmSBdZayQvo47yKhtGD
-->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent a061708 commit aab8b31
16 files changed
Lines changed: 492 additions & 24 deletions
File tree
- .changeset
- content/docs/references
- data
- system
- docs/audits/2026-07-unknown-key-strictness-ledger.counts
- packages/spec
- api-surface
- authorable-surface
- declaration-map
- export-origins
- json-schema.manifest
- liveness
- src
- data
- migrations/entries/semantic
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | | - | |
| 16 | + | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
96 | | - | |
| 96 | + | |
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
| |||
236 | 236 | | |
237 | 237 | | |
238 | 238 | | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
239 | 248 | | |
240 | 249 | | |
241 | 250 | | |
| |||
424 | 433 | | |
425 | 434 | | |
426 | 435 | | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
427 | 449 | | |
428 | 450 | | |
429 | 451 | | |
| |||
0 commit comments