@altertable/data-app 0.77.0 → 0.78.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/CONTRIBUTING.md +3 -0
  2. package/REFERENCE.md +45 -37
  3. package/dist/chunks/contract-gu1rDsV0.js +1588 -0
  4. package/dist/chunks/contract-gu1rDsV0.js.map +1 -0
  5. package/dist/chunks/data-client-BMdL73Ab.js +122 -0
  6. package/dist/chunks/data-client-BMdL73Ab.js.map +1 -0
  7. package/dist/chunks/{date-time-range-value-CnlTr1U1.js → date-time-range-value-D-XfqVTT.js} +21 -24
  8. package/dist/chunks/date-time-range-value-D-XfqVTT.js.map +1 -0
  9. package/dist/chunks/{diagnostics-Dyj-rUsY.js → diagnostics-CX9SsU79.js} +240 -63
  10. package/dist/chunks/diagnostics-CX9SsU79.js.map +1 -0
  11. package/dist/chunks/record-Cr4Uk1K3.js +9 -0
  12. package/dist/chunks/record-Cr4Uk1K3.js.map +1 -0
  13. package/dist/client/index.js +4 -101
  14. package/dist/client/index.js.map +1 -1
  15. package/dist/core/appearance.js +3 -5
  16. package/dist/core/appearance.js.map +1 -1
  17. package/dist/core/config.js +11 -3
  18. package/dist/core/config.js.map +1 -1
  19. package/dist/core/contract.js +3 -4
  20. package/dist/core/format.js +1 -1
  21. package/dist/internal.js +63 -11
  22. package/dist/internal.js.map +1 -1
  23. package/dist/types/chunks/contract.d.ts +254 -19
  24. package/dist/types/chunks/data-client.d.ts +46 -0
  25. package/dist/types/chunks/date-time-range-value.d.ts +28 -2
  26. package/dist/types/chunks/index.d.ts +65 -80
  27. package/dist/types/client/index.d.ts +4 -3
  28. package/dist/types/core/config.d.ts +10 -4
  29. package/dist/types/core/contract.d.ts +3 -5
  30. package/dist/types/core/format.d.ts +1 -2
  31. package/dist/types/index.d.ts +4 -4
  32. package/dist/types/internal.d.ts +25 -6
  33. package/docs/app-authoring.md +13 -9
  34. package/docs/client.md +14 -53
  35. package/docs/contract.md +35 -15
  36. package/docs/data-context.md +5 -2
  37. package/docs/diagnostics.md +16 -23
  38. package/docs/embed.md +60 -25
  39. package/docs/filters.md +33 -57
  40. package/docs/hosted-apps.md +9 -9
  41. package/docs/layout.md +21 -0
  42. package/docs/local-data-apps.md +5 -6
  43. package/docs/react-embed.md +44 -2
  44. package/docs/react.md +1 -2
  45. package/docs/server-bun.md +8 -5
  46. package/docs/stories-and-export.md +4 -4
  47. package/docs/styling.md +2 -1
  48. package/docs/ui.md +12 -3
  49. package/docs/views.md +12 -11
  50. package/docs/widgets.md +3 -3
  51. package/docs/worker.md +1 -1
  52. package/package.json +1 -5
  53. package/dist/chunks/contract-BQsFReRp.js +0 -780
  54. package/dist/chunks/contract-BQsFReRp.js.map +0 -1
  55. package/dist/chunks/contract-VhY9V9wd.js +0 -806
  56. package/dist/chunks/contract-VhY9V9wd.js.map +0 -1
  57. package/dist/chunks/date-time-range-value-CnlTr1U1.js.map +0 -1
  58. package/dist/chunks/diagnostics-Dyj-rUsY.js.map +0 -1
  59. package/dist/chunks/operation-BVRM-A5Y.js +0 -134
  60. package/dist/chunks/operation-BVRM-A5Y.js.map +0 -1
  61. package/dist/chunks/request-body-H1qPmmTN.js +0 -50
  62. package/dist/chunks/request-body-H1qPmmTN.js.map +0 -1
  63. package/dist/server/index.js +0 -90
  64. package/dist/server/index.js.map +0 -1
  65. package/dist/types/chunks/contract2.d.ts +0 -221
  66. package/dist/types/chunks/date-time-range.d.ts +0 -29
  67. package/dist/types/server/index.d.ts +0 -17
  68. package/docs/server.md +0 -41
package/docs/contract.md CHANGED
@@ -2,12 +2,14 @@
2
2
 
3
3
  Keep the starter's `defineDataApp()` declaration and operation registry. Declare
4
4
  named SQL queries with typed `params` and `projections`; execute them through
5
- `dataApp.defineOperation()`. Write one query and operation per widget result,
6
- and use descriptive `lowerCamelCase` query names.
5
+ `dataApp.defineOperation()`. Give independent results separate queries and
6
+ operations; widgets showing the same rows or related metrics from one summary
7
+ may share a result. Use descriptive `lowerCamelCase` query names.
7
8
 
8
9
  ## Execute named queries
9
10
 
10
- This is the hosted starter's query contract inside `defineDataApp()`:
11
+ This sample-count example illustrates the query contract inside `defineDataApp()`;
12
+ adapt the queries in the selected starter to the app's data:
11
13
 
12
14
  ```ts
13
15
  import { defineDataApp } from '@altertable/data-app';
@@ -40,23 +42,34 @@ List the [filters](filters.md) an operation reads; `run()` receives one flat
40
42
  field per filter, and you derive SQL parameters inside it:
41
43
 
42
44
  ```ts
43
- import { parseCount, searchFilter } from '@altertable/data-app/contract';
45
+ import { choiceFilter, parseCount } from '@altertable/data-app/contract';
44
46
 
45
47
  // ... dataApp
46
- const groupName = searchFilter({ key: 'group', label: 'Group' });
47
- const operations = {
48
+ const groupName = choiceFilter({
49
+ key: 'group',
50
+ label: 'Group',
51
+ defaultValue: 'all',
52
+ options: [
53
+ { id: 'all', label: 'All groups' },
54
+ { id: 'Alpha', label: 'Alpha' },
55
+ { id: 'Beta', label: 'Beta' },
56
+ ],
57
+ });
58
+ const operations = dataApp.defineOperations({
48
59
  sampleCountsByGroup: dataApp.defineOperation({
49
60
  filters: { groupName },
50
61
  policy: { maxQueryRows: 10, maxDurationMs: 15000 },
51
62
  async run({ query }, { groupName }) {
52
- const result = await query('sampleCountsByGroup', { groupName });
63
+ const result = await query('sampleCountsByGroup', {
64
+ groupName: groupName === 'all' ? '' : groupName,
65
+ });
53
66
  return result.rows.map(row => ({
54
67
  groupName: row.group_name,
55
68
  sampleCount: parseCount(row.sample_count),
56
69
  }));
57
70
  },
58
71
  }),
59
- };
72
+ });
60
73
  ```
61
74
 
62
75
  The filters validate input and supply the operation's checks; enforce business
@@ -84,9 +97,8 @@ Use `operations.sampleCountsByGroup.queryNames` for context and evidence.
84
97
 
85
98
  ### Bind date ranges
86
99
 
87
- Declare `{ type: 'dateTimeRange' }` and pass a date filter's `range` or
88
- `comparison`. Reference its bounds as `$period.from` (inclusive) and
89
- `$period.to` (exclusive):
100
+ Bind a date filter's `range` or `comparison` as two string parameters. Cast
101
+ them to DuckDB `TIMESTAMP`; include the start and exclude the end:
90
102
 
91
103
  ```ts
92
104
  const dataApp = defineDataApp({
@@ -95,9 +107,13 @@ const dataApp = defineDataApp({
95
107
  dailyOrders: {
96
108
  statement: `SELECT CAST(ordered_at AS DATE) AS day, count(*) AS orders
97
109
  FROM orders
98
- WHERE ordered_at >= $period.from AND ordered_at < $period.to
110
+ WHERE ordered_at >= CAST($period_from AS TIMESTAMP)
111
+ AND ordered_at < CAST($period_to AS TIMESTAMP)
99
112
  GROUP BY day ORDER BY day`,
100
- params: { period: { type: 'dateTimeRange' } },
113
+ params: {
114
+ period_from: { type: 'string' },
115
+ period_to: { type: 'string' },
116
+ },
101
117
  projections: {
102
118
  day: { type: 'string' },
103
119
  orders: { type: 'number' },
@@ -107,8 +123,12 @@ const dataApp = defineDataApp({
107
123
  });
108
124
  ```
109
125
 
126
+ In the operation, import `queryDateTimeRangeParams` from
127
+ `@altertable/data-app/contract` and call
128
+ `query('dailyOrders', queryDateTimeRangeParams(periodFilter, period, 'period').current)`.
129
+ This resolves relative bounds when the query runs.
130
+
110
131
  Date filters pass resolved bounds in their `timeZone`, encoded as UTC wall-clock
111
132
  fields: 4 PM in the reporting zone is 16:00Z. SQL bounds are therefore
112
133
  timezone-free timestamps; interpret timestamp-with-timezone columns in that same
113
- zone. Coverage and duration limits live on the
114
- [date filter](filters.md#date-ranges).
134
+ zone. Coverage and duration limits live on the [date filter](filters.md#date-ranges).
@@ -1,6 +1,6 @@
1
1
  # Data context and evidence
2
2
 
3
- Continue the starter's operations and context. Build one context from every
3
+ Keep the selected starter's operations and context. Build one context from every
4
4
  operation's `queryNames` and share it across the app's views. Reference only
5
5
  queries the app executes.
6
6
 
@@ -26,10 +26,13 @@ const sampleDataContext = createDataContext(queryNames)({
26
26
  });
27
27
  ```
28
28
 
29
+ This sample-count example uses the operations illustrated in [views](views.md).
29
30
  Import `createDataContext()` from `@altertable/data-app-react`. Supply
30
31
  `dataContext: sampleDataContext` on each view, then use its glossary IDs
31
32
  in `view.metric()` and `view.dataset()`. Reuse those bindings in widgets and stories.
32
- Detail views need their own context when their queries differ.
33
+ Include detail operations' query names and definitions in the shared context.
34
+ A detail view can use a separate context when it needs different definitions or
35
+ coverage; a different query alone does not require one.
33
36
 
34
37
  ## Register source identifiers
35
38
 
@@ -12,10 +12,7 @@ Change the revision identifier when app source changes.
12
12
 
13
13
  ```tsx
14
14
  import { createDataAppRepairSession } from '@altertable/data-app-embed';
15
- import {
16
- DataAppBridge,
17
- DataAppRepairBanner,
18
- } from '@altertable/data-app-embed/react';
15
+ import { DataAppBridge } from '@altertable/data-app-embed/react';
19
16
 
20
17
  const session = createDataAppRepairSession({
21
18
  state: restoredState, // New app: { automaticRequests: 0, attemptedRevisions: [] }
@@ -24,15 +21,12 @@ const session = createDataAppRepairSession({
24
21
  });
25
22
 
26
23
  const viewer = (
27
- <>
28
- <DataAppRepairBanner session={session} />
29
- <DataAppBridge
30
- source={{ type: 'bundle', javascript }}
31
- title="Data app"
32
- repair={{ session, revision }}
33
- onMessage={onMessage}
34
- />
35
- </>
24
+ <DataAppBridge
25
+ source={{ type: 'bundle', javascript }}
26
+ title="Data app"
27
+ repair={{ session, revision }}
28
+ onMessage={onMessage}
29
+ />
36
30
  );
37
31
  ```
38
32
 
@@ -40,18 +34,18 @@ The host owns authorization, delivery, and state retention. `onStateChange` is
40
34
  awaited before automatic delivery; reject if state cannot be retained. Three automatic
41
35
  requests are allowed per session; manual requests and healthy revisions do not
42
36
  reset the allowance. Callback resolution means acceptance, not agent execution.
43
- Omit `onRepairRequest` when delivery or reliable state retention is unavailable;
44
- the banner offers diagnostics to copy instead. Avoid sensitive values in errors.
37
+ Omit `onRepairRequest` when delivery or reliable state retention is unavailable,
38
+ and offer the diagnostics to copy instead. Avoid sensitive values in errors.
45
39
  Source locations use generated filenames and positions.
46
40
 
47
- ## Custom banners
41
+ ## Repair UI
48
42
 
49
- Use `session.snapshot()` to read diagnostics, delivery status, the automatic
50
- request count, and the latest request's start time. Subscribe with
51
- `session.subscribe()` and request a fix with `session.requestRepair()`. These APIs
52
- work without React or the default banner.
43
+ The host renders its own repair UI. Use `session.snapshot()` to read diagnostics,
44
+ delivery status, the automatic request count, and the latest request's start
45
+ time. Subscribe with `session.subscribe()` and request a fix with
46
+ `session.requestRepair()`. These APIs work without React.
53
47
 
54
- In React, pass the snapshot to your own banner:
48
+ In React, pass the snapshot to your banner:
55
49
 
56
50
  ```tsx
57
51
  import type { DataAppRepairSession } from '@altertable/data-app-embed';
@@ -78,5 +72,4 @@ function AppRepair({ session }: { session: DataAppRepairSession }) {
78
72
  The host owns agent activity and revision loading. Request acceptance does not
79
73
  mean the agent has started or finished. Clear the previous attempt's activity
80
74
  when requesting another fix, and clear progress when the updated revision's
81
- diagnostics settle. Custom banners choose their own presentation; the default
82
- `<DataAppRepairBanner>` accepts observed host activity through `progress`.
75
+ diagnostics settle.
package/docs/embed.md CHANGED
@@ -170,45 +170,36 @@ const router = createMessageRouter(routes, {
170
170
  `router.dispatch()` validates route input and output. Use `MessageRoutingError`
171
171
  for intentional public failures; other handler errors are hidden.
172
172
 
173
- Use `defineDataQueryRoute(operationContracts)` for typed named operations or
174
- `dataAppRoutes` for generic operation and navigation routes. Handlers must
175
- validate operations, authorize data access, and enforce backend query limits.
173
+ Use `registeredQueryRoute` for data requests, or `dataAppRoutes` for the shared
174
+ registered-query and navigation contracts. Handlers must resolve IDs against
175
+ the saved app, authorize data access, and enforce backend query limits.
176
176
 
177
- ## SQL query route
177
+ ## Registered query route
178
178
 
179
- Hosts serving browser-owned operations register `sqlQueryRoute` explicitly:
179
+ Hosts serving browser-owned operations register `registeredQueryRoute`:
180
180
 
181
181
  ```ts
182
182
  import {
183
183
  createMessageRouter,
184
- sqlQueryRoute,
184
+ registeredQueryRoute,
185
185
  } from '@altertable/data-app/contract';
186
- import { createSqlQueryHandler } from '@altertable/data-app-embed';
187
186
 
188
187
  const router = createMessageRouter(
189
- { 'data:sql': sqlQueryRoute },
188
+ { 'data:query': registeredQueryRoute },
190
189
  {
191
- 'data:sql': createSqlQueryHandler(async (query, { signal }) => {
192
- return authorizedLakehouseForCurrentViewer(query, signal);
193
- }),
190
+ 'data:query': async ({ queryId, params, limit }, { signal }) =>
191
+ runRegisteredQueryForCurrentViewer({ queryId, params, limit, signal }),
194
192
  }
195
193
  );
196
194
  // Supply router.dispatch as the shell's onMessage handler.
197
195
  ```
198
196
 
199
- The host supplies `authorizedLakehouseForCurrentViewer()`. Its backend must enforce
200
- viewer/dataset permissions, permitted query behavior, maximum rows, execution
201
- time, concurrency, and response size independently of browser policy. Route
202
- validation is not SQL authorization. `createSqlQueryHandler()` calls authorization
203
- for each query, forwards cancellation, and preserves `DataSourceError` reasons
204
- as public `source_*` errors with request IDs. Authorization failures return
205
- `forbidden`; unknown query errors are hidden. Custom handlers can return deliberate
206
- public failures with `MessageRoutingError`.
207
-
208
- The SQL route carries `{ statement, limit, params? }` and returns column
209
- metadata and row arrays; see `SqlQueryInput` and `QueryResult` in the
210
- [API reference](../REFERENCE.md). Keep SQL and parameters unchanged.
211
- For server-owned named operations, use `dataAppRoutes` and `data:query` instead.
197
+ The host resolves `queryId` against the app's saved `defineDataApp({ queries })`
198
+ registry and runs that SQL with the supplied parameter values. It must enforce
199
+ viewer permissions, maximum rows, execution time, concurrency, and response size.
200
+ The route carries `{ queryId, limit, params? }` and returns column metadata and
201
+ row arrays; see `RegisteredQueryInput` and `QueryResult` in the
202
+ [API reference](../REFERENCE.md). Unknown IDs must fail before execution.
212
203
 
213
204
  ## Parent presentation
214
205
 
@@ -230,9 +221,53 @@ host.setPresentation({ surface: 'embedded', theme: 'light' });
230
221
  Use `surface: 'embedded'` when the parent supplies page chrome and
231
222
  `'standalone'` when the app supplies it. Resolve the parent theme to `'light'` or
232
223
  `'dark'`. React `<DataApp>` applies presentation automatically: embedded surfaces
233
- keep toolbar actions and hide header/footer. Updates do not reload the iframe.
224
+ hide the header, footer, and page toolbar, and offer its actions to the parent
225
+ through [page actions](#page-actions). Updates do not reload the iframe.
234
226
  Call `host.setPresentation(undefined)` to restore standalone defaults.
235
227
 
228
+ The parent also owns annotation mode whenever the app shows no toolbar, as on
229
+ embedded surfaces: set `annotations.active` (omitted means inactive) and handle
230
+ the `annotation:mode` route.
231
+
232
+ ### Page actions
233
+
234
+ An embedded app shows no toolbar. It offers its page actions to the parent,
235
+ which renders the controls and runs them through the bridge:
236
+
237
+ ```ts
238
+ // ... iframe, authorized router, and refreshButton
239
+ const host = attachDataAppBridge({
240
+ iframe,
241
+ source: { type: 'url', url: 'https://apps.example.com/report' },
242
+ presentation: { surface: 'embedded', theme: 'light' },
243
+ onActionsChange(actions) {
244
+ refreshButton.hidden = !actions.refresh;
245
+ refreshButton.disabled = actions.refresh?.refreshing ?? true;
246
+ },
247
+ onMessage: router.dispatch,
248
+ });
249
+
250
+ refreshButton.onclick = () => host.runAction({ type: 'refresh' });
251
+ ```
252
+
253
+ `onActionsChange` receives the complete `DataAppActions` on every change. Render
254
+ only the keys present:
255
+
256
+ | Offered state | Run | Notes |
257
+ | --------------------------------------- | --------------------------------- | ---------------------------------------------------------------------- |
258
+ | `refresh: { refreshing, cancellable }` | `refresh`, `cancelRefresh` | Cancel only while `refreshing` and `cancellable`. |
259
+ | `exportCsv: { enabled, tables }` | `exportCsv` with optional `table` | Omit `table` to export every dataset, as a ZIP when there are several. |
260
+ | `presentStory: { enabled, presenting }` | `presentStory`, `closeStory` | Shows the iframe fullscreen while presenting. |
261
+ | `aboutData: { enabled }` | `aboutData` | Opens the data inspector in the frame. |
262
+
263
+ Call `runAction()` from the user's click: the bridge needs that gesture to show
264
+ a story fullscreen. It exits fullscreen when the story closes, and leaving
265
+ fullscreen closes the story. `presentStory` and `aboutData` move focus into the
266
+ frame; when that story closes, focus returns to the control that ran it unless
267
+ the reader has moved elsewhere. The app ignores actions it does not currently
268
+ offer. While the app reconnects, actions reset to `{}` and `runAction()` does
269
+ nothing.
270
+
236
271
  ### Content sizing
237
272
 
238
273
  By default the parent sizes the iframe and the app scrolls inside it. Set
package/docs/filters.md CHANGED
@@ -7,20 +7,31 @@ renders. Import filters from `@altertable/data-app/contract`.
7
7
 
8
8
  ## Declare filters on operations
9
9
 
10
- The hosted starter's operations both read one group search:
10
+ This sample-count example shares one fixed group choice across operations:
11
11
 
12
12
  ```tsx
13
- import { parseCount, searchFilter } from '@altertable/data-app/contract';
13
+ import { choiceFilter, parseCount } from '@altertable/data-app/contract';
14
14
 
15
15
  // ... dataApp, sampleDataContext, and section contents
16
- const groupName = searchFilter({ key: 'group', label: 'Group' });
16
+ const groupName = choiceFilter({
17
+ key: 'group',
18
+ label: 'Group',
19
+ defaultValue: 'all',
20
+ options: [
21
+ { id: 'all', label: 'All groups' },
22
+ { id: 'Alpha', label: 'Alpha' },
23
+ { id: 'Beta', label: 'Beta' },
24
+ ],
25
+ });
17
26
 
18
- const operations = {
27
+ const operations = dataApp.defineOperations({
19
28
  sampleCountsByGroup: dataApp.defineOperation({
20
29
  filters: { groupName },
21
30
  policy: { maxQueryRows: 10, maxDurationMs: 15000 },
22
31
  async run({ query }, { groupName }) {
23
- const result = await query('sampleCountsByGroup', { groupName });
32
+ const result = await query('sampleCountsByGroup', {
33
+ groupName: groupName === 'all' ? '' : groupName,
34
+ });
24
35
  return result.rows.map(row => ({
25
36
  groupName: row.group_name,
26
37
  sampleCount: parseCount(row.sample_count),
@@ -28,8 +39,8 @@ const operations = {
28
39
  },
29
40
  }),
30
41
  // ... sampleTotal reads the same { groupName }
31
- };
32
- const { defineView } = createDataHooks(createDataClient({ operations }));
42
+ });
43
+ const { defineView } = createDataHooks(operations.createDataClient());
33
44
  const sampleCountsView = defineView({
34
45
  dataContext: sampleDataContext,
35
46
  operation: 'sampleCountsByGroup',
@@ -69,27 +80,26 @@ function App() {
69
80
  | `numberFilter()`, `booleanFilter()` | `NumberSelection`, `BooleanSelection` |
70
81
  | `dateTimeRangeFilter()` | `{ range, comparison }` of resolved dates |
71
82
 
72
- Pass values to declared query parameters; never interpolate them into SQL. Date
73
- ranges bind as [`dateTimeRange` parameters](contract.md#bind-date-ranges). A
74
- dimension selection binds whole to a `{ type: 'dimension', valueType }`
75
- parameter; `$country.matches(column)` keeps the selected rows, including
76
- multiple members, missing values, and exclusion:
83
+ Pass values to declared query parameters; never interpolate them into SQL. Bind
84
+ date filter bounds as [separate parameters](contract.md#bind-date-ranges).
85
+ For a single-value choice, bind its selected ID as a string:
77
86
 
78
87
  ```ts
79
88
  // ... in defineDataApp({ queries })
80
89
  revenueByCampaign: {
81
90
  statement: `SELECT o.campaign, sum(o.amount) AS revenue
82
91
  FROM demo.orders o JOIN demo.customers c ON c.id = o.customer_id
83
- WHERE $country.matches(c.country)
92
+ WHERE c.country = $country
84
93
  GROUP BY o.campaign`,
85
- params: { country: { type: 'dimension', valueType: 'string' } },
94
+ params: { country: { type: 'string' } },
86
95
  projections: { campaign: { type: 'string' }, revenue: { type: 'number' } },
87
96
  },
88
97
  // ... in the operation: query('revenueByCampaign', { country: input.country })
89
98
  ```
90
99
 
91
- Dimension, number, and boolean selections support `{ kind: 'all' }`. Offer only
92
- predicates the registered query supports.
100
+ Dimension selections bind as JSON. Express multiple values, missing values, and
101
+ exclusion in DuckDB SQL. Dimension, number, and boolean selections support
102
+ `{ kind: 'all' }`. Offer only predicates the registered query supports.
93
103
 
94
104
  ## Categorical dimensions
95
105
 
@@ -208,9 +218,10 @@ period, time zone, and metric comparisons:
208
218
  import {
209
219
  dateTimeRangeFilter,
210
220
  dateTimeRangePresets,
221
+ queryDateTimeRangeParams,
211
222
  } from '@altertable/data-app/contract';
212
223
 
213
- const period = dateTimeRangeFilter({
224
+ const periodFilter = dateTimeRangeFilter({
214
225
  key: 'period',
215
226
  defaultValue: '30d',
216
227
  maxRangeDays: 90,
@@ -218,14 +229,14 @@ const period = dateTimeRangeFilter({
218
229
  presets: dateTimeRangePresets.analytics,
219
230
  });
220
231
  const dailyCounts = dataApp.defineOperation({
221
- filters: { period, groupName },
232
+ filters: { period: periodFilter, groupName },
222
233
  policy: { maxQueryRows: 100, maxDurationMs: 15000 },
223
234
  async run({ query }, { period, groupName }) {
224
235
  const current = await query('dailyCounts', {
225
- period: period.range,
236
+ ...queryDateTimeRangeParams(periodFilter, period, 'period').current,
226
237
  groupName,
227
238
  });
228
- // ... query { period: period.comparison } when it is not null
239
+ // ... use .comparison for the previous period when selected
229
240
  return current.rows;
230
241
  },
231
242
  });
@@ -233,8 +244,8 @@ const dailyCounts = dataApp.defineOperation({
233
244
 
234
245
  - `run()` receives `{ range, comparison }` with resolved dates. Ranges include
235
246
  `from` and exclude `to`: September 24–30 queries `2026-09-24T00:00:00Z`
236
- through `2026-10-01T00:00:00Z`. Bind them to a
237
- [`dateTimeRange` parameter](contract.md#bind-date-ranges).
247
+ through `2026-10-01T00:00:00Z`. Bind them as
248
+ [separate parameters](contract.md#bind-date-ranges).
238
249
  - A range that runs past now ends at now: today picked in the calendar queries
239
250
  midnight through the current time.
240
251
  - `comparison: 'off'` or `'on'` offers the previous-period toggle, starting in
@@ -258,38 +269,3 @@ use app-owned drafts only when the task needs Apply/Cancel.
258
269
  Custom control ownership is needed only when generated controls cannot express
259
270
  the requirement; use `/ui` for that case. Do not reuse reserved inspection,
260
271
  presentation, or navigation URL keys.
261
-
262
- ## Share filters with HTTP and local apps
263
-
264
- HTTP and local apps keep operations on the server, so the browser imports them
265
- as types only. Declare filters in a browser-safe module that both sides import:
266
-
267
- ```ts
268
- // src/filters.ts
269
- import { choiceFilter } from '@altertable/data-app/contract';
270
-
271
- const groupName = choiceFilter({
272
- // ... key, label, defaultValue, and options
273
- });
274
-
275
- export const operationFilters = {
276
- sampleCountsByGroup: { groupName },
277
- sampleCountsBySegment: { groupName },
278
- };
279
- ```
280
-
281
- Each operation in `src/operations.ts` declares
282
- `filters: operationFilters.sampleCountsByGroup`, and the browser client receives
283
- the same map:
284
-
285
- ```ts
286
- // src/App.tsx
287
- import { operationFilters } from '#app/filters.ts';
288
- import type { operations } from '#app/operations.ts';
289
-
290
- const { defineView } = createDataHooks(
291
- createDataClient<typeof operations>({ filters: operationFilters })
292
- );
293
- ```
294
-
295
- The client's types require `filters` whenever an operation declares them.
@@ -18,21 +18,21 @@ Replace sample queries, operations, and datasets with inspected source data. Sup
18
18
  in `defineDataApp()`. When using bound `<DataApp>`, follow its current
19
19
  [story and dataset requirements](stories-and-export.md).
20
20
 
21
- Keep the starter's client, style injection, and mounting code. The host supplies
22
- the transport; no bootstrap or message routes are needed in app code.
21
+ Keep the starter's client, style injection, and mounting code. The current
22
+ single-file starter collects the operations with `dataApp.defineOperations()`
23
+ and uses `operations.createDataClient()`. The operation's `run()` executes in
24
+ the iframe and sends its registered query IDs and parameter values through
25
+ `data:query`; no bootstrap or message routes are needed in app code.
23
26
 
24
27
  ## Convert a local data app
25
28
 
26
29
  1. Combine the app's filters, operations, data context, views, any presentation
27
30
  and export features, app declaration, and browser entry into one `index.tsx`, following the
28
31
  [single-file starter](app-authoring.md#use-release-matched-starters).
29
- 2. Replace the HTTP client with `createDataClient({ operations })`, using the
30
- operation registry as a value; it supplies the operations' filters, so drop
31
- the `filters` option. See [browser-owned operations](client.md#browser-owned-operations-for-bundle-apps)
32
- for execution through the host.
33
- 3. Remove the Bun server, HTML, server adapters, credentials, and relative or
34
- app-alias imports. Rewrite any operation that depends on server-only code
35
- to use the operation's `query()` helper.
32
+ 2. Keep `operations.createDataClient()`; the hosted bootstrap supplies its
33
+ query bridge. See [registered operations](client.md#registered-operations).
34
+ 3. Remove the Bun server, HTML, local query adapter installation, credentials,
35
+ and relative or app-alias imports.
36
36
  4. Confirm the host can query the same catalogs, tables, and fields.
37
37
  [Verify the app](app-authoring.md#verify-the-app) in the hosted runtime against
38
38
  the local version's filters and findings.
package/docs/layout.md CHANGED
@@ -38,6 +38,27 @@ Compose paragraphs, links, and inline components directly; no `<TextContent>`
38
38
  wrapper is needed. Keep headings and widgets in the body and controls in
39
39
  `footerActions`.
40
40
 
41
+ Embedded hosts supply the page chrome, so `<DataApp>` omits its header, footer,
42
+ `toolbarActions`, and `footerActions` there; the host runs refresh, export,
43
+ story, and inspection. Keep controls readers need in the body.
44
+
45
+ ## Adapt to the available container
46
+
47
+ Base layout decisions on the app's available width. An embedded panel can be
48
+ narrow inside a wide browser window. Use `<Grid>` and `<GridItem>` first: their
49
+ tracks and spans respond to the containing grid rather than a viewport breakpoint.
50
+ Choose the column count and reading order for the evidence in the app brief.
51
+
52
+ For custom layout that these primitives cannot express, give an app-owned wrapper
53
+ `container-type: inline-size` and, when needed, a `container-name`. Use CSS
54
+ `@container` queries to adapt its descendants to that wrapper's width. The
55
+ container must be an ancestor of the elements whose layout changes. Keep theme
56
+ and user-preference media queries separate from these width decisions.
57
+
58
+ Apply the same composition and container rules to hosted and local apps. Verify
59
+ both a narrow browser and a narrow embed inside a wide browser; neither should
60
+ clip controls or require horizontal page scrolling.
61
+
41
62
  ## Verify rendered layouts
42
63
 
43
64
  Review authored composition with realistic labels and values. For custom layout
@@ -2,15 +2,14 @@
2
2
 
3
3
  Use the local scaffold supplied by your authoring workflow. Its README covers
4
4
  setup and its AGENTS.md identifies app-owned files.
5
- Replace the connectivity screen or fixture examples with the content specified by
5
+ Replace the sample queries and views with the content specified by
6
6
  the app brief, using the [shared SDK patterns](app-authoring.md). Local execution
7
7
  does not require a particular content structure or presentation story.
8
8
 
9
- | Task | Documentation |
10
- | ---------------------------- | ---------------------------------------- |
11
- | Customize local serving | [Bun server](server-bun.md) |
12
- | Authorize hosted viewers | [Server](server.md) |
13
- | Customize the browser client | [HTTP client](client.md#http-operations) |
9
+ | Task | Documentation |
10
+ | ---------------------------- | ----------------------------------------- |
11
+ | Customize local serving | [Bun server](server-bun.md) |
12
+ | Customize the browser client | [Client](client.md#registered-operations) |
14
13
 
15
14
  You can also [convert the local app to a hosted data app](hosted-apps.md#convert-a-local-data-app).
16
15
 
@@ -100,5 +100,47 @@ Pass `presentation={{ surface: 'embedded', theme: resolvedTheme }}`
100
100
  to `<DataAppBridge>` in either source or connection mode. Use `'standalone'` when the app should render its own page chrome.
101
101
  Prop updates publish trusted state without reloading the iframe or reconnecting
102
102
  the session. Resolve system preference in the parent to `'light'` or `'dark'`.
103
- Inside an embedded surface, `<DataApp>` retains toolbar actions and hides its header
104
- and footer. See [parent presentation](embed.md#parent-presentation).
103
+ Inside an embedded surface, `<DataApp>` hides its header, footer, and page
104
+ toolbar. See [parent presentation](embed.md#parent-presentation).
105
+
106
+ ## Page actions
107
+
108
+ Render the app's page actions in the parent with `onActionsChange`, and run them
109
+ through the bridge's `ref`:
110
+
111
+ ```tsx
112
+ import { useRef, useState } from 'react';
113
+ import {
114
+ DataAppBridge,
115
+ type DataAppBridgeHandle,
116
+ } from '@altertable/data-app-embed/react';
117
+ import type { DataAppActions } from '@altertable/data-app-embed';
118
+
119
+ // ... javascript bundle and router
120
+ function Shell() {
121
+ const bridge = useRef<DataAppBridgeHandle>(null);
122
+ const [actions, setActions] = useState<DataAppActions>({});
123
+ return (
124
+ <>
125
+ {actions.refresh && (
126
+ <button
127
+ disabled={actions.refresh.refreshing}
128
+ onClick={() => bridge.current?.runAction({ type: 'refresh' })}
129
+ >
130
+ Refresh
131
+ </button>
132
+ )}
133
+ <DataAppBridge
134
+ ref={bridge}
135
+ title="Activity report"
136
+ source={{ type: 'bundle', javascript }}
137
+ presentation={{ surface: 'embedded', theme: 'light' }}
138
+ onActionsChange={setActions}
139
+ onMessage={router.dispatch}
140
+ />
141
+ </>
142
+ );
143
+ }
144
+ ```
145
+
146
+ See [page actions](embed.md#page-actions) for every action and its state.
package/docs/react.md CHANGED
@@ -7,9 +7,8 @@ React and React DOM 19.2 or newer are required. Start with
7
7
  ## Mount the app
8
8
 
9
9
  ```tsx
10
- import { injectDataAppStyles, mountDataApp } from '@altertable/data-app-react';
10
+ import { mountDataApp } from '@altertable/data-app-react';
11
11
 
12
- injectDataAppStyles();
13
12
  mountDataApp({ app: dataApp, component: App });
14
13
  ```
15
14
 
@@ -10,13 +10,17 @@ when typechecking a Bun app.
10
10
  ```ts
11
11
  import { serveLocalApp } from '@altertable/data-app-bun';
12
12
  import page from './index.html';
13
- import { operations } from './operations.ts';
13
+ import { dataApp } from './app.ts';
14
14
 
15
- serveLocalApp({ page, operations, title: 'Activity' });
15
+ serveLocalApp({
16
+ page,
17
+ app: dataApp,
18
+ });
16
19
  ```
17
20
 
18
21
  The server binds to `127.0.0.1`. Its default port is `25837`, overridable through
19
- `PORT` or the `port` option. It serves the Bun HTML bundle and operation requests.
22
+ `PORT` or the `port` option. It serves the Bun HTML bundle and registered queries
23
+ by ID.
20
24
 
21
25
  `localLakehouse()` reads the CLI proxy URL and token from
22
26
  `ALTERTABLE_DATA_PROXY_URL` and `ALTERTABLE_DATA_PROXY_TOKEN`. It also supports
@@ -25,5 +29,4 @@ server-only `ALTERTABLE_LAKEHOUSE_USERNAME` and
25
29
  Missing credentials fail at startup. Keep these variables out of browser code.
26
30
 
27
31
  Local serving does not authenticate hosted viewers.
28
- Use [the portable server handler](server.md) with per-request authorization when
29
- hosting an app for other people.
32
+ Hosted apps authorize viewers in the host before executing registered queries.