Skip to content

Commit e152cee

Browse files
committed
Merge the predecessor branch claude/project-thread-l4gpcv onto main
Claude-Session: https://claude.ai/code/session_01ADHkmR92m7ZN6cUVQTj1VE Co-authored-by: Claude <noreply@anthropic.com>
2 parents 0e2e4f5 + 3781dec commit e152cee

6 files changed

Lines changed: 216 additions & 6 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
'@objectstack/lint': minor
3+
'@objectstack/spec': minor
4+
---
5+
6+
feat(lint)!: a `lookupFilters` `{ $record: "path" }` path through or to a multi-valued field is refused
7+
8+
Clause-②: no (narrowing) — a `lookupFilters[].value` `{ $record }` path on a lookup, master_detail or user field whose first segment is a multi-valued field of the object owning that field (a plain path to it, or a hop through it), or whose leaf behind a single-valued hop is a multi-valued field, linted clean and published; it is now refused at error as `object-field-ref-unknown` by `os lint`, `os validate`, `os build` and the runtime publish door, and reported (never refused) on the package publish receipt's object probe.
9+
Metadata-protocol: narrowed
10+
Skills-docs: follow-up #34201 — no doc or skill teaches `{ $record }` yet, so there is no teaching to correct here; the multi-valued clause rides the describes this change edits.
11+
12+
<!-- adr-0087: registered lookup-filter-record-path-multi-valued-refused -->
13+
14+
**BREAKING** only for a `{ $record }` path that reads a list. A `{ $record }` comparand stands for ONE value of the record being edited and pairs only with `eq`, `ne`, `gt`, `lt`, `gte` or `lte`, but the path check judged only that each segment names a field, so `{ $record: "accounts.cb_market" }` through a `multiple: true` lookup, or `{ $record: "tags" }`, linted clean. A hop through a multi-valued lookup reaches no single row, so the entry was left out without a word; a plain path to a multi-valued field put a list where one value goes. `object-field-ref-unknown` now refuses the path at the multi-valued field and names it. Multi-valued means `isMultiValueField`: a field flagged `multiple: true`, or a `multiselect`, `checkboxes` or `tags` field. A registry-injected column and a leaf on an object outside the stack are not judged. Measured first-party exposure: zero — no example app, platform object, skill or docs sample writes a `$record` path.
15+
16+
**FROM → TO.** FROM `{ $record: "accounts.cb_market" }` (a hop through a `multiple: true` lookup), `{ $record: "tags" }` or `{ $record: "account.markets" }` (a multi-valued leaf) TO a path that ends at, and hops through, single-valued fields only.
17+
18+
**Fix:** copy the value you mean onto a single-valued field of the record being edited (or of the record one single-valued hop away) and reference that. The semantic entry `lookup-filter-record-path-multi-valued-refused` carries the same notice into the upgrade guide and `os migrate meta`. `os explain object-field-ref-unknown` lists the position.

‎packages/lint/src/rule-explanations.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4499,7 +4499,10 @@ const OBJECT_FIELD_REF_UNKNOWN_EXPLANATION: RuleExplanation = {
44994499
'an entry out while the value is empty, so a path the record does not have would drop the filter ' +
45004500
'without a word. A miss names the segment: an unknown head, ' +
45014501
'a hop through a field that is not a relationship, a leaf the referenced object lacks, or a ' +
4502-
'second hop. A `$record` nested inside a literal value is not a reference and is not judged.',
4502+
'second hop. A path that names real fields is refused too when it reads a list: a path through or ' +
4503+
'to a multi-valued field (one flagged `multiple: true`, or a `multiselect`, `checkboxes` or `tags` ' +
4504+
'field), or a multi-valued leaf behind one hop, because the comparand is one ' +
4505+
'value under a scalar operator. A `$record` nested inside a literal value is not a reference and is not judged.',
45034506
'A summary field\'s `summaryOperations.filter` is judged against the CHILD object ' +
45044507
'`summaryOperations.object` names: the engine ANDs it with the parent-FK match and runs it as the ' +
45054508
'query on that child, so every key (inside `$and` / `$or` / `$not` groups) is a field of the child. ' +

‎packages/lint/src/validate-object-field-refs.test.ts‎

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,7 @@ describe('validateObjectFieldRefs — lookupFilters[].value.$record (the RECORD
731731
name: { type: 'text' },
732732
cb_market: { type: 'select' },
733733
parent: { type: 'lookup', reference: 'crm_account' },
734+
markets: { type: 'multiselect' },
734735
},
735736
},
736737
{
@@ -855,6 +856,79 @@ describe('validateObjectFieldRefs — lookupFilters[].value.$record (the RECORD
855856
}));
856857
expect(findings.map((f) => f.path)).toEqual(['objects[0].fields.approver.lookupFilters[0].value.$record']);
857858
});
859+
860+
// [#34378] A path that names real fields can still read a LIST. The
861+
// comparand is one value under a scalar operator, so a multi-valued head
862+
// (a plain path to it, or a hop through it) or a multi-valued leaf behind a
863+
// single-valued hop is refused — by `isMultiValueField`, `FieldSchema`'s own
864+
// predicate: an inherently multi type, or `multiple: true` on a
865+
// multi-capable one.
866+
describe('a path through or to a multi-valued field (#34378)', () => {
867+
const multi = {
868+
tags: { type: 'tags' },
869+
regions: { type: 'select', multiple: true },
870+
stage: { type: 'select', multiple: false },
871+
accounts: { type: 'lookup', reference: 'crm_account', multiple: true },
872+
partners: { type: 'lookup', reference: 'elsewhere_partner', multiple: true },
873+
watchers: { type: 'user', multiple: true },
874+
};
875+
const refused = (path: string) => {
876+
const findings = validateObjectFieldRefs(quote([entry(path)], multi));
877+
expect(findings.map((f) => f.path)).toEqual([at(0)]);
878+
expect(findings[0]).toMatchObject({ severity: 'error', rule: OBJECT_FIELD_REF_UNKNOWN });
879+
expect(findings[0]!.hint).toContain('Point `$record` at a single-valued field');
880+
return findings[0]!.message;
881+
};
882+
883+
it('REFUSES a plain path to an inherently multi-valued field (`tags`)', () => {
884+
expect(refused('tags')).toBe(
885+
'fields.price_book.lookupFilters[0].value.$record "tags" names "tags", a multi-valued field on object '
886+
+ '"sales_quote"; a $record comparand is one value under a scalar operator.',
887+
);
888+
});
889+
890+
it('REFUSES a plain path to a `multiple: true` select', () => {
891+
expect(refused('regions')).toContain('names "regions", a multi-valued field on object "sales_quote"');
892+
});
893+
894+
it('REFUSES a hop through a `multiple: true` lookup, at the hop', () => {
895+
expect(refused('accounts.cb_market')).toBe(
896+
'fields.price_book.lookupFilters[0].value.$record "accounts.cb_market" goes through "accounts", a '
897+
+ 'multi-valued field on object "sales_quote"; a $record comparand is one value under a scalar operator.',
898+
);
899+
});
900+
901+
it('REFUSES a hop through a `multiple: true` user field, its target unjudged past the hop', () => {
902+
expect(refused('watchers.department')).toContain('goes through "watchers", a multi-valued field');
903+
});
904+
905+
it('REFUSES a hop through a multi-valued lookup to an object outside the stack: the head is this object\'s', () => {
906+
expect(refused('partners.anything')).toContain('goes through "partners", a multi-valued field');
907+
});
908+
909+
it('REFUSES a multi-valued leaf behind a single-valued hop, naming the leaf and its object', () => {
910+
expect(refused('account.markets')).toBe(
911+
'fields.price_book.lookupFilters[0].value.$record "account.markets" ends at "markets", a multi-valued '
912+
+ 'field on object "crm_account"; a $record comparand is one value under a scalar operator.',
913+
);
914+
});
915+
916+
it('reports a misspelt leaf behind a multi-valued hop once, as the miss', () => {
917+
const findings = validateObjectFieldRefs(quote([entry('accounts.cb_markt')], multi));
918+
expect(findings.map((f) => f.path)).toEqual([at(0)]);
919+
expect(findings[0]!.message).toContain('"accounts.cb_markt" is not a field on object "crm_account"');
920+
});
921+
922+
it('passes single-valued paths: a plain field, a single lookup, a hop, a `multiple: false` select', () => {
923+
expect(validateObjectFieldRefs(quote([
924+
{ field: 'valid_from', operator: 'lte', value: { $record: 'quote_date' } },
925+
entry('account', 'cb_market'),
926+
entry('account.cb_market'),
927+
entry('stage'),
928+
entry('account.created_at', 'valid_to'),
929+
], multi))).toEqual([]);
930+
});
931+
});
858932
});
859933

860934
describe('validateObjectFieldRefs — summaryOperations.filter (addresses the CHILD object, #31224)', () => {
@@ -1184,6 +1258,7 @@ describe('[#22161] one-line verdicts — object-field-ref-unknown', () => {
11841258
'`lookupColumns` and `lookupFilters[].field` against the REFERENCED object',
11851259
'`lookupFilters[].value.$record`',
11861260
'at most one relationship hop',
1261+
'a path through or to a multi-valued field',
11871262
'`lookup`, `master_detail` and `user`',
11881263
'reported once, there',
11891264
'read verbatim',

‎packages/lint/src/validate-object-field-refs.ts‎

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,14 @@
113113
* types alone, the picker being its only reader. A path of two hops is
114114
* refused at the second hop on the raw `os lint` path the parse has not
115115
* seen; a hop's leaf on an object outside this stack stays unjudged, as
116-
* every cross-package name in this family does. A `{ $record }` nested
116+
* every cross-package name in this family does. A path through or to a
117+
* MULTI-VALUED field (#34378) — a hop through a `multiple: true` lookup
118+
* (`accounts.cb_market`), a plain path to one (`tags`), or a leaf that is
119+
* one behind a single-valued hop — is refused too: the comparand is ONE
120+
* value under a scalar operator, and a list has no such value. The
121+
* predicate is `isMultiValueField` (`@objectstack/spec/data`), the one
122+
* `FieldSchema` reads. A registry-injected column, and a leaf on an object
123+
* outside this stack, stay unjudged. A `{ $record }` nested
117124
* deeper inside a literal (`value: { any: { $record: 'x' } }`) is an
118125
* opaque literal to the parse, and this rule does not name it either: no
119126
* reader resolves that shape, nothing first-party writes it, and the
@@ -286,9 +293,10 @@ import {
286293
recordsOf,
287294
resolveFieldPath,
288295
type FieldPathVerdict,
296+
type GraphField,
289297
type ObjectGraph,
290298
} from './object-graph.js';
291-
import { classifyDottedFilterHead, isVirtualSearchField } from '@objectstack/spec/data';
299+
import { classifyDottedFilterHead, isMultiValueField, isVirtualSearchField } from '@objectstack/spec/data';
292300

293301
/**
294302
* A field-name list entry — object-level, or on one of the object's fields —
@@ -478,6 +486,18 @@ interface FieldNameSlot {
478486
* different objects.
479487
*/
480488
ownFinding?: boolean;
489+
/**
490+
* [#34378] `true` when the path must read ONE value: its first segment and,
491+
* behind a hop, its leaf may not be multi-valued (`isMultiValueField`). A
492+
* path whose head is multi-valued is refused whether it ends there or hops
493+
* through it, at the head; a multi-valued leaf behind a single-valued hop is
494+
* refused at the leaf. Judged only on a path the family's resolution did
495+
* not already refuse, and only on AUTHORED fields: a registry-injected
496+
* column, or a leaf on an object outside the stack, stays unjudged.
497+
*/
498+
singleValued?: boolean;
499+
/** [#34378] The hint when {@link singleValued} refuses a path. */
500+
singleValuedPrescription?: string;
481501
}
482502

483503
function nameOf(v: unknown): string | undefined {
@@ -551,10 +571,14 @@ const FIELD_NAME_SLOTS: readonly FieldNameSlot[] = [
551571
pickerOnly: true,
552572
maxHops: 1,
553573
ownFinding: true,
574+
singleValued: true,
554575
read: readRecordReference,
555576
prescription:
556577
'Fix the path — `$record` reads the record being edited: a field of this object, or one '
557578
+ 'relationship field of it and then a field of the object it references (`account.cb_market`).',
579+
singleValuedPrescription:
580+
'Point `$record` at a single-valued field: a multi-valued field holds a list, and no scalar comparison '
581+
+ 'takes one. Copy the value you mean onto a single-valued field and reference that.',
558582
},
559583
{
560584
key: 'dependsOn',
@@ -675,6 +699,29 @@ export function validateObjectFieldRefs(stack: AnyRec): ObjectFieldRefFinding[]
675699
findings.push({ severity: 'error', rule: OBJECT_FIELD_REF_UNKNOWN, where: at.where, path: at.path, message, hint });
676700
};
677701

702+
/**
703+
* [#34378] Where a path that resolved stops reading ONE value: its AUTHORED
704+
* first segment on `objectName` when that is multi-valued (a plain path to
705+
* it, or a hop through it), else — behind a single-valued hop — its
706+
* authored leaf when that is. `undefined` = single-valued, or not
707+
* judgeable here (a registry-injected column, an object outside the stack).
708+
*/
709+
const multiValuedSegment = (
710+
objectName: string,
711+
segments: readonly string[],
712+
): { how: string; field: string; object: string } | undefined => {
713+
const isMulti = (m: GraphField | undefined): boolean =>
714+
typeof m?.type === 'string' && isMultiValueField({ type: m.type, multiple: m.multiple === true });
715+
const head = graph.get(objectName)?.fields.get(segments[0]!);
716+
if (isMulti(head)) {
717+
return { how: segments.length > 1 ? 'goes through' : 'names', field: segments[0]!, object: objectName };
718+
}
719+
if (segments.length < 2) return undefined;
720+
const verdict = resolveFieldPath(graph, objectName, segments.join('.'));
721+
if (verdict?.kind !== 'ok' || verdict.injected || !isMulti(verdict.meta)) return undefined;
722+
return { how: 'ends at', field: verdict.field, object: verdict.object };
723+
};
724+
678725
/** The declared slice of `name` on `objectName` — authored, else registry-injected. */
679726
const fieldOf = (objectName: string, name: string) => {
680727
const o = graph.get(objectName);
@@ -975,6 +1022,21 @@ export function validateObjectFieldRefs(stack: AnyRec): ObjectFieldRefFinding[]
9751022
prescription: slot.prescription,
9761023
});
9771024
if (hit && !slot.ownFinding) reported.add(`${at}=${read.name}`);
1025+
1026+
// [#34378] A path that names real fields can still read a LIST: a
1027+
// multi-valued head, or a multi-valued leaf behind one hop. The
1028+
// comparand is one value under a scalar operator, so it is refused.
1029+
if (!hit && slot.singleValued) {
1030+
const multi = multiValuedSegment(against, segments);
1031+
if (multi) {
1032+
refuseKey(
1033+
{ where, path },
1034+
`${subject} "${read.name}" ${multi.how} "${multi.field}", a multi-valued field on object `
1035+
+ `"${multi.object}"; a $record comparand is one value under a scalar operator.`,
1036+
slot.singleValuedPrescription ?? slot.prescription,
1037+
);
1038+
}
1039+
}
9781040
});
9791041
}
9801042

‎packages/spec/src/data/field.zod.ts‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,6 +1315,12 @@ const LOOKUP_FILTER_RECORD_PATH_RE = /^[a-z_][a-z0-9_]*(?:\.[a-z_][a-z0-9_]*)?$/
13151315
* - **Path.** A field of the edited record (`quote_date`), or ONE lookup hop
13161316
* from it (`account.cb_market`: the `account` lookup on the edited record,
13171317
* then `cb_market` on the account it points at). Two hops are refused.
1318+
* [#34378] A path through or to a MULTI-VALUED field (`isMultiValueField`:
1319+
* one flagged `multiple: true`, or a multiselect, checkboxes or tags field)
1320+
* has no single value — `accounts.cb_market` through a `multiple: true`
1321+
* lookup, `tags`, or `account.markets` ending at one — so it is not resolved,
1322+
* and `os lint` refuses it (`object-field-ref-unknown`). The picker's
1323+
* handling of such a path is #34389.
13181324
* - **Operator.** Only the six scalar comparisons
13191325
* ({@link LOOKUP_FILTER_SCALAR_COMPARISONS}), and the reference is the whole
13201326
* value: never a member of an `in` / `notIn` list.
@@ -1361,7 +1367,9 @@ export const LookupFilterRecordReferenceSchema = lazySchema(() => strictObject({
13611367
}).describe('Path of the value on the record being edited: a field name (`quote_date`) or one lookup hop (`account.cb_market`) — at most one dot.'),
13621368
})).describe(
13631369
'A lookupFilters comparand read from the record being edited: { $record: "field" } or { $record: "lookup_field.field" } (at most one lookup hop). '
1364-
+ 'The picker replaces it with that value before querying; unlike { $field }, which names a column of the candidate row.',
1370+
+ 'The picker replaces it with that value before querying; unlike { $field }, which names a column of the candidate row. '
1371+
+ 'A path through or to a multi-valued field (one flagged `multiple: true`, or a multiselect, checkboxes or tags field) '
1372+
+ 'has no single value: it is not resolved, and lint refuses it (`object-field-ref-unknown`).',
13651373
);
13661374

13671375
export type LookupFilterRecordReference = z.input<typeof LookupFilterRecordReferenceSchema>;
@@ -2262,8 +2270,10 @@ export const FieldSchema = lazySchema(() => {
22622270
+ '{ $now: true, addDays } comparand for a date relative to today, or a { $record: "path" } reference to the '
22632271
+ 'record being edited — a field of it, or one lookup hop ("account.cb_market"); a { $record } value pairs '
22642272
+ 'only with eq, ne, gt, lt, gte or lte. In a record form, whatever its layout, the picker sends the referenced '
2265-
+ 'value in place of the reference; every other picker host leaves the entry out. A { $record } that reaches a '
2266-
+ 'server unresolved is refused (INVALID_FILTER), never read as null.',
2273+
+ 'value in place of the reference; every other picker host leaves the entry out. A { $record } path through or '
2274+
+ 'to a multi-valued field (one flagged `multiple: true`, or a multiselect, checkboxes or tags field) has no '
2275+
+ 'single value: it is not resolved, and lint refuses it (`object-field-ref-unknown`). A { $record } that '
2276+
+ 'reaches a server unresolved is refused (INVALID_FILTER), never read as null.',
22672277
),
22682278
orEmpty: z.boolean().optional().describe(
22692279
'TRUE: the entry also matches a candidate whose column is null — "valid from the quote date, or with no '

0 commit comments

Comments
 (0)