Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
222 changes: 9 additions & 213 deletions content/docs/references/ui/view.mdx

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions docs/audits/2026-07-unknown-key-strictness-ledger.counts/ui.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The `strict` column is the one the campaign schedules against; it counts both th

| Dir | Sites | strict | passthrough | catchall | strip |
|---|---|---|---|---|---|
| `ui/` | 233 | 223 | 6 | 0 | 4 |
| `ui/` | 231 | 221 | 6 | 0 | 4 |

## `ui/` — sites

Expand All @@ -45,25 +45,25 @@ classify and is not listed (it becomes reportable the day it grows its first sit
| `report.zod.ts` | 4 |
| `responsive.zod.ts` | 1 |
| `sharing.zod.ts` | 1 |
| `view.zod.ts` | 67 |
| `view.zod.ts` | 65 |
| `widget.zod.ts` | 1 |
| **total** | **233** |
| **total** | **231** |

## `ui/` — open

Per file, how many of its sites still silently discard unknown keys. The `Class`
column that decides the bucket split is hand-written in the ledger; the arithmetic
over it is here.

**4 strip of 233**, in 4 file(s).
**4 strip of 231**, in 4 file(s).

| File | Strip | Sites |
|---|---|---|
| `action-params.zod.ts` | 1 | 1 |
| `app.zod.ts` | 1 | 20 |
| `view.zod.ts` | 1 | 67 |
| `view.zod.ts` | 1 | 65 |
| `widget.zod.ts` | 1 | 1 |
| **total** | **4** | **233** |
| **total** | **4** | **231** |

| Bucket | Sites |
|---|---|
Expand Down
38 changes: 30 additions & 8 deletions packages/metadata-protocol/src/protocol-form-reads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,17 +369,33 @@ function projectedServed(item: Record<string, unknown>, packageId: string | unde
}

/**
* [ADR-0159 D5] The effective `form` list ({@link FormReadHost}): the generic
* `form` list, the projection of the served `view` list, and the cross-type
* resolution at each address whose package authors the form as a `form` item.
* See the module header for the three readings and how they combine.
* [ADR-0159 D7] Which reading of the stored old shapes a `form` read takes.
*
* - `'major-19'`, every read that serves or executes a form: the projection
* serves no content. A stored old-shape row is never a served item, and
* where the served-row order picks one at a package's address nothing of
* that name is served from the package while it stands (rule 11's kept
* replacement check, "After the major").
* - `'before-the-switch'`, the stored-form census alone (`listStoredForms`,
* ADR-0159 D7-c): what the read served before the switch, the projected
* items included, so that the ceremony moves exactly the forms served today.
*/
export type StoredShapeReading = 'major-19' | 'before-the-switch';

/**
* [ADR-0159 D5, D7] The effective `form` list ({@link FormReadHost}): the
* generic `form` list, the projection of the served `view` list, and the
* cross-type resolution at each address whose package authors the form as a
* `form` item. See the module header for the three readings and how they
* combine, and {@link StoredShapeReading} for what the projection serves.
*/
export async function readEffectiveForms(
host: FormReadHost,
request: { type: string; packageId?: string; names?: readonly string[]; previewDrafts?: boolean },
audience: 'served' | 'execution',
reading: StoredShapeReading = 'major-19',
): Promise<unknown[]> {
return (await readEffectiveFormList(host, request, audience)).items;
return (await readEffectiveFormList(host, request, audience, reading)).items;
}

/**
Expand Down Expand Up @@ -411,9 +427,12 @@ export async function readEffectiveFormList(
host: FormReadHost,
request: { type: string; packageId?: string; names?: readonly string[]; previewDrafts?: boolean },
audience: 'served' | 'execution',
reading: StoredShapeReading = 'major-19',
): Promise<{ type: string; items: unknown[] } & Record<string, unknown>> {
// Every reading below reads through one request scope: each stored row set once.
host = formRequestScope(host);
// [ADR-0159 D7] Whether a projected item is served (the census's reading only).
const servesProjection = reading === 'before-the-switch';
const { packageId: scope, names, ...rest } = request;
const unscoped = { ...rest, type: 'form', ...(names !== undefined ? { names } : {}) };
const genericList = await host.readFlattenedMetaItems(unscoped, audience) as { items: unknown[] } & Record<string, unknown>;
Expand Down Expand Up @@ -506,8 +525,10 @@ export async function readEffectiveFormList(
put(key, item);
continue;
}
// A stored `view` row is the served row at this address.
if (served.holding.kind === 'form') put(key, projectedServed(served.holding.item, pkg));
// A stored `view` row is the served row at this address. [ADR-0159 D7]
// Since protocol 19 it serves no content: nothing of the name is served
// from the package while it stands (rule 11's kept replacement check).
if (servesProjection && served.holding.kind === 'form') put(key, projectedServed(served.holding.item, pkg));
// …else the closed reading: nothing is served for the name from the package.
}
// A package that authors the form but has no item in the generic list (its
Expand Down Expand Up @@ -541,7 +562,8 @@ export async function readEffectiveFormList(
continue;
}
}
put(key, item);
// [ADR-0159 D7] Since protocol 19 a projected item is not served.
if (servesProjection) put(key, item);
}
// …and a package-less `form` row that stood in at no such address is
// listed as its own item, as the generic list serves it.
Expand Down
30 changes: 28 additions & 2 deletions packages/metadata-protocol/src/protocol-meta-list-reads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import { ITEM_KEY_DISCRIMINATORS, isTenantAuthored, packageDependencyClosure, pairsOf } from '@objectstack/metadata-core';
import { PLURAL_TO_SINGULAR, SINGULAR_TO_PLURAL } from '@objectstack/spec/shared';
import { isAggregatedViewContainer } from '@objectstack/spec/ui';
import { isAggregatedViewContainer, isServedViewItem } from '@objectstack/spec/ui';
import {
type ItemAddress,
type ItemLock,
Expand Down Expand Up @@ -96,7 +96,33 @@ export async function getMetaItems(host: FormReadHost, request: { type: string;
// generic read where the list names no package (`readEffectiveFormList`).
if (canonical.type === 'form') return effectiveFormList(host, canonical, 'served');
// Inside a form request's reading (`readInFormRequest`), through its scope.
return inFormRequestScope(host).readFlattenedMetaItems(canonical, 'served');
const answer = await inFormRequestScope(host).readFlattenedMetaItems(canonical, 'served');
// [ADR-0159 D7] A `view` read serves lists only.
return canonical.type === 'view' ? servedViewList(answer) : answer;
}

/**
* [ADR-0159 D7] The `view` list a `view` read serves: lists only. A stored
* old-shape row is not rewritten and not refused (constraint: the stored seam
* stays on STORED_ROWS_NOT_REWRITTEN): its form items are left out of the
* served answer, and every reader of stored forms reads them raw
* ({@link getViewItemsWithStoredForms}, the stored-row reads of
* `protocol-form-reads.ts`). A new envelope; the scoped read it came from is
* shared by the request's other readings and is never mutated.
*/
function servedViewList<T extends { items: unknown[] }>(answer: T): T {
const items = answer.items.filter(isServedViewItem);
return items.length === answer.items.length ? answer : { ...answer, items };
}

/**
* The body of `ObjectStackProtocolImplementation#getViewItemsWithStoredForms`;
* the method's docblock there is its contract.
*/
export async function getViewItemsWithStoredForms(host: FormReadHost, request: { type?: string; packageId?: string; previewDrafts?: boolean }) {
// Inside a form request's reading (`readInFormRequest`), through its scope:
// the same read the served `view` list filters.
return inFormRequestScope(host).readFlattenedMetaItems({ ...request, type: 'view' }, 'served');
}

/** The body of `ObjectStackProtocolImplementation#getMetaItemsForExecution`; the method's docblock there is its contract. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1757,10 +1757,11 @@ function collectFormActionTargets(value: unknown, out: Set<string>, depth = 0):
export async function listStoredForms(host: StoredFormCensusHost): Promise<StoredFormCensus> {
const places = await storedFormPlaces(host);
const installed = installedManifestsOfEngine(host.engine);
// The forms the read serves today, by package and name: the list the doors read.
// The forms the read serves today, by package and name: the list the doors
// read before the switch, the projected items included (ADR-0159 D7).
const servedNow = new Set<string>();
const servedNames = new Set<string>();
for (const item of await readEffectiveForms(host, { type: 'form' }, 'served')) {
for (const item of await readEffectiveForms(host, { type: 'form' }, 'served', 'before-the-switch')) {
const { name, _packageId: packageId } = (item ?? {}) as { name?: unknown; _packageId?: unknown };
if (typeof name !== 'string') continue;
servedNames.add(name);
Expand Down
18 changes: 18 additions & 0 deletions packages/metadata-protocol/src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ import {
getMetaItems,
getMetaItemsForExecution,
getMetaItemsPerPackage,
getViewItemsWithStoredForms,
readFlattenedMetaItems,
} from './protocol-meta-list-reads.js';
// [#25467 E2 cut 1b] The metadata item reads and the layered reads.
Expand Down Expand Up @@ -3530,6 +3531,23 @@ export class ObjectStackProtocolImplementation implements
return getMetaItemsPerPackage(protocolHost(this), request);
}

/**
* [ADR-0159 D7] The `view` list {@link getMetaItems} serves, WITH the form
* items of the stored old-shape rows it leaves out: a `view` read serves
* lists only since protocol 19, and a stored old-shape row is neither
* rewritten nor dropped by a read. A server-only extension, kept for one
* reader: **the anonymous form doors' withdrawal judgement**
* (`form-routes.ts` in `@objectstack/rest`), which reads every body the
* doors honoured (ADR-0159 D6 rule 10, the kept reader) and is never judged
* against a narrower layer than this one.
*
* ⛔ Never call this from a door that serves a caller a document: every
* such door serves {@link getMetaItems}.
*/
async getViewItemsWithStoredForms(request: { packageId?: string; previewDrafts?: boolean } = {}) {
return getViewItemsWithStoredForms(protocolHost(this), request);
}

/** Contract: {@link readUnreadableFormBodies} [ADR-0159 D6 rule 7]; a server-only extension the anonymous form doors feature-detect. */
async getUnreadableFormBodies(): Promise<UnreadableFormBody[]> {
return readUnreadableFormBodies(protocolHost(this));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,18 @@
// version of this test that can fail when the producer drifts.

import { describe, it, expect } from 'vitest';
import { GetUiViewResponseSchema } from '@objectstack/spec/api';
import { z } from 'zod';
import { GetUiViewResponseSchema, type GetUiViewFormScaffold } from '@objectstack/spec/api';
import { FormViewSchema } from '@objectstack/spec/ui';
import { ObjectStackProtocolImplementation } from './protocol.js';

/**
* [ADR-0159 D7] The `type: 'form'` answer, `GetUiViewFormScaffold`: a view
* holds lists only since @objectstack/spec 19, so the form scaffold is not a
* `ViewSchema` and is parsed here against the form body schema it carries.
*/
const FormScaffoldSchema = z.strictObject({ object: z.string(), form: FormViewSchema });

const SCHEMA = {
name: 'account',
label: 'Account',
Expand Down Expand Up @@ -65,13 +74,41 @@ describe('[#5948] getUiView emits a body that satisfies its own declared schema'
expect(parsed.success).toBe(true);
});

it('form branch parses GREEN against GetUiViewResponseSchema', async () => {
it('form branch parses GREEN as the form scaffold: `{ object, form }`, its `form` a form body', async () => {
const p = protocolFor();
const body = await p.getUiView({ object: 'account', type: 'form' });

const parsed = GetUiViewResponseSchema.safeParse(body);
const parsed = FormScaffoldSchema.safeParse(body);
expect(explain(parsed)).toBe('GREEN');
expect(parsed.success).toBe(true);
// …and it is not a view: `ViewSchema.form` is retired in protocol 19.
expect(GetUiViewResponseSchema.safeParse(body).success).toBe(false);
});

it('the form answer is byte-equal to the protocol-18 answer', async () => {
const p = protocolFor();
const body = await p.getUiView({ object: 'account', type: 'form' });
const field = (name: string, label: unknown, type: string, required?: boolean, colSpan = 1) => ({
field: name, label, required, readonly: undefined, type, colSpan, span: 'auto',
});
const expected: GetUiViewFormScaffold = {
object: 'account',
form: {
type: 'simple',
sections: [{
label: 'General Information',
columns: 2,
collapsible: false,
collapsed: false,
fields: [
field('name', 'Name', 'text', true),
field('status', 'Status', 'text'),
field('notes', 'Notes', 'textarea', undefined, 2),
] as any,
}],
},
};
expect(JSON.stringify(body)).toBe(JSON.stringify(expected));
});

// The three keys this issue removed, pinned by name. The GREEN assertions
Expand Down
Loading
Loading