Skip to content

Commit 7ca6317

Browse files
committed
docs(changeset): declare the #30471 narrowing, lint minor, with every finding that moves
The changeset now carries Clause-② yes (narrowing) with the widening half, Metadata-protocol narrowed, a BREAKING banner and the ADR-0087 disposition, in the shape of the page-sort precedent; it lists every finding a name the fold adds now moves to, measured against main on both CLI legs. Two refusals of a stack main accepted: the hook ctx.api readonly write (warning to error) and the translation keys the fold drops (resolved to error). hook-bodies.mdx says the readonly rule's declarations include extension fields. Pin: the two translation refusals at error, on the replaced-entry shape (both legs) and on a top-level objectExtensions beside packages[]. Claude-Session: https://claude.ai/code/session_01L6bhgTqqeHSwZYJmApbDCa Co-authored-by: Claude <noreply@anthropic.com>
1 parent 105c986 commit 7ca6317

3 files changed

Lines changed: 41 additions & 7 deletions

File tree

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
11
---
2-
'@objectstack/lint': patch
2+
'@objectstack/lint': minor
33
---
44

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)
5+
fix(lint)!: the field-name indexes judge an object as the registry serves it, so a read, write or sort naming a field an `objectExtensions` entry adds is no longer refused as unknown, and the readonly, sortability and translation rules judge that field by its served definition (#30471)
66

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)
7+
Clause-②: yes (narrowing) — `os validate` / `os build` / `os lint` refuse two shapes they accepted before: a hook body's literal `ctx.api.object(NAME).update(…)` / `.updateById(…)` / `.insert(…)` writing a field an `objectExtensions` entry adds and declares `readonly: true` moves from a `hook-body-write-unknown-field` warning to a `hook-api-update-readonly-field` error; and a translation key naming a field or validation rule that only a replaced earlier entry of the same package adds, or only a top-level `objectExtensions` beside `packages[]` adds, is now `translation-target-unknown` at `error`, where it resolved. The widening half: a formula, validation, flow condition, hook condition, sharing-rule condition, flow-node, action-body or hook-body write, react page field prop, translation key, page sort or list-view sort naming a field an `objectExtensions` entry of the same artifact adds is no longer refused as an unknown field.
8+
Metadata-protocol: narrowed
9+
Skills-docs: updated here — content/docs/automation/hook-bodies.mdx
910

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. The three readonly write rules (`flow-update-readonly-field`, `hook-api-update-readonly-field`, `action-api-update-readonly-when-field` and their siblings) judge an extension field's served definition too, so a body write to an extension field declared `readonly` or `readonlyWhen` is refused by the readonly rule, where it was refused as an unknown field before; for a hook's `ctx.api.object(...).update(...)` write that moves the finding from a `warning` (`hook-body-write-unknown-field`) to the readonly rule's `error`, the severity it already has for a declared readonly field. A field two packages tie on is not judged readonly. A misspelled field within edit distance 3 of an extension-added name now gets a did-you-mean naming that field.
11+
<!-- adr-0087: not-required (no-migration-prescription) No key of any schema is added, removed or renamed: objects, object extensions, flows, hooks, actions, pages, views and translation bundles keep their shapes and meanings. What moves is which rule judges a name an objectExtensions entry adds, and at what severity: the hook write it now refuses was dropped at run time by the readonly strip, and the translation key it now refuses names nothing the registry serves. There is no rewrite that keeps what the author meant; the author drops the write or the key, or moves it to the entry the registry keeps, and the refusal says which. -->
12+
13+
**BREAKING** accept-set narrowing in `os validate` / `os build` / `os lint` (`@objectstack/lint`), for multi-package artifacts whose bodies add fields to another package's object through `objectExtensions`.
14+
15+
- **Before.** The field-name indexes of the expression passes (validation rules, formulas, flow and hook conditions, sharing-rule conditions), the three write rules, a react page's field props, the three readonly write rules and the sort rule read an object's declared `fields` only, so a name an `objectExtensions` entry adds was refused as unknown although the runtime serves the field: `flow-node-write-unknown-field` and `sort-field-unknown` / `page-field-unknown` (page sorts) at `error`, `action-body-write-unknown-field`, `hook-body-write-unknown-field` and `page-field-unknown` (react props) at `warning`, the expression passes' unknown-field error. The translation rule folded extensions through a reader of its own that kept every entry and also read a top-level `objectExtensions` beside `packages[]`.
16+
- **Now.** Every one of them reads the one shared fold in `object-graph.ts` (since #30383 the field-path rules' fold): the declared fields plus each field an `objectExtensions` entry adds, one entry per package per object, `packages[]` alone when the artifact carries it. A name no body declares or adds keeps the same refusal, rule id, severity and message; a misspelling within edit distance 3 of an extension-added name now gets a did-you-mean naming it. A name the fold adds is judged by its served definition, so these findings move (union artifact and per-package leg alike):
17+
- a hook body's `ctx.api` update / updateById / insert of a `readonly: true` field: `hook-body-write-unknown-field` `warning` → `hook-api-update-readonly-field` `error`, the severity a declared readonly field already gets (a non-system hook's `ctx.api` write is stripped at run time and the call returns success);
18+
- a translation key naming a field or rule only a replaced earlier entry of the same package, or only a top-level `objectExtensions` beside `packages[]`, adds: resolved → `translation-target-unknown` `error`, as the registry serves the object;
19+
- a flow `update_record` / `create_record` of a `readonly: true` field: `flow-node-write-unknown-field` `error` → `flow-update-readonly-field` `error`;
20+
- a page sort (every slot) or list-view sort by a `formula` field or one declaring `sortable: false`: `page-field-unknown` / `sort-field-unknown` `error` → `sort-field-unsortable` `error`;
21+
- a `readonlyWhen` field written by a flow `update_record` (`error` → `flow-update-readonly-when-field` `warning`), a hook's `ctx.api` update (`warning` → `hook-api-update-readonly-when-field` `warning`) or an action's `ctx.api` update (`warning` → `action-api-update-readonly-when-field` `warning`);
22+
- an expression reading the field: the unknown-field error becomes the served type's verdict (a type mismatch or a missing null guard, at `error` in validation rules and hook conditions, at `warning` in formulas and sharing-rule conditions) or nothing.
23+
Every other read, write or sort naming such a field passes: a hook's `ctx.input` stamp, an action's `ctx.api` write of a `readonly: true` field (an action runs elevated) and a `create_record` of a `readonlyWhen` field land at run time.
24+
- **Not judged.** A field two packages write at the same deciding priority is a served name, but no rule judges its type, nullability, readonly or sortability: which definition wins is registration order. An object that declares no field of its own stays unjudged by the write, readonly and sort rules, extended or not (an introspected schema). A react page's `searchableFields` still reads declared fields only.
25+
- **Not changed.** Which extension entries the fold keeps, the runtime, and `defineStack` (its related-list check stays additive). A stack that names no extension field reads as before.
26+
27+
**What an author does.** For a hook writing a readonly extension field, declare the hook `runAs: 'system'`, stamp the value in the record's own `beforeInsert` / `beforeUpdate` hook, or drop the field from the payload. For a translation key the fold drops, key it to a field or rule of the entry the registry keeps (the package's last entry for that object, in a `packages[]` body), or delete it.

‎content/docs/automation/hook-bodies.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ There is an asymmetry here that costs data if you learn it the hard way, so lear
309309

310310
The dropped case is the dangerous one: nothing fails, the step reports success, and the column is simply always null. Because both halves of that judgement are declared in your own stack, it is checked at author time and **gates the build**:
311311

312-
- `hook-api-update-readonly-field` — **error**. A body's literal `ctx.api.object('…').update()` / `.updateById()` / `.insert()` writes a field the named object declares `readonly: true`. Since [#15394](https://github.com/objectstack-ai/objectstack/issues/15394) the `insert` row of the table above is reported at build time exactly like the `update` row — same id, same severity, a message naming the verb — unless the hook declares `runAs: 'system'`. Only the static shape is judged on an insert: a `readonlyWhen` field has no prior record to lock on and the engine runs no conditional strip on INSERT, so no warning is produced there.
312+
- `hook-api-update-readonly-field` — **error**. A body's literal `ctx.api.object('…').update()` / `.updateById()` / `.insert()` writes a field the named object declares `readonly: true`, a field an `objectExtensions` entry of the same artifact adds to it included. Since [#15394](https://github.com/objectstack-ai/objectstack/issues/15394) the `insert` row of the table above is reported at build time exactly like the `update` row — same id, same severity, a message naming the verb — unless the hook declares `runAs: 'system'`. Only the static shape is judged on an insert: a `readonlyWhen` field has no prior record to lock on and the engine runs no conditional strip on INSERT, so no warning is produced there.
313313
- `hook-api-update-readonly-when-field` — **warning**. The same write against a `readonlyWhen` field, which strips per record *state*. The own-hook stamp **is** the workaround here, exactly as it is for static `readonly`: since [#9107](https://github.com/objectstack-ai/objectstack/issues/9107) the conditional strip judges the *caller's* entry payload, so a value a `beforeUpdate` hook **derives** is not caller-supplied and lands even on a locked record. (Deriving is the operative word — a hook that merely echoes the caller's own value back has written nothing the strip can tell from the caller's, and it still goes.) What does **not** help is elevation: unlike the static strip, the conditional lock is **not** waived by a system context, so neither `runAs: 'system'` nor the `sudo()` a body cannot reach makes a caller-supplied value survive. On this shape, confirm the write only targets records whose predicate is `false`, or derive the field in a `beforeUpdate` hook on the target object.
314314

315315
Which hooks these rules can *see* depends on the command, because every rule in this family opens on `body.language === 'js'`. A hook authored as an inline `handler` function carries no `body`, so it is judged only where the command has first lowered the handler to a metadata body: `objectstack build` always has (it lowers before it parses — see [How the build lowers a handler](#build-pipeline)), and since [#16095](https://github.com/objectstack-ai/objectstack/issues/16095) `objectstack lint` judges that same lowered view, so an author who runs only the pre-flight is told the same thing the build would refuse. Since [#16544](https://github.com/objectstack-ai/objectstack/issues/16544) `objectstack validate` lowers before it parses as well, so all three commands judge the same view of a handler-authored hook — a stack `objectstack validate` passes is one `objectstack build` does not refuse on this family. A handler the build cannot lower (a forbidden token, a module-scope identifier) has no body on any command and is reported by the lowering rules instead, never guessed at here.

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,24 @@ describe('[#30471] the field-name indexes read the objects as served', () => {
928928
expect(ids(validateTranslationReferences, artifact(keys({}, { region_set: { message: 'M' } }), replaced))).toEqual([TRANSLATION_TARGET_UNKNOWN]);
929929
});
930930

931+
// The two refusals the retired private reader did not raise, both at
932+
// `error`: it kept every entry, and read a top-level `objectExtensions`
933+
// beside `packages[]` too. The fold keeps one entry per package per target
934+
// and reads `packages[]` alone when there is one, as the registry does.
935+
it('validate-translation-references: the keys only the fold drops are refused at error', () => {
936+
const bundle = { translations: [{ 'zh-CN': { objects: { xs_deal: { fields: { region: { label: 'R' } }, _validations: { region_set: { message: 'M' } } } } } }] };
937+
const refused = [[TRANSLATION_TARGET_UNKNOWN, 'error'], [TRANSLATION_TARGET_UNKNOWN, 'error']];
938+
const verdicts = (stack: Rec) => validateTranslationReferences(stack).map((f) => [f.rule, f.severity]);
939+
const replaced = [...extensions, { extend: 'xs_deal', fields: { mood: { type: 'text' } } }];
940+
expect(verdicts(artifact(bundle, replaced))).toEqual(refused);
941+
expect(verdicts(perPackage(bundle, replaced))).toEqual(refused);
942+
const beside = { objects: [deal, account], objectExtensions: extensions, packages: [{ manifest: { id: 'app', objects: [deal, account] } }], ...bundle };
943+
expect(verdicts(beside)).toEqual(refused);
944+
// With no `packages[]`, the top level is the artifact's own and is read.
945+
const { packages: _packages, ...alone } = beside;
946+
expect(verdicts(alone)).toEqual([]);
947+
});
948+
931949
// The write rules leave an object that declares no field unjudged (an
932950
// external, introspected schema): an extension adding to it does not make
933951
// its other fields knowable.

0 commit comments

Comments
 (0)