@rocicorp/zero 0.26.0-canary.7 → 0.26.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.
Files changed (276) hide show
  1. package/out/ast-to-zql/src/ast-to-zql.d.ts.map +1 -1
  2. package/out/ast-to-zql/src/ast-to-zql.js +16 -27
  3. package/out/ast-to-zql/src/ast-to-zql.js.map +1 -1
  4. package/out/otel/src/log-options.d.ts +2 -2
  5. package/out/replicache/src/bg-interval.d.ts.map +1 -1
  6. package/out/replicache/src/bg-interval.js +3 -0
  7. package/out/replicache/src/bg-interval.js.map +1 -1
  8. package/out/shared/src/arrays.js +1 -1
  9. package/out/shared/src/arrays.js.map +1 -1
  10. package/out/shared/src/browser-env.js +0 -4
  11. package/out/shared/src/browser-env.js.map +1 -1
  12. package/out/shared/src/btree-set.js +4 -1
  13. package/out/shared/src/btree-set.js.map +1 -1
  14. package/out/shared/src/options.js +1 -1
  15. package/out/shared/src/options.js.map +1 -1
  16. package/out/shared/src/queue.js +1 -1
  17. package/out/shared/src/queue.js.map +1 -1
  18. package/out/z2s/src/compiler.d.ts.map +1 -1
  19. package/out/z2s/src/compiler.js +13 -11
  20. package/out/z2s/src/compiler.js.map +1 -1
  21. package/out/zero/package.json.js +1 -1
  22. package/out/zero/src/react.js +1 -3
  23. package/out/zero/src/react.js.map +1 -1
  24. package/out/zero-cache/src/auth/read-authorizer.js +0 -7
  25. package/out/zero-cache/src/auth/read-authorizer.js.map +1 -1
  26. package/out/zero-cache/src/config/network.d.ts +3 -2
  27. package/out/zero-cache/src/config/network.d.ts.map +1 -1
  28. package/out/zero-cache/src/config/network.js +9 -2
  29. package/out/zero-cache/src/config/network.js.map +1 -1
  30. package/out/zero-cache/src/config/server-context.d.ts +16 -0
  31. package/out/zero-cache/src/config/server-context.d.ts.map +1 -0
  32. package/out/zero-cache/src/config/server-context.js +32 -0
  33. package/out/zero-cache/src/config/server-context.js.map +1 -0
  34. package/out/zero-cache/src/config/zero-config.d.ts +3 -3
  35. package/out/zero-cache/src/config/zero-config.d.ts.map +1 -1
  36. package/out/zero-cache/src/config/zero-config.js +2 -6
  37. package/out/zero-cache/src/config/zero-config.js.map +1 -1
  38. package/out/zero-cache/src/db/migration.d.ts.map +1 -1
  39. package/out/zero-cache/src/db/migration.js +40 -51
  40. package/out/zero-cache/src/db/migration.js.map +1 -1
  41. package/out/zero-cache/src/db/run-transaction.d.ts +17 -0
  42. package/out/zero-cache/src/db/run-transaction.d.ts.map +1 -0
  43. package/out/zero-cache/src/db/run-transaction.js +24 -0
  44. package/out/zero-cache/src/db/run-transaction.js.map +1 -0
  45. package/out/zero-cache/src/db/transaction-pool.d.ts.map +1 -1
  46. package/out/zero-cache/src/db/transaction-pool.js +3 -3
  47. package/out/zero-cache/src/db/transaction-pool.js.map +1 -1
  48. package/out/zero-cache/src/scripts/decommission.d.ts +1 -1
  49. package/out/zero-cache/src/scripts/deploy-permissions.js +2 -1
  50. package/out/zero-cache/src/scripts/deploy-permissions.js.map +1 -1
  51. package/out/zero-cache/src/scripts/permissions.d.ts +1 -1
  52. package/out/zero-cache/src/server/change-streamer.d.ts.map +1 -1
  53. package/out/zero-cache/src/server/change-streamer.js +6 -2
  54. package/out/zero-cache/src/server/change-streamer.js.map +1 -1
  55. package/out/zero-cache/src/server/main.js +1 -1
  56. package/out/zero-cache/src/server/main.js.map +1 -1
  57. package/out/zero-cache/src/server/runner/run-worker.d.ts.map +1 -1
  58. package/out/zero-cache/src/server/runner/run-worker.js +7 -3
  59. package/out/zero-cache/src/server/runner/run-worker.js.map +1 -1
  60. package/out/zero-cache/src/services/change-source/common/backfill-manager.d.ts +1 -1
  61. package/out/zero-cache/src/services/change-source/common/backfill-manager.d.ts.map +1 -1
  62. package/out/zero-cache/src/services/change-source/common/backfill-manager.js +11 -9
  63. package/out/zero-cache/src/services/change-source/common/backfill-manager.js.map +1 -1
  64. package/out/zero-cache/src/services/change-source/common/replica-schema.d.ts.map +1 -1
  65. package/out/zero-cache/src/services/change-source/common/replica-schema.js +11 -0
  66. package/out/zero-cache/src/services/change-source/common/replica-schema.js.map +1 -1
  67. package/out/zero-cache/src/services/change-source/custom/change-source.d.ts +5 -2
  68. package/out/zero-cache/src/services/change-source/custom/change-source.d.ts.map +1 -1
  69. package/out/zero-cache/src/services/change-source/custom/change-source.js +6 -6
  70. package/out/zero-cache/src/services/change-source/custom/change-source.js.map +1 -1
  71. package/out/zero-cache/src/services/change-source/pg/change-source.d.ts +6 -4
  72. package/out/zero-cache/src/services/change-source/pg/change-source.d.ts.map +1 -1
  73. package/out/zero-cache/src/services/change-source/pg/change-source.js +148 -54
  74. package/out/zero-cache/src/services/change-source/pg/change-source.js.map +1 -1
  75. package/out/zero-cache/src/services/change-source/pg/decommission.d.ts.map +1 -1
  76. package/out/zero-cache/src/services/change-source/pg/decommission.js +2 -1
  77. package/out/zero-cache/src/services/change-source/pg/decommission.js.map +1 -1
  78. package/out/zero-cache/src/services/change-source/pg/initial-sync.d.ts +4 -1
  79. package/out/zero-cache/src/services/change-source/pg/initial-sync.d.ts.map +1 -1
  80. package/out/zero-cache/src/services/change-source/pg/initial-sync.js +35 -10
  81. package/out/zero-cache/src/services/change-source/pg/initial-sync.js.map +1 -1
  82. package/out/zero-cache/src/services/change-source/pg/logical-replication/stream.js +1 -1
  83. package/out/zero-cache/src/services/change-source/pg/logical-replication/stream.js.map +1 -1
  84. package/out/zero-cache/src/services/change-source/pg/schema/init.d.ts.map +1 -1
  85. package/out/zero-cache/src/services/change-source/pg/schema/init.js +10 -0
  86. package/out/zero-cache/src/services/change-source/pg/schema/init.js.map +1 -1
  87. package/out/zero-cache/src/services/change-source/pg/schema/shard.d.ts +6 -3
  88. package/out/zero-cache/src/services/change-source/pg/schema/shard.d.ts.map +1 -1
  89. package/out/zero-cache/src/services/change-source/pg/schema/shard.js +19 -10
  90. package/out/zero-cache/src/services/change-source/pg/schema/shard.js.map +1 -1
  91. package/out/zero-cache/src/services/change-source/protocol/current/data.d.ts +1 -0
  92. package/out/zero-cache/src/services/change-source/protocol/current/data.d.ts.map +1 -1
  93. package/out/zero-cache/src/services/change-source/protocol/current/data.js +4 -2
  94. package/out/zero-cache/src/services/change-source/protocol/current/data.js.map +1 -1
  95. package/out/zero-cache/src/services/change-source/protocol/current/downstream.d.ts +3 -0
  96. package/out/zero-cache/src/services/change-source/protocol/current/downstream.d.ts.map +1 -1
  97. package/out/zero-cache/src/services/change-source/protocol/current/status.d.ts +6 -4
  98. package/out/zero-cache/src/services/change-source/protocol/current/status.d.ts.map +1 -1
  99. package/out/zero-cache/src/services/change-source/protocol/current/status.js.map +1 -1
  100. package/out/zero-cache/src/services/change-streamer/backup-monitor.d.ts +2 -2
  101. package/out/zero-cache/src/services/change-streamer/backup-monitor.d.ts.map +1 -1
  102. package/out/zero-cache/src/services/change-streamer/backup-monitor.js +30 -12
  103. package/out/zero-cache/src/services/change-streamer/backup-monitor.js.map +1 -1
  104. package/out/zero-cache/src/services/change-streamer/change-streamer-service.js +23 -3
  105. package/out/zero-cache/src/services/change-streamer/change-streamer-service.js.map +1 -1
  106. package/out/zero-cache/src/services/change-streamer/change-streamer.d.ts +1 -0
  107. package/out/zero-cache/src/services/change-streamer/change-streamer.d.ts.map +1 -1
  108. package/out/zero-cache/src/services/change-streamer/forwarder.js +1 -1
  109. package/out/zero-cache/src/services/change-streamer/forwarder.js.map +1 -1
  110. package/out/zero-cache/src/services/change-streamer/schema/tables.d.ts +1 -1
  111. package/out/zero-cache/src/services/change-streamer/schema/tables.d.ts.map +1 -1
  112. package/out/zero-cache/src/services/change-streamer/schema/tables.js +12 -4
  113. package/out/zero-cache/src/services/change-streamer/schema/tables.js.map +1 -1
  114. package/out/zero-cache/src/services/change-streamer/storer.d.ts +11 -2
  115. package/out/zero-cache/src/services/change-streamer/storer.d.ts.map +1 -1
  116. package/out/zero-cache/src/services/change-streamer/storer.js +80 -42
  117. package/out/zero-cache/src/services/change-streamer/storer.js.map +1 -1
  118. package/out/zero-cache/src/services/litestream/commands.d.ts +1 -1
  119. package/out/zero-cache/src/services/litestream/commands.d.ts.map +1 -1
  120. package/out/zero-cache/src/services/litestream/commands.js +2 -1
  121. package/out/zero-cache/src/services/litestream/commands.js.map +1 -1
  122. package/out/zero-cache/src/services/mutagen/mutagen.d.ts.map +1 -1
  123. package/out/zero-cache/src/services/mutagen/mutagen.js +22 -17
  124. package/out/zero-cache/src/services/mutagen/mutagen.js.map +1 -1
  125. package/out/zero-cache/src/services/replicator/schema/replication-state.d.ts +10 -1
  126. package/out/zero-cache/src/services/replicator/schema/replication-state.d.ts.map +1 -1
  127. package/out/zero-cache/src/services/replicator/schema/replication-state.js +49 -9
  128. package/out/zero-cache/src/services/replicator/schema/replication-state.js.map +1 -1
  129. package/out/zero-cache/src/services/running-state.d.ts +1 -0
  130. package/out/zero-cache/src/services/running-state.d.ts.map +1 -1
  131. package/out/zero-cache/src/services/running-state.js +3 -0
  132. package/out/zero-cache/src/services/running-state.js.map +1 -1
  133. package/out/zero-cache/src/services/view-syncer/cvr-purger.d.ts.map +1 -1
  134. package/out/zero-cache/src/services/view-syncer/cvr-purger.js +32 -28
  135. package/out/zero-cache/src/services/view-syncer/cvr-purger.js.map +1 -1
  136. package/out/zero-cache/src/services/view-syncer/cvr-store.d.ts.map +1 -1
  137. package/out/zero-cache/src/services/view-syncer/cvr-store.js +329 -155
  138. package/out/zero-cache/src/services/view-syncer/cvr-store.js.map +1 -1
  139. package/out/zero-cache/src/services/view-syncer/cvr.d.ts.map +1 -1
  140. package/out/zero-cache/src/services/view-syncer/cvr.js +387 -345
  141. package/out/zero-cache/src/services/view-syncer/cvr.js.map +1 -1
  142. package/out/zero-cache/src/services/view-syncer/pipeline-driver.d.ts.map +1 -1
  143. package/out/zero-cache/src/services/view-syncer/pipeline-driver.js +68 -16
  144. package/out/zero-cache/src/services/view-syncer/pipeline-driver.js.map +1 -1
  145. package/out/zero-cache/src/services/view-syncer/row-record-cache.d.ts.map +1 -1
  146. package/out/zero-cache/src/services/view-syncer/row-record-cache.js +13 -8
  147. package/out/zero-cache/src/services/view-syncer/row-record-cache.js.map +1 -1
  148. package/out/zero-cache/src/services/view-syncer/tracer.d.ts +2 -0
  149. package/out/zero-cache/src/services/view-syncer/tracer.d.ts.map +1 -0
  150. package/out/zero-cache/src/services/view-syncer/tracer.js +7 -0
  151. package/out/zero-cache/src/services/view-syncer/tracer.js.map +1 -0
  152. package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts.map +1 -1
  153. package/out/zero-cache/src/services/view-syncer/view-syncer.js +58 -43
  154. package/out/zero-cache/src/services/view-syncer/view-syncer.js.map +1 -1
  155. package/out/zero-cache/src/types/pg.js +0 -4
  156. package/out/zero-cache/src/types/pg.js.map +1 -1
  157. package/out/zero-cache/src/types/streams.d.ts +3 -1
  158. package/out/zero-cache/src/types/streams.d.ts.map +1 -1
  159. package/out/zero-cache/src/types/streams.js +1 -1
  160. package/out/zero-cache/src/types/streams.js.map +1 -1
  161. package/out/zero-cache/src/types/subscription.d.ts +7 -1
  162. package/out/zero-cache/src/types/subscription.d.ts.map +1 -1
  163. package/out/zero-cache/src/types/subscription.js +8 -2
  164. package/out/zero-cache/src/types/subscription.js.map +1 -1
  165. package/out/zero-client/src/client/options.d.ts +7 -7
  166. package/out/zero-client/src/client/options.d.ts.map +1 -1
  167. package/out/zero-client/src/client/options.js.map +1 -1
  168. package/out/zero-client/src/client/query-manager.js +1 -1
  169. package/out/zero-client/src/client/query-manager.js.map +1 -1
  170. package/out/zero-client/src/client/version.js +1 -1
  171. package/out/zero-client/src/client/zero-poke-handler.d.ts +5 -5
  172. package/out/zero-client/src/client/zero-poke-handler.d.ts.map +1 -1
  173. package/out/zero-client/src/client/zero-poke-handler.js +15 -17
  174. package/out/zero-client/src/client/zero-poke-handler.js.map +1 -1
  175. package/out/zero-client/src/client/zero.d.ts +6 -2
  176. package/out/zero-client/src/client/zero.d.ts.map +1 -1
  177. package/out/zero-client/src/client/zero.js +44 -8
  178. package/out/zero-client/src/client/zero.js.map +1 -1
  179. package/out/zero-client/src/mod.d.ts +1 -1
  180. package/out/zero-client/src/mod.d.ts.map +1 -1
  181. package/out/zero-protocol/src/ast.d.ts +2 -9
  182. package/out/zero-protocol/src/ast.d.ts.map +1 -1
  183. package/out/zero-protocol/src/ast.js +15 -32
  184. package/out/zero-protocol/src/ast.js.map +1 -1
  185. package/out/zero-protocol/src/protocol-version.d.ts +1 -1
  186. package/out/zero-protocol/src/protocol-version.d.ts.map +1 -1
  187. package/out/zero-protocol/src/protocol-version.js +5 -2
  188. package/out/zero-protocol/src/protocol-version.js.map +1 -1
  189. package/out/zero-react/src/mod.d.ts +0 -2
  190. package/out/zero-react/src/mod.d.ts.map +1 -1
  191. package/out/zero-react/src/use-query.d.ts +6 -6
  192. package/out/zero-react/src/use-query.d.ts.map +1 -1
  193. package/out/zero-react/src/use-query.js +9 -2
  194. package/out/zero-react/src/use-query.js.map +1 -1
  195. package/out/zero-react/src/zero-provider.d.ts +5 -5
  196. package/out/zero-react/src/zero-provider.d.ts.map +1 -1
  197. package/out/zero-react/src/zero-provider.js.map +1 -1
  198. package/out/zero-solid/src/solid-view.d.ts +0 -42
  199. package/out/zero-solid/src/solid-view.d.ts.map +1 -1
  200. package/out/zero-solid/src/solid-view.js +1 -1
  201. package/out/zero-solid/src/solid-view.js.map +1 -1
  202. package/out/zero-solid/src/use-query.d.ts +4 -4
  203. package/out/zero-solid/src/use-query.d.ts.map +1 -1
  204. package/out/zero-solid/src/use-query.js.map +1 -1
  205. package/out/zero-solid/src/use-zero.d.ts +5 -5
  206. package/out/zero-solid/src/use-zero.d.ts.map +1 -1
  207. package/out/zero-solid/src/use-zero.js.map +1 -1
  208. package/out/zero-types/src/default-types.d.ts +2 -0
  209. package/out/zero-types/src/default-types.d.ts.map +1 -1
  210. package/out/zql/src/builder/builder.d.ts.map +1 -1
  211. package/out/zql/src/builder/builder.js +6 -48
  212. package/out/zql/src/builder/builder.js.map +1 -1
  213. package/out/zql/src/builder/filter.d.ts.map +1 -1
  214. package/out/zql/src/builder/filter.js +0 -1
  215. package/out/zql/src/builder/filter.js.map +1 -1
  216. package/out/zql/src/ivm/array-view.d.ts.map +1 -1
  217. package/out/zql/src/ivm/array-view.js +6 -57
  218. package/out/zql/src/ivm/array-view.js.map +1 -1
  219. package/out/zql/src/ivm/view-apply-change.d.ts +3 -50
  220. package/out/zql/src/ivm/view-apply-change.d.ts.map +1 -1
  221. package/out/zql/src/ivm/view-apply-change.js +105 -358
  222. package/out/zql/src/ivm/view-apply-change.js.map +1 -1
  223. package/out/zql/src/mutate/mutator-registry.d.ts +3 -3
  224. package/out/zql/src/mutate/mutator-registry.d.ts.map +1 -1
  225. package/out/zql/src/mutate/mutator-registry.js.map +1 -1
  226. package/out/zql/src/planner/planner-builder.d.ts.map +1 -1
  227. package/out/zql/src/planner/planner-builder.js +1 -2
  228. package/out/zql/src/planner/planner-builder.js.map +1 -1
  229. package/out/zql/src/query/complete-ordering.js +0 -6
  230. package/out/zql/src/query/complete-ordering.js.map +1 -1
  231. package/out/zql/src/query/expression.d.ts +2 -19
  232. package/out/zql/src/query/expression.d.ts.map +1 -1
  233. package/out/zql/src/query/expression.js +6 -50
  234. package/out/zql/src/query/expression.js.map +1 -1
  235. package/out/zql/src/query/query-delegate-base.js +3 -1
  236. package/out/zql/src/query/query-delegate-base.js.map +1 -1
  237. package/out/zql/src/query/query-impl.d.ts.map +1 -1
  238. package/out/zql/src/query/query-impl.js +8 -12
  239. package/out/zql/src/query/query-impl.js.map +1 -1
  240. package/out/zql/src/query/query-internals.js.map +1 -1
  241. package/out/zql/src/query/query-registry.d.ts +3 -3
  242. package/out/zql/src/query/query-registry.d.ts.map +1 -1
  243. package/out/zql/src/query/query-registry.js.map +1 -1
  244. package/out/zql/src/query/query.d.ts +28 -5
  245. package/out/zql/src/query/query.d.ts.map +1 -1
  246. package/out/zqlite/src/query-builder.d.ts +0 -2
  247. package/out/zqlite/src/query-builder.d.ts.map +1 -1
  248. package/out/zqlite/src/query-builder.js.map +1 -1
  249. package/out/zqlite/src/resolve-scalar-subqueries.d.ts +10 -2
  250. package/out/zqlite/src/resolve-scalar-subqueries.d.ts.map +1 -1
  251. package/out/zqlite/src/resolve-scalar-subqueries.js +41 -9
  252. package/out/zqlite/src/resolve-scalar-subqueries.js.map +1 -1
  253. package/out/zqlite/src/sqlite-cost-model.d.ts.map +1 -1
  254. package/out/zqlite/src/sqlite-cost-model.js +0 -1
  255. package/out/zqlite/src/sqlite-cost-model.js.map +1 -1
  256. package/package.json +3 -5
  257. package/out/zero-cache/src/services/change-source/custom/sync-schema.d.ts +0 -4
  258. package/out/zero-cache/src/services/change-source/custom/sync-schema.d.ts.map +0 -1
  259. package/out/zero-cache/src/services/change-source/custom/sync-schema.js +0 -14
  260. package/out/zero-cache/src/services/change-source/custom/sync-schema.js.map +0 -1
  261. package/out/zero-cache/src/services/change-source/pg/sync-schema.d.ts +0 -5
  262. package/out/zero-cache/src/services/change-source/pg/sync-schema.d.ts.map +0 -1
  263. package/out/zero-cache/src/services/change-source/pg/sync-schema.js +0 -14
  264. package/out/zero-cache/src/services/change-source/pg/sync-schema.js.map +0 -1
  265. package/out/zero-react/src/paging-reducer.d.ts +0 -61
  266. package/out/zero-react/src/paging-reducer.d.ts.map +0 -1
  267. package/out/zero-react/src/paging-reducer.js +0 -77
  268. package/out/zero-react/src/paging-reducer.js.map +0 -1
  269. package/out/zero-react/src/use-rows.d.ts +0 -39
  270. package/out/zero-react/src/use-rows.d.ts.map +0 -1
  271. package/out/zero-react/src/use-rows.js +0 -130
  272. package/out/zero-react/src/use-rows.js.map +0 -1
  273. package/out/zero-react/src/use-zero-virtualizer.d.ts +0 -122
  274. package/out/zero-react/src/use-zero-virtualizer.d.ts.map +0 -1
  275. package/out/zero-react/src/use-zero-virtualizer.js +0 -342
  276. package/out/zero-react/src/use-zero-virtualizer.js.map +0 -1
@@ -1,3 +1,4 @@
1
+ import { startSpan, startAsyncSpan } from "../../../../otel/src/span.js";
1
2
  import { assert } from "../../../../shared/src/asserts.js";
2
3
  import "../../../../shared/src/bigint-json.js";
3
4
  import { CustomKeyMap } from "../../../../shared/src/custom-key-map.js";
@@ -13,6 +14,7 @@ import { rowIDString } from "../../types/row-key.js";
13
14
  import { upstreamSchema } from "../../types/shards.js";
14
15
  import "./cvr-store.js";
15
16
  import { cmpVersions, maxVersion, oneAfter } from "./schema/types.js";
17
+ import { tracer } from "./tracer.js";
16
18
  import { ttlClockAsNumber } from "./ttl-clock.js";
17
19
  const CLIENT_LMID_QUERY_ID = "lmids";
18
20
  const CLIENT_MUTATION_RESULTS_QUERY_ID = "mutationResults";
@@ -105,70 +107,71 @@ class CVRConfigDrivenUpdater extends CVRUpdater {
105
107
  this.#shard = shard;
106
108
  }
107
109
  ensureClient(id) {
108
- let client = this._cvr.clients[id];
109
- if (client) {
110
- return client;
111
- }
112
- client = { id, desiredQueryIDs: [] };
113
- this._cvr.clients[id] = client;
114
- this._ensureNewVersion();
115
- this._cvrStore.insertClient(client);
116
- if (!this._cvr.queries[CLIENT_LMID_QUERY_ID]) {
117
- const lmidsQuery = {
118
- id: CLIENT_LMID_QUERY_ID,
119
- ast: {
120
- schema: "",
121
- table: `${upstreamSchema(this.#shard)}.clients`,
122
- where: {
123
- type: "simple",
124
- left: {
125
- type: "column",
126
- name: "clientGroupID"
110
+ return startSpan(tracer, "CVRConfigDrivenUpdater.ensureClient", () => {
111
+ let client = this._cvr.clients[id];
112
+ if (client) {
113
+ return client;
114
+ }
115
+ client = { id, desiredQueryIDs: [] };
116
+ this._cvr.clients[id] = client;
117
+ this._ensureNewVersion();
118
+ this._cvrStore.insertClient(client);
119
+ if (!this._cvr.queries[CLIENT_LMID_QUERY_ID]) {
120
+ const lmidsQuery = {
121
+ id: CLIENT_LMID_QUERY_ID,
122
+ ast: {
123
+ schema: "",
124
+ table: `${upstreamSchema(this.#shard)}.clients`,
125
+ where: {
126
+ type: "simple",
127
+ left: {
128
+ type: "column",
129
+ name: "clientGroupID"
130
+ },
131
+ op: "=",
132
+ right: {
133
+ type: "literal",
134
+ value: this._cvr.id
135
+ }
127
136
  },
128
- op: "=",
129
- right: {
130
- type: "literal",
131
- value: this._cvr.id
132
- }
137
+ orderBy: [
138
+ ["clientGroupID", "asc"],
139
+ ["clientID", "asc"]
140
+ ]
133
141
  },
134
- orderBy: [
135
- ["clientGroupID", "asc"],
136
- ["clientID", "asc"]
137
- ]
138
- },
139
- type: "internal"
140
- };
141
- this._cvr.queries[CLIENT_LMID_QUERY_ID] = lmidsQuery;
142
- this._cvrStore.putQuery(lmidsQuery);
143
- }
144
- if (!this._cvr.queries[CLIENT_MUTATION_RESULTS_QUERY_ID]) {
145
- const mutationResultsQuery = getMutationResultsQuery(
146
- upstreamSchema(this.#shard),
147
- this._cvr.id
148
- );
149
- this._cvr.queries[CLIENT_MUTATION_RESULTS_QUERY_ID] = mutationResultsQuery;
150
- this._cvrStore.putQuery(mutationResultsQuery);
151
- }
152
- return client;
142
+ type: "internal"
143
+ };
144
+ this._cvr.queries[CLIENT_LMID_QUERY_ID] = lmidsQuery;
145
+ this._cvrStore.putQuery(lmidsQuery);
146
+ }
147
+ if (!this._cvr.queries[CLIENT_MUTATION_RESULTS_QUERY_ID]) {
148
+ const mutationResultsQuery = getMutationResultsQuery(upstreamSchema(this.#shard), this._cvr.id);
149
+ this._cvr.queries[CLIENT_MUTATION_RESULTS_QUERY_ID] = mutationResultsQuery;
150
+ this._cvrStore.putQuery(mutationResultsQuery);
151
+ }
152
+ return client;
153
+ });
153
154
  }
154
155
  setClientSchema(lc, clientSchema) {
155
- if (this._cvr.clientSchema === null) {
156
- this._cvr.clientSchema = clientSchema;
157
- this._cvrStore.putInstance(this._cvr);
158
- } else if (!deepEqual(this._cvr.clientSchema, clientSchema)) {
159
- lc.warn?.(
160
- `New schema ${JSON.stringify(
161
- clientSchema
162
- )} does not match existing schema ${JSON.stringify(
163
- this._cvr.clientSchema
164
- )}`
165
- );
166
- throw new ProtocolError({
167
- kind: "InvalidConnectionRequest",
168
- message: `Provided schema does not match previous schema`,
169
- origin: ZeroCache
170
- });
171
- }
156
+ startSpan(tracer, "CVRConfigDrivenUpdater.setClientSchema", () => {
157
+ if (this._cvr.clientSchema === null) {
158
+ this._cvr.clientSchema = clientSchema;
159
+ this._cvrStore.putInstance(this._cvr);
160
+ } else if (!deepEqual(this._cvr.clientSchema, clientSchema)) {
161
+ lc.warn?.(
162
+ `New schema ${JSON.stringify(
163
+ clientSchema
164
+ )} does not match existing schema ${JSON.stringify(
165
+ this._cvr.clientSchema
166
+ )}`
167
+ );
168
+ throw new ProtocolError({
169
+ kind: "InvalidConnectionRequest",
170
+ message: `Provided schema does not match previous schema`,
171
+ origin: ZeroCache
172
+ });
173
+ }
174
+ });
172
175
  }
173
176
  setProfileID(lc, profileID) {
174
177
  if (this._cvr.profileID !== profileID) {
@@ -182,72 +185,74 @@ class CVRConfigDrivenUpdater extends CVRUpdater {
182
185
  }
183
186
  }
184
187
  putDesiredQueries(clientID, queries) {
185
- const patches = [];
186
- const client = this.ensureClient(clientID);
187
- const current = new Set(client.desiredQueryIDs);
188
- const needed = /* @__PURE__ */ new Set();
189
- const recordQueryForTelemetry = (q) => {
190
- const { ast, name, args } = q;
191
- if (ast) {
192
- recordQuery("crud");
193
- } else if (name && args) {
194
- recordQuery("custom");
195
- }
196
- };
197
- for (const q of queries) {
198
- const { hash, ttl = DEFAULT_TTL_MS } = q;
199
- const query = this._cvr.queries[hash];
200
- if (!query) {
201
- recordQueryForTelemetry(q);
202
- needed.add(hash);
203
- continue;
204
- }
205
- if (query.type === "internal") {
206
- continue;
188
+ return startSpan(tracer, "CVRConfigDrivenUpdater.putDesiredQueries", () => {
189
+ const patches = [];
190
+ const client = this.ensureClient(clientID);
191
+ const current = new Set(client.desiredQueryIDs);
192
+ const needed = /* @__PURE__ */ new Set();
193
+ const recordQueryForTelemetry = (q) => {
194
+ const { ast, name, args } = q;
195
+ if (ast) {
196
+ recordQuery("crud");
197
+ } else if (name && args) {
198
+ recordQuery("custom");
199
+ }
200
+ };
201
+ for (const q of queries) {
202
+ const { hash, ttl = DEFAULT_TTL_MS } = q;
203
+ const query = this._cvr.queries[hash];
204
+ if (!query) {
205
+ recordQueryForTelemetry(q);
206
+ needed.add(hash);
207
+ continue;
208
+ }
209
+ if (query.type === "internal") {
210
+ continue;
211
+ }
212
+ const oldClientState = query.clientState[clientID];
213
+ if (!oldClientState || oldClientState.inactivatedAt !== void 0) {
214
+ recordQueryForTelemetry(q);
215
+ needed.add(hash);
216
+ continue;
217
+ }
218
+ if (compareTTL(ttl, oldClientState.ttl) > 0) {
219
+ needed.add(hash);
220
+ }
207
221
  }
208
- const oldClientState = query.clientState[clientID];
209
- if (!oldClientState || oldClientState.inactivatedAt !== void 0) {
210
- recordQueryForTelemetry(q);
211
- needed.add(hash);
212
- continue;
222
+ if (needed.size === 0) {
223
+ return patches;
213
224
  }
214
- if (compareTTL(ttl, oldClientState.ttl) > 0) {
215
- needed.add(hash);
225
+ const newVersion = this._ensureNewVersion();
226
+ client.desiredQueryIDs = [...union(current, needed)].sort(stringCompare);
227
+ for (const id of needed) {
228
+ const q = must(queries.find(({ hash }) => hash === id));
229
+ const { ast, name, args } = q;
230
+ const ttl = clampTTL(q.ttl ?? DEFAULT_TTL_MS);
231
+ const query = this._cvr.queries[id] ?? newQueryRecord(id, ast, name, args);
232
+ assertNotInternal(query);
233
+ const inactivatedAt = void 0;
234
+ query.clientState[clientID] = {
235
+ inactivatedAt,
236
+ ttl,
237
+ version: newVersion
238
+ };
239
+ this._cvr.queries[id] = query;
240
+ patches.push({
241
+ toVersion: newVersion,
242
+ patch: { type: "query", op: "put", id, clientID }
243
+ });
244
+ this._cvrStore.putQuery(query);
245
+ this._cvrStore.putDesiredQuery(
246
+ newVersion,
247
+ query,
248
+ client,
249
+ false,
250
+ inactivatedAt,
251
+ ttl
252
+ );
216
253
  }
217
- }
218
- if (needed.size === 0) {
219
254
  return patches;
220
- }
221
- const newVersion = this._ensureNewVersion();
222
- client.desiredQueryIDs = [...union(current, needed)].sort(stringCompare);
223
- for (const id of needed) {
224
- const q = must(queries.find(({ hash }) => hash === id));
225
- const { ast, name, args } = q;
226
- const ttl = clampTTL(q.ttl ?? DEFAULT_TTL_MS);
227
- const query = this._cvr.queries[id] ?? newQueryRecord(id, ast, name, args);
228
- assertNotInternal(query);
229
- const inactivatedAt = void 0;
230
- query.clientState[clientID] = {
231
- inactivatedAt,
232
- ttl,
233
- version: newVersion
234
- };
235
- this._cvr.queries[id] = query;
236
- patches.push({
237
- toVersion: newVersion,
238
- patch: { type: "query", op: "put", id, clientID }
239
- });
240
- this._cvrStore.putQuery(query);
241
- this._cvrStore.putDesiredQuery(
242
- newVersion,
243
- query,
244
- client,
245
- false,
246
- inactivatedAt,
247
- ttl
248
- );
249
- }
250
- return patches;
255
+ });
251
256
  }
252
257
  markDesiredQueriesAsInactive(clientID, queryHashes, ttlClock) {
253
258
  return this.#deleteQueries(clientID, queryHashes, ttlClock);
@@ -256,75 +261,79 @@ class CVRConfigDrivenUpdater extends CVRUpdater {
256
261
  return this.#deleteQueries(clientID, queryHashes, void 0);
257
262
  }
258
263
  #deleteQueries(clientID, queryHashes, inactivatedAt) {
259
- const patches = [];
260
- const client = this.ensureClient(clientID);
261
- const current = new Set(client.desiredQueryIDs);
262
- const unwanted = new Set(queryHashes);
263
- const remove = intersection(unwanted, current);
264
- if (remove.size === 0) {
265
- return patches;
266
- }
267
- const newVersion = this._ensureNewVersion();
268
- client.desiredQueryIDs = [...difference(current, remove)].sort(
269
- stringCompare
270
- );
271
- for (const id of remove) {
272
- const query = this._cvr.queries[id];
273
- if (!query) {
274
- continue;
264
+ return startSpan(tracer, "CVRConfigDrivenUpdater.#deleteQueries", () => {
265
+ const patches = [];
266
+ const client = this.ensureClient(clientID);
267
+ const current = new Set(client.desiredQueryIDs);
268
+ const unwanted = new Set(queryHashes);
269
+ const remove = intersection(unwanted, current);
270
+ if (remove.size === 0) {
271
+ return patches;
275
272
  }
276
- assertNotInternal(query);
277
- let ttl = DEFAULT_TTL_MS;
278
- if (inactivatedAt === void 0) {
279
- delete query.clientState[clientID];
280
- } else {
281
- const clientState = query.clientState[clientID];
282
- if (clientState !== void 0) {
283
- assert(
284
- clientState.inactivatedAt === void 0,
285
- `Query ${id} is already inactivated`
286
- );
287
- ttl = clampTTL(clientState.ttl);
288
- query.clientState[clientID] = {
289
- inactivatedAt,
290
- ttl,
291
- version: newVersion
292
- };
273
+ const newVersion = this._ensureNewVersion();
274
+ client.desiredQueryIDs = [...difference(current, remove)].sort(
275
+ stringCompare
276
+ );
277
+ for (const id of remove) {
278
+ const query = this._cvr.queries[id];
279
+ if (!query) {
280
+ continue;
281
+ }
282
+ assertNotInternal(query);
283
+ let ttl = DEFAULT_TTL_MS;
284
+ if (inactivatedAt === void 0) {
285
+ delete query.clientState[clientID];
286
+ } else {
287
+ const clientState = query.clientState[clientID];
288
+ if (clientState !== void 0) {
289
+ assert(
290
+ clientState.inactivatedAt === void 0,
291
+ `Query ${id} is already inactivated`
292
+ );
293
+ ttl = clampTTL(clientState.ttl);
294
+ query.clientState[clientID] = {
295
+ inactivatedAt,
296
+ ttl,
297
+ version: newVersion
298
+ };
299
+ }
293
300
  }
301
+ this._cvrStore.putQuery(query);
302
+ this._cvrStore.putDesiredQuery(
303
+ newVersion,
304
+ query,
305
+ client,
306
+ true,
307
+ inactivatedAt,
308
+ ttl
309
+ );
310
+ patches.push({
311
+ toVersion: newVersion,
312
+ patch: { type: "query", op: "del", id, clientID }
313
+ });
294
314
  }
295
- this._cvrStore.putQuery(query);
296
- this._cvrStore.putDesiredQuery(
297
- newVersion,
298
- query,
299
- client,
300
- true,
301
- inactivatedAt,
302
- ttl
303
- );
304
- patches.push({
305
- toVersion: newVersion,
306
- patch: { type: "query", op: "del", id, clientID }
307
- });
308
- }
309
- return patches;
315
+ return patches;
316
+ });
310
317
  }
311
318
  clearDesiredQueries(clientID) {
312
319
  const client = this.ensureClient(clientID);
313
320
  return this.#deleteQueries(clientID, client.desiredQueryIDs, void 0);
314
321
  }
315
322
  deleteClient(clientID, ttlClock) {
316
- const client = this._cvr.clients[clientID];
317
- if (!client) {
318
- return [];
319
- }
320
- const patches = this.markDesiredQueriesAsInactive(
321
- clientID,
322
- client.desiredQueryIDs,
323
- ttlClock
324
- );
325
- delete this._cvr.clients[clientID];
326
- this._cvrStore.deleteClient(clientID);
327
- return patches;
323
+ return startSpan(tracer, "CVRConfigDrivenUpdater.deleteClient", () => {
324
+ const client = this._cvr.clients[clientID];
325
+ if (!client) {
326
+ return [];
327
+ }
328
+ const patches = this.markDesiredQueriesAsInactive(
329
+ clientID,
330
+ client.desiredQueryIDs,
331
+ ttlClock
332
+ );
333
+ delete this._cvr.clients[clientID];
334
+ this._cvrStore.deleteClient(clientID);
335
+ return patches;
336
+ });
328
337
  }
329
338
  }
330
339
  class CVRQueryDrivenUpdater extends CVRUpdater {
@@ -368,48 +377,56 @@ class CVRQueryDrivenUpdater extends CVRUpdater {
368
377
  * @returns The new CVRVersion to be used when all changes are committed.
369
378
  */
370
379
  trackQueries(lc, executed, removed) {
371
- assert(this.#existingRows === void 0, `trackQueries already called`);
372
- const queryPatches = [
373
- executed.map((q) => this.#trackExecuted(q.id, q.transformationHash)),
374
- removed.map((q) => this.#trackRemoved(q.id))
375
- ].flat(2);
376
- this.#existingRows = this.#lookupRowsForExecutedAndRemovedQueries(lc);
377
- void this.#existingRows.then(() => {
380
+ return startSpan(tracer, "CVRQueryDrivenUpdater.trackQueries", () => {
381
+ assert(this.#existingRows === void 0, `trackQueries already called`);
382
+ const queryPatches = [
383
+ executed.map((q) => this.#trackExecuted(q.id, q.transformationHash)),
384
+ removed.map((q) => this.#trackRemoved(q.id))
385
+ ].flat(2);
386
+ this.#existingRows = this.#lookupRowsForExecutedAndRemovedQueries(lc);
387
+ void this.#existingRows.then(() => {
388
+ });
389
+ return {
390
+ newVersion: this._cvr.version,
391
+ queryPatches: queryPatches.map((patch) => ({
392
+ patch,
393
+ toVersion: this._cvr.version
394
+ }))
395
+ };
378
396
  });
379
- return {
380
- newVersion: this._cvr.version,
381
- queryPatches: queryPatches.map((patch) => ({
382
- patch,
383
- toVersion: this._cvr.version
384
- }))
385
- };
386
397
  }
387
- async #lookupRowsForExecutedAndRemovedQueries(lc) {
388
- const results = new CustomKeyMap(rowIDString);
389
- if (this.#removedOrExecutedQueryIDs.size === 0) {
390
- return [];
391
- }
392
- const allRowRecords = (await this._cvrStore.getRowRecords()).values();
393
- let total = 0;
394
- for (const existing of allRowRecords) {
395
- total++;
396
- assert(
397
- existing.refCounts !== null,
398
- "allRowRecords should not include null refCounts"
399
- );
400
- for (const id of Object.keys(existing.refCounts)) {
401
- if (this.#removedOrExecutedQueryIDs.has(id)) {
402
- results.set(existing.id, existing);
403
- break;
398
+ #lookupRowsForExecutedAndRemovedQueries(lc) {
399
+ return startAsyncSpan(
400
+ tracer,
401
+ "CVRQueryDrivenUpdater.#lookupRowsForExecutedAndRemovedQueries",
402
+ async () => {
403
+ const results = new CustomKeyMap(rowIDString);
404
+ if (this.#removedOrExecutedQueryIDs.size === 0) {
405
+ return [];
406
+ }
407
+ const allRowRecords = (await this._cvrStore.getRowRecords()).values();
408
+ let total = 0;
409
+ for (const existing of allRowRecords) {
410
+ total++;
411
+ assert(
412
+ existing.refCounts !== null,
413
+ "allRowRecords should not include null refCounts"
414
+ );
415
+ for (const id of Object.keys(existing.refCounts)) {
416
+ if (this.#removedOrExecutedQueryIDs.has(id)) {
417
+ results.set(existing.id, existing);
418
+ break;
419
+ }
420
+ }
404
421
  }
422
+ lc.debug?.(
423
+ `found ${results.size} (of ${total}) rows for executed / removed queries ${[
424
+ ...this.#removedOrExecutedQueryIDs
425
+ ]}`
426
+ );
427
+ return results.values();
405
428
  }
406
- }
407
- lc.debug?.(
408
- `found ${results.size} (of ${total}) rows for executed / removed queries ${[
409
- ...this.#removedOrExecutedQueryIDs
410
- ]}`
411
429
  );
412
- return results.values();
413
430
  }
414
431
  /**
415
432
  * Tracks an executed query, ensures that it is marked as "gotten",
@@ -418,28 +435,30 @@ class CVRQueryDrivenUpdater extends CVRUpdater {
418
435
  * This must be called for all executed queries.
419
436
  */
420
437
  #trackExecuted(queryID, transformationHash) {
421
- assert(
422
- !this.#removedOrExecutedQueryIDs.has(queryID),
423
- () => `Query ${queryID} already tracked as executed or removed`
424
- );
425
- this.#removedOrExecutedQueryIDs.add(queryID);
426
- let gotQueryPatch;
427
- const query = this._cvr.queries[queryID];
428
- if (query.transformationHash !== transformationHash) {
429
- const transformationVersion = this._ensureNewVersion();
430
- if (query.type !== "internal" && query.patchVersion === void 0) {
431
- query.patchVersion = transformationVersion;
432
- gotQueryPatch = {
433
- type: "query",
434
- op: "put",
435
- id: query.id
436
- };
438
+ return startSpan(tracer, "CVRQueryDrivenUpdater.#trackExecuted", () => {
439
+ assert(
440
+ !this.#removedOrExecutedQueryIDs.has(queryID),
441
+ () => `Query ${queryID} already tracked as executed or removed`
442
+ );
443
+ this.#removedOrExecutedQueryIDs.add(queryID);
444
+ let gotQueryPatch;
445
+ const query = this._cvr.queries[queryID];
446
+ if (query.transformationHash !== transformationHash) {
447
+ const transformationVersion = this._ensureNewVersion();
448
+ if (query.type !== "internal" && query.patchVersion === void 0) {
449
+ query.patchVersion = transformationVersion;
450
+ gotQueryPatch = {
451
+ type: "query",
452
+ op: "put",
453
+ id: query.id
454
+ };
455
+ }
456
+ query.transformationHash = transformationHash;
457
+ query.transformationVersion = transformationVersion;
458
+ this._cvrStore.updateQuery(query);
437
459
  }
438
- query.transformationHash = transformationHash;
439
- query.transformationVersion = transformationVersion;
440
- this._cvrStore.updateQuery(query);
441
- }
442
- return gotQueryPatch ? [gotQueryPatch] : [];
460
+ return gotQueryPatch ? [gotQueryPatch] : [];
461
+ });
443
462
  }
444
463
  /**
445
464
  * Tracks a query removed from the "gotten" set. In addition to producing the
@@ -452,18 +471,20 @@ class CVRQueryDrivenUpdater extends CVRUpdater {
452
471
  * This must only be called on queries that are not "desired" by any client.
453
472
  */
454
473
  #trackRemoved(queryID) {
455
- const query = this._cvr.queries[queryID];
456
- assertNotInternal(query);
457
- assert(
458
- !this.#removedOrExecutedQueryIDs.has(queryID),
459
- () => `Query ${queryID} already tracked as executed or removed`
460
- );
461
- this.#removedOrExecutedQueryIDs.add(queryID);
462
- delete this._cvr.queries[queryID];
463
- const newVersion = this._ensureNewVersion();
464
- const queryPatch = { type: "query", op: "del", id: queryID };
465
- this._cvrStore.markQueryAsDeleted(newVersion, queryPatch);
466
- return [queryPatch];
474
+ return startSpan(tracer, "CVRQueryDrivenUpdater.#trackRemoved", () => {
475
+ const query = this._cvr.queries[queryID];
476
+ assertNotInternal(query);
477
+ assert(
478
+ !this.#removedOrExecutedQueryIDs.has(queryID),
479
+ () => `Query ${queryID} already tracked as executed or removed`
480
+ );
481
+ this.#removedOrExecutedQueryIDs.add(queryID);
482
+ delete this._cvr.queries[queryID];
483
+ const newVersion = this._ensureNewVersion();
484
+ const queryPatch = { type: "query", op: "del", id: queryID };
485
+ this._cvrStore.markQueryAsDeleted(newVersion, queryPatch);
486
+ return [queryPatch];
487
+ });
467
488
  }
468
489
  /**
469
490
  * Asserts that a new version has already been set.
@@ -486,65 +507,74 @@ class CVRQueryDrivenUpdater extends CVRUpdater {
486
507
  * returns (put) patches to be returned to update their state, versioned by
487
508
  * patchVersion so that only the patches new to the clients are sent.
488
509
  */
489
- async received(_lc, rows) {
490
- const patches = [];
491
- const existingRows = await this._cvrStore.getRowRecords();
492
- for (const [id, update] of rows.entries()) {
493
- const { contents, version, refCounts } = update;
494
- let existing = existingRows.get(id);
495
- const previouslyReceived = this.#receivedRows.get(id);
496
- const merged = previouslyReceived !== void 0 ? mergeRefCounts(previouslyReceived, refCounts) : mergeRefCounts(
497
- existing?.refCounts,
498
- refCounts,
499
- this.#removedOrExecutedQueryIDs
500
- );
501
- this.#receivedRows.set(id, merged);
502
- const newRowVersion = merged === null ? void 0 : version;
503
- const patchVersion = existing && existing.rowVersion === newRowVersion ? existing.patchVersion : this.#assertNewVersion();
504
- const rowVersion = version ?? existing?.rowVersion;
505
- if (rowVersion) {
506
- this._cvrStore.putRowRecord({
507
- id,
508
- rowVersion,
509
- patchVersion,
510
- refCounts: merged
511
- });
512
- } else {
513
- this._cvrStore.delRowRecord(id);
514
- }
515
- const lastPatch = this.#lastPatches.get(id);
516
- const toVersion = maxVersion(patchVersion, lastPatch?.toVersion);
517
- if (merged === null) {
518
- if (existing || previouslyReceived) {
519
- if (lastPatch?.rowVersion !== null) {
520
- patches.push({
521
- patch: {
522
- type: "row",
523
- op: "del",
524
- id
525
- },
526
- toVersion
510
+ received(_lc, rows) {
511
+ return startAsyncSpan(
512
+ tracer,
513
+ "CVRQueryDrivenUpdater.received",
514
+ async () => {
515
+ const patches = [];
516
+ const existingRows = await this._cvrStore.getRowRecords();
517
+ for (const [id, update] of rows.entries()) {
518
+ const { contents, version, refCounts } = update;
519
+ let existing = existingRows.get(id);
520
+ const previouslyReceived = this.#receivedRows.get(id);
521
+ const merged = previouslyReceived !== void 0 ? mergeRefCounts(previouslyReceived, refCounts) : mergeRefCounts(
522
+ existing?.refCounts,
523
+ refCounts,
524
+ this.#removedOrExecutedQueryIDs
525
+ );
526
+ this.#receivedRows.set(id, merged);
527
+ const newRowVersion = merged === null ? void 0 : version;
528
+ const patchVersion = existing && existing.rowVersion === newRowVersion ? existing.patchVersion : this.#assertNewVersion();
529
+ const rowVersion = version ?? existing?.rowVersion;
530
+ if (rowVersion) {
531
+ this._cvrStore.putRowRecord({
532
+ id,
533
+ rowVersion,
534
+ patchVersion,
535
+ refCounts: merged
527
536
  });
528
- this.#lastPatches.set(id, { rowVersion: null, toVersion });
537
+ } else {
538
+ this._cvrStore.delRowRecord(id);
539
+ }
540
+ const lastPatch = this.#lastPatches.get(id);
541
+ const toVersion = maxVersion(patchVersion, lastPatch?.toVersion);
542
+ if (merged === null) {
543
+ if (existing || previouslyReceived) {
544
+ if (lastPatch?.rowVersion !== null) {
545
+ patches.push({
546
+ patch: {
547
+ type: "row",
548
+ op: "del",
549
+ id
550
+ },
551
+ toVersion
552
+ });
553
+ this.#lastPatches.set(id, { rowVersion: null, toVersion });
554
+ }
555
+ }
556
+ } else if (contents) {
557
+ assert(
558
+ rowVersion,
559
+ "rowVersion is required when contents is present"
560
+ );
561
+ if (!lastPatch?.rowVersion || lastPatch.rowVersion < rowVersion) {
562
+ patches.push({
563
+ patch: {
564
+ type: "row",
565
+ op: "put",
566
+ id,
567
+ contents
568
+ },
569
+ toVersion
570
+ });
571
+ this.#lastPatches.set(id, { rowVersion, toVersion });
572
+ }
529
573
  }
530
574
  }
531
- } else if (contents) {
532
- assert(rowVersion, "rowVersion is required when contents is present");
533
- if (!lastPatch?.rowVersion || lastPatch.rowVersion < rowVersion) {
534
- patches.push({
535
- patch: {
536
- type: "row",
537
- op: "put",
538
- id,
539
- contents
540
- },
541
- toVersion
542
- });
543
- this.#lastPatches.set(id, { rowVersion, toVersion });
544
- }
575
+ return patches;
545
576
  }
546
- }
547
- return patches;
577
+ );
548
578
  }
549
579
  /**
550
580
  * Computes and updates the row records based on:
@@ -558,49 +588,61 @@ class CVRQueryDrivenUpdater extends CVRUpdater {
558
588
  * This is Step [5] of the
559
589
  * [CVR Sync Algorithm](https://www.notion.so/replicache/Sync-and-Client-View-Records-CVR-a18e02ec3ec543449ea22070855ff33d?pvs=4#7874f9b80a514be2b8cd5cf538b88d37).
560
590
  */
561
- async deleteUnreferencedRows(lc) {
562
- if (this.#removedOrExecutedQueryIDs.size === 0) {
563
- assert(
564
- this.#receivedRows.size === 0,
565
- () => `Expected no received rows for query-less update, got ${this.#receivedRows.size}`
566
- );
567
- return [];
568
- }
569
- const patches = [];
570
- const start = Date.now();
571
- assert(this.#existingRows, `trackQueries() was not called`);
572
- for (const existing of await this.#existingRows) {
573
- const deletedID = this.#deleteUnreferencedRow(existing);
574
- if (deletedID === null) {
575
- continue;
591
+ deleteUnreferencedRows(lc) {
592
+ return startAsyncSpan(
593
+ tracer,
594
+ "CVRQueryDrivenUpdater.deleteUnreferencedRows",
595
+ async () => {
596
+ if (this.#removedOrExecutedQueryIDs.size === 0) {
597
+ assert(
598
+ this.#receivedRows.size === 0,
599
+ () => `Expected no received rows for query-less update, got ${this.#receivedRows.size}`
600
+ );
601
+ return [];
602
+ }
603
+ const patches = [];
604
+ const start = Date.now();
605
+ assert(this.#existingRows, `trackQueries() was not called`);
606
+ for (const existing of await this.#existingRows) {
607
+ const deletedID = this.#deleteUnreferencedRow(existing);
608
+ if (deletedID === null) {
609
+ continue;
610
+ }
611
+ patches.push({
612
+ toVersion: this._cvr.version,
613
+ patch: { type: "row", op: "del", id: deletedID }
614
+ });
615
+ }
616
+ lc?.debug?.(
617
+ `computed ${patches.length} delete patches (${Date.now() - start} ms)`
618
+ );
619
+ return patches;
576
620
  }
577
- patches.push({
578
- toVersion: this._cvr.version,
579
- patch: { type: "row", op: "del", id: deletedID }
580
- });
581
- }
582
- lc?.debug?.(
583
- `computed ${patches.length} delete patches (${Date.now() - start} ms)`
584
621
  );
585
- return patches;
586
622
  }
587
623
  #deleteUnreferencedRow(existing) {
588
- if (this.#receivedRows.get(existing.id)) {
589
- return null;
590
- }
591
- const newRefCounts = mergeRefCounts(
592
- existing.refCounts,
593
- void 0,
594
- this.#removedOrExecutedQueryIDs
624
+ return startSpan(
625
+ tracer,
626
+ "CVRQueryDrivenUpdater.#deleteUnreferencedRow",
627
+ () => {
628
+ if (this.#receivedRows.get(existing.id)) {
629
+ return null;
630
+ }
631
+ const newRefCounts = mergeRefCounts(
632
+ existing.refCounts,
633
+ void 0,
634
+ this.#removedOrExecutedQueryIDs
635
+ );
636
+ const patchVersion = newRefCounts ? existing.patchVersion : this.#assertNewVersion();
637
+ const rowRecord = {
638
+ ...existing,
639
+ patchVersion,
640
+ refCounts: newRefCounts
641
+ };
642
+ this._cvrStore.putRowRecord(rowRecord);
643
+ return newRefCounts ? null : existing.id;
644
+ }
595
645
  );
596
- const patchVersion = newRefCounts ? existing.patchVersion : this.#assertNewVersion();
597
- const rowRecord = {
598
- ...existing,
599
- patchVersion,
600
- refCounts: newRefCounts
601
- };
602
- this._cvrStore.putRowRecord(rowRecord);
603
- return newRefCounts ? null : existing.id;
604
646
  }
605
647
  }
606
648
  function mergeRefCounts(existing, received, removeHashes) {