@rocicorp/zero 1.11.0-canary.2 → 1.11.0-canary.21

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 (832) hide show
  1. package/out/analyze-query/src/bin-analyze.js +9 -8
  2. package/out/analyze-query/src/bin-analyze.js.map +1 -1
  3. package/out/ast-to-zql/src/ast-to-zql.d.ts +8 -1
  4. package/out/ast-to-zql/src/ast-to-zql.d.ts.map +1 -1
  5. package/out/ast-to-zql/src/ast-to-zql.js +25 -25
  6. package/out/ast-to-zql/src/ast-to-zql.js.map +1 -1
  7. package/out/otel/src/log-options.d.ts +16 -0
  8. package/out/otel/src/log-options.d.ts.map +1 -1
  9. package/out/otel/src/log-options.js +54 -1
  10. package/out/otel/src/log-options.js.map +1 -1
  11. package/out/replicache/src/bg-interval.d.ts +2 -1
  12. package/out/replicache/src/bg-interval.d.ts.map +1 -1
  13. package/out/replicache/src/bg-interval.js +13 -4
  14. package/out/replicache/src/bg-interval.js.map +1 -1
  15. package/out/replicache/src/btree/node.d.ts.map +1 -1
  16. package/out/replicache/src/btree/node.js +3 -6
  17. package/out/replicache/src/btree/node.js.map +1 -1
  18. package/out/replicache/src/dag/gc.d.ts.map +1 -1
  19. package/out/replicache/src/dag/gc.js +8 -11
  20. package/out/replicache/src/dag/gc.js.map +1 -1
  21. package/out/replicache/src/dag/invalid-ref-count-error.d.ts +12 -0
  22. package/out/replicache/src/dag/invalid-ref-count-error.d.ts.map +1 -0
  23. package/out/replicache/src/dag/invalid-ref-count-error.js +19 -0
  24. package/out/replicache/src/dag/invalid-ref-count-error.js.map +1 -0
  25. package/out/replicache/src/dag/lazy-store.d.ts +17 -4
  26. package/out/replicache/src/dag/lazy-store.d.ts.map +1 -1
  27. package/out/replicache/src/dag/lazy-store.js +35 -9
  28. package/out/replicache/src/dag/lazy-store.js.map +1 -1
  29. package/out/replicache/src/dag/store-impl.d.ts +12 -2
  30. package/out/replicache/src/dag/store-impl.d.ts.map +1 -1
  31. package/out/replicache/src/dag/store-impl.js +29 -9
  32. package/out/replicache/src/dag/store-impl.js.map +1 -1
  33. package/out/replicache/src/db/rebase.d.ts +14 -2
  34. package/out/replicache/src/db/rebase.d.ts.map +1 -1
  35. package/out/replicache/src/db/rebase.js +27 -5
  36. package/out/replicache/src/db/rebase.js.map +1 -1
  37. package/out/replicache/src/get-kv-store-provider.d.ts +1 -1
  38. package/out/replicache/src/get-kv-store-provider.d.ts.map +1 -1
  39. package/out/replicache/src/get-kv-store-provider.js +4 -4
  40. package/out/replicache/src/get-kv-store-provider.js.map +1 -1
  41. package/out/replicache/src/kv/expo-sqlite/store.d.ts.map +1 -1
  42. package/out/replicache/src/kv/expo-sqlite/store.js +28 -5
  43. package/out/replicache/src/kv/expo-sqlite/store.js.map +1 -1
  44. package/out/replicache/src/kv/idb-store.d.ts +18 -0
  45. package/out/replicache/src/kv/idb-store.d.ts.map +1 -1
  46. package/out/replicache/src/kv/idb-store.js +30 -2
  47. package/out/replicache/src/kv/idb-store.js.map +1 -1
  48. package/out/replicache/src/kv/mem-fallback-store.d.ts +54 -0
  49. package/out/replicache/src/kv/mem-fallback-store.d.ts.map +1 -0
  50. package/out/replicache/src/kv/mem-fallback-store.js +177 -0
  51. package/out/replicache/src/kv/mem-fallback-store.js.map +1 -0
  52. package/out/replicache/src/kv/mem-store.d.ts +1 -0
  53. package/out/replicache/src/kv/mem-store.d.ts.map +1 -1
  54. package/out/replicache/src/kv/mem-store.js +3 -0
  55. package/out/replicache/src/kv/mem-store.js.map +1 -1
  56. package/out/replicache/src/kv/op-sqlite/store.d.ts.map +1 -1
  57. package/out/replicache/src/kv/op-sqlite/store.js +4 -4
  58. package/out/replicache/src/kv/op-sqlite/store.js.map +1 -1
  59. package/out/replicache/src/kv/sqlite-store.d.ts +22 -1
  60. package/out/replicache/src/kv/sqlite-store.d.ts.map +1 -1
  61. package/out/replicache/src/kv/sqlite-store.js +159 -14
  62. package/out/replicache/src/kv/sqlite-store.js.map +1 -1
  63. package/out/replicache/src/kv/store.d.ts +6 -0
  64. package/out/replicache/src/kv/store.d.ts.map +1 -1
  65. package/out/replicache/src/new-client-channel.js.map +1 -1
  66. package/out/replicache/src/persist/client-gc.d.ts +2 -1
  67. package/out/replicache/src/persist/client-gc.d.ts.map +1 -1
  68. package/out/replicache/src/persist/client-gc.js +2 -2
  69. package/out/replicache/src/persist/client-gc.js.map +1 -1
  70. package/out/replicache/src/persist/client-group-gc.d.ts +2 -1
  71. package/out/replicache/src/persist/client-group-gc.d.ts.map +1 -1
  72. package/out/replicache/src/persist/client-group-gc.js +2 -2
  73. package/out/replicache/src/persist/client-group-gc.js.map +1 -1
  74. package/out/replicache/src/persist/collect-idb-databases.d.ts +28 -8
  75. package/out/replicache/src/persist/collect-idb-databases.d.ts.map +1 -1
  76. package/out/replicache/src/persist/collect-idb-databases.js +97 -20
  77. package/out/replicache/src/persist/collect-idb-databases.js.map +1 -1
  78. package/out/replicache/src/persist/heartbeat.d.ts +2 -1
  79. package/out/replicache/src/persist/heartbeat.d.ts.map +1 -1
  80. package/out/replicache/src/persist/heartbeat.js +2 -2
  81. package/out/replicache/src/persist/heartbeat.js.map +1 -1
  82. package/out/replicache/src/persist/idb-databases-store-db-name.js +1 -1
  83. package/out/replicache/src/persist/idb-databases-store-db-name.js.map +1 -1
  84. package/out/replicache/src/persist/persist.d.ts.map +1 -1
  85. package/out/replicache/src/persist/persist.js +18 -8
  86. package/out/replicache/src/persist/persist.js.map +1 -1
  87. package/out/replicache/src/persist/refresh.js +6 -2
  88. package/out/replicache/src/persist/refresh.js.map +1 -1
  89. package/out/replicache/src/replicache-impl.d.ts +85 -3
  90. package/out/replicache/src/replicache-impl.d.ts.map +1 -1
  91. package/out/replicache/src/replicache-impl.js +321 -29
  92. package/out/replicache/src/replicache-impl.js.map +1 -1
  93. package/out/replicache/src/replicache-options.d.ts +9 -0
  94. package/out/replicache/src/replicache-options.d.ts.map +1 -1
  95. package/out/replicache/src/storage-failure.d.ts +37 -0
  96. package/out/replicache/src/storage-failure.d.ts.map +1 -0
  97. package/out/replicache/src/storage-failure.js +31 -0
  98. package/out/replicache/src/storage-failure.js.map +1 -0
  99. package/out/shared/src/arrays.d.ts +5 -0
  100. package/out/shared/src/arrays.d.ts.map +1 -1
  101. package/out/shared/src/arrays.js +8 -10
  102. package/out/shared/src/arrays.js.map +1 -1
  103. package/out/shared/src/error.d.ts +11 -0
  104. package/out/shared/src/error.d.ts.map +1 -1
  105. package/out/shared/src/error.js +35 -1
  106. package/out/shared/src/error.js.map +1 -1
  107. package/out/shared/src/iterables.d.ts +2 -0
  108. package/out/shared/src/iterables.d.ts.map +1 -1
  109. package/out/shared/src/iterables.js +18 -1
  110. package/out/shared/src/iterables.js.map +1 -1
  111. package/out/shared/src/map.d.ts +24 -2
  112. package/out/shared/src/map.d.ts.map +1 -1
  113. package/out/shared/src/map.js +18 -4
  114. package/out/shared/src/map.js.map +1 -1
  115. package/out/shared/src/random-values.js +12 -1
  116. package/out/shared/src/random-values.js.map +1 -1
  117. package/out/shared/src/ring-buffer.d.ts +10 -0
  118. package/out/shared/src/ring-buffer.d.ts.map +1 -1
  119. package/out/shared/src/ring-buffer.js +26 -1
  120. package/out/shared/src/ring-buffer.js.map +1 -1
  121. package/out/z2s/src/compiler.js +1 -1
  122. package/out/z2s/src/sql.d.ts.map +1 -1
  123. package/out/z2s/src/sql.js +2 -2
  124. package/out/z2s/src/sql.js.map +1 -1
  125. package/out/zero/package.js +3 -4
  126. package/out/zero/package.js.map +1 -1
  127. package/out/zero/src/zero.js +2 -1
  128. package/out/zero-cache/src/auth/write-authorizer.d.ts.map +1 -1
  129. package/out/zero-cache/src/auth/write-authorizer.js +1 -0
  130. package/out/zero-cache/src/auth/write-authorizer.js.map +1 -1
  131. package/out/zero-cache/src/config/normalize.d.ts.map +1 -1
  132. package/out/zero-cache/src/config/normalize.js +26 -2
  133. package/out/zero-cache/src/config/normalize.js.map +1 -1
  134. package/out/zero-cache/src/config/zero-config.d.ts +102 -6
  135. package/out/zero-cache/src/config/zero-config.d.ts.map +1 -1
  136. package/out/zero-cache/src/config/zero-config.js +254 -57
  137. package/out/zero-cache/src/config/zero-config.js.map +1 -1
  138. package/out/zero-cache/src/db/lite-tables.d.ts.map +1 -1
  139. package/out/zero-cache/src/db/lite-tables.js +3 -4
  140. package/out/zero-cache/src/db/lite-tables.js.map +1 -1
  141. package/out/zero-cache/src/observability/events.js +4 -1
  142. package/out/zero-cache/src/observability/events.js.map +1 -1
  143. package/out/zero-cache/src/observability/log-throttle.d.ts +44 -0
  144. package/out/zero-cache/src/observability/log-throttle.d.ts.map +1 -0
  145. package/out/zero-cache/src/observability/log-throttle.js +76 -0
  146. package/out/zero-cache/src/observability/log-throttle.js.map +1 -0
  147. package/out/zero-cache/src/observability/metrics.d.ts.map +1 -1
  148. package/out/zero-cache/src/observability/metrics.js +2 -7
  149. package/out/zero-cache/src/observability/metrics.js.map +1 -1
  150. package/out/zero-cache/src/scripts/permissions.d.ts +16 -0
  151. package/out/zero-cache/src/scripts/permissions.d.ts.map +1 -1
  152. package/out/zero-cache/src/server/change-streamer.d.ts.map +1 -1
  153. package/out/zero-cache/src/server/change-streamer.js +27 -10
  154. package/out/zero-cache/src/server/change-streamer.js.map +1 -1
  155. package/out/zero-cache/src/server/inspector-delegate.d.ts +28 -2
  156. package/out/zero-cache/src/server/inspector-delegate.d.ts.map +1 -1
  157. package/out/zero-cache/src/server/inspector-delegate.js +37 -17
  158. package/out/zero-cache/src/server/inspector-delegate.js.map +1 -1
  159. package/out/zero-cache/src/server/main.d.ts.map +1 -1
  160. package/out/zero-cache/src/server/main.js +8 -1
  161. package/out/zero-cache/src/server/main.js.map +1 -1
  162. package/out/zero-cache/src/server/mutator.js +2 -0
  163. package/out/zero-cache/src/server/mutator.js.map +1 -1
  164. package/out/zero-cache/src/server/reaper.d.ts.map +1 -1
  165. package/out/zero-cache/src/server/reaper.js +2 -0
  166. package/out/zero-cache/src/server/reaper.js.map +1 -1
  167. package/out/zero-cache/src/server/replicator.d.ts +3 -0
  168. package/out/zero-cache/src/server/replicator.d.ts.map +1 -1
  169. package/out/zero-cache/src/server/replicator.js +79 -15
  170. package/out/zero-cache/src/server/replicator.js.map +1 -1
  171. package/out/zero-cache/src/server/runner/zero-dispatcher.d.ts.map +1 -1
  172. package/out/zero-cache/src/server/runner/zero-dispatcher.js +5 -0
  173. package/out/zero-cache/src/server/runner/zero-dispatcher.js.map +1 -1
  174. package/out/zero-cache/src/server/syncer-assigner.d.ts +14 -0
  175. package/out/zero-cache/src/server/syncer-assigner.d.ts.map +1 -0
  176. package/out/zero-cache/src/server/syncer-assigner.js +72 -0
  177. package/out/zero-cache/src/server/syncer-assigner.js.map +1 -0
  178. package/out/zero-cache/src/server/syncer.d.ts.map +1 -1
  179. package/out/zero-cache/src/server/syncer.js +24 -2
  180. package/out/zero-cache/src/server/syncer.js.map +1 -1
  181. package/out/zero-cache/src/server/worker-dispatcher.d.ts.map +1 -1
  182. package/out/zero-cache/src/server/worker-dispatcher.js +21 -4
  183. package/out/zero-cache/src/server/worker-dispatcher.js.map +1 -1
  184. package/out/zero-cache/src/services/analyze.d.ts.map +1 -1
  185. package/out/zero-cache/src/services/analyze.js +11 -9
  186. package/out/zero-cache/src/services/analyze.js.map +1 -1
  187. package/out/zero-cache/src/services/change-source/common/backfill-manager.d.ts.map +1 -1
  188. package/out/zero-cache/src/services/change-source/common/backfill-manager.js +198 -24
  189. package/out/zero-cache/src/services/change-source/common/backfill-manager.js.map +1 -1
  190. package/out/zero-cache/src/services/change-source/common/change-stream-multiplexer.d.ts.map +1 -1
  191. package/out/zero-cache/src/services/change-source/common/change-stream-multiplexer.js +15 -3
  192. package/out/zero-cache/src/services/change-source/common/change-stream-multiplexer.js.map +1 -1
  193. package/out/zero-cache/src/services/change-source/common/replica-schema.d.ts +1 -0
  194. package/out/zero-cache/src/services/change-source/common/replica-schema.d.ts.map +1 -1
  195. package/out/zero-cache/src/services/change-source/common/replica-schema.js +15 -3
  196. package/out/zero-cache/src/services/change-source/common/replica-schema.js.map +1 -1
  197. package/out/zero-cache/src/services/change-source/pg/backfill-stream.d.ts +9 -0
  198. package/out/zero-cache/src/services/change-source/pg/backfill-stream.d.ts.map +1 -1
  199. package/out/zero-cache/src/services/change-source/pg/backfill-stream.js +204 -18
  200. package/out/zero-cache/src/services/change-source/pg/backfill-stream.js.map +1 -1
  201. package/out/zero-cache/src/services/change-source/pg/change-source-init.d.ts +25 -0
  202. package/out/zero-cache/src/services/change-source/pg/change-source-init.d.ts.map +1 -0
  203. package/out/zero-cache/src/services/change-source/pg/change-source-init.js +202 -0
  204. package/out/zero-cache/src/services/change-source/pg/change-source-init.js.map +1 -0
  205. package/out/zero-cache/src/services/change-source/pg/change-source.d.ts +14 -16
  206. package/out/zero-cache/src/services/change-source/pg/change-source.d.ts.map +1 -1
  207. package/out/zero-cache/src/services/change-source/pg/change-source.js +64 -143
  208. package/out/zero-cache/src/services/change-source/pg/change-source.js.map +1 -1
  209. package/out/zero-cache/src/services/change-source/pg/initial-sync.d.ts +37 -2
  210. package/out/zero-cache/src/services/change-source/pg/initial-sync.d.ts.map +1 -1
  211. package/out/zero-cache/src/services/change-source/pg/initial-sync.js +53 -21
  212. package/out/zero-cache/src/services/change-source/pg/initial-sync.js.map +1 -1
  213. package/out/zero-cache/src/services/change-source/pg/replication-slot-cleanup-monitor.d.ts +16 -0
  214. package/out/zero-cache/src/services/change-source/pg/replication-slot-cleanup-monitor.d.ts.map +1 -0
  215. package/out/zero-cache/src/services/change-source/pg/replication-slot-cleanup-monitor.js +113 -0
  216. package/out/zero-cache/src/services/change-source/pg/replication-slot-cleanup-monitor.js.map +1 -0
  217. package/out/zero-cache/src/services/change-source/pg/replication-slots.d.ts +21 -15
  218. package/out/zero-cache/src/services/change-source/pg/replication-slots.d.ts.map +1 -1
  219. package/out/zero-cache/src/services/change-source/pg/replication-slots.js +86 -23
  220. package/out/zero-cache/src/services/change-source/pg/replication-slots.js.map +1 -1
  221. package/out/zero-cache/src/services/change-source/pg/schema/index-predicate.d.ts.map +1 -1
  222. package/out/zero-cache/src/services/change-source/pg/schema/index-predicate.js +68 -8
  223. package/out/zero-cache/src/services/change-source/pg/schema/index-predicate.js.map +1 -1
  224. package/out/zero-cache/src/services/change-source/pg/schema/init.d.ts.map +1 -1
  225. package/out/zero-cache/src/services/change-source/pg/schema/init.js +32 -1
  226. package/out/zero-cache/src/services/change-source/pg/schema/init.js.map +1 -1
  227. package/out/zero-cache/src/services/change-source/pg/schema/replica-stage-enum.d.ts +10 -0
  228. package/out/zero-cache/src/services/change-source/pg/schema/replica-stage-enum.d.ts.map +1 -0
  229. package/out/zero-cache/src/services/change-source/pg/schema/replica-stage-enum.js +6 -0
  230. package/out/zero-cache/src/services/change-source/pg/schema/replica-stage-enum.js.map +1 -0
  231. package/out/zero-cache/src/services/change-source/pg/schema/shard.d.ts +50 -27
  232. package/out/zero-cache/src/services/change-source/pg/schema/shard.d.ts.map +1 -1
  233. package/out/zero-cache/src/services/change-source/pg/schema/shard.js +100 -34
  234. package/out/zero-cache/src/services/change-source/pg/schema/shard.js.map +1 -1
  235. package/out/zero-cache/src/services/change-source/protocol/backfill-progress.d.ts +68 -0
  236. package/out/zero-cache/src/services/change-source/protocol/backfill-progress.d.ts.map +1 -0
  237. package/out/zero-cache/src/services/change-source/protocol/backfill-progress.js +141 -0
  238. package/out/zero-cache/src/services/change-source/protocol/backfill-progress.js.map +1 -0
  239. package/out/zero-cache/src/services/change-source/protocol/current/data.d.ts +43 -0
  240. package/out/zero-cache/src/services/change-source/protocol/current/data.d.ts.map +1 -1
  241. package/out/zero-cache/src/services/change-source/protocol/current/data.js +10 -1
  242. package/out/zero-cache/src/services/change-source/protocol/current/data.js.map +1 -1
  243. package/out/zero-cache/src/services/change-source/protocol/current/downstream.d.ts +57 -0
  244. package/out/zero-cache/src/services/change-source/protocol/current/downstream.d.ts.map +1 -1
  245. package/out/zero-cache/src/services/change-source/protocol/current/upstream.d.ts +20 -6
  246. package/out/zero-cache/src/services/change-source/protocol/current/upstream.d.ts.map +1 -1
  247. package/out/zero-cache/src/services/change-source/protocol/current/upstream.js +17 -7
  248. package/out/zero-cache/src/services/change-source/protocol/current/upstream.js.map +1 -1
  249. package/out/zero-cache/src/services/change-source/protocol/current.js +2 -1
  250. package/out/zero-cache/src/services/change-streamer/backfill-state-tracker.d.ts +66 -0
  251. package/out/zero-cache/src/services/change-streamer/backfill-state-tracker.d.ts.map +1 -0
  252. package/out/zero-cache/src/services/change-streamer/backfill-state-tracker.js +154 -0
  253. package/out/zero-cache/src/services/change-streamer/backfill-state-tracker.js.map +1 -0
  254. package/out/zero-cache/src/services/change-streamer/backfill-state.d.ts +50 -0
  255. package/out/zero-cache/src/services/change-streamer/backfill-state.d.ts.map +1 -0
  256. package/out/zero-cache/src/services/change-streamer/backfill-state.js +268 -0
  257. package/out/zero-cache/src/services/change-streamer/backfill-state.js.map +1 -0
  258. package/out/zero-cache/src/services/change-streamer/backup-cleanup-monitor-factory.d.ts.map +1 -1
  259. package/out/zero-cache/src/services/change-streamer/backup-cleanup-monitor-factory.js +2 -0
  260. package/out/zero-cache/src/services/change-streamer/backup-cleanup-monitor-factory.js.map +1 -1
  261. package/out/zero-cache/src/services/change-streamer/backup-monitor.d.ts.map +1 -1
  262. package/out/zero-cache/src/services/change-streamer/backup-monitor.js +58 -7
  263. package/out/zero-cache/src/services/change-streamer/backup-monitor.js.map +1 -1
  264. package/out/zero-cache/src/services/change-streamer/broadcast.d.ts +8 -2
  265. package/out/zero-cache/src/services/change-streamer/broadcast.d.ts.map +1 -1
  266. package/out/zero-cache/src/services/change-streamer/broadcast.js +24 -4
  267. package/out/zero-cache/src/services/change-streamer/broadcast.js.map +1 -1
  268. package/out/zero-cache/src/services/change-streamer/change-log-codec.d.ts +19 -4
  269. package/out/zero-cache/src/services/change-streamer/change-log-codec.d.ts.map +1 -1
  270. package/out/zero-cache/src/services/change-streamer/change-log-codec.js +28 -8
  271. package/out/zero-cache/src/services/change-streamer/change-log-codec.js.map +1 -1
  272. package/out/zero-cache/src/services/change-streamer/change-streamer-http.d.ts +48 -6
  273. package/out/zero-cache/src/services/change-streamer/change-streamer-http.d.ts.map +1 -1
  274. package/out/zero-cache/src/services/change-streamer/change-streamer-http.js +130 -34
  275. package/out/zero-cache/src/services/change-streamer/change-streamer-http.js.map +1 -1
  276. package/out/zero-cache/src/services/change-streamer/change-streamer-service.d.ts +11 -0
  277. package/out/zero-cache/src/services/change-streamer/change-streamer-service.d.ts.map +1 -1
  278. package/out/zero-cache/src/services/change-streamer/change-streamer-service.js +118 -68
  279. package/out/zero-cache/src/services/change-streamer/change-streamer-service.js.map +1 -1
  280. package/out/zero-cache/src/services/change-streamer/change-streamer.d.ts +37 -15
  281. package/out/zero-cache/src/services/change-streamer/change-streamer.d.ts.map +1 -1
  282. package/out/zero-cache/src/services/change-streamer/change-streamer.js.map +1 -1
  283. package/out/zero-cache/src/services/change-streamer/forwarder.d.ts +3 -3
  284. package/out/zero-cache/src/services/change-streamer/forwarder.d.ts.map +1 -1
  285. package/out/zero-cache/src/services/change-streamer/forwarder.js +36 -5
  286. package/out/zero-cache/src/services/change-streamer/forwarder.js.map +1 -1
  287. package/out/zero-cache/src/services/change-streamer/litestream-sync-requester.d.ts +51 -0
  288. package/out/zero-cache/src/services/change-streamer/litestream-sync-requester.d.ts.map +1 -0
  289. package/out/zero-cache/src/services/change-streamer/litestream-sync-requester.js +132 -0
  290. package/out/zero-cache/src/services/change-streamer/litestream-sync-requester.js.map +1 -0
  291. package/out/zero-cache/src/services/change-streamer/schema/tables.d.ts +1 -1
  292. package/out/zero-cache/src/services/change-streamer/schema/tables.d.ts.map +1 -1
  293. package/out/zero-cache/src/services/change-streamer/schema/tables.js +19 -8
  294. package/out/zero-cache/src/services/change-streamer/schema/tables.js.map +1 -1
  295. package/out/zero-cache/src/services/change-streamer/snapshot-message.d.ts +92 -0
  296. package/out/zero-cache/src/services/change-streamer/snapshot-message.d.ts.map +1 -0
  297. package/out/zero-cache/src/services/change-streamer/snapshot-message.js +42 -0
  298. package/out/zero-cache/src/services/change-streamer/snapshot-message.js.map +1 -0
  299. package/out/zero-cache/src/services/change-streamer/snapshot-reservations.d.ts +1 -1
  300. package/out/zero-cache/src/services/change-streamer/snapshot-reservations.d.ts.map +1 -1
  301. package/out/zero-cache/src/services/change-streamer/snapshot-reservations.js +16 -4
  302. package/out/zero-cache/src/services/change-streamer/snapshot-reservations.js.map +1 -1
  303. package/out/zero-cache/src/services/change-streamer/snapshot.d.ts +7 -69
  304. package/out/zero-cache/src/services/change-streamer/snapshot.d.ts.map +1 -1
  305. package/out/zero-cache/src/services/change-streamer/snapshot.js +21 -53
  306. package/out/zero-cache/src/services/change-streamer/snapshot.js.map +1 -1
  307. package/out/zero-cache/src/services/change-streamer/sqlite-change-log-writer.d.ts +6 -1
  308. package/out/zero-cache/src/services/change-streamer/sqlite-change-log-writer.d.ts.map +1 -1
  309. package/out/zero-cache/src/services/change-streamer/sqlite-change-log-writer.js +27 -9
  310. package/out/zero-cache/src/services/change-streamer/sqlite-change-log-writer.js.map +1 -1
  311. package/out/zero-cache/src/services/change-streamer/storer.d.ts +2 -2
  312. package/out/zero-cache/src/services/change-streamer/storer.d.ts.map +1 -1
  313. package/out/zero-cache/src/services/change-streamer/storer.js +9 -6
  314. package/out/zero-cache/src/services/change-streamer/storer.js.map +1 -1
  315. package/out/zero-cache/src/services/change-streamer/subscribe.d.ts +446 -0
  316. package/out/zero-cache/src/services/change-streamer/subscribe.d.ts.map +1 -0
  317. package/out/zero-cache/src/services/change-streamer/subscribe.js +76 -0
  318. package/out/zero-cache/src/services/change-streamer/subscribe.js.map +1 -0
  319. package/out/zero-cache/src/services/change-streamer/subscriber.d.ts +33 -1
  320. package/out/zero-cache/src/services/change-streamer/subscriber.d.ts.map +1 -1
  321. package/out/zero-cache/src/services/change-streamer/subscriber.js +76 -0
  322. package/out/zero-cache/src/services/change-streamer/subscriber.js.map +1 -1
  323. package/out/zero-cache/src/services/change-streamer/upstream-acker.d.ts +17 -1
  324. package/out/zero-cache/src/services/change-streamer/upstream-acker.d.ts.map +1 -1
  325. package/out/zero-cache/src/services/change-streamer/upstream-acker.js +19 -3
  326. package/out/zero-cache/src/services/change-streamer/upstream-acker.js.map +1 -1
  327. package/out/zero-cache/src/services/change-streamer/vfs-watermark-poller.d.ts +5 -0
  328. package/out/zero-cache/src/services/change-streamer/vfs-watermark-poller.d.ts.map +1 -1
  329. package/out/zero-cache/src/services/change-streamer/vfs-watermark-poller.js +35 -5
  330. package/out/zero-cache/src/services/change-streamer/vfs-watermark-poller.js.map +1 -1
  331. package/out/zero-cache/src/services/life-cycle.d.ts.map +1 -1
  332. package/out/zero-cache/src/services/life-cycle.js +3 -1
  333. package/out/zero-cache/src/services/life-cycle.js.map +1 -1
  334. package/out/zero-cache/src/services/litestream/commands.d.ts +15 -3
  335. package/out/zero-cache/src/services/litestream/commands.d.ts.map +1 -1
  336. package/out/zero-cache/src/services/litestream/commands.js +24 -7
  337. package/out/zero-cache/src/services/litestream/commands.js.map +1 -1
  338. package/out/zero-cache/src/services/litestream/config-v5.yml +11 -4
  339. package/out/zero-cache/src/services/litestream/litestream-checkpointer.js +51 -24
  340. package/out/zero-cache/src/services/litestream/litestream-checkpointer.js.map +1 -1
  341. package/out/zero-cache/src/services/litestream/litestream-controller.d.ts +10 -2
  342. package/out/zero-cache/src/services/litestream/litestream-controller.d.ts.map +1 -1
  343. package/out/zero-cache/src/services/litestream/litestream-controller.js +3 -2
  344. package/out/zero-cache/src/services/litestream/litestream-controller.js.map +1 -1
  345. package/out/zero-cache/src/services/litestream/restore-progress.d.ts +24 -0
  346. package/out/zero-cache/src/services/litestream/restore-progress.d.ts.map +1 -0
  347. package/out/zero-cache/src/services/litestream/restore-progress.js +91 -0
  348. package/out/zero-cache/src/services/litestream/restore-progress.js.map +1 -0
  349. package/out/zero-cache/src/services/mutagen/mutagen.d.ts +5 -0
  350. package/out/zero-cache/src/services/mutagen/mutagen.d.ts.map +1 -1
  351. package/out/zero-cache/src/services/mutagen/mutagen.js +7 -1
  352. package/out/zero-cache/src/services/mutagen/mutagen.js.map +1 -1
  353. package/out/zero-cache/src/services/mutagen/pusher.d.ts.map +1 -1
  354. package/out/zero-cache/src/services/mutagen/pusher.js +5 -6
  355. package/out/zero-cache/src/services/mutagen/pusher.js.map +1 -1
  356. package/out/zero-cache/src/services/plannerz.d.ts +163 -0
  357. package/out/zero-cache/src/services/plannerz.d.ts.map +1 -0
  358. package/out/zero-cache/src/services/plannerz.js +267 -0
  359. package/out/zero-cache/src/services/plannerz.js.map +1 -0
  360. package/out/zero-cache/src/services/profz.d.ts +30 -0
  361. package/out/zero-cache/src/services/profz.d.ts.map +1 -0
  362. package/out/zero-cache/src/services/profz.js +145 -0
  363. package/out/zero-cache/src/services/profz.js.map +1 -0
  364. package/out/zero-cache/src/services/replicator/change-log-cookies.js +1 -1
  365. package/out/zero-cache/src/services/replicator/change-log-cookies.js.map +1 -1
  366. package/out/zero-cache/src/services/replicator/change-log-stream-writer.d.ts +5 -4
  367. package/out/zero-cache/src/services/replicator/change-log-stream-writer.d.ts.map +1 -1
  368. package/out/zero-cache/src/services/replicator/change-log-stream-writer.js +20 -22
  369. package/out/zero-cache/src/services/replicator/change-log-stream-writer.js.map +1 -1
  370. package/out/zero-cache/src/services/replicator/change-processor.d.ts.map +1 -1
  371. package/out/zero-cache/src/services/replicator/change-processor.js +49 -5
  372. package/out/zero-cache/src/services/replicator/change-processor.js.map +1 -1
  373. package/out/zero-cache/src/services/replicator/incremental-sync.d.ts +3 -2
  374. package/out/zero-cache/src/services/replicator/incremental-sync.d.ts.map +1 -1
  375. package/out/zero-cache/src/services/replicator/incremental-sync.js +50 -20
  376. package/out/zero-cache/src/services/replicator/incremental-sync.js.map +1 -1
  377. package/out/zero-cache/src/services/replicator/replication-status.d.ts +35 -1
  378. package/out/zero-cache/src/services/replicator/replication-status.d.ts.map +1 -1
  379. package/out/zero-cache/src/services/replicator/replication-status.js +96 -6
  380. package/out/zero-cache/src/services/replicator/replication-status.js.map +1 -1
  381. package/out/zero-cache/src/services/replicator/replicator.d.ts +2 -1
  382. package/out/zero-cache/src/services/replicator/replicator.d.ts.map +1 -1
  383. package/out/zero-cache/src/services/replicator/replicator.js +2 -2
  384. package/out/zero-cache/src/services/replicator/replicator.js.map +1 -1
  385. package/out/zero-cache/src/services/replicator/schema/backfilling.d.ts +23 -2
  386. package/out/zero-cache/src/services/replicator/schema/backfilling.d.ts.map +1 -1
  387. package/out/zero-cache/src/services/replicator/schema/backfilling.js +54 -2
  388. package/out/zero-cache/src/services/replicator/schema/backfilling.js.map +1 -1
  389. package/out/zero-cache/src/services/replicator/sqlite-change-log-observability.d.ts +6 -6
  390. package/out/zero-cache/src/services/replicator/sqlite-change-log-observability.d.ts.map +1 -1
  391. package/out/zero-cache/src/services/replicator/sqlite-change-log-observability.js +19 -14
  392. package/out/zero-cache/src/services/replicator/sqlite-change-log-observability.js.map +1 -1
  393. package/out/zero-cache/src/services/replicator/write-worker-client.d.ts +11 -3
  394. package/out/zero-cache/src/services/replicator/write-worker-client.d.ts.map +1 -1
  395. package/out/zero-cache/src/services/replicator/write-worker-client.js.map +1 -1
  396. package/out/zero-cache/src/services/replicator/write-worker.js +5 -1
  397. package/out/zero-cache/src/services/replicator/write-worker.js.map +1 -1
  398. package/out/zero-cache/src/services/run-ast.d.ts +12 -0
  399. package/out/zero-cache/src/services/run-ast.d.ts.map +1 -1
  400. package/out/zero-cache/src/services/run-ast.js +26 -14
  401. package/out/zero-cache/src/services/run-ast.js.map +1 -1
  402. package/out/zero-cache/src/services/runner.d.ts +2 -1
  403. package/out/zero-cache/src/services/runner.d.ts.map +1 -1
  404. package/out/zero-cache/src/services/runner.js +10 -2
  405. package/out/zero-cache/src/services/runner.js.map +1 -1
  406. package/out/zero-cache/src/services/statz.d.ts +4 -0
  407. package/out/zero-cache/src/services/statz.d.ts.map +1 -1
  408. package/out/zero-cache/src/services/statz.js +22 -5
  409. package/out/zero-cache/src/services/statz.js.map +1 -1
  410. package/out/zero-cache/src/services/view-syncer/client-handler.d.ts +19 -2
  411. package/out/zero-cache/src/services/view-syncer/client-handler.d.ts.map +1 -1
  412. package/out/zero-cache/src/services/view-syncer/client-handler.js +42 -30
  413. package/out/zero-cache/src/services/view-syncer/client-handler.js.map +1 -1
  414. package/out/zero-cache/src/services/view-syncer/cvr-store.d.ts +19 -1
  415. package/out/zero-cache/src/services/view-syncer/cvr-store.d.ts.map +1 -1
  416. package/out/zero-cache/src/services/view-syncer/cvr-store.js +34 -11
  417. package/out/zero-cache/src/services/view-syncer/cvr-store.js.map +1 -1
  418. package/out/zero-cache/src/services/view-syncer/cvr.d.ts +51 -2
  419. package/out/zero-cache/src/services/view-syncer/cvr.d.ts.map +1 -1
  420. package/out/zero-cache/src/services/view-syncer/cvr.js +142 -6
  421. package/out/zero-cache/src/services/view-syncer/cvr.js.map +1 -1
  422. package/out/zero-cache/src/services/view-syncer/deferred-writes-budget.d.ts +81 -0
  423. package/out/zero-cache/src/services/view-syncer/deferred-writes-budget.d.ts.map +1 -0
  424. package/out/zero-cache/src/services/view-syncer/deferred-writes-budget.js +128 -0
  425. package/out/zero-cache/src/services/view-syncer/deferred-writes-budget.js.map +1 -0
  426. package/out/zero-cache/src/services/view-syncer/drain-coordinator.d.ts +14 -1
  427. package/out/zero-cache/src/services/view-syncer/drain-coordinator.d.ts.map +1 -1
  428. package/out/zero-cache/src/services/view-syncer/drain-coordinator.js +30 -4
  429. package/out/zero-cache/src/services/view-syncer/drain-coordinator.js.map +1 -1
  430. package/out/zero-cache/src/services/view-syncer/hydration-budget.d.ts +33 -0
  431. package/out/zero-cache/src/services/view-syncer/hydration-budget.d.ts.map +1 -0
  432. package/out/zero-cache/src/services/view-syncer/hydration-budget.js +62 -0
  433. package/out/zero-cache/src/services/view-syncer/hydration-budget.js.map +1 -0
  434. package/out/zero-cache/src/services/view-syncer/hydration-circuit-breaker.d.ts +51 -0
  435. package/out/zero-cache/src/services/view-syncer/hydration-circuit-breaker.d.ts.map +1 -0
  436. package/out/zero-cache/src/services/view-syncer/hydration-circuit-breaker.js +78 -0
  437. package/out/zero-cache/src/services/view-syncer/hydration-circuit-breaker.js.map +1 -0
  438. package/out/zero-cache/src/services/view-syncer/inspect-handler.d.ts +1 -1
  439. package/out/zero-cache/src/services/view-syncer/inspect-handler.d.ts.map +1 -1
  440. package/out/zero-cache/src/services/view-syncer/inspect-handler.js +3 -3
  441. package/out/zero-cache/src/services/view-syncer/inspect-handler.js.map +1 -1
  442. package/out/zero-cache/src/services/view-syncer/pipeline-driver.d.ts +50 -2
  443. package/out/zero-cache/src/services/view-syncer/pipeline-driver.d.ts.map +1 -1
  444. package/out/zero-cache/src/services/view-syncer/pipeline-driver.js +466 -62
  445. package/out/zero-cache/src/services/view-syncer/pipeline-driver.js.map +1 -1
  446. package/out/zero-cache/src/services/view-syncer/plan-warnings.d.ts +7 -0
  447. package/out/zero-cache/src/services/view-syncer/plan-warnings.d.ts.map +1 -0
  448. package/out/zero-cache/src/services/view-syncer/plan-warnings.js +35 -0
  449. package/out/zero-cache/src/services/view-syncer/plan-warnings.js.map +1 -0
  450. package/out/zero-cache/src/services/view-syncer/query-covering.d.ts.map +1 -1
  451. package/out/zero-cache/src/services/view-syncer/query-covering.js +2 -6
  452. package/out/zero-cache/src/services/view-syncer/query-covering.js.map +1 -1
  453. package/out/zero-cache/src/services/view-syncer/query-shape.d.ts +25 -0
  454. package/out/zero-cache/src/services/view-syncer/query-shape.d.ts.map +1 -0
  455. package/out/zero-cache/src/services/view-syncer/query-shape.js +28 -0
  456. package/out/zero-cache/src/services/view-syncer/query-shape.js.map +1 -0
  457. package/out/zero-cache/src/services/view-syncer/query-stats.d.ts +77 -0
  458. package/out/zero-cache/src/services/view-syncer/query-stats.d.ts.map +1 -0
  459. package/out/zero-cache/src/services/view-syncer/query-stats.js +206 -0
  460. package/out/zero-cache/src/services/view-syncer/query-stats.js.map +1 -0
  461. package/out/zero-cache/src/services/view-syncer/snapshot-row-cache.d.ts +95 -0
  462. package/out/zero-cache/src/services/view-syncer/snapshot-row-cache.d.ts.map +1 -0
  463. package/out/zero-cache/src/services/view-syncer/snapshot-row-cache.js +155 -0
  464. package/out/zero-cache/src/services/view-syncer/snapshot-row-cache.js.map +1 -0
  465. package/out/zero-cache/src/services/view-syncer/snapshotter.d.ts +78 -4
  466. package/out/zero-cache/src/services/view-syncer/snapshotter.d.ts.map +1 -1
  467. package/out/zero-cache/src/services/view-syncer/snapshotter.js +158 -28
  468. package/out/zero-cache/src/services/view-syncer/snapshotter.js.map +1 -1
  469. package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts +11 -1
  470. package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts.map +1 -1
  471. package/out/zero-cache/src/services/view-syncer/view-syncer.js +587 -103
  472. package/out/zero-cache/src/services/view-syncer/view-syncer.js.map +1 -1
  473. package/out/zero-cache/src/types/processes.d.ts +39 -0
  474. package/out/zero-cache/src/types/processes.d.ts.map +1 -1
  475. package/out/zero-cache/src/types/processes.js +43 -4
  476. package/out/zero-cache/src/types/processes.js.map +1 -1
  477. package/out/zero-cache/src/types/profiler.d.ts +12 -0
  478. package/out/zero-cache/src/types/profiler.d.ts.map +1 -1
  479. package/out/zero-cache/src/types/profiler.js +46 -1
  480. package/out/zero-cache/src/types/profiler.js.map +1 -1
  481. package/out/zero-cache/src/types/row-key.d.ts.map +1 -1
  482. package/out/zero-cache/src/types/row-key.js +5 -5
  483. package/out/zero-cache/src/types/row-key.js.map +1 -1
  484. package/out/zero-cache/src/types/streams.d.ts +49 -7
  485. package/out/zero-cache/src/types/streams.d.ts.map +1 -1
  486. package/out/zero-cache/src/types/streams.js +190 -58
  487. package/out/zero-cache/src/types/streams.js.map +1 -1
  488. package/out/zero-cache/src/types/subscription.d.ts +15 -0
  489. package/out/zero-cache/src/types/subscription.d.ts.map +1 -1
  490. package/out/zero-cache/src/types/subscription.js +123 -31
  491. package/out/zero-cache/src/types/subscription.js.map +1 -1
  492. package/out/zero-cache/src/types/websocket-handoff.d.ts +1 -1
  493. package/out/zero-cache/src/types/websocket-handoff.d.ts.map +1 -1
  494. package/out/zero-cache/src/types/websocket-handoff.js +18 -9
  495. package/out/zero-cache/src/types/websocket-handoff.js.map +1 -1
  496. package/out/zero-cache/src/types/ws.d.ts.map +1 -1
  497. package/out/zero-cache/src/types/ws.js +1 -16
  498. package/out/zero-cache/src/types/ws.js.map +1 -1
  499. package/out/zero-cache/src/workers/connect-params.d.ts +1 -0
  500. package/out/zero-cache/src/workers/connect-params.d.ts.map +1 -1
  501. package/out/zero-cache/src/workers/connect-params.js.map +1 -1
  502. package/out/zero-cache/src/workers/syncer-ws-message-handler.d.ts.map +1 -1
  503. package/out/zero-cache/src/workers/syncer-ws-message-handler.js +21 -16
  504. package/out/zero-cache/src/workers/syncer-ws-message-handler.js.map +1 -1
  505. package/out/zero-cache/src/workers/syncer.d.ts.map +1 -1
  506. package/out/zero-cache/src/workers/syncer.js +55 -4
  507. package/out/zero-cache/src/workers/syncer.js.map +1 -1
  508. package/out/zero-client/src/client/active-clients-manager.d.ts.map +1 -1
  509. package/out/zero-client/src/client/active-clients-manager.js +4 -1
  510. package/out/zero-client/src/client/active-clients-manager.js.map +1 -1
  511. package/out/zero-client/src/client/connection-manager.d.ts +20 -0
  512. package/out/zero-client/src/client/connection-manager.d.ts.map +1 -1
  513. package/out/zero-client/src/client/connection-manager.js +77 -13
  514. package/out/zero-client/src/client/connection-manager.js.map +1 -1
  515. package/out/zero-client/src/client/connection-status-enum.d.ts +2 -0
  516. package/out/zero-client/src/client/connection-status-enum.d.ts.map +1 -1
  517. package/out/zero-client/src/client/connection-status-enum.js +3 -1
  518. package/out/zero-client/src/client/connection-status-enum.js.map +1 -1
  519. package/out/zero-client/src/client/connection.d.ts +6 -0
  520. package/out/zero-client/src/client/connection.d.ts.map +1 -1
  521. package/out/zero-client/src/client/connection.js +2 -1
  522. package/out/zero-client/src/client/connection.js.map +1 -1
  523. package/out/zero-client/src/client/context.d.ts +22 -12
  524. package/out/zero-client/src/client/context.d.ts.map +1 -1
  525. package/out/zero-client/src/client/context.js +92 -25
  526. package/out/zero-client/src/client/context.js.map +1 -1
  527. package/out/zero-client/src/client/custom.js +2 -2
  528. package/out/zero-client/src/client/custom.js.map +1 -1
  529. package/out/zero-client/src/client/error.js +1 -1
  530. package/out/zero-client/src/client/ivm-branch.d.ts.map +1 -1
  531. package/out/zero-client/src/client/ivm-branch.js +20 -3
  532. package/out/zero-client/src/client/ivm-branch.js.map +1 -1
  533. package/out/zero-client/src/client/mutator-proxy.d.ts.map +1 -1
  534. package/out/zero-client/src/client/mutator-proxy.js +5 -2
  535. package/out/zero-client/src/client/mutator-proxy.js.map +1 -1
  536. package/out/zero-client/src/client/options.d.ts +33 -0
  537. package/out/zero-client/src/client/options.d.ts.map +1 -1
  538. package/out/zero-client/src/client/options.js.map +1 -1
  539. package/out/zero-client/src/client/query-manager.d.ts.map +1 -1
  540. package/out/zero-client/src/client/query-manager.js +44 -11
  541. package/out/zero-client/src/client/query-manager.js.map +1 -1
  542. package/out/zero-client/src/client/version.js +1 -1
  543. package/out/zero-client/src/client/zero-rep.d.ts +1 -0
  544. package/out/zero-client/src/client/zero-rep.d.ts.map +1 -1
  545. package/out/zero-client/src/client/zero-rep.js +8 -6
  546. package/out/zero-client/src/client/zero-rep.js.map +1 -1
  547. package/out/zero-client/src/client/zero.d.ts +18 -3
  548. package/out/zero-client/src/client/zero.d.ts.map +1 -1
  549. package/out/zero-client/src/client/zero.js +84 -47
  550. package/out/zero-client/src/client/zero.js.map +1 -1
  551. package/out/zero-client/src/mod.d.ts +1 -0
  552. package/out/zero-client/src/mod.d.ts.map +1 -1
  553. package/out/zero-client/src/mod.js +1 -0
  554. package/out/zero-client/src/types/query-result.d.ts +2 -0
  555. package/out/zero-client/src/types/query-result.d.ts.map +1 -1
  556. package/out/zero-events/src/status.d.ts +58 -0
  557. package/out/zero-events/src/status.d.ts.map +1 -1
  558. package/out/zero-protocol/src/ast.d.ts.map +1 -1
  559. package/out/zero-protocol/src/ast.js +13 -14
  560. package/out/zero-protocol/src/ast.js.map +1 -1
  561. package/out/zero-protocol/src/down.d.ts +29 -29
  562. package/out/zero-protocol/src/query-hash.d.ts.map +1 -1
  563. package/out/zero-protocol/src/query-hash.js +2 -5
  564. package/out/zero-protocol/src/query-hash.js.map +1 -1
  565. package/out/zero-react/src/use-query.d.ts +5 -4
  566. package/out/zero-react/src/use-query.d.ts.map +1 -1
  567. package/out/zero-react/src/use-query.js +62 -4
  568. package/out/zero-react/src/use-query.js.map +1 -1
  569. package/out/zero-react/src/zero.js +1 -0
  570. package/out/zero-server/src/adapters/drizzle.d.ts +2 -1
  571. package/out/zero-server/src/adapters/drizzle.d.ts.map +1 -1
  572. package/out/zero-server/src/adapters/drizzle.js +12 -7
  573. package/out/zero-server/src/adapters/drizzle.js.map +1 -1
  574. package/out/zero-server/src/adapters/kysely.d.ts +2 -1
  575. package/out/zero-server/src/adapters/kysely.d.ts.map +1 -1
  576. package/out/zero-server/src/adapters/kysely.js +8 -2
  577. package/out/zero-server/src/adapters/kysely.js.map +1 -1
  578. package/out/zero-server/src/adapters/pg.d.ts +1 -0
  579. package/out/zero-server/src/adapters/pg.d.ts.map +1 -1
  580. package/out/zero-server/src/adapters/pg.js +8 -2
  581. package/out/zero-server/src/adapters/pg.js.map +1 -1
  582. package/out/zero-server/src/adapters/postgresjs.d.ts +1 -0
  583. package/out/zero-server/src/adapters/postgresjs.d.ts.map +1 -1
  584. package/out/zero-server/src/adapters/postgresjs.js +7 -1
  585. package/out/zero-server/src/adapters/postgresjs.js.map +1 -1
  586. package/out/zero-server/src/adapters/prisma.d.ts +3 -2
  587. package/out/zero-server/src/adapters/prisma.d.ts.map +1 -1
  588. package/out/zero-server/src/adapters/prisma.js +8 -2
  589. package/out/zero-server/src/adapters/prisma.js.map +1 -1
  590. package/out/zero-server/src/custom.d.ts +5 -1
  591. package/out/zero-server/src/custom.d.ts.map +1 -1
  592. package/out/zero-server/src/custom.js +6 -3
  593. package/out/zero-server/src/custom.js.map +1 -1
  594. package/out/zero-server/src/logging.d.ts +2 -2
  595. package/out/zero-server/src/logging.d.ts.map +1 -1
  596. package/out/zero-server/src/logging.js +2 -2
  597. package/out/zero-server/src/logging.js.map +1 -1
  598. package/out/zero-server/src/mod.d.ts +1 -1
  599. package/out/zero-server/src/mod.d.ts.map +1 -1
  600. package/out/zero-server/src/pg-query-executor.d.ts +2 -2
  601. package/out/zero-server/src/pg-query-executor.d.ts.map +1 -1
  602. package/out/zero-server/src/pg-query-executor.js +2 -2
  603. package/out/zero-server/src/pg-query-executor.js.map +1 -1
  604. package/out/zero-server/src/process-mutations.d.ts +12 -3
  605. package/out/zero-server/src/process-mutations.d.ts.map +1 -1
  606. package/out/zero-server/src/process-mutations.js +13 -8
  607. package/out/zero-server/src/process-mutations.js.map +1 -1
  608. package/out/zero-server/src/push-processor.d.ts +8 -2
  609. package/out/zero-server/src/push-processor.d.ts.map +1 -1
  610. package/out/zero-server/src/push-processor.js +12 -4
  611. package/out/zero-server/src/push-processor.js.map +1 -1
  612. package/out/zero-server/src/schema.d.ts +2 -2
  613. package/out/zero-server/src/schema.d.ts.map +1 -1
  614. package/out/zero-server/src/schema.js +2 -2
  615. package/out/zero-server/src/schema.js.map +1 -1
  616. package/out/zero-server/src/zql-database.d.ts +21 -1
  617. package/out/zero-server/src/zql-database.d.ts.map +1 -1
  618. package/out/zero-server/src/zql-database.js +33 -2
  619. package/out/zero-server/src/zql-database.js.map +1 -1
  620. package/out/zero-solid/src/solid-view.d.ts +17 -0
  621. package/out/zero-solid/src/solid-view.d.ts.map +1 -1
  622. package/out/zero-solid/src/solid-view.js +39 -1
  623. package/out/zero-solid/src/solid-view.js.map +1 -1
  624. package/out/zero-solid/src/use-query.js +1 -2
  625. package/out/zero-solid/src/use-query.js.map +1 -1
  626. package/out/zero-solid/src/zero.js +1 -0
  627. package/out/zql/src/builder/builder.d.ts +25 -0
  628. package/out/zql/src/builder/builder.d.ts.map +1 -1
  629. package/out/zql/src/builder/builder.js +69 -19
  630. package/out/zql/src/builder/builder.js.map +1 -1
  631. package/out/zql/src/builder/correlated-predicate-pushdown.d.ts +43 -0
  632. package/out/zql/src/builder/correlated-predicate-pushdown.d.ts.map +1 -0
  633. package/out/zql/src/builder/correlated-predicate-pushdown.js +161 -0
  634. package/out/zql/src/builder/correlated-predicate-pushdown.js.map +1 -0
  635. package/out/zql/src/builder/debug-delegate.d.ts +6 -1
  636. package/out/zql/src/builder/debug-delegate.d.ts.map +1 -1
  637. package/out/zql/src/builder/debug-delegate.js +14 -2
  638. package/out/zql/src/builder/debug-delegate.js.map +1 -1
  639. package/out/zql/src/ivm/array-view.d.ts +29 -0
  640. package/out/zql/src/ivm/array-view.d.ts.map +1 -1
  641. package/out/zql/src/ivm/array-view.js +58 -9
  642. package/out/zql/src/ivm/array-view.js.map +1 -1
  643. package/out/zql/src/ivm/cap.d.ts +2 -1
  644. package/out/zql/src/ivm/cap.d.ts.map +1 -1
  645. package/out/zql/src/ivm/cap.js +14 -4
  646. package/out/zql/src/ivm/cap.js.map +1 -1
  647. package/out/zql/src/ivm/connection-index.d.ts +68 -0
  648. package/out/zql/src/ivm/connection-index.d.ts.map +1 -0
  649. package/out/zql/src/ivm/connection-index.js +149 -0
  650. package/out/zql/src/ivm/connection-index.js.map +1 -0
  651. package/out/zql/src/ivm/data.d.ts.map +1 -1
  652. package/out/zql/src/ivm/data.js +8 -3
  653. package/out/zql/src/ivm/data.js.map +1 -1
  654. package/out/zql/src/ivm/deferred-input.d.ts.map +1 -1
  655. package/out/zql/src/ivm/deferred-input.js +3 -2
  656. package/out/zql/src/ivm/deferred-input.js.map +1 -1
  657. package/out/zql/src/ivm/exists.d.ts +3 -1
  658. package/out/zql/src/ivm/exists.d.ts.map +1 -1
  659. package/out/zql/src/ivm/exists.js +4 -1
  660. package/out/zql/src/ivm/exists.js.map +1 -1
  661. package/out/zql/src/ivm/fan-in.d.ts +6 -2
  662. package/out/zql/src/ivm/fan-in.d.ts.map +1 -1
  663. package/out/zql/src/ivm/fan-in.js +13 -5
  664. package/out/zql/src/ivm/fan-in.js.map +1 -1
  665. package/out/zql/src/ivm/fan-out.d.ts +5 -2
  666. package/out/zql/src/ivm/fan-out.d.ts.map +1 -1
  667. package/out/zql/src/ivm/fan-out.js +4 -0
  668. package/out/zql/src/ivm/fan-out.js.map +1 -1
  669. package/out/zql/src/ivm/filter-operators.d.ts +8 -6
  670. package/out/zql/src/ivm/filter-operators.d.ts.map +1 -1
  671. package/out/zql/src/ivm/filter-operators.js +19 -8
  672. package/out/zql/src/ivm/filter-operators.js.map +1 -1
  673. package/out/zql/src/ivm/filter.d.ts +5 -2
  674. package/out/zql/src/ivm/filter.d.ts.map +1 -1
  675. package/out/zql/src/ivm/filter.js +10 -4
  676. package/out/zql/src/ivm/filter.js.map +1 -1
  677. package/out/zql/src/ivm/flipped-join.d.ts +9 -4
  678. package/out/zql/src/ivm/flipped-join.d.ts.map +1 -1
  679. package/out/zql/src/ivm/flipped-join.js +97 -46
  680. package/out/zql/src/ivm/flipped-join.js.map +1 -1
  681. package/out/zql/src/ivm/join-index-tap.d.ts +33 -0
  682. package/out/zql/src/ivm/join-index-tap.d.ts.map +1 -0
  683. package/out/zql/src/ivm/join-index-tap.js +70 -0
  684. package/out/zql/src/ivm/join-index-tap.js.map +1 -0
  685. package/out/zql/src/ivm/join-index.d.ts +35 -0
  686. package/out/zql/src/ivm/join-index.d.ts.map +1 -0
  687. package/out/zql/src/ivm/join-index.js +141 -0
  688. package/out/zql/src/ivm/join-index.js.map +1 -0
  689. package/out/zql/src/ivm/join-utils.d.ts +6 -0
  690. package/out/zql/src/ivm/join-utils.d.ts.map +1 -1
  691. package/out/zql/src/ivm/join-utils.js +22 -1
  692. package/out/zql/src/ivm/join-utils.js.map +1 -1
  693. package/out/zql/src/ivm/join.d.ts +19 -1
  694. package/out/zql/src/ivm/join.d.ts.map +1 -1
  695. package/out/zql/src/ivm/join.js +107 -15
  696. package/out/zql/src/ivm/join.js.map +1 -1
  697. package/out/zql/src/ivm/maybe-split-and-push-edit-change.d.ts +1 -1
  698. package/out/zql/src/ivm/maybe-split-and-push-edit-change.d.ts.map +1 -1
  699. package/out/zql/src/ivm/maybe-split-and-push-edit-change.js +6 -4
  700. package/out/zql/src/ivm/maybe-split-and-push-edit-change.js.map +1 -1
  701. package/out/zql/src/ivm/memory-source.d.ts +28 -3
  702. package/out/zql/src/ivm/memory-source.d.ts.map +1 -1
  703. package/out/zql/src/ivm/memory-source.js +69 -33
  704. package/out/zql/src/ivm/memory-source.js.map +1 -1
  705. package/out/zql/src/ivm/memory-storage.d.ts +1 -0
  706. package/out/zql/src/ivm/memory-storage.d.ts.map +1 -1
  707. package/out/zql/src/ivm/memory-storage.js +1 -0
  708. package/out/zql/src/ivm/memory-storage.js.map +1 -1
  709. package/out/zql/src/ivm/operator.d.ts +45 -10
  710. package/out/zql/src/ivm/operator.d.ts.map +1 -1
  711. package/out/zql/src/ivm/operator.js +9 -4
  712. package/out/zql/src/ivm/operator.js.map +1 -1
  713. package/out/zql/src/ivm/push-accumulated.d.ts +6 -1
  714. package/out/zql/src/ivm/push-accumulated.d.ts.map +1 -1
  715. package/out/zql/src/ivm/push-accumulated.js +47 -2
  716. package/out/zql/src/ivm/push-accumulated.js.map +1 -1
  717. package/out/zql/src/ivm/skip.d.ts +2 -1
  718. package/out/zql/src/ivm/skip.d.ts.map +1 -1
  719. package/out/zql/src/ivm/skip.js +3 -0
  720. package/out/zql/src/ivm/skip.js.map +1 -1
  721. package/out/zql/src/ivm/take-gate.d.ts +57 -0
  722. package/out/zql/src/ivm/take-gate.d.ts.map +1 -0
  723. package/out/zql/src/ivm/take-gate.js +106 -0
  724. package/out/zql/src/ivm/take-gate.js.map +1 -0
  725. package/out/zql/src/ivm/take.d.ts +8 -2
  726. package/out/zql/src/ivm/take.d.ts.map +1 -1
  727. package/out/zql/src/ivm/take.js +139 -103
  728. package/out/zql/src/ivm/take.js.map +1 -1
  729. package/out/zql/src/ivm/union-fan-in.d.ts +3 -0
  730. package/out/zql/src/ivm/union-fan-in.d.ts.map +1 -1
  731. package/out/zql/src/ivm/union-fan-in.js +63 -10
  732. package/out/zql/src/ivm/union-fan-in.js.map +1 -1
  733. package/out/zql/src/ivm/union-fan-out.d.ts +2 -1
  734. package/out/zql/src/ivm/union-fan-out.d.ts.map +1 -1
  735. package/out/zql/src/ivm/union-fan-out.js +5 -0
  736. package/out/zql/src/ivm/union-fan-out.js.map +1 -1
  737. package/out/zql/src/ivm/view-apply-change.d.ts.map +1 -1
  738. package/out/zql/src/ivm/view-apply-change.js +9 -4
  739. package/out/zql/src/ivm/view-apply-change.js.map +1 -1
  740. package/out/zql/src/ivm/view.d.ts +15 -0
  741. package/out/zql/src/ivm/view.d.ts.map +1 -1
  742. package/out/zql/src/mutate/custom.d.ts +24 -1
  743. package/out/zql/src/mutate/custom.d.ts.map +1 -1
  744. package/out/zql/src/mutate/custom.js.map +1 -1
  745. package/out/zql/src/mutate/mutator-registry.d.ts.map +1 -1
  746. package/out/zql/src/mutate/mutator-registry.js +2 -2
  747. package/out/zql/src/mutate/mutator-registry.js.map +1 -1
  748. package/out/zql/src/planner/planner-builder.d.ts +23 -3
  749. package/out/zql/src/planner/planner-builder.d.ts.map +1 -1
  750. package/out/zql/src/planner/planner-builder.js +34 -17
  751. package/out/zql/src/planner/planner-builder.js.map +1 -1
  752. package/out/zql/src/planner/planner-connection.d.ts +58 -2
  753. package/out/zql/src/planner/planner-connection.d.ts.map +1 -1
  754. package/out/zql/src/planner/planner-connection.js +103 -11
  755. package/out/zql/src/planner/planner-connection.js.map +1 -1
  756. package/out/zql/src/planner/planner-debug.d.ts.map +1 -1
  757. package/out/zql/src/planner/planner-debug.js +3 -8
  758. package/out/zql/src/planner/planner-debug.js.map +1 -1
  759. package/out/zql/src/planner/planner-graph.d.ts +10 -0
  760. package/out/zql/src/planner/planner-graph.d.ts.map +1 -1
  761. package/out/zql/src/planner/planner-graph.js +14 -0
  762. package/out/zql/src/planner/planner-graph.js.map +1 -1
  763. package/out/zql/src/planner/planner-source.d.ts +2 -2
  764. package/out/zql/src/planner/planner-source.d.ts.map +1 -1
  765. package/out/zql/src/planner/planner-source.js +2 -2
  766. package/out/zql/src/planner/planner-source.js.map +1 -1
  767. package/out/zql/src/planner/planner-warnings.d.ts +83 -0
  768. package/out/zql/src/planner/planner-warnings.d.ts.map +1 -0
  769. package/out/zql/src/planner/planner-warnings.js +78 -0
  770. package/out/zql/src/planner/planner-warnings.js.map +1 -0
  771. package/out/zql/src/query/measure-push-operator.d.ts +2 -1
  772. package/out/zql/src/query/measure-push-operator.d.ts.map +1 -1
  773. package/out/zql/src/query/measure-push-operator.js +33 -4
  774. package/out/zql/src/query/measure-push-operator.js.map +1 -1
  775. package/out/zql/src/query/query-delegate-base.d.ts +4 -2
  776. package/out/zql/src/query/query-delegate-base.d.ts.map +1 -1
  777. package/out/zql/src/query/query-delegate-base.js +66 -33
  778. package/out/zql/src/query/query-delegate-base.js.map +1 -1
  779. package/out/zql/src/query/query-delegate.d.ts +33 -6
  780. package/out/zql/src/query/query-delegate.d.ts.map +1 -1
  781. package/out/zql/src/query/query-impl.d.ts +1 -0
  782. package/out/zql/src/query/query-impl.d.ts.map +1 -1
  783. package/out/zql/src/query/query-impl.js +6 -23
  784. package/out/zql/src/query/query-impl.js.map +1 -1
  785. package/out/zql/src/query/query-transitions.d.ts.map +1 -1
  786. package/out/zql/src/query/query-transitions.js +2 -5
  787. package/out/zql/src/query/query-transitions.js.map +1 -1
  788. package/out/zql/src/query/query.d.ts +11 -2
  789. package/out/zql/src/query/query.d.ts.map +1 -1
  790. package/out/zql/src/query/runnable-query-impl.d.ts +1 -0
  791. package/out/zql/src/query/runnable-query-impl.d.ts.map +1 -1
  792. package/out/zql/src/query/runnable-query-impl.js +2 -10
  793. package/out/zql/src/query/runnable-query-impl.js.map +1 -1
  794. package/out/zql/src/query/typed-view.d.ts +1 -1
  795. package/out/zql/src/query/typed-view.d.ts.map +1 -1
  796. package/out/zqlite/src/database-storage.d.ts.map +1 -1
  797. package/out/zqlite/src/database-storage.js +9 -1
  798. package/out/zqlite/src/database-storage.js.map +1 -1
  799. package/out/zqlite/src/db.d.ts +9 -1
  800. package/out/zqlite/src/db.d.ts.map +1 -1
  801. package/out/zqlite/src/db.js +31 -27
  802. package/out/zqlite/src/db.js.map +1 -1
  803. package/out/zqlite/src/pending-delta.d.ts +110 -0
  804. package/out/zqlite/src/pending-delta.d.ts.map +1 -0
  805. package/out/zqlite/src/pending-delta.js +278 -0
  806. package/out/zqlite/src/pending-delta.js.map +1 -0
  807. package/out/zqlite/src/query-builder.d.ts +17 -1
  808. package/out/zqlite/src/query-builder.d.ts.map +1 -1
  809. package/out/zqlite/src/query-builder.js +111 -20
  810. package/out/zqlite/src/query-builder.js.map +1 -1
  811. package/out/zqlite/src/query-delegate.d.ts.map +1 -1
  812. package/out/zqlite/src/query-delegate.js +10 -7
  813. package/out/zqlite/src/query-delegate.js.map +1 -1
  814. package/out/zqlite/src/sqlite-cost-model.d.ts.map +1 -1
  815. package/out/zqlite/src/sqlite-cost-model.js +52 -1
  816. package/out/zqlite/src/sqlite-cost-model.js.map +1 -1
  817. package/out/zqlite/src/sqlite-stat-fanout.d.ts.map +1 -1
  818. package/out/zqlite/src/sqlite-stat-fanout.js +5 -31
  819. package/out/zqlite/src/sqlite-stat-fanout.js.map +1 -1
  820. package/out/zqlite/src/sqlite-stat4-sample.d.ts +37 -0
  821. package/out/zqlite/src/sqlite-stat4-sample.d.ts.map +1 -0
  822. package/out/zqlite/src/sqlite-stat4-sample.js +61 -0
  823. package/out/zqlite/src/sqlite-stat4-sample.js.map +1 -0
  824. package/out/zqlite/src/table-source.d.ts +82 -2
  825. package/out/zqlite/src/table-source.d.ts.map +1 -1
  826. package/out/zqlite/src/table-source.js +261 -38
  827. package/out/zqlite/src/table-source.js.map +1 -1
  828. package/package.json +3 -4
  829. package/out/replicache/src/kv/idb-store-with-mem-fallback.d.ts +0 -25
  830. package/out/replicache/src/kv/idb-store-with-mem-fallback.d.ts.map +0 -1
  831. package/out/replicache/src/kv/idb-store-with-mem-fallback.js +0 -83
  832. package/out/replicache/src/kv/idb-store-with-mem-fallback.js.map +0 -1
@@ -0,0 +1,141 @@
1
+ import { must } from "../../../shared/src/must.js";
2
+ import { canonicalKey } from "./join-utils.js";
3
+ //#region ../zql/src/ivm/join-index.ts
4
+ var UNPARTITIONED = [void 0];
5
+ /**
6
+ * An in-memory index from a join key to the parent rows that have it. Join
7
+ * and FlippedJoin look up a child change's join key here to skip the parent
8
+ * fetch when no indexed parent can see the change.
9
+ *
10
+ * Parents are tracked by primary key so that adding or removing a row twice
11
+ * is harmless. Lookups only report whether any parent has the key and, when
12
+ * the index is partitioned, in which partitions.
13
+ */
14
+ var JoinIndex = class {
15
+ #parentKey;
16
+ #primaryKey;
17
+ /** The join key is the primary key, so one string serves as both. */
18
+ #joinKeyIsPK;
19
+ #partitionKey;
20
+ #unpartitioned = /* @__PURE__ */ new Map();
21
+ #partitioned = /* @__PURE__ */ new Map();
22
+ #size = 0;
23
+ constructor(parentKey, primaryKey, partitionKey) {
24
+ this.#parentKey = parentKey;
25
+ this.#primaryKey = primaryKey;
26
+ this.#joinKeyIsPK = parentKey.length === primaryKey.length && parentKey.every((k, i) => k === primaryKey[i]);
27
+ this.#partitionKey = partitionKey;
28
+ }
29
+ /** The number of parent rows in the index. */
30
+ get size() {
31
+ return this.#size;
32
+ }
33
+ add(row) {
34
+ const joinKey = joinKeyOf(row, this.#parentKey);
35
+ if (joinKey === void 0) return;
36
+ const pk = this.#pkOf(row, joinKey);
37
+ const partitionKey = this.#partitionKey;
38
+ if (partitionKey === void 0) {
39
+ let pks = this.#unpartitioned.get(joinKey);
40
+ if (pks === void 0) {
41
+ pks = /* @__PURE__ */ new Set();
42
+ this.#unpartitioned.set(joinKey, pks);
43
+ }
44
+ if (!pks.has(pk)) {
45
+ pks.add(pk);
46
+ this.#size++;
47
+ }
48
+ return;
49
+ }
50
+ const partKey = canonicalKey(row, partitionKey);
51
+ let partitions = this.#partitioned.get(joinKey);
52
+ if (partitions === void 0) {
53
+ partitions = /* @__PURE__ */ new Map();
54
+ this.#partitioned.set(joinKey, partitions);
55
+ }
56
+ let partition = partitions.get(partKey);
57
+ if (partition === void 0) {
58
+ const constraint = {};
59
+ for (const key of partitionKey) constraint[key] = row[key];
60
+ partition = {
61
+ constraint,
62
+ pks: /* @__PURE__ */ new Set()
63
+ };
64
+ partitions.set(partKey, partition);
65
+ }
66
+ if (!partition.pks.has(pk)) {
67
+ partition.pks.add(pk);
68
+ this.#size++;
69
+ }
70
+ }
71
+ remove(row) {
72
+ const joinKey = joinKeyOf(row, this.#parentKey);
73
+ if (joinKey === void 0) return;
74
+ const pk = this.#pkOf(row, joinKey);
75
+ const partitionKey = this.#partitionKey;
76
+ if (partitionKey === void 0) {
77
+ const pks = this.#unpartitioned.get(joinKey);
78
+ if (pks === void 0) return;
79
+ if (pks.delete(pk)) {
80
+ this.#size--;
81
+ if (pks.size === 0) this.#unpartitioned.delete(joinKey);
82
+ }
83
+ return;
84
+ }
85
+ const partitions = this.#partitioned.get(joinKey);
86
+ if (partitions === void 0) return;
87
+ const partKey = canonicalKey(row, partitionKey);
88
+ const partition = partitions.get(partKey);
89
+ if (partition === void 0) return;
90
+ if (partition.pks.delete(pk)) {
91
+ this.#size--;
92
+ if (partition.pks.size === 0) {
93
+ partitions.delete(partKey);
94
+ if (partitions.size === 0) this.#partitioned.delete(joinKey);
95
+ }
96
+ }
97
+ }
98
+ /**
99
+ * The partitions of the indexed parents whose join key matches `childRow`
100
+ * over `childKey`, or `undefined` if there are none.
101
+ */
102
+ lookup(childRow, childKey) {
103
+ const joinKey = joinKeyOf(childRow, childKey);
104
+ if (joinKey === void 0) return;
105
+ if (this.#partitionKey === void 0) return this.#unpartitioned.has(joinKey) ? UNPARTITIONED : void 0;
106
+ const partitions = this.#partitioned.get(joinKey);
107
+ if (partitions === void 0) return;
108
+ return Array.from(partitions.values(), (p) => p.constraint);
109
+ }
110
+ /**
111
+ * The index as the operator storage entries it replaced, keyed
112
+ * `j\0<joinKey>\0[<partitionKey>\0]<primaryKey>`. For tests.
113
+ */
114
+ entriesForTest() {
115
+ const entries = {};
116
+ for (const [joinKey, pks] of this.#unpartitioned) for (const pk of pks) entries[`j\x00${joinKey}\x00${pk}`] = 1;
117
+ for (const [joinKey, partitions] of this.#partitioned) {
118
+ const partitionKey = must(this.#partitionKey);
119
+ for (const { constraint, pks } of partitions.values()) {
120
+ const partKey = canonicalKey(constraint, partitionKey);
121
+ for (const pk of pks) entries[`j\x00${joinKey}\x00${partKey}\x00${pk}`] = 1;
122
+ }
123
+ }
124
+ return entries;
125
+ }
126
+ #pkOf(row, joinKey) {
127
+ return this.#joinKeyIsPK ? joinKey : canonicalKey(row, this.#primaryKey);
128
+ }
129
+ };
130
+ /**
131
+ * The canonical join key of `row`, or `undefined` if any part of it is null:
132
+ * a null key cannot match anything.
133
+ */
134
+ function joinKeyOf(row, key) {
135
+ for (const k of key) if (row[k] === null) return;
136
+ return canonicalKey(row, key);
137
+ }
138
+ //#endregion
139
+ export { JoinIndex };
140
+
141
+ //# sourceMappingURL=join-index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"join-index.js","names":["#parentKey","#primaryKey","#joinKeyIsPK","#partitionKey","#unpartitioned","#partitioned","#size","#pkOf"],"sources":["../../../../../zql/src/ivm/join-index.ts"],"sourcesContent":["import {must} from '../../../shared/src/must.ts';\nimport type {CompoundKey} from '../../../zero-protocol/src/ast.ts';\nimport type {Row, Value} from '../../../zero-protocol/src/data.ts';\nimport {canonicalKey} from './join-utils.ts';\n\n/**\n * The partitions of the indexed parents that share a join key, as fetch\n * constraints. An unpartitioned index reports a single `undefined`.\n */\nexport type ParentPartitions = readonly (Record<string, Value> | undefined)[];\n\nconst UNPARTITIONED: ParentPartitions = [undefined];\n\ntype Partition = {\n readonly constraint: Record<string, Value>;\n readonly pks: Set<string>;\n};\n\n/**\n * An in-memory index from a join key to the parent rows that have it. Join\n * and FlippedJoin look up a child change's join key here to skip the parent\n * fetch when no indexed parent can see the change.\n *\n * Parents are tracked by primary key so that adding or removing a row twice\n * is harmless. Lookups only report whether any parent has the key and, when\n * the index is partitioned, in which partitions.\n */\nexport class JoinIndex {\n readonly #parentKey: CompoundKey;\n readonly #primaryKey: CompoundKey;\n /** The join key is the primary key, so one string serves as both. */\n readonly #joinKeyIsPK: boolean;\n readonly #partitionKey: CompoundKey | undefined;\n readonly #unpartitioned = new Map<string, Set<string>>();\n readonly #partitioned = new Map<string, Map<string, Partition>>();\n #size = 0;\n\n constructor(\n parentKey: CompoundKey,\n primaryKey: CompoundKey,\n partitionKey?: CompoundKey | undefined,\n ) {\n this.#parentKey = parentKey;\n this.#primaryKey = primaryKey;\n this.#joinKeyIsPK =\n parentKey.length === primaryKey.length &&\n parentKey.every((k, i) => k === primaryKey[i]);\n this.#partitionKey = partitionKey;\n }\n\n /** The number of parent rows in the index. */\n get size(): number {\n return this.#size;\n }\n\n add(row: Row): void {\n const joinKey = joinKeyOf(row, this.#parentKey);\n if (joinKey === undefined) {\n return;\n }\n const pk = this.#pkOf(row, joinKey);\n const partitionKey = this.#partitionKey;\n if (partitionKey === undefined) {\n let pks = this.#unpartitioned.get(joinKey);\n if (pks === undefined) {\n pks = new Set();\n this.#unpartitioned.set(joinKey, pks);\n }\n if (!pks.has(pk)) {\n pks.add(pk);\n this.#size++;\n }\n return;\n }\n\n const partKey = canonicalKey(row, partitionKey);\n let partitions = this.#partitioned.get(joinKey);\n if (partitions === undefined) {\n partitions = new Map();\n this.#partitioned.set(joinKey, partitions);\n }\n let partition = partitions.get(partKey);\n if (partition === undefined) {\n const constraint: Record<string, Value> = {};\n for (const key of partitionKey) {\n constraint[key] = row[key];\n }\n partition = {constraint, pks: new Set()};\n partitions.set(partKey, partition);\n }\n if (!partition.pks.has(pk)) {\n partition.pks.add(pk);\n this.#size++;\n }\n }\n\n remove(row: Row): void {\n const joinKey = joinKeyOf(row, this.#parentKey);\n if (joinKey === undefined) {\n return;\n }\n const pk = this.#pkOf(row, joinKey);\n const partitionKey = this.#partitionKey;\n if (partitionKey === undefined) {\n const pks = this.#unpartitioned.get(joinKey);\n if (pks === undefined) {\n return;\n }\n if (pks.delete(pk)) {\n this.#size--;\n if (pks.size === 0) {\n this.#unpartitioned.delete(joinKey);\n }\n }\n return;\n }\n\n const partitions = this.#partitioned.get(joinKey);\n if (partitions === undefined) {\n return;\n }\n const partKey = canonicalKey(row, partitionKey);\n const partition = partitions.get(partKey);\n if (partition === undefined) {\n return;\n }\n if (partition.pks.delete(pk)) {\n this.#size--;\n if (partition.pks.size === 0) {\n partitions.delete(partKey);\n if (partitions.size === 0) {\n this.#partitioned.delete(joinKey);\n }\n }\n }\n }\n\n /**\n * The partitions of the indexed parents whose join key matches `childRow`\n * over `childKey`, or `undefined` if there are none.\n */\n lookup(childRow: Row, childKey: CompoundKey): ParentPartitions | undefined {\n const joinKey = joinKeyOf(childRow, childKey);\n if (joinKey === undefined) {\n return undefined;\n }\n if (this.#partitionKey === undefined) {\n return this.#unpartitioned.has(joinKey) ? UNPARTITIONED : undefined;\n }\n const partitions = this.#partitioned.get(joinKey);\n if (partitions === undefined) {\n return undefined;\n }\n return Array.from(partitions.values(), p => p.constraint);\n }\n\n /**\n * The index as the operator storage entries it replaced, keyed\n * `j\\0<joinKey>\\0[<partitionKey>\\0]<primaryKey>`. For tests.\n */\n entriesForTest(): Record<string, 1> {\n const entries: Record<string, 1> = {};\n for (const [joinKey, pks] of this.#unpartitioned) {\n for (const pk of pks) {\n entries[`j\\x00${joinKey}\\x00${pk}`] = 1;\n }\n }\n for (const [joinKey, partitions] of this.#partitioned) {\n const partitionKey = must(this.#partitionKey);\n for (const {constraint, pks} of partitions.values()) {\n const partKey = canonicalKey(constraint, partitionKey);\n for (const pk of pks) {\n entries[`j\\x00${joinKey}\\x00${partKey}\\x00${pk}`] = 1;\n }\n }\n }\n return entries;\n }\n\n #pkOf(row: Row, joinKey: string): string {\n return this.#joinKeyIsPK ? joinKey : canonicalKey(row, this.#primaryKey);\n }\n}\n\n/**\n * The canonical join key of `row`, or `undefined` if any part of it is null:\n * a null key cannot match anything.\n */\nfunction joinKeyOf(row: Row, key: CompoundKey): string | undefined {\n for (const k of key) {\n if (row[k] === null) {\n return undefined;\n }\n }\n return canonicalKey(row, key);\n}\n"],"mappings":";;;AAWA,IAAM,gBAAkC,CAAC,KAAA,CAAS;;;;;;;;;;AAgBlD,IAAa,YAAb,MAAuB;CACrB;CACA;;CAEA;CACA;CACA,iCAA0B,IAAI,IAAyB;CACvD,+BAAwB,IAAI,IAAoC;CAChE,QAAQ;CAER,YACE,WACA,YACA,cACA;EACA,KAAKA,aAAa;EAClB,KAAKC,cAAc;EACnB,KAAKC,eACH,UAAU,WAAW,WAAW,UAChC,UAAU,OAAO,GAAG,MAAM,MAAM,WAAW,EAAE;EAC/C,KAAKC,gBAAgB;CACvB;;CAGA,IAAI,OAAe;EACjB,OAAO,KAAKG;CACd;CAEA,IAAI,KAAgB;EAClB,MAAM,UAAU,UAAU,KAAK,KAAKN,UAAU;EAC9C,IAAI,YAAY,KAAA,GACd;EAEF,MAAM,KAAK,KAAKO,MAAM,KAAK,OAAO;EAClC,MAAM,eAAe,KAAKJ;EAC1B,IAAI,iBAAiB,KAAA,GAAW;GAC9B,IAAI,MAAM,KAAKC,eAAe,IAAI,OAAO;GACzC,IAAI,QAAQ,KAAA,GAAW;IACrB,sBAAM,IAAI,IAAI;IACd,KAAKA,eAAe,IAAI,SAAS,GAAG;GACtC;GACA,IAAI,CAAC,IAAI,IAAI,EAAE,GAAG;IAChB,IAAI,IAAI,EAAE;IACV,KAAKE;GACP;GACA;EACF;EAEA,MAAM,UAAU,aAAa,KAAK,YAAY;EAC9C,IAAI,aAAa,KAAKD,aAAa,IAAI,OAAO;EAC9C,IAAI,eAAe,KAAA,GAAW;GAC5B,6BAAa,IAAI,IAAI;GACrB,KAAK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F,kBAAkB,KAAA,GACzB,OAAO,KAAKC,eAAe,IAAI,OAAO,IAAI,gBAAgB,KAAA;EAE5D,MAAM,aAAa,KAAKC,aAAa,IAAI,OAAO;EAChD,IAAI,eAAe,KAAA,GACjB;EAEF,OAAO,MAAM,KAAK,WAAW,OAAO,IAAG,MAAK,EAAE,UAAU;CAC1D;;;;;CAMA,iBAAoC;EAClC,MAAM,UAA6B,CAAC;EACpC,KAAK,MAAM,CAAC,SAAS,QAAQ,KAAKD,gBAChC,KAAK,MAAM,MAAM,KACf,QAAQ,QAAQ,QAAQ,MAAM,QAAQ;EAG1C,KAAK,MAAM,CAAC,SAAS,eAAe,KAAKC,cAAc;GACrD,MAAM,eAAe,KAAK,KAAKF,aAAa;GAC5C,KAAK,MAAM,EAAC,YAAY,SAAQ,WAAW,OAAO,GAAG;IACnD,MAAM,UAAU,aAAa,YAAY,YAAY;IACrD,KAAK,MAAM,MAAM,KACf,QAAQ,QAAQ,QAAQ,MAAM,QAAQ,MAAM,QAAQ;GAExD;EACF;EACA,OAAO;CACT;CAEA,MAAM,KAAU,SAAyB;EACvC,OAAO,KAAKD,eAAe,UAAU,aAAa,KAAK,KAAKD,WAAW;CACzE;AACF;;;;;AAMA,SAAS,UAAU,KAAU,KAAsC;CACjE,KAAK,MAAM,KAAK,KACd,IAAI,IAAI,OAAO,MACb;CAGJ,OAAO,aAAa,KAAK,GAAG;AAC9B"}
@@ -16,4 +16,10 @@ export declare function isJoinMatch(parent: Row, parentKey: CompoundKey, child:
16
16
  * since null foreign keys cannot match any rows.
17
17
  */
18
18
  export declare function buildJoinConstraint(sourceRow: Row, sourceKey: CompoundKey, targetKey: CompoundKey): Record<string, Value> | undefined;
19
+ export declare function canonicalKeyForTest(record: Record<string, Value | undefined>, keys: CompoundKey): string;
20
+ /**
21
+ * Canonical string key over `keys` of `record`. Tags values by type
22
+ * so distinct types (e.g. 1 and "1") do not collide.
23
+ */
24
+ export declare function canonicalKey(record: Record<string, Value | undefined>, keys: CompoundKey): string;
19
25
  //# sourceMappingURL=join-utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"join-utils.d.ts","sourceRoot":"","sources":["../../../../../zql/src/ivm/join-utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,mCAAmC,CAAC;AACnE,OAAO,KAAK,EAAC,GAAG,EAAE,KAAK,EAAC,MAAM,oCAAoC,CAAC;AAGnE,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AACxC,OAAO,EAA6B,KAAK,IAAI,EAAC,MAAM,WAAW,CAAC;AAChE,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AAExC,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,EACpB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,YAAY,GACnB,MAAM,CAAC,IAAI,CAAC,CAEd;AAED,wBAAiB,mBAAmB,CAClC,MAAM,EAAE,MAAM,CAAC,IAAI,GAAG,OAAO,CAAC,EAC9B,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,YAAY,GACnB,MAAM,CAAC,IAAI,GAAG,OAAO,CAAC,CAqGxB;AAED,wBAAgB,mCAAmC,CACjD,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,EACpB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,YAAY,GACnB,MAAM,CAAC,IAAI,CAAC,CAEd;AAED,wBAAiB,4BAA4B,CAC3C,MAAM,EAAE,MAAM,CAAC,IAAI,GAAG,OAAO,CAAC,EAC9B,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,YAAY,GACnB,MAAM,CAAC,IAAI,GAAG,OAAO,CAAC,CAkExB;AAED,wBAAgB,uBAAuB,CACrC,CAAC,EAAE,GAAG,EACN,CAAC,EAAE,GAAG,EACN,GAAG,EAAE,WAAW,GACf,OAAO,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EAAE,MAAM,CAAC,IAAI,GAAG,OAAO,CAAC,EAC9B,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,YAAY,GACnB,MAAM,CAAC,IAAI,GAAG,OAAO,CAAC,CAkExB;AAED,wBAAgB,uBAAuB,CACrC,CAAC,EAAE,GAAG,EACN,CAAC,EAAE,GAAG,EACN,GAAG,EAAE,WAAW,GACf,OAAO,CAOT;AAED,wBAAgB,WAAW,CACzB,MAAM,EAAE,GAAG,EACX,SAAS,EAAE,WAAW,EACtB,KAAK,EAAE,GAAG,EACV,QAAQ,EAAE,WAAW,WAQtB;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,GAAG,EACd,SAAS,EAAE,WAAW,EACtB,SAAS,EAAE,WAAW,GACrB,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,SAAS,CAUnC;AAED,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,GAAG,SAAS,CAAC,EACzC,IAAI,EAAE,WAAW,GAChB,MAAM,CAER;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,GAAG,SAAS,CAAC,EACzC,IAAI,EAAE,WAAW,GAChB,MAAM,CAUR"}
@@ -124,7 +124,28 @@ function buildJoinConstraint(sourceRow, sourceKey, targetKey) {
124
124
  }
125
125
  return constraint;
126
126
  }
127
+ /**
128
+ * Canonical string key over `keys` of `record`. Tags values by type
129
+ * so distinct types (e.g. 1 and "1") do not collide.
130
+ */
131
+ function canonicalKey(record, keys) {
132
+ if (keys.length === 1) return canonicalValue(record[keys[0]]);
133
+ let s = "";
134
+ for (let i = 0; i < keys.length; i++) {
135
+ if (i > 0) s += "\0";
136
+ s += canonicalValue(record[keys[i]]);
137
+ }
138
+ return s;
139
+ }
140
+ function canonicalValue(v) {
141
+ if (v === null || v === void 0) return "n";
142
+ const t = typeof v;
143
+ if (t === "string") return "s" + v;
144
+ if (t === "number") return "d" + v;
145
+ if (t === "boolean") return v ? "t" : "f";
146
+ return "j" + JSON.stringify(v);
147
+ }
127
148
  //#endregion
128
- export { buildJoinConstraint, generateWithOverlay, generateWithOverlayNoYield, generateWithOverlayUnordered, isJoinMatch, rowEqualsForCompoundKey };
149
+ export { buildJoinConstraint, canonicalKey, generateWithOverlay, generateWithOverlayNoYield, generateWithOverlayUnordered, isJoinMatch, rowEqualsForCompoundKey };
129
150
 
130
151
  //# sourceMappingURL=join-utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"join-utils.js","names":[],"sources":["../../../../../zql/src/ivm/join-utils.ts"],"sourcesContent":["import {assert} from '../../../shared/src/asserts.ts';\nimport type {CompoundKey} from '../../../zero-protocol/src/ast.ts';\nimport type {Row, Value} from '../../../zero-protocol/src/data.ts';\nimport {ChangeIndex} from './change-index.ts';\nimport {ChangeType} from './change-type.ts';\nimport type {Change} from './change.ts';\nimport {compareValues, valuesEqual, type Node} from './data.ts';\nimport type {SourceSchema} from './schema.ts';\nimport type {Stream} from './stream.ts';\n\nexport function generateWithOverlayNoYield(\n stream: Stream<Node>,\n overlay: Change,\n schema: SourceSchema,\n): Stream<Node> {\n return generateWithOverlay(stream, overlay, schema) as Stream<Node>;\n}\n\nexport function* generateWithOverlay(\n stream: Stream<Node | 'yield'>,\n overlay: Change,\n schema: SourceSchema,\n): Stream<Node | 'yield'> {\n let applied = false;\n let editOldApplied = false;\n let editNewApplied = false;\n for (const node of stream) {\n if (node === 'yield') {\n yield node;\n continue;\n }\n let yieldNode = true;\n if (!applied) {\n switch (overlay[ChangeIndex.TYPE]) {\n case ChangeType.ADD: {\n if (\n schema.compareRows(overlay[ChangeIndex.NODE].row, node.row) === 0\n ) {\n applied = true;\n yieldNode = false;\n }\n break;\n }\n case ChangeType.REMOVE: {\n if (schema.compareRows(overlay[ChangeIndex.NODE].row, node.row) < 0) {\n applied = true;\n yield overlay[ChangeIndex.NODE];\n }\n break;\n }\n case ChangeType.EDIT: {\n if (\n !editOldApplied &&\n schema.compareRows(overlay[ChangeIndex.OLD_NODE].row, node.row) < 0\n ) {\n editOldApplied = true;\n if (editNewApplied) {\n applied = true;\n }\n yield overlay[ChangeIndex.OLD_NODE];\n }\n if (\n !editNewApplied &&\n schema.compareRows(overlay[ChangeIndex.NODE].row, node.row) === 0\n ) {\n editNewApplied = true;\n if (editOldApplied) {\n applied = true;\n }\n yieldNode = false;\n }\n break;\n }\n case ChangeType.CHILD: {\n if (\n schema.compareRows(overlay[ChangeIndex.NODE].row, node.row) === 0\n ) {\n applied = true;\n yield {\n row: node.row,\n relationships: {\n ...node.relationships,\n [overlay[ChangeIndex.CHILD_DATA].relationshipName]: () =>\n generateWithOverlay(\n node.relationships[\n overlay[ChangeIndex.CHILD_DATA].relationshipName\n ](),\n overlay[ChangeIndex.CHILD_DATA].change,\n schema.relationships[\n overlay[ChangeIndex.CHILD_DATA].relationshipName\n ],\n ),\n },\n };\n yieldNode = false;\n }\n break;\n }\n }\n }\n if (yieldNode) {\n yield node;\n }\n }\n if (!applied) {\n if (overlay[ChangeIndex.TYPE] === ChangeType.REMOVE) {\n applied = true;\n yield overlay[ChangeIndex.NODE];\n } else if (overlay[ChangeIndex.TYPE] === ChangeType.EDIT) {\n assert(\n editNewApplied,\n 'edit overlay: new node must be applied before old node',\n );\n editOldApplied = true;\n applied = true;\n yield overlay[ChangeIndex.OLD_NODE];\n }\n }\n\n assert(\n applied,\n 'overlayGenerator: overlay was never applied to any fetched node',\n );\n}\n\nexport function generateWithOverlayNoYieldUnordered(\n stream: Stream<Node>,\n overlay: Change,\n schema: SourceSchema,\n): Stream<Node> {\n return generateWithOverlayUnordered(stream, overlay, schema) as Stream<Node>;\n}\n\nexport function* generateWithOverlayUnordered(\n stream: Stream<Node | 'yield'>,\n overlay: Change,\n schema: SourceSchema,\n): Stream<Node | 'yield'> {\n // Eager inject\n if (overlay[ChangeIndex.TYPE] === ChangeType.REMOVE) {\n yield overlay[ChangeIndex.NODE];\n } else if (overlay[ChangeIndex.TYPE] === ChangeType.EDIT) {\n yield overlay[ChangeIndex.OLD_NODE];\n }\n\n // Stream with inline suppress\n let suppressed = false;\n for (const node of stream) {\n if (node === 'yield') {\n yield node;\n continue;\n }\n if (!suppressed) {\n if (\n overlay[ChangeIndex.TYPE] === ChangeType.ADD ||\n overlay[ChangeIndex.TYPE] === ChangeType.EDIT\n ) {\n if (\n rowEqualsForCompoundKey(\n overlay[ChangeIndex.NODE].row,\n node.row,\n schema.primaryKey,\n )\n ) {\n suppressed = true;\n continue;\n }\n }\n if (overlay[ChangeIndex.TYPE] === ChangeType.CHILD) {\n if (\n rowEqualsForCompoundKey(\n overlay[ChangeIndex.NODE].row,\n node.row,\n schema.primaryKey,\n )\n ) {\n suppressed = true;\n yield {\n row: node.row,\n relationships: {\n ...node.relationships,\n [overlay[ChangeIndex.CHILD_DATA].relationshipName]: () =>\n generateWithOverlay(\n node.relationships[\n overlay[ChangeIndex.CHILD_DATA].relationshipName\n ](),\n overlay[ChangeIndex.CHILD_DATA].change,\n schema.relationships[\n overlay[ChangeIndex.CHILD_DATA].relationshipName\n ],\n ),\n },\n };\n continue;\n }\n }\n }\n yield node;\n }\n assert(\n suppressed || overlay[ChangeIndex.TYPE] === ChangeType.REMOVE,\n 'overlayGenerator: overlay was never applied to any fetched node',\n );\n}\n\nexport function rowEqualsForCompoundKey(\n a: Row,\n b: Row,\n key: CompoundKey,\n): boolean {\n for (let i = 0; i < key.length; i++) {\n if (compareValues(a[key[i]], b[key[i]]) !== 0) {\n return false;\n }\n }\n return true;\n}\n\nexport function isJoinMatch(\n parent: Row,\n parentKey: CompoundKey,\n child: Row,\n childKey: CompoundKey,\n) {\n for (let i = 0; i < parentKey.length; i++) {\n if (!valuesEqual(parent[parentKey[i]], child[childKey[i]])) {\n return false;\n }\n }\n return true;\n}\n\n/**\n * Builds a constraint object by mapping values from `sourceRow` using `sourceKey`\n * to keys specified by `targetKey`. Returns `undefined` if any source value is `null`,\n * since null foreign keys cannot match any rows.\n */\nexport function buildJoinConstraint(\n sourceRow: Row,\n sourceKey: CompoundKey,\n targetKey: CompoundKey,\n): Record<string, Value> | undefined {\n const constraint: Record<string, Value> = {};\n for (let i = 0; i < targetKey.length; i++) {\n const value = sourceRow[sourceKey[i]];\n if (value === null) {\n return undefined;\n }\n constraint[targetKey[i]] = value;\n }\n return constraint;\n}\n"],"mappings":";;;AAUA,SAAgB,2BACd,QACA,SACA,QACc;CACd,OAAO,oBAAoB,QAAQ,SAAS,MAAM;AACpD;AAEA,UAAiB,oBACf,QACA,SACA,QACwB;CACxB,IAAI,UAAU;CACd,IAAI,iBAAiB;CACrB,IAAI,iBAAiB;CACrB,KAAK,MAAM,QAAQ,QAAQ;EACzB,IAAI,SAAS,SAAS;GACpB,MAAM;GACN;EACF;EACA,IAAI,YAAY;EAChB,IAAI,CAAC,SACH,QAAQ,QAAQ,IAAhB;GACE,KAAK;IACH,IACE,OAAO,YAAY,QAAQ,GAAkB,KAAK,KAAK,GAAG,MAAM,GAChE;KACA,UAAU;KACV,YAAY;IACd;IACA;GAEF,KAAK;IACH,IAAI,OAAO,YAAY,QAAQ,GAAkB,KAAK,KAAK,GAAG,IAAI,GAAG;KACnE,UAAU;KACV,MAAM,QAAQ;IAChB;IACA;GAEF,KAAK;IACH,IACE,CAAC,kBACD,OAAO,YAAY,QAAQ,GAAsB,KAAK,KAAK,GAAG,IAAI,GAClE;KACA,iBAAiB;KACjB,IAAI,gBACF,UAAU;KAEZ,MAAM,QAAQ;IAChB;IACA,IACE,CAAC,kBACD,OAAO,YAAY,QAAQ,GAAkB,KAAK,KAAK,GAAG,MAAM,GAChE;KACA,iBAAiB;KACjB,IAAI,gBACF,UAAU;KAEZ,YAAY;IACd;IACA;GAEF,KAAK;IACH,IACE,OAAO,YAAY,QAAQ,GAAkB,KAAK,KAAK,GAAG,MAAM,GAChE;KACA,UAAU;KACV,MAAM;MACJ,KAAK,KAAK;MACV,eAAe;OACb,GAAG,KAAK;Q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,KAC9B,IAAI,cAAc,EAAE,IAAI,KAAK,EAAE,IAAI,GAAG,MAAM,GAC1C,OAAO;CAGX,OAAO;AACT;AAEA,SAAgB,YACd,QACA,WACA,OACA,UACA;CACA,KAAK,IAAI,IAAI,GAAG,IAAI,UAAU,QAAQ,KACpC,IAAI,CAAC,YAAY,OAAO,UAAU,KAAK,MAAM,SAAS,GAAG,GACvD,OAAO;CAGX,OAAO;AACT;;;;;;AAOA,SAAgB,oBACd,WACA,WACA,WACmC;CACnC,MAAM,aAAoC,CAAC;CAC3C,KAAK,IAAI,IAAI,GAAG,IAAI,UAAU,QAAQ,KAAK;EACzC,MAAM,QAAQ,UAAU,UAAU;EAClC,IAAI,UAAU,MACZ;EAEF,WAAW,UAAU,MAAM;CAC7B;CACA,OAAO;AACT"}
1
+ {"version":3,"file":"join-utils.js","names":[],"sources":["../../../../../zql/src/ivm/join-utils.ts"],"sourcesContent":["import {assert} from '../../../shared/src/asserts.ts';\nimport type {CompoundKey} from '../../../zero-protocol/src/ast.ts';\nimport type {Row, Value} from '../../../zero-protocol/src/data.ts';\nimport {ChangeIndex} from './change-index.ts';\nimport {ChangeType} from './change-type.ts';\nimport type {Change} from './change.ts';\nimport {compareValues, valuesEqual, type Node} from './data.ts';\nimport type {SourceSchema} from './schema.ts';\nimport type {Stream} from './stream.ts';\n\nexport function generateWithOverlayNoYield(\n stream: Stream<Node>,\n overlay: Change,\n schema: SourceSchema,\n): Stream<Node> {\n return generateWithOverlay(stream, overlay, schema) as Stream<Node>;\n}\n\nexport function* generateWithOverlay(\n stream: Stream<Node | 'yield'>,\n overlay: Change,\n schema: SourceSchema,\n): Stream<Node | 'yield'> {\n let applied = false;\n let editOldApplied = false;\n let editNewApplied = false;\n for (const node of stream) {\n if (node === 'yield') {\n yield node;\n continue;\n }\n let yieldNode = true;\n if (!applied) {\n switch (overlay[ChangeIndex.TYPE]) {\n case ChangeType.ADD: {\n if (\n schema.compareRows(overlay[ChangeIndex.NODE].row, node.row) === 0\n ) {\n applied = true;\n yieldNode = false;\n }\n break;\n }\n case ChangeType.REMOVE: {\n if (schema.compareRows(overlay[ChangeIndex.NODE].row, node.row) < 0) {\n applied = true;\n yield overlay[ChangeIndex.NODE];\n }\n break;\n }\n case ChangeType.EDIT: {\n if (\n !editOldApplied &&\n schema.compareRows(overlay[ChangeIndex.OLD_NODE].row, node.row) < 0\n ) {\n editOldApplied = true;\n if (editNewApplied) {\n applied = true;\n }\n yield overlay[ChangeIndex.OLD_NODE];\n }\n if (\n !editNewApplied &&\n schema.compareRows(overlay[ChangeIndex.NODE].row, node.row) === 0\n ) {\n editNewApplied = true;\n if (editOldApplied) {\n applied = true;\n }\n yieldNode = false;\n }\n break;\n }\n case ChangeType.CHILD: {\n if (\n schema.compareRows(overlay[ChangeIndex.NODE].row, node.row) === 0\n ) {\n applied = true;\n yield {\n row: node.row,\n relationships: {\n ...node.relationships,\n [overlay[ChangeIndex.CHILD_DATA].relationshipName]: () =>\n generateWithOverlay(\n node.relationships[\n overlay[ChangeIndex.CHILD_DATA].relationshipName\n ](),\n overlay[ChangeIndex.CHILD_DATA].change,\n schema.relationships[\n overlay[ChangeIndex.CHILD_DATA].relationshipName\n ],\n ),\n },\n };\n yieldNode = false;\n }\n break;\n }\n }\n }\n if (yieldNode) {\n yield node;\n }\n }\n if (!applied) {\n if (overlay[ChangeIndex.TYPE] === ChangeType.REMOVE) {\n applied = true;\n yield overlay[ChangeIndex.NODE];\n } else if (overlay[ChangeIndex.TYPE] === ChangeType.EDIT) {\n assert(\n editNewApplied,\n 'edit overlay: new node must be applied before old node',\n );\n editOldApplied = true;\n applied = true;\n yield overlay[ChangeIndex.OLD_NODE];\n }\n }\n\n assert(\n applied,\n 'overlayGenerator: overlay was never applied to any fetched node',\n );\n}\n\nexport function generateWithOverlayNoYieldUnordered(\n stream: Stream<Node>,\n overlay: Change,\n schema: SourceSchema,\n): Stream<Node> {\n return generateWithOverlayUnordered(stream, overlay, schema) as Stream<Node>;\n}\n\nexport function* generateWithOverlayUnordered(\n stream: Stream<Node | 'yield'>,\n overlay: Change,\n schema: SourceSchema,\n): Stream<Node | 'yield'> {\n // Eager inject\n if (overlay[ChangeIndex.TYPE] === ChangeType.REMOVE) {\n yield overlay[ChangeIndex.NODE];\n } else if (overlay[ChangeIndex.TYPE] === ChangeType.EDIT) {\n yield overlay[ChangeIndex.OLD_NODE];\n }\n\n // Stream with inline suppress\n let suppressed = false;\n for (const node of stream) {\n if (node === 'yield') {\n yield node;\n continue;\n }\n if (!suppressed) {\n if (\n overlay[ChangeIndex.TYPE] === ChangeType.ADD ||\n overlay[ChangeIndex.TYPE] === ChangeType.EDIT\n ) {\n if (\n rowEqualsForCompoundKey(\n overlay[ChangeIndex.NODE].row,\n node.row,\n schema.primaryKey,\n )\n ) {\n suppressed = true;\n continue;\n }\n }\n if (overlay[ChangeIndex.TYPE] === ChangeType.CHILD) {\n if (\n rowEqualsForCompoundKey(\n overlay[ChangeIndex.NODE].row,\n node.row,\n schema.primaryKey,\n )\n ) {\n suppressed = true;\n yield {\n row: node.row,\n relationships: {\n ...node.relationships,\n [overlay[ChangeIndex.CHILD_DATA].relationshipName]: () =>\n generateWithOverlay(\n node.relationships[\n overlay[ChangeIndex.CHILD_DATA].relationshipName\n ](),\n overlay[ChangeIndex.CHILD_DATA].change,\n schema.relationships[\n overlay[ChangeIndex.CHILD_DATA].relationshipName\n ],\n ),\n },\n };\n continue;\n }\n }\n }\n yield node;\n }\n assert(\n suppressed || overlay[ChangeIndex.TYPE] === ChangeType.REMOVE,\n 'overlayGenerator: overlay was never applied to any fetched node',\n );\n}\n\nexport function rowEqualsForCompoundKey(\n a: Row,\n b: Row,\n key: CompoundKey,\n): boolean {\n for (let i = 0; i < key.length; i++) {\n if (compareValues(a[key[i]], b[key[i]]) !== 0) {\n return false;\n }\n }\n return true;\n}\n\nexport function isJoinMatch(\n parent: Row,\n parentKey: CompoundKey,\n child: Row,\n childKey: CompoundKey,\n) {\n for (let i = 0; i < parentKey.length; i++) {\n if (!valuesEqual(parent[parentKey[i]], child[childKey[i]])) {\n return false;\n }\n }\n return true;\n}\n\n/**\n * Builds a constraint object by mapping values from `sourceRow` using `sourceKey`\n * to keys specified by `targetKey`. Returns `undefined` if any source value is `null`,\n * since null foreign keys cannot match any rows.\n */\nexport function buildJoinConstraint(\n sourceRow: Row,\n sourceKey: CompoundKey,\n targetKey: CompoundKey,\n): Record<string, Value> | undefined {\n const constraint: Record<string, Value> = {};\n for (let i = 0; i < targetKey.length; i++) {\n const value = sourceRow[sourceKey[i]];\n if (value === null) {\n return undefined;\n }\n constraint[targetKey[i]] = value;\n }\n return constraint;\n}\n\nexport function canonicalKeyForTest(\n record: Record<string, Value | undefined>,\n keys: CompoundKey,\n): string {\n return canonicalKey(record, keys);\n}\n\n/**\n * Canonical string key over `keys` of `record`. Tags values by type\n * so distinct types (e.g. 1 and \"1\") do not collide.\n */\nexport function canonicalKey(\n record: Record<string, Value | undefined>,\n keys: CompoundKey,\n): string {\n if (keys.length === 1) {\n return canonicalValue(record[keys[0]]);\n }\n let s = '';\n for (let i = 0; i < keys.length; i++) {\n if (i > 0) s += '\\x00';\n s += canonicalValue(record[keys[i]]);\n }\n return s;\n}\n\nfunction canonicalValue(v: Value): string {\n // Tag by type so we don't conflate e.g. `1` (number) with `\"1\"` (string).\n if (v === null || v === undefined) return 'n';\n const t = typeof v;\n if (t === 'string') return 's' + (v as string);\n if (t === 'number') return 'd' + (v as number);\n if (t === 'boolean') return v ? 't' : 'f';\n return 'j' + JSON.stringify(v);\n}\n"],"mappings":";;;AAUA,SAAgB,2BACd,QACA,SACA,QACc;CACd,OAAO,oBAAoB,QAAQ,SAAS,MAAM;AACpD;AAEA,UAAiB,oBACf,QACA,SACA,QACwB;CACxB,IAAI,UAAU;CACd,IAAI,iBAAiB;CACrB,IAAI,iBAAiB;CACrB,KAAK,MAAM,QAAQ,QAAQ;EACzB,IAAI,SAAS,SAAS;GACpB,MAAM;GACN;EACF;EACA,IAAI,YAAY;EACh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;CACR,IAAI,KAAK,WAAW,GAClB,OAAO,eAAe,OAAO,KAAK,GAAG;CAEvC,IAAI,IAAI;CACR,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;EACpC,IAAI,IAAI,GAAG,KAAK;EAChB,KAAK,eAAe,OAAO,KAAK,GAAG;CACrC;CACA,OAAO;AACT;AAEA,SAAS,eAAe,GAAkB;CAExC,IAAI,MAAM,QAAQ,MAAM,KAAA,GAAW,OAAO;CAC1C,MAAM,IAAI,OAAO;CACjB,IAAI,MAAM,UAAU,OAAO,MAAO;CAClC,IAAI,MAAM,UAAU,OAAO,MAAO;CAClC,IAAI,MAAM,WAAW,OAAO,IAAI,MAAM;CACtC,OAAO,MAAM,KAAK,UAAU,CAAC;AAC/B"}
@@ -1,8 +1,10 @@
1
1
  import type { CompoundKey, System } from '../../../zero-protocol/src/ast.ts';
2
2
  import type { Node } from './data.ts';
3
+ import { JoinIndex } from './join-index.ts';
3
4
  import { type FetchRequest, type Input, type Output } from './operator.ts';
4
5
  import type { SourceSchema } from './schema.ts';
5
6
  import { type Stream } from './stream.ts';
7
+ import { type TakeBoundProvider } from './take-gate.ts';
6
8
  type Args = {
7
9
  parent: Input;
8
10
  child: Input;
@@ -11,6 +13,21 @@ type Args = {
11
13
  relationshipName: string;
12
14
  hidden: boolean;
13
15
  system: System;
16
+ parentPartitionKey?: CompoundKey | undefined;
17
+ boundProvider?: TakeBoundProvider | undefined;
18
+ /**
19
+ * Set when this join feeds an EXISTS or NOT EXISTS condition. Its parent
20
+ * index is then kept by a JoinIndexTap at the end of the pipeline, so it
21
+ * only holds the parents the pipeline emits, not every parent this join
22
+ * sees. A child change that misses the index is dropped unless it could
23
+ * make a parent pass the condition: an add for EXISTS, a remove for NOT
24
+ * EXISTS. Those still fetch the parents.
25
+ */
26
+ exists?: ExistsJoin | undefined;
27
+ };
28
+ export type ExistsJoin = {
29
+ readonly op: 'EXISTS' | 'NOT EXISTS';
30
+ readonly parentIndex: JoinIndex;
14
31
  };
15
32
  /**
16
33
  * The Join operator joins the output from two upstream inputs. Zero's join
@@ -24,8 +41,9 @@ type Args = {
24
41
  */
25
42
  export declare class Join implements Input {
26
43
  #private;
27
- constructor({ parent, child, parentKey, childKey, relationshipName, hidden, system, }: Args);
44
+ constructor({ parent, child, parentKey, childKey, relationshipName, hidden, system, parentPartitionKey, boundProvider, exists, }: Args);
28
45
  destroy(): void;
46
+ get parentIndexForTest(): JoinIndex;
29
47
  setOutput(output: Output): void;
30
48
  getSchema(): SourceSchema;
31
49
  fetch(req: FetchRequest): Stream<Node | 'yield'>;
@@ -1 +1 @@
1
- {"version":3,"file":"join.d.ts","sourceRoot":"","sources":["../../../../../zql/src/ivm/join.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,WAAW,EAAE,MAAM,EAAC,MAAM,mCAAmC,CAAC;AAW3E,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,WAAW,CAAC;AAQpC,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,KAAK,EACV,KAAK,MAAM,EACZ,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAC,KAAK,MAAM,EAAC,MAAM,aAAa,CAAC;AAExC,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,KAAK,CAAC;IACd,KAAK,EAAE,KAAK,CAAC;IAEb,SAAS,EAAE,WAAW,CAAC;IACvB,QAAQ,EAAE,WAAW,CAAC;IACtB,gBAAgB,EAAE,MAAM,CAAC;IACzB,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;;;;;;;;GASG;AACH,qBAAa,IAAK,YAAW,KAAK;;IAahC,YAAY,EACV,MAAM,EACN,KAAK,EACL,SAAS,EACT,QAAQ,EACR,gBAAgB,EAChB,MAAM,EACN,MAAM,GACP,EAAE,IAAI,EAgCN;IAED,OAAO,IAAI,IAAI,CAGd;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C;CACjC,CAAC;AAEF;;;;;;;;;GASG;AACH,qBAAa,IAAK,YAAW,KAAK;;IAkChC,YAAY,EACV,MAAM,EACN,KAAK,EACL,SAAS,EACT,QAAQ,EACR,gBAAgB,EAChB,MAAM,EACN,MAAM,EACN,kBAAkB,EAClB,aAAa,EACb,MAAM,GACP,EAAE,IAAI,EAkDN;IAQD,OAAO,IAAI,IAAI,CAGd;IAED,IAAI,kBAAkB,IAAI,SAAS,CAElC;IAED,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAE9B;IAED,SAAS,IAAI,YAAY,CAExB;IAEA,KAAK,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAAC,IAAI,GAAG,OAAO,CAAC,CAShD;CA0QF"}
@@ -1,7 +1,10 @@
1
1
  import { assert, unreachable } from "../../../shared/src/asserts.js";
2
2
  import { throwOutput } from "./operator.js";
3
3
  import { makeAddChange, makeChildChange, makeEditChange, makeRemoveChange } from "./change.js";
4
- import { buildJoinConstraint, generateWithOverlay, generateWithOverlayUnordered, isJoinMatch, rowEqualsForCompoundKey } from "./join-utils.js";
4
+ import { buildJoinConstraint, canonicalKey, generateWithOverlay, generateWithOverlayUnordered, isJoinMatch, rowEqualsForCompoundKey } from "./join-utils.js";
5
+ import { JoinIndex } from "./join-index.js";
6
+ import { mergeSortedStreams } from "./memory-source.js";
7
+ import { isInParentFetch, readParentFetchBounds } from "./take-gate.js";
5
8
  //#region ../zql/src/ivm/join.ts
6
9
  /**
7
10
  * The Join operator joins the output from two upstream inputs. Zero's join
@@ -20,17 +23,49 @@ var Join = class {
20
23
  #childKey;
21
24
  #relationshipName;
22
25
  #schema;
26
+ #parentIndex;
27
+ /**
28
+ * Whether this join adds and removes parents in #parentIndex itself. Not
29
+ * so for EXISTS joins, see Args.exists.
30
+ */
31
+ #indexesParents;
32
+ /**
33
+ * The child change type that is still pushed to the parents when no
34
+ * indexed parent has its join key. See Args.exists.
35
+ */
36
+ #qualifyingChildChange;
37
+ #boundProvider;
23
38
  #output = throwOutput;
24
39
  #inprogressChildChange;
25
40
  #inprogressChildChangePosition;
26
- constructor({ parent, child, parentKey, childKey, relationshipName, hidden, system }) {
41
+ /**
42
+ * Primary keys of the parents #inprogressChildChange has reached so far,
43
+ * kept only when the parent input is unordered. An unordered stream is not
44
+ * in `compareRows` order (SQLite returns it in whatever order its plan
45
+ * visits, e.g. rowid order), so whether a parent is still in the push queue
46
+ * cannot be decided by comparing it to #inprogressChildChangePosition.
47
+ */
48
+ #inprogressReachedParents;
49
+ #inprogressParentFetchBounds;
50
+ constructor({ parent, child, parentKey, childKey, relationshipName, hidden, system, parentPartitionKey, boundProvider, exists }) {
27
51
  assert(parent !== child, "Parent and child must be different operators");
28
52
  assert(parentKey.length === childKey.length, "The parentKey and childKey keys must have same length");
53
+ assert(!exists || !parentPartitionKey, "EXISTS joins are not partitioned");
29
54
  this.#parent = parent;
30
55
  this.#child = child;
31
56
  this.#parentKey = parentKey;
32
57
  this.#childKey = childKey;
33
58
  this.#relationshipName = relationshipName;
59
+ if (exists) {
60
+ this.#parentIndex = exists.parentIndex;
61
+ this.#indexesParents = false;
62
+ this.#qualifyingChildChange = exists.op === "EXISTS" ? 0 : 1;
63
+ } else {
64
+ this.#parentIndex = new JoinIndex(parentKey, parent.getSchema().primaryKey, parentPartitionKey);
65
+ this.#indexesParents = true;
66
+ this.#qualifyingChildChange = void 0;
67
+ }
68
+ this.#boundProvider = boundProvider;
34
69
  const parentSchema = parent.getSchema();
35
70
  const childSchema = child.getSchema();
36
71
  this.#schema = {
@@ -44,13 +79,25 @@ var Join = class {
44
79
  }
45
80
  }
46
81
  };
47
- parent.setOutput({ push: (change) => this.#pushParent(change) });
48
- child.setOutput({ push: (change) => this.#pushChild(change) });
82
+ parent.setOutput({
83
+ push: (change) => this.#pushParent(change),
84
+ reconcile: () => this.#reconcile()
85
+ });
86
+ child.setOutput({
87
+ push: (change) => this.#pushChild(change),
88
+ reconcile: () => this.#reconcile()
89
+ });
90
+ }
91
+ *#reconcile() {
92
+ if (this.#output.reconcile) yield* this.#output.reconcile(this);
49
93
  }
50
94
  destroy() {
51
95
  this.#parent.destroy();
52
96
  this.#child.destroy();
53
97
  }
98
+ get parentIndexForTest() {
99
+ return this.#parentIndex;
100
+ }
54
101
  setOutput(output) {
55
102
  this.#output = output;
56
103
  }
@@ -63,15 +110,18 @@ var Join = class {
63
110
  yield parentNode;
64
111
  continue;
65
112
  }
113
+ this.#indexParentRow(parentNode.row);
66
114
  yield this.#processParentNode(parentNode.row, parentNode.relationships);
67
115
  }
68
116
  }
69
117
  *#pushParent(change) {
70
118
  switch (change[0]) {
71
119
  case 0:
120
+ this.#indexParentRow(change[1].row);
72
121
  yield* this.#output.push(makeAddChange(this.#processParentNode(change[1].row, change[1].relationships)), this);
73
122
  break;
74
123
  case 1:
124
+ this.#unindexParentRow(change[1].row);
75
125
  yield* this.#output.push(makeRemoveChange(this.#processParentNode(change[1].row, change[1].relationships)), this);
76
126
  break;
77
127
  case 3:
@@ -79,6 +129,8 @@ var Join = class {
79
129
  break;
80
130
  case 2:
81
131
  assert(rowEqualsForCompoundKey(change[2].row, change[1].row, this.#parentKey), `Parent edit must not change relationship.`);
132
+ this.#unindexParentRow(change[2].row);
133
+ this.#indexParentRow(change[1].row);
82
134
  yield* this.#output.push(makeEditChange(this.#processParentNode(change[1].row, change[1].relationships), this.#processParentNode(change[2].row, change[2].relationships)), this);
83
135
  break;
84
136
  default: unreachable(change);
@@ -106,29 +158,69 @@ var Join = class {
106
158
  *#pushChildChange(childRow, change) {
107
159
  this.#inprogressChildChange = change;
108
160
  this.#inprogressChildChangePosition = void 0;
161
+ this.#inprogressReachedParents = this.#parent.getSchema().sort === void 0 ? /* @__PURE__ */ new Set() : void 0;
109
162
  try {
110
163
  const constraint = buildJoinConstraint(childRow, this.#childKey, this.#parentKey);
111
- if (constraint) for (const parentNode of this.#parent.fetch({ constraint })) {
112
- if (parentNode === "yield") {
113
- yield parentNode;
114
- continue;
164
+ if (constraint) {
165
+ const partitions = this.#parentIndex.lookup(childRow, this.#childKey);
166
+ let fetchConstraints;
167
+ if (partitions) fetchConstraints = partitions.map((partitionConstraint) => partitionConstraint ? {
168
+ ...constraint,
169
+ ...partitionConstraint
170
+ } : constraint);
171
+ else if (change[0] === this.#qualifyingChildChange) fetchConstraints = [constraint];
172
+ else return;
173
+ if (this.#boundProvider) this.#inprogressParentFetchBounds = readParentFetchBounds(this.#boundProvider, fetchConstraints);
174
+ let parentNodeStream;
175
+ if (fetchConstraints.length === 1) parentNodeStream = this.#parent.fetch({ constraint: fetchConstraints[0] });
176
+ else {
177
+ const streams = fetchConstraints.map((c) => this.#parent.fetch({ constraint: c }));
178
+ const compare = (a, b) => this.#schema.compareRows(a.row, b.row);
179
+ parentNodeStream = mergeSortedStreams(streams, compare);
180
+ }
181
+ for (const parentNode of parentNodeStream) {
182
+ if (parentNode === "yield") {
183
+ yield parentNode;
184
+ continue;
185
+ }
186
+ this.#inprogressChildChangePosition = parentNode.row;
187
+ this.#inprogressReachedParents?.add(canonicalKey(parentNode.row, this.#schema.primaryKey));
188
+ const childChange = makeChildChange(this.#processParentNode(parentNode.row, parentNode.relationships), {
189
+ relationshipName: this.#relationshipName,
190
+ change
191
+ });
192
+ yield* this.#output.push(childChange, this);
115
193
  }
116
- this.#inprogressChildChangePosition = parentNode.row;
117
- const childChange = makeChildChange(this.#processParentNode(parentNode.row, parentNode.relationships), {
118
- relationshipName: this.#relationshipName,
119
- change
120
- });
121
- yield* this.#output.push(childChange, this);
122
194
  }
123
195
  } finally {
124
196
  this.#inprogressChildChange = void 0;
197
+ this.#inprogressChildChangePosition = void 0;
198
+ this.#inprogressReachedParents = void 0;
199
+ this.#inprogressParentFetchBounds = void 0;
125
200
  }
126
201
  }
202
+ /**
203
+ * Whether the in-progress child change has yet to reach `parentNodeRow`,
204
+ * i.e. the row comes after #inprogressChildChangePosition in the parent
205
+ * stream.
206
+ */
207
+ #isAfterInprogressPosition(parentNodeRow) {
208
+ if (this.#inprogressChildChangePosition === void 0) return false;
209
+ if (this.#inprogressReachedParents) return !this.#inprogressReachedParents.has(canonicalKey(parentNodeRow, this.#schema.primaryKey));
210
+ return this.#schema.compareRows(parentNodeRow, this.#inprogressChildChangePosition) > 0;
211
+ }
212
+ #indexParentRow(row) {
213
+ if (this.#indexesParents) this.#parentIndex.add(row);
214
+ }
215
+ #unindexParentRow(row) {
216
+ if (this.#indexesParents) this.#parentIndex.remove(row);
217
+ }
127
218
  #processParentNode(parentNodeRow, parentNodeRelations) {
128
219
  const childStream = () => {
129
220
  const constraint = buildJoinConstraint(parentNodeRow, this.#parentKey, this.#childKey);
130
221
  const stream = constraint ? this.#child.fetch({ constraint }) : [];
131
- if (this.#inprogressChildChange && isJoinMatch(parentNodeRow, this.#parentKey, this.#inprogressChildChange[1].row, this.#childKey) && this.#inprogressChildChangePosition && this.#schema.compareRows(parentNodeRow, this.#inprogressChildChangePosition) > 0) {
222
+ const inPushQueue = this.#isAfterInprogressPosition(parentNodeRow) && (this.#inprogressParentFetchBounds === void 0 || isInParentFetch(this.#inprogressParentFetchBounds, parentNodeRow, this.#schema.compareRows));
223
+ if (this.#inprogressChildChange && isJoinMatch(parentNodeRow, this.#parentKey, this.#inprogressChildChange[1].row, this.#childKey) && inPushQueue) {
132
224
  const childSchema = this.#child.getSchema();
133
225
  if (childSchema.sort === void 0) return generateWithOverlayUnordered(stream, this.#inprogressChildChange, childSchema);
134
226
  return generateWithOverlay(stream, this.#inprogressChildChange, childSchema);
@@ -1 +1 @@
1
- {"version":3,"file":"join.js","names":["#parent","#child","#parentKey","#childKey","#relationshipName","#schema","#pushParent","#pushChild","#output","#processParentNode","#pushChildChange","#inprogressChildChange","#inprogressChildChangePosition"],"sources":["../../../../../zql/src/ivm/join.ts"],"sourcesContent":["import {assert, unreachable} from '../../../shared/src/asserts.ts';\nimport type {CompoundKey, System} from '../../../zero-protocol/src/ast.ts';\nimport type {Row} from '../../../zero-protocol/src/data.ts';\nimport {ChangeIndex} from './change-index.ts';\nimport {ChangeType} from './change-type.ts';\nimport {\n makeAddChange,\n makeChildChange,\n makeEditChange,\n makeRemoveChange,\n type Change,\n} from './change.ts';\nimport type {Node} from './data.ts';\nimport {\n buildJoinConstraint,\n generateWithOverlay,\n generateWithOverlayUnordered,\n isJoinMatch,\n rowEqualsForCompoundKey,\n} from './join-utils.ts';\nimport {\n throwOutput,\n type FetchRequest,\n type Input,\n type Output,\n} from './operator.ts';\nimport type {SourceSchema} from './schema.ts';\nimport {type Stream} from './stream.ts';\n\ntype Args = {\n parent: Input;\n child: Input;\n // The nth key in parentKey corresponds to the nth key in childKey.\n parentKey: CompoundKey;\n childKey: CompoundKey;\n relationshipName: string;\n hidden: boolean;\n system: System;\n};\n\n/**\n * The Join operator joins the output from two upstream inputs. Zero's join\n * is a little different from SQL's join in that we output hierarchical data,\n * not a flat table. This makes it a lot more useful for UI programming and\n * avoids duplicating tons of data like left join would.\n *\n * The Nodes output from Join have a new relationship added to them, which has\n * the name #relationshipName. The value of the relationship is a stream of\n * child nodes which are the corresponding values from the child source.\n */\nexport class Join implements Input {\n readonly #parent: Input;\n readonly #child: Input;\n readonly #parentKey: CompoundKey;\n readonly #childKey: CompoundKey;\n readonly #relationshipName: string;\n readonly #schema: SourceSchema;\n\n #output: Output = throwOutput;\n\n #inprogressChildChange: Change | undefined;\n #inprogressChildChangePosition: Row | undefined;\n\n constructor({\n parent,\n child,\n parentKey,\n childKey,\n relationshipName,\n hidden,\n system,\n }: Args) {\n assert(parent !== child, 'Parent and child must be different operators');\n assert(\n parentKey.length === childKey.length,\n 'The parentKey and childKey keys must have same length',\n );\n this.#parent = parent;\n this.#child = child;\n this.#parentKey = parentKey;\n this.#childKey = childKey;\n this.#relationshipName = relationshipName;\n\n const parentSchema = parent.getSchema();\n const childSchema = child.getSchema();\n this.#schema = {\n ...parentSchema,\n relationships: {\n ...parentSchema.relationships,\n [relationshipName]: {\n ...childSchema,\n isHidden: hidden,\n system,\n },\n },\n };\n\n parent.setOutput({\n push: (change: Change) => this.#pushParent(change),\n });\n child.setOutput({\n push: (change: Change) => this.#pushChild(change),\n });\n }\n\n destroy(): void {\n this.#parent.destroy();\n this.#child.destroy();\n }\n\n setOutput(output: Output): void {\n this.#output = output;\n }\n\n getSchema(): SourceSchema {\n return this.#schema;\n }\n\n *fetch(req: FetchRequest): Stream<Node | 'yield'> {\n for (const parentNode of this.#parent.fetch(req)) {\n if (parentNode === 'yield') {\n yield parentNode;\n continue;\n }\n yield this.#processParentNode(parentNode.row, parentNode.relationships);\n }\n }\n\n *#pushParent(change: Change): Stream<'yield'> {\n switch (change[ChangeIndex.TYPE]) {\n case ChangeType.ADD:\n yield* this.#output.push(\n makeAddChange(\n this.#processParentNode(\n change[ChangeIndex.NODE].row,\n change[ChangeIndex.NODE].relationships,\n ),\n ),\n this,\n );\n break;\n case ChangeType.REMOVE:\n yield* this.#output.push(\n makeRemoveChange(\n this.#processParentNode(\n change[ChangeIndex.NODE].row,\n change[ChangeIndex.NODE].relationships,\n ),\n ),\n this,\n );\n break;\n case ChangeType.CHILD:\n yield* this.#output.push(\n makeChildChange(\n this.#processParentNode(\n change[ChangeIndex.NODE].row,\n change[ChangeIndex.NODE].relationships,\n ),\n change[ChangeIndex.CHILD_DATA],\n ),\n this,\n );\n break;\n case ChangeType.EDIT: {\n // Assert the edit could not change the relationship.\n assert(\n rowEqualsForCompoundKey(\n change[ChangeIndex.OLD_NODE].row,\n change[ChangeIndex.NODE].row,\n this.#parentKey,\n ),\n `Parent edit must not change relationship.`,\n );\n yield* this.#output.push(\n makeEditChange(\n this.#processParentNode(\n change[ChangeIndex.NODE].row,\n change[ChangeIndex.NODE].relationships,\n ),\n this.#processParentNode(\n change[ChangeIndex.OLD_NODE].row,\n change[ChangeIndex.OLD_NODE].relationships,\n ),\n ),\n this,\n );\n break;\n }\n default:\n unreachable(change);\n }\n }\n\n *#pushChild(change: Change): Stream<'yield'> {\n switch (change[ChangeIndex.TYPE]) {\n case ChangeType.ADD:\n case ChangeType.REMOVE:\n yield* this.#pushChildChange(change[ChangeIndex.NODE].row, change);\n break;\n case ChangeType.CHILD:\n yield* this.#pushChildChange(change[ChangeIndex.NODE].row, change);\n break;\n case ChangeType.EDIT: {\n const childRow = change[ChangeIndex.NODE].row;\n const oldChildRow = change[ChangeIndex.OLD_NODE].row;\n // Assert the edit could not change the relationship.\n assert(\n rowEqualsForCompoundKey(oldChildRow, childRow, this.#childKey),\n 'Child edit must not change relationship.',\n );\n yield* this.#pushChildChange(childRow, change);\n break;\n }\n\n default:\n unreachable(change);\n }\n }\n\n *#pushChildChange(childRow: Row, change: Change): Stream<'yield'> {\n this.#inprogressChildChange = change;\n this.#inprogressChildChangePosition = undefined;\n try {\n const constraint = buildJoinConstraint(\n childRow,\n this.#childKey,\n this.#parentKey,\n );\n if (constraint) {\n for (const parentNode of this.#parent.fetch({constraint})) {\n if (parentNode === 'yield') {\n yield parentNode;\n continue;\n }\n this.#inprogressChildChangePosition = parentNode.row;\n const childChange = makeChildChange(\n this.#processParentNode(parentNode.row, parentNode.relationships),\n {\n relationshipName: this.#relationshipName,\n change,\n },\n );\n yield* this.#output.push(childChange, this);\n }\n }\n } finally {\n this.#inprogressChildChange = undefined;\n }\n }\n\n #processParentNode(\n parentNodeRow: Row,\n parentNodeRelations: Record<string, () => Stream<Node | 'yield'>>,\n ): Node {\n const childStream = () => {\n const constraint = buildJoinConstraint(\n parentNodeRow,\n this.#parentKey,\n this.#childKey,\n );\n const stream = constraint ? this.#child.fetch({constraint}) : [];\n\n if (\n this.#inprogressChildChange &&\n isJoinMatch(\n parentNodeRow,\n this.#parentKey,\n this.#inprogressChildChange[ChangeIndex.NODE].row,\n this.#childKey,\n ) &&\n this.#inprogressChildChangePosition &&\n this.#schema.compareRows(\n parentNodeRow,\n this.#inprogressChildChangePosition,\n ) > 0\n ) {\n const childSchema = this.#child.getSchema();\n if (childSchema.sort === undefined) {\n return generateWithOverlayUnordered(\n stream,\n this.#inprogressChildChange,\n childSchema,\n );\n }\n return generateWithOverlay(\n stream,\n this.#inprogressChildChange,\n childSchema,\n );\n }\n return stream;\n };\n\n return {\n row: parentNodeRow,\n relationships: {\n ...parentNodeRelations,\n [this.#relationshipName]: childStream,\n },\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAkDA,IAAa,OAAb,MAAmC;CACjC;CACA;CACA;CACA;CACA;CACA;CAEA,UAAkB;CAElB;CACA;CAEA,YAAY,EACV,QACA,OACA,WACA,UACA,kBACA,QACA,UACO;EACP,OAAO,WAAW,OAAO,8CAA8C;EACvE,OACE,UAAU,WAAW,SAAS,QAC9B,uDACF;EACA,KAAKA,UAAU;EACf,KAAKC,SAAS;EACd,KAAKC,aAAa;EAClB,KAAKC,YAAY;EACjB,KAAKC,oBAAoB;EAEzB,MAAM,eAAe,OAAO,UAAU;EACtC,MAAM,cAAc,MAAM,UAAU;EACpC,KAAKC,UAAU;GACb,GAAG;GACH,eAAe;IACb,GAAG,aAAa;KACf,mBAAmB;KAClB,GAAG;KACH,UAAU;KACV;IACF;GACF;EACF;EAEA,OAAO,UAAU,EACf,OAAO,WAAmB,KAAKC,YAAY,MAAM,EACnD,CAAC;EACD,MAAM,UAAU,EACd,OAAO,WAAmB,KAAKC,WAAW,MAAM,EAClD,CAAC;CACH;CAEA,UAAgB;EACd,KAAKP,QAAQ,QAAQ;EACrB,KAAKC,OAAO,QAAQ;CACtB;CAEA,UAAU,QAAsB;EAC9B,KAAKO,UAAU;CACjB;CAEA,YAA0B;EACxB,OAAO,KAAKH;CACd;CAEA,CAAC,MAAM,KAA2C;EAChD,KAAK,MAAM,cAAc,KAAKL,QAAQ,MAAM,GAAG,GAAG;GAChD,IAAI,eAAe,SAAS;IAC1B,MAAM;IACN;GACF;GACA,MAAM,KAAKS,mBAAmB,WAAW,KAAK,WAAW,aAAa;EACxE;CACF;CAEA,CAACH,YAAY,QAAiC;EAC5C,QAAQ,OAAO,IAAf;GACE,KAAK;IACH,OAAO,KAAKE,QAAQ,KAClB,cAC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QAAQ,MAAM,EAAC,WAAU,CAAC,GAAG;IACzD,IAAI,eAAe,SAAS;KAC1B,MAAM;KACN;IACF;IACA,KAAKY,iCAAiC,WAAW;IACjD,MAAM,cAAc,gBAClB,KAAKH,mBAAmB,WAAW,KAAK,WAAW,aAAa,GAChE;KACE,kBAAkB,KAAKL;KACvB;IACF,CACF;IACA,OAAO,KAAKI,QAAQ,KAAK,aAAa,IAAI;GAC5C;EAEJ,UAAU;GACR,KAAKG,yBAAyB,KAAA;EAChC;CACF;CAEA,mBACE,eACA,qBACM;EACN,MAAM,oBAAoB;GACxB,MAAM,aAAa,oBACjB,eACA,KAAKT,YACL,KAAKC,SACP;GACA,MAAM,SAAS,aAAa,KAAKF,OAAO,MAAM,EAAC,WAAU,CAAC,IAAI,CAAC;GAE/D,IACE,KAAKU,0BACL,YACE,eACA,KAAKT,YACL,KAAKS,uBAAuB,GAAkB,KAC9C,KAAKR,SACP,KACA,KAAKS,kCACL,KAAKP,QAAQ,YACX,eACA,KAAKO,8BACP,IAAI,GACJ;IACA,MAAM,cAAc,KAAKX,OAAO,UAAU;IAC1C,IAAI,YAAY,SAAS,KAAA,GACvB,OAAO,6BACL,QACA,KAAKU,wBACL,WACF;IAEF,OAAO,oBACL,QACA,KAAKA,wBACL,WACF;GACF;GACA,OAAO;EACT;EAEA,OAAO;GACL,KAAK;GACL,eAAe;IACb,GAAG;KACF,KAAKP,oBAAoB;GAC5B;EACF;CACF;AACF"}
1
+ {"version":3,"file":"join.js","names":["#parent","#child","#parentKey","#childKey","#relationshipName","#schema","#parentIndex","#indexesParents","#qualifyingChildChange","#boundProvider","#pushParent","#reconcile","#pushChild","#output","#indexParentRow","#processParentNode","#unindexParentRow","#pushChildChange","#inprogressChildChange","#inprogressChildChangePosition","#inprogressReachedParents","#inprogressParentFetchBounds","#isAfterInprogressPosition"],"sources":["../../../../../zql/src/ivm/join.ts"],"sourcesContent":["import {assert, unreachable} from '../../../shared/src/asserts.ts';\nimport type {CompoundKey, System} from '../../../zero-protocol/src/ast.ts';\nimport type {Row, Value} from '../../../zero-protocol/src/data.ts';\nimport {ChangeIndex} from './change-index.ts';\nimport {ChangeType} from './change-type.ts';\nimport {\n makeAddChange,\n makeChildChange,\n makeEditChange,\n makeRemoveChange,\n type Change,\n} from './change.ts';\nimport type {Node} from './data.ts';\nimport {JoinIndex} from './join-index.ts';\nimport {\n buildJoinConstraint,\n canonicalKey,\n generateWithOverlay,\n generateWithOverlayUnordered,\n isJoinMatch,\n rowEqualsForCompoundKey,\n} from './join-utils.ts';\nimport {mergeSortedStreams} from './memory-source.ts';\nimport {\n throwOutput,\n type FetchRequest,\n type Input,\n type Output,\n} from './operator.ts';\nimport type {SourceSchema} from './schema.ts';\nimport {type Stream} from './stream.ts';\nimport {\n isInParentFetch,\n readParentFetchBounds,\n type ParentFetchBound,\n type TakeBoundProvider,\n} from './take-gate.ts';\n\ntype Args = {\n parent: Input;\n child: Input;\n // The nth key in parentKey corresponds to the nth key in childKey.\n parentKey: CompoundKey;\n childKey: CompoundKey;\n relationshipName: string;\n hidden: boolean;\n system: System;\n parentPartitionKey?: CompoundKey | undefined;\n boundProvider?: TakeBoundProvider | undefined;\n /**\n * Set when this join feeds an EXISTS or NOT EXISTS condition. Its parent\n * index is then kept by a JoinIndexTap at the end of the pipeline, so it\n * only holds the parents the pipeline emits, not every parent this join\n * sees. A child change that misses the index is dropped unless it could\n * make a parent pass the condition: an add for EXISTS, a remove for NOT\n * EXISTS. Those still fetch the parents.\n */\n exists?: ExistsJoin | undefined;\n};\n\nexport type ExistsJoin = {\n readonly op: 'EXISTS' | 'NOT EXISTS';\n readonly parentIndex: JoinIndex;\n};\n\n/**\n * The Join operator joins the output from two upstream inputs. Zero's join\n * is a little different from SQL's join in that we output hierarchical data,\n * not a flat table. This makes it a lot more useful for UI programming and\n * avoids duplicating tons of data like left join would.\n *\n * The Nodes output from Join have a new relationship added to them, which has\n * the name #relationshipName. The value of the relationship is a stream of\n * child nodes which are the corresponding values from the child source.\n */\nexport class Join implements Input {\n readonly #parent: Input;\n readonly #child: Input;\n readonly #parentKey: CompoundKey;\n readonly #childKey: CompoundKey;\n readonly #relationshipName: string;\n readonly #schema: SourceSchema;\n readonly #parentIndex: JoinIndex;\n /**\n * Whether this join adds and removes parents in #parentIndex itself. Not\n * so for EXISTS joins, see Args.exists.\n */\n readonly #indexesParents: boolean;\n /**\n * The child change type that is still pushed to the parents when no\n * indexed parent has its join key. See Args.exists.\n */\n readonly #qualifyingChildChange: ChangeType | undefined;\n readonly #boundProvider: TakeBoundProvider | undefined;\n\n #output: Output = throwOutput;\n\n #inprogressChildChange: Change | undefined;\n #inprogressChildChangePosition: Row | undefined;\n /**\n * Primary keys of the parents #inprogressChildChange has reached so far,\n * kept only when the parent input is unordered. An unordered stream is not\n * in `compareRows` order (SQLite returns it in whatever order its plan\n * visits, e.g. rowid order), so whether a parent is still in the push queue\n * cannot be decided by comparing it to #inprogressChildChangePosition.\n */\n #inprogressReachedParents: Set<string> | undefined;\n #inprogressParentFetchBounds: ParentFetchBound[] | undefined;\n\n constructor({\n parent,\n child,\n parentKey,\n childKey,\n relationshipName,\n hidden,\n system,\n parentPartitionKey,\n boundProvider,\n exists,\n }: Args) {\n assert(parent !== child, 'Parent and child must be different operators');\n assert(\n parentKey.length === childKey.length,\n 'The parentKey and childKey keys must have same length',\n );\n assert(!exists || !parentPartitionKey, 'EXISTS joins are not partitioned');\n this.#parent = parent;\n this.#child = child;\n this.#parentKey = parentKey;\n this.#childKey = childKey;\n this.#relationshipName = relationshipName;\n if (exists) {\n this.#parentIndex = exists.parentIndex;\n this.#indexesParents = false;\n this.#qualifyingChildChange =\n exists.op === 'EXISTS' ? ChangeType.ADD : ChangeType.REMOVE;\n } else {\n this.#parentIndex = new JoinIndex(\n parentKey,\n parent.getSchema().primaryKey,\n parentPartitionKey,\n );\n this.#indexesParents = true;\n this.#qualifyingChildChange = undefined;\n }\n this.#boundProvider = boundProvider;\n\n const parentSchema = parent.getSchema();\n const childSchema = child.getSchema();\n this.#schema = {\n ...parentSchema,\n relationships: {\n ...parentSchema.relationships,\n [relationshipName]: {\n ...childSchema,\n isHidden: hidden,\n system,\n },\n },\n };\n\n parent.setOutput({\n push: (change: Change) => this.#pushParent(change),\n reconcile: () => this.#reconcile(),\n });\n child.setOutput({\n push: (change: Change) => this.#pushChild(change),\n reconcile: () => this.#reconcile(),\n });\n }\n\n *#reconcile(): Stream<'yield'> {\n if (this.#output.reconcile) {\n yield* this.#output.reconcile(this);\n }\n }\n\n destroy(): void {\n this.#parent.destroy();\n this.#child.destroy();\n }\n\n get parentIndexForTest(): JoinIndex {\n return this.#parentIndex;\n }\n\n setOutput(output: Output): void {\n this.#output = output;\n }\n\n getSchema(): SourceSchema {\n return this.#schema;\n }\n\n *fetch(req: FetchRequest): Stream<Node | 'yield'> {\n for (const parentNode of this.#parent.fetch(req)) {\n if (parentNode === 'yield') {\n yield parentNode;\n continue;\n }\n this.#indexParentRow(parentNode.row);\n yield this.#processParentNode(parentNode.row, parentNode.relationships);\n }\n }\n\n *#pushParent(change: Change): Stream<'yield'> {\n switch (change[ChangeIndex.TYPE]) {\n case ChangeType.ADD:\n this.#indexParentRow(change[ChangeIndex.NODE].row);\n yield* this.#output.push(\n makeAddChange(\n this.#processParentNode(\n change[ChangeIndex.NODE].row,\n change[ChangeIndex.NODE].relationships,\n ),\n ),\n this,\n );\n break;\n case ChangeType.REMOVE:\n this.#unindexParentRow(change[ChangeIndex.NODE].row);\n yield* this.#output.push(\n makeRemoveChange(\n this.#processParentNode(\n change[ChangeIndex.NODE].row,\n change[ChangeIndex.NODE].relationships,\n ),\n ),\n this,\n );\n break;\n case ChangeType.CHILD:\n yield* this.#output.push(\n makeChildChange(\n this.#processParentNode(\n change[ChangeIndex.NODE].row,\n change[ChangeIndex.NODE].relationships,\n ),\n change[ChangeIndex.CHILD_DATA],\n ),\n this,\n );\n break;\n case ChangeType.EDIT: {\n // Assert the edit could not change the relationship.\n assert(\n rowEqualsForCompoundKey(\n change[ChangeIndex.OLD_NODE].row,\n change[ChangeIndex.NODE].row,\n this.#parentKey,\n ),\n `Parent edit must not change relationship.`,\n );\n this.#unindexParentRow(change[ChangeIndex.OLD_NODE].row);\n this.#indexParentRow(change[ChangeIndex.NODE].row);\n yield* this.#output.push(\n makeEditChange(\n this.#processParentNode(\n change[ChangeIndex.NODE].row,\n change[ChangeIndex.NODE].relationships,\n ),\n this.#processParentNode(\n change[ChangeIndex.OLD_NODE].row,\n change[ChangeIndex.OLD_NODE].relationships,\n ),\n ),\n this,\n );\n break;\n }\n default:\n unreachable(change);\n }\n }\n\n *#pushChild(change: Change): Stream<'yield'> {\n switch (change[ChangeIndex.TYPE]) {\n case ChangeType.ADD:\n case ChangeType.REMOVE:\n yield* this.#pushChildChange(change[ChangeIndex.NODE].row, change);\n break;\n case ChangeType.CHILD:\n yield* this.#pushChildChange(change[ChangeIndex.NODE].row, change);\n break;\n case ChangeType.EDIT: {\n const childRow = change[ChangeIndex.NODE].row;\n const oldChildRow = change[ChangeIndex.OLD_NODE].row;\n // Assert the edit could not change the relationship.\n assert(\n rowEqualsForCompoundKey(oldChildRow, childRow, this.#childKey),\n 'Child edit must not change relationship.',\n );\n yield* this.#pushChildChange(childRow, change);\n break;\n }\n\n default:\n unreachable(change);\n }\n }\n\n *#pushChildChange(childRow: Row, change: Change): Stream<'yield'> {\n this.#inprogressChildChange = change;\n this.#inprogressChildChangePosition = undefined;\n this.#inprogressReachedParents =\n this.#parent.getSchema().sort === undefined ? new Set() : undefined;\n try {\n const constraint = buildJoinConstraint(\n childRow,\n this.#childKey,\n this.#parentKey,\n );\n if (constraint) {\n const partitions = this.#parentIndex.lookup(childRow, this.#childKey);\n let fetchConstraints: Record<string, Value>[];\n if (partitions) {\n fetchConstraints = partitions.map(partitionConstraint =>\n partitionConstraint\n ? {...constraint, ...partitionConstraint}\n : constraint,\n );\n } else if (change[ChangeIndex.TYPE] === this.#qualifyingChildChange) {\n fetchConstraints = [constraint];\n } else {\n return;\n }\n\n if (this.#boundProvider) {\n this.#inprogressParentFetchBounds = readParentFetchBounds(\n this.#boundProvider,\n fetchConstraints,\n );\n }\n\n let parentNodeStream: Stream<Node | 'yield'>;\n if (fetchConstraints.length === 1) {\n parentNodeStream = this.#parent.fetch({\n constraint: fetchConstraints[0],\n });\n } else {\n const streams = fetchConstraints.map(c =>\n this.#parent.fetch({constraint: c}),\n );\n const compare = (a: Node, b: Node) =>\n this.#schema.compareRows(a.row, b.row);\n parentNodeStream = mergeSortedStreams(streams, compare);\n }\n\n for (const parentNode of parentNodeStream) {\n if (parentNode === 'yield') {\n yield parentNode;\n continue;\n }\n this.#inprogressChildChangePosition = parentNode.row;\n this.#inprogressReachedParents?.add(\n canonicalKey(parentNode.row, this.#schema.primaryKey),\n );\n const childChange = makeChildChange(\n this.#processParentNode(parentNode.row, parentNode.relationships),\n {\n relationshipName: this.#relationshipName,\n change,\n },\n );\n yield* this.#output.push(childChange, this);\n }\n }\n } finally {\n this.#inprogressChildChange = undefined;\n this.#inprogressChildChangePosition = undefined;\n this.#inprogressReachedParents = undefined;\n this.#inprogressParentFetchBounds = undefined;\n }\n }\n\n /**\n * Whether the in-progress child change has yet to reach `parentNodeRow`,\n * i.e. the row comes after #inprogressChildChangePosition in the parent\n * stream.\n */\n #isAfterInprogressPosition(parentNodeRow: Row): boolean {\n if (this.#inprogressChildChangePosition === undefined) {\n return false;\n }\n if (this.#inprogressReachedParents) {\n return !this.#inprogressReachedParents.has(\n canonicalKey(parentNodeRow, this.#schema.primaryKey),\n );\n }\n return (\n this.#schema.compareRows(\n parentNodeRow,\n this.#inprogressChildChangePosition,\n ) > 0\n );\n }\n\n #indexParentRow(row: Row): void {\n if (this.#indexesParents) {\n this.#parentIndex.add(row);\n }\n }\n\n #unindexParentRow(row: Row): void {\n if (this.#indexesParents) {\n this.#parentIndex.remove(row);\n }\n }\n\n #processParentNode(\n parentNodeRow: Row,\n parentNodeRelations: Record<string, () => Stream<Node | 'yield'>>,\n ): Node {\n const childStream = () => {\n const constraint = buildJoinConstraint(\n parentNodeRow,\n this.#parentKey,\n this.#childKey,\n );\n const stream = constraint ? this.#child.fetch({constraint}) : [];\n\n // The parent has yet to get the in-progress child change if it comes\n // after the current position and a parent fetch of the push yields it.\n // With a TakeGate the fetches are capped at the bounds read when they\n // started.\n const inPushQueue =\n this.#isAfterInprogressPosition(parentNodeRow) &&\n (this.#inprogressParentFetchBounds === undefined ||\n isInParentFetch(\n this.#inprogressParentFetchBounds,\n parentNodeRow,\n this.#schema.compareRows,\n ));\n\n if (\n this.#inprogressChildChange &&\n isJoinMatch(\n parentNodeRow,\n this.#parentKey,\n this.#inprogressChildChange[ChangeIndex.NODE].row,\n this.#childKey,\n ) &&\n inPushQueue\n ) {\n const childSchema = this.#child.getSchema();\n if (childSchema.sort === undefined) {\n return generateWithOverlayUnordered(\n stream,\n this.#inprogressChildChange,\n childSchema,\n );\n }\n return generateWithOverlay(\n stream,\n this.#inprogressChildChange,\n childSchema,\n );\n }\n return stream;\n };\n\n return {\n row: parentNodeRow,\n relationships: {\n ...parentNodeRelations,\n [this.#relationshipName]: childStream,\n },\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA2EA,IAAa,OAAb,MAAmC;CACjC;CACA;CACA;CACA;CACA;CACA;CACA;;;;;CAKA;;;;;CAKA;CACA;CAEA,UAAkB;CAElB;CACA;;;;;;;;CAQA;CACA;CAEA,YAAY,EACV,QACA,OACA,WACA,UACA,kBACA,QACA,QACA,oBACA,eACA,UACO;EACP,OAAO,WAAW,OAAO,8CAA8C;EACvE,OACE,UAAU,WAAW,SAAS,QAC9B,uDACF;EACA,OAAO,CAAC,UAAU,CAAC,oBAAoB,kCAAkC;EACzE,KAAKA,UAAU;EACf,KAAKC,SAAS;EACd,KAAKC,aAAa;EAClB,KAAKC,YAAY;EACjB,KAAKC,oBAAoB;EACzB,IAAI,QAAQ;GACV,KAAKE,eAAe,OAAO;GAC3B,KAAKC,kBAAkB;GACvB,KAAKC,yB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A;EACtC;CACF;;;;;;CAOA,2BAA2B,eAA6B;EACtD,IAAI,KAAKF,mCAAmC,KAAA,GAC1C,OAAO;EAET,IAAI,KAAKC,2BACP,OAAO,CAAC,KAAKA,0BAA0B,IACrC,aAAa,eAAe,KAAKf,QAAQ,UAAU,CACrD;EAEF,OACE,KAAKA,QAAQ,YACX,eACA,KAAKc,8BACP,IAAI;CAER;CAEA,gBAAgB,KAAgB;EAC9B,IAAI,KAAKZ,iBACP,KAAKD,aAAa,IAAI,GAAG;CAE7B;CAEA,kBAAkB,KAAgB;EAChC,IAAI,KAAKC,iBACP,KAAKD,aAAa,OAAO,GAAG;CAEhC;CAEA,mBACE,eACA,qBACM;EACN,MAAM,oBAAoB;GACxB,MAAM,aAAa,oBACjB,eACA,KAAKJ,YACL,KAAKC,SACP;GACA,MAAM,SAAS,aAAa,KAAKF,OAAO,MAAM,EAAC,WAAU,CAAC,IAAI,CAAC;GAM/D,MAAM,cACJ,KAAKqB,2BAA2B,aAAa,MAC5C,KAAKD,iCAAiC,KAAA,KACrC,gBACE,KAAKA,8BACL,eACA,KAAKhB,QAAQ,WACf;GAEJ,IACE,KAAKa,0BACL,YACE,eACA,KAAKhB,YACL,KAAKgB,uBAAuB,GAAkB,KAC9C,KAAKf,SACP,KACA,aACA;IACA,MAAM,cAAc,KAAKF,OAAO,UAAU;IAC1C,IAAI,YAAY,SAAS,KAAA,GACvB,OAAO,6BACL,QACA,KAAKiB,wBACL,WACF;IAEF,OAAO,oBACL,QACA,KAAKA,wBACL,WACF;GACF;GACA,OAAO;EACT;EAEA,OAAO;GACL,KAAK;GACL,eAAe;IACb,GAAG;KACF,KAAKd,oBAAoB;GAC5B;EACF;CACF;AACF"}
@@ -6,5 +6,5 @@ import type { InputBase, Output } from './operator.ts';
6
6
  * should be present based on the row's data. It then splits the change and
7
7
  * pushes the appropriate changes to the output based on the predicate.
8
8
  */
9
- export declare function maybeSplitAndPushEditChange(change: EditChange, predicate: (row: Row) => boolean, output: Output, pusher: InputBase): Generator<"yield", void, any>;
9
+ export declare function maybeSplitAndPushEditChange(change: EditChange, predicate: (row: Row) => boolean, output: Output, pusher: InputBase): import("./stream.ts").Stream<"yield">;
10
10
  //# sourceMappingURL=maybe-split-and-push-edit-change.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"maybe-split-and-push-edit-change.d.ts","sourceRoot":"","sources":["../../../../../zql/src/ivm/maybe-split-and-push-edit-change.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,oCAAoC,CAAC;AAE5D,OAAO,EAAkC,KAAK,UAAU,EAAC,MAAM,aAAa,CAAC;AAC7E,OAAO,KAAK,EAAC,SAAS,EAAE,MAAM,EAAC,MAAM,eAAe,CAAC;AAErD;;;;GAIG;AACH,wBAAiB,2BAA2B,CAC1C,MAAM,EAAE,UAAU,EAClB,SAAS,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,EAChC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,SAAS,iCAYlB"}
1
+ {"version":3,"file":"maybe-split-and-push-edit-change.d.ts","sourceRoot":"","sources":["../../../../../zql/src/ivm/maybe-split-and-push-edit-change.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,oCAAoC,CAAC;AAE5D,OAAO,EAAkC,KAAK,UAAU,EAAC,MAAM,aAAa,CAAC;AAC7E,OAAO,KAAK,EAAC,SAAS,EAAE,MAAM,EAAC,MAAM,eAAe,CAAC;AAErD;;;;GAIG;AACH,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,UAAU,EAClB,SAAS,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,EAChC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,SAAS,yCAgBlB"}
@@ -1,3 +1,4 @@
1
+ import { emptyArray } from "../../../shared/src/sentinels.js";
1
2
  import { makeAddChange, makeRemoveChange } from "./change.js";
2
3
  //#region ../zql/src/ivm/maybe-split-and-push-edit-change.ts
3
4
  /**
@@ -5,12 +6,13 @@ import { makeAddChange, makeRemoveChange } from "./change.js";
5
6
  * should be present based on the row's data. It then splits the change and
6
7
  * pushes the appropriate changes to the output based on the predicate.
7
8
  */
8
- function* maybeSplitAndPushEditChange(change, predicate, output, pusher) {
9
+ function maybeSplitAndPushEditChange(change, predicate, output, pusher) {
9
10
  const oldWasPresent = predicate(change[2].row);
10
11
  const newIsPresent = predicate(change[1].row);
11
- if (oldWasPresent && newIsPresent) yield* output.push(change, pusher);
12
- else if (oldWasPresent && !newIsPresent) yield* output.push(makeRemoveChange(change[2]), pusher);
13
- else if (!oldWasPresent && newIsPresent) yield* output.push(makeAddChange(change[1]), pusher);
12
+ if (oldWasPresent && newIsPresent) return output.push(change, pusher);
13
+ if (oldWasPresent && !newIsPresent) return output.push(makeRemoveChange(change[2]), pusher);
14
+ if (!oldWasPresent && newIsPresent) return output.push(makeAddChange(change[1]), pusher);
15
+ return emptyArray;
14
16
  }
15
17
  //#endregion
16
18
  export { maybeSplitAndPushEditChange };