@altertable/data-app 0.77.0 → 0.79.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 (70) hide show
  1. package/AGENTS.md +3 -0
  2. package/CONTRIBUTING.md +5 -1
  3. package/REFERENCE.md +70 -180
  4. package/dist/chunks/contract-BTG-BUwW.js +1589 -0
  5. package/dist/chunks/contract-BTG-BUwW.js.map +1 -0
  6. package/dist/chunks/data-client-C4Pay-UE.js +122 -0
  7. package/dist/chunks/data-client-C4Pay-UE.js.map +1 -0
  8. package/dist/chunks/{date-time-range-value-CnlTr1U1.js → date-time-range-value-D-XfqVTT.js} +21 -24
  9. package/dist/chunks/date-time-range-value-D-XfqVTT.js.map +1 -0
  10. package/dist/chunks/{diagnostics-Dyj-rUsY.js → diagnostics-BwpM9wGn.js} +240 -63
  11. package/dist/chunks/diagnostics-BwpM9wGn.js.map +1 -0
  12. package/dist/chunks/record-Cr4Uk1K3.js +9 -0
  13. package/dist/chunks/record-Cr4Uk1K3.js.map +1 -0
  14. package/dist/client/index.js +4 -101
  15. package/dist/client/index.js.map +1 -1
  16. package/dist/core/appearance.js +3 -5
  17. package/dist/core/appearance.js.map +1 -1
  18. package/dist/core/config.js +12 -3
  19. package/dist/core/config.js.map +1 -1
  20. package/dist/core/contract.js +3 -4
  21. package/dist/core/format.js +1 -1
  22. package/dist/internal.js +63 -11
  23. package/dist/internal.js.map +1 -1
  24. package/dist/types/chunks/contract.d.ts +260 -20
  25. package/dist/types/chunks/data-client.d.ts +46 -0
  26. package/dist/types/chunks/date-time-range-value.d.ts +28 -2
  27. package/dist/types/chunks/index.d.ts +65 -80
  28. package/dist/types/client/index.d.ts +4 -3
  29. package/dist/types/core/config.d.ts +13 -4
  30. package/dist/types/core/contract.d.ts +3 -5
  31. package/dist/types/core/format.d.ts +1 -2
  32. package/dist/types/index.d.ts +4 -4
  33. package/dist/types/internal.d.ts +25 -6
  34. package/docs/app-authoring.md +160 -72
  35. package/docs/client.md +14 -53
  36. package/docs/contract.md +47 -26
  37. package/docs/data-context.md +11 -11
  38. package/docs/diagnostics.md +16 -23
  39. package/docs/embed.md +60 -25
  40. package/docs/filters.md +39 -65
  41. package/docs/formatting-and-appearance.md +2 -5
  42. package/docs/hosted-apps.md +11 -11
  43. package/docs/layout.md +21 -0
  44. package/docs/local-data-apps.md +10 -7
  45. package/docs/react-embed.md +44 -2
  46. package/docs/react.md +2 -5
  47. package/docs/server-bun.md +8 -5
  48. package/docs/stories-and-export.md +5 -6
  49. package/docs/styling.md +2 -1
  50. package/docs/ui.md +37 -10
  51. package/docs/views.md +18 -19
  52. package/docs/widgets.md +10 -11
  53. package/docs/worker.md +1 -1
  54. package/package.json +1 -5
  55. package/dist/chunks/contract-BQsFReRp.js +0 -780
  56. package/dist/chunks/contract-BQsFReRp.js.map +0 -1
  57. package/dist/chunks/contract-VhY9V9wd.js +0 -806
  58. package/dist/chunks/contract-VhY9V9wd.js.map +0 -1
  59. package/dist/chunks/date-time-range-value-CnlTr1U1.js.map +0 -1
  60. package/dist/chunks/diagnostics-Dyj-rUsY.js.map +0 -1
  61. package/dist/chunks/operation-BVRM-A5Y.js +0 -134
  62. package/dist/chunks/operation-BVRM-A5Y.js.map +0 -1
  63. package/dist/chunks/request-body-H1qPmmTN.js +0 -50
  64. package/dist/chunks/request-body-H1qPmmTN.js.map +0 -1
  65. package/dist/server/index.js +0 -90
  66. package/dist/server/index.js.map +0 -1
  67. package/dist/types/chunks/contract2.d.ts +0 -221
  68. package/dist/types/chunks/date-time-range.d.ts +0 -29
  69. package/dist/types/server/index.d.ts +0 -17
  70. package/docs/server.md +0 -41
@@ -14,78 +14,162 @@ for the requested change. For a new app, use the starter supplied by the authori
14
14
  | Hosted / remote / cloud | `starter-data-app/index.tsx` |
15
15
  | Local | `starter-local-data-app` |
16
16
  | Hosted metric | `starter-metric-data-app/index.tsx` |
17
- | Hosted Finding | `starter-finding-data-app/index.tsx` |
18
17
  | Local metric | `starter-local-metric-data-app` |
18
+ | Hosted Finding | `starter-finding-data-app/index.tsx` |
19
19
  | Local Finding | `starter-local-finding-data-app` |
20
20
 
21
- Choose the runtime and use case supplied by the app brief. Each starter is editable
22
- source; replace fixture queries and sample content before publishing. The hosted starter demonstrates query → operation
23
- → context → view → dataset → widget composition, including a story example.
24
- Hosted apps stay in one file with public package imports
25
- and a literal `defineDataApp()` declaration. Local apps use the same composition
26
- with their existing server/client wiring. Replace fixture data and connectivity screens; edit
27
- app-owned files, not installed packages.
28
-
29
- ## Connect data and components
30
-
31
- 1. **Define the question and scope.** Inspect relevant fields, definitions, time
32
- coverage, and missing or incomplete observations. Establish the population,
33
- grain, measures, and comparison. Choose a chart that answers the question.
34
- 2. **Write one query and operation per widget.** Give each metric, chart, and
35
- table its own named query and operation; do not combine unrelated results
36
- into one query. Write queries against inspected data and preserve supplied
37
- metric definitions. Declare `params` and result aliases in `projections`.
38
- Execute named queries with `query()` and derive results from its typed rows.
39
- 3. **Update context and bindings.** Describe definitions and coverage in the data
40
- context, using the operation's `queryNames` for evidence. Declare each dataset
41
- and metric once, with stable row keys, raw column values, and shared formats.
42
- 4. **Declare filters once, then one view per operation.** Declare each filter
43
- and display choice as a constant and list the ones each operation reads in
44
- its `filters`; the operation receives one flat input field per filter. Define
45
- each view with `defineView({ operation, dataContext })`: its filters,
46
- reporting period, and scope derive from the operation. Pass the headline view
47
- to `<DataApp view>`, which renders every filter's control, and render each
48
- view in its own `<DataSection>`. Keep protected values such as `orgId`
49
- backend-owned. See [views](views.md#give-each-widget-its-own-view) and
50
- [filters](filters.md).
51
- 5. **Compose the content.** Follow the app brief for section order and narrative.
52
- Use `<Stack>` for sections, `<Grid>` for peers, and bound widgets
53
- from `@altertable/data-app-react`. Keep static explanations outside loading
54
- boundaries. Use app tabs only for distinct questions and widget `views` only
55
- for alternate representations of one dataset. Keep default appearance;
56
- customize when requested. Use custom UI only when bound components cannot
57
- express the requirement.
58
- 6. **Connect shell features.** See [stories and export](stories-and-export.md)
59
- for the current `<DataApp>` requirements and how to bind these features to the
60
- displayed result. The app brief determines presentation content and export
61
- coverage.
62
-
63
- Keep credentials, authorization, and enforced query limits in the host/backend.
64
- The starter supplies transport and mounting; change them only for an explicit
65
- integration task.
66
-
67
- ## Link to external pages
68
-
69
- Use `<ExternalLink>` for HTTPS destinations in widget content:
70
-
71
- ```tsx
72
- import { ExternalLink } from '@altertable/data-app-react';
73
-
74
- function ReportLink() {
75
- return (
76
- <ExternalLink href="https://example.com/report">
77
- View full report
78
- </ExternalLink>
79
- );
80
- }
81
- ```
82
-
83
- For programmatic navigation, import `navigateNewTab`, `navigateNewWindow`, or
84
- `navigateNewWindowOrTab` from `@altertable/data-app/client`. For example,
85
- `navigateNewWindowOrTab(url, event)` accepts a DOM or React event: Shift requests
86
- a window, Ctrl/Cmd requests a tab, and an unmodified event does nothing.
87
-
88
- Embedded hosts must enable the [external link route](embed.md#external-links).
21
+ Choose the runtime and use case supplied by the app brief. The general starter
22
+ is one complete result: one query, operation, view, dataset, and chart. The
23
+ metric and Finding starters add a second result, drill-down, and comparison.
24
+ Hosted apps stay in one file with public package imports and a literal
25
+ `defineDataApp()` declaration. Local apps split the same code across app-owned
26
+ files. Edit app-owned files, not installed packages.
27
+
28
+ ## Write the app in order
29
+
30
+ Each step uses what the previous one declared. The snippets are the general
31
+ starter; repeat steps 2–7 for each independent result. Widgets share a result
32
+ when they show the same rows or metrics from one summary, such as a total, a
33
+ count, and their average.
34
+
35
+ 1. **Inspect the data.** Establish the population, grain, measures, and
36
+ comparison from real fields, definitions, time coverage, and missing
37
+ observations. Preserve supplied metric definitions.
38
+ 2. **Declare the query.** Write DuckDB SQL with named parameters, and declare
39
+ every parameter and result alias. See [queries](contract.md).
40
+
41
+ ```ts
42
+ export const dataApp = defineDataApp({
43
+ // ... title, description, and scope
44
+ queries: {
45
+ sampleCountsByGroup: {
46
+ statement: `
47
+ SELECT group_name, CAST(SUM(sample_count) AS BIGINT) AS sample_count
48
+ FROM sample_counts
49
+ WHERE $groupName = 'all' OR group_name = $groupName
50
+ GROUP BY group_name ORDER BY sample_count DESC, group_name LIMIT $limit`,
51
+ params: {
52
+ groupName: { type: 'string', defaultValue: 'all' },
53
+ limit: { type: 'number', defaultValue: 10 },
54
+ },
55
+ projections: {
56
+ group_name: { type: 'string' },
57
+ sample_count: { type: 'number' },
58
+ },
59
+ },
60
+ },
61
+ });
62
+ ```
63
+
64
+ 3. **Declare filters, then the operation that reads them.** Declare each filter
65
+ once as a constant. `run()` receives one field per filter and returns the
66
+ rows the app displays. See [filters](filters.md).
67
+
68
+ ```ts
69
+ const groupName = choiceFilter({
70
+ key: 'group',
71
+ label: 'Group',
72
+ defaultValue: 'all',
73
+ options: [
74
+ { id: 'all', label: 'All groups' },
75
+ { id: 'Alpha', label: 'Alpha' },
76
+ ],
77
+ });
78
+
79
+ export const operations = dataApp.defineOperations({
80
+ sampleCountsByGroup: dataApp.defineOperation({
81
+ filters: { groupName },
82
+ policy: { maxQueryRows: 10 },
83
+ async run({ query }, { groupName }) {
84
+ const { rows } = await query('sampleCountsByGroup', { groupName });
85
+ return rows.map(row => ({
86
+ groupName: row.group_name,
87
+ sampleCount: row.sample_count,
88
+ }));
89
+ },
90
+ }),
91
+ });
92
+ ```
93
+
94
+ 4. **Describe the data.** Define the terms readers need and cite the queries
95
+ behind each one. See [data context](data-context.md).
96
+
97
+ ```ts
98
+ const dataContext = createDataContext(dataApp.queryNames)({
99
+ description: 'Sample counts by group.',
100
+ glossary: {
101
+ sampleCount: {
102
+ term: 'Sample count',
103
+ definition: 'Sum of recorded samples in the selected group scope.',
104
+ queryNames: [dataApp.queryNames.sampleCountsByGroup],
105
+ },
106
+ },
107
+ });
108
+ ```
109
+
110
+ 5. **Define one view per operation.** Its filters, reporting period, and scope
111
+ derive from the operation. See [views](views.md).
112
+
113
+ ```ts
114
+ const { defineView } = createDataHooks(operations.createDataClient());
115
+ const sampleCountsView = defineView({
116
+ dataContext,
117
+ operation: 'sampleCountsByGroup',
118
+ emptyFallback: { title: 'No matching groups' },
119
+ });
120
+ ```
121
+
122
+ 6. **Bind a dataset or metric to the view.** A column named after a row field
123
+ reads it; a stable `rowKey` identifies each row. See
124
+ [widgets](widgets.md#declare-datasets-and-metrics).
125
+
126
+ ```ts
127
+ const sampleCounts = sampleCountsView.dataset({
128
+ name: 'Sample counts',
129
+ rowKey: row => row.groupName,
130
+ columns: {
131
+ groupName: { label: 'Group' },
132
+ sampleCount: { format: { kind: 'count' } },
133
+ },
134
+ evidence: { id: 'counts-by-group', glossaryIds: ['sampleCount'] },
135
+ });
136
+ ```
137
+
138
+ 7. **Render the result.** Pass the headline view to `<DataApp view>`, which
139
+ renders every filter's control, and give each view's content its own
140
+ `<DataSection>`. Follow the app brief for section order and narrative.
141
+
142
+ ```tsx
143
+ const countsContent = sampleCountsView.content(result => (
144
+ <VisualizationWidget dataset={sampleCounts} source={result}>
145
+ {rows => (
146
+ <BarChart
147
+ ariaLabel="Sample counts by group"
148
+ unit="samples"
149
+ items={rows.map(row => ({
150
+ id: row.groupName,
151
+ label: row.groupName,
152
+ value: row.sampleCount,
153
+ }))}
154
+ />
155
+ )}
156
+ </VisualizationWidget>
157
+ ));
158
+
159
+ function App() {
160
+ return (
161
+ <DataApp view={sampleCountsView} datasets={[sampleCounts]}>
162
+ <DataSection content={countsContent} />
163
+ </DataApp>
164
+ );
165
+ }
166
+ ```
167
+
168
+ Use bound widgets from `@altertable/data-app-react` for data-backed content.
169
+ Use [`/ui` components](ui.md) or custom UI only when a bound widget cannot
170
+ express the requirement. Keep credentials, authorization, protected values such
171
+ as `orgId`, and enforced query limits in the host/backend. The starter supplies
172
+ transport and mounting; change them only for an explicit integration task.
89
173
 
90
174
  ## Verify the app
91
175
 
@@ -108,10 +192,10 @@ for host integration.
108
192
 
109
193
  ## Look up only what is missing
110
194
 
111
- Search [REFERENCE.md](../REFERENCE.md) for the exact symbol first:
195
+ Search [REFERENCE.md](../REFERENCE.md) for the exact export or method first:
112
196
 
113
197
  ```sh
114
- rg '^LineChart\b' REFERENCE.md
198
+ rg '(^|\.)defineView\b' REFERENCE.md
115
199
  ```
116
200
 
117
201
  Open only the section needed for a requirement the starter does not cover:
@@ -120,8 +204,12 @@ Open only the section needed for a requirement the starter does not cover:
120
204
  | -------------------------------------------- | ----------------------------------------------------------------- |
121
205
  | Adding categorical, numeric, or time filters | [Filters](filters.md) |
122
206
  | Adding a chart or narrative binding | [Widgets](widgets.md) |
123
- | Adding supplemental control hints | [Tooltips](ui.md#tooltips-and-explanations) |
207
+ | Adding a second result or a summary | [Views](views.md#give-each-independent-result-its-own-view) |
124
208
  | Adding a detail destination | [Detail views](views.md#detail-destinations) |
209
+ | Adding a presentation story or CSV export | [Stories and export](stories-and-export.md) |
210
+ | Arranging sections or adapting to width | [Layout](layout.md) |
211
+ | Linking to external pages | [External links](ui.md#external-links) |
212
+ | Adding supplemental control hints | [Tooltips](ui.md#tooltips-and-explanations) |
125
213
  | Registering physical sources | [Source identifiers](data-context.md#register-source-identifiers) |
126
214
  | Customizing appearance or CSS | [Formatting](formatting-and-appearance.md), [styling](styling.md) |
127
215
 
package/docs/client.md CHANGED
@@ -1,71 +1,32 @@
1
1
  # Client
2
2
 
3
3
  Use this guide when customizing client delivery. Standard apps keep the
4
- starter's client. Import `createDataClient()` from `@altertable/data-app/client`.
4
+ starter's client.
5
5
 
6
- ## HTTP operations
6
+ ## Registered operations
7
7
 
8
- ```ts
9
- import { createDataClient } from '@altertable/data-app/client';
10
- import { operationFilters } from './filters.ts';
11
- import type { operations } from './operations.ts';
8
+ Hosted and local metric/finding starters use the same operation client:
12
9
 
13
- const client = createDataClient<typeof operations>({
14
- filters: operationFilters,
15
- });
16
- const response = await client.query(
17
- 'sampleCountsByGroup',
18
- { groupName: '' },
19
- { signal }
20
- );
10
+ ```ts
11
+ const operations = dataApp.defineOperations({ sampleCountsByGroup });
12
+ const client = operations.createDataClient();
21
13
  ```
22
14
 
23
- Keep the operations import type-only so implementations stay on the server.
24
- Pass the filters each operation reads from a browser-safe module both sides
25
- import ([shared filters](filters.md#share-filters-with-http-and-local-apps)).
26
- Inputs and data are inferred from the operation map and `run()`.
27
-
28
- The default endpoint is `/api/data`. Override it with
29
- `createDataClient<typeof operations>({ filters, endpoint, fetch })` to change the base URL or supply a Fetch
30
- implementation. Calls POST JSON to `/api/data/:operation`; the client sends
31
- 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.
32
20
 
33
21
  For direct client calls, render `response.data` and label it with `response.input`
34
22
  so retained results keep their original scope during refresh. React views handle
35
- this automatically. For custom error handling, import `DataAppError` from the same
36
- entry for public codes and request IDs. Pass an abort signal to cancel a request.
23
+ this automatically. Import `DataAppError` for public codes and request IDs.
24
+ Pass an abort signal to cancel a query.
37
25
 
38
- See [contracts](contract.md), [server handlers](server.md), and
39
- [React bindings](react.md).
40
-
41
- ## Browser-owned operations for bundle apps
42
-
43
- Bundle apps pass their operation registry as a value, which also supplies its
44
- filters:
45
-
46
- ```ts
47
- import { createDataClient } from '@altertable/data-app/client';
48
-
49
- // ... operations declared with dataApp.defineOperation()
50
- const client = createDataClient({ operations });
51
- const response = await client.query('sampleCountsByGroup', { groupName: '' });
52
- ```
53
-
54
- Operations run in the browser and query through the host's `data:sql` route.
55
- The trusted bootstrap installs the bridge before app execution. A custom runtime
56
- must install it first or supply an authorized `lakehouse` adapter.
57
-
58
- Do not combine `operations` with `transport`, `endpoint`, or `fetch`. Browser
59
- policy bounds app requests; the [host SQL handler](embed.md#sql-query-route)
60
- must independently enforce access and resource limits.
26
+ See [contracts](contract.md) and [React bindings](react.md).
61
27
 
62
28
  ## Iframe transport
63
29
 
64
- `createDataClient<typeof operations>({ filters, transport })` accepts a `DataTransport`. Without an explicit
65
- transport, endpoint, or Fetch implementation, it discovers an installed iframe
66
- transport before falling back to HTTP. Explicit endpoint/Fetch options select
67
- HTTP. `createHttpTransport()` provides the underlying operation delivery adapter.
68
-
69
30
  A URL-hosted app configures trust and installs the bridge before mounting:
70
31
 
71
32
  ```ts
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';
@@ -19,10 +21,10 @@ const dataApp = defineDataApp({
19
21
  statement: `
20
22
  WITH sample_counts(group_name, sample_count) AS (VALUES ('Alpha', 2200000), ('Beta', 0))
21
23
  SELECT group_name, sample_count FROM sample_counts
22
- WHERE $groupName = '' OR group_name = $groupName
24
+ WHERE $groupName = 'all' OR group_name = $groupName
23
25
  ORDER BY group_name LIMIT $limit`,
24
26
  params: {
25
- groupName: { type: 'string', defaultValue: '' },
27
+ groupName: { type: 'string', defaultValue: 'all' },
26
28
  limit: { type: 'number', defaultValue: 10 },
27
29
  },
28
30
  projections: {
@@ -40,23 +42,32 @@ 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 } 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
- policy: { maxQueryRows: 10, maxDurationMs: 15000 },
61
+ policy: { maxQueryRows: 10 },
51
62
  async run({ query }, { groupName }) {
52
- const result = await query('sampleCountsByGroup', { groupName });
53
- return result.rows.map(row => ({
63
+ const { rows } = await query('sampleCountsByGroup', { groupName });
64
+ return rows.map(row => ({
54
65
  groupName: row.group_name,
55
- sampleCount: parseCount(row.sample_count),
66
+ sampleCount: row.sample_count,
56
67
  }));
57
68
  },
58
69
  }),
59
- };
70
+ });
60
71
  ```
61
72
 
62
73
  The filters validate input and supply the operation's checks; enforce business
@@ -69,24 +80,26 @@ returned type. HTTP results must be JSON-serializable.
69
80
 
70
81
  Host `queryParams` supplies protected parameters that callers cannot override.
71
82
  Other values come from `query()` arguments or defaults. The host/backend enforces
72
- data access and limits. Operation policies must set `maxQueryRows` to a positive
73
- integer no greater than 10,000. The shared SQL host handler also rejects requests
74
- for more than 10,000 rows.
83
+ data access and limits. Each operation's `policy` sets `maxQueryRows` to a positive
84
+ integer no greater than 10,000, which also limits each `query()` unless it passes
85
+ its own `limit`. The shared SQL host handler also rejects requests for more than
86
+ 10,000 rows.
75
87
 
76
88
  ### Declare query projections
77
89
 
78
90
  Declare every returned SQL alias with `{ type, nullable? }` and keep its exact
79
91
  casing. Infer nullability from the schema and SQL, not sampled rows. Update
80
- projections when changing SQL. `query()` converts cells to declared types;
81
- return SQL text and declare `string` when exact numeric precision matters.
92
+ projections when changing SQL. `query()` converts cells to declared types, so a
93
+ `number` projection is already a number; return SQL text and declare `string`
94
+ when exact numeric precision matters. Use `parseCount()` only to reject negative
95
+ or fractional counts.
82
96
 
83
- Use `operations.sampleCountsByGroup.queryNames` for context and evidence.
97
+ Use `dataApp.queryNames` for context and evidence.
84
98
 
85
99
  ### Bind date ranges
86
100
 
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):
101
+ Bind a date filter's `range` or `comparison` as two string parameters. Cast
102
+ them to DuckDB `TIMESTAMP`; include the start and exclude the end:
90
103
 
91
104
  ```ts
92
105
  const dataApp = defineDataApp({
@@ -95,9 +108,13 @@ const dataApp = defineDataApp({
95
108
  dailyOrders: {
96
109
  statement: `SELECT CAST(ordered_at AS DATE) AS day, count(*) AS orders
97
110
  FROM orders
98
- WHERE ordered_at >= $period.from AND ordered_at < $period.to
111
+ WHERE ordered_at >= CAST($period_from AS TIMESTAMP)
112
+ AND ordered_at < CAST($period_to AS TIMESTAMP)
99
113
  GROUP BY day ORDER BY day`,
100
- params: { period: { type: 'dateTimeRange' } },
114
+ params: {
115
+ period_from: { type: 'string' },
116
+ period_to: { type: 'string' },
117
+ },
101
118
  projections: {
102
119
  day: { type: 'string' },
103
120
  orders: { type: 'number' },
@@ -107,8 +124,12 @@ const dataApp = defineDataApp({
107
124
  });
108
125
  ```
109
126
 
127
+ In the operation, import `queryDateTimeRangeParams` from
128
+ `@altertable/data-app/contract` and call
129
+ `query('dailyOrders', queryDateTimeRangeParams(periodFilter, period, 'period').current)`.
130
+ This resolves relative bounds when the query runs.
131
+
110
132
  Date filters pass resolved bounds in their `timeZone`, encoded as UTC wall-clock
111
133
  fields: 4 PM in the reporting zone is 16:00Z. SQL bounds are therefore
112
134
  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).
135
+ zone. Coverage and duration limits live on the [date filter](filters.md#date-ranges).
@@ -1,19 +1,16 @@
1
1
  # Data context and evidence
2
2
 
3
- Continue the 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.
3
+ Keep the selected starter's operations and context. Build one context from
4
+ `dataApp.queryNames` and share it across the app's views. Each glossary entry
5
+ and dataset cites the queries that support it.
6
6
 
7
7
  ## Bind evidence
8
8
 
9
9
  ```tsx
10
10
  import { createDataContext } from '@altertable/data-app-react';
11
11
 
12
- // ... operations
13
- const queryNames = {
14
- ...operations.sampleCountsByGroup.queryNames,
15
- ...operations.sampleTotal.queryNames,
16
- };
12
+ // ... dataApp
13
+ const { queryNames } = dataApp;
17
14
  const sampleDataContext = createDataContext(queryNames)({
18
15
  description: 'Sample counts for the selected groups.',
19
16
  glossary: {
@@ -26,10 +23,13 @@ const sampleDataContext = createDataContext(queryNames)({
26
23
  });
27
24
  ```
28
25
 
26
+ This sample-count example uses the operations illustrated in [views](views.md).
29
27
  Import `createDataContext()` from `@altertable/data-app-react`. Supply
30
28
  `dataContext: sampleDataContext` on each view, then use its glossary IDs
31
29
  in `view.metric()` and `view.dataset()`. Reuse those bindings in widgets and stories.
32
- Detail views need their own context when their queries differ.
30
+ Include detail operations' query names and definitions in the shared context.
31
+ A detail view can use a separate context when it needs different definitions or
32
+ coverage; a different query alone does not require one.
33
33
 
34
34
  ## Register source identifiers
35
35
 
@@ -55,8 +55,8 @@ const identifiers = defineDataIdentifiers({
55
55
  });
56
56
  const { DataIdentifier } = identifiers;
57
57
 
58
- // ... queryNames for the inspected source
59
- const eventDataContext = createDataContext(queryNames)({
58
+ // ... dataApp for the inspected source
59
+ const eventDataContext = createDataContext(dataApp.queryNames)({
60
60
  identifiers: identifiers.definitions,
61
61
  description: (
62
62
  <>
@@ -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.