Skip to content

Commit f4cc54a

Browse files
committed
fix(lint): field-name indexes read the objects as served, pins and changeset
Claude-Session: https://claude.ai/code/session_01WGufzft7TrxiryiTZm4o9p Co-authored-by: Claude <noreply@anthropic.com>
1 parent 82de298 commit f4cc54a

3 files changed

Lines changed: 27 additions & 13 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
'@objectstack/lint': patch
3+
---
4+
5+
fix(lint): the field-name indexes judge an object as the registry serves it, so a formula, validation, flow, hook, sharing-rule condition, flow node write, action or hook body write, react page prop or translation key naming a field that an `objectExtensions` entry adds is no longer refused (#30471)
6+
7+
Clause-②: yes (widening: field-name reads accept fields a sibling package adds through `objectExtensions`, which the runtime already serves; any site that deliberately stays on declared fields says why)
8+
Metadata-protocol: none (lint judgements, no authorable key)
9+
10+
- **Before.** The `record.FIELD` index of the expression passes (validation rules, formulas, flow conditions, hooks, sharing-rule conditions), the field index of the three write rules (`flow-node-write-unknown-field`, `action-body-write-unknown-field`, `hook-body-write-unknown-field`) and a react page's field props read an object's declared `fields` only. On a multi-package artifact, where a module package adds fields to an app package's object through `objectExtensions`, a read or write naming one of those fields was refused as unknown although the runtime serves the field. The translation rule folded extensions through a reader of its own that kept every entry and read the top level beside `packages[]`.
11+
- **Now.** They read the one shared fold in `object-graph.ts`, as the field-path rules do since #30383: the declared fields plus every field an `objectExtensions` entry of any body adds, one entry per package per object. A field no body declares or adds keeps the same refusal, with the same rule id, severity and message. A field two packages write at the same deciding priority is a served name, but the expression passes judge neither its type nor whether it is nullable, since which definition wins is registration order. The write rules still leave an object that declares no field unjudged. The translation rule now keeps one entry per package per object too, so a key naming a field or rule only a replaced earlier entry of the same package adds is an orphan, as the registry serves it.

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -926,21 +926,24 @@ describe('[#30471] the field-name indexes read the objects as served', () => {
926926
});
927927

928928
// A field two packages write at the deciding priority: its name is served,
929-
// its definition is registration order. The expression type check leaves it
930-
// untyped; each pair lists last the definition the check would refuse.
931-
it('validate-expressions: a field two packages tie on is a served name with no type', () => {
932-
const tie = (a: Rec, b: Rec, extra: Rec): Rec => ({
933-
objects: [deal, account],
929+
// its definition is registration order. The two definition questions of the
930+
// expression passes (its type, whether it is nullable) leave it unjudged;
931+
// the single-writer controls show both verdicts the tie would otherwise get.
932+
it('validate-expressions: a field two packages tie on is a served name, judged on no definition', () => {
933+
const tie = (a: Rec, b: Rec): Rec => ({
934+
...validationOn('record.score + 1 > 2'),
934935
packages: [
935936
{ manifest: { id: 'app', objects: [deal, account] } },
936937
{ manifest: { id: 'mod', objectExtensions: [{ extend: 'xs_deal', fields: a }] } },
937938
{ manifest: { id: 'mod2', objectExtensions: [{ extend: 'xs_deal', fields: b }] } },
938939
],
939-
...extra,
940940
});
941-
const sum = validationOn('record.score + 1 > 2');
942-
expect(ids(expressions, tie({ score: { type: 'number' } }, { score: { type: 'text' } }, sum))).toEqual([]);
943-
expect(ids(expressions, tie({ score: { type: 'text' } }, {}, sum))).toEqual(['expression']);
944-
expect(ids(expressions, tie({ score: { type: 'number' } }, {}, sum))).toEqual([]);
941+
const messages = (a: Rec, b: Rec) => validateStackExpressions(tie(a, b)).map((issue) => issue.message);
942+
const num = { score: { type: 'number' } };
943+
const text = { score: { type: 'text' } };
944+
expect(messages(num, text)).toEqual([]);
945+
expect(messages(text, num)).toEqual([]);
946+
expect(messages(text, {})).toEqual([expect.stringContaining('type mismatch'), expect.stringContaining('nullable')]);
947+
expect(messages(num, {})).toEqual([expect.stringContaining('nullable')]);
945948
});
946949
});

‎packages/lint/src/validate-expressions.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2242,9 +2242,9 @@ export function runStackExpressionPasses(stack: AnyRec, options: StackExpression
22422242
// the registry serves is registration order, which the stack does not state,
22432243
// so such a field is a known name with no type and no null-guard verdict.
22442244
// The read-attachment index is object-level and an extension carries none.
2245-
const served = objectsAsServed(stack);
2246-
const typedObjects = objectsWithoutTiedFields(served);
2247-
const fieldIndex = buildFieldIndex(served.objects);
2245+
const { objects: servedObjects, tied } = objectsAsServed(stack);
2246+
const typedObjects = objectsWithoutTiedFields({ objects: servedObjects, tied });
2247+
const fieldIndex = buildFieldIndex(servedObjects);
22482248
const attachedOnReadIndex = buildAttachedOnReadIndex(objects);
22492249
const fieldTypeIndex = buildFieldTypeIndex(typedObjects);
22502250
const nullableIndex = buildNullableFieldIndex(typedObjects);

0 commit comments

Comments
 (0)