Skip to content

Commit 5ba1e15

Browse files
committed
feat(data-objectstack): the bundle goes through the client's conditional getAppBundle, typed by the spec's bundle response
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibzFu8iUogiZhxL9tAo
1 parent ceaa10d commit 5ba1e15

6 files changed

Lines changed: 23 additions & 21 deletions

File tree

‎.changeset/27627-console-app-metadata-bundle.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ feat(console): entering an app loads its metadata bundle once, and a record open
88
Clause-②: no
99
Metadata-protocol: none
1010

11-
Entering an app now loads that app's metadata bundle (`GET /api/v1/meta/app/{appId}/bundle`) in one request, through the new `ObjectStackAdapter.loadAppBundle(appId)`. The bundle holds the app, the objects its navigation reaches together with the objects that reference them, and their views, pages and dashboards. Re-entering the app sends `If-None-Match` with the held `ETag` exactly as served, and a `304` keeps the bundle the console already holds. A bundle served `no-store` answers the reads that waited on it and is not kept.
11+
Entering an app now loads that app's metadata bundle (`GET /api/v1/meta/app/{appId}/bundle`) in one request, through the new `ObjectStackAdapter.loadAppBundle(appId)`. The bundle holds the app, the objects its navigation reaches together with the objects that reference them, and their views, pages and dashboards. Re-entering the app sends `If-None-Match` with the held `ETag` exactly as served, and a `304` keeps the bundle the console already holds. The request goes through the client's conditional `meta.getAppBundle(appId, { ifNoneMatch })`. A bundle served `no-store` with no `ETag` answers the reads that waited on it and is not kept.
1212

1313
- **Reads of bundled items.** A by-name metadata read of an item the bundle holds is answered from the bundle, as that item's own envelope, and never goes to its by-name route. This covers `getObjectSchema`, `getView`, `getPage`, `getApp`, `getItems`, and every caller of the client's `meta.getItem(type, name)`, including app-shell's `MetadataProvider`. A record open in a warm session therefore sends its page request and no metadata request. A cold open adds at most the one bundle request, sent alongside the page request.
1414
- **Reads of everything else.** Items outside the app (Studio's reads, a lookup to `sys_user`, an item the caller may not read) keep their by-name routes. A read with options does too. An item withheld from the caller is absent from the bundle and carries no name there, so its by-name read gives that item's own refusal.

‎content/docs/frontend/data-objectstack.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ pages and dashboards. Each one is the envelope its own
265265
- Calling `loadAppBundle` again for the same app sends `If-None-Match` with the
266266
held `ETag` exactly as served (a weak `W/` validator included), and a `304`
267267
keeps the bundle already held.
268-
- A bundle served `no-store` (the server could not settle a member's field
268+
- A bundle served `no-store` with no `ETag` (the server could not settle a member's field
269269
visibility) answers the reads that waited on it and is not kept. Later reads
270270
go by name until the app is entered again.
271271
- A metadata write through the client, or an `invalidateCache(key)` that names

‎ui/packages/app-shell/src/views/RecordDetailView.recordPagePayload-27627.test.tsx‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ const TOTAL: Record<string, number> = { os_27627_task: 7, os_27627_case: 4, os_2
9494

9595
interface Held { wave: number; method: string; path: string; body: any; released: boolean; release: () => void }
9696

97-
const json = (body: unknown) => new Response(JSON.stringify(body), { status: 200, headers: { 'content-type': 'application/json' } });
97+
const json = (body: unknown, headers: Record<string, string> = {}) =>
98+
new Response(JSON.stringify(body), { status: 200, headers: { 'content-type': 'application/json', ...headers } });
9899

99100
/** The page payload the route answers for `body`, for record `id`. */
100101
function pageAnswer(id: string, body: any) {
@@ -120,6 +121,9 @@ function pageAnswer(id: string, body: any) {
120121
const APP = 'demo';
121122
const BUNDLE = `/api/v1/meta/app/${APP}/bundle`;
122123

124+
/** The bundle carries its per-caller validator, as the route serves a bundle it may be kept by. */
125+
const BUNDLE_HEADERS = { ETag: 'W/"demo-bundle-1"', 'Cache-Control': 'private, no-cache' };
126+
123127
function answerFor(h: Held): unknown {
124128
if (h.path === BUNDLE) {
125129
const env = (type: string, item: { name: string }) => ({ type, name: item.name, item });
@@ -148,7 +152,7 @@ function heldTransport() {
148152
wave: state.wave, method, path,
149153
body: typeof init?.body === 'string' ? JSON.parse(init.body) : undefined,
150154
released: false,
151-
release: () => { if (h.released) return; h.released = true; resolve(json(answerFor(h))); },
155+
release: () => { if (h.released) return; h.released = true; resolve(json(answerFor(h), h.path === BUNDLE ? BUNDLE_HEADERS : {})); },
152156
};
153157
held.push(h);
154158
});

‎ui/packages/data-objectstack/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ dataSource.clearCache();
451451

452452
`loadAppBundle(appId)` loads an app's metadata bundle (`GET /api/v1/meta/app/{appId}/bundle`) in one request. The console calls it when it enters an app. A by-name read of an item the bundle holds is then answered from the bundle and never sent: `getObjectSchema`, `getView`, `getPage`, `getApp`, `getItems` and `getClient().meta.getItem(type, name)`. Items the bundle does not hold keep their by-name reads.
453453

454-
Calling `loadAppBundle` again for the same app sends `If-None-Match` with the held `ETag` exactly as served (a weak `W/` validator included), and a `304` keeps what is held. A bundle served `no-store` answers the reads that waited on it and is not kept. A metadata write through the client, or an `invalidateCache(key)` that names a bundled item, makes the next bundled read revalidate the bundle first. `clearCache()` drops the bundles.
454+
Calling `loadAppBundle` again for the same app sends `If-None-Match` with the held `ETag` exactly as served (a weak `W/` validator included), and a `304` keeps what is held. A bundle served `no-store` with no `ETag` answers the reads that waited on it and is not kept. A metadata write through the client, or an `invalidateCache(key)` that names a bundled item, makes the next bundled read revalidate the bundle first. `clearCache()` drops the bundles.
455455

456456
### Cache Configuration
457457

‎ui/packages/data-objectstack/src/app-bundle.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
* asks the server and reports what it answered.
3434
*/
3535

36+
import type { AppMetadataBundleResponse } from '@objectstack/spec/api';
37+
3638
/** One bundled item. */
3739
export interface AppBundleEntry {
3840
/** The item's document (the envelope's `item`). */
@@ -186,17 +188,17 @@ const BUNDLE_LISTS: ReadonlyArray<readonly [key: string, type: string]> = [
186188
];
187189

188190
/**
189-
* Index the bundle's answer (`AppMetadataBundleResponse`, `@objectstack/spec/api`)
191+
* Index the bundle's answer (`AppMetadataBundleResponseSchema`, `@objectstack/spec/api`)
190192
* by type and name. The answer is bare, as the `/meta` item reads answer: the
191193
* app under `app`, and the other items listed under `objects`, `views`,
192194
* `pages` and `dashboards`. Every member is the envelope its own
193195
* `GET /meta/{type}/{name}` answers (`GetMetaItemResponse`), so it is kept
194196
* whole and handed back as that read's answer.
195197
*/
196-
export function indexAppBundle(body: unknown): AppBundleItems {
198+
export function indexAppBundle(body: AppMetadataBundleResponse): AppBundleItems {
197199
const items: AppBundleItems = new Map();
198200
if (!body || typeof body !== 'object') return items;
199-
const bag = body as Record<string, unknown>;
201+
const bag = body as unknown as Record<string, unknown>;
200202
const put = (type: string, member: unknown) => {
201203
if (!member || typeof member !== 'object') return;
202204
const envelope = member as Record<string, unknown>;

‎ui/packages/data-objectstack/src/index.ts‎

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4549,21 +4549,17 @@ export class ObjectStackAdapter<T = unknown> implements DataSource<T> {
45494549
/** The one round trip behind {@link loadAppBundle}. */
45504550
private async requestAppBundle(appId: string, etag: string | undefined): Promise<AppBundleAnswer> {
45514551
await this.connect();
4552-
const url = `${this.baseUrl}/api/v1/meta/app/${encodeURIComponent(appId)}/bundle`;
4553-
const headers: Record<string, string> = { 'Content-Type': 'application/json', ...this.getAuthHeaders() };
4554-
if (etag) headers['If-None-Match'] = etag;
4555-
// `no-store`: the validator is this adapter's to send, so the browser's
4556-
// HTTP cache neither answers for the server nor hides its `304`.
4557-
const res = await this.fetchImpl(url, { method: 'GET', headers, cache: 'no-store' });
4558-
if (res.status === 304) return { status: 'unchanged' };
4559-
if (!res.ok) return { status: 'absent' };
4560-
const items = indexAppBundle(await res.json());
4552+
// The client's conditional read: a `304` is answered as `notModified`,
4553+
// any other refusal rejects (the store reads that as no bundle).
4554+
const answer = await this.client.meta.getAppBundle(appId, etag ? { ifNoneMatch: etag } : undefined);
4555+
if (answer.notModified) return { status: 'unchanged' };
4556+
const items = indexAppBundle(answer.data);
45614557
// A bundle holding a member whose field visibility the server could not
4562-
// settle is served `no-store`, with no validator: it answers the reads
4558+
// settle is served `no-store` with no validator: it answers the reads
45634559
// that waited on it and is not kept.
4564-
if (/\bno-store\b/i.test(res.headers.get('cache-control') ?? '')) return { status: 'fresh', items, noStore: true };
4565-
// The validator goes back byte-for-byte, a weak `W/` prefix included.
4566-
return { status: 'fresh', etag: res.headers.get('etag') ?? undefined, items };
4560+
if (!answer.etag) return { status: 'fresh', items, noStore: true };
4561+
// The validator goes back as the server spelled it, a weak `W/` included.
4562+
return { status: 'fresh', etag: `${answer.etag.weak ? 'W/' : ''}"${answer.etag.value}"`, items };
45674563
}
45684564

45694565
/**

0 commit comments

Comments
 (0)