@tanstack/table-core 9.0.0-beta.47 → 9.0.0-beta.48
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/dist/core/row-models/coreRowModelsFeature.types.d.cts +1 -1
- package/dist/core/row-models/coreRowModelsFeature.types.d.ts +1 -1
- package/dist/core/row-models/coreRowModelsFeature.utils.cjs +1 -1
- package/dist/core/row-models/coreRowModelsFeature.utils.cjs.map +1 -1
- package/dist/core/row-models/coreRowModelsFeature.utils.d.cts +1 -1
- package/dist/core/row-models/coreRowModelsFeature.utils.d.ts +1 -1
- package/dist/core/row-models/coreRowModelsFeature.utils.js +1 -1
- package/dist/core/row-models/coreRowModelsFeature.utils.js.map +1 -1
- package/dist/features/aggregation/aggregationFeature.cjs +38 -0
- package/dist/features/aggregation/aggregationFeature.cjs.map +1 -0
- package/dist/features/aggregation/aggregationFeature.d.cts +10 -0
- package/dist/features/aggregation/aggregationFeature.d.ts +10 -0
- package/dist/features/aggregation/aggregationFeature.js +38 -0
- package/dist/features/aggregation/aggregationFeature.js.map +1 -0
- package/dist/features/aggregation/aggregationFeature.types.cjs +13 -0
- package/dist/features/aggregation/aggregationFeature.types.cjs.map +1 -0
- package/dist/features/aggregation/aggregationFeature.types.d.cts +172 -0
- package/dist/features/aggregation/aggregationFeature.types.d.ts +172 -0
- package/dist/features/aggregation/aggregationFeature.types.js +12 -0
- package/dist/features/aggregation/aggregationFeature.types.js.map +1 -0
- package/dist/features/aggregation/aggregationFeature.utils.cjs +198 -0
- package/dist/features/aggregation/aggregationFeature.utils.cjs.map +1 -0
- package/dist/features/aggregation/aggregationFeature.utils.d.cts +33 -0
- package/dist/features/aggregation/aggregationFeature.utils.d.ts +33 -0
- package/dist/features/aggregation/aggregationFeature.utils.js +192 -0
- package/dist/features/aggregation/aggregationFeature.utils.js.map +1 -0
- package/dist/features/aggregation/aggregationFns.cjs +240 -0
- package/dist/features/aggregation/aggregationFns.cjs.map +1 -0
- package/dist/features/aggregation/aggregationFns.d.cts +67 -0
- package/dist/features/aggregation/aggregationFns.d.ts +67 -0
- package/dist/features/aggregation/aggregationFns.js +229 -0
- package/dist/features/aggregation/aggregationFns.js.map +1 -0
- package/dist/features/column-filtering/columnFilteringFeature.types.d.cts +1 -1
- package/dist/features/column-filtering/columnFilteringFeature.types.d.ts +1 -1
- package/dist/{fns → features/column-filtering}/filterFns.cjs +1 -1
- package/dist/features/column-filtering/filterFns.cjs.map +1 -0
- package/dist/{fns → features/column-filtering}/filterFns.d.cts +4 -4
- package/dist/{fns → features/column-filtering}/filterFns.d.ts +4 -4
- package/dist/{fns → features/column-filtering}/filterFns.js +1 -1
- package/dist/features/column-filtering/filterFns.js.map +1 -0
- package/dist/features/column-grouping/columnGroupingFeature.cjs +3 -12
- package/dist/features/column-grouping/columnGroupingFeature.cjs.map +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.d.cts +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.d.ts +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.js +4 -13
- package/dist/features/column-grouping/columnGroupingFeature.js.map +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.types.d.cts +6 -87
- package/dist/features/column-grouping/columnGroupingFeature.types.d.ts +6 -87
- package/dist/features/column-grouping/columnGroupingFeature.utils.cjs +0 -64
- package/dist/features/column-grouping/columnGroupingFeature.utils.cjs.map +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.utils.d.cts +2 -44
- package/dist/features/column-grouping/columnGroupingFeature.utils.d.ts +2 -44
- package/dist/features/column-grouping/columnGroupingFeature.utils.js +2 -63
- package/dist/features/column-grouping/columnGroupingFeature.utils.js.map +1 -1
- package/dist/features/column-grouping/createGroupedRowModel.cjs +23 -16
- package/dist/features/column-grouping/createGroupedRowModel.cjs.map +1 -1
- package/dist/features/column-grouping/createGroupedRowModel.d.cts +2 -6
- package/dist/features/column-grouping/createGroupedRowModel.d.ts +2 -6
- package/dist/features/column-grouping/createGroupedRowModel.js +25 -18
- package/dist/features/column-grouping/createGroupedRowModel.js.map +1 -1
- package/dist/features/global-filtering/globalFilteringFeature.utils.cjs +1 -1
- package/dist/features/global-filtering/globalFilteringFeature.utils.cjs.map +1 -1
- package/dist/features/global-filtering/globalFilteringFeature.utils.js +1 -1
- package/dist/features/global-filtering/globalFilteringFeature.utils.js.map +1 -1
- package/dist/features/row-sorting/rowSortingFeature.types.d.cts +1 -1
- package/dist/features/row-sorting/rowSortingFeature.types.d.ts +1 -1
- package/dist/features/row-sorting/rowSortingFeature.utils.cjs +1 -1
- package/dist/features/row-sorting/rowSortingFeature.utils.cjs.map +1 -1
- package/dist/features/row-sorting/rowSortingFeature.utils.js +1 -1
- package/dist/features/row-sorting/rowSortingFeature.utils.js.map +1 -1
- package/dist/{fns → features/row-sorting}/sortFns.cjs +1 -1
- package/dist/{fns/sortFns.js.map → features/row-sorting/sortFns.cjs.map} +1 -1
- package/dist/{fns → features/row-sorting}/sortFns.d.cts +4 -4
- package/dist/{fns → features/row-sorting}/sortFns.d.ts +4 -4
- package/dist/{fns → features/row-sorting}/sortFns.js +1 -1
- package/dist/features/row-sorting/sortFns.js.map +1 -0
- package/dist/features/stockFeatures.cjs +2 -0
- package/dist/features/stockFeatures.cjs.map +1 -1
- package/dist/features/stockFeatures.d.cts +2 -0
- package/dist/features/stockFeatures.d.ts +2 -0
- package/dist/features/stockFeatures.js +2 -0
- package/dist/features/stockFeatures.js.map +1 -1
- package/dist/index.cjs +7 -4
- package/dist/index.d.cts +7 -5
- package/dist/index.d.ts +7 -5
- package/dist/index.js +6 -4
- package/dist/static-functions.cjs +8 -3
- package/dist/static-functions.d.cts +3 -2
- package/dist/static-functions.d.ts +3 -2
- package/dist/static-functions.js +3 -2
- package/dist/types/Cell.d.cts +3 -1
- package/dist/types/Cell.d.ts +3 -1
- package/dist/types/Column.d.cts +4 -2
- package/dist/types/Column.d.ts +4 -2
- package/dist/types/ColumnDef.d.cts +5 -3
- package/dist/types/ColumnDef.d.ts +5 -3
- package/dist/types/Row.d.cts +3 -1
- package/dist/types/Row.d.ts +3 -1
- package/dist/types/RowModel.d.cts +1 -1
- package/dist/types/RowModel.d.ts +1 -1
- package/dist/types/RowModelFns.d.cts +3 -3
- package/dist/types/RowModelFns.d.ts +3 -3
- package/dist/types/Table.d.cts +1 -1
- package/dist/types/Table.d.ts +1 -1
- package/dist/types/TableFeatures.d.cts +4 -4
- package/dist/types/TableFeatures.d.ts +4 -4
- package/dist/types/TableOptions.d.cts +5 -3
- package/dist/types/TableOptions.d.ts +5 -3
- package/dist/types/TableState.d.cts +1 -1
- package/dist/types/TableState.d.ts +1 -1
- package/dist/worker/initTableWorker.cjs.map +1 -1
- package/dist/worker/initTableWorker.js.map +1 -1
- package/package.json +1 -1
- package/skills/aggregation/SKILL.md +131 -0
- package/skills/api-not-found/SKILL.md +1 -1
- package/skills/client-vs-server/SKILL.md +1 -1
- package/skills/column-faceting/SKILL.md +1 -1
- package/skills/column-filtering/SKILL.md +1 -1
- package/skills/column-ordering/SKILL.md +1 -1
- package/skills/column-pinning/SKILL.md +1 -1
- package/skills/column-resizing/SKILL.md +1 -1
- package/skills/column-sizing/SKILL.md +1 -1
- package/skills/column-visibility/SKILL.md +1 -1
- package/skills/core/SKILL.md +1 -1
- package/skills/custom-features/SKILL.md +1 -1
- package/skills/expanding/SKILL.md +1 -1
- package/skills/global-filtering/SKILL.md +1 -1
- package/skills/grouping/SKILL.md +12 -18
- package/skills/migrate-v8-to-v9/SKILL.md +15 -2
- package/skills/pagination/SKILL.md +1 -1
- package/skills/row-pinning/SKILL.md +1 -1
- package/skills/row-selection/SKILL.md +1 -1
- package/skills/sorting/SKILL.md +1 -1
- package/skills/table-features/SKILL.md +5 -2
- package/skills/typescript/SKILL.md +1 -1
- package/src/core/row-models/coreRowModelsFeature.utils.ts +1 -1
- package/src/features/aggregation/aggregationFeature.ts +59 -0
- package/src/features/aggregation/aggregationFeature.types.ts +312 -0
- package/src/features/aggregation/aggregationFeature.utils.ts +401 -0
- package/src/features/aggregation/aggregationFns.ts +336 -0
- package/src/features/column-filtering/columnFilteringFeature.types.ts +1 -1
- package/src/{fns → features/column-filtering}/filterFns.ts +4 -4
- package/src/features/column-grouping/columnGroupingFeature.ts +1 -20
- package/src/features/column-grouping/columnGroupingFeature.types.ts +4 -141
- package/src/features/column-grouping/columnGroupingFeature.utils.ts +1 -122
- package/src/features/column-grouping/createGroupedRowModel.ts +32 -41
- package/src/features/global-filtering/globalFilteringFeature.utils.ts +1 -1
- package/src/features/row-sorting/rowSortingFeature.types.ts +1 -1
- package/src/features/row-sorting/rowSortingFeature.utils.ts +1 -1
- package/src/{fns → features/row-sorting}/sortFns.ts +4 -7
- package/src/features/stockFeatures.ts +3 -0
- package/src/index.ts +7 -8
- package/src/static-functions.ts +1 -0
- package/src/types/Cell.ts +2 -0
- package/src/types/Column.ts +3 -1
- package/src/types/ColumnDef.ts +6 -3
- package/src/types/Row.ts +2 -0
- package/src/types/RowModelFns.ts +3 -3
- package/src/types/TableFeatures.ts +4 -4
- package/src/types/TableOptions.ts +5 -1
- package/src/worker/initTableWorker.ts +1 -1
- package/dist/fns/aggregationFns.cjs +0 -234
- package/dist/fns/aggregationFns.cjs.map +0 -1
- package/dist/fns/aggregationFns.d.cts +0 -139
- package/dist/fns/aggregationFns.d.ts +0 -139
- package/dist/fns/aggregationFns.js +0 -221
- package/dist/fns/aggregationFns.js.map +0 -1
- package/dist/fns/filterFns.cjs.map +0 -1
- package/dist/fns/filterFns.js.map +0 -1
- package/dist/fns/sortFns.cjs.map +0 -1
- package/src/fns/aggregationFns.ts +0 -303
|
@@ -5,7 +5,7 @@ description: >
|
|
|
5
5
|
metadata:
|
|
6
6
|
type: lifecycle
|
|
7
7
|
library: '@tanstack/table-core'
|
|
8
|
-
library_version: '9.0.0-beta.
|
|
8
|
+
library_version: '9.0.0-beta.48'
|
|
9
9
|
requires: ['core', 'table-features', 'typescript']
|
|
10
10
|
sources:
|
|
11
11
|
- 'TanStack/table:docs/framework/react/guide/migrating.md'
|
|
@@ -70,7 +70,8 @@ V8 bundled all stock features. V9 exposes an API only when its feature is presen
|
|
|
70
70
|
| --------------------------- | ------------------------- |
|
|
71
71
|
| Column faceting | `columnFacetingFeature` |
|
|
72
72
|
| Column filtering | `columnFilteringFeature` |
|
|
73
|
-
|
|
|
73
|
+
| Aggregation | `aggregationFeature` |
|
|
74
|
+
| Grouping | `columnGroupingFeature` |
|
|
74
75
|
| Column ordering | `columnOrderingFeature` |
|
|
75
76
|
| Column pinning | `columnPinningFeature` |
|
|
76
77
|
| Interactive column resizing | `columnResizingFeature` |
|
|
@@ -90,6 +91,7 @@ Honor feature prerequisites in the same `tableFeatures` call:
|
|
|
90
91
|
- `columnResizingFeature` requires `columnSizingFeature`.
|
|
91
92
|
- `globalFilteringFeature` requires `columnFilteringFeature`.
|
|
92
93
|
- Every row-model or function-registry slot requires its associated feature.
|
|
94
|
+
- `aggregationFns` requires `aggregationFeature`; grouped aggregation uses both `aggregationFeature` and `columnGroupingFeature`.
|
|
93
95
|
- Put prerequisite feature properties before dependent slots so inference and diagnostics remain clear.
|
|
94
96
|
|
|
95
97
|
### 2. Move row models into feature slots and rename factories
|
|
@@ -120,6 +122,16 @@ Move registries from table options or factory arguments into these feature slots
|
|
|
120
122
|
|
|
121
123
|
Register only the built-ins the table references by string name, importing each individually (`filterFn_includesString`, `sortFn_alphanumeric`, `aggregationFn_sum`, and so on) alongside any custom functions. The full registry objects (`filterFns`, `sortFns`, `aggregationFns` exports) still work but bundle every built-in. A slot's keys become the valid string names in column definitions, and `'auto'` resolves only registered functions.
|
|
122
124
|
|
|
125
|
+
Aggregation is independent from grouping. Add `aggregationFeature` for
|
|
126
|
+
`aggregationFn`, `aggregatedCell`, `column.getAggregationValue(rows?)`, and
|
|
127
|
+
`cell.getIsAggregated`. A root total does not require grouping. Convert legacy
|
|
128
|
+
custom callables `(columnId, leafRows, childRows) => result` to
|
|
129
|
+
`constructAggregationFn({ aggregate: (context) => result, merge? })`
|
|
130
|
+
definitions. Replace `column.getAggregationFn()` with
|
|
131
|
+
`column.getAggregationFns()`; arrays in `aggregationFn` return keyed objects.
|
|
132
|
+
Replace the old `AggregationFn` and `CreatedAggregationFn` types with
|
|
133
|
+
`AggregationFnDef`.
|
|
134
|
+
|
|
123
135
|
### 3. Migrate state reads and whole-state observation
|
|
124
136
|
|
|
125
137
|
`table.getState()` and the top-level `onStateChange` option are removed. Individual `on[Slice]Change` callbacks remain.
|
|
@@ -280,6 +292,7 @@ Do not confuse new capabilities with required breakages. After the table works,
|
|
|
280
292
|
- [ ] Move all remaining `get*RowModel()` options or earlier-beta `rowModels` entries to `create*RowModel()` feature slots.
|
|
281
293
|
- [ ] Register each dependent feature before its row-model slot.
|
|
282
294
|
- [ ] Move `filterFns`, `sortingFns`/`sortFns`, and `aggregationFns` into feature slots, registering individually imported built-ins; pass no registries to factories.
|
|
295
|
+
- [ ] Register `aggregationFeature` independently and migrate custom aggregation callables to context-based `AggregationFnDef` definitions.
|
|
283
296
|
- [ ] Register `columnFilteringFeature` before global filtering and filter/facet dependencies.
|
|
284
297
|
- [ ] Register `columnSizingFeature` before `columnResizingFeature`.
|
|
285
298
|
- [ ] Replace `table.getState()` and top-level `onStateChange` according to the adapter state guide.
|
package/skills/sorting/SKILL.md
CHANGED
|
@@ -5,7 +5,7 @@ description: >
|
|
|
5
5
|
metadata:
|
|
6
6
|
type: sub-skill
|
|
7
7
|
library: '@tanstack/table-core'
|
|
8
|
-
library_version: '9.0.0-beta.
|
|
8
|
+
library_version: '9.0.0-beta.48'
|
|
9
9
|
requires: ['core']
|
|
10
10
|
sources:
|
|
11
11
|
- 'TanStack/table:docs/guide/row-models.md'
|
|
@@ -22,6 +22,7 @@ This skill builds on `core`. Read it first for the headless model and stable inp
|
|
|
22
22
|
|
|
23
23
|
```ts
|
|
24
24
|
import {
|
|
25
|
+
aggregationFeature,
|
|
25
26
|
aggregationFn_sum,
|
|
26
27
|
columnGroupingFeature,
|
|
27
28
|
createFilteredRowModel,
|
|
@@ -37,6 +38,7 @@ export const features = tableFeatures({
|
|
|
37
38
|
columnFilteringFeature,
|
|
38
39
|
filteredRowModel: createFilteredRowModel(),
|
|
39
40
|
filterFns: { includesString: filterFn_includesString },
|
|
41
|
+
aggregationFeature,
|
|
40
42
|
columnGroupingFeature,
|
|
41
43
|
aggregationFns: { sum: aggregationFn_sum },
|
|
42
44
|
rowSortingFeature,
|
|
@@ -66,6 +68,7 @@ const features = tableFeatures({
|
|
|
66
68
|
filterFns: { includesString: filterFn_includesString },
|
|
67
69
|
rowSortingFeature,
|
|
68
70
|
sortFns: { alphanumeric: sortFn_alphanumeric },
|
|
71
|
+
aggregationFeature,
|
|
69
72
|
columnGroupingFeature,
|
|
70
73
|
aggregationFns: { sum: aggregationFn_sum },
|
|
71
74
|
})
|
|
@@ -73,7 +76,7 @@ const features = tableFeatures({
|
|
|
73
76
|
|
|
74
77
|
`filterFns`, `sortFns`, and `aggregationFns` are feature slots, not table
|
|
75
78
|
options. They respectively require `columnFilteringFeature`,
|
|
76
|
-
`rowSortingFeature`, and `
|
|
79
|
+
`rowSortingFeature`, and `aggregationFeature`. Import individual built-ins
|
|
77
80
|
(`filterFn_*`, `sortFn_*`, `aggregationFn_*`) and register them under their
|
|
78
81
|
conventional keys; the full registry objects (`filterFns`, `sortFns`,
|
|
79
82
|
`aggregationFns` exports) still work but bundle every built-in. A registered
|
|
@@ -92,7 +92,7 @@ export function table_getPreGroupedRowModel<
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
/**
|
|
95
|
-
* Resolves the row model after grouping has produced grouped
|
|
95
|
+
* Resolves the row model after grouping has produced grouped rows.
|
|
96
96
|
*
|
|
97
97
|
* When `manualGrouping` is enabled, or no grouped row-model factory was
|
|
98
98
|
* registered, this returns the pre-grouped row model unchanged.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { assignPrototypeAPIs, makeObjectMap } from '../../utils'
|
|
2
|
+
import {
|
|
3
|
+
cell_getIsAggregated,
|
|
4
|
+
column_getAggregationFns,
|
|
5
|
+
column_getAggregationValue,
|
|
6
|
+
column_getAutoAggregationFn,
|
|
7
|
+
formatAggregatedCellValue,
|
|
8
|
+
} from './aggregationFeature.utils'
|
|
9
|
+
import type { TableFeature } from '../../types/TableFeatures'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Independent aggregation feature for grouped values and root/custom-row totals.
|
|
13
|
+
*/
|
|
14
|
+
export const aggregationFeature: TableFeature = {
|
|
15
|
+
getDefaultColumnDef: () => ({
|
|
16
|
+
aggregatedCell: ({ column, getValue }: any) =>
|
|
17
|
+
formatAggregatedCellValue(getValue(), column.columnDef.aggregationFn),
|
|
18
|
+
aggregationFn: 'auto',
|
|
19
|
+
}),
|
|
20
|
+
|
|
21
|
+
getDefaultTableOptions: () => ({
|
|
22
|
+
manualAggregation: false,
|
|
23
|
+
}),
|
|
24
|
+
|
|
25
|
+
assignCellPrototype: (prototype, table) => {
|
|
26
|
+
assignPrototypeAPIs('aggregationFeature', prototype, table, {
|
|
27
|
+
cell_getIsAggregated: {
|
|
28
|
+
fn: (cell) => cell_getIsAggregated(cell),
|
|
29
|
+
},
|
|
30
|
+
})
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
assignColumnPrototype: (prototype, table) => {
|
|
34
|
+
assignPrototypeAPIs('aggregationFeature', prototype, table, {
|
|
35
|
+
column_getAggregationFns: {
|
|
36
|
+
fn: (column) => column_getAggregationFns(column),
|
|
37
|
+
},
|
|
38
|
+
column_getAggregationValue: {
|
|
39
|
+
fn: (column, rows) => column_getAggregationValue(column, rows),
|
|
40
|
+
},
|
|
41
|
+
column_getAutoAggregationFn: {
|
|
42
|
+
fn: (column) => column_getAutoAggregationFn(column),
|
|
43
|
+
memoDeps: (column) => [
|
|
44
|
+
column.table.getCoreRowModel(),
|
|
45
|
+
column.table._rowModelFns.aggregationFns,
|
|
46
|
+
],
|
|
47
|
+
},
|
|
48
|
+
})
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
initColumnInstanceData: (column) => {
|
|
52
|
+
;(column as any)._aggregationValueCache = undefined
|
|
53
|
+
;(column as any)._resolvedAggregationFnsCache = undefined
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
initRowInstanceData: (row) => {
|
|
57
|
+
;(row as any)._aggregationValuesCache = makeObjectMap()
|
|
58
|
+
},
|
|
59
|
+
}
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import type { BuiltInAggregationFn } from './aggregationFns'
|
|
2
|
+
import type { Cell } from '../../types/Cell'
|
|
3
|
+
import type { Column } from '../../types/Column'
|
|
4
|
+
import type { ColumnDefTemplate } from '../../types/ColumnDef'
|
|
5
|
+
import type { IsAny, TableFeatures } from '../../types/TableFeatures'
|
|
6
|
+
import type { Row } from '../../types/Row'
|
|
7
|
+
import type { Table } from '../../types/Table'
|
|
8
|
+
import type { CellData, RowData } from '../../types/type-utils'
|
|
9
|
+
|
|
10
|
+
/** Declaration-merging fallback for named aggregation definitions. */
|
|
11
|
+
export interface AggregationFns {}
|
|
12
|
+
|
|
13
|
+
/** Values and table objects available while one aggregation is evaluated. */
|
|
14
|
+
export interface AggregationContext<
|
|
15
|
+
TFeatures extends TableFeatures,
|
|
16
|
+
TData extends RowData,
|
|
17
|
+
TValue = unknown,
|
|
18
|
+
> {
|
|
19
|
+
/** The column whose values are being aggregated. */
|
|
20
|
+
column: Column<TFeatures, TData, TValue>
|
|
21
|
+
/** Convenience alias for `column.id`. */
|
|
22
|
+
columnId: string
|
|
23
|
+
/** Reads this column's value from one of `rows`. */
|
|
24
|
+
getValue: (row: Row<TFeatures, TData>) => TValue
|
|
25
|
+
/**
|
|
26
|
+
* The synthetic grouped row receiving this result. This property is omitted
|
|
27
|
+
* for root or caller-supplied-row aggregation. Its `depth` identifies the
|
|
28
|
+
* grouping level when grouped aggregation needs that distinction.
|
|
29
|
+
*/
|
|
30
|
+
groupingRow?: Row<TFeatures, TData>
|
|
31
|
+
/**
|
|
32
|
+
* Terminal leaf rows included in this aggregation. The executor normalizes
|
|
33
|
+
* hierarchical and duplicate row inputs before invoking the definition.
|
|
34
|
+
*/
|
|
35
|
+
rows: ReadonlyArray<Row<TFeatures, TData>>
|
|
36
|
+
/** The table that owns the column and rows. */
|
|
37
|
+
table: Table<TFeatures, TData>
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Additional values available when merging nested grouped results. */
|
|
41
|
+
export interface AggregationMergeContext<
|
|
42
|
+
TFeatures extends TableFeatures,
|
|
43
|
+
TData extends RowData,
|
|
44
|
+
TValue,
|
|
45
|
+
TResult,
|
|
46
|
+
> extends AggregationContext<TFeatures, TData, TValue> {
|
|
47
|
+
/** Results produced for each immediate child group, in child-row order. */
|
|
48
|
+
childResults: ReadonlyArray<TResult>
|
|
49
|
+
/** Immediate child group rows corresponding to `childResults`. */
|
|
50
|
+
childRows: ReadonlyArray<Row<TFeatures, TData>>
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** A context-based aggregation definition and optional grouped-result merge. */
|
|
54
|
+
export interface AggregationFnDef<
|
|
55
|
+
TFeatures extends TableFeatures = any,
|
|
56
|
+
TData extends RowData = any,
|
|
57
|
+
TValue = unknown,
|
|
58
|
+
TResult = unknown,
|
|
59
|
+
> {
|
|
60
|
+
/** Computes a result directly from normalized terminal rows. */
|
|
61
|
+
aggregate: (context: AggregationContext<TFeatures, TData, TValue>) => TResult
|
|
62
|
+
/**
|
|
63
|
+
* Combines already-computed immediate child-group results. When omitted,
|
|
64
|
+
* nested grouping falls back to `aggregate` over the group's terminal rows.
|
|
65
|
+
*/
|
|
66
|
+
merge?: (
|
|
67
|
+
context: AggregationMergeContext<TFeatures, TData, TValue, TResult>,
|
|
68
|
+
) => TResult
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Creates a typed context-based aggregation definition for a column or
|
|
73
|
+
* aggregation-function registry.
|
|
74
|
+
*/
|
|
75
|
+
export function constructAggregationFn<
|
|
76
|
+
TFeatures extends TableFeatures = any,
|
|
77
|
+
TData extends RowData = any,
|
|
78
|
+
TValue = unknown,
|
|
79
|
+
TResult = unknown,
|
|
80
|
+
>(
|
|
81
|
+
definition: AggregationFnDef<TFeatures, TData, TValue, TResult>,
|
|
82
|
+
): AggregationFnDef<TFeatures, TData, TValue, TResult> {
|
|
83
|
+
return definition
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Aggregation-definition registry carried by a table feature set. */
|
|
87
|
+
export interface RowModelFns_Aggregation<
|
|
88
|
+
in out TFeatures extends TableFeatures,
|
|
89
|
+
in out TData extends RowData,
|
|
90
|
+
> {
|
|
91
|
+
aggregationFns: Record<string, AggregationFnDef<TFeatures, TData, any, any>>
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Named context-based aggregation definitions registered on a feature set. */
|
|
95
|
+
export type CustomAggregationFns<
|
|
96
|
+
TFeatures extends TableFeatures,
|
|
97
|
+
TData extends RowData,
|
|
98
|
+
> = Record<string, AggregationFnDef<TFeatures, TData, any, any>>
|
|
99
|
+
|
|
100
|
+
/** String names available from a feature set's aggregation registry. */
|
|
101
|
+
export type ExtractAggregationFnKeys<TFeatures extends TableFeatures> =
|
|
102
|
+
IsAny<TFeatures> extends true
|
|
103
|
+
? keyof AggregationFns | BuiltInAggregationFn
|
|
104
|
+
: TFeatures extends { aggregationFns: infer TAggregationFns extends object }
|
|
105
|
+
? Extract<keyof TAggregationFns, string>
|
|
106
|
+
: keyof AggregationFns
|
|
107
|
+
|
|
108
|
+
/** A registered name, automatic inference, or inline aggregation definition. */
|
|
109
|
+
export type AggregationFnRef<
|
|
110
|
+
TFeatures extends TableFeatures,
|
|
111
|
+
TData extends RowData,
|
|
112
|
+
TValue = unknown,
|
|
113
|
+
TResult = unknown,
|
|
114
|
+
> =
|
|
115
|
+
| 'auto'
|
|
116
|
+
| ExtractAggregationFnKeys<TFeatures>
|
|
117
|
+
| AggregationFnDef<TFeatures, TData, TValue, TResult>
|
|
118
|
+
|
|
119
|
+
/** Gives an aggregation reference a stable key in a multiple result. */
|
|
120
|
+
export interface AggregationFnDescriptor<
|
|
121
|
+
TFeatures extends TableFeatures,
|
|
122
|
+
TData extends RowData,
|
|
123
|
+
TValue = unknown,
|
|
124
|
+
TResult = unknown,
|
|
125
|
+
> {
|
|
126
|
+
/** The named, automatic, or inline definition to execute. */
|
|
127
|
+
aggregationFn: AggregationFnRef<TFeatures, TData, TValue, TResult>
|
|
128
|
+
/** Stable key used in the object returned by a multiple aggregation. */
|
|
129
|
+
id: string
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** One named or explicitly keyed entry in a multiple aggregation option. */
|
|
133
|
+
export type AggregationFnListItem<
|
|
134
|
+
TFeatures extends TableFeatures,
|
|
135
|
+
TData extends RowData,
|
|
136
|
+
TValue = unknown,
|
|
137
|
+
> =
|
|
138
|
+
| 'auto'
|
|
139
|
+
| ExtractAggregationFnKeys<TFeatures>
|
|
140
|
+
| AggregationFnDescriptor<TFeatures, TData, TValue, any>
|
|
141
|
+
|
|
142
|
+
/** A scalar aggregation reference or a list that produces a keyed object. */
|
|
143
|
+
export type AggregationFnOption<
|
|
144
|
+
TFeatures extends TableFeatures,
|
|
145
|
+
TData extends RowData,
|
|
146
|
+
TValue = unknown,
|
|
147
|
+
> =
|
|
148
|
+
| AggregationFnRef<TFeatures, TData, TValue, any>
|
|
149
|
+
| ReadonlyArray<AggregationFnListItem<TFeatures, TData, TValue>>
|
|
150
|
+
|
|
151
|
+
/** Extracts the result type produced by an aggregation definition. */
|
|
152
|
+
export type AggregationResultOf<TDefinition> =
|
|
153
|
+
TDefinition extends AggregationFnDef<any, any, any, infer TResult>
|
|
154
|
+
? TResult
|
|
155
|
+
: unknown
|
|
156
|
+
|
|
157
|
+
type RegisteredAggregationDefinition<
|
|
158
|
+
TFeatures extends TableFeatures,
|
|
159
|
+
TKey extends PropertyKey,
|
|
160
|
+
> = TFeatures extends {
|
|
161
|
+
aggregationFns: infer TRegistry extends Record<PropertyKey, unknown>
|
|
162
|
+
}
|
|
163
|
+
? TKey extends keyof TRegistry
|
|
164
|
+
? TRegistry[TKey]
|
|
165
|
+
: never
|
|
166
|
+
: never
|
|
167
|
+
|
|
168
|
+
type AggregationResultOfRef<TRef, TFeatures extends TableFeatures> =
|
|
169
|
+
TRef extends AggregationFnDef<any, any, any, any>
|
|
170
|
+
? AggregationResultOf<TRef>
|
|
171
|
+
: TRef extends 'auto'
|
|
172
|
+
? RegisteredAggregationResult<TFeatures>
|
|
173
|
+
: TRef extends PropertyKey
|
|
174
|
+
? AggregationResultOf<RegisteredAggregationDefinition<TFeatures, TRef>>
|
|
175
|
+
: unknown
|
|
176
|
+
|
|
177
|
+
type AggregationEntryId<TEntry> = TEntry extends string
|
|
178
|
+
? TEntry
|
|
179
|
+
: TEntry extends { id: infer TId extends string }
|
|
180
|
+
? TId
|
|
181
|
+
: never
|
|
182
|
+
|
|
183
|
+
type AggregationEntryDefinition<TEntry> = TEntry extends {
|
|
184
|
+
aggregationFn: infer TDefinition
|
|
185
|
+
}
|
|
186
|
+
? TDefinition
|
|
187
|
+
: TEntry
|
|
188
|
+
|
|
189
|
+
/** Infers the scalar or keyed result produced by an aggregation option. */
|
|
190
|
+
export type AggregationResult<TOption, TFeatures extends TableFeatures = any> =
|
|
191
|
+
TOption extends ReadonlyArray<infer TEntry>
|
|
192
|
+
? {
|
|
193
|
+
[TKey in AggregationEntryId<TEntry>]: AggregationResultOfRef<
|
|
194
|
+
AggregationEntryDefinition<Extract<TEntry, TKey | { id: TKey }>>,
|
|
195
|
+
TFeatures
|
|
196
|
+
>
|
|
197
|
+
}
|
|
198
|
+
: AggregationResultOfRef<TOption, TFeatures>
|
|
199
|
+
|
|
200
|
+
type RegisteredAggregationResult<TFeatures extends TableFeatures> =
|
|
201
|
+
TFeatures extends {
|
|
202
|
+
aggregationFns: infer TRegistry extends Record<string, unknown>
|
|
203
|
+
}
|
|
204
|
+
? AggregationResultOf<TRegistry[keyof TRegistry]>
|
|
205
|
+
: unknown
|
|
206
|
+
|
|
207
|
+
/** Default public result union when a column's precise option is not known. */
|
|
208
|
+
export type ColumnAggregationValue<TFeatures extends TableFeatures> =
|
|
209
|
+
| RegisteredAggregationResult<TFeatures>
|
|
210
|
+
| Record<string, RegisteredAggregationResult<TFeatures> | undefined>
|
|
211
|
+
| undefined
|
|
212
|
+
|
|
213
|
+
/** A validated aggregation entry returned by `column.getAggregationFns()`. */
|
|
214
|
+
export interface ResolvedAggregationFn<
|
|
215
|
+
TFeatures extends TableFeatures,
|
|
216
|
+
TData extends RowData,
|
|
217
|
+
> {
|
|
218
|
+
/** Resolved definition, or `undefined` when configuration is invalid. */
|
|
219
|
+
aggregationFn: AggregationFnDef<TFeatures, TData, any, any> | undefined
|
|
220
|
+
/** Key used for a multiple result; scalar inline definitions have no id. */
|
|
221
|
+
id: string | undefined
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** Column-definition options installed by `aggregationFeature`. */
|
|
225
|
+
export interface ColumnDef_Aggregation<
|
|
226
|
+
in out TFeatures extends TableFeatures,
|
|
227
|
+
in out TData extends RowData,
|
|
228
|
+
TValue extends CellData = CellData,
|
|
229
|
+
> {
|
|
230
|
+
/** Renderer used for a grouped row's aggregated cell. */
|
|
231
|
+
aggregatedCell?: ColumnDefTemplate<
|
|
232
|
+
ReturnType<Cell<TFeatures, TData, TValue>['getContext']>
|
|
233
|
+
>
|
|
234
|
+
/**
|
|
235
|
+
* One aggregation reference for a scalar result, or an array for a keyed
|
|
236
|
+
* result object. Inline definitions in an array require an explicit `id`.
|
|
237
|
+
*/
|
|
238
|
+
aggregationFn?: AggregationFnOption<TFeatures, TData, TValue>
|
|
239
|
+
/**
|
|
240
|
+
* Optionally supplies a precomputed aggregation value for this column.
|
|
241
|
+
* Return `{ value }` to handle the request, including `{ value: undefined }`;
|
|
242
|
+
* return `undefined` to use the local aggregation fallback.
|
|
243
|
+
*/
|
|
244
|
+
getAggregationValue?: (
|
|
245
|
+
context: AggregationValueContext<TFeatures, TData, TValue>,
|
|
246
|
+
) => AggregationValueResult | undefined
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/** Column instance APIs installed by `aggregationFeature`. */
|
|
250
|
+
export interface Column_Aggregation<
|
|
251
|
+
in out TFeatures extends TableFeatures,
|
|
252
|
+
in out TData extends RowData,
|
|
253
|
+
> {
|
|
254
|
+
/** Resolves the configured scalar or multiple aggregation definitions. */
|
|
255
|
+
getAggregationFns: () => ReadonlyArray<
|
|
256
|
+
ResolvedAggregationFn<TFeatures, TData>
|
|
257
|
+
>
|
|
258
|
+
/**
|
|
259
|
+
* Aggregates this column over the default pre-grouped row model, or over a
|
|
260
|
+
* caller-provided array of rows. Explicit rows are normalized to unique
|
|
261
|
+
* terminal leaves and are intentionally not cached.
|
|
262
|
+
*/
|
|
263
|
+
getAggregationValue: <TResult = ColumnAggregationValue<TFeatures>>(
|
|
264
|
+
rows?: ReadonlyArray<Row<TFeatures, TData>>,
|
|
265
|
+
) => TResult
|
|
266
|
+
/** Infers `sum` for a numeric first row and `extent` for a Date first row. */
|
|
267
|
+
getAutoAggregationFn: () =>
|
|
268
|
+
| AggregationFnDef<TFeatures, TData, any, any>
|
|
269
|
+
| undefined
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/** Cell instance APIs installed by `aggregationFeature`. */
|
|
273
|
+
export interface Cell_Aggregation {
|
|
274
|
+
/** Whether this cell displays an aggregate on a synthetic grouped row. */
|
|
275
|
+
getIsAggregated: () => boolean
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/** Internal per-row cache used while grouped aggregates are evaluated. */
|
|
279
|
+
export interface Row_Aggregation {
|
|
280
|
+
/** Cached aggregate results keyed by column id. */
|
|
281
|
+
_aggregationValuesCache: Record<string, unknown>
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/** Values passed to a column-level aggregation-value provider. */
|
|
285
|
+
export interface AggregationValueContext<
|
|
286
|
+
TFeatures extends TableFeatures,
|
|
287
|
+
TData extends RowData,
|
|
288
|
+
TValue extends CellData = CellData,
|
|
289
|
+
> {
|
|
290
|
+
/** The column whose value was requested. */
|
|
291
|
+
column: Column<TFeatures, TData, TValue>
|
|
292
|
+
/** Caller-provided rows, or `undefined` for the default row model. */
|
|
293
|
+
rows?: ReadonlyArray<Row<TFeatures, TData>>
|
|
294
|
+
/** The table that owns the column. */
|
|
295
|
+
table: Table<TFeatures, TData>
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/** Marks an aggregation-value override as handled. */
|
|
299
|
+
export interface AggregationValueResult<TResult = unknown> {
|
|
300
|
+
/** The supplied value. `undefined` is still a handled result. */
|
|
301
|
+
value: TResult
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/** Table options installed by `aggregationFeature`. */
|
|
305
|
+
export interface TableOptions_Aggregation {
|
|
306
|
+
/**
|
|
307
|
+
* Disables local `column.getAggregationValue()` calculation when a column
|
|
308
|
+
* override does not handle the request. Group values supplied by manually
|
|
309
|
+
* grouped rows remain the responsibility of the data owner.
|
|
310
|
+
*/
|
|
311
|
+
manualAggregation?: boolean
|
|
312
|
+
}
|