Skip to content

Commit fdf882b

Browse files
committed
fix(lint): field-path rules resolve through the served object fold
Twelve field-path rules indexed declared objects only, and two rules folded objectExtensions through private readers that differed from the registry. All now read the one shared fold in object-graph.ts (objectsAsServed / objectExtensionsByTarget): a view, report, dataset, page or widget naming a field a sibling package adds through objectExtensions resolves as it does at runtime. Adds indexServedObjectGraph, the graph over objectsAsServed. Claude-Session: https://claude.ai/code/session_01WGufzg3UmwhpAtL969c7YG Co-authored-by: Claude <noreply@anthropic.com>
1 parent 7d7babb commit fdf882b

15 files changed

Lines changed: 100 additions & 81 deletions

‎packages/lint/src/object-graph.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,17 @@ export function objectsAsServed(stack: unknown): { objects: AnyRec[]; tied: Map<
500500
return { objects: served, tied };
501501
}
502502

503+
/**
504+
* [#30383] {@link indexObjectGraph} over {@link objectsAsServed}: the graph of
505+
* the objects the registry serves, every `objectExtensions` field folded in.
506+
* The field-path rules of this package resolve through it, so a path naming a
507+
* field a sibling package adds resolves as it does at runtime, and a field no
508+
* body declares or extends is still a miss.
509+
*/
510+
export function indexServedObjectGraph(stack: unknown): ObjectGraph {
511+
return indexObjectGraph({ objects: objectsAsServed(stack).objects });
512+
}
513+
503514
/** What a path resolved to, or precisely how it failed. */
504515
export type FieldPathVerdict =
505516
/**

‎packages/lint/src/validate-dataset-measure-aggregates.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ import { DATASET_DURATION_FIELD_TYPE } from '@objectstack/spec/ui';
222222

223223
import { collectionEntries } from './collection-entries.js';
224224
import {
225-
indexObjectGraph,
225+
indexServedObjectGraph,
226226
isUnjudgeable,
227227
recordsOf,
228228
resolveFieldPath,
@@ -651,7 +651,7 @@ export function validateDatasetMeasureAggregates(stack: unknown): DatasetMeasure
651651
const cubes = collectionEntries(stack.analyticsCubes, 'analyticsCubes');
652652
if (datasets.length === 0 && cubes.length === 0) return findings;
653653

654-
const graph: ObjectGraph = indexObjectGraph(stack);
654+
const graph: ObjectGraph = indexServedObjectGraph(stack);
655655

656656
datasets.forEach((ds, di) => {
657657
// ── Skip 1: no base object, or one the graph cannot answer for ──

‎packages/lint/src/validate-dataset-references.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
import { walkFilterFieldKeys } from './filter-walk.js';
120120
import {
121121
describeFieldPathVerdict,
122-
indexObjectGraph,
122+
indexServedObjectGraph,
123123
isUnjudgeable,
124124
joinablePrefixes,
125125
recordsOf,
@@ -182,7 +182,7 @@ export function validateDatasetReferences(stack: AnyRec): DatasetRefFinding[] {
182182
const datasets = recordsOf(stack.datasets);
183183
if (datasets.length === 0) return findings;
184184

185-
const graph: ObjectGraph = indexObjectGraph(stack);
185+
const graph: ObjectGraph = indexServedObjectGraph(stack);
186186

187187
datasets.forEach((ds, di) => {
188188
const dsName = strName(ds.name) ?? `#${di}`;

‎packages/lint/src/validate-field-consumers.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,10 @@
165165
* `controlled_by_parent` sharing, roll-ups and inline grids as its
166166
* readers; the relationship is consumed by being declared).
167167
* - **Object extensions** (`objectExtensions`) are not judged: the fields
168-
* they add belong to objects this stack does not own.
168+
* they add belong to objects this stack does not own. They are still
169+
* READ (#30383): a dataset or cube path is resolved over the objects as
170+
* served, so a hop through an extension-added relationship credits the
171+
* declared field it reaches.
169172
*
170173
* Severity is `warning` and stays so: a refusal would narrow the authorable
171174
* surface (today-valid metadata would start being refused), which is the
@@ -183,7 +186,7 @@ import type { DisplayNameObjectMeta } from '@objectstack/spec/data';
183186
import { referenceTargetOf } from '@objectstack/spec/data';
184187
import { collectionEntries } from './collection-entries.js';
185188
import {
186-
indexObjectGraph,
189+
indexServedObjectGraph,
187190
isUnjudgeable,
188191
joinablePrefixes,
189192
recordsOf,
@@ -1194,7 +1197,7 @@ function creditColumnPath(
11941197
* walk.
11951198
*/
11961199
function creditAnalyticsColumns(ledger: ConsumerLedger, stack: AnyRec): void {
1197-
const graph = indexObjectGraph(stack);
1200+
const graph = indexServedObjectGraph(stack);
11981201
for (const { rec: ds, path: dsPath } of collectionEntries(stack.datasets, 'datasets')) {
11991202
const object = strName(ds.object);
12001203
if (!object || !graph.get(object)) continue;

‎packages/lint/src/validate-list-view-field-refs.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ import {
428428
describeFieldPathVerdict,
429429
indexObjectGraph,
430430
isUnjudgeable,
431+
objectsAsServed,
431432
recordsOf,
432433
resolveFieldPath,
433434
suggestName,
@@ -959,7 +960,12 @@ export function validateListViewFieldRefs(
959960
const findings: ListViewFieldRefFinding[] = [];
960961
if (!isRec(stack)) return findings;
961962

962-
const graph: ObjectGraph = indexObjectGraph(stack);
963+
// [#30383] The objects as the registry serves them, every `objectExtensions`
964+
// field folded in: the graph and the option map below both read this, so a
965+
// column, filter key or `groupByField` naming a field a sibling package adds
966+
// resolves as it does at runtime.
967+
const served = objectsAsServed(stack).objects;
968+
const graph: ObjectGraph = indexObjectGraph({ objects: served });
963969
const scope = options?.packageScope;
964970
// [#24668] The whole collection, stated — and only without a closure, which
965971
// is the narrower set and wins.
@@ -1058,11 +1064,11 @@ export function validateListViewFieldRefs(
10581064

10591065
/**
10601066
* [#28018] The inline option values each object's fields declare, read from
1061-
* the same `stack.objects` the graph indexes. A field with no non-empty
1067+
* the same served objects the graph indexes. A field with no non-empty
10621068
* inline `options` array is absent: its lanes are not judged.
10631069
*/
10641070
const optionValues = new Map<string, Map<string, ReadonlySet<string>>>();
1065-
for (const obj of recordsOf(stack.objects)) {
1071+
for (const obj of served) {
10661072
const objName = strName(obj.name);
10671073
if (!objName) continue;
10681074
const byField = new Map<string, ReadonlySet<string>>();

‎packages/lint/src/validate-mapping-target-fields.ts‎

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@
5151
*
5252
* Fields an `objectExtensions[]` entry merges into the object (from this stack
5353
* or from a sibling package of the same artifact) ARE addressable at runtime,
54-
* because the registry merges every extension layer onto its target, so they
55-
* are folded into the object's field map before it is judged. Fields injected
54+
* because the registry merges every extension layer onto its target, so the
55+
* object is judged as served: through the package's one fold
56+
* (`objectsAsServed`, #30383), which keeps one entry per package per target
57+
* as the registry does. Fields injected
5658
* imperatively by plugin code are not metadata and no static rule can see
5759
* them; the import door, which reads the registered object, still judges them.
5860
*/
@@ -64,7 +66,7 @@ import {
6466
type ImportMappingTargetHead,
6567
} from '@objectstack/spec/data';
6668

67-
import { packagesOf, recordsOf, suggestName } from './object-graph.js';
69+
import { objectsAsServed, packagesOf, recordsOf, suggestName } from './object-graph.js';
6870

6971
/**
7072
* A `fieldMapping[].target` the mapping cannot write on its object: it names no
@@ -94,30 +96,6 @@ function strName(v: unknown): string | undefined {
9496
return typeof v === 'string' && v.length > 0 ? v : undefined;
9597
}
9698

97-
/**
98-
* Target object name → the field records every `objectExtensions[]` entry
99-
* aimed at it contributes, read from the stack in hand and from each
100-
* `packages[].manifest` body (the per-package leg of `os build` sees a
101-
* sibling's extension only there).
102-
*/
103-
function extensionFieldsByTarget(stack: AnyRec): Map<string, AnyRec[]> {
104-
const byTarget = new Map<string, AnyRec[]>();
105-
const add = (extensions: unknown) => {
106-
for (const extension of recordsOf(extensions)) {
107-
const target = strName(extension.extend);
108-
if (!target) continue;
109-
const fields = recordsOf(extension.fields);
110-
if (fields.length === 0) continue;
111-
byTarget.set(target, [...(byTarget.get(target) ?? []), ...fields]);
112-
}
113-
};
114-
add(stack.objectExtensions);
115-
for (const entry of packagesOf(stack)) {
116-
if (isRec(entry.manifest)) add(entry.manifest.objectExtensions);
117-
}
118-
return byTarget;
119-
}
120-
12199
/**
122100
* Report every import-mapping target its mapping cannot write on its object:
123101
* one that names no field and no declared part of a compound field, and a
@@ -130,23 +108,21 @@ export function validateMappingTargetFields(stack: AnyRec): MappingTargetFieldFi
130108
const mappings = recordsOf(stack.mappings);
131109
if (mappings.length === 0) return findings;
132110

111+
// A present non-array `packages` is still refused (ruling A on #15293): the
112+
// shared fold reads such a value as absent, so the refusal is asked here.
113+
packagesOf(stack);
133114
const objects = new Map<string, AnyRec>();
134-
for (const obj of recordsOf(stack.objects)) {
115+
for (const obj of objectsAsServed(stack).objects) {
135116
const n = strName(obj.name);
136117
if (n) objects.set(n, obj);
137118
}
138-
const extensionFields = extensionFieldsByTarget(stack);
139119

140120
for (let mi = 0; mi < mappings.length; mi++) {
141121
const mapping = mappings[mi];
142122
const objectName = strName(mapping.targetObject);
143123
if (!objectName) continue; // a missing targetObject is the schema's subject
144-
const declared = objects.get(objectName);
145-
if (!declared) continue; // skip 1
146-
const extra = extensionFields.get(objectName);
147-
const objectDef: AnyRec = extra
148-
? { ...declared, fields: [...recordsOf(declared.fields), ...extra] }
149-
: declared;
124+
const objectDef = objects.get(objectName);
125+
if (!objectDef) continue; // skip 1
150126

151127
const misses = unknownImportMappingTargets(mapping.fieldMapping, objectDef);
152128
if (misses.length === 0) continue; // clean, or skip 2

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@
211211

212212
import {
213213
describeFieldPathVerdict,
214-
indexObjectGraph,
214+
indexServedObjectGraph,
215215
isUnjudgeable,
216216
recordsOf,
217217
resolveFieldPath,
@@ -466,7 +466,7 @@ export function validateObjectFieldRefs(stack: AnyRec): ObjectFieldRefFinding[]
466466
const findings: ObjectFieldRefFinding[] = [];
467467
if (!isRec(stack)) return findings;
468468

469-
const graph: ObjectGraph = indexObjectGraph(stack);
469+
const graph: ObjectGraph = indexServedObjectGraph(stack);
470470
if (graph.size === 0) return findings;
471471

472472
/**

‎packages/lint/src/validate-page-field-bindings.ts‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ import {
125125
sectionGroupRefs,
126126
type SectionGroupRef,
127127
} from './object-field-groups.js';
128-
import { indexObjectGraph, recordsOf, resolveFieldPath, suggestName, type ObjectGraph } from './object-graph.js';
128+
import { indexObjectGraph, objectsAsServed, recordsOf, resolveFieldPath, suggestName, type ObjectGraph } from './object-graph.js';
129129
// [#23013] The one answer to "does this field hold several values?" — the
130130
// predicate storage, the aggregate answer and the generator already ask.
131131
import { isMultiValueField } from '@objectstack/spec/data';
@@ -604,17 +604,20 @@ export function validatePageFieldBindings(stack: AnyRec): PageFieldFinding[] {
604604
const findings: PageFieldFinding[] = [];
605605
if (!stack || typeof stack !== 'object') return findings;
606606

607-
// object name → its declared field names. Built with `recordsOf` so BOTH
608-
// `fields` shapes (array of `{name}` and name-keyed map) resolve.
609-
const objectFields = indexObjectFields(stack);
607+
// object name → its field names. Built with `recordsOf` so BOTH `fields`
608+
// shapes (array of `{name}` and name-keyed map) resolve. [#30383] Over the
609+
// objects as served, every `objectExtensions` field folded in, as the graph
610+
// below: a binding naming a field a sibling package adds is served.
611+
const served = { objects: objectsAsServed(stack).objects };
612+
const objectFields = indexObjectFields(served);
610613
// [#8340] The provenance index alongside the existence one — same keying,
611614
// asked on the path where the existence check stays silent.
612615
const unprovisionedAnchors = indexUnprovisionedAnchors(stack);
613616
// [#13855] object name → its declared field-group keys, for `section.group`.
614617
const objectFieldGroups = indexObjectFieldGroups(stack);
615618
// [#23013] Field DEFINITIONS (type, `multiple`), for the one question a
616619
// name index cannot answer: is a counted field multi-valued?
617-
const objectGraph = indexObjectGraph(stack);
620+
const objectGraph = indexObjectGraph(served);
618621

619622
const pages = recordsOf(stack.pages);
620623
for (let pi = 0; pi < pages.length; pi++) {

‎packages/lint/src/validate-preset-comparands.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
import { normalizeFilterOperator } from '@objectstack/spec/ui';
1212

1313
import { filterGroupRules, walkAuthoredFilters, type FilterSurface } from './filter-walk.js';
14-
import { indexObjectGraph, recordsOf, resolveFieldPath, type ObjectGraph } from './object-graph.js';
14+
import { indexServedObjectGraph, recordsOf, resolveFieldPath, type ObjectGraph } from './object-graph.js';
1515

1616
/**
1717
* Build-time refusal of a bare dashboard date-range PRESET name authored as a
@@ -743,7 +743,7 @@ export function validatePresetComparands(
743743
if (!stack || typeof stack !== 'object') return [];
744744
const out: PresetComparandFinding[] = [];
745745

746-
const graph = indexObjectGraph(stack);
746+
const graph = indexServedObjectGraph(stack);
747747
const datasets = new Map<string, AnyRec>();
748748
for (const dataset of recordsOf(stack.datasets)) {
749749
const name = strName(dataset.name);

‎packages/lint/src/validate-related-list-refs.ts‎

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@
2323
*
2424
* ## Which children are judged — the universe the caller hands over
2525
*
26-
* The children are the stack's `objects` (map or array form) with the fields
27-
* their `objectExtensions` add merged in by name, since an extension can be
28-
* the one that adds the FK.
26+
* The children are the stack's `objects` (map or array form) as the registry
27+
* serves them, since an extension can be the one that adds the FK: every
28+
* `objectExtensions` field folded in through the package's one fold
29+
* (`objectsAsServed`, #30383), and a child only an extension reaches (another
30+
* package's object) carrying its extensions' fields alone. A field record is
31+
* read by name in either `fields` shape.
2932
*
3033
* - A named child that IS in the stack but carries no such FK is refused on
3134
* every surface: that child's fields are known.
@@ -58,7 +61,7 @@
5861
*/
5962

6063
import { fieldGroupBodyTableRefusal, type NamedInboundRelationship } from '@objectstack/spec/data';
61-
import { recordsOf } from './object-graph.js';
64+
import { objectExtensionsByTarget, objectsAsServed, recordsOf } from './object-graph.js';
6265

6366
/** A related-list entry that matches no inbound relationship of its object. */
6467
export const RELATED_LIST_REF_UNKNOWN = 'related-list-ref-unknown';
@@ -123,22 +126,26 @@ export function validateRelatedListRefs(stack: AnyRec, options?: RelatedListRefO
123126
const objects = recordsOf(stack.objects);
124127
if (objects.length === 0) return findings;
125128

126-
// Child object name → its fields (declaration and extensions merged by name).
127-
const fieldsByObject = new Map<string, AnyRec>();
128-
for (const obj of objects) {
129-
if (typeof obj.name !== 'string') continue;
130-
fieldsByObject.set(obj.name, { ...fieldsByObject.get(obj.name), ...(isRec(obj.fields) ? obj.fields : {}) });
129+
// Child object name → its fields by name, as served (see the header).
130+
const fieldsByObject = new Map<string, Map<string, AnyRec>>();
131+
const merge = (child: string, fields: AnyRec[]): void => {
132+
const byName = fieldsByObject.get(child) ?? new Map<string, AnyRec>();
133+
for (const f of fields) if (typeof f.name === 'string') byName.set(f.name, f);
134+
fieldsByObject.set(child, byName);
135+
};
136+
for (const obj of objectsAsServed(stack).objects) {
137+
if (typeof obj.name === 'string') merge(obj.name, recordsOf(obj.fields));
131138
}
132-
for (const ext of recordsOf(stack.objectExtensions)) {
133-
if (typeof ext.extend !== 'string') continue;
134-
fieldsByObject.set(ext.extend, { ...fieldsByObject.get(ext.extend), ...(isRec(ext.fields) ? ext.fields : {}) });
139+
for (const [target, extensions] of objectExtensionsByTarget(stack)) {
140+
if (fieldsByObject.has(target)) continue; // folded in above
141+
for (const ext of extensions) merge(target, ext.fields);
135142
}
136143

137144
// Parent name → its inbound relationships, in child then field order.
138145
const inbound = new Map<string, NamedInboundRelationship[]>();
139146
for (const [child, fields] of fieldsByObject) {
140-
for (const [field, def] of Object.entries(fields)) {
141-
if (!isRec(def) || (def.type !== 'lookup' && def.type !== 'master_detail')) continue;
147+
for (const [field, def] of fields) {
148+
if (def.type !== 'lookup' && def.type !== 'master_detail') continue;
142149
if (typeof def.reference !== 'string' || AUDIT_FKS.has(field)) continue;
143150
const list = inbound.get(def.reference) ?? [];
144151
list.push({ child, field, def });

0 commit comments

Comments
 (0)