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

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 (73) hide show
  1. package/dist/core/rows/coreRowsFeature.cjs +5 -1
  2. package/dist/core/rows/coreRowsFeature.cjs.map +1 -1
  3. package/dist/core/rows/coreRowsFeature.js +6 -2
  4. package/dist/core/rows/coreRowsFeature.js.map +1 -1
  5. package/dist/core/rows/coreRowsFeature.types.d.cts +8 -0
  6. package/dist/core/rows/coreRowsFeature.types.d.ts +8 -0
  7. package/dist/core/rows/coreRowsFeature.utils.cjs +11 -0
  8. package/dist/core/rows/coreRowsFeature.utils.cjs.map +1 -1
  9. package/dist/core/rows/coreRowsFeature.utils.d.cts +6 -1
  10. package/dist/core/rows/coreRowsFeature.utils.d.ts +6 -1
  11. package/dist/core/rows/coreRowsFeature.utils.js +11 -1
  12. package/dist/core/rows/coreRowsFeature.utils.js.map +1 -1
  13. package/dist/features/aggregation/aggregationFeature.cjs +3 -2
  14. package/dist/features/aggregation/aggregationFeature.cjs.map +1 -1
  15. package/dist/features/aggregation/aggregationFeature.js +3 -2
  16. package/dist/features/aggregation/aggregationFeature.js.map +1 -1
  17. package/dist/features/aggregation/aggregationFeature.types.cjs.map +1 -1
  18. package/dist/features/aggregation/aggregationFeature.types.d.cts +36 -13
  19. package/dist/features/aggregation/aggregationFeature.types.d.ts +36 -13
  20. package/dist/features/aggregation/aggregationFeature.types.js.map +1 -1
  21. package/dist/features/aggregation/aggregationFeature.utils.cjs +36 -22
  22. package/dist/features/aggregation/aggregationFeature.utils.cjs.map +1 -1
  23. package/dist/features/aggregation/aggregationFeature.utils.d.cts +9 -8
  24. package/dist/features/aggregation/aggregationFeature.utils.d.ts +9 -8
  25. package/dist/features/aggregation/aggregationFeature.utils.js +36 -22
  26. package/dist/features/aggregation/aggregationFeature.utils.js.map +1 -1
  27. package/dist/features/aggregation/aggregationFns.cjs +35 -29
  28. package/dist/features/aggregation/aggregationFns.cjs.map +1 -1
  29. package/dist/features/aggregation/aggregationFns.d.cts +8 -7
  30. package/dist/features/aggregation/aggregationFns.d.ts +8 -7
  31. package/dist/features/aggregation/aggregationFns.js +35 -29
  32. package/dist/features/aggregation/aggregationFns.js.map +1 -1
  33. package/dist/features/column-grouping/createGroupedRowModel.cjs +3 -3
  34. package/dist/features/column-grouping/createGroupedRowModel.cjs.map +1 -1
  35. package/dist/features/column-grouping/createGroupedRowModel.js +3 -3
  36. package/dist/features/column-grouping/createGroupedRowModel.js.map +1 -1
  37. package/dist/index.d.cts +2 -2
  38. package/dist/index.d.ts +2 -2
  39. package/dist/static-functions.cjs +1 -0
  40. package/dist/static-functions.d.cts +2 -2
  41. package/dist/static-functions.d.ts +2 -2
  42. package/dist/static-functions.js +2 -2
  43. package/package.json +1 -1
  44. package/skills/aggregation/SKILL.md +25 -15
  45. package/skills/api-not-found/SKILL.md +1 -1
  46. package/skills/client-vs-server/SKILL.md +1 -1
  47. package/skills/column-faceting/SKILL.md +1 -1
  48. package/skills/column-filtering/SKILL.md +1 -1
  49. package/skills/column-ordering/SKILL.md +1 -1
  50. package/skills/column-pinning/SKILL.md +1 -1
  51. package/skills/column-resizing/SKILL.md +1 -1
  52. package/skills/column-sizing/SKILL.md +1 -1
  53. package/skills/column-visibility/SKILL.md +1 -1
  54. package/skills/core/SKILL.md +1 -1
  55. package/skills/custom-features/SKILL.md +1 -1
  56. package/skills/expanding/SKILL.md +1 -1
  57. package/skills/global-filtering/SKILL.md +1 -1
  58. package/skills/grouping/SKILL.md +1 -1
  59. package/skills/migrate-v8-to-v9/SKILL.md +11 -3
  60. package/skills/pagination/SKILL.md +1 -1
  61. package/skills/row-pinning/SKILL.md +1 -1
  62. package/skills/row-selection/SKILL.md +1 -1
  63. package/skills/sorting/SKILL.md +1 -1
  64. package/skills/table-features/SKILL.md +1 -1
  65. package/skills/typescript/SKILL.md +1 -1
  66. package/src/core/rows/coreRowsFeature.ts +5 -0
  67. package/src/core/rows/coreRowsFeature.types.ts +8 -0
  68. package/src/core/rows/coreRowsFeature.utils.ts +18 -0
  69. package/src/features/aggregation/aggregationFeature.ts +2 -1
  70. package/src/features/aggregation/aggregationFeature.types.ts +39 -12
  71. package/src/features/aggregation/aggregationFeature.utils.ts +56 -27
  72. package/src/features/aggregation/aggregationFns.ts +42 -33
  73. package/src/features/column-grouping/createGroupedRowModel.ts +3 -3
@@ -16,6 +16,14 @@ interface AggregationContext<TFeatures extends TableFeatures, TData extends RowD
16
16
  column: Column<TFeatures, TData, TValue>;
17
17
  /** Convenience alias for `column.id`. */
18
18
  columnId: string;
19
+ /** Maximum relative sub-row depth used to select `rows`. */
20
+ maxDepth: number;
21
+ /**
22
+ * Immediate sub-rows for grouped aggregation. This property is omitted
23
+ * for root or caller-supplied-row aggregation. At a terminal grouping level
24
+ * these are the direct data rows; at a nested level they are sub-row groups.
25
+ */
26
+ subRows?: ReadonlyArray<Row<TFeatures, TData>>;
19
27
  /** Reads this column's value from one of `rows`. */
20
28
  getValue: (row: Row<TFeatures, TData>) => TValue;
21
29
  /**
@@ -25,8 +33,8 @@ interface AggregationContext<TFeatures extends TableFeatures, TData extends RowD
25
33
  */
26
34
  groupingRow?: Row<TFeatures, TData>;
27
35
  /**
28
- * Terminal leaf rows included in this aggregation. The executor normalizes
29
- * hierarchical and duplicate row inputs before invoking the definition.
36
+ * Unique rows selected at `maxDepth`. Branches that end before `maxDepth`
37
+ * contribute their deepest available row.
30
38
  */
31
39
  rows: ReadonlyArray<Row<TFeatures, TData>>;
32
40
  /** The table that owns the column and rows. */
@@ -34,18 +42,18 @@ interface AggregationContext<TFeatures extends TableFeatures, TData extends RowD
34
42
  }
35
43
  /** Additional values available when merging nested grouped results. */
36
44
  interface AggregationMergeContext<TFeatures extends TableFeatures, TData extends RowData, TValue, TResult> extends AggregationContext<TFeatures, TData, TValue> {
37
- /** Results produced for each immediate child group, in child-row order. */
38
- childResults: ReadonlyArray<TResult>;
39
- /** Immediate child group rows corresponding to `childResults`. */
40
- childRows: ReadonlyArray<Row<TFeatures, TData>>;
45
+ /** Results produced for each immediate sub-row group, in sub-row order. */
46
+ subRowResults: ReadonlyArray<TResult>;
47
+ /** Immediate sub-row groups corresponding to `subRowResults`. */
48
+ subRows: ReadonlyArray<Row<TFeatures, TData>>;
41
49
  }
42
50
  /** A context-based aggregation definition and optional grouped-result merge. */
43
51
  interface AggregationFnDef<TFeatures extends TableFeatures = any, TData extends RowData = any, TValue = unknown, TResult = unknown> {
44
- /** Computes a result directly from normalized terminal rows. */
52
+ /** Computes a result directly from the selected `rows`. */
45
53
  aggregate: (context: AggregationContext<TFeatures, TData, TValue>) => TResult;
46
54
  /**
47
- * Combines already-computed immediate child-group results. When omitted,
48
- * nested grouping falls back to `aggregate` over the group's terminal rows.
55
+ * Combines already-computed immediate sub-row results. When omitted,
56
+ * nested grouping falls back to `aggregate` over the group's selected rows.
49
57
  */
50
58
  merge?: (context: AggregationMergeContext<TFeatures, TData, TValue, TResult>) => TResult;
51
59
  }
@@ -114,6 +122,12 @@ interface ColumnDef_Aggregation<in out TFeatures extends TableFeatures, in out T
114
122
  * result object. Inline definitions in an array require an explicit `id`.
115
123
  */
116
124
  aggregationFn?: AggregationFnOption<TFeatures, TData, TValue>;
125
+ /**
126
+ * Maximum relative sub-row depth used for grouped aggregation and cached
127
+ * default totals. `0` selects the supplied root rows, `1` their direct
128
+ * sub-rows, and so on. Defaults to `0`.
129
+ */
130
+ maxAggregationDepth?: number;
117
131
  /**
118
132
  * Optionally supplies a precomputed aggregation value for this column.
119
133
  * Return `{ value }` to handle the request, including `{ value: undefined }`;
@@ -127,13 +141,20 @@ interface Column_Aggregation<in out TFeatures extends TableFeatures, in out TDat
127
141
  getAggregationFns: () => ReadonlyArray<ResolvedAggregationFn<TFeatures, TData>>;
128
142
  /**
129
143
  * Aggregates this column over the default pre-grouped row model, or over a
130
- * caller-provided array of rows. Explicit rows are normalized to unique
131
- * terminal leaves and are intentionally not cached.
144
+ * caller-provided array of rows. `options.maxDepth` overrides the column's
145
+ * `maxAggregationDepth`. Explicit-row calls are intentionally not cached.
132
146
  */
133
- getAggregationValue: <TResult = ColumnAggregationValue<TFeatures>>(rows?: ReadonlyArray<Row<TFeatures, TData>>) => TResult;
147
+ getAggregationValue: <TResult = ColumnAggregationValue<TFeatures>>(options?: AggregationValueOptions<TFeatures, TData>) => TResult;
134
148
  /** Infers `sum` for a numeric first row and `extent` for a Date first row. */
135
149
  getAutoAggregationFn: () => AggregationFnDef<TFeatures, TData, any, any> | undefined;
136
150
  }
151
+ /** Options for a caller-requested column aggregation value. */
152
+ interface AggregationValueOptions<in out TFeatures extends TableFeatures, in out TData extends RowData> {
153
+ /** Overrides the column's `maxAggregationDepth` for this request. */
154
+ maxDepth?: number;
155
+ /** Rows to aggregate instead of the default pre-grouped row model. */
156
+ rows?: ReadonlyArray<Row<TFeatures, TData>>;
157
+ }
137
158
  /** Cell instance APIs installed by `aggregationFeature`. */
138
159
  interface Cell_Aggregation {
139
160
  /** Whether this cell displays an aggregate on a synthetic grouped row. */
@@ -148,6 +169,8 @@ interface Row_Aggregation {
148
169
  interface AggregationValueContext<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData> {
149
170
  /** The column whose value was requested. */
150
171
  column: Column<TFeatures, TData, TValue>;
172
+ /** Maximum relative sub-row depth used for the request. */
173
+ maxDepth: number;
151
174
  /** Caller-provided rows, or `undefined` for the default row model. */
152
175
  rows?: ReadonlyArray<Row<TFeatures, TData>>;
153
176
  /** The table that owns the column. */
@@ -168,5 +191,5 @@ interface TableOptions_Aggregation {
168
191
  manualAggregation?: boolean;
169
192
  }
170
193
  //#endregion
171
- export { AggregationContext, AggregationFnDef, AggregationFnDescriptor, AggregationFnListItem, AggregationFnOption, AggregationFnRef, AggregationFns, AggregationMergeContext, AggregationResult, AggregationResultOf, AggregationValueContext, AggregationValueResult, Cell_Aggregation, ColumnAggregationValue, ColumnDef_Aggregation, Column_Aggregation, CustomAggregationFns, ExtractAggregationFnKeys, ResolvedAggregationFn, RowModelFns_Aggregation, Row_Aggregation, TableOptions_Aggregation, constructAggregationFn };
194
+ export { AggregationContext, AggregationFnDef, AggregationFnDescriptor, AggregationFnListItem, AggregationFnOption, AggregationFnRef, AggregationFns, AggregationMergeContext, AggregationResult, AggregationResultOf, AggregationValueContext, AggregationValueOptions, AggregationValueResult, Cell_Aggregation, ColumnAggregationValue, ColumnDef_Aggregation, Column_Aggregation, CustomAggregationFns, ExtractAggregationFnKeys, ResolvedAggregationFn, RowModelFns_Aggregation, Row_Aggregation, TableOptions_Aggregation, constructAggregationFn };
172
195
  //# sourceMappingURL=aggregationFeature.types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"aggregationFeature.types.js","names":[],"sources":["../../../src/features/aggregation/aggregationFeature.types.ts"],"sourcesContent":["import type { BuiltInAggregationFn } from './aggregationFns'\nimport type { Cell } from '../../types/Cell'\nimport type { Column } from '../../types/Column'\nimport type { ColumnDefTemplate } from '../../types/ColumnDef'\nimport type { IsAny, TableFeatures } from '../../types/TableFeatures'\nimport type { Row } from '../../types/Row'\nimport type { Table } from '../../types/Table'\nimport type { CellData, RowData } from '../../types/type-utils'\n\n/** Declaration-merging fallback for named aggregation definitions. */\nexport interface AggregationFns {}\n\n/** Values and table objects available while one aggregation is evaluated. */\nexport interface AggregationContext<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue = unknown,\n> {\n /** The column whose values are being aggregated. */\n column: Column<TFeatures, TData, TValue>\n /** Convenience alias for `column.id`. */\n columnId: string\n /** Reads this column's value from one of `rows`. */\n getValue: (row: Row<TFeatures, TData>) => TValue\n /**\n * The synthetic grouped row receiving this result. This property is omitted\n * for root or caller-supplied-row aggregation. Its `depth` identifies the\n * grouping level when grouped aggregation needs that distinction.\n */\n groupingRow?: Row<TFeatures, TData>\n /**\n * Terminal leaf rows included in this aggregation. The executor normalizes\n * hierarchical and duplicate row inputs before invoking the definition.\n */\n rows: ReadonlyArray<Row<TFeatures, TData>>\n /** The table that owns the column and rows. */\n table: Table<TFeatures, TData>\n}\n\n/** Additional values available when merging nested grouped results. */\nexport interface AggregationMergeContext<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue,\n TResult,\n> extends AggregationContext<TFeatures, TData, TValue> {\n /** Results produced for each immediate child group, in child-row order. */\n childResults: ReadonlyArray<TResult>\n /** Immediate child group rows corresponding to `childResults`. */\n childRows: ReadonlyArray<Row<TFeatures, TData>>\n}\n\n/** A context-based aggregation definition and optional grouped-result merge. */\nexport interface AggregationFnDef<\n TFeatures extends TableFeatures = any,\n TData extends RowData = any,\n TValue = unknown,\n TResult = unknown,\n> {\n /** Computes a result directly from normalized terminal rows. */\n aggregate: (context: AggregationContext<TFeatures, TData, TValue>) => TResult\n /**\n * Combines already-computed immediate child-group results. When omitted,\n * nested grouping falls back to `aggregate` over the group's terminal rows.\n */\n merge?: (\n context: AggregationMergeContext<TFeatures, TData, TValue, TResult>,\n ) => TResult\n}\n\n/**\n * Creates a typed context-based aggregation definition for a column or\n * aggregation-function registry.\n */\nexport function constructAggregationFn<\n TFeatures extends TableFeatures = any,\n TData extends RowData = any,\n TValue = unknown,\n TResult = unknown,\n>(\n definition: AggregationFnDef<TFeatures, TData, TValue, TResult>,\n): AggregationFnDef<TFeatures, TData, TValue, TResult> {\n return definition\n}\n\n/** Aggregation-definition registry carried by a table feature set. */\nexport interface RowModelFns_Aggregation<\n in out TFeatures extends TableFeatures,\n in out TData extends RowData,\n> {\n aggregationFns: Record<string, AggregationFnDef<TFeatures, TData, any, any>>\n}\n\n/** Named context-based aggregation definitions registered on a feature set. */\nexport type CustomAggregationFns<\n TFeatures extends TableFeatures,\n TData extends RowData,\n> = Record<string, AggregationFnDef<TFeatures, TData, any, any>>\n\n/** String names available from a feature set's aggregation registry. */\nexport type ExtractAggregationFnKeys<TFeatures extends TableFeatures> =\n IsAny<TFeatures> extends true\n ? keyof AggregationFns | BuiltInAggregationFn\n : TFeatures extends { aggregationFns: infer TAggregationFns extends object }\n ? Extract<keyof TAggregationFns, string>\n : keyof AggregationFns\n\n/** A registered name, automatic inference, or inline aggregation definition. */\nexport type AggregationFnRef<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue = unknown,\n TResult = unknown,\n> =\n | 'auto'\n | ExtractAggregationFnKeys<TFeatures>\n | AggregationFnDef<TFeatures, TData, TValue, TResult>\n\n/** Gives an aggregation reference a stable key in a multiple result. */\nexport interface AggregationFnDescriptor<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue = unknown,\n TResult = unknown,\n> {\n /** The named, automatic, or inline definition to execute. */\n aggregationFn: AggregationFnRef<TFeatures, TData, TValue, TResult>\n /** Stable key used in the object returned by a multiple aggregation. */\n id: string\n}\n\n/** One named or explicitly keyed entry in a multiple aggregation option. */\nexport type AggregationFnListItem<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue = unknown,\n> =\n | 'auto'\n | ExtractAggregationFnKeys<TFeatures>\n | AggregationFnDescriptor<TFeatures, TData, TValue, any>\n\n/** A scalar aggregation reference or a list that produces a keyed object. */\nexport type AggregationFnOption<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue = unknown,\n> =\n | AggregationFnRef<TFeatures, TData, TValue, any>\n | ReadonlyArray<AggregationFnListItem<TFeatures, TData, TValue>>\n\n/** Extracts the result type produced by an aggregation definition. */\nexport type AggregationResultOf<TDefinition> =\n TDefinition extends AggregationFnDef<any, any, any, infer TResult>\n ? TResult\n : unknown\n\ntype RegisteredAggregationDefinition<\n TFeatures extends TableFeatures,\n TKey extends PropertyKey,\n> = TFeatures extends {\n aggregationFns: infer TRegistry extends Record<PropertyKey, unknown>\n}\n ? TKey extends keyof TRegistry\n ? TRegistry[TKey]\n : never\n : never\n\ntype AggregationResultOfRef<TRef, TFeatures extends TableFeatures> =\n TRef extends AggregationFnDef<any, any, any, any>\n ? AggregationResultOf<TRef>\n : TRef extends 'auto'\n ? RegisteredAggregationResult<TFeatures>\n : TRef extends PropertyKey\n ? AggregationResultOf<RegisteredAggregationDefinition<TFeatures, TRef>>\n : unknown\n\ntype AggregationEntryId<TEntry> = TEntry extends string\n ? TEntry\n : TEntry extends { id: infer TId extends string }\n ? TId\n : never\n\ntype AggregationEntryDefinition<TEntry> = TEntry extends {\n aggregationFn: infer TDefinition\n}\n ? TDefinition\n : TEntry\n\n/** Infers the scalar or keyed result produced by an aggregation option. */\nexport type AggregationResult<TOption, TFeatures extends TableFeatures = any> =\n TOption extends ReadonlyArray<infer TEntry>\n ? {\n [TKey in AggregationEntryId<TEntry>]: AggregationResultOfRef<\n AggregationEntryDefinition<Extract<TEntry, TKey | { id: TKey }>>,\n TFeatures\n >\n }\n : AggregationResultOfRef<TOption, TFeatures>\n\ntype RegisteredAggregationResult<TFeatures extends TableFeatures> =\n TFeatures extends {\n aggregationFns: infer TRegistry extends Record<string, unknown>\n }\n ? AggregationResultOf<TRegistry[keyof TRegistry]>\n : unknown\n\n/** Default public result union when a column's precise option is not known. */\nexport type ColumnAggregationValue<TFeatures extends TableFeatures> =\n | RegisteredAggregationResult<TFeatures>\n | Record<string, RegisteredAggregationResult<TFeatures> | undefined>\n | undefined\n\n/** A validated aggregation entry returned by `column.getAggregationFns()`. */\nexport interface ResolvedAggregationFn<\n TFeatures extends TableFeatures,\n TData extends RowData,\n> {\n /** Resolved definition, or `undefined` when configuration is invalid. */\n aggregationFn: AggregationFnDef<TFeatures, TData, any, any> | undefined\n /** Key used for a multiple result; scalar inline definitions have no id. */\n id: string | undefined\n}\n\n/** Column-definition options installed by `aggregationFeature`. */\nexport interface ColumnDef_Aggregation<\n in out TFeatures extends TableFeatures,\n in out TData extends RowData,\n TValue extends CellData = CellData,\n> {\n /** Renderer used for a grouped row's aggregated cell. */\n aggregatedCell?: ColumnDefTemplate<\n ReturnType<Cell<TFeatures, TData, TValue>['getContext']>\n >\n /**\n * One aggregation reference for a scalar result, or an array for a keyed\n * result object. Inline definitions in an array require an explicit `id`.\n */\n aggregationFn?: AggregationFnOption<TFeatures, TData, TValue>\n /**\n * Optionally supplies a precomputed aggregation value for this column.\n * Return `{ value }` to handle the request, including `{ value: undefined }`;\n * return `undefined` to use the local aggregation fallback.\n */\n getAggregationValue?: (\n context: AggregationValueContext<TFeatures, TData, TValue>,\n ) => AggregationValueResult | undefined\n}\n\n/** Column instance APIs installed by `aggregationFeature`. */\nexport interface Column_Aggregation<\n in out TFeatures extends TableFeatures,\n in out TData extends RowData,\n> {\n /** Resolves the configured scalar or multiple aggregation definitions. */\n getAggregationFns: () => ReadonlyArray<\n ResolvedAggregationFn<TFeatures, TData>\n >\n /**\n * Aggregates this column over the default pre-grouped row model, or over a\n * caller-provided array of rows. Explicit rows are normalized to unique\n * terminal leaves and are intentionally not cached.\n */\n getAggregationValue: <TResult = ColumnAggregationValue<TFeatures>>(\n rows?: ReadonlyArray<Row<TFeatures, TData>>,\n ) => TResult\n /** Infers `sum` for a numeric first row and `extent` for a Date first row. */\n getAutoAggregationFn: () =>\n | AggregationFnDef<TFeatures, TData, any, any>\n | undefined\n}\n\n/** Cell instance APIs installed by `aggregationFeature`. */\nexport interface Cell_Aggregation {\n /** Whether this cell displays an aggregate on a synthetic grouped row. */\n getIsAggregated: () => boolean\n}\n\n/** Internal per-row cache used while grouped aggregates are evaluated. */\nexport interface Row_Aggregation {\n /** Cached aggregate results keyed by column id. */\n _aggregationValuesCache: Record<string, unknown>\n}\n\n/** Values passed to a column-level aggregation-value provider. */\nexport interface AggregationValueContext<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n> {\n /** The column whose value was requested. */\n column: Column<TFeatures, TData, TValue>\n /** Caller-provided rows, or `undefined` for the default row model. */\n rows?: ReadonlyArray<Row<TFeatures, TData>>\n /** The table that owns the column. */\n table: Table<TFeatures, TData>\n}\n\n/** Marks an aggregation-value override as handled. */\nexport interface AggregationValueResult<TResult = unknown> {\n /** The supplied value. `undefined` is still a handled result. */\n value: TResult\n}\n\n/** Table options installed by `aggregationFeature`. */\nexport interface TableOptions_Aggregation {\n /**\n * Disables local `column.getAggregationValue()` calculation when a column\n * override does not handle the request. Group values supplied by manually\n * grouped rows remain the responsibility of the data owner.\n */\n manualAggregation?: boolean\n}\n"],"mappings":";;;;;AA0EA,SAAgB,uBAMd,YACqD;CACrD,OAAO;AACT"}
1
+ {"version":3,"file":"aggregationFeature.types.js","names":[],"sources":["../../../src/features/aggregation/aggregationFeature.types.ts"],"sourcesContent":["import type { BuiltInAggregationFn } from './aggregationFns'\nimport type { Cell } from '../../types/Cell'\nimport type { Column } from '../../types/Column'\nimport type { ColumnDefTemplate } from '../../types/ColumnDef'\nimport type { IsAny, TableFeatures } from '../../types/TableFeatures'\nimport type { Row } from '../../types/Row'\nimport type { Table } from '../../types/Table'\nimport type { CellData, RowData } from '../../types/type-utils'\n\n/** Declaration-merging fallback for named aggregation definitions. */\nexport interface AggregationFns {}\n\n/** Values and table objects available while one aggregation is evaluated. */\nexport interface AggregationContext<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue = unknown,\n> {\n /** The column whose values are being aggregated. */\n column: Column<TFeatures, TData, TValue>\n /** Convenience alias for `column.id`. */\n columnId: string\n /** Maximum relative sub-row depth used to select `rows`. */\n maxDepth: number\n /**\n * Immediate sub-rows for grouped aggregation. This property is omitted\n * for root or caller-supplied-row aggregation. At a terminal grouping level\n * these are the direct data rows; at a nested level they are sub-row groups.\n */\n subRows?: ReadonlyArray<Row<TFeatures, TData>>\n /** Reads this column's value from one of `rows`. */\n getValue: (row: Row<TFeatures, TData>) => TValue\n /**\n * The synthetic grouped row receiving this result. This property is omitted\n * for root or caller-supplied-row aggregation. Its `depth` identifies the\n * grouping level when grouped aggregation needs that distinction.\n */\n groupingRow?: Row<TFeatures, TData>\n /**\n * Unique rows selected at `maxDepth`. Branches that end before `maxDepth`\n * contribute their deepest available row.\n */\n rows: ReadonlyArray<Row<TFeatures, TData>>\n /** The table that owns the column and rows. */\n table: Table<TFeatures, TData>\n}\n\n/** Additional values available when merging nested grouped results. */\nexport interface AggregationMergeContext<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue,\n TResult,\n> extends AggregationContext<TFeatures, TData, TValue> {\n /** Results produced for each immediate sub-row group, in sub-row order. */\n subRowResults: ReadonlyArray<TResult>\n /** Immediate sub-row groups corresponding to `subRowResults`. */\n subRows: ReadonlyArray<Row<TFeatures, TData>>\n}\n\n/** A context-based aggregation definition and optional grouped-result merge. */\nexport interface AggregationFnDef<\n TFeatures extends TableFeatures = any,\n TData extends RowData = any,\n TValue = unknown,\n TResult = unknown,\n> {\n /** Computes a result directly from the selected `rows`. */\n aggregate: (context: AggregationContext<TFeatures, TData, TValue>) => TResult\n /**\n * Combines already-computed immediate sub-row results. When omitted,\n * nested grouping falls back to `aggregate` over the group's selected rows.\n */\n merge?: (\n context: AggregationMergeContext<TFeatures, TData, TValue, TResult>,\n ) => TResult\n}\n\n/**\n * Creates a typed context-based aggregation definition for a column or\n * aggregation-function registry.\n */\nexport function constructAggregationFn<\n TFeatures extends TableFeatures = any,\n TData extends RowData = any,\n TValue = unknown,\n TResult = unknown,\n>(\n definition: AggregationFnDef<TFeatures, TData, TValue, TResult>,\n): AggregationFnDef<TFeatures, TData, TValue, TResult> {\n return definition\n}\n\n/** Aggregation-definition registry carried by a table feature set. */\nexport interface RowModelFns_Aggregation<\n in out TFeatures extends TableFeatures,\n in out TData extends RowData,\n> {\n aggregationFns: Record<string, AggregationFnDef<TFeatures, TData, any, any>>\n}\n\n/** Named context-based aggregation definitions registered on a feature set. */\nexport type CustomAggregationFns<\n TFeatures extends TableFeatures,\n TData extends RowData,\n> = Record<string, AggregationFnDef<TFeatures, TData, any, any>>\n\n/** String names available from a feature set's aggregation registry. */\nexport type ExtractAggregationFnKeys<TFeatures extends TableFeatures> =\n IsAny<TFeatures> extends true\n ? keyof AggregationFns | BuiltInAggregationFn\n : TFeatures extends { aggregationFns: infer TAggregationFns extends object }\n ? Extract<keyof TAggregationFns, string>\n : keyof AggregationFns\n\n/** A registered name, automatic inference, or inline aggregation definition. */\nexport type AggregationFnRef<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue = unknown,\n TResult = unknown,\n> =\n | 'auto'\n | ExtractAggregationFnKeys<TFeatures>\n | AggregationFnDef<TFeatures, TData, TValue, TResult>\n\n/** Gives an aggregation reference a stable key in a multiple result. */\nexport interface AggregationFnDescriptor<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue = unknown,\n TResult = unknown,\n> {\n /** The named, automatic, or inline definition to execute. */\n aggregationFn: AggregationFnRef<TFeatures, TData, TValue, TResult>\n /** Stable key used in the object returned by a multiple aggregation. */\n id: string\n}\n\n/** One named or explicitly keyed entry in a multiple aggregation option. */\nexport type AggregationFnListItem<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue = unknown,\n> =\n | 'auto'\n | ExtractAggregationFnKeys<TFeatures>\n | AggregationFnDescriptor<TFeatures, TData, TValue, any>\n\n/** A scalar aggregation reference or a list that produces a keyed object. */\nexport type AggregationFnOption<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue = unknown,\n> =\n | AggregationFnRef<TFeatures, TData, TValue, any>\n | ReadonlyArray<AggregationFnListItem<TFeatures, TData, TValue>>\n\n/** Extracts the result type produced by an aggregation definition. */\nexport type AggregationResultOf<TDefinition> =\n TDefinition extends AggregationFnDef<any, any, any, infer TResult>\n ? TResult\n : unknown\n\ntype RegisteredAggregationDefinition<\n TFeatures extends TableFeatures,\n TKey extends PropertyKey,\n> = TFeatures extends {\n aggregationFns: infer TRegistry extends Record<PropertyKey, unknown>\n}\n ? TKey extends keyof TRegistry\n ? TRegistry[TKey]\n : never\n : never\n\ntype AggregationResultOfRef<TRef, TFeatures extends TableFeatures> =\n TRef extends AggregationFnDef<any, any, any, any>\n ? AggregationResultOf<TRef>\n : TRef extends 'auto'\n ? RegisteredAggregationResult<TFeatures>\n : TRef extends PropertyKey\n ? AggregationResultOf<RegisteredAggregationDefinition<TFeatures, TRef>>\n : unknown\n\ntype AggregationEntryId<TEntry> = TEntry extends string\n ? TEntry\n : TEntry extends { id: infer TId extends string }\n ? TId\n : never\n\ntype AggregationEntryDefinition<TEntry> = TEntry extends {\n aggregationFn: infer TDefinition\n}\n ? TDefinition\n : TEntry\n\n/** Infers the scalar or keyed result produced by an aggregation option. */\nexport type AggregationResult<TOption, TFeatures extends TableFeatures = any> =\n TOption extends ReadonlyArray<infer TEntry>\n ? {\n [TKey in AggregationEntryId<TEntry>]: AggregationResultOfRef<\n AggregationEntryDefinition<Extract<TEntry, TKey | { id: TKey }>>,\n TFeatures\n >\n }\n : AggregationResultOfRef<TOption, TFeatures>\n\ntype RegisteredAggregationResult<TFeatures extends TableFeatures> =\n TFeatures extends {\n aggregationFns: infer TRegistry extends Record<string, unknown>\n }\n ? AggregationResultOf<TRegistry[keyof TRegistry]>\n : unknown\n\n/** Default public result union when a column's precise option is not known. */\nexport type ColumnAggregationValue<TFeatures extends TableFeatures> =\n | RegisteredAggregationResult<TFeatures>\n | Record<string, RegisteredAggregationResult<TFeatures> | undefined>\n | undefined\n\n/** A validated aggregation entry returned by `column.getAggregationFns()`. */\nexport interface ResolvedAggregationFn<\n TFeatures extends TableFeatures,\n TData extends RowData,\n> {\n /** Resolved definition, or `undefined` when configuration is invalid. */\n aggregationFn: AggregationFnDef<TFeatures, TData, any, any> | undefined\n /** Key used for a multiple result; scalar inline definitions have no id. */\n id: string | undefined\n}\n\n/** Column-definition options installed by `aggregationFeature`. */\nexport interface ColumnDef_Aggregation<\n in out TFeatures extends TableFeatures,\n in out TData extends RowData,\n TValue extends CellData = CellData,\n> {\n /** Renderer used for a grouped row's aggregated cell. */\n aggregatedCell?: ColumnDefTemplate<\n ReturnType<Cell<TFeatures, TData, TValue>['getContext']>\n >\n /**\n * One aggregation reference for a scalar result, or an array for a keyed\n * result object. Inline definitions in an array require an explicit `id`.\n */\n aggregationFn?: AggregationFnOption<TFeatures, TData, TValue>\n /**\n * Maximum relative sub-row depth used for grouped aggregation and cached\n * default totals. `0` selects the supplied root rows, `1` their direct\n * sub-rows, and so on. Defaults to `0`.\n */\n maxAggregationDepth?: number\n /**\n * Optionally supplies a precomputed aggregation value for this column.\n * Return `{ value }` to handle the request, including `{ value: undefined }`;\n * return `undefined` to use the local aggregation fallback.\n */\n getAggregationValue?: (\n context: AggregationValueContext<TFeatures, TData, TValue>,\n ) => AggregationValueResult | undefined\n}\n\n/** Column instance APIs installed by `aggregationFeature`. */\nexport interface Column_Aggregation<\n in out TFeatures extends TableFeatures,\n in out TData extends RowData,\n> {\n /** Resolves the configured scalar or multiple aggregation definitions. */\n getAggregationFns: () => ReadonlyArray<\n ResolvedAggregationFn<TFeatures, TData>\n >\n /**\n * Aggregates this column over the default pre-grouped row model, or over a\n * caller-provided array of rows. `options.maxDepth` overrides the column's\n * `maxAggregationDepth`. Explicit-row calls are intentionally not cached.\n */\n getAggregationValue: <TResult = ColumnAggregationValue<TFeatures>>(\n options?: AggregationValueOptions<TFeatures, TData>,\n ) => TResult\n /** Infers `sum` for a numeric first row and `extent` for a Date first row. */\n getAutoAggregationFn: () =>\n | AggregationFnDef<TFeatures, TData, any, any>\n | undefined\n}\n\n/** Options for a caller-requested column aggregation value. */\nexport interface AggregationValueOptions<\n in out TFeatures extends TableFeatures,\n in out TData extends RowData,\n> {\n /** Overrides the column's `maxAggregationDepth` for this request. */\n maxDepth?: number\n /** Rows to aggregate instead of the default pre-grouped row model. */\n rows?: ReadonlyArray<Row<TFeatures, TData>>\n}\n\n/** Cell instance APIs installed by `aggregationFeature`. */\nexport interface Cell_Aggregation {\n /** Whether this cell displays an aggregate on a synthetic grouped row. */\n getIsAggregated: () => boolean\n}\n\n/** Internal per-row cache used while grouped aggregates are evaluated. */\nexport interface Row_Aggregation {\n /** Cached aggregate results keyed by column id. */\n _aggregationValuesCache: Record<string, unknown>\n}\n\n/** Values passed to a column-level aggregation-value provider. */\nexport interface AggregationValueContext<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n> {\n /** The column whose value was requested. */\n column: Column<TFeatures, TData, TValue>\n /** Maximum relative sub-row depth used for the request. */\n maxDepth: number\n /** Caller-provided rows, or `undefined` for the default row model. */\n rows?: ReadonlyArray<Row<TFeatures, TData>>\n /** The table that owns the column. */\n table: Table<TFeatures, TData>\n}\n\n/** Marks an aggregation-value override as handled. */\nexport interface AggregationValueResult<TResult = unknown> {\n /** The supplied value. `undefined` is still a handled result. */\n value: TResult\n}\n\n/** Table options installed by `aggregationFeature`. */\nexport interface TableOptions_Aggregation {\n /**\n * Disables local `column.getAggregationValue()` calculation when a column\n * override does not handle the request. Group values supplied by manually\n * grouped rows remain the responsibility of the data owner.\n */\n manualAggregation?: boolean\n}\n"],"mappings":";;;;;AAkFA,SAAgB,uBAMd,YACqD;CACrD,OAAO;AACT"}
@@ -10,16 +10,20 @@ function isAggregationFnDescriptor(value) {
10
10
  function warn(message) {
11
11
  if (process.env.NODE_ENV === "development") console.warn(message);
12
12
  }
13
+ function resolveMaxAggregationDepth(maxDepth) {
14
+ return maxDepth === void 0 || Number.isNaN(maxDepth) ? 0 : Math.max(0, Math.floor(maxDepth));
15
+ }
13
16
  /**
14
- * Flattens hierarchical row inputs to unique terminal leaves in encounter
15
- * order. This is the normalization used by public aggregation-value calls.
17
+ * Selects unique rows at a maximum relative depth in encounter order.
18
+ * Branches that end before the requested depth contribute their deepest row.
16
19
  */
17
- function normalizeAggregationRows(rows) {
20
+ function normalizeAggregationRows(rows, maxDepth = 0) {
18
21
  const result = [];
19
22
  const seen = /* @__PURE__ */ new Set();
20
- const visit = (row) => {
21
- if (row.subRows.length) {
22
- for (let i = 0; i < row.subRows.length; i++) visit(row.subRows[i]);
23
+ const normalizedMaxDepth = resolveMaxAggregationDepth(maxDepth);
24
+ const visit = (row, depth) => {
25
+ if (row.subRows.length && depth < normalizedMaxDepth) {
26
+ for (let i = 0; i < row.subRows.length; i++) visit(row.subRows[i], depth + 1);
23
27
  return;
24
28
  }
25
29
  if (!seen.has(row.id)) {
@@ -27,7 +31,7 @@ function normalizeAggregationRows(rows) {
27
31
  result.push(row);
28
32
  }
29
33
  };
30
- for (let i = 0; i < rows.length; i++) visit(rows[i]);
34
+ for (let i = 0; i < rows.length; i++) visit(rows[i], 0);
31
35
  return result;
32
36
  }
33
37
  function getAutoAggregationFnName(value) {
@@ -105,33 +109,37 @@ function column_getAggregationFns(column) {
105
109
  }
106
110
  return finish(resolved);
107
111
  }
108
- function getChildResult(childValue, isMultiple, id) {
109
- if (!isMultiple) return childValue;
110
- if (!id || !childValue || typeof childValue !== "object") return void 0;
111
- return require_utils.hasOwn(childValue, id) ? childValue[id] : void 0;
112
+ function getSubRowResult(subRowValue, isMultiple, id) {
113
+ if (!isMultiple) return subRowValue;
114
+ if (!id || !subRowValue || typeof subRowValue !== "object") return void 0;
115
+ return require_utils.hasOwn(subRowValue, id) ? subRowValue[id] : void 0;
112
116
  }
113
- /** Executes every configured aggregation for a column over normalized rows. */
117
+ /** Executes every configured aggregation over a depth-selected row frontier. */
114
118
  function aggregateColumnValue(args) {
115
- const { childRows, column, groupingRow, rows } = args;
119
+ const { subRows, column, groupingRow, rows } = args;
116
120
  const internalColumn = column;
121
+ const maxDepth = resolveMaxAggregationDepth(args.maxDepth ?? internalColumn.columnDef.maxAggregationDepth);
122
+ const aggregationRows = normalizeAggregationRows(rows, maxDepth);
117
123
  const entries = column_getAggregationFns(internalColumn);
118
124
  const isMultiple = Array.isArray(internalColumn.columnDef.aggregationFn);
119
- const canMerge = !!childRows?.length && childRows.every((row) => !!row.groupingColumnId && row.groupingColumnId !== column.id);
125
+ const canMerge = !!subRows?.length && subRows.every((row) => !!row.groupingColumnId && row.groupingColumnId !== column.id);
120
126
  const execute = (entry) => {
121
127
  const definition = entry.aggregationFn;
122
128
  if (!definition) return void 0;
123
129
  const context = {
130
+ ...subRows ? { subRows } : {},
124
131
  column,
125
132
  columnId: column.id,
126
133
  getValue: (row) => row.getValue(column.id),
127
134
  ...groupingRow ? { groupingRow } : {},
128
- rows,
135
+ maxDepth,
136
+ rows: aggregationRows,
129
137
  table: column.table
130
138
  };
131
139
  if (canMerge && definition.merge) return definition.merge({
132
140
  ...context,
133
- childResults: childRows.map((row) => getChildResult(row.getValue(column.id), isMultiple, entry.id)),
134
- childRows
141
+ subRowResults: subRows.map((row) => getSubRowResult(row.getValue(column.id), isMultiple, entry.id)),
142
+ subRows
135
143
  });
136
144
  return definition.aggregate(context);
137
145
  };
@@ -143,10 +151,13 @@ function aggregateColumnValue(args) {
143
151
  }
144
152
  return result;
145
153
  }
146
- /** Implements `column.getAggregationValue(rows?)` and its default-value cache. */
147
- function column_getAggregationValue(column, rows) {
154
+ /** Implements `column.getAggregationValue(options?)` and its default cache. */
155
+ function column_getAggregationValue(column, options) {
156
+ const rows = options?.rows;
157
+ const resolvedMaxDepth = resolveMaxAggregationDepth(options?.maxDepth ?? column.columnDef.maxAggregationDepth);
148
158
  const providedResult = column.columnDef.getAggregationValue?.({
149
159
  column,
160
+ maxDepth: resolvedMaxDepth,
150
161
  rows,
151
162
  table: column.table
152
163
  });
@@ -154,20 +165,23 @@ function column_getAggregationValue(column, rows) {
154
165
  if (column.table.options.manualAggregation) return void 0;
155
166
  if (rows !== void 0) return aggregateColumnValue({
156
167
  column,
157
- rows: normalizeAggregationRows(rows)
168
+ maxDepth: resolvedMaxDepth,
169
+ rows
158
170
  });
159
171
  const model = column.table.getPreGroupedRowModel();
160
172
  const previous = column._aggregationValueCache;
161
173
  const registry = column.table._rowModelFns.aggregationFns;
162
174
  const aggregationFnOption = column.columnDef.aggregationFn;
163
- if (previous && previous.dependency === model && previous.registry === registry && previous.aggregationFnOption === aggregationFnOption) return previous.value;
175
+ if (previous && previous.dependency === model && previous.maxDepth === resolvedMaxDepth && previous.registry === registry && previous.aggregationFnOption === aggregationFnOption) return previous.value;
164
176
  const value = aggregateColumnValue({
165
177
  column,
166
- rows: normalizeAggregationRows(model.rows)
178
+ maxDepth: resolvedMaxDepth,
179
+ rows: model.rows
167
180
  });
168
181
  column._aggregationValueCache = {
169
182
  aggregationFnOption,
170
183
  dependency: model,
184
+ maxDepth: resolvedMaxDepth,
171
185
  registry,
172
186
  value
173
187
  };
@@ -1 +1 @@
1
- {"version":3,"file":"aggregationFeature.utils.cjs","names":["makeObjectMap","hasOwn"],"sources":["../../../src/features/aggregation/aggregationFeature.utils.ts"],"sourcesContent":["import { hasOwn, makeObjectMap } from '../../utils'\nimport type { Cell } from '../../types/Cell'\nimport type { Column, Column_Internal } from '../../types/Column'\nimport type { Row } from '../../types/Row'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { CellData, RowData } from '../../types/type-utils'\nimport type {\n AggregationFnDef,\n AggregationFnDescriptor,\n AggregationFnRef,\n ColumnAggregationValue,\n ResolvedAggregationFn,\n} from './aggregationFeature.types'\n\ninterface AggregationCacheEntry {\n aggregationFnOption: unknown\n dependency: unknown\n registry: unknown\n value: unknown\n}\n\ninterface ResolvedAggregationFnsCacheEntry<\n TFeatures extends TableFeatures,\n TData extends RowData,\n> {\n coreRowModel: unknown\n option: unknown\n registry: unknown\n value: ReadonlyArray<ResolvedAggregationFn<TFeatures, TData>>\n}\n\nfunction isAggregationFnDef(value: unknown): value is AggregationFnDef {\n return !!value && typeof value === 'object' && 'aggregate' in value\n}\n\nfunction isAggregationFnDescriptor(\n value: unknown,\n): value is AggregationFnDescriptor<any, any> {\n return (\n !!value &&\n typeof value === 'object' &&\n 'id' in value &&\n 'aggregationFn' in value\n )\n}\n\nfunction warn(message: string) {\n if (process.env.NODE_ENV === 'development') {\n console.warn(message)\n }\n}\n\n/**\n * Flattens hierarchical row inputs to unique terminal leaves in encounter\n * order. This is the normalization used by public aggregation-value calls.\n */\nexport function normalizeAggregationRows<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(rows: ReadonlyArray<Row<TFeatures, TData>>): Array<Row<TFeatures, TData>> {\n const result: Array<Row<TFeatures, TData>> = []\n const seen = new Set<string>()\n\n const visit = (row: Row<TFeatures, TData>) => {\n if (row.subRows.length) {\n for (let i = 0; i < row.subRows.length; i++) {\n visit(row.subRows[i]!)\n }\n return\n }\n\n if (!seen.has(row.id)) {\n seen.add(row.id)\n result.push(row)\n }\n }\n\n for (let i = 0; i < rows.length; i++) {\n visit(rows[i]!)\n }\n\n return result\n}\n\nfunction getAutoAggregationFnName(\n value: unknown,\n): 'extent' | 'sum' | undefined {\n if (typeof value === 'number') {\n return 'sum'\n }\n\n if (value instanceof Date && !Number.isNaN(value.getTime())) {\n return 'extent'\n }\n\n return undefined\n}\n\n/** Resolves the `sum` or `extent` definition inferred from the first core row. */\nexport function column_getAutoAggregationFn<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n const value = column.table.getCoreRowModel().flatRows[0]?.getValue(column.id)\n\n const name = getAutoAggregationFnName(value)\n if (!name) return undefined\n\n const aggregationFn = column.table._rowModelFns.aggregationFns?.[name]\n\n if (!aggregationFn) {\n warn(\n `aggregationFn '${name}' (auto) for column '${column.id}' is not registered`,\n )\n }\n\n return aggregationFn\n}\n\nfunction resolveAggregationFn<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n column: Column_Internal<TFeatures, TData, any>,\n ref: AggregationFnRef<TFeatures, TData, any, any>,\n): AggregationFnDef<TFeatures, TData, any, any> | undefined {\n if (isAggregationFnDef(ref)) return ref as any\n if (ref === 'auto') return column_getAutoAggregationFn(column)\n\n const aggregationFn =\n column.table._rowModelFns.aggregationFns?.[ref as string]\n if (!aggregationFn) {\n warn(\n `aggregationFn '${String(ref)}' for column '${column.id}' is not registered`,\n )\n }\n return aggregationFn\n}\n\n/** Resolves and validates a column's scalar or multiple aggregation option. */\nexport function column_getAggregationFns<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(\n column: Column_Internal<TFeatures, TData, TValue>,\n): ReadonlyArray<ResolvedAggregationFn<TFeatures, TData>> {\n const option = column.columnDef.aggregationFn\n const registry = column.table._rowModelFns.aggregationFns\n const coreRowModel = column.table.getCoreRowModel()\n const previous = (column as any)._resolvedAggregationFnsCache as\n | ResolvedAggregationFnsCacheEntry<TFeatures, TData>\n | undefined\n\n if (\n previous &&\n previous.option === option &&\n previous.registry === registry &&\n previous.coreRowModel === coreRowModel\n ) {\n return previous.value\n }\n\n const finish = (\n value: ReadonlyArray<ResolvedAggregationFn<TFeatures, TData>>,\n ) => {\n ;(column as any)._resolvedAggregationFnsCache = {\n coreRowModel,\n option,\n registry,\n value,\n } satisfies ResolvedAggregationFnsCacheEntry<TFeatures, TData>\n return value\n }\n\n if (option == null) return finish([])\n\n if (!Array.isArray(option)) {\n return finish([\n {\n aggregationFn: resolveAggregationFn(column, option as any),\n id: typeof option === 'string' ? option : undefined,\n },\n ])\n }\n\n const ids = makeObjectMap<number>()\n for (let i = 0; i < option.length; i++) {\n const item = option[i]\n const id =\n typeof item === 'string'\n ? item\n : isAggregationFnDescriptor(item)\n ? item.id\n : undefined\n if (id !== undefined) ids[id] = (ids[id] ?? 0) + 1\n }\n\n const resolved: Array<ResolvedAggregationFn<TFeatures, TData>> = []\n\n for (let i = 0; i < option.length; i++) {\n const item = option[i]\n const id =\n typeof item === 'string'\n ? item\n : isAggregationFnDescriptor(item)\n ? item.id\n : undefined\n\n if (id === undefined) {\n warn(\n `aggregationFn at index ${i} for column '${column.id}' needs a stable id`,\n )\n resolved.push({ aggregationFn: undefined, id: undefined })\n continue\n }\n\n if (ids[id]! > 1) {\n warn(`aggregationFn id '${id}' for column '${column.id}' is duplicated`)\n resolved.push({ aggregationFn: undefined, id })\n continue\n }\n\n const ref = isAggregationFnDescriptor(item) ? item.aggregationFn : item\n resolved.push({\n aggregationFn: resolveAggregationFn(column, ref),\n id,\n })\n }\n\n return finish(resolved)\n}\n\nfunction getChildResult(\n childValue: unknown,\n isMultiple: boolean,\n id: string | undefined,\n) {\n if (!isMultiple) return childValue\n if (!id || !childValue || typeof childValue !== 'object') return undefined\n return hasOwn(childValue, id)\n ? (childValue as Record<string, unknown>)[id]\n : undefined\n}\n\n/** Executes every configured aggregation for a column over normalized rows. */\nexport function aggregateColumnValue<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(args: {\n childRows?: ReadonlyArray<Row<TFeatures, TData>>\n column: Column<TFeatures, TData, unknown>\n groupingRow?: Row<TFeatures, TData>\n rows: ReadonlyArray<Row<TFeatures, TData>>\n}): unknown {\n const { childRows, column, groupingRow, rows } = args\n const internalColumn = column as Column_Internal<TFeatures, TData, unknown>\n const entries = column_getAggregationFns(internalColumn)\n const isMultiple = Array.isArray(internalColumn.columnDef.aggregationFn)\n const canMerge =\n !!childRows?.length &&\n childRows.every(\n (row) =>\n !!(row as any).groupingColumnId &&\n (row as any).groupingColumnId !== column.id,\n )\n\n const execute = (entry: ResolvedAggregationFn<TFeatures, TData>) => {\n const definition = entry.aggregationFn\n if (!definition) return undefined\n\n const context = {\n column,\n columnId: column.id,\n getValue: (row: Row<TFeatures, TData>) => row.getValue(column.id),\n ...(groupingRow ? { groupingRow } : {}),\n rows,\n table: column.table as any,\n }\n\n if (canMerge && definition.merge) {\n return definition.merge({\n ...context,\n childResults: childRows.map((row) =>\n getChildResult(row.getValue(column.id), isMultiple, entry.id),\n ),\n childRows: childRows,\n })\n }\n\n return definition.aggregate(context)\n }\n\n if (!isMultiple) {\n return entries[0] ? execute(entries[0]) : undefined\n }\n\n const result = makeObjectMap<unknown>()\n for (let i = 0; i < entries.length; i++) {\n const entry = entries[i]!\n if (entry.id !== undefined) {\n result[entry.id] = execute(entry)\n }\n }\n return result\n}\n\n/** Implements `column.getAggregationValue(rows?)` and its default-value cache. */\nexport function column_getAggregationValue<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(\n column: Column_Internal<TFeatures, TData, TValue>,\n rows?: ReadonlyArray<Row<TFeatures, TData>>,\n): ColumnAggregationValue<TFeatures> {\n const providedResult = column.columnDef.getAggregationValue?.({\n column: column as any,\n rows,\n table: column.table as any,\n })\n\n if (providedResult) return providedResult.value as any\n if (column.table.options.manualAggregation) return undefined\n\n if (rows !== undefined) {\n return aggregateColumnValue({\n column: column as any,\n rows: normalizeAggregationRows(rows),\n }) as any\n }\n\n const model = column.table.getPreGroupedRowModel()\n const previous = (column as any)._aggregationValueCache as\n | AggregationCacheEntry\n | undefined\n const registry = column.table._rowModelFns.aggregationFns\n const aggregationFnOption = column.columnDef.aggregationFn\n\n if (\n previous &&\n previous.dependency === model &&\n previous.registry === registry &&\n previous.aggregationFnOption === aggregationFnOption\n ) {\n return previous.value as any\n }\n\n const value = aggregateColumnValue({\n column: column as any,\n rows: normalizeAggregationRows(model.rows),\n })\n ;(column as any)._aggregationValueCache = {\n aggregationFnOption,\n dependency: model,\n registry,\n value,\n } satisfies AggregationCacheEntry\n return value as any\n}\n\n/** Implements `cell.getIsAggregated()` for synthetic grouped rows. */\nexport function cell_getIsAggregated<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(cell: Cell<TFeatures, TData, TValue>) {\n const groupingColumnId = (cell.row as any).groupingColumnId as\n | string\n | undefined\n if (!groupingColumnId || groupingColumnId === cell.column.id) return false\n\n const grouping = (cell.column.table as any).atoms.grouping?.get?.() as\n | Array<string>\n | undefined\n if (grouping?.includes(cell.column.id)) return false\n\n return column_getAggregationFns(cell.column as any).some(\n (entry) => !!entry.aggregationFn,\n )\n}\n\n/** Formats the default scalar or keyed aggregated-cell representation. */\nexport function formatAggregatedCellValue(\n value: unknown,\n option: unknown,\n): string | null {\n if (value == null) return null\n\n if (Array.isArray(option) && typeof value === 'object') {\n const entries = Object.keys(value)\n return entries\n .map(\n (key) => `${key}: ${String((value as Record<string, unknown>)[key])}`,\n )\n .join(', ')\n }\n\n return String(value)\n}\n"],"mappings":";;;AA+BA,SAAS,mBAAmB,OAA2C;CACrE,OAAO,CAAC,CAAC,SAAS,OAAO,UAAU,YAAY,eAAe;AAChE;AAEA,SAAS,0BACP,OAC4C;CAC5C,OACE,C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M,KAAK,OAAO,UAAU,UAE5C,OADgB,OAAO,KAAK,KACf,CAAC,CACX,KACE,QAAQ,GAAG,IAAI,IAAI,OAAQ,MAAkC,IAAI,GACpE,CAAC,CACA,KAAK,IAAI;CAGd,OAAO,OAAO,KAAK;AACrB"}
1
+ {"version":3,"file":"aggregationFeature.utils.cjs","names":["makeObjectMap","hasOwn"],"sources":["../../../src/features/aggregation/aggregationFeature.utils.ts"],"sourcesContent":["import { hasOwn, makeObjectMap } from '../../utils'\nimport type { Cell } from '../../types/Cell'\nimport type { Column, Column_Internal } from '../../types/Column'\nimport type { Row } from '../../types/Row'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { CellData, RowData } from '../../types/type-utils'\nimport type {\n AggregationContext,\n AggregationFnDef,\n AggregationFnDescriptor,\n AggregationFnRef,\n AggregationValueOptions,\n ColumnAggregationValue,\n ResolvedAggregationFn,\n} from './aggregationFeature.types'\n\ninterface AggregationCacheEntry {\n aggregationFnOption: unknown\n dependency: unknown\n maxDepth: number\n registry: unknown\n value: unknown\n}\n\ninterface ResolvedAggregationFnsCacheEntry<\n TFeatures extends TableFeatures,\n TData extends RowData,\n> {\n coreRowModel: unknown\n option: unknown\n registry: unknown\n value: ReadonlyArray<ResolvedAggregationFn<TFeatures, TData>>\n}\n\nfunction isAggregationFnDef(value: unknown): value is AggregationFnDef {\n return !!value && typeof value === 'object' && 'aggregate' in value\n}\n\nfunction isAggregationFnDescriptor(\n value: unknown,\n): value is AggregationFnDescriptor<any, any> {\n return (\n !!value &&\n typeof value === 'object' &&\n 'id' in value &&\n 'aggregationFn' in value\n )\n}\n\nfunction warn(message: string) {\n if (process.env.NODE_ENV === 'development') {\n console.warn(message)\n }\n}\n\nfunction resolveMaxAggregationDepth(maxDepth: number | undefined) {\n return maxDepth === undefined || Number.isNaN(maxDepth)\n ? 0\n : Math.max(0, Math.floor(maxDepth))\n}\n\n/**\n * Selects unique rows at a maximum relative depth in encounter order.\n * Branches that end before the requested depth contribute their deepest row.\n */\nexport function normalizeAggregationRows<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n rows: ReadonlyArray<Row<TFeatures, TData>>,\n maxDepth = 0,\n): Array<Row<TFeatures, TData>> {\n const result: Array<Row<TFeatures, TData>> = []\n const seen = new Set<string>()\n const normalizedMaxDepth = resolveMaxAggregationDepth(maxDepth)\n\n const visit = (row: Row<TFeatures, TData>, depth: number) => {\n if (row.subRows.length && depth < normalizedMaxDepth) {\n for (let i = 0; i < row.subRows.length; i++) {\n visit(row.subRows[i]!, depth + 1)\n }\n return\n }\n\n if (!seen.has(row.id)) {\n seen.add(row.id)\n result.push(row)\n }\n }\n\n for (let i = 0; i < rows.length; i++) {\n visit(rows[i]!, 0)\n }\n\n return result\n}\n\nfunction getAutoAggregationFnName(\n value: unknown,\n): 'extent' | 'sum' | undefined {\n if (typeof value === 'number') {\n return 'sum'\n }\n\n if (value instanceof Date && !Number.isNaN(value.getTime())) {\n return 'extent'\n }\n\n return undefined\n}\n\n/** Resolves the `sum` or `extent` definition inferred from the first core row. */\nexport function column_getAutoAggregationFn<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n const value = column.table.getCoreRowModel().flatRows[0]?.getValue(column.id)\n\n const name = getAutoAggregationFnName(value)\n if (!name) return undefined\n\n const aggregationFn = column.table._rowModelFns.aggregationFns?.[name]\n\n if (!aggregationFn) {\n warn(\n `aggregationFn '${name}' (auto) for column '${column.id}' is not registered`,\n )\n }\n\n return aggregationFn\n}\n\nfunction resolveAggregationFn<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n column: Column_Internal<TFeatures, TData, any>,\n ref: AggregationFnRef<TFeatures, TData, any, any>,\n): AggregationFnDef<TFeatures, TData, any, any> | undefined {\n if (isAggregationFnDef(ref)) return ref as any\n if (ref === 'auto') return column_getAutoAggregationFn(column)\n\n const aggregationFn =\n column.table._rowModelFns.aggregationFns?.[ref as string]\n if (!aggregationFn) {\n warn(\n `aggregationFn '${String(ref)}' for column '${column.id}' is not registered`,\n )\n }\n return aggregationFn\n}\n\n/** Resolves and validates a column's scalar or multiple aggregation option. */\nexport function column_getAggregationFns<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(\n column: Column_Internal<TFeatures, TData, TValue>,\n): ReadonlyArray<ResolvedAggregationFn<TFeatures, TData>> {\n const option = column.columnDef.aggregationFn\n const registry = column.table._rowModelFns.aggregationFns\n const coreRowModel = column.table.getCoreRowModel()\n const previous = (column as any)._resolvedAggregationFnsCache as\n | ResolvedAggregationFnsCacheEntry<TFeatures, TData>\n | undefined\n\n if (\n previous &&\n previous.option === option &&\n previous.registry === registry &&\n previous.coreRowModel === coreRowModel\n ) {\n return previous.value\n }\n\n const finish = (\n value: ReadonlyArray<ResolvedAggregationFn<TFeatures, TData>>,\n ) => {\n ;(column as any)._resolvedAggregationFnsCache = {\n coreRowModel,\n option,\n registry,\n value,\n } satisfies ResolvedAggregationFnsCacheEntry<TFeatures, TData>\n return value\n }\n\n if (option == null) return finish([])\n\n if (!Array.isArray(option)) {\n return finish([\n {\n aggregationFn: resolveAggregationFn(column, option as any),\n id: typeof option === 'string' ? option : undefined,\n },\n ])\n }\n\n const ids = makeObjectMap<number>()\n for (let i = 0; i < option.length; i++) {\n const item = option[i]\n const id =\n typeof item === 'string'\n ? item\n : isAggregationFnDescriptor(item)\n ? item.id\n : undefined\n if (id !== undefined) ids[id] = (ids[id] ?? 0) + 1\n }\n\n const resolved: Array<ResolvedAggregationFn<TFeatures, TData>> = []\n\n for (let i = 0; i < option.length; i++) {\n const item = option[i]\n const id =\n typeof item === 'string'\n ? item\n : isAggregationFnDescriptor(item)\n ? item.id\n : undefined\n\n if (id === undefined) {\n warn(\n `aggregationFn at index ${i} for column '${column.id}' needs a stable id`,\n )\n resolved.push({ aggregationFn: undefined, id: undefined })\n continue\n }\n\n if (ids[id]! > 1) {\n warn(`aggregationFn id '${id}' for column '${column.id}' is duplicated`)\n resolved.push({ aggregationFn: undefined, id })\n continue\n }\n\n const ref = isAggregationFnDescriptor(item) ? item.aggregationFn : item\n resolved.push({\n aggregationFn: resolveAggregationFn(column, ref),\n id,\n })\n }\n\n return finish(resolved)\n}\n\nfunction getSubRowResult(\n subRowValue: unknown,\n isMultiple: boolean,\n id: string | undefined,\n) {\n if (!isMultiple) return subRowValue\n if (!id || !subRowValue || typeof subRowValue !== 'object') return undefined\n return hasOwn(subRowValue, id)\n ? (subRowValue as Record<string, unknown>)[id]\n : undefined\n}\n\n/** Executes every configured aggregation over a depth-selected row frontier. */\nexport function aggregateColumnValue<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(args: {\n maxDepth?: number\n subRows?: ReadonlyArray<Row<TFeatures, TData>>\n column: Column<TFeatures, TData, unknown>\n groupingRow?: Row<TFeatures, TData>\n rows: ReadonlyArray<Row<TFeatures, TData>>\n}): unknown {\n const { subRows, column, groupingRow, rows } = args\n const internalColumn = column as Column_Internal<TFeatures, TData, unknown>\n const maxDepth = resolveMaxAggregationDepth(\n args.maxDepth ?? internalColumn.columnDef.maxAggregationDepth,\n )\n const aggregationRows = normalizeAggregationRows(rows, maxDepth)\n const entries = column_getAggregationFns(internalColumn)\n const isMultiple = Array.isArray(internalColumn.columnDef.aggregationFn)\n const canMerge =\n !!subRows?.length &&\n subRows.every(\n (row) =>\n !!(row as any).groupingColumnId &&\n (row as any).groupingColumnId !== column.id,\n )\n\n const execute = (entry: ResolvedAggregationFn<TFeatures, TData>) => {\n const definition = entry.aggregationFn\n if (!definition) return undefined\n\n const context: AggregationContext<TFeatures, TData, unknown> = {\n ...(subRows ? { subRows } : {}),\n column,\n columnId: column.id,\n getValue: (row: Row<TFeatures, TData>) => row.getValue(column.id),\n ...(groupingRow ? { groupingRow } : {}),\n maxDepth,\n rows: aggregationRows,\n table: column.table as any,\n }\n\n if (canMerge && definition.merge) {\n return definition.merge({\n ...context,\n subRowResults: subRows.map((row) =>\n getSubRowResult(row.getValue(column.id), isMultiple, entry.id),\n ),\n subRows,\n })\n }\n\n return definition.aggregate(context)\n }\n\n if (!isMultiple) {\n return entries[0] ? execute(entries[0]) : undefined\n }\n\n const result = makeObjectMap<unknown>()\n for (let i = 0; i < entries.length; i++) {\n const entry = entries[i]!\n if (entry.id !== undefined) {\n result[entry.id] = execute(entry)\n }\n }\n return result\n}\n\n/** Implements `column.getAggregationValue(options?)` and its default cache. */\nexport function column_getAggregationValue<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(\n column: Column_Internal<TFeatures, TData, TValue>,\n options?: AggregationValueOptions<TFeatures, TData>,\n): ColumnAggregationValue<TFeatures> {\n const rows = options?.rows\n const resolvedMaxDepth = resolveMaxAggregationDepth(\n options?.maxDepth ?? column.columnDef.maxAggregationDepth,\n )\n const providedResult = column.columnDef.getAggregationValue?.({\n column: column as any,\n maxDepth: resolvedMaxDepth,\n rows,\n table: column.table as any,\n })\n\n if (providedResult) return providedResult.value as any\n if (column.table.options.manualAggregation) return undefined\n\n if (rows !== undefined) {\n return aggregateColumnValue({\n column: column as any,\n maxDepth: resolvedMaxDepth,\n rows,\n }) as any\n }\n\n const model = column.table.getPreGroupedRowModel()\n const previous = (column as any)._aggregationValueCache as\n | AggregationCacheEntry\n | undefined\n const registry = column.table._rowModelFns.aggregationFns\n const aggregationFnOption = column.columnDef.aggregationFn\n\n if (\n previous &&\n previous.dependency === model &&\n previous.maxDepth === resolvedMaxDepth &&\n previous.registry === registry &&\n previous.aggregationFnOption === aggregationFnOption\n ) {\n return previous.value as any\n }\n\n const value = aggregateColumnValue({\n column: column as any,\n maxDepth: resolvedMaxDepth,\n rows: model.rows,\n })\n ;(column as any)._aggregationValueCache = {\n aggregationFnOption,\n dependency: model,\n maxDepth: resolvedMaxDepth,\n registry,\n value,\n } satisfies AggregationCacheEntry\n return value as any\n}\n\n/** Implements `cell.getIsAggregated()` for synthetic grouped rows. */\nexport function cell_getIsAggregated<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(cell: Cell<TFeatures, TData, TValue>) {\n const groupingColumnId = (cell.row as any).groupingColumnId as\n | string\n | undefined\n if (!groupingColumnId || groupingColumnId === cell.column.id) return false\n\n const grouping = (cell.column.table as any).atoms.grouping?.get?.() as\n | Array<string>\n | undefined\n if (grouping?.includes(cell.column.id)) return false\n\n return column_getAggregationFns(cell.column as any).some(\n (entry) => !!entry.aggregationFn,\n )\n}\n\n/** Formats the default scalar or keyed aggregated-cell representation. */\nexport function formatAggregatedCellValue(\n value: unknown,\n option: unknown,\n): string | null {\n if (value == null) return null\n\n if (Array.isArray(option) && typeof value === 'object') {\n const entries = Object.keys(value)\n return entries\n .map(\n (key) => `${key}: ${String((value as Record<string, unknown>)[key])}`,\n )\n .join(', ')\n }\n\n return String(value)\n}\n"],"mappings":";;;AAkCA,SAAS,mBAAmB,OAA2C;CACrE,OAAO,CAAC,CAAC,SAAS,OAAO,UAAU,YAAY,eAAe;AAChE;AAEA,SAAS,0BACP,OAC4C;CAC5C,OACE,CAAC,CAAC,SACF,OAAO,UAAU,YACjB,QAAQ,SACR,mBAAmB;AAEvB;AAEA,SAAS,KAAK,SAAiB;CAC7B,IAAI,QAAQ,IAAI,aAAa,eAC3B,QAAQ,KAAK,OAAO;AAExB;AAEA,SAAS,2BAA2B,UAA8B;CAChE,OAAO,aAAa,UAAa,OAAO,MAAM,QAAQ,IAClD,IACA,KAAK,IAAI,GAAG,KAAK,MAAM,QAAQ,CAAC;AACtC;;;;;AAMA,SAAgB,yBAId,MACA,WAAW,GACmB;CAC9B,MAAM,SAAuC,CAAC;CAC9C,MAAM,uBAAO,IAAI,IAAY;CAC7B,MAAM,qBAAqB,2BAA2B,QAAQ;CAE9D,MAAM,SAAS,KAA4B,UAAkB;EAC3D,IAAI,IAAI,QAAQ,UAAU,QAAQ,oBAAoB;GACpD,KAAK,IAAI,IAAI,GAAG,IAAI,IAAI,QAAQ,QAAQ,KACtC,MAA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,IAAI,IAAI,OAAQ,MAAkC,IAAI,GACpE,CAAC,CACA,KAAK,IAAI;CAGd,OAAO,OAAO,KAAK;AACrB"}
@@ -1,5 +1,5 @@
1
1
  import { CellData, RowData } from "../../types/type-utils.cjs";
2
- import { AggregationFnDef, ColumnAggregationValue, ResolvedAggregationFn } from "./aggregationFeature.types.cjs";
2
+ import { AggregationFnDef, AggregationValueOptions, ColumnAggregationValue, ResolvedAggregationFn } from "./aggregationFeature.types.cjs";
3
3
  import { Cell } from "../../types/Cell.cjs";
4
4
  import { Row } from "../../types/Row.cjs";
5
5
  import { Column } from "../../types/Column.cjs";
@@ -7,23 +7,24 @@ import { TableFeatures } from "../../types/TableFeatures.cjs";
7
7
 
8
8
  //#region src/features/aggregation/aggregationFeature.utils.d.ts
9
9
  /**
10
- * Flattens hierarchical row inputs to unique terminal leaves in encounter
11
- * order. This is the normalization used by public aggregation-value calls.
10
+ * Selects unique rows at a maximum relative depth in encounter order.
11
+ * Branches that end before the requested depth contribute their deepest row.
12
12
  */
13
- declare function normalizeAggregationRows<TFeatures extends TableFeatures, TData extends RowData>(rows: ReadonlyArray<Row<TFeatures, TData>>): Array<Row<TFeatures, TData>>;
13
+ declare function normalizeAggregationRows<TFeatures extends TableFeatures, TData extends RowData>(rows: ReadonlyArray<Row<TFeatures, TData>>, maxDepth?: number): Array<Row<TFeatures, TData>>;
14
14
  /** Resolves the `sum` or `extent` definition inferred from the first core row. */
15
15
  declare function column_getAutoAggregationFn<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column: Column<TFeatures, TData, TValue>): AggregationFnDef<TFeatures, TData, any, any> | undefined;
16
16
  /** Resolves and validates a column's scalar or multiple aggregation option. */
17
17
  declare function column_getAggregationFns<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column: Column<TFeatures, TData, TValue>): ReadonlyArray<ResolvedAggregationFn<TFeatures, TData>>;
18
- /** Executes every configured aggregation for a column over normalized rows. */
18
+ /** Executes every configured aggregation over a depth-selected row frontier. */
19
19
  declare function aggregateColumnValue<TFeatures extends TableFeatures, TData extends RowData>(args: {
20
- childRows?: ReadonlyArray<Row<TFeatures, TData>>;
20
+ maxDepth?: number;
21
+ subRows?: ReadonlyArray<Row<TFeatures, TData>>;
21
22
  column: Column<TFeatures, TData, unknown>;
22
23
  groupingRow?: Row<TFeatures, TData>;
23
24
  rows: ReadonlyArray<Row<TFeatures, TData>>;
24
25
  }): unknown;
25
- /** Implements `column.getAggregationValue(rows?)` and its default-value cache. */
26
- declare function column_getAggregationValue<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column: Column<TFeatures, TData, TValue>, rows?: ReadonlyArray<Row<TFeatures, TData>>): ColumnAggregationValue<TFeatures>;
26
+ /** Implements `column.getAggregationValue(options?)` and its default cache. */
27
+ declare function column_getAggregationValue<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column: Column<TFeatures, TData, TValue>, options?: AggregationValueOptions<TFeatures, TData>): ColumnAggregationValue<TFeatures>;
27
28
  /** Implements `cell.getIsAggregated()` for synthetic grouped rows. */
28
29
  declare function cell_getIsAggregated<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(cell: Cell<TFeatures, TData, TValue>): boolean;
29
30
  /** Formats the default scalar or keyed aggregated-cell representation. */
@@ -1,5 +1,5 @@
1
1
  import { CellData, RowData } from "../../types/type-utils.js";
2
- import { AggregationFnDef, ColumnAggregationValue, ResolvedAggregationFn } from "./aggregationFeature.types.js";
2
+ import { AggregationFnDef, AggregationValueOptions, ColumnAggregationValue, ResolvedAggregationFn } from "./aggregationFeature.types.js";
3
3
  import { Cell } from "../../types/Cell.js";
4
4
  import { Row } from "../../types/Row.js";
5
5
  import { Column } from "../../types/Column.js";
@@ -7,23 +7,24 @@ import { TableFeatures } from "../../types/TableFeatures.js";
7
7
 
8
8
  //#region src/features/aggregation/aggregationFeature.utils.d.ts
9
9
  /**
10
- * Flattens hierarchical row inputs to unique terminal leaves in encounter
11
- * order. This is the normalization used by public aggregation-value calls.
10
+ * Selects unique rows at a maximum relative depth in encounter order.
11
+ * Branches that end before the requested depth contribute their deepest row.
12
12
  */
13
- declare function normalizeAggregationRows<TFeatures extends TableFeatures, TData extends RowData>(rows: ReadonlyArray<Row<TFeatures, TData>>): Array<Row<TFeatures, TData>>;
13
+ declare function normalizeAggregationRows<TFeatures extends TableFeatures, TData extends RowData>(rows: ReadonlyArray<Row<TFeatures, TData>>, maxDepth?: number): Array<Row<TFeatures, TData>>;
14
14
  /** Resolves the `sum` or `extent` definition inferred from the first core row. */
15
15
  declare function column_getAutoAggregationFn<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column: Column<TFeatures, TData, TValue>): AggregationFnDef<TFeatures, TData, any, any> | undefined;
16
16
  /** Resolves and validates a column's scalar or multiple aggregation option. */
17
17
  declare function column_getAggregationFns<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column: Column<TFeatures, TData, TValue>): ReadonlyArray<ResolvedAggregationFn<TFeatures, TData>>;
18
- /** Executes every configured aggregation for a column over normalized rows. */
18
+ /** Executes every configured aggregation over a depth-selected row frontier. */
19
19
  declare function aggregateColumnValue<TFeatures extends TableFeatures, TData extends RowData>(args: {
20
- childRows?: ReadonlyArray<Row<TFeatures, TData>>;
20
+ maxDepth?: number;
21
+ subRows?: ReadonlyArray<Row<TFeatures, TData>>;
21
22
  column: Column<TFeatures, TData, unknown>;
22
23
  groupingRow?: Row<TFeatures, TData>;
23
24
  rows: ReadonlyArray<Row<TFeatures, TData>>;
24
25
  }): unknown;
25
- /** Implements `column.getAggregationValue(rows?)` and its default-value cache. */
26
- declare function column_getAggregationValue<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column: Column<TFeatures, TData, TValue>, rows?: ReadonlyArray<Row<TFeatures, TData>>): ColumnAggregationValue<TFeatures>;
26
+ /** Implements `column.getAggregationValue(options?)` and its default cache. */
27
+ declare function column_getAggregationValue<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column: Column<TFeatures, TData, TValue>, options?: AggregationValueOptions<TFeatures, TData>): ColumnAggregationValue<TFeatures>;
27
28
  /** Implements `cell.getIsAggregated()` for synthetic grouped rows. */
28
29
  declare function cell_getIsAggregated<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(cell: Cell<TFeatures, TData, TValue>): boolean;
29
30
  /** Formats the default scalar or keyed aggregated-cell representation. */
@@ -10,16 +10,20 @@ function isAggregationFnDescriptor(value) {
10
10
  function warn(message) {
11
11
  if (process.env.NODE_ENV === "development") console.warn(message);
12
12
  }
13
+ function resolveMaxAggregationDepth(maxDepth) {
14
+ return maxDepth === void 0 || Number.isNaN(maxDepth) ? 0 : Math.max(0, Math.floor(maxDepth));
15
+ }
13
16
  /**
14
- * Flattens hierarchical row inputs to unique terminal leaves in encounter
15
- * order. This is the normalization used by public aggregation-value calls.
17
+ * Selects unique rows at a maximum relative depth in encounter order.
18
+ * Branches that end before the requested depth contribute their deepest row.
16
19
  */
17
- function normalizeAggregationRows(rows) {
20
+ function normalizeAggregationRows(rows, maxDepth = 0) {
18
21
  const result = [];
19
22
  const seen = /* @__PURE__ */ new Set();
20
- const visit = (row) => {
21
- if (row.subRows.length) {
22
- for (let i = 0; i < row.subRows.length; i++) visit(row.subRows[i]);
23
+ const normalizedMaxDepth = resolveMaxAggregationDepth(maxDepth);
24
+ const visit = (row, depth) => {
25
+ if (row.subRows.length && depth < normalizedMaxDepth) {
26
+ for (let i = 0; i < row.subRows.length; i++) visit(row.subRows[i], depth + 1);
23
27
  return;
24
28
  }
25
29
  if (!seen.has(row.id)) {
@@ -27,7 +31,7 @@ function normalizeAggregationRows(rows) {
27
31
  result.push(row);
28
32
  }
29
33
  };
30
- for (let i = 0; i < rows.length; i++) visit(rows[i]);
34
+ for (let i = 0; i < rows.length; i++) visit(rows[i], 0);
31
35
  return result;
32
36
  }
33
37
  function getAutoAggregationFnName(value) {
@@ -105,33 +109,37 @@ function column_getAggregationFns(column) {
105
109
  }
106
110
  return finish(resolved);
107
111
  }
108
- function getChildResult(childValue, isMultiple, id) {
109
- if (!isMultiple) return childValue;
110
- if (!id || !childValue || typeof childValue !== "object") return void 0;
111
- return hasOwn(childValue, id) ? childValue[id] : void 0;
112
+ function getSubRowResult(subRowValue, isMultiple, id) {
113
+ if (!isMultiple) return subRowValue;
114
+ if (!id || !subRowValue || typeof subRowValue !== "object") return void 0;
115
+ return hasOwn(subRowValue, id) ? subRowValue[id] : void 0;
112
116
  }
113
- /** Executes every configured aggregation for a column over normalized rows. */
117
+ /** Executes every configured aggregation over a depth-selected row frontier. */
114
118
  function aggregateColumnValue(args) {
115
- const { childRows, column, groupingRow, rows } = args;
119
+ const { subRows, column, groupingRow, rows } = args;
116
120
  const internalColumn = column;
121
+ const maxDepth = resolveMaxAggregationDepth(args.maxDepth ?? internalColumn.columnDef.maxAggregationDepth);
122
+ const aggregationRows = normalizeAggregationRows(rows, maxDepth);
117
123
  const entries = column_getAggregationFns(internalColumn);
118
124
  const isMultiple = Array.isArray(internalColumn.columnDef.aggregationFn);
119
- const canMerge = !!childRows?.length && childRows.every((row) => !!row.groupingColumnId && row.groupingColumnId !== column.id);
125
+ const canMerge = !!subRows?.length && subRows.every((row) => !!row.groupingColumnId && row.groupingColumnId !== column.id);
120
126
  const execute = (entry) => {
121
127
  const definition = entry.aggregationFn;
122
128
  if (!definition) return void 0;
123
129
  const context = {
130
+ ...subRows ? { subRows } : {},
124
131
  column,
125
132
  columnId: column.id,
126
133
  getValue: (row) => row.getValue(column.id),
127
134
  ...groupingRow ? { groupingRow } : {},
128
- rows,
135
+ maxDepth,
136
+ rows: aggregationRows,
129
137
  table: column.table
130
138
  };
131
139
  if (canMerge && definition.merge) return definition.merge({
132
140
  ...context,
133
- childResults: childRows.map((row) => getChildResult(row.getValue(column.id), isMultiple, entry.id)),
134
- childRows
141
+ subRowResults: subRows.map((row) => getSubRowResult(row.getValue(column.id), isMultiple, entry.id)),
142
+ subRows
135
143
  });
136
144
  return definition.aggregate(context);
137
145
  };
@@ -143,10 +151,13 @@ function aggregateColumnValue(args) {
143
151
  }
144
152
  return result;
145
153
  }
146
- /** Implements `column.getAggregationValue(rows?)` and its default-value cache. */
147
- function column_getAggregationValue(column, rows) {
154
+ /** Implements `column.getAggregationValue(options?)` and its default cache. */
155
+ function column_getAggregationValue(column, options) {
156
+ const rows = options?.rows;
157
+ const resolvedMaxDepth = resolveMaxAggregationDepth(options?.maxDepth ?? column.columnDef.maxAggregationDepth);
148
158
  const providedResult = column.columnDef.getAggregationValue?.({
149
159
  column,
160
+ maxDepth: resolvedMaxDepth,
150
161
  rows,
151
162
  table: column.table
152
163
  });
@@ -154,20 +165,23 @@ function column_getAggregationValue(column, rows) {
154
165
  if (column.table.options.manualAggregation) return void 0;
155
166
  if (rows !== void 0) return aggregateColumnValue({
156
167
  column,
157
- rows: normalizeAggregationRows(rows)
168
+ maxDepth: resolvedMaxDepth,
169
+ rows
158
170
  });
159
171
  const model = column.table.getPreGroupedRowModel();
160
172
  const previous = column._aggregationValueCache;
161
173
  const registry = column.table._rowModelFns.aggregationFns;
162
174
  const aggregationFnOption = column.columnDef.aggregationFn;
163
- if (previous && previous.dependency === model && previous.registry === registry && previous.aggregationFnOption === aggregationFnOption) return previous.value;
175
+ if (previous && previous.dependency === model && previous.maxDepth === resolvedMaxDepth && previous.registry === registry && previous.aggregationFnOption === aggregationFnOption) return previous.value;
164
176
  const value = aggregateColumnValue({
165
177
  column,
166
- rows: normalizeAggregationRows(model.rows)
178
+ maxDepth: resolvedMaxDepth,
179
+ rows: model.rows
167
180
  });
168
181
  column._aggregationValueCache = {
169
182
  aggregationFnOption,
170
183
  dependency: model,
184
+ maxDepth: resolvedMaxDepth,
171
185
  registry,
172
186
  value
173
187
  };