@tanstack/table-core 9.0.0-beta.47 → 9.0.0-beta.49

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 (186) 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-faceting/createFacetedMinMaxValues.cjs +7 -4
  34. package/dist/features/column-faceting/createFacetedMinMaxValues.cjs.map +1 -1
  35. package/dist/features/column-faceting/createFacetedMinMaxValues.js +8 -5
  36. package/dist/features/column-faceting/createFacetedMinMaxValues.js.map +1 -1
  37. package/dist/features/column-faceting/createFacetedRowModel.cjs +1 -1
  38. package/dist/features/column-faceting/createFacetedRowModel.cjs.map +1 -1
  39. package/dist/features/column-faceting/createFacetedRowModel.js +1 -1
  40. package/dist/features/column-faceting/createFacetedRowModel.js.map +1 -1
  41. package/dist/features/column-faceting/createFacetedUniqueValues.cjs +8 -4
  42. package/dist/features/column-faceting/createFacetedUniqueValues.cjs.map +1 -1
  43. package/dist/features/column-faceting/createFacetedUniqueValues.js +9 -5
  44. package/dist/features/column-faceting/createFacetedUniqueValues.js.map +1 -1
  45. package/dist/features/column-filtering/columnFilteringFeature.types.d.cts +1 -1
  46. package/dist/features/column-filtering/columnFilteringFeature.types.d.ts +1 -1
  47. package/dist/{fns → features/column-filtering}/filterFns.cjs +1 -1
  48. package/dist/features/column-filtering/filterFns.cjs.map +1 -0
  49. package/dist/{fns → features/column-filtering}/filterFns.d.cts +4 -4
  50. package/dist/{fns → features/column-filtering}/filterFns.d.ts +4 -4
  51. package/dist/{fns → features/column-filtering}/filterFns.js +1 -1
  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 -87
  60. package/dist/features/column-grouping/columnGroupingFeature.types.d.ts +6 -87
  61. package/dist/features/column-grouping/columnGroupingFeature.utils.cjs +0 -64
  62. package/dist/features/column-grouping/columnGroupingFeature.utils.cjs.map +1 -1
  63. package/dist/features/column-grouping/columnGroupingFeature.utils.d.cts +2 -44
  64. package/dist/features/column-grouping/columnGroupingFeature.utils.d.ts +2 -44
  65. package/dist/features/column-grouping/columnGroupingFeature.utils.js +2 -63
  66. package/dist/features/column-grouping/columnGroupingFeature.utils.js.map +1 -1
  67. package/dist/features/column-grouping/createGroupedRowModel.cjs +23 -16
  68. package/dist/features/column-grouping/createGroupedRowModel.cjs.map +1 -1
  69. package/dist/features/column-grouping/createGroupedRowModel.d.cts +2 -6
  70. package/dist/features/column-grouping/createGroupedRowModel.d.ts +2 -6
  71. package/dist/features/column-grouping/createGroupedRowModel.js +25 -18
  72. package/dist/features/column-grouping/createGroupedRowModel.js.map +1 -1
  73. package/dist/features/global-filtering/globalFilteringFeature.utils.cjs +1 -1
  74. package/dist/features/global-filtering/globalFilteringFeature.utils.cjs.map +1 -1
  75. package/dist/features/global-filtering/globalFilteringFeature.utils.js +1 -1
  76. package/dist/features/global-filtering/globalFilteringFeature.utils.js.map +1 -1
  77. package/dist/features/row-sorting/rowSortingFeature.types.d.cts +1 -1
  78. package/dist/features/row-sorting/rowSortingFeature.types.d.ts +1 -1
  79. package/dist/features/row-sorting/rowSortingFeature.utils.cjs +1 -1
  80. package/dist/features/row-sorting/rowSortingFeature.utils.cjs.map +1 -1
  81. package/dist/features/row-sorting/rowSortingFeature.utils.js +1 -1
  82. package/dist/features/row-sorting/rowSortingFeature.utils.js.map +1 -1
  83. package/dist/{fns → features/row-sorting}/sortFns.cjs +1 -1
  84. package/dist/{fns/sortFns.js.map → features/row-sorting/sortFns.cjs.map} +1 -1
  85. package/dist/{fns → features/row-sorting}/sortFns.d.cts +4 -4
  86. package/dist/{fns → features/row-sorting}/sortFns.d.ts +4 -4
  87. package/dist/{fns → features/row-sorting}/sortFns.js +1 -1
  88. package/dist/features/row-sorting/sortFns.js.map +1 -0
  89. package/dist/features/stockFeatures.cjs +2 -0
  90. package/dist/features/stockFeatures.cjs.map +1 -1
  91. package/dist/features/stockFeatures.d.cts +2 -0
  92. package/dist/features/stockFeatures.d.ts +2 -0
  93. package/dist/features/stockFeatures.js +2 -0
  94. package/dist/features/stockFeatures.js.map +1 -1
  95. package/dist/index.cjs +7 -4
  96. package/dist/index.d.cts +7 -5
  97. package/dist/index.d.ts +7 -5
  98. package/dist/index.js +6 -4
  99. package/dist/static-functions.cjs +8 -3
  100. package/dist/static-functions.d.cts +3 -2
  101. package/dist/static-functions.d.ts +3 -2
  102. package/dist/static-functions.js +3 -2
  103. package/dist/types/Cell.d.cts +3 -1
  104. package/dist/types/Cell.d.ts +3 -1
  105. package/dist/types/Column.d.cts +4 -2
  106. package/dist/types/Column.d.ts +4 -2
  107. package/dist/types/ColumnDef.d.cts +5 -3
  108. package/dist/types/ColumnDef.d.ts +5 -3
  109. package/dist/types/Row.d.cts +3 -1
  110. package/dist/types/Row.d.ts +3 -1
  111. package/dist/types/RowModel.d.cts +1 -1
  112. package/dist/types/RowModel.d.ts +1 -1
  113. package/dist/types/RowModelFns.d.cts +3 -3
  114. package/dist/types/RowModelFns.d.ts +3 -3
  115. package/dist/types/Table.d.cts +1 -1
  116. package/dist/types/Table.d.ts +1 -1
  117. package/dist/types/TableFeatures.d.cts +4 -4
  118. package/dist/types/TableFeatures.d.ts +4 -4
  119. package/dist/types/TableOptions.d.cts +5 -3
  120. package/dist/types/TableOptions.d.ts +5 -3
  121. package/dist/types/TableState.d.cts +1 -1
  122. package/dist/types/TableState.d.ts +1 -1
  123. package/dist/worker/initTableWorker.cjs.map +1 -1
  124. package/dist/worker/initTableWorker.js.map +1 -1
  125. package/package.json +1 -1
  126. package/skills/aggregation/SKILL.md +131 -0
  127. package/skills/api-not-found/SKILL.md +1 -1
  128. package/skills/client-vs-server/SKILL.md +1 -1
  129. package/skills/column-faceting/SKILL.md +1 -1
  130. package/skills/column-filtering/SKILL.md +1 -1
  131. package/skills/column-ordering/SKILL.md +1 -1
  132. package/skills/column-pinning/SKILL.md +1 -1
  133. package/skills/column-resizing/SKILL.md +1 -1
  134. package/skills/column-sizing/SKILL.md +1 -1
  135. package/skills/column-visibility/SKILL.md +1 -1
  136. package/skills/core/SKILL.md +1 -1
  137. package/skills/custom-features/SKILL.md +1 -1
  138. package/skills/expanding/SKILL.md +1 -1
  139. package/skills/global-filtering/SKILL.md +1 -1
  140. package/skills/grouping/SKILL.md +12 -18
  141. package/skills/migrate-v8-to-v9/SKILL.md +15 -2
  142. package/skills/pagination/SKILL.md +1 -1
  143. package/skills/row-pinning/SKILL.md +1 -1
  144. package/skills/row-selection/SKILL.md +1 -1
  145. package/skills/sorting/SKILL.md +1 -1
  146. package/skills/table-features/SKILL.md +5 -2
  147. package/skills/typescript/SKILL.md +1 -1
  148. package/src/core/row-models/coreRowModelsFeature.utils.ts +1 -1
  149. package/src/features/aggregation/aggregationFeature.ts +59 -0
  150. package/src/features/aggregation/aggregationFeature.types.ts +312 -0
  151. package/src/features/aggregation/aggregationFeature.utils.ts +401 -0
  152. package/src/features/aggregation/aggregationFns.ts +336 -0
  153. package/src/features/column-faceting/createFacetedMinMaxValues.ts +33 -7
  154. package/src/features/column-faceting/createFacetedRowModel.ts +4 -1
  155. package/src/features/column-faceting/createFacetedUniqueValues.ts +45 -11
  156. package/src/features/column-filtering/columnFilteringFeature.types.ts +1 -1
  157. package/src/{fns → features/column-filtering}/filterFns.ts +4 -4
  158. package/src/features/column-grouping/columnGroupingFeature.ts +1 -20
  159. package/src/features/column-grouping/columnGroupingFeature.types.ts +4 -141
  160. package/src/features/column-grouping/columnGroupingFeature.utils.ts +1 -122
  161. package/src/features/column-grouping/createGroupedRowModel.ts +32 -41
  162. package/src/features/global-filtering/globalFilteringFeature.utils.ts +1 -1
  163. package/src/features/row-sorting/rowSortingFeature.types.ts +1 -1
  164. package/src/features/row-sorting/rowSortingFeature.utils.ts +1 -1
  165. package/src/{fns → features/row-sorting}/sortFns.ts +4 -7
  166. package/src/features/stockFeatures.ts +3 -0
  167. package/src/index.ts +7 -8
  168. package/src/static-functions.ts +1 -0
  169. package/src/types/Cell.ts +2 -0
  170. package/src/types/Column.ts +3 -1
  171. package/src/types/ColumnDef.ts +6 -3
  172. package/src/types/Row.ts +2 -0
  173. package/src/types/RowModelFns.ts +3 -3
  174. package/src/types/TableFeatures.ts +4 -4
  175. package/src/types/TableOptions.ts +5 -1
  176. package/src/worker/initTableWorker.ts +1 -1
  177. package/dist/fns/aggregationFns.cjs +0 -234
  178. package/dist/fns/aggregationFns.cjs.map +0 -1
  179. package/dist/fns/aggregationFns.d.cts +0 -139
  180. package/dist/fns/aggregationFns.d.ts +0 -139
  181. package/dist/fns/aggregationFns.js +0 -221
  182. package/dist/fns/aggregationFns.js.map +0 -1
  183. package/dist/fns/filterFns.cjs.map +0 -1
  184. package/dist/fns/filterFns.js.map +0 -1
  185. package/dist/fns/sortFns.cjs.map +0 -1
  186. package/src/fns/aggregationFns.ts +0 -303
@@ -10,7 +10,7 @@ import type { StockFeatures } from '../features/stockFeatures'
10
10
  import type { RowModel } from '../core/row-models/coreRowModelsFeature.types'
11
11
  import type { FilterFn } from '../features/column-filtering/columnFilteringFeature.types'
12
12
  import type { SortFn } from '../features/row-sorting/rowSortingFeature.types'
13
- import type { AggregationFn } from '../features/column-grouping/columnGroupingFeature.types'
13
+ import type { AggregationFnDef } from '../features/aggregation/aggregationFeature.types'
14
14
 
15
15
  /**
16
16
  * Detects whether a type is `any`.
@@ -90,9 +90,9 @@ export type NonFeatureKeys =
90
90
  */
91
91
  export interface FeatureSlotPrereqs {
92
92
  /**
93
- * Named aggregation functions are only meaningful when grouping is enabled.
93
+ * Named aggregation functions require the independent aggregation feature.
94
94
  */
95
- aggregationFns: 'columnGroupingFeature'
95
+ aggregationFns: 'aggregationFeature'
96
96
  /**
97
97
  * Column resizing builds on the column sizing state and APIs.
98
98
  */
@@ -190,7 +190,7 @@ export interface TableFeatures
190
190
  * Spreading the exported `aggregationFns` registry also works, but puts
191
191
  * every built-in aggregation function in your bundle.
192
192
  */
193
- aggregationFns?: Record<string, AggregationFn<any, any>>
193
+ aggregationFns?: Record<string, AggregationFnDef<any, any, any, any>>
194
194
  /**
195
195
  * Type-only slot for declaring the type of `columnDef.meta` for all columns
196
196
  * of this table.
@@ -4,6 +4,7 @@ import type { TableOptions_Columns } from '../core/columns/coreColumnsFeature.ty
4
4
  import type { TableOptions_Rows } from '../core/rows/coreRowsFeature.types'
5
5
  import type { TableOptions_Table } from '../core/table/coreTablesFeature.types'
6
6
  import type { TableOptions_ColumnFiltering } from '../features/column-filtering/columnFilteringFeature.types'
7
+ import type { TableOptions_Aggregation } from '../features/aggregation/aggregationFeature.types'
7
8
  import type { TableOptions_ColumnGrouping } from '../features/column-grouping/columnGroupingFeature.types'
8
9
  import type { TableOptions_ColumnOrdering } from '../features/column-ordering/columnOrderingFeature.types'
9
10
  import type { TableOptions_ColumnPinning } from '../features/column-pinning/columnPinningFeature.types'
@@ -58,6 +59,7 @@ export interface TableOptions_FeatureMap<
58
59
  in out TFeatures extends TableFeatures,
59
60
  in out TData extends RowData,
60
61
  > {
62
+ aggregationFeature: TableOptions_Aggregation
61
63
  columnFilteringFeature: TableOptions_ColumnFiltering<TFeatures, TData>
62
64
  columnGroupingFeature: TableOptions_ColumnGrouping
63
65
  columnOrderingFeature: TableOptions_ColumnOrdering
@@ -74,6 +76,7 @@ export interface TableOptions_FeatureMap<
74
76
  }
75
77
 
76
78
  type TableOptions_StockFeatureKeys =
79
+ | 'aggregationFeature'
77
80
  | 'columnFilteringFeature'
78
81
  | 'columnGroupingFeature'
79
82
  | 'columnOrderingFeature'
@@ -133,7 +136,8 @@ export type TableOptions_All<
133
136
  TData extends RowData,
134
137
  > = TableOptions_Core<TFeatures, TData> &
135
138
  Partial<
136
- TableOptions_ColumnFiltering<TFeatures, TData> &
139
+ TableOptions_Aggregation &
140
+ TableOptions_ColumnFiltering<TFeatures, TData> &
137
141
  TableOptions_ColumnGrouping &
138
142
  TableOptions_ColumnOrdering &
139
143
  TableOptions_ColumnPinning &
@@ -84,7 +84,7 @@ export function initTableWorker<
84
84
  // per group. Sync tables aggregate lazily (visible cells only), so
85
85
  // auto-aggregating every column would explode on high-cardinality
86
86
  // grouping for values nothing renders. Read the RAW column defs:
87
- // columnGroupingFeature injects default aggregatedCell/aggregationFn
87
+ // aggregationFeature injects default aggregatedCell/aggregationFn
88
88
  // into every resolved columnDef, so the resolved defs can't tell
89
89
  // explicit from default.
90
90
  aggregateColumnIds = flattenColumnDefs(config.columns as Array<any>)
@@ -1,234 +0,0 @@
1
-
2
- //#region src/fns/aggregationFns.ts
3
- /**
4
- * Builds an `AggregationFn` from a value-level reducer plus optional
5
- * `resolveDataValue` and `fromRows` settings.
6
- *
7
- * The `aggregate` reducer receives an array of the group rows' values, each
8
- * already passed through `resolveDataValue` when one is defined. Keeping
9
- * normalization in the resolver means a variant of an existing aggregation
10
- * function only has to swap the resolver, not re-implement the computation.
11
- *
12
- * The definition is attached to the returned function, so a variant can be
13
- * created by spreading a built-in aggregation function and overriding what
14
- * differs. For example, a `min` that works on date columns:
15
- *
16
- * ```ts
17
- * const earliest = constructAggregationFn({
18
- * ...aggregationFn_min,
19
- * resolveDataValue: (value) =>
20
- * value instanceof Date ? value.getTime() : value,
21
- * })
22
- * ```
23
- *
24
- * The built-in `count`, `first`, and `last` aggregation functions are plain
25
- * row-level functions instead: they read group position or size and never
26
- * look at every value, so materializing a values array would be wasted work.
27
- */
28
- function constructAggregationFn(def) {
29
- const aggregationFn = Object.assign((columnId, leafRows, childRows) => {
30
- const rows = aggregationFn.fromRows === "childRows" ? childRows : leafRows;
31
- const resolveDataValue = aggregationFn.resolveDataValue;
32
- const values = new Array(rows.length);
33
- for (let i = 0; i < rows.length; i++) {
34
- const value = rows[i].getValue(columnId);
35
- values[i] = resolveDataValue ? resolveDataValue(value) : value;
36
- }
37
- return aggregationFn.aggregate(values, rows, columnId);
38
- }, def);
39
- return aggregationFn;
40
- }
41
- /**
42
- * Sums numeric child-row values for a grouped column.
43
- *
44
- * Non-number values contribute `0`. Child rows are used so nested group totals
45
- * can reuse already aggregated values.
46
- */
47
- const aggregationFn_sum = constructAggregationFn({
48
- fromRows: "childRows",
49
- aggregate: (values) => {
50
- let sumValue = 0;
51
- for (let i = 0; i < values.length; i++) {
52
- const nextValue = values[i];
53
- sumValue += typeof nextValue === "number" ? nextValue : 0;
54
- }
55
- return sumValue;
56
- }
57
- });
58
- /**
59
- * Finds the minimum numeric child-row value for a grouped column.
60
- *
61
- * Nullish and non-number values are ignored. Returns `undefined` when no
62
- * numeric value is found.
63
- */
64
- const aggregationFn_min = constructAggregationFn({
65
- fromRows: "childRows",
66
- aggregate: (values) => {
67
- let minValue;
68
- for (let i = 0; i < values.length; i++) {
69
- const value = values[i];
70
- if (typeof value === "number" && (minValue === void 0 || value < minValue)) minValue = value;
71
- }
72
- return minValue;
73
- }
74
- });
75
- /**
76
- * Finds the maximum numeric child-row value for a grouped column.
77
- *
78
- * Nullish and non-number values are ignored. Returns `undefined` when no
79
- * numeric value is found.
80
- */
81
- const aggregationFn_max = constructAggregationFn({
82
- fromRows: "childRows",
83
- aggregate: (values) => {
84
- let maxValue;
85
- for (let i = 0; i < values.length; i++) {
86
- const value = values[i];
87
- if (typeof value === "number" && (maxValue === void 0 || value > maxValue)) maxValue = value;
88
- }
89
- return maxValue;
90
- }
91
- });
92
- /**
93
- * Finds the numeric extent for a grouped column.
94
- *
95
- * Returns `[min, max]`, where each entry is `undefined` when no numeric value is
96
- * present.
97
- */
98
- const aggregationFn_extent = constructAggregationFn({
99
- fromRows: "childRows",
100
- aggregate: (values) => {
101
- let minValue;
102
- let maxValue;
103
- for (let i = 0; i < values.length; i++) {
104
- const value = values[i];
105
- if (typeof value === "number") if (minValue === void 0) minValue = maxValue = value;
106
- else {
107
- if (minValue > value) minValue = value;
108
- if (maxValue < value) maxValue = value;
109
- }
110
- }
111
- return [minValue, maxValue];
112
- }
113
- });
114
- /**
115
- * Averages numeric leaf-row values for a grouped column.
116
- *
117
- * Number-like values are coerced with unary `+`; nullish and non-numeric values
118
- * are ignored.
119
- */
120
- const aggregationFn_mean = constructAggregationFn({ aggregate: (values) => {
121
- let count = 0;
122
- let sumValue = 0;
123
- for (let i = 0; i < values.length; i++) {
124
- const value = values[i];
125
- if (value != null && typeof value === "number") {
126
- ++count;
127
- sumValue += value;
128
- } else if (value != null) {
129
- const numValue = +value;
130
- if (!Number.isNaN(numValue)) {
131
- ++count;
132
- sumValue += numValue;
133
- }
134
- }
135
- }
136
- if (count) return sumValue / count;
137
- } });
138
- /**
139
- * Computes the median of numeric leaf-row values for a grouped column.
140
- *
141
- * All values must be numbers. If any value is non-numeric, or no leaf rows are
142
- * present, the result is `undefined`.
143
- */
144
- const aggregationFn_median = constructAggregationFn({ aggregate: (values) => {
145
- if (!values.length) return;
146
- for (let i = 0; i < values.length; i++) if (typeof values[i] !== "number") return;
147
- if (values.length === 1) return values[0];
148
- const mid = Math.floor(values.length / 2);
149
- values.sort((a, b) => a - b);
150
- return values.length % 2 !== 0 ? values[mid] : (values[mid - 1] + values[mid]) / 2;
151
- } });
152
- /**
153
- * Collects unique leaf-row values for a grouped column.
154
- *
155
- * Values are compared with JavaScript `Set` semantics.
156
- */
157
- const aggregationFn_unique = constructAggregationFn({ aggregate: (values) => Array.from(new Set(values).values()) });
158
- /**
159
- * Counts unique leaf-row values for a grouped column.
160
- *
161
- * Values are compared with JavaScript `Set` semantics.
162
- */
163
- const aggregationFn_uniqueCount = constructAggregationFn({ aggregate: (values) => new Set(values).size });
164
- /**
165
- * Counts the number of leaf rows in the group.
166
- *
167
- * The column id is ignored because the result is based only on group size.
168
- * This is a plain row-level function (not built with
169
- * `constructAggregationFn`) because it never reads row values.
170
- */
171
- function aggregationFn_count(_columnId, leafRows) {
172
- return leafRows.length;
173
- }
174
- /**
175
- * Returns the first leaf-row value for a grouped column.
176
- *
177
- * This is a plain row-level function (not built with
178
- * `constructAggregationFn`) because it only reads one positional value.
179
- */
180
- function aggregationFn_first(columnId, leafRows) {
181
- return leafRows[0]?.getValue(columnId);
182
- }
183
- /**
184
- * Returns the last leaf-row value for a grouped column.
185
- *
186
- * This is a plain row-level function (not built with
187
- * `constructAggregationFn`) because it only reads one positional value.
188
- */
189
- function aggregationFn_last(columnId, leafRows) {
190
- return leafRows[leafRows.length - 1]?.getValue(columnId);
191
- }
192
- /**
193
- * The built-in aggregation function registry.
194
- *
195
- * Registering this full object opts out of tree-shaking: every built-in
196
- * aggregation function ends up in your bundle. Prefer importing the
197
- * `aggregationFn_*` functions you actually use and registering just those in
198
- * the `aggregationFns` slot, or passing them directly to the `aggregationFn`
199
- * column option.
200
- *
201
- * @deprecated Import individual `aggregationFn_*` functions instead for a
202
- * smaller bundle. This export still works and is not going away in v9, but
203
- * built-in name resolution (including `aggregationFn: 'auto'`) only finds
204
- * functions you register yourself.
205
- */
206
- const aggregationFns = {
207
- sum: aggregationFn_sum,
208
- min: aggregationFn_min,
209
- max: aggregationFn_max,
210
- extent: aggregationFn_extent,
211
- mean: aggregationFn_mean,
212
- median: aggregationFn_median,
213
- unique: aggregationFn_unique,
214
- uniqueCount: aggregationFn_uniqueCount,
215
- count: aggregationFn_count,
216
- first: aggregationFn_first,
217
- last: aggregationFn_last
218
- };
219
-
220
- //#endregion
221
- exports.aggregationFn_count = aggregationFn_count;
222
- exports.aggregationFn_extent = aggregationFn_extent;
223
- exports.aggregationFn_first = aggregationFn_first;
224
- exports.aggregationFn_last = aggregationFn_last;
225
- exports.aggregationFn_max = aggregationFn_max;
226
- exports.aggregationFn_mean = aggregationFn_mean;
227
- exports.aggregationFn_median = aggregationFn_median;
228
- exports.aggregationFn_min = aggregationFn_min;
229
- exports.aggregationFn_sum = aggregationFn_sum;
230
- exports.aggregationFn_unique = aggregationFn_unique;
231
- exports.aggregationFn_uniqueCount = aggregationFn_uniqueCount;
232
- exports.aggregationFns = aggregationFns;
233
- exports.constructAggregationFn = constructAggregationFn;
234
- //# sourceMappingURL=aggregationFns.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"aggregationFns.cjs","names":[],"sources":["../../src/fns/aggregationFns.ts"],"sourcesContent":["import type {\n AggregationFnDef,\n CreatedAggregationFn,\n} from '../features/column-grouping/columnGroupingFeature.types'\nimport type { RowData } from '../types/type-utils'\nimport type { TableFeatures } from '../types/TableFeatures'\nimport type { Row } from '../types/Row'\n\n/**\n * Builds an `AggregationFn` from a value-level reducer plus optional\n * `resolveDataValue` and `fromRows` settings.\n *\n * The `aggregate` reducer receives an array of the group rows' values, each\n * already passed through `resolveDataValue` when one is defined. Keeping\n * normalization in the resolver means a variant of an existing aggregation\n * function only has to swap the resolver, not re-implement the computation.\n *\n * The definition is attached to the returned function, so a variant can be\n * created by spreading a built-in aggregation function and overriding what\n * differs. For example, a `min` that works on date columns:\n *\n * ```ts\n * const earliest = constructAggregationFn({\n * ...aggregationFn_min,\n * resolveDataValue: (value) =>\n * value instanceof Date ? value.getTime() : value,\n * })\n * ```\n *\n * The built-in `count`, `first`, and `last` aggregation functions are plain\n * row-level functions instead: they read group position or size and never\n * look at every value, so materializing a values array would be wasted work.\n */\nexport function constructAggregationFn<\n TFeatures extends TableFeatures = any,\n TData extends RowData = any,\n>(\n def: AggregationFnDef<TFeatures, TData>,\n): CreatedAggregationFn<TFeatures, TData> {\n const aggregationFn: CreatedAggregationFn<TFeatures, TData> = Object.assign(\n <TRowFeatures extends TableFeatures, TRowData extends RowData>(\n columnId: string,\n leafRows: Array<Row<TRowFeatures, TRowData>>,\n childRows: Array<Row<TRowFeatures, TRowData>>,\n ): any => {\n const rows = aggregationFn.fromRows === 'childRows' ? childRows : leafRows\n const resolveDataValue = aggregationFn.resolveDataValue\n const values: Array<any> = new Array(rows.length)\n for (let i = 0; i < rows.length; i++) {\n const value = rows[i]!.getValue(columnId)\n values[i] = resolveDataValue ? resolveDataValue(value) : value\n }\n // The def's reducer is typed against the factory's TFeatures/TData;\n // the caller's row generics are erased at this boundary.\n return aggregationFn.aggregate(values, rows as any, columnId)\n },\n def,\n )\n return aggregationFn\n}\n\n/**\n * Sums numeric child-row values for a grouped column.\n *\n * Non-number values contribute `0`. Child rows are used so nested group totals\n * can reuse already aggregated values.\n */\nexport const aggregationFn_sum = constructAggregationFn({\n fromRows: 'childRows',\n aggregate: (values) => {\n let sumValue = 0\n for (let i = 0; i < values.length; i++) {\n const nextValue = values[i]\n sumValue += typeof nextValue === 'number' ? nextValue : 0\n }\n return sumValue\n },\n})\n\n/**\n * Finds the minimum numeric child-row value for a grouped column.\n *\n * Nullish and non-number values are ignored. Returns `undefined` when no\n * numeric value is found.\n */\nexport const aggregationFn_min = constructAggregationFn({\n fromRows: 'childRows',\n aggregate: (values) => {\n let minValue: number | undefined\n\n for (let i = 0; i < values.length; i++) {\n const value = values[i]\n if (\n typeof value === 'number' &&\n (minValue === undefined || value < minValue)\n ) {\n minValue = value\n }\n }\n\n return minValue\n },\n})\n\n/**\n * Finds the maximum numeric child-row value for a grouped column.\n *\n * Nullish and non-number values are ignored. Returns `undefined` when no\n * numeric value is found.\n */\nexport const aggregationFn_max = constructAggregationFn({\n fromRows: 'childRows',\n aggregate: (values) => {\n let maxValue: number | undefined\n\n for (let i = 0; i < values.length; i++) {\n const value = values[i]\n if (\n typeof value === 'number' &&\n (maxValue === undefined || value > maxValue)\n ) {\n maxValue = value\n }\n }\n\n return maxValue\n },\n})\n\n/**\n * Finds the numeric extent for a grouped column.\n *\n * Returns `[min, max]`, where each entry is `undefined` when no numeric value is\n * present.\n */\nexport const aggregationFn_extent = constructAggregationFn({\n fromRows: 'childRows',\n aggregate: (values) => {\n let minValue: number | undefined\n let maxValue: number | undefined\n\n for (let i = 0; i < values.length; i++) {\n const value = values[i]\n if (typeof value === 'number') {\n if (minValue === undefined) {\n minValue = maxValue = value\n } else {\n if (minValue > value) minValue = value\n if (maxValue! < value) maxValue = value\n }\n }\n }\n\n return [minValue, maxValue]\n },\n})\n\n/**\n * Averages numeric leaf-row values for a grouped column.\n *\n * Number-like values are coerced with unary `+`; nullish and non-numeric values\n * are ignored.\n */\nexport const aggregationFn_mean = constructAggregationFn({\n aggregate: (values) => {\n let count = 0\n let sumValue = 0\n\n for (let i = 0; i < values.length; i++) {\n const value = values[i]\n if (value != null && typeof value === 'number') {\n ++count\n sumValue += value\n } else if (value != null) {\n const numValue = +value\n if (!Number.isNaN(numValue)) {\n ++count\n sumValue += numValue\n }\n }\n }\n\n if (count) return sumValue / count\n\n return\n },\n})\n\n/**\n * Computes the median of numeric leaf-row values for a grouped column.\n *\n * All values must be numbers. If any value is non-numeric, or no leaf rows are\n * present, the result is `undefined`.\n */\nexport const aggregationFn_median = constructAggregationFn({\n aggregate: (values: Array<number>) => {\n if (!values.length) {\n return\n }\n\n for (let i = 0; i < values.length; i++) {\n if (typeof values[i] !== 'number') return\n }\n\n if (values.length === 1) {\n return values[0]\n }\n\n const mid = Math.floor(values.length / 2)\n values.sort((a, b) => a - b)\n return values.length % 2 !== 0\n ? values[mid]\n : (values[mid - 1]! + values[mid]!) / 2\n },\n})\n\n/**\n * Collects unique leaf-row values for a grouped column.\n *\n * Values are compared with JavaScript `Set` semantics.\n */\nexport const aggregationFn_unique = constructAggregationFn({\n aggregate: (values) => Array.from(new Set(values).values()),\n})\n\n/**\n * Counts unique leaf-row values for a grouped column.\n *\n * Values are compared with JavaScript `Set` semantics.\n */\nexport const aggregationFn_uniqueCount = constructAggregationFn({\n aggregate: (values) => new Set(values).size,\n})\n\n/**\n * Counts the number of leaf rows in the group.\n *\n * The column id is ignored because the result is based only on group size.\n * This is a plain row-level function (not built with\n * `constructAggregationFn`) because it never reads row values.\n */\nexport function aggregationFn_count<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(_columnId: string, leafRows: Array<Row<TFeatures, TData>>) {\n return leafRows.length\n}\n\n/**\n * Returns the first leaf-row value for a grouped column.\n *\n * This is a plain row-level function (not built with\n * `constructAggregationFn`) because it only reads one positional value.\n */\nexport function aggregationFn_first<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(columnId: string, leafRows: Array<Row<TFeatures, TData>>) {\n return leafRows[0]?.getValue(columnId)\n}\n\n/**\n * Returns the last leaf-row value for a grouped column.\n *\n * This is a plain row-level function (not built with\n * `constructAggregationFn`) because it only reads one positional value.\n */\nexport function aggregationFn_last<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(columnId: string, leafRows: Array<Row<TFeatures, TData>>) {\n return leafRows[leafRows.length - 1]?.getValue(columnId)\n}\n\n/**\n * The built-in aggregation function registry.\n *\n * Registering this full object opts out of tree-shaking: every built-in\n * aggregation function ends up in your bundle. Prefer importing the\n * `aggregationFn_*` functions you actually use and registering just those in\n * the `aggregationFns` slot, or passing them directly to the `aggregationFn`\n * column option.\n *\n * @deprecated Import individual `aggregationFn_*` functions instead for a\n * smaller bundle. This export still works and is not going away in v9, but\n * built-in name resolution (including `aggregationFn: 'auto'`) only finds\n * functions you register yourself.\n */\nexport const aggregationFns = {\n sum: aggregationFn_sum,\n min: aggregationFn_min,\n max: aggregationFn_max,\n extent: aggregationFn_extent,\n mean: aggregationFn_mean,\n median: aggregationFn_median,\n unique: aggregationFn_unique,\n uniqueCount: aggregationFn_uniqueCount,\n count: aggregationFn_count,\n first: aggregationFn_first,\n last: aggregationFn_last,\n}\n\nexport type BuiltInAggregationFn = keyof typeof aggregationFns\n"],"mappings":"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"}
@@ -1,139 +0,0 @@
1
- import { RowData } from "../types/type-utils.cjs";
2
- import { AggregationFnDef, CreatedAggregationFn } from "../features/column-grouping/columnGroupingFeature.types.cjs";
3
- import { Row } from "../types/Row.cjs";
4
- import { TableFeatures } from "../types/TableFeatures.cjs";
5
-
6
- //#region src/fns/aggregationFns.d.ts
7
- /**
8
- * Builds an `AggregationFn` from a value-level reducer plus optional
9
- * `resolveDataValue` and `fromRows` settings.
10
- *
11
- * The `aggregate` reducer receives an array of the group rows' values, each
12
- * already passed through `resolveDataValue` when one is defined. Keeping
13
- * normalization in the resolver means a variant of an existing aggregation
14
- * function only has to swap the resolver, not re-implement the computation.
15
- *
16
- * The definition is attached to the returned function, so a variant can be
17
- * created by spreading a built-in aggregation function and overriding what
18
- * differs. For example, a `min` that works on date columns:
19
- *
20
- * ```ts
21
- * const earliest = constructAggregationFn({
22
- * ...aggregationFn_min,
23
- * resolveDataValue: (value) =>
24
- * value instanceof Date ? value.getTime() : value,
25
- * })
26
- * ```
27
- *
28
- * The built-in `count`, `first`, and `last` aggregation functions are plain
29
- * row-level functions instead: they read group position or size and never
30
- * look at every value, so materializing a values array would be wasted work.
31
- */
32
- declare function constructAggregationFn<TFeatures extends TableFeatures = any, TData extends RowData = any>(def: AggregationFnDef<TFeatures, TData>): CreatedAggregationFn<TFeatures, TData>;
33
- /**
34
- * Sums numeric child-row values for a grouped column.
35
- *
36
- * Non-number values contribute `0`. Child rows are used so nested group totals
37
- * can reuse already aggregated values.
38
- */
39
- declare const aggregationFn_sum: CreatedAggregationFn<any, any>;
40
- /**
41
- * Finds the minimum numeric child-row value for a grouped column.
42
- *
43
- * Nullish and non-number values are ignored. Returns `undefined` when no
44
- * numeric value is found.
45
- */
46
- declare const aggregationFn_min: CreatedAggregationFn<any, any>;
47
- /**
48
- * Finds the maximum numeric child-row value for a grouped column.
49
- *
50
- * Nullish and non-number values are ignored. Returns `undefined` when no
51
- * numeric value is found.
52
- */
53
- declare const aggregationFn_max: CreatedAggregationFn<any, any>;
54
- /**
55
- * Finds the numeric extent for a grouped column.
56
- *
57
- * Returns `[min, max]`, where each entry is `undefined` when no numeric value is
58
- * present.
59
- */
60
- declare const aggregationFn_extent: CreatedAggregationFn<any, any>;
61
- /**
62
- * Averages numeric leaf-row values for a grouped column.
63
- *
64
- * Number-like values are coerced with unary `+`; nullish and non-numeric values
65
- * are ignored.
66
- */
67
- declare const aggregationFn_mean: CreatedAggregationFn<any, any>;
68
- /**
69
- * Computes the median of numeric leaf-row values for a grouped column.
70
- *
71
- * All values must be numbers. If any value is non-numeric, or no leaf rows are
72
- * present, the result is `undefined`.
73
- */
74
- declare const aggregationFn_median: CreatedAggregationFn<any, any>;
75
- /**
76
- * Collects unique leaf-row values for a grouped column.
77
- *
78
- * Values are compared with JavaScript `Set` semantics.
79
- */
80
- declare const aggregationFn_unique: CreatedAggregationFn<any, any>;
81
- /**
82
- * Counts unique leaf-row values for a grouped column.
83
- *
84
- * Values are compared with JavaScript `Set` semantics.
85
- */
86
- declare const aggregationFn_uniqueCount: CreatedAggregationFn<any, any>;
87
- /**
88
- * Counts the number of leaf rows in the group.
89
- *
90
- * The column id is ignored because the result is based only on group size.
91
- * This is a plain row-level function (not built with
92
- * `constructAggregationFn`) because it never reads row values.
93
- */
94
- declare function aggregationFn_count<TFeatures extends TableFeatures, TData extends RowData>(_columnId: string, leafRows: Array<Row<TFeatures, TData>>): number;
95
- /**
96
- * Returns the first leaf-row value for a grouped column.
97
- *
98
- * This is a plain row-level function (not built with
99
- * `constructAggregationFn`) because it only reads one positional value.
100
- */
101
- declare function aggregationFn_first<TFeatures extends TableFeatures, TData extends RowData>(columnId: string, leafRows: Array<Row<TFeatures, TData>>): unknown;
102
- /**
103
- * Returns the last leaf-row value for a grouped column.
104
- *
105
- * This is a plain row-level function (not built with
106
- * `constructAggregationFn`) because it only reads one positional value.
107
- */
108
- declare function aggregationFn_last<TFeatures extends TableFeatures, TData extends RowData>(columnId: string, leafRows: Array<Row<TFeatures, TData>>): unknown;
109
- /**
110
- * The built-in aggregation function registry.
111
- *
112
- * Registering this full object opts out of tree-shaking: every built-in
113
- * aggregation function ends up in your bundle. Prefer importing the
114
- * `aggregationFn_*` functions you actually use and registering just those in
115
- * the `aggregationFns` slot, or passing them directly to the `aggregationFn`
116
- * column option.
117
- *
118
- * @deprecated Import individual `aggregationFn_*` functions instead for a
119
- * smaller bundle. This export still works and is not going away in v9, but
120
- * built-in name resolution (including `aggregationFn: 'auto'`) only finds
121
- * functions you register yourself.
122
- */
123
- declare const aggregationFns: {
124
- sum: CreatedAggregationFn<any, any>;
125
- min: CreatedAggregationFn<any, any>;
126
- max: CreatedAggregationFn<any, any>;
127
- extent: CreatedAggregationFn<any, any>;
128
- mean: CreatedAggregationFn<any, any>;
129
- median: CreatedAggregationFn<any, any>;
130
- unique: CreatedAggregationFn<any, any>;
131
- uniqueCount: CreatedAggregationFn<any, any>;
132
- count: typeof aggregationFn_count;
133
- first: typeof aggregationFn_first;
134
- last: typeof aggregationFn_last;
135
- };
136
- type BuiltInAggregationFn = keyof typeof aggregationFns;
137
- //#endregion
138
- export { BuiltInAggregationFn, aggregationFn_count, aggregationFn_extent, aggregationFn_first, aggregationFn_last, aggregationFn_max, aggregationFn_mean, aggregationFn_median, aggregationFn_min, aggregationFn_sum, aggregationFn_unique, aggregationFn_uniqueCount, aggregationFns, constructAggregationFn };
139
- //# sourceMappingURL=aggregationFns.d.cts.map
@@ -1,139 +0,0 @@
1
- import { RowData } from "../types/type-utils.js";
2
- import { AggregationFnDef, CreatedAggregationFn } from "../features/column-grouping/columnGroupingFeature.types.js";
3
- import { Row } from "../types/Row.js";
4
- import { TableFeatures } from "../types/TableFeatures.js";
5
-
6
- //#region src/fns/aggregationFns.d.ts
7
- /**
8
- * Builds an `AggregationFn` from a value-level reducer plus optional
9
- * `resolveDataValue` and `fromRows` settings.
10
- *
11
- * The `aggregate` reducer receives an array of the group rows' values, each
12
- * already passed through `resolveDataValue` when one is defined. Keeping
13
- * normalization in the resolver means a variant of an existing aggregation
14
- * function only has to swap the resolver, not re-implement the computation.
15
- *
16
- * The definition is attached to the returned function, so a variant can be
17
- * created by spreading a built-in aggregation function and overriding what
18
- * differs. For example, a `min` that works on date columns:
19
- *
20
- * ```ts
21
- * const earliest = constructAggregationFn({
22
- * ...aggregationFn_min,
23
- * resolveDataValue: (value) =>
24
- * value instanceof Date ? value.getTime() : value,
25
- * })
26
- * ```
27
- *
28
- * The built-in `count`, `first`, and `last` aggregation functions are plain
29
- * row-level functions instead: they read group position or size and never
30
- * look at every value, so materializing a values array would be wasted work.
31
- */
32
- declare function constructAggregationFn<TFeatures extends TableFeatures = any, TData extends RowData = any>(def: AggregationFnDef<TFeatures, TData>): CreatedAggregationFn<TFeatures, TData>;
33
- /**
34
- * Sums numeric child-row values for a grouped column.
35
- *
36
- * Non-number values contribute `0`. Child rows are used so nested group totals
37
- * can reuse already aggregated values.
38
- */
39
- declare const aggregationFn_sum: CreatedAggregationFn<any, any>;
40
- /**
41
- * Finds the minimum numeric child-row value for a grouped column.
42
- *
43
- * Nullish and non-number values are ignored. Returns `undefined` when no
44
- * numeric value is found.
45
- */
46
- declare const aggregationFn_min: CreatedAggregationFn<any, any>;
47
- /**
48
- * Finds the maximum numeric child-row value for a grouped column.
49
- *
50
- * Nullish and non-number values are ignored. Returns `undefined` when no
51
- * numeric value is found.
52
- */
53
- declare const aggregationFn_max: CreatedAggregationFn<any, any>;
54
- /**
55
- * Finds the numeric extent for a grouped column.
56
- *
57
- * Returns `[min, max]`, where each entry is `undefined` when no numeric value is
58
- * present.
59
- */
60
- declare const aggregationFn_extent: CreatedAggregationFn<any, any>;
61
- /**
62
- * Averages numeric leaf-row values for a grouped column.
63
- *
64
- * Number-like values are coerced with unary `+`; nullish and non-numeric values
65
- * are ignored.
66
- */
67
- declare const aggregationFn_mean: CreatedAggregationFn<any, any>;
68
- /**
69
- * Computes the median of numeric leaf-row values for a grouped column.
70
- *
71
- * All values must be numbers. If any value is non-numeric, or no leaf rows are
72
- * present, the result is `undefined`.
73
- */
74
- declare const aggregationFn_median: CreatedAggregationFn<any, any>;
75
- /**
76
- * Collects unique leaf-row values for a grouped column.
77
- *
78
- * Values are compared with JavaScript `Set` semantics.
79
- */
80
- declare const aggregationFn_unique: CreatedAggregationFn<any, any>;
81
- /**
82
- * Counts unique leaf-row values for a grouped column.
83
- *
84
- * Values are compared with JavaScript `Set` semantics.
85
- */
86
- declare const aggregationFn_uniqueCount: CreatedAggregationFn<any, any>;
87
- /**
88
- * Counts the number of leaf rows in the group.
89
- *
90
- * The column id is ignored because the result is based only on group size.
91
- * This is a plain row-level function (not built with
92
- * `constructAggregationFn`) because it never reads row values.
93
- */
94
- declare function aggregationFn_count<TFeatures extends TableFeatures, TData extends RowData>(_columnId: string, leafRows: Array<Row<TFeatures, TData>>): number;
95
- /**
96
- * Returns the first leaf-row value for a grouped column.
97
- *
98
- * This is a plain row-level function (not built with
99
- * `constructAggregationFn`) because it only reads one positional value.
100
- */
101
- declare function aggregationFn_first<TFeatures extends TableFeatures, TData extends RowData>(columnId: string, leafRows: Array<Row<TFeatures, TData>>): unknown;
102
- /**
103
- * Returns the last leaf-row value for a grouped column.
104
- *
105
- * This is a plain row-level function (not built with
106
- * `constructAggregationFn`) because it only reads one positional value.
107
- */
108
- declare function aggregationFn_last<TFeatures extends TableFeatures, TData extends RowData>(columnId: string, leafRows: Array<Row<TFeatures, TData>>): unknown;
109
- /**
110
- * The built-in aggregation function registry.
111
- *
112
- * Registering this full object opts out of tree-shaking: every built-in
113
- * aggregation function ends up in your bundle. Prefer importing the
114
- * `aggregationFn_*` functions you actually use and registering just those in
115
- * the `aggregationFns` slot, or passing them directly to the `aggregationFn`
116
- * column option.
117
- *
118
- * @deprecated Import individual `aggregationFn_*` functions instead for a
119
- * smaller bundle. This export still works and is not going away in v9, but
120
- * built-in name resolution (including `aggregationFn: 'auto'`) only finds
121
- * functions you register yourself.
122
- */
123
- declare const aggregationFns: {
124
- sum: CreatedAggregationFn<any, any>;
125
- min: CreatedAggregationFn<any, any>;
126
- max: CreatedAggregationFn<any, any>;
127
- extent: CreatedAggregationFn<any, any>;
128
- mean: CreatedAggregationFn<any, any>;
129
- median: CreatedAggregationFn<any, any>;
130
- unique: CreatedAggregationFn<any, any>;
131
- uniqueCount: CreatedAggregationFn<any, any>;
132
- count: typeof aggregationFn_count;
133
- first: typeof aggregationFn_first;
134
- last: typeof aggregationFn_last;
135
- };
136
- type BuiltInAggregationFn = keyof typeof aggregationFns;
137
- //#endregion
138
- export { BuiltInAggregationFn, aggregationFn_count, aggregationFn_extent, aggregationFn_first, aggregationFn_last, aggregationFn_max, aggregationFn_mean, aggregationFn_median, aggregationFn_min, aggregationFn_sum, aggregationFn_unique, aggregationFn_uniqueCount, aggregationFns, constructAggregationFn };
139
- //# sourceMappingURL=aggregationFns.d.ts.map