@rocicorp/zero 1.10.0-canary.22 → 1.10.0-canary.24

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 (302) hide show
  1. package/out/analyze-query/src/analyze-cli.js +2 -2
  2. package/out/analyze-query/src/analyze-cli.js.map +1 -1
  3. package/out/analyze-query/src/bin-analyze.js +9 -8
  4. package/out/analyze-query/src/bin-analyze.js.map +1 -1
  5. package/out/replicache/src/btree/node.d.ts.map +1 -1
  6. package/out/replicache/src/btree/node.js +3 -6
  7. package/out/replicache/src/btree/node.js.map +1 -1
  8. package/out/replicache/src/dag/gc.d.ts.map +1 -1
  9. package/out/replicache/src/dag/gc.js +6 -10
  10. package/out/replicache/src/dag/gc.js.map +1 -1
  11. package/out/replicache/src/kv/sqlite-store.d.ts.map +1 -1
  12. package/out/replicache/src/kv/sqlite-store.js +24 -2
  13. package/out/replicache/src/kv/sqlite-store.js.map +1 -1
  14. package/out/replicache/src/persist/persist.js +1 -1
  15. package/out/shared/src/arrays.d.ts +5 -0
  16. package/out/shared/src/arrays.d.ts.map +1 -1
  17. package/out/shared/src/arrays.js +8 -10
  18. package/out/shared/src/arrays.js.map +1 -1
  19. package/out/shared/src/map.d.ts +19 -2
  20. package/out/shared/src/map.d.ts.map +1 -1
  21. package/out/shared/src/map.js +18 -4
  22. package/out/shared/src/map.js.map +1 -1
  23. package/out/z2s/src/compiler.js +1 -1
  24. package/out/z2s/src/sql.d.ts.map +1 -1
  25. package/out/z2s/src/sql.js +2 -2
  26. package/out/z2s/src/sql.js.map +1 -1
  27. package/out/zero/package.js +1 -1
  28. package/out/zero/package.js.map +1 -1
  29. package/out/zero-cache/src/auth/write-authorizer.d.ts.map +1 -1
  30. package/out/zero-cache/src/auth/write-authorizer.js +1 -0
  31. package/out/zero-cache/src/auth/write-authorizer.js.map +1 -1
  32. package/out/zero-cache/src/config/zero-config.d.ts +23 -0
  33. package/out/zero-cache/src/config/zero-config.d.ts.map +1 -1
  34. package/out/zero-cache/src/config/zero-config.js +63 -1
  35. package/out/zero-cache/src/config/zero-config.js.map +1 -1
  36. package/out/zero-cache/src/db/lite-tables.d.ts.map +1 -1
  37. package/out/zero-cache/src/db/lite-tables.js +3 -4
  38. package/out/zero-cache/src/db/lite-tables.js.map +1 -1
  39. package/out/zero-cache/src/observability/metrics.d.ts.map +1 -1
  40. package/out/zero-cache/src/observability/metrics.js +2 -7
  41. package/out/zero-cache/src/observability/metrics.js.map +1 -1
  42. package/out/zero-cache/src/server/change-streamer.d.ts.map +1 -1
  43. package/out/zero-cache/src/server/change-streamer.js +11 -3
  44. package/out/zero-cache/src/server/change-streamer.js.map +1 -1
  45. package/out/zero-cache/src/server/inspector-delegate.d.ts +18 -2
  46. package/out/zero-cache/src/server/inspector-delegate.d.ts.map +1 -1
  47. package/out/zero-cache/src/server/inspector-delegate.js +22 -15
  48. package/out/zero-cache/src/server/inspector-delegate.js.map +1 -1
  49. package/out/zero-cache/src/server/main.d.ts.map +1 -1
  50. package/out/zero-cache/src/server/main.js +8 -1
  51. package/out/zero-cache/src/server/main.js.map +1 -1
  52. package/out/zero-cache/src/server/mutator.js +2 -0
  53. package/out/zero-cache/src/server/mutator.js.map +1 -1
  54. package/out/zero-cache/src/server/reaper.d.ts.map +1 -1
  55. package/out/zero-cache/src/server/reaper.js +2 -0
  56. package/out/zero-cache/src/server/reaper.js.map +1 -1
  57. package/out/zero-cache/src/server/replicator.d.ts.map +1 -1
  58. package/out/zero-cache/src/server/replicator.js +2 -0
  59. package/out/zero-cache/src/server/replicator.js.map +1 -1
  60. package/out/zero-cache/src/server/runner/zero-dispatcher.d.ts.map +1 -1
  61. package/out/zero-cache/src/server/runner/zero-dispatcher.js +3 -0
  62. package/out/zero-cache/src/server/runner/zero-dispatcher.js.map +1 -1
  63. package/out/zero-cache/src/server/syncer.d.ts.map +1 -1
  64. package/out/zero-cache/src/server/syncer.js +5 -1
  65. package/out/zero-cache/src/server/syncer.js.map +1 -1
  66. package/out/zero-cache/src/services/analyze.d.ts.map +1 -1
  67. package/out/zero-cache/src/services/analyze.js +11 -9
  68. package/out/zero-cache/src/services/analyze.js.map +1 -1
  69. package/out/zero-cache/src/services/change-source/common/backfill-manager.d.ts.map +1 -1
  70. package/out/zero-cache/src/services/change-source/common/backfill-manager.js +14 -1
  71. package/out/zero-cache/src/services/change-source/common/backfill-manager.js.map +1 -1
  72. package/out/zero-cache/src/services/change-source/common/change-stream-multiplexer.d.ts.map +1 -1
  73. package/out/zero-cache/src/services/change-source/common/change-stream-multiplexer.js +15 -3
  74. package/out/zero-cache/src/services/change-source/common/change-stream-multiplexer.js.map +1 -1
  75. package/out/zero-cache/src/services/change-source/custom/change-source.js +2 -2
  76. package/out/zero-cache/src/services/change-source/custom/change-source.js.map +1 -1
  77. package/out/zero-cache/src/services/change-source/pg/initial-sync.js +1 -1
  78. package/out/zero-cache/src/services/change-streamer/change-streamer-http.d.ts +3 -0
  79. package/out/zero-cache/src/services/change-streamer/change-streamer-http.d.ts.map +1 -1
  80. package/out/zero-cache/src/services/change-streamer/change-streamer-http.js +6 -4
  81. package/out/zero-cache/src/services/change-streamer/change-streamer-http.js.map +1 -1
  82. package/out/zero-cache/src/services/mutagen/mutagen.d.ts +5 -0
  83. package/out/zero-cache/src/services/mutagen/mutagen.d.ts.map +1 -1
  84. package/out/zero-cache/src/services/mutagen/mutagen.js +7 -1
  85. package/out/zero-cache/src/services/mutagen/mutagen.js.map +1 -1
  86. package/out/zero-cache/src/services/mutagen/pusher.d.ts +32 -32
  87. package/out/zero-cache/src/services/mutagen/pusher.d.ts.map +1 -1
  88. package/out/zero-cache/src/services/mutagen/pusher.js +5 -6
  89. package/out/zero-cache/src/services/mutagen/pusher.js.map +1 -1
  90. package/out/zero-cache/src/services/profz.d.ts +7 -0
  91. package/out/zero-cache/src/services/profz.d.ts.map +1 -0
  92. package/out/zero-cache/src/services/profz.js +103 -0
  93. package/out/zero-cache/src/services/profz.js.map +1 -0
  94. package/out/zero-cache/src/services/run-ast.d.ts +12 -0
  95. package/out/zero-cache/src/services/run-ast.d.ts.map +1 -1
  96. package/out/zero-cache/src/services/run-ast.js +26 -14
  97. package/out/zero-cache/src/services/run-ast.js.map +1 -1
  98. package/out/zero-cache/src/services/runner.d.ts.map +1 -1
  99. package/out/zero-cache/src/services/runner.js +1 -1
  100. package/out/zero-cache/src/services/runner.js.map +1 -1
  101. package/out/zero-cache/src/services/view-syncer/cvr.d.ts +45 -0
  102. package/out/zero-cache/src/services/view-syncer/cvr.d.ts.map +1 -1
  103. package/out/zero-cache/src/services/view-syncer/cvr.js +133 -1
  104. package/out/zero-cache/src/services/view-syncer/cvr.js.map +1 -1
  105. package/out/zero-cache/src/services/view-syncer/drain-coordinator.d.ts +14 -1
  106. package/out/zero-cache/src/services/view-syncer/drain-coordinator.d.ts.map +1 -1
  107. package/out/zero-cache/src/services/view-syncer/drain-coordinator.js +30 -4
  108. package/out/zero-cache/src/services/view-syncer/drain-coordinator.js.map +1 -1
  109. package/out/zero-cache/src/services/view-syncer/hydration-budget.d.ts +33 -0
  110. package/out/zero-cache/src/services/view-syncer/hydration-budget.d.ts.map +1 -0
  111. package/out/zero-cache/src/services/view-syncer/hydration-budget.js +62 -0
  112. package/out/zero-cache/src/services/view-syncer/hydration-budget.js.map +1 -0
  113. package/out/zero-cache/src/services/view-syncer/hydration-circuit-breaker.d.ts +51 -0
  114. package/out/zero-cache/src/services/view-syncer/hydration-circuit-breaker.d.ts.map +1 -0
  115. package/out/zero-cache/src/services/view-syncer/hydration-circuit-breaker.js +78 -0
  116. package/out/zero-cache/src/services/view-syncer/hydration-circuit-breaker.js.map +1 -0
  117. package/out/zero-cache/src/services/view-syncer/inspect-handler.d.ts +1 -1
  118. package/out/zero-cache/src/services/view-syncer/inspect-handler.d.ts.map +1 -1
  119. package/out/zero-cache/src/services/view-syncer/inspect-handler.js +2 -2
  120. package/out/zero-cache/src/services/view-syncer/inspect-handler.js.map +1 -1
  121. package/out/zero-cache/src/services/view-syncer/pipeline-driver.d.ts +2 -1
  122. package/out/zero-cache/src/services/view-syncer/pipeline-driver.d.ts.map +1 -1
  123. package/out/zero-cache/src/services/view-syncer/pipeline-driver.js +42 -17
  124. package/out/zero-cache/src/services/view-syncer/pipeline-driver.js.map +1 -1
  125. package/out/zero-cache/src/services/view-syncer/query-covering.d.ts.map +1 -1
  126. package/out/zero-cache/src/services/view-syncer/query-covering.js +2 -6
  127. package/out/zero-cache/src/services/view-syncer/query-covering.js.map +1 -1
  128. package/out/zero-cache/src/services/view-syncer/snapshot-row-cache.d.ts +95 -0
  129. package/out/zero-cache/src/services/view-syncer/snapshot-row-cache.d.ts.map +1 -0
  130. package/out/zero-cache/src/services/view-syncer/snapshot-row-cache.js +155 -0
  131. package/out/zero-cache/src/services/view-syncer/snapshot-row-cache.js.map +1 -0
  132. package/out/zero-cache/src/services/view-syncer/snapshotter.d.ts +42 -4
  133. package/out/zero-cache/src/services/view-syncer/snapshotter.d.ts.map +1 -1
  134. package/out/zero-cache/src/services/view-syncer/snapshotter.js +117 -28
  135. package/out/zero-cache/src/services/view-syncer/snapshotter.js.map +1 -1
  136. package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts +11 -1
  137. package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts.map +1 -1
  138. package/out/zero-cache/src/services/view-syncer/view-syncer.js +466 -95
  139. package/out/zero-cache/src/services/view-syncer/view-syncer.js.map +1 -1
  140. package/out/zero-cache/src/types/processes.d.ts +32 -0
  141. package/out/zero-cache/src/types/processes.d.ts.map +1 -1
  142. package/out/zero-cache/src/types/processes.js +43 -4
  143. package/out/zero-cache/src/types/processes.js.map +1 -1
  144. package/out/zero-cache/src/types/profiler.d.ts +12 -0
  145. package/out/zero-cache/src/types/profiler.d.ts.map +1 -1
  146. package/out/zero-cache/src/types/profiler.js +46 -1
  147. package/out/zero-cache/src/types/profiler.js.map +1 -1
  148. package/out/zero-cache/src/types/row-key.d.ts.map +1 -1
  149. package/out/zero-cache/src/types/row-key.js +5 -5
  150. package/out/zero-cache/src/types/row-key.js.map +1 -1
  151. package/out/zero-cache/src/workers/connection.js +3 -3
  152. package/out/zero-cache/src/workers/connection.js.map +1 -1
  153. package/out/zero-cache/src/workers/syncer-ws-message-handler.d.ts.map +1 -1
  154. package/out/zero-cache/src/workers/syncer-ws-message-handler.js +21 -16
  155. package/out/zero-cache/src/workers/syncer-ws-message-handler.js.map +1 -1
  156. package/out/zero-cache/src/workers/syncer.d.ts.map +1 -1
  157. package/out/zero-cache/src/workers/syncer.js +10 -1
  158. package/out/zero-cache/src/workers/syncer.js.map +1 -1
  159. package/out/zero-client/src/client/context.d.ts +16 -3
  160. package/out/zero-client/src/client/context.d.ts.map +1 -1
  161. package/out/zero-client/src/client/context.js +85 -14
  162. package/out/zero-client/src/client/context.js.map +1 -1
  163. package/out/zero-client/src/client/ivm-branch.d.ts.map +1 -1
  164. package/out/zero-client/src/client/ivm-branch.js +20 -3
  165. package/out/zero-client/src/client/ivm-branch.js.map +1 -1
  166. package/out/zero-client/src/client/query-manager.d.ts.map +1 -1
  167. package/out/zero-client/src/client/query-manager.js +2 -5
  168. package/out/zero-client/src/client/query-manager.js.map +1 -1
  169. package/out/zero-client/src/client/version.js +1 -1
  170. package/out/zero-client/src/client/zero-rep.d.ts.map +1 -1
  171. package/out/zero-client/src/client/zero-rep.js +1 -1
  172. package/out/zero-client/src/client/zero-rep.js.map +1 -1
  173. package/out/zero-client/src/client/zero.d.ts.map +1 -1
  174. package/out/zero-client/src/client/zero.js +2 -2
  175. package/out/zero-client/src/client/zero.js.map +1 -1
  176. package/out/zero-protocol/src/analyze-query-result.d.ts +5 -5
  177. package/out/zero-protocol/src/analyze-query-result.d.ts.map +1 -1
  178. package/out/zero-protocol/src/analyze-query-result.js +1 -1
  179. package/out/zero-protocol/src/analyze-query-result.js.map +1 -1
  180. package/out/zero-protocol/src/ast.d.ts.map +1 -1
  181. package/out/zero-protocol/src/ast.js +13 -14
  182. package/out/zero-protocol/src/ast.js.map +1 -1
  183. package/out/zero-protocol/src/down.d.ts +2 -2
  184. package/out/zero-protocol/src/error.d.ts +1 -1
  185. package/out/zero-protocol/src/inspect-down.d.ts +6 -6
  186. package/out/zero-protocol/src/protocol-version.d.ts.map +1 -1
  187. package/out/zero-protocol/src/protocol-version.js.map +1 -1
  188. package/out/zero-protocol/src/query-hash.d.ts.map +1 -1
  189. package/out/zero-protocol/src/query-hash.js +2 -5
  190. package/out/zero-protocol/src/query-hash.js.map +1 -1
  191. package/out/zero-solid/src/solid-view.d.ts +7 -0
  192. package/out/zero-solid/src/solid-view.d.ts.map +1 -1
  193. package/out/zero-solid/src/solid-view.js +13 -2
  194. package/out/zero-solid/src/solid-view.js.map +1 -1
  195. package/out/zql/src/builder/builder.d.ts +19 -0
  196. package/out/zql/src/builder/builder.d.ts.map +1 -1
  197. package/out/zql/src/builder/builder.js +28 -11
  198. package/out/zql/src/builder/builder.js.map +1 -1
  199. package/out/zql/src/builder/correlated-predicate-pushdown.d.ts +43 -0
  200. package/out/zql/src/builder/correlated-predicate-pushdown.d.ts.map +1 -0
  201. package/out/zql/src/builder/correlated-predicate-pushdown.js +161 -0
  202. package/out/zql/src/builder/correlated-predicate-pushdown.js.map +1 -0
  203. package/out/zql/src/builder/debug-delegate.d.ts +6 -1
  204. package/out/zql/src/builder/debug-delegate.d.ts.map +1 -1
  205. package/out/zql/src/builder/debug-delegate.js +14 -2
  206. package/out/zql/src/builder/debug-delegate.js.map +1 -1
  207. package/out/zql/src/ivm/array-view.d.ts +19 -0
  208. package/out/zql/src/ivm/array-view.d.ts.map +1 -1
  209. package/out/zql/src/ivm/array-view.js +39 -2
  210. package/out/zql/src/ivm/array-view.js.map +1 -1
  211. package/out/zql/src/ivm/connection-index.d.ts +68 -0
  212. package/out/zql/src/ivm/connection-index.d.ts.map +1 -0
  213. package/out/zql/src/ivm/connection-index.js +149 -0
  214. package/out/zql/src/ivm/connection-index.js.map +1 -0
  215. package/out/zql/src/ivm/exists.js +1 -1
  216. package/out/zql/src/ivm/filter-operators.d.ts +3 -2
  217. package/out/zql/src/ivm/filter-operators.d.ts.map +1 -1
  218. package/out/zql/src/ivm/filter-operators.js +19 -4
  219. package/out/zql/src/ivm/filter-operators.js.map +1 -1
  220. package/out/zql/src/ivm/memory-source.d.ts +13 -1
  221. package/out/zql/src/ivm/memory-source.d.ts.map +1 -1
  222. package/out/zql/src/ivm/memory-source.js +43 -4
  223. package/out/zql/src/ivm/memory-source.js.map +1 -1
  224. package/out/zql/src/ivm/operator.d.ts +40 -0
  225. package/out/zql/src/ivm/operator.d.ts.map +1 -1
  226. package/out/zql/src/ivm/operator.js.map +1 -1
  227. package/out/zql/src/ivm/view.d.ts +15 -0
  228. package/out/zql/src/ivm/view.d.ts.map +1 -1
  229. package/out/zql/src/planner/planner-builder.d.ts +12 -3
  230. package/out/zql/src/planner/planner-builder.d.ts.map +1 -1
  231. package/out/zql/src/planner/planner-builder.js +40 -20
  232. package/out/zql/src/planner/planner-builder.js.map +1 -1
  233. package/out/zql/src/planner/planner-connection.d.ts +28 -2
  234. package/out/zql/src/planner/planner-connection.d.ts.map +1 -1
  235. package/out/zql/src/planner/planner-connection.js +108 -8
  236. package/out/zql/src/planner/planner-connection.js.map +1 -1
  237. package/out/zql/src/planner/planner-debug.d.ts +1 -1
  238. package/out/zql/src/planner/planner-debug.d.ts.map +1 -1
  239. package/out/zql/src/planner/planner-debug.js +3 -8
  240. package/out/zql/src/planner/planner-debug.js.map +1 -1
  241. package/out/zql/src/planner/planner-fan-out.d.ts +1 -0
  242. package/out/zql/src/planner/planner-fan-out.d.ts.map +1 -1
  243. package/out/zql/src/planner/planner-fan-out.js +3 -0
  244. package/out/zql/src/planner/planner-fan-out.js.map +1 -1
  245. package/out/zql/src/planner/planner-filter.d.ts +59 -0
  246. package/out/zql/src/planner/planner-filter.d.ts.map +1 -0
  247. package/out/zql/src/planner/planner-filter.js +116 -0
  248. package/out/zql/src/planner/planner-filter.js.map +1 -0
  249. package/out/zql/src/planner/planner-graph.d.ts +2 -0
  250. package/out/zql/src/planner/planner-graph.d.ts.map +1 -1
  251. package/out/zql/src/planner/planner-graph.js +2 -0
  252. package/out/zql/src/planner/planner-graph.js.map +1 -1
  253. package/out/zql/src/planner/planner-join.d.ts +2 -0
  254. package/out/zql/src/planner/planner-join.d.ts.map +1 -1
  255. package/out/zql/src/planner/planner-join.js +7 -0
  256. package/out/zql/src/planner/planner-join.js.map +1 -1
  257. package/out/zql/src/planner/planner-node.d.ts +2 -1
  258. package/out/zql/src/planner/planner-node.d.ts.map +1 -1
  259. package/out/zql/src/planner/planner-node.js.map +1 -1
  260. package/out/zql/src/planner/planner-source.d.ts +2 -2
  261. package/out/zql/src/planner/planner-source.d.ts.map +1 -1
  262. package/out/zql/src/planner/planner-source.js +2 -2
  263. package/out/zql/src/planner/planner-source.js.map +1 -1
  264. package/out/zql/src/query/query-delegate-base.d.ts +2 -2
  265. package/out/zql/src/query/query-delegate-base.d.ts.map +1 -1
  266. package/out/zql/src/query/query-delegate-base.js +16 -10
  267. package/out/zql/src/query/query-delegate-base.js.map +1 -1
  268. package/out/zql/src/query/query-delegate.d.ts +22 -5
  269. package/out/zql/src/query/query-delegate.d.ts.map +1 -1
  270. package/out/zql/src/query/query-impl.d.ts.map +1 -1
  271. package/out/zql/src/query/query-impl.js +6 -23
  272. package/out/zql/src/query/query-impl.js.map +1 -1
  273. package/out/zql/src/query/query-transitions.d.ts.map +1 -1
  274. package/out/zql/src/query/query-transitions.js +2 -5
  275. package/out/zql/src/query/query-transitions.js.map +1 -1
  276. package/out/zql/src/query/query.d.ts +4 -1
  277. package/out/zql/src/query/query.d.ts.map +1 -1
  278. package/out/zql/src/query/runnable-query-impl.d.ts.map +1 -1
  279. package/out/zql/src/query/runnable-query-impl.js +2 -10
  280. package/out/zql/src/query/runnable-query-impl.js.map +1 -1
  281. package/out/zqlite/src/db.d.ts +9 -1
  282. package/out/zqlite/src/db.d.ts.map +1 -1
  283. package/out/zqlite/src/db.js +8 -2
  284. package/out/zqlite/src/db.js.map +1 -1
  285. package/out/zqlite/src/query-builder.d.ts +1 -1
  286. package/out/zqlite/src/query-builder.d.ts.map +1 -1
  287. package/out/zqlite/src/query-builder.js +2 -1
  288. package/out/zqlite/src/query-builder.js.map +1 -1
  289. package/out/zqlite/src/query-delegate.d.ts.map +1 -1
  290. package/out/zqlite/src/query-delegate.js +5 -6
  291. package/out/zqlite/src/query-delegate.js.map +1 -1
  292. package/out/zqlite/src/sqlite-cost-model.d.ts.map +1 -1
  293. package/out/zqlite/src/sqlite-cost-model.js +2 -30
  294. package/out/zqlite/src/sqlite-cost-model.js.map +1 -1
  295. package/out/zqlite/src/sqlite-stat-fanout.d.ts.map +1 -1
  296. package/out/zqlite/src/sqlite-stat-fanout.js +3 -5
  297. package/out/zqlite/src/sqlite-stat-fanout.js.map +1 -1
  298. package/out/zqlite/src/table-source.d.ts +15 -2
  299. package/out/zqlite/src/table-source.d.ts.map +1 -1
  300. package/out/zqlite/src/table-source.js +28 -12
  301. package/out/zqlite/src/table-source.js.map +1 -1
  302. package/package.json +1 -1
@@ -6,7 +6,7 @@ import { using, withRead } from "../../../replicache/src/with-transactions.js";
6
6
  import { must } from "../../../shared/src/must.js";
7
7
  import { diffBinarySearch } from "../../../replicache/src/subscriptions.js";
8
8
  import { consume } from "../../../zql/src/ivm/stream.js";
9
- import { makeSourceChangeAdd, makeSourceChangeEdit, makeSourceChangeRemove } from "../../../zql/src/ivm/source.js";
9
+ import { makeSourceChangeEdit, makeSourceChangeRemove } from "../../../zql/src/ivm/source.js";
10
10
  import { MemorySource } from "../../../zql/src/ivm/memory-source.js";
11
11
  import { sourceNameFromKey } from "./keys.js";
12
12
  //#region ../zero-client/src/client/ivm-branch.ts
@@ -119,15 +119,32 @@ function applyDiffs(diffs, branch) {
119
119
  case "del":
120
120
  consume(source.push(makeSourceChangeRemove(diff.oldValue)));
121
121
  break;
122
- case "add":
123
- consume(source.push(makeSourceChangeAdd(diff.newValue)));
122
+ case "add": {
123
+ const rows = takeAddsForSource(diffs, i, name);
124
+ i += rows.length - 1;
125
+ source.pushAdds(rows);
124
126
  break;
127
+ }
125
128
  case "change":
126
129
  consume(source.push(makeSourceChangeEdit(diff.newValue, diff.oldValue)));
127
130
  break;
128
131
  }
129
132
  }
130
133
  }
134
+ /**
135
+ * Returns the rows of the run of `add` diffs for the source `name` that starts
136
+ * at `start`. Diffs are ordered by key so a table's rows are contiguous.
137
+ */
138
+ function takeAddsForSource(diffs, start, name) {
139
+ const prefix = "e/" + name + "/";
140
+ const rows = [];
141
+ for (let i = start; i < diffs.length; i++) {
142
+ const diff = diffs[i];
143
+ if (diff.op !== "add" || !diff.key.startsWith(prefix)) break;
144
+ rows.push(diff.newValue);
145
+ }
146
+ return rows;
147
+ }
131
148
  //#endregion
132
149
  export { IVMSourceBranch };
133
150
 
@@ -1 +1 @@
1
- {"version":3,"file":"ivm-branch.js","names":["#sources","#tables","#throwIfInvalid","#advanceError"],"sources":["../../../../../zero-client/src/client/ivm-branch.ts"],"sourcesContent":["import type {\n InternalDiff,\n InternalDiffOperation,\n NoIndexDiff,\n} from '../../../replicache/src/btree/node.ts';\nimport type {LazyStore} from '../../../replicache/src/dag/lazy-store.ts';\nimport {type Read, type Store} from '../../../replicache/src/dag/store.ts';\nimport {readFromHash} from '../../../replicache/src/db/read.ts';\nimport * as FormatVersion from '../../../replicache/src/format-version-enum.ts';\nimport type {Hash} from '../../../replicache/src/hash.ts';\nimport type {ZeroReadOptions} from '../../../replicache/src/replicache-options.ts';\nimport {diffBinarySearch} from '../../../replicache/src/subscriptions.ts';\nimport type {DiffsMap} from '../../../replicache/src/sync/diff.ts';\nimport {diff} from '../../../replicache/src/sync/diff.ts';\nimport {using, withRead} from '../../../replicache/src/with-transactions.ts';\nimport {assert} from '../../../shared/src/asserts.ts';\nimport {wrapIterable} from '../../../shared/src/iterables.ts';\nimport {must} from '../../../shared/src/must.ts';\nimport type {Row} from '../../../zero-protocol/src/data.ts';\nimport type {TableSchema} from '../../../zero-schema/src/table-schema.ts';\nimport {MemorySource} from '../../../zql/src/ivm/memory-source.ts';\nimport {consume} from '../../../zql/src/ivm/stream.ts';\nimport {ENTITIES_KEY_PREFIX, sourceNameFromKey} from './keys.ts';\n\nimport {\n makeSourceChangeAdd,\n makeSourceChangeEdit,\n makeSourceChangeRemove,\n} from '../../../zql/src/ivm/source.ts';\n/**\n * Replicache needs to rebase mutations onto different\n * commits of it's b-tree. These mutations can have reads\n * in them and those reads must be run against the IVM sources.\n *\n * To ensure the reads get the correct state, the IVM\n * sources need to reflect the state of the commit\n * being rebased onto. `IVMSourceBranch` allows us to:\n * 1. fork the IVM sources\n * 2. patch them up to match the desired head\n * 3. run the reads against the forked sources\n *\n * (2) is expected to be a cheap operation as there should only\n * ever be a few outstanding diffs to apply given Zero is meant\n * to be run in a connected state.\n */\nexport class IVMSourceBranch {\n readonly #sources: Map<string, MemorySource | undefined>;\n readonly #tables: Record<string, TableSchema>;\n #advanceError: unknown;\n hash: Hash | undefined;\n\n constructor(\n tables: Record<string, TableSchema>,\n hash?: Hash,\n sources: Map<string, MemorySource | undefined> = new Map(),\n ) {\n this.#tables = tables;\n this.#sources = sources;\n this.hash = hash;\n }\n\n getSource(name: string): MemorySource | undefined {\n this.#throwIfInvalid();\n\n if (this.#sources.has(name)) {\n return this.#sources.get(name);\n }\n\n const schema = this.#tables[name];\n const source = schema\n ? new MemorySource(name, schema.columns, schema.primaryKey)\n : undefined;\n this.#sources.set(name, source);\n return source;\n }\n\n clear() {\n this.#sources.clear();\n }\n\n #throwIfInvalid() {\n if (this.#advanceError) {\n throw this.#advanceError;\n }\n }\n\n /**\n * Mutates the current branch, advancing it to the new head\n * by applying the given diffs.\n */\n advance(expectedHead: Hash | undefined, newHead: Hash, diffs: NoIndexDiff) {\n this.#throwIfInvalid();\n\n assert(\n this.hash === expectedHead,\n () =>\n `Expected head must match the main head. Got: ${this.hash}, expected: ${expectedHead}`,\n );\n\n try {\n applyDiffs(diffs, this);\n this.hash = newHead;\n } catch (e) {\n this.#advanceError = e;\n this.clear();\n throw e;\n }\n }\n\n /**\n * Fork the branch and patch it up to match the desired head.\n */\n async forkToHead(\n store: LazyStore,\n desiredHead: Hash,\n readOptions?: ZeroReadOptions,\n ): Promise<IVMSourceBranch> {\n this.#throwIfInvalid();\n\n const fork = this.fork();\n\n if (fork.hash === desiredHead) {\n return fork;\n }\n\n await patchBranch(desiredHead, store, fork, readOptions);\n fork.hash = desiredHead;\n return fork;\n }\n\n /**\n * Creates a new IVMSourceBranch that is a copy of the current one.\n * This is a cheap operation since the b-trees are shared until a write is performed\n * and then only the modified nodes are copied.\n *\n * IVM branches are forked when we need to rebase mutations.\n * The mutations modify the fork rather than original branch.\n */\n fork() {\n this.#throwIfInvalid();\n\n return new IVMSourceBranch(\n this.#tables,\n this.hash,\n new Map(\n wrapIterable(this.#sources.entries()).map(([name, source]) => [\n name,\n source?.fork(),\n ]),\n ),\n );\n }\n}\n\nexport async function initFromStore(\n branch: IVMSourceBranch,\n hash: Hash,\n store: Store,\n) {\n const diffs: InternalDiffOperation[] = [];\n await withRead(store, async dagRead => {\n const read = await readFromHash(hash, dagRead, FormatVersion.Latest);\n for await (const entry of read.map.scan(ENTITIES_KEY_PREFIX, true)) {\n if (!entry[0].startsWith(ENTITIES_KEY_PREFIX)) {\n break;\n }\n diffs.push({\n op: 'add',\n key: entry[0],\n newValue: entry[1],\n });\n }\n });\n\n branch.advance(undefined, hash, diffs);\n}\n\nasync function patchBranch(\n desiredHead: Hash,\n store: LazyStore,\n fork: IVMSourceBranch,\n readOptions: ZeroReadOptions | undefined,\n) {\n const diffs = await computeDiffs(\n must(fork.hash),\n desiredHead,\n store,\n readOptions,\n );\n if (!diffs) {\n return;\n }\n applyDiffs(diffs, fork);\n}\n\nasync function computeDiffs(\n startHash: Hash,\n endHash: Hash,\n store: LazyStore,\n readOptions: ZeroReadOptions | undefined,\n): Promise<InternalDiff | undefined> {\n const readFn = (dagRead: Read) =>\n diff(\n startHash,\n endHash,\n dagRead,\n {\n shouldComputeDiffs: () => true,\n shouldComputeDiffsForIndex(_name) {\n return false;\n },\n },\n FormatVersion.Latest,\n );\n\n let diffs: DiffsMap;\n if (readOptions?.openLazySourceRead) {\n diffs = await using(store.read(readOptions.openLazySourceRead), readFn);\n } else if (readOptions?.openLazyRead) {\n diffs = await readFn(readOptions.openLazyRead);\n } else {\n diffs = await withRead(store, readFn);\n }\n\n return diffs.get('');\n}\n\nfunction applyDiffs(diffs: NoIndexDiff, branch: IVMSourceBranch) {\n for (\n let i = diffBinarySearch(diffs, ENTITIES_KEY_PREFIX, diff => diff.key);\n i < diffs.length;\n i++\n ) {\n const diff = diffs[i];\n const {key} = diff;\n if (!key.startsWith(ENTITIES_KEY_PREFIX)) {\n break;\n }\n const name = sourceNameFromKey(key);\n const source = must(branch.getSource(name));\n switch (diff.op) {\n case 'del':\n consume(source.push(makeSourceChangeRemove(diff.oldValue as Row)));\n break;\n case 'add':\n consume(source.push(makeSourceChangeAdd(diff.newValue as Row)));\n break;\n case 'change':\n consume(\n source.push(\n makeSourceChangeEdit(diff.newValue as Row, diff.oldValue as Row),\n ),\n );\n break;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,IAAa,kBAAb,MAAa,gBAAgB;CAC3B;CACA;CACA;CACA;CAEA,YACE,QACA,MACA,0BAAiD,IAAI,IAAI,GACzD;EACA,KAAKC,UAAU;EACf,KAAKD,WAAW;EAChB,KAAK,OAAO;CACd;CAEA,UAAU,MAAwC;EAChD,KAAKE,gBAAgB;EAErB,IAAI,KAAKF,SAAS,IAAI,IAAI,GACxB,OAAO,KAAKA,SAAS,IAAI,IAAI;EAG/B,MAAM,SAAS,KAAKC,QAAQ;EAC5B,MAAM,SAAS,SACX,IAAI,aAAa,MAAM,OAAO,SAAS,OAAO,UAAU,IACxD,KAAA;EACJ,KAAKD,SAAS,IAAI,MAAM,MAAM;EAC9B,OAAO;CACT;CAEA,QAAQ;EACN,KAA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S,OAAO,MAAM;CAGtC,OAAO,MAAM,IAAI,EAAE;AACrB;AAEA,SAAS,WAAW,OAAoB,QAAyB;CAC/D,KACE,IAAI,IAAI,iBAAiB,OAAA,OAA4B,SAAQ,KAAK,GAAG,GACrE,IAAI,MAAM,QACV,KACA;EACA,MAAM,OAAO,MAAM;EACnB,MAAM,EAAC,QAAO;EACd,IAAI,CAAC,IAAI,WAAA,IAA8B,GACrC;EAEF,MAAM,OAAO,kBAAkB,GAAG;EAClC,MAAM,SAAS,KAAK,OAAO,UAAU,IAAI,CAAC;EAC1C,QAAQ,KAAK,IAAb;GACE,KAAK;IACH,QAAQ,OAAO,KAAK,uBAAuB,KAAK,QAAe,CAAC,CAAC;IACjE;GACF,KAAK;IACH,QAAQ,OAAO,KAAK,oBAAoB,KAAK,QAAe,CAAC,CAAC;IAC9D;GACF,KAAK;IACH,QACE,OAAO,KACL,qBAAqB,KAAK,UAAiB,KAAK,QAAe,CACjE,CACF;IACA;EACJ;CACF;AACF"}
1
+ {"version":3,"file":"ivm-branch.js","names":["#sources","#tables","#throwIfInvalid","#advanceError"],"sources":["../../../../../zero-client/src/client/ivm-branch.ts"],"sourcesContent":["import type {\n InternalDiff,\n InternalDiffOperation,\n NoIndexDiff,\n} from '../../../replicache/src/btree/node.ts';\nimport type {LazyStore} from '../../../replicache/src/dag/lazy-store.ts';\nimport {type Read, type Store} from '../../../replicache/src/dag/store.ts';\nimport {readFromHash} from '../../../replicache/src/db/read.ts';\nimport * as FormatVersion from '../../../replicache/src/format-version-enum.ts';\nimport type {Hash} from '../../../replicache/src/hash.ts';\nimport type {ZeroReadOptions} from '../../../replicache/src/replicache-options.ts';\nimport {diffBinarySearch} from '../../../replicache/src/subscriptions.ts';\nimport type {DiffsMap} from '../../../replicache/src/sync/diff.ts';\nimport {diff} from '../../../replicache/src/sync/diff.ts';\nimport {using, withRead} from '../../../replicache/src/with-transactions.ts';\nimport {assert} from '../../../shared/src/asserts.ts';\nimport {wrapIterable} from '../../../shared/src/iterables.ts';\nimport {must} from '../../../shared/src/must.ts';\nimport type {Row} from '../../../zero-protocol/src/data.ts';\nimport type {TableSchema} from '../../../zero-schema/src/table-schema.ts';\nimport {MemorySource} from '../../../zql/src/ivm/memory-source.ts';\nimport {consume} from '../../../zql/src/ivm/stream.ts';\nimport {ENTITIES_KEY_PREFIX, sourceNameFromKey} from './keys.ts';\n\nimport {\n makeSourceChangeEdit,\n makeSourceChangeRemove,\n} from '../../../zql/src/ivm/source.ts';\n/**\n * Replicache needs to rebase mutations onto different\n * commits of it's b-tree. These mutations can have reads\n * in them and those reads must be run against the IVM sources.\n *\n * To ensure the reads get the correct state, the IVM\n * sources need to reflect the state of the commit\n * being rebased onto. `IVMSourceBranch` allows us to:\n * 1. fork the IVM sources\n * 2. patch them up to match the desired head\n * 3. run the reads against the forked sources\n *\n * (2) is expected to be a cheap operation as there should only\n * ever be a few outstanding diffs to apply given Zero is meant\n * to be run in a connected state.\n */\nexport class IVMSourceBranch {\n readonly #sources: Map<string, MemorySource | undefined>;\n readonly #tables: Record<string, TableSchema>;\n #advanceError: unknown;\n hash: Hash | undefined;\n\n constructor(\n tables: Record<string, TableSchema>,\n hash?: Hash,\n sources: Map<string, MemorySource | undefined> = new Map(),\n ) {\n this.#tables = tables;\n this.#sources = sources;\n this.hash = hash;\n }\n\n getSource(name: string): MemorySource | undefined {\n this.#throwIfInvalid();\n\n if (this.#sources.has(name)) {\n return this.#sources.get(name);\n }\n\n const schema = this.#tables[name];\n const source = schema\n ? new MemorySource(name, schema.columns, schema.primaryKey)\n : undefined;\n this.#sources.set(name, source);\n return source;\n }\n\n clear() {\n this.#sources.clear();\n }\n\n #throwIfInvalid() {\n if (this.#advanceError) {\n throw this.#advanceError;\n }\n }\n\n /**\n * Mutates the current branch, advancing it to the new head\n * by applying the given diffs.\n */\n advance(expectedHead: Hash | undefined, newHead: Hash, diffs: NoIndexDiff) {\n this.#throwIfInvalid();\n\n assert(\n this.hash === expectedHead,\n () =>\n `Expected head must match the main head. Got: ${this.hash}, expected: ${expectedHead}`,\n );\n\n try {\n applyDiffs(diffs, this);\n this.hash = newHead;\n } catch (e) {\n this.#advanceError = e;\n this.clear();\n throw e;\n }\n }\n\n /**\n * Fork the branch and patch it up to match the desired head.\n */\n async forkToHead(\n store: LazyStore,\n desiredHead: Hash,\n readOptions?: ZeroReadOptions,\n ): Promise<IVMSourceBranch> {\n this.#throwIfInvalid();\n\n const fork = this.fork();\n\n if (fork.hash === desiredHead) {\n return fork;\n }\n\n await patchBranch(desiredHead, store, fork, readOptions);\n fork.hash = desiredHead;\n return fork;\n }\n\n /**\n * Creates a new IVMSourceBranch that is a copy of the current one.\n * This is a cheap operation since the b-trees are shared until a write is performed\n * and then only the modified nodes are copied.\n *\n * IVM branches are forked when we need to rebase mutations.\n * The mutations modify the fork rather than original branch.\n */\n fork() {\n this.#throwIfInvalid();\n\n return new IVMSourceBranch(\n this.#tables,\n this.hash,\n new Map(\n wrapIterable(this.#sources.entries()).map(([name, source]) => [\n name,\n source?.fork(),\n ]),\n ),\n );\n }\n}\n\nexport async function initFromStore(\n branch: IVMSourceBranch,\n hash: Hash,\n store: Store,\n) {\n const diffs: InternalDiffOperation[] = [];\n await withRead(store, async dagRead => {\n const read = await readFromHash(hash, dagRead, FormatVersion.Latest);\n for await (const entry of read.map.scan(ENTITIES_KEY_PREFIX, true)) {\n if (!entry[0].startsWith(ENTITIES_KEY_PREFIX)) {\n break;\n }\n diffs.push({\n op: 'add',\n key: entry[0],\n newValue: entry[1],\n });\n }\n });\n\n branch.advance(undefined, hash, diffs);\n}\n\nasync function patchBranch(\n desiredHead: Hash,\n store: LazyStore,\n fork: IVMSourceBranch,\n readOptions: ZeroReadOptions | undefined,\n) {\n const diffs = await computeDiffs(\n must(fork.hash),\n desiredHead,\n store,\n readOptions,\n );\n if (!diffs) {\n return;\n }\n applyDiffs(diffs, fork);\n}\n\nasync function computeDiffs(\n startHash: Hash,\n endHash: Hash,\n store: LazyStore,\n readOptions: ZeroReadOptions | undefined,\n): Promise<InternalDiff | undefined> {\n const readFn = (dagRead: Read) =>\n diff(\n startHash,\n endHash,\n dagRead,\n {\n shouldComputeDiffs: () => true,\n shouldComputeDiffsForIndex(_name) {\n return false;\n },\n },\n FormatVersion.Latest,\n );\n\n let diffs: DiffsMap;\n if (readOptions?.openLazySourceRead) {\n diffs = await using(store.read(readOptions.openLazySourceRead), readFn);\n } else if (readOptions?.openLazyRead) {\n diffs = await readFn(readOptions.openLazyRead);\n } else {\n diffs = await withRead(store, readFn);\n }\n\n return diffs.get('');\n}\n\nfunction applyDiffs(diffs: NoIndexDiff, branch: IVMSourceBranch) {\n for (\n let i = diffBinarySearch(diffs, ENTITIES_KEY_PREFIX, diff => diff.key);\n i < diffs.length;\n i++\n ) {\n const diff = diffs[i];\n const {key} = diff;\n if (!key.startsWith(ENTITIES_KEY_PREFIX)) {\n break;\n }\n const name = sourceNameFromKey(key);\n const source = must(branch.getSource(name));\n switch (diff.op) {\n case 'del':\n consume(source.push(makeSourceChangeRemove(diff.oldValue as Row)));\n break;\n case 'add': {\n const rows = takeAddsForSource(diffs, i, name);\n i += rows.length - 1;\n source.pushAdds(rows);\n break;\n }\n case 'change':\n consume(\n source.push(\n makeSourceChangeEdit(diff.newValue as Row, diff.oldValue as Row),\n ),\n );\n break;\n }\n }\n}\n\n/**\n * Returns the rows of the run of `add` diffs for the source `name` that starts\n * at `start`. Diffs are ordered by key so a table's rows are contiguous.\n */\nfunction takeAddsForSource(\n diffs: NoIndexDiff,\n start: number,\n name: string,\n): Row[] {\n const prefix = ENTITIES_KEY_PREFIX + name + '/';\n const rows: Row[] = [];\n for (let i = start; i < diffs.length; i++) {\n const diff = diffs[i];\n if (diff.op !== 'add' || !diff.key.startsWith(prefix)) {\n break;\n }\n rows.push(diff.newValue as Row);\n }\n return rows;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,IAAa,kBAAb,MAAa,gBAAgB;CAC3B;CACA;CACA;CACA;CA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IAAI,EAAE,IAAI,EAAC,EAAE,aAAa,EAC3B,GAAG,EAAE,GAAG,EACR,WAAW,CAAC,EAAE,WAAW,GACxB,MAAM,IAAI;IAMb,kBAAkB;IAClB,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,WAAW,CAAC,EAAE,WAAW,GAAG,MAAM,IAAI;IAsFpE,YAAY,CAAC,EAAC,IAAI,EAAE,IAAI,EAAC,EAAE,aAAa,EAAE,GAAG,EAAE,GAAG;IAMlD,kBAAkB;IAClB,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG;IAsC/B,UAAU;IAwCV;;OAEG;IACH,IAAI,OAAO,IAAI,YAAY,CAE1B;IAED,SAAS,CAAC,CAAC,SAAS,MAAM,eAAe,EACvC,MAAM,EAAE,CAAC,EACT,KAAK,EAAE,MAAM,EACb,GAAG,IAAI,EAAE,eAAe,CAAC,CAAC,CAAC,GAC1B,IAAI;IA2DP,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,oBAAoB,GAAG,SAAS;IAIlE;;OAEG;IACH,uBAAuB,IAAI,QAAQ,CAAC,MAAM,CAAC;CAG5C"}
@@ -1,4 +1,5 @@
1
1
  import { assert, unreachable } from "../../../shared/src/asserts.js";
2
+ import { getOrInsertComputed } from "../../../shared/src/map.js";
2
3
  import { must } from "../../../shared/src/must.js";
3
4
  import { mapAST, normalizeAST } from "../../../zero-protocol/src/ast.js";
4
5
  import { clientToServer, serverToClient } from "../../../zero-schema/src/name-mapper.js";
@@ -350,11 +351,7 @@ var QueryManager = class {
350
351
  if (this.#slowMaterializeThreshold !== void 0 && value > this.#slowMaterializeThreshold) this.#lc.warn?.("Slow query materialization (including server/network)", queryID, ast, value);
351
352
  else this.#lc.debug?.("Materialized query (including server/network)", queryID, ast, value);
352
353
  }
353
- let existing = this.#queryMetrics.get(queryID);
354
- if (!existing) {
355
- existing = newPerQueryMetrics();
356
- this.#queryMetrics.set(queryID, existing);
357
- }
354
+ const existing = getOrInsertComputed(this.#queryMetrics, queryID, newPerQueryMetrics);
358
355
  switch (metric) {
359
356
  case "query-update-client":
360
357
  existing["query-update-client"].add(value);
@@ -1 +1 @@
1
- {"version":3,"file":"query-manager.js","names":["#clientID","#clientToServer","#serverToClient","#send","#onFatalError","#queries","#recentQueriesMaxSize","#recentQueries","#gotQueries","#cachedQueries","#mutationTracker","#pendingQueryChanges","#queryChangeThrottleMs","#lc","#metrics","#queryMetrics","#slowMaterializeThreshold","#pendingRemovals","#awaitingPersistedGotDiff","#fireGotCallbacks","#gotQueriesAuthoritative","#queryEvictedCallback","#closedError","#add","#queueQueryChange","#updateEntry","#remove","#scheduleBatch","#batchTimer"],"sources":["../../../../../zero-client/src/client/query-manager.ts"],"sourcesContent":["import type {LogContext} from '@rocicorp/logger';\nimport type {ReplicacheImpl} from '../../../replicache/src/replicache-impl.ts';\nimport type {ClientID} from '../../../replicache/src/sync/ids.ts';\nimport {assert, unreachable} from '../../../shared/src/asserts.ts';\nimport type {ReadonlyJSONValue} from '../../../shared/src/json.ts';\nimport {must} from '../../../shared/src/must.ts';\nimport {difference} from '../../../shared/src/set-utils.ts';\nimport {TDigest} from '../../../shared/src/tdigest.ts';\nimport {\n mapAST,\n normalizeAST,\n type AST,\n} from '../../../zero-protocol/src/ast.ts';\nimport type {ChangeDesiredQueriesMessage} from '../../../zero-protocol/src/change-desired-queries.ts';\nimport type {ErroredQuery} from '../../../zero-protocol/src/custom-queries.ts';\nimport {ErrorKind} from '../../../zero-protocol/src/error-kind.ts';\nimport {ErrorOrigin} from '../../../zero-protocol/src/error-origin.ts';\nimport {ErrorReason} from '../../../zero-protocol/src/error-reason.ts';\nimport {ProtocolError} from '../../../zero-protocol/src/error.ts';\nimport type {UpQueriesPatchOp} from '../../../zero-protocol/src/queries-patch.ts';\nimport {\n hashOfAST,\n hashOfNameAndArgs,\n} from '../../../zero-protocol/src/query-hash.ts';\nimport {\n clientToServer,\n serverToClient,\n type NameMapper,\n} from '../../../zero-schema/src/name-mapper.ts';\nimport type {TableSchema} from '../../../zero-schema/src/table-schema.ts';\nimport type {ClientMetricMap} from '../../../zql/src/query/metrics-delegate.ts';\nimport type {CustomQueryID} from '../../../zql/src/query/named.ts';\nimport type {GotCallback} from '../../../zql/src/query/query-delegate.ts';\nimport {clampTTL, compareTTL, type TTL} from '../../../zql/src/query/ttl.ts';\nimport type {ClientErrorKind} from './client-error-kind.ts';\nimport type {ClientError} from './error.ts';\nimport {type ZeroError} from './error.ts';\nimport type {InspectorDelegate} from './inspector/inspector.ts';\nimport type {QueryClientMetrics} from './inspector/lazy-inspector.ts';\nimport {desiredQueriesPrefixForClient, GOT_QUERIES_KEY_PREFIX} from './keys.ts';\nimport type {MutationTracker} from './mutation-tracker.ts';\nimport type {ReadTransaction} from './replicache-types.ts';\n\ntype QueryHash = string;\n\ntype Entry = {\n // We keep track of the AST so we can use it in the inspector.\n normalized: AST;\n name: string | undefined;\n args: readonly ReadonlyJSONValue[] | undefined;\n count: number;\n gotCallbacks: GotCallback[];\n ttl: TTL;\n};\n\n// A thrown value, boxed so that `throw undefined` is still distinguishable\n// from \"nothing thrown\".\ntype ThrownBy = {readonly error: unknown};\n\ntype ClientMetric = {\n [K in keyof ClientMetricMap]: TDigest;\n};\n\ntype PerQueryClientMetric = {\n 'query-materialization-client': number | undefined;\n 'query-materialization-end-to-end': number | undefined;\n 'query-update-client': TDigest;\n};\n\n/**\n * Tracks what queries the client is currently subscribed to on the server.\n * Sends `changeDesiredQueries` message to server when this changes.\n * Deduplicates requests so that we only listen to a given unique query once.\n */\nexport class QueryManager implements InspectorDelegate {\n readonly #clientID: ClientID;\n readonly #clientToServer: NameMapper;\n readonly #serverToClient: NameMapper;\n readonly #send: (change: ChangeDesiredQueriesMessage) => void;\n readonly #onFatalError: (error: ZeroError) => void;\n readonly #queries: Map<QueryHash, Entry> = new Map();\n readonly #recentQueriesMaxSize: number;\n readonly #recentQueries: Set<string> = new Set();\n readonly #gotQueries: Set<string> = new Set();\n // Whether `#gotQueries` can be trusted. The persisted set loaded from\n // IndexedDB may be stale (a query 'got' in a previous session can be evicted\n // server-side); see `markGotQueriesAuthoritative`.\n #gotQueriesAuthoritative = false;\n // The got keys whose result the store holds from a previous connection: the\n // set persisted by a previous session, and on disconnect everything the\n // connection just torn down had confirmed. Until the got set is\n // authoritative, a registration reports these as 'cached'. Keys added by a\n // live diff are not in it; see the watch below.\n readonly #cachedQueries: Set<string> = new Set();\n // Whether the got-queries watch has yet to deliver its first diff, the\n // persisted set. Cleared before that diff is processed, so a throwing\n // callback cannot leave it set.\n #awaitingPersistedGotDiff = true;\n readonly #mutationTracker: MutationTracker;\n readonly #pendingQueryChanges: UpQueriesPatchOp[] = [];\n readonly #queryChangeThrottleMs: number;\n #pendingRemovals: Array<() => void> = [];\n #batchTimer: ReturnType<typeof setTimeout> | undefined;\n readonly #lc: LogContext;\n readonly #metrics: ClientMetric = newMetrics();\n readonly #queryMetrics: Map<string, PerQueryClientMetric> = new Map();\n readonly #slowMaterializeThreshold: number;\n #closedError: ZeroError | undefined;\n #queryEvictedCallback:\n | ((hash: string, ast: AST, metrics: QueryClientMetrics) => void)\n | undefined;\n\n constructor(\n lc: LogContext,\n mutationTracker: MutationTracker,\n clientID: ClientID,\n tables: Record<string, TableSchema>,\n send: (change: ChangeDesiredQueriesMessage) => void,\n experimentalWatch: ReplicacheImpl['experimentalWatch'],\n recentQueriesMaxSize: number,\n queryChangeThrottleMs: number,\n slowMaterializeThreshold: number,\n onFatalError: (error: ZeroError) => void,\n ) {\n this.#lc = lc.withContext('QueryManager');\n this.#clientID = clientID;\n this.#clientToServer = clientToServer(tables);\n this.#serverToClient = serverToClient(tables);\n this.#recentQueriesMaxSize = recentQueriesMaxSize;\n this.#send = send;\n this.#mutationTracker = mutationTracker;\n this.#queryChangeThrottleMs = queryChangeThrottleMs;\n this.#slowMaterializeThreshold = slowMaterializeThreshold;\n this.#onFatalError = onFatalError;\n this.#mutationTracker.onAllMutationsApplied(() => {\n if (this.#pendingRemovals.length === 0) {\n return;\n }\n const pendingRemovals = this.#pendingRemovals;\n this.#pendingRemovals = [];\n for (const removal of pendingRemovals) {\n removal();\n }\n });\n\n // The first diff is the got set persisted by a previous session, the only\n // state the watch may report as 'cached'. Every later diff is live: this\n // tab's own poke, whose keys are confirmations on this connection and are\n // reported as got once the poke has been applied (see\n // `markGotQueriesAuthoritative`), or another tab's state arriving via\n // replicache refresh. A live diff can therefore only revoke a cached\n // claim (a deleted key), never grant one.\n experimentalWatch(\n diff => {\n const persisted = this.#awaitingPersistedGotDiff;\n this.#awaitingPersistedGotDiff = false;\n // A throwing callback must not leave the rest of the diff unapplied,\n // or later keys would never enter the got set. The first error is\n // rethrown once the sets are consistent.\n let thrown: ThrownBy | undefined;\n const fire = (queryHash: string, got: boolean | 'cached') => {\n const e = this.#fireGotCallbacks(queryHash, got);\n thrown ??= e;\n };\n for (const diffOp of diff) {\n const queryHash = diffOp.key.substring(GOT_QUERIES_KEY_PREFIX.length);\n switch (diffOp.op) {\n case 'add':\n this.#gotQueries.add(queryHash);\n if (this.#gotQueriesAuthoritative) {\n fire(queryHash, true);\n } else if (persisted) {\n this.#cachedQueries.add(queryHash);\n fire(queryHash, 'cached');\n }\n break;\n case 'del':\n this.#gotQueries.delete(queryHash);\n this.#cachedQueries.delete(queryHash);\n fire(queryHash, false);\n break;\n }\n }\n if (thrown) {\n throw thrown.error;\n }\n },\n {\n prefix: GOT_QUERIES_KEY_PREFIX,\n initialValuesInFirstDiff: true,\n },\n );\n }\n\n getAST(queryID: string): AST | undefined {\n const ast = this.#queries.get(queryID)?.normalized;\n return ast && mapAST(ast, this.#serverToClient);\n }\n\n setQueryEvictedCallback(\n cb: (hash: string, ast: AST, metrics: QueryClientMetrics) => void,\n ): void {\n this.#queryEvictedCallback = cb;\n }\n\n mapClientASTToServer(ast: AST): AST {\n return mapAST(ast, this.#clientToServer);\n }\n\n /**\n * Notifies every subscriber of the query. A throwing subscriber does not\n * keep the others from being notified; the first error is returned so the\n * caller can rethrow it once its own bookkeeping is consistent.\n */\n #fireGotCallbacks(\n queryHash: string,\n got: boolean | 'cached',\n ): ThrownBy | undefined {\n const entry = this.#queries.get(queryHash);\n if (!entry) {\n return undefined;\n }\n let thrown: ThrownBy | undefined;\n // A subscriber may unregister during dispatch (a run() waiter destroys its\n // view on the notification it was waiting for), so iterate a snapshot.\n for (const gotCallback of [...entry.gotCallbacks]) {\n try {\n gotCallback(got);\n } catch (error) {\n thrown ??= {error};\n }\n }\n return thrown;\n }\n\n /**\n * Trust `#gotQueries`. Called once the first poke after a (re)connect has\n * been applied. Because `gotQueriesPatch` is a diff, the server won't re-send\n * `put`s for queries it thinks the client already has, so we re-derive and\n * fire `got` for every subscribed query already in the set. Only fires\n * `true`, so this never reverts a query from 'complete'. Idempotent.\n */\n markGotQueriesAuthoritative(): void {\n if (this.#gotQueriesAuthoritative) {\n return;\n }\n this.#gotQueriesAuthoritative = true;\n // Whatever the previous connection held, this one has now confirmed or\n // deleted. Should the watch's first diff have been skipped (a failed\n // initial run), the next diff is live too.\n this.#cachedQueries.clear();\n this.#awaitingPersistedGotDiff = false;\n let thrown: ThrownBy | undefined;\n for (const queryHash of this.#queries.keys()) {\n if (this.#gotQueries.has(queryHash)) {\n const e = this.#fireGotCallbacks(queryHash, true);\n thrown ??= e;\n }\n }\n if (thrown) {\n throw thrown.error;\n }\n }\n\n /** Called on disconnect. The next connect must re-confirm `#gotQueries`. */\n clearGotQueriesAuthoritative(): void {\n if (!this.#gotQueriesAuthoritative) {\n // The connection never confirmed the got set, so the persisted\n // classification still stands. Keys a live diff added in the meantime\n // were not confirmed by this connection and stay unclaimed.\n return;\n }\n this.#gotQueriesAuthoritative = false;\n // Everything got at this point was confirmed by the connection just torn\n // down, which for a new registration is the cached claim.\n for (const queryHash of this.#gotQueries) {\n this.#cachedQueries.add(queryHash);\n }\n }\n\n /**\n * Get the queries that need to be registered with the server.\n *\n * An optional `lastPatch` can be provided. This is the last patch that was\n * sent to the server and may not yet have been acked. If `lastPatch` is provided,\n * this method will return a patch that does not include any events sent in `lastPatch`.\n *\n * This diffing of last patch and current patch is needed since we send\n * a set of queries to the server when we first connect inside of the `sec-protocol` as\n * the `initConnectionMessage`.\n *\n * While we're waiting for the `connected` response to come back from the server,\n * the client may have registered more queries. We need to diff the `initConnectionMessage`\n * queries with the current set of queries to understand what those were.\n */\n async getQueriesPatch(\n tx: ReadTransaction,\n lastPatch?: Map<string, UpQueriesPatchOp>,\n ): Promise<Map<string, UpQueriesPatchOp>> {\n const existingQueryHashes = new Set<string>();\n const prefix = desiredQueriesPrefixForClient(this.#clientID);\n for await (const key of tx.scan({prefix}).keys()) {\n existingQueryHashes.add(key.substring(prefix.length, key.length));\n }\n const patch: Map<string, UpQueriesPatchOp> = new Map();\n for (const hash of existingQueryHashes) {\n if (!this.#queries.has(hash)) {\n patch.set(hash, {op: 'del', hash});\n }\n }\n\n for (const [hash, {normalized, ttl, name, args}] of this.#queries) {\n if (!existingQueryHashes.has(hash)) {\n patch.set(hash, {\n op: 'put',\n hash,\n ast: name === undefined ? normalized : undefined,\n name,\n args,\n // We get TTL out of the DagStore so it is possible that the TTL was written\n // with a too high TTL.\n ttl: clampTTL(ttl), // no lc here since no need to log here\n });\n }\n }\n\n if (lastPatch) {\n // if there are any `puts` in `lastPatch` that are not in `patch` then we need to\n // send a `del` event in `patch`.\n for (const [hash, {op}] of lastPatch) {\n if (op === 'put' && !patch.has(hash)) {\n patch.set(hash, {op: 'del', hash});\n }\n }\n // Remove everything from `patch` that was already sent in `lastPatch`.\n for (const [hash, {op}] of patch) {\n const lastPatchOp = lastPatch.get(hash);\n if (lastPatchOp && lastPatchOp.op === op) {\n patch.delete(hash);\n }\n }\n }\n\n return patch;\n }\n\n handleTransformErrors(errors: ErroredQuery[]) {\n for (const error of errors) {\n const queryId = error.id;\n const entry = this.#queries.get(queryId);\n\n // if we don't have the query registered, continue\n if (!entry) {\n continue;\n }\n\n if (error.error === 'app' || error.error === 'parse') {\n entry.gotCallbacks.forEach(callback => callback(false, error));\n }\n // this code path is not possible technically since errors were never implemented in the legacy query transform error\n // but is included for backwards compatibility and we have a test case for it\n else {\n this.#onFatalError(\n new ProtocolError({\n kind: ErrorKind.TransformFailed,\n origin: ErrorOrigin.ZeroCache,\n reason: ErrorReason.Internal,\n message: `Unknown error transforming queries: ${JSON.stringify(error)}`,\n queryIDs: [],\n }),\n );\n // unreachable(error); TODO(0xcadams): this should eventually be unreachable\n }\n }\n }\n\n handleClosed(\n reason: ClientError<{kind: ClientErrorKind.ClientClosed; message: string}>,\n ) {\n if (this.#closedError) {\n return;\n }\n this.#closedError = reason;\n for (const [queryId, entry] of this.#queries) {\n const erroredQuery: ErroredQuery = {\n error: 'app',\n id: queryId,\n name: entry.name ?? 'legacy',\n message: reason.message,\n details: {kind: reason.kind},\n };\n for (const gotCallback of entry.gotCallbacks) {\n gotCallback(false, erroredQuery);\n }\n }\n }\n\n addCustom(\n ast: AST,\n {name, args}: CustomQueryID,\n ttl: TTL,\n gotCallback?: GotCallback,\n ): () => void {\n const normalized = normalizeAST(ast);\n const queryId = hashOfNameAndArgs(name, args);\n return this.#add(queryId, normalized, name, args, ttl, gotCallback);\n }\n\n /** @deprecated */\n addLegacy(ast: AST, ttl: TTL, gotCallback?: GotCallback): () => void {\n const normalized = normalizeAST(ast);\n const astHash = hashOfAST(normalized);\n return this.#add(\n astHash,\n normalized,\n undefined, // name is undefined for legacy queries\n undefined, // args are undefined for legacy queries\n ttl,\n gotCallback,\n );\n }\n\n #add(\n queryId: string,\n normalized: AST,\n name: string | undefined,\n args: readonly ReadonlyJSONValue[] | undefined,\n ttl: TTL,\n gotCallback?: GotCallback,\n ) {\n assert(\n (name === undefined) === (args === undefined),\n 'If name is defined, args must be defined',\n );\n ttl = clampTTL(ttl, this.#lc);\n let entry = this.#queries.get(queryId);\n this.#recentQueries.delete(queryId);\n if (!entry) {\n normalized = mapAST(normalized, this.#clientToServer);\n\n entry = {\n normalized,\n name,\n args,\n count: 1,\n gotCallbacks: gotCallback ? [gotCallback] : [],\n ttl,\n };\n this.#queries.set(queryId, entry);\n this.#queueQueryChange({\n op: 'put',\n hash: queryId,\n ast: name === undefined ? normalized : undefined,\n name,\n args,\n ttl,\n });\n } else {\n ++entry.count;\n this.#updateEntry(entry, queryId, ttl);\n\n if (gotCallback) {\n entry.gotCallbacks.push(gotCallback);\n }\n }\n\n if (gotCallback) {\n gotCallback(\n this.#gotQueriesAuthoritative\n ? this.#gotQueries.has(queryId)\n : this.#cachedQueries.has(queryId) && 'cached',\n );\n }\n\n let removed = false;\n const cleanupCb = () => {\n if (removed) {\n return;\n }\n removed = true;\n\n // We cannot remove queries while mutations are pending\n // as that could take data out of scope that is needed in a rebase\n if (this.#mutationTracker.size > 0) {\n this.#pendingRemovals.push(() =>\n this.#remove(entry, queryId, gotCallback),\n );\n return;\n }\n\n this.#remove(entry, queryId, gotCallback);\n };\n return cleanupCb;\n }\n\n updateCustom({name, args}: CustomQueryID, ttl: TTL) {\n const queryID = hashOfNameAndArgs(name, args);\n const entry = must(this.#queries.get(queryID));\n this.#updateEntry(entry, queryID, ttl);\n }\n\n /** @deprecated */\n updateLegacy(ast: AST, ttl: TTL) {\n const normalized = normalizeAST(ast);\n const queryID = hashOfAST(normalized);\n const entry = must(this.#queries.get(queryID));\n this.#updateEntry(entry, queryID, ttl);\n }\n\n #updateEntry(entry: Entry, queryID: string, ttl: TTL): void {\n // If the query already exists and the new ttl is larger than the old one\n // we send a changeDesiredQueries message to the server to update the ttl.\n ttl = clampTTL(ttl, this.#lc);\n if (compareTTL(ttl, entry.ttl) > 0) {\n entry.ttl = ttl;\n this.#queueQueryChange({\n op: 'put',\n hash: queryID,\n ast: entry.name === undefined ? entry.normalized : undefined,\n name: entry.name,\n args: entry.args,\n ttl,\n });\n }\n }\n\n #queueQueryChange(op: UpQueriesPatchOp) {\n this.#pendingQueryChanges.push(op);\n this.#scheduleBatch();\n }\n\n #scheduleBatch() {\n if (this.#batchTimer === undefined) {\n this.#batchTimer = setTimeout(\n () => this.flushBatch(),\n this.#queryChangeThrottleMs,\n );\n }\n }\n\n flushBatch() {\n if (this.#batchTimer !== undefined) {\n clearTimeout(this.#batchTimer);\n this.#batchTimer = undefined;\n }\n if (this.#pendingQueryChanges.length > 0) {\n this.#send([\n 'changeDesiredQueries',\n {\n desiredQueriesPatch: [...this.#pendingQueryChanges],\n },\n ]);\n this.#pendingQueryChanges.length = 0;\n }\n }\n\n #remove(entry: Entry, astHash: string, gotCallback: GotCallback | undefined) {\n if (gotCallback) {\n const index = entry.gotCallbacks.indexOf(gotCallback);\n entry.gotCallbacks.splice(index, 1);\n }\n --entry.count;\n if (entry.count === 0) {\n this.#recentQueries.add(astHash);\n if (this.#recentQueries.size > this.#recentQueriesMaxSize) {\n const lruQueryID = this.#recentQueries.values().next().value;\n assert(lruQueryID, 'Expected LRU query ID to exist');\n const evictedAST = this.getAST(lruQueryID);\n const evictedMetrics =\n this.#queryMetrics.get(lruQueryID) ?? newPerQueryMetrics();\n this.#queries.delete(lruQueryID);\n this.#recentQueries.delete(lruQueryID);\n this.#queryMetrics.delete(lruQueryID);\n this.#queueQueryChange({op: 'del', hash: lruQueryID});\n assert(evictedAST, 'Expected evicted AST to exist');\n this.#queryEvictedCallback?.(lruQueryID, evictedAST, evictedMetrics);\n }\n }\n }\n\n /**\n * Gets the aggregated metrics for all queries managed by this QueryManager.\n */\n get metrics(): ClientMetric {\n return this.#metrics;\n }\n\n addMetric<K extends keyof ClientMetricMap>(\n metric: K,\n value: number,\n ...args: ClientMetricMap[K]\n ): void {\n // Only query metrics are tracked at this point.\n // If this check fails then we need to add a runtime check.\n metric satisfies `query-${string}`;\n\n // We track all materializations of queries as well as per\n // query materializations.\n this.#metrics[metric].add(value);\n\n const queryID = args[0];\n\n // Handle slow query logging for end-to-end materialization\n if (metric === 'query-materialization-end-to-end') {\n const ast = args[1];\n\n if (\n this.#slowMaterializeThreshold !== undefined &&\n value > this.#slowMaterializeThreshold\n ) {\n this.#lc.warn?.(\n 'Slow query materialization (including server/network)',\n queryID,\n ast,\n value,\n );\n } else {\n this.#lc.debug?.(\n 'Materialized query (including server/network)',\n queryID,\n ast,\n value,\n );\n }\n }\n\n // The query manager manages metrics that are per query.\n let existing = this.#queryMetrics.get(queryID);\n if (!existing) {\n existing = newPerQueryMetrics();\n this.#queryMetrics.set(queryID, existing);\n }\n switch (metric) {\n case 'query-update-client':\n existing['query-update-client'].add(value);\n break;\n case 'query-materialization-client':\n case 'query-materialization-end-to-end':\n // Recorded once per query (last value wins).\n existing[\n metric as\n | 'query-materialization-client'\n | 'query-materialization-end-to-end'\n ] = value;\n break;\n default:\n unreachable(metric);\n }\n }\n\n getQueryMetrics(queryID: string): PerQueryClientMetric | undefined {\n return this.#queryMetrics.get(queryID);\n }\n\n /**\n * For testing only: returns all query hashes currently registered.\n */\n getAllNonGotQueryHashes(): Iterable<string> {\n return difference(this.#queries, this.#gotQueries);\n }\n}\n\nfunction newMetrics(): ClientMetric {\n return {\n 'query-materialization-client': new TDigest(),\n 'query-materialization-end-to-end': new TDigest(),\n 'query-update-client': new TDigest(),\n };\n}\n\nfunction newPerQueryMetrics(): PerQueryClientMetric {\n return {\n 'query-materialization-client': undefined,\n 'query-materialization-end-to-end': undefined,\n 'query-update-client': new TDigest(),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA0EA,IAAa,eAAb,MAAuD;CACrD;CACA;CACA;CACA;CACA;CACA,2BAA2C,IAAI,IAAI;CACnD;CACA,iCAAuC,IAAI,IAAI;CAC/C,8BAAoC,IAAI,IAAI;CAI5C,2BAA2B;CAM3B,iCAAuC,IAAI,IAAI;CAI/C,4BAA4B;CAC5B;CACA,uBAAoD,CAAC;CACrD;CACA,mBAAsC,CAAC;CACvC;CACA;CACA,WAAkC,WAAW;CAC7C,gCAA4D,IAAI,IAAI;CACpE;CACA;CACA;CAIA,YACE,IACA,iBACA,UACA,QACA,MACA,mBACA,sBACA,uBACA,0BACA,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UAGE;IACJ;GACF,SACE,YAAY,MAAM;EACtB;CACF;CAEA,gBAAgB,SAAmD;EACjE,OAAO,KAAKA,cAAc,IAAI,OAAO;CACvC;;;;CAKA,0BAA4C;EAC1C,OAAO,WAAW,KAAKV,UAAU,KAAKG,WAAW;CACnD;AACF;AAEA,SAAS,aAA2B;CAClC,OAAO;EACL,gCAAgC,IAAI,QAAQ;EAC5C,oCAAoC,IAAI,QAAQ;EAChD,uBAAuB,IAAI,QAAQ;CACrC;AACF;AAEA,SAAS,qBAA2C;CAClD,OAAO;EACL,gCAAgC,KAAA;EAChC,oCAAoC,KAAA;EACpC,uBAAuB,IAAI,QAAQ;CACrC;AACF"}
1
+ {"version":3,"file":"query-manager.js","names":["#clientID","#clientToServer","#serverToClient","#send","#onFatalError","#queries","#recentQueriesMaxSize","#recentQueries","#gotQueries","#cachedQueries","#mutationTracker","#pendingQueryChanges","#queryChangeThrottleMs","#lc","#metrics","#queryMetrics","#slowMaterializeThreshold","#pendingRemovals","#awaitingPersistedGotDiff","#fireGotCallbacks","#gotQueriesAuthoritative","#queryEvictedCallback","#closedError","#add","#queueQueryChange","#updateEntry","#remove","#scheduleBatch","#batchTimer"],"sources":["../../../../../zero-client/src/client/query-manager.ts"],"sourcesContent":["import type {LogContext} from '@rocicorp/logger';\nimport type {ReplicacheImpl} from '../../../replicache/src/replicache-impl.ts';\nimport type {ClientID} from '../../../replicache/src/sync/ids.ts';\nimport {assert, unreachable} from '../../../shared/src/asserts.ts';\nimport type {ReadonlyJSONValue} from '../../../shared/src/json.ts';\nimport {getOrInsertComputed} from '../../../shared/src/map.ts';\nimport {must} from '../../../shared/src/must.ts';\nimport {difference} from '../../../shared/src/set-utils.ts';\nimport {TDigest} from '../../../shared/src/tdigest.ts';\nimport {\n mapAST,\n normalizeAST,\n type AST,\n} from '../../../zero-protocol/src/ast.ts';\nimport type {ChangeDesiredQueriesMessage} from '../../../zero-protocol/src/change-desired-queries.ts';\nimport type {ErroredQuery} from '../../../zero-protocol/src/custom-queries.ts';\nimport {ErrorKind} from '../../../zero-protocol/src/error-kind.ts';\nimport {ErrorOrigin} from '../../../zero-protocol/src/error-origin.ts';\nimport {ErrorReason} from '../../../zero-protocol/src/error-reason.ts';\nimport {ProtocolError} from '../../../zero-protocol/src/error.ts';\nimport type {UpQueriesPatchOp} from '../../../zero-protocol/src/queries-patch.ts';\nimport {\n hashOfAST,\n hashOfNameAndArgs,\n} from '../../../zero-protocol/src/query-hash.ts';\nimport {\n clientToServer,\n serverToClient,\n type NameMapper,\n} from '../../../zero-schema/src/name-mapper.ts';\nimport type {TableSchema} from '../../../zero-schema/src/table-schema.ts';\nimport type {ClientMetricMap} from '../../../zql/src/query/metrics-delegate.ts';\nimport type {CustomQueryID} from '../../../zql/src/query/named.ts';\nimport type {GotCallback} from '../../../zql/src/query/query-delegate.ts';\nimport {clampTTL, compareTTL, type TTL} from '../../../zql/src/query/ttl.ts';\nimport type {ClientErrorKind} from './client-error-kind.ts';\nimport type {ClientError} from './error.ts';\nimport {type ZeroError} from './error.ts';\nimport type {InspectorDelegate} from './inspector/inspector.ts';\nimport type {QueryClientMetrics} from './inspector/lazy-inspector.ts';\nimport {desiredQueriesPrefixForClient, GOT_QUERIES_KEY_PREFIX} from './keys.ts';\nimport type {MutationTracker} from './mutation-tracker.ts';\nimport type {ReadTransaction} from './replicache-types.ts';\n\ntype QueryHash = string;\n\ntype Entry = {\n // We keep track of the AST so we can use it in the inspector.\n normalized: AST;\n name: string | undefined;\n args: readonly ReadonlyJSONValue[] | undefined;\n count: number;\n gotCallbacks: GotCallback[];\n ttl: TTL;\n};\n\n// A thrown value, boxed so that `throw undefined` is still distinguishable\n// from \"nothing thrown\".\ntype ThrownBy = {readonly error: unknown};\n\ntype ClientMetric = {\n [K in keyof ClientMetricMap]: TDigest;\n};\n\ntype PerQueryClientMetric = {\n 'query-materialization-client': number | undefined;\n 'query-materialization-end-to-end': number | undefined;\n 'query-update-client': TDigest;\n};\n\n/**\n * Tracks what queries the client is currently subscribed to on the server.\n * Sends `changeDesiredQueries` message to server when this changes.\n * Deduplicates requests so that we only listen to a given unique query once.\n */\nexport class QueryManager implements InspectorDelegate {\n readonly #clientID: ClientID;\n readonly #clientToServer: NameMapper;\n readonly #serverToClient: NameMapper;\n readonly #send: (change: ChangeDesiredQueriesMessage) => void;\n readonly #onFatalError: (error: ZeroError) => void;\n readonly #queries: Map<QueryHash, Entry> = new Map();\n readonly #recentQueriesMaxSize: number;\n readonly #recentQueries: Set<string> = new Set();\n readonly #gotQueries: Set<string> = new Set();\n // Whether `#gotQueries` can be trusted. The persisted set loaded from\n // IndexedDB may be stale (a query 'got' in a previous session can be evicted\n // server-side); see `markGotQueriesAuthoritative`.\n #gotQueriesAuthoritative = false;\n // The got keys whose result the store holds from a previous connection: the\n // set persisted by a previous session, and on disconnect everything the\n // connection just torn down had confirmed. Until the got set is\n // authoritative, a registration reports these as 'cached'. Keys added by a\n // live diff are not in it; see the watch below.\n readonly #cachedQueries: Set<string> = new Set();\n // Whether the got-queries watch has yet to deliver its first diff, the\n // persisted set. Cleared before that diff is processed, so a throwing\n // callback cannot leave it set.\n #awaitingPersistedGotDiff = true;\n readonly #mutationTracker: MutationTracker;\n readonly #pendingQueryChanges: UpQueriesPatchOp[] = [];\n readonly #queryChangeThrottleMs: number;\n #pendingRemovals: Array<() => void> = [];\n #batchTimer: ReturnType<typeof setTimeout> | undefined;\n readonly #lc: LogContext;\n readonly #metrics: ClientMetric = newMetrics();\n readonly #queryMetrics: Map<string, PerQueryClientMetric> = new Map();\n readonly #slowMaterializeThreshold: number;\n #closedError: ZeroError | undefined;\n #queryEvictedCallback:\n | ((hash: string, ast: AST, metrics: QueryClientMetrics) => void)\n | undefined;\n\n constructor(\n lc: LogContext,\n mutationTracker: MutationTracker,\n clientID: ClientID,\n tables: Record<string, TableSchema>,\n send: (change: ChangeDesiredQueriesMessage) => void,\n experimentalWatch: ReplicacheImpl['experimentalWatch'],\n recentQueriesMaxSize: number,\n queryChangeThrottleMs: number,\n slowMaterializeThreshold: number,\n onFatalError: (error: ZeroError) => void,\n ) {\n this.#lc = lc.withContext('QueryManager');\n this.#clientID = clientID;\n this.#clientToServer = clientToServer(tables);\n this.#serverToClient = serverToClient(tables);\n this.#recentQueriesMaxSize = recentQueriesMaxSize;\n this.#send = send;\n this.#mutationTracker = mutationTracker;\n this.#queryChangeThrottleMs = queryChangeThrottleMs;\n this.#slowMaterializeThreshold = slowMaterializeThreshold;\n this.#onFatalError = onFatalError;\n this.#mutationTracker.onAllMutationsApplied(() => {\n if (this.#pendingRemovals.length === 0) {\n return;\n }\n const pendingRemovals = this.#pendingRemovals;\n this.#pendingRemovals = [];\n for (const removal of pendingRemovals) {\n removal();\n }\n });\n\n // The first diff is the got set persisted by a previous session, the only\n // state the watch may report as 'cached'. Every later diff is live: this\n // tab's own poke, whose keys are confirmations on this connection and are\n // reported as got once the poke has been applied (see\n // `markGotQueriesAuthoritative`), or another tab's state arriving via\n // replicache refresh. A live diff can therefore only revoke a cached\n // claim (a deleted key), never grant one.\n experimentalWatch(\n diff => {\n const persisted = this.#awaitingPersistedGotDiff;\n this.#awaitingPersistedGotDiff = false;\n // A throwing callback must not leave the rest of the diff unapplied,\n // or later keys would never enter the got set. The first error is\n // rethrown once the sets are consistent.\n let thrown: ThrownBy | undefined;\n const fire = (queryHash: string, got: boolean | 'cached') => {\n const e = this.#fireGotCallbacks(queryHash, got);\n thrown ??= e;\n };\n for (const diffOp of diff) {\n const queryHash = diffOp.key.substring(GOT_QUERIES_KEY_PREFIX.length);\n switch (diffOp.op) {\n case 'add':\n this.#gotQueries.add(queryHash);\n if (this.#gotQueriesAuthoritative) {\n fire(queryHash, true);\n } else if (persisted) {\n this.#cachedQueries.add(queryHash);\n fire(queryHash, 'cached');\n }\n break;\n case 'del':\n this.#gotQueries.delete(queryHash);\n this.#cachedQueries.delete(queryHash);\n fire(queryHash, false);\n break;\n }\n }\n if (thrown) {\n throw thrown.error;\n }\n },\n {\n prefix: GOT_QUERIES_KEY_PREFIX,\n initialValuesInFirstDiff: true,\n },\n );\n }\n\n getAST(queryID: string): AST | undefined {\n const ast = this.#queries.get(queryID)?.normalized;\n return ast && mapAST(ast, this.#serverToClient);\n }\n\n setQueryEvictedCallback(\n cb: (hash: string, ast: AST, metrics: QueryClientMetrics) => void,\n ): void {\n this.#queryEvictedCallback = cb;\n }\n\n mapClientASTToServer(ast: AST): AST {\n return mapAST(ast, this.#clientToServer);\n }\n\n /**\n * Notifies every subscriber of the query. A throwing subscriber does not\n * keep the others from being notified; the first error is returned so the\n * caller can rethrow it once its own bookkeeping is consistent.\n */\n #fireGotCallbacks(\n queryHash: string,\n got: boolean | 'cached',\n ): ThrownBy | undefined {\n const entry = this.#queries.get(queryHash);\n if (!entry) {\n return undefined;\n }\n let thrown: ThrownBy | undefined;\n // A subscriber may unregister during dispatch (a run() waiter destroys its\n // view on the notification it was waiting for), so iterate a snapshot.\n for (const gotCallback of [...entry.gotCallbacks]) {\n try {\n gotCallback(got);\n } catch (error) {\n thrown ??= {error};\n }\n }\n return thrown;\n }\n\n /**\n * Trust `#gotQueries`. Called once the first poke after a (re)connect has\n * been applied. Because `gotQueriesPatch` is a diff, the server won't re-send\n * `put`s for queries it thinks the client already has, so we re-derive and\n * fire `got` for every subscribed query already in the set. Only fires\n * `true`, so this never reverts a query from 'complete'. Idempotent.\n */\n markGotQueriesAuthoritative(): void {\n if (this.#gotQueriesAuthoritative) {\n return;\n }\n this.#gotQueriesAuthoritative = true;\n // Whatever the previous connection held, this one has now confirmed or\n // deleted. Should the watch's first diff have been skipped (a failed\n // initial run), the next diff is live too.\n this.#cachedQueries.clear();\n this.#awaitingPersistedGotDiff = false;\n let thrown: ThrownBy | undefined;\n for (const queryHash of this.#queries.keys()) {\n if (this.#gotQueries.has(queryHash)) {\n const e = this.#fireGotCallbacks(queryHash, true);\n thrown ??= e;\n }\n }\n if (thrown) {\n throw thrown.error;\n }\n }\n\n /** Called on disconnect. The next connect must re-confirm `#gotQueries`. */\n clearGotQueriesAuthoritative(): void {\n if (!this.#gotQueriesAuthoritative) {\n // The connection never confirmed the got set, so the persisted\n // classification still stands. Keys a live diff added in the meantime\n // were not confirmed by this connection and stay unclaimed.\n return;\n }\n this.#gotQueriesAuthoritative = false;\n // Everything got at this point was confirmed by the connection just torn\n // down, which for a new registration is the cached claim.\n for (const queryHash of this.#gotQueries) {\n this.#cachedQueries.add(queryHash);\n }\n }\n\n /**\n * Get the queries that need to be registered with the server.\n *\n * An optional `lastPatch` can be provided. This is the last patch that was\n * sent to the server and may not yet have been acked. If `lastPatch` is provided,\n * this method will return a patch that does not include any events sent in `lastPatch`.\n *\n * This diffing of last patch and current patch is needed since we send\n * a set of queries to the server when we first connect inside of the `sec-protocol` as\n * the `initConnectionMessage`.\n *\n * While we're waiting for the `connected` response to come back from the server,\n * the client may have registered more queries. We need to diff the `initConnectionMessage`\n * queries with the current set of queries to understand what those were.\n */\n async getQueriesPatch(\n tx: ReadTransaction,\n lastPatch?: Map<string, UpQueriesPatchOp>,\n ): Promise<Map<string, UpQueriesPatchOp>> {\n const existingQueryHashes = new Set<string>();\n const prefix = desiredQueriesPrefixForClient(this.#clientID);\n for await (const key of tx.scan({prefix}).keys()) {\n existingQueryHashes.add(key.substring(prefix.length, key.length));\n }\n const patch: Map<string, UpQueriesPatchOp> = new Map();\n for (const hash of existingQueryHashes) {\n if (!this.#queries.has(hash)) {\n patch.set(hash, {op: 'del', hash});\n }\n }\n\n for (const [hash, {normalized, ttl, name, args}] of this.#queries) {\n if (!existingQueryHashes.has(hash)) {\n patch.set(hash, {\n op: 'put',\n hash,\n ast: name === undefined ? normalized : undefined,\n name,\n args,\n // We get TTL out of the DagStore so it is possible that the TTL was written\n // with a too high TTL.\n ttl: clampTTL(ttl), // no lc here since no need to log here\n });\n }\n }\n\n if (lastPatch) {\n // if there are any `puts` in `lastPatch` that are not in `patch` then we need to\n // send a `del` event in `patch`.\n for (const [hash, {op}] of lastPatch) {\n if (op === 'put' && !patch.has(hash)) {\n patch.set(hash, {op: 'del', hash});\n }\n }\n // Remove everything from `patch` that was already sent in `lastPatch`.\n for (const [hash, {op}] of patch) {\n const lastPatchOp = lastPatch.get(hash);\n if (lastPatchOp && lastPatchOp.op === op) {\n patch.delete(hash);\n }\n }\n }\n\n return patch;\n }\n\n handleTransformErrors(errors: ErroredQuery[]) {\n for (const error of errors) {\n const queryId = error.id;\n const entry = this.#queries.get(queryId);\n\n // if we don't have the query registered, continue\n if (!entry) {\n continue;\n }\n\n if (error.error === 'app' || error.error === 'parse') {\n entry.gotCallbacks.forEach(callback => callback(false, error));\n }\n // this code path is not possible technically since errors were never implemented in the legacy query transform error\n // but is included for backwards compatibility and we have a test case for it\n else {\n this.#onFatalError(\n new ProtocolError({\n kind: ErrorKind.TransformFailed,\n origin: ErrorOrigin.ZeroCache,\n reason: ErrorReason.Internal,\n message: `Unknown error transforming queries: ${JSON.stringify(error)}`,\n queryIDs: [],\n }),\n );\n // unreachable(error); TODO(0xcadams): this should eventually be unreachable\n }\n }\n }\n\n handleClosed(\n reason: ClientError<{kind: ClientErrorKind.ClientClosed; message: string}>,\n ) {\n if (this.#closedError) {\n return;\n }\n this.#closedError = reason;\n for (const [queryId, entry] of this.#queries) {\n const erroredQuery: ErroredQuery = {\n error: 'app',\n id: queryId,\n name: entry.name ?? 'legacy',\n message: reason.message,\n details: {kind: reason.kind},\n };\n for (const gotCallback of entry.gotCallbacks) {\n gotCallback(false, erroredQuery);\n }\n }\n }\n\n addCustom(\n ast: AST,\n {name, args}: CustomQueryID,\n ttl: TTL,\n gotCallback?: GotCallback,\n ): () => void {\n const normalized = normalizeAST(ast);\n const queryId = hashOfNameAndArgs(name, args);\n return this.#add(queryId, normalized, name, args, ttl, gotCallback);\n }\n\n /** @deprecated */\n addLegacy(ast: AST, ttl: TTL, gotCallback?: GotCallback): () => void {\n const normalized = normalizeAST(ast);\n const astHash = hashOfAST(normalized);\n return this.#add(\n astHash,\n normalized,\n undefined, // name is undefined for legacy queries\n undefined, // args are undefined for legacy queries\n ttl,\n gotCallback,\n );\n }\n\n #add(\n queryId: string,\n normalized: AST,\n name: string | undefined,\n args: readonly ReadonlyJSONValue[] | undefined,\n ttl: TTL,\n gotCallback?: GotCallback,\n ) {\n assert(\n (name === undefined) === (args === undefined),\n 'If name is defined, args must be defined',\n );\n ttl = clampTTL(ttl, this.#lc);\n let entry = this.#queries.get(queryId);\n this.#recentQueries.delete(queryId);\n if (!entry) {\n normalized = mapAST(normalized, this.#clientToServer);\n\n entry = {\n normalized,\n name,\n args,\n count: 1,\n gotCallbacks: gotCallback ? [gotCallback] : [],\n ttl,\n };\n this.#queries.set(queryId, entry);\n this.#queueQueryChange({\n op: 'put',\n hash: queryId,\n ast: name === undefined ? normalized : undefined,\n name,\n args,\n ttl,\n });\n } else {\n ++entry.count;\n this.#updateEntry(entry, queryId, ttl);\n\n if (gotCallback) {\n entry.gotCallbacks.push(gotCallback);\n }\n }\n\n if (gotCallback) {\n gotCallback(\n this.#gotQueriesAuthoritative\n ? this.#gotQueries.has(queryId)\n : this.#cachedQueries.has(queryId) && 'cached',\n );\n }\n\n let removed = false;\n const cleanupCb = () => {\n if (removed) {\n return;\n }\n removed = true;\n\n // We cannot remove queries while mutations are pending\n // as that could take data out of scope that is needed in a rebase\n if (this.#mutationTracker.size > 0) {\n this.#pendingRemovals.push(() =>\n this.#remove(entry, queryId, gotCallback),\n );\n return;\n }\n\n this.#remove(entry, queryId, gotCallback);\n };\n return cleanupCb;\n }\n\n updateCustom({name, args}: CustomQueryID, ttl: TTL) {\n const queryID = hashOfNameAndArgs(name, args);\n const entry = must(this.#queries.get(queryID));\n this.#updateEntry(entry, queryID, ttl);\n }\n\n /** @deprecated */\n updateLegacy(ast: AST, ttl: TTL) {\n const normalized = normalizeAST(ast);\n const queryID = hashOfAST(normalized);\n const entry = must(this.#queries.get(queryID));\n this.#updateEntry(entry, queryID, ttl);\n }\n\n #updateEntry(entry: Entry, queryID: string, ttl: TTL): void {\n // If the query already exists and the new ttl is larger than the old one\n // we send a changeDesiredQueries message to the server to update the ttl.\n ttl = clampTTL(ttl, this.#lc);\n if (compareTTL(ttl, entry.ttl) > 0) {\n entry.ttl = ttl;\n this.#queueQueryChange({\n op: 'put',\n hash: queryID,\n ast: entry.name === undefined ? entry.normalized : undefined,\n name: entry.name,\n args: entry.args,\n ttl,\n });\n }\n }\n\n #queueQueryChange(op: UpQueriesPatchOp) {\n this.#pendingQueryChanges.push(op);\n this.#scheduleBatch();\n }\n\n #scheduleBatch() {\n if (this.#batchTimer === undefined) {\n this.#batchTimer = setTimeout(\n () => this.flushBatch(),\n this.#queryChangeThrottleMs,\n );\n }\n }\n\n flushBatch() {\n if (this.#batchTimer !== undefined) {\n clearTimeout(this.#batchTimer);\n this.#batchTimer = undefined;\n }\n if (this.#pendingQueryChanges.length > 0) {\n this.#send([\n 'changeDesiredQueries',\n {\n desiredQueriesPatch: [...this.#pendingQueryChanges],\n },\n ]);\n this.#pendingQueryChanges.length = 0;\n }\n }\n\n #remove(entry: Entry, astHash: string, gotCallback: GotCallback | undefined) {\n if (gotCallback) {\n const index = entry.gotCallbacks.indexOf(gotCallback);\n entry.gotCallbacks.splice(index, 1);\n }\n --entry.count;\n if (entry.count === 0) {\n this.#recentQueries.add(astHash);\n if (this.#recentQueries.size > this.#recentQueriesMaxSize) {\n const lruQueryID = this.#recentQueries.values().next().value;\n assert(lruQueryID, 'Expected LRU query ID to exist');\n const evictedAST = this.getAST(lruQueryID);\n const evictedMetrics =\n this.#queryMetrics.get(lruQueryID) ?? newPerQueryMetrics();\n this.#queries.delete(lruQueryID);\n this.#recentQueries.delete(lruQueryID);\n this.#queryMetrics.delete(lruQueryID);\n this.#queueQueryChange({op: 'del', hash: lruQueryID});\n assert(evictedAST, 'Expected evicted AST to exist');\n this.#queryEvictedCallback?.(lruQueryID, evictedAST, evictedMetrics);\n }\n }\n }\n\n /**\n * Gets the aggregated metrics for all queries managed by this QueryManager.\n */\n get metrics(): ClientMetric {\n return this.#metrics;\n }\n\n addMetric<K extends keyof ClientMetricMap>(\n metric: K,\n value: number,\n ...args: ClientMetricMap[K]\n ): void {\n // Only query metrics are tracked at this point.\n // If this check fails then we need to add a runtime check.\n metric satisfies `query-${string}`;\n\n // We track all materializations of queries as well as per\n // query materializations.\n this.#metrics[metric].add(value);\n\n const queryID = args[0];\n\n // Handle slow query logging for end-to-end materialization\n if (metric === 'query-materialization-end-to-end') {\n const ast = args[1];\n\n if (\n this.#slowMaterializeThreshold !== undefined &&\n value > this.#slowMaterializeThreshold\n ) {\n this.#lc.warn?.(\n 'Slow query materialization (including server/network)',\n queryID,\n ast,\n value,\n );\n } else {\n this.#lc.debug?.(\n 'Materialized query (including server/network)',\n queryID,\n ast,\n value,\n );\n }\n }\n\n // The query manager manages metrics that are per query.\n const existing = getOrInsertComputed(\n this.#queryMetrics,\n queryID,\n newPerQueryMetrics,\n );\n switch (metric) {\n case 'query-update-client':\n existing['query-update-client'].add(value);\n break;\n case 'query-materialization-client':\n case 'query-materialization-end-to-end':\n // Recorded once per query (last value wins).\n existing[\n metric as\n | 'query-materialization-client'\n | 'query-materialization-end-to-end'\n ] = value;\n break;\n default:\n unreachable(metric);\n }\n }\n\n getQueryMetrics(queryID: string): PerQueryClientMetric | undefined {\n return this.#queryMetrics.get(queryID);\n }\n\n /**\n * For testing only: returns all query hashes currently registered.\n */\n getAllNonGotQueryHashes(): Iterable<string> {\n return difference(this.#queries, this.#gotQueries);\n }\n}\n\nfunction newMetrics(): ClientMetric {\n return {\n 'query-materialization-client': new TDigest(),\n 'query-materialization-end-to-end': new TDigest(),\n 'query-update-client': new TDigest(),\n };\n}\n\nfunction newPerQueryMetrics(): PerQueryClientMetric {\n return {\n 'query-materialization-client': undefined,\n 'query-materialization-end-to-end': undefined,\n 'query-update-client': new TDigest(),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA2EA,IAAa,eAAb,MAAuD;CACrD;CACA;CACA;CACA;CACA;CACA,2BAA2C,IAAI,IAA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DACA,SACA,KACA,KACF;QAEA,KAAKA,IAAI,QACP,iDACA,SACA,KACA,KACF;EAEJ;EAGA,MAAM,WAAW,oBACf,KAAKE,eACL,SACA,kBACF;EACA,QAAQ,QAAR;GACE,KAAK;IACH,SAAS,uBAAuB,IAAI,KAAK;IACzC;GACF,KAAK;GACL,KAAK;IAEH,SACE,UAGE;IACJ;GACF,SACE,YAAY,MAAM;EACtB;CACF;CAEA,gBAAgB,SAAmD;EACjE,OAAO,KAAKA,cAAc,IAAI,OAAO;CACvC;;;;CAKA,0BAA4C;EAC1C,OAAO,WAAW,KAAKV,UAAU,KAAKG,WAAW;CACnD;AACF;AAEA,SAAS,aAA2B;CAClC,OAAO;EACL,gCAAgC,IAAI,QAAQ;EAC5C,oCAAoC,IAAI,QAAQ;EAChD,uBAAuB,IAAI,QAAQ;CACrC;AACF;AAEA,SAAS,qBAA2C;CAClD,OAAO;EACL,gCAAgC,KAAA;EAChC,oCAAoC,KAAA;EACpC,uBAAuB,IAAI,QAAQ;CACrC;AACF"}
@@ -2,7 +2,7 @@
2
2
  /**
3
3
  * The current version of Zero.
4
4
  */
5
- var version = "1.10.0-canary.22";
5
+ var version = "1.10.0-canary.24";
6
6
  //#endregion
7
7
  export { version };
8
8
 
@@ -1 +1 @@
1
- {"version":3,"file":"zero-rep.d.ts","sourceRoot":"","sources":["../../../../../zero-client/src/client/zero-rep.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EAEb,MAAM,uCAAuC,CAAC;AAC/C,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,2CAA2C,CAAC;AAGzE,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,iCAAiC,CAAC;AAC1D,OAAO,KAAK,EACV,WAAW,EACX,oBAAoB,EACpB,UAAU,EACV,eAAe,EAChB,MAAM,+CAA+C,CAAC;AAGvD,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAC,eAAe,EAAC,M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,WAAW,EAAE,EAAE,EAAE,OAAO,GAAG,IAAI;CAG5D"}
@@ -37,7 +37,7 @@ var ZeroRep = class {
37
37
  });
38
38
  this.#store = store;
39
39
  this.#context.processChanges(void 0, hash, diffs);
40
- this.#context.markPipelinesReady();
40
+ await this.#context.hydratePendingPipelines();
41
41
  }
42
42
  getTxData = (desiredHead, readOptions) => {
43
43
  if (!this.#customMutatorsEnabled) return;
@@ -1 +1 @@
1
- {"version":3,"file":"zero-rep.js","names":["#context","#ivmMain","#customMutatorsEnabled","#mutationTracker","#auth","#store","#makeTxData"],"sources":["../../../../../zero-client/src/client/zero-rep.ts"],"sourcesContent":["import type {\n InternalDiff,\n InternalDiffOperation,\n} from '../../../replicache/src/btree/node.ts';\nimport type {LazyStore} from '../../../replicache/src/dag/lazy-store.ts';\nimport {readFromHash} from '../../../replicache/src/db/read.ts';\nimport * as FormatVersion from '../../../replicache/src/format-version-enum.ts';\nimport type {Hash} from '../../../replicache/src/hash.ts';\nimport type {\n EphemeralID,\n MutationTrackingData,\n ZeroOption,\n ZeroReadOptions,\n} from '../../../replicache/src/replicache-options.ts';\nimport {withRead} from '../../../replicache/src/with-transactions.ts';\nimport {must} from '../../../shared/src/must.ts';\nimport type {ZeroContext} from './context.ts';\nimport type {IVMSourceBranch} from './ivm-branch.ts';\nimport {ENTITIES_KEY_PREFIX} from './keys.ts';\nimport type {MutationTracker} from './mutation-tracker.ts';\n\n// Replicache doesn't support undefined auth tokens\nconst REPLICACHE_NO_AUTH_TOKEN = '';\n\nexport const toReplicacheAuthToken = (\n auth: string | undefined | null,\n): string => auth ?? REPLICACHE_NO_AUTH_TOKEN;\n\nexport const fromReplicacheAuthToken = (auth: string): string | undefined =>\n !auth ? undefined : auth;\n\ntype TxData = {\n ivmSources: IVMSourceBranch;\n token: string | undefined;\n context: unknown;\n fork: () => TxData;\n};\n\nexport class ZeroRep implements ZeroOption {\n readonly #context: ZeroContext;\n readonly #ivmMain: IVMSourceBranch;\n readonly #customMutatorsEnabled: boolean;\n readonly #mutationTracker: MutationTracker;\n #store: LazyStore | undefined;\n // matches replicache's auth token type\n #auth: string = REPLICACHE_NO_AUTH_TOKEN;\n\n constructor(\n context: ZeroContext,\n ivmMain: IVMSourceBranch,\n customMutatorsEnabled: boolean,\n mutationTracker: MutationTracker,\n ) {\n this.#context = context;\n this.#ivmMain = ivmMain;\n this.#customMutatorsEnabled = customMutatorsEnabled;\n this.#mutationTracker = mutationTracker;\n }\n\n set auth(auth: string) {\n this.#auth = auth;\n }\n\n async init(hash: Hash, store: LazyStore) {\n const diffs: InternalDiffOperation[] = [];\n await withRead(store, async dagRead => {\n const read = await readFromHash(hash, dagRead, FormatVersion.Latest);\n for await (const entry of read.map.scan(ENTITIES_KEY_PREFIX, true)) {\n if (!entry[0].startsWith(ENTITIES_KEY_PREFIX)) {\n break;\n }\n diffs.push({\n op: 'add',\n key: entry[0],\n newValue: entry[1],\n });\n }\n });\n this.#store = store;\n\n this.#context.processChanges(undefined, hash, diffs);\n // Pipelines for queries materialized before this point were deferred so\n // the replica above was loaded into the sources without fanning out to\n // them. Build and hydrate them now that the sources are populated.\n this.#context.markPipelinesReady();\n }\n\n getTxData = (\n desiredHead: Hash,\n readOptions?: ZeroReadOptions,\n ): Promise<TxData> | undefined => {\n // getTxData requires some extensive testing for complete confidence\n // that it will not break. Do not enable `getTxData` unless the user\n // has opted into custom mutators.\n if (!this.#customMutatorsEnabled) {\n return;\n }\n\n return this.#ivmMain\n .forkToHead(must(this.#store), desiredHead, readOptions)\n .then(branch => this.#makeTxData(branch));\n };\n\n #makeTxData = (branch: IVMSourceBranch): TxData => ({\n ivmSources: branch,\n token: fromReplicacheAuthToken(this.#auth),\n context: this.#context,\n fork: () => this.#makeTxData(branch.fork()),\n });\n\n advance = (expectedHash: Hash, newHash: Hash, diffs: InternalDiff): void => {\n this.#context.processChanges(expectedHash, newHash, diffs);\n };\n\n trackMutation(): MutationTrackingData {\n return this.#mutationTracker.trackMutation();\n }\n mutationIDAssigned(ephemeralID: EphemeralID, mutationID: number): void {\n this.#mutationTracker.mutationIDAssigned(ephemeralID, mutationID);\n }\n rejectMutation(ephemeralID: EphemeralID, ex: unknown): void {\n this.#mutationTracker.rejectMutation(ephemeralID, ex);\n }\n}\n"],"mappings":";;;;;AAsBA,IAAM,2BAA2B;AAEjC,IAAa,yBACX,SACW,QAAQ;AAErB,IAAa,2BAA2B,SACtC,CAAC,OAAO,KAAA,IAAY;AAStB,IAAa,UAAb,MAA2C;CACzC;CACA;CACA;CACA;CACA;CAEA,QAAgB;CAEhB,YACE,SACA,SACA,uBACA,iBACA;EACA,KAAKA,WAAW;EAChB,KAAKC,WAAW;EAChB,KAAKC,yBAAyB;EAC9B,KAAKC,mBAAmB;CAC1B;CAEA,IAAI,KAAK,MAAc;EACrB,KAAKC,QAAQ;CACf;CAEA,MAAM,KAAK,MAAY,OAAkB;EACvC,MAAM,QAAiC,CAAC;EACxC,MAAM,SAAS,OAAO,OAAM,YAAW;GACrC,MAAM,OAAO,MAAM,aAAa,MAAM,SAAS,CAAoB;GACnE,WAAW,MAAM,SAAS,KAAK,IAAI,KAAA,MAA0B,IAAI,GAAG;IAClE,IAAI,CAAC,MAAM,GAAG,WAAA,IAA8B,GAC1C;IAEF,MAAM,KAAK;KACT,IAAI;KACJ,KAAK,MAAM;KACX,UAAU,MAAM;IAClB,CAAC;GACH;EACF,CAAC;EACD,KAAKC,SAAS;EAEd,KAAKL,SAAS,eAAe,KAAA,GAAW,MAAM,KAAK;EAInD,KAAKA,SAAS,mBAAmB;CACnC;CAEA,aACE,aACA,gBACgC;EAIhC,IAAI,CAAC,KAAKE,wBACR;EAGF,OAAO,KAAKD,SACT,WAAW,KAAK,KAAKI,MAAM,GAAG,aAAa,WAAW,EACtD,MAAK,WAAU,KAAKC,YAAY,MAAM,CAAC;CAC5C;CAEA,eAAe,YAAqC;EAClD,YAAY;EACZ,OAAO,wBAAwB,KAAKF,KAAK;EACzC,SAAS,KAAKJ;EACd,YAAY,KAAKM,YAAY,OAAO,KAAK,CAAC;CAC5C;CAEA,WAAW,cAAoB,SAAe,UAA8B;EAC1E,KAAKN,SAAS,eAAe,cAAc,SAAS,KAAK;CAC3D;CAEA,gBAAsC;EACpC,OAAO,KAAKG,iBAAiB,cAAc;CAC7C;CACA,mBAAmB,aAA0B,YAA0B;EACrE,KAAKA,iBAAiB,mBAAmB,aAAa,UAAU;CAClE;CACA,eAAe,aAA0B,IAAmB;EAC1D,KAAKA,iBAAiB,eAAe,aAAa,EAAE;CACtD;AACF"}
1
+ {"version":3,"file":"zero-rep.js","names":["#context","#ivmMain","#customMutatorsEnabled","#mutationTracker","#auth","#store","#makeTxData"],"sources":["../../../../../zero-client/src/client/zero-rep.ts"],"sourcesContent":["import type {\n InternalDiff,\n InternalDiffOperation,\n} from '../../../replicache/src/btree/node.ts';\nimport type {LazyStore} from '../../../replicache/src/dag/lazy-store.ts';\nimport {readFromHash} from '../../../replicache/src/db/read.ts';\nimport * as FormatVersion from '../../../replicache/src/format-version-enum.ts';\nimport type {Hash} from '../../../replicache/src/hash.ts';\nimport type {\n EphemeralID,\n MutationTrackingData,\n ZeroOption,\n ZeroReadOptions,\n} from '../../../replicache/src/replicache-options.ts';\nimport {withRead} from '../../../replicache/src/with-transactions.ts';\nimport {must} from '../../../shared/src/must.ts';\nimport type {ZeroContext} from './context.ts';\nimport type {IVMSourceBranch} from './ivm-branch.ts';\nimport {ENTITIES_KEY_PREFIX} from './keys.ts';\nimport type {MutationTracker} from './mutation-tracker.ts';\n\n// Replicache doesn't support undefined auth tokens\nconst REPLICACHE_NO_AUTH_TOKEN = '';\n\nexport const toReplicacheAuthToken = (\n auth: string | undefined | null,\n): string => auth ?? REPLICACHE_NO_AUTH_TOKEN;\n\nexport const fromReplicacheAuthToken = (auth: string): string | undefined =>\n !auth ? undefined : auth;\n\ntype TxData = {\n ivmSources: IVMSourceBranch;\n token: string | undefined;\n context: unknown;\n fork: () => TxData;\n};\n\nexport class ZeroRep implements ZeroOption {\n readonly #context: ZeroContext;\n readonly #ivmMain: IVMSourceBranch;\n readonly #customMutatorsEnabled: boolean;\n readonly #mutationTracker: MutationTracker;\n #store: LazyStore | undefined;\n // matches replicache's auth token type\n #auth: string = REPLICACHE_NO_AUTH_TOKEN;\n\n constructor(\n context: ZeroContext,\n ivmMain: IVMSourceBranch,\n customMutatorsEnabled: boolean,\n mutationTracker: MutationTracker,\n ) {\n this.#context = context;\n this.#ivmMain = ivmMain;\n this.#customMutatorsEnabled = customMutatorsEnabled;\n this.#mutationTracker = mutationTracker;\n }\n\n set auth(auth: string) {\n this.#auth = auth;\n }\n\n async init(hash: Hash, store: LazyStore) {\n const diffs: InternalDiffOperation[] = [];\n await withRead(store, async dagRead => {\n const read = await readFromHash(hash, dagRead, FormatVersion.Latest);\n for await (const entry of read.map.scan(ENTITIES_KEY_PREFIX, true)) {\n if (!entry[0].startsWith(ENTITIES_KEY_PREFIX)) {\n break;\n }\n diffs.push({\n op: 'add',\n key: entry[0],\n newValue: entry[1],\n });\n }\n });\n this.#store = store;\n\n this.#context.processChanges(undefined, hash, diffs);\n // Pipelines for queries materialized before this point were deferred so\n // the replica above was loaded into the sources without fanning out to\n // them. Build and hydrate them now that the sources are populated,\n // yielding between pipelines so the app stays responsive. Replicache is\n // not ready until this returns so no changes arrive in the meantime.\n await this.#context.hydratePendingPipelines();\n }\n\n getTxData = (\n desiredHead: Hash,\n readOptions?: ZeroReadOptions,\n ): Promise<TxData> | undefined => {\n // getTxData requires some extensive testing for complete confidence\n // that it will not break. Do not enable `getTxData` unless the user\n // has opted into custom mutators.\n if (!this.#customMutatorsEnabled) {\n return;\n }\n\n return this.#ivmMain\n .forkToHead(must(this.#store), desiredHead, readOptions)\n .then(branch => this.#makeTxData(branch));\n };\n\n #makeTxData = (branch: IVMSourceBranch): TxData => ({\n ivmSources: branch,\n token: fromReplicacheAuthToken(this.#auth),\n context: this.#context,\n fork: () => this.#makeTxData(branch.fork()),\n });\n\n advance = (expectedHash: Hash, newHash: Hash, diffs: InternalDiff): void => {\n this.#context.processChanges(expectedHash, newHash, diffs);\n };\n\n trackMutation(): MutationTrackingData {\n return this.#mutationTracker.trackMutation();\n }\n mutationIDAssigned(ephemeralID: EphemeralID, mutationID: number): void {\n this.#mutationTracker.mutationIDAssigned(ephemeralID, mutationID);\n }\n rejectMutation(ephemeralID: EphemeralID, ex: unknown): void {\n this.#mutationTracker.rejectMutation(ephemeralID, ex);\n }\n}\n"],"mappings":";;;;;AAsBA,IAAM,2BAA2B;AAEjC,IAAa,yBACX,SACW,QAAQ;AAErB,IAAa,2BAA2B,SACtC,CAAC,OAAO,KAAA,IAAY;AAStB,IAAa,UAAb,MAA2C;CACzC;CACA;CACA;CACA;CACA;CAEA,QAAgB;CAEhB,YACE,SACA,SACA,uBACA,iBACA;EACA,KAAKA,WAAW;EAChB,KAAKC,WAAW;EAChB,KAAKC,yBAAyB;EAC9B,KAAKC,mBAAmB;CAC1B;CAEA,IAAI,KAAK,MAAc;EACrB,KAAKC,QAAQ;CACf;CAEA,MAAM,KAAK,MAAY,OAAkB;EACvC,MAAM,QAAiC,CAAC;EACxC,MAAM,SAAS,OAAO,OAAM,YAAW;GACrC,MAAM,OAAO,MAAM,aAAa,MAAM,SAAS,CAAoB;GACnE,WAAW,MAAM,SAAS,KAAK,IAAI,KAAA,MAA0B,IAAI,GAAG;IAClE,IAAI,CAAC,MAAM,GAAG,WAAA,IAA8B,GAC1C;IAEF,MAAM,KAAK;KACT,IAAI;KACJ,KAAK,MAAM;KACX,UAAU,MAAM;IAClB,CAAC;GACH;EACF,CAAC;EACD,KAAKC,SAAS;EAEd,KAAKL,SAAS,eAAe,KAAA,GAAW,MAAM,KAAK;EAMnD,MAAM,KAAKA,SAAS,wBAAwB;CAC9C;CAEA,aACE,aACA,gBACgC;EAIhC,IAAI,CAAC,KAAKE,wBACR;EAGF,OAAO,KAAKD,SACT,WAAW,KAAK,KAAKI,MAAM,GAAG,aAAa,WAAW,EACtD,MAAK,WAAU,KAAKC,YA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cher = getDocumentVisibilityWatcher(getBrowserGlobal("document"), hiddenTabDisconnectDelay, this.#closeAbortController.signal);
304
305
  this.#zeroContext = new ZeroContext(lc, this.#ivmMain, (ast, ttl, gotCallback) => {
305
306
  if (enableLegacyQueries) return this.#queryManager.addLegacy(ast, ttl, gotCallback);
306
307
  return emptyFunction;
307
308
  }, (ast, customQueryID, ttl, gotCallback) => this.#queryManager.addCustom(ast, customQueryID, ttl, gotCallback), (ast, ttl) => {
308
309
  if (enableLegacyQueries) this.#queryManager.updateLegacy(ast, ttl);
309
- }, (customQueryID, ttl) => this.#queryManager.updateCustom(customQueryID, ttl), () => this.#queryManager.flushBatch(), batchViewUpdates, this.#addMetric, assertValidRunOptions);
310
+ }, (customQueryID, ttl) => this.#queryManager.updateCustom(customQueryID, ttl), () => this.#queryManager.flushBatch(), batchViewUpdates, this.#addMetric, assertValidRunOptions, this.#visibilityWatcher);
310
311
  this.query = createRunnableBuilder(this.#zeroContext, schema);
311
312
  const rep = new ReplicacheImpl(replicacheOptions, {
312
313
  enableClientGroupForking: false,
@@ -381,7 +382,6 @@ var Zero = class Zero {
381
382
  await this.#rep.poke(poke);
382
383
  if (socket !== void 0 && this.#socket === socket) this.#queryManager.markGotQueriesAuthoritative();
383
384
  }, (e) => this.#onPokeError(e), rep.clientID, schema, this.#lc, this.#mutationTracker);
384
- this.#visibilityWatcher = getDocumentVisibilityWatcher(getBrowserGlobal("document"), hiddenTabDisconnectDelay, this.#closeAbortController.signal);
385
385
  this.#runLoop();
386
386
  this.#expose();
387
387
  }