Skip to content

Commit 8565c18

Browse files
committed
feat(spec): object-level composite/repeater are untyped JSON; sub-field keys refused with the child-object route
Claude-Session: https://claude.ai/code/session_01T2U7eGg8aRTpJ8kKXxDiog Co-authored-by: Claude <noreply@anthropic.com>
1 parent 47af3dd commit 8565c18

3 files changed

Lines changed: 79 additions & 3 deletions

File tree

‎packages/spec/src/data/authoring-key-lint.test.ts‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,52 @@ describe('the `id_field` retirement is reached, not merely declared', () => {
164164
expect(shapeKeys(InlineGridColumnSchema)).toContain('idField');
165165
});
166166
});
167+
168+
/**
169+
* An object-level `composite` / `repeater` is untyped JSON by ruling
170+
* 6386744473, and a typed list is a child object. The parse already refused
171+
* these keys before the rows existed; what the rows add is the ROUTE, so that
172+
* is what is pinned — on the same channel as the `id_field` block above.
173+
*/
174+
describe('a typed list declared on an embedded-JSON field is refused with the child-object route', () => {
175+
const unrecognized = (value: unknown) => {
176+
const r = FieldSchema.safeParse(value);
177+
expect(r.success).toBe(false);
178+
if (r.success) throw new Error('unreachable');
179+
const issue = r.error.issues.find((i) => i.code === 'unrecognized_keys');
180+
expect(issue, 'the field parse did not refuse the unknown key at all').toBeTruthy();
181+
return issue!;
182+
};
183+
const SUB_ROWS = [{ name: 'item', label: 'Item', type: 'text' }];
184+
const CASES: Array<[string, unknown]> = [
185+
['fields', SUB_ROWS],
186+
['subFields', SUB_ROWS],
187+
['columns', ['item', 'score']],
188+
];
189+
190+
for (const type of ['repeater', 'composite'] as const) {
191+
for (const [key, value] of CASES) {
192+
it(`${type} + \`${key}\`: refused by name, answered with this table's sentence`, () => {
193+
const issue = unrecognized({ name: 'checklist', label: 'Checklist', type, [key]: value });
194+
expect((issue as { keys?: string[] }).keys).toEqual([key]);
195+
expect(issue.message).toContain(FIELD_KEY_GUIDANCE[key]!.why!);
196+
expect(issue.message).toContain('`master_detail`');
197+
expect(issue.message).not.toContain('Did you mean');
198+
});
199+
}
200+
}
201+
202+
it('the field itself, with no sub-field key, still parses — the type is untyped, not refused', () => {
203+
for (const type of ['repeater', 'composite'] as const) {
204+
expect(FieldSchema.safeParse({ name: 'checklist', label: 'Checklist', type }).success).toBe(true);
205+
}
206+
});
207+
208+
it('`columns` names the three live column keys, and each really is declared', () => {
209+
const why = FIELD_KEY_GUIDANCE.columns!.why!;
210+
for (const live of ['lookupColumns', 'relatedListColumns', 'inlineColumns']) {
211+
expect(why).toContain(`\`${live}\``);
212+
expect(shapeKeys(FieldSchema)).toContain(live);
213+
}
214+
});
215+
});

‎packages/spec/src/data/authoring-key-lint.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ export interface UnknownAuthoringKeyFinding {
7272
guidance?: string;
7373
}
7474

75+
/**
76+
* The route for a typed list, shared by the sub-field rows below. Module-private:
77+
* the rows are the published face, and `@objectstack/lint` words its own finding.
78+
*/
79+
const EMBEDDED_JSON_TYPED_LIST =
80+
'An object-level `composite` / `repeater` stores untyped JSON — no per-column labels, types, '
81+
+ 'options or required flags. A list that needs typed columns is a child object whose '
82+
+ '`master_detail` field points back at this object, shown on the record as an inline related list.';
83+
7584
/**
7685
* Semantic near-misses on `FieldSchema` — a different **word** for the same
7786
* intent, or a key that was retired outright.
@@ -144,6 +153,18 @@ export const FIELD_KEY_GUIDANCE: Readonly<
144153
// ⛔ Do not "normalise" this to `idField` to match its neighbours; the
145154
// reachability test in `authoring-key-lint.test.ts` fails if you do.
146155
id_field: { why: '`id_field` was never a FieldSchema key: a lookup stores the referenced record\'s id, and which field holds that value is not an authored per-field choice — the picker resolves record identity itself. Use `displayField` to change which field is SHOWN as a candidate\'s label, and a seed dataset\'s `externalId` to author references by a portable natural key. The live `idField` is the one on an `inlineColumns` entry — the GridColumn mirror in `field.zod.ts`, which is a DIFFERENT schema.' },
156+
// ── A typed list declared on an embedded-JSON field (ruling 6386744473) ──
157+
// An object-level `composite` / `repeater` is untyped JSON BY RULING: no
158+
// sub-field member is added, and a list that needs typed columns is a child
159+
// object. These are the spellings an author reaches for when they expect one
160+
// (the three the ruling names; objectui's structured cell documents `fields` /
161+
// `subFields` as refused). Without a row the parse names the key and nothing
162+
// else, so the author learns the key is wrong but not where the list goes.
163+
// `@objectstack/lint`'s `field/embedded-sub-fields` says the same on the doors
164+
// that never parse. A form view's `fields` sub-rows are a different schema.
165+
fields: { why: `\`fields\` is not a field key: a field declares no sub-fields. ${EMBEDDED_JSON_TYPED_LIST}` },
166+
subFields: { why: `\`subFields\` is not a field key: a field declares no sub-fields. ${EMBEDDED_JSON_TYPED_LIST}` },
167+
columns: { why: `\`columns\` is not a field key. A lookup's picker columns are \`lookupColumns\`; a \`master_detail\` field's related-list columns are \`relatedListColumns\` and its inline-grid columns \`inlineColumns\`. ${EMBEDDED_JSON_TYPED_LIST}` },
147168
});
148169

149170
/**

‎packages/spec/src/data/field.zod.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,15 @@ export const FieldType = z.enum([
9292
'image', 'file', 'avatar', 'video', 'audio',
9393
// Calculated / System
9494
'formula', 'summary', 'autonumber',
95-
// Embedded structured values (stored as JSON on the parent row — no separate table / FK)
96-
'composite', // Single embedded sub-object with declared sub-fields (≈ Strapi component / ACF group)
97-
'repeater', // Repeating embedded sub-object array with declared sub-fields (≈ Strapi repeatable component / ACF repeater)
95+
// Embedded structured values (stored as JSON on the parent row — no separate table / FK).
96+
// On an OBJECT field, `composite` / `repeater` are UNTYPED JSON containers of CMS lineage
97+
// (≈ Strapi component / ACF group / ACF repeater): `FieldSchema` declares no sub-field
98+
// member, so nothing types, labels, validates or addresses the inner keys or rows.
99+
// A list that needs typed columns is a CHILD OBJECT whose `master_detail` field points
100+
// back at the parent, shown on the record as an inline related list (ruling 6386744473).
101+
// A form view's `fields` sub-rows (`ui/view.zod.ts`) are a different surface.
102+
'composite', // Single embedded JSON object, untyped — no declared sub-fields
103+
'repeater', // Array of embedded JSON objects, untyped — no declared sub-fields or columns
98104
'record', // Name-keyed map of embedded sub-objects (Record<string, SubObject>). Insertion order = display order. Used for collections where each item has a stable machine name (e.g. object.fields). See ADR-0007.
99105
// Enhanced Types
100106
'location', // GPS coordinates

0 commit comments

Comments
 (0)