@rocicorp/zero 0.26.0-canary.8 → 0.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (275) hide show
  1. package/out/ast-to-zql/src/ast-to-zql.d.ts.map +1 -1
  2. package/out/ast-to-zql/src/ast-to-zql.js +16 -27
  3. package/out/ast-to-zql/src/ast-to-zql.js.map +1 -1
  4. package/out/otel/src/log-options.d.ts +2 -2
  5. package/out/replicache/src/bg-interval.d.ts.map +1 -1
  6. package/out/replicache/src/bg-interval.js +3 -0
  7. package/out/replicache/src/bg-interval.js.map +1 -1
  8. package/out/shared/src/arrays.js +1 -1
  9. package/out/shared/src/arrays.js.map +1 -1
  10. package/out/shared/src/browser-env.js +0 -4
  11. package/out/shared/src/browser-env.js.map +1 -1
  12. package/out/shared/src/btree-set.js +4 -1
  13. package/out/shared/src/btree-set.js.map +1 -1
  14. package/out/shared/src/options.js +1 -1
  15. package/out/shared/src/options.js.map +1 -1
  16. package/out/shared/src/queue.js +1 -1
  17. package/out/shared/src/queue.js.map +1 -1
  18. package/out/z2s/src/compiler.d.ts.map +1 -1
  19. package/out/z2s/src/compiler.js +13 -11
  20. package/out/z2s/src/compiler.js.map +1 -1
  21. package/out/zero/package.json.js +1 -1
  22. package/out/zero/src/react.js +1 -3
  23. package/out/zero/src/react.js.map +1 -1
  24. package/out/zero-cache/src/auth/read-authorizer.js +0 -7
  25. package/out/zero-cache/src/auth/read-authorizer.js.map +1 -1
  26. package/out/zero-cache/src/config/network.d.ts +3 -2
  27. package/out/zero-cache/src/config/network.d.ts.map +1 -1
  28. package/out/zero-cache/src/config/network.js +9 -2
  29. package/out/zero-cache/src/config/network.js.map +1 -1
  30. package/out/zero-cache/src/config/server-context.d.ts +16 -0
  31. package/out/zero-cache/src/config/server-context.d.ts.map +1 -0
  32. package/out/zero-cache/src/config/server-context.js +32 -0
  33. package/out/zero-cache/src/config/server-context.js.map +1 -0
  34. package/out/zero-cache/src/config/zero-config.d.ts +3 -3
  35. package/out/zero-cache/src/config/zero-config.d.ts.map +1 -1
  36. package/out/zero-cache/src/config/zero-config.js +2 -6
  37. package/out/zero-cache/src/config/zero-config.js.map +1 -1
  38. package/out/zero-cache/src/db/migration.d.ts.map +1 -1
  39. package/out/zero-cache/src/db/migration.js +40 -51
  40. package/out/zero-cache/src/db/migration.js.map +1 -1
  41. package/out/zero-cache/src/db/run-transaction.d.ts +17 -0
  42. package/out/zero-cache/src/db/run-transaction.d.ts.map +1 -0
  43. package/out/zero-cache/src/db/run-transaction.js +24 -0
  44. package/out/zero-cache/src/db/run-transaction.js.map +1 -0
  45. package/out/zero-cache/src/db/transaction-pool.d.ts.map +1 -1
  46. package/out/zero-cache/src/db/transaction-pool.js +3 -3
  47. package/out/zero-cache/src/db/transaction-pool.js.map +1 -1
  48. package/out/zero-cache/src/scripts/decommission.d.ts +1 -1
  49. package/out/zero-cache/src/scripts/deploy-permissions.js +2 -1
  50. package/out/zero-cache/src/scripts/deploy-permissions.js.map +1 -1
  51. package/out/zero-cache/src/scripts/permissions.d.ts +1 -1
  52. package/out/zero-cache/src/server/change-streamer.d.ts.map +1 -1
  53. package/out/zero-cache/src/server/change-streamer.js +6 -2
  54. package/out/zero-cache/src/server/change-streamer.js.map +1 -1
  55. package/out/zero-cache/src/server/main.js +1 -1
  56. package/out/zero-cache/src/server/main.js.map +1 -1
  57. package/out/zero-cache/src/server/runner/run-worker.d.ts.map +1 -1
  58. package/out/zero-cache/src/server/runner/run-worker.js +7 -3
  59. package/out/zero-cache/src/server/runner/run-worker.js.map +1 -1
  60. package/out/zero-cache/src/services/change-source/common/backfill-manager.d.ts +1 -1
  61. package/out/zero-cache/src/services/change-source/common/backfill-manager.js +4 -4
  62. package/out/zero-cache/src/services/change-source/common/backfill-manager.js.map +1 -1
  63. package/out/zero-cache/src/services/change-source/common/replica-schema.d.ts.map +1 -1
  64. package/out/zero-cache/src/services/change-source/common/replica-schema.js +11 -0
  65. package/out/zero-cache/src/services/change-source/common/replica-schema.js.map +1 -1
  66. package/out/zero-cache/src/services/change-source/custom/change-source.d.ts +5 -2
  67. package/out/zero-cache/src/services/change-source/custom/change-source.d.ts.map +1 -1
  68. package/out/zero-cache/src/services/change-source/custom/change-source.js +6 -6
  69. package/out/zero-cache/src/services/change-source/custom/change-source.js.map +1 -1
  70. package/out/zero-cache/src/services/change-source/pg/change-source.d.ts +6 -4
  71. package/out/zero-cache/src/services/change-source/pg/change-source.d.ts.map +1 -1
  72. package/out/zero-cache/src/services/change-source/pg/change-source.js +130 -43
  73. package/out/zero-cache/src/services/change-source/pg/change-source.js.map +1 -1
  74. package/out/zero-cache/src/services/change-source/pg/decommission.d.ts.map +1 -1
  75. package/out/zero-cache/src/services/change-source/pg/decommission.js +2 -1
  76. package/out/zero-cache/src/services/change-source/pg/decommission.js.map +1 -1
  77. package/out/zero-cache/src/services/change-source/pg/initial-sync.d.ts +4 -1
  78. package/out/zero-cache/src/services/change-source/pg/initial-sync.d.ts.map +1 -1
  79. package/out/zero-cache/src/services/change-source/pg/initial-sync.js +35 -10
  80. package/out/zero-cache/src/services/change-source/pg/initial-sync.js.map +1 -1
  81. package/out/zero-cache/src/services/change-source/pg/logical-replication/stream.js +1 -1
  82. package/out/zero-cache/src/services/change-source/pg/logical-replication/stream.js.map +1 -1
  83. package/out/zero-cache/src/services/change-source/pg/schema/init.d.ts.map +1 -1
  84. package/out/zero-cache/src/services/change-source/pg/schema/init.js +10 -0
  85. package/out/zero-cache/src/services/change-source/pg/schema/init.js.map +1 -1
  86. package/out/zero-cache/src/services/change-source/pg/schema/shard.d.ts +6 -3
  87. package/out/zero-cache/src/services/change-source/pg/schema/shard.d.ts.map +1 -1
  88. package/out/zero-cache/src/services/change-source/pg/schema/shard.js +19 -10
  89. package/out/zero-cache/src/services/change-source/pg/schema/shard.js.map +1 -1
  90. package/out/zero-cache/src/services/change-source/protocol/current/data.d.ts +1 -0
  91. package/out/zero-cache/src/services/change-source/protocol/current/data.d.ts.map +1 -1
  92. package/out/zero-cache/src/services/change-source/protocol/current/data.js +4 -2
  93. package/out/zero-cache/src/services/change-source/protocol/current/data.js.map +1 -1
  94. package/out/zero-cache/src/services/change-source/protocol/current/downstream.d.ts +3 -0
  95. package/out/zero-cache/src/services/change-source/protocol/current/downstream.d.ts.map +1 -1
  96. package/out/zero-cache/src/services/change-source/protocol/current/status.d.ts +6 -4
  97. package/out/zero-cache/src/services/change-source/protocol/current/status.d.ts.map +1 -1
  98. package/out/zero-cache/src/services/change-source/protocol/current/status.js.map +1 -1
  99. package/out/zero-cache/src/services/change-streamer/backup-monitor.d.ts +2 -2
  100. package/out/zero-cache/src/services/change-streamer/backup-monitor.d.ts.map +1 -1
  101. package/out/zero-cache/src/services/change-streamer/backup-monitor.js +30 -12
  102. package/out/zero-cache/src/services/change-streamer/backup-monitor.js.map +1 -1
  103. package/out/zero-cache/src/services/change-streamer/change-streamer-service.js +23 -3
  104. package/out/zero-cache/src/services/change-streamer/change-streamer-service.js.map +1 -1
  105. package/out/zero-cache/src/services/change-streamer/change-streamer.d.ts +1 -0
  106. package/out/zero-cache/src/services/change-streamer/change-streamer.d.ts.map +1 -1
  107. package/out/zero-cache/src/services/change-streamer/forwarder.js +1 -1
  108. package/out/zero-cache/src/services/change-streamer/forwarder.js.map +1 -1
  109. package/out/zero-cache/src/services/change-streamer/schema/tables.d.ts +1 -1
  110. package/out/zero-cache/src/services/change-streamer/schema/tables.d.ts.map +1 -1
  111. package/out/zero-cache/src/services/change-streamer/schema/tables.js +12 -4
  112. package/out/zero-cache/src/services/change-streamer/schema/tables.js.map +1 -1
  113. package/out/zero-cache/src/services/change-streamer/storer.d.ts +11 -2
  114. package/out/zero-cache/src/services/change-streamer/storer.d.ts.map +1 -1
  115. package/out/zero-cache/src/services/change-streamer/storer.js +80 -42
  116. package/out/zero-cache/src/services/change-streamer/storer.js.map +1 -1
  117. package/out/zero-cache/src/services/litestream/commands.d.ts +1 -1
  118. package/out/zero-cache/src/services/litestream/commands.d.ts.map +1 -1
  119. package/out/zero-cache/src/services/litestream/commands.js +2 -1
  120. package/out/zero-cache/src/services/litestream/commands.js.map +1 -1
  121. package/out/zero-cache/src/services/mutagen/mutagen.d.ts.map +1 -1
  122. package/out/zero-cache/src/services/mutagen/mutagen.js +22 -17
  123. package/out/zero-cache/src/services/mutagen/mutagen.js.map +1 -1
  124. package/out/zero-cache/src/services/replicator/schema/replication-state.d.ts +10 -1
  125. package/out/zero-cache/src/services/replicator/schema/replication-state.d.ts.map +1 -1
  126. package/out/zero-cache/src/services/replicator/schema/replication-state.js +49 -9
  127. package/out/zero-cache/src/services/replicator/schema/replication-state.js.map +1 -1
  128. package/out/zero-cache/src/services/running-state.d.ts +1 -0
  129. package/out/zero-cache/src/services/running-state.d.ts.map +1 -1
  130. package/out/zero-cache/src/services/running-state.js +3 -0
  131. package/out/zero-cache/src/services/running-state.js.map +1 -1
  132. package/out/zero-cache/src/services/view-syncer/cvr-purger.d.ts.map +1 -1
  133. package/out/zero-cache/src/services/view-syncer/cvr-purger.js +32 -28
  134. package/out/zero-cache/src/services/view-syncer/cvr-purger.js.map +1 -1
  135. package/out/zero-cache/src/services/view-syncer/cvr-store.d.ts.map +1 -1
  136. package/out/zero-cache/src/services/view-syncer/cvr-store.js +329 -155
  137. package/out/zero-cache/src/services/view-syncer/cvr-store.js.map +1 -1
  138. package/out/zero-cache/src/services/view-syncer/cvr.d.ts.map +1 -1
  139. package/out/zero-cache/src/services/view-syncer/cvr.js +387 -345
  140. package/out/zero-cache/src/services/view-syncer/cvr.js.map +1 -1
  141. package/out/zero-cache/src/services/view-syncer/pipeline-driver.d.ts.map +1 -1
  142. package/out/zero-cache/src/services/view-syncer/pipeline-driver.js +68 -16
  143. package/out/zero-cache/src/services/view-syncer/pipeline-driver.js.map +1 -1
  144. package/out/zero-cache/src/services/view-syncer/row-record-cache.d.ts.map +1 -1
  145. package/out/zero-cache/src/services/view-syncer/row-record-cache.js +13 -8
  146. package/out/zero-cache/src/services/view-syncer/row-record-cache.js.map +1 -1
  147. package/out/zero-cache/src/services/view-syncer/tracer.d.ts +2 -0
  148. package/out/zero-cache/src/services/view-syncer/tracer.d.ts.map +1 -0
  149. package/out/zero-cache/src/services/view-syncer/tracer.js +7 -0
  150. package/out/zero-cache/src/services/view-syncer/tracer.js.map +1 -0
  151. package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts.map +1 -1
  152. package/out/zero-cache/src/services/view-syncer/view-syncer.js +58 -43
  153. package/out/zero-cache/src/services/view-syncer/view-syncer.js.map +1 -1
  154. package/out/zero-cache/src/types/pg.js +0 -4
  155. package/out/zero-cache/src/types/pg.js.map +1 -1
  156. package/out/zero-cache/src/types/streams.d.ts +3 -1
  157. package/out/zero-cache/src/types/streams.d.ts.map +1 -1
  158. package/out/zero-cache/src/types/streams.js +1 -1
  159. package/out/zero-cache/src/types/streams.js.map +1 -1
  160. package/out/zero-cache/src/types/subscription.d.ts +7 -1
  161. package/out/zero-cache/src/types/subscription.d.ts.map +1 -1
  162. package/out/zero-cache/src/types/subscription.js +8 -2
  163. package/out/zero-cache/src/types/subscription.js.map +1 -1
  164. package/out/zero-client/src/client/options.d.ts +7 -7
  165. package/out/zero-client/src/client/options.d.ts.map +1 -1
  166. package/out/zero-client/src/client/options.js.map +1 -1
  167. package/out/zero-client/src/client/query-manager.js +1 -1
  168. package/out/zero-client/src/client/query-manager.js.map +1 -1
  169. package/out/zero-client/src/client/version.js +1 -1
  170. package/out/zero-client/src/client/zero-poke-handler.d.ts +5 -5
  171. package/out/zero-client/src/client/zero-poke-handler.d.ts.map +1 -1
  172. package/out/zero-client/src/client/zero-poke-handler.js +15 -17
  173. package/out/zero-client/src/client/zero-poke-handler.js.map +1 -1
  174. package/out/zero-client/src/client/zero.d.ts +6 -2
  175. package/out/zero-client/src/client/zero.d.ts.map +1 -1
  176. package/out/zero-client/src/client/zero.js +44 -8
  177. package/out/zero-client/src/client/zero.js.map +1 -1
  178. package/out/zero-client/src/mod.d.ts +1 -1
  179. package/out/zero-client/src/mod.d.ts.map +1 -1
  180. package/out/zero-protocol/src/ast.d.ts +2 -9
  181. package/out/zero-protocol/src/ast.d.ts.map +1 -1
  182. package/out/zero-protocol/src/ast.js +15 -32
  183. package/out/zero-protocol/src/ast.js.map +1 -1
  184. package/out/zero-protocol/src/protocol-version.d.ts +1 -1
  185. package/out/zero-protocol/src/protocol-version.d.ts.map +1 -1
  186. package/out/zero-protocol/src/protocol-version.js +5 -2
  187. package/out/zero-protocol/src/protocol-version.js.map +1 -1
  188. package/out/zero-react/src/mod.d.ts +0 -2
  189. package/out/zero-react/src/mod.d.ts.map +1 -1
  190. package/out/zero-react/src/use-query.d.ts +6 -6
  191. package/out/zero-react/src/use-query.d.ts.map +1 -1
  192. package/out/zero-react/src/use-query.js +9 -2
  193. package/out/zero-react/src/use-query.js.map +1 -1
  194. package/out/zero-react/src/zero-provider.d.ts +5 -5
  195. package/out/zero-react/src/zero-provider.d.ts.map +1 -1
  196. package/out/zero-react/src/zero-provider.js.map +1 -1
  197. package/out/zero-solid/src/solid-view.d.ts +0 -42
  198. package/out/zero-solid/src/solid-view.d.ts.map +1 -1
  199. package/out/zero-solid/src/solid-view.js +1 -1
  200. package/out/zero-solid/src/solid-view.js.map +1 -1
  201. package/out/zero-solid/src/use-query.d.ts +4 -4
  202. package/out/zero-solid/src/use-query.d.ts.map +1 -1
  203. package/out/zero-solid/src/use-query.js.map +1 -1
  204. package/out/zero-solid/src/use-zero.d.ts +5 -5
  205. package/out/zero-solid/src/use-zero.d.ts.map +1 -1
  206. package/out/zero-solid/src/use-zero.js.map +1 -1
  207. package/out/zero-types/src/default-types.d.ts +2 -0
  208. package/out/zero-types/src/default-types.d.ts.map +1 -1
  209. package/out/zql/src/builder/builder.d.ts.map +1 -1
  210. package/out/zql/src/builder/builder.js +6 -48
  211. package/out/zql/src/builder/builder.js.map +1 -1
  212. package/out/zql/src/builder/filter.d.ts.map +1 -1
  213. package/out/zql/src/builder/filter.js +0 -1
  214. package/out/zql/src/builder/filter.js.map +1 -1
  215. package/out/zql/src/ivm/array-view.d.ts.map +1 -1
  216. package/out/zql/src/ivm/array-view.js +6 -57
  217. package/out/zql/src/ivm/array-view.js.map +1 -1
  218. package/out/zql/src/ivm/view-apply-change.d.ts +3 -50
  219. package/out/zql/src/ivm/view-apply-change.d.ts.map +1 -1
  220. package/out/zql/src/ivm/view-apply-change.js +105 -358
  221. package/out/zql/src/ivm/view-apply-change.js.map +1 -1
  222. package/out/zql/src/mutate/mutator-registry.d.ts +3 -3
  223. package/out/zql/src/mutate/mutator-registry.d.ts.map +1 -1
  224. package/out/zql/src/mutate/mutator-registry.js.map +1 -1
  225. package/out/zql/src/planner/planner-builder.d.ts.map +1 -1
  226. package/out/zql/src/planner/planner-builder.js +1 -2
  227. package/out/zql/src/planner/planner-builder.js.map +1 -1
  228. package/out/zql/src/query/complete-ordering.js +0 -6
  229. package/out/zql/src/query/complete-ordering.js.map +1 -1
  230. package/out/zql/src/query/expression.d.ts +2 -19
  231. package/out/zql/src/query/expression.d.ts.map +1 -1
  232. package/out/zql/src/query/expression.js +6 -50
  233. package/out/zql/src/query/expression.js.map +1 -1
  234. package/out/zql/src/query/query-delegate-base.js +3 -1
  235. package/out/zql/src/query/query-delegate-base.js.map +1 -1
  236. package/out/zql/src/query/query-impl.d.ts.map +1 -1
  237. package/out/zql/src/query/query-impl.js +8 -12
  238. package/out/zql/src/query/query-impl.js.map +1 -1
  239. package/out/zql/src/query/query-internals.js.map +1 -1
  240. package/out/zql/src/query/query-registry.d.ts +3 -3
  241. package/out/zql/src/query/query-registry.d.ts.map +1 -1
  242. package/out/zql/src/query/query-registry.js.map +1 -1
  243. package/out/zql/src/query/query.d.ts +28 -5
  244. package/out/zql/src/query/query.d.ts.map +1 -1
  245. package/out/zqlite/src/query-builder.d.ts +0 -2
  246. package/out/zqlite/src/query-builder.d.ts.map +1 -1
  247. package/out/zqlite/src/query-builder.js.map +1 -1
  248. package/out/zqlite/src/resolve-scalar-subqueries.d.ts +10 -2
  249. package/out/zqlite/src/resolve-scalar-subqueries.d.ts.map +1 -1
  250. package/out/zqlite/src/resolve-scalar-subqueries.js +41 -9
  251. package/out/zqlite/src/resolve-scalar-subqueries.js.map +1 -1
  252. package/out/zqlite/src/sqlite-cost-model.d.ts.map +1 -1
  253. package/out/zqlite/src/sqlite-cost-model.js +0 -1
  254. package/out/zqlite/src/sqlite-cost-model.js.map +1 -1
  255. package/package.json +3 -5
  256. package/out/zero-cache/src/services/change-source/custom/sync-schema.d.ts +0 -4
  257. package/out/zero-cache/src/services/change-source/custom/sync-schema.d.ts.map +0 -1
  258. package/out/zero-cache/src/services/change-source/custom/sync-schema.js +0 -14
  259. package/out/zero-cache/src/services/change-source/custom/sync-schema.js.map +0 -1
  260. package/out/zero-cache/src/services/change-source/pg/sync-schema.d.ts +0 -5
  261. package/out/zero-cache/src/services/change-source/pg/sync-schema.d.ts.map +0 -1
  262. package/out/zero-cache/src/services/change-source/pg/sync-schema.js +0 -14
  263. package/out/zero-cache/src/services/change-source/pg/sync-schema.js.map +0 -1
  264. package/out/zero-react/src/paging-reducer.d.ts +0 -61
  265. package/out/zero-react/src/paging-reducer.d.ts.map +0 -1
  266. package/out/zero-react/src/paging-reducer.js +0 -77
  267. package/out/zero-react/src/paging-reducer.js.map +0 -1
  268. package/out/zero-react/src/use-rows.d.ts +0 -39
  269. package/out/zero-react/src/use-rows.d.ts.map +0 -1
  270. package/out/zero-react/src/use-rows.js +0 -130
  271. package/out/zero-react/src/use-rows.js.map +0 -1
  272. package/out/zero-react/src/use-zero-virtualizer.d.ts +0 -122
  273. package/out/zero-react/src/use-zero-virtualizer.d.ts.map +0 -1
  274. package/out/zero-react/src/use-zero-virtualizer.js +0 -342
  275. package/out/zero-react/src/use-zero-virtualizer.js.map +0 -1
@@ -51,12 +51,6 @@ function bindStaticParameters(ast, staticQueryParameters) {
51
51
  }
52
52
  };
53
53
  }
54
- if (condition.type === "scalarSubquery") {
55
- return {
56
- ...condition,
57
- subquery: visit(condition.subquery)
58
- };
59
- }
60
54
  return {
61
55
  ...condition,
62
56
  conditions: condition.conditions.map(bindCondition)
@@ -95,7 +89,6 @@ const PERMISSIONS_EXISTS_LIMIT = 1;
95
89
  function assertNoNotExists(condition) {
96
90
  switch (condition.type) {
97
91
  case "simple":
98
- case "scalarSubquery":
99
92
  return;
100
93
  case "correlatedSubquery":
101
94
  if (condition.op === "NOT EXISTS") {
@@ -114,47 +107,11 @@ function assertNoNotExists(condition) {
114
107
  unreachable();
115
108
  }
116
109
  }
117
- function rewriteScalarSubqueryConditions(condition) {
118
- if (condition.type === "scalarSubquery") {
119
- return rewriteScalarSubquery(condition);
120
- }
121
- if (condition.type === "and" || condition.type === "or") {
122
- return {
123
- type: condition.type,
124
- conditions: condition.conditions.map(rewriteScalarSubqueryConditions)
125
- };
126
- }
127
- return condition;
128
- }
129
- function rewriteScalarSubquery(condition) {
130
- const correlated = {
131
- correlation: {
132
- parentField: [condition.parentField],
133
- childField: [condition.childField]
134
- },
135
- subquery: condition.subquery
136
- };
137
- if (condition.op === "=") {
138
- return {
139
- type: "correlatedSubquery",
140
- related: correlated,
141
- op: "EXISTS"
142
- };
143
- }
144
- return {
145
- type: "correlatedSubquery",
146
- related: correlated,
147
- op: "NOT EXISTS"
148
- };
149
- }
150
110
  function buildPipelineInternal(ast, delegate, queryID, name, partitionKey) {
151
111
  const source = delegate.getSource(ast.table);
152
112
  if (!source) {
153
113
  throw new Error(`Source not found: ${ast.table}`);
154
114
  }
155
- if (ast.where) {
156
- ast = { ...ast, where: rewriteScalarSubqueryConditions(ast.where) };
157
- }
158
115
  ast = uniquifyCorrelatedSubqueryConditionAliases(ast);
159
116
  if (!delegate.enableNotExists && ast.where) {
160
117
  assertNoNotExists(ast.where);
@@ -345,8 +302,6 @@ function applyFilter(input, condition, delegate, name) {
345
302
  return applyCorrelatedSubqueryCondition(input, condition, delegate, name);
346
303
  case "simple":
347
304
  return applySimpleCondition(input, delegate, condition);
348
- case "scalarSubquery":
349
- throw new Error("Unexpected scalarSubquery in applyFilter");
350
305
  }
351
306
  }
352
307
  function applyAnd(input, condition, delegate, name) {
@@ -403,7 +358,7 @@ function groupSubqueryConditions(condition) {
403
358
  return partitioned;
404
359
  }
405
360
  function isNotAndDoesNotContainSubquery(condition) {
406
- if (condition.type === "correlatedSubquery" || condition.type === "scalarSubquery") {
361
+ if (condition.type === "correlatedSubquery") {
407
362
  return false;
408
363
  }
409
364
  if (condition.type === "simple") {
@@ -457,7 +412,10 @@ function applyCorrelatedSubQuery(sq, delegate, queryID, end, name, fromCondition
457
412
  return delegate.decorateInput(join, joinName);
458
413
  }
459
414
  function applyCorrelatedSubqueryCondition(input, condition, delegate, name) {
460
- assert(condition.op === "EXISTS" || condition.op === "NOT EXISTS");
415
+ assert(
416
+ condition.op === "EXISTS" || condition.op === "NOT EXISTS",
417
+ "Expected EXISTS or NOT EXISTS operator"
418
+ );
461
419
  if (condition.related.subquery.limit === 0) {
462
420
  if (condition.op === "EXISTS") {
463
421
  const filter2 = new Filter(input, () => false);
@@ -517,7 +475,7 @@ function uniquifyCorrelatedSubqueryConditionAliases(ast) {
517
475
  }
518
476
  });
519
477
  const uniquify = (cond) => {
520
- if (cond.type === "simple" || cond.type === "scalarSubquery") {
478
+ if (cond.type === "simple") {
521
479
  return cond;
522
480
  } else if (cond.type === "correlatedSubquery") {
523
481
  return uniquifyCorrelatedSubquery(cond);
@@ -1 +1 @@
1
- {"version":3,"file":"builder.js","sources":["../../../../../zql/src/builder/builder.ts"],"sourcesContent":["import type {LogContext} from '@rocicorp/logger';\nimport {assert, unreachable} from '../../../shared/src/asserts.ts';\nimport type {JSONValue} from '../../../shared/src/json.ts';\nimport {must} from '../../../shared/src/must.ts';\nimport type {\n AST,\n ColumnReference,\n CompoundKey,\n Condition,\n Conjunction,\n CorrelatedSubquery,\n CorrelatedSubqueryCondition,\n Disjunction,\n LiteralValue,\n Ordering,\n Parameter,\n ScalarSubqueryCondition,\n SimpleCondition,\n ValuePosition,\n} from '../../../zero-protocol/src/ast.ts';\nimport type {Row} from '../../../zero-protocol/src/data.ts';\nimport type {PrimaryKey} from '../../../zero-protocol/src/primary-key.ts';\nimport {Exists} from '../ivm/exists.ts';\nimport {FanIn} from '../ivm/fan-in.ts';\nimport {FanOut} from '../ivm/fan-out.ts';\nimport {\n buildFilterPipeline,\n type FilterInput,\n} from '../ivm/filter-operators.ts';\nimport {Filter} from '../ivm/filter.ts';\nimport {FlippedJoin} from '../ivm/flipped-join.ts';\nimport {Join} from '../ivm/join.ts';\nimport type {Input, InputBase, Storage} from '../ivm/operator.ts';\nimport {Skip} from '../ivm/skip.ts';\nimport type {Source, SourceInput} from '../ivm/source.ts';\nimport {Take} from '../ivm/take.ts';\nimport {UnionFanIn} from '../ivm/union-fan-in.ts';\nimport {UnionFanOut} from '../ivm/union-fan-out.ts';\nimport {planQuery} from '../planner/planner-builder.ts';\nimport type {ConnectionCostModel} from '../planner/planner-connection.ts';\nimport {completeOrdering} from '../query/complete-ordering.ts';\nimport type {PlanDebugger} from '../planner/planner-debug.ts';\nimport type {DebugDelegate} from './debug-delegate.ts';\nimport {createPredicate, type NoSubqueryCondition} from './filter.ts';\n\nexport type StaticQueryParameters = {\n authData: Record<string, JSONValue>;\n preMutationRow?: Row | undefined;\n};\n\n/**\n * Interface required of caller to buildPipeline. Connects to constructed\n * pipeline to delegate environment to provide sources and storage.\n */\nexport interface BuilderDelegate {\n readonly applyFiltersAnyway?: boolean | undefined;\n debug?: DebugDelegate | undefined;\n\n /**\n * When true, allows NOT EXISTS conditions in queries.\n * Defaults to false.\n *\n * We only set this to true on the server.\n * The client-side query engine cannot support NOT EXISTS because:\n * 1. Zero only syncs a subset of data to the client\n * 2. On the client, we can't distinguish between a row not existing vs.\n * a row not being synced to the client\n * 3. NOT EXISTS requires complete knowledge of what doesn't exist\n */\n readonly enableNotExists?: boolean | undefined;\n\n /**\n * Called once for each source needed by the AST.\n * Might be called multiple times with same tableName. It is OK to return\n * same storage instance in that case.\n */\n getSource(tableName: string): Source | undefined;\n\n /**\n * Called once for each operator that requires storage. Should return a new\n * unique storage object for each call.\n */\n createStorage(name: string): Storage;\n\n decorateInput(input: Input, name: string): Input;\n\n addEdge(source: InputBase, dest: InputBase): void;\n\n decorateFilterInput(input: FilterInput, name: string): FilterInput;\n\n decorateSourceInput(input: SourceInput, queryID: string): Input;\n\n /**\n * The AST is mapped on-the-wire between client and server names.\n *\n * There is no \"wire\" for zqlite tests so this function is provided\n * to allow tests to remap the AST.\n */\n mapAst?: ((ast: AST) => AST) | undefined;\n}\n\n/**\n * Builds a pipeline from an AST. Caller must provide a delegate to create source\n * and storage interfaces as necessary.\n *\n * Usage:\n *\n * ```ts\n * class MySink implements Output {\n * readonly #input: Input;\n *\n * constructor(input: Input) {\n * this.#input = input;\n * input.setOutput(this);\n * }\n *\n * push(change: Change, _: Operator) {\n * console.log(change);\n * }\n * }\n *\n * const input = buildPipeline(ast, myDelegate, hash(ast));\n * const sink = new MySink(input);\n * ```\n */\nexport function buildPipeline(\n ast: AST,\n delegate: BuilderDelegate,\n queryID: string,\n costModel?: ConnectionCostModel,\n lc?: LogContext,\n planDebugger?: PlanDebugger,\n): Input {\n ast = delegate.mapAst ? delegate.mapAst(ast) : ast;\n ast = completeOrdering(\n ast,\n tableName => must(delegate.getSource(tableName)).tableSchema.primaryKey,\n );\n if (costModel) {\n ast = planQuery(ast, costModel, planDebugger, lc);\n }\n return buildPipelineInternal(ast, delegate, queryID, '');\n}\n\nexport function bindStaticParameters(\n ast: AST,\n staticQueryParameters: StaticQueryParameters | undefined,\n) {\n const visit = (node: AST): AST => ({\n ...node,\n where: node.where ? bindCondition(node.where) : undefined,\n related: node.related?.map(sq => ({\n ...sq,\n subquery: visit(sq.subquery),\n })),\n });\n\n function bindCondition(condition: Condition): Condition {\n if (condition.type === 'simple') {\n return {\n ...condition,\n left: bindValue(condition.left),\n right: bindValue(condition.right) as Exclude<\n ValuePosition,\n ColumnReference\n >,\n };\n }\n if (condition.type === 'correlatedSubquery') {\n return {\n ...condition,\n related: {\n ...condition.related,\n subquery: visit(condition.related.subquery),\n },\n };\n }\n if (condition.type === 'scalarSubquery') {\n return {\n ...condition,\n subquery: visit(condition.subquery),\n };\n }\n return {\n ...condition,\n conditions: condition.conditions.map(bindCondition),\n };\n }\n\n const bindValue = (value: ValuePosition): ValuePosition => {\n if (isParameter(value)) {\n const anchor = must(\n staticQueryParameters,\n 'Static query params do not exist',\n )[value.anchor];\n const resolvedValue = resolveField(anchor, value.field);\n return {\n type: 'literal',\n value: resolvedValue as LiteralValue,\n };\n }\n return value;\n };\n\n return visit(ast);\n}\n\nfunction resolveField(\n anchor: Record<string, JSONValue> | Row | undefined,\n field: string | string[],\n): unknown {\n if (anchor === undefined) {\n return null;\n }\n\n if (Array.isArray(field)) {\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n return field.reduce((acc, f) => (acc as any)?.[f], anchor) ?? null;\n }\n\n return anchor[field] ?? null;\n}\n\nfunction isParameter(value: ValuePosition): value is Parameter {\n return value.type === 'static';\n}\n\nconst EXISTS_LIMIT = 3;\nconst PERMISSIONS_EXISTS_LIMIT = 1;\n\n/**\n * Checks if a condition tree contains any NOT EXISTS operations.\n * Recursively checks AND/OR branches but does not recurse into nested subqueries\n * (those are checked when buildPipelineInternal processes them).\n */\nexport function assertNoNotExists(condition: Condition): void {\n switch (condition.type) {\n case 'simple':\n case 'scalarSubquery':\n return;\n\n case 'correlatedSubquery':\n if (condition.op === 'NOT EXISTS') {\n throw new Error(\n 'not(exists()) is not supported on the client - see https://bugs.rocicorp.dev/issue/3438',\n );\n }\n return;\n\n case 'and':\n case 'or':\n for (const c of condition.conditions) {\n assertNoNotExists(c);\n }\n return;\n default:\n unreachable(condition);\n }\n}\n\nfunction rewriteScalarSubqueryConditions(condition: Condition): Condition {\n if (condition.type === 'scalarSubquery') {\n return rewriteScalarSubquery(condition);\n }\n if (condition.type === 'and' || condition.type === 'or') {\n return {\n type: condition.type,\n conditions: condition.conditions.map(rewriteScalarSubqueryConditions),\n };\n }\n return condition;\n}\n\nfunction rewriteScalarSubquery(condition: ScalarSubqueryCondition): Condition {\n const correlated: CorrelatedSubquery = {\n correlation: {\n parentField: [condition.parentField],\n childField: [condition.childField],\n },\n subquery: condition.subquery,\n };\n\n if (condition.op === '=') {\n // field = (SELECT col FROM ...) rewrites to EXISTS with correlation\n return {\n type: 'correlatedSubquery',\n related: correlated,\n op: 'EXISTS',\n };\n }\n\n // field IS NOT (SELECT col FROM ...) rewrites to NOT EXISTS with correlation\n return {\n type: 'correlatedSubquery',\n related: correlated,\n op: 'NOT EXISTS',\n };\n}\n\nfunction buildPipelineInternal(\n ast: AST,\n delegate: BuilderDelegate,\n queryID: string,\n name: string,\n partitionKey?: CompoundKey,\n): Input {\n const source = delegate.getSource(ast.table);\n if (!source) {\n throw new Error(`Source not found: ${ast.table}`);\n }\n\n // Rewrite scalar subquery conditions to correlated subquery conditions\n // before the rest of the pipeline processing.\n if (ast.where) {\n ast = {...ast, where: rewriteScalarSubqueryConditions(ast.where)};\n }\n\n ast = uniquifyCorrelatedSubqueryConditionAliases(ast);\n\n if (!delegate.enableNotExists && ast.where) {\n assertNoNotExists(ast.where);\n }\n\n const csqConditions = gatherCorrelatedSubqueryQueryConditions(ast.where);\n const splitEditKeys: Set<string> = partitionKey\n ? new Set(partitionKey)\n : new Set();\n const aliases = new Set<string>();\n for (const csq of csqConditions) {\n aliases.add(csq.related.subquery.alias || '');\n for (const key of csq.related.correlation.parentField) {\n splitEditKeys.add(key);\n }\n }\n if (ast.related) {\n for (const csq of ast.related) {\n for (const key of csq.correlation.parentField) {\n splitEditKeys.add(key);\n }\n }\n }\n const conn = source.connect(\n must(ast.orderBy),\n ast.where,\n splitEditKeys,\n delegate.debug,\n );\n\n let end: Input = delegate.decorateSourceInput(conn, queryID);\n end = delegate.decorateInput(end, `${name}:source(${ast.table})`);\n const {fullyAppliedFilters} = conn;\n\n if (ast.start) {\n const skip = new Skip(end, ast.start);\n delegate.addEdge(end, skip);\n end = delegate.decorateInput(skip, `${name}:skip)`);\n }\n\n for (const csqCondition of csqConditions) {\n // flipped EXISTS are handled in applyWhere\n if (!csqCondition.flip) {\n end = applyCorrelatedSubQuery(\n {\n ...csqCondition.related,\n subquery: {\n ...csqCondition.related.subquery,\n limit:\n csqCondition.related.system === 'permissions'\n ? PERMISSIONS_EXISTS_LIMIT\n : EXISTS_LIMIT,\n },\n },\n delegate,\n queryID,\n end,\n name,\n true,\n );\n }\n }\n\n if (ast.where && (!fullyAppliedFilters || delegate.applyFiltersAnyway)) {\n end = applyWhere(end, ast.where, delegate, name);\n }\n\n if (ast.limit !== undefined) {\n const takeName = `${name}:take`;\n const take = new Take(\n end,\n delegate.createStorage(takeName),\n ast.limit,\n partitionKey,\n );\n delegate.addEdge(end, take);\n end = delegate.decorateInput(take, takeName);\n }\n\n if (ast.related) {\n for (const csq of ast.related) {\n end = applyCorrelatedSubQuery(csq, delegate, queryID, end, name, false);\n }\n }\n\n return end;\n}\n\nfunction applyWhere(\n input: Input,\n condition: Condition,\n delegate: BuilderDelegate,\n name: string,\n): Input {\n if (!conditionIncludesFlippedSubqueryAtAnyLevel(condition)) {\n return buildFilterPipeline(input, delegate, filterInput =>\n applyFilter(filterInput, condition, delegate, name),\n );\n }\n\n return applyFilterWithFlips(input, condition, delegate, name);\n}\n\nfunction applyFilterWithFlips(\n input: Input,\n condition: Condition,\n delegate: BuilderDelegate,\n name: string,\n): Input {\n let end = input;\n assert(condition.type !== 'simple', 'Simple conditions cannot have flips');\n\n switch (condition.type) {\n case 'and': {\n const [withFlipped, withoutFlipped] = partitionBranches(\n condition.conditions,\n conditionIncludesFlippedSubqueryAtAnyLevel,\n );\n if (withoutFlipped.length > 0) {\n end = buildFilterPipeline(input, delegate, filterInput =>\n applyAnd(\n filterInput,\n {\n type: 'and',\n conditions: withoutFlipped,\n },\n delegate,\n name,\n ),\n );\n }\n assert(withFlipped.length > 0, 'Impossible to have no flips here');\n for (const cond of withFlipped) {\n end = applyFilterWithFlips(end, cond, delegate, name);\n }\n break;\n }\n case 'or': {\n const [withFlipped, withoutFlipped] = partitionBranches(\n condition.conditions,\n conditionIncludesFlippedSubqueryAtAnyLevel,\n );\n assert(withFlipped.length > 0, 'Impossible to have no flips here');\n\n const ufo = new UnionFanOut(end);\n delegate.addEdge(end, ufo);\n end = delegate.decorateInput(ufo, `${name}:ufo`);\n\n const branches: Input[] = [];\n if (withoutFlipped.length > 0) {\n branches.push(\n buildFilterPipeline(end, delegate, filterInput =>\n applyOr(\n filterInput,\n {\n type: 'or',\n conditions: withoutFlipped,\n },\n delegate,\n name,\n ),\n ),\n );\n }\n\n for (const cond of withFlipped) {\n branches.push(applyFilterWithFlips(end, cond, delegate, name));\n }\n\n const ufi = new UnionFanIn(ufo, branches);\n for (const branch of branches) {\n delegate.addEdge(branch, ufi);\n }\n end = delegate.decorateInput(ufi, `${name}:ufi`);\n\n break;\n }\n case 'correlatedSubquery': {\n const sq = condition.related;\n const child = buildPipelineInternal(\n sq.subquery,\n delegate,\n '',\n `${name}.${sq.subquery.alias}`,\n sq.correlation.childField,\n );\n const flippedJoin = new FlippedJoin({\n parent: end,\n child,\n parentKey: sq.correlation.parentField,\n childKey: sq.correlation.childField,\n relationshipName: must(\n sq.subquery.alias,\n 'Subquery must have an alias',\n ),\n hidden: sq.hidden ?? false,\n system: sq.system ?? 'client',\n });\n delegate.addEdge(end, flippedJoin);\n delegate.addEdge(child, flippedJoin);\n end = delegate.decorateInput(\n flippedJoin,\n `${name}:flipped-join(${sq.subquery.alias})`,\n );\n break;\n }\n }\n\n return end;\n}\n\nfunction applyFilter(\n input: FilterInput,\n condition: Condition,\n delegate: BuilderDelegate,\n name: string,\n): FilterInput {\n switch (condition.type) {\n case 'and':\n return applyAnd(input, condition, delegate, name);\n case 'or':\n return applyOr(input, condition, delegate, name);\n case 'correlatedSubquery':\n return applyCorrelatedSubqueryCondition(input, condition, delegate, name);\n case 'simple':\n return applySimpleCondition(input, delegate, condition);\n case 'scalarSubquery':\n // Scalar subqueries are rewritten to correlated subqueries before\n // the filter pipeline is built, so this should not be reached.\n throw new Error('Unexpected scalarSubquery in applyFilter');\n }\n}\n\nfunction applyAnd(\n input: FilterInput,\n condition: Conjunction,\n delegate: BuilderDelegate,\n name: string,\n): FilterInput {\n for (const subCondition of condition.conditions) {\n input = applyFilter(input, subCondition, delegate, name);\n }\n return input;\n}\n\nexport function applyOr(\n input: FilterInput,\n condition: Disjunction,\n delegate: BuilderDelegate,\n name: string,\n): FilterInput {\n const [subqueryConditions, otherConditions] =\n groupSubqueryConditions(condition);\n // if there are no subquery conditions, no fan-in / fan-out is needed\n if (subqueryConditions.length === 0) {\n const filter = new Filter(\n input,\n createPredicate({\n type: 'or',\n conditions: otherConditions,\n }),\n );\n delegate.addEdge(input, filter);\n return filter;\n }\n\n const fanOut = new FanOut(input);\n delegate.addEdge(input, fanOut);\n const branches = subqueryConditions.map(subCondition =>\n applyFilter(fanOut, subCondition, delegate, name),\n );\n if (otherConditions.length > 0) {\n const filter = new Filter(\n fanOut,\n createPredicate({\n type: 'or',\n conditions: otherConditions,\n }),\n );\n delegate.addEdge(fanOut, filter);\n branches.push(filter);\n }\n const ret = new FanIn(fanOut, branches);\n for (const branch of branches) {\n delegate.addEdge(branch, ret);\n }\n fanOut.setFanIn(ret);\n return ret;\n}\n\nexport function groupSubqueryConditions(condition: Disjunction) {\n const partitioned: [\n subqueryConditions: Condition[],\n otherConditions: NoSubqueryCondition[],\n ] = [[], []];\n for (const subCondition of condition.conditions) {\n if (isNotAndDoesNotContainSubquery(subCondition)) {\n partitioned[1].push(subCondition);\n } else {\n partitioned[0].push(subCondition);\n }\n }\n return partitioned;\n}\n\nexport function isNotAndDoesNotContainSubquery(\n condition: Condition,\n): condition is NoSubqueryCondition {\n if (\n condition.type === 'correlatedSubquery' ||\n condition.type === 'scalarSubquery'\n ) {\n return false;\n }\n if (condition.type === 'simple') {\n return true;\n }\n return condition.conditions.every(isNotAndDoesNotContainSubquery);\n}\n\nfunction applySimpleCondition(\n input: FilterInput,\n delegate: BuilderDelegate,\n condition: SimpleCondition,\n): FilterInput {\n const filter = new Filter(input, createPredicate(condition));\n delegate.decorateFilterInput(\n filter,\n `${valuePosName(condition.left)}:${condition.op}:${valuePosName(condition.right)}`,\n );\n delegate.addEdge(input, filter);\n return filter;\n}\n\nfunction valuePosName(left: ValuePosition) {\n switch (left.type) {\n case 'static':\n return left.field;\n case 'literal':\n return left.value;\n case 'column':\n return left.name;\n }\n}\n\nfunction applyCorrelatedSubQuery(\n sq: CorrelatedSubquery,\n delegate: BuilderDelegate,\n queryID: string,\n end: Input,\n name: string,\n fromCondition: boolean,\n) {\n // TODO: we only omit the join if the CSQ if from a condition since\n // we want to create an empty array for `related` fields that are `limit(0)`\n if (sq.subquery.limit === 0 && fromCondition) {\n return end;\n }\n\n assert(sq.subquery.alias, 'Subquery must have an alias');\n const child = buildPipelineInternal(\n sq.subquery,\n delegate,\n queryID,\n `${name}.${sq.subquery.alias}`,\n sq.correlation.childField,\n );\n\n const joinName = `${name}:join(${sq.subquery.alias})`;\n const join = new Join({\n parent: end,\n child,\n parentKey: sq.correlation.parentField,\n childKey: sq.correlation.childField,\n relationshipName: sq.subquery.alias,\n hidden: sq.hidden ?? false,\n system: sq.system ?? 'client',\n });\n delegate.addEdge(end, join);\n delegate.addEdge(child, join);\n return delegate.decorateInput(join, joinName);\n}\n\nfunction applyCorrelatedSubqueryCondition(\n input: FilterInput,\n condition: CorrelatedSubqueryCondition,\n delegate: BuilderDelegate,\n name: string,\n): FilterInput {\n assert(condition.op === 'EXISTS' || condition.op === 'NOT EXISTS');\n if (condition.related.subquery.limit === 0) {\n if (condition.op === 'EXISTS') {\n const filter = new Filter(input, () => false);\n delegate.addEdge(input, filter);\n return filter;\n }\n const filter = new Filter(input, () => true);\n delegate.addEdge(input, filter);\n return filter;\n }\n const existsName = `${name}:exists(${condition.related.subquery.alias})`;\n const exists = new Exists(\n input,\n must(condition.related.subquery.alias),\n condition.related.correlation.parentField,\n condition.op,\n );\n delegate.addEdge(input, exists);\n return delegate.decorateFilterInput(exists, existsName);\n}\n\nfunction gatherCorrelatedSubqueryQueryConditions(\n condition: Condition | undefined,\n) {\n const csqs: CorrelatedSubqueryCondition[] = [];\n const gather = (condition: Condition) => {\n if (condition.type === 'correlatedSubquery') {\n csqs.push(condition);\n return;\n }\n if (condition.type === 'and' || condition.type === 'or') {\n for (const c of condition.conditions) {\n gather(c);\n }\n return;\n }\n };\n if (condition) {\n gather(condition);\n }\n return csqs;\n}\n\nexport function assertOrderingIncludesPK(\n ordering: Ordering,\n pk: PrimaryKey,\n): void {\n // oxlint-disable-next-line unicorn/prefer-set-has -- Array is more appropriate here for small collections\n const orderingFields = ordering.map(([field]) => field);\n const missingFields = pk.filter(pkField => !orderingFields.includes(pkField));\n\n if (missingFields.length > 0) {\n throw new Error(\n `Ordering must include all primary key fields. Missing: ${missingFields.join(\n ', ',\n )}. ZQL automatically appends primary key fields to the ordering if they are missing \n so a common cause of this error is a casing mismatch between Postgres and ZQL.\n E.g., \"userid\" vs \"userID\".\n You may want to add double-quotes around your Postgres column names to prevent Postgres from lower-casing them:\n https://www.postgresql.org/docs/current/sql-syntax-lexical.htm`,\n );\n }\n}\n\nfunction uniquifyCorrelatedSubqueryConditionAliases(ast: AST): AST {\n if (!ast.where) {\n return ast;\n }\n const {where} = ast;\n if (where.type !== 'and' && where.type !== 'or') {\n return ast;\n }\n\n let count = 0;\n const uniquifyCorrelatedSubquery = (csqc: CorrelatedSubqueryCondition) => ({\n ...csqc,\n related: {\n ...csqc.related,\n subquery: {\n ...csqc.related.subquery,\n alias: (csqc.related.subquery.alias ?? '') + '_' + count++,\n },\n },\n });\n\n const uniquify = (cond: Condition): Condition => {\n if (cond.type === 'simple' || cond.type === 'scalarSubquery') {\n return cond;\n } else if (cond.type === 'correlatedSubquery') {\n return uniquifyCorrelatedSubquery(cond);\n }\n const conditions = [];\n for (const c of cond.conditions) {\n conditions.push(uniquify(c));\n }\n return {\n type: cond.type,\n conditions,\n };\n };\n\n const result = {\n ...ast,\n where: uniquify(where),\n };\n return result;\n}\n\nexport function conditionIncludesFlippedSubqueryAtAnyLevel(\n cond: Condition,\n): boolean {\n if (cond.type === 'correlatedSubquery') {\n return !!cond.flip;\n }\n if (cond.type === 'and' || cond.type === 'or') {\n return cond.conditions.some(c =>\n conditionIncludesFlippedSubqueryAtAnyLevel(c),\n );\n }\n // simple and scalarSubquery don't have flips\n return false;\n}\n\nexport function partitionBranches(\n conditions: readonly Condition[],\n predicate: (c: Condition) => boolean,\n) {\n const matched: Condition[] = [];\n const notMatched: Condition[] = [];\n for (const c of conditions) {\n if (predicate(c)) {\n matched.push(c);\n } else {\n notMatched.push(c);\n }\n }\n return [matched, notMatched] as const;\n}\n"],"names":["filter","condition"],"mappings":";;;;;;;;;;;;;;;;AA6HO,SAAS,cACd,KACA,UACA,SACA,WACA,IACA,cACO;AACP,QAAM,SAAS,SAAS,SAAS,OAAO,GAAG,IAAI;AAC/C,QAAM;AAAA,IACJ;AAAA,IACA,eAAa,KAAK,SAAS,UAAU,SAAS,CAAC,EAAE,YAAY;AAAA,EAAA;AAE/D,MAAI,WAAW;AACb,UAAM,UAAU,KAAK,WAAW,cAAc,EAAE;AAAA,EAClD;AACA,SAAO,sBAAsB,KAAK,UAAU,SAAS,EAAE;AACzD;AAEO,SAAS,qBACd,KACA,uBACA;AACA,QAAM,QAAQ,CAAC,UAAoB;AAAA,IACjC,GAAG;AAAA,IACH,OAAO,KAAK,QAAQ,cAAc,KAAK,KAAK,IAAI;AAAA,IAChD,SAAS,KAAK,SAAS,IAAI,CAAA,QAAO;AAAA,MAChC,GAAG;AAAA,MACH,UAAU,MAAM,GAAG,QAAQ;AAAA,IAAA,EAC3B;AAAA,EAAA;AAGJ,WAAS,cAAc,WAAiC;AACtD,QAAI,UAAU,SAAS,UAAU;AAC/B,aAAO;AAAA,QACL,GAAG;AAAA,QACH,MAAM,UAAU,UAAU,IAAI;AAAA,QA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AAAA,EAEJ;AAEA,QAAM,SAAS;AAAA,IACb,GAAG;AAAA,IACH,OAAO,SAAS,KAAK;AAAA,EAAA;AAEvB,SAAO;AACT;AAEO,SAAS,2CACd,MACS;AACT,MAAI,KAAK,SAAS,sBAAsB;AACtC,WAAO,CAAC,CAAC,KAAK;AAAA,EAChB;AACA,MAAI,KAAK,SAAS,SAAS,KAAK,SAAS,MAAM;AAC7C,WAAO,KAAK,WAAW;AAAA,MAAK,CAAA,MAC1B,2CAA2C,CAAC;AAAA,IAAA;AAAA,EAEhD;AAEA,SAAO;AACT;AAEO,SAAS,kBACd,YACA,WACA;AACA,QAAM,UAAuB,CAAA;AAC7B,QAAM,aAA0B,CAAA;AAChC,aAAW,KAAK,YAAY;AAC1B,QAAI,UAAU,CAAC,GAAG;AAChB,cAAQ,KAAK,CAAC;AAAA,IAChB,OAAO;AACL,iBAAW,KAAK,CAAC;AAAA,IACnB;AAAA,EACF;AACA,SAAO,CAAC,SAAS,UAAU;AAC7B;"}
1
+ {"version":3,"file":"builder.js","sources":["../../../../../zql/src/builder/builder.ts"],"sourcesContent":["import type {LogContext} from '@rocicorp/logger';\nimport {assert, unreachable} from '../../../shared/src/asserts.ts';\nimport type {JSONValue} from '../../../shared/src/json.ts';\nimport {must} from '../../../shared/src/must.ts';\nimport type {\n AST,\n ColumnReference,\n CompoundKey,\n Condition,\n Conjunction,\n CorrelatedSubquery,\n CorrelatedSubqueryCondition,\n Disjunction,\n LiteralValue,\n Ordering,\n Parameter,\n SimpleCondition,\n ValuePosition,\n} from '../../../zero-protocol/src/ast.ts';\nimport type {Row} from '../../../zero-protocol/src/data.ts';\nimport type {PrimaryKey} from '../../../zero-protocol/src/primary-key.ts';\nimport {Exists} from '../ivm/exists.ts';\nimport {FanIn} from '../ivm/fan-in.ts';\nimport {FanOut} from '../ivm/fan-out.ts';\nimport {\n buildFilterPipeline,\n type FilterInput,\n} from '../ivm/filter-operators.ts';\nimport {Filter} from '../ivm/filter.ts';\nimport {FlippedJoin} from '../ivm/flipped-join.ts';\nimport {Join} from '../ivm/join.ts';\nimport type {Input, InputBase, Storage} from '../ivm/operator.ts';\nimport {Skip} from '../ivm/skip.ts';\nimport type {Source, SourceInput} from '../ivm/source.ts';\nimport {Take} from '../ivm/take.ts';\nimport {UnionFanIn} from '../ivm/union-fan-in.ts';\nimport {UnionFanOut} from '../ivm/union-fan-out.ts';\nimport {planQuery} from '../planner/planner-builder.ts';\nimport type {ConnectionCostModel} from '../planner/planner-connection.ts';\nimport {completeOrdering} from '../query/complete-ordering.ts';\nimport type {PlanDebugger} from '../planner/planner-debug.ts';\nimport type {DebugDelegate} from './debug-delegate.ts';\nimport {createPredicate, type NoSubqueryCondition} from './filter.ts';\n\nexport type StaticQueryParameters = {\n authData: Record<string, JSONValue>;\n preMutationRow?: Row | undefined;\n};\n\n/**\n * Interface required of caller to buildPipeline. Connects to constructed\n * pipeline to delegate environment to provide sources and storage.\n */\nexport interface BuilderDelegate {\n readonly applyFiltersAnyway?: boolean | undefined;\n debug?: DebugDelegate | undefined;\n\n /**\n * When true, allows NOT EXISTS conditions in queries.\n * Defaults to false.\n *\n * We only set this to true on the server.\n * The client-side query engine cannot support NOT EXISTS because:\n * 1. Zero only syncs a subset of data to the client\n * 2. On the client, we can't distinguish between a row not existing vs.\n * a row not being synced to the client\n * 3. NOT EXISTS requires complete knowledge of what doesn't exist\n */\n readonly enableNotExists?: boolean | undefined;\n\n /**\n * Called once for each source needed by the AST.\n * Might be called multiple times with same tableName. It is OK to return\n * same storage instance in that case.\n */\n getSource(tableName: string): Source | undefined;\n\n /**\n * Called once for each operator that requires storage. Should return a new\n * unique storage object for each call.\n */\n createStorage(name: string): Storage;\n\n decorateInput(input: Input, name: string): Input;\n\n addEdge(source: InputBase, dest: InputBase): void;\n\n decorateFilterInput(input: FilterInput, name: string): FilterInput;\n\n decorateSourceInput(input: SourceInput, queryID: string): Input;\n\n /**\n * The AST is mapped on-the-wire between client and server names.\n *\n * There is no \"wire\" for zqlite tests so this function is provided\n * to allow tests to remap the AST.\n */\n mapAst?: ((ast: AST) => AST) | undefined;\n}\n\n/**\n * Builds a pipeline from an AST. Caller must provide a delegate to create source\n * and storage interfaces as necessary.\n *\n * Usage:\n *\n * ```ts\n * class MySink implements Output {\n * readonly #input: Input;\n *\n * constructor(input: Input) {\n * this.#input = input;\n * input.setOutput(this);\n * }\n *\n * push(change: Change, _: Operator) {\n * console.log(change);\n * }\n * }\n *\n * const input = buildPipeline(ast, myDelegate, hash(ast));\n * const sink = new MySink(input);\n * ```\n */\nexport function buildPipeline(\n ast: AST,\n delegate: BuilderDelegate,\n queryID: string,\n costModel?: ConnectionCostModel,\n lc?: LogContext,\n planDebugger?: PlanDebugger,\n): Input {\n ast = delegate.mapAst ? delegate.mapAst(ast) : ast;\n ast = completeOrdering(\n ast,\n tableName => must(delegate.getSource(tableName)).tableSchema.primaryKey,\n );\n\n if (costModel) {\n ast = planQuery(ast, costModel, planDebugger, lc);\n }\n return buildPipelineInternal(ast, delegate, queryID, '');\n}\n\nexport function bindStaticParameters(\n ast: AST,\n staticQueryParameters: StaticQueryParameters | undefined,\n) {\n const visit = (node: AST): AST => ({\n ...node,\n where: node.where ? bindCondition(node.where) : undefined,\n related: node.related?.map(sq => ({\n ...sq,\n subquery: visit(sq.subquery),\n })),\n });\n\n function bindCondition(condition: Condition): Condition {\n if (condition.type === 'simple') {\n return {\n ...condition,\n left: bindValue(condition.left),\n right: bindValue(condition.right) as Exclude<\n ValuePosition,\n ColumnReference\n >,\n };\n }\n if (condition.type === 'correlatedSubquery') {\n return {\n ...condition,\n related: {\n ...condition.related,\n subquery: visit(condition.related.subquery),\n },\n };\n }\n\n return {\n ...condition,\n conditions: condition.conditions.map(bindCondition),\n };\n }\n\n const bindValue = (value: ValuePosition): ValuePosition => {\n if (isParameter(value)) {\n const anchor = must(\n staticQueryParameters,\n 'Static query params do not exist',\n )[value.anchor];\n const resolvedValue = resolveField(anchor, value.field);\n return {\n type: 'literal',\n value: resolvedValue as LiteralValue,\n };\n }\n return value;\n };\n\n return visit(ast);\n}\n\nfunction resolveField(\n anchor: Record<string, JSONValue> | Row | undefined,\n field: string | string[],\n): unknown {\n if (anchor === undefined) {\n return null;\n }\n\n if (Array.isArray(field)) {\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n return field.reduce((acc, f) => (acc as any)?.[f], anchor) ?? null;\n }\n\n return anchor[field] ?? null;\n}\n\nfunction isParameter(value: ValuePosition): value is Parameter {\n return value.type === 'static';\n}\n\nconst EXISTS_LIMIT = 3;\nconst PERMISSIONS_EXISTS_LIMIT = 1;\n\n/**\n * Checks if a condition tree contains any NOT EXISTS operations.\n * Recursively checks AND/OR branches but does not recurse into nested subqueries\n * (those are checked when buildPipelineInternal processes them).\n */\nexport function assertNoNotExists(condition: Condition): void {\n switch (condition.type) {\n case 'simple':\n return;\n\n case 'correlatedSubquery':\n if (condition.op === 'NOT EXISTS') {\n throw new Error(\n 'not(exists()) is not supported on the client - see https://bugs.rocicorp.dev/issue/3438',\n );\n }\n return;\n\n case 'and':\n case 'or':\n for (const c of condition.conditions) {\n assertNoNotExists(c);\n }\n return;\n default:\n unreachable(condition);\n }\n}\n\nfunction buildPipelineInternal(\n ast: AST,\n delegate: BuilderDelegate,\n queryID: string,\n name: string,\n partitionKey?: CompoundKey,\n): Input {\n const source = delegate.getSource(ast.table);\n if (!source) {\n throw new Error(`Source not found: ${ast.table}`);\n }\n\n ast = uniquifyCorrelatedSubqueryConditionAliases(ast);\n\n if (!delegate.enableNotExists && ast.where) {\n assertNoNotExists(ast.where);\n }\n\n const csqConditions = gatherCorrelatedSubqueryQueryConditions(ast.where);\n const splitEditKeys: Set<string> = partitionKey\n ? new Set(partitionKey)\n : new Set();\n const aliases = new Set<string>();\n for (const csq of csqConditions) {\n aliases.add(csq.related.subquery.alias || '');\n for (const key of csq.related.correlation.parentField) {\n splitEditKeys.add(key);\n }\n }\n if (ast.related) {\n for (const csq of ast.related) {\n for (const key of csq.correlation.parentField) {\n splitEditKeys.add(key);\n }\n }\n }\n const conn = source.connect(\n must(ast.orderBy),\n ast.where,\n splitEditKeys,\n delegate.debug,\n );\n\n let end: Input = delegate.decorateSourceInput(conn, queryID);\n end = delegate.decorateInput(end, `${name}:source(${ast.table})`);\n const {fullyAppliedFilters} = conn;\n\n if (ast.start) {\n const skip = new Skip(end, ast.start);\n delegate.addEdge(end, skip);\n end = delegate.decorateInput(skip, `${name}:skip)`);\n }\n\n for (const csqCondition of csqConditions) {\n // flipped EXISTS are handled in applyWhere\n if (!csqCondition.flip) {\n end = applyCorrelatedSubQuery(\n {\n ...csqCondition.related,\n subquery: {\n ...csqCondition.related.subquery,\n limit:\n csqCondition.related.system === 'permissions'\n ? PERMISSIONS_EXISTS_LIMIT\n : EXISTS_LIMIT,\n },\n },\n delegate,\n queryID,\n end,\n name,\n true,\n );\n }\n }\n\n if (ast.where && (!fullyAppliedFilters || delegate.applyFiltersAnyway)) {\n end = applyWhere(end, ast.where, delegate, name);\n }\n\n if (ast.limit !== undefined) {\n const takeName = `${name}:take`;\n const take = new Take(\n end,\n delegate.createStorage(takeName),\n ast.limit,\n partitionKey,\n );\n delegate.addEdge(end, take);\n end = delegate.decorateInput(take, takeName);\n }\n\n if (ast.related) {\n for (const csq of ast.related) {\n end = applyCorrelatedSubQuery(csq, delegate, queryID, end, name, false);\n }\n }\n\n return end;\n}\n\nfunction applyWhere(\n input: Input,\n condition: Condition,\n delegate: BuilderDelegate,\n name: string,\n): Input {\n if (!conditionIncludesFlippedSubqueryAtAnyLevel(condition)) {\n return buildFilterPipeline(input, delegate, filterInput =>\n applyFilter(filterInput, condition, delegate, name),\n );\n }\n\n return applyFilterWithFlips(input, condition, delegate, name);\n}\n\nfunction applyFilterWithFlips(\n input: Input,\n condition: Condition,\n delegate: BuilderDelegate,\n name: string,\n): Input {\n let end = input;\n assert(condition.type !== 'simple', 'Simple conditions cannot have flips');\n\n switch (condition.type) {\n case 'and': {\n const [withFlipped, withoutFlipped] = partitionBranches(\n condition.conditions,\n conditionIncludesFlippedSubqueryAtAnyLevel,\n );\n if (withoutFlipped.length > 0) {\n end = buildFilterPipeline(input, delegate, filterInput =>\n applyAnd(\n filterInput,\n {\n type: 'and',\n conditions: withoutFlipped,\n },\n delegate,\n name,\n ),\n );\n }\n assert(withFlipped.length > 0, 'Impossible to have no flips here');\n for (const cond of withFlipped) {\n end = applyFilterWithFlips(end, cond, delegate, name);\n }\n break;\n }\n case 'or': {\n const [withFlipped, withoutFlipped] = partitionBranches(\n condition.conditions,\n conditionIncludesFlippedSubqueryAtAnyLevel,\n );\n assert(withFlipped.length > 0, 'Impossible to have no flips here');\n\n const ufo = new UnionFanOut(end);\n delegate.addEdge(end, ufo);\n end = delegate.decorateInput(ufo, `${name}:ufo`);\n\n const branches: Input[] = [];\n if (withoutFlipped.length > 0) {\n branches.push(\n buildFilterPipeline(end, delegate, filterInput =>\n applyOr(\n filterInput,\n {\n type: 'or',\n conditions: withoutFlipped,\n },\n delegate,\n name,\n ),\n ),\n );\n }\n\n for (const cond of withFlipped) {\n branches.push(applyFilterWithFlips(end, cond, delegate, name));\n }\n\n const ufi = new UnionFanIn(ufo, branches);\n for (const branch of branches) {\n delegate.addEdge(branch, ufi);\n }\n end = delegate.decorateInput(ufi, `${name}:ufi`);\n\n break;\n }\n case 'correlatedSubquery': {\n const sq = condition.related;\n const child = buildPipelineInternal(\n sq.subquery,\n delegate,\n '',\n `${name}.${sq.subquery.alias}`,\n sq.correlation.childField,\n );\n const flippedJoin = new FlippedJoin({\n parent: end,\n child,\n parentKey: sq.correlation.parentField,\n childKey: sq.correlation.childField,\n relationshipName: must(\n sq.subquery.alias,\n 'Subquery must have an alias',\n ),\n hidden: sq.hidden ?? false,\n system: sq.system ?? 'client',\n });\n delegate.addEdge(end, flippedJoin);\n delegate.addEdge(child, flippedJoin);\n end = delegate.decorateInput(\n flippedJoin,\n `${name}:flipped-join(${sq.subquery.alias})`,\n );\n break;\n }\n }\n\n return end;\n}\n\nfunction applyFilter(\n input: FilterInput,\n condition: Condition,\n delegate: BuilderDelegate,\n name: string,\n): FilterInput {\n switch (condition.type) {\n case 'and':\n return applyAnd(input, condition, delegate, name);\n case 'or':\n return applyOr(input, condition, delegate, name);\n case 'correlatedSubquery':\n return applyCorrelatedSubqueryCondition(input, condition, delegate, name);\n case 'simple':\n return applySimpleCondition(input, delegate, condition);\n }\n}\n\nfunction applyAnd(\n input: FilterInput,\n condition: Conjunction,\n delegate: BuilderDelegate,\n name: string,\n): FilterInput {\n for (const subCondition of condition.conditions) {\n input = applyFilter(input, subCondition, delegate, name);\n }\n return input;\n}\n\nexport function applyOr(\n input: FilterInput,\n condition: Disjunction,\n delegate: BuilderDelegate,\n name: string,\n): FilterInput {\n const [subqueryConditions, otherConditions] =\n groupSubqueryConditions(condition);\n // if there are no subquery conditions, no fan-in / fan-out is needed\n if (subqueryConditions.length === 0) {\n const filter = new Filter(\n input,\n createPredicate({\n type: 'or',\n conditions: otherConditions,\n }),\n );\n delegate.addEdge(input, filter);\n return filter;\n }\n\n const fanOut = new FanOut(input);\n delegate.addEdge(input, fanOut);\n const branches = subqueryConditions.map(subCondition =>\n applyFilter(fanOut, subCondition, delegate, name),\n );\n if (otherConditions.length > 0) {\n const filter = new Filter(\n fanOut,\n createPredicate({\n type: 'or',\n conditions: otherConditions,\n }),\n );\n delegate.addEdge(fanOut, filter);\n branches.push(filter);\n }\n const ret = new FanIn(fanOut, branches);\n for (const branch of branches) {\n delegate.addEdge(branch, ret);\n }\n fanOut.setFanIn(ret);\n return ret;\n}\n\nexport function groupSubqueryConditions(condition: Disjunction) {\n const partitioned: [\n subqueryConditions: Condition[],\n otherConditions: NoSubqueryCondition[],\n ] = [[], []];\n for (const subCondition of condition.conditions) {\n if (isNotAndDoesNotContainSubquery(subCondition)) {\n partitioned[1].push(subCondition);\n } else {\n partitioned[0].push(subCondition);\n }\n }\n return partitioned;\n}\n\nexport function isNotAndDoesNotContainSubquery(\n condition: Condition,\n): condition is NoSubqueryCondition {\n if (condition.type === 'correlatedSubquery') {\n return false;\n }\n if (condition.type === 'simple') {\n return true;\n }\n return condition.conditions.every(isNotAndDoesNotContainSubquery);\n}\n\nfunction applySimpleCondition(\n input: FilterInput,\n delegate: BuilderDelegate,\n condition: SimpleCondition,\n): FilterInput {\n const filter = new Filter(input, createPredicate(condition));\n delegate.decorateFilterInput(\n filter,\n `${valuePosName(condition.left)}:${condition.op}:${valuePosName(condition.right)}`,\n );\n delegate.addEdge(input, filter);\n return filter;\n}\n\nfunction valuePosName(left: ValuePosition) {\n switch (left.type) {\n case 'static':\n return left.field;\n case 'literal':\n return left.value;\n case 'column':\n return left.name;\n }\n}\n\nfunction applyCorrelatedSubQuery(\n sq: CorrelatedSubquery,\n delegate: BuilderDelegate,\n queryID: string,\n end: Input,\n name: string,\n fromCondition: boolean,\n) {\n // TODO: we only omit the join if the CSQ if from a condition since\n // we want to create an empty array for `related` fields that are `limit(0)`\n if (sq.subquery.limit === 0 && fromCondition) {\n return end;\n }\n\n assert(sq.subquery.alias, 'Subquery must have an alias');\n const child = buildPipelineInternal(\n sq.subquery,\n delegate,\n queryID,\n `${name}.${sq.subquery.alias}`,\n sq.correlation.childField,\n );\n\n const joinName = `${name}:join(${sq.subquery.alias})`;\n const join = new Join({\n parent: end,\n child,\n parentKey: sq.correlation.parentField,\n childKey: sq.correlation.childField,\n relationshipName: sq.subquery.alias,\n hidden: sq.hidden ?? false,\n system: sq.system ?? 'client',\n });\n delegate.addEdge(end, join);\n delegate.addEdge(child, join);\n return delegate.decorateInput(join, joinName);\n}\n\nfunction applyCorrelatedSubqueryCondition(\n input: FilterInput,\n condition: CorrelatedSubqueryCondition,\n delegate: BuilderDelegate,\n name: string,\n): FilterInput {\n assert(\n condition.op === 'EXISTS' || condition.op === 'NOT EXISTS',\n 'Expected EXISTS or NOT EXISTS operator',\n );\n if (condition.related.subquery.limit === 0) {\n if (condition.op === 'EXISTS') {\n const filter = new Filter(input, () => false);\n delegate.addEdge(input, filter);\n return filter;\n }\n const filter = new Filter(input, () => true);\n delegate.addEdge(input, filter);\n return filter;\n }\n const existsName = `${name}:exists(${condition.related.subquery.alias})`;\n const exists = new Exists(\n input,\n must(condition.related.subquery.alias),\n condition.related.correlation.parentField,\n condition.op,\n );\n delegate.addEdge(input, exists);\n return delegate.decorateFilterInput(exists, existsName);\n}\n\nfunction gatherCorrelatedSubqueryQueryConditions(\n condition: Condition | undefined,\n) {\n const csqs: CorrelatedSubqueryCondition[] = [];\n const gather = (condition: Condition) => {\n if (condition.type === 'correlatedSubquery') {\n csqs.push(condition);\n return;\n }\n if (condition.type === 'and' || condition.type === 'or') {\n for (const c of condition.conditions) {\n gather(c);\n }\n return;\n }\n };\n if (condition) {\n gather(condition);\n }\n return csqs;\n}\n\nexport function assertOrderingIncludesPK(\n ordering: Ordering,\n pk: PrimaryKey,\n): void {\n // oxlint-disable-next-line unicorn/prefer-set-has -- Array is more appropriate here for small collections\n const orderingFields = ordering.map(([field]) => field);\n const missingFields = pk.filter(pkField => !orderingFields.includes(pkField));\n\n if (missingFields.length > 0) {\n throw new Error(\n `Ordering must include all primary key fields. Missing: ${missingFields.join(\n ', ',\n )}. ZQL automatically appends primary key fields to the ordering if they are missing \n so a common cause of this error is a casing mismatch between Postgres and ZQL.\n E.g., \"userid\" vs \"userID\".\n You may want to add double-quotes around your Postgres column names to prevent Postgres from lower-casing them:\n https://www.postgresql.org/docs/current/sql-syntax-lexical.htm`,\n );\n }\n}\n\nfunction uniquifyCorrelatedSubqueryConditionAliases(ast: AST): AST {\n if (!ast.where) {\n return ast;\n }\n const {where} = ast;\n if (where.type !== 'and' && where.type !== 'or') {\n return ast;\n }\n\n let count = 0;\n const uniquifyCorrelatedSubquery = (csqc: CorrelatedSubqueryCondition) => ({\n ...csqc,\n related: {\n ...csqc.related,\n subquery: {\n ...csqc.related.subquery,\n alias: (csqc.related.subquery.alias ?? '') + '_' + count++,\n },\n },\n });\n\n const uniquify = (cond: Condition): Condition => {\n if (cond.type === 'simple') {\n return cond;\n } else if (cond.type === 'correlatedSubquery') {\n return uniquifyCorrelatedSubquery(cond);\n }\n const conditions = [];\n for (const c of cond.conditions) {\n conditions.push(uniquify(c));\n }\n return {\n type: cond.type,\n conditions,\n };\n };\n\n const result = {\n ...ast,\n where: uniquify(where),\n };\n return result;\n}\n\nexport function conditionIncludesFlippedSubqueryAtAnyLevel(\n cond: Condition,\n): boolean {\n if (cond.type === 'correlatedSubquery') {\n return !!cond.flip;\n }\n if (cond.type === 'and' || cond.type === 'or') {\n return cond.conditions.some(c =>\n conditionIncludesFlippedSubqueryAtAnyLevel(c),\n );\n }\n // simple conditions don't have flips\n return false;\n}\n\nexport function partitionBranches(\n conditions: readonly Condition[],\n predicate: (c: Condition) => boolean,\n) {\n const matched: Condition[] = [];\n const notMatched: Condition[] = [];\n for (const c of conditions) {\n if (predicate(c)) {\n matched.push(c);\n } else {\n notMatched.push(c);\n }\n }\n return [matched, notMatched] as const;\n}\n"],"names":["filter","condition"],"mappings":";;;;;;;;;;;;;;;;AA4HO,SAAS,cACd,KACA,UACA,SACA,WACA,IACA,cACO;AACP,QAAM,SAAS,SAAS,SAAS,OAAO,GAAG,IAAI;AAC/C,QAAM;AAAA,IACJ;AAAA,IACA,eAAa,KAAK,SAAS,UAAU,SAAS,CAAC,EAAE,YAAY;AAAA,EAAA;AAG/D,MAAI,WAAW;AACb,UAAM,UAAU,KAAK,WAAW,cAAc,EAAE;AAAA,EAClD;AACA,SAAO,sBAAsB,KAAK,UAAU,SAAS,EAAE;AACzD;AAEO,SAAS,qBACd,KACA,uBACA;AACA,QAAM,QAAQ,CAAC,UAAoB;AAAA,IACjC,GAAG;AAAA,IACH,OAAO,KAAK,QAAQ,cAAc,KAAK,KAAK,IAAI;AAAA,IAChD,SAAS,KAAK,SAAS,IAAI,CAAA,QAAO;AAAA,MAChC,GAAG;AAAA,MACH,UAAU,MAAM,GAAG,QAAQ;AAAA,IAAA,EAC3B;AAAA,EAAA;AAGJ,WAAS,cAAc,WAAi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;IACE,IAAI,EAAE,KAAK,CAAC;IACZ,UAAU,EAAE,SAAS,mBAAmB,EAAE,CAAC;CAC5C,GACD;IACE,IAAI,EAAE,IAAI,CAAC;IACX,UAAU,EAAE,SAAS,mBAAmB,EAAE,CAAC;CAC5C,CAAC;AAEN,wBAAgB,eAAe,CAC7B,SAAS,EAAE,mBAAmB,GAC7B,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,CAkEvB;AA2DD;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,SAAS,GAAG,SAAS,GAAG;IAChE,OAAO,EAAE,mBAAmB,GAAG,SAAS,CAAC;IACzC,iBAAiB,EAAE,OAAO,CAAC;CAC5B,CAoCA"}
@@ -115,7 +115,6 @@ function transformFilters(filters) {
115
115
  case "simple":
116
116
  return { filters, conditionsRemoved: false };
117
117
  case "correlatedSubquery":
118
- case "scalarSubquery":
119
118
  return { filters: void 0, conditionsRemoved: true };
120
119
  case "and":
121
120
  case "or": {
@@ -1 +1 @@
1
- {"version":3,"file":"filter.js","sources":["../../../../../zql/src/builder/filter.ts"],"sourcesContent":["import {assert, unreachable} from '../../../shared/src/asserts.ts';\nimport type {\n Condition,\n SimpleCondition,\n SimpleOperator,\n} from '../../../zero-protocol/src/ast.ts';\nimport type {Row, Value} from '../../../zero-protocol/src/data.ts';\nimport {simplifyCondition} from '../query/expression.ts';\nimport {getLikePredicate} from './like.ts';\n\nexport type NonNullValue = Exclude<Value, null | undefined>;\nexport type SimplePredicate = (rhs: Value) => boolean;\nexport type SimplePredicateNoNull = (rhs: NonNullValue) => boolean;\n\nexport type NoSubqueryCondition =\n | SimpleCondition\n | {\n type: 'and';\n conditions: readonly NoSubqueryCondition[];\n }\n | {\n type: 'or';\n conditions: readonly NoSubqueryCondition[];\n };\n\nexport function createPredicate(\n condition: NoSubqueryCondition,\n): (row: Row) => boolean {\n if (condition.type !== 'simple') {\n const predicates = condition.conditions.map(c => createPredicate(c));\n return condition.type === 'and'\n ? (row: Row) => {\n // and\n for (const predicate of predicates) {\n if (!predicate(row)) {\n return false;\n }\n }\n return true;\n }\n : (row: Row) => {\n // or\n for (const predicate of predicates) {\n if (predicate(row)) {\n return true;\n }\n }\n return false;\n };\n }\n const {left} = condition;\n const {right} = condition;\n assert(\n right.type !== 'static',\n 'static values should be resolved before creating predicates',\n );\n assert(\n left.type !== 'static',\n 'static values should be resolved before creating predicates',\n );\n\n switch (condition.op) {\n case 'IS':\n case 'IS NOT': {\n const impl = createIsPredicate(right.value, condition.op);\n if (left.type === 'literal') {\n const result = impl(left.value);\n return () => result;\n }\n return (row: Row) => impl(row[left.name]);\n }\n }\n\n if (right.value === null || right.value === undefined) {\n return (_row: Row) => false;\n }\n\n const impl = createPredicateImpl(right.value, condition.op);\n if (left.type === 'literal') {\n if (left.value === null || left.value === undefined) {\n return (_row: Row) => false;\n }\n const result = impl(left.value);\n return () => result;\n }\n\n return (row: Row) => {\n const lhs = row[left.name];\n if (lhs === null || lhs === undefined) {\n return false;\n }\n return impl(lhs);\n };\n}\n\nfunction createIsPredicate(\n rhs: Value | readonly Value[],\n operator: 'IS' | 'IS NOT',\n): SimplePredicate {\n switch (operator) {\n case 'IS':\n return lhs => lhs === rhs;\n case 'IS NOT':\n return lhs => lhs !== rhs;\n }\n}\n\nfunction createPredicateImpl(\n rhs: NonNullValue | readonly NonNullValue[],\n operator: Exclude<SimpleOperator, 'IS' | 'IS NOT'>,\n): SimplePredicateNoNull {\n switch (operator) {\n case '=':\n return lhs => lhs === rhs;\n case '!=':\n return lhs => lhs !== rhs;\n case '<':\n return lhs => lhs < rhs;\n case '<=':\n return lhs => lhs <= rhs;\n case '>':\n return lhs => lhs > rhs;\n case '>=':\n return lhs => lhs >= rhs;\n case 'LIKE':\n return getLikePredicate(rhs, '');\n case 'NOT LIKE':\n return not(getLikePredicate(rhs, ''));\n case 'ILIKE':\n return getLikePredicate(rhs, 'i');\n case 'NOT ILIKE':\n return not(getLikePredicate(rhs, 'i'));\n case 'IN': {\n assert(Array.isArray(rhs));\n const set = new Set(rhs);\n return lhs => set.has(lhs);\n }\n case 'NOT IN': {\n assert(Array.isArray(rhs));\n const set = new Set(rhs);\n return lhs => !set.has(lhs);\n }\n default:\n operator satisfies never;\n throw new Error(`Unexpected operator: ${operator}`);\n }\n}\n\nfunction not<T>(f: (lhs: T) => boolean) {\n return (lhs: T) => !f(lhs);\n}\n\n/**\n * If the condition contains any CorrelatedSubqueryConditions, returns a\n * transformed condition which contains no CorrelatedSubqueryCondition(s) but\n * which will filter a subset of the rows that would be filtered by the original\n * condition, or undefined if no such transformation exists.\n *\n * If the condition does not contain any CorrelatedSubqueryConditions\n * returns the condition unmodified and `conditionsRemoved: false`.\n */\nexport function transformFilters(filters: Condition | undefined): {\n filters: NoSubqueryCondition | undefined;\n conditionsRemoved: boolean;\n} {\n if (!filters) {\n return {filters: undefined, conditionsRemoved: false};\n }\n switch (filters.type) {\n case 'simple':\n return {filters, conditionsRemoved: false};\n case 'correlatedSubquery':\n case 'scalarSubquery':\n return {filters: undefined, conditionsRemoved: true};\n case 'and':\n case 'or': {\n const transformedConditions: NoSubqueryCondition[] = [];\n let conditionsRemoved = false;\n for (const cond of filters.conditions) {\n const transformed = transformFilters(cond);\n // If any branch of the OR ends up empty, the entire OR needs\n // to be removed.\n if (transformed.filters === undefined && filters.type === 'or') {\n return {filters: undefined, conditionsRemoved: true};\n }\n conditionsRemoved = conditionsRemoved || transformed.conditionsRemoved;\n if (transformed.filters) {\n transformedConditions.push(transformed.filters);\n }\n }\n return {\n filters: simplifyCondition({\n type: filters.type,\n conditions: transformedConditions,\n }) as NoSubqueryCondition,\n conditionsRemoved,\n };\n }\n default:\n unreachable(filters);\n }\n}\n"],"names":["impl"],"mappings":";;;AAyBO,SAAS,gBACd,WACuB;AACvB,MAAI,UAAU,SAAS,UAAU;AAC/B,UAAM,aAAa,UAAU,WAAW,IAAI,CAAA,MAAK,gBAAgB,CAAC,CAAC;AACnE,WAAO,UAAU,SAAS,QACt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d,KAAK;AACH,aAAO,EAAC,SAAS,mBAAmB,MAAA;AAAA,IACtC,KAAK;AAAA,IACL,KAAK;AACH,aAAO,EAAC,SAAS,QAAW,mBAAmB,KAAA;AAAA,IACjD,KAAK;AAAA,IACL,KAAK,MAAM;AACT,YAAM,wBAA+C,CAAA;AACrD,UAAI,oBAAoB;AACxB,iBAAW,QAAQ,QAAQ,YAAY;AACrC,cAAM,cAAc,iBAAiB,IAAI;AAGzC,YAAI,YAAY,YAAY,UAAa,QAAQ,SAAS,MAAM;AAC9D,iBAAO,EAAC,SAAS,QAAW,mBAAmB,KAAA;AAAA,QACjD;AACA,4BAAoB,qBAAqB,YAAY;AACrD,YAAI,YAAY,SAAS;AACvB,gCAAsB,KAAK,YAAY,OAAO;AAAA,QAChD;AAAA,MACF;AACA,aAAO;AAAA,QACL,SAAS,kBAAkB;AAAA,UACzB,MAAM,QAAQ;AAAA,UACd,YAAY;AAAA,QAAA,CACb;AAAA,QACD;AAAA,MAAA;AAAA,IAEJ;AAAA,IACA;AACE,kBAAmB;AAAA,EAAA;AAEzB;"}
1
+ {"version":3,"file":"filter.js","sources":["../../../../../zql/src/builder/filter.ts"],"sourcesContent":["import {assert, unreachable} from '../../../shared/src/asserts.ts';\nimport type {\n Condition,\n SimpleCondition,\n SimpleOperator,\n} from '../../../zero-protocol/src/ast.ts';\nimport type {Row, Value} from '../../../zero-protocol/src/data.ts';\nimport {simplifyCondition} from '../query/expression.ts';\nimport {getLikePredicate} from './like.ts';\n\nexport type NonNullValue = Exclude<Value, null | undefined>;\nexport type SimplePredicate = (rhs: Value) => boolean;\nexport type SimplePredicateNoNull = (rhs: NonNullValue) => boolean;\n\nexport type NoSubqueryCondition =\n | SimpleCondition\n | {\n type: 'and';\n conditions: readonly NoSubqueryCondition[];\n }\n | {\n type: 'or';\n conditions: readonly NoSubqueryCondition[];\n };\n\nexport function createPredicate(\n condition: NoSubqueryCondition,\n): (row: Row) => boolean {\n if (condition.type !== 'simple') {\n const predicates = condition.conditions.map(c => createPredicate(c));\n return condition.type === 'and'\n ? (row: Row) => {\n // and\n for (const predicate of predicates) {\n if (!predicate(row)) {\n return false;\n }\n }\n return true;\n }\n : (row: Row) => {\n // or\n for (const predicate of predicates) {\n if (predicate(row)) {\n return true;\n }\n }\n return false;\n };\n }\n const {left} = condition;\n const {right} = condition;\n assert(\n right.type !== 'static',\n 'static values should be resolved before creating predicates',\n );\n assert(\n left.type !== 'static',\n 'static values should be resolved before creating predicates',\n );\n\n switch (condition.op) {\n case 'IS':\n case 'IS NOT': {\n const impl = createIsPredicate(right.value, condition.op);\n if (left.type === 'literal') {\n const result = impl(left.value);\n return () => result;\n }\n return (row: Row) => impl(row[left.name]);\n }\n }\n\n if (right.value === null || right.value === undefined) {\n return (_row: Row) => false;\n }\n\n const impl = createPredicateImpl(right.value, condition.op);\n if (left.type === 'literal') {\n if (left.value === null || left.value === undefined) {\n return (_row: Row) => false;\n }\n const result = impl(left.value);\n return () => result;\n }\n\n return (row: Row) => {\n const lhs = row[left.name];\n if (lhs === null || lhs === undefined) {\n return false;\n }\n return impl(lhs);\n };\n}\n\nfunction createIsPredicate(\n rhs: Value | readonly Value[],\n operator: 'IS' | 'IS NOT',\n): SimplePredicate {\n switch (operator) {\n case 'IS':\n return lhs => lhs === rhs;\n case 'IS NOT':\n return lhs => lhs !== rhs;\n }\n}\n\nfunction createPredicateImpl(\n rhs: NonNullValue | readonly NonNullValue[],\n operator: Exclude<SimpleOperator, 'IS' | 'IS NOT'>,\n): SimplePredicateNoNull {\n switch (operator) {\n case '=':\n return lhs => lhs === rhs;\n case '!=':\n return lhs => lhs !== rhs;\n case '<':\n return lhs => lhs < rhs;\n case '<=':\n return lhs => lhs <= rhs;\n case '>':\n return lhs => lhs > rhs;\n case '>=':\n return lhs => lhs >= rhs;\n case 'LIKE':\n return getLikePredicate(rhs, '');\n case 'NOT LIKE':\n return not(getLikePredicate(rhs, ''));\n case 'ILIKE':\n return getLikePredicate(rhs, 'i');\n case 'NOT ILIKE':\n return not(getLikePredicate(rhs, 'i'));\n case 'IN': {\n assert(Array.isArray(rhs));\n const set = new Set(rhs);\n return lhs => set.has(lhs);\n }\n case 'NOT IN': {\n assert(Array.isArray(rhs));\n const set = new Set(rhs);\n return lhs => !set.has(lhs);\n }\n default:\n operator satisfies never;\n throw new Error(`Unexpected operator: ${operator}`);\n }\n}\n\nfunction not<T>(f: (lhs: T) => boolean) {\n return (lhs: T) => !f(lhs);\n}\n\n/**\n * If the condition contains any CorrelatedSubqueryConditions, returns a\n * transformed condition which contains no CorrelatedSubqueryCondition(s) but\n * which will filter a subset of the rows that would be filtered by the original\n * condition, or undefined if no such transformation exists.\n *\n * If the condition does not contain any CorrelatedSubqueryConditions\n * returns the condition unmodified and `conditionsRemoved: false`.\n */\nexport function transformFilters(filters: Condition | undefined): {\n filters: NoSubqueryCondition | undefined;\n conditionsRemoved: boolean;\n} {\n if (!filters) {\n return {filters: undefined, conditionsRemoved: false};\n }\n switch (filters.type) {\n case 'simple':\n return {filters, conditionsRemoved: false};\n case 'correlatedSubquery':\n return {filters: undefined, conditionsRemoved: true};\n case 'and':\n case 'or': {\n const transformedConditions: NoSubqueryCondition[] = [];\n let conditionsRemoved = false;\n for (const cond of filters.conditions) {\n const transformed = transformFilters(cond);\n // If any branch of the OR ends up empty, the entire OR needs\n // to be removed.\n if (transformed.filters === undefined && filters.type === 'or') {\n return {filters: undefined, conditionsRemoved: true};\n }\n conditionsRemoved = conditionsRemoved || transformed.conditionsRemoved;\n if (transformed.filters) {\n transformedConditions.push(transformed.filters);\n }\n }\n return {\n filters: simplifyCondition({\n type: filters.type,\n conditions: transformedConditions,\n }) as NoSubqueryCondition,\n conditionsRemoved,\n };\n }\n default:\n unreachable(filters);\n }\n}\n"],"names":["impl"],"mappings":";;;AAyBO,SAAS,gBACd,WACuB;AACvB,MAAI,UAAU,SAAS,UAAU;AAC/B,UAAM,aAAa,UAAU,WAAW,IAAI,CAAA,MAAK,gBAAgB,CAAC,CAAC;AACn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C,EAClD,SAAS,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI;IA6B/B,IAAI,IAAI,IACmB,CAAC,CAC3B;IAED,WAAW,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;IAqBjC,OAAO;IAkBP,IAAI,CAAC,MAAM,EAAE,MAAM;IAMnB,KAAK;IAQL,SAAS,CAAC,GAAG,EAAE,GAAG;CAGnB"}
@@ -1,39 +1,7 @@
1
1
  import { assert } from "../../../shared/src/asserts.js";
2
- import { mapValues } from "../../../shared/src/objects.js";
3
2
  import { emptyArray } from "../../../shared/src/sentinels.js";
4
3
  import { skipYields } from "./operator.js";
5
- import { applyChanges } from "./view-apply-change.js";
6
- function expandNode(node) {
7
- return {
8
- row: node.row,
9
- relationships: mapValues(
10
- node.relationships,
11
- (v) => Array.from(skipYields(v()), expandNode)
12
- )
13
- };
14
- }
15
- function expandChange(change) {
16
- switch (change.type) {
17
- case "add":
18
- case "remove":
19
- return { type: change.type, node: expandNode(change.node) };
20
- case "edit":
21
- return {
22
- type: "edit",
23
- node: expandNode(change.node),
24
- oldNode: expandNode(change.oldNode)
25
- };
26
- case "child":
27
- return {
28
- type: "child",
29
- node: expandNode(change.node),
30
- child: {
31
- relationshipName: change.child.relationshipName,
32
- change: expandChange(change.child.change)
33
- }
34
- };
35
- }
36
- }
4
+ import { applyChange } from "./view-apply-change.js";
37
5
  class ArrayView {
38
6
  #input;
39
7
  #listeners = /* @__PURE__ */ new Set();
@@ -47,8 +15,6 @@ class ArrayView {
47
15
  #resultType = "unknown";
48
16
  #error;
49
17
  #updateTTL;
50
- // Pending changes buffered for batch application (O(N + K) optimization)
51
- #pendingChanges = [];
52
18
  constructor(input, format, queryComplete, updateTTL) {
53
19
  this.#input = input;
54
20
  this.#schema = input.getSchema();
@@ -62,34 +28,20 @@ class ArrayView {
62
28
  this.#resultType = "error";
63
29
  this.#error = queryComplete;
64
30
  } else {
65
- const flushAndFire = () => this.#dirty ? this.flush() : this.#fireListeners();
66
31
  void queryComplete.then(() => {
67
32
  this.#resultType = "complete";
68
- flushAndFire();
33
+ this.#fireListeners();
69
34
  }).catch((e) => {
70
35
  this.#resultType = "error";
71
36
  this.#error = e;
72
- flushAndFire();
37
+ this.#fireListeners();
73
38
  });
74
39
  }
75
40
  this.#hydrate();
76
41
  }
77
42
  get data() {
78
- this.#applyPendingChanges();
79
43
  return this.#root[""];
80
44
  }
81
- #applyPendingChanges() {
82
- if (this.#pendingChanges.length > 0) {
83
- this.#root = applyChanges(
84
- this.#root,
85
- this.#pendingChanges,
86
- this.#schema,
87
- "",
88
- this.#format
89
- );
90
- this.#pendingChanges = [];
91
- }
92
- }
93
45
  addListener(listener) {
94
46
  assert(!this.#listeners.has(listener), "Listener already registered");
95
47
  this.#listeners.add(listener);
@@ -112,10 +64,9 @@ class ArrayView {
112
64
  #hydrate() {
113
65
  this.#dirty = true;
114
66
  for (const node of skipYields(this.#input.fetch({}))) {
115
- const expanded = expandNode(node);
116
- this.#root = applyChanges(
67
+ applyChange(
117
68
  this.#root,
118
- [{ type: "add", node: expanded }],
69
+ { type: "add", node },
119
70
  this.#schema,
120
71
  "",
121
72
  this.#format
@@ -125,8 +76,7 @@ class ArrayView {
125
76
  }
126
77
  push(change) {
127
78
  this.#dirty = true;
128
- const expanded = expandChange(change);
129
- this.#pendingChanges.push(expanded);
79
+ applyChange(this.#root, change, this.#schema, "", this.#format);
130
80
  return emptyArray;
131
81
  }
132
82
  flush() {
@@ -134,7 +84,6 @@ class ArrayView {
134
84
  return;
135
85
  }
136
86
  this.#dirty = false;
137
- this.#applyPendingChanges();
138
87
  this.#fireListeners();
139
88
  }
140
89
  updateTTL(ttl) {
@@ -1 +1 @@
1
- {"version":3,"file":"array-view.js","sources":["../../../../../zql/src/ivm/array-view.ts"],"sourcesContent":["import {assert} from '../../../shared/src/asserts.ts';\nimport type {Immutable} from '../../../shared/src/immutable.ts';\nimport {mapValues} from '../../../shared/src/objects.ts';\nimport {emptyArray} from '../../../shared/src/sentinels.ts';\nimport type {ErroredQuery} from '../../../zero-protocol/src/custom-queries.ts';\nimport type {TTL} from '../query/ttl.ts';\nimport type {Listener, ResultType, TypedView} from '../query/typed-view.ts';\nimport type {Change} from './change.ts';\nimport type {Node} from './data.ts';\nimport {skipYields, type Input, type Output} from './operator.ts';\nimport type {SourceSchema} from './schema.ts';\nimport {\n applyChanges,\n type ExpandedNode,\n type ViewChange,\n} from './view-apply-change.ts';\nimport type {Entry, Format, View} from './view.ts';\n\n/**\n * Eagerly expand a Node's lazy relationship generators into arrays.\n * This captures the current state of the source at the moment of expansion.\n */\nfunction expandNode(node: Node): ExpandedNode {\n return {\n row: node.row,\n relationships: mapValues(node.relationships, v =>\n Array.from(skipYields(v()), expandNode),\n ),\n };\n}\n\n/**\n * Expand a Change by eagerly evaluating all lazy relationship generators.\n */\nfunction expandChange(change: Change): ViewChange {\n switch (change.type) {\n case 'add':\n case 'remove':\n return {type: change.type, node: expandNode(change.node)};\n case 'edit':\n return {\n type: 'edit',\n node: expandNode(change.node),\n oldNode: expandNode(change.oldNode),\n };\n case 'child':\n return {\n type: 'child',\n node: expandNode(change.node),\n child: {\n relationshipName: change.child.relationshipName,\n change: expandChange(change.child.change),\n },\n };\n }\n}\n\n/**\n * Implements a materialized view of the output of an operator.\n *\n * It might seem more efficient to use an immutable b-tree for the\n * materialization, but it's not so clear. Inserts in the middle are\n * asymptotically slower in an array, but can often be done with zero\n * allocations, where changes to the b-tree will often require several allocs.\n *\n * Also the plain array view is more convenient for consumers since you can dump\n * it into console to see what it is, rather than having to iterate it.\n */\nexport class ArrayView<V extends View> implements Output, TypedView<V> {\n readonly #input: Input;\n readonly #listeners = new Set<Listener<V>>();\n readonly #schema: SourceSchema;\n readonly #format: Format;\n\n // Synthetic \"root\" entry that has a single \"\" relationship, so that we can\n // treat all changes, including the root change, generically.\n #root: Entry;\n\n onDestroy: (() => void) | undefined;\n\n #dirty = false;\n #resultType: ResultType = 'unknown';\n #error: ErroredQuery | undefined;\n readonly #updateTTL: (ttl: TTL) => void;\n\n // Pending changes buffered for batch application (O(N + K) optimization)\n #pendingChanges: ViewChange[] = [];\n\n constructor(\n input: Input,\n format: Format,\n queryComplete: true | ErroredQuery | Promise<true>,\n updateTTL: (ttl: TTL) => void,\n ) {\n this.#input = input;\n this.#schema = input.getSchema();\n this.#format = format;\n this.#updateTTL = updateTTL;\n this.#root = {'': format.singular ? undefined : []};\n input.setOutput(this);\n\n if (queryComplete === true) {\n this.#resultType = 'complete';\n } else if ('error' in queryComplete) {\n this.#resultType = 'error';\n this.#error = queryComplete;\n } else {\n const flushAndFire = () =>\n this.#dirty ? this.flush() : this.#fireListeners();\n void queryComplete\n .then(() => {\n this.#resultType = 'complete';\n flushAndFire();\n })\n .catch((e: ErroredQuery) => {\n this.#resultType = 'error';\n this.#error = e;\n flushAndFire();\n });\n }\n this.#hydrate();\n }\n\n get data() {\n // Auto-flush for backwards compatibility. Recommended: push() then flush().\n //\n // push(A) ──► buffer ──► push(B) ──► buffer ──► flush() ──► apply all\n // │\n // Legacy code may read .data here ─────────────────┘ (before flush)\n // │\n // ▼\n // Without auto-flush: stale data (missing A, B)\n // With auto-flush: current data (has A, B)\n this.#applyPendingChanges();\n return this.#root[''] as V;\n }\n\n #applyPendingChanges() {\n if (this.#pendingChanges.length > 0) {\n this.#root = applyChanges(\n this.#root,\n this.#pendingChanges,\n this.#schema,\n '',\n this.#format,\n );\n this.#pendingChanges = [];\n }\n }\n\n addListener(listener: Listener<V>) {\n assert(!this.#listeners.has(listener), 'Listener already registered');\n this.#listeners.add(listener);\n\n this.#fireListener(listener);\n\n return () => {\n this.#listeners.delete(listener);\n };\n }\n\n #fireListeners() {\n for (const listener of this.#listeners) {\n this.#fireListener(listener);\n }\n }\n\n #fireListener(listener: Listener<V>) {\n listener(this.data as Immutable<V>, this.#resultType, this.#error);\n }\n\n destroy() {\n this.onDestroy?.();\n }\n\n #hydrate() {\n this.#dirty = true;\n // During hydration, expand and apply nodes immediately\n for (const node of skipYields(this.#input.fetch({}))) {\n const expanded = expandNode(node);\n this.#root = applyChanges(\n this.#root,\n [{type: 'add', node: expanded}],\n this.#schema,\n '',\n this.#format,\n );\n }\n this.flush();\n }\n\n push(change: Change) {\n this.#dirty = true;\n // Eagerly expand the change to capture current source state.\n // This is critical: lazy generators would see stale data if deferred.\n // Buffer the change for batch application (O(N + K) optimization).\n const expanded = expandChange(change);\n this.#pendingChanges.push(expanded);\n return emptyArray;\n }\n\n flush() {\n if (!this.#dirty) {\n return;\n }\n this.#dirty = false;\n // Apply all pending changes in one batch (O(N + K) optimization)\n this.#applyPendingChanges();\n this.#fireListeners();\n }\n\n updateTTL(ttl: TTL) {\n this.#updateTTL(ttl);\n }\n}\n"],"names":[],"mappings":";;;;;AAsBA,SAAS,WAAW,MAA0B;AAC5C,SAAO;AAAA,IACL,KAAK,KAAK;AAAA,IACV,eAAe;AAAA,MAAU,KAAK;AAAA,MAAe,OAC3C,MAAM,KAAK,WAAW,EAAA,CAAG,GAAG,UAAU;AAAA,IAAA;AAAA,EACxC;AAEJ;AAKA,SAAS,aAAa,QAA4B;AAChD,UAAQ,OAAO,MAAA;AAAA,IACb,KAAK;AAAA,IACL,KAAK;AACH,aAAO,EAAC,MAAM,OAAO,MAAM,MAAM,WAAW,OAAO,IAAI,EAAA;AAAA,IACzD,KAAK;AACH,aAAO;AAAA,QACL,MAAM;AAAA,QACN,MAAM,WAAW,OAAO,IAAI;AAAA,QAC5B,SAAS,WAAW,OAAO,OAAO;AAAA,MAAA;AAAA,IAEtC,KAAK;AACH,aAAO;AAAA,QACL,MAAM;AAAA,QACN,MAAM,WAAW,OAAO,IAAI;AAAA,QAC5B,OAAO;AAAA,UACL,kBAAkB,OAAO,MAAM;AAAA,UAC/B,QAAQ,aAAa,OAAO,MAAM,MAAM;AAAA,QAAA;AAAA,MAC1C;AAAA,EACF;AAEN;AAaO,MAAM,UAA0D;AAAA,EAC5D;AAAA,EACA,iCAAiB,IAAA;AAAA,EACjB;AAAA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ACjC;AAAA,EACF;AAAA,EAEA,iBAAiB;AACf,eAAW,YAAY,KAAK,YAAY;AACtC,WAAK,cAAc,QAAQ;AAAA,IAC7B;AAAA,EACF;AAAA,EAEA,cAAc,UAAuB;AACnC,aAAS,KAAK,MAAsB,KAAK,aAAa,KAAK,MAAM;AAAA,EACnE;AAAA,EAEA,UAAU;AACR,SAAK,YAAA;AAAA,EACP;AAAA,EAEA,WAAW;AACT,SAAK,SAAS;AAEd,eAAW,QAAQ,WAAW,KAAK,OAAO,MAAM,CAAA,CAAE,CAAC,GAAG;AACpD,YAAM,WAAW,WAAW,IAAI;AAChC,WAAK,QAAQ;AAAA,QACX,KAAK;AAAA,QACL,CAAC,EAAC,MAAM,OAAO,MAAM,UAAS;AAAA,QAC9B,KAAK;AAAA,QACL;AAAA,QACA,KAAK;AAAA,MAAA;AAAA,IAET;AACA,SAAK,MAAA;AAAA,EACP;AAAA,EAEA,KAAK,QAAgB;AACnB,SAAK,SAAS;AAId,UAAM,WAAW,aAAa,MAAM;AACpC,SAAK,gBAAgB,KAAK,QAAQ;AAClC,WAAO;AAAA,EACT;AAAA,EAEA,QAAQ;AACN,QAAI,CAAC,KAAK,QAAQ;AAChB;AAAA,IACF;AACA,SAAK,SAAS;AAEd,SAAK,qBAAA;AACL,SAAK,eAAA;AAAA,EACP;AAAA,EAEA,UAAU,KAAU;AAClB,SAAK,WAAW,GAAG;AAAA,EACrB;AACF;"}
1
+ {"version":3,"file":"array-view.js","sources":["../../../../../zql/src/ivm/array-view.ts"],"sourcesContent":["import {assert} from '../../../shared/src/asserts.ts';\nimport type {Immutable} from '../../../shared/src/immutable.ts';\nimport {emptyArray} from '../../../shared/src/sentinels.ts';\nimport type {ErroredQuery} from '../../../zero-protocol/src/custom-queries.ts';\nimport type {TTL} from '../query/ttl.ts';\nimport type {Listener, ResultType, TypedView} from '../query/typed-view.ts';\nimport type {Change} from './change.ts';\nimport {skipYields, type Input, type Output} from './operator.ts';\nimport type {SourceSchema} from './schema.ts';\nimport {applyChange} from './view-apply-change.ts';\nimport type {Entry, Format, View} from './view.ts';\n\n/**\n * Implements a materialized view of the output of an operator.\n *\n * It might seem more efficient to use an immutable b-tree for the\n * materialization, but it's not so clear. Inserts in the middle are\n * asymptotically slower in an array, but can often be done with zero\n * allocations, where changes to the b-tree will often require several allocs.\n *\n * Also the plain array view is more convenient for consumers since you can dump\n * it into console to see what it is, rather than having to iterate it.\n */\nexport class ArrayView<V extends View> implements Output, TypedView<V> {\n readonly #input: Input;\n readonly #listeners = new Set<Listener<V>>();\n readonly #schema: SourceSchema;\n readonly #format: Format;\n\n // Synthetic \"root\" entry that has a single \"\" relationship, so that we can\n // treat all changes, including the root change, generically.\n readonly #root: Entry;\n\n onDestroy: (() => void) | undefined;\n\n #dirty = false;\n #resultType: ResultType = 'unknown';\n #error: ErroredQuery | undefined;\n readonly #updateTTL: (ttl: TTL) => void;\n\n constructor(\n input: Input,\n format: Format,\n queryComplete: true | ErroredQuery | Promise<true>,\n updateTTL: (ttl: TTL) => void,\n ) {\n this.#input = input;\n this.#schema = input.getSchema();\n this.#format = format;\n this.#updateTTL = updateTTL;\n this.#root = {'': format.singular ? undefined : []};\n input.setOutput(this);\n\n if (queryComplete === true) {\n this.#resultType = 'complete';\n } else if ('error' in queryComplete) {\n this.#resultType = 'error';\n this.#error = queryComplete;\n } else {\n void queryComplete\n .then(() => {\n this.#resultType = 'complete';\n this.#fireListeners();\n })\n .catch(e => {\n this.#resultType = 'error';\n this.#error = e;\n this.#fireListeners();\n });\n }\n this.#hydrate();\n }\n\n get data() {\n return this.#root[''] as V;\n }\n\n addListener(listener: Listener<V>) {\n assert(!this.#listeners.has(listener), 'Listener already registered');\n this.#listeners.add(listener);\n\n this.#fireListener(listener);\n\n return () => {\n this.#listeners.delete(listener);\n };\n }\n\n #fireListeners() {\n for (const listener of this.#listeners) {\n this.#fireListener(listener);\n }\n }\n\n #fireListener(listener: Listener<V>) {\n listener(this.data as Immutable<V>, this.#resultType, this.#error);\n }\n\n destroy() {\n this.onDestroy?.();\n }\n\n #hydrate() {\n this.#dirty = true;\n for (const node of skipYields(this.#input.fetch({}))) {\n applyChange(\n this.#root,\n {type: 'add', node},\n this.#schema,\n '',\n this.#format,\n );\n }\n this.flush();\n }\n\n push(change: Change) {\n this.#dirty = true;\n applyChange(this.#root, change, this.#schema, '', this.#format);\n return emptyArray;\n }\n\n flush() {\n if (!this.#dirty) {\n return;\n }\n this.#dirty = false;\n this.#fireListeners();\n }\n\n updateTTL(ttl: TTL) {\n this.#updateTTL(ttl);\n }\n}\n"],"names":[],"mappings":";;;;AAuBO,MAAM,UAA0D;AAAA,EAC5D;AAAA,EACA,iCAAiB,IAAA;AAAA,EACjB;AAAA,EACA;AAAA;AAAA;AAAA,EAIA;AAAA,EAET;AAAA,EAEA,SAAS;AAAA,EACT,cAA0B;AAAA,EAC1B;AAAA,EACS;AAAA,EAET,YACE,OACA,QACA,eACA,WACA;AACA,SAAK,SAAS;AACd,SAAK,UAAU,MAAM,UAAA;AACrB,SAAK,UAAU;AACf,SAAK,aAAa;AAClB,SAAK,QAAQ,EAAC,IAAI,OAAO,WAAW,SAAY,GAAC;AACjD,UAAM,UAAU,IAAI;AAEpB,QAAI,kBAAkB,MAAM;AAC1B,WAAK,cAAc;AAAA,IACrB,WAAW,WAAW,eAAe;AACnC,WAAK,cAAc;AACnB,WAAK,SAAS;AAAA,IAChB,OAAO;AACL,WAAK,cACF,KAAK,MAAM;AACV,aAAK,cAAc;AACnB,aAAK,eAAA;AAAA,MACP,CAAC,EACA,MAAM,CAAA,MAAK;AACV,aAAK,cAAc;AACnB,aAAK,SAAS;AACd,aAAK,eAAA;AAAA,MACP,CAAC;AAAA,IACL;AACA,SAAK,SAAA;AAAA,EACP;AAAA,EAEA,IAAI,OAAO;AACT,WAAO,KAAK,MAAM,EAAE;AAAA,EACtB;AAAA,EAEA,YAAY,UAAuB;AACjC,WAAO,CAAC,KAAK,WAAW,IAAI,QAAQ,GAAG,6BAA6B;AACpE,SAAK,WAAW,IAAI,QAAQ;AAE5B,SAAK,cAAc,QAAQ;AAE3B,WAAO,MAAM;AACX,WAAK,WAAW,OAAO,QAAQ;AAAA,IACjC;AAAA,EACF;AAAA,EAEA,iBAAiB;AACf,eAAW,YAAY,KAAK,YAAY;AACtC,WAAK,cAAc,QAAQ;AAAA,IAC7B;AAAA,EACF;AAAA,EAEA,cAAc,UAAuB;AACnC,aAAS,KAAK,MAAsB,KAAK,aAAa,KAAK,MAAM;AAAA,EACnE;AAAA,EAEA,UAAU;AACR,SAAK,YAAA;AAAA,EACP;AAAA,EAEA,WAAW;AACT,SAAK,SAAS;AACd,eAAW,QAAQ,WAAW,KAAK,OAAO,MAAM,CAAA,CAAE,CAAC,GAAG;AACpD;AAAA,QACE,KAAK;AAAA,QACL,EAAC,MAAM,OAAO,KAAA;AAAA,QACd,KAAK;AAAA,QACL;AAAA,QACA,KAAK;AAAA,MAAA;AAAA,IAET;AACA,SAAK,MAAA;AAAA,EACP;AAAA,EAEA,KAAK,QAAgB;AACnB,SAAK,SAAS;AACd,gBAAY,KAAK,OAAO,QAAQ,KAAK,SAAS,IAAI,KAAK,OAAO;AAC9D,WAAO;AAAA,EACT;AAAA,EAEA,QAAQ;AACN,QAAI,CAAC,KAAK,QAAQ;AAChB;AAAA,IACF;AACA,SAAK,SAAS;AACd,SAAK,eAAA;AAAA,EACP;AAAA,EAEA,UAAU,KAAU;AAClB,SAAK,WAAW,GAAG;AAAA,EACrB;AACF;"}
@@ -1,35 +1,9 @@
1
- import type { Writable } from '../../../shared/src/writable.ts';
2
1
  import type { Row } from '../../../zero-protocol/src/data.ts';
3
2
  import { type Node } from './data.ts';
4
3
  import type { SourceSchema } from './schema.ts';
5
4
  import type { Entry, Format } from './view.ts';
6
5
  export declare const refCountSymbol: unique symbol;
7
6
  export declare const idSymbol: unique symbol;
8
- type ReadonlyMetaEntry = Entry & {
9
- readonly [refCountSymbol]: number;
10
- readonly [idSymbol]?: string | undefined;
11
- };
12
- type MutableMetaEntry = Writable<ReadonlyMetaEntry>;
13
- /**
14
- * MetaEntry is an Entry with internal tracking fields for reference counting
15
- * and stable identity. All entries in the view tree are MetaEntry instances,
16
- * created through makeNewMetaEntry().
17
- */
18
- type MetaEntry<M extends Mutate> = M extends true ? MutableMetaEntry : ReadonlyMetaEntry;
19
- /**
20
- * Node with eagerly-expanded relationships (arrays instead of generators).
21
- * Used when batching changes to capture source state at push time.
22
- */
23
- export type ExpandedNode = {
24
- row: Row;
25
- relationships: Record<string, ExpandedNode[]>;
26
- };
27
- /**
28
- * A node for view changes. Can be either:
29
- * - A lazy Node with generator relationships (original behavior)
30
- * - An ExpandedNode with pre-computed relationship arrays (for batching)
31
- */
32
- export type ViewNode = Node | ExpandedNode;
33
7
  /**
34
8
  * `applyChange` does not consume the `relationships` of `ChildChange#node`,
35
9
  * `EditChange#node` and `EditChange#oldNode`. The `ViewChange` type
@@ -41,11 +15,11 @@ export type RowOnlyNode = {
41
15
  };
42
16
  export type AddViewChange = {
43
17
  type: 'add';
44
- node: ViewNode;
18
+ node: Node;
45
19
  };
46
20
  export type RemoveViewChange = {
47
21
  type: 'remove';
48
- node: ViewNode;
22
+ node: Node;
49
23
  };
50
24
  type ChildViewChange = {
51
25
  type: 'child';
@@ -69,27 +43,6 @@ export interface RefCountMap {
69
43
  set(entry: Entry, refCount: number): void;
70
44
  delete(entry: Entry): boolean;
71
45
  }
72
- type Mutate = boolean;
73
- type WithIDs = boolean;
74
- /**
75
- * Immutable view update. Returns new Entry on change, same Entry if unchanged.
76
- * Unchanged entries keep identity, enabling shallow comparison optimizations
77
- * in UI frameworks (React.memo, Solid's fine-grained reactivity, etc).
78
- *
79
- * Propagation: recurse DOWN to find target, copy objects on the way UP.
80
- * Siblings keep original refs. Only the ancestor path is copied.
81
- *
82
- * root {users:[A,B], items:[C,D,E]} --edit C--> root' {users:[A,B], items':[C',D,E]}
83
- * │ same ref │ │ │
84
- * └─────────────────┴── unchanged ──────────────┘ new array C' new, D/E same
85
- */
86
- export declare function applyChange(parentEntry: Entry, change: ViewChange, schema: SourceSchema, relationship: string, format: Format, withIDs?: boolean, mutate?: boolean): Entry;
87
- export declare function applyChangeInternal<M extends Mutate>(parentEntry: MetaEntry<M>, change: ViewChange, schema: SourceSchema, relationship: string, format: Format, withIDs: WithIDs, mutate: M): MetaEntry<M>;
88
- /**
89
- * Batch apply multiple changes to an Entry tree.
90
- * For small batches or complex cases, falls back to sequential applyChange.
91
- * Future optimization: O(N + K) batch processing for large K.
92
- */
93
- export declare function applyChanges(parentEntry: Entry, changes: ViewChange[], schema: SourceSchema, relationship: string, format: Format, withIDs?: WithIDs, mutate?: Mutate): Entry;
46
+ export declare function applyChange(parentEntry: Entry, change: ViewChange, schema: SourceSchema, relationship: string, format: Format, withIDs?: boolean): void;
94
47
  export {};
95
48
  //# sourceMappingURL=view-apply-change.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"view-apply-change.d.ts","sourceRoot":"","sources":["../../../../../zql/src/ivm/view-apply-change.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,iCAAiC,CAAC;AAC9D,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,oCAAoC,CAAC;AAC5D,OAAO,EAAkB,KAAK,IAAI,EAAC,MAAM,WAAW,CAAC;AAErD,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAC,KAAK,EAAE,MAAM,EAAC,MAAM,WAAW,CAAC;AAE7C,eAAO,MAAM,cAAc,eAAe,CAAC;AAC3C,eAAO,MAAM,QAAQ,eAAe,CAAC;AAErC,KAAK,iBAAiB,GAAG,KAAK,GAAG;IAC/B,QAAQ,CAAC,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1C,CAAC;AAEF,KAAK,gBAAgB,GAAG,QAAQ,CAAC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