@altertable/data-app-examples 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 (34) hide show
  1. package/package.json +1 -1
  2. package/templates/starter-data-app/index.tsx +686 -136
  3. package/templates/starter-finding-data-app/index.tsx +530 -188
  4. package/templates/starter-local-data-app/AGENTS.md +9 -9
  5. package/templates/starter-local-data-app/README.md +14 -5
  6. package/templates/starter-local-data-app/app.ts +256 -21
  7. package/templates/starter-local-data-app/package.json +5 -5
  8. package/templates/starter-local-data-app/src/App.tsx +276 -5
  9. package/templates/starter-local-data-app/src/data-context.ts +28 -14
  10. package/templates/starter-local-data-app/src/filters.ts +35 -0
  11. package/templates/starter-local-data-app/src/main.tsx +3 -3
  12. package/templates/starter-local-data-app/src/operations.ts +129 -4
  13. package/templates/starter-local-data-app/src/server.ts +1 -2
  14. package/templates/starter-local-finding-data-app/AGENTS.md +9 -9
  15. package/templates/starter-local-finding-data-app/README.md +3 -4
  16. package/templates/starter-local-finding-data-app/app.ts +63 -34
  17. package/templates/starter-local-finding-data-app/package.json +5 -5
  18. package/templates/starter-local-finding-data-app/src/App.tsx +308 -126
  19. package/templates/starter-local-finding-data-app/src/data-context.ts +19 -4
  20. package/templates/starter-local-finding-data-app/src/filters.ts +66 -0
  21. package/templates/starter-local-finding-data-app/src/main.tsx +3 -3
  22. package/templates/starter-local-finding-data-app/src/operations.ts +101 -37
  23. package/templates/starter-local-finding-data-app/src/server.ts +4 -2
  24. package/templates/starter-local-metric-data-app/AGENTS.md +9 -9
  25. package/templates/starter-local-metric-data-app/README.md +3 -4
  26. package/templates/starter-local-metric-data-app/app.ts +5 -2
  27. package/templates/starter-local-metric-data-app/package.json +5 -5
  28. package/templates/starter-local-metric-data-app/src/App.tsx +69 -71
  29. package/templates/starter-local-metric-data-app/src/data-context.ts +9 -5
  30. package/templates/starter-local-metric-data-app/src/filters.ts +18 -0
  31. package/templates/starter-local-metric-data-app/src/main.tsx +3 -3
  32. package/templates/starter-local-metric-data-app/src/operations.ts +34 -41
  33. package/templates/starter-local-metric-data-app/src/server.ts +4 -2
  34. package/templates/starter-metric-data-app/index.tsx +125 -122
@@ -1,41 +1,106 @@
1
- import { parseCount } from '@altertable/data-app/contract';
1
+ import {
2
+ parseCount,
3
+ queryDateTimeRangeParams,
4
+ } from '@altertable/data-app/contract';
2
5
 
3
- import { dataApp, period } from '#config';
4
- export const operations = {
5
- samples: dataApp.defineOperation({
6
- input: value => {
7
- const {
8
- period: selection,
6
+ import { operationFilters, periodFilter } from '#app/filters.ts';
7
+ import { dataApp } from '#config';
8
+
9
+ const policy = { maxQueryRows: 500, maxDurationMs: 15000 };
10
+ export const operations = dataApp.defineOperations({
11
+ sampleTotals: dataApp.defineOperation({
12
+ filters: operationFilters.sampleTotals,
13
+ policy,
14
+ async run({ query }, { period, groupName }) {
15
+ const bounds = queryDateTimeRangeParams(periodFilter, period, 'period');
16
+ const [current, previous] = await Promise.all([
17
+ query('sampleTotals', { ...bounds.current, groupName }),
18
+ bounds.comparison
19
+ ? query('sampleTotals', { ...bounds.comparison, groupName })
20
+ : null,
21
+ ]);
22
+ const row = current.rows[0];
23
+ if (!row) return [];
24
+ const baseline = previous?.rows[0];
25
+ return [
26
+ {
27
+ currentCount: parseCount(row.sample_count),
28
+ previousCount: baseline ? parseCount(baseline.sample_count) : null,
29
+ },
30
+ ];
31
+ },
32
+ }),
33
+ samplesOverTime: dataApp.defineOperation({
34
+ filters: operationFilters.samplesOverTime,
35
+ policy,
36
+ async run({ query }, { period, groupName, grain }) {
37
+ const bounds = queryDateTimeRangeParams(periodFilter, period, 'period');
38
+ const result = await query('samplesOverTime', {
39
+ ...bounds.combined,
40
+ groupName,
9
41
  grain,
10
- breakdown,
11
- } = (value ?? {}) as Record<string, unknown>;
12
- if (grain !== 'day' && grain !== 'week')
13
- throw new Error('Expected a day or week grain.');
14
- if (breakdown !== 'segment' && breakdown !== 'group')
15
- throw new Error('Expected a segment or group breakdown.');
16
- return { period: period.parseInput(selection), grain, breakdown };
42
+ });
43
+ return result.rows.map(row => ({
44
+ periodStart: row.period_start,
45
+ sampleCount: parseCount(row.sample_count),
46
+ }));
17
47
  },
18
- checks: [
19
- {
20
- period: period.input({
21
- ...period.defaultValue,
22
- comparison: 'previous',
23
- }),
24
- grain: 'day',
25
- breakdown: 'segment',
26
- },
27
- {
28
- period: period.input(period.defaultValue),
29
- grain: 'week',
30
- breakdown: 'group',
31
- },
32
- ],
33
- policy: { maxQueryRows: 500, maxDurationMs: 15000 },
34
- async run({ query }, { period: { range, comparison }, grain, breakdown }) {
35
- const result = await query('samples', {
36
- start: (comparison?.from ?? range.from).toISOString(),
37
- end: range.to.toISOString(),
38
- selected_start: range.from.toISOString(),
48
+ }),
49
+ samplesByMember: dataApp.defineOperation({
50
+ filters: operationFilters.samplesByMember,
51
+ policy,
52
+ async run({ query }, { period, groupName, breakdown }) {
53
+ const bounds = queryDateTimeRangeParams(periodFilter, period, 'period');
54
+ const [current, previous] = await Promise.all([
55
+ query('samplesByMember', { ...bounds.current, groupName, breakdown }),
56
+ bounds.comparison
57
+ ? query('samplesByMember', {
58
+ ...bounds.comparison,
59
+ groupName,
60
+ breakdown,
61
+ })
62
+ : null,
63
+ ]);
64
+ const currentCounts = new Map(
65
+ current.rows.map(row => [row.member, parseCount(row.sample_count)])
66
+ );
67
+ const previousCounts = new Map(
68
+ previous?.rows.map(row => [row.member, parseCount(row.sample_count)])
69
+ );
70
+ const members = new Set([
71
+ ...currentCounts.keys(),
72
+ ...previousCounts.keys(),
73
+ ]);
74
+ return [...members]
75
+ .map(member => {
76
+ const currentCount = currentCounts.get(member) ?? null;
77
+ const previousCount = previousCounts.get(member) ?? null;
78
+ const change =
79
+ currentCount !== null && previousCount !== null
80
+ ? currentCount - previousCount
81
+ : null;
82
+ return {
83
+ member,
84
+ currentCount,
85
+ previousCount,
86
+ change,
87
+ changeRate:
88
+ change !== null && previousCount !== null && previousCount > 0
89
+ ? change / previousCount
90
+ : null,
91
+ };
92
+ })
93
+ .sort((a, b) => Math.abs(b.change ?? 0) - Math.abs(a.change ?? 0));
94
+ },
95
+ }),
96
+ sampleRows: dataApp.defineOperation({
97
+ filters: operationFilters.sampleRows,
98
+ policy,
99
+ async run({ query }, { period, groupName, grain, breakdown }) {
100
+ const bounds = queryDateTimeRangeParams(periodFilter, period, 'period');
101
+ const result = await query('sampleRows', {
102
+ ...bounds.combined,
103
+ groupName,
39
104
  grain,
40
105
  breakdown,
41
106
  });
@@ -43,8 +108,7 @@ export const operations = {
43
108
  periodStart: row.period_start,
44
109
  member: row.member,
45
110
  sampleCount: parseCount(row.sample_count),
46
- selected: row.selected,
47
111
  }));
48
112
  },
49
113
  }),
50
- };
114
+ });
@@ -1,7 +1,9 @@
1
1
  import { serveLocalApp } from '@altertable/data-app-bun';
2
2
 
3
3
  import page from '#app/index.html';
4
- import { operations } from '#app/operations.ts';
5
4
  import { dataApp } from '#config';
6
5
 
7
- serveLocalApp({ page, operations, title: dataApp.title });
6
+ serveLocalApp({
7
+ page,
8
+ app: dataApp,
9
+ });
@@ -2,16 +2,16 @@
2
2
 
3
3
  Read `node_modules/@altertable/data-app/docs/app-authoring.md` and use this project
4
4
  as the selected scaffold. If dependencies are unavailable, read the
5
- [version-matched recipe](https://github.com/altertable-ai/data-app/blob/v0.76.0/docs/app-authoring.md). <!-- x-release-please-version -->
5
+ [version-matched recipe](https://github.com/altertable-ai/data-app/blob/v0.78.0/docs/app-authoring.md). <!-- x-release-please-version -->
6
6
 
7
- | Task | App-owned files |
8
- | ------------------------------------------ | -------------------------------------------------------- |
9
- | Define queries and inputs | `app.ts`, `src/operations.ts`, optional shared contracts |
10
- | Compose app content and supported features | `src/App.tsx` |
11
- | Bind definitions and source evidence | `src/data-context.ts` |
12
- | Change identity and appearance | `app.ts` |
13
- | Inject styles and mount React | `src/main.tsx` |
14
- | Configure local serving | `src/server.ts` |
7
+ | Task | App-owned files |
8
+ | ------------------------------------------ | ----------------------------------------------- |
9
+ | Define queries, filters, and operations | `app.ts`, `src/filters.ts`, `src/operations.ts` |
10
+ | Compose app content and supported features | `src/App.tsx` |
11
+ | Bind definitions and source evidence | `src/data-context.ts` |
12
+ | Change identity and appearance | `app.ts` |
13
+ | Inject styles and mount React | `src/main.tsx` |
14
+ | Configure local serving | `src/server.ts` |
15
15
 
16
16
  See [README.md](README.md) for setup and checks.
17
17
 
@@ -1,11 +1,11 @@
1
1
  # Local metric data app starter
2
2
 
3
3
  Use `node_modules/@altertable/data-app/docs/app-authoring.md` for this SDK version.
4
- Otherwise, read the [version-matched authoring recipe](https://github.com/altertable-ai/data-app/blob/v0.76.0/docs/app-authoring.md). <!-- x-release-please-version -->
4
+ Otherwise, read the [version-matched authoring recipe](https://github.com/altertable-ai/data-app/blob/v0.78.0/docs/app-authoring.md). <!-- x-release-please-version -->
5
5
  See [AGENTS.md](AGENTS.md) for app-owned files.
6
6
 
7
7
  The example queries require the seeded sample data described in the
8
- [local preview guide](https://github.com/altertable-ai/data-app/blob/v0.76.0/docs/local-data-apps.md#preview-the-use-case-starters). <!-- x-release-please-version -->
8
+ [local preview guide](https://github.com/altertable-ai/data-app/blob/v0.78.0/docs/local-data-apps.md#preview-the-use-case-starters). <!-- x-release-please-version -->
9
9
  Use that mock for development, or replace the example queries with verified data
10
10
  in your lakehouse. The starter does not install a mock or create demo tables.
11
11
 
@@ -35,8 +35,7 @@ specified by the app brief. Change identity, appearance, and queries in `app.ts`
35
35
  bun run check
36
36
  ```
37
37
 
38
- `bun run check` includes the build, which writes browser assets to `dist/`. Hosting them requires an authorized
39
- `/api/data` backend; the local adapter does not authenticate hosted viewers.
38
+ `bun run check` includes the build, which writes browser assets to `dist/`. Hosted apps require an authorized query bridge; the local adapter does not authenticate hosted viewers.
40
39
 
41
40
  ## License
42
41
 
@@ -1,9 +1,12 @@
1
1
  import { defineDataApp } from '@altertable/data-app';
2
2
  export const dataApp = defineDataApp({
3
+ // Replace the demo title, description, and scope labels with the app's identity.
3
4
  title: 'Sample metric',
4
- description: 'Fixture counts by group; replace with the requested metric.',
5
+ description: 'Explore sample volume across groups and segments.',
5
6
  scope: { organization: 'demo', environment: 'sample' },
6
7
  appearance: { theme: 'system' },
8
+ // starter_sample_counts is the seeded semantic view for fictional sample counts.
9
+ // Replace these queries with verified sources before publishing.
7
10
  queries: {
8
11
  sampleCountsBySegment: {
9
12
  projections: {
@@ -14,7 +17,7 @@ export const dataApp = defineDataApp({
14
17
  SELECT segment_name, sample_count FROM SEMANTIC_VIEW(
15
18
  starter_sample_counts DIMENSIONS samples.segment_name METRICS samples.sample_count
16
19
  WHERE $groupName = '' OR samples.group_name = $groupName
17
- ) ORDER BY segment_name LIMIT $limit`,
20
+ ) ORDER BY sample_count DESC, segment_name LIMIT $limit`,
18
21
  params: {
19
22
  groupName: { type: 'string', defaultValue: '' },
20
23
  limit: { type: 'number', defaultValue: 10 },
@@ -8,18 +8,18 @@
8
8
  },
9
9
  "scripts": {
10
10
  "typecheck": "tsc --noEmit",
11
- "lint": "oxlint --type-aware src",
11
+ "lint": "oxlint --type-aware src app.ts",
12
12
  "format": "oxfmt src app.ts",
13
13
  "format:check": "oxfmt --check src app.ts",
14
14
  "dev": "bun --hot src/server.ts",
15
15
  "build": "bun run typecheck && bun build src/index.html --outdir=dist --production",
16
16
  "check": "bun run lint && bun run format:check && bun run build",
17
- "lint:fix": "oxlint --type-aware --fix src"
17
+ "lint:fix": "oxlint --type-aware --fix src app.ts"
18
18
  },
19
19
  "dependencies": {
20
- "@altertable/data-app": "0.76.0",
21
- "@altertable/data-app-bun": "0.76.0",
22
- "@altertable/data-app-react": "0.76.0",
20
+ "@altertable/data-app": "0.78.0",
21
+ "@altertable/data-app-bun": "0.78.0",
22
+ "@altertable/data-app-react": "0.78.0",
23
23
  "react": "19.3.1",
24
24
  "react-dom": "19.3.1"
25
25
  },
@@ -3,34 +3,20 @@ import {
3
3
  DataApp,
4
4
  DataSection,
5
5
  VisualizationWidget,
6
- Stack,
7
- choiceVariable,
6
+ Ranking,
7
+ Grid,
8
+ GridItem,
8
9
  } from '@altertable/data-app-react';
9
10
  import { BarChart } from '@altertable/data-app-react/ui';
10
- import { createDataClient } from '@altertable/data-app/client';
11
+ import { formatCount } from '@altertable/data-app/format';
11
12
 
12
13
  import { sampleDataContext } from '#app/data-context.ts';
13
- import type { operations } from '#app/operations.ts';
14
- const { defineDataView } =
15
- createDataHooks(createDataClient<typeof operations>());
16
- const sampleCountsView = defineDataView({
14
+ import { operations } from '#app/operations.ts';
15
+ const { defineView } = createDataHooks(operations.createDataClient());
16
+ const sampleCountsView = defineView({
17
17
  dataContext: sampleDataContext,
18
18
  operation: 'sampleCountsByGroup',
19
- variables: {
20
- groupName: choiceVariable({
21
- key: 'group',
22
- label: 'Group',
23
- defaultValue: 'all',
24
- options: [
25
- { id: 'all', label: 'All groups' },
26
- { id: 'Alpha', label: 'Alpha' },
27
- { id: 'Beta', label: 'Beta' },
28
- ],
29
- }),
30
- },
31
- describeInput: ({ groupName }) =>
32
- groupName === 'all' ? 'all groups' : groupName,
33
- isEmpty: result => result.groups.length === 0,
19
+ isEmpty: rows => rows.length === 0,
34
20
  emptyFallback: {
35
21
  title: 'No matching groups',
36
22
  description: 'No observations are available for this query.',
@@ -38,7 +24,7 @@ const sampleCountsView = defineDataView({
38
24
  });
39
25
  const sampleCounts = sampleCountsView.dataset({
40
26
  name: 'Sample counts',
41
- select: result => result.groups,
27
+ select: rows => rows,
42
28
  rowKey: row => row.groupName,
43
29
  columns: {
44
30
  groupName: { label: 'Group', value: row => row.groupName },
@@ -49,9 +35,18 @@ const sampleCounts = sampleCountsView.dataset({
49
35
  glossaryIds: ['sampleCount'],
50
36
  },
51
37
  });
52
- const segments = sampleCountsView.dataset({
38
+ const segmentCountsView = defineView({
39
+ dataContext: sampleDataContext,
40
+ operation: 'sampleCountsBySegment',
41
+ isEmpty: rows => rows.length === 0,
42
+ emptyFallback: {
43
+ title: 'No matching segments',
44
+ description: 'No observations are available for this query.',
45
+ },
46
+ });
47
+ const segmentCounts = segmentCountsView.dataset({
53
48
  name: 'Counts by segment',
54
- select: result => result.segments,
49
+ select: rows => rows,
55
50
  rowKey: row => row.segmentName,
56
51
  columns: {
57
52
  segmentName: { label: 'Segment', value: row => row.segmentName },
@@ -59,6 +54,7 @@ const segments = sampleCountsView.dataset({
59
54
  },
60
55
  evidence: { id: 'counts-by-segment', glossaryIds: ['sampleCount'] },
61
56
  });
57
+ // Selecting a group applies the shared group filter to both charts.
62
58
  const groupActions = sampleCounts.actions(
63
59
  action => ({
64
60
  drill: action.filter({
@@ -69,56 +65,58 @@ const groupActions = sampleCounts.actions(
69
65
  }),
70
66
  { primary: 'drill' }
71
67
  );
72
- // Keep only the breakdowns and interactions relevant to the requested metric.
73
- const sampleContent = sampleCountsView.content(result => (
74
- <Stack>
75
- <VisualizationWidget
76
- dataset={sampleCounts}
77
- source={result}
78
- title="Sample count"
79
- description="Select a group to filter both charts; choose All groups to reset."
80
- actions={groupActions}
81
- >
82
- {(rows, actions) => (
83
- <BarChart
84
- ariaLabel="Sample counts by group"
85
- unit="samples"
86
- items={rows.map(row => ({
87
- ...row,
88
- id: row.groupName,
89
- label: row.groupName,
90
- value: row.sampleCount,
91
- }))}
92
- itemActions={actions}
93
- />
94
- )}
95
- </VisualizationWidget>
96
- <VisualizationWidget
97
- dataset={segments}
98
- source={result}
99
- title="Samples by segment"
100
- description="Segment breakdown for the selected group scope."
101
- >
102
- {(rows, actions) => (
103
- <BarChart
104
- ariaLabel="Sample counts by segment"
105
- unit="samples"
106
- items={rows.map(row => ({
107
- ...row,
108
- id: row.segmentName,
109
- label: row.segmentName,
110
- value: row.sampleCount,
111
- }))}
112
- itemActions={actions}
113
- />
114
- )}
115
- </VisualizationWidget>
116
- </Stack>
68
+ const groupContent = sampleCountsView.content(result => (
69
+ <VisualizationWidget
70
+ dataset={sampleCounts}
71
+ source={result}
72
+ title="Samples by group"
73
+ actions={groupActions}
74
+ >
75
+ {(rows, actions) => (
76
+ <BarChart
77
+ ariaLabel="Sample counts by group"
78
+ unit="samples"
79
+ items={rows.map(row => ({
80
+ ...row,
81
+ id: row.groupName,
82
+ label: `${row.groupName} · ${formatCount(row.sampleCount, { compact: true })}`,
83
+ value: row.sampleCount,
84
+ }))}
85
+ horizontalGrid={false}
86
+ itemActions={actions}
87
+ />
88
+ )}
89
+ </VisualizationWidget>
90
+ ));
91
+ const segmentContent = segmentCountsView.content(result => (
92
+ <VisualizationWidget
93
+ dataset={segmentCounts}
94
+ source={result}
95
+ title="Samples by segment"
96
+ >
97
+ {rows => (
98
+ <Ranking
99
+ aria-label="Sample counts by segment"
100
+ items={rows.map(row => ({
101
+ id: row.segmentName,
102
+ label: row.segmentName,
103
+ value: row.sampleCount,
104
+ }))}
105
+ />
106
+ )}
107
+ </VisualizationWidget>
117
108
  ));
118
109
  export function App() {
119
110
  return (
120
111
  <DataApp view={sampleCountsView} showToolbar={false}>
121
- <DataSection content={sampleContent} />
112
+ <Grid columns={3}>
113
+ <GridItem span={2}>
114
+ <DataSection content={groupContent} />
115
+ </GridItem>
116
+ <GridItem>
117
+ <DataSection content={segmentContent} />
118
+ </GridItem>
119
+ </Grid>
122
120
  </DataApp>
123
121
  );
124
122
  }
@@ -1,15 +1,19 @@
1
1
  import { createDataContext } from '@altertable/data-app-react';
2
+
3
+ import { operations } from '#app/operations.ts';
4
+
2
5
  const queryNames = {
3
- sampleCountsByGroup: 'sampleCountsByGroup',
4
- sampleCountsBySegment: 'sampleCountsBySegment',
5
- } as const;
6
+ ...operations.sampleCountsByGroup.queryNames,
7
+ ...operations.sampleCountsBySegment.queryNames,
8
+ };
6
9
  export const sampleDataContext = createDataContext(queryNames)({
7
10
  description:
8
- 'The starter_sample_counts semantic view measures fictional samples by group and segment. Replace it with the requested semantic metric before publishing.',
11
+ 'The starter_sample_counts semantic view measures fictional sample volume by group and segment. The source has no time dimension.',
9
12
  glossary: {
10
13
  sampleCount: {
11
14
  term: 'Sample count',
12
- definition: 'A fixture value: Alpha is 2,200,000 and Beta is 600,000.',
15
+ definition:
16
+ 'Sum of recorded sample counts in the selected group scope. Additive across groups and segments.',
13
17
  queryNames: [
14
18
  queryNames.sampleCountsByGroup,
15
19
  queryNames.sampleCountsBySegment,
@@ -0,0 +1,18 @@
1
+ import { choiceFilter } from '@altertable/data-app/contract';
2
+
3
+ // Reuse this group filter in both operations so one selection updates both charts.
4
+ const groupName = choiceFilter({
5
+ key: 'group',
6
+ label: 'Group',
7
+ defaultValue: 'all',
8
+ options: [
9
+ { id: 'all', label: 'All groups' },
10
+ { id: 'Alpha', label: 'Alpha' },
11
+ { id: 'Beta', label: 'Beta' },
12
+ ],
13
+ });
14
+
15
+ export const operationFilters = {
16
+ sampleCountsByGroup: { groupName },
17
+ sampleCountsBySegment: { groupName },
18
+ };
@@ -1,8 +1,8 @@
1
- import { injectDataAppStyles, mountDataApp } from '@altertable/data-app-react';
1
+ import { mountDataApp } from '@altertable/data-app-react';
2
+ import { installLocalQueryLakehouse } from '@altertable/data-app/client';
2
3
 
3
4
  import { App } from '#app/App.tsx';
4
5
  import { dataApp } from '#config';
5
6
 
6
- injectDataAppStyles();
7
-
7
+ installLocalQueryLakehouse();
8
8
  mountDataApp({ app: dataApp, component: App });
@@ -1,50 +1,43 @@
1
1
  import { parseCount } from '@altertable/data-app/contract';
2
2
 
3
+ import { operationFilters } from '#app/filters.ts';
3
4
  import { dataApp } from '#config';
4
- export const operations = {
5
+
6
+ // The sample SQL uses '' for all groups; the filter control uses 'all'.
7
+ function queryGroup(groupName: string) {
8
+ return groupName === 'all' ? '' : groupName;
9
+ }
10
+ export const operations = dataApp.defineOperations({
5
11
  sampleCountsByGroup: dataApp.defineOperation({
6
- input: value => {
7
- if (
8
- !value ||
9
- typeof value !== 'object' ||
10
- !('groupName' in value) ||
11
- typeof value.groupName !== 'string' ||
12
- !['all', 'Alpha', 'Beta'].includes(value.groupName)
13
- )
14
- throw new Error('Expected a fixture group.');
15
- return { groupName: value.groupName };
12
+ filters: operationFilters.sampleCountsByGroup,
13
+ policy: { maxQueryRows: 10, maxDurationMs: 15000 },
14
+ async run({ query }, { groupName }) {
15
+ const queryResult = await query('sampleCountsByGroup', {
16
+ groupName: queryGroup(groupName),
17
+ });
18
+ return queryResult.rows.map(
19
+ (row): { groupName: 'Alpha' | 'Beta'; sampleCount: number } => {
20
+ if (row.group_name !== 'Alpha' && row.group_name !== 'Beta')
21
+ throw new Error('Unexpected fixture group.');
22
+ return {
23
+ groupName: row.group_name,
24
+ sampleCount: parseCount(row.sample_count),
25
+ };
26
+ }
27
+ );
16
28
  },
17
- checks: [
18
- { groupName: 'all' },
19
- { groupName: 'Alpha' },
20
- { groupName: 'Beta' },
21
- ],
29
+ }),
30
+ sampleCountsBySegment: dataApp.defineOperation({
31
+ filters: operationFilters.sampleCountsBySegment,
22
32
  policy: { maxQueryRows: 10, maxDurationMs: 15000 },
23
33
  async run({ query }, { groupName }) {
24
- const [groups, segments] = await Promise.all([
25
- query('sampleCountsByGroup', {
26
- groupName: groupName === 'all' ? '' : groupName,
27
- }),
28
- query('sampleCountsBySegment', {
29
- groupName: groupName === 'all' ? '' : groupName,
30
- }),
31
- ]);
32
- return {
33
- groups: groups.rows.map(
34
- (row): { groupName: 'Alpha' | 'Beta'; sampleCount: number } => {
35
- if (row.group_name !== 'Alpha' && row.group_name !== 'Beta')
36
- throw new Error('Unexpected fixture group.');
37
- return {
38
- groupName: row.group_name,
39
- sampleCount: parseCount(row.sample_count),
40
- };
41
- }
42
- ),
43
- segments: segments.rows.map(row => ({
44
- segmentName: row.segment_name,
45
- sampleCount: parseCount(row.sample_count),
46
- })),
47
- };
34
+ const queryResult = await query('sampleCountsBySegment', {
35
+ groupName: queryGroup(groupName),
36
+ });
37
+ return queryResult.rows.map(row => ({
38
+ segmentName: row.segment_name,
39
+ sampleCount: parseCount(row.sample_count),
40
+ }));
48
41
  },
49
42
  }),
50
- };
43
+ });
@@ -1,7 +1,9 @@
1
1
  import { serveLocalApp } from '@altertable/data-app-bun';
2
2
 
3
3
  import page from '#app/index.html';
4
- import { operations } from '#app/operations.ts';
5
4
  import { dataApp } from '#config';
6
5
 
7
- serveLocalApp({ page, operations, title: dataApp.title });
6
+ serveLocalApp({
7
+ page,
8
+ app: dataApp,
9
+ });