From cf735f7d186bed371028e559b3bf587176ea5f9c Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 05:37:18 +0000 Subject: [PATCH 01/12] fix(core): resolveFilterTokens refuses an unresolved { $record } comparand by name The lookupFilters { $record: 'path' } comparand reads the record a form is editing, which only that form's record picker knows. An unresolved one now answers INVALID_FILTER / 400 from the engine's token pass, naming the field, the $record path and its position, instead of reaching the driver. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jUZKdq3PK2Sab53cT3 --- packages/core/src/utils/filter-tokens.test.ts | 61 +++++++++ packages/core/src/utils/filter-tokens.ts | 123 +++++++++++++++++- 2 files changed, 182 insertions(+), 2 deletions(-) diff --git a/packages/core/src/utils/filter-tokens.test.ts b/packages/core/src/utils/filter-tokens.test.ts index 04d07031700..2b48cf08d86 100644 --- a/packages/core/src/utils/filter-tokens.test.ts +++ b/packages/core/src/utils/filter-tokens.test.ts @@ -259,6 +259,67 @@ describe('resolveFilterTokens — the record-context token refuses by name', () }); }); +describe('[#34199] resolveFilterTokens — an unresolved { $record } comparand refuses by name', () => { + // A FULL context, as for `{record_id}`: nothing a request carries resolves it. + const full = { now: NOW, userId: 'usr_1', orgId: 'org_9', timezone: 'UTC' }; + + function refusal(filter: unknown): { code?: string; status?: number; message: string } { + let err: unknown; + try { + resolveFilterTokens(filter, full); + } catch (e) { + err = e; + } + expect(err, 'expected a refusal').toBeInstanceOf(Error); + return err as { code?: string; status?: number; message: string }; + } + + it.each([ + // The two shapes a picker that does not resolve it sends (the card's market entry). + ['the eq shorthand', { cb_market: { $record: 'account.cb_market' } }, 'cb_market', 'account.cb_market', 'filter.cb_market'], + ['an operator comparand', { cb_market: { $eq: { $record: 'account.cb_market' } } }, 'cb_market', 'account.cb_market', 'filter.cb_market.$eq'], + ['an ordering comparand', { valid_from: { $lte: { $record: 'quote_date' } } }, 'valid_from', 'quote_date', 'filter.valid_from.$lte'], + ['inside $or beside a literal', { $or: [{ cb_market: 'export' }, { cb_market: { $record: 'account.cb_market' } }] }, 'cb_market', 'account.cb_market', 'filter.$or[1].cb_market'], + ['under $not', { $not: { cb_market: { $ne: { $record: 'account.cb_market' } } } }, 'cb_market', 'account.cb_market', 'filter.$not.cb_market.$ne'], + ['beside a string token it no longer depends on', { $and: [{ owner: '{current_user_id}' }, { cb_market: { $record: 'account.cb_market' } }] }, 'cb_market', 'account.cb_market', 'filter.$and[1].cb_market'], + ['the nested-relation form', { account: { cb_market: { $record: 'account.cb_market' } } }, 'account.cb_market', 'account.cb_market', 'filter.account.cb_market'], + ['a rule entry, as a lookupFilters entry is written', [{ field: 'cb_market', operator: 'eq', value: { $record: 'account.cb_market' } }], 'cb_market', 'account.cb_market', 'filter[0].value'], + ['a [field, op, value] tuple', ['cb_market', '=', { $record: 'account.cb_market' }], 'cb_market', 'account.cb_market', 'filter[2]'], + ])('%s: INVALID_FILTER / 400 naming the field, the $record path and the position', (_label, filter, field, path, at) => { + const err = refusal(filter); + expect(err.code).toBe('INVALID_FILTER'); + expect(err.status).toBe(400); + expect(err.message).toContain(`{ "$record": "${path}" }`); + expect(err.message).toContain(`on field "${field}"`); + expect(err.message).toContain(`at ${at} reached the server unresolved`); + }); + + it('refuses a malformed reference by its key too, and one at the root names no field', () => { + const malformed = refusal({ cb_market: { $record: 'account.cb_market', addDays: 1 } }); + expect(malformed.code).toBe('INVALID_FILTER'); + expect(malformed.message).toContain('on field "cb_market"'); + const root = refusal({ $record: 'account.cb_market' }); + expect(root.code).toBe('INVALID_FILTER'); + expect(root.status).toBe(400); + expect(root.message).not.toContain('on field'); + expect(root.message).toContain('at filter reached the server unresolved'); + }); + + it('control — a filter with no placeholder still returns by reference, nested objects included', () => { + const plain = { cb_market: 'export', account: { region: 'NA' }, meta: { $eq: 'x' }, $or: [{ score: { $gt: 1 } }] }; + expect(resolveFilterTokens(plain, full)).toBe(plain); + }); + + it('control — string tokens and the $now anchor resolve as before, with `record` only as a value', () => { + expect(resolveFilterTokens({ owner: '{current_user_id}', due: { $lt: '{today}' }, note: '$record', kind: 'record' }, full)).toEqual({ + owner: 'usr_1', due: { $lt: '2026-07-15' }, note: '$record', kind: 'record', + }); + expect(resolveFilterTokens({ due: { $gte: { $now: true, addDays: -1 } } }, full)).toEqual({ + due: { $gte: { $now: NOW.toISOString(), addDays: -1 } }, + }); + }); +}); + describe('resolveFilterTokens — tree walk', () => { const ctx = { now: NOW, userId: 'usr_1', orgId: 'org_9' }; diff --git a/packages/core/src/utils/filter-tokens.ts b/packages/core/src/utils/filter-tokens.ts index 7211feb2c60..e30975d3af7 100644 --- a/packages/core/src/utils/filter-tokens.ts +++ b/packages/core/src/utils/filter-tokens.ts @@ -111,6 +111,14 @@ * to `null`, `undefined` or the literal: a count written as "about this * record" would otherwise come back as "about nobody", or, with the condition * gone, "about everybody". + * + * # A `{ $record }` comparand always refuses here too + * + * [#34199] The `lookupFilters` comparand `{ $record: 'path' }` reads the record + * a form is editing, which only that form's record picker knows, so it is the + * same case as `{record_id}` in object form: refused by name on every path, + * `INVALID_FILTER` / 400 naming the field, the `$record` path and where it + * sits — see {@link isRecordReference}. */ import { @@ -521,6 +529,9 @@ function hasFilterToken(node: unknown): boolean { if (node && typeof node === 'object' && !(node instanceof Date)) { // [#25808] An unresolved `$now` anchor is a placeholder by construction. if (isUnresolvedNowAnchor(node)) return true; + // [#34199] So is a `{ $record }` reference — one the walk refuses, so the + // fast path must not hand it back by reference for want of a string token. + if (isRecordReference(node)) return true; return Object.values(node as Record).some(hasFilterToken); } return false; @@ -572,6 +583,101 @@ class MalformedNowAnchorError extends Error { } } +/** + * [#34199] `{ $record: 'path' }` — the `lookupFilters` comparand that reads the + * RECORD BEING EDITED (`LookupFilterRecordReferenceSchema`, + * `@objectstack/spec/data`): a field of that record, or one lookup hop from it + * (`account.cb_market`). Only the record picker of the form editing that + * record can resolve it — it sends the referenced value in its place before + * the query leaves the browser — and no server path knows which record a form + * is editing. So, like `{record_id}`, it never resolves here: any plain object + * carrying an own `$record` key, at any depth and in any position, is refused + * by name ({@link UnresolvedRecordReferenceError}) before a driver sees it. + * + * Refused HERE because this is the one pass every engine read and write + * filter, and every analytics filter, goes through, whether or not it holds a + * string token. Before this, the reference reached the driver and was refused + * there in words that never named it (driver-memory: an unsupported operator + * `"$record"`; driver-sql: an operator withheld from the message). The refusal reads + * the KEY, not the shape: a malformed reference (`{ $record: 1 }`, a key + * beside `$record`) is no more resolvable than a well-formed one. + * + * Doors upstream of this pass may refuse first, in their own words: the + * engine's comparand-type door refuses any plain object under an operator + * (`{ f: { $eq: { $record: 'x' } } }`), and the temporal door a non-date + * comparand on a date column. Either way the filter never runs. + */ +function isRecordReference(node: unknown): node is Record { + return !!node && typeof node === 'object' && !Array.isArray(node) + && Object.prototype.hasOwnProperty.call(node, '$record'); +} + +/** One step of the walk: the node descended from and the key or index taken. */ +interface FilterWalkStep { + readonly parent: unknown; + readonly key: string | number; +} + +/** + * [#34199] The field a `{ $record }` comparand is aimed at, read off the walk's + * steps: the non-`$` keys on the way down (`account` then `region` for the + * nested-relation form), a rule entry's own `field` when the reference is its + * `value` (`{ field, operator, value }`), and the head of a `[field, op, + * value]` tuple. `undefined` when no field names it (the filter's root). + */ +function fieldOfRecordReference(steps: readonly FilterWalkStep[]): string | undefined { + let parts: string[] = []; + for (const { parent, key } of steps) { + if (Array.isArray(parent)) { + if (key === 2 && parent.length === 3 && typeof parent[0] === 'string') parts = [parent[0]]; + continue; + } + const k = String(key); + if (k.startsWith('$')) continue; + const ruleField = (parent as Record).field; + if (k === 'value' && typeof ruleField === 'string') parts = [ruleField]; + else parts.push(k); + } + return parts.length > 0 ? parts.join('.') : undefined; +} + +/** [#34199] Where the walk stands, spelled from the filter's root: `filter.$or[0].cb_market`. */ +function filterLocation(steps: readonly FilterWalkStep[]): string { + return steps.reduce((at, { key }) => (typeof key === 'number' ? `${at}[${key}]` : `${at}.${key}`), 'filter'); +} + +/** + * [#34199] An unresolved `{ $record }` comparand met at resolution — see + * {@link isRecordReference}. `INVALID_FILTER` / 400, the code every comparand + * door answers with and the one the drivers answered this input with before; + * the message names the field, the `$record` path and where it sits. + * ⛔ Not `FILTER_TOKEN_UNRESOLVED`: that code's declared meaning is a + * vocabulary placeholder string the request carries no context for, and the + * `{ $record }` reference is a comparand object, not a placeholder string. + * + * Not exported, like the module's other `INVALID_FILTER` refusals: a caller + * reads `code` and `status`. + */ +class UnresolvedRecordReferenceError extends Error { + readonly status = 400; + readonly code = 'INVALID_FILTER' satisfies StandardErrorCode; + + constructor(reference: Record, steps: readonly FilterWalkStep[]) { + const field = fieldOfRecordReference(steps); + super( + `A { "$record": ${JSON.stringify(reference.$record)} } comparand ` + + `${field ? `on field "${field}" ` : ''}at ${filterLocation(steps)} reached the server unresolved, ` + + 'and is refused rather than compared. { $record } reads the record being edited (a field of it, ' + + 'or one lookup hop such as "account.cb_market"), and only the record picker of the form editing ' + + 'that record can resolve it: the picker sends the referenced value in its place. No server path ' + + 'knows which record a form is editing, so reading the reference as null, or comparing the object ' + + 'as a literal, would answer rows the filter was written to exclude. Send the referenced value ' + + 'itself, or write { $record } only in a lookup field\'s lookupFilters, where the picker resolves it.', + ); + this.name = 'UnresolvedRecordReferenceError'; + } +} + /** [#25808] The anchor with its instant pinned — see {@link isUnresolvedNowAnchor}. */ function resolveNowAnchor(node: { $now: true; addDays?: unknown }, now: Date): Record { const offset = node.addDays; @@ -612,6 +718,17 @@ export function resolveFilterTokens( // One instant for the whole tree (see FilterTokenResolutionContext.now). const pinned: FilterTokenResolutionContext = { ...ctx, now: ctx.now ?? new Date() }; + // [#34199] Where the walk stands, read only to word a refusal. Pushed and + // popped around each descent; a throw abandons the whole walk, so it needs + // no unwinding. + const steps: FilterWalkStep[] = []; + const descend = (parent: unknown, key: string | number, child: unknown): unknown => { + steps.push({ parent, key }); + const out = walk(child); + steps.pop(); + return out; + }; + const walk = (node: unknown): unknown => { if (typeof node === 'string') { const cls = classifyFilterToken(node); @@ -624,16 +741,18 @@ export function resolveFilterTokens( if (resolved === undefined) throw new UnknownFilterTokenError(cls.token); return resolved; } - if (Array.isArray(node)) return node.map(walk); + if (Array.isArray(node)) return node.map((v, i) => descend(node, i, v)); // [ADR-0139 D1] The leaf by reference, brand intact (see above). if (isReadableIds(node)) return node; if (node && typeof node === 'object') { // Dates and other class instances are comparands, not filter structure. if (node instanceof Date) return node; + // [#34199] A `{ $record }` reference never resolves on a server. + if (isRecordReference(node)) throw new UnresolvedRecordReferenceError(node, steps); // [#25808] The now anchor: its instant pinned, its offset kept. if (isUnresolvedNowAnchor(node)) return resolveNowAnchor(node, pinned.now!); const out: Record = {}; - for (const [k, v] of Object.entries(node as Record)) out[k] = walk(v); + for (const [k, v] of Object.entries(node as Record)) out[k] = descend(node, k, v); return out; } return node; From dd3e51197ce3f1ad6ae12ea0c0b06348a07044e6 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 05:39:35 +0000 Subject: [PATCH 02/12] test(drivers): pin the by-name { $record } refusal on driver-memory and driver-sql; spec describes state the server half Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jUZKdq3PK2Sab53cT3 --- .../memory-record-reference-refusal.test.ts | 87 ++++++++++++++++++ ...ql-driver-record-reference-refusal.test.ts | 90 +++++++++++++++++++ packages/spec/src/data/field.zod.ts | 9 +- 3 files changed, 182 insertions(+), 4 deletions(-) create mode 100644 packages/drivers/driver-memory/src/memory-record-reference-refusal.test.ts create mode 100644 packages/drivers/driver-sql/src/sql-driver-record-reference-refusal.test.ts diff --git a/packages/drivers/driver-memory/src/memory-record-reference-refusal.test.ts b/packages/drivers/driver-memory/src/memory-record-reference-refusal.test.ts new file mode 100644 index 00000000000..81144f43281 --- /dev/null +++ b/packages/drivers/driver-memory/src/memory-record-reference-refusal.test.ts @@ -0,0 +1,87 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * [#34199] An unresolved `lookupFilters` `{ $record: 'path' }` comparand never + * reaches this driver: the engine's token pass (`resolveFilterTokens`, + * `@objectstack/core`) refuses it by name, `INVALID_FILTER` / 400, naming the + * field, the `$record` path and its position. + * + * `{ $record }` reads the record a form is editing, which only that form's + * record picker knows; a picker that does not resolve it sends the eq + * shorthand `{ cb_market: { $record: 'account.cb_market' } }` or an operator + * comparand. Measured on `origin/main` 22438726f3, this driver refused the + * shorthand itself, as an operator it does not know (`Unsupported filter + * operator "$record"`, `INVALID_FILTER` / 400); the second half below pins + * that it still does for a caller that passes no seam. The operator form + * (`{ $eq: { $record } }`) is refused through the engine by its comparand + * door before this driver is asked, so it is pinned here at the seam only. + */ + +import { describe, it, expect, beforeEach, vi } from 'vitest'; +import { resolveFilterTokens } from '@objectstack/core'; +import type { FilterCondition } from '@objectstack/spec/data'; +import { InMemoryDriver } from './memory-driver.js'; + +/** What the engine's token pass hands a driver. */ +const seamed = (where: unknown): FilterCondition => + resolveFilterTokens(where, { userId: 'usr_1' }) as FilterCondition; + +interface Refusal { code?: string; status?: number; message: string } + +describe('[#34199] InMemoryDriver — an unresolved { $record } comparand', () => { + let driver: InMemoryDriver; + + beforeEach(async () => { + driver = new InMemoryDriver({ persistence: false }); + await driver.syncSchema('price_book', { + fields: { + id: { type: 'text', name: 'id' }, + cb_market: { type: 'text', name: 'cb_market' }, + owner: { type: 'text', name: 'owner' }, + }, + }); + await driver.create('price_book', { id: '1', cb_market: 'export', owner: 'usr_1' }); + await driver.create('price_book', { id: '2', cb_market: null, owner: 'usr_2' }); + }); + + const refusalOf = async (read: () => Promise): Promise => { + try { + await read(); + } catch (e) { + return e as Refusal; + } + throw new Error('expected a refusal, but the read resolved'); + }; + + const SHAPES: ReadonlyArray = [ + ['the eq shorthand', { cb_market: { $record: 'account.cb_market' } }, 'filter.cb_market'], + ['an operator comparand', { cb_market: { $eq: { $record: 'account.cb_market' } } }, 'filter.cb_market.$eq'], + ]; + + for (const [label, where, at] of SHAPES) { + it(`${label}: refused by name at the engine's token seam, before the driver is asked`, async () => { + const find = vi.spyOn(driver, 'find'); + const err = await refusalOf(async () => driver.find('price_book', { fields: ['id'], where: seamed(where) })); + expect(err.code).toBe('INVALID_FILTER'); + expect(err.status).toBe(400); + expect(err.message).toContain('{ "$record": "account.cb_market" }'); + expect(err.message).toContain('on field "cb_market"'); + expect(err.message).toContain(`at ${at} reached the server unresolved`); + expect(find).not.toHaveBeenCalled(); + }); + } + + it('the eq shorthand: a caller that passes no seam is refused by the driver itself, never answered rows', async () => { + const err = await refusalOf(() => + driver.find('price_book', { fields: ['id'], where: { cb_market: { $record: 'account.cb_market' } } as unknown as FilterCondition })); + expect(err.code).toBe('INVALID_FILTER'); + expect(err.status).toBe(400); + }); + + it('control — an ordinary filter and a string token run through the same seam as before', async () => { + const ids = async (where: unknown) => + ((await driver.find('price_book', { fields: ['id'], where: seamed(where) })) as Array<{ id: string }>).map((r) => String(r.id)).sort(); + expect(await ids({ cb_market: 'export' })).toEqual(['1']); + expect(await ids({ owner: '{current_user_id}' })).toEqual(['1']); + }); +}); diff --git a/packages/drivers/driver-sql/src/sql-driver-record-reference-refusal.test.ts b/packages/drivers/driver-sql/src/sql-driver-record-reference-refusal.test.ts new file mode 100644 index 00000000000..4c7ee7f9704 --- /dev/null +++ b/packages/drivers/driver-sql/src/sql-driver-record-reference-refusal.test.ts @@ -0,0 +1,90 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * [#34199] An unresolved `lookupFilters` `{ $record: 'path' }` comparand never + * reaches this driver: the engine's token pass (`resolveFilterTokens`, + * `@objectstack/core`) refuses it by name, `INVALID_FILTER` / 400, naming the + * field, the `$record` path and its position. + * + * `{ $record }` reads the record a form is editing, which only that form's + * record picker knows; a picker that does not resolve it sends the eq + * shorthand `{ cb_market: { $record: 'account.cb_market' } }` or an operator + * comparand. Measured on `origin/main` 22438726f3 (SQLite, in-process), this + * driver refused both itself, in words that withheld which operator and field + * it met: "A filter operator in this filter is not one this driver evaluates" + * (shorthand) and "requires a single comparable value" (`$eq`), each + * `INVALID_FILTER` / 400. The second half below pins that it still refuses, + * so a caller that passes no seam never gets rows for it either. + */ + +import { describe, it, expect, beforeEach, vi } from 'vitest'; +import { resolveFilterTokens } from '@objectstack/core'; +import type { FilterCondition } from '@objectstack/spec/data'; +import { lowerFilterCondition } from '@objectstack/spec/data'; +import { SqlDriver } from './index.js'; + +/** What the engine hands a driver: tokens resolved, then the shared lowering. */ +const seamed = (where: unknown): FilterCondition => + lowerFilterCondition(resolveFilterTokens(where, { userId: 'usr_1' }) as FilterCondition, { isDatetimeColumn: () => false }) as FilterCondition; + +interface Refusal { code?: string; status?: number; message: string } + +describe('[#34199] SqlDriver — an unresolved { $record } comparand', () => { + let driver: SqlDriver; + + beforeEach(async () => { + driver = new SqlDriver({ client: 'better-sqlite3', connection: { filename: ':memory:' }, useNullAsDefault: true }); + await driver.initObjects([ + { + name: 'price_book', + fields: { + id: { type: 'text', name: 'id' }, + cb_market: { type: 'text', name: 'cb_market' }, + owner: { type: 'text', name: 'owner' }, + }, + } as any, + ]); + await driver.create('price_book', { id: '1', cb_market: 'export', owner: 'usr_1' }); + await driver.create('price_book', { id: '2', cb_market: null, owner: 'usr_2' }); + }); + + const refusalOf = async (read: () => Promise): Promise => { + try { + await read(); + } catch (e) { + return e as Refusal; + } + throw new Error('expected a refusal, but the read resolved'); + }; + + const SHAPES: ReadonlyArray = [ + ['the eq shorthand', { cb_market: { $record: 'account.cb_market' } }, 'filter.cb_market'], + ['an operator comparand', { cb_market: { $eq: { $record: 'account.cb_market' } } }, 'filter.cb_market.$eq'], + ]; + + for (const [label, where, at] of SHAPES) { + it(`${label}: refused by name at the engine's token seam, before the driver is asked`, async () => { + const find = vi.spyOn(driver, 'find'); + const err = await refusalOf(async () => driver.find('price_book', { fields: ['id'], where: seamed(where) })); + expect(err.code).toBe('INVALID_FILTER'); + expect(err.status).toBe(400); + expect(err.message).toContain('{ "$record": "account.cb_market" }'); + expect(err.message).toContain('on field "cb_market"'); + expect(err.message).toContain(`at ${at} reached the server unresolved`); + expect(find).not.toHaveBeenCalled(); + }); + + it(`${label}: a caller that passes no seam is refused by the driver itself, never answered rows`, async () => { + const err = await refusalOf(() => driver.find('price_book', { fields: ['id'], where: where as FilterCondition })); + expect(err.code).toBe('INVALID_FILTER'); + expect(err.status).toBe(400); + }); + } + + it('control — an ordinary filter and a string token run through the same seam as before', async () => { + const ids = async (where: unknown) => + ((await driver.find('price_book', { fields: ['id'], where: seamed(where) })) as Array<{ id: string }>).map((r) => String(r.id)).sort(); + expect(await ids({ cb_market: 'export' })).toEqual(['1']); + expect(await ids({ owner: '{current_user_id}' })).toEqual(['1']); + }); +}); diff --git a/packages/spec/src/data/field.zod.ts b/packages/spec/src/data/field.zod.ts index 5acb2adaa7f..bed40f8d039 100644 --- a/packages/spec/src/data/field.zod.ts +++ b/packages/spec/src/data/field.zod.ts @@ -2251,7 +2251,8 @@ export const FieldSchema = lazySchema(() => { 'The comparand: a literal (an array for `in` / `notIn`), a date placeholder such as `{today}` or a ' + '{ $now: true, addDays } comparand for a date relative to today, or a { $record: "path" } reference to the ' + 'record being edited — a field of it, or one lookup hop ("account.cb_market"); a { $record } value pairs ' - + 'only with eq, ne, gt, lt, gte or lte. [PLANNED — not enforced] The picker does not resolve { $record } yet.', + + 'only with eq, ne, gt, lt, gte or lte. A { $record } that reaches a server unresolved is refused by name ' + + '(INVALID_FILTER). [PLANNED — not enforced] The picker does not resolve { $record } yet.', ), orEmpty: z.boolean().optional().describe( '[PLANNED — not enforced] TRUE: the entry also matches a candidate whose column is null — "valid from the ' @@ -2266,9 +2267,9 @@ export const FieldSchema = lazySchema(() => { + '(`dependsOn: [\'quote_date\']` adds `quote_date = …` to the query over the referenced object). While the value is ' + 'empty, and on a picker with no single record being edited (a bulk-action bar, a filter panel), the entry is left ' + 'out. A { $record } is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A { $record } that reaches a ' - + 'server unresolved is refused, never read as null. The picker narrows the choice only: a rule the save must ' - + 'enforce belongs on the server too. [PLANNED — not enforced] { $record } and orEmpty are declared ahead of the ' - + 'picker that resolves them.', + + 'server unresolved is refused by name (INVALID_FILTER, naming the field and the path), never read as null. The ' + + 'picker narrows the choice only: a rule the save must enforce belongs on the server too. [PLANNED — not ' + + 'enforced] The picker does not resolve { $record } or read orEmpty yet.', ), dependsOn: z.array(z.union([z.string(), strictObject({ surface: 'this dependsOn entry', From 95db9b9e5d375f15b3f4f098e7b70651bae8b481 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 05:46:26 +0000 Subject: [PATCH 03/12] docs(spec): regenerate the field references for the lookupFilters describes Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jUZKdq3PK2Sab53cT3 --- content/docs/references/data/field.mdx | 4 ++-- content/docs/references/data/object.mdx | 4 ++-- content/docs/references/system/migration.mdx | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/content/docs/references/data/field.mdx b/content/docs/references/data/field.mdx index bb7336bbe6b..b91e2cf0292 100644 --- a/content/docs/references/data/field.mdx +++ b/content/docs/references/data/field.mdx @@ -93,7 +93,7 @@ const result = CurrencyConfigSchema.parse(data); | **descriptionField** | `string` | optional | Secondary field shown under the label in the quick-select popover. | | **lookupColumns** | `(string \| { field: string; label?: string; width?: string; type?: string })[]` | optional | Explicit columns for the record-picker table; auto-derived from the referenced object when omitted. | | **lookupPageSize** | `integer` | optional | Rows per page in the record-picker dialog (default 10). | -| **lookupFilters** | `{ field: string; operator: Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>; value: any; orEmpty?: boolean }[]` | optional | Base filters restricting which records are selectable (e.g. only active). The structured, picker-honoured lookup filter. Each entry compares a column of the CANDIDATE record (`field`, on the referenced object) with `value`. A value may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }` (at most one lookup hop): the picker sends that value in its place and re-queries whenever a referenced field changes. Those fields are implied: do not list them in `dependsOn`, which also scopes the candidate query by equality (`dependsOn: ['quote_date']` adds `quote_date = …` to the query over the referenced object). While the value is empty, and on a picker with no single record being edited (a bulk-action bar, a filter panel), the entry is left out. A `{ $record }` is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A `{ $record }` that reaches a server unresolved is refused, never read as null. The picker narrows the choice only: a rule the save must enforce belongs on the server too. [PLANNED — not enforced] `{ $record }` and orEmpty are declared ahead of the picker that resolves them. | +| **lookupFilters** | `{ field: string; operator: Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>; value: any; orEmpty?: boolean }[]` | optional | Base filters restricting which records are selectable (e.g. only active). The structured, picker-honoured lookup filter. Each entry compares a column of the CANDIDATE record (`field`, on the referenced object) with `value`. A value may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }` (at most one lookup hop): the picker sends that value in its place and re-queries whenever a referenced field changes. Those fields are implied: do not list them in `dependsOn`, which also scopes the candidate query by equality (`dependsOn: ['quote_date']` adds `quote_date = …` to the query over the referenced object). While the value is empty, and on a picker with no single record being edited (a bulk-action bar, a filter panel), the entry is left out. A `{ $record }` is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A `{ $record }` that reaches a server unresolved is refused by name (INVALID_FILTER, naming the field and the path), never read as null. The picker narrows the choice only: a rule the save must enforce belongs on the server too. [PLANNED — not enforced] The picker does not resolve `{ $record }` or read orEmpty yet. | | **dependsOn** | `(string \| { field: string; param?: string })[]` | optional | Declares that this field's available values depend on the value of other field(s) on the same record — the form gates the field until they are set and re-evaluates as they change. For `lookup`/`master_detail` it scopes the candidate query (string = same local/remote key; `{field,param}` when the remote filter key differs — the `{field,param}` form is lookup-only). For `select`/`multiselect`/`radio` the actual per-option rule lives in each option's `visibleWhen`; list the referenced fields here (string form) so the option list gates and refreshes with the parent. | | **allowCreate** | `boolean` | optional | Allow inline quick-create from the record picker: when no match exists the user can create a record from the typed text (optimistic dataSource.create with the display field). Best for simple objects whose only required field is the display field. | | **lookupAutofill** | `{ target: string; source: string; overwrite?: boolean }[]` | optional | Fields a pick in this lookup fills on the record being edited: each `{ target, source }` pair copies the picked record's `source` field (a field of the `reference` object) into this object's `target` field — e.g. `[{ target: 'unit_price', source: 'list_price' }]` on a quote line's product lookup. Read wherever this field is picked: the record form, and a line-item grid column over it. OVERWRITE RULE — the default, `overwrite` absent or false: a pick never replaces a value somebody wrote. The target is filled only while it is empty or still holds the value an earlier pick filled in; a value the user typed, or one the record already stored, stays. Only a pair that declares `overwrite: true` replaces the target on every pick, whatever it holds. Client-side only: it fills the form, and nothing on the write path reads it — the filled value is saved as an ordinary write, and an import or API write that sets the lookup fills nothing. Only on a single-value `lookup` / `master_detail`. Each target is a field of this object other than this one, written by its author — not `readonly`, not computed (`formula`, `summary`, `autonumber`, or an `expression`) — and named once. Each source is a field of the referenced object that the record carries (not `internal`) and whose value the target can hold; `os validate` / `os build` judge the source. In a line-item grid the column key `autofill` still governs only the same-named copy and is unchanged; a declared pair takes its target out of that copy. | @@ -242,7 +242,7 @@ const result = CurrencyConfigSchema.parse(data); | :--- | :--- | :--- | :--- | | **field** | `string` | ✅ | | | **operator** | `Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>` | ✅ | | -| **value** | `any` | ✅ | The comparand: a literal (an array for `in` / `notIn`), a date placeholder such as `{today}` or a `{ $now: true, addDays }` comparand for a date relative to today, or a `{ $record: "path" }` reference to the record being edited — a field of it, or one lookup hop ("account.cb_market"); a `{ $record }` value pairs only with eq, ne, gt, lt, gte or lte. [PLANNED — not enforced] The picker does not resolve `{ $record }` yet. | +| **value** | `any` | ✅ | The comparand: a literal (an array for `in` / `notIn`), a date placeholder such as `{today}` or a `{ $now: true, addDays }` comparand for a date relative to today, or a `{ $record: "path" }` reference to the record being edited — a field of it, or one lookup hop ("account.cb_market"); a `{ $record }` value pairs only with eq, ne, gt, lt, gte or lte. A `{ $record }` that reaches a server unresolved is refused by name (INVALID_FILTER). [PLANNED — not enforced] The picker does not resolve `{ $record }` yet. | | **orEmpty** | `boolean` | optional | [PLANNED — not enforced] TRUE: the entry also matches a candidate whose column is null — "valid from the quote date, or with no start date". Only with eq, ne, gt, lt, gte or lte. The picker does not read it yet. | ### Nested Shape: `Field.lookupAutofill[number]` diff --git a/content/docs/references/data/object.mdx b/content/docs/references/data/object.mdx index c571b0fe6bf..bd5c6e5993c 100644 --- a/content/docs/references/data/object.mdx +++ b/content/docs/references/data/object.mdx @@ -270,7 +270,7 @@ const result = ApiMethod.parse(data); | **descriptionField** | `string` | optional | Secondary field shown under the label in the quick-select popover. | | **lookupColumns** | `(string \| { field: string; label?: string; width?: string; type?: string })[]` | optional | Explicit columns for the record-picker table; auto-derived from the referenced object when omitted. | | **lookupPageSize** | `integer` | optional | Rows per page in the record-picker dialog (default 10). | -| **lookupFilters** | `{ field: string; operator: Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>; value: any; orEmpty?: boolean }[]` | optional | Base filters restricting which records are selectable (e.g. only active). The structured, picker-honoured lookup filter. Each entry compares a column of the CANDIDATE record (`field`, on the referenced object) with `value`. A value may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }` (at most one lookup hop): the picker sends that value in its place and re-queries whenever a referenced field changes. Those fields are implied: do not list them in `dependsOn`, which also scopes the candidate query by equality (`dependsOn: ['quote_date']` adds `quote_date = …` to the query over the referenced object). While the value is empty, and on a picker with no single record being edited (a bulk-action bar, a filter panel), the entry is left out. A `{ $record }` is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A `{ $record }` that reaches a server unresolved is refused, never read as null. The picker narrows the choice only: a rule the save must enforce belongs on the server too. [PLANNED — not enforced] `{ $record }` and orEmpty are declared ahead of the picker that resolves them. | +| **lookupFilters** | `{ field: string; operator: Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>; value: any; orEmpty?: boolean }[]` | optional | Base filters restricting which records are selectable (e.g. only active). The structured, picker-honoured lookup filter. Each entry compares a column of the CANDIDATE record (`field`, on the referenced object) with `value`. A value may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }` (at most one lookup hop): the picker sends that value in its place and re-queries whenever a referenced field changes. Those fields are implied: do not list them in `dependsOn`, which also scopes the candidate query by equality (`dependsOn: ['quote_date']` adds `quote_date = …` to the query over the referenced object). While the value is empty, and on a picker with no single record being edited (a bulk-action bar, a filter panel), the entry is left out. A `{ $record }` is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A `{ $record }` that reaches a server unresolved is refused by name (INVALID_FILTER, naming the field and the path), never read as null. The picker narrows the choice only: a rule the save must enforce belongs on the server too. [PLANNED — not enforced] The picker does not resolve `{ $record }` or read orEmpty yet. | | **dependsOn** | `(string \| { field: string; param?: string })[]` | optional | Declares that this field's available values depend on the value of other field(s) on the same record — the form gates the field until they are set and re-evaluates as they change. For `lookup`/`master_detail` it scopes the candidate query (string = same local/remote key; `{field,param}` when the remote filter key differs — the `{field,param}` form is lookup-only). For `select`/`multiselect`/`radio` the actual per-option rule lives in each option's `visibleWhen`; list the referenced fields here (string form) so the option list gates and refreshes with the parent. | | **allowCreate** | `boolean` | optional | Allow inline quick-create from the record picker: when no match exists the user can create a record from the typed text (optimistic dataSource.create with the display field). Best for simple objects whose only required field is the display field. | | **lookupAutofill** | `{ target: string; source: string; overwrite?: boolean }[]` | optional | Fields a pick in this lookup fills on the record being edited: each `{ target, source }` pair copies the picked record's `source` field (a field of the `reference` object) into this object's `target` field — e.g. `[{ target: 'unit_price', source: 'list_price' }]` on a quote line's product lookup. Read wherever this field is picked: the record form, and a line-item grid column over it. OVERWRITE RULE — the default, `overwrite` absent or false: a pick never replaces a value somebody wrote. The target is filled only while it is empty or still holds the value an earlier pick filled in; a value the user typed, or one the record already stored, stays. Only a pair that declares `overwrite: true` replaces the target on every pick, whatever it holds. Client-side only: it fills the form, and nothing on the write path reads it — the filled value is saved as an ordinary write, and an import or API write that sets the lookup fills nothing. Only on a single-value `lookup` / `master_detail`. Each target is a field of this object other than this one, written by its author — not `readonly`, not computed (`formula`, `summary`, `autonumber`, or an `expression`) — and named once. Each source is a field of the referenced object that the record carries (not `internal`) and whose value the target can hold; `os validate` / `os build` judge the source. In a line-item grid the column key `autofill` still governs only the same-named copy and is unchanged; a declared pair takes its target out of that copy. | @@ -647,7 +647,7 @@ const result = ApiMethod.parse(data); | **descriptionField** | `string` | optional | Secondary field shown under the label in the quick-select popover. | | **lookupColumns** | `(string \| { field: string; label?: string; width?: string; type?: string })[]` | optional | Explicit columns for the record-picker table; auto-derived from the referenced object when omitted. | | **lookupPageSize** | `integer` | optional | Rows per page in the record-picker dialog (default 10). | -| **lookupFilters** | `{ field: string; operator: Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>; value: any; orEmpty?: boolean }[]` | optional | Base filters restricting which records are selectable (e.g. only active). The structured, picker-honoured lookup filter. Each entry compares a column of the CANDIDATE record (`field`, on the referenced object) with `value`. A value may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }` (at most one lookup hop): the picker sends that value in its place and re-queries whenever a referenced field changes. Those fields are implied: do not list them in `dependsOn`, which also scopes the candidate query by equality (`dependsOn: ['quote_date']` adds `quote_date = …` to the query over the referenced object). While the value is empty, and on a picker with no single record being edited (a bulk-action bar, a filter panel), the entry is left out. A `{ $record }` is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A `{ $record }` that reaches a server unresolved is refused, never read as null. The picker narrows the choice only: a rule the save must enforce belongs on the server too. [PLANNED — not enforced] `{ $record }` and orEmpty are declared ahead of the picker that resolves them. | +| **lookupFilters** | `{ field: string; operator: Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>; value: any; orEmpty?: boolean }[]` | optional | Base filters restricting which records are selectable (e.g. only active). The structured, picker-honoured lookup filter. Each entry compares a column of the CANDIDATE record (`field`, on the referenced object) with `value`. A value may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }` (at most one lookup hop): the picker sends that value in its place and re-queries whenever a referenced field changes. Those fields are implied: do not list them in `dependsOn`, which also scopes the candidate query by equality (`dependsOn: ['quote_date']` adds `quote_date = …` to the query over the referenced object). While the value is empty, and on a picker with no single record being edited (a bulk-action bar, a filter panel), the entry is left out. A `{ $record }` is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A `{ $record }` that reaches a server unresolved is refused by name (INVALID_FILTER, naming the field and the path), never read as null. The picker narrows the choice only: a rule the save must enforce belongs on the server too. [PLANNED — not enforced] The picker does not resolve `{ $record }` or read orEmpty yet. | | **dependsOn** | `(string \| { field: string; param?: string })[]` | optional | Declares that this field's available values depend on the value of other field(s) on the same record — the form gates the field until they are set and re-evaluates as they change. For `lookup`/`master_detail` it scopes the candidate query (string = same local/remote key; `{field,param}` when the remote filter key differs — the `{field,param}` form is lookup-only). For `select`/`multiselect`/`radio` the actual per-option rule lives in each option's `visibleWhen`; list the referenced fields here (string form) so the option list gates and refreshes with the parent. | | **allowCreate** | `boolean` | optional | Allow inline quick-create from the record picker: when no match exists the user can create a record from the typed text (optimistic dataSource.create with the display field). Best for simple objects whose only required field is the display field. | | **lookupAutofill** | `{ target: string; source: string; overwrite?: boolean }[]` | optional | Fields a pick in this lookup fills on the record being edited: each `{ target, source }` pair copies the picked record's `source` field (a field of the `reference` object) into this object's `target` field — e.g. `[{ target: 'unit_price', source: 'list_price' }]` on a quote line's product lookup. Read wherever this field is picked: the record form, and a line-item grid column over it. OVERWRITE RULE — the default, `overwrite` absent or false: a pick never replaces a value somebody wrote. The target is filled only while it is empty or still holds the value an earlier pick filled in; a value the user typed, or one the record already stored, stays. Only a pair that declares `overwrite: true` replaces the target on every pick, whatever it holds. Client-side only: it fills the form, and nothing on the write path reads it — the filled value is saved as an ordinary write, and an import or API write that sets the lookup fills nothing. Only on a single-value `lookup` / `master_detail`. Each target is a field of this object other than this one, written by its author — not `readonly`, not computed (`formula`, `summary`, `autonumber`, or an `expression`) — and named once. Each source is a field of the referenced object that the record carries (not `internal`) and whose value the target can hold; `os validate` / `os build` judge the source. In a line-item grid the column key `autofill` still governs only the same-named copy and is unchanged; a declared pair takes its target out of that copy. | diff --git a/content/docs/references/system/migration.mdx b/content/docs/references/system/migration.mdx index 138a99c90d1..cfe1bf1c29e 100644 --- a/content/docs/references/system/migration.mdx +++ b/content/docs/references/system/migration.mdx @@ -96,7 +96,7 @@ Add a new field to an existing object | **descriptionField** | `string` | optional | Secondary field shown under the label in the quick-select popover. | | **lookupColumns** | `(string \| { field: string; label?: string; width?: string; type?: string })[]` | optional | Explicit columns for the record-picker table; auto-derived from the referenced object when omitted. | | **lookupPageSize** | `integer` | optional | Rows per page in the record-picker dialog (default 10). | -| **lookupFilters** | `{ field: string; operator: Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>; value: any; orEmpty?: boolean }[]` | optional | Base filters restricting which records are selectable (e.g. only active). The structured, picker-honoured lookup filter. Each entry compares a column of the CANDIDATE record (`field`, on the referenced object) with `value`. A value may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }` (at most one lookup hop): the picker sends that value in its place and re-queries whenever a referenced field changes. Those fields are implied: do not list them in `dependsOn`, which also scopes the candidate query by equality (`dependsOn: ['quote_date']` adds `quote_date = …` to the query over the referenced object). While the value is empty, and on a picker with no single record being edited (a bulk-action bar, a filter panel), the entry is left out. A `{ $record }` is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A `{ $record }` that reaches a server unresolved is refused, never read as null. The picker narrows the choice only: a rule the save must enforce belongs on the server too. [PLANNED — not enforced] `{ $record }` and orEmpty are declared ahead of the picker that resolves them. | +| **lookupFilters** | `{ field: string; operator: Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>; value: any; orEmpty?: boolean }[]` | optional | Base filters restricting which records are selectable (e.g. only active). The structured, picker-honoured lookup filter. Each entry compares a column of the CANDIDATE record (`field`, on the referenced object) with `value`. A value may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }` (at most one lookup hop): the picker sends that value in its place and re-queries whenever a referenced field changes. Those fields are implied: do not list them in `dependsOn`, which also scopes the candidate query by equality (`dependsOn: ['quote_date']` adds `quote_date = …` to the query over the referenced object). While the value is empty, and on a picker with no single record being edited (a bulk-action bar, a filter panel), the entry is left out. A `{ $record }` is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A `{ $record }` that reaches a server unresolved is refused by name (INVALID_FILTER, naming the field and the path), never read as null. The picker narrows the choice only: a rule the save must enforce belongs on the server too. [PLANNED — not enforced] The picker does not resolve `{ $record }` or read orEmpty yet. | | **dependsOn** | `(string \| { field: string; param?: string })[]` | optional | Declares that this field's available values depend on the value of other field(s) on the same record — the form gates the field until they are set and re-evaluates as they change. For `lookup`/`master_detail` it scopes the candidate query (string = same local/remote key; `{field,param}` when the remote filter key differs — the `{field,param}` form is lookup-only). For `select`/`multiselect`/`radio` the actual per-option rule lives in each option's `visibleWhen`; list the referenced fields here (string form) so the option list gates and refreshes with the parent. | | **allowCreate** | `boolean` | optional | Allow inline quick-create from the record picker: when no match exists the user can create a record from the typed text (optimistic dataSource.create with the display field). Best for simple objects whose only required field is the display field. | | **lookupAutofill** | `{ target: string; source: string; overwrite?: boolean }[]` | optional | Fields a pick in this lookup fills on the record being edited: each `{ target, source }` pair copies the picked record's `source` field (a field of the `reference` object) into this object's `target` field — e.g. `[{ target: 'unit_price', source: 'list_price' }]` on a quote line's product lookup. Read wherever this field is picked: the record form, and a line-item grid column over it. OVERWRITE RULE — the default, `overwrite` absent or false: a pick never replaces a value somebody wrote. The target is filled only while it is empty or still holds the value an earlier pick filled in; a value the user typed, or one the record already stored, stays. Only a pair that declares `overwrite: true` replaces the target on every pick, whatever it holds. Client-side only: it fills the form, and nothing on the write path reads it — the filled value is saved as an ordinary write, and an import or API write that sets the lookup fills nothing. Only on a single-value `lookup` / `master_detail`. Each target is a field of this object other than this one, written by its author — not `readonly`, not computed (`formula`, `summary`, `autonumber`, or an `expression`) — and named once. Each source is a field of the referenced object that the record carries (not `internal`) and whose value the target can hold; `os validate` / `os build` judge the source. In a line-item grid the column key `autofill` still governs only the same-named copy and is unchanged; a declared pair takes its target out of that copy. | @@ -532,7 +532,7 @@ Add a new field to an existing object | **descriptionField** | `string` | optional | Secondary field shown under the label in the quick-select popover. | | **lookupColumns** | `(string \| { field: string; label?: string; width?: string; type?: string })[]` | optional | Explicit columns for the record-picker table; auto-derived from the referenced object when omitted. | | **lookupPageSize** | `integer` | optional | Rows per page in the record-picker dialog (default 10). | -| **lookupFilters** | `{ field: string; operator: Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>; value: any; orEmpty?: boolean }[]` | optional | Base filters restricting which records are selectable (e.g. only active). The structured, picker-honoured lookup filter. Each entry compares a column of the CANDIDATE record (`field`, on the referenced object) with `value`. A value may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }` (at most one lookup hop): the picker sends that value in its place and re-queries whenever a referenced field changes. Those fields are implied: do not list them in `dependsOn`, which also scopes the candidate query by equality (`dependsOn: ['quote_date']` adds `quote_date = …` to the query over the referenced object). While the value is empty, and on a picker with no single record being edited (a bulk-action bar, a filter panel), the entry is left out. A `{ $record }` is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A `{ $record }` that reaches a server unresolved is refused, never read as null. The picker narrows the choice only: a rule the save must enforce belongs on the server too. [PLANNED — not enforced] `{ $record }` and orEmpty are declared ahead of the picker that resolves them. | +| **lookupFilters** | `{ field: string; operator: Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>; value: any; orEmpty?: boolean }[]` | optional | Base filters restricting which records are selectable (e.g. only active). The structured, picker-honoured lookup filter. Each entry compares a column of the CANDIDATE record (`field`, on the referenced object) with `value`. A value may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }` (at most one lookup hop): the picker sends that value in its place and re-queries whenever a referenced field changes. Those fields are implied: do not list them in `dependsOn`, which also scopes the candidate query by equality (`dependsOn: ['quote_date']` adds `quote_date = …` to the query over the referenced object). While the value is empty, and on a picker with no single record being edited (a bulk-action bar, a filter panel), the entry is left out. A `{ $record }` is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A `{ $record }` that reaches a server unresolved is refused by name (INVALID_FILTER, naming the field and the path), never read as null. The picker narrows the choice only: a rule the save must enforce belongs on the server too. [PLANNED — not enforced] The picker does not resolve `{ $record }` or read orEmpty yet. | | **dependsOn** | `(string \| { field: string; param?: string })[]` | optional | Declares that this field's available values depend on the value of other field(s) on the same record — the form gates the field until they are set and re-evaluates as they change. For `lookup`/`master_detail` it scopes the candidate query (string = same local/remote key; `{field,param}` when the remote filter key differs — the `{field,param}` form is lookup-only). For `select`/`multiselect`/`radio` the actual per-option rule lives in each option's `visibleWhen`; list the referenced fields here (string form) so the option list gates and refreshes with the parent. | | **allowCreate** | `boolean` | optional | Allow inline quick-create from the record picker: when no match exists the user can create a record from the typed text (optimistic dataSource.create with the display field). Best for simple objects whose only required field is the display field. | | **lookupAutofill** | `{ target: string; source: string; overwrite?: boolean }[]` | optional | Fields a pick in this lookup fills on the record being edited: each `{ target, source }` pair copies the picked record's `source` field (a field of the `reference` object) into this object's `target` field — e.g. `[{ target: 'unit_price', source: 'list_price' }]` on a quote line's product lookup. Read wherever this field is picked: the record form, and a line-item grid column over it. OVERWRITE RULE — the default, `overwrite` absent or false: a pick never replaces a value somebody wrote. The target is filled only while it is empty or still holds the value an earlier pick filled in; a value the user typed, or one the record already stored, stays. Only a pair that declares `overwrite: true` replaces the target on every pick, whatever it holds. Client-side only: it fills the form, and nothing on the write path reads it — the filled value is saved as an ordinary write, and an import or API write that sets the lookup fills nothing. Only on a single-value `lookup` / `master_detail`. Each target is a field of this object other than this one, written by its author — not `readonly`, not computed (`formula`, `summary`, `autonumber`, or an `expression`) — and named once. Each source is a field of the referenced object that the record carries (not `internal`) and whose value the target can hold; `os validate` / `os build` judge the source. In a line-item grid the column key `autofill` still governs only the same-named copy and is unchanged; a declared pair takes its target out of that copy. | From 3ffb1f689d911392fdebd07a0423827b3b44436e Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 05:47:13 +0000 Subject: [PATCH 04/12] chore: changeset for the by-name { $record } refusal Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jUZKdq3PK2Sab53cT3 --- .../34199-record-reference-refused-by-name.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .changeset/34199-record-reference-refused-by-name.md diff --git a/.changeset/34199-record-reference-refused-by-name.md b/.changeset/34199-record-reference-refused-by-name.md new file mode 100644 index 00000000000..3f948cbc94e --- /dev/null +++ b/.changeset/34199-record-reference-refused-by-name.md @@ -0,0 +1,18 @@ +--- +'@objectstack/core': minor +'@objectstack/spec': minor +--- + +fix(core): an unresolved `{ $record }` lookup-filter comparand is refused by name before any driver sees it + +Clause-②: no +Metadata-protocol: semantic + +A `lookupFilters` entry may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }`; only the record picker of the form editing that record can replace it with a value. When one reaches a server unresolved, the engine's token pass (`resolveFilterTokens`) now refuses it with `INVALID_FILTER` / 400, and the message names the field, the `$record` path and its position, for example: + +`A { "$record": "account.cb_market" } comparand on field "cb_market" at filter.cb_market reached the server unresolved, and is refused rather than compared.` + +- Before: the eq shorthand `{ cb_market: { $record: "account.cb_market" } }` reached the driver, which refused it in its own words: driver-memory as an unsupported operator `"$record"`, driver-sql with the operator and field withheld. Both were already `INVALID_FILTER` / 400 (driver-mongodb refuses an unknown operator the same way), so on the built-in drivers no filter that answered rows now refuses. +- Now: every read and write filter the engine resolves, and every analytics filter, is refused in the one sentence above, whether or not it also holds a string placeholder. The operator form `{ cb_market: { $eq: { $record: "…" } } }` is still refused one door earlier on the engine's object path, by the comparand-type door, as before. + +The `lookupFilters` describes now state the server half as enforced; the `[PLANNED — not enforced]` marker stays on the picker half, which does not resolve `{ $record }` or read `orEmpty` yet. From b566d04bef84bd4ba236a98f2a87488f311e4206 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 05:47:27 +0000 Subject: [PATCH 05/12] chore: changeset wording Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jUZKdq3PK2Sab53cT3 --- .changeset/34199-record-reference-refused-by-name.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/34199-record-reference-refused-by-name.md b/.changeset/34199-record-reference-refused-by-name.md index 3f948cbc94e..5074b1ce2d1 100644 --- a/.changeset/34199-record-reference-refused-by-name.md +++ b/.changeset/34199-record-reference-refused-by-name.md @@ -13,6 +13,6 @@ A `lookupFilters` entry may read the record being edited as `{ $record: "field" `A { "$record": "account.cb_market" } comparand on field "cb_market" at filter.cb_market reached the server unresolved, and is refused rather than compared.` - Before: the eq shorthand `{ cb_market: { $record: "account.cb_market" } }` reached the driver, which refused it in its own words: driver-memory as an unsupported operator `"$record"`, driver-sql with the operator and field withheld. Both were already `INVALID_FILTER` / 400 (driver-mongodb refuses an unknown operator the same way), so on the built-in drivers no filter that answered rows now refuses. -- Now: every read and write filter the engine resolves, and every analytics filter, is refused in the one sentence above, whether or not it also holds a string placeholder. The operator form `{ cb_market: { $eq: { $record: "…" } } }` is still refused one door earlier on the engine's object path, by the comparand-type door, as before. +- Now: a read or write filter the engine resolves, or an analytics filter, that carries one is refused in the one sentence above, whether or not it also holds a string placeholder. The operator form `{ cb_market: { $eq: { $record: "…" } } }` is still refused one door earlier on the engine's object path, by the comparand-type door, as before. The `lookupFilters` describes now state the server half as enforced; the `[PLANNED — not enforced]` marker stays on the picker half, which does not resolve `{ $record }` or read `orEmpty` yet. From 9718f78ca647312ab51b6baa4af8277261a8ee53 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 08:04:02 +0000 Subject: [PATCH 06/12] fix(core): refuse an unresolved { $record } only where it is a field's comparand A { $record } inside a no-$ object beneath a field is a deep-equality comparand or a nested-relation condition, and passes through as before; the refusal reads the field's own value and its operators' values only. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jUZKdq3PK2Sab53cT3 --- packages/core/src/utils/filter-tokens.test.ts | 40 ++-- packages/core/src/utils/filter-tokens.ts | 185 ++++++++++-------- 2 files changed, 131 insertions(+), 94 deletions(-) diff --git a/packages/core/src/utils/filter-tokens.test.ts b/packages/core/src/utils/filter-tokens.test.ts index 2b48cf08d86..17a8000d406 100644 --- a/packages/core/src/utils/filter-tokens.test.ts +++ b/packages/core/src/utils/filter-tokens.test.ts @@ -275,34 +275,42 @@ describe('[#34199] resolveFilterTokens — an unresolved { $record } comparand r } it.each([ - // The two shapes a picker that does not resolve it sends (the card's market entry). + // The eq shorthand is what a picker that does not resolve it sends (the card's market entry). ['the eq shorthand', { cb_market: { $record: 'account.cb_market' } }, 'cb_market', 'account.cb_market', 'filter.cb_market'], ['an operator comparand', { cb_market: { $eq: { $record: 'account.cb_market' } } }, 'cb_market', 'account.cb_market', 'filter.cb_market.$eq'], ['an ordering comparand', { valid_from: { $lte: { $record: 'quote_date' } } }, 'valid_from', 'quote_date', 'filter.valid_from.$lte'], ['inside $or beside a literal', { $or: [{ cb_market: 'export' }, { cb_market: { $record: 'account.cb_market' } }] }, 'cb_market', 'account.cb_market', 'filter.$or[1].cb_market'], ['under $not', { $not: { cb_market: { $ne: { $record: 'account.cb_market' } } } }, 'cb_market', 'account.cb_market', 'filter.$not.cb_market.$ne'], ['beside a string token it no longer depends on', { $and: [{ owner: '{current_user_id}' }, { cb_market: { $record: 'account.cb_market' } }] }, 'cb_market', 'account.cb_market', 'filter.$and[1].cb_market'], - ['the nested-relation form', { account: { cb_market: { $record: 'account.cb_market' } } }, 'account.cb_market', 'account.cb_market', 'filter.account.cb_market'], - ['a rule entry, as a lookupFilters entry is written', [{ field: 'cb_market', operator: 'eq', value: { $record: 'account.cb_market' } }], 'cb_market', 'account.cb_market', 'filter[0].value'], - ['a [field, op, value] tuple', ['cb_market', '=', { $record: 'account.cb_market' }], 'cb_market', 'account.cb_market', 'filter[2]'], + // A column literally named `value` beside one named `field` is two columns, not a rule entry. + ['on a column named value beside one named field', { field: 'x', value: { $record: 'account.cb_market' } }, 'value', 'account.cb_market', 'filter.value'], ])('%s: INVALID_FILTER / 400 naming the field, the $record path and the position', (_label, filter, field, path, at) => { const err = refusal(filter); expect(err.code).toBe('INVALID_FILTER'); expect(err.status).toBe(400); expect(err.message).toContain(`{ "$record": "${path}" }`); - expect(err.message).toContain(`on field "${field}"`); - expect(err.message).toContain(`at ${at} reached the server unresolved`); + expect(err.message).toContain(`on field "${field}" at ${at} reached the server unresolved`); }); - it('refuses a malformed reference by its key too, and one at the root names no field', () => { + it('refuses a malformed reference by its key too', () => { const malformed = refusal({ cb_market: { $record: 'account.cb_market', addDays: 1 } }); expect(malformed.code).toBe('INVALID_FILTER'); - expect(malformed.message).toContain('on field "cb_market"'); - const root = refusal({ $record: 'account.cb_market' }); - expect(root.code).toBe('INVALID_FILTER'); - expect(root.status).toBe(400); - expect(root.message).not.toContain('on field'); - expect(root.message).toContain('at filter reached the server unresolved'); + expect(malformed.status).toBe(400); + expect(malformed.message).toContain('on field "cb_market" at filter.cb_market reached'); + }); + + it.each([ + // A no-`$` object beneath a field is a deep-equality comparand (or a + // nested-relation condition): the `$record` inside it is data to this pass. + ['inside a deep-equality comparand', { attachment: { meta: { $record: 'x' } } }], + ['inside a nested-relation condition', { account: { cb_market: { $record: 'account.cb_market' } } }], + // A list member: the engine's comparand-type door refuses it first, and the + // first string of the list is never read as a field name. + ['as an $in list member', { region: { $in: ['NA', 'EU', { $record: 'account.region' }] } }], + ['at the root, where no field names it', { $record: 'account.cb_market' }], + ['as the third member of a [field, op, value] tuple', ['cb_market', '=', { $record: 'account.cb_market' }]], + ])('control — %s: not a field\'s comparand, so it comes back by reference', (_label, filter) => { + expect(resolveFilterTokens(filter, full)).toBe(filter); }); it('control — a filter with no placeholder still returns by reference, nested objects included', () => { @@ -318,6 +326,12 @@ describe('[#34199] resolveFilterTokens — an unresolved { $record } comparand r due: { $gte: { $now: NOW.toISOString(), addDays: -1 } }, }); }); + + it('control — a deep { $record } beside a string token is resolved around, kept as written', () => { + expect(resolveFilterTokens({ owner: '{current_user_id}', attachment: { meta: { $record: 'x' } } }, full)).toEqual({ + owner: 'usr_1', attachment: { meta: { $record: 'x' } }, + }); + }); }); describe('resolveFilterTokens — tree walk', () => { diff --git a/packages/core/src/utils/filter-tokens.ts b/packages/core/src/utils/filter-tokens.ts index e30975d3af7..f2645adc6bd 100644 --- a/packages/core/src/utils/filter-tokens.ts +++ b/packages/core/src/utils/filter-tokens.ts @@ -112,13 +112,13 @@ * record" would otherwise come back as "about nobody", or, with the condition * gone, "about everybody". * - * # A `{ $record }` comparand always refuses here too + * # A `{ $record }` comparand refuses here by name * * [#34199] The `lookupFilters` comparand `{ $record: 'path' }` reads the record - * a form is editing, which only that form's record picker knows, so it is the - * same case as `{record_id}` in object form: refused by name on every path, - * `INVALID_FILTER` / 400 naming the field, the `$record` path and where it - * sits — see {@link isRecordReference}. + * a form is editing, which only that form's record picker knows. Where it IS a + * field's comparand it is refused here, `INVALID_FILTER` / 400 naming the field, + * the `$record` path and where it sits; deeper inside a comparand it is data + * and is left alone — see {@link findRecordReferenceComparand}. */ import { @@ -529,9 +529,6 @@ function hasFilterToken(node: unknown): boolean { if (node && typeof node === 'object' && !(node instanceof Date)) { // [#25808] An unresolved `$now` anchor is a placeholder by construction. if (isUnresolvedNowAnchor(node)) return true; - // [#34199] So is a `{ $record }` reference — one the walk refuses, so the - // fast path must not hand it back by reference for want of a string token. - if (isRecordReference(node)) return true; return Object.values(node as Record).some(hasFilterToken); } return false; @@ -590,70 +587,106 @@ class MalformedNowAnchorError extends Error { * (`account.cb_market`). Only the record picker of the form editing that * record can resolve it — it sends the referenced value in its place before * the query leaves the browser — and no server path knows which record a form - * is editing. So, like `{record_id}`, it never resolves here: any plain object - * carrying an own `$record` key, at any depth and in any position, is refused - * by name ({@link UnresolvedRecordReferenceError}) before a driver sees it. - * - * Refused HERE because this is the one pass every engine read and write - * filter, and every analytics filter, goes through, whether or not it holds a - * string token. Before this, the reference reached the driver and was refused - * there in words that never named it (driver-memory: an unsupported operator - * `"$record"`; driver-sql: an operator withheld from the message). The refusal reads - * the KEY, not the shape: a malformed reference (`{ $record: 1 }`, a key - * beside `$record`) is no more resolvable than a well-formed one. - * - * Doors upstream of this pass may refuse first, in their own words: the - * engine's comparand-type door refuses any plain object under an operator - * (`{ f: { $eq: { $record: 'x' } } }`), and the temporal door a non-date - * comparand on a date column. Either way the filter never runs. + * is editing. The KEY decides, not the shape: a malformed reference + * (`{ $record: 1 }`, a key beside `$record`) is no more resolvable. */ function isRecordReference(node: unknown): node is Record { return !!node && typeof node === 'object' && !Array.isArray(node) && Object.prototype.hasOwnProperty.call(node, '$record'); } -/** One step of the walk: the node descended from and the key or index taken. */ -interface FilterWalkStep { - readonly parent: unknown; - readonly key: string | number; +/** A plain filter object (not a `Date`, not a branded `ReadableIds` leaf). */ +function isFilterObject(node: unknown): node is Record { + return !!node && typeof node === 'object' && !Array.isArray(node) + && !(node instanceof Date) && !isReadableIds(node); +} + +/** An operator object: a field's value carrying at least one `$` key. */ +function isOperatorObject(node: unknown): node is Record { + return isFilterObject(node) && Object.keys(node).some((k) => k.startsWith('$')); +} + +/** [#34199] A `{ $record }` met where it is a field's comparand. */ +interface RecordReferenceComparand { + readonly reference: Record; + readonly field: string; + readonly at: string; } /** - * [#34199] The field a `{ $record }` comparand is aimed at, read off the walk's - * steps: the non-`$` keys on the way down (`account` then `region` for the - * nested-relation form), a rule entry's own `field` when the reference is its - * `value` (`{ field, operator, value }`), and the head of a `[field, op, - * value]` tuple. `undefined` when no field names it (the filter's root). + * [#34199] The first `{ $record }` that IS a field's comparand, walking the + * filter's node grammar (`FilterCondition`): the field's own value (the eq + * shorthand `{ f: { $record } }`, which is what the picker's flat lowering of + * `eq` sends) or the value of an operator on that field (`{ f: { $gt: { + * $record } } }`), under any `$and` / `$or` / `$not` nesting. `at` is spelled + * from the filter's root: `filter.$or[1].cb_market`. + * + * Deliberately NOT judged — each left exactly as it was before this pass + * learned the reference: + * + * - **Inside a no-`$` object beneath a field** (`{ attachment: { meta: { + * $record: 'x' } } }`). That object is a deep-equality comparand or a + * nested-relation condition, and only the field's declaration tells the two + * apart, which this field-agnostic resolver never reads. As a deep-equality + * comparand the `$record` key is part of a literal a driver may compare + * whole (driver-memory does), so refusing it here would refuse a filter that + * answers today. + * - **A member of an operator's list** (`$in: ['NA', { $record }]`) and + * anything deeper inside an operator's value: the comparand-type door + * refuses a plain-object list member on the engine's path first. + * - **A `$` key in a node position that is not `$and` / `$or` / `$not`** + * (`{ $record: 'x' }` at the root): it is not a field's comparand, and the + * drivers already refuse an undeclared node key. + * - **An array where a node belongs** is walked as a list of nodes, so the + * legacy `[field, op, value]` tuple is never read as one: its third member is + * a node to this walk, and a `{ $record }` node names no field. + * + * Allocation-free and shallow (it never enters a comparand), so it costs a + * read whose filter holds no reference one walk of its node keys. */ -function fieldOfRecordReference(steps: readonly FilterWalkStep[]): string | undefined { - let parts: string[] = []; - for (const { parent, key } of steps) { - if (Array.isArray(parent)) { - if (key === 2 && parent.length === 3 && typeof parent[0] === 'string') parts = [parent[0]]; +function findRecordReferenceComparand(node: unknown, at = 'filter'): RecordReferenceComparand | undefined { + if (Array.isArray(node)) { + for (let i = 0; i < node.length; i++) { + const hit = findRecordReferenceComparand(node[i], `${at}[${i}]`); + if (hit) return hit; + } + return undefined; + } + if (!isFilterObject(node)) return undefined; + for (const [key, value] of Object.entries(node)) { + if (key === '$and' || key === '$or' || key === '$not') { + const hit = findRecordReferenceComparand(value, `${at}.${key}`); + if (hit) return hit; continue; } - const k = String(key); - if (k.startsWith('$')) continue; - const ruleField = (parent as Record).field; - if (k === 'value' && typeof ruleField === 'string') parts = [ruleField]; - else parts.push(k); + if (key.startsWith('$')) continue; + if (isRecordReference(value)) return { reference: value, field: key, at: `${at}.${key}` }; + // A no-`$` object: a deep-equality comparand or a nested-relation condition — not judged. + if (!isOperatorObject(value)) continue; + for (const [op, comparand] of Object.entries(value)) { + if (op.startsWith('$') && isRecordReference(comparand)) { + return { reference: comparand, field: key, at: `${at}.${key}.${op}` }; + } + } } - return parts.length > 0 ? parts.join('.') : undefined; -} - -/** [#34199] Where the walk stands, spelled from the filter's root: `filter.$or[0].cb_market`. */ -function filterLocation(steps: readonly FilterWalkStep[]): string { - return steps.reduce((at, { key }) => (typeof key === 'number' ? `${at}[${key}]` : `${at}.${key}`), 'filter'); + return undefined; } /** - * [#34199] An unresolved `{ $record }` comparand met at resolution — see - * {@link isRecordReference}. `INVALID_FILTER` / 400, the code every comparand - * door answers with and the one the drivers answered this input with before; - * the message names the field, the `$record` path and where it sits. - * ⛔ Not `FILTER_TOKEN_UNRESOLVED`: that code's declared meaning is a - * vocabulary placeholder string the request carries no context for, and the - * `{ $record }` reference is a comparand object, not a placeholder string. + * [#34199] An unresolved `{ $record }` met where it is a field's comparand — + * see {@link findRecordReferenceComparand}. `INVALID_FILTER` / 400, the code + * every comparand door answers with and the one the drivers answered this + * input with before; the message names the field, the `$record` path and + * where it sits. ⛔ Not `FILTER_TOKEN_UNRESOLVED`: that code's declared meaning + * is a vocabulary placeholder STRING the request carries no context for, and + * the reference is a comparand object. + * + * On the engine's object path the doors in front of this pass meet most + * operator forms first: the comparand-type door refuses any plain object + * under an operator (`{ f: { $gt: { $record } } }`), and the temporal door the + * eq shorthand on a temporal column — each in its own words. What reaches + * this pass there is the eq shorthand on any other column, and every shape + * from a caller with no such door in front. * * Not exported, like the module's other `INVALID_FILTER` refusals: a caller * reads `code` and `status`. @@ -662,17 +695,16 @@ class UnresolvedRecordReferenceError extends Error { readonly status = 400; readonly code = 'INVALID_FILTER' satisfies StandardErrorCode; - constructor(reference: Record, steps: readonly FilterWalkStep[]) { - const field = fieldOfRecordReference(steps); + constructor({ reference, field, at }: RecordReferenceComparand) { super( - `A { "$record": ${JSON.stringify(reference.$record)} } comparand ` + - `${field ? `on field "${field}" ` : ''}at ${filterLocation(steps)} reached the server unresolved, ` + - 'and is refused rather than compared. { $record } reads the record being edited (a field of it, ' + - 'or one lookup hop such as "account.cb_market"), and only the record picker of the form editing ' + - 'that record can resolve it: the picker sends the referenced value in its place. No server path ' + - 'knows which record a form is editing, so reading the reference as null, or comparing the object ' + - 'as a literal, would answer rows the filter was written to exclude. Send the referenced value ' + - 'itself, or write { $record } only in a lookup field\'s lookupFilters, where the picker resolves it.', + `A { "$record": ${JSON.stringify(reference.$record)} } comparand on field "${field}" at ${at} ` + + 'reached the server unresolved, and is refused rather than compared. { $record } reads the record ' + + 'being edited (a field of it, or one lookup hop such as "account.cb_market"), and only the record ' + + 'picker of the form editing that record can resolve it: the picker sends the referenced value in ' + + 'its place. No server path knows which record a form is editing, so reading the reference as null, ' + + 'or comparing the object as a literal, would answer rows the filter was written to exclude. Send ' + + 'the referenced value itself, or write { $record } only in a lookup field\'s lookupFilters, where ' + + 'the picker resolves it.', ); this.name = 'UnresolvedRecordReferenceError'; } @@ -713,22 +745,15 @@ export function resolveFilterTokens( ctx: FilterTokenResolutionContext = {}, ): T { if (filter == null) return filter; + // [#34199] Before the fast path: the refusal must not depend on a string + // token being in the same tree, and it reads only comparand positions. + const reference = findRecordReferenceComparand(filter); + if (reference) throw new UnresolvedRecordReferenceError(reference); if (!hasFilterToken(filter)) return filter; // One instant for the whole tree (see FilterTokenResolutionContext.now). const pinned: FilterTokenResolutionContext = { ...ctx, now: ctx.now ?? new Date() }; - // [#34199] Where the walk stands, read only to word a refusal. Pushed and - // popped around each descent; a throw abandons the whole walk, so it needs - // no unwinding. - const steps: FilterWalkStep[] = []; - const descend = (parent: unknown, key: string | number, child: unknown): unknown => { - steps.push({ parent, key }); - const out = walk(child); - steps.pop(); - return out; - }; - const walk = (node: unknown): unknown => { if (typeof node === 'string') { const cls = classifyFilterToken(node); @@ -741,18 +766,16 @@ export function resolveFilterTokens( if (resolved === undefined) throw new UnknownFilterTokenError(cls.token); return resolved; } - if (Array.isArray(node)) return node.map((v, i) => descend(node, i, v)); + if (Array.isArray(node)) return node.map(walk); // [ADR-0139 D1] The leaf by reference, brand intact (see above). if (isReadableIds(node)) return node; if (node && typeof node === 'object') { // Dates and other class instances are comparands, not filter structure. if (node instanceof Date) return node; - // [#34199] A `{ $record }` reference never resolves on a server. - if (isRecordReference(node)) throw new UnresolvedRecordReferenceError(node, steps); // [#25808] The now anchor: its instant pinned, its offset kept. if (isUnresolvedNowAnchor(node)) return resolveNowAnchor(node, pinned.now!); const out: Record = {}; - for (const [k, v] of Object.entries(node as Record)) out[k] = descend(node, k, v); + for (const [k, v] of Object.entries(node as Record)) out[k] = walk(v); return out; } return node; From a03f1233e17de3d0d09c589fa407562ba4a195b1 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 08:13:01 +0000 Subject: [PATCH 07/12] test(drivers): pin a deep { $record } comparand passing through; spec describes say what holds on every path Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jUZKdq3PK2Sab53cT3 --- .../34199-record-reference-refused-by-name.md | 7 ++++--- .../memory-record-reference-refusal.test.ts | 19 +++++++++++++++++-- ...ql-driver-record-reference-refusal.test.ts | 19 +++++++++++++++++++ packages/spec/src/data/field.test.ts | 10 +++++----- packages/spec/src/data/field.zod.ts | 8 +++++--- 5 files changed, 50 insertions(+), 13 deletions(-) diff --git a/.changeset/34199-record-reference-refused-by-name.md b/.changeset/34199-record-reference-refused-by-name.md index 5074b1ce2d1..901b5316f36 100644 --- a/.changeset/34199-record-reference-refused-by-name.md +++ b/.changeset/34199-record-reference-refused-by-name.md @@ -8,11 +8,12 @@ fix(core): an unresolved `{ $record }` lookup-filter comparand is refused by nam Clause-②: no Metadata-protocol: semantic -A `lookupFilters` entry may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }`; only the record picker of the form editing that record can replace it with a value. When one reaches a server unresolved, the engine's token pass (`resolveFilterTokens`) now refuses it with `INVALID_FILTER` / 400, and the message names the field, the `$record` path and its position, for example: +A `lookupFilters` entry may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }`; only the record picker of the form editing that record can replace it with a value. When one reaches a server unresolved as a field's comparand (the field's own value, or the value of an operator on that field), the engine's token pass (`resolveFilterTokens`) now refuses it with `INVALID_FILTER` / 400, and the message names the field, the `$record` path and its position, for example: `A { "$record": "account.cb_market" } comparand on field "cb_market" at filter.cb_market reached the server unresolved, and is refused rather than compared.` - Before: the eq shorthand `{ cb_market: { $record: "account.cb_market" } }` reached the driver, which refused it in its own words: driver-memory as an unsupported operator `"$record"`, driver-sql with the operator and field withheld. Both were already `INVALID_FILTER` / 400 (driver-mongodb refuses an unknown operator the same way), so on the built-in drivers no filter that answered rows now refuses. -- Now: a read or write filter the engine resolves, or an analytics filter, that carries one is refused in the one sentence above, whether or not it also holds a string placeholder. The operator form `{ cb_market: { $eq: { $record: "…" } } }` is still refused one door earlier on the engine's object path, by the comparand-type door, as before. +- Now: that shape is refused by name before any driver is asked, on every engine verb and in the analytics service, whether or not the filter also holds a string placeholder. On the engine's object path the other five operators (`{ valid_from: { $lte: { $record: "…" } } }`) and the eq shorthand on a date or datetime column are still refused one door earlier, in that door's own words, as before. +- Unchanged: a `{ $record }` deeper inside a comparand, such as `{ attachment: { meta: { $record: "x" } } }`, is a deep-equality literal (or a nested-relation condition) and passes through as before; driver-memory still compares it whole. -The `lookupFilters` describes now state the server half as enforced; the `[PLANNED — not enforced]` marker stays on the picker half, which does not resolve `{ $record }` or read `orEmpty` yet. +The `lookupFilters` describes now say what holds on every path: an unresolved `{ $record }` is refused with `INVALID_FILTER`, never read as null, and by name on the eq shorthand of a column that is not a date or datetime. The `[PLANNED — not enforced]` marker stays on the picker half, which does not resolve `{ $record }` or read `orEmpty` yet. diff --git a/packages/drivers/driver-memory/src/memory-record-reference-refusal.test.ts b/packages/drivers/driver-memory/src/memory-record-reference-refusal.test.ts index 81144f43281..6e7cdf2c13a 100644 --- a/packages/drivers/driver-memory/src/memory-record-reference-refusal.test.ts +++ b/packages/drivers/driver-memory/src/memory-record-reference-refusal.test.ts @@ -38,10 +38,11 @@ describe('[#34199] InMemoryDriver — an unresolved { $record } comparand', () = id: { type: 'text', name: 'id' }, cb_market: { type: 'text', name: 'cb_market' }, owner: { type: 'text', name: 'owner' }, + attachment: { type: 'file', name: 'attachment' }, }, }); - await driver.create('price_book', { id: '1', cb_market: 'export', owner: 'usr_1' }); - await driver.create('price_book', { id: '2', cb_market: null, owner: 'usr_2' }); + await driver.create('price_book', { id: '1', cb_market: 'export', owner: 'usr_1', attachment: { meta: { $record: 'x' } } }); + await driver.create('price_book', { id: '2', cb_market: null, owner: 'usr_2', attachment: { meta: { other: 1 } } }); }); const refusalOf = async (read: () => Promise): Promise => { @@ -78,6 +79,20 @@ describe('[#34199] InMemoryDriver — an unresolved { $record } comparand', () = expect(err.status).toBe(400); }); + it('control — a { $record } inside a deep-equality comparand reaches the driver unchanged and is answered as before', async () => { + // Not a field's comparand: the no-`$` object beneath `attachment` is a + // deep-equality literal, which this driver compares whole. The token pass + // hands it over by reference, so the driver answers exactly as it did + // before the pass learned the reference: the one row holding that value. + const where = { attachment: { meta: { $record: 'x' } } }; + const find = vi.spyOn(driver, 'find'); + const seam = seamed(where); + expect(seam).toBe(where); + const rows = (await driver.find('price_book', { fields: ['id'], where: seam })) as Array<{ id: string }>; + expect(find).toHaveBeenCalledTimes(1); + expect(rows.map((r) => String(r.id))).toEqual(['1']); + }); + it('control — an ordinary filter and a string token run through the same seam as before', async () => { const ids = async (where: unknown) => ((await driver.find('price_book', { fields: ['id'], where: seamed(where) })) as Array<{ id: string }>).map((r) => String(r.id)).sort(); diff --git a/packages/drivers/driver-sql/src/sql-driver-record-reference-refusal.test.ts b/packages/drivers/driver-sql/src/sql-driver-record-reference-refusal.test.ts index 4c7ee7f9704..b42b0a1638c 100644 --- a/packages/drivers/driver-sql/src/sql-driver-record-reference-refusal.test.ts +++ b/packages/drivers/driver-sql/src/sql-driver-record-reference-refusal.test.ts @@ -41,6 +41,7 @@ describe('[#34199] SqlDriver — an unresolved { $record } comparand', () => { id: { type: 'text', name: 'id' }, cb_market: { type: 'text', name: 'cb_market' }, owner: { type: 'text', name: 'owner' }, + attachment: { type: 'json', name: 'attachment' }, }, } as any, ]); @@ -81,6 +82,24 @@ describe('[#34199] SqlDriver — an unresolved { $record } comparand', () => { }); } + it('control — a { $record } inside a deep-equality comparand reaches the driver unchanged and is answered as before', async () => { + // Not a field's comparand: the no-`$` object beneath `attachment` is a + // deep-equality literal. The token pass hands it over by reference, so + // this driver gives the answer it gave before the pass learned the + // reference, whatever that answer is. + const where = { attachment: { meta: { $record: 'x' } } }; + expect(resolveFilterTokens(where, { userId: 'usr_1' })).toBe(where); + const answer = async (w: unknown) => { + try { + return { rows: await driver.find('price_book', { fields: ['id'], where: w as FilterCondition }) }; + } catch (e) { + const { code, status } = e as Refusal; + return { code, status }; + } + }; + expect(await answer(seamed(where))).toEqual(await answer(where)); + }); + it('control — an ordinary filter and a string token run through the same seam as before', async () => { const ids = async (where: unknown) => ((await driver.find('price_book', { fields: ['id'], where: seamed(where) })) as Array<{ id: string }>).map((r) => String(r.id)).sort(); diff --git a/packages/spec/src/data/field.test.ts b/packages/spec/src/data/field.test.ts index 7cd14c4ef70..7437396da75 100644 --- a/packages/spec/src/data/field.test.ts +++ b/packages/spec/src/data/field.test.ts @@ -2989,14 +2989,14 @@ describe('FieldSchema.lookupFilters — { $record } comparand and orEmpty', () = } }); - it('lets the eq shorthand the picker sends through the shared door unchanged (refused later, by the driver)', () => { + it('lets the eq shorthand the picker sends through the shared door unchanged (refused later, by the engine\'s token pass)', () => { // The card's market entry: the picker lowers `eq` to the shorthand // { field: value }, so an unresolved { $record } arrives as // { cb_market: { $record } }. The door reads that object as filter - // structure and passes it through as it is; a driver then meets `$record` - // as an operator it does not know and refuses the query (INVALID_FILTER). - // A refusal by name at the door is the server follow-up's: when it lands, - // this pin turns into a refusal and moves with it. + // structure and passes it through as it is; the engine's token pass + // (`resolveFilterTokens`, `@objectstack/core`) then refuses it by name, + // INVALID_FILTER / 400 naming the field and the path, before any driver + // is asked (pinned in `packages/core/src/utils/filter-tokens.test.ts`). const shorthand = { cb_market: { $record: 'account.cb_market' } }; expect(parseFilterAST(shorthand)).toEqual(shorthand); }); diff --git a/packages/spec/src/data/field.zod.ts b/packages/spec/src/data/field.zod.ts index bed40f8d039..87932d958d2 100644 --- a/packages/spec/src/data/field.zod.ts +++ b/packages/spec/src/data/field.zod.ts @@ -2251,8 +2251,8 @@ export const FieldSchema = lazySchema(() => { 'The comparand: a literal (an array for `in` / `notIn`), a date placeholder such as `{today}` or a ' + '{ $now: true, addDays } comparand for a date relative to today, or a { $record: "path" } reference to the ' + 'record being edited — a field of it, or one lookup hop ("account.cb_market"); a { $record } value pairs ' - + 'only with eq, ne, gt, lt, gte or lte. A { $record } that reaches a server unresolved is refused by name ' - + '(INVALID_FILTER). [PLANNED — not enforced] The picker does not resolve { $record } yet.', + + 'only with eq, ne, gt, lt, gte or lte. A { $record } that reaches a server unresolved is refused ' + + '(INVALID_FILTER), never read as null. [PLANNED — not enforced] The picker does not resolve { $record } yet.', ), orEmpty: z.boolean().optional().describe( '[PLANNED — not enforced] TRUE: the entry also matches a candidate whose column is null — "valid from the ' @@ -2267,7 +2267,9 @@ export const FieldSchema = lazySchema(() => { + '(`dependsOn: [\'quote_date\']` adds `quote_date = …` to the query over the referenced object). While the value is ' + 'empty, and on a picker with no single record being edited (a bulk-action bar, a filter panel), the entry is left ' + 'out. A { $record } is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A { $record } that reaches a ' - + 'server unresolved is refused by name (INVALID_FILTER, naming the field and the path), never read as null. The ' + + 'server unresolved is refused (INVALID_FILTER), never read as null: by name, naming the field and the path, when ' + + 'it arrives as the eq shorthand on a column that is not a date or datetime; any other operator, and eq on a date ' + + 'or datetime column, is refused earlier, in generic words. The ' + 'picker narrows the choice only: a rule the save must enforce belongs on the server too. [PLANNED — not ' + 'enforced] The picker does not resolve { $record } or read orEmpty yet.', ), From 0f98ad4241a306f325a93ed721a647920a2bb5e3 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 08:31:31 +0000 Subject: [PATCH 08/12] docs(spec): regenerate the field references for the lookupFilters describes Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jUZKdq3PK2Sab53cT3 --- content/docs/references/data/field.mdx | 4 ++-- content/docs/references/data/object.mdx | 4 ++-- content/docs/references/system/migration.mdx | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/content/docs/references/data/field.mdx b/content/docs/references/data/field.mdx index b91e2cf0292..af3a5280605 100644 --- a/content/docs/references/data/field.mdx +++ b/content/docs/references/data/field.mdx @@ -93,7 +93,7 @@ const result = CurrencyConfigSchema.parse(data); | **descriptionField** | `string` | optional | Secondary field shown under the label in the quick-select popover. | | **lookupColumns** | `(string \| { field: string; label?: string; width?: string; type?: string })[]` | optional | Explicit columns for the record-picker table; auto-derived from the referenced object when omitted. | | **lookupPageSize** | `integer` | optional | Rows per page in the record-picker dialog (default 10). | -| **lookupFilters** | `{ field: string; operator: Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>; value: any; orEmpty?: boolean }[]` | optional | Base filters restricting which records are selectable (e.g. only active). The structured, picker-honoured lookup filter. Each entry compares a column of the CANDIDATE record (`field`, on the referenced object) with `value`. A value may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }` (at most one lookup hop): the picker sends that value in its place and re-queries whenever a referenced field changes. Those fields are implied: do not list them in `dependsOn`, which also scopes the candidate query by equality (`dependsOn: ['quote_date']` adds `quote_date = …` to the query over the referenced object). While the value is empty, and on a picker with no single record being edited (a bulk-action bar, a filter panel), the entry is left out. A `{ $record }` is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A `{ $record }` that reaches a server unresolved is refused by name (INVALID_FILTER, naming the field and the path), never read as null. The picker narrows the choice only: a rule the save must enforce belongs on the server too. [PLANNED — not enforced] The picker does not resolve `{ $record }` or read orEmpty yet. | +| **lookupFilters** | `{ field: string; operator: Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>; value: any; orEmpty?: boolean }[]` | optional | Base filters restricting which records are selectable (e.g. only active). The structured, picker-honoured lookup filter. Each entry compares a column of the CANDIDATE record (`field`, on the referenced object) with `value`. A value may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }` (at most one lookup hop): the picker sends that value in its place and re-queries whenever a referenced field changes. Those fields are implied: do not list them in `dependsOn`, which also scopes the candidate query by equality (`dependsOn: ['quote_date']` adds `quote_date = …` to the query over the referenced object). While the value is empty, and on a picker with no single record being edited (a bulk-action bar, a filter panel), the entry is left out. A `{ $record }` is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A `{ $record }` that reaches a server unresolved is refused (INVALID_FILTER), never read as null: by name, naming the field and the path, when it arrives as the eq shorthand on a column that is not a date or datetime; any other operator, and eq on a date or datetime column, is refused earlier, in generic words. The picker narrows the choice only: a rule the save must enforce belongs on the server too. [PLANNED — not enforced] The picker does not resolve `{ $record }` or read orEmpty yet. | | **dependsOn** | `(string \| { field: string; param?: string })[]` | optional | Declares that this field's available values depend on the value of other field(s) on the same record — the form gates the field until they are set and re-evaluates as they change. For `lookup`/`master_detail` it scopes the candidate query (string = same local/remote key; `{field,param}` when the remote filter key differs — the `{field,param}` form is lookup-only). For `select`/`multiselect`/`radio` the actual per-option rule lives in each option's `visibleWhen`; list the referenced fields here (string form) so the option list gates and refreshes with the parent. | | **allowCreate** | `boolean` | optional | Allow inline quick-create from the record picker: when no match exists the user can create a record from the typed text (optimistic dataSource.create with the display field). Best for simple objects whose only required field is the display field. | | **lookupAutofill** | `{ target: string; source: string; overwrite?: boolean }[]` | optional | Fields a pick in this lookup fills on the record being edited: each `{ target, source }` pair copies the picked record's `source` field (a field of the `reference` object) into this object's `target` field — e.g. `[{ target: 'unit_price', source: 'list_price' }]` on a quote line's product lookup. Read wherever this field is picked: the record form, and a line-item grid column over it. OVERWRITE RULE — the default, `overwrite` absent or false: a pick never replaces a value somebody wrote. The target is filled only while it is empty or still holds the value an earlier pick filled in; a value the user typed, or one the record already stored, stays. Only a pair that declares `overwrite: true` replaces the target on every pick, whatever it holds. Client-side only: it fills the form, and nothing on the write path reads it — the filled value is saved as an ordinary write, and an import or API write that sets the lookup fills nothing. Only on a single-value `lookup` / `master_detail`. Each target is a field of this object other than this one, written by its author — not `readonly`, not computed (`formula`, `summary`, `autonumber`, or an `expression`) — and named once. Each source is a field of the referenced object that the record carries (not `internal`) and whose value the target can hold; `os validate` / `os build` judge the source. In a line-item grid the column key `autofill` still governs only the same-named copy and is unchanged; a declared pair takes its target out of that copy. | @@ -242,7 +242,7 @@ const result = CurrencyConfigSchema.parse(data); | :--- | :--- | :--- | :--- | | **field** | `string` | ✅ | | | **operator** | `Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>` | ✅ | | -| **value** | `any` | ✅ | The comparand: a literal (an array for `in` / `notIn`), a date placeholder such as `{today}` or a `{ $now: true, addDays }` comparand for a date relative to today, or a `{ $record: "path" }` reference to the record being edited — a field of it, or one lookup hop ("account.cb_market"); a `{ $record }` value pairs only with eq, ne, gt, lt, gte or lte. A `{ $record }` that reaches a server unresolved is refused by name (INVALID_FILTER). [PLANNED — not enforced] The picker does not resolve `{ $record }` yet. | +| **value** | `any` | ✅ | The comparand: a literal (an array for `in` / `notIn`), a date placeholder such as `{today}` or a `{ $now: true, addDays }` comparand for a date relative to today, or a `{ $record: "path" }` reference to the record being edited — a field of it, or one lookup hop ("account.cb_market"); a `{ $record }` value pairs only with eq, ne, gt, lt, gte or lte. A `{ $record }` that reaches a server unresolved is refused (INVALID_FILTER), never read as null. [PLANNED — not enforced] The picker does not resolve `{ $record }` yet. | | **orEmpty** | `boolean` | optional | [PLANNED — not enforced] TRUE: the entry also matches a candidate whose column is null — "valid from the quote date, or with no start date". Only with eq, ne, gt, lt, gte or lte. The picker does not read it yet. | ### Nested Shape: `Field.lookupAutofill[number]` diff --git a/content/docs/references/data/object.mdx b/content/docs/references/data/object.mdx index bd5c6e5993c..662e9819221 100644 --- a/content/docs/references/data/object.mdx +++ b/content/docs/references/data/object.mdx @@ -270,7 +270,7 @@ const result = ApiMethod.parse(data); | **descriptionField** | `string` | optional | Secondary field shown under the label in the quick-select popover. | | **lookupColumns** | `(string \| { field: string; label?: string; width?: string; type?: string })[]` | optional | Explicit columns for the record-picker table; auto-derived from the referenced object when omitted. | | **lookupPageSize** | `integer` | optional | Rows per page in the record-picker dialog (default 10). | -| **lookupFilters** | `{ field: string; operator: Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>; value: any; orEmpty?: boolean }[]` | optional | Base filters restricting which records are selectable (e.g. only active). The structured, picker-honoured lookup filter. Each entry compares a column of the CANDIDATE record (`field`, on the referenced object) with `value`. A value may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }` (at most one lookup hop): the picker sends that value in its place and re-queries whenever a referenced field changes. Those fields are implied: do not list them in `dependsOn`, which also scopes the candidate query by equality (`dependsOn: ['quote_date']` adds `quote_date = …` to the query over the referenced object). While the value is empty, and on a picker with no single record being edited (a bulk-action bar, a filter panel), the entry is left out. A `{ $record }` is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A `{ $record }` that reaches a server unresolved is refused by name (INVALID_FILTER, naming the field and the path), never read as null. The picker narrows the choice only: a rule the save must enforce belongs on the server too. [PLANNED — not enforced] The picker does not resolve `{ $record }` or read orEmpty yet. | +| **lookupFilters** | `{ field: string; operator: Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>; value: any; orEmpty?: boolean }[]` | optional | Base filters restricting which records are selectable (e.g. only active). The structured, picker-honoured lookup filter. Each entry compares a column of the CANDIDATE record (`field`, on the referenced object) with `value`. A value may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }` (at most one lookup hop): the picker sends that value in its place and re-queries whenever a referenced field changes. Those fields are implied: do not list them in `dependsOn`, which also scopes the candidate query by equality (`dependsOn: ['quote_date']` adds `quote_date = …` to the query over the referenced object). While the value is empty, and on a picker with no single record being edited (a bulk-action bar, a filter panel), the entry is left out. A `{ $record }` is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A `{ $record }` that reaches a server unresolved is refused (INVALID_FILTER), never read as null: by name, naming the field and the path, when it arrives as the eq shorthand on a column that is not a date or datetime; any other operator, and eq on a date or datetime column, is refused earlier, in generic words. The picker narrows the choice only: a rule the save must enforce belongs on the server too. [PLANNED — not enforced] The picker does not resolve `{ $record }` or read orEmpty yet. | | **dependsOn** | `(string \| { field: string; param?: string })[]` | optional | Declares that this field's available values depend on the value of other field(s) on the same record — the form gates the field until they are set and re-evaluates as they change. For `lookup`/`master_detail` it scopes the candidate query (string = same local/remote key; `{field,param}` when the remote filter key differs — the `{field,param}` form is lookup-only). For `select`/`multiselect`/`radio` the actual per-option rule lives in each option's `visibleWhen`; list the referenced fields here (string form) so the option list gates and refreshes with the parent. | | **allowCreate** | `boolean` | optional | Allow inline quick-create from the record picker: when no match exists the user can create a record from the typed text (optimistic dataSource.create with the display field). Best for simple objects whose only required field is the display field. | | **lookupAutofill** | `{ target: string; source: string; overwrite?: boolean }[]` | optional | Fields a pick in this lookup fills on the record being edited: each `{ target, source }` pair copies the picked record's `source` field (a field of the `reference` object) into this object's `target` field — e.g. `[{ target: 'unit_price', source: 'list_price' }]` on a quote line's product lookup. Read wherever this field is picked: the record form, and a line-item grid column over it. OVERWRITE RULE — the default, `overwrite` absent or false: a pick never replaces a value somebody wrote. The target is filled only while it is empty or still holds the value an earlier pick filled in; a value the user typed, or one the record already stored, stays. Only a pair that declares `overwrite: true` replaces the target on every pick, whatever it holds. Client-side only: it fills the form, and nothing on the write path reads it — the filled value is saved as an ordinary write, and an import or API write that sets the lookup fills nothing. Only on a single-value `lookup` / `master_detail`. Each target is a field of this object other than this one, written by its author — not `readonly`, not computed (`formula`, `summary`, `autonumber`, or an `expression`) — and named once. Each source is a field of the referenced object that the record carries (not `internal`) and whose value the target can hold; `os validate` / `os build` judge the source. In a line-item grid the column key `autofill` still governs only the same-named copy and is unchanged; a declared pair takes its target out of that copy. | @@ -647,7 +647,7 @@ const result = ApiMethod.parse(data); | **descriptionField** | `string` | optional | Secondary field shown under the label in the quick-select popover. | | **lookupColumns** | `(string \| { field: string; label?: string; width?: string; type?: string })[]` | optional | Explicit columns for the record-picker table; auto-derived from the referenced object when omitted. | | **lookupPageSize** | `integer` | optional | Rows per page in the record-picker dialog (default 10). | -| **lookupFilters** | `{ field: string; operator: Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>; value: any; orEmpty?: boolean }[]` | optional | Base filters restricting which records are selectable (e.g. only active). The structured, picker-honoured lookup filter. Each entry compares a column of the CANDIDATE record (`field`, on the referenced object) with `value`. A value may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }` (at most one lookup hop): the picker sends that value in its place and re-queries whenever a referenced field changes. Those fields are implied: do not list them in `dependsOn`, which also scopes the candidate query by equality (`dependsOn: ['quote_date']` adds `quote_date = …` to the query over the referenced object). While the value is empty, and on a picker with no single record being edited (a bulk-action bar, a filter panel), the entry is left out. A `{ $record }` is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A `{ $record }` that reaches a server unresolved is refused by name (INVALID_FILTER, naming the field and the path), never read as null. The picker narrows the choice only: a rule the save must enforce belongs on the server too. [PLANNED — not enforced] The picker does not resolve `{ $record }` or read orEmpty yet. | +| **lookupFilters** | `{ field: string; operator: Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>; value: any; orEmpty?: boolean }[]` | optional | Base filters restricting which records are selectable (e.g. only active). The structured, picker-honoured lookup filter. Each entry compares a column of the CANDIDATE record (`field`, on the referenced object) with `value`. A value may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }` (at most one lookup hop): the picker sends that value in its place and re-queries whenever a referenced field changes. Those fields are implied: do not list them in `dependsOn`, which also scopes the candidate query by equality (`dependsOn: ['quote_date']` adds `quote_date = …` to the query over the referenced object). While the value is empty, and on a picker with no single record being edited (a bulk-action bar, a filter panel), the entry is left out. A `{ $record }` is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A `{ $record }` that reaches a server unresolved is refused (INVALID_FILTER), never read as null: by name, naming the field and the path, when it arrives as the eq shorthand on a column that is not a date or datetime; any other operator, and eq on a date or datetime column, is refused earlier, in generic words. The picker narrows the choice only: a rule the save must enforce belongs on the server too. [PLANNED — not enforced] The picker does not resolve `{ $record }` or read orEmpty yet. | | **dependsOn** | `(string \| { field: string; param?: string })[]` | optional | Declares that this field's available values depend on the value of other field(s) on the same record — the form gates the field until they are set and re-evaluates as they change. For `lookup`/`master_detail` it scopes the candidate query (string = same local/remote key; `{field,param}` when the remote filter key differs — the `{field,param}` form is lookup-only). For `select`/`multiselect`/`radio` the actual per-option rule lives in each option's `visibleWhen`; list the referenced fields here (string form) so the option list gates and refreshes with the parent. | | **allowCreate** | `boolean` | optional | Allow inline quick-create from the record picker: when no match exists the user can create a record from the typed text (optimistic dataSource.create with the display field). Best for simple objects whose only required field is the display field. | | **lookupAutofill** | `{ target: string; source: string; overwrite?: boolean }[]` | optional | Fields a pick in this lookup fills on the record being edited: each `{ target, source }` pair copies the picked record's `source` field (a field of the `reference` object) into this object's `target` field — e.g. `[{ target: 'unit_price', source: 'list_price' }]` on a quote line's product lookup. Read wherever this field is picked: the record form, and a line-item grid column over it. OVERWRITE RULE — the default, `overwrite` absent or false: a pick never replaces a value somebody wrote. The target is filled only while it is empty or still holds the value an earlier pick filled in; a value the user typed, or one the record already stored, stays. Only a pair that declares `overwrite: true` replaces the target on every pick, whatever it holds. Client-side only: it fills the form, and nothing on the write path reads it — the filled value is saved as an ordinary write, and an import or API write that sets the lookup fills nothing. Only on a single-value `lookup` / `master_detail`. Each target is a field of this object other than this one, written by its author — not `readonly`, not computed (`formula`, `summary`, `autonumber`, or an `expression`) — and named once. Each source is a field of the referenced object that the record carries (not `internal`) and whose value the target can hold; `os validate` / `os build` judge the source. In a line-item grid the column key `autofill` still governs only the same-named copy and is unchanged; a declared pair takes its target out of that copy. | diff --git a/content/docs/references/system/migration.mdx b/content/docs/references/system/migration.mdx index cfe1bf1c29e..283a1508e0a 100644 --- a/content/docs/references/system/migration.mdx +++ b/content/docs/references/system/migration.mdx @@ -96,7 +96,7 @@ Add a new field to an existing object | **descriptionField** | `string` | optional | Secondary field shown under the label in the quick-select popover. | | **lookupColumns** | `(string \| { field: string; label?: string; width?: string; type?: string })[]` | optional | Explicit columns for the record-picker table; auto-derived from the referenced object when omitted. | | **lookupPageSize** | `integer` | optional | Rows per page in the record-picker dialog (default 10). | -| **lookupFilters** | `{ field: string; operator: Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>; value: any; orEmpty?: boolean }[]` | optional | Base filters restricting which records are selectable (e.g. only active). The structured, picker-honoured lookup filter. Each entry compares a column of the CANDIDATE record (`field`, on the referenced object) with `value`. A value may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }` (at most one lookup hop): the picker sends that value in its place and re-queries whenever a referenced field changes. Those fields are implied: do not list them in `dependsOn`, which also scopes the candidate query by equality (`dependsOn: ['quote_date']` adds `quote_date = …` to the query over the referenced object). While the value is empty, and on a picker with no single record being edited (a bulk-action bar, a filter panel), the entry is left out. A `{ $record }` is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A `{ $record }` that reaches a server unresolved is refused by name (INVALID_FILTER, naming the field and the path), never read as null. The picker narrows the choice only: a rule the save must enforce belongs on the server too. [PLANNED — not enforced] The picker does not resolve `{ $record }` or read orEmpty yet. | +| **lookupFilters** | `{ field: string; operator: Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>; value: any; orEmpty?: boolean }[]` | optional | Base filters restricting which records are selectable (e.g. only active). The structured, picker-honoured lookup filter. Each entry compares a column of the CANDIDATE record (`field`, on the referenced object) with `value`. A value may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }` (at most one lookup hop): the picker sends that value in its place and re-queries whenever a referenced field changes. Those fields are implied: do not list them in `dependsOn`, which also scopes the candidate query by equality (`dependsOn: ['quote_date']` adds `quote_date = …` to the query over the referenced object). While the value is empty, and on a picker with no single record being edited (a bulk-action bar, a filter panel), the entry is left out. A `{ $record }` is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A `{ $record }` that reaches a server unresolved is refused (INVALID_FILTER), never read as null: by name, naming the field and the path, when it arrives as the eq shorthand on a column that is not a date or datetime; any other operator, and eq on a date or datetime column, is refused earlier, in generic words. The picker narrows the choice only: a rule the save must enforce belongs on the server too. [PLANNED — not enforced] The picker does not resolve `{ $record }` or read orEmpty yet. | | **dependsOn** | `(string \| { field: string; param?: string })[]` | optional | Declares that this field's available values depend on the value of other field(s) on the same record — the form gates the field until they are set and re-evaluates as they change. For `lookup`/`master_detail` it scopes the candidate query (string = same local/remote key; `{field,param}` when the remote filter key differs — the `{field,param}` form is lookup-only). For `select`/`multiselect`/`radio` the actual per-option rule lives in each option's `visibleWhen`; list the referenced fields here (string form) so the option list gates and refreshes with the parent. | | **allowCreate** | `boolean` | optional | Allow inline quick-create from the record picker: when no match exists the user can create a record from the typed text (optimistic dataSource.create with the display field). Best for simple objects whose only required field is the display field. | | **lookupAutofill** | `{ target: string; source: string; overwrite?: boolean }[]` | optional | Fields a pick in this lookup fills on the record being edited: each `{ target, source }` pair copies the picked record's `source` field (a field of the `reference` object) into this object's `target` field — e.g. `[{ target: 'unit_price', source: 'list_price' }]` on a quote line's product lookup. Read wherever this field is picked: the record form, and a line-item grid column over it. OVERWRITE RULE — the default, `overwrite` absent or false: a pick never replaces a value somebody wrote. The target is filled only while it is empty or still holds the value an earlier pick filled in; a value the user typed, or one the record already stored, stays. Only a pair that declares `overwrite: true` replaces the target on every pick, whatever it holds. Client-side only: it fills the form, and nothing on the write path reads it — the filled value is saved as an ordinary write, and an import or API write that sets the lookup fills nothing. Only on a single-value `lookup` / `master_detail`. Each target is a field of this object other than this one, written by its author — not `readonly`, not computed (`formula`, `summary`, `autonumber`, or an `expression`) — and named once. Each source is a field of the referenced object that the record carries (not `internal`) and whose value the target can hold; `os validate` / `os build` judge the source. In a line-item grid the column key `autofill` still governs only the same-named copy and is unchanged; a declared pair takes its target out of that copy. | @@ -532,7 +532,7 @@ Add a new field to an existing object | **descriptionField** | `string` | optional | Secondary field shown under the label in the quick-select popover. | | **lookupColumns** | `(string \| { field: string; label?: string; width?: string; type?: string })[]` | optional | Explicit columns for the record-picker table; auto-derived from the referenced object when omitted. | | **lookupPageSize** | `integer` | optional | Rows per page in the record-picker dialog (default 10). | -| **lookupFilters** | `{ field: string; operator: Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>; value: any; orEmpty?: boolean }[]` | optional | Base filters restricting which records are selectable (e.g. only active). The structured, picker-honoured lookup filter. Each entry compares a column of the CANDIDATE record (`field`, on the referenced object) with `value`. A value may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }` (at most one lookup hop): the picker sends that value in its place and re-queries whenever a referenced field changes. Those fields are implied: do not list them in `dependsOn`, which also scopes the candidate query by equality (`dependsOn: ['quote_date']` adds `quote_date = …` to the query over the referenced object). While the value is empty, and on a picker with no single record being edited (a bulk-action bar, a filter panel), the entry is left out. A `{ $record }` is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A `{ $record }` that reaches a server unresolved is refused by name (INVALID_FILTER, naming the field and the path), never read as null. The picker narrows the choice only: a rule the save must enforce belongs on the server too. [PLANNED — not enforced] The picker does not resolve `{ $record }` or read orEmpty yet. | +| **lookupFilters** | `{ field: string; operator: Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>; value: any; orEmpty?: boolean }[]` | optional | Base filters restricting which records are selectable (e.g. only active). The structured, picker-honoured lookup filter. Each entry compares a column of the CANDIDATE record (`field`, on the referenced object) with `value`. A value may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }` (at most one lookup hop): the picker sends that value in its place and re-queries whenever a referenced field changes. Those fields are implied: do not list them in `dependsOn`, which also scopes the candidate query by equality (`dependsOn: ['quote_date']` adds `quote_date = …` to the query over the referenced object). While the value is empty, and on a picker with no single record being edited (a bulk-action bar, a filter panel), the entry is left out. A `{ $record }` is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A `{ $record }` that reaches a server unresolved is refused (INVALID_FILTER), never read as null: by name, naming the field and the path, when it arrives as the eq shorthand on a column that is not a date or datetime; any other operator, and eq on a date or datetime column, is refused earlier, in generic words. The picker narrows the choice only: a rule the save must enforce belongs on the server too. [PLANNED — not enforced] The picker does not resolve `{ $record }` or read orEmpty yet. | | **dependsOn** | `(string \| { field: string; param?: string })[]` | optional | Declares that this field's available values depend on the value of other field(s) on the same record — the form gates the field until they are set and re-evaluates as they change. For `lookup`/`master_detail` it scopes the candidate query (string = same local/remote key; `{field,param}` when the remote filter key differs — the `{field,param}` form is lookup-only). For `select`/`multiselect`/`radio` the actual per-option rule lives in each option's `visibleWhen`; list the referenced fields here (string form) so the option list gates and refreshes with the parent. | | **allowCreate** | `boolean` | optional | Allow inline quick-create from the record picker: when no match exists the user can create a record from the typed text (optimistic dataSource.create with the display field). Best for simple objects whose only required field is the display field. | | **lookupAutofill** | `{ target: string; source: string; overwrite?: boolean }[]` | optional | Fields a pick in this lookup fills on the record being edited: each `{ target, source }` pair copies the picked record's `source` field (a field of the `reference` object) into this object's `target` field — e.g. `[{ target: 'unit_price', source: 'list_price' }]` on a quote line's product lookup. Read wherever this field is picked: the record form, and a line-item grid column over it. OVERWRITE RULE — the default, `overwrite` absent or false: a pick never replaces a value somebody wrote. The target is filled only while it is empty or still holds the value an earlier pick filled in; a value the user typed, or one the record already stored, stays. Only a pair that declares `overwrite: true` replaces the target on every pick, whatever it holds. Client-side only: it fills the form, and nothing on the write path reads it — the filled value is saved as an ordinary write, and an import or API write that sets the lookup fills nothing. Only on a single-value `lookup` / `master_detail`. Each target is a field of this object other than this one, written by its author — not `readonly`, not computed (`formula`, `summary`, `autonumber`, or an `expression`) — and named once. Each source is a field of the referenced object that the record carries (not `internal`) and whose value the target can hold; `os validate` / `os build` judge the source. In a line-item grid the column key `autofill` still governs only the same-named copy and is unchanged; a declared pair takes its target out of that copy. | From 15c27dc8a6a257d7ed929f0b9c59afb19beee69e Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 12:33:19 +0000 Subject: [PATCH 09/12] fix(core): leave a [field, op, value] tuple's comparand to the doors that judged it The token pass walked the value position of a legacy tuple as a filter node, so ['attachment', '=', { meta: { $record: 'x' } }] was refused where the same deep-equality literal in the object spelling comes back by reference. An array whose first member is a string other than and / or is a comparison: its third member is a comparand, not a node. CONTROL pins for the tuple spelling; the refusal's $record echo is bounded to 60 characters; the describe and the changeset name the time column the temporal door also covers. Claude-Session: https://claude.ai/code/session_01FEkQ5kgF3mo9f7LXuv5hac Co-Authored-By: Claude --- .../34199-record-reference-refused-by-name.md | 8 ++--- packages/core/src/utils/filter-tokens.test.ts | 21 +++++++++++ packages/core/src/utils/filter-tokens.ts | 36 ++++++++++++++++--- packages/spec/src/data/field.zod.ts | 4 +-- 4 files changed, 58 insertions(+), 11 deletions(-) diff --git a/.changeset/34199-record-reference-refused-by-name.md b/.changeset/34199-record-reference-refused-by-name.md index 901b5316f36..a43a16b8d68 100644 --- a/.changeset/34199-record-reference-refused-by-name.md +++ b/.changeset/34199-record-reference-refused-by-name.md @@ -12,8 +12,8 @@ A `lookupFilters` entry may read the record being edited as `{ $record: "field" `A { "$record": "account.cb_market" } comparand on field "cb_market" at filter.cb_market reached the server unresolved, and is refused rather than compared.` -- Before: the eq shorthand `{ cb_market: { $record: "account.cb_market" } }` reached the driver, which refused it in its own words: driver-memory as an unsupported operator `"$record"`, driver-sql with the operator and field withheld. Both were already `INVALID_FILTER` / 400 (driver-mongodb refuses an unknown operator the same way), so on the built-in drivers no filter that answered rows now refuses. -- Now: that shape is refused by name before any driver is asked, on every engine verb and in the analytics service, whether or not the filter also holds a string placeholder. On the engine's object path the other five operators (`{ valid_from: { $lte: { $record: "…" } } }`) and the eq shorthand on a date or datetime column are still refused one door earlier, in that door's own words, as before. -- Unchanged: a `{ $record }` deeper inside a comparand, such as `{ attachment: { meta: { $record: "x" } } }`, is a deep-equality literal (or a nested-relation condition) and passes through as before; driver-memory still compares it whole. +- Before: the eq shorthand `{ cb_market: { $record: "account.cb_market" } }` reached the driver, which refused it in its own words: driver-memory as an unsupported operator `"$record"`, driver-sql with the operator and field withheld. Both were already `INVALID_FILTER` / 400 (driver-mongodb refuses an unknown operator the same way), so on the built-in drivers no filter that answered rows now refuses: the pass judges only a field's comparand, never a value inside one (see Unchanged). +- Now: that shape is refused by name before any driver is asked, on every engine verb and in the analytics service, whether or not the filter also holds a string placeholder. On the engine's object path the other five operators (`{ valid_from: { $lte: { $record: "…" } } }`) and the eq shorthand on a date, datetime or time column are still refused one door earlier, in that door's own words, as before. The engine lowers a `[field, op, value]` array `where` before the pass, so there the array spelling is judged as its object form; the analytics service hands the pass its `where` unlowered, and the pass leaves a tuple to the doors that judged it before. +- Unchanged: a `{ $record }` deeper inside a comparand is a deep-equality literal (or a nested-relation condition) and passes through as before, in either spelling: the object form `{ attachment: { meta: { $record: "x" } } }`, which driver-memory still compares whole, and the tuple `['attachment', '=', { meta: { $record: "x" } }]`, whose third member is a comparand, never a filter node. Both come back from the pass by reference (pinned as CONTROLs on `resolveFilterTokens`). -The `lookupFilters` describes now say what holds on every path: an unresolved `{ $record }` is refused with `INVALID_FILTER`, never read as null, and by name on the eq shorthand of a column that is not a date or datetime. The `[PLANNED — not enforced]` marker stays on the picker half, which does not resolve `{ $record }` or read `orEmpty` yet. +The `lookupFilters` describes now say what holds on every path: an unresolved `{ $record }` is refused with `INVALID_FILTER`, never read as null, and by name on the eq shorthand of a column other than a date, datetime or time column. The `[PLANNED — not enforced]` marker stays on the picker half, which does not resolve `{ $record }` or read `orEmpty` yet. diff --git a/packages/core/src/utils/filter-tokens.test.ts b/packages/core/src/utils/filter-tokens.test.ts index 17a8000d406..2914bd68120 100644 --- a/packages/core/src/utils/filter-tokens.test.ts +++ b/packages/core/src/utils/filter-tokens.test.ts @@ -292,6 +292,21 @@ describe('[#34199] resolveFilterTokens — an unresolved { $record } comparand r expect(err.message).toContain(`on field "${field}" at ${at} reached the server unresolved`); }); + it('walks an or-array from its second member: an object node there is still judged', () => { + const err = refusal(['or', ['stage', '=', 'won'], { cb_market: { $record: 'account.cb_market' } }]); + expect(err.code).toBe('INVALID_FILTER'); + expect(err.status).toBe(400); + expect(err.message).toContain('on field "cb_market" at filter[2].cb_market reached'); + }); + + it('bounds the echoed $record value, which came off the wire', () => { + const err = refusal({ cb_market: { $record: 'x'.repeat(500) } }); + expect(err.code).toBe('INVALID_FILTER'); + expect(err.status).toBe(400); + expect(err.message).not.toContain('x'.repeat(60)); + expect(err.message).toContain('on field "cb_market" at filter.cb_market reached'); + }); + it('refuses a malformed reference by its key too', () => { const malformed = refusal({ cb_market: { $record: 'account.cb_market', addDays: 1 } }); expect(malformed.code).toBe('INVALID_FILTER'); @@ -309,6 +324,12 @@ describe('[#34199] resolveFilterTokens — an unresolved { $record } comparand r ['as an $in list member', { region: { $in: ['NA', 'EU', { $record: 'account.region' }] } }], ['at the root, where no field names it', { $record: 'account.cb_market' }], ['as the third member of a [field, op, value] tuple', ['cb_market', '=', { $record: 'account.cb_market' }]], + // The tuple's value is a comparand: the array spelling of the deep-equality + // CONTROL above is the same literal, and the analytics service hands the + // unlowered array to this pass. + ['inside a deep-equality comparand in the array spelling', ['attachment', '=', { meta: { $record: 'x' } }]], + ['inside a tuple under an and-array', ['and', ['stage', '=', 'won'], ['attachment', '=', { meta: { $record: 'x' } }]]], + ['inside a tuple of a legacy list of tuples', [['stage', '=', 'won'], ['attachment', 'in', [{ meta: { $record: 'x' } }]]]], ])('control — %s: not a field\'s comparand, so it comes back by reference', (_label, filter) => { expect(resolveFilterTokens(filter, full)).toBe(filter); }); diff --git a/packages/core/src/utils/filter-tokens.ts b/packages/core/src/utils/filter-tokens.ts index f2645adc6bd..244045f6cd2 100644 --- a/packages/core/src/utils/filter-tokens.ts +++ b/packages/core/src/utils/filter-tokens.ts @@ -637,16 +637,27 @@ interface RecordReferenceComparand { * - **A `$` key in a node position that is not `$and` / `$or` / `$not`** * (`{ $record: 'x' }` at the root): it is not a field's comparand, and the * drivers already refuse an undeclared node key. - * - **An array where a node belongs** is walked as a list of nodes, so the - * legacy `[field, op, value]` tuple is never read as one: its third member is - * a node to this walk, and a `{ $record }` node names no field. + * - **A legacy `[field, op, value]` tuple** (an array whose first member is a + * string other than `and` / `or`, the split `parseFilterAST` lowers by): + * it is a comparison, not a list of nodes, and its third member is a + * comparand — `['attachment', '=', { meta: { $record: 'x' } }]` is the same + * deep-equality literal as the object spelling above, and comes back by + * reference like it. An `['and' | 'or', …]` array is walked from its second + * member, and any other array as a list of nodes. * * Allocation-free and shallow (it never enters a comparand), so it costs a * read whose filter holds no reference one walk of its node keys. */ function findRecordReferenceComparand(node: unknown, at = 'filter'): RecordReferenceComparand | undefined { if (Array.isArray(node)) { - for (let i = 0; i < node.length; i++) { + let start = 0; + if (typeof node[0] === 'string') { + const head = node[0].toLowerCase(); + // A `[field, op, value]` tuple: a comparison whose value is a comparand — not judged. + if (head !== 'and' && head !== 'or') return undefined; + start = 1; + } + for (let i = start; i < node.length; i++) { const hit = findRecordReferenceComparand(node[i], `${at}[${i}]`); if (hit) return hit; } @@ -697,7 +708,7 @@ class UnresolvedRecordReferenceError extends Error { constructor({ reference, field, at }: RecordReferenceComparand) { super( - `A { "$record": ${JSON.stringify(reference.$record)} } comparand on field "${field}" at ${at} ` + + `A { "$record": ${previewReferencePath(reference.$record)} } comparand on field "${field}" at ${at} ` + 'reached the server unresolved, and is refused rather than compared. { $record } reads the record ' + 'being edited (a field of it, or one lookup hop such as "account.cb_market"), and only the record ' + 'picker of the form editing that record can resolve it: the picker sends the referenced value in ' + @@ -710,6 +721,21 @@ class UnresolvedRecordReferenceError extends Error { } } +/** + * [#34199] The `$record` value as the refusal echoes it: JSON, bounded to 60 + * characters like the sibling comparand doors' previews — a malformed + * reference came off the wire and can carry any JSON value. + */ +function previewReferencePath(path: unknown): string { + let text: string; + try { + text = JSON.stringify(path) ?? String(path); + } catch { + text = String(path); + } + return text.length > 60 ? `${text.slice(0, 59)}…` : text; +} + /** [#25808] The anchor with its instant pinned — see {@link isUnresolvedNowAnchor}. */ function resolveNowAnchor(node: { $now: true; addDays?: unknown }, now: Date): Record { const offset = node.addDays; diff --git a/packages/spec/src/data/field.zod.ts b/packages/spec/src/data/field.zod.ts index ab88c7fe5a9..51fb295de1d 100644 --- a/packages/spec/src/data/field.zod.ts +++ b/packages/spec/src/data/field.zod.ts @@ -2271,8 +2271,8 @@ export const FieldSchema = lazySchema(() => { + 'empty, and on a picker with no single record being edited (a bulk-action bar, a filter panel), the entry is left ' + 'out. A { $record } is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A { $record } that reaches a ' + 'server unresolved is refused (INVALID_FILTER), never read as null: by name, naming the field and the path, when ' - + 'it arrives as the eq shorthand on a column that is not a date or datetime; any other operator, and eq on a date ' - + 'or datetime column, is refused earlier, in generic words. The ' + + 'it arrives as the eq shorthand on a column other than a date, datetime or time column; any other operator, and ' + + 'eq on a date, datetime or time column, is refused earlier, in generic words. The ' + 'picker narrows the choice only: a rule the save must enforce belongs on the server too. [PLANNED — not ' + 'enforced] The picker does not resolve { $record } or read orEmpty yet.', ), From 16c765b3711d4a5b3525feecf4cefa95611d22a3 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 13:03:15 +0000 Subject: [PATCH 10/12] docs(spec): regenerate the field references for the temporal-column wording Claude-Session: https://claude.ai/code/session_01FEkQ5kgF3mo9f7LXuv5hac Co-Authored-By: Claude --- content/docs/references/data/field.mdx | 2 +- content/docs/references/data/object.mdx | 4 ++-- content/docs/references/system/migration.mdx | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/content/docs/references/data/field.mdx b/content/docs/references/data/field.mdx index af3a5280605..e504866d0e5 100644 --- a/content/docs/references/data/field.mdx +++ b/content/docs/references/data/field.mdx @@ -93,7 +93,7 @@ const result = CurrencyConfigSchema.parse(data); | **descriptionField** | `string` | optional | Secondary field shown under the label in the quick-select popover. | | **lookupColumns** | `(string \| { field: string; label?: string; width?: string; type?: string })[]` | optional | Explicit columns for the record-picker table; auto-derived from the referenced object when omitted. | | **lookupPageSize** | `integer` | optional | Rows per page in the record-picker dialog (default 10). | -| **lookupFilters** | `{ field: string; operator: Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>; value: any; orEmpty?: boolean }[]` | optional | Base filters restricting which records are selectable (e.g. only active). The structured, picker-honoured lookup filter. Each entry compares a column of the CANDIDATE record (`field`, on the referenced object) with `value`. A value may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }` (at most one lookup hop): the picker sends that value in its place and re-queries whenever a referenced field changes. Those fields are implied: do not list them in `dependsOn`, which also scopes the candidate query by equality (`dependsOn: ['quote_date']` adds `quote_date = …` to the query over the referenced object). While the value is empty, and on a picker with no single record being edited (a bulk-action bar, a filter panel), the entry is left out. A `{ $record }` is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A `{ $record }` that reaches a server unresolved is refused (INVALID_FILTER), never read as null: by name, naming the field and the path, when it arrives as the eq shorthand on a column that is not a date or datetime; any other operator, and eq on a date or datetime column, is refused earlier, in generic words. The picker narrows the choice only: a rule the save must enforce belongs on the server too. [PLANNED — not enforced] The picker does not resolve `{ $record }` or read orEmpty yet. | +| **lookupFilters** | `{ field: string; operator: Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>; value: any; orEmpty?: boolean }[]` | optional | Base filters restricting which records are selectable (e.g. only active). The structured, picker-honoured lookup filter. Each entry compares a column of the CANDIDATE record (`field`, on the referenced object) with `value`. A value may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }` (at most one lookup hop): the picker sends that value in its place and re-queries whenever a referenced field changes. Those fields are implied: do not list them in `dependsOn`, which also scopes the candidate query by equality (`dependsOn: ['quote_date']` adds `quote_date = …` to the query over the referenced object). While the value is empty, and on a picker with no single record being edited (a bulk-action bar, a filter panel), the entry is left out. A `{ $record }` is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A `{ $record }` that reaches a server unresolved is refused (INVALID_FILTER), never read as null: by name, naming the field and the path, when it arrives as the eq shorthand on a column other than a date, datetime or time column; any other operator, and eq on a date, datetime or time column, is refused earlier, in generic words. The picker narrows the choice only: a rule the save must enforce belongs on the server too. [PLANNED — not enforced] The picker does not resolve `{ $record }` or read orEmpty yet. | | **dependsOn** | `(string \| { field: string; param?: string })[]` | optional | Declares that this field's available values depend on the value of other field(s) on the same record — the form gates the field until they are set and re-evaluates as they change. For `lookup`/`master_detail` it scopes the candidate query (string = same local/remote key; `{field,param}` when the remote filter key differs — the `{field,param}` form is lookup-only). For `select`/`multiselect`/`radio` the actual per-option rule lives in each option's `visibleWhen`; list the referenced fields here (string form) so the option list gates and refreshes with the parent. | | **allowCreate** | `boolean` | optional | Allow inline quick-create from the record picker: when no match exists the user can create a record from the typed text (optimistic dataSource.create with the display field). Best for simple objects whose only required field is the display field. | | **lookupAutofill** | `{ target: string; source: string; overwrite?: boolean }[]` | optional | Fields a pick in this lookup fills on the record being edited: each `{ target, source }` pair copies the picked record's `source` field (a field of the `reference` object) into this object's `target` field — e.g. `[{ target: 'unit_price', source: 'list_price' }]` on a quote line's product lookup. Read wherever this field is picked: the record form, and a line-item grid column over it. OVERWRITE RULE — the default, `overwrite` absent or false: a pick never replaces a value somebody wrote. The target is filled only while it is empty or still holds the value an earlier pick filled in; a value the user typed, or one the record already stored, stays. Only a pair that declares `overwrite: true` replaces the target on every pick, whatever it holds. Client-side only: it fills the form, and nothing on the write path reads it — the filled value is saved as an ordinary write, and an import or API write that sets the lookup fills nothing. Only on a single-value `lookup` / `master_detail`. Each target is a field of this object other than this one, written by its author — not `readonly`, not computed (`formula`, `summary`, `autonumber`, or an `expression`) — and named once. Each source is a field of the referenced object that the record carries (not `internal`) and whose value the target can hold; `os validate` / `os build` judge the source. In a line-item grid the column key `autofill` still governs only the same-named copy and is unchanged; a declared pair takes its target out of that copy. | diff --git a/content/docs/references/data/object.mdx b/content/docs/references/data/object.mdx index 662e9819221..0ed4e137604 100644 --- a/content/docs/references/data/object.mdx +++ b/content/docs/references/data/object.mdx @@ -270,7 +270,7 @@ const result = ApiMethod.parse(data); | **descriptionField** | `string` | optional | Secondary field shown under the label in the quick-select popover. | | **lookupColumns** | `(string \| { field: string; label?: string; width?: string; type?: string })[]` | optional | Explicit columns for the record-picker table; auto-derived from the referenced object when omitted. | | **lookupPageSize** | `integer` | optional | Rows per page in the record-picker dialog (default 10). | -| **lookupFilters** | `{ field: string; operator: Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>; value: any; orEmpty?: boolean }[]` | optional | Base filters restricting which records are selectable (e.g. only active). The structured, picker-honoured lookup filter. Each entry compares a column of the CANDIDATE record (`field`, on the referenced object) with `value`. A value may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }` (at most one lookup hop): the picker sends that value in its place and re-queries whenever a referenced field changes. Those fields are implied: do not list them in `dependsOn`, which also scopes the candidate query by equality (`dependsOn: ['quote_date']` adds `quote_date = …` to the query over the referenced object). While the value is empty, and on a picker with no single record being edited (a bulk-action bar, a filter panel), the entry is left out. A `{ $record }` is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A `{ $record }` that reaches a server unresolved is refused (INVALID_FILTER), never read as null: by name, naming the field and the path, when it arrives as the eq shorthand on a column that is not a date or datetime; any other operator, and eq on a date or datetime column, is refused earlier, in generic words. The picker narrows the choice only: a rule the save must enforce belongs on the server too. [PLANNED — not enforced] The picker does not resolve `{ $record }` or read orEmpty yet. | +| **lookupFilters** | `{ field: string; operator: Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>; value: any; orEmpty?: boolean }[]` | optional | Base filters restricting which records are selectable (e.g. only active). The structured, picker-honoured lookup filter. Each entry compares a column of the CANDIDATE record (`field`, on the referenced object) with `value`. A value may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }` (at most one lookup hop): the picker sends that value in its place and re-queries whenever a referenced field changes. Those fields are implied: do not list them in `dependsOn`, which also scopes the candidate query by equality (`dependsOn: ['quote_date']` adds `quote_date = …` to the query over the referenced object). While the value is empty, and on a picker with no single record being edited (a bulk-action bar, a filter panel), the entry is left out. A `{ $record }` is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A `{ $record }` that reaches a server unresolved is refused (INVALID_FILTER), never read as null: by name, naming the field and the path, when it arrives as the eq shorthand on a column other than a date, datetime or time column; any other operator, and eq on a date, datetime or time column, is refused earlier, in generic words. The picker narrows the choice only: a rule the save must enforce belongs on the server too. [PLANNED — not enforced] The picker does not resolve `{ $record }` or read orEmpty yet. | | **dependsOn** | `(string \| { field: string; param?: string })[]` | optional | Declares that this field's available values depend on the value of other field(s) on the same record — the form gates the field until they are set and re-evaluates as they change. For `lookup`/`master_detail` it scopes the candidate query (string = same local/remote key; `{field,param}` when the remote filter key differs — the `{field,param}` form is lookup-only). For `select`/`multiselect`/`radio` the actual per-option rule lives in each option's `visibleWhen`; list the referenced fields here (string form) so the option list gates and refreshes with the parent. | | **allowCreate** | `boolean` | optional | Allow inline quick-create from the record picker: when no match exists the user can create a record from the typed text (optimistic dataSource.create with the display field). Best for simple objects whose only required field is the display field. | | **lookupAutofill** | `{ target: string; source: string; overwrite?: boolean }[]` | optional | Fields a pick in this lookup fills on the record being edited: each `{ target, source }` pair copies the picked record's `source` field (a field of the `reference` object) into this object's `target` field — e.g. `[{ target: 'unit_price', source: 'list_price' }]` on a quote line's product lookup. Read wherever this field is picked: the record form, and a line-item grid column over it. OVERWRITE RULE — the default, `overwrite` absent or false: a pick never replaces a value somebody wrote. The target is filled only while it is empty or still holds the value an earlier pick filled in; a value the user typed, or one the record already stored, stays. Only a pair that declares `overwrite: true` replaces the target on every pick, whatever it holds. Client-side only: it fills the form, and nothing on the write path reads it — the filled value is saved as an ordinary write, and an import or API write that sets the lookup fills nothing. Only on a single-value `lookup` / `master_detail`. Each target is a field of this object other than this one, written by its author — not `readonly`, not computed (`formula`, `summary`, `autonumber`, or an `expression`) — and named once. Each source is a field of the referenced object that the record carries (not `internal`) and whose value the target can hold; `os validate` / `os build` judge the source. In a line-item grid the column key `autofill` still governs only the same-named copy and is unchanged; a declared pair takes its target out of that copy. | @@ -647,7 +647,7 @@ const result = ApiMethod.parse(data); | **descriptionField** | `string` | optional | Secondary field shown under the label in the quick-select popover. | | **lookupColumns** | `(string \| { field: string; label?: string; width?: string; type?: string })[]` | optional | Explicit columns for the record-picker table; auto-derived from the referenced object when omitted. | | **lookupPageSize** | `integer` | optional | Rows per page in the record-picker dialog (default 10). | -| **lookupFilters** | `{ field: string; operator: Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>; value: any; orEmpty?: boolean }[]` | optional | Base filters restricting which records are selectable (e.g. only active). The structured, picker-honoured lookup filter. Each entry compares a column of the CANDIDATE record (`field`, on the referenced object) with `value`. A value may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }` (at most one lookup hop): the picker sends that value in its place and re-queries whenever a referenced field changes. Those fields are implied: do not list them in `dependsOn`, which also scopes the candidate query by equality (`dependsOn: ['quote_date']` adds `quote_date = …` to the query over the referenced object). While the value is empty, and on a picker with no single record being edited (a bulk-action bar, a filter panel), the entry is left out. A `{ $record }` is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A `{ $record }` that reaches a server unresolved is refused (INVALID_FILTER), never read as null: by name, naming the field and the path, when it arrives as the eq shorthand on a column that is not a date or datetime; any other operator, and eq on a date or datetime column, is refused earlier, in generic words. The picker narrows the choice only: a rule the save must enforce belongs on the server too. [PLANNED — not enforced] The picker does not resolve `{ $record }` or read orEmpty yet. | +| **lookupFilters** | `{ field: string; operator: Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>; value: any; orEmpty?: boolean }[]` | optional | Base filters restricting which records are selectable (e.g. only active). The structured, picker-honoured lookup filter. Each entry compares a column of the CANDIDATE record (`field`, on the referenced object) with `value`. A value may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }` (at most one lookup hop): the picker sends that value in its place and re-queries whenever a referenced field changes. Those fields are implied: do not list them in `dependsOn`, which also scopes the candidate query by equality (`dependsOn: ['quote_date']` adds `quote_date = …` to the query over the referenced object). While the value is empty, and on a picker with no single record being edited (a bulk-action bar, a filter panel), the entry is left out. A `{ $record }` is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A `{ $record }` that reaches a server unresolved is refused (INVALID_FILTER), never read as null: by name, naming the field and the path, when it arrives as the eq shorthand on a column other than a date, datetime or time column; any other operator, and eq on a date, datetime or time column, is refused earlier, in generic words. The picker narrows the choice only: a rule the save must enforce belongs on the server too. [PLANNED — not enforced] The picker does not resolve `{ $record }` or read orEmpty yet. | | **dependsOn** | `(string \| { field: string; param?: string })[]` | optional | Declares that this field's available values depend on the value of other field(s) on the same record — the form gates the field until they are set and re-evaluates as they change. For `lookup`/`master_detail` it scopes the candidate query (string = same local/remote key; `{field,param}` when the remote filter key differs — the `{field,param}` form is lookup-only). For `select`/`multiselect`/`radio` the actual per-option rule lives in each option's `visibleWhen`; list the referenced fields here (string form) so the option list gates and refreshes with the parent. | | **allowCreate** | `boolean` | optional | Allow inline quick-create from the record picker: when no match exists the user can create a record from the typed text (optimistic dataSource.create with the display field). Best for simple objects whose only required field is the display field. | | **lookupAutofill** | `{ target: string; source: string; overwrite?: boolean }[]` | optional | Fields a pick in this lookup fills on the record being edited: each `{ target, source }` pair copies the picked record's `source` field (a field of the `reference` object) into this object's `target` field — e.g. `[{ target: 'unit_price', source: 'list_price' }]` on a quote line's product lookup. Read wherever this field is picked: the record form, and a line-item grid column over it. OVERWRITE RULE — the default, `overwrite` absent or false: a pick never replaces a value somebody wrote. The target is filled only while it is empty or still holds the value an earlier pick filled in; a value the user typed, or one the record already stored, stays. Only a pair that declares `overwrite: true` replaces the target on every pick, whatever it holds. Client-side only: it fills the form, and nothing on the write path reads it — the filled value is saved as an ordinary write, and an import or API write that sets the lookup fills nothing. Only on a single-value `lookup` / `master_detail`. Each target is a field of this object other than this one, written by its author — not `readonly`, not computed (`formula`, `summary`, `autonumber`, or an `expression`) — and named once. Each source is a field of the referenced object that the record carries (not `internal`) and whose value the target can hold; `os validate` / `os build` judge the source. In a line-item grid the column key `autofill` still governs only the same-named copy and is unchanged; a declared pair takes its target out of that copy. | diff --git a/content/docs/references/system/migration.mdx b/content/docs/references/system/migration.mdx index 283a1508e0a..aa8ef18f2a1 100644 --- a/content/docs/references/system/migration.mdx +++ b/content/docs/references/system/migration.mdx @@ -96,7 +96,7 @@ Add a new field to an existing object | **descriptionField** | `string` | optional | Secondary field shown under the label in the quick-select popover. | | **lookupColumns** | `(string \| { field: string; label?: string; width?: string; type?: string })[]` | optional | Explicit columns for the record-picker table; auto-derived from the referenced object when omitted. | | **lookupPageSize** | `integer` | optional | Rows per page in the record-picker dialog (default 10). | -| **lookupFilters** | `{ field: string; operator: Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>; value: any; orEmpty?: boolean }[]` | optional | Base filters restricting which records are selectable (e.g. only active). The structured, picker-honoured lookup filter. Each entry compares a column of the CANDIDATE record (`field`, on the referenced object) with `value`. A value may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }` (at most one lookup hop): the picker sends that value in its place and re-queries whenever a referenced field changes. Those fields are implied: do not list them in `dependsOn`, which also scopes the candidate query by equality (`dependsOn: ['quote_date']` adds `quote_date = …` to the query over the referenced object). While the value is empty, and on a picker with no single record being edited (a bulk-action bar, a filter panel), the entry is left out. A `{ $record }` is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A `{ $record }` that reaches a server unresolved is refused (INVALID_FILTER), never read as null: by name, naming the field and the path, when it arrives as the eq shorthand on a column that is not a date or datetime; any other operator, and eq on a date or datetime column, is refused earlier, in generic words. The picker narrows the choice only: a rule the save must enforce belongs on the server too. [PLANNED — not enforced] The picker does not resolve `{ $record }` or read orEmpty yet. | +| **lookupFilters** | `{ field: string; operator: Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>; value: any; orEmpty?: boolean }[]` | optional | Base filters restricting which records are selectable (e.g. only active). The structured, picker-honoured lookup filter. Each entry compares a column of the CANDIDATE record (`field`, on the referenced object) with `value`. A value may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }` (at most one lookup hop): the picker sends that value in its place and re-queries whenever a referenced field changes. Those fields are implied: do not list them in `dependsOn`, which also scopes the candidate query by equality (`dependsOn: ['quote_date']` adds `quote_date = …` to the query over the referenced object). While the value is empty, and on a picker with no single record being edited (a bulk-action bar, a filter panel), the entry is left out. A `{ $record }` is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A `{ $record }` that reaches a server unresolved is refused (INVALID_FILTER), never read as null: by name, naming the field and the path, when it arrives as the eq shorthand on a column other than a date, datetime or time column; any other operator, and eq on a date, datetime or time column, is refused earlier, in generic words. The picker narrows the choice only: a rule the save must enforce belongs on the server too. [PLANNED — not enforced] The picker does not resolve `{ $record }` or read orEmpty yet. | | **dependsOn** | `(string \| { field: string; param?: string })[]` | optional | Declares that this field's available values depend on the value of other field(s) on the same record — the form gates the field until they are set and re-evaluates as they change. For `lookup`/`master_detail` it scopes the candidate query (string = same local/remote key; `{field,param}` when the remote filter key differs — the `{field,param}` form is lookup-only). For `select`/`multiselect`/`radio` the actual per-option rule lives in each option's `visibleWhen`; list the referenced fields here (string form) so the option list gates and refreshes with the parent. | | **allowCreate** | `boolean` | optional | Allow inline quick-create from the record picker: when no match exists the user can create a record from the typed text (optimistic dataSource.create with the display field). Best for simple objects whose only required field is the display field. | | **lookupAutofill** | `{ target: string; source: string; overwrite?: boolean }[]` | optional | Fields a pick in this lookup fills on the record being edited: each `{ target, source }` pair copies the picked record's `source` field (a field of the `reference` object) into this object's `target` field — e.g. `[{ target: 'unit_price', source: 'list_price' }]` on a quote line's product lookup. Read wherever this field is picked: the record form, and a line-item grid column over it. OVERWRITE RULE — the default, `overwrite` absent or false: a pick never replaces a value somebody wrote. The target is filled only while it is empty or still holds the value an earlier pick filled in; a value the user typed, or one the record already stored, stays. Only a pair that declares `overwrite: true` replaces the target on every pick, whatever it holds. Client-side only: it fills the form, and nothing on the write path reads it — the filled value is saved as an ordinary write, and an import or API write that sets the lookup fills nothing. Only on a single-value `lookup` / `master_detail`. Each target is a field of this object other than this one, written by its author — not `readonly`, not computed (`formula`, `summary`, `autonumber`, or an `expression`) — and named once. Each source is a field of the referenced object that the record carries (not `internal`) and whose value the target can hold; `os validate` / `os build` judge the source. In a line-item grid the column key `autofill` still governs only the same-named copy and is unchanged; a declared pair takes its target out of that copy. | @@ -532,7 +532,7 @@ Add a new field to an existing object | **descriptionField** | `string` | optional | Secondary field shown under the label in the quick-select popover. | | **lookupColumns** | `(string \| { field: string; label?: string; width?: string; type?: string })[]` | optional | Explicit columns for the record-picker table; auto-derived from the referenced object when omitted. | | **lookupPageSize** | `integer` | optional | Rows per page in the record-picker dialog (default 10). | -| **lookupFilters** | `{ field: string; operator: Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>; value: any; orEmpty?: boolean }[]` | optional | Base filters restricting which records are selectable (e.g. only active). The structured, picker-honoured lookup filter. Each entry compares a column of the CANDIDATE record (`field`, on the referenced object) with `value`. A value may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }` (at most one lookup hop): the picker sends that value in its place and re-queries whenever a referenced field changes. Those fields are implied: do not list them in `dependsOn`, which also scopes the candidate query by equality (`dependsOn: ['quote_date']` adds `quote_date = …` to the query over the referenced object). While the value is empty, and on a picker with no single record being edited (a bulk-action bar, a filter panel), the entry is left out. A `{ $record }` is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A `{ $record }` that reaches a server unresolved is refused (INVALID_FILTER), never read as null: by name, naming the field and the path, when it arrives as the eq shorthand on a column that is not a date or datetime; any other operator, and eq on a date or datetime column, is refused earlier, in generic words. The picker narrows the choice only: a rule the save must enforce belongs on the server too. [PLANNED — not enforced] The picker does not resolve `{ $record }` or read orEmpty yet. | +| **lookupFilters** | `{ field: string; operator: Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>; value: any; orEmpty?: boolean }[]` | optional | Base filters restricting which records are selectable (e.g. only active). The structured, picker-honoured lookup filter. Each entry compares a column of the CANDIDATE record (`field`, on the referenced object) with `value`. A value may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }` (at most one lookup hop): the picker sends that value in its place and re-queries whenever a referenced field changes. Those fields are implied: do not list them in `dependsOn`, which also scopes the candidate query by equality (`dependsOn: ['quote_date']` adds `quote_date = …` to the query over the referenced object). While the value is empty, and on a picker with no single record being edited (a bulk-action bar, a filter panel), the entry is left out. A `{ $record }` is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A `{ $record }` that reaches a server unresolved is refused (INVALID_FILTER), never read as null: by name, naming the field and the path, when it arrives as the eq shorthand on a column other than a date, datetime or time column; any other operator, and eq on a date, datetime or time column, is refused earlier, in generic words. The picker narrows the choice only: a rule the save must enforce belongs on the server too. [PLANNED — not enforced] The picker does not resolve `{ $record }` or read orEmpty yet. | | **dependsOn** | `(string \| { field: string; param?: string })[]` | optional | Declares that this field's available values depend on the value of other field(s) on the same record — the form gates the field until they are set and re-evaluates as they change. For `lookup`/`master_detail` it scopes the candidate query (string = same local/remote key; `{field,param}` when the remote filter key differs — the `{field,param}` form is lookup-only). For `select`/`multiselect`/`radio` the actual per-option rule lives in each option's `visibleWhen`; list the referenced fields here (string form) so the option list gates and refreshes with the parent. | | **allowCreate** | `boolean` | optional | Allow inline quick-create from the record picker: when no match exists the user can create a record from the typed text (optimistic dataSource.create with the display field). Best for simple objects whose only required field is the display field. | | **lookupAutofill** | `{ target: string; source: string; overwrite?: boolean }[]` | optional | Fields a pick in this lookup fills on the record being edited: each `{ target, source }` pair copies the picked record's `source` field (a field of the `reference` object) into this object's `target` field — e.g. `[{ target: 'unit_price', source: 'list_price' }]` on a quote line's product lookup. Read wherever this field is picked: the record form, and a line-item grid column over it. OVERWRITE RULE — the default, `overwrite` absent or false: a pick never replaces a value somebody wrote. The target is filled only while it is empty or still holds the value an earlier pick filled in; a value the user typed, or one the record already stored, stays. Only a pair that declares `overwrite: true` replaces the target on every pick, whatever it holds. Client-side only: it fills the form, and nothing on the write path reads it — the filled value is saved as an ordinary write, and an import or API write that sets the lookup fills nothing. Only on a single-value `lookup` / `master_detail`. Each target is a field of this object other than this one, written by its author — not `readonly`, not computed (`formula`, `summary`, `autonumber`, or an `expression`) — and named once. Each source is a field of the referenced object that the record carries (not `internal`) and whose value the target can hold; `os validate` / `os build` judge the source. In a line-item grid the column key `autofill` still governs only the same-named copy and is unchanged; a declared pair takes its target out of that copy. | From e3775ec5ff76efaa578df5f99dad1ff983d157ec Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 14:21:50 +0000 Subject: [PATCH 11/12] docs(spec): regenerate the field references from the merged source The os-regen driver kept one side of the three references in the merge; os-regen-merge.sh step 2 took main's side, and gen:schema + gen:docs re-derive them from the merged field.zod.ts: main's picker sentences plus this branch's server sentences. Claude-Session: https://claude.ai/code/session_01FEkQ5kgF3mo9f7LXuv5hac Co-Authored-By: Claude --- content/docs/references/data/field.mdx | 6 +++--- content/docs/references/data/object.mdx | 4 ++-- content/docs/references/system/migration.mdx | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/content/docs/references/data/field.mdx b/content/docs/references/data/field.mdx index e504866d0e5..18f6f0d956b 100644 --- a/content/docs/references/data/field.mdx +++ b/content/docs/references/data/field.mdx @@ -93,7 +93,7 @@ const result = CurrencyConfigSchema.parse(data); | **descriptionField** | `string` | optional | Secondary field shown under the label in the quick-select popover. | | **lookupColumns** | `(string \| { field: string; label?: string; width?: string; type?: string })[]` | optional | Explicit columns for the record-picker table; auto-derived from the referenced object when omitted. | | **lookupPageSize** | `integer` | optional | Rows per page in the record-picker dialog (default 10). | -| **lookupFilters** | `{ field: string; operator: Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>; value: any; orEmpty?: boolean }[]` | optional | Base filters restricting which records are selectable (e.g. only active). The structured, picker-honoured lookup filter. Each entry compares a column of the CANDIDATE record (`field`, on the referenced object) with `value`. A value may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }` (at most one lookup hop): the picker sends that value in its place and re-queries whenever a referenced field changes. Those fields are implied: do not list them in `dependsOn`, which also scopes the candidate query by equality (`dependsOn: ['quote_date']` adds `quote_date = …` to the query over the referenced object). While the value is empty, and on a picker with no single record being edited (a bulk-action bar, a filter panel), the entry is left out. A `{ $record }` is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A `{ $record }` that reaches a server unresolved is refused (INVALID_FILTER), never read as null: by name, naming the field and the path, when it arrives as the eq shorthand on a column other than a date, datetime or time column; any other operator, and eq on a date, datetime or time column, is refused earlier, in generic words. The picker narrows the choice only: a rule the save must enforce belongs on the server too. [PLANNED — not enforced] The picker does not resolve `{ $record }` or read orEmpty yet. | +| **lookupFilters** | `{ field: string; operator: Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>; value: any; orEmpty?: boolean }[]` | optional | Base filters restricting which records are selectable (e.g. only active). The structured, picker-honoured lookup filter. Each entry compares a column of the CANDIDATE record (`field`, on the referenced object) with `value`. A value may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }` (at most one lookup hop). In a record form, whatever its layout, the picker sends that value in its place and re-queries whenever a referenced field changes; every other picker host leaves every `{ $record }` entry out: inline edit on a record page, a record page's header or related list, an action's parameter dialog, and a picker with no single record being edited (a bulk action over selected rows). The referenced fields are implied: do not list them in `dependsOn`, which also scopes the candidate query by equality (`dependsOn: ['quote_date']` adds `quote_date = …` to the query over the referenced object). While the value is empty or cannot be read (the hop's row or field does not come back, no object is named for the hop, or the host has no single-row reader), the entry is left out. A `{ $record }` is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A `{ $record }` that reaches a server unresolved is refused (INVALID_FILTER), never read as null: by name, naming the field and the path, when it arrives as the eq shorthand on a column other than a date, datetime or time column; any other operator, and eq on a date, datetime or time column, is refused earlier, in generic words. The picker narrows the choice only: a rule the save must enforce belongs on the server too. | | **dependsOn** | `(string \| { field: string; param?: string })[]` | optional | Declares that this field's available values depend on the value of other field(s) on the same record — the form gates the field until they are set and re-evaluates as they change. For `lookup`/`master_detail` it scopes the candidate query (string = same local/remote key; `{field,param}` when the remote filter key differs — the `{field,param}` form is lookup-only). For `select`/`multiselect`/`radio` the actual per-option rule lives in each option's `visibleWhen`; list the referenced fields here (string form) so the option list gates and refreshes with the parent. | | **allowCreate** | `boolean` | optional | Allow inline quick-create from the record picker: when no match exists the user can create a record from the typed text (optimistic dataSource.create with the display field). Best for simple objects whose only required field is the display field. | | **lookupAutofill** | `{ target: string; source: string; overwrite?: boolean }[]` | optional | Fields a pick in this lookup fills on the record being edited: each `{ target, source }` pair copies the picked record's `source` field (a field of the `reference` object) into this object's `target` field — e.g. `[{ target: 'unit_price', source: 'list_price' }]` on a quote line's product lookup. Read wherever this field is picked: the record form, and a line-item grid column over it. OVERWRITE RULE — the default, `overwrite` absent or false: a pick never replaces a value somebody wrote. The target is filled only while it is empty or still holds the value an earlier pick filled in; a value the user typed, or one the record already stored, stays. Only a pair that declares `overwrite: true` replaces the target on every pick, whatever it holds. Client-side only: it fills the form, and nothing on the write path reads it — the filled value is saved as an ordinary write, and an import or API write that sets the lookup fills nothing. Only on a single-value `lookup` / `master_detail`. Each target is a field of this object other than this one, written by its author — not `readonly`, not computed (`formula`, `summary`, `autonumber`, or an `expression`) — and named once. Each source is a field of the referenced object that the record carries (not `internal`) and whose value the target can hold; `os validate` / `os build` judge the source. In a line-item grid the column key `autofill` still governs only the same-named copy and is unchanged; a declared pair takes its target out of that copy. | @@ -242,8 +242,8 @@ const result = CurrencyConfigSchema.parse(data); | :--- | :--- | :--- | :--- | | **field** | `string` | ✅ | | | **operator** | `Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>` | ✅ | | -| **value** | `any` | ✅ | The comparand: a literal (an array for `in` / `notIn`), a date placeholder such as `{today}` or a `{ $now: true, addDays }` comparand for a date relative to today, or a `{ $record: "path" }` reference to the record being edited — a field of it, or one lookup hop ("account.cb_market"); a `{ $record }` value pairs only with eq, ne, gt, lt, gte or lte. A `{ $record }` that reaches a server unresolved is refused (INVALID_FILTER), never read as null. [PLANNED — not enforced] The picker does not resolve `{ $record }` yet. | -| **orEmpty** | `boolean` | optional | [PLANNED — not enforced] TRUE: the entry also matches a candidate whose column is null — "valid from the quote date, or with no start date". Only with eq, ne, gt, lt, gte or lte. The picker does not read it yet. | +| **value** | `any` | ✅ | The comparand: a literal (an array for `in` / `notIn`), a date placeholder such as `{today}` or a `{ $now: true, addDays }` comparand for a date relative to today, or a `{ $record: "path" }` reference to the record being edited — a field of it, or one lookup hop ("account.cb_market"); a `{ $record }` value pairs only with eq, ne, gt, lt, gte or lte. In a record form, whatever its layout, the picker sends the referenced value in place of the reference; every other picker host leaves the entry out. A `{ $record }` that reaches a server unresolved is refused (INVALID_FILTER), never read as null. | +| **orEmpty** | `boolean` | optional | TRUE: the entry also matches a candidate whose column is null — "valid from the quote date, or with no start date". Only with eq, ne, gt, lt, gte or lte. The picker sends the comparison or a null match on the same column. | ### Nested Shape: `Field.lookupAutofill[number]` diff --git a/content/docs/references/data/object.mdx b/content/docs/references/data/object.mdx index 0ed4e137604..f81d49afcd7 100644 --- a/content/docs/references/data/object.mdx +++ b/content/docs/references/data/object.mdx @@ -270,7 +270,7 @@ const result = ApiMethod.parse(data); | **descriptionField** | `string` | optional | Secondary field shown under the label in the quick-select popover. | | **lookupColumns** | `(string \| { field: string; label?: string; width?: string; type?: string })[]` | optional | Explicit columns for the record-picker table; auto-derived from the referenced object when omitted. | | **lookupPageSize** | `integer` | optional | Rows per page in the record-picker dialog (default 10). | -| **lookupFilters** | `{ field: string; operator: Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>; value: any; orEmpty?: boolean }[]` | optional | Base filters restricting which records are selectable (e.g. only active). The structured, picker-honoured lookup filter. Each entry compares a column of the CANDIDATE record (`field`, on the referenced object) with `value`. A value may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }` (at most one lookup hop): the picker sends that value in its place and re-queries whenever a referenced field changes. Those fields are implied: do not list them in `dependsOn`, which also scopes the candidate query by equality (`dependsOn: ['quote_date']` adds `quote_date = …` to the query over the referenced object). While the value is empty, and on a picker with no single record being edited (a bulk-action bar, a filter panel), the entry is left out. A `{ $record }` is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A `{ $record }` that reaches a server unresolved is refused (INVALID_FILTER), never read as null: by name, naming the field and the path, when it arrives as the eq shorthand on a column other than a date, datetime or time column; any other operator, and eq on a date, datetime or time column, is refused earlier, in generic words. The picker narrows the choice only: a rule the save must enforce belongs on the server too. [PLANNED — not enforced] The picker does not resolve `{ $record }` or read orEmpty yet. | +| **lookupFilters** | `{ field: string; operator: Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>; value: any; orEmpty?: boolean }[]` | optional | Base filters restricting which records are selectable (e.g. only active). The structured, picker-honoured lookup filter. Each entry compares a column of the CANDIDATE record (`field`, on the referenced object) with `value`. A value may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }` (at most one lookup hop). In a record form, whatever its layout, the picker sends that value in its place and re-queries whenever a referenced field changes; every other picker host leaves every `{ $record }` entry out: inline edit on a record page, a record page's header or related list, an action's parameter dialog, and a picker with no single record being edited (a bulk action over selected rows). The referenced fields are implied: do not list them in `dependsOn`, which also scopes the candidate query by equality (`dependsOn: ['quote_date']` adds `quote_date = …` to the query over the referenced object). While the value is empty or cannot be read (the hop's row or field does not come back, no object is named for the hop, or the host has no single-row reader), the entry is left out. A `{ $record }` is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A `{ $record }` that reaches a server unresolved is refused (INVALID_FILTER), never read as null: by name, naming the field and the path, when it arrives as the eq shorthand on a column other than a date, datetime or time column; any other operator, and eq on a date, datetime or time column, is refused earlier, in generic words. The picker narrows the choice only: a rule the save must enforce belongs on the server too. | | **dependsOn** | `(string \| { field: string; param?: string })[]` | optional | Declares that this field's available values depend on the value of other field(s) on the same record — the form gates the field until they are set and re-evaluates as they change. For `lookup`/`master_detail` it scopes the candidate query (string = same local/remote key; `{field,param}` when the remote filter key differs — the `{field,param}` form is lookup-only). For `select`/`multiselect`/`radio` the actual per-option rule lives in each option's `visibleWhen`; list the referenced fields here (string form) so the option list gates and refreshes with the parent. | | **allowCreate** | `boolean` | optional | Allow inline quick-create from the record picker: when no match exists the user can create a record from the typed text (optimistic dataSource.create with the display field). Best for simple objects whose only required field is the display field. | | **lookupAutofill** | `{ target: string; source: string; overwrite?: boolean }[]` | optional | Fields a pick in this lookup fills on the record being edited: each `{ target, source }` pair copies the picked record's `source` field (a field of the `reference` object) into this object's `target` field — e.g. `[{ target: 'unit_price', source: 'list_price' }]` on a quote line's product lookup. Read wherever this field is picked: the record form, and a line-item grid column over it. OVERWRITE RULE — the default, `overwrite` absent or false: a pick never replaces a value somebody wrote. The target is filled only while it is empty or still holds the value an earlier pick filled in; a value the user typed, or one the record already stored, stays. Only a pair that declares `overwrite: true` replaces the target on every pick, whatever it holds. Client-side only: it fills the form, and nothing on the write path reads it — the filled value is saved as an ordinary write, and an import or API write that sets the lookup fills nothing. Only on a single-value `lookup` / `master_detail`. Each target is a field of this object other than this one, written by its author — not `readonly`, not computed (`formula`, `summary`, `autonumber`, or an `expression`) — and named once. Each source is a field of the referenced object that the record carries (not `internal`) and whose value the target can hold; `os validate` / `os build` judge the source. In a line-item grid the column key `autofill` still governs only the same-named copy and is unchanged; a declared pair takes its target out of that copy. | @@ -647,7 +647,7 @@ const result = ApiMethod.parse(data); | **descriptionField** | `string` | optional | Secondary field shown under the label in the quick-select popover. | | **lookupColumns** | `(string \| { field: string; label?: string; width?: string; type?: string })[]` | optional | Explicit columns for the record-picker table; auto-derived from the referenced object when omitted. | | **lookupPageSize** | `integer` | optional | Rows per page in the record-picker dialog (default 10). | -| **lookupFilters** | `{ field: string; operator: Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>; value: any; orEmpty?: boolean }[]` | optional | Base filters restricting which records are selectable (e.g. only active). The structured, picker-honoured lookup filter. Each entry compares a column of the CANDIDATE record (`field`, on the referenced object) with `value`. A value may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }` (at most one lookup hop): the picker sends that value in its place and re-queries whenever a referenced field changes. Those fields are implied: do not list them in `dependsOn`, which also scopes the candidate query by equality (`dependsOn: ['quote_date']` adds `quote_date = …` to the query over the referenced object). While the value is empty, and on a picker with no single record being edited (a bulk-action bar, a filter panel), the entry is left out. A `{ $record }` is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A `{ $record }` that reaches a server unresolved is refused (INVALID_FILTER), never read as null: by name, naming the field and the path, when it arrives as the eq shorthand on a column other than a date, datetime or time column; any other operator, and eq on a date, datetime or time column, is refused earlier, in generic words. The picker narrows the choice only: a rule the save must enforce belongs on the server too. [PLANNED — not enforced] The picker does not resolve `{ $record }` or read orEmpty yet. | +| **lookupFilters** | `{ field: string; operator: Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>; value: any; orEmpty?: boolean }[]` | optional | Base filters restricting which records are selectable (e.g. only active). The structured, picker-honoured lookup filter. Each entry compares a column of the CANDIDATE record (`field`, on the referenced object) with `value`. A value may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }` (at most one lookup hop). In a record form, whatever its layout, the picker sends that value in its place and re-queries whenever a referenced field changes; every other picker host leaves every `{ $record }` entry out: inline edit on a record page, a record page's header or related list, an action's parameter dialog, and a picker with no single record being edited (a bulk action over selected rows). The referenced fields are implied: do not list them in `dependsOn`, which also scopes the candidate query by equality (`dependsOn: ['quote_date']` adds `quote_date = …` to the query over the referenced object). While the value is empty or cannot be read (the hop's row or field does not come back, no object is named for the hop, or the host has no single-row reader), the entry is left out. A `{ $record }` is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A `{ $record }` that reaches a server unresolved is refused (INVALID_FILTER), never read as null: by name, naming the field and the path, when it arrives as the eq shorthand on a column other than a date, datetime or time column; any other operator, and eq on a date, datetime or time column, is refused earlier, in generic words. The picker narrows the choice only: a rule the save must enforce belongs on the server too. | | **dependsOn** | `(string \| { field: string; param?: string })[]` | optional | Declares that this field's available values depend on the value of other field(s) on the same record — the form gates the field until they are set and re-evaluates as they change. For `lookup`/`master_detail` it scopes the candidate query (string = same local/remote key; `{field,param}` when the remote filter key differs — the `{field,param}` form is lookup-only). For `select`/`multiselect`/`radio` the actual per-option rule lives in each option's `visibleWhen`; list the referenced fields here (string form) so the option list gates and refreshes with the parent. | | **allowCreate** | `boolean` | optional | Allow inline quick-create from the record picker: when no match exists the user can create a record from the typed text (optimistic dataSource.create with the display field). Best for simple objects whose only required field is the display field. | | **lookupAutofill** | `{ target: string; source: string; overwrite?: boolean }[]` | optional | Fields a pick in this lookup fills on the record being edited: each `{ target, source }` pair copies the picked record's `source` field (a field of the `reference` object) into this object's `target` field — e.g. `[{ target: 'unit_price', source: 'list_price' }]` on a quote line's product lookup. Read wherever this field is picked: the record form, and a line-item grid column over it. OVERWRITE RULE — the default, `overwrite` absent or false: a pick never replaces a value somebody wrote. The target is filled only while it is empty or still holds the value an earlier pick filled in; a value the user typed, or one the record already stored, stays. Only a pair that declares `overwrite: true` replaces the target on every pick, whatever it holds. Client-side only: it fills the form, and nothing on the write path reads it — the filled value is saved as an ordinary write, and an import or API write that sets the lookup fills nothing. Only on a single-value `lookup` / `master_detail`. Each target is a field of this object other than this one, written by its author — not `readonly`, not computed (`formula`, `summary`, `autonumber`, or an `expression`) — and named once. Each source is a field of the referenced object that the record carries (not `internal`) and whose value the target can hold; `os validate` / `os build` judge the source. In a line-item grid the column key `autofill` still governs only the same-named copy and is unchanged; a declared pair takes its target out of that copy. | diff --git a/content/docs/references/system/migration.mdx b/content/docs/references/system/migration.mdx index aa8ef18f2a1..102c9953f41 100644 --- a/content/docs/references/system/migration.mdx +++ b/content/docs/references/system/migration.mdx @@ -96,7 +96,7 @@ Add a new field to an existing object | **descriptionField** | `string` | optional | Secondary field shown under the label in the quick-select popover. | | **lookupColumns** | `(string \| { field: string; label?: string; width?: string; type?: string })[]` | optional | Explicit columns for the record-picker table; auto-derived from the referenced object when omitted. | | **lookupPageSize** | `integer` | optional | Rows per page in the record-picker dialog (default 10). | -| **lookupFilters** | `{ field: string; operator: Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>; value: any; orEmpty?: boolean }[]` | optional | Base filters restricting which records are selectable (e.g. only active). The structured, picker-honoured lookup filter. Each entry compares a column of the CANDIDATE record (`field`, on the referenced object) with `value`. A value may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }` (at most one lookup hop): the picker sends that value in its place and re-queries whenever a referenced field changes. Those fields are implied: do not list them in `dependsOn`, which also scopes the candidate query by equality (`dependsOn: ['quote_date']` adds `quote_date = …` to the query over the referenced object). While the value is empty, and on a picker with no single record being edited (a bulk-action bar, a filter panel), the entry is left out. A `{ $record }` is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A `{ $record }` that reaches a server unresolved is refused (INVALID_FILTER), never read as null: by name, naming the field and the path, when it arrives as the eq shorthand on a column other than a date, datetime or time column; any other operator, and eq on a date, datetime or time column, is refused earlier, in generic words. The picker narrows the choice only: a rule the save must enforce belongs on the server too. [PLANNED — not enforced] The picker does not resolve `{ $record }` or read orEmpty yet. | +| **lookupFilters** | `{ field: string; operator: Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>; value: any; orEmpty?: boolean }[]` | optional | Base filters restricting which records are selectable (e.g. only active). The structured, picker-honoured lookup filter. Each entry compares a column of the CANDIDATE record (`field`, on the referenced object) with `value`. A value may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }` (at most one lookup hop). In a record form, whatever its layout, the picker sends that value in its place and re-queries whenever a referenced field changes; every other picker host leaves every `{ $record }` entry out: inline edit on a record page, a record page's header or related list, an action's parameter dialog, and a picker with no single record being edited (a bulk action over selected rows). The referenced fields are implied: do not list them in `dependsOn`, which also scopes the candidate query by equality (`dependsOn: ['quote_date']` adds `quote_date = …` to the query over the referenced object). While the value is empty or cannot be read (the hop's row or field does not come back, no object is named for the hop, or the host has no single-row reader), the entry is left out. A `{ $record }` is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A `{ $record }` that reaches a server unresolved is refused (INVALID_FILTER), never read as null: by name, naming the field and the path, when it arrives as the eq shorthand on a column other than a date, datetime or time column; any other operator, and eq on a date, datetime or time column, is refused earlier, in generic words. The picker narrows the choice only: a rule the save must enforce belongs on the server too. | | **dependsOn** | `(string \| { field: string; param?: string })[]` | optional | Declares that this field's available values depend on the value of other field(s) on the same record — the form gates the field until they are set and re-evaluates as they change. For `lookup`/`master_detail` it scopes the candidate query (string = same local/remote key; `{field,param}` when the remote filter key differs — the `{field,param}` form is lookup-only). For `select`/`multiselect`/`radio` the actual per-option rule lives in each option's `visibleWhen`; list the referenced fields here (string form) so the option list gates and refreshes with the parent. | | **allowCreate** | `boolean` | optional | Allow inline quick-create from the record picker: when no match exists the user can create a record from the typed text (optimistic dataSource.create with the display field). Best for simple objects whose only required field is the display field. | | **lookupAutofill** | `{ target: string; source: string; overwrite?: boolean }[]` | optional | Fields a pick in this lookup fills on the record being edited: each `{ target, source }` pair copies the picked record's `source` field (a field of the `reference` object) into this object's `target` field — e.g. `[{ target: 'unit_price', source: 'list_price' }]` on a quote line's product lookup. Read wherever this field is picked: the record form, and a line-item grid column over it. OVERWRITE RULE — the default, `overwrite` absent or false: a pick never replaces a value somebody wrote. The target is filled only while it is empty or still holds the value an earlier pick filled in; a value the user typed, or one the record already stored, stays. Only a pair that declares `overwrite: true` replaces the target on every pick, whatever it holds. Client-side only: it fills the form, and nothing on the write path reads it — the filled value is saved as an ordinary write, and an import or API write that sets the lookup fills nothing. Only on a single-value `lookup` / `master_detail`. Each target is a field of this object other than this one, written by its author — not `readonly`, not computed (`formula`, `summary`, `autonumber`, or an `expression`) — and named once. Each source is a field of the referenced object that the record carries (not `internal`) and whose value the target can hold; `os validate` / `os build` judge the source. In a line-item grid the column key `autofill` still governs only the same-named copy and is unchanged; a declared pair takes its target out of that copy. | @@ -532,7 +532,7 @@ Add a new field to an existing object | **descriptionField** | `string` | optional | Secondary field shown under the label in the quick-select popover. | | **lookupColumns** | `(string \| { field: string; label?: string; width?: string; type?: string })[]` | optional | Explicit columns for the record-picker table; auto-derived from the referenced object when omitted. | | **lookupPageSize** | `integer` | optional | Rows per page in the record-picker dialog (default 10). | -| **lookupFilters** | `{ field: string; operator: Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>; value: any; orEmpty?: boolean }[]` | optional | Base filters restricting which records are selectable (e.g. only active). The structured, picker-honoured lookup filter. Each entry compares a column of the CANDIDATE record (`field`, on the referenced object) with `value`. A value may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }` (at most one lookup hop): the picker sends that value in its place and re-queries whenever a referenced field changes. Those fields are implied: do not list them in `dependsOn`, which also scopes the candidate query by equality (`dependsOn: ['quote_date']` adds `quote_date = …` to the query over the referenced object). While the value is empty, and on a picker with no single record being edited (a bulk-action bar, a filter panel), the entry is left out. A `{ $record }` is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A `{ $record }` that reaches a server unresolved is refused (INVALID_FILTER), never read as null: by name, naming the field and the path, when it arrives as the eq shorthand on a column other than a date, datetime or time column; any other operator, and eq on a date, datetime or time column, is refused earlier, in generic words. The picker narrows the choice only: a rule the save must enforce belongs on the server too. [PLANNED — not enforced] The picker does not resolve `{ $record }` or read orEmpty yet. | +| **lookupFilters** | `{ field: string; operator: Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>; value: any; orEmpty?: boolean }[]` | optional | Base filters restricting which records are selectable (e.g. only active). The structured, picker-honoured lookup filter. Each entry compares a column of the CANDIDATE record (`field`, on the referenced object) with `value`. A value may read the record being edited as `{ $record: "field" }` or `{ $record: "lookup_field.field" }` (at most one lookup hop). In a record form, whatever its layout, the picker sends that value in its place and re-queries whenever a referenced field changes; every other picker host leaves every `{ $record }` entry out: inline edit on a record page, a record page's header or related list, an action's parameter dialog, and a picker with no single record being edited (a bulk action over selected rows). The referenced fields are implied: do not list them in `dependsOn`, which also scopes the candidate query by equality (`dependsOn: ['quote_date']` adds `quote_date = …` to the query over the referenced object). While the value is empty or cannot be read (the hop's row or field does not come back, no object is named for the hop, or the host has no single-row reader), the entry is left out. A `{ $record }` is the whole value, never a member of an `in` / `notIn` list. `orEmpty: true` also matches a candidate whose column is null. A `{ $record }` that reaches a server unresolved is refused (INVALID_FILTER), never read as null: by name, naming the field and the path, when it arrives as the eq shorthand on a column other than a date, datetime or time column; any other operator, and eq on a date, datetime or time column, is refused earlier, in generic words. The picker narrows the choice only: a rule the save must enforce belongs on the server too. | | **dependsOn** | `(string \| { field: string; param?: string })[]` | optional | Declares that this field's available values depend on the value of other field(s) on the same record — the form gates the field until they are set and re-evaluates as they change. For `lookup`/`master_detail` it scopes the candidate query (string = same local/remote key; `{field,param}` when the remote filter key differs — the `{field,param}` form is lookup-only). For `select`/`multiselect`/`radio` the actual per-option rule lives in each option's `visibleWhen`; list the referenced fields here (string form) so the option list gates and refreshes with the parent. | | **allowCreate** | `boolean` | optional | Allow inline quick-create from the record picker: when no match exists the user can create a record from the typed text (optimistic dataSource.create with the display field). Best for simple objects whose only required field is the display field. | | **lookupAutofill** | `{ target: string; source: string; overwrite?: boolean }[]` | optional | Fields a pick in this lookup fills on the record being edited: each `{ target, source }` pair copies the picked record's `source` field (a field of the `reference` object) into this object's `target` field — e.g. `[{ target: 'unit_price', source: 'list_price' }]` on a quote line's product lookup. Read wherever this field is picked: the record form, and a line-item grid column over it. OVERWRITE RULE — the default, `overwrite` absent or false: a pick never replaces a value somebody wrote. The target is filled only while it is empty or still holds the value an earlier pick filled in; a value the user typed, or one the record already stored, stays. Only a pair that declares `overwrite: true` replaces the target on every pick, whatever it holds. Client-side only: it fills the form, and nothing on the write path reads it — the filled value is saved as an ordinary write, and an import or API write that sets the lookup fills nothing. Only on a single-value `lookup` / `master_detail`. Each target is a field of this object other than this one, written by its author — not `readonly`, not computed (`formula`, `summary`, `autonumber`, or an `expression`) — and named once. Each source is a field of the referenced object that the record carries (not `internal`) and whose value the target can hold; `os validate` / `os build` judge the source. In a line-item grid the column key `autofill` still governs only the same-named copy and is unchanged; a declared pair takes its target out of that copy. | From 4fe8f01a373ccc488034c73d0c4f649fedf8328c Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 14:21:52 +0000 Subject: [PATCH 12/12] docs(changeset): say what the merged describes say about the picker The picker now resolves { $record } in a record form, so the last paragraph no longer says the marker stays on a picker half that does not resolve it. Claude-Session: https://claude.ai/code/session_01FEkQ5kgF3mo9f7LXuv5hac Co-Authored-By: Claude --- .changeset/34199-record-reference-refused-by-name.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/34199-record-reference-refused-by-name.md b/.changeset/34199-record-reference-refused-by-name.md index a43a16b8d68..1040fe68d16 100644 --- a/.changeset/34199-record-reference-refused-by-name.md +++ b/.changeset/34199-record-reference-refused-by-name.md @@ -16,4 +16,4 @@ A `lookupFilters` entry may read the record being edited as `{ $record: "field" - Now: that shape is refused by name before any driver is asked, on every engine verb and in the analytics service, whether or not the filter also holds a string placeholder. On the engine's object path the other five operators (`{ valid_from: { $lte: { $record: "…" } } }`) and the eq shorthand on a date, datetime or time column are still refused one door earlier, in that door's own words, as before. The engine lowers a `[field, op, value]` array `where` before the pass, so there the array spelling is judged as its object form; the analytics service hands the pass its `where` unlowered, and the pass leaves a tuple to the doors that judged it before. - Unchanged: a `{ $record }` deeper inside a comparand is a deep-equality literal (or a nested-relation condition) and passes through as before, in either spelling: the object form `{ attachment: { meta: { $record: "x" } } }`, which driver-memory still compares whole, and the tuple `['attachment', '=', { meta: { $record: "x" } }]`, whose third member is a comparand, never a filter node. Both come back from the pass by reference (pinned as CONTROLs on `resolveFilterTokens`). -The `lookupFilters` describes now say what holds on every path: an unresolved `{ $record }` is refused with `INVALID_FILTER`, never read as null, and by name on the eq shorthand of a column other than a date, datetime or time column. The `[PLANNED — not enforced]` marker stays on the picker half, which does not resolve `{ $record }` or read `orEmpty` yet. +The `value` and `lookupFilters` describes now say what holds on the server: an unresolved `{ $record }` is refused with `INVALID_FILTER`, never read as null, and, in `lookupFilters`, by name on the eq shorthand of a column other than a date, datetime or time column. Their picker sentences (a record form sends the referenced value; every other picker host leaves the entry out) are not changed by this entry.