@altertable/data-app 0.76.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.
- package/CONTRIBUTING.md +3 -0
- package/REFERENCE.md +392 -276
- package/dist/chunks/contract-gu1rDsV0.js +1588 -0
- package/dist/chunks/contract-gu1rDsV0.js.map +1 -0
- package/dist/chunks/data-client-BMdL73Ab.js +122 -0
- package/dist/chunks/data-client-BMdL73Ab.js.map +1 -0
- package/dist/chunks/{date-time-range-value-TE8KCsfV.js → date-time-range-value-D-XfqVTT.js} +28 -31
- package/dist/chunks/date-time-range-value-D-XfqVTT.js.map +1 -0
- package/dist/chunks/{diagnostics-DhCqGklq.js → diagnostics-CX9SsU79.js} +240 -63
- package/dist/chunks/diagnostics-CX9SsU79.js.map +1 -0
- package/dist/chunks/record-Cr4Uk1K3.js +9 -0
- package/dist/chunks/record-Cr4Uk1K3.js.map +1 -0
- package/dist/client/index.js +4 -86
- package/dist/client/index.js.map +1 -1
- package/dist/core/appearance.js +3 -5
- package/dist/core/appearance.js.map +1 -1
- package/dist/core/config.js +11 -3
- package/dist/core/config.js.map +1 -1
- package/dist/core/contract.js +3 -4
- package/dist/core/format.js +1 -1
- package/dist/internal.js +58 -124
- package/dist/internal.js.map +1 -1
- package/dist/types/chunks/contract.d.ts +592 -308
- package/dist/types/chunks/data-client.d.ts +46 -0
- package/dist/types/chunks/date-time-range-value.d.ts +28 -2
- package/dist/types/chunks/index.d.ts +65 -53
- package/dist/types/client/index.d.ts +4 -3
- package/dist/types/core/config.d.ts +16 -6
- package/dist/types/core/contract.d.ts +3 -5
- package/dist/types/core/format.d.ts +1 -2
- package/dist/types/index.d.ts +4 -4
- package/dist/types/internal.d.ts +26 -7
- package/docs/app-authoring.md +23 -14
- package/docs/client.md +14 -48
- package/docs/contract.md +58 -56
- package/docs/data-context.md +13 -6
- package/docs/diagnostics.md +16 -23
- package/docs/embed.md +60 -25
- package/docs/filters.md +271 -0
- package/docs/hosted-apps.md +11 -10
- package/docs/layout.md +45 -18
- package/docs/local-data-apps.md +5 -6
- package/docs/react-embed.md +44 -2
- package/docs/react.md +1 -2
- package/docs/server-bun.md +8 -5
- package/docs/stories-and-export.md +23 -14
- package/docs/styling.md +2 -1
- package/docs/ui.md +18 -8
- package/docs/views.md +63 -26
- package/docs/widgets.md +40 -16
- package/docs/worker.md +1 -1
- package/package.json +1 -5
- package/dist/chunks/contract-DsyRYgN_.js +0 -626
- package/dist/chunks/contract-DsyRYgN_.js.map +0 -1
- package/dist/chunks/contract-kNFYPHRK.js +0 -713
- package/dist/chunks/contract-kNFYPHRK.js.map +0 -1
- package/dist/chunks/date-time-range-value-TE8KCsfV.js.map +0 -1
- package/dist/chunks/diagnostics-DhCqGklq.js.map +0 -1
- package/dist/chunks/operation-7tiT4cpJ.js +0 -134
- package/dist/chunks/operation-7tiT4cpJ.js.map +0 -1
- package/dist/chunks/request-body-H1qPmmTN.js +0 -50
- package/dist/chunks/request-body-H1qPmmTN.js.map +0 -1
- package/dist/server/index.js +0 -90
- package/dist/server/index.js.map +0 -1
- package/dist/types/chunks/contract2.d.ts +0 -207
- package/dist/types/chunks/date-time-range.d.ts +0 -29
- package/dist/types/server/index.d.ts +0 -17
- package/docs/server.md +0 -41
- package/docs/variables.md +0 -280
package/docs/client.md
CHANGED
|
@@ -1,66 +1,32 @@
|
|
|
1
1
|
# Client
|
|
2
2
|
|
|
3
3
|
Use this guide when customizing client delivery. Standard apps keep the
|
|
4
|
-
starter's client.
|
|
4
|
+
starter's client.
|
|
5
5
|
|
|
6
|
-
##
|
|
6
|
+
## Registered operations
|
|
7
|
+
|
|
8
|
+
Hosted and local metric/finding starters use the same operation client:
|
|
7
9
|
|
|
8
10
|
```ts
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const client = createDataClient<typeof operations>();
|
|
13
|
-
const response = await client.query(
|
|
14
|
-
'sampleCountsByGroup',
|
|
15
|
-
{ groupName: '' },
|
|
16
|
-
{ signal }
|
|
17
|
-
);
|
|
11
|
+
const operations = dataApp.defineOperations({ sampleCountsByGroup });
|
|
12
|
+
const client = operations.createDataClient();
|
|
18
13
|
```
|
|
19
14
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
`createDataClient<typeof operations>({ endpoint, fetch })` to change the base URL or supply a Fetch
|
|
26
|
-
implementation. Calls POST JSON to `/api/data/:operation`; the client sends
|
|
27
|
-
operation inputs rather than SQL or credentials.
|
|
15
|
+
`run()` executes in the browser. Hosted apps send each named query through
|
|
16
|
+
`data:query`; local apps install `installLocalQueryLakehouse()` before mounting
|
|
17
|
+
and send it to `POST /api/query/:queryId`. Both backends execute only registered
|
|
18
|
+
SQL. The local Bun server receives `app: dataApp` through `serveLocalApp()`.
|
|
19
|
+
Keep `run()` and its imports browser-safe in this mode.
|
|
28
20
|
|
|
29
21
|
For direct client calls, render `response.data` and label it with `response.input`
|
|
30
22
|
so retained results keep their original scope during refresh. React views handle
|
|
31
|
-
this automatically.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
See [contracts](contract.md), [server handlers](server.md), and
|
|
35
|
-
[React bindings](react.md).
|
|
23
|
+
this automatically. Import `DataAppError` for public codes and request IDs.
|
|
24
|
+
Pass an abort signal to cancel a query.
|
|
36
25
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
Bundle apps pass their operation registry as a value:
|
|
40
|
-
|
|
41
|
-
```ts
|
|
42
|
-
import { createDataClient } from '@altertable/data-app/client';
|
|
43
|
-
|
|
44
|
-
// ... operations declared with dataApp.defineOperation()
|
|
45
|
-
const client = createDataClient({ operations });
|
|
46
|
-
const response = await client.query('sampleCountsByGroup', { groupName: '' });
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
Operations run in the browser and query through the host's `data:sql` route.
|
|
50
|
-
The trusted bootstrap installs the bridge before app execution. A custom runtime
|
|
51
|
-
must install it first or supply an authorized `lakehouse` adapter.
|
|
52
|
-
|
|
53
|
-
Do not combine `operations` with `transport`, `endpoint`, or `fetch`. Browser
|
|
54
|
-
policy bounds app requests; the [host SQL handler](embed.md#sql-query-route)
|
|
55
|
-
must independently enforce access and resource limits.
|
|
26
|
+
See [contracts](contract.md) and [React bindings](react.md).
|
|
56
27
|
|
|
57
28
|
## Iframe transport
|
|
58
29
|
|
|
59
|
-
`createDataClient<typeof operations>({ transport })` accepts a `DataTransport`. Without an explicit
|
|
60
|
-
transport, endpoint, or Fetch implementation, it discovers an installed iframe
|
|
61
|
-
transport before falling back to HTTP. Explicit endpoint/Fetch options select
|
|
62
|
-
HTTP. `createHttpTransport()` provides the underlying operation delivery adapter.
|
|
63
|
-
|
|
64
30
|
A URL-hosted app configures trust and installs the bridge before mounting:
|
|
65
31
|
|
|
66
32
|
```ts
|
package/docs/contract.md
CHANGED
|
@@ -2,11 +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()`.
|
|
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.
|
|
6
8
|
|
|
7
9
|
## Execute named queries
|
|
8
10
|
|
|
9
|
-
This
|
|
11
|
+
This sample-count example illustrates the query contract inside `defineDataApp()`;
|
|
12
|
+
adapt the queries in the selected starter to the app's data:
|
|
10
13
|
|
|
11
14
|
```ts
|
|
12
15
|
import { defineDataApp } from '@altertable/data-app';
|
|
@@ -35,37 +38,47 @@ ORDER BY group_name LIMIT $limit`,
|
|
|
35
38
|
|
|
36
39
|
Replace fixture SQL with inspected data. Keep query declarations and projections
|
|
37
40
|
in sync when adapting SQL to the app's inputs. Preserve metric definitions.
|
|
38
|
-
|
|
41
|
+
List the [filters](filters.md) an operation reads; `run()` receives one flat
|
|
42
|
+
field per filter, and you derive SQL parameters inside it:
|
|
39
43
|
|
|
40
44
|
```ts
|
|
41
|
-
import { parseCount } from '@altertable/data-app/contract';
|
|
42
|
-
|
|
43
|
-
// ... dataApp
|
|
44
|
-
const
|
|
45
|
+
import { choiceFilter, parseCount } from '@altertable/data-app/contract';
|
|
46
|
+
|
|
47
|
+
// ... dataApp
|
|
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({
|
|
45
59
|
sampleCountsByGroup: dataApp.defineOperation({
|
|
46
|
-
|
|
47
|
-
checks: [
|
|
48
|
-
{ groupName: '' },
|
|
49
|
-
{ groupName: 'Alpha' },
|
|
50
|
-
{ groupName: 'missing' },
|
|
51
|
-
],
|
|
60
|
+
filters: { groupName },
|
|
52
61
|
policy: { maxQueryRows: 10, maxDurationMs: 15000 },
|
|
53
62
|
async run({ query }, { groupName }) {
|
|
54
|
-
const result = await query('sampleCountsByGroup', {
|
|
63
|
+
const result = await query('sampleCountsByGroup', {
|
|
64
|
+
groupName: groupName === 'all' ? '' : groupName,
|
|
65
|
+
});
|
|
55
66
|
return result.rows.map(row => ({
|
|
56
67
|
groupName: row.group_name,
|
|
57
68
|
sampleCount: parseCount(row.sample_count),
|
|
58
69
|
}));
|
|
59
70
|
},
|
|
60
71
|
}),
|
|
61
|
-
};
|
|
72
|
+
});
|
|
62
73
|
```
|
|
63
74
|
|
|
64
|
-
The
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
75
|
+
The filters validate input and supply the operation's checks; enforce business
|
|
76
|
+
rules in `run()`. Omit `filters` for an operation without inputs. An operation
|
|
77
|
+
with its own fields, such as a detail record ID, adds an `input` parser and
|
|
78
|
+
representative valid `checks` for those fields; its `filters` still parse the
|
|
79
|
+
scope it reads. Derive results from `query()` rows
|
|
80
|
+
without duplicate schemas or type assertions; clients and views infer the
|
|
81
|
+
returned type. HTTP results must be JSON-serializable.
|
|
69
82
|
|
|
70
83
|
Host `queryParams` supplies protected parameters that callers cannot override.
|
|
71
84
|
Other values come from `query()` arguments or defaults. The host/backend enforces
|
|
@@ -82,51 +95,40 @@ return SQL text and declare `string` when exact numeric precision matters.
|
|
|
82
95
|
|
|
83
96
|
Use `operations.sampleCountsByGroup.queryNames` for context and evidence.
|
|
84
97
|
|
|
85
|
-
### Bind
|
|
98
|
+
### Bind date ranges
|
|
86
99
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
pass its `range` or `comparison` bounds. Reference those bounds in SQL:
|
|
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({
|
|
93
105
|
// ... title, description, and scope
|
|
94
106
|
queries: {
|
|
95
|
-
|
|
96
|
-
statement: `SELECT
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
107
|
+
dailyOrders: {
|
|
108
|
+
statement: `SELECT CAST(ordered_at AS DATE) AS day, count(*) AS orders
|
|
109
|
+
FROM orders
|
|
110
|
+
WHERE ordered_at >= CAST($period_from AS TIMESTAMP)
|
|
111
|
+
AND ordered_at < CAST($period_to AS TIMESTAMP)
|
|
112
|
+
GROUP BY day ORDER BY day`,
|
|
113
|
+
params: {
|
|
114
|
+
period_from: { type: 'string' },
|
|
115
|
+
period_to: { type: 'string' },
|
|
116
|
+
},
|
|
117
|
+
projections: {
|
|
118
|
+
day: { type: 'string' },
|
|
119
|
+
orders: { type: 'number' },
|
|
120
|
+
},
|
|
100
121
|
},
|
|
101
122
|
},
|
|
102
123
|
});
|
|
103
124
|
```
|
|
104
125
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
reporting timezone and interpret timestamp-with-timezone comparisons in that
|
|
110
|
-
same zone.
|
|
111
|
-
|
|
112
|
-
## Share reporting policy
|
|
113
|
-
|
|
114
|
-
Pass an optional `defineDateRangeContract()` to `dateTimeRangeVariable()` to
|
|
115
|
-
share coverage, duration limits, and reporting timezone between the picker and
|
|
116
|
-
server parser. By default, coverage ends yesterday; set `completeDays: false`
|
|
117
|
-
to include today. Declare the policy once:
|
|
118
|
-
|
|
119
|
-
```ts
|
|
120
|
-
import { defineDateRangeContract } from '@altertable/data-app/contract';
|
|
121
|
-
|
|
122
|
-
const calendar = defineDateRangeContract({
|
|
123
|
-
minDate: '2026-01-01',
|
|
124
|
-
maxRangeDays: 90,
|
|
125
|
-
timeZone: 'UTC',
|
|
126
|
-
});
|
|
127
|
-
```
|
|
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.
|
|
128
130
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
131
|
+
Date filters pass resolved bounds in their `timeZone`, encoded as UTC wall-clock
|
|
132
|
+
fields: 4 PM in the reporting zone is 16:00Z. SQL bounds are therefore
|
|
133
|
+
timezone-free timestamps; interpret timestamp-with-timezone columns in that same
|
|
134
|
+
zone. Coverage and duration limits live on the [date filter](filters.md#date-ranges).
|
package/docs/data-context.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# Data context and evidence
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Keep the selected starter's operations and context. Build one context from every
|
|
4
|
+
operation's `queryNames` and share it across the app's views. Reference only
|
|
5
|
+
queries the app executes.
|
|
5
6
|
|
|
6
7
|
## Bind evidence
|
|
7
8
|
|
|
@@ -9,23 +10,29 @@ business definitions and evidence. Reference only queries the view executes.
|
|
|
9
10
|
import { createDataContext } from '@altertable/data-app-react';
|
|
10
11
|
|
|
11
12
|
// ... operations
|
|
12
|
-
const queryNames =
|
|
13
|
+
const queryNames = {
|
|
14
|
+
...operations.sampleCountsByGroup.queryNames,
|
|
15
|
+
...operations.sampleTotal.queryNames,
|
|
16
|
+
};
|
|
13
17
|
const sampleDataContext = createDataContext(queryNames)({
|
|
14
18
|
description: 'Sample counts for the selected groups.',
|
|
15
19
|
glossary: {
|
|
16
20
|
sampleCount: {
|
|
17
21
|
term: 'Sample count',
|
|
18
22
|
definition: 'The number of samples in each group.',
|
|
19
|
-
queryNames: [queryNames.sampleCountsByGroup],
|
|
23
|
+
queryNames: [queryNames.sampleCountsByGroup, queryNames.sampleTotal],
|
|
20
24
|
},
|
|
21
25
|
},
|
|
22
26
|
});
|
|
23
27
|
```
|
|
24
28
|
|
|
29
|
+
This sample-count example uses the operations illustrated in [views](views.md).
|
|
25
30
|
Import `createDataContext()` from `@altertable/data-app-react`. Supply
|
|
26
|
-
`dataContext: sampleDataContext` on
|
|
31
|
+
`dataContext: sampleDataContext` on each view, then use its glossary IDs
|
|
27
32
|
in `view.metric()` and `view.dataset()`. Reuse those bindings in widgets and stories.
|
|
28
|
-
|
|
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.
|
|
29
36
|
|
|
30
37
|
## Register source identifiers
|
|
31
38
|
|
package/docs/diagnostics.md
CHANGED
|
@@ -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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
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
|
-
##
|
|
41
|
+
## Repair UI
|
|
48
42
|
|
|
49
|
-
Use `session.snapshot()` to read diagnostics,
|
|
50
|
-
request count, and the latest request's start
|
|
51
|
-
`session.subscribe()` and request a fix with
|
|
52
|
-
work without React
|
|
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
|
|
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.
|
|
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 `
|
|
174
|
-
|
|
175
|
-
|
|
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
|
-
##
|
|
177
|
+
## Registered query route
|
|
178
178
|
|
|
179
|
-
Hosts serving browser-owned operations register `
|
|
179
|
+
Hosts serving browser-owned operations register `registeredQueryRoute`:
|
|
180
180
|
|
|
181
181
|
```ts
|
|
182
182
|
import {
|
|
183
183
|
createMessageRouter,
|
|
184
|
-
|
|
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:
|
|
188
|
+
{ 'data:query': registeredQueryRoute },
|
|
190
189
|
{
|
|
191
|
-
'data:
|
|
192
|
-
|
|
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
|
|
200
|
-
|
|
201
|
-
time, concurrency, and response size
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
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
|
-
|
|
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
|