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

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 (568) hide show
  1. package/out/analyze-query/src/bin-analyze.js +8 -9
  2. package/out/analyze-query/src/bin-analyze.js.map +1 -1
  3. package/out/replicache/src/btree/node.d.ts.map +1 -1
  4. package/out/replicache/src/btree/node.js +6 -3
  5. package/out/replicache/src/btree/node.js.map +1 -1
  6. package/out/replicache/src/btree/read.d.ts +1 -12
  7. package/out/replicache/src/btree/read.d.ts.map +1 -1
  8. package/out/replicache/src/btree/read.js +12 -24
  9. package/out/replicache/src/btree/read.js.map +1 -1
  10. package/out/replicache/src/dag/gc.d.ts.map +1 -1
  11. package/out/replicache/src/dag/gc.js +11 -8
  12. package/out/replicache/src/dag/gc.js.map +1 -1
  13. package/out/replicache/src/dag/store-impl.d.ts +2 -12
  14. package/out/replicache/src/dag/store-impl.d.ts.map +1 -1
  15. package/out/replicache/src/dag/store-impl.js +8 -22
  16. package/out/replicache/src/dag/store-impl.js.map +1 -1
  17. package/out/replicache/src/db/rebase.d.ts +2 -14
  18. package/out/replicache/src/db/rebase.d.ts.map +1 -1
  19. package/out/replicache/src/db/rebase.js +5 -27
  20. package/out/replicache/src/db/rebase.js.map +1 -1
  21. package/out/replicache/src/db/write.js.map +1 -1
  22. package/out/replicache/src/kv/expo-sqlite/store.d.ts.map +1 -1
  23. package/out/replicache/src/kv/expo-sqlite/store.js +5 -28
  24. package/out/replicache/src/kv/expo-sqlite/store.js.map +1 -1
  25. package/out/replicache/src/kv/idb-store-with-mem-fallback.d.ts +5 -15
  26. package/out/replicache/src/kv/idb-store-with-mem-fallback.d.ts.map +1 -1
  27. package/out/replicache/src/kv/idb-store-with-mem-fallback.js +25 -25
  28. package/out/replicache/src/kv/idb-store-with-mem-fallback.js.map +1 -1
  29. package/out/replicache/src/kv/idb-store.d.ts +0 -9
  30. package/out/replicache/src/kv/idb-store.d.ts.map +1 -1
  31. package/out/replicache/src/kv/idb-store.js +2 -14
  32. package/out/replicache/src/kv/idb-store.js.map +1 -1
  33. package/out/replicache/src/kv/mem-store.d.ts +0 -1
  34. package/out/replicache/src/kv/mem-store.d.ts.map +1 -1
  35. package/out/replicache/src/kv/mem-store.js +0 -3
  36. package/out/replicache/src/kv/mem-store.js.map +1 -1
  37. package/out/replicache/src/kv/op-sqlite/store.d.ts.map +1 -1
  38. package/out/replicache/src/kv/op-sqlite/store.js +1 -1
  39. package/out/replicache/src/kv/op-sqlite/store.js.map +1 -1
  40. package/out/replicache/src/kv/sqlite-store.d.ts +1 -13
  41. package/out/replicache/src/kv/sqlite-store.d.ts.map +1 -1
  42. package/out/replicache/src/kv/sqlite-store.js +6 -73
  43. package/out/replicache/src/kv/sqlite-store.js.map +1 -1
  44. package/out/replicache/src/kv/store.d.ts +0 -6
  45. package/out/replicache/src/kv/store.d.ts.map +1 -1
  46. package/out/replicache/src/persist/collect-idb-databases.d.ts +5 -10
  47. package/out/replicache/src/persist/collect-idb-databases.d.ts.map +1 -1
  48. package/out/replicache/src/persist/collect-idb-databases.js +9 -16
  49. package/out/replicache/src/persist/collect-idb-databases.js.map +1 -1
  50. package/out/replicache/src/persist/persist.d.ts.map +1 -1
  51. package/out/replicache/src/persist/persist.js +6 -13
  52. package/out/replicache/src/persist/persist.js.map +1 -1
  53. package/out/replicache/src/persist/refresh.js +2 -6
  54. package/out/replicache/src/persist/refresh.js.map +1 -1
  55. package/out/replicache/src/replicache-impl.d.ts +3 -14
  56. package/out/replicache/src/replicache-impl.d.ts.map +1 -1
  57. package/out/replicache/src/replicache-impl.js +11 -118
  58. package/out/replicache/src/replicache-impl.js.map +1 -1
  59. package/out/replicache/src/replicache-options.d.ts +0 -9
  60. package/out/replicache/src/replicache-options.d.ts.map +1 -1
  61. package/out/replicache/src/transactions.d.ts.map +1 -1
  62. package/out/replicache/src/transactions.js +1 -1
  63. package/out/replicache/src/transactions.js.map +1 -1
  64. package/out/shared/src/arrays.d.ts +0 -5
  65. package/out/shared/src/arrays.d.ts.map +1 -1
  66. package/out/shared/src/arrays.js +24 -8
  67. package/out/shared/src/arrays.js.map +1 -1
  68. package/out/shared/src/base64.d.ts +19 -0
  69. package/out/shared/src/base64.d.ts.map +1 -0
  70. package/out/shared/src/base64.js +40 -0
  71. package/out/shared/src/base64.js.map +1 -0
  72. package/out/shared/src/error.d.ts +0 -11
  73. package/out/shared/src/error.d.ts.map +1 -1
  74. package/out/shared/src/error.js +1 -35
  75. package/out/shared/src/error.js.map +1 -1
  76. package/out/shared/src/hash.d.ts +0 -1
  77. package/out/shared/src/hash.d.ts.map +1 -1
  78. package/out/shared/src/hash.js +10 -87
  79. package/out/shared/src/hash.js.map +1 -1
  80. package/out/shared/src/iterables.d.ts +0 -2
  81. package/out/shared/src/iterables.d.ts.map +1 -1
  82. package/out/shared/src/iterables.js +1 -18
  83. package/out/shared/src/iterables.js.map +1 -1
  84. package/out/shared/src/json.d.ts.map +1 -1
  85. package/out/shared/src/json.js +2 -2
  86. package/out/shared/src/json.js.map +1 -1
  87. package/out/shared/src/map.d.ts +2 -24
  88. package/out/shared/src/map.d.ts.map +1 -1
  89. package/out/shared/src/map.js +4 -18
  90. package/out/shared/src/map.js.map +1 -1
  91. package/out/shared/src/ring-buffer.d.ts +0 -8
  92. package/out/shared/src/ring-buffer.d.ts.map +1 -1
  93. package/out/shared/src/ring-buffer.js +1 -22
  94. package/out/shared/src/ring-buffer.js.map +1 -1
  95. package/out/z2s/src/sql.d.ts.map +1 -1
  96. package/out/z2s/src/sql.js +2 -2
  97. package/out/z2s/src/sql.js.map +1 -1
  98. package/out/zero/package.js +3 -2
  99. package/out/zero/package.js.map +1 -1
  100. package/out/zero-cache/src/auth/read-authorizer.js +1 -1
  101. package/out/zero-cache/src/auth/write-authorizer.d.ts.map +1 -1
  102. package/out/zero-cache/src/auth/write-authorizer.js +0 -1
  103. package/out/zero-cache/src/auth/write-authorizer.js.map +1 -1
  104. package/out/zero-cache/src/config/zero-config.d.ts +2 -42
  105. package/out/zero-cache/src/config/zero-config.d.ts.map +1 -1
  106. package/out/zero-cache/src/config/zero-config.js +28 -149
  107. package/out/zero-cache/src/config/zero-config.js.map +1 -1
  108. package/out/zero-cache/src/custom-queries/transform-query.js +1 -1
  109. package/out/zero-cache/src/db/create.d.ts.map +1 -1
  110. package/out/zero-cache/src/db/create.js +1 -4
  111. package/out/zero-cache/src/db/create.js.map +1 -1
  112. package/out/zero-cache/src/db/lite-tables.d.ts +2 -10
  113. package/out/zero-cache/src/db/lite-tables.d.ts.map +1 -1
  114. package/out/zero-cache/src/db/lite-tables.js +6 -10
  115. package/out/zero-cache/src/db/lite-tables.js.map +1 -1
  116. package/out/zero-cache/src/db/specs.d.ts +0 -41
  117. package/out/zero-cache/src/db/specs.d.ts.map +1 -1
  118. package/out/zero-cache/src/db/specs.js +3 -30
  119. package/out/zero-cache/src/db/specs.js.map +1 -1
  120. package/out/zero-cache/src/observability/metrics.d.ts.map +1 -1
  121. package/out/zero-cache/src/observability/metrics.js +7 -2
  122. package/out/zero-cache/src/observability/metrics.js.map +1 -1
  123. package/out/zero-cache/src/server/change-streamer.d.ts.map +1 -1
  124. package/out/zero-cache/src/server/change-streamer.js +4 -13
  125. package/out/zero-cache/src/server/change-streamer.js.map +1 -1
  126. package/out/zero-cache/src/server/inspector-delegate.d.ts +2 -18
  127. package/out/zero-cache/src/server/inspector-delegate.d.ts.map +1 -1
  128. package/out/zero-cache/src/server/inspector-delegate.js +17 -25
  129. package/out/zero-cache/src/server/inspector-delegate.js.map +1 -1
  130. package/out/zero-cache/src/server/main.d.ts.map +1 -1
  131. package/out/zero-cache/src/server/main.js +1 -8
  132. package/out/zero-cache/src/server/main.js.map +1 -1
  133. package/out/zero-cache/src/server/mutator.js +0 -2
  134. package/out/zero-cache/src/server/mutator.js.map +1 -1
  135. package/out/zero-cache/src/server/reaper.d.ts.map +1 -1
  136. package/out/zero-cache/src/server/reaper.js +0 -2
  137. package/out/zero-cache/src/server/reaper.js.map +1 -1
  138. package/out/zero-cache/src/server/replicator.d.ts.map +1 -1
  139. package/out/zero-cache/src/server/replicator.js +2 -8
  140. package/out/zero-cache/src/server/replicator.js.map +1 -1
  141. package/out/zero-cache/src/server/runner/zero-dispatcher.d.ts.map +1 -1
  142. package/out/zero-cache/src/server/runner/zero-dispatcher.js +0 -3
  143. package/out/zero-cache/src/server/runner/zero-dispatcher.js.map +1 -1
  144. package/out/zero-cache/src/server/syncer.d.ts.map +1 -1
  145. package/out/zero-cache/src/server/syncer.js +1 -5
  146. package/out/zero-cache/src/server/syncer.js.map +1 -1
  147. package/out/zero-cache/src/services/analyze.d.ts.map +1 -1
  148. package/out/zero-cache/src/services/analyze.js +9 -11
  149. package/out/zero-cache/src/services/analyze.js.map +1 -1
  150. package/out/zero-cache/src/services/change-source/common/backfill-manager.d.ts.map +1 -1
  151. package/out/zero-cache/src/services/change-source/common/backfill-manager.js +1 -14
  152. package/out/zero-cache/src/services/change-source/common/backfill-manager.js.map +1 -1
  153. package/out/zero-cache/src/services/change-source/common/change-stream-multiplexer.d.ts.map +1 -1
  154. package/out/zero-cache/src/services/change-source/common/change-stream-multiplexer.js +3 -15
  155. package/out/zero-cache/src/services/change-source/common/change-stream-multiplexer.js.map +1 -1
  156. package/out/zero-cache/src/services/change-source/pg/change-source.d.ts +1 -11
  157. package/out/zero-cache/src/services/change-source/pg/change-source.d.ts.map +1 -1
  158. package/out/zero-cache/src/services/change-source/pg/change-source.js +2 -21
  159. package/out/zero-cache/src/services/change-source/pg/change-source.js.map +1 -1
  160. package/out/zero-cache/src/services/change-source/pg/initial-sync.d.ts +0 -1
  161. package/out/zero-cache/src/services/change-source/pg/initial-sync.d.ts.map +1 -1
  162. package/out/zero-cache/src/services/change-source/pg/initial-sync.js +7 -8
  163. package/out/zero-cache/src/services/change-source/pg/initial-sync.js.map +1 -1
  164. package/out/zero-cache/src/services/change-source/pg/schema/ddl.d.ts +229 -1513
  165. package/out/zero-cache/src/services/change-source/pg/schema/ddl.d.ts.map +1 -1
  166. package/out/zero-cache/src/services/change-source/pg/schema/ddl.js +2 -2
  167. package/out/zero-cache/src/services/change-source/pg/schema/ddl.js.map +1 -1
  168. package/out/zero-cache/src/services/change-source/pg/schema/init.d.ts +1 -1
  169. package/out/zero-cache/src/services/change-source/pg/schema/init.d.ts.map +1 -1
  170. package/out/zero-cache/src/services/change-source/pg/schema/init.js +6 -15
  171. package/out/zero-cache/src/services/change-source/pg/schema/init.js.map +1 -1
  172. package/out/zero-cache/src/services/change-source/pg/schema/published.d.ts +20 -137
  173. package/out/zero-cache/src/services/change-source/pg/schema/published.d.ts.map +1 -1
  174. package/out/zero-cache/src/services/change-source/pg/schema/published.js +13 -82
  175. package/out/zero-cache/src/services/change-source/pg/schema/published.js.map +1 -1
  176. package/out/zero-cache/src/services/change-source/pg/schema/shard.d.ts +21 -128
  177. package/out/zero-cache/src/services/change-source/pg/schema/shard.d.ts.map +1 -1
  178. package/out/zero-cache/src/services/change-source/pg/schema/shard.js +5 -5
  179. package/out/zero-cache/src/services/change-source/pg/schema/shard.js.map +1 -1
  180. package/out/zero-cache/src/services/change-source/protocol/current/data.d.ts +0 -2
  181. package/out/zero-cache/src/services/change-source/protocol/current/data.d.ts.map +1 -1
  182. package/out/zero-cache/src/services/change-source/protocol/current/downstream.d.ts +0 -3
  183. package/out/zero-cache/src/services/change-source/protocol/current/downstream.d.ts.map +1 -1
  184. package/out/zero-cache/src/services/change-streamer/change-streamer-http.d.ts +0 -3
  185. package/out/zero-cache/src/services/change-streamer/change-streamer-http.d.ts.map +1 -1
  186. package/out/zero-cache/src/services/change-streamer/change-streamer-http.js +1 -3
  187. package/out/zero-cache/src/services/change-streamer/change-streamer-http.js.map +1 -1
  188. package/out/zero-cache/src/services/change-streamer/change-streamer.d.ts +0 -1
  189. package/out/zero-cache/src/services/change-streamer/change-streamer.d.ts.map +1 -1
  190. package/out/zero-cache/src/services/litestream/commands.d.ts.map +1 -1
  191. package/out/zero-cache/src/services/litestream/commands.js +3 -8
  192. package/out/zero-cache/src/services/litestream/commands.js.map +1 -1
  193. package/out/zero-cache/src/services/litestream/config-v5.yml +1 -15
  194. package/out/zero-cache/src/services/mutagen/mutagen.d.ts +0 -5
  195. package/out/zero-cache/src/services/mutagen/mutagen.d.ts.map +1 -1
  196. package/out/zero-cache/src/services/mutagen/mutagen.js +1 -7
  197. package/out/zero-cache/src/services/mutagen/mutagen.js.map +1 -1
  198. package/out/zero-cache/src/services/mutagen/pusher.d.ts +119 -119
  199. package/out/zero-cache/src/services/mutagen/pusher.d.ts.map +1 -1
  200. package/out/zero-cache/src/services/mutagen/pusher.js +6 -5
  201. package/out/zero-cache/src/services/mutagen/pusher.js.map +1 -1
  202. package/out/zero-cache/src/services/replicator/change-processor.d.ts.map +1 -1
  203. package/out/zero-cache/src/services/replicator/change-processor.js +16 -16
  204. package/out/zero-cache/src/services/replicator/change-processor.js.map +1 -1
  205. package/out/zero-cache/src/services/replicator/incremental-sync.d.ts.map +1 -1
  206. package/out/zero-cache/src/services/replicator/incremental-sync.js +0 -1
  207. package/out/zero-cache/src/services/replicator/incremental-sync.js.map +1 -1
  208. package/out/zero-cache/src/services/replicator/write-worker-client.d.ts +2 -27
  209. package/out/zero-cache/src/services/replicator/write-worker-client.d.ts.map +1 -1
  210. package/out/zero-cache/src/services/replicator/write-worker-client.js +2 -3
  211. package/out/zero-cache/src/services/replicator/write-worker-client.js.map +1 -1
  212. package/out/zero-cache/src/services/replicator/write-worker.js +5 -24
  213. package/out/zero-cache/src/services/replicator/write-worker.js.map +1 -1
  214. package/out/zero-cache/src/services/run-ast.d.ts +0 -12
  215. package/out/zero-cache/src/services/run-ast.d.ts.map +1 -1
  216. package/out/zero-cache/src/services/run-ast.js +15 -27
  217. package/out/zero-cache/src/services/run-ast.js.map +1 -1
  218. package/out/zero-cache/src/services/runner.d.ts.map +1 -1
  219. package/out/zero-cache/src/services/runner.js +1 -1
  220. package/out/zero-cache/src/services/runner.js.map +1 -1
  221. package/out/zero-cache/src/services/view-syncer/cvr.d.ts +0 -45
  222. package/out/zero-cache/src/services/view-syncer/cvr.d.ts.map +1 -1
  223. package/out/zero-cache/src/services/view-syncer/cvr.js +1 -133
  224. package/out/zero-cache/src/services/view-syncer/cvr.js.map +1 -1
  225. package/out/zero-cache/src/services/view-syncer/drain-coordinator.d.ts +1 -14
  226. package/out/zero-cache/src/services/view-syncer/drain-coordinator.d.ts.map +1 -1
  227. package/out/zero-cache/src/services/view-syncer/drain-coordinator.js +4 -30
  228. package/out/zero-cache/src/services/view-syncer/drain-coordinator.js.map +1 -1
  229. package/out/zero-cache/src/services/view-syncer/inspect-handler.d.ts +1 -1
  230. package/out/zero-cache/src/services/view-syncer/inspect-handler.d.ts.map +1 -1
  231. package/out/zero-cache/src/services/view-syncer/inspect-handler.js +2 -2
  232. package/out/zero-cache/src/services/view-syncer/inspect-handler.js.map +1 -1
  233. package/out/zero-cache/src/services/view-syncer/pipeline-driver.d.ts +1 -2
  234. package/out/zero-cache/src/services/view-syncer/pipeline-driver.d.ts.map +1 -1
  235. package/out/zero-cache/src/services/view-syncer/pipeline-driver.js +27 -48
  236. package/out/zero-cache/src/services/view-syncer/pipeline-driver.js.map +1 -1
  237. package/out/zero-cache/src/services/view-syncer/query-covering.d.ts.map +1 -1
  238. package/out/zero-cache/src/services/view-syncer/query-covering.js +6 -2
  239. package/out/zero-cache/src/services/view-syncer/query-covering.js.map +1 -1
  240. package/out/zero-cache/src/services/view-syncer/snapshotter.d.ts +4 -42
  241. package/out/zero-cache/src/services/view-syncer/snapshotter.d.ts.map +1 -1
  242. package/out/zero-cache/src/services/view-syncer/snapshotter.js +28 -117
  243. package/out/zero-cache/src/services/view-syncer/snapshotter.js.map +1 -1
  244. package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts +1 -11
  245. package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts.map +1 -1
  246. package/out/zero-cache/src/services/view-syncer/view-syncer.js +95 -466
  247. package/out/zero-cache/src/services/view-syncer/view-syncer.js.map +1 -1
  248. package/out/zero-cache/src/types/processes.d.ts +0 -32
  249. package/out/zero-cache/src/types/processes.d.ts.map +1 -1
  250. package/out/zero-cache/src/types/processes.js +4 -43
  251. package/out/zero-cache/src/types/processes.js.map +1 -1
  252. package/out/zero-cache/src/types/profiler.d.ts +0 -12
  253. package/out/zero-cache/src/types/profiler.d.ts.map +1 -1
  254. package/out/zero-cache/src/types/profiler.js +1 -46
  255. package/out/zero-cache/src/types/profiler.js.map +1 -1
  256. package/out/zero-cache/src/types/row-key.d.ts.map +1 -1
  257. package/out/zero-cache/src/types/row-key.js +5 -5
  258. package/out/zero-cache/src/types/row-key.js.map +1 -1
  259. package/out/zero-cache/src/workers/connect-params.d.ts +7 -0
  260. package/out/zero-cache/src/workers/connect-params.d.ts.map +1 -1
  261. package/out/zero-cache/src/workers/connect-params.js +20 -1
  262. package/out/zero-cache/src/workers/connect-params.js.map +1 -1
  263. package/out/zero-cache/src/workers/connection.d.ts +4 -4
  264. package/out/zero-cache/src/workers/connection.d.ts.map +1 -1
  265. package/out/zero-cache/src/workers/connection.js +8 -8
  266. package/out/zero-cache/src/workers/connection.js.map +1 -1
  267. package/out/zero-cache/src/workers/replicator.d.ts +0 -1
  268. package/out/zero-cache/src/workers/replicator.d.ts.map +1 -1
  269. package/out/zero-cache/src/workers/replicator.js +2 -4
  270. package/out/zero-cache/src/workers/replicator.js.map +1 -1
  271. package/out/zero-cache/src/workers/syncer-ws-message-handler.d.ts.map +1 -1
  272. package/out/zero-cache/src/workers/syncer-ws-message-handler.js +16 -21
  273. package/out/zero-cache/src/workers/syncer-ws-message-handler.js.map +1 -1
  274. package/out/zero-cache/src/workers/syncer.d.ts.map +1 -1
  275. package/out/zero-cache/src/workers/syncer.js +1 -10
  276. package/out/zero-cache/src/workers/syncer.js.map +1 -1
  277. package/out/zero-client/src/client/connection-manager.d.ts +0 -20
  278. package/out/zero-client/src/client/connection-manager.d.ts.map +1 -1
  279. package/out/zero-client/src/client/connection-manager.js +13 -77
  280. package/out/zero-client/src/client/connection-manager.js.map +1 -1
  281. package/out/zero-client/src/client/connection-status-enum.d.ts +0 -2
  282. package/out/zero-client/src/client/connection-status-enum.d.ts.map +1 -1
  283. package/out/zero-client/src/client/connection-status-enum.js +1 -3
  284. package/out/zero-client/src/client/connection-status-enum.js.map +1 -1
  285. package/out/zero-client/src/client/connection.d.ts +0 -6
  286. package/out/zero-client/src/client/connection.d.ts.map +1 -1
  287. package/out/zero-client/src/client/connection.js +1 -2
  288. package/out/zero-client/src/client/connection.js.map +1 -1
  289. package/out/zero-client/src/client/context.d.ts +2 -27
  290. package/out/zero-client/src/client/context.d.ts.map +1 -1
  291. package/out/zero-client/src/client/context.js +1 -112
  292. package/out/zero-client/src/client/context.js.map +1 -1
  293. package/out/zero-client/src/client/custom.js +2 -2
  294. package/out/zero-client/src/client/custom.js.map +1 -1
  295. package/out/zero-client/src/client/error.js +1 -1
  296. package/out/zero-client/src/client/inspector/lazy-inspector.js +2 -2
  297. package/out/zero-client/src/client/inspector/lazy-inspector.js.map +1 -1
  298. package/out/zero-client/src/client/ivm-branch.d.ts.map +1 -1
  299. package/out/zero-client/src/client/ivm-branch.js +3 -20
  300. package/out/zero-client/src/client/ivm-branch.js.map +1 -1
  301. package/out/zero-client/src/client/mutation-tracker.d.ts.map +1 -1
  302. package/out/zero-client/src/client/mutation-tracker.js +1 -1
  303. package/out/zero-client/src/client/mutation-tracker.js.map +1 -1
  304. package/out/zero-client/src/client/mutator-proxy.d.ts.map +1 -1
  305. package/out/zero-client/src/client/mutator-proxy.js +1 -2
  306. package/out/zero-client/src/client/mutator-proxy.js.map +1 -1
  307. package/out/zero-client/src/client/options.d.ts +0 -3
  308. package/out/zero-client/src/client/options.d.ts.map +1 -1
  309. package/out/zero-client/src/client/options.js.map +1 -1
  310. package/out/zero-client/src/client/query-manager.d.ts +0 -2
  311. package/out/zero-client/src/client/query-manager.d.ts.map +1 -1
  312. package/out/zero-client/src/client/query-manager.js +14 -50
  313. package/out/zero-client/src/client/query-manager.js.map +1 -1
  314. package/out/zero-client/src/client/version.js +1 -1
  315. package/out/zero-client/src/client/zero-rep.d.ts +0 -1
  316. package/out/zero-client/src/client/zero-rep.d.ts.map +1 -1
  317. package/out/zero-client/src/client/zero-rep.js +6 -9
  318. package/out/zero-client/src/client/zero-rep.js.map +1 -1
  319. package/out/zero-client/src/client/zero.d.ts +3 -18
  320. package/out/zero-client/src/client/zero.d.ts.map +1 -1
  321. package/out/zero-client/src/client/zero.js +36 -123
  322. package/out/zero-client/src/client/zero.js.map +1 -1
  323. package/out/zero-client/src/types/query-result.d.ts +0 -2
  324. package/out/zero-client/src/types/query-result.d.ts.map +1 -1
  325. package/out/zero-protocol/src/analyze-query-result.d.ts +5 -5
  326. package/out/zero-protocol/src/analyze-query-result.d.ts.map +1 -1
  327. package/out/zero-protocol/src/analyze-query-result.js +1 -1
  328. package/out/zero-protocol/src/analyze-query-result.js.map +1 -1
  329. package/out/zero-protocol/src/ast.d.ts +1 -64
  330. package/out/zero-protocol/src/ast.d.ts.map +1 -1
  331. package/out/zero-protocol/src/ast.js +54 -225
  332. package/out/zero-protocol/src/ast.js.map +1 -1
  333. package/out/zero-protocol/src/connect.d.ts +13 -0
  334. package/out/zero-protocol/src/connect.d.ts.map +1 -1
  335. package/out/zero-protocol/src/connect.js +30 -1
  336. package/out/zero-protocol/src/connect.js.map +1 -1
  337. package/out/zero-protocol/src/down.d.ts +2 -2
  338. package/out/zero-protocol/src/error.d.ts +1 -1
  339. package/out/zero-protocol/src/inspect-down.d.ts +6 -6
  340. package/out/zero-protocol/src/poke.d.ts +11 -4
  341. package/out/zero-protocol/src/poke.d.ts.map +1 -1
  342. package/out/zero-protocol/src/poke.js +3 -2
  343. package/out/zero-protocol/src/poke.js.map +1 -1
  344. package/out/zero-protocol/src/protocol-flag-enum.d.ts +7 -0
  345. package/out/zero-protocol/src/protocol-flag-enum.d.ts.map +1 -0
  346. package/out/zero-protocol/src/protocol-flag-enum.js +7 -0
  347. package/out/zero-protocol/src/protocol-flag-enum.js.map +1 -0
  348. package/out/zero-protocol/src/protocol-flag.d.ts +14 -0
  349. package/out/zero-protocol/src/protocol-flag.d.ts.map +1 -0
  350. package/out/zero-protocol/src/protocol-flag.js +8 -0
  351. package/out/zero-protocol/src/protocol-flag.js.map +1 -0
  352. package/out/zero-protocol/src/protocol-version.d.ts +30 -6
  353. package/out/zero-protocol/src/protocol-version.d.ts.map +1 -1
  354. package/out/zero-protocol/src/protocol-version.js +1 -1
  355. package/out/zero-protocol/src/protocol-version.js.map +1 -1
  356. package/out/zero-protocol/src/query-hash.d.ts +2 -7
  357. package/out/zero-protocol/src/query-hash.d.ts.map +1 -1
  358. package/out/zero-protocol/src/query-hash.js +10 -10
  359. package/out/zero-protocol/src/query-hash.js.map +1 -1
  360. package/out/zero-react/src/use-query.d.ts +4 -5
  361. package/out/zero-react/src/use-query.d.ts.map +1 -1
  362. package/out/zero-react/src/use-query.js +9 -86
  363. package/out/zero-react/src/use-query.js.map +1 -1
  364. package/out/zero-solid/src/solid-view.d.ts +0 -17
  365. package/out/zero-solid/src/solid-view.d.ts.map +1 -1
  366. package/out/zero-solid/src/solid-view.js +1 -39
  367. package/out/zero-solid/src/solid-view.js.map +1 -1
  368. package/out/zero-solid/src/use-query.js +3 -5
  369. package/out/zero-solid/src/use-query.js.map +1 -1
  370. package/out/zql/src/builder/builder.d.ts +0 -19
  371. package/out/zql/src/builder/builder.d.ts.map +1 -1
  372. package/out/zql/src/builder/builder.js +11 -28
  373. package/out/zql/src/builder/builder.js.map +1 -1
  374. package/out/zql/src/builder/debug-delegate.d.ts +1 -6
  375. package/out/zql/src/builder/debug-delegate.d.ts.map +1 -1
  376. package/out/zql/src/builder/debug-delegate.js +2 -14
  377. package/out/zql/src/builder/debug-delegate.js.map +1 -1
  378. package/out/zql/src/ivm/array-view.d.ts +0 -29
  379. package/out/zql/src/ivm/array-view.d.ts.map +1 -1
  380. package/out/zql/src/ivm/array-view.js +12 -63
  381. package/out/zql/src/ivm/array-view.js.map +1 -1
  382. package/out/zql/src/ivm/cap.d.ts.map +1 -1
  383. package/out/zql/src/ivm/cap.js +3 -5
  384. package/out/zql/src/ivm/cap.js.map +1 -1
  385. package/out/zql/src/ivm/data.d.ts.map +1 -1
  386. package/out/zql/src/ivm/data.js +3 -8
  387. package/out/zql/src/ivm/data.js.map +1 -1
  388. package/out/zql/src/ivm/exists.d.ts +1 -1
  389. package/out/zql/src/ivm/exists.d.ts.map +1 -1
  390. package/out/zql/src/ivm/exists.js.map +1 -1
  391. package/out/zql/src/ivm/fan-in.d.ts +2 -2
  392. package/out/zql/src/ivm/fan-in.d.ts.map +1 -1
  393. package/out/zql/src/ivm/fan-in.js +5 -6
  394. package/out/zql/src/ivm/fan-in.js.map +1 -1
  395. package/out/zql/src/ivm/fan-out.d.ts +2 -2
  396. package/out/zql/src/ivm/fan-out.d.ts.map +1 -1
  397. package/out/zql/src/ivm/fan-out.js.map +1 -1
  398. package/out/zql/src/ivm/filter-operators.d.ts +6 -7
  399. package/out/zql/src/ivm/filter-operators.d.ts.map +1 -1
  400. package/out/zql/src/ivm/filter-operators.js +12 -29
  401. package/out/zql/src/ivm/filter-operators.js.map +1 -1
  402. package/out/zql/src/ivm/filter.d.ts +2 -2
  403. package/out/zql/src/ivm/filter.d.ts.map +1 -1
  404. package/out/zql/src/ivm/filter.js +4 -7
  405. package/out/zql/src/ivm/filter.js.map +1 -1
  406. package/out/zql/src/ivm/flipped-join.js +2 -2
  407. package/out/zql/src/ivm/flipped-join.js.map +1 -1
  408. package/out/zql/src/ivm/maybe-split-and-push-edit-change.d.ts +1 -1
  409. package/out/zql/src/ivm/maybe-split-and-push-edit-change.d.ts.map +1 -1
  410. package/out/zql/src/ivm/maybe-split-and-push-edit-change.js +4 -6
  411. package/out/zql/src/ivm/maybe-split-and-push-edit-change.js.map +1 -1
  412. package/out/zql/src/ivm/memory-source.d.ts +3 -15
  413. package/out/zql/src/ivm/memory-source.d.ts.map +1 -1
  414. package/out/zql/src/ivm/memory-source.js +23 -57
  415. package/out/zql/src/ivm/memory-source.js.map +1 -1
  416. package/out/zql/src/ivm/operator.d.ts +0 -40
  417. package/out/zql/src/ivm/operator.d.ts.map +1 -1
  418. package/out/zql/src/ivm/operator.js.map +1 -1
  419. package/out/zql/src/ivm/take.d.ts.map +1 -1
  420. package/out/zql/src/ivm/take.js +4 -3
  421. package/out/zql/src/ivm/take.js.map +1 -1
  422. package/out/zql/src/ivm/union-fan-in.d.ts.map +1 -1
  423. package/out/zql/src/ivm/union-fan-in.js +7 -9
  424. package/out/zql/src/ivm/union-fan-in.js.map +1 -1
  425. package/out/zql/src/ivm/view-apply-change.d.ts.map +1 -1
  426. package/out/zql/src/ivm/view-apply-change.js +4 -9
  427. package/out/zql/src/ivm/view-apply-change.js.map +1 -1
  428. package/out/zql/src/ivm/view.d.ts +0 -15
  429. package/out/zql/src/ivm/view.d.ts.map +1 -1
  430. package/out/zql/src/mutate/mutator-registry.d.ts.map +1 -1
  431. package/out/zql/src/mutate/mutator-registry.js +2 -2
  432. package/out/zql/src/mutate/mutator-registry.js.map +1 -1
  433. package/out/zql/src/planner/planner-builder.d.ts +3 -12
  434. package/out/zql/src/planner/planner-builder.d.ts.map +1 -1
  435. package/out/zql/src/planner/planner-builder.js +20 -40
  436. package/out/zql/src/planner/planner-builder.js.map +1 -1
  437. package/out/zql/src/planner/planner-connection.d.ts +2 -28
  438. package/out/zql/src/planner/planner-connection.d.ts.map +1 -1
  439. package/out/zql/src/planner/planner-connection.js +8 -108
  440. package/out/zql/src/planner/planner-connection.js.map +1 -1
  441. package/out/zql/src/planner/planner-debug.d.ts +1 -1
  442. package/out/zql/src/planner/planner-debug.d.ts.map +1 -1
  443. package/out/zql/src/planner/planner-debug.js +8 -3
  444. package/out/zql/src/planner/planner-debug.js.map +1 -1
  445. package/out/zql/src/planner/planner-fan-out.d.ts +0 -1
  446. package/out/zql/src/planner/planner-fan-out.d.ts.map +1 -1
  447. package/out/zql/src/planner/planner-fan-out.js +0 -3
  448. package/out/zql/src/planner/planner-fan-out.js.map +1 -1
  449. package/out/zql/src/planner/planner-graph.d.ts +0 -2
  450. package/out/zql/src/planner/planner-graph.d.ts.map +1 -1
  451. package/out/zql/src/planner/planner-graph.js +0 -2
  452. package/out/zql/src/planner/planner-graph.js.map +1 -1
  453. package/out/zql/src/planner/planner-join.d.ts +0 -2
  454. package/out/zql/src/planner/planner-join.d.ts.map +1 -1
  455. package/out/zql/src/planner/planner-join.js +0 -7
  456. package/out/zql/src/planner/planner-join.js.map +1 -1
  457. package/out/zql/src/planner/planner-node.d.ts +1 -2
  458. package/out/zql/src/planner/planner-node.d.ts.map +1 -1
  459. package/out/zql/src/planner/planner-node.js.map +1 -1
  460. package/out/zql/src/planner/planner-source.d.ts +2 -2
  461. package/out/zql/src/planner/planner-source.d.ts.map +1 -1
  462. package/out/zql/src/planner/planner-source.js +2 -2
  463. package/out/zql/src/planner/planner-source.js.map +1 -1
  464. package/out/zql/src/query/query-delegate-base.d.ts +1 -9
  465. package/out/zql/src/query/query-delegate-base.d.ts.map +1 -1
  466. package/out/zql/src/query/query-delegate-base.js +36 -132
  467. package/out/zql/src/query/query-delegate-base.js.map +1 -1
  468. package/out/zql/src/query/query-delegate.d.ts +1 -50
  469. package/out/zql/src/query/query-delegate.d.ts.map +1 -1
  470. package/out/zql/src/query/query-impl.d.ts +14 -25
  471. package/out/zql/src/query/query-impl.d.ts.map +1 -1
  472. package/out/zql/src/query/query-impl.js +94 -397
  473. package/out/zql/src/query/query-impl.js.map +1 -1
  474. package/out/zql/src/query/query-internals.d.ts +11 -21
  475. package/out/zql/src/query/query-internals.d.ts.map +1 -1
  476. package/out/zql/src/query/query-internals.js.map +1 -1
  477. package/out/zql/src/query/query.d.ts +2 -11
  478. package/out/zql/src/query/query.d.ts.map +1 -1
  479. package/out/zql/src/query/runnable-query-impl.d.ts +2 -3
  480. package/out/zql/src/query/runnable-query-impl.d.ts.map +1 -1
  481. package/out/zql/src/query/runnable-query-impl.js +2 -15
  482. package/out/zql/src/query/runnable-query-impl.js.map +1 -1
  483. package/out/zql/src/query/typed-view.d.ts +1 -1
  484. package/out/zql/src/query/typed-view.d.ts.map +1 -1
  485. package/out/zqlite/src/db.d.ts +1 -9
  486. package/out/zqlite/src/db.d.ts.map +1 -1
  487. package/out/zqlite/src/db.js +2 -8
  488. package/out/zqlite/src/db.js.map +1 -1
  489. package/out/zqlite/src/query-builder.d.ts +1 -1
  490. package/out/zqlite/src/query-builder.d.ts.map +1 -1
  491. package/out/zqlite/src/query-builder.js +2 -4
  492. package/out/zqlite/src/query-builder.js.map +1 -1
  493. package/out/zqlite/src/query-delegate.d.ts.map +1 -1
  494. package/out/zqlite/src/query-delegate.js +6 -5
  495. package/out/zqlite/src/query-delegate.js.map +1 -1
  496. package/out/zqlite/src/sqlite-cost-model.d.ts.map +1 -1
  497. package/out/zqlite/src/sqlite-cost-model.js +30 -2
  498. package/out/zqlite/src/sqlite-cost-model.js.map +1 -1
  499. package/out/zqlite/src/sqlite-stat-fanout.d.ts.map +1 -1
  500. package/out/zqlite/src/sqlite-stat-fanout.js +5 -4
  501. package/out/zqlite/src/sqlite-stat-fanout.js.map +1 -1
  502. package/out/zqlite/src/table-source.d.ts +3 -16
  503. package/out/zqlite/src/table-source.d.ts.map +1 -1
  504. package/out/zqlite/src/table-source.js +14 -33
  505. package/out/zqlite/src/table-source.js.map +1 -1
  506. package/package.json +3 -2
  507. package/out/replicache/src/dag/invalid-ref-count-error.d.ts +0 -12
  508. package/out/replicache/src/dag/invalid-ref-count-error.d.ts.map +0 -1
  509. package/out/replicache/src/dag/invalid-ref-count-error.js +0 -19
  510. package/out/replicache/src/dag/invalid-ref-count-error.js.map +0 -1
  511. package/out/shared/src/xxhash32.d.ts +0 -36
  512. package/out/shared/src/xxhash32.d.ts.map +0 -1
  513. package/out/shared/src/xxhash32.js +0 -51
  514. package/out/shared/src/xxhash32.js.map +0 -1
  515. package/out/zero-cache/src/db/index-predicate.d.ts +0 -4
  516. package/out/zero-cache/src/db/index-predicate.d.ts.map +0 -1
  517. package/out/zero-cache/src/db/index-predicate.js +0 -46
  518. package/out/zero-cache/src/db/index-predicate.js.map +0 -1
  519. package/out/zero-cache/src/services/change-source/pg/schema/index-predicate.d.ts +0 -19
  520. package/out/zero-cache/src/services/change-source/pg/schema/index-predicate.d.ts.map +0 -1
  521. package/out/zero-cache/src/services/change-source/pg/schema/index-predicate.js +0 -581
  522. package/out/zero-cache/src/services/change-source/pg/schema/index-predicate.js.map +0 -1
  523. package/out/zero-cache/src/services/litestream/litestream-checkpointer.js +0 -131
  524. package/out/zero-cache/src/services/litestream/litestream-checkpointer.js.map +0 -1
  525. package/out/zero-cache/src/services/litestream/litestream-controller.d.ts +0 -70
  526. package/out/zero-cache/src/services/litestream/litestream-controller.d.ts.map +0 -1
  527. package/out/zero-cache/src/services/litestream/litestream-controller.js +0 -101
  528. package/out/zero-cache/src/services/litestream/litestream-controller.js.map +0 -1
  529. package/out/zero-cache/src/services/profz.d.ts +0 -7
  530. package/out/zero-cache/src/services/profz.d.ts.map +0 -1
  531. package/out/zero-cache/src/services/profz.js +0 -103
  532. package/out/zero-cache/src/services/profz.js.map +0 -1
  533. package/out/zero-cache/src/services/view-syncer/hydration-budget.d.ts +0 -33
  534. package/out/zero-cache/src/services/view-syncer/hydration-budget.d.ts.map +0 -1
  535. package/out/zero-cache/src/services/view-syncer/hydration-budget.js +0 -62
  536. package/out/zero-cache/src/services/view-syncer/hydration-budget.js.map +0 -1
  537. package/out/zero-cache/src/services/view-syncer/hydration-circuit-breaker.d.ts +0 -51
  538. package/out/zero-cache/src/services/view-syncer/hydration-circuit-breaker.d.ts.map +0 -1
  539. package/out/zero-cache/src/services/view-syncer/hydration-circuit-breaker.js +0 -78
  540. package/out/zero-cache/src/services/view-syncer/hydration-circuit-breaker.js.map +0 -1
  541. package/out/zero-cache/src/services/view-syncer/snapshot-row-cache.d.ts +0 -95
  542. package/out/zero-cache/src/services/view-syncer/snapshot-row-cache.d.ts.map +0 -1
  543. package/out/zero-cache/src/services/view-syncer/snapshot-row-cache.js +0 -155
  544. package/out/zero-cache/src/services/view-syncer/snapshot-row-cache.js.map +0 -1
  545. package/out/zero-protocol/src/query-hash-visitor.d.ts +0 -81
  546. package/out/zero-protocol/src/query-hash-visitor.d.ts.map +0 -1
  547. package/out/zero-protocol/src/query-hash-visitor.js +0 -324
  548. package/out/zero-protocol/src/query-hash-visitor.js.map +0 -1
  549. package/out/zql/src/builder/correlated-predicate-pushdown.d.ts +0 -43
  550. package/out/zql/src/builder/correlated-predicate-pushdown.d.ts.map +0 -1
  551. package/out/zql/src/builder/correlated-predicate-pushdown.js +0 -161
  552. package/out/zql/src/builder/correlated-predicate-pushdown.js.map +0 -1
  553. package/out/zql/src/ivm/connection-index.d.ts +0 -68
  554. package/out/zql/src/ivm/connection-index.d.ts.map +0 -1
  555. package/out/zql/src/ivm/connection-index.js +0 -149
  556. package/out/zql/src/ivm/connection-index.js.map +0 -1
  557. package/out/zql/src/ivm/deferred-input.d.ts +0 -44
  558. package/out/zql/src/ivm/deferred-input.d.ts.map +0 -1
  559. package/out/zql/src/ivm/deferred-input.js +0 -89
  560. package/out/zql/src/ivm/deferred-input.js.map +0 -1
  561. package/out/zql/src/planner/planner-filter.d.ts +0 -59
  562. package/out/zql/src/planner/planner-filter.d.ts.map +0 -1
  563. package/out/zql/src/planner/planner-filter.js +0 -116
  564. package/out/zql/src/planner/planner-filter.js.map +0 -1
  565. package/out/zql/src/query/query-transitions.d.ts +0 -171
  566. package/out/zql/src/query/query-transitions.d.ts.map +0 -1
  567. package/out/zql/src/query/query-transitions.js +0 -204
  568. package/out/zql/src/query/query-transitions.js.map +0 -1
@@ -1,324 +0,0 @@
1
- import { unreachable } from "../../shared/src/asserts.js";
2
- import { PRIME32_1, PRIME32_5, avalanche32, round32 } from "../../shared/src/xxhash32.js";
3
- import "../../shared/src/hash.js";
4
- //#region ../zero-protocol/src/query-hash-visitor.ts
5
- var h1 = 0;
6
- var h2 = 0;
7
- /**
8
- * Fold one 32-bit word into both lanes.
9
- *
10
- * Both lanes run xxHash32's own round; only their starting values differ, so
11
- * they diverge immediately and stay diverged. That is the same construction
12
- * `h64` uses to widen xxHash32 past 32 bits, just fed words taken from a
13
- * structure rather than bytes taken from a string.
14
- */
15
- function mix(w) {
16
- h1 = round32(h1, w);
17
- h2 = round32(h2, w);
18
- }
19
- /**
20
- * Fold a string, two UTF-16 units per word.
21
- *
22
- * The leading length keeps `['ab','c']` and `['a','bc']` apart. STR_MARK is
23
- * folded into that same word rather than mixed separately: it costs nothing,
24
- * and since every other count written by this file is a small array length, a
25
- * string can never fold like one.
26
- */
27
- function mixString(s) {
28
- const n = s.length;
29
- mix(n | STR_MARK);
30
- let i = 0;
31
- for (; i + 1 < n; i += 2) mix(s.charCodeAt(i) | s.charCodeAt(i + 1) << 16);
32
- if (i < n) mix(s.charCodeAt(i));
33
- }
34
- var numView = /* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(8));
35
- /** Fold a number: one word for an int32, two for anything else. */
36
- function mixNumber(n) {
37
- if ((n | 0) === n) mix(n);
38
- else {
39
- numView.setFloat64(0, n, true);
40
- mix(numView.getInt32(0, true));
41
- mix(numView.getInt32(4, true));
42
- }
43
- }
44
- var TAG_NULL = 4097;
45
- var TAG_FALSE = 4098;
46
- var TAG_TRUE = 4099;
47
- var TAG_INT = 4100;
48
- var TAG_FLOAT = 4101;
49
- var TAG_ARR = 4103;
50
- var TAG_OBJ = 4104;
51
- var TAG_END = 4105;
52
- var TAG_UNDEF = 4106;
53
- var TAG_LITERAL = 8193;
54
- var TAG_COLUMN = 8194;
55
- var TAG_STATIC = 8195;
56
- var TAG_SIMPLE = 8196;
57
- var TAG_SUBQUERY = 8197;
58
- var TAG_AND = 8198;
59
- var TAG_OR = 8199;
60
- var TAG_FORMAT = 8200;
61
- var TAG_NAME_ARGS = 8201;
62
- var TAG_SYSTEM_PERMISSIONS = 8202;
63
- var TAG_SYSTEM_CLIENT = 8203;
64
- var TAG_SYSTEM_TEST = 8204;
65
- var TAG_JUNCTION = 8205;
66
- var STR_MARK = 1073741824;
67
- function reset() {
68
- h1 = PRIME32_5;
69
- h2 = PRIME32_1;
70
- }
71
- /** Collapse the two lanes into one 64-bit value, avalanching each first. */
72
- function finalize() {
73
- return avalanche32(h1).toString(36).padStart(7, "0") + avalanche32(h2).toString(36).padStart(7, "0");
74
- }
75
- function visitValue(v) {
76
- switch (typeof v) {
77
- case "string":
78
- mixString(v);
79
- return;
80
- case "number":
81
- if (!Number.isFinite(v)) {
82
- mix(TAG_NULL);
83
- return;
84
- }
85
- mix((v | 0) === v ? TAG_INT : TAG_FLOAT);
86
- mixNumber(v);
87
- return;
88
- case "boolean":
89
- mix(v ? TAG_TRUE : TAG_FALSE);
90
- return;
91
- case "object": {
92
- if (v === null) {
93
- mix(TAG_NULL);
94
- return;
95
- }
96
- if (Array.isArray(v)) {
97
- mix(TAG_ARR);
98
- for (let i = 0; i < v.length; i++) {
99
- const e = v[i];
100
- visitValue(e === void 0 ? null : e);
101
- }
102
- mix(TAG_END);
103
- return;
104
- }
105
- mix(TAG_OBJ);
106
- const keys = Object.keys(v).sort();
107
- for (const k of keys) {
108
- const val = v[k];
109
- if (val === void 0) continue;
110
- mixString(k);
111
- visitValue(val);
112
- }
113
- mix(TAG_END);
114
- return;
115
- }
116
- default: return;
117
- }
118
- }
119
- function visitOptionalString(s) {
120
- if (s === void 0) mix(TAG_UNDEF);
121
- else mixString(s);
122
- }
123
- function mixOptionalSystem(system) {
124
- if (system === void 0) mix(TAG_UNDEF);
125
- else mixSystem(system);
126
- }
127
- function mixSystem(system) {
128
- switch (system) {
129
- case "permissions":
130
- mix(TAG_SYSTEM_PERMISSIONS);
131
- break;
132
- case "client":
133
- mix(TAG_SYSTEM_CLIENT);
134
- break;
135
- case "test":
136
- mix(TAG_SYSTEM_TEST);
137
- break;
138
- default: unreachable(system);
139
- }
140
- }
141
- function visitCompoundKey(k) {
142
- mix(k.length);
143
- for (let i = 0; i < k.length; i++) mixString(k[i]);
144
- }
145
- function visitOrdering(o) {
146
- if (o === void 0) {
147
- mix(TAG_UNDEF);
148
- return;
149
- }
150
- mix(o.length);
151
- for (let i = 0; i < o.length; i++) {
152
- const [field, dir] = o[i];
153
- mixString(field);
154
- mix(dir === "asc" ? TAG_TRUE : TAG_FALSE);
155
- }
156
- }
157
- function visitValuePosition(v) {
158
- switch (v.type) {
159
- case "literal":
160
- mix(TAG_LITERAL);
161
- visitValue(v.value);
162
- return;
163
- case "column":
164
- mix(TAG_COLUMN);
165
- mixString(v.name);
166
- return;
167
- case "static":
168
- mix(TAG_STATIC);
169
- mixString(v.anchor);
170
- if (typeof v.field === "string") mixString(v.field);
171
- else visitCompoundKey(v.field);
172
- return;
173
- default: unreachable(v);
174
- }
175
- }
176
- function visitCondition(c) {
177
- switch (c.type) {
178
- case "simple":
179
- mix(TAG_SIMPLE);
180
- mixString(c.op);
181
- visitValuePosition(c.left);
182
- visitValuePosition(c.right);
183
- return;
184
- case "correlatedSubquery":
185
- mix(TAG_SUBQUERY);
186
- mixString(c.op);
187
- mix(c.flip === void 0 ? TAG_UNDEF : c.flip ? TAG_TRUE : TAG_FALSE);
188
- mix(c.scalar === void 0 ? TAG_UNDEF : c.scalar ? TAG_TRUE : TAG_FALSE);
189
- visitCorrelatedSubquery(c.related);
190
- return;
191
- default: {
192
- c.type;
193
- mix(c.type === "and" ? TAG_AND : TAG_OR);
194
- const conds = c.conditions;
195
- mix(conds.length);
196
- for (let i = 0; i < conds.length; i++) visitCondition(conds[i]);
197
- return;
198
- }
199
- }
200
- }
201
- function visitCorrelatedSubquery(csq) {
202
- visitCompoundKey(csq.correlation.parentField);
203
- visitCompoundKey(csq.correlation.childField);
204
- mix(csq.hidden === void 0 ? TAG_UNDEF : csq.hidden ? TAG_TRUE : TAG_FALSE);
205
- mixOptionalSystem(csq.system);
206
- visitAST(csq.subquery);
207
- }
208
- function visitAST(ast) {
209
- mix(TAG_OBJ);
210
- visitOptionalString(ast.schema);
211
- mixString(ast.table);
212
- visitOptionalString(ast.alias);
213
- if (ast.where === void 0) mix(TAG_UNDEF);
214
- else visitCondition(ast.where);
215
- const related = ast.related;
216
- if (related === void 0) mix(TAG_UNDEF);
217
- else {
218
- mix(related.length);
219
- for (let i = 0; i < related.length; i++) visitCorrelatedSubquery(related[i]);
220
- }
221
- const start = ast.start;
222
- if (start === void 0) mix(TAG_UNDEF);
223
- else {
224
- mix(start.exclusive ? TAG_TRUE : TAG_FALSE);
225
- visitValue(start.row);
226
- }
227
- if (ast.limit === void 0) mix(TAG_UNDEF);
228
- else {
229
- mix(TAG_INT);
230
- mixNumber(ast.limit);
231
- }
232
- visitOrdering(ast.orderBy);
233
- mix(TAG_END);
234
- }
235
- function hashAST(ast) {
236
- const s1 = h1;
237
- const s2 = h2;
238
- try {
239
- reset();
240
- visitAST(ast);
241
- return finalize();
242
- } finally {
243
- h1 = s1;
244
- h2 = s2;
245
- }
246
- }
247
- /**
248
- * The identity of a custom query: its name and its arguments.
249
- *
250
- * Same walk, entered at a different node. `args` is arbitrary JSON, which is
251
- * what `visitValue` already exists to handle. The leading tag keeps this hash
252
- * space disjoint from `hashAST`'s -- both produce query IDs that live in the
253
- * same namespace, so an AST must not be able to fold to the same words as some
254
- * name and args.
255
- */
256
- function hashNameAndArgs(name, args) {
257
- const s1 = h1;
258
- const s2 = h2;
259
- try {
260
- reset();
261
- mix(TAG_NAME_ARGS);
262
- mixString(name);
263
- visitValue(args);
264
- return finalize();
265
- } finally {
266
- h1 = s1;
267
- h2 = s2;
268
- }
269
- }
270
- /**
271
- * The identity of a query as the client sees it: its AST, the shape it returns,
272
- * the system it was built for, and -- for a custom query -- the name and
273
- * arguments it was declared with.
274
- *
275
- * Everything past the AST is here because it is part of what makes two queries
276
- * different while leaving no trace, or an incomplete one, in the AST itself:
277
- *
278
- * - **name and args**: `nameAndArgs` reuses the AST it is given and only
279
- * attaches a `CustomQueryID`, so without these two different named queries
280
- * over the same table would be indistinguishable.
281
- * - **system**: a query stamps it onto every `related` entry and every `exists`
282
- * correlation it builds, so it is already hashed via
283
- * {@link visitCorrelatedSubquery} -- but a query with neither has nowhere to
284
- * put it, and would otherwise hash the same whether it was built for the
285
- * client or for permissions.
286
- * - **currentJunction**: builder state, set on the sub-query handed to a
287
- * two-hop relationship's callback, which makes `limit` and `orderBy` throw.
288
- * It leaves no trace in the AST at all, so two queries that differ only in
289
- * whether those methods work would otherwise be indistinguishable.
290
- *
291
- * The name and args are taken apart rather than as a `CustomQueryID` because
292
- * that type lives in `zql`, which is above this package; `hashNameAndArgs`
293
- * splits them the same way.
294
- */
295
- function hashOfQueryInternals(ast, format, system, currentJunction, customQueryName, customQueryArgs) {
296
- const s1 = h1;
297
- const s2 = h2;
298
- try {
299
- reset();
300
- visitAST(ast);
301
- mix(TAG_FORMAT);
302
- visitValue(format);
303
- mixSystem(system);
304
- if (currentJunction === void 0) mix(TAG_UNDEF);
305
- else {
306
- mix(TAG_JUNCTION);
307
- mixString(currentJunction);
308
- }
309
- if (customQueryName === void 0) mix(TAG_UNDEF);
310
- else {
311
- mix(TAG_NAME_ARGS);
312
- mixString(customQueryName);
313
- visitValue(customQueryArgs);
314
- }
315
- return finalize();
316
- } finally {
317
- h1 = s1;
318
- h2 = s2;
319
- }
320
- }
321
- //#endregion
322
- export { hashAST, hashNameAndArgs, hashOfQueryInternals };
323
-
324
- //# sourceMappingURL=query-hash-visitor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"query-hash-visitor.js","names":[],"sources":["../../../../zero-protocol/src/query-hash-visitor.ts"],"sourcesContent":["import {unreachable} from '../../shared/src/asserts.ts';\n// These live in shared/src/xxhash32.ts, imported via hash.ts's re-export\n// rather than directly: the direct zero-protocol -> shared/xxhash32.ts edge\n// makes tsc 7.0.2 mis-evaluate Query-type relations in other programs --\n// phantom TS2345s in zql's runnable-query-impl.ts under the packages/zero\n// declaration build, and zero-client silently losing the type error that\n// custom.test.ts pins with a ts-expect-error directive. Bisected cold-cache\n// to that one import statement; the hash.ts route checks clean everywhere.\n// Collapse to a direct import when TypeScript is upgraded past this.\nimport {\n avalanche32,\n PRIME32_1,\n PRIME32_5,\n round32,\n} from '../../shared/src/hash.ts';\nimport type {Format} from '../../zero-types/src/format.ts';\n\n/**\n * Hashes a normalized AST by visiting it, rather than by rendering it to JSON\n * and hashing the bytes. `hashOfAST` and `hashOfNameAndArgs` in\n * `query-hash.ts` are both built on this, so these digests are the query IDs\n * the client registers and the transformation hashes the server stores.\n *\n * The pipeline this replaced was\n * `h64(JSON.stringify(normalizeAST(ast))).toString(36)`, which materialized\n * the whole AST as a string, UTF-8 encoded it, and only then hashed it — three\n * passes over the data, two of which existed purely to produce bytes to hash.\n *\n * A visitor can fold values into the hash state as it walks, so nothing is\n * materialized at all. The primitives that make that pay off:\n *\n * - Two 32-bit accumulators held in module-level `let`s, so the \"state\" is\n * plain numbers in registers rather than an object being threaded through\n * the walk.\n * - xxHash32's own round and final mix, shared with `shared/src/hash.ts` via\n * `shared/src/xxhash32.ts`. Only the ingestion differs: that one feeds them\n * UTF-8 bytes, this one feeds them words straight out of the structure.\n * - Strings folded straight from `charCodeAt`, two UTF-16 units at a time, into\n * one 32-bit word. No UTF-8 encoding, and half the loop iterations a\n * byte-oriented hash would need over ASCII.\n *\n * These digests do not agree with xxHash32 over the old JSON encoding, and are\n * not meant to: nothing recomputes a hash produced elsewhere and compares it,\n * so the encoding is free to change as long as every writer moves together.\n * What it does have to give is distinct words for structurally distinct\n * queries — a 64-bit digest cannot promise that absolutely, but every field\n * and node kind must at least reach the mixer, and no two of them may be\n * written so as to be confusable. `query-hash-visitor.test.ts` holds that\n * line with a corpus and a per-field mutation test.\n *\n * The walk is deliberately specialized to the AST shape rather than written as\n * a generic JSON-value walk. That is not premature: a generic version was\n * measured alongside this one and came out ~2.4x slower, no better than the\n * `JSON.stringify` it was meant to replace, because `for...in` and the\n * megamorphic property loads cost about what the native stringify costs. Only\n * `visitValue` below stays generic, for the two places an AST holds arbitrary\n * JSON: a literal's value and a bound's row.\n */\nimport type {\n AST,\n Condition,\n CorrelatedSubquery,\n Ordering,\n System,\n ValuePosition,\n} from './ast.ts';\n\n// Two 32-bit lanes, combined into 64 bits at the end. Module-level so the walk\n// mutates registers rather than allocating or threading state through it.\nlet h1 = 0;\nlet h2 = 0;\n\n/**\n * Fold one 32-bit word into both lanes.\n *\n * Both lanes run xxHash32's own round; only their starting values differ, so\n * they diverge immediately and stay diverged. That is the same construction\n * `h64` uses to widen xxHash32 past 32 bits, just fed words taken from a\n * structure rather than bytes taken from a string.\n */\nfunction mix(w: number): void {\n h1 = round32(h1, w);\n h2 = round32(h2, w);\n}\n\n/**\n * Fold a string, two UTF-16 units per word.\n *\n * The leading length keeps `['ab','c']` and `['a','bc']` apart. STR_MARK is\n * folded into that same word rather than mixed separately: it costs nothing,\n * and since every other count written by this file is a small array length, a\n * string can never fold like one.\n */\nfunction mixString(s: string): void {\n const n = s.length;\n mix(n | STR_MARK);\n let i = 0;\n for (; i + 1 < n; i += 2) {\n mix(s.charCodeAt(i) | (s.charCodeAt(i + 1) << 16));\n }\n if (i < n) {\n mix(s.charCodeAt(i));\n }\n}\n\n// A DataView with an explicit byte order, not a Float64Array/Int32Array\n// aliasing pair: typed arrays read the buffer in host byte order, and these\n// digests are persisted, so a big-endian runtime would fold a float's words\n// swapped and disagree with every little-endian peer.\nconst numView = new DataView(new ArrayBuffer(8));\n\n/** Fold a number: one word for an int32, two for anything else. */\nfunction mixNumber(n: number): void {\n if ((n | 0) === n) {\n mix(n);\n } else {\n numView.setFloat64(0, n, true);\n mix(numView.getInt32(0, true));\n mix(numView.getInt32(4, true));\n }\n}\n\n// Structural tags. Distinct constants so that, say, a string \"1\" and the\n// number 1 cannot fold to the same state.\nconst TAG_NULL = 0x1001;\nconst TAG_FALSE = 0x1002;\nconst TAG_TRUE = 0x1003;\nconst TAG_INT = 0x1004;\nconst TAG_FLOAT = 0x1005;\nconst TAG_ARR = 0x1007;\nconst TAG_OBJ = 0x1008;\nconst TAG_END = 0x1009;\nconst TAG_UNDEF = 0x100a;\n\n// Discriminators for the AST's own unions, kept distinct from the value tags\n// above so a node kind can never fold like a value of some other type.\nconst TAG_LITERAL = 0x2001;\nconst TAG_COLUMN = 0x2002;\nconst TAG_STATIC = 0x2003;\nconst TAG_SIMPLE = 0x2004;\nconst TAG_SUBQUERY = 0x2005;\nconst TAG_AND = 0x2006;\nconst TAG_OR = 0x2007;\nconst TAG_FORMAT = 0x2008;\nconst TAG_NAME_ARGS = 0x2009;\n// `System` is a closed set of three, so it folds as one word rather than as a\n// string -- on an AST it appears once per correlated subquery, so this is on\n// the walk's hot path. The switch below is exhaustive, so adding a member is a\n// type error rather than a silent collision with an existing one.\nconst TAG_SYSTEM_PERMISSIONS = 0x200a;\nconst TAG_SYSTEM_CLIENT = 0x200b;\nconst TAG_SYSTEM_TEST = 0x200c;\nconst TAG_JUNCTION = 0x200d;\n\n// Set on a string's length word. High enough that no array length reaches it.\nconst STR_MARK = 0x40000000;\n\nfunction reset(): void {\n h1 = PRIME32_5;\n h2 = PRIME32_1;\n}\n\n/** Collapse the two lanes into one 64-bit value, avalanching each first. */\nfunction finalize(): string {\n return (\n avalanche32(h1).toString(36).padStart(7, '0') +\n avalanche32(h2).toString(36).padStart(7, '0')\n );\n}\n\n// ---------------------------------------------------------------------------\n// The generic part: arbitrary JSON, for literal values and bound rows.\n// ---------------------------------------------------------------------------\n\nfunction visitValue(v: unknown): void {\n switch (typeof v) {\n case 'string':\n mixString(v);\n return;\n case 'number':\n // NaN and Infinity are null by the time they reach the wire, because\n // that is what JSON.stringify writes for them. Two queries identical on\n // the wire must not get different IDs.\n if (!Number.isFinite(v)) {\n mix(TAG_NULL);\n return;\n }\n mix((v | 0) === v ? TAG_INT : TAG_FLOAT);\n mixNumber(v);\n return;\n case 'boolean':\n mix(v ? TAG_TRUE : TAG_FALSE);\n return;\n case 'object': {\n if (v === null) {\n mix(TAG_NULL);\n return;\n }\n if (Array.isArray(v)) {\n mix(TAG_ARR);\n for (let i = 0; i < v.length; i++) {\n // An `undefined` element is `null` by the time it reaches the wire,\n // because that is what JSON.stringify makes of it. Dropping it\n // instead would fold `[undefined]` onto `[]`.\n const e: unknown = v[i];\n visitValue(e === undefined ? null : e);\n }\n mix(TAG_END);\n return;\n }\n mix(TAG_OBJ);\n // Sorted, so the digest is a function of the object's contents and not\n // of its key order. Rows and custom-query args round-trip through\n // Postgres JSONB, which reorders keys; an order-sensitive digest made\n // reloaded query records look changed. (The AST's own fields don't need\n // this: visitAST reads them in a fixed order by name.)\n const keys = Object.keys(v).sort();\n for (const k of keys) {\n const val = (v as Record<string, unknown>)[k];\n if (val === undefined) {\n continue; // as JSON.stringify does\n }\n mixString(k);\n visitValue(val);\n }\n mix(TAG_END);\n return;\n }\n default:\n // `undefined` and functions as an object's value: dropped, as\n // JSON.stringify drops them. Array elements are handled above.\n return;\n }\n}\n\n// ---------------------------------------------------------------------------\n// The specialized part: the AST's own shape.\n// ---------------------------------------------------------------------------\n\nfunction visitOptionalString(s: string | undefined): void {\n if (s === undefined) {\n mix(TAG_UNDEF);\n } else {\n mixString(s);\n }\n}\n\nfunction mixOptionalSystem(system: System | undefined): void {\n if (system === undefined) {\n mix(TAG_UNDEF);\n } else {\n mixSystem(system);\n }\n}\n\nfunction mixSystem(system: System): void {\n switch (system) {\n case 'permissions':\n mix(TAG_SYSTEM_PERMISSIONS);\n break;\n case 'client':\n mix(TAG_SYSTEM_CLIENT);\n break;\n case 'test':\n mix(TAG_SYSTEM_TEST);\n break;\n default:\n unreachable(system);\n }\n}\n\nfunction visitCompoundKey(k: readonly string[]): void {\n mix(k.length);\n for (let i = 0; i < k.length; i++) {\n mixString(k[i]);\n }\n}\n\nfunction visitOrdering(o: Ordering | undefined): void {\n if (o === undefined) {\n mix(TAG_UNDEF);\n return;\n }\n mix(o.length);\n for (let i = 0; i < o.length; i++) {\n const [field, dir] = o[i];\n mixString(field);\n mix(dir === 'asc' ? TAG_TRUE : TAG_FALSE);\n }\n}\n\nfunction visitValuePosition(v: ValuePosition): void {\n switch (v.type) {\n case 'literal':\n mix(TAG_LITERAL);\n visitValue(v.value);\n return;\n case 'column':\n mix(TAG_COLUMN);\n mixString(v.name);\n return;\n case 'static': {\n mix(TAG_STATIC);\n mixString(v.anchor);\n if (typeof v.field === 'string') {\n mixString(v.field);\n } else {\n visitCompoundKey(v.field);\n }\n return;\n }\n default:\n unreachable(v);\n }\n}\n\nfunction visitCondition(c: Condition): void {\n switch (c.type) {\n case 'simple':\n mix(TAG_SIMPLE);\n mixString(c.op);\n visitValuePosition(c.left);\n visitValuePosition(c.right);\n return;\n case 'correlatedSubquery':\n mix(TAG_SUBQUERY);\n mixString(c.op);\n mix(c.flip === undefined ? TAG_UNDEF : c.flip ? TAG_TRUE : TAG_FALSE);\n mix(c.scalar === undefined ? TAG_UNDEF : c.scalar ? TAG_TRUE : TAG_FALSE);\n visitCorrelatedSubquery(c.related);\n return;\n default: {\n c.type satisfies 'and' | 'or';\n mix(c.type === 'and' ? TAG_AND : TAG_OR);\n const conds = c.conditions;\n mix(conds.length);\n for (let i = 0; i < conds.length; i++) {\n visitCondition(conds[i]);\n }\n return;\n }\n }\n}\n\nfunction visitCorrelatedSubquery(csq: CorrelatedSubquery): void {\n visitCompoundKey(csq.correlation.parentField);\n visitCompoundKey(csq.correlation.childField);\n mix(csq.hidden === undefined ? TAG_UNDEF : csq.hidden ? TAG_TRUE : TAG_FALSE);\n mixOptionalSystem(csq.system);\n visitAST(csq.subquery);\n}\n\nfunction visitAST(ast: AST): void {\n mix(TAG_OBJ);\n visitOptionalString(ast.schema);\n mixString(ast.table);\n visitOptionalString(ast.alias);\n\n if (ast.where === undefined) {\n mix(TAG_UNDEF);\n } else {\n visitCondition(ast.where);\n }\n\n const related = ast.related;\n if (related === undefined) {\n mix(TAG_UNDEF);\n } else {\n mix(related.length);\n for (let i = 0; i < related.length; i++) {\n visitCorrelatedSubquery(related[i]);\n }\n }\n\n const start = ast.start;\n if (start === undefined) {\n mix(TAG_UNDEF);\n } else {\n mix(start.exclusive ? TAG_TRUE : TAG_FALSE);\n visitValue(start.row);\n }\n\n if (ast.limit === undefined) {\n mix(TAG_UNDEF);\n } else {\n // Tagged, because this is the one optional field whose present and absent\n // forms would otherwise both write a single bare word: an untagged\n // `limit: 4106` is the same word as TAG_UNDEF. The other optionals are\n // safe -- a present string carries STR_MARK, a condition or bound leads\n // with its own kind tag, and `related`/`orderBy` write a count followed by\n // that many items, so their streams diverge straight after.\n mix(TAG_INT);\n mixNumber(ast.limit);\n }\n\n visitOrdering(ast.orderBy);\n mix(TAG_END);\n}\n\nexport function hashAST(ast: AST): string {\n // Save and restore the lanes: `visitValue` reads properties of arbitrary\n // runtime objects, and a getter is free to ask for another hash mid-walk.\n // Without this, the inner call's reset() would corrupt the outer digest.\n const s1 = h1;\n const s2 = h2;\n try {\n reset();\n visitAST(ast);\n return finalize();\n } finally {\n h1 = s1;\n h2 = s2;\n }\n}\n\n/**\n * The identity of a custom query: its name and its arguments.\n *\n * Same walk, entered at a different node. `args` is arbitrary JSON, which is\n * what `visitValue` already exists to handle. The leading tag keeps this hash\n * space disjoint from `hashAST`'s -- both produce query IDs that live in the\n * same namespace, so an AST must not be able to fold to the same words as some\n * name and args.\n */\nexport function hashNameAndArgs(\n name: string,\n args: readonly unknown[],\n): string {\n const s1 = h1;\n const s2 = h2;\n try {\n reset();\n mix(TAG_NAME_ARGS);\n mixString(name);\n visitValue(args);\n return finalize();\n } finally {\n h1 = s1;\n h2 = s2;\n }\n}\n\n/**\n * The identity of a query as the client sees it: its AST, the shape it returns,\n * the system it was built for, and -- for a custom query -- the name and\n * arguments it was declared with.\n *\n * Everything past the AST is here because it is part of what makes two queries\n * different while leaving no trace, or an incomplete one, in the AST itself:\n *\n * - **name and args**: `nameAndArgs` reuses the AST it is given and only\n * attaches a `CustomQueryID`, so without these two different named queries\n * over the same table would be indistinguishable.\n * - **system**: a query stamps it onto every `related` entry and every `exists`\n * correlation it builds, so it is already hashed via\n * {@link visitCorrelatedSubquery} -- but a query with neither has nowhere to\n * put it, and would otherwise hash the same whether it was built for the\n * client or for permissions.\n * - **currentJunction**: builder state, set on the sub-query handed to a\n * two-hop relationship's callback, which makes `limit` and `orderBy` throw.\n * It leaves no trace in the AST at all, so two queries that differ only in\n * whether those methods work would otherwise be indistinguishable.\n *\n * The name and args are taken apart rather than as a `CustomQueryID` because\n * that type lives in `zql`, which is above this package; `hashNameAndArgs`\n * splits them the same way.\n */\nexport function hashOfQueryInternals(\n ast: AST,\n format: Format,\n system: System,\n currentJunction: string | undefined,\n customQueryName: string | undefined,\n customQueryArgs: readonly unknown[] | undefined,\n): string {\n const s1 = h1;\n const s2 = h2;\n try {\n reset();\n visitAST(ast);\n mix(TAG_FORMAT);\n visitValue(format);\n mixSystem(system);\n if (currentJunction === undefined) {\n mix(TAG_UNDEF);\n } else {\n mix(TAG_JUNCTION);\n mixString(currentJunction);\n }\n if (customQueryName === undefined) {\n mix(TAG_UNDEF);\n } else {\n mix(TAG_NAME_ARGS);\n mixString(customQueryName);\n visitValue(customQueryArgs);\n }\n return finalize();\n } finally {\n h1 = s1;\n h2 = s2;\n }\n}\n"],"mappings":";;;;AAqEA,IAAI,KAAK;AACT,IAAI,KAAK;;;;;;;;;AAUT,SAAS,IAAI,GAAiB;CAC5B,KAAK,QAAQ,IAAI,CAAC;CAClB,KAAK,QAAQ,IAAI,CAAC;AACpB;;;;;;;;;AAUA,SAAS,UAAU,GAAiB;CAClC,MAAM,IAAI,EAAE;CACZ,IAAI,IAAI,QAAQ;CAChB,IAAI,IAAI;CACR,OAAO,IAAI,IAAI,GAAG,KAAK,GACrB,IAAI,EAAE,WAAW,CAAC,IAAK,EAAE,WAAW,IAAI,CAAC,KAAK,EAAG;CAEnD,IAAI,IAAI,GACN,IAAI,EAAE,WAAW,CAAC,CAAC;AAEvB;AAMA,IAAM,0BAAU,IAAI,yBAAS,IAAI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GACtB,IAAI,SAAS;OACR;GACL,IAAI,aAAa;GACjB,UAAU,eAAe;GACzB,WAAW,eAAe;EAC5B;EACA,OAAO,SAAS;CAClB,UAAU;EACR,KAAK;EACL,KAAK;CACP;AACF"}
@@ -1,43 +0,0 @@
1
- import type { AST, SimpleCondition } from '../../../zero-protocol/src/ast.ts';
2
- import type { SchemaValue } from '../../../zero-types/src/schema-value.ts';
3
- /**
4
- * The longest `IN` list that is copied into a child. `IN` compiles to
5
- * `IN (SELECT value FROM json_each(?))`, and every per-parent fetch of the
6
- * child carries the whole list.
7
- */
8
- export declare const MAX_PUSHED_IN_VALUES = 32;
9
- /**
10
- * Copies a parent's condition on a correlation column into the child
11
- * subquery, renamed to the matching child column. For example,
12
- * `user.where('user_id', X).related('reading')` becomes
13
- * `user.where('user_id', X).related('reading', r => r.where('user_id', X))`.
14
- *
15
- * The result is the same. Only child rows that cannot join to a parent that
16
- * matters are removed. But a push that climbs the tree then fetches parents
17
- * with SQL that includes the ancestor's condition, and a change to a child row
18
- * that cannot match stops at the child's source.
19
- *
20
- * Conditions are copied only when they are true for every parent row where
21
- * the edge can affect the result:
22
- * - for `related`, the top-level AND conjuncts of the parent's `where`;
23
- * - for EXISTS and NOT EXISTS, the conjuncts of every AND on the path from
24
- * the root of `where` to the subquery condition. An OR adds no facts.
25
- *
26
- * A condition is copied when it is `column = literal`, `column IS literal`, or
27
- * `column IN literal-list` (at most {@link MAX_PUSHED_IN_VALUES} values), the
28
- * column is a `parentField` of the correlation, and the parent and child
29
- * columns have the same Zero type, which is not `json`.
30
- *
31
- * A condition is not copied when the child already has the same condition as
32
- * a conjunct. So the pass does not change an AST that it already pushed.
33
- *
34
- * Does not change its input. Returns the same object for every part of the
35
- * AST that it does not change.
36
- *
37
- * @param pushed When given, receives each child conjunct that is a copy of a
38
- * parent condition: the copies that the pass adds, and the child's own
39
- * conjuncts that equal a copy. The parent's condition implies each of them
40
- * wherever the join binds its column, so the planner ignores them there.
41
- */
42
- export declare function pushDownCorrelatedPredicates(ast: AST, columnsOf: (table: string) => Record<string, SchemaValue>, pushed?: Set<SimpleCondition> | undefined): AST;
43
- //# sourceMappingURL=correlated-predicate-pushdown.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"correlated-predicate-pushdown.d.ts","sourceRoot":"","sources":["../../../../../zql/src/builder/correlated-predicate-pushdown.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,GAAG,EAIH,eAAe,EAChB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,yCAAyC,CAAC;AAGzE;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,KAAK,CAAC;AAMvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,4BAA4B,CAC1C,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,EACzD,MAAM,CAAC,EAAE,GAAG,CAAC,eAAe,CAAC,GAAG,SAAS,GACxC,GAAG,CAyGL"}
@@ -1,161 +0,0 @@
1
- import { deepEqual } from "../../../shared/src/json.js";
2
- import { simplifyCondition } from "../query/expression.js";
3
- /**
4
- * Copies a parent's condition on a correlation column into the child
5
- * subquery, renamed to the matching child column. For example,
6
- * `user.where('user_id', X).related('reading')` becomes
7
- * `user.where('user_id', X).related('reading', r => r.where('user_id', X))`.
8
- *
9
- * The result is the same. Only child rows that cannot join to a parent that
10
- * matters are removed. But a push that climbs the tree then fetches parents
11
- * with SQL that includes the ancestor's condition, and a change to a child row
12
- * that cannot match stops at the child's source.
13
- *
14
- * Conditions are copied only when they are true for every parent row where
15
- * the edge can affect the result:
16
- * - for `related`, the top-level AND conjuncts of the parent's `where`;
17
- * - for EXISTS and NOT EXISTS, the conjuncts of every AND on the path from
18
- * the root of `where` to the subquery condition. An OR adds no facts.
19
- *
20
- * A condition is copied when it is `column = literal`, `column IS literal`, or
21
- * `column IN literal-list` (at most {@link MAX_PUSHED_IN_VALUES} values), the
22
- * column is a `parentField` of the correlation, and the parent and child
23
- * columns have the same Zero type, which is not `json`.
24
- *
25
- * A condition is not copied when the child already has the same condition as
26
- * a conjunct. So the pass does not change an AST that it already pushed.
27
- *
28
- * Does not change its input. Returns the same object for every part of the
29
- * AST that it does not change.
30
- *
31
- * @param pushed When given, receives each child conjunct that is a copy of a
32
- * parent condition: the copies that the pass adds, and the child's own
33
- * conjuncts that equal a copy. The parent's condition implies each of them
34
- * wherever the join binds its column, so the planner ignores them there.
35
- */
36
- function pushDownCorrelatedPredicates(ast, columnsOf, pushed) {
37
- function visit(ast) {
38
- const where = ast.where && visitCondition(ast.where, ast.table, []);
39
- const facts = where ? simpleConjuncts(where) : [];
40
- const related = ast.related && mapShared(ast.related, (csq) => {
41
- const subquery = visit(pushInto(csq, facts, ast.table));
42
- return subquery === csq.subquery ? csq : {
43
- ...csq,
44
- subquery
45
- };
46
- });
47
- if (where === ast.where && related === ast.related) return ast;
48
- return {
49
- ...ast,
50
- where,
51
- related
52
- };
53
- }
54
- function visitCondition(c, table, facts) {
55
- switch (c.type) {
56
- case "simple": return c;
57
- case "and": return visitConjunction(c, table, [...facts, ...simpleConjuncts(c)]);
58
- case "or": {
59
- const conditions = mapShared(c.conditions, (x) => visitCondition(x, table, facts));
60
- return conditions === c.conditions ? c : {
61
- ...c,
62
- conditions
63
- };
64
- }
65
- case "correlatedSubquery": {
66
- const subquery = visit(pushInto(c.related, facts, table));
67
- return subquery === c.related.subquery ? c : {
68
- ...c,
69
- related: {
70
- ...c.related,
71
- subquery
72
- }
73
- };
74
- }
75
- }
76
- }
77
- function visitConjunction(c, table, facts) {
78
- const conditions = mapShared(c.conditions, (x) => x.type === "and" ? visitConjunction(x, table, facts) : visitCondition(x, table, facts));
79
- return conditions === c.conditions ? c : {
80
- ...c,
81
- conditions
82
- };
83
- }
84
- function pushInto(csq, facts, parentTable) {
85
- const { parentField, childField } = csq.correlation;
86
- const { subquery } = csq;
87
- const conjuncts = subquery.where ? simpleConjuncts(subquery.where) : [];
88
- const added = [];
89
- for (const fact of facts) {
90
- if (!isPushable(fact)) continue;
91
- for (let i = 0; i < parentField.length; i++) if (parentField[i] === fact.left.name && haveSameScalarType(columnsOf(parentTable)[parentField[i]], columnsOf(subquery.table)[childField[i]])) {
92
- const copy = {
93
- ...fact,
94
- left: {
95
- type: "column",
96
- name: childField[i]
97
- }
98
- };
99
- const same = conjuncts.find((c) => isSameCondition(c, copy));
100
- if (same) pushed?.add(same);
101
- else {
102
- conjuncts.push(copy);
103
- added.push(copy);
104
- pushed?.add(copy);
105
- }
106
- }
107
- }
108
- if (added.length === 0) return subquery;
109
- return {
110
- ...subquery,
111
- where: simplifyCondition({
112
- type: "and",
113
- conditions: subquery.where ? [subquery.where, ...added] : added
114
- })
115
- };
116
- }
117
- return visit(ast);
118
- }
119
- /**
120
- * The simple conditions that are conjuncts of `c`, including those of ANDs
121
- * nested in ANDs.
122
- */
123
- function simpleConjuncts(c) {
124
- switch (c.type) {
125
- case "simple": return [c];
126
- case "and": return c.conditions.flatMap(simpleConjuncts);
127
- default: return [];
128
- }
129
- }
130
- function isPushable(c) {
131
- if (c.left.type !== "column" || c.right.type !== "literal") return false;
132
- switch (c.op) {
133
- case "=":
134
- case "IS": return true;
135
- case "IN": return Array.isArray(c.right.value) && c.right.value.length <= 32;
136
- default: return false;
137
- }
138
- }
139
- function isSameCondition(a, b) {
140
- return a.op === b.op && a.left.type === "column" && b.left.type === "column" && a.left.name === b.left.name && a.right.type === "literal" && b.right.type === "literal" && deepEqual(a.right.value, b.right.value);
141
- }
142
- function haveSameScalarType(parent, child) {
143
- return parent !== void 0 && child !== void 0 && parent.type === child.type && parent.type !== "json";
144
- }
145
- /**
146
- * Like `Array.prototype.map`, but returns `arr` itself when `f` returns every
147
- * element unchanged.
148
- */
149
- function mapShared(arr, f) {
150
- let result;
151
- for (let i = 0; i < arr.length; i++) {
152
- const x = f(arr[i]);
153
- if (result === void 0 && x !== arr[i]) result = arr.slice(0, i);
154
- result?.push(x);
155
- }
156
- return result ?? arr;
157
- }
158
- //#endregion
159
- export { pushDownCorrelatedPredicates };
160
-
161
- //# sourceMappingURL=correlated-predicate-pushdown.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"correlated-predicate-pushdown.js","names":[],"sources":["../../../../../zql/src/builder/correlated-predicate-pushdown.ts"],"sourcesContent":["import {deepEqual} from '../../../shared/src/json.ts';\nimport type {\n AST,\n Condition,\n Conjunction,\n CorrelatedSubquery,\n SimpleCondition,\n} from '../../../zero-protocol/src/ast.ts';\nimport type {SchemaValue} from '../../../zero-types/src/schema-value.ts';\nimport {simplifyCondition} from '../query/expression.ts';\n\n/**\n * The longest `IN` list that is copied into a child. `IN` compiles to\n * `IN (SELECT value FROM json_each(?))`, and every per-parent fetch of the\n * child carries the whole list.\n */\nexport const MAX_PUSHED_IN_VALUES = 32;\n\ntype ColumnCondition = SimpleCondition & {\n readonly left: {readonly type: 'column'; readonly name: string};\n};\n\n/**\n * Copies a parent's condition on a correlation column into the child\n * subquery, renamed to the matching child column. For example,\n * `user.where('user_id', X).related('reading')` becomes\n * `user.where('user_id', X).related('reading', r => r.where('user_id', X))`.\n *\n * The result is the same. Only child rows that cannot join to a parent that\n * matters are removed. But a push that climbs the tree then fetches parents\n * with SQL that includes the ancestor's condition, and a change to a child row\n * that cannot match stops at the child's source.\n *\n * Conditions are copied only when they are true for every parent row where\n * the edge can affect the result:\n * - for `related`, the top-level AND conjuncts of the parent's `where`;\n * - for EXISTS and NOT EXISTS, the conjuncts of every AND on the path from\n * the root of `where` to the subquery condition. An OR adds no facts.\n *\n * A condition is copied when it is `column = literal`, `column IS literal`, or\n * `column IN literal-list` (at most {@link MAX_PUSHED_IN_VALUES} values), the\n * column is a `parentField` of the correlation, and the parent and child\n * columns have the same Zero type, which is not `json`.\n *\n * A condition is not copied when the child already has the same condition as\n * a conjunct. So the pass does not change an AST that it already pushed.\n *\n * Does not change its input. Returns the same object for every part of the\n * AST that it does not change.\n *\n * @param pushed When given, receives each child conjunct that is a copy of a\n * parent condition: the copies that the pass adds, and the child's own\n * conjuncts that equal a copy. The parent's condition implies each of them\n * wherever the join binds its column, so the planner ignores them there.\n */\nexport function pushDownCorrelatedPredicates(\n ast: AST,\n columnsOf: (table: string) => Record<string, SchemaValue>,\n pushed?: Set<SimpleCondition> | undefined,\n): AST {\n function visit(ast: AST): AST {\n const where = ast.where && visitCondition(ast.where, ast.table, []);\n const facts = where ? simpleConjuncts(where) : [];\n const related =\n ast.related &&\n mapShared(ast.related, csq => {\n const subquery = visit(pushInto(csq, facts, ast.table));\n return subquery === csq.subquery ? csq : {...csq, subquery};\n });\n if (where === ast.where && related === ast.related) {\n return ast;\n }\n return {...ast, where, related};\n }\n\n function visitCondition(\n c: Condition,\n table: string,\n facts: readonly SimpleCondition[],\n ): Condition {\n switch (c.type) {\n case 'simple':\n return c;\n case 'and':\n return visitConjunction(c, table, [...facts, ...simpleConjuncts(c)]);\n case 'or': {\n const conditions = mapShared(c.conditions, x =>\n visitCondition(x, table, facts),\n );\n return conditions === c.conditions ? c : {...c, conditions};\n }\n case 'correlatedSubquery': {\n const subquery = visit(pushInto(c.related, facts, table));\n return subquery === c.related.subquery\n ? c\n : {...c, related: {...c.related, subquery}};\n }\n }\n }\n\n // `facts` already holds the simple conjuncts of `c` and of the ANDs nested\n // directly in it, so nested ANDs must not add them again.\n function visitConjunction(\n c: Conjunction,\n table: string,\n facts: readonly SimpleCondition[],\n ): Conjunction {\n const conditions = mapShared(c.conditions, x =>\n x.type === 'and'\n ? visitConjunction(x, table, facts)\n : visitCondition(x, table, facts),\n );\n return conditions === c.conditions ? c : {...c, conditions};\n }\n\n function pushInto(\n csq: CorrelatedSubquery,\n facts: readonly SimpleCondition[],\n parentTable: string,\n ): AST {\n const {parentField, childField} = csq.correlation;\n const {subquery} = csq;\n const conjuncts = subquery.where ? simpleConjuncts(subquery.where) : [];\n const added: SimpleCondition[] = [];\n for (const fact of facts) {\n if (!isPushable(fact)) {\n continue;\n }\n for (let i = 0; i < parentField.length; i++) {\n if (\n parentField[i] === fact.left.name &&\n haveSameScalarType(\n columnsOf(parentTable)[parentField[i]],\n columnsOf(subquery.table)[childField[i]],\n )\n ) {\n const copy: SimpleCondition = {\n ...fact,\n left: {type: 'column', name: childField[i]},\n };\n const same = conjuncts.find(c => isSameCondition(c, copy));\n if (same) {\n pushed?.add(same);\n } else {\n conjuncts.push(copy);\n added.push(copy);\n pushed?.add(copy);\n }\n }\n }\n }\n if (added.length === 0) {\n return subquery;\n }\n return {\n ...subquery,\n where: simplifyCondition({\n type: 'and',\n conditions: subquery.where ? [subquery.where, ...added] : added,\n }),\n };\n }\n\n return visit(ast);\n}\n\n/**\n * The simple conditions that are conjuncts of `c`, including those of ANDs\n * nested in ANDs.\n */\nfunction simpleConjuncts(c: Condition): SimpleCondition[] {\n switch (c.type) {\n case 'simple':\n return [c];\n case 'and':\n return c.conditions.flatMap(simpleConjuncts);\n default:\n return [];\n }\n}\n\nfunction isPushable(c: SimpleCondition): c is ColumnCondition {\n if (c.left.type !== 'column' || c.right.type !== 'literal') {\n return false;\n }\n switch (c.op) {\n case '=':\n case 'IS':\n return true;\n case 'IN':\n return (\n Array.isArray(c.right.value) &&\n c.right.value.length <= MAX_PUSHED_IN_VALUES\n );\n default:\n return false;\n }\n}\n\nfunction isSameCondition(a: SimpleCondition, b: SimpleCondition): boolean {\n return (\n a.op === b.op &&\n a.left.type === 'column' &&\n b.left.type === 'column' &&\n a.left.name === b.left.name &&\n a.right.type === 'literal' &&\n b.right.type === 'literal' &&\n deepEqual(a.right.value, b.right.value)\n );\n}\n\nfunction haveSameScalarType(\n parent: SchemaValue | undefined,\n child: SchemaValue | undefined,\n): boolean {\n return (\n parent !== undefined &&\n child !== undefined &&\n parent.type === child.type &&\n parent.type !== 'json'\n );\n}\n\n/**\n * Like `Array.prototype.map`, but returns `arr` itself when `f` returns every\n * element unchanged.\n */\nfunction mapShared<T>(arr: readonly T[], f: (x: T) => T): readonly T[] {\n let result: T[] | undefined;\n for (let i = 0; i < arr.length; i++) {\n const x = f(arr[i]);\n if (result === undefined && x !== arr[i]) {\n result = arr.slice(0, i);\n }\n result?.push(x);\n }\n return result ?? arr;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDA,SAAgB,6BACd,KACA,WACA,QACK;CACL,SAAS,MAAM,KAAe;EAC5B,MAAM,QAAQ,IAAI,SAAS,eAAe,IAAI,OAAO,IAAI,OAAO,CAAC,CAAC;EAClE,MAAM,QAAQ,QAAQ,gBAAgB,KAAK,IAAI,CAAC;EAChD,MAAM,UACJ,IAAI,WACJ,UAAU,IAAI,UAAS,QAAO;GAC5B,MAAM,WAAW,MAAM,SAAS,KAAK,OAAO,IAAI,KAAK,CAAC;GACtD,OAAO,aAAa,IAAI,WAAW,MAAM;IAAC,GAAG;IAAK;GAAQ;EAC5D,CAAC;EACH,IAAI,UAAU,IAAI,SAAS,YAAY,IAAI,SACzC,OAAO;EAET,OAAO;GAAC,GAAG;GAAK;GAAO;EAAO;CAChC;CAEA,SAAS,eACP,GACA,OACA,OACW;EACX,QAAQ,EAAE,MAAV;GACE,KAAK,UACH,OAAO;GACT,KAAK,OACH,OAAO,iBAAiB,GAAG,OAAO,CAAC,GAAG,OAAO,GAAG,gBAAgB,CAAC,CAAC,CAAC;GACrE,KAAK,MAAM;IACT,MAAM,aAAa,UAAU,EAAE,aAAY,MACzC,eAAe,GAAG,OAAO,KAAK,CAChC;IACA,OAAO,eAAe,EAAE,aAAa,IAAI;KAAC,GAAG;KAAG;IAAU;GAC5D;GACA,KAAK,sBAAsB;IACzB,MAAM,WAAW,MAAM,SAAS,EAAE,SAAS,OAAO,KAAK,CAAC;IACxD,OAAO,aAAa,EAAE,QAAQ,WAC1B,IACA;KAAC,GAAG;KAAG,SAAS;MAAC,GAAG,EAAE;MAAS;KAAQ;IAAC;GAC9C;EACF;CACF;CAIA,SAAS,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eAAe;EAC7C,SACE,OAAO,CAAC;CACZ;AACF;AAEA,SAAS,WAAW,GAA0C;CAC5D,IAAI,EAAE,KAAK,SAAS,YAAY,EAAE,MAAM,SAAS,WAC/C,OAAO;CAET,QAAQ,EAAE,IAAV;EACE,KAAK;EACL,KAAK,MACH,OAAO;EACT,KAAK,MACH,OACE,MAAM,QAAQ,EAAE,MAAM,KAAK,KAC3B,EAAE,MAAM,MAAM,UAAA;EAElB,SACE,OAAO;CACX;AACF;AAEA,SAAS,gBAAgB,GAAoB,GAA6B;CACxE,OACE,EAAE,OAAO,EAAE,MACX,EAAE,KAAK,SAAS,YAChB,EAAE,KAAK,SAAS,YAChB,EAAE,KAAK,SAAS,EAAE,KAAK,QACvB,EAAE,MAAM,SAAS,aACjB,EAAE,MAAM,SAAS,aACjB,UAAU,EAAE,MAAM,OAAO,EAAE,MAAM,KAAK;AAE1C;AAEA,SAAS,mBACP,QACA,OACS;CACT,OACE,WAAW,KAAA,KACX,UAAU,KAAA,KACV,OAAO,SAAS,MAAM,QACtB,OAAO,SAAS;AAEpB;;;;;AAMA,SAAS,UAAa,KAAmB,GAA8B;CACrE,IAAI;CACJ,KAAK,IAAI,IAAI,GAAG,IAAI,IAAI,QAAQ,KAAK;EACnC,MAAM,IAAI,EAAE,IAAI,EAAE;EAClB,IAAI,WAAW,KAAA,KAAa,MAAM,IAAI,IACpC,SAAS,IAAI,MAAM,GAAG,CAAC;EAEzB,QAAQ,KAAK,CAAC;CAChB;CACA,OAAO,UAAU;AACnB"}
@@ -1,68 +0,0 @@
1
- import type { Row, Value } from '../../../zero-protocol/src/data.ts';
2
- import type { NoSubqueryCondition } from '../builder/filter.ts';
3
- import type { SourceChange } from './source.ts';
4
- /**
5
- * The static equality constraint a connection's filters place on a single
6
- * column: the row is accepted only if `row[column]` is one of `values`.
7
- * The push-time counterpart of the fetch-time `Constraint` in
8
- * `constraint.ts`, which pins columns to single values.
9
- */
10
- export type StaticConstraint = {
11
- readonly column: string;
12
- readonly values: readonly Value[];
13
- };
14
- /**
15
- * Indexes the connections of a source by a static equality constraint
16
- * (`column = literal` or `column IN (literals)`) taken from each
17
- * connection's filters, so that a push can determine in O(distinct indexed
18
- * columns) whether any connection could possibly accept a row, before doing
19
- * any per-connection work.
20
- *
21
- * The index is conservative: {@link mayAccept} returns `true` whenever a
22
- * connection's filters could accept the row, and may return `true` when they
23
- * do not (e.g. the connection has further conditions that reject it).
24
- * It only ever returns `false` when every connection's filters reject the
25
- * row. Connections without a static equality constraint (no filters, or
26
- * filters whose top level is not an equality) count as unconstrained and
27
- * make every row a candidate, as does an index with no connections at all.
28
- *
29
- * Values are matched with SameValueZero (`Map` key semantics), which agrees
30
- * with the `=` / `IN` predicates (`===` / `Set#has`) for every value except
31
- * `NaN`, where the index is merely more permissive.
32
- */
33
- export declare class ConnectionIndex<C> {
34
- #private;
35
- add(connection: C, filters: NoSubqueryCondition | undefined): void;
36
- remove(connection: C): void;
37
- get size(): number;
38
- /**
39
- * Returns `false` only if the filters of every indexed connection reject
40
- * `row`. An empty index accepts every row: a source with no connections
41
- * is still written to (e.g. to populate it).
42
- */
43
- mayAccept(row: Row): boolean;
44
- /**
45
- * Returns `false` only if the filters of every indexed connection reject
46
- * the row(s) of `change`: the row for an add or remove, and both the old
47
- * and the new row for an edit.
48
- */
49
- mayAcceptChange(change: SourceChange): boolean;
50
- }
51
- /**
52
- * Extracts a static equality constraint that every row accepted by
53
- * `condition` must satisfy, or `undefined` if there is none.
54
- *
55
- * - `column = literal`, `column IS literal` and `column IN (literals)`
56
- * constrain the column. `column = null` (which the predicate folds to
57
- * `false`) and an empty `IN` constrain it to the empty set, i.e. the
58
- * connection never accepts a row.
59
- * - An `and` is constrained by any of its constrained conditions; the one
60
- * with the fewest values is chosen, so a never-matching condition wins.
61
- * - An `or` is constrained only if all of its branches constrain the same
62
- * column, by the union of their values. Never-matching branches cannot
63
- * widen the result and are ignored.
64
- * - Anything else (`!=`, `IS NOT`, `NOT IN`, ranges, `LIKE`, a literal on
65
- * the left) is unconstrained.
66
- */
67
- export declare function staticConstraint(condition: NoSubqueryCondition | undefined): StaticConstraint | undefined;
68
- //# sourceMappingURL=connection-index.d.ts.map