|
119 | 119 | * one behind a single-valued hop — is refused too: the comparand is ONE |
120 | 120 | * value under a scalar operator, and a list has no such value. The |
121 | 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 |
| 122 | + * `FieldSchema` reads. A plain path to, or a leaf behind a hop at, a |
| 123 | + * STRUCTURED field (#34562) — a member of `STRUCTURED_JSON_TYPES` |
| 124 | + * (`@objectstack/spec/data`): json, address, location, … — is refused the |
| 125 | + * same way, with the same hint: it holds a list or an object rather than |
| 126 | + * one value. A |
| 127 | + * registry-injected column, and a leaf on an object outside this stack, |
| 128 | + * stay unjudged. A `{ $record }` nested |
124 | 129 | * deeper inside a literal (`value: { any: { $record: 'x' } }`) is an |
125 | 130 | * opaque literal to the parse, and this rule does not name it either: no |
126 | 131 | * reader resolves that shape, nothing first-party writes it, and the |
@@ -302,7 +307,12 @@ import { |
302 | 307 | type GraphField, |
303 | 308 | type ObjectGraph, |
304 | 309 | } from './object-graph.js'; |
305 | | -import { classifyDottedFilterHead, isMultiValueField, isVirtualSearchField } from '@objectstack/spec/data'; |
| 310 | +import { |
| 311 | + classifyDottedFilterHead, |
| 312 | + isMultiValueField, |
| 313 | + isVirtualSearchField, |
| 314 | + STRUCTURED_JSON_TYPES, |
| 315 | +} from '@objectstack/spec/data'; |
306 | 316 |
|
307 | 317 | /** |
308 | 318 | * A field-name list entry — object-level, or on one of the object's fields — |
@@ -494,7 +504,8 @@ interface FieldNameSlot { |
494 | 504 | ownFinding?: boolean; |
495 | 505 | /** |
496 | 506 | * [#34378] `true` when the path must read ONE value: its first segment and, |
497 | | - * behind a hop, its leaf may not be multi-valued (`isMultiValueField`). A |
| 507 | + * behind a hop, its leaf may not be multi-valued (`isMultiValueField`) or |
| 508 | + * structured (`STRUCTURED_JSON_TYPES`, #34562). A |
498 | 509 | * path whose head is multi-valued is refused whether it ends there or hops |
499 | 510 | * through it, at the head; a multi-valued leaf behind a single-valued hop is |
500 | 511 | * refused at the leaf. Judged only on a path the family's resolution did |
@@ -727,23 +738,38 @@ export function validateObjectFieldRefs(stack: AnyRec): ObjectFieldRefFinding[] |
727 | 738 | * [#34378] Where a path that resolved stops reading ONE value: its AUTHORED |
728 | 739 | * first segment on `objectName` when that is multi-valued (a plain path to |
729 | 740 | * it, or a hop through it), else — behind a single-valued hop — its |
730 | | - * authored leaf when that is. `undefined` = single-valued, or not |
731 | | - * judgeable here (a registry-injected column, an object outside the stack). |
| 741 | + * authored leaf when that is. A STRUCTURED field (#34562: a member of |
| 742 | + * `STRUCTURED_JSON_TYPES`, `@objectstack/spec/data` — json, address, |
| 743 | + * location, …) holds a list or an object rather than one value, so it has |
| 744 | + * no scalar value either and is |
| 745 | + * named at the same two positions. `what` is the finding's noun for the |
| 746 | + * field. `undefined` = one scalar value, or not judgeable here (a |
| 747 | + * registry-injected column, an object outside the stack). |
732 | 748 | */ |
733 | 749 | const multiValuedSegment = ( |
734 | 750 | objectName: string, |
735 | 751 | segments: readonly string[], |
736 | | - ): { how: string; field: string; object: string } | undefined => { |
737 | | - const isMulti = (m: GraphField | undefined): boolean => |
738 | | - typeof m?.type === 'string' && isMultiValueField({ type: m.type, multiple: m.multiple === true }); |
| 752 | + ): { how: string; field: string; object: string; what: string } | undefined => { |
| 753 | + const nonScalar = (m: GraphField | undefined): string | undefined => { |
| 754 | + if (typeof m?.type !== 'string') return undefined; |
| 755 | + if (isMultiValueField({ type: m.type, multiple: m.multiple === true })) return 'a multi-valued field'; |
| 756 | + return STRUCTURED_JSON_TYPES.has(m.type) ? 'a structured field' : undefined; |
| 757 | + }; |
739 | 758 | const head = graph.get(objectName)?.fields.get(segments[0]!); |
740 | | - if (isMulti(head)) { |
741 | | - return { how: segments.length > 1 ? 'goes through' : 'names', field: segments[0]!, object: objectName }; |
| 759 | + const headWhat = nonScalar(head); |
| 760 | + if (headWhat) { |
| 761 | + return { |
| 762 | + how: segments.length > 1 ? 'goes through' : 'names', |
| 763 | + field: segments[0]!, |
| 764 | + object: objectName, |
| 765 | + what: headWhat, |
| 766 | + }; |
742 | 767 | } |
743 | 768 | if (segments.length < 2) return undefined; |
744 | 769 | const verdict = resolveFieldPath(graph, objectName, segments.join('.')); |
745 | | - if (verdict?.kind !== 'ok' || verdict.injected || !isMulti(verdict.meta)) return undefined; |
746 | | - return { how: 'ends at', field: verdict.field, object: verdict.object }; |
| 770 | + if (verdict?.kind !== 'ok' || verdict.injected) return undefined; |
| 771 | + const leafWhat = nonScalar(verdict.meta); |
| 772 | + return leafWhat ? { how: 'ends at', field: verdict.field, object: verdict.object, what: leafWhat } : undefined; |
747 | 773 | }; |
748 | 774 |
|
749 | 775 | /** The declared slice of `name` on `objectName` — authored, else registry-injected. */ |
@@ -1063,14 +1089,15 @@ export function validateObjectFieldRefs(stack: AnyRec): ObjectFieldRefFinding[] |
1063 | 1089 | } |
1064 | 1090 |
|
1065 | 1091 | // [#34378] A path that names real fields can still read a LIST: a |
1066 | | - // multi-valued head, or a multi-valued leaf behind one hop. The |
1067 | | - // comparand is one value under a scalar operator, so it is refused. |
| 1092 | + // multi-valued head, or a multi-valued leaf behind one hop — or |
| 1093 | + // (#34562) an OBJECT: a structured head or leaf. The comparand is |
| 1094 | + // one value under a scalar operator, so it is refused. |
1068 | 1095 | if (!hit && slot.singleValued) { |
1069 | 1096 | const multi = multiValuedSegment(against, segments); |
1070 | 1097 | if (multi) { |
1071 | 1098 | refuseKey( |
1072 | 1099 | { where, path }, |
1073 | | - `${subject} "${read.name}" ${multi.how} "${multi.field}", a multi-valued field on object ` |
| 1100 | + `${subject} "${read.name}" ${multi.how} "${multi.field}", ${multi.what} on object ` |
1074 | 1101 | + `"${multi.object}"; a $record comparand is one value under a scalar operator.`, |
1075 | 1102 | slot.singleValuedPrescription ?? slot.prescription, |
1076 | 1103 | ); |
|
0 commit comments