Skip to content

Commit 1f8915d

Browse files
committed
docs(data-objectstack): the app metadata bundle; app-shell pins the app entry load
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibzFu8iUogiZhxL9tAo
1 parent 3ab5016 commit 1f8915d

4 files changed

Lines changed: 190 additions & 1 deletion

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@object-ui/data-objectstack': patch
3+
'@object-ui/app-shell': patch
4+
---
5+
6+
feat(console): entering an app loads its metadata bundle once, and a record open reads no metadata
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
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.
12+
13+
- **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.
14+
- **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.
15+
- **Staying current.** A metadata write through any of the client's write doors, or a host invalidation that names a bundled item, makes the next bundled read revalidate the bundle first. An answer older than the adapter cache's lifetime is revalidated the same way. A cache clear, which happens on an organization, session or locale switch, downloads the bundle again with no validator.
16+
- **No bundle.** If the bundle is refused, the app is unknown, or the server has no such route, every read goes to its by-name route as before.

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,19 +234,44 @@ either form):
234234

235235
- `connect()` - Establish the connection (called lazily by every operation)
236236
- `getCacheStats()` / `invalidateCache(key?)` / `clearCache()` - Cache control
237+
- `loadAppBundle(appId)` - Load the app's metadata bundle (`GET /meta/app/{appId}/bundle`), or revalidate the one held with `If-None-Match`; by-name metadata reads of the items it holds are answered from it (see [App metadata bundle](#app-metadata-bundle))
237238
- `getClient()` - Access the underlying `@objectstack/client` instance
238239
- `getConnectionState()` / `isConnected()` - Connection introspection
239240
- `onConnectionStateChange(listener)` - Subscribe to state changes (returns unsubscribe)
240241
- `onBatchProgress(listener)` - Subscribe to bulk progress (returns unsubscribe)
241242

242-
Those six bullets cover nine members, and they are the documented subset.
243+
Those seven bullets cover ten members, and they are the documented subset.
243244
`ObjectStackAdapter` declares more members beyond `DataSource` than these —
244245
`Exclude<keyof ObjectStackAdapter<unknown>, keyof DataSource<unknown>>` lists
245246
them all; the rest are lower-level seams — client discovery, cache-key
246247
invalidation, dataset and dashboard access and advisory subscriptions among
247248
them — which this page does not document and which carry no compatibility
248249
promise here.
249250

251+
### App metadata bundle
252+
253+
The console calls `loadAppBundle(appName)` when it enters an app. One request,
254+
`GET /api/v1/meta/app/{appId}/bundle`, returns the app, the objects its
255+
navigation reaches with the objects that reference them, and their views,
256+
pages and dashboards. Each one is the envelope its own
257+
`GET /meta/{type}/{name}` read would return to this caller.
258+
259+
- A by-name read of an item the bundle holds is answered from the bundle and
260+
never sent: `getObjectSchema`, `getView`, `getPage`, `getApp`, `getItems`,
261+
and the client's `meta.getItem(type, name)` with no options.
262+
- An item the bundle does not hold keeps its by-name read. That covers objects
263+
outside the app, reads made with options, and an item withheld from the
264+
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.
267+
- A metadata write through the client, or an `invalidateCache(key)` that names
268+
a bundled item, makes the next bundled read revalidate the bundle first. So
269+
does an answer older than the cache TTL. `clearCache()` drops every bundle,
270+
and the next read downloads it again.
271+
272+
If the bundle is refused, or the server has no such route, every read stays on
273+
its by-name route.
274+
250275
### Per-element data binding
251276

252277
A schema node's `dataSource` key is the spec's `ElementDataSource` (validated by
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
/**
10+
* objectstack#27627 — entering an app loads its metadata bundle, by the app's
11+
* NAME (the address `GET /meta/app/:name/bundle` takes), on the package-id
12+
* route the sidebar builds and on the name alias alike; staying in the app
13+
* asks it once.
14+
*
15+
* Measured from a real `AppContent` mount (the
16+
* `AppContent.recentOnPackageRoute-11818` harness); the adapter's
17+
* `loadAppBundle` is the observation point.
18+
*/
19+
20+
import '@testing-library/jest-dom/vitest';
21+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
22+
import React from 'react';
23+
import { render, cleanup, screen } from '@testing-library/react';
24+
import { MemoryRouter, Routes, Route } from 'react-router-dom';
25+
import { createI18n, I18nProvider } from '@object-ui/i18n';
26+
27+
vi.mock('@object-ui/plugin-form', async (importOriginal) => ({
28+
...(await importOriginal<Record<string, unknown>>()),
29+
ModalForm: () => null,
30+
}));
31+
32+
vi.mock('@object-ui/plugin-designer', async (importOriginal) => ({
33+
...(await importOriginal<typeof import('@object-ui/plugin-designer')>()),
34+
CreateAppPage: () => <div data-testid="create-app-page" />,
35+
EditAppPage: () => <div data-testid="edit-app-page" />,
36+
DashboardDesignPage: () => <div data-testid="dashboard-design-page" />,
37+
}));
38+
39+
vi.mock('../../layout/ConsoleLayout', () => ({
40+
ConsoleLayout: ({ children }: { children?: React.ReactNode }) => (
41+
<div data-testid="console-layout">{children}</div>
42+
),
43+
}));
44+
vi.mock('../../chrome/CommandPalette', () => ({ CommandPalette: () => null }));
45+
vi.mock('../../chrome/KeyboardShortcutsDialog', () => ({ KeyboardShortcutsDialog: () => null }));
46+
vi.mock('../../chrome/OnboardingWalkthrough', () => ({ OnboardingWalkthrough: () => null }));
47+
vi.mock('../../views/ObjectView', () => ({ ObjectView: () => <div data-testid="object-view" /> }));
48+
vi.mock('../../views/RecordDetailView', () => ({ RecordDetailView: () => null }));
49+
50+
vi.mock('@object-ui/auth', async (importOriginal) => ({
51+
...(await importOriginal<Record<string, unknown>>()),
52+
useAuth: () => ({
53+
user: { id: 'u1', name: 'Ada', email: 'ada@example.com', role: 'user' },
54+
getAuthConfig: async () => ({ features: {} }),
55+
activeOrganization: null,
56+
}),
57+
useWorkspaceAdminStatus: () => ({ isAdmin: true, isResolved: true }),
58+
}));
59+
60+
const { loadAppBundle } = vi.hoisted(() => ({ loadAppBundle: vi.fn(async (_appId: string) => {}) }));
61+
const dataSourceStub = {
62+
onConnectionStateChange: () => () => {},
63+
getConnectionState: () => 'connected',
64+
loadAppBundle,
65+
};
66+
vi.mock('../../providers/AdapterProvider', async (importOriginal) => ({
67+
...(await importOriginal<Record<string, unknown>>()),
68+
useAdapter: () => dataSourceStub,
69+
}));
70+
71+
/** The showcase app as the catalog serves it: a name AND a package id. */
72+
const APPS = [
73+
{
74+
name: 'showcase_app',
75+
label: 'Showcase',
76+
_packageId: 'com.example.showcase',
77+
isDefault: true,
78+
navigation: [{ id: 'tasks', type: 'object', objectName: 'showcase_task', label: 'Tasks' }],
79+
},
80+
];
81+
82+
const OBJECTS = [{ name: 'showcase_task', label: 'Task', pluralLabel: 'Tasks', fields: { title: { type: 'text' } } }];
83+
84+
// One value for the whole run: the route's effects key on these members, and
85+
// a fresh value per render would re-run them without end.
86+
const METADATA = {
87+
apps: APPS,
88+
objects: OBJECTS,
89+
loading: false,
90+
ensureType: undefined,
91+
error: null,
92+
refresh: async () => {},
93+
};
94+
vi.mock('../../providers/MetadataProvider', async (importOriginal) => ({
95+
...(await importOriginal<Record<string, unknown>>()),
96+
useMetadata: () => METADATA,
97+
}));
98+
99+
const ACTION_RUNNER = { execute: () => {}, runner: { registerHandler: () => {}, getContext: () => ({}) } };
100+
vi.mock('@object-ui/react', async (importOriginal) => ({
101+
...(await importOriginal<Record<string, unknown>>()),
102+
useActionRunner: () => ACTION_RUNNER,
103+
useGlobalUndo: () => {},
104+
useMutationInvalidationBridge: () => {},
105+
}));
106+
107+
import { AppContent } from '../AppContent';
108+
109+
beforeEach(() => {
110+
loadAppBundle.mockClear();
111+
});
112+
afterEach(cleanup);
113+
114+
async function visit(path: string) {
115+
const i18n = createI18n({ defaultLanguage: 'en', detectBrowserLanguage: false });
116+
const view = (
117+
<I18nProvider instance={i18n}>
118+
<MemoryRouter initialEntries={[path]}>
119+
<Routes>
120+
<Route path="/apps/:appName/*" element={<AppContent />} />
121+
</Routes>
122+
</MemoryRouter>
123+
</I18nProvider>
124+
);
125+
const mounted = render(view);
126+
await screen.findByTestId('object-view', undefined, { timeout: 5000 });
127+
return { rerender: () => mounted.rerender(view) };
128+
}
129+
130+
describe('AppContent loads the entered app\'s metadata bundle (objectstack#27627)', () => {
131+
it('on the package-id route, by the app name, once', async () => {
132+
const { rerender } = await visit('/apps/com.example.showcase/showcase_task');
133+
rerender();
134+
expect(loadAppBundle.mock.calls).toEqual([['showcase_app']]);
135+
});
136+
137+
it('on the name alias, by the same name', async () => {
138+
await visit('/apps/showcase_app/showcase_task');
139+
expect(loadAppBundle.mock.calls.map(([app]) => app)).toEqual(expect.arrayContaining(['showcase_app']));
140+
expect(new Set(loadAppBundle.mock.calls.map(([app]) => app))).toEqual(new Set(['showcase_app']));
141+
});
142+
});

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,12 @@ dataSource.invalidateCache(); // Invalidate all cached schemas
447447
dataSource.clearCache();
448448
```
449449

450+
### App metadata bundle
451+
452+
`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.
453+
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.
455+
450456
### Cache Configuration
451457

452458
- **LRU Eviction**: Automatically evicts least recently used entries when cache is full

0 commit comments

Comments
 (0)