@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.
Files changed (69) hide show
  1. package/CONTRIBUTING.md +3 -0
  2. package/REFERENCE.md +392 -276
  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-TE8KCsfV.js → date-time-range-value-D-XfqVTT.js} +28 -31
  8. package/dist/chunks/date-time-range-value-D-XfqVTT.js.map +1 -0
  9. package/dist/chunks/{diagnostics-DhCqGklq.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 -86
  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 +58 -124
  22. package/dist/internal.js.map +1 -1
  23. package/dist/types/chunks/contract.d.ts +592 -308
  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 -53
  27. package/dist/types/client/index.d.ts +4 -3
  28. package/dist/types/core/config.d.ts +16 -6
  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 +26 -7
  33. package/docs/app-authoring.md +23 -14
  34. package/docs/client.md +14 -48
  35. package/docs/contract.md +58 -56
  36. package/docs/data-context.md +13 -6
  37. package/docs/diagnostics.md +16 -23
  38. package/docs/embed.md +60 -25
  39. package/docs/filters.md +271 -0
  40. package/docs/hosted-apps.md +11 -10
  41. package/docs/layout.md +45 -18
  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 +23 -14
  47. package/docs/styling.md +2 -1
  48. package/docs/ui.md +18 -8
  49. package/docs/views.md +63 -26
  50. package/docs/widgets.md +40 -16
  51. package/docs/worker.md +1 -1
  52. package/package.json +1 -5
  53. package/dist/chunks/contract-DsyRYgN_.js +0 -626
  54. package/dist/chunks/contract-DsyRYgN_.js.map +0 -1
  55. package/dist/chunks/contract-kNFYPHRK.js +0 -713
  56. package/dist/chunks/contract-kNFYPHRK.js.map +0 -1
  57. package/dist/chunks/date-time-range-value-TE8KCsfV.js.map +0 -1
  58. package/dist/chunks/diagnostics-DhCqGklq.js.map +0 -1
  59. package/dist/chunks/operation-7tiT4cpJ.js +0 -134
  60. package/dist/chunks/operation-7tiT4cpJ.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 -207
  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
  69. package/docs/variables.md +0 -280
package/docs/variables.md DELETED
@@ -1,280 +0,0 @@
1
- # Variables and filters
2
-
3
- Declare controls once in the view's `variables`; `<DataApp view={view}>` renders
4
- them and owns URL state. Use flat operation inputs matching variable names and
5
- resolved types. Derive SQL parameters inside the operation.
6
-
7
- ## Declare controls once
8
-
9
- The starter's operation accepts `{ groupName: string }`, so it needs no `input`
10
- mapper or explicit `bindings`:
11
-
12
- ```ts
13
- // ... client and sampleDataContext
14
- const { defineDataView } = createDataHooks(client);
15
-
16
- const sampleCountsView = defineDataView({
17
- dataContext: sampleDataContext,
18
- operation: 'sampleCountsByGroup',
19
- variables: {
20
- groupName: searchVariable({
21
- key: 'group',
22
- label: 'Group',
23
- defaultValue: '',
24
- }),
25
- },
26
- describeInput: ({ groupName }) =>
27
- groupName ? `group ${groupName}` : 'all groups',
28
- isEmpty: rows => rows.length === 0,
29
- emptyFallback: { title: 'No matching groups' },
30
- });
31
- ```
32
-
33
- Keep search local only when it filters already loaded rows. Add dataset
34
- `suggestions` when record names make useful query completions; suggestions cover
35
- supplied rows only.
36
-
37
- ## Independent filters and chart breakdowns
38
-
39
- For source-backed categorical members, use `dataApp.defineDimension()`:
40
-
41
- ```ts
42
- // ... dataApp with its registered groups query
43
- const group = dataApp.defineDimension({
44
- key: 'group',
45
- label: 'Group',
46
- valueType: 'string',
47
- selectionMode: 'multiple',
48
- source: { query: 'groups' },
49
- });
50
- const parseInput = variableInput(parseEmptyInput, { group });
51
- ```
52
-
53
- Import `variableInput()` and `parseEmptyInput()` from `/contract`. Use `parseInput`
54
- on the operation and declare the same `group` in the view's `variables`. Use an
55
- app-owned base parser instead of `parseEmptyInput()` for other input fields.
56
-
57
- Declare the source query in `defineDataApp()` with a nullable `member` parameter
58
- matching `valueType`. Its nonnullable projections are `value` (same type),
59
- `label` (string), and optional `count` (number). Null requests options; a selected
60
- member requests exact lookup. Other parameters need defaults or trusted values:
61
-
62
- ```sql
63
- SELECT DISTINCT group_name AS value, group_name AS label
64
- FROM sample_counts
65
- WHERE ($member IS NULL OR group_name = $member)
66
- ORDER BY label
67
- ```
68
-
69
- Here `sample_counts` is the inspected table replacing the starter's fixture.
70
- Validate these variables in every consuming operation, including details. Map
71
- parsed predicates to declared query parameters; never interpolate filter values
72
- into SQL. Each dimension is independent: changing one preserves other selections,
73
- even when their combination returns no rows. No selection means all members.
74
-
75
- ### Chart breakdowns
76
-
77
- Use `choiceVariable()` for a display choice, separately from population filters:
78
-
79
- ```ts
80
- const countsBy = choiceVariable({
81
- key: 'counts-by',
82
- label: 'Counts breakdown',
83
- defaultValue: 'group',
84
- options: [
85
- { id: 'group', label: 'Group' },
86
- { id: 'country', label: 'Country' },
87
- ],
88
- presentation: { group: 'display', control: 'widget' },
89
- });
90
- ```
91
-
92
- Pass `view.breakdown('countsBy')` to `<VisualizationWidget breakdown={...}>`.
93
- Declare a separate choice for each independently controlled chart.
94
- Use `presentation.prominence: 'secondary'` for less frequent scope filters.
95
-
96
- ## Fixed options and query-backed facets
97
-
98
- Use `dimensionFilter()` from `/contract` when options are known constants:
99
-
100
- ```ts
101
- const group = dimensionFilter({
102
- key: 'group',
103
- label: 'Group',
104
- valueType: 'string',
105
- selectionMode: 'multiple',
106
- options: [
107
- { value: 'Alpha', label: 'Alpha' },
108
- { value: 'Beta', label: 'Beta' },
109
- ],
110
- });
111
- ```
112
-
113
- Use `defineFacetFilter()` only when options must depend on other selections:
114
-
115
- ```ts
116
- // ... client and period variable
117
- const { defineFacetFilter } = createDataHooks(client);
118
-
119
- const group = defineFacetFilter({
120
- key: 'group',
121
- label: 'Group',
122
- valueType: 'string',
123
- selectionMode: 'multiple',
124
- facet: {
125
- context: { period },
126
- operation: 'groups',
127
- input: values => ({ period: values.period }),
128
- },
129
- });
130
- ```
131
-
132
- Declare `period` with `dateTimeRangeVariable()`, include it alongside `group` in the view's variables,
133
- and return parsed dimension options from the `groups` operation. Validate facet
134
- selections with `parseDimensionSelection(value, group)` from `/contract`.
135
-
136
- Use `single` for a replacement choice and `multiple` for independent members.
137
- Enable `allowExclusion` only when the query supports exclusion and its intended
138
- missing-value behavior. Use `multiChoiceVariable()` for fixed multiselect
139
- choices; empty means no choices, unlike an unrestricted dimension.
140
-
141
- ## Reporting periods
142
-
143
- Use `defineTimeView()` when the analysis is period-driven. Declare a
144
- `dateTimeRangeVariable()` and share its `defineDateRangeContract()` with the
145
- operation parser. Datetime bounds include `from` and exclude `to`; the `period`
146
- URL value stores the datetime selection. After adapting the operation to accept
147
- `{ period, groupName }`, the view can stay flat:
148
-
149
- ```ts
150
- // ... client, dailyCountsContext, and calendar contract
151
- const { defineTimeView } = createDataHooks(client);
152
- const period = dateTimeRangeVariable({
153
- key: 'period',
154
- contract: calendar,
155
- defaultValue: {
156
- from: new Date('2026-03-04T00:00:00Z'),
157
- to: new Date('2026-03-11T00:00:00Z'),
158
- },
159
- });
160
-
161
- const dailyCountsView = defineTimeView({
162
- dataContext: dailyCountsContext,
163
- operation: 'dailyCountsByGroup',
164
- time: period,
165
- variables: {
166
- groupName: searchVariable({
167
- key: 'group',
168
- label: 'Group',
169
- defaultValue: '',
170
- }),
171
- },
172
- isEmpty: rows => rows.length === 0,
173
- emptyFallback: { title: 'No matching groups' },
174
- });
175
- ```
176
-
177
- The operation's parser validates `period` with `period.parse()` or
178
- `period.parseInput()` when comparison is enabled. Resolved comparison requests
179
- have exclusive `range.to` and `comparison.to` bounds.
180
- Use `defineDataView()` for fixed snapshots or analysis without a reporting period.
181
-
182
- ## Numeric and boolean predicates
183
-
184
- Use `numberFilter()` or `booleanFilter()` from `/contract` for field predicates.
185
- Declare them in `variables` and validate input with `parseNumberSelection()` or
186
- `parseBooleanSelection()` using the same declarations. Both support
187
- `{ kind: 'all' }`. Offer only predicates the registered query supports.
188
-
189
- ## Exclusion, clear, and reset
190
-
191
- Clear removes scope predicates and returns dates to defaults, preserving search
192
- and display choices. `resetAll()` restores all defaults. Filters apply immediately;
193
- use app-owned drafts only when the task needs Apply/Cancel.
194
-
195
- ## Adapt existing input shapes
196
-
197
- Add a mapper and bindings only when an existing operation requires nested or
198
- differently named inputs. Preserve selected values unchanged in both directions:
199
-
200
- ```ts
201
- // ... client; operation input is { filters: { period, groupName } }
202
- const { defineTimeView } = createDataHooks(client);
203
-
204
- const dailyCountsView = defineTimeView({
205
- // ... operation, dataContext, time, variables, isEmpty, and emptyFallback
206
- input: values => ({
207
- filters: { period: values.period, groupName: values.groupName },
208
- }),
209
- bindings: {
210
- period: input => input.filters.period,
211
- groupName: input => input.filters.groupName,
212
- },
213
- });
214
- ```
215
-
216
- Custom control ownership is needed only when generated controls cannot express
217
- the requirement; use `/ui` for that case. Do not reuse reserved inspection,
218
- presentation, or navigation URL keys.
219
-
220
- ## Absolute and relative datetime ranges
221
-
222
- Use `dateTimeRangeVariable()` for calendar days, times, rolling windows, or
223
- mixed absolute and relative bounds. Share the variable between the operation parser and the view;
224
- `<DataApp>` supplies the picker and URL state:
225
-
226
- ```ts
227
- import {
228
- dateTimeRangeVariable,
229
- dateTimeRangePresets,
230
- defineDateRangeContract,
231
- variableInput,
232
- } from '@altertable/data-app/contract';
233
- import { createDataHooks } from '@altertable/data-app-react';
234
-
235
- const calendar = defineDateRangeContract({
236
- maxRangeDays: 366,
237
- timeZone: 'UTC',
238
- completeDays: false,
239
- });
240
- const period = dateTimeRangeVariable({
241
- key: 'period',
242
- contract: calendar,
243
- allowComparison: true,
244
- defaultValue: '30d',
245
- presets: [
246
- ...dateTimeRangePresets.analytics,
247
- { label: 'Past 6 months', range: '6mo', shortcut: '6mo' },
248
- ],
249
- });
250
- const events = dataApp.defineOperation({
251
- input: variableInput(() => ({}), { period }),
252
- checks: [{ period: period.input(period.defaultValue) }],
253
- policy: { maxQueryRows: 1000, maxDurationMs: 15000 },
254
- async run({ query }, input) {
255
- const current = await query('events', { period: input.period.range });
256
- const previous = input.period.comparison
257
- ? await query('events', { period: input.period.comparison })
258
- : null;
259
- return { current: current.rows, previous: previous?.rows ?? null };
260
- },
261
- });
262
- // ... client created from { events }, and eventsContext
263
- const { defineTimeView } = createDataHooks(client);
264
- const eventsView = defineTimeView({
265
- operation: 'events',
266
- dataContext: eventsContext,
267
- time: period,
268
- isEmpty: result => result.current.length === 0,
269
- emptyFallback: { title: 'No events' },
270
- });
271
- ```
272
-
273
- Use `dateTimeRangePresets.monitoring` for shorter windows. Bind the query bounds
274
- to a [datetime parameter](contract.md#bind-datetime-ranges).
275
- `allowComparison: true` adds the toggle and supplies current/previous ranges resolved
276
- against one reference time; the view derives metric comparison labels from that
277
- request. Omit `comparison` for a plain `DateTimeRange` input, and omit `contract`
278
- when no shared reporting policy is needed. Relative selections stay relative
279
- across reloads. Query `from` inclusively and `to` exclusively. A September 24–30
280
- calendar selection uses `2026-09-24T00:00:00Z` through `2026-10-01T00:00:00Z`.