@rocicorp/zero 1.12.0-canary.10 → 1.12.0-canary.11

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 (218) hide show
  1. package/out/analyze-query/src/zql-chain.js +9 -1
  2. package/out/analyze-query/src/zql-chain.js.map +1 -1
  3. package/out/ast-to-zql/src/ast-to-zql.d.ts.map +1 -1
  4. package/out/ast-to-zql/src/ast-to-zql.js +61 -20
  5. package/out/ast-to-zql/src/ast-to-zql.js.map +1 -1
  6. package/out/z2s/src/compiler.d.ts +1 -1
  7. package/out/z2s/src/compiler.d.ts.map +1 -1
  8. package/out/z2s/src/compiler.js +339 -2
  9. package/out/z2s/src/compiler.js.map +1 -1
  10. package/out/z2s/src/sql.d.ts +8 -0
  11. package/out/z2s/src/sql.d.ts.map +1 -1
  12. package/out/z2s/src/sql.js +58 -11
  13. package/out/z2s/src/sql.js.map +1 -1
  14. package/out/zero/package.js +1 -1
  15. package/out/zero/package.js.map +1 -1
  16. package/out/zero/src/bindings.js +4 -4
  17. package/out/zero-cache/src/auth/write-authorizer.js +1 -1
  18. package/out/zero-cache/src/config/zero-config.d.ts +4 -0
  19. package/out/zero-cache/src/config/zero-config.d.ts.map +1 -1
  20. package/out/zero-cache/src/config/zero-config.js +13 -0
  21. package/out/zero-cache/src/config/zero-config.js.map +1 -1
  22. package/out/zero-cache/src/db/create.js +1 -1
  23. package/out/zero-cache/src/scripts/decommission.js +1 -1
  24. package/out/zero-cache/src/server/runner/run-worker.d.ts.map +1 -1
  25. package/out/zero-cache/src/server/runner/run-worker.js +8 -5
  26. package/out/zero-cache/src/server/runner/run-worker.js.map +1 -1
  27. package/out/zero-cache/src/services/change-source/pg/backfill-stream.js +1 -1
  28. package/out/zero-cache/src/services/change-source/pg/initial-sync.js +1 -1
  29. package/out/zero-cache/src/services/change-source/pg/logical-replication/stream.js +1 -1
  30. package/out/zero-cache/src/services/change-source/pg/schema/ddl.js +1 -1
  31. package/out/zero-cache/src/services/change-source/pg/schema/init.js +1 -1
  32. package/out/zero-cache/src/services/change-source/pg/schema/shard.js +1 -1
  33. package/out/zero-cache/src/services/http-service.d.ts +6 -0
  34. package/out/zero-cache/src/services/http-service.d.ts.map +1 -1
  35. package/out/zero-cache/src/services/http-service.js +13 -1
  36. package/out/zero-cache/src/services/http-service.js.map +1 -1
  37. package/out/zero-cache/src/services/life-cycle.d.ts +19 -0
  38. package/out/zero-cache/src/services/life-cycle.d.ts.map +1 -1
  39. package/out/zero-cache/src/services/life-cycle.js +53 -1
  40. package/out/zero-cache/src/services/life-cycle.js.map +1 -1
  41. package/out/zero-cache/src/services/replicator/change-processor.js +1 -1
  42. package/out/zero-cache/src/services/view-syncer/pipeline-driver.js +100 -12
  43. package/out/zero-cache/src/services/view-syncer/pipeline-driver.js.map +1 -1
  44. package/out/zero-cache/src/services/view-syncer/query-covering.js +2 -2
  45. package/out/zero-cache/src/services/view-syncer/query-covering.js.map +1 -1
  46. package/out/zero-cache/src/services/view-syncer/snapshotter.js +1 -1
  47. package/out/zero-cache/src/types/processes.js +4 -4
  48. package/out/zero-cache/src/types/processes.js.map +1 -1
  49. package/out/zero-cache/src/types/row-key.js +8 -1
  50. package/out/zero-cache/src/types/row-key.js.map +1 -1
  51. package/out/zero-cache/src/workers/connection.js +2 -2
  52. package/out/zero-client/src/client/bindings.d.ts +1 -1
  53. package/out/zero-client/src/client/bindings.d.ts.map +1 -1
  54. package/out/zero-client/src/client/bindings.js +4 -4
  55. package/out/zero-client/src/client/context.d.ts +7 -1
  56. package/out/zero-client/src/client/context.d.ts.map +1 -1
  57. package/out/zero-client/src/client/context.js +7 -0
  58. package/out/zero-client/src/client/context.js.map +1 -1
  59. package/out/zero-client/src/client/crud-impl.d.ts.map +1 -1
  60. package/out/zero-client/src/client/crud-impl.js +171 -2
  61. package/out/zero-client/src/client/crud-impl.js.map +1 -1
  62. package/out/zero-client/src/client/custom.d.ts.map +1 -1
  63. package/out/zero-client/src/client/custom.js +42 -3
  64. package/out/zero-client/src/client/custom.js.map +1 -1
  65. package/out/zero-client/src/client/ivm-branch.d.ts +62 -2
  66. package/out/zero-client/src/client/ivm-branch.d.ts.map +1 -1
  67. package/out/zero-client/src/client/ivm-branch.js +152 -31
  68. package/out/zero-client/src/client/ivm-branch.js.map +1 -1
  69. package/out/zero-client/src/client/keys.d.ts +33 -0
  70. package/out/zero-client/src/client/keys.d.ts.map +1 -1
  71. package/out/zero-client/src/client/keys.js +43 -4
  72. package/out/zero-client/src/client/keys.js.map +1 -1
  73. package/out/zero-client/src/client/version.js +1 -1
  74. package/out/zero-client/src/client/zero-poke-handler.d.ts.map +1 -1
  75. package/out/zero-client/src/client/zero-poke-handler.js +29 -1
  76. package/out/zero-client/src/client/zero-poke-handler.js.map +1 -1
  77. package/out/zero-client/src/client/zero-rep.d.ts +1 -1
  78. package/out/zero-client/src/client/zero-rep.d.ts.map +1 -1
  79. package/out/zero-client/src/client/zero-rep.js +2 -15
  80. package/out/zero-client/src/client/zero-rep.js.map +1 -1
  81. package/out/zero-client/src/client/zero.js +1 -1
  82. package/out/zero-client/src/mod.d.ts +3 -3
  83. package/out/zero-client/src/mod.d.ts.map +1 -1
  84. package/out/zero-protocol/src/aggregate-table.d.ts +15 -0
  85. package/out/zero-protocol/src/aggregate-table.d.ts.map +1 -0
  86. package/out/zero-protocol/src/aggregate-table.js +5 -0
  87. package/out/zero-protocol/src/aggregate-table.js.map +1 -0
  88. package/out/zero-protocol/src/ast.d.ts +141 -5
  89. package/out/zero-protocol/src/ast.d.ts.map +1 -1
  90. package/out/zero-protocol/src/ast.js +244 -18
  91. package/out/zero-protocol/src/ast.js.map +1 -1
  92. package/out/zero-protocol/src/down.d.ts +29 -29
  93. package/out/zero-protocol/src/inspect-down.d.ts +81 -81
  94. package/out/zero-protocol/src/protocol-version.d.ts +1 -1
  95. package/out/zero-protocol/src/protocol-version.d.ts.map +1 -1
  96. package/out/zero-protocol/src/protocol-version.js.map +1 -1
  97. package/out/zero-protocol/src/query-hash-visitor.d.ts.map +1 -1
  98. package/out/zero-protocol/src/query-hash-visitor.js +38 -0
  99. package/out/zero-protocol/src/query-hash-visitor.js.map +1 -1
  100. package/out/zero-react/src/bindings.js +4 -4
  101. package/out/zero-react/src/use-query.d.ts +3 -1
  102. package/out/zero-react/src/use-query.d.ts.map +1 -1
  103. package/out/zero-react/src/use-query.js +4 -2
  104. package/out/zero-react/src/use-query.js.map +1 -1
  105. package/out/zero-schema/src/builder/schema-builder.d.ts.map +1 -1
  106. package/out/zero-schema/src/builder/schema-builder.js +2 -0
  107. package/out/zero-schema/src/builder/schema-builder.js.map +1 -1
  108. package/out/zero-schema/src/name-mapper.d.ts.map +1 -1
  109. package/out/zero-schema/src/name-mapper.js +7 -4
  110. package/out/zero-schema/src/name-mapper.js.map +1 -1
  111. package/out/zero-server/src/custom.js +1 -1
  112. package/out/zero-server/src/schema.d.ts.map +1 -1
  113. package/out/zero-server/src/schema.js +13 -2
  114. package/out/zero-server/src/schema.js.map +1 -1
  115. package/out/zero-solid/src/bindings.js +4 -4
  116. package/out/zero-solid/src/solid-view.d.ts.map +1 -1
  117. package/out/zero-solid/src/solid-view.js +3 -3
  118. package/out/zero-solid/src/solid-view.js.map +1 -1
  119. package/out/zero-types/src/format.d.ts +13 -0
  120. package/out/zero-types/src/format.d.ts.map +1 -1
  121. package/out/zero-types/src/format.js.map +1 -1
  122. package/out/zero-types/src/name-mapper.d.ts +14 -0
  123. package/out/zero-types/src/name-mapper.d.ts.map +1 -1
  124. package/out/zero-types/src/name-mapper.js +12 -0
  125. package/out/zero-types/src/name-mapper.js.map +1 -1
  126. package/out/zero-types/src/schema-value.d.ts +2 -0
  127. package/out/zero-types/src/schema-value.d.ts.map +1 -1
  128. package/out/zero-types/src/schema-value.js +15 -0
  129. package/out/zero-types/src/schema-value.js.map +1 -0
  130. package/out/zero-types/src/server-schema.d.ts +18 -0
  131. package/out/zero-types/src/server-schema.d.ts.map +1 -1
  132. package/out/zql/src/builder/builder.d.ts +126 -1
  133. package/out/zql/src/builder/builder.d.ts.map +1 -1
  134. package/out/zql/src/builder/builder.js +281 -11
  135. package/out/zql/src/builder/builder.js.map +1 -1
  136. package/out/zql/src/builder/filter.d.ts +1 -1
  137. package/out/zql/src/builder/filter.d.ts.map +1 -1
  138. package/out/zql/src/builder/filter.js +41 -3
  139. package/out/zql/src/builder/filter.js.map +1 -1
  140. package/out/zql/src/ivm/aggregate.d.ts +188 -0
  141. package/out/zql/src/ivm/aggregate.d.ts.map +1 -0
  142. package/out/zql/src/ivm/aggregate.js +470 -0
  143. package/out/zql/src/ivm/aggregate.js.map +1 -0
  144. package/out/zql/src/ivm/array-view.d.ts +1 -1
  145. package/out/zql/src/ivm/array-view.d.ts.map +1 -1
  146. package/out/zql/src/ivm/array-view.js +3 -3
  147. package/out/zql/src/ivm/array-view.js.map +1 -1
  148. package/out/zql/src/ivm/cap.js +2 -2
  149. package/out/zql/src/ivm/constraint.d.ts.map +1 -1
  150. package/out/zql/src/ivm/constraint.js +2 -1
  151. package/out/zql/src/ivm/constraint.js.map +1 -1
  152. package/out/zql/src/ivm/deferred-input.js +1 -1
  153. package/out/zql/src/ivm/fan-in.js +1 -1
  154. package/out/zql/src/ivm/flipped-join.d.ts.map +1 -1
  155. package/out/zql/src/ivm/flipped-join.js +3 -2
  156. package/out/zql/src/ivm/flipped-join.js.map +1 -1
  157. package/out/zql/src/ivm/group-by.d.ts +98 -0
  158. package/out/zql/src/ivm/group-by.d.ts.map +1 -0
  159. package/out/zql/src/ivm/group-by.js +384 -0
  160. package/out/zql/src/ivm/group-by.js.map +1 -0
  161. package/out/zql/src/ivm/join-index.d.ts.map +1 -1
  162. package/out/zql/src/ivm/join-index.js +2 -1
  163. package/out/zql/src/ivm/join-index.js.map +1 -1
  164. package/out/zql/src/ivm/join-utils.d.ts.map +1 -1
  165. package/out/zql/src/ivm/join-utils.js +2 -1
  166. package/out/zql/src/ivm/join-utils.js.map +1 -1
  167. package/out/zql/src/ivm/join.js +1 -1
  168. package/out/zql/src/ivm/lift-field.d.ts +54 -0
  169. package/out/zql/src/ivm/lift-field.d.ts.map +1 -0
  170. package/out/zql/src/ivm/lift-field.js +168 -0
  171. package/out/zql/src/ivm/lift-field.js.map +1 -0
  172. package/out/zql/src/ivm/maybe-split-and-push-edit-change.js +1 -1
  173. package/out/zql/src/ivm/memory-source.d.ts +2 -0
  174. package/out/zql/src/ivm/memory-source.d.ts.map +1 -1
  175. package/out/zql/src/ivm/memory-source.js +9 -4
  176. package/out/zql/src/ivm/memory-source.js.map +1 -1
  177. package/out/zql/src/ivm/push-accumulated.js +1 -1
  178. package/out/zql/src/ivm/schema.d.ts +1 -0
  179. package/out/zql/src/ivm/schema.d.ts.map +1 -1
  180. package/out/zql/src/ivm/source.d.ts +21 -0
  181. package/out/zql/src/ivm/source.d.ts.map +1 -1
  182. package/out/zql/src/ivm/source.js.map +1 -1
  183. package/out/zql/src/ivm/take.js +1 -1
  184. package/out/zql/src/ivm/union-fan-in.js +1 -1
  185. package/out/zql/src/ivm/view-apply-change.d.ts +5 -0
  186. package/out/zql/src/ivm/view-apply-change.d.ts.map +1 -1
  187. package/out/zql/src/ivm/view-apply-change.js +23 -3
  188. package/out/zql/src/ivm/view-apply-change.js.map +1 -1
  189. package/out/zql/src/planner/planner-debug.d.ts +1 -1
  190. package/out/zql/src/planner/planner-debug.d.ts.map +1 -1
  191. package/out/zql/src/planner/planner-debug.js +4 -0
  192. package/out/zql/src/planner/planner-debug.js.map +1 -1
  193. package/out/zql/src/query/expression.d.ts +50 -3
  194. package/out/zql/src/query/expression.d.ts.map +1 -1
  195. package/out/zql/src/query/expression.js +62 -6
  196. package/out/zql/src/query/expression.js.map +1 -1
  197. package/out/zql/src/query/measure-push-operator.js +1 -1
  198. package/out/zql/src/query/query-delegate-base.d.ts +8 -0
  199. package/out/zql/src/query/query-delegate-base.d.ts.map +1 -1
  200. package/out/zql/src/query/query-delegate-base.js +13 -5
  201. package/out/zql/src/query/query-delegate-base.js.map +1 -1
  202. package/out/zql/src/query/query-impl.d.ts +17 -3
  203. package/out/zql/src/query/query-impl.d.ts.map +1 -1
  204. package/out/zql/src/query/query-impl.js +239 -7
  205. package/out/zql/src/query/query-impl.js.map +1 -1
  206. package/out/zql/src/query/query.d.ts +319 -7
  207. package/out/zql/src/query/query.d.ts.map +1 -1
  208. package/out/zqlite/src/pending-delta.d.ts.map +1 -1
  209. package/out/zqlite/src/pending-delta.js +4 -3
  210. package/out/zqlite/src/pending-delta.js.map +1 -1
  211. package/out/zqlite/src/query-builder.d.ts +12 -1
  212. package/out/zqlite/src/query-builder.d.ts.map +1 -1
  213. package/out/zqlite/src/query-builder.js +114 -13
  214. package/out/zqlite/src/query-builder.js.map +1 -1
  215. package/out/zqlite/src/table-source.d.ts.map +1 -1
  216. package/out/zqlite/src/table-source.js +37 -3
  217. package/out/zqlite/src/table-source.js.map +1 -1
  218. package/package.json +1 -1
@@ -2,20 +2,23 @@ import { assert, unreachable } from "../../../../shared/src/asserts.js";
2
2
  import { deepEqual } from "../../../../shared/src/json.js";
3
3
  import { getOrInsertComputed } from "../../../../shared/src/map.js";
4
4
  import { must } from "../../../../shared/src/must.js";
5
+ import { h32 } from "../../../../shared/src/hash.js";
5
6
  import { assignProperty } from "../../../../shared/src/objects.js";
6
7
  import { skipYields } from "../../../../zql/src/ivm/skip-yields.js";
7
8
  import { throwOutput } from "../../../../zql/src/ivm/operator.js";
8
9
  import { MeasurePushOperator } from "../../../../zql/src/query/measure-push-operator.js";
9
10
  import { makeSourceChangeAdd, makeSourceChangeEdit, makeSourceChangeRemove } from "../../../../zql/src/ivm/source.js";
10
- import { buildPipeline } from "../../../../zql/src/builder/builder.js";
11
+ import { buildPipeline, isAggregateTableName, topLevelAggregateTableName } from "../../../../zql/src/builder/builder.js";
12
+ import { stringify } from "../../../../shared/src/bigint-json.js";
11
13
  import { Debug, runtimeDebugFlags } from "../../../../zql/src/builder/debug-delegate.js";
12
14
  import { TableSource } from "../../../../zqlite/src/table-source.js";
13
15
  import { randInt } from "../../../../shared/src/rand.js";
14
16
  import { getOrCreateCounter, getOrCreateLatencyHistogram } from "../../observability/metrics.js";
15
17
  import { ZERO_VERSION_COLUMN_NAME } from "../replicator/schema/constants.js";
16
18
  import { computeZqlSpecs, mustGetTableSpec } from "../../db/lite-tables.js";
17
- import "../../types/row-key.js";
19
+ import { rowKeyString } from "../../types/row-key.js";
18
20
  import { getSubscriptionState } from "../replicator/schema/replication-state.js";
21
+ import { versionToLexi } from "../../types/lexi-version.js";
19
22
  import { reloadPermissionsIfChanged } from "../../auth/load-permissions.js";
20
23
  import { resolveSimpleScalarSubqueries } from "../../../../zqlite/src/resolve-scalar-subqueries.js";
21
24
  import { createSQLiteCostModel } from "../../../../zqlite/src/sqlite-cost-model.js";
@@ -82,6 +85,13 @@ function formatAdvancementBreakdown(advanceContext, elapsed) {
82
85
  */
83
86
  var PipelineDriver = class {
84
87
  #tables = /* @__PURE__ */ new Map();
88
+ /**
89
+ * The latest synthetic aggregate row streamed for each key, by synthetic
90
+ * table. Aggregate tables have no {@link TableSource}, so this is what
91
+ * {@link getRow} reads for them when the view-syncer rebuilds a put patch on
92
+ * client catch-up. Entries live as long as the query that produced them.
93
+ */
94
+ #aggregateRows = /* @__PURE__ */ new Map();
85
95
  #pipelines = /* @__PURE__ */ new Map();
86
96
  /**
87
97
  * XOR signature of the set of rows currently attached to each active
@@ -196,6 +206,7 @@ var PipelineDriver = class {
196
206
  this.#abandoned.clear();
197
207
  this.#costBasedAdvanceIncomplete = false;
198
208
  this.#tables.clear();
209
+ this.#aggregateRows.clear();
199
210
  this.#allTableNames.clear();
200
211
  this.#rowSetSignatures.clear();
201
212
  this.#changedRowSetSignatures.clear();
@@ -211,7 +222,7 @@ var PipelineDriver = class {
211
222
  for (const table of fullTables.keys()) this.#allTableNames.add(table);
212
223
  const primaryKeys = buildRowKeys(clientSchema, this.#tableSpecs, this.#primaryKeys ?? void 0);
213
224
  this.#primaryKeys = primaryKeys;
214
- this.#streamer ??= new Streamer(primaryKeys, this.#tableSpecs);
225
+ this.#streamer ??= new Streamer(primaryKeys, this.#tableSpecs, () => this.currentVersion(), this.#aggregateRows);
215
226
  const { replicaVersion } = getSubscriptionState(db);
216
227
  this.#replicaVersion = replicaVersion;
217
228
  }
@@ -282,6 +293,7 @@ var PipelineDriver = class {
282
293
  this.#destroyPipeline(queryID, pipeline, "destroy");
283
294
  }
284
295
  this.#tables.clear();
296
+ this.#aggregateRows.clear();
285
297
  this.#rowSetSignatures.clear();
286
298
  this.#changedRowSetSignatures.clear();
287
299
  this.#storage.destroy();
@@ -672,6 +684,12 @@ var PipelineDriver = class {
672
684
  }
673
685
  this.#rowSetSignatures.delete(queryID);
674
686
  this.#changedRowSetSignatures.delete(queryID);
687
+ const topLevel = topLevelAggregateTableName(queryID);
688
+ const prefix = topLevel + ":";
689
+ for (const [table, byKey] of this.#aggregateRows) if (table === topLevel || table.startsWith(prefix)) {
690
+ if (stopReason === "remove-query") this.#aggregateRows.delete(table);
691
+ else for (const entry of byKey.values()) entry.refs = 0;
692
+ }
675
693
  if (stopReason !== "replace-query") this.#abandoned.delete(queryID);
676
694
  if (stopReason === "remove-query") this.#pushCosts.forget(queryID);
677
695
  }
@@ -748,6 +766,7 @@ var PipelineDriver = class {
748
766
  */
749
767
  getRow(table, pk) {
750
768
  assert(this.initialized(), "Not yet initialized");
769
+ if (isAggregateTableName(table)) return this.#aggregateRows.get(table)?.get(rowKeyString(pk))?.row;
751
770
  return must(this.#tables.get(table)).getRow(pk);
752
771
  }
753
772
  /**
@@ -1386,9 +1405,15 @@ var PipelineDriver = class {
1386
1405
  var Streamer = class {
1387
1406
  #primaryKeys;
1388
1407
  #tableSpecs;
1389
- constructor(primaryKeys, tableSpecs) {
1408
+ #version;
1409
+ #aggregateRows;
1410
+ #stampVersion;
1411
+ #stampCount = 0;
1412
+ constructor(primaryKeys, tableSpecs, version, aggregateRows) {
1390
1413
  this.#primaryKeys = primaryKeys;
1391
1414
  this.#tableSpecs = tableSpecs;
1415
+ this.#version = version;
1416
+ this.#aggregateRows = aggregateRows;
1392
1417
  }
1393
1418
  /** The row changes for a change pushed out of the pipeline of `queryID`. */
1394
1419
  *streamChange(queryID, schema, change) {
@@ -1417,8 +1442,9 @@ var Streamer = class {
1417
1442
  *streamNodes(queryID, schema, op, nodes) {
1418
1443
  const { tableName: table, system } = schema;
1419
1444
  if (system === "permissions") return;
1420
- const primaryKey = must(this.#primaryKeys.get(table));
1421
- const spec = must(this.#tableSpecs.get(table)).tableSpec;
1445
+ const isAggregate = schema.isAggregate ?? false;
1446
+ const primaryKey = isAggregate ? schema.primaryKey : must(this.#primaryKeys.get(table));
1447
+ const minRowVersion = isAggregate ? void 0 : must(this.#tableSpecs.get(table)).tableSpec.minRowVersion;
1422
1448
  for (const node of nodes) {
1423
1449
  if (node === "yield") {
1424
1450
  yield node;
@@ -1428,12 +1454,16 @@ var Streamer = class {
1428
1454
  let { row } = node;
1429
1455
  const rowKey = getRowKey(primaryKey, row);
1430
1456
  if (op !== 1) {
1431
- const rowVersion = row[ZERO_VERSION_COLUMN_NAME];
1432
- if (typeof rowVersion === "string" && rowVersion < (spec.minRowVersion ?? "00")) row = {
1433
- ...row,
1434
- [ZERO_VERSION_COLUMN_NAME]: spec.minRowVersion
1435
- };
1457
+ if (isAggregate) row = this.#stampAggregateRow(table, rowKey, row, op);
1458
+ else {
1459
+ const rowVersion = row[ZERO_VERSION_COLUMN_NAME];
1460
+ if (typeof rowVersion === "string" && rowVersion < (minRowVersion ?? "00")) row = {
1461
+ ...row,
1462
+ [ZERO_VERSION_COLUMN_NAME]: minRowVersion
1463
+ };
1464
+ }
1436
1465
  }
1466
+ if (op === 1 && isAggregate) this.#releaseAggregateRow(table, rowKeyString(rowKey));
1437
1467
  yield {
1438
1468
  type: op,
1439
1469
  queryID,
@@ -1447,6 +1477,64 @@ var Streamer = class {
1447
1477
  }
1448
1478
  }
1449
1479
  }
1480
+ /**
1481
+ * Stamps a synthetic aggregate row with the replica state version and
1482
+ * remembers it for {@link PipelineDriver.getRow}.
1483
+ *
1484
+ * The CVR only sends a put whose version is strictly greater than the last
1485
+ * one it sent for that row, and the rows of one advance reach it in pages.
1486
+ * An aggregate row is emitted once per changed child, so a stamp is the
1487
+ * replica version plus a count of the stamps made at it, which keeps a row's
1488
+ * stamps strictly increasing however often it is removed and re-added. The
1489
+ * count is a LexiVersion, and a LexiVersion is never a proper prefix of a
1490
+ * later one, so the stamp stays below the next replica version.
1491
+ *
1492
+ * The CVR also takes an equal version to mean equal contents, but the count
1493
+ * starts over in a new process, so the stamp ends in a hash of the contents.
1494
+ */
1495
+ #stampAggregateRow(table, rowKey, row, op) {
1496
+ const key = rowKeyString(rowKey);
1497
+ const version = this.#version();
1498
+ if (version !== this.#stampVersion) {
1499
+ this.#stampVersion = version;
1500
+ this.#stampCount = 0;
1501
+ }
1502
+ const count = versionToLexi(this.#stampCount++);
1503
+ const hash = h32(stringify(row)).toString(36);
1504
+ const stamped = {
1505
+ ...row,
1506
+ [ZERO_VERSION_COLUMN_NAME]: `${version}.${count}.${hash}`
1507
+ };
1508
+ this.#rememberAggregateRow(table, key, stamped, op === 0);
1509
+ return stamped;
1510
+ }
1511
+ #rememberAggregateRow(table, key, row, add) {
1512
+ const rows = this.#aggregateRows;
1513
+ if (!rows) return;
1514
+ let byKey = rows.get(table);
1515
+ if (!byKey) {
1516
+ byKey = /* @__PURE__ */ new Map();
1517
+ rows.set(table, byKey);
1518
+ }
1519
+ const entry = byKey.get(key);
1520
+ if (entry) {
1521
+ entry.row = row;
1522
+ entry.refs += add ? 1 : 0;
1523
+ } else byKey.set(key, {
1524
+ row,
1525
+ refs: add ? 1 : 0
1526
+ });
1527
+ }
1528
+ /**
1529
+ * Drops one reference to an aggregate row. Parents that share a correlation
1530
+ * value share the row, so it is forgotten only when the last one is removed,
1531
+ * as the CVR counts it.
1532
+ */
1533
+ #releaseAggregateRow(table, key) {
1534
+ const byKey = this.#aggregateRows?.get(table);
1535
+ const entry = byKey?.get(key);
1536
+ if (entry && --entry.refs <= 0) byKey?.delete(key);
1537
+ }
1450
1538
  };
1451
1539
  var QueryFailureLoggingOperator = class {
1452
1540
  #lc;
@@ -1530,7 +1618,7 @@ function isKeyedBy(rowKey, primaryKey) {
1530
1618
  * of a table outside `clientSchema` are keyed by its key in the replica.
1531
1619
  */
1532
1620
  function hydrate(input, hash, clientSchema, tableSpecs) {
1533
- return new Streamer(buildRowKeys(clientSchema, tableSpecs), tableSpecs).streamNodes(hash, input.getSchema(), 0, input.fetch({}));
1621
+ return new Streamer(buildRowKeys(clientSchema, tableSpecs), tableSpecs, () => "00").streamNodes(hash, input.getSchema(), 0, input.fetch({}));
1534
1622
  }
1535
1623
  /**
1536
1624
  * Returns the value of `childField` in the row of `input`, the pipeline of a