Skip to content

Commit b09c164

Browse files
committed
feat(spec)!: changeset, and the measured door readings in the D3 entry
Claude-Session: https://claude.ai/code/session_01WGufzf5kvTFdbWYDbe8bHE Co-Authored-By: Claude <noreply@anthropic.com>
1 parent bdd897e commit b09c164

3 files changed

Lines changed: 33 additions & 7 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 `fields` is keyed by the field map's own key grammar, so a field no object could declare is refused where it is written
6+
7+
`ObjectExtensionSchema.fields` was keyed by any string. The fields an extension adds are merged into the target object's field map, and every key of that map is lowercase snake_case: `ObjectSchema.fields` refuses any other. So an extension could add a field under a key (`Region Code`, `region-code`) that the target's own declaration could never hold.
8+
9+
Clause-②: no (narrowing) — `ObjectExtensionSchema` refuses a `fields` 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 add a field under anything but a snake_case field name)
12+
13+
Skills-docs: updated here — `content/docs/data-modeling/object-extensions.mdx` ("Naming the fields you add") gains the key grammar. `skills/objectstack-data/SKILL.md` and its evals teach extension fields only as `region__c`, so every taught line stays true and no skill line changes.
14+
15+
<!-- adr-0087: registered object-extension-field-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.** `fields: { 'Region Code': { type: 'text', label: 'Region' } }` parsed in `defineStack`, whether or not the target was in the same stack, and `os validate` raised nothing on it. In a `.custom` package, `fields: { 'Region Code__c': … }` was saved and published by the `object_extension` doors, served on every object read, re-registered at boot, and stored values in a column of that name.
20+
- **Now.** One `invalid_key` issue at `fields.Region Code`, naming the grammar and an example. The key schema is the one `ObjectSchema.fields` and `fieldPatches` read, one constant, so the three cannot drift.
21+
- **Unchanged.** A snake_case key parses as before, `__c` included (`region_code__c`); where the `__c` suffix is required or refused is still judged by the doors' `__c` rule.
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 that registers stored extensions counts it as an error and registers none of it, its `fieldPatches` included, and its next save is refused (422 `INVALID_METADATA`) until the field is renamed. `os migrate meta --stored` lists such a row beforehand, one TODO for each refused key at `fields.KEY`, and leaves it as stored for its owner to rename.
23+
24+
**FROM → TO.** `fields: { 'Region Code': { type: 'text', label: 'Region Code' } }` → `fields: { region_code: { type: 'text', label: 'Region Code' } }` (`region_code__c` in a customization package): key each added field by a lowercase snake_case name, and keep the display text in its `label`. Renaming a field that already stores values also means renaming every view, formula and caller that reads it. The upgrade guide entry is `object-extension-field-key-grammar-refused`.

‎packages/spec/src/conversions/refused-shapes.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,8 +676,8 @@ const objectExtensionFieldKeyGrammar: RefusedStoredShape = {
676676
+ '(lower-casing it, turning `-` or a space into `_`) names a different column than the one rows, '
677677
+ 'views and formulas may already read, or lands on a field the object already declares, so the '
678678
+ 'name is the author\'s to choose. Left as stored, the row no longer parses: the sync that registers '
679-
+ 'stored extensions names it (INVALID_METADATA) and registers none of it, its `fieldPatches` '
680-
+ 'included, and its next save is refused until the field is renamed. '
679+
+ 'stored extensions counts it as an error and registers none of it, its `fieldPatches` included, '
680+
+ 'and its next save is refused with 422 INVALID_METADATA until the field is renamed. '
681681
+ message,
682682
});
683683
}

‎packages/spec/src/migrations/entries/semantic/18.object-extension-field-key-grammar-refused.ts‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,17 @@ export const entry: SemanticMigration = {
2929
'An extension\'s `fields` are merged into the target object\'s field map, and every key of that map is '
3030
+ 'lowercase snake_case: `ObjectSchema.fields` refuses any other key. The extension schema used to take '
3131
+ 'any string, so such a field parsed in `defineStack` and in `defineObjectExtension`, whether or not '
32-
+ 'the target was in the same stack, and was merged into an object whose own declaration could never '
33-
+ 'have held it. The key is now judged where it is written, by the same key schema the field map uses.',
32+
+ 'the target was in the same stack, and `os validate` raised nothing on it. In a customization package, '
33+
+ 'an `object_extension` row keyed `Region Code__c` was saved and published, served on every read of '
34+
+ 'the target, and stored values under that name: a field the target\'s own declaration could never '
35+
+ 'have held. The key is now judged where it is written, by the same key schema the field map uses.',
3436
acceptanceCriteria:
3537
'Every `fields` key of every object extension in the stack is lowercase snake_case, and `os validate` '
3638
+ 'passes. A key outside the grammar is refused at parse with one `invalid_key` issue at `fields.KEY` '
3739
+ 'that names the grammar and an example. A stored `object_extension` row whose body still carries such '
38-
+ 'a key no longer parses, so the sync that registers stored extensions names the row '
39-
+ '(`INVALID_METADATA`) and registers none of it, its `fieldPatches` included, and its next save is '
40-
+ 'refused until the field is renamed. `os migrate meta --stored` lists such a row before the upgrade, '
40+
+ 'a key no longer parses, so the sync that registers stored extensions counts the row as an error and '
41+
+ 'registers none of it, its `fieldPatches` included, and its next save is refused (422 '
42+
+ '`INVALID_METADATA`) until the field is renamed. `os migrate meta --stored` lists such a row before the upgrade, '
4143
+ 'one TODO for each refused key at `fields.KEY` naming the extended object, and leaves it as stored: '
4244
+ 'rename each listed field to a snake_case name, along with every view, formula and caller that reads '
4345
+ 'it, and save the extension.',

0 commit comments

Comments
 (0)