Skip to content

Commit 1998374

Browse files
committed
fix(data-objectstack): a no-store bundle is not kept; the weak validator goes back as served
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibzFu8iUogiZhxL9tAo
1 parent c6e775c commit 1998374

6 files changed

Lines changed: 75 additions & 24 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`, and a `304` keeps the bundle the console already holds.
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.
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: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,12 @@ pages and dashboards. Each one is the envelope its own
262262
- An item the bundle does not hold keeps its by-name read. That covers objects
263263
outside the app, reads made with options, and an item withheld from the
264264
caller, which is absent from the bundle and gets its own read's refusal.
265-
- Calling `loadAppBundle` again for the same app sends `If-None-Match`, and a
266-
`304` keeps the bundle already held.
265+
- Calling `loadAppBundle` again for the same app sends `If-None-Match` with the
266+
held `ETag` exactly as served (a weak `W/` validator included), and a `304`
267+
keeps the bundle already held.
268+
- A bundle served `no-store` (the server could not settle a member's field
269+
visibility) answers the reads that waited on it and is not kept. Later reads
270+
go by name until the app is entered again.
267271
- A metadata write through the client, or an `invalidateCache(key)` that names
268272
a bundled item, makes the next bundled read revalidate the bundle first. So
269273
does an answer older than the cache TTL. `clearCache()` drops every bundle,

‎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`, and a `304` keeps what is held. 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` 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: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222
* included (Studio, objects outside the app, an item withheld from the
2323
* caller);
2424
* - re-entering an app, or reading past the adapter's cache lifetime, asks
25-
* again with `If-None-Match`: a `304` keeps what is held;
25+
* again with `If-None-Match`, the validator sent back byte-for-byte: a
26+
* `304` keeps what is held;
27+
* - a bundle served `no-store` answers the reads that waited on it and is
28+
* not kept: later reads go by name until the app is entered again;
2629
* - a metadata write the adapter sees, or an invalidation a host asks for,
2730
* marks the bundles stale, and the next bundled read asks again first.
2831
*
@@ -43,8 +46,11 @@ export type AppBundleItems = Map<string, Map<string, AppBundleEntry>>;
4346

4447
/** What one bundle request obtained. */
4548
export type AppBundleAnswer =
46-
/** A `200`: the bundle, and its validator when the server sent one. */
47-
| { status: 'fresh'; etag?: string; items: AppBundleItems }
49+
/**
50+
* A `200`: the bundle, and its validator when the server sent one.
51+
* `noStore`: served `no-store`, so it answers the reads waiting on it and is not kept.
52+
*/
53+
| { status: 'fresh'; etag?: string; items: AppBundleItems; noStore?: boolean }
4854
/** A `304`: what is held is current. */
4955
| { status: 'unchanged' }
5056
/** No bundle for this app: refused, unknown, or no such route on this server. */
@@ -59,7 +65,8 @@ interface AppBundleState {
5965
/** When the server last answered for this bundle (a `200` or a `304`). */
6066
checkedAt: number;
6167
stale: boolean;
62-
inflight: Promise<void> | null;
68+
/** The load on the wire; it settles with the items its answer gives the reads waiting on it. */
69+
inflight: Promise<AppBundleItems> | null;
6370
}
6471

6572
/**
@@ -86,8 +93,7 @@ export class AppBundleStore {
8693
if (!appId) return Promise.resolve();
8794
this.active = appId;
8895
const state = this.bundles.get(appId);
89-
if (state?.inflight) return state.inflight;
90-
return this.ask(appId);
96+
return (state?.inflight ?? this.ask(appId)).then(() => undefined);
9197
}
9298

9399
/**
@@ -98,12 +104,12 @@ export class AppBundleStore {
98104
async read(type: string, name: string): Promise<AppBundleEntry | undefined> {
99105
const appId = this.active;
100106
if (!appId) return undefined;
101-
let state = this.bundles.get(appId);
107+
const state = this.bundles.get(appId);
102108
if (!state) return undefined;
103-
if (state.inflight) await state.inflight;
104-
else if (state.stale || Date.now() - state.checkedAt >= this.ttlMs) await this.ask(appId);
105-
state = this.bundles.get(appId);
106-
return state?.items.get(type)?.get(name);
109+
let items = state.items;
110+
if (state.inflight) items = await state.inflight;
111+
else if (state.stale || Date.now() - state.checkedAt >= this.ttlMs) items = await this.ask(appId);
112+
return items.get(type)?.get(name);
107113
}
108114

109115
/** Whether any bundle held this session holds `type` / `name`. */
@@ -138,7 +144,7 @@ export class AppBundleStore {
138144
}
139145
}
140146

141-
private ask(appId: string): Promise<void> {
147+
private ask(appId: string): Promise<AppBundleItems> {
142148
const held = this.bundles.get(appId);
143149
const state: AppBundleState = held ?? { appId, items: new Map(), checkedAt: 0, stale: true, inflight: null };
144150
this.bundles.set(appId, state);
@@ -147,17 +153,24 @@ export class AppBundleStore {
147153
.then((answer) => {
148154
// A `clear()` while this was out replaced the state: this answer
149155
// belongs to the world it left, so it is dropped.
150-
if (this.bundles.get(appId) !== state) return;
156+
const current = this.bundles.get(appId);
157+
if (current !== state) return current?.items ?? new Map();
151158
state.inflight = null;
152159
state.checkedAt = Date.now();
153160
state.stale = false;
161+
if (answer.status === 'fresh' && answer.noStore) {
162+
state.items = new Map();
163+
state.etag = undefined;
164+
return answer.items;
165+
}
154166
if (answer.status === 'fresh') {
155167
state.items = answer.items;
156168
state.etag = answer.etag;
157169
} else if (answer.status === 'absent') {
158170
state.items = new Map();
159171
state.etag = undefined;
160172
}
173+
return state.items;
161174
});
162175
state.inflight = inflight;
163176
return inflight;

‎ui/packages/data-objectstack/src/appBundle-27627.test.ts‎

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919
* never asked by name (objects, views, pages, dashboards, the app);
2020
* - an item the bundle does not hold, and a call with options, keep the
2121
* by-name route;
22-
* - re-entering sends `If-None-Match`, and a `304` keeps what is held;
22+
* - re-entering sends `If-None-Match` (a weak validator byte-for-byte), and a
23+
* `304` keeps what is held;
2324
* - an invalidation naming a bundled item, and any metadata write through the
2425
* client, make the next bundled read ask the bundle again first;
2526
* - a bundled object carries its envelope's `sortability`, as its by-name read does;
26-
* - a cache clear, or a bundle served with no validator, downloads it again;
27+
* - a cache clear downloads it again;
28+
* - a bundle served `no-store` answers the reads that waited on it and is not kept;
2729
* - a refused bundle leaves every read to its by-name route.
2830
*/
2931
import { describe, it, expect, vi } from 'vitest';
@@ -243,17 +245,43 @@ describe('objectstack#27627 — the app metadata bundle', () => {
243245
expect(readObjectSortability(await ds.getObjectSchema('b27627_contact'))?.fields.name?.sortable).toBe(true);
244246
});
245247

246-
it('a bundle served with no validator (`no-store`) is downloaded again, never revalidated', async () => {
248+
it('a weak validator goes back byte-for-byte, its `W/` prefix included', async () => {
247249
const { ds, held } = await heldAdapter();
248250
const first = ds.loadAppBundle(APP);
249251
await drain();
252+
held[0].respond(200, bundle(), { ETag: 'W/"sha256-Zm9vYmFy"' });
253+
await first;
254+
const again = ds.loadAppBundle(APP);
255+
await drain();
256+
expect(held[1].headers['if-none-match']).toBe('W/"sha256-Zm9vYmFy"');
257+
held[1].respond(304);
258+
await again;
259+
});
260+
261+
it('a bundle served `no-store` answers the reads that waited on it, and is not kept', async () => {
262+
const { ds, held } = await heldAdapter();
263+
const first = ds.loadAppBundle(APP);
264+
const waiting = ds.getObjectSchema('b27627_contact');
265+
await drain();
266+
// A member under an undetermined posture: no validator, not to be cached.
250267
held[0].respond(200, bundle(), { 'Cache-Control': 'private, no-store' });
251268
await first;
269+
expect((await waiting as any).label).toBe('Contact');
270+
expect(held).toHaveLength(1);
271+
272+
// Nothing was kept: the next read of a member goes by name.
273+
const later = ds.getClient().meta.getItem('object', 'b27627_task');
274+
await drain();
275+
expect(held[1].path).toBe('/api/v1/meta/object/b27627_task');
276+
held[1].respond(200, { success: true, data: { type: 'object', name: 'b27627_task', item: task } });
277+
await later;
278+
279+
// Re-entering downloads it again, with no validator.
252280
const again = ds.loadAppBundle(APP);
253281
await drain();
254-
expect(held[1].path).toBe(BUNDLE_PATH);
255-
expect(held[1].headers['if-none-match']).toBeUndefined();
256-
held[1].respond(200, bundle());
282+
expect(held[2].path).toBe(BUNDLE_PATH);
283+
expect(held[2].headers['if-none-match']).toBeUndefined();
284+
held[2].respond(200, bundle(), { 'Cache-Control': 'private, no-store' });
257285
await again;
258286
});
259287

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4534,7 +4534,13 @@ export class ObjectStackAdapter<T = unknown> implements DataSource<T> {
45344534
const res = await this.fetchImpl(url, { method: 'GET', headers, cache: 'no-store' });
45354535
if (res.status === 304) return { status: 'unchanged' };
45364536
if (!res.ok) return { status: 'absent' };
4537-
return { status: 'fresh', etag: res.headers.get('etag') ?? undefined, items: indexAppBundle(await res.json()) };
4537+
const items = indexAppBundle(await res.json());
4538+
// A bundle holding a member whose field visibility the server could not
4539+
// settle is served `no-store`, with no validator: it answers the reads
4540+
// that waited on it and is not kept.
4541+
if (/\bno-store\b/i.test(res.headers.get('cache-control') ?? '')) return { status: 'fresh', items, noStore: true };
4542+
// The validator goes back byte-for-byte, a weak `W/` prefix included.
4543+
return { status: 'fresh', etag: res.headers.get('etag') ?? undefined, items };
45384544
}
45394545

45404546
/**

0 commit comments

Comments
 (0)