@tanstack/table-core 9.0.0-beta.46 → 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.
Files changed (212) hide show
  1. package/dist/core/row-models/coreRowModelsFeature.types.d.cts +1 -1
  2. package/dist/core/row-models/coreRowModelsFeature.types.d.ts +1 -1
  3. package/dist/core/row-models/coreRowModelsFeature.utils.cjs +1 -1
  4. package/dist/core/row-models/coreRowModelsFeature.utils.cjs.map +1 -1
  5. package/dist/core/row-models/coreRowModelsFeature.utils.d.cts +1 -1
  6. package/dist/core/row-models/coreRowModelsFeature.utils.d.ts +1 -1
  7. package/dist/core/row-models/coreRowModelsFeature.utils.js +1 -1
  8. package/dist/core/row-models/coreRowModelsFeature.utils.js.map +1 -1
  9. package/dist/features/aggregation/aggregationFeature.cjs +38 -0
  10. package/dist/features/aggregation/aggregationFeature.cjs.map +1 -0
  11. package/dist/features/aggregation/aggregationFeature.d.cts +10 -0
  12. package/dist/features/aggregation/aggregationFeature.d.ts +10 -0
  13. package/dist/features/aggregation/aggregationFeature.js +38 -0
  14. package/dist/features/aggregation/aggregationFeature.js.map +1 -0
  15. package/dist/features/aggregation/aggregationFeature.types.cjs +13 -0
  16. package/dist/features/aggregation/aggregationFeature.types.cjs.map +1 -0
  17. package/dist/features/aggregation/aggregationFeature.types.d.cts +172 -0
  18. package/dist/features/aggregation/aggregationFeature.types.d.ts +172 -0
  19. package/dist/features/aggregation/aggregationFeature.types.js +12 -0
  20. package/dist/features/aggregation/aggregationFeature.types.js.map +1 -0
  21. package/dist/features/aggregation/aggregationFeature.utils.cjs +198 -0
  22. package/dist/features/aggregation/aggregationFeature.utils.cjs.map +1 -0
  23. package/dist/features/aggregation/aggregationFeature.utils.d.cts +33 -0
  24. package/dist/features/aggregation/aggregationFeature.utils.d.ts +33 -0
  25. package/dist/features/aggregation/aggregationFeature.utils.js +192 -0
  26. package/dist/features/aggregation/aggregationFeature.utils.js.map +1 -0
  27. package/dist/features/aggregation/aggregationFns.cjs +240 -0
  28. package/dist/features/aggregation/aggregationFns.cjs.map +1 -0
  29. package/dist/features/aggregation/aggregationFns.d.cts +67 -0
  30. package/dist/features/aggregation/aggregationFns.d.ts +67 -0
  31. package/dist/features/aggregation/aggregationFns.js +229 -0
  32. package/dist/features/aggregation/aggregationFns.js.map +1 -0
  33. package/dist/features/column-filtering/columnFilteringFeature.types.d.cts +43 -3
  34. package/dist/features/column-filtering/columnFilteringFeature.types.d.ts +43 -3
  35. package/dist/features/column-filtering/columnFilteringFeature.utils.cjs +18 -9
  36. package/dist/features/column-filtering/columnFilteringFeature.utils.cjs.map +1 -1
  37. package/dist/features/column-filtering/columnFilteringFeature.utils.d.cts +6 -2
  38. package/dist/features/column-filtering/columnFilteringFeature.utils.d.ts +6 -2
  39. package/dist/features/column-filtering/columnFilteringFeature.utils.js +18 -9
  40. package/dist/features/column-filtering/columnFilteringFeature.utils.js.map +1 -1
  41. package/dist/features/column-filtering/createFilteredRowModel.cjs +7 -2
  42. package/dist/features/column-filtering/createFilteredRowModel.cjs.map +1 -1
  43. package/dist/features/column-filtering/createFilteredRowModel.d.cts +6 -2
  44. package/dist/features/column-filtering/createFilteredRowModel.d.ts +6 -2
  45. package/dist/features/column-filtering/createFilteredRowModel.js +7 -2
  46. package/dist/features/column-filtering/createFilteredRowModel.js.map +1 -1
  47. package/dist/features/column-filtering/filterFns.cjs +399 -0
  48. package/dist/features/column-filtering/filterFns.cjs.map +1 -0
  49. package/dist/features/column-filtering/filterFns.d.cts +210 -0
  50. package/dist/features/column-filtering/filterFns.d.ts +210 -0
  51. package/dist/features/column-filtering/filterFns.js +375 -0
  52. package/dist/features/column-filtering/filterFns.js.map +1 -0
  53. package/dist/features/column-grouping/columnGroupingFeature.cjs +3 -12
  54. package/dist/features/column-grouping/columnGroupingFeature.cjs.map +1 -1
  55. package/dist/features/column-grouping/columnGroupingFeature.d.cts +1 -1
  56. package/dist/features/column-grouping/columnGroupingFeature.d.ts +1 -1
  57. package/dist/features/column-grouping/columnGroupingFeature.js +4 -13
  58. package/dist/features/column-grouping/columnGroupingFeature.js.map +1 -1
  59. package/dist/features/column-grouping/columnGroupingFeature.types.d.cts +6 -49
  60. package/dist/features/column-grouping/columnGroupingFeature.types.d.ts +6 -49
  61. package/dist/features/column-grouping/columnGroupingFeature.utils.cjs +0 -50
  62. package/dist/features/column-grouping/columnGroupingFeature.utils.cjs.map +1 -1
  63. package/dist/features/column-grouping/columnGroupingFeature.utils.d.cts +2 -39
  64. package/dist/features/column-grouping/columnGroupingFeature.utils.d.ts +2 -39
  65. package/dist/features/column-grouping/columnGroupingFeature.utils.js +2 -49
  66. package/dist/features/column-grouping/columnGroupingFeature.utils.js.map +1 -1
  67. package/dist/features/column-grouping/createGroupedRowModel.cjs +23 -13
  68. package/dist/features/column-grouping/createGroupedRowModel.cjs.map +1 -1
  69. package/dist/features/column-grouping/createGroupedRowModel.d.cts +2 -3
  70. package/dist/features/column-grouping/createGroupedRowModel.d.ts +2 -3
  71. package/dist/features/column-grouping/createGroupedRowModel.js +25 -15
  72. package/dist/features/column-grouping/createGroupedRowModel.js.map +1 -1
  73. package/dist/features/global-filtering/globalFilteringFeature.utils.cjs +4 -2
  74. package/dist/features/global-filtering/globalFilteringFeature.utils.cjs.map +1 -1
  75. package/dist/features/global-filtering/globalFilteringFeature.utils.d.cts +2 -6
  76. package/dist/features/global-filtering/globalFilteringFeature.utils.d.ts +2 -6
  77. package/dist/features/global-filtering/globalFilteringFeature.utils.js +4 -2
  78. package/dist/features/global-filtering/globalFilteringFeature.utils.js.map +1 -1
  79. package/dist/features/row-sorting/createSortedRowModel.cjs +6 -2
  80. package/dist/features/row-sorting/createSortedRowModel.cjs.map +1 -1
  81. package/dist/features/row-sorting/createSortedRowModel.d.cts +6 -2
  82. package/dist/features/row-sorting/createSortedRowModel.d.ts +6 -2
  83. package/dist/features/row-sorting/createSortedRowModel.js +6 -2
  84. package/dist/features/row-sorting/createSortedRowModel.js.map +1 -1
  85. package/dist/features/row-sorting/rowSortingFeature.types.d.cts +32 -3
  86. package/dist/features/row-sorting/rowSortingFeature.types.d.ts +32 -3
  87. package/dist/features/row-sorting/rowSortingFeature.utils.cjs +20 -5
  88. package/dist/features/row-sorting/rowSortingFeature.utils.cjs.map +1 -1
  89. package/dist/features/row-sorting/rowSortingFeature.utils.js +20 -5
  90. package/dist/features/row-sorting/rowSortingFeature.utils.js.map +1 -1
  91. package/dist/{fns → features/row-sorting}/sortFns.cjs +69 -22
  92. package/dist/features/row-sorting/sortFns.cjs.map +1 -0
  93. package/dist/features/row-sorting/sortFns.d.cts +98 -0
  94. package/dist/features/row-sorting/sortFns.d.ts +98 -0
  95. package/dist/{fns → features/row-sorting}/sortFns.js +69 -23
  96. package/dist/features/row-sorting/sortFns.js.map +1 -0
  97. package/dist/features/stockFeatures.cjs +2 -0
  98. package/dist/features/stockFeatures.cjs.map +1 -1
  99. package/dist/features/stockFeatures.d.cts +2 -0
  100. package/dist/features/stockFeatures.d.ts +2 -0
  101. package/dist/features/stockFeatures.js +2 -0
  102. package/dist/features/stockFeatures.js.map +1 -1
  103. package/dist/helpers/tableFeatures.cjs +5 -4
  104. package/dist/helpers/tableFeatures.cjs.map +1 -1
  105. package/dist/helpers/tableFeatures.d.cts +5 -4
  106. package/dist/helpers/tableFeatures.d.ts +5 -4
  107. package/dist/helpers/tableFeatures.js +5 -4
  108. package/dist/helpers/tableFeatures.js.map +1 -1
  109. package/dist/index.cjs +18 -3
  110. package/dist/index.d.cts +10 -8
  111. package/dist/index.d.ts +10 -8
  112. package/dist/index.js +6 -4
  113. package/dist/static-functions.cjs +8 -3
  114. package/dist/static-functions.d.cts +3 -2
  115. package/dist/static-functions.d.ts +3 -2
  116. package/dist/static-functions.js +3 -2
  117. package/dist/types/Cell.d.cts +3 -1
  118. package/dist/types/Cell.d.ts +3 -1
  119. package/dist/types/Column.d.cts +4 -2
  120. package/dist/types/Column.d.ts +4 -2
  121. package/dist/types/ColumnDef.d.cts +5 -3
  122. package/dist/types/ColumnDef.d.ts +5 -3
  123. package/dist/types/Row.d.cts +3 -1
  124. package/dist/types/Row.d.ts +3 -1
  125. package/dist/types/RowModel.d.cts +1 -1
  126. package/dist/types/RowModel.d.ts +1 -1
  127. package/dist/types/RowModelFns.d.cts +3 -3
  128. package/dist/types/RowModelFns.d.ts +3 -3
  129. package/dist/types/Table.d.cts +1 -1
  130. package/dist/types/Table.d.ts +1 -1
  131. package/dist/types/TableFeatures.d.cts +19 -11
  132. package/dist/types/TableFeatures.d.ts +19 -11
  133. package/dist/types/TableOptions.d.cts +5 -3
  134. package/dist/types/TableOptions.d.ts +5 -3
  135. package/dist/types/TableState.d.cts +1 -1
  136. package/dist/types/TableState.d.ts +1 -1
  137. package/dist/types/type-utils.d.cts +8 -1
  138. package/dist/types/type-utils.d.ts +8 -1
  139. package/dist/worker/initTableWorker.cjs.map +1 -1
  140. package/dist/worker/initTableWorker.js.map +1 -1
  141. package/package.json +1 -1
  142. package/skills/aggregation/SKILL.md +131 -0
  143. package/skills/api-not-found/SKILL.md +1 -1
  144. package/skills/client-vs-server/SKILL.md +1 -1
  145. package/skills/column-faceting/SKILL.md +11 -5
  146. package/skills/column-filtering/SKILL.md +8 -3
  147. package/skills/column-ordering/SKILL.md +1 -1
  148. package/skills/column-pinning/SKILL.md +1 -1
  149. package/skills/column-resizing/SKILL.md +1 -1
  150. package/skills/column-sizing/SKILL.md +1 -1
  151. package/skills/column-visibility/SKILL.md +1 -1
  152. package/skills/core/SKILL.md +1 -1
  153. package/skills/custom-features/SKILL.md +1 -1
  154. package/skills/expanding/SKILL.md +1 -1
  155. package/skills/global-filtering/SKILL.md +3 -3
  156. package/skills/grouping/SKILL.md +12 -13
  157. package/skills/migrate-v8-to-v9/SKILL.md +21 -8
  158. package/skills/pagination/SKILL.md +1 -1
  159. package/skills/row-pinning/SKILL.md +1 -1
  160. package/skills/row-selection/SKILL.md +1 -1
  161. package/skills/sorting/SKILL.md +9 -3
  162. package/skills/table-features/SKILL.md +19 -13
  163. package/skills/typescript/SKILL.md +1 -1
  164. package/src/core/row-models/coreRowModelsFeature.utils.ts +1 -1
  165. package/src/features/aggregation/aggregationFeature.ts +59 -0
  166. package/src/features/aggregation/aggregationFeature.types.ts +312 -0
  167. package/src/features/aggregation/aggregationFeature.utils.ts +401 -0
  168. package/src/features/aggregation/aggregationFns.ts +336 -0
  169. package/src/features/column-filtering/columnFilteringFeature.types.ts +61 -1
  170. package/src/features/column-filtering/columnFilteringFeature.utils.ts +33 -19
  171. package/src/features/column-filtering/createFilteredRowModel.ts +13 -3
  172. package/src/features/column-filtering/filterFns.ts +533 -0
  173. package/src/features/column-grouping/columnGroupingFeature.ts +1 -20
  174. package/src/features/column-grouping/columnGroupingFeature.types.ts +4 -86
  175. package/src/features/column-grouping/columnGroupingFeature.utils.ts +1 -88
  176. package/src/features/column-grouping/createGroupedRowModel.ts +32 -38
  177. package/src/features/global-filtering/globalFilteringFeature.utils.ts +9 -1
  178. package/src/features/row-sorting/createSortedRowModel.ts +6 -2
  179. package/src/features/row-sorting/rowSortingFeature.types.ts +54 -2
  180. package/src/features/row-sorting/rowSortingFeature.utils.ts +46 -14
  181. package/src/{fns → features/row-sorting}/sortFns.ts +95 -81
  182. package/src/features/stockFeatures.ts +3 -0
  183. package/src/helpers/tableFeatures.ts +5 -4
  184. package/src/index.ts +7 -8
  185. package/src/static-functions.ts +1 -0
  186. package/src/types/Cell.ts +2 -0
  187. package/src/types/Column.ts +3 -1
  188. package/src/types/ColumnDef.ts +6 -3
  189. package/src/types/Row.ts +2 -0
  190. package/src/types/RowModelFns.ts +3 -3
  191. package/src/types/TableFeatures.ts +19 -11
  192. package/src/types/TableOptions.ts +5 -1
  193. package/src/types/type-utils.ts +8 -0
  194. package/src/worker/initTableWorker.ts +1 -1
  195. package/dist/fns/aggregationFns.cjs +0 -163
  196. package/dist/fns/aggregationFns.cjs.map +0 -1
  197. package/dist/fns/aggregationFns.d.cts +0 -85
  198. package/dist/fns/aggregationFns.d.ts +0 -85
  199. package/dist/fns/aggregationFns.js +0 -153
  200. package/dist/fns/aggregationFns.js.map +0 -1
  201. package/dist/fns/filterFns.cjs +0 -242
  202. package/dist/fns/filterFns.cjs.map +0 -1
  203. package/dist/fns/filterFns.d.cts +0 -178
  204. package/dist/fns/filterFns.d.ts +0 -178
  205. package/dist/fns/filterFns.js +0 -226
  206. package/dist/fns/filterFns.js.map +0 -1
  207. package/dist/fns/sortFns.cjs.map +0 -1
  208. package/dist/fns/sortFns.d.cts +0 -65
  209. package/dist/fns/sortFns.d.ts +0 -65
  210. package/dist/fns/sortFns.js.map +0 -1
  211. package/src/fns/aggregationFns.ts +0 -245
  212. package/src/fns/filterFns.ts +0 -455
@@ -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
+ }