Skip to content

Commit 82f060c

Browse files
committed
wip(spec): the view write door's wire members refuse an unknown top-level key
Claude-Session: https://claude.ai/code/session_01WGufziYCUHZQE3MXucvWe9 Co-authored-by: Claude <noreply@anthropic.com>
1 parent ef7067f commit 82f060c

1 file changed

Lines changed: 97 additions & 34 deletions

File tree

‎packages/spec/src/ui/view.zod.ts‎

Lines changed: 97 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
import { z } from 'zod';
5252
import { ProtectionSchema } from '../shared/protection.zod';
5353
import { MetadataProtectionFields } from '../kernel/metadata-protection.zod';
54-
import { closedObject, strictObject, strictObjectError } from '../shared/strict-object';
54+
import { closedObject, strictObject, strictObjectError, type StrictObjectOptions } from '../shared/strict-object';
5555
import { SnakeCaseIdentifierSchema, QUALIFIED_ITEM_NAME_PATTERN } from '../shared/identifiers.zod';
5656
import { EvaluatedExpressionInputSchema } from '../shared/expression.zod';
5757
import { ConditionalFormattingRuleSchema } from '../shared/conditional-formatting.zod';
@@ -5596,34 +5596,94 @@ function viewItemWireFields() {
55965596
};
55975597
}
55985598

5599+
/**
5600+
* [#26711] What the write door's three wire members said about an unknown
5601+
* top-level key before they were closed: nothing. The save answered success
5602+
* and stored the parsed body, without the key.
5603+
*/
5604+
const VIEW_WIRE_HISTORY =
5605+
'Until the `view` write door closed this shape an unknown top-level key was dropped silently — '
5606+
+ 'the save answered success and the key was not stored.';
5607+
5608+
/**
5609+
* [#26711] The alias spellings the #20456 census found on stored `view` rows,
5610+
* each mapped to the declared key it means. Undeclared on purpose (see
5611+
* {@link VIEW_CONSOLE_ROUND_TRIP_KEYS}); named here so the refusal points at
5612+
* the declared spelling instead of leaving the author to guess.
5613+
*/
5614+
const VIEW_WIRE_ALIASES = { objectName: 'object', id: 'name' } as const;
5615+
5616+
/** [#26711] The unknown-key refusal of member 1, the ViewItem record. */
5617+
const VIEW_ITEM_WIRE_SURFACE: StrictObjectOptions = {
5618+
surface: 'this view item record',
5619+
history: VIEW_WIRE_HISTORY,
5620+
aliases: VIEW_WIRE_ALIASES,
5621+
};
5622+
5623+
/** [#26711] The unknown-key refusal of member 3, the flattened list overlay. */
5624+
const LIST_OVERLAY_WIRE_SURFACE: StrictObjectOptions = {
5625+
surface: 'this inline list view',
5626+
history: VIEW_WIRE_HISTORY,
5627+
aliases: VIEW_WIRE_ALIASES,
5628+
};
5629+
5630+
/** [#26711] The unknown-key refusal of member 4, the flattened form overlay. */
5631+
const FORM_OVERLAY_WIRE_SURFACE: StrictObjectOptions = {
5632+
surface: 'this inline form view',
5633+
history: VIEW_WIRE_HISTORY,
5634+
aliases: VIEW_WIRE_ALIASES,
5635+
};
5636+
5637+
/**
5638+
* [#26711] Close a wire member's TOP level, with its own unknown-key refusal.
5639+
*
5640+
* The flattened overlays are built by extending an authoring shape, and an
5641+
* extension inherits that shape's refusal: the surface named in it, and the
5642+
* candidate list a typo is pointed at, which would miss every key the overlay
5643+
* adds (`isPinned`, `columnState`, …). So the member is closed with a refusal
5644+
* built from its OWN shape — the same `strictObjectError` map
5645+
* {@link strictObject} attaches — and re-declared as a `closedObject`, so the
5646+
* refusal is terminal on this surface and the union keeps its envelope.
5647+
*
5648+
* Nested blocks keep their own posture, as before: closing the top level does
5649+
* not recurse any more than `.strip()` did, and the console's row ids are
5650+
* still removed before the parse by {@link stripViewConsoleDecorations}.
5651+
*/
5652+
function closeWireMember<T extends z.ZodObject>(member: T, options: StrictObjectOptions) {
5653+
const strict = member.strict();
5654+
const def = strict._zod.def;
5655+
return closedObject(strict.clone({ ...def, error: strictObjectError(options, def.shape) }));
5656+
}
5657+
55995658
/**
56005659
* [#5074] The WIRE variant of {@link ViewItemSchema} — member 1 of
5601-
* {@link ViewMetadataSchema}, re-opened with `.strip()`.
5660+
* {@link ViewMetadataSchema}.
56025661
*
5603-
* Exactly the pattern the two flattened members below already use
5604-
* (`ListViewSchema.extend(flattenedViewOverlayFields()).strip()`), reached one
5605-
* member further. `z.discriminatedUnion` cannot be `.extend()`ed, so the two
5606-
* postures share {@link viewItemArmShape} rather than a `.extend()` chain —
5607-
* derive-by-reference either way, one shape, two doors.
5662+
* `z.discriminatedUnion` cannot be `.extend()`ed, so the two postures share
5663+
* {@link viewItemArmShape} rather than a `.extend()` chain — derive-by-reference
5664+
* either way, one shape, two doors. The wire variant adds the console's
5665+
* round-trip keys ({@link viewItemWireFields}) and nothing else.
56085666
*
5609-
* `.strip()` covers the TOP level only. Nested console decorations
5610-
* (`config.filter[].id`, `config.sort[].id`) are handled by
5611-
* {@link stripViewConsoleDecorations} on the wire door — see that function for
5612-
* why a recursive strip is the piece a posture flip cannot provide.
5667+
* [#26711] Closed, like the authoring schema: an unknown top-level key is
5668+
* refused by name. Until then this member `.strip()`ped it, and because the
5669+
* save stores the parsed body (#20051) a misspelt key answered success and was
5670+
* not stored. Nested console decorations (`config.filter[].id`,
5671+
* `config.sort[].id`) are still removed before the parse by
5672+
* {@link stripViewConsoleDecorations} on the wire door.
56135673
*/
56145674
export const ViewItemWireSchema: z.ZodDiscriminatedUnion<[
5615-
z.ZodObject<ViewItemWireArmShape<'list', typeof ListViewSchema>, z.core.$strip>,
5616-
z.ZodObject<ViewItemWireArmShape<'form', typeof FormViewSchema>, z.core.$strip>,
5675+
z.ZodObject<ViewItemWireArmShape<'list', typeof ListViewSchema>, z.core.$strict>,
5676+
z.ZodObject<ViewItemWireArmShape<'form', typeof FormViewSchema>, z.core.$strict>,
56175677
], 'viewKind'> = lazySchema(() =>
56185678
z.discriminatedUnion('viewKind', [
5619-
z.object({
5679+
strictObject(VIEW_ITEM_WIRE_SURFACE, {
56205680
...viewItemArmShape('list', ListViewSchema.describe('List-family view configuration.')),
56215681
...viewItemWireFields(),
5622-
}).strip(),
5623-
z.object({
5682+
}),
5683+
strictObject(VIEW_ITEM_WIRE_SURFACE, {
56245684
...viewItemArmShape('form', FormViewSchema.describe('Form view configuration.')),
56255685
...viewItemWireFields(),
5626-
}).strip(),
5686+
}),
56275687
]),
56285688
);
56295689

@@ -6439,22 +6499,24 @@ function formOverlayColumnsField(): z.ZodOptional<z.ZodNumber> {
64396499
* identity/round-trip fields a personalization PUT carries. Published as
64406500
* `VIEW_METADATA_MEMBERS.listOverlay`.
64416501
*
6442-
* `.strip()` is load-bearing, not leftover. `.extend()` INHERITS strictness, so
6443-
* closing `ListViewSchema` for authoring (#4001) silently made this overlay
6444-
* strict too — and this member exists precisely to carry Studio's auxiliary
6445-
* round-trip keys (`isPinned`, `sortOrder`, …), which the save keeps because
6446-
* they are declared. Strict here is a 422 on a shape the platform itself writes. The
6447-
* ledger names this as the trap to watch while batching: a response-side
6448-
* extension of an authoring schema must strip back, or an upstream field
6449-
* addition becomes a crash.
6502+
* [#26711] Closed at the top level, with its own refusal
6503+
* ({@link closeWireMember}). It used to `.strip()`: `.extend()` inherits
6504+
* strictness, so closing `ListViewSchema` for authoring (#4001) made this
6505+
* overlay strict too while Studio's round-trip keys (`isPinned`, `sortOrder`,
6506+
* …) were still undeclared, and strict would have been a 422 on a shape the
6507+
* platform itself writes. #20456 declared every one of them
6508+
* ({@link VIEW_CONSOLE_ROUND_TRIP_KEYS}), and #20051 made the save store the
6509+
* parsed body, so the strip had become a silent loss: a misspelt key answered
6510+
* success and was not stored. An undeclared key the console writes is now a
6511+
* refusal that names it — declare it here, with its meaning, as #20456 did.
64506512
*
64516513
* [#7741] `object` + `viewKind` are required on this arm (and its form
64526514
* sibling) — see {@link flattenedViewOverlayFields} for the ruling and the
64536515
* measured serving filter that decides exactly this pair.
64546516
*
64556517
* [#20051] …and `options` is DECLARED here, judged by
6456-
* {@link ListViewOverlayOptionsSchema}: `.strip()` re-opens the top level for
6457-
* round-trip keys, and a bag the renderer reads is not one of those.
6518+
* {@link ListViewOverlayOptionsSchema}: a bag the renderer reads is not a
6519+
* round-trip key.
64586520
*
64596521
* [#20186] This member judges `viewKind: 'list'` only (the form sibling
64606522
* `'form'` only), and it judges a column-less PATCH as well as a full inline
@@ -6470,19 +6532,19 @@ const ListViewOverlayWireSchema = lazySchema(() =>
64706532
// [#13216] Built from {@link ListViewShapeSchema}, not {@link ListViewSchema}:
64716533
// `flattenedViewOverlayFields()` re-declares `name` and `label`, and zod 4
64726534
// refuses to overwrite a key on an object that carries refinements. So the
6473-
// binding check is re-attached AFTER `.strip()` instead of inherited — this
6535+
// binding check is re-attached AFTER the close instead of inherited — this
64746536
// is the runtime write door (`PUT /api/v1/meta/view`), the one an MCP/AI
64756537
// author reaches, so it is the last place the refusals may go missing.
64766538
// `viewDoorsCarryingObjectLevelChecks` in `view.test.ts` fails if any of the
64776539
// three attachment points is dropped.
6478-
ListViewShapeSchema.extend({
6540+
closeWireMember(ListViewShapeSchema.extend({
64796541
...flattenedViewOverlayFields('list'),
64806542
options: ListViewOverlayOptionsSchema.optional(),
64816543
...listOverlayPatchFields(),
64826544
// [#20456] The console's round-trip keys on this row shape, declared so
6483-
// the parse keeps them instead of `.strip()`ping them unread.
6545+
// the parse keeps them.
64846546
...listOverlayRoundTripFields(),
6485-
}).strip()
6547+
}), LIST_OVERLAY_WIRE_SURFACE)
64866548
.superRefine(checkListOverlayTypeNeedsColumns)
64876549
.superRefine(checkListViewCalendarVisualization)
64886550
.superRefine(checkListViewChartBinding)
@@ -6492,7 +6554,8 @@ const ListViewOverlayWireSchema = lazySchema(() =>
64926554
/**
64936555
* [#6391] Member 4 of {@link ViewMetadataSchema} — a flattened runtime FORM
64946556
* overlay, published as `VIEW_METADATA_MEMBERS.formOverlay`. Same construction
6495-
* and the same `.strip()` rationale as {@link ListViewOverlayWireSchema}.
6557+
* as {@link ListViewOverlayWireSchema}, and closed at the top level the same way
6558+
* (#26711).
64966559
*
64976560
* [#20051] `options` is pinned ABSENT here — see
64986561
* {@link FORM_OVERLAY_OPTIONS_REFUSED} for the fall-through it closes.
@@ -6508,11 +6571,11 @@ const FormViewOverlayWireSchema = lazySchema(() =>
65086571
// (`columns`, see {@link formOverlayColumnsField}), and {@link FormViewSchema}
65096572
// carries refinements, which `.extend()` refuses to combine with an overwrite.
65106573
// The two differ in that throw only — the refinements ride along either way.
6511-
FormViewSchema.safeExtend({
6574+
closeWireMember(FormViewSchema.safeExtend({
65126575
...flattenedViewOverlayFields('form'),
65136576
options: z.undefined({ error: () => FORM_OVERLAY_OPTIONS_REFUSED }).optional(),
65146577
columns: formOverlayColumnsField(),
6515-
}).strip(),
6578+
}), FORM_OVERLAY_WIRE_SURFACE),
65166579
);
65176580

65186581
/**

0 commit comments

Comments
 (0)