Skip to content

Commit 7d479c6

Browse files
committed
feat(spec)!: register the fieldPatches key-grammar narrowing (ADR-0087 semantic entry, changeset, guide)
Claude-Session: https://claude.ai/code/session_01ADHkmSCC3J91hA9anBJ81g Co-authored-by: Claude <noreply@anthropic.com>
1 parent 2ff18a7 commit 7d479c6

3 files changed

Lines changed: 63 additions & 3 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
'@objectstack/spec': minor
3+
---
4+
5+
feat(spec)!: an object extension's `fieldPatches` is keyed by the field map's own key grammar, so a key no field name can be is refused where it is written
6+
7+
`ObjectExtensionSchema.fieldPatches` (ADR-0146 D10) was keyed by any string. A field patch addresses one of the extended object's own fields by name, and every field name is lowercase snake_case, so a key such as `Industry` or `Annual Revenue` could never match a field. It still parsed, and was refused only downstream, where the target judge reaches.
8+
9+
Clause-②: no (narrowing) — `ObjectExtensionSchema` refuses a `fieldPatches` key outside the snake_case grammar of an object's `fields` keys, which it accepted. Nothing is widened, and no public export is added.
10+
11+
Metadata-protocol: narrowed (an object extension may no longer key a field patch by anything but a field name)
12+
13+
Skills-docs: updated here — `content/docs/data-modeling/object-extensions.mdx` ("A patch must name something real") gains the key grammar. `skills/objectstack-data/SKILL.md` keys its `fieldPatches` example by `industry`, so every taught line stays true and no skill line changes.
14+
15+
<!-- adr-0087: registered object-extension-field-patch-key-grammar-refused -->
16+
17+
**BREAKING** accept-set narrowing on `ObjectExtensionSchema` (`@objectstack/spec`), at every door that parses an object extension: `defineObjectExtension`, `defineStack({ objectExtensions })`, `os validate`, the marketplace install and the `/api/v1/meta` `object_extension` save door.
18+
19+
- **Before.** `fieldPatches: { Industry: { label: 'Sector' } }` parsed in `defineStack`, was stored by the save door and booted: the registry fold named the patch once in the log and applied nothing, and `os validate` refused it only when the target object was in the same stack.
20+
- **Now.** One `invalid_key` issue at `fieldPatches.Industry`, naming the grammar and an example. The key schema is the one `ObjectSchema.fields` reads, hoisted to one constant, so the two cannot drift.
21+
- **Unchanged.** A snake_case key parses as before, and a `__c` key is still refused by the `__c` rule with its own prescription.
22+
- **Who sees it.** No extension in this repository's examples, skills, docs or templates writes such a key. A stored `object_extension` row that carries one no longer parses, so the sync names the row (`INVALID_METADATA`) and registers none of it, its `fields` included; its next save is refused until the key is renamed.
23+
24+
**FROM → TO.** `fieldPatches: { Industry: { label: 'Sector' } }` → `fieldPatches: { industry: { label: 'Sector' } }`: key each patch by the name of the field the extended object declares (the key of its `fields` entry), never by its label. The upgrade guide entry is `object-extension-field-patch-key-grammar-refused`.

‎content/docs/data-modeling/object-extensions.mdx‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,11 @@ reason.
142142
can be (`Tech Sector`, a label) is refused too.
143143
- **Conflicts resolve like `label`.** Two extensions patching the same key: the higher
144144
`priority` wins. A tenant who has edited that text keeps their own, [below](#extensions-and-tenant-customization).
145-
- **A patch must name something real.** A field the target does not declare, or an option
146-
value its field does not have, is refused when the package installs and by
147-
`os validate` when the target is in the same stack. A field whose options come from a
145+
- **A patch must name something real.** A key that cannot be a field name (`Industry`,
146+
`Annual Revenue`, a label) is refused when it parses: `fieldPatches` is keyed by the
147+
field's name, lowercase snake_case like every key of `fields`. A field the target does
148+
not declare, or an option value its field does not have, is refused when the package
149+
installs and by `os validate` when the target is in the same stack. A field whose options come from a
148150
shared picklist has no option labels of its own to patch. At boot, an unmatched patch
149151
is not applied and is named once in the log; the boot carries on.
150152
- **Options are the owner's too.** A patch is judged against the options the owner
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
import type { SemanticMigration } from '../../types.js';
4+
5+
// #29366: an object extension's `fieldPatches` is keyed by the key schema
6+
// `ObjectSchema.fields` reads. A semantic entry and not a conversion: the key
7+
// that was meant is the name of a field the target declares, and a rewrite of
8+
// the spelling (lower-casing, `-` to `_`) can land on a different field or on
9+
// none, so which field is the author's to name.
10+
export const entry: SemanticMigration = {
11+
id: 'object-extension-field-patch-key-grammar-refused',
12+
surface:
13+
'`objectExtensions[].fieldPatches` keys (`defineObjectExtension({ fieldPatches })`) that are not a '
14+
+ 'field name: any key outside the lowercase snake_case grammar of an object\'s `fields` keys, such as '
15+
+ 'a label (`Industry`, `Annual Revenue`) or a kebab spelling (`annual-revenue`).',
16+
replacement:
17+
'The name of the field the extended object declares, the key of its `fields` entry: '
18+
+ '`fieldPatches: { industry: { label: \'Sector\' } }`, never `fieldPatches: { Industry: { … } }`.',
19+
reason:
20+
'A field patch addresses one of the target\'s own fields by name, and every field name is lowercase '
21+
+ 'snake_case, so a key outside that grammar can never match a field. The schema used to take any '
22+
+ 'string, so such a patch parsed in `defineStack`, was stored by the `object_extension` save door, '
23+
+ 'and booted: the registry fold only named it in the log and applied nothing, and `os validate` '
24+
+ 'refused it only when the target object was part of the composed stack. The author read "Sector" '
25+
+ 'in their package while the screen kept the vendor\'s label. The key is now judged where it is '
26+
+ 'written, by the same key schema the field map uses.',
27+
acceptanceCriteria:
28+
'Every `fieldPatches` key in the stack is the name of a field its `extend` target declares, and '
29+
+ '`os validate` passes. A key outside the grammar is refused at parse with one `invalid_key` issue '
30+
+ 'at `fieldPatches.KEY` that names the grammar and an example. A stored `object_extension` row whose '
31+
+ 'body still carries such a key no longer parses, so the sync that registers stored extensions names '
32+
+ 'the row (`INVALID_METADATA`) and registers none of it, its `fields` included, and its next save is '
33+
+ 'refused until the key is renamed to the field it meant.',
34+
};

0 commit comments

Comments
 (0)