@pretable/core 0.20.2 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- //#region \0@oxc-project+runtime@0.143.0/helpers/esm/typeof.js
1
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/typeof.js
2
2
  function _typeof(o) {
3
3
  "@babel/helpers - typeof";
4
4
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -8,28 +8,25 @@ function _typeof(o) {
8
8
  }, _typeof(o);
9
9
  }
10
10
 
11
- //#endregion
12
- //#region \0@oxc-project+runtime@0.143.0/helpers/esm/toPrimitive.js
13
- function toPrimitive(t, r) {
11
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/toPrimitive.js
12
+ function toPrimitive(t, e) {
14
13
  if ("object" != _typeof(t) || !t) return t;
15
- var e = t[Symbol.toPrimitive];
16
- if (void 0 !== e) {
17
- var i = e.call(t, r || "default");
14
+ var r;
15
+ if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) {
16
+ var i = r.call(t, e || "default");
18
17
  if ("object" != _typeof(i)) return i;
19
18
  throw new TypeError("@@toPrimitive must return a primitive value.");
20
19
  }
21
- return ("string" === r ? String : Number)(t);
20
+ return ("string" === e ? String : Number)(t);
22
21
  }
23
22
 
24
- //#endregion
25
- //#region \0@oxc-project+runtime@0.143.0/helpers/esm/toPropertyKey.js
23
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/toPropertyKey.js
26
24
  function toPropertyKey(t) {
27
25
  var i = toPrimitive(t, "string");
28
26
  return "symbol" == _typeof(i) ? i : i + "";
29
27
  }
30
28
 
31
- //#endregion
32
- //#region \0@oxc-project+runtime@0.143.0/helpers/esm/defineProperty.js
29
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/defineProperty.js
33
30
  function _defineProperty(e, r, t) {
34
31
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
35
32
  value: t,
@@ -39,45 +36,38 @@ function _defineProperty(e, r, t) {
39
36
  }) : e[r] = t, e;
40
37
  }
41
38
 
42
- //#endregion
43
- //#region \0@oxc-project+runtime@0.143.0/helpers/esm/checkPrivateRedeclaration.js
39
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/checkPrivateRedeclaration.js
44
40
  function _checkPrivateRedeclaration(e, t) {
45
41
  if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object");
46
42
  }
47
43
 
48
- //#endregion
49
- //#region \0@oxc-project+runtime@0.143.0/helpers/esm/classPrivateMethodInitSpec.js
44
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/classPrivateMethodInitSpec.js
50
45
  function _classPrivateMethodInitSpec(e, a) {
51
46
  _checkPrivateRedeclaration(e, a), a.add(e);
52
47
  }
53
48
 
54
- //#endregion
55
- //#region \0@oxc-project+runtime@0.143.0/helpers/esm/classPrivateFieldInitSpec.js
49
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/classPrivateFieldInitSpec.js
56
50
  function _classPrivateFieldInitSpec(e, t, a) {
57
51
  _checkPrivateRedeclaration(e, t), t.set(e, a);
58
52
  }
59
53
 
60
- //#endregion
61
- //#region \0@oxc-project+runtime@0.143.0/helpers/esm/assertClassBrand.js
54
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/assertClassBrand.js
62
55
  function _assertClassBrand(e, t, n) {
63
56
  if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n;
64
57
  throw new TypeError("Private element is not present on this object");
65
58
  }
66
59
 
67
- //#endregion
68
- //#region \0@oxc-project+runtime@0.143.0/helpers/esm/classPrivateFieldSet2.js
60
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/classPrivateFieldSet2.js
69
61
  function _classPrivateFieldSet2(s, a, r) {
70
62
  return s.set(_assertClassBrand(s, a), r), r;
71
63
  }
72
64
 
73
- //#endregion
74
- //#region \0@oxc-project+runtime@0.143.0/helpers/esm/classPrivateFieldGet2.js
65
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/classPrivateFieldGet2.js
75
66
  function _classPrivateFieldGet2(s, a) {
76
67
  return s.get(_assertClassBrand(s, a));
77
68
  }
78
69
 
79
- //#endregion
80
- //#region ../layout-core/dist/dense-membership.js
70
+ // ../layout-core/dist/dense-membership.js
81
71
  /**
82
72
  * Membership bitset: one bit per dense key (row-model SLOT). Duplicated from
83
73
  * `@pretable-internal/row-model`'s `membership-bitset.ts` BY DESIGN —
@@ -110,8 +100,7 @@ function testDenseBit(bits, slot) {
110
100
  return word === void 0 ? false : (word >>> (slot & 31) & 1) === 1;
111
101
  }
112
102
 
113
- //#endregion
114
- //#region ../layout-core/dist/row-height-index.js
103
+ // ../layout-core/dist/row-height-index.js
115
104
  var _a$1;
116
105
  function createWork(entriesVisited = 0) {
117
106
  return {
@@ -1964,8 +1953,7 @@ function _release() {
1964
1953
  _classPrivateFieldSet2(_root2$2, this, null);
1965
1954
  }
1966
1955
 
1967
- //#endregion
1968
- //#region ../grid-core/dist/indexed-selection.js
1956
+ // ../grid-core/dist/indexed-selection.js
1969
1957
  let _Symbol$iterator;
1970
1958
  let _Symbol$toStringTag;
1971
1959
  let _Symbol$iterator2;
@@ -3414,8 +3402,7 @@ function reconcileIndexedSelection(selection, snapshot, eviction) {
3414
3402
  });
3415
3403
  }
3416
3404
 
3417
- //#endregion
3418
- //#region ../grid-core/dist/indexed-focus.js
3405
+ // ../grid-core/dist/indexed-focus.js
3419
3406
  /**
3420
3407
  * The one header address there is.
3421
3408
  *
@@ -3580,8 +3567,7 @@ function moveIndexedFocus(input) {
3580
3567
  return nextRow === rowIndex ? current : (_focusAt5 = focusAt(snapshot, nextRow, current.columnId)) !== null && _focusAt5 !== void 0 ? _focusAt5 : current;
3581
3568
  }
3582
3569
 
3583
- //#endregion
3584
- //#region ../grid-core/dist/create-grid-ui-core.js
3570
+ // ../grid-core/dist/create-grid-ui-core.js
3585
3571
  var PretableGridUiError = class extends Error {
3586
3572
  constructor(code, message, cause) {
3587
3573
  super(message);
@@ -4330,13 +4316,11 @@ function createGridUiCore(options) {
4330
4316
  };
4331
4317
  }
4332
4318
 
4333
- //#endregion
4334
- //#region ../grid-core/dist/group-column.js
4319
+ // ../grid-core/dist/group-column.js
4335
4320
  /** Id of the synthetic visual column that carries grouped row labels. @public */
4336
4321
  const GROUP_COLUMN_ID = "__pretable_group__";
4337
4322
 
4338
- //#endregion
4339
- //#region src/create-grid.ts
4323
+ // src/create-grid.ts
4340
4324
  /**
4341
4325
  * Create a framework-independent UI-state grid over an explicit indexed row
4342
4326
  * model. Data, queries, grouping, aggregation, and expansion remain owned by
@@ -4349,8 +4333,7 @@ function createGrid(options) {
4349
4333
  return createGridUiCore(options);
4350
4334
  }
4351
4335
 
4352
- //#endregion
4353
- //#region ../row-model/dist/column-types.js
4336
+ // ../row-model/dist/column-types.js
4354
4337
  /** @public */
4355
4338
  function createColumnHelper$1() {
4356
4339
  return { accessor(id, accessorOrOptions, maybeOptions) {
@@ -4375,8 +4358,7 @@ function isPretableFilterGroup(node) {
4375
4358
  return typeof node === "object" && node !== null && "children" in node && (node.op === "and" || node.op === "or");
4376
4359
  }
4377
4360
 
4378
- //#endregion
4379
- //#region ../calendar-date/dist/calendar-date.js
4361
+ // ../calendar-date/dist/calendar-date.js
4380
4362
  const ASCII_ZERO = 48;
4381
4363
  const ASCII_NINE = 57;
4382
4364
  const ASCII_HYPHEN = 45;
@@ -4408,8 +4390,7 @@ function compareDateValues(left, right) {
4408
4390
  return 0;
4409
4391
  }
4410
4392
 
4411
- //#endregion
4412
- //#region ../row-model/dist/calendar-date-aggregates.js
4393
+ // ../row-model/dist/calendar-date-aggregates.js
4413
4394
  function calendarDateExtremum(kind) {
4414
4395
  return Object.freeze({
4415
4396
  init: () => null,
@@ -4438,8 +4419,7 @@ function isCalendarDateAggregate(aggregate) {
4438
4419
  return aggregate === calendarDateMin || aggregate === calendarDateMax;
4439
4420
  }
4440
4421
 
4441
- //#endregion
4442
- //#region ../row-model/dist/errors.js
4422
+ // ../row-model/dist/errors.js
4443
4423
  /** @public */
4444
4424
  var PretableRowModelError = class extends Error {
4445
4425
  constructor(code, message, context) {
@@ -4532,8 +4512,7 @@ var PretableTransitionCancelledError = class extends Error {
4532
4512
  }
4533
4513
  };
4534
4514
 
4535
- //#endregion
4536
- //#region ../row-model/dist/query-equality.js
4515
+ // ../row-model/dist/query-equality.js
4537
4516
  function isRuntimeFilterGroup$1(node) {
4538
4517
  return "children" in node;
4539
4518
  }
@@ -4584,8 +4563,7 @@ function queryEqual(left, right) {
4584
4563
  return filterNodeListEqual(left.filters, right.filters) && orderingEqual(left.sort, right.sort) && orderingEqual(left.rowGroups, right.rowGroups);
4585
4564
  }
4586
4565
 
4587
- //#endregion
4588
- //#region ../row-model/dist/compiled-query.js
4566
+ // ../row-model/dist/compiled-query.js
4589
4567
  var CompiledQueryValidationError = class extends TypeError {
4590
4568
  constructor(detail, path, columnId, options) {
4591
4569
  super(`Invalid compiled query at ${path}: ${detail}`, options);
@@ -5286,6 +5264,7 @@ var CompiledQueryPlan = class CompiledQueryPlan {
5286
5264
  constructor(capturedColumns, capturedQuery, operation, filterAuthority, sortAuthority) {
5287
5265
  _classPrivateMethodInitSpec(this, _CompiledQueryPlan_brand);
5288
5266
  _defineProperty(this, "activeColumnIds", void 0);
5267
+ _defineProperty(this, "aggregateColumnIds", void 0);
5289
5268
  _classPrivateFieldInitSpec(this, _publicColumns, void 0);
5290
5269
  _classPrivateFieldInitSpec(this, _publicQuery, void 0);
5291
5270
  _classPrivateFieldInitSpec(this, _runtimeColumns, void 0);
@@ -5315,6 +5294,7 @@ var CompiledQueryPlan = class CompiledQueryPlan {
5315
5294
  _classPrivateFieldGet2(_runtimeQuery, this).rowGroups.forEach((entry) => activeIds.add(entry.columnId));
5316
5295
  _classPrivateFieldGet2(_runtimeQuery, this).sort.forEach((entry) => activeIds.add(entry.columnId));
5317
5296
  _classPrivateFieldSet2(_aggregateColumns, this, _classPrivateFieldGet2(_runtimeColumns, this).filter((column) => column.aggregate !== void 0));
5297
+ this.aggregateColumnIds = Object.freeze(_classPrivateFieldGet2(_aggregateColumns, this).map((column) => column.id));
5318
5298
  _classPrivateFieldGet2(_aggregateColumns, this).forEach((column) => activeIds.add(column.id));
5319
5299
  _classPrivateFieldSet2(_active, this, _classPrivateFieldGet2(_runtimeColumns, this).filter((column) => activeIds.has(column.id)));
5320
5300
  this.activeColumnIds = Object.freeze(_classPrivateFieldGet2(_active, this).map((column) => column.id));
@@ -5769,50 +5749,25 @@ function compileQuery(input) {
5769
5749
  return new CompiledQueryPlan(captured.columns, captured.query, (_input$operation = input.operation) !== null && _input$operation !== void 0 ? _input$operation : "set-query", captured.filterAuthority, captured.sortAuthority);
5770
5750
  }
5771
5751
 
5772
- //#endregion
5773
- //#region ../row-model/dist/membership-bitset.js
5752
+ // ../row-model/dist/ordered-row-entry.js
5774
5753
  /**
5775
- * Membership bitsets: one bit per SLOT (see `slot-allocator`). A committed
5776
- * root's verdict is its membership (the filter-membership invariant); the
5777
- * bitset is a faster INDEX of that same structural answer for flat roots,
5778
- * never a stored verdict. Grouped roots carry `EMPTY_MEMBERSHIP` and keep
5779
- * answering from the group index.
5780
- *
5781
- * Mutable while a producer is building the next revision's set; frozen by
5782
- * convention once a root captures it (no Object.freeze — typed arrays do not
5783
- * support it; discipline is "producers build fresh or clone, never write a
5784
- * captured root's bitset", the same convention every persistent structure
5785
- * here relies on).
5754
+ * Standalone module because both visible-index and group-index need it and
5755
+ * visible-index already imports group-index — either home would cycle.
5786
5756
  *
5787
- * Whole-copy on change is the point: 50k rows is 6.25KB, negligible per
5788
- * commit (M0 measured ~1µs), so no COW machinery exists at this layer.
5757
+ * Decorates a record for tree residence: ONE store get, at insert time. The
5758
+ * record must already be evaluated (or swap-filled) under `queryPlan` —
5759
+ * `sortKeysOf` throws otherwise, which is the fail-loud contract. Entry keys
5760
+ * stay valid for the tree's lifetime because a tree is bound to one plan
5761
+ * (the A2 rebuild-or-reseed invariant) and row updates replace the entry.
5789
5762
  */
5790
- /** Shared sentinel for roots whose membership lives elsewhere (grouped). */
5791
- const EMPTY_MEMBERSHIP = /* @__PURE__ */ new Uint32Array(0);
5792
- function createMembership(capacity) {
5793
- return new Uint32Array(capacity + 31 >>> 5);
5794
- }
5795
- /** Clone, growing to `capacity` when it exceeds the source's words. */
5796
- function cloneMembership(bits, capacity) {
5797
- const words = Math.max(bits.length, capacity + 31 >>> 5);
5798
- const next = new Uint32Array(words);
5799
- next.set(bits);
5800
- return next;
5801
- }
5802
- function setMembershipBit(bits, slot) {
5803
- bits[slot >>> 5] |= 1 << (slot & 31);
5804
- }
5805
- function clearMembershipBit(bits, slot) {
5806
- bits[slot >>> 5] &= ~(1 << (slot & 31));
5807
- }
5808
- /** Out-of-range slots read as false — the EMPTY sentinel relies on this. */
5809
- function testMembershipBit(bits, slot) {
5810
- const word = bits[slot >>> 5];
5811
- return word === void 0 ? false : (word >>> (slot & 31) & 1) === 1;
5763
+ function orderedRowEntry(queryPlan, record) {
5764
+ return Object.freeze({
5765
+ record,
5766
+ keys: sortKeysOf(queryPlan, record)
5767
+ });
5812
5768
  }
5813
5769
 
5814
- //#endregion
5815
- //#region ../row-model/dist/persistent/transient.js
5770
+ // ../row-model/dist/persistent/transient.js
5816
5771
  var _editable$1 = /* @__PURE__ */ new WeakMap();
5817
5772
  var TransientEditToken = class {
5818
5773
  constructor() {
@@ -5826,8 +5781,7 @@ var TransientEditToken = class {
5826
5781
  }
5827
5782
  };
5828
5783
 
5829
- //#endregion
5830
- //#region ../row-model/dist/persistent/persistent-map.js
5784
+ // ../row-model/dist/persistent/persistent-map.js
5831
5785
  const inspectPersistentPath = Symbol("inspectPersistentPath");
5832
5786
  const inspectTransientPath = Symbol("inspectTransientPath");
5833
5787
  const attachInstrumentation$2 = Symbol("attachInstrumentation");
@@ -6195,8 +6149,7 @@ function instrumentPersistentMap(map, instrumentation) {
6195
6149
  return map[attachInstrumentation$2](instrumentation);
6196
6150
  }
6197
6151
 
6198
- //#endregion
6199
- //#region ../row-model/dist/persistent/order-statistic-tree.js
6152
+ // ../row-model/dist/persistent/order-statistic-tree.js
6200
6153
  var _a;
6201
6154
  const attachInstrumentation$1 = Symbol("attachOrderInstrumentation");
6202
6155
  const createDeferredMeasureDraft$1 = Symbol("createDeferredMeasureDraft");
@@ -6891,102 +6844,7 @@ function instrumentMeasuredOrderStatisticTree(tree, instrumentation, beforeCombi
6891
6844
  return tree[attachInstrumentation$1](instrumentation, beforeCombine);
6892
6845
  }
6893
6846
 
6894
- //#endregion
6895
- //#region ../row-model/dist/slot-vector.js
6896
- /**
6897
- * Immutable chunked slot-indexed vector: a chunk table over
6898
- * `SLOT_VECTOR_CHUNK`-element chunks, copy-on-write per commit. A commit
6899
- * touching k slots copies the table plus each touched chunk once — this is
6900
- * what keeps old snapshots valid under slot reuse: every revision holds its
6901
- * own table, so revision N still binds slot s to whatever row owned s at
6902
- * revision N no matter what later commits do (M0 priced maintenance at
6903
- * ~33–98µs per 100-write commit).
6904
- *
6905
- * Holes (`undefined`) are free slots. Iteration hole-skips, which is why no
6906
- * separate "live" bitset exists (recorded plan deviation from the spec).
6907
- */
6908
- const SLOT_VECTOR_CHUNK = 1024;
6909
- const EMPTY = Object.freeze({ chunks: Object.freeze([]) });
6910
- function slotVectorFromEntries(entries, capacity) {
6911
- const tableSize = Math.ceil(capacity / SLOT_VECTOR_CHUNK);
6912
- const limit = tableSize * SLOT_VECTOR_CHUNK;
6913
- const chunks = new Array(tableSize);
6914
- for (const [slot, value] of entries) {
6915
- if (slot >= limit) throw new RangeError(`Slot ${slot} is beyond capacity ${capacity}.`);
6916
- const index = slot / SLOT_VECTOR_CHUNK | 0;
6917
- let chunk = chunks[index];
6918
- if (chunk === void 0) {
6919
- chunk = new Array(SLOT_VECTOR_CHUNK);
6920
- chunks[index] = chunk;
6921
- }
6922
- chunk[slot % SLOT_VECTOR_CHUNK] = value;
6923
- }
6924
- return { chunks };
6925
- }
6926
- /**
6927
- * One commit's writes (`undefined` value = clear the slot), COW: table copied
6928
- * once, each touched chunk copied once. `capacity` may exceed the old
6929
- * table's reach (allocator growth).
6930
- *
6931
- * `chunksTouched` counts every chunk this commit allocated or copied,
6932
- * including a brand-new chunk created for a hole beyond the old table — that
6933
- * counts as touched even though nothing was copied.
6934
- */
6935
- function slotVectorWithAll(vector, writes, capacity) {
6936
- const tableSize = Math.max(vector.chunks.length, Math.ceil(capacity / SLOT_VECTOR_CHUNK));
6937
- const limit = tableSize * SLOT_VECTOR_CHUNK;
6938
- const chunks = new Array(tableSize);
6939
- for (let i = 0; i < vector.chunks.length; i += 1) chunks[i] = vector.chunks[i];
6940
- let chunksTouched = 0;
6941
- for (const [slot, value] of writes) {
6942
- if (slot >= limit) throw new RangeError(`Slot ${slot} is beyond capacity ${capacity}.`);
6943
- const index = slot / SLOT_VECTOR_CHUNK | 0;
6944
- if (chunks[index] === void 0 || chunks[index] === vector.chunks[index]) {
6945
- const existing = chunks[index];
6946
- chunks[index] = existing === void 0 ? new Array(SLOT_VECTOR_CHUNK) : existing.slice();
6947
- chunksTouched += 1;
6948
- }
6949
- chunks[index][slot % SLOT_VECTOR_CHUNK] = value;
6950
- }
6951
- return {
6952
- next: { chunks },
6953
- chunksTouched
6954
- };
6955
- }
6956
- /** Hole-skipping walk in slot order. */
6957
- function forEachSlotEntry(vector, callback) {
6958
- for (let index = 0; index < vector.chunks.length; index += 1) {
6959
- const chunk = vector.chunks[index];
6960
- if (chunk === void 0) continue;
6961
- const base = index * SLOT_VECTOR_CHUNK;
6962
- for (let offset = 0; offset < chunk.length; offset += 1) {
6963
- const value = chunk[offset];
6964
- if (value !== void 0) callback(value, base + offset);
6965
- }
6966
- }
6967
- }
6968
-
6969
- //#endregion
6970
- //#region ../row-model/dist/ordered-row-entry.js
6971
- /**
6972
- * Standalone module because both visible-index and group-index need it and
6973
- * visible-index already imports group-index — either home would cycle.
6974
- *
6975
- * Decorates a record for tree residence: ONE store get, at insert time. The
6976
- * record must already be evaluated (or swap-filled) under `queryPlan` —
6977
- * `sortKeysOf` throws otherwise, which is the fail-loud contract. Entry keys
6978
- * stay valid for the tree's lifetime because a tree is bound to one plan
6979
- * (the A2 rebuild-or-reseed invariant) and row updates replace the entry.
6980
- */
6981
- function orderedRowEntry(queryPlan, record) {
6982
- return Object.freeze({
6983
- record,
6984
- keys: sortKeysOf(queryPlan, record)
6985
- });
6986
- }
6987
-
6988
- //#endregion
6989
- //#region ../row-model/dist/persistent/aggregate-tree.js
6847
+ // ../row-model/dist/persistent/aggregate-tree.js
6990
6848
  const attachInstrumentation = Symbol("attachAggregateInstrumentation");
6991
6849
  const createDeferredMeasureDraft = Symbol("createDeferredMeasureDraft");
6992
6850
  const DEVELOPMENT$2 = process.env.NODE_ENV !== "production";
@@ -7476,8 +7334,7 @@ function instrumentAggregateTree(tree, instrumentation) {
7476
7334
  return tree[attachInstrumentation](instrumentation);
7477
7335
  }
7478
7336
 
7479
- //#endregion
7480
- //#region ../row-model/dist/group-index.js
7337
+ // ../row-model/dist/group-index.js
7481
7338
  const visibleRangeDiagnostics = /* @__PURE__ */ new WeakMap();
7482
7339
  const EMPTY_COUNTS = Object.freeze({
7483
7340
  collapsed: 0,
@@ -8556,8 +8413,308 @@ function nearestVisible(root, ref, policy) {
8556
8413
  }
8557
8414
  }
8558
8415
 
8559
- //#endregion
8560
- //#region ../row-model/dist/visible-index.js
8416
+ // ../row-model/dist/filter-membership.js
8417
+ /**
8418
+ * Filter verdicts are not stored. A committed root already carries the answer
8419
+ * structurally: a row passes this root's filters exactly when it is a MEMBER
8420
+ * of the root's visible structure. This module is the one place that knows
8421
+ * which structure answers for which root shape.
8422
+ *
8423
+ * - **Flat root** (`query.rowGroups.length === 0`): `root.visible.rows` holds
8424
+ * one entry per passing row and nothing else, so membership is a lookup.
8425
+ * This is the same predicate `nearestVisibleRef` has always used.
8426
+ * - **Grouped root**: `root.visible.rows` is deliberately EMPTY (a grouped
8427
+ * visible index attaches the group index to an empty flat tree), so the
8428
+ * answer lives in the group index: every inserted row — passing or not —
8429
+ * gets a `rowParents` entry, and only passing rows are inserted into their
8430
+ * leaf group's `leaves` tree. So `rowParents` locates the leaf group and
8431
+ * `leaves` holds the verdict.
8432
+ *
8433
+ * Absence is the answer, not a fault: a row this root never saw, or one its
8434
+ * filters reject, is simply not a member. Nothing here fails loud.
8435
+ *
8436
+ * These read a COMMITTED root, so they answer "did this row pass under the
8437
+ * plan that built this root" — the OLD verdict at every site that compares
8438
+ * against a new one. A NEW verdict is computed, never resolved: producers
8439
+ * call `filterVerdict(plan, record)` and use it locally to decide where the
8440
+ * row goes.
8441
+ */
8442
+ /** Did `rowId` pass the filters of the plan that built `root`? */
8443
+ function rowPassesFilter(root, rowId) {
8444
+ const grouped = getGroupIndex(root.visible);
8445
+ return grouped === void 0 ? root.visible.rows.get(rowId) !== void 0 : rowPassesFilterInGroupIndex(grouped, rowId);
8446
+ }
8447
+
8448
+ // ../row-model/dist/summary-index.js
8449
+ function emptyRoots(plan, instrumentation) {
8450
+ const roots = /* @__PURE__ */ new Map();
8451
+ for (const column of plan.derivations) {
8452
+ if (column.aggregate === void 0) continue;
8453
+ const aggregate = lowerCalendarDateAggregate(column.type, column.aggregate);
8454
+ const factory = createAggregateTree;
8455
+ const tree = isScalarBuiltinAggregator(aggregate) ? createScalarAggregateCell({
8456
+ columnId: column.id,
8457
+ aggregator: aggregate
8458
+ }) : factory({
8459
+ columnId: column.id,
8460
+ aggregator: aggregate,
8461
+ compare: (a, b) => compareWithSortKeys(plan, {
8462
+ rowId: a.id,
8463
+ row: a.row,
8464
+ sourceOrder: a.dependency.sourceOrder
8465
+ }, a.dependency.sortKeys, {
8466
+ rowId: b.id,
8467
+ row: b.row,
8468
+ sourceOrder: b.dependency.sourceOrder
8469
+ }, b.dependency.sortKeys)
8470
+ });
8471
+ roots.set(column.id, instrumentAggregateTree(tree, instrumentation));
8472
+ }
8473
+ return roots;
8474
+ }
8475
+ function finish(roots) {
8476
+ const results = {};
8477
+ for (const scope of ["all", "filtered"]) {
8478
+ const trees = roots[scope];
8479
+ if (trees === void 0) continue;
8480
+ const values = Object.create(null);
8481
+ for (const [id, tree] of trees) values[id] = tree.finalize();
8482
+ results[scope] = Object.freeze({
8483
+ scope,
8484
+ values: Object.freeze(values)
8485
+ });
8486
+ }
8487
+ return Object.freeze({
8488
+ roots: Object.freeze(roots),
8489
+ results: Object.freeze(results)
8490
+ });
8491
+ }
8492
+ function contribute(roots, record, plan, add, instrumentation) {
8493
+ if (instrumentation) instrumentation.work.summaryRowsVisited += 1;
8494
+ const next = new Map(roots);
8495
+ for (const entry of record.metadata.aggregateLeaves) {
8496
+ const tree = next.get(entry.columnId);
8497
+ if (tree === void 0) continue;
8498
+ if (instrumentation) instrumentation.work.summaryCellsUpdated += 1;
8499
+ const leaf = {
8500
+ ...entry.allLeaf,
8501
+ dependency: {
8502
+ sourceOrder: record.sourceOrder,
8503
+ sortKeys: sortKeysOf(plan, record)
8504
+ }
8505
+ };
8506
+ next.set(entry.columnId, add ? tree.insertOrReplace(leaf) : tree.remove(record.rowId, leaf));
8507
+ }
8508
+ return next;
8509
+ }
8510
+ /** Only affected records are visited, scalar cells apply exact inverse deltas. */
8511
+ function updateSummaryIndex(previous, next, ids, instrumentation) {
8512
+ if (previous.summaries === void 0) return void 0;
8513
+ const roots = { ...previous.summaries.roots };
8514
+ for (const scope of ["all", "filtered"]) {
8515
+ let trees = roots[scope];
8516
+ if (trees === void 0) continue;
8517
+ for (const id of ids) {
8518
+ const old = previous.rows.get(id);
8519
+ const current = next.rows.get(id);
8520
+ if (old && (scope === "all" || rowPassesFilter(previous, id))) trees = contribute(trees, old, previous.queryPlan, false, instrumentation);
8521
+ if (current && (scope === "all" || rowPassesFilter(next, id))) trees = contribute(trees, current, next.queryPlan, true, instrumentation);
8522
+ }
8523
+ roots[scope] = trees;
8524
+ }
8525
+ return finish(roots);
8526
+ }
8527
+ function retainSummaryScopes(index, scopes) {
8528
+ if (index === void 0 || scopes.length === 0) return void 0;
8529
+ const roots = {};
8530
+ const results = {};
8531
+ for (const scope of scopes) {
8532
+ roots[scope] = index.roots[scope];
8533
+ results[scope] = index.results[scope];
8534
+ }
8535
+ return Object.freeze({
8536
+ roots: Object.freeze(roots),
8537
+ results: Object.freeze(results)
8538
+ });
8539
+ }
8540
+ /** A private rebuild: one source record or replay record per cooperative step. */
8541
+ function createSummaryBuild(captured, plan, scopes, instrumentation) {
8542
+ let activeScopes = [...scopes];
8543
+ const roots = {};
8544
+ for (const scope of activeScopes) roots[scope] = emptyRoots(plan, instrumentation);
8545
+ const records = /* @__PURE__ */ new Map();
8546
+ let iterator = captured.rows.entries();
8547
+ const deltas = /* @__PURE__ */ new Map();
8548
+ function replace(id, original) {
8549
+ const old = records.get(id);
8550
+ if (old) {
8551
+ for (const scope of activeScopes) if (scope === "all" || old.matches) roots[scope] = contribute(roots[scope], old.record, plan, false, instrumentation);
8552
+ }
8553
+ records.delete(id);
8554
+ if (!original) return;
8555
+ const record = plan === captured.queryPlan ? original : {
8556
+ ...original,
8557
+ metadata: plan.evaluate({
8558
+ rowId: id,
8559
+ row: original.row,
8560
+ sourceOrder: original.sourceOrder,
8561
+ slot: original.slot
8562
+ })
8563
+ };
8564
+ const matches = filterVerdict(plan, record);
8565
+ records.set(id, {
8566
+ record,
8567
+ matches
8568
+ });
8569
+ for (const scope of activeScopes) if (scope === "all" || matches) roots[scope] = contribute(roots[scope], record, plan, true, instrumentation);
8570
+ }
8571
+ return {
8572
+ retainScopes(requested) {
8573
+ activeScopes = activeScopes.filter((scope) => requested.includes(scope));
8574
+ for (const scope of ["all", "filtered"]) if (!activeScopes.includes(scope)) delete roots[scope];
8575
+ },
8576
+ append(target, ids) {
8577
+ for (const id of ids) deltas.set(id, target.rows.get(id));
8578
+ },
8579
+ step() {
8580
+ if (iterator) {
8581
+ const item = iterator.next();
8582
+ if (!item.done) {
8583
+ replace(item.value[0], item.value[1]);
8584
+ return false;
8585
+ }
8586
+ iterator = void 0;
8587
+ }
8588
+ const delta = deltas.entries().next();
8589
+ if (!delta.done) {
8590
+ deltas.delete(delta.value[0]);
8591
+ replace(delta.value[0], delta.value[1]);
8592
+ return false;
8593
+ }
8594
+ return true;
8595
+ },
8596
+ finish() {
8597
+ return finish(roots);
8598
+ }
8599
+ };
8600
+ }
8601
+
8602
+ // ../row-model/dist/membership-bitset.js
8603
+ /**
8604
+ * Membership bitsets: one bit per SLOT (see `slot-allocator`). A committed
8605
+ * root's verdict is its membership (the filter-membership invariant); the
8606
+ * bitset is a faster INDEX of that same structural answer for flat roots,
8607
+ * never a stored verdict. Grouped roots carry `EMPTY_MEMBERSHIP` and keep
8608
+ * answering from the group index.
8609
+ *
8610
+ * Mutable while a producer is building the next revision's set; frozen by
8611
+ * convention once a root captures it (no Object.freeze — typed arrays do not
8612
+ * support it; discipline is "producers build fresh or clone, never write a
8613
+ * captured root's bitset", the same convention every persistent structure
8614
+ * here relies on).
8615
+ *
8616
+ * Whole-copy on change is the point: 50k rows is 6.25KB, negligible per
8617
+ * commit (M0 measured ~1µs), so no COW machinery exists at this layer.
8618
+ */
8619
+ /** Shared sentinel for roots whose membership lives elsewhere (grouped). */
8620
+ const EMPTY_MEMBERSHIP = /* @__PURE__ */ new Uint32Array(0);
8621
+ function createMembership(capacity) {
8622
+ return new Uint32Array(capacity + 31 >>> 5);
8623
+ }
8624
+ /** Clone, growing to `capacity` when it exceeds the source's words. */
8625
+ function cloneMembership(bits, capacity) {
8626
+ const words = Math.max(bits.length, capacity + 31 >>> 5);
8627
+ const next = new Uint32Array(words);
8628
+ next.set(bits);
8629
+ return next;
8630
+ }
8631
+ function setMembershipBit(bits, slot) {
8632
+ bits[slot >>> 5] |= 1 << (slot & 31);
8633
+ }
8634
+ function clearMembershipBit(bits, slot) {
8635
+ bits[slot >>> 5] &= ~(1 << (slot & 31));
8636
+ }
8637
+ /** Out-of-range slots read as false — the EMPTY sentinel relies on this. */
8638
+ function testMembershipBit(bits, slot) {
8639
+ const word = bits[slot >>> 5];
8640
+ return word === void 0 ? false : (word >>> (slot & 31) & 1) === 1;
8641
+ }
8642
+
8643
+ // ../row-model/dist/slot-vector.js
8644
+ /**
8645
+ * Immutable chunked slot-indexed vector: a chunk table over
8646
+ * `SLOT_VECTOR_CHUNK`-element chunks, copy-on-write per commit. A commit
8647
+ * touching k slots copies the table plus each touched chunk once — this is
8648
+ * what keeps old snapshots valid under slot reuse: every revision holds its
8649
+ * own table, so revision N still binds slot s to whatever row owned s at
8650
+ * revision N no matter what later commits do (M0 priced maintenance at
8651
+ * ~33–98µs per 100-write commit).
8652
+ *
8653
+ * Holes (`undefined`) are free slots. Iteration hole-skips, which is why no
8654
+ * separate "live" bitset exists (recorded plan deviation from the spec).
8655
+ */
8656
+ const SLOT_VECTOR_CHUNK = 1024;
8657
+ const EMPTY = Object.freeze({ chunks: Object.freeze([]) });
8658
+ function slotVectorFromEntries(entries, capacity) {
8659
+ const tableSize = Math.ceil(capacity / SLOT_VECTOR_CHUNK);
8660
+ const limit = tableSize * SLOT_VECTOR_CHUNK;
8661
+ const chunks = new Array(tableSize);
8662
+ for (const [slot, value] of entries) {
8663
+ if (slot >= limit) throw new RangeError(`Slot ${slot} is beyond capacity ${capacity}.`);
8664
+ const index = slot / SLOT_VECTOR_CHUNK | 0;
8665
+ let chunk = chunks[index];
8666
+ if (chunk === void 0) {
8667
+ chunk = new Array(SLOT_VECTOR_CHUNK);
8668
+ chunks[index] = chunk;
8669
+ }
8670
+ chunk[slot % SLOT_VECTOR_CHUNK] = value;
8671
+ }
8672
+ return { chunks };
8673
+ }
8674
+ /**
8675
+ * One commit's writes (`undefined` value = clear the slot), COW: table copied
8676
+ * once, each touched chunk copied once. `capacity` may exceed the old
8677
+ * table's reach (allocator growth).
8678
+ *
8679
+ * `chunksTouched` counts every chunk this commit allocated or copied,
8680
+ * including a brand-new chunk created for a hole beyond the old table — that
8681
+ * counts as touched even though nothing was copied.
8682
+ */
8683
+ function slotVectorWithAll(vector, writes, capacity) {
8684
+ const tableSize = Math.max(vector.chunks.length, Math.ceil(capacity / SLOT_VECTOR_CHUNK));
8685
+ const limit = tableSize * SLOT_VECTOR_CHUNK;
8686
+ const chunks = new Array(tableSize);
8687
+ for (let i = 0; i < vector.chunks.length; i += 1) chunks[i] = vector.chunks[i];
8688
+ let chunksTouched = 0;
8689
+ for (const [slot, value] of writes) {
8690
+ if (slot >= limit) throw new RangeError(`Slot ${slot} is beyond capacity ${capacity}.`);
8691
+ const index = slot / SLOT_VECTOR_CHUNK | 0;
8692
+ if (chunks[index] === void 0 || chunks[index] === vector.chunks[index]) {
8693
+ const existing = chunks[index];
8694
+ chunks[index] = existing === void 0 ? new Array(SLOT_VECTOR_CHUNK) : existing.slice();
8695
+ chunksTouched += 1;
8696
+ }
8697
+ chunks[index][slot % SLOT_VECTOR_CHUNK] = value;
8698
+ }
8699
+ return {
8700
+ next: { chunks },
8701
+ chunksTouched
8702
+ };
8703
+ }
8704
+ /** Hole-skipping walk in slot order. */
8705
+ function forEachSlotEntry(vector, callback) {
8706
+ for (let index = 0; index < vector.chunks.length; index += 1) {
8707
+ const chunk = vector.chunks[index];
8708
+ if (chunk === void 0) continue;
8709
+ const base = index * SLOT_VECTOR_CHUNK;
8710
+ for (let offset = 0; offset < chunk.length; offset += 1) {
8711
+ const value = chunk[offset];
8712
+ if (value !== void 0) callback(value, base + offset);
8713
+ }
8714
+ }
8715
+ }
8716
+
8717
+ // ../row-model/dist/visible-index.js
8561
8718
  function createFlatVisibleIndex(records, queryPlan) {
8562
8719
  const draft = createFlatVisibleTree(queryPlan).asTransient();
8563
8720
  for (const record of records) if (filterVerdict(queryPlan, record)) draft.insertOrReplace(orderedRowEntry(queryPlan, record));
@@ -8613,6 +8770,11 @@ function createFlatSnapshot(root) {
8613
8770
  const count = visibleCount(grouped, policy);
8614
8771
  const dataCount = visibleDataCount(grouped, policy);
8615
8772
  return Object.freeze({
8773
+ getSummary: (scope) => {
8774
+ var _root$summaries;
8775
+ return (_root$summaries = root.summaries) === null || _root$summaries === void 0 ? void 0 : _root$summaries.results[scope];
8776
+ },
8777
+ aggregateColumnIds: root.queryPlan.aggregateColumnIds,
8616
8778
  revision: root.revision,
8617
8779
  sourceRowCount: root.rows.size,
8618
8780
  visibleRowCount: count,
@@ -8647,6 +8809,11 @@ function createFlatSnapshot(root) {
8647
8809
  };
8648
8810
  const lookupRank = (ref) => ref.kind === "data" ? visible.rankOf(ref.rowId) : void 0;
8649
8811
  return Object.freeze({
8812
+ getSummary: (scope) => {
8813
+ var _root$summaries2;
8814
+ return (_root$summaries2 = root.summaries) === null || _root$summaries2 === void 0 ? void 0 : _root$summaries2.results[scope];
8815
+ },
8816
+ aggregateColumnIds: root.queryPlan.aggregateColumnIds,
8650
8817
  revision: root.revision,
8651
8818
  sourceRowCount: root.rows.size,
8652
8819
  visibleRowCount: visible.size,
@@ -8692,8 +8859,7 @@ function createFlatSnapshot(root) {
8692
8859
  });
8693
8860
  }
8694
8861
 
8695
- //#endregion
8696
- //#region ../row-model/dist/filter-rebuild.js
8862
+ // ../row-model/dist/filter-rebuild.js
8697
8863
  /**
8698
8864
  * Synchronous subset rebuild for a filter-only plan change on an ungrouped
8699
8865
  * query. Runs to completion on the caller's stack, like `sort-rebuild` — a
@@ -8780,41 +8946,7 @@ function rebuildRootForFilterOnlyChange(options) {
8780
8946
  return root;
8781
8947
  }
8782
8948
 
8783
- //#endregion
8784
- //#region ../row-model/dist/filter-membership.js
8785
- /**
8786
- * Filter verdicts are not stored. A committed root already carries the answer
8787
- * structurally: a row passes this root's filters exactly when it is a MEMBER
8788
- * of the root's visible structure. This module is the one place that knows
8789
- * which structure answers for which root shape.
8790
- *
8791
- * - **Flat root** (`query.rowGroups.length === 0`): `root.visible.rows` holds
8792
- * one entry per passing row and nothing else, so membership is a lookup.
8793
- * This is the same predicate `nearestVisibleRef` has always used.
8794
- * - **Grouped root**: `root.visible.rows` is deliberately EMPTY (a grouped
8795
- * visible index attaches the group index to an empty flat tree), so the
8796
- * answer lives in the group index: every inserted row — passing or not —
8797
- * gets a `rowParents` entry, and only passing rows are inserted into their
8798
- * leaf group's `leaves` tree. So `rowParents` locates the leaf group and
8799
- * `leaves` holds the verdict.
8800
- *
8801
- * Absence is the answer, not a fault: a row this root never saw, or one its
8802
- * filters reject, is simply not a member. Nothing here fails loud.
8803
- *
8804
- * These read a COMMITTED root, so they answer "did this row pass under the
8805
- * plan that built this root" — the OLD verdict at every site that compares
8806
- * against a new one. A NEW verdict is computed, never resolved: producers
8807
- * call `filterVerdict(plan, record)` and use it locally to decide where the
8808
- * row goes.
8809
- */
8810
- /** Did `rowId` pass the filters of the plan that built `root`? */
8811
- function rowPassesFilter(root, rowId) {
8812
- const grouped = getGroupIndex(root.visible);
8813
- return grouped === void 0 ? root.visible.rows.get(rowId) !== void 0 : rowPassesFilterInGroupIndex(grouped, rowId);
8814
- }
8815
-
8816
- //#endregion
8817
- //#region ../row-model/dist/sort-rebuild.js
8949
+ // ../row-model/dist/sort-rebuild.js
8818
8950
  /**
8819
8951
  * Synchronous whole-root rebuild for a sort-only plan change on an ungrouped
8820
8952
  * query. Runs to completion on the caller's stack — the deliberate trade
@@ -8861,8 +8993,7 @@ function rebuildRootForSortOnlyChange(options) {
8861
8993
  return root;
8862
8994
  }
8863
8995
 
8864
- //#endregion
8865
- //#region ../row-model/dist/flat-cooperative-candidate.js
8996
+ // ../row-model/dist/flat-cooperative-candidate.js
8866
8997
  /**
8867
8998
  * The flat (ungrouped) cooperative transition candidate. Builds against an
8868
8999
  * immutable source root and replays exact live-row deltas; nothing reachable
@@ -9217,8 +9348,7 @@ function createFlatCooperativeCandidate(options) {
9217
9348
  return candidate;
9218
9349
  }
9219
9350
 
9220
- //#endregion
9221
- //#region ../row-model/dist/cooperative-transition.js
9351
+ // ../row-model/dist/cooperative-transition.js
9222
9352
  const candidateDiagnostics = /* @__PURE__ */ new WeakMap();
9223
9353
  /**
9224
9354
  * Registers a candidate's diagnostics reader in the shared WeakMap so
@@ -9680,8 +9810,7 @@ function createCooperativeTransitionCandidate(options) {
9680
9810
  return candidate;
9681
9811
  }
9682
9812
 
9683
- //#endregion
9684
- //#region ../row-model/dist/distinct-values.js
9813
+ // ../row-model/dist/distinct-values.js
9685
9814
  const DEFAULT_RESULT_LIMIT = 100;
9686
9815
  const MAX_RESULT_LIMIT = 1e3;
9687
9816
  const DEFAULT_CACHE_CAPACITY = 8;
@@ -10404,8 +10533,7 @@ function createDistinctValueManager(options) {
10404
10533
  };
10405
10534
  }
10406
10535
 
10407
- //#endregion
10408
- //#region ../row-model/dist/change-journal.js
10536
+ // ../row-model/dist/change-journal.js
10409
10537
  const DEFAULT_CHANGE_JOURNAL_CAPACITY = 128;
10410
10538
  const operationDiagnostics = /* @__PURE__ */ new WeakMap();
10411
10539
  const journalDiagnostics = /* @__PURE__ */ new WeakMap();
@@ -10567,8 +10695,7 @@ function createChangeJournal(capacity = 128) {
10567
10695
  return frozen;
10568
10696
  }
10569
10697
 
10570
- //#endregion
10571
- //#region ../row-model/dist/row-integrity.js
10698
+ // ../row-model/dist/row-integrity.js
10572
10699
  const DEVELOPMENT$1 = process.env.NODE_ENV !== "production";
10573
10700
  function failIntegrity(operation, cause) {
10574
10701
  throw new PretableRowModelError("derivation-failed", "A row could not be inspected safely before publication.", {
@@ -10670,8 +10797,7 @@ function fingerprintInspection(current, rowId, previous, sameReference) {
10670
10797
  };
10671
10798
  }
10672
10799
 
10673
- //#endregion
10674
- //#region ../row-model/dist/row-store.js
10800
+ // ../row-model/dist/row-store.js
10675
10801
  function createSourceOrderTree(instrumentation) {
10676
10802
  return instrumentOrderStatisticTree(createOrderStatisticTree({
10677
10803
  getId: (entry) => entry.rowId,
@@ -10779,8 +10905,7 @@ function buildRowStore(input) {
10779
10905
  };
10780
10906
  }
10781
10907
 
10782
- //#endregion
10783
- //#region ../row-model/dist/slot-allocator.js
10908
+ // ../row-model/dist/slot-allocator.js
10784
10909
  /**
10785
10910
  * Per-MODEL slot allocator: every row gets a small dense integer for its
10786
10911
  * lifetime, assigned at ingest and released only on permanent removal.
@@ -10822,8 +10947,7 @@ function createSlotAllocator() {
10822
10947
  };
10823
10948
  }
10824
10949
 
10825
- //#endregion
10826
- //#region ../row-model/dist/transaction-draft.js
10950
+ // ../row-model/dist/transaction-draft.js
10827
10951
  var TransactionExecutionError = class extends PretableRowModelError {
10828
10952
  constructor(error) {
10829
10953
  super(error.code, error.message, {
@@ -11436,10 +11560,21 @@ function applyFlatTransactionDraft(input) {
11436
11560
  const slotWrites = [...removedRecords.map((record) => [record.slot, void 0]), ...prepared.map((record) => [record.slot, record])];
11437
11561
  const { next: recordsBySlot, chunksTouched } = slotVectorWithAll(input.root.recordsBySlot, slotWrites, input.slots.capacity);
11438
11562
  if (input.instrumentation !== void 0) input.instrumentation.work.slotChunksTouched += chunksTouched;
11563
+ const frozenSource = sourceDraft.freeze();
11564
+ const summaries = input.root.summaries === void 0 ? void 0 : updateSummaryIndex(input.root, {
11565
+ ...input.root,
11566
+ rows: frozenRows,
11567
+ sourceOrder: frozenSource,
11568
+ visible,
11569
+ recordsBySlot,
11570
+ visibleSlots,
11571
+ queryPlan: input.queryPlan
11572
+ }, [...effectiveRemoves, ...prepared.map((record) => record.rowId)], input.instrumentation);
11439
11573
  for (const record of removedRecords) input.slots.release(record.slot);
11440
11574
  return {
11441
11575
  rows: frozenRows,
11442
- sourceOrder: sourceDraft.freeze(),
11576
+ sourceOrder: frozenSource,
11577
+ summaries,
11443
11578
  visible,
11444
11579
  recordsBySlot,
11445
11580
  visibleSlots,
@@ -11661,10 +11796,20 @@ function replaceFlatRowsDraft(input) {
11661
11796
  const slotWrites = [...removedRecords.map((record) => [record.slot, void 0]), ...changedRecords.map((record) => [record.slot, record])];
11662
11797
  const { next: recordsBySlot, chunksTouched } = slotVectorWithAll(input.root.recordsBySlot, slotWrites, input.slots.capacity);
11663
11798
  if (input.instrumentation !== void 0) input.instrumentation.work.slotChunksTouched += chunksTouched;
11799
+ const summaries = input.root.summaries === void 0 ? void 0 : updateSummaryIndex(input.root, {
11800
+ ...input.root,
11801
+ rows: frozenRows,
11802
+ sourceOrder: frozenSource,
11803
+ visible,
11804
+ recordsBySlot,
11805
+ visibleSlots,
11806
+ queryPlan: input.queryPlan
11807
+ }, [...removedRecords.map((record) => record.rowId), ...changedRecords.map((record) => record.rowId)], input.instrumentation);
11664
11808
  for (const slot of reusableRemovedSlots) input.slots.release(slot);
11665
11809
  return {
11666
11810
  rows: frozenRows,
11667
11811
  sourceOrder: frozenSource,
11812
+ summaries,
11668
11813
  visible,
11669
11814
  recordsBySlot,
11670
11815
  visibleSlots,
@@ -11687,8 +11832,7 @@ function replaceFlatRowsDraft(input) {
11687
11832
  }
11688
11833
  }
11689
11834
 
11690
- //#endregion
11691
- //#region ../row-model/dist/create-local-row-model.js
11835
+ // ../row-model/dist/create-local-row-model.js
11692
11836
  function createSnapshot(root, instrumentation) {
11693
11837
  const snapshot = createFlatSnapshot(root);
11694
11838
  if (instrumentation === void 0) return snapshot;
@@ -11971,6 +12115,25 @@ function createLocalRowModel$1(options) {
11971
12115
  let nextSourceOrder = initialStore.records.length;
11972
12116
  let nextTransitionId = 1;
11973
12117
  let activeTransition;
12118
+ const summaryLeases = /* @__PURE__ */ new Map();
12119
+ const requestedSummaryScopes = () => ["all", "filtered"].filter((scope) => {
12120
+ var _summaryLeases$get;
12121
+ return ((_summaryLeases$get = summaryLeases.get(scope)) !== null && _summaryLeases$get !== void 0 ? _summaryLeases$get : 0) > 0;
12122
+ });
12123
+ let summaryAcquisition;
12124
+ let cancelSummaryRetry;
12125
+ const cancelSummaryAcquisition = () => {
12126
+ try {
12127
+ cancelSummaryRetry === null || cancelSummaryRetry === void 0 || cancelSummaryRetry();
12128
+ } catch (_unused2) {}
12129
+ cancelSummaryRetry = void 0;
12130
+ const pending = summaryAcquisition;
12131
+ summaryAcquisition = void 0;
12132
+ try {
12133
+ var _pending$cancel;
12134
+ pending === null || pending === void 0 || (_pending$cancel = pending.cancel) === null || _pending$cancel === void 0 || _pending$cancel.call(pending);
12135
+ } catch (_unused3) {}
12136
+ };
11974
12137
  const listeners = /* @__PURE__ */ new Set();
11975
12138
  const changeJournal = createChangeJournal(options.changeJournalCapacity);
11976
12139
  const sortFastPathRowLimit = (_options$ɵsortFastPa = options.ɵsortFastPathRowLimit) !== null && _options$ɵsortFastPa !== void 0 ? _options$ɵsortFastPa : SORT_FAST_PATH_ROW_LIMIT_DEFAULT;
@@ -12022,9 +12185,10 @@ function createLocalRowModel$1(options) {
12022
12185
  const notify = () => {
12023
12186
  for (const listener of Array.from(listeners)) try {
12024
12187
  listener();
12025
- } catch (_unused2) {}
12188
+ } catch (_unused4) {}
12026
12189
  };
12027
12190
  const publishCommittedRoot = (committedRoot, previousRevision, revision, barrierReason = "bulk-replace") => {
12191
+ cancelSummaryAcquisition();
12028
12192
  queryPlan = committedRoot.queryPlan;
12029
12193
  query = committedRoot.queryPlan.query;
12030
12194
  derivations = committedRoot.queryPlan.derivations;
@@ -12047,7 +12211,8 @@ function createLocalRowModel$1(options) {
12047
12211
  transition.cancelScheduled = void 0;
12048
12212
  try {
12049
12213
  cancelScheduled === null || cancelScheduled === void 0 || cancelScheduled();
12050
- } catch (_unused3) {}
12214
+ } catch (_unused5) {}
12215
+ transition.summaryBuild = void 0;
12051
12216
  transition.candidate.release();
12052
12217
  transition.reject(new PretableTransitionCancelledError(transition.id, reason));
12053
12218
  return transition;
@@ -12060,7 +12225,8 @@ function createLocalRowModel$1(options) {
12060
12225
  transition.cancelScheduled = void 0;
12061
12226
  try {
12062
12227
  cancelScheduled === null || cancelScheduled === void 0 || cancelScheduled();
12063
- } catch (_unused4) {}
12228
+ } catch (_unused6) {}
12229
+ transition.summaryBuild = void 0;
12064
12230
  transition.candidate.release();
12065
12231
  const typed = (_findPretableReentran = findPretableReentrantMutationError(error)) !== null && _findPretableReentran !== void 0 ? _findPretableReentran : transitionError(error, transition.operation);
12066
12232
  state = Object.freeze({
@@ -12092,7 +12258,18 @@ function createLocalRowModel$1(options) {
12092
12258
  const runTransitionSlice = (transition) => {
12093
12259
  if (activeTransition !== transition || disposed) return false;
12094
12260
  try {
12095
- const complete = runCooperativeTransitionSlice(transitionRuntime, () => transition.candidate.step());
12261
+ var _transition$summaryBu3;
12262
+ const scopes = requestedSummaryScopes();
12263
+ const key = scopes.join(",");
12264
+ if (transition.summaryScopesKey !== key) {
12265
+ transition.summaryScopesKey = key;
12266
+ transition.summaryBuild = scopes.length ? createSummaryBuild(root, transition.summaryPlan, scopes, instrumentation) : void 0;
12267
+ }
12268
+ const complete = runCooperativeTransitionSlice(transitionRuntime, () => {
12269
+ var _transition$summaryBu, _transition$summaryBu2;
12270
+ if (!transition.candidate.step()) return false;
12271
+ return (_transition$summaryBu = (_transition$summaryBu2 = transition.summaryBuild) === null || _transition$summaryBu2 === void 0 ? void 0 : _transition$summaryBu2.step()) !== null && _transition$summaryBu !== void 0 ? _transition$summaryBu : true;
12272
+ });
12096
12273
  if (activeTransition !== transition || disposed) return false;
12097
12274
  if (!complete) {
12098
12275
  state = Object.freeze({
@@ -12104,14 +12281,18 @@ function createLocalRowModel$1(options) {
12104
12281
  }
12105
12282
  const previousRevision = root.revision;
12106
12283
  const revision = previousRevision + 1;
12107
- const committedRoot = transition.candidate.finish(revision);
12284
+ const committedRoot = Object.freeze({
12285
+ ...transition.candidate.finish(revision),
12286
+ summaries: (_transition$summaryBu3 = transition.summaryBuild) === null || _transition$summaryBu3 === void 0 ? void 0 : _transition$summaryBu3.finish()
12287
+ });
12108
12288
  activeTransition = void 0;
12109
12289
  const cancelScheduled = transition.cancelScheduled;
12110
12290
  transition.cancelScheduled = void 0;
12111
12291
  try {
12112
12292
  cancelScheduled === null || cancelScheduled === void 0 || cancelScheduled();
12113
- } catch (_unused5) {}
12293
+ } catch (_unused7) {}
12114
12294
  publishCommittedRoot(committedRoot, previousRevision, revision);
12295
+ transition.summaryBuild = void 0;
12115
12296
  transition.candidate.release();
12116
12297
  transition.resolve(revision);
12117
12298
  return true;
@@ -12139,6 +12320,9 @@ function createLocalRowModel$1(options) {
12139
12320
  operation,
12140
12321
  instrumentation
12141
12322
  }),
12323
+ summaryPlan: nextPlan,
12324
+ summaryScopesKey: "",
12325
+ summaryBuild: void 0,
12142
12326
  finished,
12143
12327
  resolve,
12144
12328
  reject,
@@ -12153,6 +12337,14 @@ function createLocalRowModel$1(options) {
12153
12337
  return transition;
12154
12338
  };
12155
12339
  const appendTransitionDelta = (target, affectedRowIds) => {
12340
+ var _activeTransition$sum;
12341
+ if (summaryAcquisition) {
12342
+ if (summaryAcquisition.rebase !== void 0 || summaryAcquisition.plan !== target.queryPlan) {
12343
+ summaryAcquisition.plan = target.queryPlan;
12344
+ summaryAcquisition.rebase = target;
12345
+ } else summaryAcquisition.build.append(target, affectedRowIds);
12346
+ }
12347
+ activeTransition === null || activeTransition === void 0 || (_activeTransition$sum = activeTransition.summaryBuild) === null || _activeTransition$sum === void 0 || _activeTransition$sum.append(target, affectedRowIds);
12156
12348
  activeTransition === null || activeTransition === void 0 || activeTransition.candidate.append(Object.freeze({
12157
12349
  target,
12158
12350
  affectedRowIds: Object.freeze([...affectedRowIds])
@@ -12212,9 +12404,139 @@ function createLocalRowModel$1(options) {
12212
12404
  throw remapOperationError(error, operation);
12213
12405
  }
12214
12406
  };
12407
+ const reportSummaryFailure = (error) => {
12408
+ if (activeTransition === void 0) state = Object.freeze({
12409
+ snapshot,
12410
+ status: Object.freeze({
12411
+ kind: "error",
12412
+ transitionId: nextTransitionId++,
12413
+ error: transitionError(error, "set-derivations")
12414
+ })
12415
+ });
12416
+ };
12417
+ const restartSummaryAcquisition = () => {
12418
+ const scopes = requestedSummaryScopes();
12419
+ const key = scopes.join(",");
12420
+ if ((summaryAcquisition === null || summaryAcquisition === void 0 ? void 0 : summaryAcquisition.key) === key && summaryAcquisition.plan === root.queryPlan) return;
12421
+ if (scopes.every((scope) => {
12422
+ var _root$summaries;
12423
+ return ((_root$summaries = root.summaries) === null || _root$summaries === void 0 ? void 0 : _root$summaries.results[scope]) !== void 0;
12424
+ })) {
12425
+ cancelSummaryAcquisition();
12426
+ return;
12427
+ }
12428
+ const previousAcquisition = summaryAcquisition;
12429
+ const pending = {
12430
+ plan: root.queryPlan,
12431
+ key,
12432
+ rebase: void 0,
12433
+ build: createSummaryBuild(root, root.queryPlan, scopes, instrumentation),
12434
+ cancel: void 0
12435
+ };
12436
+ summaryAcquisition = pending;
12437
+ const advance = () => {
12438
+ if (disposed || summaryAcquisition !== pending) return;
12439
+ if (pending.rebase !== void 0) {
12440
+ pending.build = createSummaryBuild(pending.rebase, pending.plan, requestedSummaryScopes(), instrumentation);
12441
+ pending.rebase = void 0;
12442
+ }
12443
+ if (runCooperativeTransitionSlice(transitionRuntime, () => pending.build.step())) {
12444
+ const previous = root;
12445
+ const next = Object.freeze({
12446
+ ...root,
12447
+ revision: root.revision + 1,
12448
+ parentRevision: root.revision,
12449
+ summaries: retainSummaryScopes(pending.build.finish(), requestedSummaryScopes())
12450
+ });
12451
+ summaryAcquisition = void 0;
12452
+ appendTransitionDelta(next, []);
12453
+ commit(next);
12454
+ changeJournal.appendChanges(previous.revision, next.revision, Object.freeze([]));
12455
+ } else pending.cancel = transitionRuntime.scheduler.schedule(() => {
12456
+ if (disposed || summaryAcquisition !== pending) return;
12457
+ try {
12458
+ guarded("set-derivations", advance);
12459
+ } catch (error) {
12460
+ cancelSummaryAcquisition();
12461
+ reportSummaryFailure(error);
12462
+ }
12463
+ notify();
12464
+ });
12465
+ };
12466
+ try {
12467
+ advance();
12468
+ } catch (error) {
12469
+ try {
12470
+ var _pending$cancel2;
12471
+ (_pending$cancel2 = pending.cancel) === null || _pending$cancel2 === void 0 || _pending$cancel2.call(pending);
12472
+ } catch (_unused8) {}
12473
+ summaryAcquisition = previousAcquisition;
12474
+ throw error;
12475
+ }
12476
+ try {
12477
+ var _previousAcquisition$;
12478
+ previousAcquisition === null || previousAcquisition === void 0 || (_previousAcquisition$ = previousAcquisition.cancel) === null || _previousAcquisition$ === void 0 || _previousAcquisition$.call(previousAcquisition);
12479
+ } catch (_unused9) {}
12480
+ };
12215
12481
  const model = {
12216
12482
  getState: () => state,
12217
12483
  getColumns: () => columns,
12484
+ acquireSummaryScopes(scopes) {
12485
+ assertCommandAllowed("set-derivations");
12486
+ const unique = [...new Set(scopes)];
12487
+ if (unique.some((scope) => scope !== "all" && scope !== "filtered")) throw new TypeError("Unknown summary scope.");
12488
+ guarded("set-derivations", () => {
12489
+ var _summaryLeases$get2;
12490
+ for (const scope of unique) summaryLeases.set(scope, ((_summaryLeases$get2 = summaryLeases.get(scope)) !== null && _summaryLeases$get2 !== void 0 ? _summaryLeases$get2 : 0) + 1);
12491
+ try {
12492
+ restartSummaryAcquisition();
12493
+ } catch (error) {
12494
+ for (const scope of unique) summaryLeases.set(scope, summaryLeases.get(scope) - 1);
12495
+ throw error;
12496
+ }
12497
+ });
12498
+ notify();
12499
+ let released = false;
12500
+ return () => {
12501
+ if (released || disposed) return;
12502
+ guarded("set-derivations", () => {
12503
+ released = true;
12504
+ for (const scope of unique) summaryLeases.set(scope, summaryLeases.get(scope) - 1);
12505
+ const retained = retainSummaryScopes(root.summaries, requestedSummaryScopes());
12506
+ commit(Object.freeze({
12507
+ ...root,
12508
+ summaries: retained
12509
+ }));
12510
+ const requested = requestedSummaryScopes();
12511
+ if (summaryAcquisition) {
12512
+ summaryAcquisition.build.retainScopes(requested);
12513
+ summaryAcquisition.key = requested.join(",");
12514
+ if (requested.every((scope) => {
12515
+ var _root$summaries2;
12516
+ return ((_root$summaries2 = root.summaries) === null || _root$summaries2 === void 0 ? void 0 : _root$summaries2.results[scope]) !== void 0;
12517
+ })) cancelSummaryAcquisition();
12518
+ } else if (requested.some((scope) => {
12519
+ var _root$summaries3;
12520
+ return ((_root$summaries3 = root.summaries) === null || _root$summaries3 === void 0 ? void 0 : _root$summaries3.results[scope]) === void 0;
12521
+ })) try {
12522
+ cancelSummaryRetry === null || cancelSummaryRetry === void 0 || cancelSummaryRetry();
12523
+ cancelSummaryRetry = transitionRuntime.scheduler.schedule(() => {
12524
+ cancelSummaryRetry = void 0;
12525
+ if (disposed) return;
12526
+ try {
12527
+ guarded("set-derivations", restartSummaryAcquisition);
12528
+ } catch (error) {
12529
+ reportSummaryFailure(error);
12530
+ }
12531
+ notify();
12532
+ });
12533
+ } catch (error) {
12534
+ reportSummaryFailure(error);
12535
+ }
12536
+ });
12537
+ notify();
12538
+ };
12539
+ },
12218
12540
  subscribe(listener) {
12219
12541
  if (disposed) return () => void 0;
12220
12542
  listeners.add(listener);
@@ -12282,6 +12604,7 @@ function createLocalRowModel$1(options) {
12282
12604
  revision: previousRevision + 1,
12283
12605
  parentRevision: previousRevision,
12284
12606
  rows: drafted.rows,
12607
+ summaries: drafted.summaries,
12285
12608
  sourceOrder: drafted.sourceOrder,
12286
12609
  recordsBySlot: drafted.recordsBySlot,
12287
12610
  slotCapacity: slots.capacity,
@@ -12334,6 +12657,7 @@ function createLocalRowModel$1(options) {
12334
12657
  revision: result.revision,
12335
12658
  parentRevision: previousRoot.revision,
12336
12659
  rows: drafted.rows,
12660
+ summaries: drafted.summaries,
12337
12661
  sourceOrder: drafted.sourceOrder,
12338
12662
  recordsBySlot: drafted.recordsBySlot,
12339
12663
  slotCapacity: slots.capacity,
@@ -12387,7 +12711,7 @@ function createLocalRowModel$1(options) {
12387
12711
  };
12388
12712
  }
12389
12713
  const residentRowCount = root.rows.size;
12390
- const fastPath = nextPlan.query.rowGroups.length > 0 ? void 0 : isSortOnlyChange(queryPlan, nextPlan) ? residentRowCount <= sortFastPathRowLimit ? Object.freeze({
12714
+ const fastPath = nextPlan.query.rowGroups.length > 0 || requestedSummaryScopes().length > 0 ? void 0 : isSortOnlyChange(queryPlan, nextPlan) ? residentRowCount <= sortFastPathRowLimit ? Object.freeze({
12391
12715
  rebuild: rebuildRootForSortOnlyChange,
12392
12716
  barrierReason: "reorder"
12393
12717
  }) : void 0 : isFilterOnlyChange(queryPlan, nextPlan) ? residentRowCount <= filterFastPathRowLimit ? Object.freeze({
@@ -12582,6 +12906,8 @@ function createLocalRowModel$1(options) {
12582
12906
  if (activeMutation !== void 0) throw new PretableReentrantMutationError("dispose", activeMutation);
12583
12907
  if (disposed) return;
12584
12908
  const current = guarded("dispose", () => {
12909
+ cancelSummaryAcquisition();
12910
+ summaryLeases.clear();
12585
12911
  cancelActiveTransition("disposed");
12586
12912
  distinctValues.dispose(new PretableDisposedModelError("distinct-values"));
12587
12913
  changeJournal.clear();
@@ -12597,7 +12923,7 @@ function createLocalRowModel$1(options) {
12597
12923
  });
12598
12924
  for (const listener of current) try {
12599
12925
  listener();
12600
- } catch (_unused6) {}
12926
+ } catch (_unused10) {}
12601
12927
  }
12602
12928
  };
12603
12929
  modelChangeJournals.set(model, changeJournal);
@@ -12622,8 +12948,7 @@ function createLocalRowModel$1(options) {
12622
12948
  return model;
12623
12949
  }
12624
12950
 
12625
- //#endregion
12626
- //#region ../row-model/dist/aggregate-overrides.js
12951
+ // ../row-model/dist/aggregate-overrides.js
12627
12952
  /**
12628
12953
  * Per-column aggregate OVERRIDES, applied to a derivation list.
12629
12954
  *
@@ -12709,13 +13034,11 @@ function mergeColumnAggregateOverrides(derivations, overrides) {
12709
13034
  return changed ? merged : derivations;
12710
13035
  }
12711
13036
 
12712
- //#endregion
12713
- //#region ../row-model/dist/aggregator-law.js
13037
+ // ../row-model/dist/aggregator-law.js
12714
13038
  const DEVELOPMENT = process.env.NODE_ENV !== "production";
12715
13039
  const productionValidator = Object.freeze({ observe: () => void 0 });
12716
13040
 
12717
- //#endregion
12718
- //#region src/create-column-helper.ts
13041
+ // src/create-column-helper.ts
12719
13042
  /**
12720
13043
  * Creates a typed column-definition helper for an ordinary row object.
12721
13044
  *
@@ -12725,14 +13048,12 @@ function createColumnHelper() {
12725
13048
  return createColumnHelper$1();
12726
13049
  }
12727
13050
 
12728
- //#endregion
12729
- //#region src/create-local-row-model.ts
13051
+ // src/create-local-row-model.ts
12730
13052
  function createLocalRowModel(options) {
12731
13053
  return createLocalRowModel$1(options);
12732
13054
  }
12733
13055
 
12734
- //#endregion
12735
- //#region src/number-formats.ts
13056
+ // src/number-formats.ts
12736
13057
  function currencyOptions(options, currencySign) {
12737
13058
  return {
12738
13059
  ...options,
@@ -12755,6 +13076,5 @@ const numberFormats = {
12755
13076
  }
12756
13077
  };
12757
13078
 
12758
- //#endregion
12759
13079
  export { GROUP_COLUMN_ID, PretableDisposedModelError, PretableInvalidGroupKeyError, PretableReentrantMutationError, PretableRowIdentityChangeError, PretableRowModelError, PretableTransitionCancelledError, PretableUnsupportedRowUpdateError, createColumnHelper, createGrid, createLocalRowModel, describeRowSelection, isPretableFilterGroup, isValidDateValue, mergeColumnAggregateOverrides, numberFormats, HEADER_FOCUS_REF as ɵHEADER_FOCUS_REF, createGridUiCore as ɵcreateGridUiCore, getIndexedCellSelectionSummary as ɵgetIndexedCellSelectionSummary, indexedRangeContainsCell as ɵindexedRangeContainsCell, ɵsetLocalRowModelFilterAuthority, ɵsetLocalRowModelSortAuthority };
12760
13080
  //# sourceMappingURL=index.mjs.map