4545 * ({@link externalBindingDatasourceRefusal}), and the one-name-per-action
4646 * judge of the object refinement ({@link duplicateActionNames}), and the
4747 * one-key-per-global-filter judge of the dashboard refinement
48- * ({@link duplicateGlobalFilterNames}), and the `fieldPatches` key
49- * grammar of `ObjectExtensionSchema`'s own parse
50- * ({@link refusedFieldPatchKeys}). A site is listed here exactly
48+ * ({@link duplicateGlobalFilterNames}), and the `fieldPatches` and
49+ * `fields` key grammar of `ObjectExtensionSchema`'s own parse
50+ * ({@link refusedFieldPatchKeys}, { @link refusedExtensionFieldKeys} ). A site is listed here exactly
5151 * when that door refuses it. One door lives outside this package: the
5252 * page/view `visibleWhen` rule in `@objectstack/lint` judges a `has()`
5353 * argument on the engine's AST, which this package cannot parse, so its
@@ -597,12 +597,25 @@ const dashboardDuplicateGlobalFilterName: RefusedStoredShape = {
597597 * a key is listed here exactly when that parse refuses it as a key.
598598 */
599599function refusedFieldPatchKeys ( extension : Dict ) : Array < { key : string ; message : string } > {
600- if ( ! isDict ( extension . fieldPatches ) ) return [ ] ;
600+ return refusedExtensionRecordKeys ( extension , 'fieldPatches' ) ;
601+ }
602+
603+ /**
604+ * The keys of one field-name-keyed record of an object extension (`fields` or
605+ * `fieldPatches`) that `ObjectExtensionSchema` refuses as no field name: each
606+ * `invalid_key` issue the extension's own parse locates at `SLOT.KEY`, with
607+ * that issue's message.
608+ */
609+ function refusedExtensionRecordKeys (
610+ extension : Dict ,
611+ slot : 'fields' | 'fieldPatches' ,
612+ ) : Array < { key : string ; message : string } > {
613+ if ( ! isDict ( extension [ slot ] ) ) return [ ] ;
601614 const parsed = ObjectExtensionSchema . safeParse ( extension ) ;
602615 if ( parsed . success ) return [ ] ;
603616 const refused : Array < { key : string ; message : string } > = [ ] ;
604617 for ( const issue of parsed . error . issues ) {
605- if ( issue . code !== 'invalid_key' || issue . path . length !== 2 || issue . path [ 0 ] !== 'fieldPatches' ) continue ;
618+ if ( issue . code !== 'invalid_key' || issue . path . length !== 2 || issue . path [ 0 ] !== slot ) continue ;
606619 const key = issue . path [ 1 ] ;
607620 if ( typeof key === 'string' ) refused . push ( { key, message : issue . message } ) ;
608621 }
@@ -634,6 +647,45 @@ const objectExtensionFieldPatchKeyGrammar: RefusedStoredShape = {
634647 } ,
635648} ;
636649
650+ // ── #29523: an object extension whose `fields` key cannot be a field name ──
651+
652+ /**
653+ * The `fields` keys `ObjectExtensionSchema` refuses as no field name, read as
654+ * {@link refusedFieldPatchKeys} reads `fieldPatches`: the extension's own
655+ * parse, the one the save door and the sync that registers stored extensions
656+ * run, so a key is listed here exactly when that parse refuses it as a key.
657+ */
658+ function refusedExtensionFieldKeys ( extension : Dict ) : Array < { key : string ; message : string } > {
659+ return refusedExtensionRecordKeys ( extension , 'fields' ) ;
660+ }
661+
662+ const objectExtensionFieldKeyGrammar : RefusedStoredShape = {
663+ id : 'object-extension-field-key-grammar-refused' ,
664+ toMajor : 18 ,
665+ surface : 'objectExtensions[].fields — a key outside the snake_case grammar of an object\'s `fields` keys' ,
666+ detect ( stack , report ) {
667+ mapCollection ( stack , 'objectExtensions' , ( extension , path ) => {
668+ const target = typeof extension . extend === 'string' ? `\`${ extension . extend } \`` : 'its target' ;
669+ for ( const { key, message } of refusedExtensionFieldKeys ( extension ) ) {
670+ report ( {
671+ path : `${ path } .fields.${ key } ` ,
672+ // The key and the field's type only: the body is the author's, the key is what is refused.
673+ from : JSON . stringify ( { [ key ] : { type : ( ( extension . fields as Dict ) [ key ] as Dict | undefined ) ?. type } } ) ,
674+ reason : `The extension of ${ target } adds a field under \`${ key } \`. `
675+ + 'No lossless rewrite: the key is the name the field is stored and read under, and re-spelling it '
676+ + '(lower-casing it, turning `-` or a space into `_`) names a different column than the one rows, '
677+ + 'views and formulas may already read, or lands on a field the object already declares, so the '
678+ + '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. '
681+ + message ,
682+ } ) ;
683+ }
684+ return extension ;
685+ } ) ;
686+ } ,
687+ } ;
688+
637689/**
638690 * Every refused stored shape, in report order. A new entry is a reviewed edit:
639691 * `refused-shapes.test.ts` pins each one.
@@ -648,6 +700,7 @@ export const REFUSED_STORED_SHAPES: readonly RefusedStoredShape[] = [
648700 objectDuplicateActionName ,
649701 dashboardDuplicateGlobalFilterName ,
650702 objectExtensionFieldPatchKeyGrammar ,
703+ objectExtensionFieldKeyGrammar ,
651704] ;
652705
653706/**
0 commit comments