@rocicorp/zero 0.5.2024103100 → 0.6.2024111600

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 (724) hide show
  1. package/out/{internal.js → advanced.js} +2 -2
  2. package/out/{chunk-TBA526RR.js → chunk-V5NTGJ4X.js} +1211 -624
  3. package/out/chunk-V5NTGJ4X.js.map +7 -0
  4. package/out/{chunk-RCVGGCMG.js → chunk-YCMA66NH.js} +2 -2
  5. package/out/{chunk-RCVGGCMG.js.map → chunk-YCMA66NH.js.map} +2 -2
  6. package/out/react.js.map +2 -2
  7. package/out/shared/src/browser-env.d.ts +17 -0
  8. package/out/shared/src/browser-env.d.ts.map +1 -1
  9. package/out/shared/src/expand.d.ts +7 -0
  10. package/out/shared/src/expand.d.ts.map +1 -0
  11. package/out/shared/src/valita.d.ts +7 -0
  12. package/out/shared/src/valita.d.ts.map +1 -1
  13. package/out/shared/src/valita.js +28 -0
  14. package/out/shared/src/valita.js.map +1 -1
  15. package/out/solid.js +5 -5
  16. package/out/solid.js.map +2 -2
  17. package/out/zero-advanced/src/mod.d.ts +7 -7
  18. package/out/zero-advanced/src/mod.d.ts.map +1 -1
  19. package/out/zero-cache/src/auth/load-authorization.d.ts +3 -0
  20. package/out/zero-cache/src/auth/load-authorization.d.ts.map +1 -0
  21. package/out/zero-cache/src/auth/load-authorization.js +21 -0
  22. package/out/zero-cache/src/auth/load-authorization.js.map +1 -0
  23. package/out/zero-cache/src/config/config.d.ts +112 -0
  24. package/out/zero-cache/src/config/config.d.ts.map +1 -0
  25. package/out/zero-cache/src/config/config.js +246 -0
  26. package/out/zero-cache/src/config/config.js.map +1 -0
  27. package/out/zero-cache/src/config/zero-config.d.ts +145 -964
  28. package/out/zero-cache/src/config/zero-config.d.ts.map +1 -1
  29. package/out/zero-cache/src/config/zero-config.js +242 -115
  30. package/out/zero-cache/src/config/zero-config.js.map +1 -1
  31. package/out/zero-cache/src/db/delete-lite-db.d.ts +2 -0
  32. package/out/zero-cache/src/db/delete-lite-db.d.ts.map +1 -0
  33. package/out/zero-cache/src/db/delete-lite-db.js +7 -0
  34. package/out/zero-cache/src/db/delete-lite-db.js.map +1 -0
  35. package/out/zero-cache/src/db/migration.d.ts +1 -0
  36. package/out/zero-cache/src/db/migration.d.ts.map +1 -1
  37. package/out/zero-cache/src/db/migration.js +17 -7
  38. package/out/zero-cache/src/db/migration.js.map +1 -1
  39. package/out/zero-cache/src/db/pg-to-lite.d.ts +1 -1
  40. package/out/zero-cache/src/db/pg-to-lite.d.ts.map +1 -1
  41. package/out/zero-cache/src/db/pg-to-lite.js +7 -3
  42. package/out/zero-cache/src/db/pg-to-lite.js.map +1 -1
  43. package/out/zero-cache/src/db/short-lived-client.d.ts +16 -0
  44. package/out/zero-cache/src/db/short-lived-client.d.ts.map +1 -0
  45. package/out/zero-cache/src/db/short-lived-client.js +50 -0
  46. package/out/zero-cache/src/db/short-lived-client.js.map +1 -0
  47. package/out/zero-cache/src/db/specs.d.ts +12 -3
  48. package/out/zero-cache/src/db/specs.d.ts.map +1 -1
  49. package/out/zero-cache/src/db/specs.js +6 -1
  50. package/out/zero-cache/src/db/specs.js.map +1 -1
  51. package/out/zero-cache/src/db/transaction-pool.d.ts +7 -2
  52. package/out/zero-cache/src/db/transaction-pool.d.ts.map +1 -1
  53. package/out/zero-cache/src/db/transaction-pool.js +42 -8
  54. package/out/zero-cache/src/db/transaction-pool.js.map +1 -1
  55. package/out/zero-cache/src/server/change-streamer.d.ts.map +1 -1
  56. package/out/zero-cache/src/server/change-streamer.js +34 -9
  57. package/out/zero-cache/src/server/change-streamer.js.map +1 -1
  58. package/out/zero-cache/src/server/life-cycle.d.ts +1 -1
  59. package/out/zero-cache/src/server/life-cycle.d.ts.map +1 -1
  60. package/out/zero-cache/src/server/life-cycle.js +2 -3
  61. package/out/zero-cache/src/server/life-cycle.js.map +1 -1
  62. package/out/zero-cache/src/server/logging.d.ts.map +1 -1
  63. package/out/zero-cache/src/server/logging.js +2 -15
  64. package/out/zero-cache/src/server/logging.js.map +1 -1
  65. package/out/zero-cache/src/server/main.js +28 -10
  66. package/out/zero-cache/src/server/main.js.map +1 -1
  67. package/out/zero-cache/src/server/replicator.d.ts.map +1 -1
  68. package/out/zero-cache/src/server/replicator.js +6 -5
  69. package/out/zero-cache/src/server/replicator.js.map +1 -1
  70. package/out/zero-cache/src/server/syncer.d.ts.map +1 -1
  71. package/out/zero-cache/src/server/syncer.js +16 -12
  72. package/out/zero-cache/src/server/syncer.js.map +1 -1
  73. package/out/zero-cache/src/services/change-streamer/change-streamer-http.d.ts +2 -3
  74. package/out/zero-cache/src/services/change-streamer/change-streamer-http.d.ts.map +1 -1
  75. package/out/zero-cache/src/services/change-streamer/change-streamer-http.js +2 -3
  76. package/out/zero-cache/src/services/change-streamer/change-streamer-http.js.map +1 -1
  77. package/out/zero-cache/src/services/change-streamer/change-streamer-service.d.ts +153 -2
  78. package/out/zero-cache/src/services/change-streamer/change-streamer-service.d.ts.map +1 -1
  79. package/out/zero-cache/src/services/change-streamer/change-streamer-service.js +136 -19
  80. package/out/zero-cache/src/services/change-streamer/change-streamer-service.js.map +1 -1
  81. package/out/zero-cache/src/services/change-streamer/change-streamer.d.ts +17 -9
  82. package/out/zero-cache/src/services/change-streamer/change-streamer.d.ts.map +1 -1
  83. package/out/zero-cache/src/services/change-streamer/change-streamer.js +4 -2
  84. package/out/zero-cache/src/services/change-streamer/change-streamer.js.map +1 -1
  85. package/out/zero-cache/src/services/change-streamer/forwarder.d.ts +1 -0
  86. package/out/zero-cache/src/services/change-streamer/forwarder.d.ts.map +1 -1
  87. package/out/zero-cache/src/services/change-streamer/forwarder.js +9 -2
  88. package/out/zero-cache/src/services/change-streamer/forwarder.js.map +1 -1
  89. package/out/zero-cache/src/services/change-streamer/pg/change-source.d.ts +10 -0
  90. package/out/zero-cache/src/services/change-streamer/pg/change-source.d.ts.map +1 -1
  91. package/out/zero-cache/src/services/change-streamer/pg/change-source.js +171 -24
  92. package/out/zero-cache/src/services/change-streamer/pg/change-source.js.map +1 -1
  93. package/out/zero-cache/src/services/change-streamer/pg/initial-sync.d.ts.map +1 -1
  94. package/out/zero-cache/src/services/change-streamer/pg/initial-sync.js +32 -18
  95. package/out/zero-cache/src/services/change-streamer/pg/initial-sync.js.map +1 -1
  96. package/out/zero-cache/src/services/change-streamer/pg/schema/ddl.d.ts +62 -39
  97. package/out/zero-cache/src/services/change-streamer/pg/schema/ddl.d.ts.map +1 -1
  98. package/out/zero-cache/src/services/change-streamer/pg/schema/ddl.js +8 -40
  99. package/out/zero-cache/src/services/change-streamer/pg/schema/ddl.js.map +1 -1
  100. package/out/zero-cache/src/services/change-streamer/pg/schema/init.d.ts +8 -0
  101. package/out/zero-cache/src/services/change-streamer/pg/schema/init.d.ts.map +1 -1
  102. package/out/zero-cache/src/services/change-streamer/pg/schema/init.js +41 -8
  103. package/out/zero-cache/src/services/change-streamer/pg/schema/init.js.map +1 -1
  104. package/out/zero-cache/src/services/change-streamer/pg/schema/published.d.ts +83 -13
  105. package/out/zero-cache/src/services/change-streamer/pg/schema/published.d.ts.map +1 -1
  106. package/out/zero-cache/src/services/change-streamer/pg/schema/published.js +15 -5
  107. package/out/zero-cache/src/services/change-streamer/pg/schema/published.js.map +1 -1
  108. package/out/zero-cache/src/services/change-streamer/pg/schema/shard.d.ts +39 -3
  109. package/out/zero-cache/src/services/change-streamer/pg/schema/shard.d.ts.map +1 -1
  110. package/out/zero-cache/src/services/change-streamer/pg/schema/shard.js +67 -36
  111. package/out/zero-cache/src/services/change-streamer/pg/schema/shard.js.map +1 -1
  112. package/out/zero-cache/src/services/change-streamer/pg/schema/validation.d.ts +8 -0
  113. package/out/zero-cache/src/services/change-streamer/pg/schema/validation.d.ts.map +1 -0
  114. package/out/zero-cache/src/services/change-streamer/pg/schema/validation.js +33 -0
  115. package/out/zero-cache/src/services/change-streamer/pg/schema/validation.js.map +1 -0
  116. package/out/zero-cache/src/services/change-streamer/schema/change.d.ts +5 -1
  117. package/out/zero-cache/src/services/change-streamer/schema/change.d.ts.map +1 -1
  118. package/out/zero-cache/src/services/change-streamer/schema/change.js +3 -0
  119. package/out/zero-cache/src/services/change-streamer/schema/change.js.map +1 -1
  120. package/out/zero-cache/src/services/change-streamer/schema/init.d.ts.map +1 -1
  121. package/out/zero-cache/src/services/change-streamer/schema/init.js +4 -6
  122. package/out/zero-cache/src/services/change-streamer/schema/init.js.map +1 -1
  123. package/out/zero-cache/src/services/change-streamer/schema/tables.d.ts +6 -1
  124. package/out/zero-cache/src/services/change-streamer/schema/tables.d.ts.map +1 -1
  125. package/out/zero-cache/src/services/change-streamer/schema/tables.js +19 -4
  126. package/out/zero-cache/src/services/change-streamer/schema/tables.js.map +1 -1
  127. package/out/zero-cache/src/services/change-streamer/storer.d.ts +29 -2
  128. package/out/zero-cache/src/services/change-streamer/storer.d.ts.map +1 -1
  129. package/out/zero-cache/src/services/change-streamer/storer.js +90 -8
  130. package/out/zero-cache/src/services/change-streamer/storer.js.map +1 -1
  131. package/out/zero-cache/src/services/change-streamer/subscriber.d.ts +1 -0
  132. package/out/zero-cache/src/services/change-streamer/subscriber.d.ts.map +1 -1
  133. package/out/zero-cache/src/services/change-streamer/subscriber.js +18 -3
  134. package/out/zero-cache/src/services/change-streamer/subscriber.js.map +1 -1
  135. package/out/zero-cache/src/services/dispatcher/dispatcher.d.ts +5 -3
  136. package/out/zero-cache/src/services/dispatcher/dispatcher.d.ts.map +1 -1
  137. package/out/zero-cache/src/services/dispatcher/dispatcher.js +20 -5
  138. package/out/zero-cache/src/services/dispatcher/dispatcher.js.map +1 -1
  139. package/out/zero-cache/src/services/mutagen/mutagen.d.ts +6 -5
  140. package/out/zero-cache/src/services/mutagen/mutagen.d.ts.map +1 -1
  141. package/out/zero-cache/src/services/mutagen/mutagen.js +26 -20
  142. package/out/zero-cache/src/services/mutagen/mutagen.js.map +1 -1
  143. package/out/zero-cache/src/services/mutagen/write-authorizer.d.ts +7 -6
  144. package/out/zero-cache/src/services/mutagen/write-authorizer.d.ts.map +1 -1
  145. package/out/zero-cache/src/services/mutagen/write-authorizer.js +12 -20
  146. package/out/zero-cache/src/services/mutagen/write-authorizer.js.map +1 -1
  147. package/out/zero-cache/src/services/replicator/incremental-sync.d.ts +1 -1
  148. package/out/zero-cache/src/services/replicator/incremental-sync.d.ts.map +1 -1
  149. package/out/zero-cache/src/services/replicator/incremental-sync.js +8 -8
  150. package/out/zero-cache/src/services/replicator/incremental-sync.js.map +1 -1
  151. package/out/zero-cache/src/services/replicator/schema/replication-state.d.ts.map +1 -1
  152. package/out/zero-cache/src/services/replicator/schema/replication-state.js +1 -10
  153. package/out/zero-cache/src/services/replicator/schema/replication-state.js.map +1 -1
  154. package/out/zero-cache/src/services/running-state.d.ts +6 -1
  155. package/out/zero-cache/src/services/running-state.d.ts.map +1 -1
  156. package/out/zero-cache/src/services/running-state.js +23 -5
  157. package/out/zero-cache/src/services/running-state.js.map +1 -1
  158. package/out/zero-cache/src/services/view-syncer/database-storage.d.ts +1 -1
  159. package/out/zero-cache/src/services/view-syncer/database-storage.d.ts.map +1 -1
  160. package/out/zero-cache/src/services/view-syncer/pipeline-driver.js +1 -1
  161. package/out/zero-cache/src/services/view-syncer/pipeline-driver.js.map +1 -1
  162. package/out/zero-cache/src/services/view-syncer/schema/types.d.ts +49 -29
  163. package/out/zero-cache/src/services/view-syncer/schema/types.d.ts.map +1 -1
  164. package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts.map +1 -1
  165. package/out/zero-cache/src/services/view-syncer/view-syncer.js +2 -1
  166. package/out/zero-cache/src/services/view-syncer/view-syncer.js.map +1 -1
  167. package/out/zero-cache/src/types/lexi-version.d.ts +3 -2
  168. package/out/zero-cache/src/types/lexi-version.d.ts.map +1 -1
  169. package/out/zero-cache/src/types/lexi-version.js +8 -6
  170. package/out/zero-cache/src/types/lexi-version.js.map +1 -1
  171. package/out/zero-cache/src/types/lite.d.ts +1 -1
  172. package/out/zero-cache/src/types/lite.d.ts.map +1 -1
  173. package/out/zero-cache/src/types/lite.js +0 -1
  174. package/out/zero-cache/src/types/lite.js.map +1 -1
  175. package/out/zero-cache/src/types/processes.d.ts.map +1 -1
  176. package/out/zero-cache/src/types/processes.js +1 -0
  177. package/out/zero-cache/src/types/processes.js.map +1 -1
  178. package/out/zero-cache/src/workers/replicator.d.ts.map +1 -1
  179. package/out/zero-cache/src/workers/replicator.js +2 -4
  180. package/out/zero-cache/src/workers/replicator.js.map +1 -1
  181. package/out/zero-cache/src/workers/syncer.js +1 -1
  182. package/out/zero-cache/src/workers/syncer.js.map +1 -1
  183. package/out/zero-client/src/client/context.d.ts +4 -4
  184. package/out/zero-client/src/client/context.d.ts.map +1 -1
  185. package/out/zero-client/src/client/crud.d.ts +57 -26
  186. package/out/zero-client/src/client/crud.d.ts.map +1 -1
  187. package/out/zero-client/src/client/http-string.d.ts +1 -0
  188. package/out/zero-client/src/client/http-string.d.ts.map +1 -1
  189. package/out/zero-client/src/client/keys.d.ts +1 -1
  190. package/out/zero-client/src/client/keys.d.ts.map +1 -1
  191. package/out/zero-client/src/client/log-options.d.ts +2 -1
  192. package/out/zero-client/src/client/log-options.d.ts.map +1 -1
  193. package/out/zero-client/src/client/options.d.ts +9 -9
  194. package/out/zero-client/src/client/options.d.ts.map +1 -1
  195. package/out/zero-client/src/client/protocol-version.d.ts +2 -0
  196. package/out/zero-client/src/client/protocol-version.d.ts.map +1 -0
  197. package/out/zero-client/src/client/query-manager.d.ts +1 -1
  198. package/out/zero-client/src/client/query-manager.d.ts.map +1 -1
  199. package/out/zero-client/src/client/server-option.d.ts.map +1 -1
  200. package/out/zero-client/src/client/zero-poke-handler.d.ts +1 -1
  201. package/out/zero-client/src/client/zero-poke-handler.d.ts.map +1 -1
  202. package/out/zero-client/src/client/zero.d.ts +27 -22
  203. package/out/zero-client/src/client/zero.d.ts.map +1 -1
  204. package/out/zero-client/src/mod.d.ts +8 -7
  205. package/out/zero-client/src/mod.d.ts.map +1 -1
  206. package/out/zero-protocol/src/ast.d.ts +37 -21
  207. package/out/zero-protocol/src/ast.d.ts.map +1 -1
  208. package/out/zero-protocol/src/ast.js +21 -6
  209. package/out/zero-protocol/src/ast.js.map +1 -1
  210. package/out/zero-protocol/src/change-desired-queries.d.ts +16 -8
  211. package/out/zero-protocol/src/change-desired-queries.d.ts.map +1 -1
  212. package/out/zero-protocol/src/connect.d.ts +16 -8
  213. package/out/zero-protocol/src/connect.d.ts.map +1 -1
  214. package/out/zero-protocol/src/down.d.ts +16 -8
  215. package/out/zero-protocol/src/down.d.ts.map +1 -1
  216. package/out/zero-protocol/src/poke.d.ts +32 -16
  217. package/out/zero-protocol/src/poke.d.ts.map +1 -1
  218. package/out/zero-protocol/src/push.d.ts +18 -18
  219. package/out/zero-protocol/src/push.d.ts.map +1 -1
  220. package/out/zero-protocol/src/push.js +5 -5
  221. package/out/zero-protocol/src/push.js.map +1 -1
  222. package/out/zero-protocol/src/queries-patch.d.ts +24 -12
  223. package/out/zero-protocol/src/queries-patch.d.ts.map +1 -1
  224. package/out/zero-protocol/src/up.d.ts +18 -10
  225. package/out/zero-protocol/src/up.d.ts.map +1 -1
  226. package/out/zero-react/src/use-query.d.ts +2 -1
  227. package/out/zero-react/src/use-query.d.ts.map +1 -1
  228. package/out/zero-react/src/use-zero.d.ts +2 -1
  229. package/out/zero-react/src/use-zero.d.ts.map +1 -1
  230. package/out/zero-schema/src/authorization.d.ts +25 -0
  231. package/out/zero-schema/src/authorization.d.ts.map +1 -0
  232. package/out/zero-schema/src/compiled-authorization.d.ts +379 -0
  233. package/out/zero-schema/src/compiled-authorization.d.ts.map +1 -0
  234. package/out/zero-schema/src/compiled-authorization.js +15 -0
  235. package/out/zero-schema/src/compiled-authorization.js.map +1 -0
  236. package/out/zero-schema/src/mod.d.ts +5 -0
  237. package/out/zero-schema/src/mod.d.ts.map +1 -0
  238. package/out/{zql/src/zql/query → zero-schema/src}/normalize-table-schema.d.ts +2 -3
  239. package/out/zero-schema/src/normalize-table-schema.d.ts.map +1 -0
  240. package/out/{zero-client/src/client → zero-schema/src}/normalized-schema.d.ts +2 -2
  241. package/out/zero-schema/src/normalized-schema.d.ts.map +1 -0
  242. package/out/zero-schema/src/schema.d.ts +9 -0
  243. package/out/zero-schema/src/schema.d.ts.map +1 -0
  244. package/out/{zql/src/zql/query/schema.d.ts → zero-schema/src/table-schema.d.ts} +47 -3
  245. package/out/zero-schema/src/table-schema.d.ts.map +1 -0
  246. package/out/{zql/src/zql/query/schema.js → zero-schema/src/table-schema.js} +1 -1
  247. package/out/zero-schema/src/table-schema.js.map +1 -0
  248. package/out/zero-solid/src/create-zero.d.ts +2 -1
  249. package/out/zero-solid/src/create-zero.d.ts.map +1 -1
  250. package/out/zero.js +6 -14
  251. package/out/zql/src/{zql/builder → builder}/builder.d.ts +5 -5
  252. package/out/zql/src/builder/builder.d.ts.map +1 -0
  253. package/out/zql/src/{zql/builder → builder}/builder.js +81 -33
  254. package/out/zql/src/builder/builder.js.map +1 -0
  255. package/out/zql/src/builder/error.d.ts.map +1 -0
  256. package/out/zql/src/builder/error.js.map +1 -0
  257. package/out/zql/src/builder/filter.d.ts +7 -0
  258. package/out/zql/src/builder/filter.d.ts.map +1 -0
  259. package/out/zql/src/{zql/builder → builder}/filter.js +19 -1
  260. package/out/zql/src/builder/filter.js.map +1 -0
  261. package/out/zql/src/builder/like.d.ts +3 -0
  262. package/out/zql/src/builder/like.d.ts.map +1 -0
  263. package/out/zql/src/{zql/builder → builder}/like.js +1 -1
  264. package/out/zql/src/builder/like.js.map +1 -0
  265. package/out/zql/src/ivm/array-view.d.ts.map +1 -0
  266. package/out/zql/src/{zql/ivm → ivm}/change.d.ts +2 -1
  267. package/out/zql/src/ivm/change.d.ts.map +1 -0
  268. package/out/zql/src/ivm/change.js +5 -0
  269. package/out/zql/src/ivm/change.js.map +1 -0
  270. package/out/zql/src/{zql/ivm → ivm}/data.d.ts +2 -2
  271. package/out/zql/src/ivm/data.d.ts.map +1 -0
  272. package/out/zql/src/{zql/ivm → ivm}/data.js +1 -1
  273. package/out/zql/src/ivm/data.js.map +1 -0
  274. package/out/zql/src/ivm/exists.d.ts +18 -0
  275. package/out/zql/src/ivm/exists.d.ts.map +1 -0
  276. package/out/zql/src/ivm/exists.js +186 -0
  277. package/out/zql/src/ivm/exists.js.map +1 -0
  278. package/out/zql/src/{zql/ivm → ivm}/fan-in.d.ts +3 -3
  279. package/out/zql/src/ivm/fan-in.d.ts.map +1 -0
  280. package/out/zql/src/{zql/ivm → ivm}/fan-in.js +8 -11
  281. package/out/zql/src/ivm/fan-in.js.map +1 -0
  282. package/out/zql/src/{zql/ivm → ivm}/fan-out.d.ts +1 -1
  283. package/out/zql/src/ivm/fan-out.d.ts.map +1 -0
  284. package/out/zql/src/{zql/ivm → ivm}/fan-out.js +8 -7
  285. package/out/zql/src/ivm/fan-out.js.map +1 -0
  286. package/out/zql/src/{zql/ivm → ivm}/filter.d.ts +3 -3
  287. package/out/zql/src/ivm/filter.d.ts.map +1 -0
  288. package/out/zql/src/{zql/ivm → ivm}/filter.js +2 -2
  289. package/out/zql/src/ivm/filter.js.map +1 -0
  290. package/out/zql/src/{zql/ivm → ivm}/join.d.ts +2 -2
  291. package/out/zql/src/ivm/join.d.ts.map +1 -0
  292. package/out/zql/src/{zql/ivm → ivm}/join.js +2 -2
  293. package/out/zql/src/ivm/join.js.map +1 -0
  294. package/out/zql/src/ivm/lookahead-iterator.d.ts.map +1 -0
  295. package/out/zql/src/ivm/lookahead-iterator.js.map +1 -0
  296. package/out/zql/src/{zql/ivm → ivm}/maybe-split-and-push-edit-change.d.ts +1 -1
  297. package/out/zql/src/ivm/maybe-split-and-push-edit-change.d.ts.map +1 -0
  298. package/out/zql/src/ivm/maybe-split-and-push-edit-change.js.map +1 -0
  299. package/out/zql/src/{zql/ivm → ivm}/memory-source.d.ts +16 -12
  300. package/out/zql/src/ivm/memory-source.d.ts.map +1 -0
  301. package/out/zql/src/{zql/ivm → ivm}/memory-source.js +72 -92
  302. package/out/zql/src/ivm/memory-source.js.map +1 -0
  303. package/out/zql/src/{zql/ivm → ivm}/memory-storage.d.ts +1 -1
  304. package/out/zql/src/ivm/memory-storage.d.ts.map +1 -0
  305. package/out/zql/src/{zql/ivm → ivm}/operator.d.ts +5 -5
  306. package/out/zql/src/ivm/operator.d.ts.map +1 -0
  307. package/out/zql/src/ivm/operator.js.map +1 -0
  308. package/out/zql/src/ivm/schema.d.ts +15 -0
  309. package/out/zql/src/ivm/schema.d.ts.map +1 -0
  310. package/out/zql/src/ivm/schema.js +2 -0
  311. package/out/zql/src/ivm/schema.js.map +1 -0
  312. package/out/zql/src/{zql/ivm → ivm}/skip.d.ts +3 -3
  313. package/out/zql/src/ivm/skip.d.ts.map +1 -0
  314. package/out/zql/src/{zql/ivm → ivm}/skip.js +2 -2
  315. package/out/zql/src/ivm/skip.js.map +1 -0
  316. package/out/zql/src/{zql/ivm → ivm}/source.d.ts +2 -2
  317. package/out/zql/src/ivm/source.d.ts.map +1 -0
  318. package/out/zql/src/ivm/source.js.map +1 -0
  319. package/out/zql/src/ivm/stream.d.ts.map +1 -0
  320. package/out/zql/src/ivm/stream.js.map +1 -0
  321. package/out/zql/src/{zql/ivm → ivm}/take.d.ts +3 -3
  322. package/out/zql/src/ivm/take.d.ts.map +1 -0
  323. package/out/zql/src/{zql/ivm → ivm}/take.js +13 -9
  324. package/out/zql/src/ivm/take.js.map +1 -0
  325. package/out/zql/src/ivm/view-apply-change.d.ts +5 -0
  326. package/out/zql/src/ivm/view-apply-change.d.ts.map +1 -0
  327. package/out/zql/src/{zql/ivm → ivm}/view.d.ts +2 -2
  328. package/out/zql/src/ivm/view.d.ts.map +1 -0
  329. package/out/zql/src/query/auth-query.d.ts +24 -0
  330. package/out/zql/src/query/auth-query.d.ts.map +1 -0
  331. package/out/zql/src/query/dnf.d.ts +10 -0
  332. package/out/zql/src/query/dnf.d.ts.map +1 -0
  333. package/out/zql/src/query/escape-like.d.ts.map +1 -0
  334. package/out/zql/src/query/expression.d.ts +41 -0
  335. package/out/zql/src/query/expression.d.ts.map +1 -0
  336. package/out/zql/src/{zql/query → query}/query-impl.d.ts +9 -8
  337. package/out/zql/src/query/query-impl.d.ts.map +1 -0
  338. package/out/zql/src/{zql/query → query}/query-internal.d.ts +1 -1
  339. package/out/zql/src/query/query-internal.d.ts.map +1 -0
  340. package/out/zql/src/query/query.d.ts +98 -0
  341. package/out/zql/src/query/query.d.ts.map +1 -0
  342. package/out/zql/src/{zql/query → query}/typed-view.d.ts +1 -1
  343. package/out/zql/src/query/typed-view.d.ts.map +1 -0
  344. package/out/zqlite/src/db.d.ts.map +1 -1
  345. package/out/zqlite/src/db.js +19 -6
  346. package/out/zqlite/src/db.js.map +1 -1
  347. package/out/zqlite/src/table-source.d.ts +24 -3
  348. package/out/zqlite/src/table-source.d.ts.map +1 -1
  349. package/out/zqlite/src/table-source.js +117 -18
  350. package/out/zqlite/src/table-source.js.map +1 -1
  351. package/package.json +11 -6
  352. package/out/chunk-TBA526RR.js.map +0 -7
  353. package/out/datadog/src/datadog-log-sink.js +0 -231
  354. package/out/datadog/src/datadog-log-sink.js.map +0 -1
  355. package/out/datadog/src/mod.js +0 -2
  356. package/out/datadog/src/mod.js.map +0 -1
  357. package/out/replicache/src/async-iterable-to-array.js +0 -8
  358. package/out/replicache/src/async-iterable-to-array.js.map +0 -1
  359. package/out/replicache/src/bg-interval.js +0 -38
  360. package/out/replicache/src/bg-interval.js.map +0 -1
  361. package/out/replicache/src/binary-search.js +0 -31
  362. package/out/replicache/src/binary-search.js.map +0 -1
  363. package/out/replicache/src/broadcast-channel.js +0 -29
  364. package/out/replicache/src/broadcast-channel.js.map +0 -1
  365. package/out/replicache/src/btree/diff.js +0 -6
  366. package/out/replicache/src/btree/diff.js.map +0 -1
  367. package/out/replicache/src/btree/node.js +0 -392
  368. package/out/replicache/src/btree/node.js.map +0 -1
  369. package/out/replicache/src/btree/read.js +0 -227
  370. package/out/replicache/src/btree/read.js.map +0 -1
  371. package/out/replicache/src/btree/splice.js +0 -79
  372. package/out/replicache/src/btree/splice.js.map +0 -1
  373. package/out/replicache/src/btree/write.js +0 -154
  374. package/out/replicache/src/btree/write.js.map +0 -1
  375. package/out/replicache/src/call-default-fetch.js +0 -37
  376. package/out/replicache/src/call-default-fetch.js.map +0 -1
  377. package/out/replicache/src/config.js +0 -13
  378. package/out/replicache/src/config.js.map +0 -1
  379. package/out/replicache/src/connection-loop-delegates.js +0 -30
  380. package/out/replicache/src/connection-loop-delegates.js.map +0 -1
  381. package/out/replicache/src/connection-loop.js +0 -268
  382. package/out/replicache/src/connection-loop.js.map +0 -1
  383. package/out/replicache/src/cookies.js +0 -41
  384. package/out/replicache/src/cookies.js.map +0 -1
  385. package/out/replicache/src/dag/chunk.js +0 -60
  386. package/out/replicache/src/dag/chunk.js.map +0 -1
  387. package/out/replicache/src/dag/gc.js +0 -126
  388. package/out/replicache/src/dag/gc.js.map +0 -1
  389. package/out/replicache/src/dag/key-type-enum.js +0 -6
  390. package/out/replicache/src/dag/key-type-enum.js.map +0 -1
  391. package/out/replicache/src/dag/key.js +0 -54
  392. package/out/replicache/src/dag/key.js.map +0 -1
  393. package/out/replicache/src/dag/lazy-store.js +0 -532
  394. package/out/replicache/src/dag/lazy-store.js.map +0 -1
  395. package/out/replicache/src/dag/store-impl.js +0 -175
  396. package/out/replicache/src/dag/store-impl.js.map +0 -1
  397. package/out/replicache/src/dag/store.js +0 -22
  398. package/out/replicache/src/dag/store.js.map +0 -1
  399. package/out/replicache/src/dag/visitor.js +0 -22
  400. package/out/replicache/src/dag/visitor.js.map +0 -1
  401. package/out/replicache/src/db/commit.js +0 -443
  402. package/out/replicache/src/db/commit.js.map +0 -1
  403. package/out/replicache/src/db/index-operation-enum.js +0 -4
  404. package/out/replicache/src/db/index-operation-enum.js.map +0 -1
  405. package/out/replicache/src/db/index.js +0 -170
  406. package/out/replicache/src/db/index.js.map +0 -1
  407. package/out/replicache/src/db/meta-type-enum.js +0 -7
  408. package/out/replicache/src/db/meta-type-enum.js.map +0 -1
  409. package/out/replicache/src/db/read.js +0 -59
  410. package/out/replicache/src/db/read.js.map +0 -1
  411. package/out/replicache/src/db/rebase.js +0 -56
  412. package/out/replicache/src/db/rebase.js.map +0 -1
  413. package/out/replicache/src/db/scan.js +0 -2
  414. package/out/replicache/src/db/scan.js.map +0 -1
  415. package/out/replicache/src/db/write.js +0 -260
  416. package/out/replicache/src/db/write.js.map +0 -1
  417. package/out/replicache/src/error-responses.js +0 -30
  418. package/out/replicache/src/error-responses.js.map +0 -1
  419. package/out/replicache/src/filter-async-iterable.js +0 -15
  420. package/out/replicache/src/filter-async-iterable.js.map +0 -1
  421. package/out/replicache/src/format-version-enum.js +0 -9
  422. package/out/replicache/src/format-version-enum.js.map +0 -1
  423. package/out/replicache/src/format-version.js +0 -8
  424. package/out/replicache/src/format-version.js.map +0 -1
  425. package/out/replicache/src/frozen-json.js +0 -151
  426. package/out/replicache/src/frozen-json.js.map +0 -1
  427. package/out/replicache/src/get-default-puller.js +0 -74
  428. package/out/replicache/src/get-default-puller.js.map +0 -1
  429. package/out/replicache/src/get-default-pusher.js +0 -36
  430. package/out/replicache/src/get-default-pusher.js.map +0 -1
  431. package/out/replicache/src/hash.js +0 -73
  432. package/out/replicache/src/hash.js.map +0 -1
  433. package/out/replicache/src/http-request-info.js +0 -7
  434. package/out/replicache/src/http-request-info.js.map +0 -1
  435. package/out/replicache/src/impl.js +0 -2
  436. package/out/replicache/src/impl.js.map +0 -1
  437. package/out/replicache/src/index-defs.js +0 -28
  438. package/out/replicache/src/index-defs.js.map +0 -1
  439. package/out/replicache/src/invoke-kind-enum.js +0 -4
  440. package/out/replicache/src/invoke-kind-enum.js.map +0 -1
  441. package/out/replicache/src/iterable-union.js +0 -5
  442. package/out/replicache/src/iterable-union.js.map +0 -1
  443. package/out/replicache/src/kv/idb-store-with-mem-fallback.js +0 -93
  444. package/out/replicache/src/kv/idb-store-with-mem-fallback.js.map +0 -1
  445. package/out/replicache/src/kv/idb-store.js +0 -179
  446. package/out/replicache/src/kv/idb-store.js.map +0 -1
  447. package/out/replicache/src/kv/mem-store.js +0 -61
  448. package/out/replicache/src/kv/mem-store.js.map +0 -1
  449. package/out/replicache/src/kv/read-impl.js +0 -23
  450. package/out/replicache/src/kv/read-impl.js.map +0 -1
  451. package/out/replicache/src/kv/store.js +0 -2
  452. package/out/replicache/src/kv/store.js.map +0 -1
  453. package/out/replicache/src/kv/write-impl-base.js +0 -48
  454. package/out/replicache/src/kv/write-impl-base.js.map +0 -1
  455. package/out/replicache/src/kv/write-impl.js +0 -25
  456. package/out/replicache/src/kv/write-impl.js.map +0 -1
  457. package/out/replicache/src/lazy.js +0 -10
  458. package/out/replicache/src/lazy.js.map +0 -1
  459. package/out/replicache/src/log-options.js +0 -13
  460. package/out/replicache/src/log-options.js.map +0 -1
  461. package/out/replicache/src/merge-async-iterables.js +0 -61
  462. package/out/replicache/src/merge-async-iterables.js.map +0 -1
  463. package/out/replicache/src/mod.js +0 -14
  464. package/out/replicache/src/mod.js.map +0 -1
  465. package/out/replicache/src/mutation-recovery.js +0 -439
  466. package/out/replicache/src/mutation-recovery.js.map +0 -1
  467. package/out/replicache/src/new-client-channel.js +0 -77
  468. package/out/replicache/src/new-client-channel.js.map +0 -1
  469. package/out/replicache/src/on-persist-channel.js +0 -33
  470. package/out/replicache/src/on-persist-channel.js.map +0 -1
  471. package/out/replicache/src/patch-operation.js +0 -37
  472. package/out/replicache/src/patch-operation.js.map +0 -1
  473. package/out/replicache/src/pending-mutations.js +0 -18
  474. package/out/replicache/src/pending-mutations.js.map +0 -1
  475. package/out/replicache/src/persist/client-gc.js +0 -38
  476. package/out/replicache/src/persist/client-gc.js.map +0 -1
  477. package/out/replicache/src/persist/client-group-gc.js +0 -38
  478. package/out/replicache/src/persist/client-group-gc.js.map +0 -1
  479. package/out/replicache/src/persist/client-groups.js +0 -180
  480. package/out/replicache/src/persist/client-groups.js.map +0 -1
  481. package/out/replicache/src/persist/clients.js +0 -390
  482. package/out/replicache/src/persist/clients.js.map +0 -1
  483. package/out/replicache/src/persist/collect-idb-databases.js +0 -174
  484. package/out/replicache/src/persist/collect-idb-databases.js.map +0 -1
  485. package/out/replicache/src/persist/gather-mem-only-visitor.js +0 -25
  486. package/out/replicache/src/persist/gather-mem-only-visitor.js.map +0 -1
  487. package/out/replicache/src/persist/gather-not-cached-visitor.js +0 -35
  488. package/out/replicache/src/persist/gather-not-cached-visitor.js.map +0 -1
  489. package/out/replicache/src/persist/heartbeat.js +0 -37
  490. package/out/replicache/src/persist/heartbeat.js.map +0 -1
  491. package/out/replicache/src/persist/idb-databases-store-db-name.js +0 -18
  492. package/out/replicache/src/persist/idb-databases-store-db-name.js.map +0 -1
  493. package/out/replicache/src/persist/idb-databases-store.js +0 -90
  494. package/out/replicache/src/persist/idb-databases-store.js.map +0 -1
  495. package/out/replicache/src/persist/make-client-id.js +0 -13
  496. package/out/replicache/src/persist/make-client-id.js.map +0 -1
  497. package/out/replicache/src/persist/persist.js +0 -132
  498. package/out/replicache/src/persist/persist.js.map +0 -1
  499. package/out/replicache/src/persist/refresh.js +0 -147
  500. package/out/replicache/src/persist/refresh.js.map +0 -1
  501. package/out/replicache/src/process-scheduler.js +0 -93
  502. package/out/replicache/src/process-scheduler.js.map +0 -1
  503. package/out/replicache/src/puller.js +0 -2
  504. package/out/replicache/src/puller.js.map +0 -1
  505. package/out/replicache/src/pusher.js +0 -32
  506. package/out/replicache/src/pusher.js.map +0 -1
  507. package/out/replicache/src/replicache-impl.js +0 -1007
  508. package/out/replicache/src/replicache-impl.js.map +0 -1
  509. package/out/replicache/src/replicache-options.js +0 -2
  510. package/out/replicache/src/replicache-options.js.map +0 -1
  511. package/out/replicache/src/replicache.js +0 -387
  512. package/out/replicache/src/replicache.js.map +0 -1
  513. package/out/replicache/src/request-idle.js +0 -15
  514. package/out/replicache/src/request-idle.js.map +0 -1
  515. package/out/replicache/src/scan-iterator.js +0 -202
  516. package/out/replicache/src/scan-iterator.js.map +0 -1
  517. package/out/replicache/src/scan-options.js +0 -45
  518. package/out/replicache/src/scan-options.js.map +0 -1
  519. package/out/replicache/src/set-interval-with-signal.js +0 -7
  520. package/out/replicache/src/set-interval-with-signal.js.map +0 -1
  521. package/out/replicache/src/size-of-value.js +0 -77
  522. package/out/replicache/src/size-of-value.js.map +0 -1
  523. package/out/replicache/src/subscriptions.js +0 -357
  524. package/out/replicache/src/subscriptions.js.map +0 -1
  525. package/out/replicache/src/sync/diff.js +0 -75
  526. package/out/replicache/src/sync/diff.js.map +0 -1
  527. package/out/replicache/src/sync/handle-pull-response-result-type-enum.js +0 -5
  528. package/out/replicache/src/sync/handle-pull-response-result-type-enum.js.map +0 -1
  529. package/out/replicache/src/sync/ids.js +0 -4
  530. package/out/replicache/src/sync/ids.js.map +0 -1
  531. package/out/replicache/src/sync/patch.js +0 -41
  532. package/out/replicache/src/sync/patch.js.map +0 -1
  533. package/out/replicache/src/sync/pull-error.js +0 -16
  534. package/out/replicache/src/sync/pull-error.js.map +0 -1
  535. package/out/replicache/src/sync/pull.js +0 -375
  536. package/out/replicache/src/sync/pull.js.map +0 -1
  537. package/out/replicache/src/sync/push.js +0 -141
  538. package/out/replicache/src/sync/push.js.map +0 -1
  539. package/out/replicache/src/sync/request-id.js +0 -31
  540. package/out/replicache/src/sync/request-id.js.map +0 -1
  541. package/out/replicache/src/sync/sync-head-name.js +0 -2
  542. package/out/replicache/src/sync/sync-head-name.js.map +0 -1
  543. package/out/replicache/src/test-license-key.js +0 -3
  544. package/out/replicache/src/test-license-key.js.map +0 -1
  545. package/out/replicache/src/to-error.js +0 -7
  546. package/out/replicache/src/to-error.js.map +0 -1
  547. package/out/replicache/src/transaction-closed-error.js +0 -17
  548. package/out/replicache/src/transaction-closed-error.js.map +0 -1
  549. package/out/replicache/src/transactions.js +0 -144
  550. package/out/replicache/src/transactions.js.map +0 -1
  551. package/out/replicache/src/types.js +0 -2
  552. package/out/replicache/src/types.js.map +0 -1
  553. package/out/replicache/src/version.js +0 -6
  554. package/out/replicache/src/version.js.map +0 -1
  555. package/out/replicache/src/with-transactions.js +0 -28
  556. package/out/replicache/src/with-transactions.js.map +0 -1
  557. package/out/shared/src/browser-env.js +0 -14
  558. package/out/shared/src/browser-env.js.map +0 -1
  559. package/out/shared/src/document-visible.js +0 -76
  560. package/out/shared/src/document-visible.js.map +0 -1
  561. package/out/shared/src/immutable.js +0 -2
  562. package/out/shared/src/immutable.js.map +0 -1
  563. package/out/shared/src/navigator.js +0 -3
  564. package/out/shared/src/navigator.js.map +0 -1
  565. package/out/shared/src/random-uint64.js +0 -8
  566. package/out/shared/src/random-uint64.js.map +0 -1
  567. package/out/shared/src/sorted-entries.js +0 -6
  568. package/out/shared/src/sorted-entries.js.map +0 -1
  569. package/out/shared/src/types.js +0 -2
  570. package/out/shared/src/types.js.map +0 -1
  571. package/out/shared/src/writable.js +0 -2
  572. package/out/shared/src/writable.js.map +0 -1
  573. package/out/zero/src/config.d.ts +0 -2
  574. package/out/zero/src/config.d.ts.map +0 -1
  575. package/out/zero/src/config.js +0 -2
  576. package/out/zero/src/config.js.map +0 -1
  577. package/out/zero-cache/src/config/config-query.d.ts +0 -19
  578. package/out/zero-cache/src/config/config-query.d.ts.map +0 -1
  579. package/out/zero-cache/src/config/config-query.js +0 -22
  580. package/out/zero-cache/src/config/config-query.js.map +0 -1
  581. package/out/zero-cache/src/config/define-config.d.ts +0 -43
  582. package/out/zero-cache/src/config/define-config.d.ts.map +0 -1
  583. package/out/zero-cache/src/config/define-config.js +0 -120
  584. package/out/zero-cache/src/config/define-config.js.map +0 -1
  585. package/out/zero-cache/src/config/refs.d.ts +0 -3
  586. package/out/zero-cache/src/config/refs.d.ts.map +0 -1
  587. package/out/zero-cache/src/config/refs.js +0 -14
  588. package/out/zero-cache/src/config/refs.js.map +0 -1
  589. package/out/zero-client/src/client/context.js +0 -113
  590. package/out/zero-client/src/client/context.js.map +0 -1
  591. package/out/zero-client/src/client/crud.js +0 -181
  592. package/out/zero-client/src/client/crud.js.map +0 -1
  593. package/out/zero-client/src/client/enable-analytics.js +0 -21
  594. package/out/zero-client/src/client/enable-analytics.js.map +0 -1
  595. package/out/zero-client/src/client/http-string.js +0 -14
  596. package/out/zero-client/src/client/http-string.js.map +0 -1
  597. package/out/zero-client/src/client/keys.js +0 -32
  598. package/out/zero-client/src/client/keys.js.map +0 -1
  599. package/out/zero-client/src/client/log-options.js +0 -57
  600. package/out/zero-client/src/client/log-options.js.map +0 -1
  601. package/out/zero-client/src/client/metrics.js +0 -268
  602. package/out/zero-client/src/client/metrics.js.map +0 -1
  603. package/out/zero-client/src/client/normalized-schema.d.ts.map +0 -1
  604. package/out/zero-client/src/client/normalized-schema.js +0 -31
  605. package/out/zero-client/src/client/normalized-schema.js.map +0 -1
  606. package/out/zero-client/src/client/options.js +0 -2
  607. package/out/zero-client/src/client/options.js.map +0 -1
  608. package/out/zero-client/src/client/query-manager.js +0 -146
  609. package/out/zero-client/src/client/query-manager.js.map +0 -1
  610. package/out/zero-client/src/client/reload-error-handler.js +0 -23
  611. package/out/zero-client/src/client/reload-error-handler.js.map +0 -1
  612. package/out/zero-client/src/client/replicache-types.js +0 -2
  613. package/out/zero-client/src/client/replicache-types.js.map +0 -1
  614. package/out/zero-client/src/client/server-error.js +0 -22
  615. package/out/zero-client/src/client/server-error.js.map +0 -1
  616. package/out/zero-client/src/client/server-option.js +0 -37
  617. package/out/zero-client/src/client/server-option.js.map +0 -1
  618. package/out/zero-client/src/client/version.js +0 -6
  619. package/out/zero-client/src/client/version.js.map +0 -1
  620. package/out/zero-client/src/client/zero-poke-handler.js +0 -240
  621. package/out/zero-client/src/client/zero-poke-handler.js.map +0 -1
  622. package/out/zero-client/src/client/zero.js +0 -1233
  623. package/out/zero-client/src/client/zero.js.map +0 -1
  624. package/out/zero-client/src/mod.js +0 -7
  625. package/out/zero-client/src/mod.js.map +0 -1
  626. package/out/zero-client/src/util/nanoid.js +0 -34
  627. package/out/zero-client/src/util/nanoid.js.map +0 -1
  628. package/out/zero-client/src/util/socket.js +0 -4
  629. package/out/zero-client/src/util/socket.js.map +0 -1
  630. package/out/zero-protocol/src/ast-hash.js +0 -14
  631. package/out/zero-protocol/src/ast-hash.js.map +0 -1
  632. package/out/zql/src/zql/builder/builder.d.ts.map +0 -1
  633. package/out/zql/src/zql/builder/builder.js.map +0 -1
  634. package/out/zql/src/zql/builder/error.d.ts.map +0 -1
  635. package/out/zql/src/zql/builder/error.js.map +0 -1
  636. package/out/zql/src/zql/builder/filter.d.ts +0 -6
  637. package/out/zql/src/zql/builder/filter.d.ts.map +0 -1
  638. package/out/zql/src/zql/builder/filter.js.map +0 -1
  639. package/out/zql/src/zql/builder/like.d.ts +0 -3
  640. package/out/zql/src/zql/builder/like.d.ts.map +0 -1
  641. package/out/zql/src/zql/builder/like.js.map +0 -1
  642. package/out/zql/src/zql/ivm/array-view.d.ts.map +0 -1
  643. package/out/zql/src/zql/ivm/array-view.js +0 -70
  644. package/out/zql/src/zql/ivm/array-view.js.map +0 -1
  645. package/out/zql/src/zql/ivm/change.d.ts.map +0 -1
  646. package/out/zql/src/zql/ivm/change.js +0 -2
  647. package/out/zql/src/zql/ivm/change.js.map +0 -1
  648. package/out/zql/src/zql/ivm/data.d.ts.map +0 -1
  649. package/out/zql/src/zql/ivm/data.js.map +0 -1
  650. package/out/zql/src/zql/ivm/fan-in.d.ts.map +0 -1
  651. package/out/zql/src/zql/ivm/fan-in.js.map +0 -1
  652. package/out/zql/src/zql/ivm/fan-out.d.ts.map +0 -1
  653. package/out/zql/src/zql/ivm/fan-out.js.map +0 -1
  654. package/out/zql/src/zql/ivm/filter.d.ts.map +0 -1
  655. package/out/zql/src/zql/ivm/filter.js.map +0 -1
  656. package/out/zql/src/zql/ivm/join.d.ts.map +0 -1
  657. package/out/zql/src/zql/ivm/join.js.map +0 -1
  658. package/out/zql/src/zql/ivm/lookahead-iterator.d.ts.map +0 -1
  659. package/out/zql/src/zql/ivm/lookahead-iterator.js.map +0 -1
  660. package/out/zql/src/zql/ivm/maybe-split-and-push-edit-change.d.ts.map +0 -1
  661. package/out/zql/src/zql/ivm/maybe-split-and-push-edit-change.js.map +0 -1
  662. package/out/zql/src/zql/ivm/memory-source.d.ts.map +0 -1
  663. package/out/zql/src/zql/ivm/memory-source.js.map +0 -1
  664. package/out/zql/src/zql/ivm/memory-storage.d.ts.map +0 -1
  665. package/out/zql/src/zql/ivm/memory-storage.js +0 -33
  666. package/out/zql/src/zql/ivm/memory-storage.js.map +0 -1
  667. package/out/zql/src/zql/ivm/operator.d.ts.map +0 -1
  668. package/out/zql/src/zql/ivm/operator.js.map +0 -1
  669. package/out/zql/src/zql/ivm/schema.d.ts +0 -29
  670. package/out/zql/src/zql/ivm/schema.d.ts.map +0 -1
  671. package/out/zql/src/zql/ivm/schema.js +0 -3
  672. package/out/zql/src/zql/ivm/schema.js.map +0 -1
  673. package/out/zql/src/zql/ivm/skip.d.ts.map +0 -1
  674. package/out/zql/src/zql/ivm/skip.js.map +0 -1
  675. package/out/zql/src/zql/ivm/source.d.ts.map +0 -1
  676. package/out/zql/src/zql/ivm/source.js.map +0 -1
  677. package/out/zql/src/zql/ivm/stream.d.ts.map +0 -1
  678. package/out/zql/src/zql/ivm/stream.js.map +0 -1
  679. package/out/zql/src/zql/ivm/take.d.ts.map +0 -1
  680. package/out/zql/src/zql/ivm/take.js.map +0 -1
  681. package/out/zql/src/zql/ivm/view-apply-change.d.ts +0 -5
  682. package/out/zql/src/zql/ivm/view-apply-change.d.ts.map +0 -1
  683. package/out/zql/src/zql/ivm/view-apply-change.js +0 -156
  684. package/out/zql/src/zql/ivm/view-apply-change.js.map +0 -1
  685. package/out/zql/src/zql/ivm/view.d.ts.map +0 -1
  686. package/out/zql/src/zql/ivm/view.js +0 -2
  687. package/out/zql/src/zql/ivm/view.js.map +0 -1
  688. package/out/zql/src/zql/query/escape-like.d.ts.map +0 -1
  689. package/out/zql/src/zql/query/escape-like.js +0 -4
  690. package/out/zql/src/zql/query/escape-like.js.map +0 -1
  691. package/out/zql/src/zql/query/expression.d.ts +0 -25
  692. package/out/zql/src/zql/query/expression.d.ts.map +0 -1
  693. package/out/zql/src/zql/query/expression.js +0 -115
  694. package/out/zql/src/zql/query/expression.js.map +0 -1
  695. package/out/zql/src/zql/query/normalize-table-schema.d.ts.map +0 -1
  696. package/out/zql/src/zql/query/normalize-table-schema.js +0 -116
  697. package/out/zql/src/zql/query/normalize-table-schema.js.map +0 -1
  698. package/out/zql/src/zql/query/query-impl.d.ts.map +0 -1
  699. package/out/zql/src/zql/query/query-impl.js +0 -289
  700. package/out/zql/src/zql/query/query-impl.js.map +0 -1
  701. package/out/zql/src/zql/query/query-internal.d.ts.map +0 -1
  702. package/out/zql/src/zql/query/query-internal.js +0 -2
  703. package/out/zql/src/zql/query/query-internal.js.map +0 -1
  704. package/out/zql/src/zql/query/query.d.ts +0 -142
  705. package/out/zql/src/zql/query/query.d.ts.map +0 -1
  706. package/out/zql/src/zql/query/query.js +0 -3
  707. package/out/zql/src/zql/query/query.js.map +0 -1
  708. package/out/zql/src/zql/query/schema.d.ts.map +0 -1
  709. package/out/zql/src/zql/query/schema.js.map +0 -1
  710. package/out/zql/src/zql/query/typed-view.d.ts.map +0 -1
  711. package/out/zql/src/zql/query/typed-view.js +0 -2
  712. package/out/zql/src/zql/query/typed-view.js.map +0 -1
  713. /package/out/{internal.js.map → advanced.js.map} +0 -0
  714. /package/out/zql/src/{zql/builder → builder}/error.d.ts +0 -0
  715. /package/out/zql/src/{zql/builder → builder}/error.js +0 -0
  716. /package/out/zql/src/{zql/ivm → ivm}/array-view.d.ts +0 -0
  717. /package/out/zql/src/{zql/ivm → ivm}/lookahead-iterator.d.ts +0 -0
  718. /package/out/zql/src/{zql/ivm → ivm}/lookahead-iterator.js +0 -0
  719. /package/out/zql/src/{zql/ivm → ivm}/maybe-split-and-push-edit-change.js +0 -0
  720. /package/out/zql/src/{zql/ivm → ivm}/operator.js +0 -0
  721. /package/out/zql/src/{zql/ivm → ivm}/source.js +0 -0
  722. /package/out/zql/src/{zql/ivm → ivm}/stream.d.ts +0 -0
  723. /package/out/zql/src/{zql/ivm → ivm}/stream.js +0 -0
  724. /package/out/zql/src/{zql/query → query}/escape-like.d.ts +0 -0
@@ -14,7 +14,7 @@ import {
14
14
  must,
15
15
  throwInvalidType,
16
16
  unreachable
17
- } from "./chunk-RCVGGCMG.js";
17
+ } from "./chunk-YCMA66NH.js";
18
18
  import {
19
19
  __export,
20
20
  __reExport
@@ -564,6 +564,9 @@ var WriteImplBase = class {
564
564
  function getBrowserGlobal(name) {
565
565
  return globalThis[name];
566
566
  }
567
+ function getBrowserGlobalMethod(name) {
568
+ return globalThis[name]?.bind(globalThis);
569
+ }
567
570
  function mustGetBrowserGlobal(name) {
568
571
  const r = getBrowserGlobal(name);
569
572
  if (r === void 0) {
@@ -1477,13 +1480,15 @@ function randomUint64() {
1477
1480
  var valita_exports = {};
1478
1481
  __export(valita_exports, {
1479
1482
  assert: () => assert2,
1483
+ instanceOfAbstractType: () => instanceOfAbstractType,
1480
1484
  is: () => is,
1481
1485
  parse: () => parse,
1482
1486
  readonly: () => readonly,
1483
1487
  readonlyArray: () => readonlyArray,
1484
1488
  readonlyObject: () => readonlyObject,
1485
1489
  readonlyRecord: () => readonlyRecord,
1486
- test: () => test
1490
+ test: () => test,
1491
+ testOptional: () => testOptional
1487
1492
  });
1488
1493
  __reExport(valita_exports, valita_star);
1489
1494
  import * as v from "@badrap/valita";
@@ -1593,6 +1598,22 @@ function test(value, schema, mode) {
1593
1598
  }
1594
1599
  return res;
1595
1600
  }
1601
+ function testOptional(value, schema, mode) {
1602
+ let flags = 1;
1603
+ if (mode === "passthrough") {
1604
+ flags = 0;
1605
+ } else if (mode === "strip") {
1606
+ flags = 2;
1607
+ }
1608
+ const res = schema.func(value, flags);
1609
+ if (res === void 0) {
1610
+ return { ok: true, value };
1611
+ } else if (res.ok) {
1612
+ return res;
1613
+ }
1614
+ const err2 = new v.ValitaError(res);
1615
+ return { ok: false, error: getMessage(err2, value) };
1616
+ }
1596
1617
  function readonly(t2) {
1597
1618
  return t2;
1598
1619
  }
@@ -1605,6 +1626,12 @@ function readonlyArray(t2) {
1605
1626
  function readonlyRecord(t2) {
1606
1627
  return v.record(t2);
1607
1628
  }
1629
+ var AbstractType = Object.getPrototypeOf(
1630
+ Object.getPrototypeOf(v.string().optional())
1631
+ ).constructor;
1632
+ function instanceOfAbstractType(obj) {
1633
+ return obj instanceof AbstractType;
1634
+ }
1608
1635
 
1609
1636
  // ../replicache/src/hash.ts
1610
1637
  var STRING_LENGTH = 22;
@@ -9212,7 +9239,7 @@ function getKVStoreProvider(lc, kvStore) {
9212
9239
  // ../replicache/src/mod.ts
9213
9240
  import { consoleLogSink as consoleLogSink3 } from "@rocicorp/logger";
9214
9241
 
9215
- // ../zql/src/zql/query/schema.ts
9242
+ // ../zero-schema/src/table-schema.ts
9216
9243
  function createTableSchema(schema) {
9217
9244
  return schema;
9218
9245
  }
@@ -9223,118 +9250,178 @@ function isJunctionRelationship(relationship) {
9223
9250
  return !isFieldRelationship(relationship);
9224
9251
  }
9225
9252
 
9226
- // ../zql/src/zql/query/expression.ts
9227
- function cmp(field, opOrValue, value) {
9228
- let op;
9229
- if (value === void 0) {
9230
- value = opOrValue;
9231
- op = "=";
9232
- } else {
9233
- op = opOrValue;
9253
+ // ../shared/src/sorted-entries.ts
9254
+ function sortedEntries(object16) {
9255
+ return Object.entries(object16).sort((a, b) => stringCompare(a[0], b[0]));
9256
+ }
9257
+
9258
+ // ../zero-schema/src/normalize-table-schema.ts
9259
+ var NormalizedTableSchema = class {
9260
+ tableName;
9261
+ primaryKey;
9262
+ columns;
9263
+ relationships;
9264
+ constructor(tableSchema, tableSchemaCache) {
9265
+ this.tableName = tableSchema.tableName;
9266
+ const primaryKey = normalizePrimaryKey(tableSchema.primaryKey);
9267
+ this.primaryKey = primaryKey;
9268
+ this.columns = normalizeColumns(tableSchema.columns, primaryKey);
9269
+ tableSchemaCache.set(tableSchema, this);
9270
+ this.relationships = normalizeRelationships(
9271
+ tableSchema.relationships,
9272
+ tableSchemaCache
9273
+ );
9234
9274
  }
9235
- return {
9236
- type: "simple",
9237
- field,
9238
- op,
9239
- value
9240
- };
9275
+ };
9276
+ function normalizeTableSchema(tableSchema) {
9277
+ return normalizeTableSchemaWithCache(
9278
+ tableSchema,
9279
+ tableSchema.tableName,
9280
+ /* @__PURE__ */ new Map()
9281
+ );
9241
9282
  }
9242
- function and(...conditions) {
9243
- const ands = conditions.flatMap((c) => {
9244
- if (c.type === "and") {
9245
- return c.conditions;
9246
- } else if (c.type === "simple") {
9247
- return [c];
9248
- }
9249
- return [];
9250
- });
9251
- const ors = conditions.filter(
9252
- (c) => c.type === "or"
9283
+ function normalizeTableSchemaWithCache(tableSchema, expectedName, tableSchemaCache) {
9284
+ if (tableSchema instanceof NormalizedTableSchema) {
9285
+ return tableSchema;
9286
+ }
9287
+ assert(
9288
+ tableSchema.tableName === expectedName,
9289
+ `Table name mismatch: "${tableSchema.tableName}" !== "${expectedName}"`
9290
+ );
9291
+ let normalizedTableSchema = tableSchemaCache.get(tableSchema);
9292
+ if (normalizedTableSchema) {
9293
+ return normalizedTableSchema;
9294
+ }
9295
+ normalizedTableSchema = new NormalizedTableSchema(
9296
+ tableSchema,
9297
+ tableSchemaCache
9253
9298
  );
9254
- if (ors.length === 0) {
9255
- return { type: "and", conditions: ands };
9299
+ return normalizedTableSchema;
9300
+ }
9301
+ function isSorted(arr) {
9302
+ for (let i = 1; i < arr.length; i++) {
9303
+ if (arr[i - 1] >= arr[i]) {
9304
+ return false;
9305
+ }
9306
+ }
9307
+ return true;
9308
+ }
9309
+ function assertNoDuplicates(arr) {
9310
+ for (let i = 1; i < arr.length; i++) {
9311
+ assert(arr[i - 1] !== arr[i], "Primary key must not contain duplicates");
9312
+ }
9313
+ }
9314
+ function normalizePrimaryKey(arr) {
9315
+ if (isSorted(arr)) {
9316
+ return arr;
9317
+ }
9318
+ arr = [...arr].sort();
9319
+ assertNoDuplicates(arr);
9320
+ return arr;
9321
+ }
9322
+ function normalizeColumns(columns, primaryKey) {
9323
+ const rv = {};
9324
+ for (const pk of primaryKey) {
9325
+ const schemaValue = columns[pk];
9326
+ assert(schemaValue, `Primary key column "${pk}" not found`);
9327
+ const { type, optional } = schemaValue;
9328
+ assert(!optional, `Primary key column "${pk}" cannot be optional`);
9329
+ assert(
9330
+ type === "string" || type === "number" || type === "boolean",
9331
+ `Primary key column "${pk}" must be a string, number, or boolean. Got ${type}`
9332
+ );
9333
+ }
9334
+ for (const [name, column] of sortedEntries(columns)) {
9335
+ rv[name] = normalizeSchemaValue(column);
9256
9336
  }
9257
- const flatOrs = flatten("or", ors);
9258
- const flatAnds = flatten("and", ands);
9337
+ return rv;
9338
+ }
9339
+ function normalizeSchemaValue(value) {
9259
9340
  return {
9260
- type: "or",
9261
- conditions: flatOrs.conditions.map((part) => ({
9262
- type: "and",
9263
- conditions: [
9264
- ...part.type === "and" ? part.conditions : [part],
9265
- ...flatAnds.conditions
9266
- ]
9267
- }))
9341
+ type: value.type,
9342
+ optional: value.optional ?? false
9268
9343
  };
9269
9344
  }
9270
- function or(...conditions) {
9271
- return flatten("or", conditions);
9345
+ function normalizeRelationships(relationships, tableSchemaCache) {
9346
+ const rv = {};
9347
+ for (const [name, relationship] of sortedEntries(relationships)) {
9348
+ rv[name] = normalizeRelationship(relationship, tableSchemaCache);
9349
+ }
9350
+ return rv;
9272
9351
  }
9273
- function not(expr) {
9274
- switch (expr.type) {
9275
- case "and":
9276
- return {
9277
- type: "or",
9278
- conditions: expr.conditions.map(not)
9279
- };
9280
- case "or":
9281
- return {
9282
- type: "and",
9283
- conditions: expr.conditions.map(not)
9284
- };
9285
- default:
9286
- return {
9287
- type: "simple",
9288
- op: negateOperator(expr.op),
9289
- field: expr.field,
9290
- value: expr.value
9291
- };
9352
+ function normalizeRelationship(relationship, tableSchemaCache) {
9353
+ if (isFieldRelationship(relationship)) {
9354
+ return normalizeFieldRelationship(relationship, tableSchemaCache);
9292
9355
  }
9356
+ return normalizeJunctionRelationship(relationship, tableSchemaCache);
9293
9357
  }
9294
- function flatten(type, conditions) {
9295
- const flattened2 = [];
9296
- for (const c of conditions) {
9297
- if (c.type === type) {
9298
- flattened2.push(...c.conditions);
9299
- } else {
9300
- flattened2.push(c);
9358
+ function normalizeFieldRelationship(relationship, tableSchemaCache) {
9359
+ return {
9360
+ source: relationship.source,
9361
+ dest: {
9362
+ field: relationship.dest.field,
9363
+ schema: normalizeLazyTableSchema(
9364
+ relationship.dest.schema,
9365
+ tableSchemaCache
9366
+ )
9301
9367
  }
9302
- }
9368
+ };
9369
+ }
9370
+ function normalizeJunctionRelationship(relationship, tableSchemaCache) {
9303
9371
  return {
9304
- type,
9305
- conditions: flattened2
9372
+ source: relationship.source,
9373
+ junction: {
9374
+ sourceField: relationship.junction.sourceField,
9375
+ destField: relationship.junction.destField,
9376
+ schema: normalizeLazyTableSchema(
9377
+ relationship.junction.schema,
9378
+ tableSchemaCache
9379
+ )
9380
+ },
9381
+ dest: {
9382
+ field: relationship.dest.field,
9383
+ schema: normalizeLazyTableSchema(
9384
+ relationship.dest.schema,
9385
+ tableSchemaCache
9386
+ )
9387
+ }
9306
9388
  };
9307
9389
  }
9308
- function negateOperator(op) {
9309
- switch (op) {
9310
- case "=":
9311
- return "!=";
9312
- case "!=":
9313
- return "=";
9314
- case "<":
9315
- return ">=";
9316
- case ">":
9317
- return "<=";
9318
- case ">=":
9319
- return "<";
9320
- case "<=":
9321
- return ">";
9322
- case "IN":
9323
- return "NOT IN";
9324
- case "NOT IN":
9325
- return "IN";
9326
- case "LIKE":
9327
- return "NOT LIKE";
9328
- case "NOT LIKE":
9329
- return "LIKE";
9330
- case "ILIKE":
9331
- return "NOT ILIKE";
9332
- case "NOT ILIKE":
9333
- return "ILIKE";
9390
+ function normalizeLazyTableSchema(tableSchema, buildCache) {
9391
+ const tableSchemaInstance = typeof tableSchema === "function" ? tableSchema() : tableSchema;
9392
+ return normalizeTableSchemaWithCache(
9393
+ tableSchemaInstance,
9394
+ tableSchemaInstance.tableName,
9395
+ // Don't care about name here.
9396
+ buildCache
9397
+ );
9398
+ }
9399
+
9400
+ // ../zero-schema/src/normalized-schema.ts
9401
+ function normalizeSchema(schema) {
9402
+ if (schema instanceof NormalizedSchema) {
9403
+ return schema;
9404
+ }
9405
+ return new NormalizedSchema(schema);
9406
+ }
9407
+ var NormalizedSchema = class {
9408
+ version;
9409
+ tables;
9410
+ constructor(schema) {
9411
+ this.version = schema.version;
9412
+ this.tables = normalizeTables(schema.tables);
9413
+ }
9414
+ };
9415
+ function normalizeTables(tables) {
9416
+ const rv = {};
9417
+ const tableSchemaCache = /* @__PURE__ */ new Map();
9418
+ for (const [name, table] of sortedEntries(tables)) {
9419
+ rv[name] = normalizeTableSchemaWithCache(table, name, tableSchemaCache);
9334
9420
  }
9421
+ return rv;
9335
9422
  }
9336
9423
 
9337
- // ../zql/src/zql/query/query-impl.ts
9424
+ // ../zql/src/query/query-impl.ts
9338
9425
  import { resolver as resolver7 } from "@rocicorp/resolver";
9339
9426
 
9340
9427
  // ../shared/src/xxhash.ts
@@ -9376,7 +9463,12 @@ var primitiveSchema = valita_exports.union(
9376
9463
  valita_exports.boolean(),
9377
9464
  valita_exports.null()
9378
9465
  );
9379
- var equalityOpsSchema = valita_exports.union(valita_exports.literal("="), valita_exports.literal("!="));
9466
+ var equalityOpsSchema = valita_exports.union(
9467
+ valita_exports.literal("="),
9468
+ valita_exports.literal("!="),
9469
+ valita_exports.literal("IS"),
9470
+ valita_exports.literal("IS NOT")
9471
+ );
9380
9472
  var orderOpsSchema = valita_exports.union(
9381
9473
  valita_exports.literal("<"),
9382
9474
  valita_exports.literal(">"),
@@ -9404,6 +9496,7 @@ var simpleConditionSchema = valita_exports.object({
9404
9496
  valita_exports.string(),
9405
9497
  valita_exports.number(),
9406
9498
  valita_exports.boolean(),
9499
+ valita_exports.null(),
9407
9500
  readonlyArray(valita_exports.union(valita_exports.string(), valita_exports.number(), valita_exports.boolean())),
9408
9501
  valita_exports.object({
9409
9502
  type: valita_exports.literal("static"),
@@ -9412,10 +9505,20 @@ var simpleConditionSchema = valita_exports.object({
9412
9505
  })
9413
9506
  )
9414
9507
  });
9508
+ var correlatedSubqueryConditionOperatorSchema = valita_exports.union(
9509
+ valita_exports.literal("EXISTS"),
9510
+ valita_exports.literal("NOT EXISTS")
9511
+ );
9512
+ var correlatedSubqueryConditionSchema = readonlyObject({
9513
+ type: valita_exports.literal("correlatedSubquery"),
9514
+ related: valita_exports.lazy(() => correlatedSubquerySchema),
9515
+ op: correlatedSubqueryConditionOperatorSchema
9516
+ });
9415
9517
  var conditionSchema = valita_exports.union(
9416
9518
  simpleConditionSchema,
9417
9519
  valita_exports.lazy(() => conjunctionSchema),
9418
- valita_exports.lazy(() => disjunctionSchema)
9520
+ valita_exports.lazy(() => disjunctionSchema),
9521
+ correlatedSubqueryConditionSchema
9419
9522
  );
9420
9523
  var conjunctionSchema = readonlyObject({
9421
9524
  type: valita_exports.literal("and"),
@@ -9482,7 +9585,7 @@ function normalizeAST(ast) {
9482
9585
  return normalized;
9483
9586
  }
9484
9587
  function sortedWhere(where) {
9485
- if (where.type === "simple") {
9588
+ if (where.type === "simple" || where.type === "correlatedSubquery") {
9486
9589
  return where;
9487
9590
  }
9488
9591
  return {
@@ -9506,6 +9609,15 @@ function cmpCondition(a, b) {
9506
9609
  if (b.type === "simple") {
9507
9610
  return 1;
9508
9611
  }
9612
+ if (a.type === "correlatedSubquery") {
9613
+ if (b.type !== "correlatedSubquery") {
9614
+ return -1;
9615
+ }
9616
+ return cmpRelated(a.related, b.related) || compareUTF8MaybeNull(a.op, b.op);
9617
+ }
9618
+ if (b.type === "correlatedSubquery") {
9619
+ return -1;
9620
+ }
9509
9621
  const val = compareUTF8MaybeNull(a.type, b.type);
9510
9622
  if (val !== 0) {
9511
9623
  return val;
@@ -9525,7 +9637,7 @@ function flattened(cond) {
9525
9637
  if (cond === void 0) {
9526
9638
  return void 0;
9527
9639
  }
9528
- if (cond.type === "simple") {
9640
+ if (cond.type === "simple" || cond.type === "correlatedSubquery") {
9529
9641
  return cond;
9530
9642
  }
9531
9643
  const conditions = defined(
@@ -9571,53 +9683,289 @@ function hashOfAST(ast) {
9571
9683
  return hash;
9572
9684
  }
9573
9685
 
9574
- // ../zql/src/zql/ivm/fan-in.ts
9575
- var FanIn = class {
9576
- #inputs;
9577
- #fanOut;
9578
- #output;
9579
- #schema;
9580
- constructor(fanOut, inputs) {
9581
- this.#inputs = inputs;
9582
- this.#schema = inputs[0].getSchema();
9583
- this.#fanOut = fanOut;
9584
- for (const input of inputs) {
9585
- input.setOutput(this);
9586
- assert(
9587
- deepEqual(
9588
- this.#schema,
9589
- input.getSchema()
9590
- ),
9591
- `Schema mismatch in fan-in`
9592
- );
9593
- }
9686
+ // ../zql/src/ivm/change.ts
9687
+ function rowForChange(change) {
9688
+ const { type } = change;
9689
+ return type === "add" || type === "remove" ? change.node.row : change.row;
9690
+ }
9691
+
9692
+ // ../zql/src/ivm/data.ts
9693
+ import { compareUTF8 as compareUTF84 } from "compare-utf8";
9694
+ function compareValues(a, b) {
9695
+ a = normalizeUndefined(a);
9696
+ b = normalizeUndefined(b);
9697
+ if (a === b) {
9698
+ return 0;
9594
9699
  }
9595
- setOutput(output) {
9596
- this.#output = output;
9700
+ if (a === null) {
9701
+ return -1;
9597
9702
  }
9598
- destroy() {
9599
- for (const input of this.#inputs) {
9600
- input.destroy();
9601
- }
9703
+ if (b === null) {
9704
+ return 1;
9602
9705
  }
9603
- getSchema() {
9604
- return this.#inputs[0].getSchema();
9706
+ if (typeof a === "boolean") {
9707
+ assertBoolean(b);
9708
+ return a ? 1 : -1;
9605
9709
  }
9606
- fetch(req) {
9607
- return this.#fetchOrCleanup((input) => input.fetch(req));
9710
+ if (typeof a === "number") {
9711
+ assertNumber(b);
9712
+ return a - b;
9713
+ }
9714
+ if (typeof a === "string") {
9715
+ assertString(b);
9716
+ return compareUTF84(a, b);
9717
+ }
9718
+ throw new Error(`Unsupported type: ${a}`);
9719
+ }
9720
+ function normalizeUndefined(v2) {
9721
+ return v2 ?? null;
9722
+ }
9723
+ function makeComparator(order) {
9724
+ return (a, b) => {
9725
+ for (const ord of order) {
9726
+ const field = ord[0];
9727
+ const comp = compareValues(a[field], b[field]);
9728
+ if (comp !== 0) {
9729
+ return ord[1] === "asc" ? comp : -comp;
9730
+ }
9731
+ }
9732
+ return 0;
9733
+ };
9734
+ }
9735
+ function valuesEqual(a, b) {
9736
+ a = normalizeUndefined(a);
9737
+ b = normalizeUndefined(b);
9738
+ if (a === null || b === null) {
9739
+ return false;
9740
+ }
9741
+ return a === b;
9742
+ }
9743
+
9744
+ // ../zql/src/ivm/stream.ts
9745
+ function* take(stream, limit) {
9746
+ if (limit < 1) {
9747
+ return;
9748
+ }
9749
+ let count = 0;
9750
+ for (const v2 of stream) {
9751
+ yield v2;
9752
+ if (++count === limit) {
9753
+ break;
9754
+ }
9755
+ }
9756
+ }
9757
+ function first(stream) {
9758
+ const it = stream[Symbol.iterator]();
9759
+ const { value } = it.next();
9760
+ it.return?.();
9761
+ return value;
9762
+ }
9763
+
9764
+ // ../zql/src/ivm/exists.ts
9765
+ var Exists = class {
9766
+ #input;
9767
+ #relationshipName;
9768
+ #storage;
9769
+ #not;
9770
+ #output;
9771
+ constructor(input, storage, relationshipName, type) {
9772
+ this.#input = input;
9773
+ this.#relationshipName = relationshipName;
9774
+ this.#input.setOutput(this);
9775
+ this.#storage = storage;
9776
+ assert(this.#input.getSchema().relationships[relationshipName]);
9777
+ this.#not = type === "NOT EXISTS";
9778
+ }
9779
+ setOutput(output) {
9780
+ this.#output = output;
9781
+ }
9782
+ destroy() {
9783
+ this.#input.destroy();
9784
+ }
9785
+ getSchema() {
9786
+ return this.#input.getSchema();
9787
+ }
9788
+ *fetch(req) {
9789
+ for (const node of this.#input.fetch(req)) {
9790
+ if (this.#filter(node.row)) {
9791
+ yield node;
9792
+ }
9793
+ }
9794
+ }
9795
+ *cleanup(req) {
9796
+ for (const node of this.#input.cleanup(req)) {
9797
+ if (this.#filter(node.row)) {
9798
+ yield node;
9799
+ }
9800
+ this.#delSize(node.row);
9801
+ }
9802
+ }
9803
+ push(change) {
9804
+ assert(this.#output, "Output not set");
9805
+ switch (change.type) {
9806
+ case "add":
9807
+ case "edit": {
9808
+ this.#pushWithFilter(change);
9809
+ return;
9810
+ }
9811
+ case "remove": {
9812
+ this.#pushWithFilter(change);
9813
+ this.#delSize(change.node.row);
9814
+ return;
9815
+ }
9816
+ case "child":
9817
+ if (change.child.relationshipName !== this.#relationshipName || change.child.change.type === "edit" || change.child.change.type === "child") {
9818
+ this.#pushWithFilter(change);
9819
+ return;
9820
+ }
9821
+ switch (change.child.change.type) {
9822
+ case "add": {
9823
+ let size = this.#getSize(change.row);
9824
+ if (size !== void 0) {
9825
+ size++;
9826
+ this.#setSize(change.row, size);
9827
+ } else {
9828
+ size = this.#fetchSize(change.row);
9829
+ }
9830
+ if (size === 1) {
9831
+ this.#output.push({
9832
+ type: this.#not ? "remove" : "add",
9833
+ node: this.#fetchNodeForRow(change.row)
9834
+ });
9835
+ } else {
9836
+ this.#pushWithFilter(change, size);
9837
+ }
9838
+ return;
9839
+ }
9840
+ case "remove": {
9841
+ let size = this.#getSize(change.row);
9842
+ if (size !== void 0) {
9843
+ assert(size > 0);
9844
+ size--;
9845
+ this.#setSize(change.row, size);
9846
+ } else {
9847
+ size = this.#fetchSize(change.row);
9848
+ }
9849
+ if (size === 0) {
9850
+ this.#output.push({
9851
+ type: this.#not ? "add" : "remove",
9852
+ node: this.#fetchNodeForRow(change.row)
9853
+ });
9854
+ } else {
9855
+ this.#pushWithFilter(change, size);
9856
+ }
9857
+ return;
9858
+ }
9859
+ }
9860
+ return;
9861
+ default:
9862
+ unreachable(change);
9863
+ }
9864
+ }
9865
+ /**
9866
+ * Returns whether or not the change's row's this.#relationshipName
9867
+ * relationship passes the exist/not exists filter condition.
9868
+ * If the optional `size` is passed it is used.
9869
+ * Otherwise, if there is a stored size for the row it is used.
9870
+ * Otherwise the size is computed by fetching a node for the row from
9871
+ * this.#input (this computed size is also stored).
9872
+ */
9873
+ #filter(row, size) {
9874
+ const exists = (size ?? this.#getOrFetchSize(row)) > 0;
9875
+ return this.#not ? !exists : exists;
9876
+ }
9877
+ /**
9878
+ * Pushes a change if this.#filter is true for its row.
9879
+ */
9880
+ #pushWithFilter(change, size) {
9881
+ const row = rowForChange(change);
9882
+ if (this.#filter(row, size)) {
9883
+ must(this.#output).push(change);
9884
+ }
9885
+ }
9886
+ #getSize(row) {
9887
+ return this.#storage.get(this.#makeSizeStorageKey(row));
9888
+ }
9889
+ #setSize(row, size) {
9890
+ this.#storage.set(this.#makeSizeStorageKey(row), size);
9891
+ }
9892
+ #delSize(row) {
9893
+ this.#storage.del(this.#makeSizeStorageKey(row));
9894
+ }
9895
+ #getOrFetchSize(row) {
9896
+ const size = this.#getSize(row);
9897
+ if (size !== void 0) {
9898
+ return size;
9899
+ }
9900
+ return this.#fetchSize(row);
9901
+ }
9902
+ #fetchSize(row) {
9903
+ const relationship = this.#fetchNodeForRow(row).relationships[this.#relationshipName];
9904
+ assert(relationship);
9905
+ let size = 0;
9906
+ for (const _relatedNode of relationship) {
9907
+ size++;
9908
+ }
9909
+ this.#setSize(row, size);
9910
+ return size;
9911
+ }
9912
+ #fetchNodeForRow(row) {
9913
+ return must(
9914
+ first(
9915
+ this.#input.fetch({
9916
+ start: { row, basis: "at" }
9917
+ })
9918
+ )
9919
+ );
9920
+ }
9921
+ #makeSizeStorageKey(row) {
9922
+ const primaryKey = [];
9923
+ for (const key of this.#input.getSchema().primaryKey) {
9924
+ primaryKey.push(normalizeUndefined(row[key]));
9925
+ }
9926
+ return JSON.stringify(["size", primaryKey]);
9927
+ }
9928
+ };
9929
+
9930
+ // ../zql/src/ivm/fan-in.ts
9931
+ var FanIn = class {
9932
+ #inputs;
9933
+ #fanOut;
9934
+ #schema;
9935
+ #output;
9936
+ constructor(fanOut, inputs) {
9937
+ this.#inputs = inputs;
9938
+ this.#schema = fanOut.getSchema();
9939
+ this.#fanOut = fanOut;
9940
+ for (const input of inputs) {
9941
+ input.setOutput(this);
9942
+ assert(this.#schema === input.getSchema(), `Schema mismatch in fan-in`);
9943
+ }
9944
+ }
9945
+ setOutput(output) {
9946
+ this.#output = output;
9947
+ }
9948
+ destroy() {
9949
+ for (const input of this.#inputs) {
9950
+ input.destroy();
9951
+ }
9952
+ }
9953
+ getSchema() {
9954
+ return this.#schema;
9955
+ }
9956
+ fetch(req) {
9957
+ return this.#fetchOrCleanup((input) => input.fetch(req));
9608
9958
  }
9609
9959
  cleanup(req) {
9610
9960
  return this.#fetchOrCleanup((input) => input.cleanup(req));
9611
9961
  }
9612
9962
  *#fetchOrCleanup(streamProvider) {
9613
9963
  const iterables = this.#inputs.map((input) => streamProvider(input));
9614
- for (const node of mergeIterables(
9964
+ yield* mergeIterables(
9615
9965
  iterables,
9616
9966
  (l, r) => must(this.#schema).compareRows(l.row, r.row),
9617
9967
  true
9618
- )) {
9619
- yield node;
9620
- }
9968
+ );
9621
9969
  }
9622
9970
  push(change) {
9623
9971
  this.#fanOut.onFanInReceivedPush();
@@ -9625,18 +9973,19 @@ var FanIn = class {
9625
9973
  }
9626
9974
  };
9627
9975
 
9628
- // ../zql/src/zql/ivm/fan-out.ts
9976
+ // ../zql/src/ivm/fan-out.ts
9629
9977
  var FanOut = class {
9630
9978
  #input;
9631
- #outputs;
9632
- #fanInReceivedPush;
9633
- #destroyCount;
9979
+ #outputs = [];
9980
+ // FanOut is paired with a FanIn.
9981
+ // Once FanIn has received a push from FanOut along
9982
+ // any branch, FanOut no longer needs to push that value
9983
+ // across the rest of its outputs..
9984
+ #fanInReceivedPush = false;
9985
+ #destroyCount = 0;
9634
9986
  constructor(input) {
9635
9987
  this.#input = input;
9636
- this.#input.setOutput(this);
9637
- this.#outputs = [];
9638
- this.#fanInReceivedPush = false;
9639
- this.#destroyCount = 0;
9988
+ input.setOutput(this);
9640
9989
  }
9641
9990
  setOutput(output) {
9642
9991
  this.#outputs.push(output);
@@ -9674,7 +10023,7 @@ var FanOut = class {
9674
10023
  }
9675
10024
  };
9676
10025
 
9677
- // ../zql/src/zql/ivm/maybe-split-and-push-edit-change.ts
10026
+ // ../zql/src/ivm/maybe-split-and-push-edit-change.ts
9678
10027
  function maybeSplitAndPushEditChange(change, predicate, output) {
9679
10028
  const oldWasPresent = predicate(change.oldRow);
9680
10029
  const newIsPresent = predicate(change.row);
@@ -9699,7 +10048,7 @@ function maybeSplitAndPushEditChange(change, predicate, output) {
9699
10048
  }
9700
10049
  }
9701
10050
 
9702
- // ../zql/src/zql/ivm/filter.ts
10051
+ // ../zql/src/ivm/filter.ts
9703
10052
  var Filter = class {
9704
10053
  #input;
9705
10054
  #mode;
@@ -9709,7 +10058,7 @@ var Filter = class {
9709
10058
  this.#input = input;
9710
10059
  this.#mode = mode;
9711
10060
  this.#predicate = predicate;
9712
- this.#input.setOutput(this);
10061
+ input.setOutput(this);
9713
10062
  }
9714
10063
  setOutput(output) {
9715
10064
  this.#output = output;
@@ -9756,79 +10105,7 @@ var Filter = class {
9756
10105
  }
9757
10106
  };
9758
10107
 
9759
- // ../zql/src/zql/ivm/data.ts
9760
- import { compareUTF8 as compareUTF84 } from "compare-utf8";
9761
- function compareValues(a, b) {
9762
- a = normalizeUndefined(a);
9763
- b = normalizeUndefined(b);
9764
- if (a === b) {
9765
- return 0;
9766
- }
9767
- if (a === null) {
9768
- return -1;
9769
- }
9770
- if (b === null) {
9771
- return 1;
9772
- }
9773
- if (typeof a === "boolean") {
9774
- assertBoolean(b);
9775
- return a ? 1 : -1;
9776
- }
9777
- if (typeof a === "number") {
9778
- assertNumber(b);
9779
- return a - b;
9780
- }
9781
- if (typeof a === "string") {
9782
- assertString(b);
9783
- return compareUTF84(a, b);
9784
- }
9785
- throw new Error(`Unsupported type: ${a}`);
9786
- }
9787
- function normalizeUndefined(v2) {
9788
- return v2 ?? null;
9789
- }
9790
- function makeComparator(order) {
9791
- return (a, b) => {
9792
- for (const ord of order) {
9793
- const field = ord[0];
9794
- const comp = compareValues(a[field], b[field]);
9795
- if (comp !== 0) {
9796
- return ord[1] === "asc" ? comp : -comp;
9797
- }
9798
- }
9799
- return 0;
9800
- };
9801
- }
9802
- function valuesEqual(a, b) {
9803
- a = normalizeUndefined(a);
9804
- b = normalizeUndefined(b);
9805
- if (a === null || b === null) {
9806
- return false;
9807
- }
9808
- return a === b;
9809
- }
9810
-
9811
- // ../zql/src/zql/ivm/stream.ts
9812
- function* take(stream, limit) {
9813
- if (limit < 1) {
9814
- return;
9815
- }
9816
- let count = 0;
9817
- for (const v2 of stream) {
9818
- yield v2;
9819
- if (++count === limit) {
9820
- break;
9821
- }
9822
- }
9823
- }
9824
- function first(stream) {
9825
- const it = stream[Symbol.iterator]();
9826
- const { value } = it.next();
9827
- it.return?.();
9828
- return value;
9829
- }
9830
-
9831
- // ../zql/src/zql/ivm/join.ts
10108
+ // ../zql/src/ivm/join.ts
9832
10109
  var Join = class {
9833
10110
  #parent;
9834
10111
  #child;
@@ -10114,7 +10391,7 @@ function makeStorageKey(keyValue, primaryKey, row) {
10114
10391
  return createPrimaryKeySetStorageKey(parentPrimaryKey);
10115
10392
  }
10116
10393
 
10117
- // ../zql/src/zql/ivm/skip.ts
10394
+ // ../zql/src/ivm/skip.ts
10118
10395
  var Skip = class {
10119
10396
  #input;
10120
10397
  #bound;
@@ -10124,7 +10401,7 @@ var Skip = class {
10124
10401
  this.#input = input;
10125
10402
  this.#bound = bound;
10126
10403
  this.#comparator = input.getSchema().compareRows;
10127
- this.#input.setOutput(this);
10404
+ input.setOutput(this);
10128
10405
  }
10129
10406
  getSchema() {
10130
10407
  return this.#input.getSchema();
@@ -10200,7 +10477,7 @@ var Skip = class {
10200
10477
  }
10201
10478
  };
10202
10479
 
10203
- // ../zql/src/zql/ivm/take.ts
10480
+ // ../zql/src/ivm/take.ts
10204
10481
  var MAX_BOUND_KEY = "maxBound";
10205
10482
  var Take = class {
10206
10483
  #input;
@@ -10215,10 +10492,10 @@ var Take = class {
10215
10492
  this.#partitionKey = partitionKey;
10216
10493
  assert(limit >= 0);
10217
10494
  assertOrderingIncludesPK(
10218
- this.#input.getSchema().sort,
10219
- this.#input.getSchema().primaryKey
10495
+ input.getSchema().sort,
10496
+ input.getSchema().primaryKey
10220
10497
  );
10221
- this.#input.setOutput(this);
10498
+ input.setOutput(this);
10222
10499
  }
10223
10500
  setOutput(output) {
10224
10501
  this.#output = output;
@@ -10340,8 +10617,7 @@ var Take = class {
10340
10617
  return;
10341
10618
  }
10342
10619
  assert(this.#output, "Output not set");
10343
- assert(change.type !== "child", "child changes are not supported");
10344
- const { takeState, takeStateKey, maxBound, constraint } = this.#getStateAndConstraint(change.node.row);
10620
+ const { takeState, takeStateKey, maxBound, constraint } = this.#getStateAndConstraint(rowForChange(change));
10345
10621
  if (!takeState) {
10346
10622
  return;
10347
10623
  }
@@ -10460,6 +10736,10 @@ var Take = class {
10460
10736
  maxBound
10461
10737
  );
10462
10738
  this.#output.push(change);
10739
+ } else if (change.type === "child") {
10740
+ if (takeState.bound && compareRows(change.row, takeState.bound) <= 0) {
10741
+ this.#output.push(change);
10742
+ }
10463
10743
  }
10464
10744
  }
10465
10745
  #pushEditChange(change) {
@@ -10653,11 +10933,11 @@ function getTakeStateKey(partitionValue) {
10653
10933
  return JSON.stringify(["take", normalizeUndefined(partitionValue)]);
10654
10934
  }
10655
10935
 
10656
- // ../zql/src/zql/builder/error.ts
10936
+ // ../zql/src/builder/error.ts
10657
10937
  var MissingParameterError = class extends Error {
10658
10938
  };
10659
10939
 
10660
- // ../zql/src/zql/builder/like.ts
10940
+ // ../zql/src/builder/like.ts
10661
10941
  function getLikePredicate(pattern, flags) {
10662
10942
  const op = getLikeOp(String(pattern), flags);
10663
10943
  return (lhs) => {
@@ -10705,12 +10985,19 @@ function patternToRegExp(source, flags = "") {
10705
10985
  return new RegExp(pattern + "$", flags + "m");
10706
10986
  }
10707
10987
 
10708
- // ../zql/src/zql/builder/filter.ts
10988
+ // ../zql/src/builder/filter.ts
10709
10989
  function createPredicate(condition) {
10710
- const impl = createPredicateImpl(
10711
- condition.value,
10712
- condition.op
10713
- );
10990
+ switch (condition.op) {
10991
+ case "IS":
10992
+ case "IS NOT": {
10993
+ const impl2 = createIsPredicate(condition.value, condition.op);
10994
+ return (row) => impl2(row[condition.field]);
10995
+ }
10996
+ }
10997
+ if (condition.value === null || condition.value === void 0) {
10998
+ return (_row) => false;
10999
+ }
11000
+ const impl = createPredicateImpl(condition.value, condition.op);
10714
11001
  return (row) => {
10715
11002
  const lhs = row[condition.field];
10716
11003
  if (lhs === null || lhs === void 0) {
@@ -10719,6 +11006,14 @@ function createPredicate(condition) {
10719
11006
  return impl(lhs);
10720
11007
  };
10721
11008
  }
11009
+ function createIsPredicate(rhs, operator) {
11010
+ switch (operator) {
11011
+ case "IS":
11012
+ return (lhs) => lhs === rhs;
11013
+ case "IS NOT":
11014
+ return (lhs) => lhs !== rhs;
11015
+ }
11016
+ }
10722
11017
  function createPredicateImpl(rhs, operator) {
10723
11018
  switch (operator) {
10724
11019
  case "=":
@@ -10736,11 +11031,11 @@ function createPredicateImpl(rhs, operator) {
10736
11031
  case "LIKE":
10737
11032
  return getLikePredicate(rhs, "");
10738
11033
  case "NOT LIKE":
10739
- return not2(getLikePredicate(rhs, ""));
11034
+ return not(getLikePredicate(rhs, ""));
10740
11035
  case "ILIKE":
10741
11036
  return getLikePredicate(rhs, "i");
10742
11037
  case "NOT ILIKE":
10743
- return not2(getLikePredicate(rhs, "i"));
11038
+ return not(getLikePredicate(rhs, "i"));
10744
11039
  case "IN": {
10745
11040
  assert(Array.isArray(rhs));
10746
11041
  const set = new Set(rhs);
@@ -10756,11 +11051,11 @@ function createPredicateImpl(rhs, operator) {
10756
11051
  throw new Error(`Unexpected operator: ${operator}`);
10757
11052
  }
10758
11053
  }
10759
- function not2(f) {
11054
+ function not(f) {
10760
11055
  return (lhs) => !f(lhs);
10761
11056
  }
10762
11057
 
10763
- // ../zql/src/zql/builder/builder.ts
11058
+ // ../zql/src/builder/builder.ts
10764
11059
  function buildPipeline(ast, delegate, staticQueryParameters) {
10765
11060
  return buildPipelineInternal(
10766
11061
  bindStaticParameters(ast, staticQueryParameters),
@@ -10783,10 +11078,22 @@ function bindStaticParameters(ast, staticQueryParameters) {
10783
11078
  return node;
10784
11079
  };
10785
11080
  function bindCondition(condition) {
10786
- return condition.type === "simple" ? {
10787
- ...condition,
10788
- value: bindValue(condition.value)
10789
- } : {
11081
+ if (condition.type === "simple") {
11082
+ return {
11083
+ ...condition,
11084
+ value: bindValue(condition.value)
11085
+ };
11086
+ }
11087
+ if (condition.type === "correlatedSubquery") {
11088
+ return {
11089
+ ...condition,
11090
+ related: {
11091
+ ...condition.related,
11092
+ subquery: visit(condition.related.subquery)
11093
+ }
11094
+ };
11095
+ }
11096
+ return {
10790
11097
  ...condition,
10791
11098
  conditions: condition.conditions.map(bindCondition)
10792
11099
  };
@@ -10822,57 +11129,45 @@ function buildPipelineInternal(ast, delegate, staticQueryParameters, partitionKe
10822
11129
  if (ast.start) {
10823
11130
  end = new Skip(end, ast.start);
10824
11131
  }
11132
+ for (const csq of gatherCorrelatedSubqueryQueriesFromCondition(ast.where)) {
11133
+ end = applyCorrelatedSubQuery(csq, delegate, staticQueryParameters, end);
11134
+ }
10825
11135
  if (ast.where) {
10826
- end = applyWhere(end, ast.where, appliedFilters);
11136
+ end = applyWhere(end, ast.where, appliedFilters, delegate);
10827
11137
  }
10828
11138
  if (ast.limit) {
10829
11139
  end = new Take(end, delegate.createStorage(), ast.limit, partitionKey);
10830
11140
  }
10831
11141
  if (ast.related) {
10832
- for (const sq of ast.related) {
10833
- assert(sq.subquery.alias, "Subquery must have an alias");
10834
- const child = buildPipelineInternal(
10835
- sq.subquery,
10836
- delegate,
10837
- staticQueryParameters,
10838
- sq.correlation.childField
10839
- );
10840
- end = new Join({
10841
- parent: end,
10842
- child,
10843
- storage: delegate.createStorage(),
10844
- parentKey: sq.correlation.parentField,
10845
- childKey: sq.correlation.childField,
10846
- relationshipName: sq.subquery.alias,
10847
- hidden: sq.hidden ?? false
10848
- });
11142
+ for (const csq of ast.related) {
11143
+ end = applyCorrelatedSubQuery(csq, delegate, staticQueryParameters, end);
10849
11144
  }
10850
11145
  }
10851
11146
  return end;
10852
11147
  }
10853
- function applyWhere(input, condition, appliedFilters) {
11148
+ function applyWhere(input, condition, appliedFilters, delegate) {
10854
11149
  switch (condition.type) {
10855
11150
  case "and":
10856
- return applyAnd(input, condition, appliedFilters);
11151
+ return applyAnd(input, condition, appliedFilters, delegate);
10857
11152
  case "or":
10858
- return applyOr(input, condition, appliedFilters);
11153
+ return applyOr(input, condition, appliedFilters, delegate);
11154
+ case "correlatedSubquery":
11155
+ return applyCorrelatedSubqueryCondition(input, condition, delegate);
10859
11156
  default:
10860
11157
  return applySimpleCondition(input, condition, appliedFilters);
10861
11158
  }
10862
11159
  }
10863
- function applyAnd(input, condition, appliedFilters) {
11160
+ function applyAnd(input, condition, appliedFilters, delegate) {
10864
11161
  for (const subCondition of condition.conditions) {
10865
- input = applyWhere(input, subCondition, appliedFilters);
11162
+ input = applyWhere(input, subCondition, appliedFilters, delegate);
10866
11163
  }
10867
11164
  return input;
10868
11165
  }
10869
- function applyOr(input, condition, appliedFilters) {
11166
+ function applyOr(input, condition, appliedFilters, delegate) {
10870
11167
  const fanOut = new FanOut(input);
10871
- const branches = [];
10872
- for (const subCondition of condition.conditions) {
10873
- branches.push(applyWhere(fanOut, subCondition, appliedFilters));
10874
- }
10875
- assert(branches.length > 0, "Or condition must have at least one branch");
11168
+ const branches = condition.conditions.map(
11169
+ (subCondition) => applyWhere(fanOut, subCondition, appliedFilters, delegate)
11170
+ );
10876
11171
  return new FanIn(fanOut, branches);
10877
11172
  }
10878
11173
  function applySimpleCondition(input, condition, appliedFilters) {
@@ -10882,6 +11177,58 @@ function applySimpleCondition(input, condition, appliedFilters) {
10882
11177
  createPredicate(condition)
10883
11178
  );
10884
11179
  }
11180
+ function applyCorrelatedSubQuery(sq, delegate, staticQueryParameters, end) {
11181
+ assert(sq.subquery.alias, "Subquery must have an alias");
11182
+ const child = buildPipelineInternal(
11183
+ sq.subquery,
11184
+ delegate,
11185
+ staticQueryParameters,
11186
+ sq.correlation.childField
11187
+ );
11188
+ end = new Join({
11189
+ parent: end,
11190
+ child,
11191
+ storage: delegate.createStorage(),
11192
+ parentKey: sq.correlation.parentField,
11193
+ childKey: sq.correlation.childField,
11194
+ relationshipName: sq.subquery.alias,
11195
+ hidden: sq.hidden ?? false
11196
+ });
11197
+ return end;
11198
+ }
11199
+ function applyCorrelatedSubqueryCondition(input, condition, delegate) {
11200
+ assert(condition.op === "EXISTS" || condition.op === "NOT EXISTS");
11201
+ return new Exists(
11202
+ input,
11203
+ delegate.createStorage(),
11204
+ must(condition.related.subquery.alias),
11205
+ condition.op
11206
+ );
11207
+ }
11208
+ function gatherCorrelatedSubqueryQueriesFromCondition(condition) {
11209
+ const csqs = [];
11210
+ const gather = (condition2) => {
11211
+ if (condition2.type === "correlatedSubquery") {
11212
+ assert(condition2.op === "EXISTS" || condition2.op === "NOT EXISTS");
11213
+ csqs.push({
11214
+ ...condition2.related,
11215
+ subquery: { ...condition2.related.subquery, limit: EXISTS_LIMIT }
11216
+ });
11217
+ return;
11218
+ }
11219
+ if (condition2.type === "and" || condition2.type === "or") {
11220
+ for (const c of condition2.conditions) {
11221
+ gather(c);
11222
+ }
11223
+ return;
11224
+ }
11225
+ };
11226
+ if (condition) {
11227
+ gather(condition);
11228
+ }
11229
+ return csqs;
11230
+ }
11231
+ var EXISTS_LIMIT = 5;
10885
11232
  function assertOrderingIncludesPK(ordering, pk) {
10886
11233
  const orderingFields = ordering.map(([field]) => field);
10887
11234
  const missingFields = pk.filter((pkField) => !orderingFields.includes(pkField));
@@ -10889,12 +11236,16 @@ function assertOrderingIncludesPK(ordering, pk) {
10889
11236
  throw new Error(
10890
11237
  `Ordering must include all primary key fields. Missing: ${missingFields.join(
10891
11238
  ", "
10892
- )}`
11239
+ )}. ZQL automatically appends primary key fields to the ordering if they are missing
11240
+ so a common cause of this error is a casing mismatch between Postgres and ZQL.
11241
+ E.g., "userid" vs "userID".
11242
+ You may want to add double-quotes around your Postgres column names to prevent Postgres from lower-casing them:
11243
+ https://www.postgresql.org/docs/current/sql-syntax-lexical.htm`
10893
11244
  );
10894
11245
  }
10895
11246
  }
10896
11247
 
10897
- // ../zql/src/zql/ivm/array-view.ts
11248
+ // ../zql/src/ivm/array-view.ts
10898
11249
  var ArrayView = class {
10899
11250
  #input;
10900
11251
  #listeners = /* @__PURE__ */ new Set();
@@ -10909,8 +11260,8 @@ var ArrayView = class {
10909
11260
  this.#input = input;
10910
11261
  this.#schema = input.getSchema();
10911
11262
  this.#format = format;
10912
- this.#input.setOutput(this);
10913
11263
  this.#root = { "": format.singular ? void 0 : [] };
11264
+ input.setOutput(this);
10914
11265
  this.#hydrate();
10915
11266
  }
10916
11267
  get data() {
@@ -10958,160 +11309,216 @@ var ArrayView = class {
10958
11309
  }
10959
11310
  };
10960
11311
 
10961
- // ../shared/src/sorted-entries.ts
10962
- function sortedEntries(object16) {
10963
- return Object.entries(object16).sort((a, b) => stringCompare(a[0], b[0]));
10964
- }
10965
-
10966
- // ../zql/src/zql/query/normalize-table-schema.ts
10967
- var NormalizedTableSchema = class {
10968
- tableName;
10969
- primaryKey;
10970
- columns;
10971
- relationships;
10972
- constructor(tableSchema, tableSchemaCache) {
10973
- this.tableName = tableSchema.tableName;
10974
- const primaryKey = normalizePrimaryKey(tableSchema.primaryKey);
10975
- this.primaryKey = primaryKey;
10976
- this.columns = normalizeColumns(tableSchema.columns, primaryKey);
10977
- tableSchemaCache.set(tableSchema, this);
10978
- this.relationships = normalizeRelationships(
10979
- tableSchema.relationships,
10980
- tableSchemaCache
10981
- );
11312
+ // ../zql/src/query/expression.ts
11313
+ var ExpressionBuilder = class {
11314
+ #exists;
11315
+ constructor(exists) {
11316
+ this.#exists = exists;
11317
+ this.exists = this.exists.bind(this);
11318
+ }
11319
+ get eb() {
11320
+ return this;
11321
+ }
11322
+ cmp(field, opOrValue, value) {
11323
+ return cmp(field, opOrValue, value);
11324
+ }
11325
+ and = and;
11326
+ or = or;
11327
+ not = not2;
11328
+ exists(relationship, cb) {
11329
+ return this.#exists(relationship, cb);
10982
11330
  }
10983
11331
  };
10984
- function normalizeTableSchema(tableSchema) {
10985
- return normalizeTableSchemaWithCache(
10986
- tableSchema,
10987
- tableSchema.tableName,
10988
- /* @__PURE__ */ new Map()
10989
- );
10990
- }
10991
- function normalizeTableSchemaWithCache(tableSchema, expectedName, tableSchemaCache) {
10992
- if (tableSchema instanceof NormalizedTableSchema) {
10993
- return tableSchema;
11332
+ function and(...conditions) {
11333
+ const expressions = filterTrue(filterUndefined(conditions));
11334
+ if (expressions.length === 1) {
11335
+ return expressions[0];
10994
11336
  }
10995
- assert(
10996
- tableSchema.tableName === expectedName,
10997
- `Table name mismatch: "${tableSchema.tableName}" !== "${expectedName}"`
10998
- );
10999
- let normalizedTableSchema = tableSchemaCache.get(tableSchema);
11000
- if (normalizedTableSchema) {
11001
- return normalizedTableSchema;
11337
+ if (expressions.some(isAlwaysFalse)) {
11338
+ return FALSE;
11002
11339
  }
11003
- normalizedTableSchema = new NormalizedTableSchema(
11004
- tableSchema,
11005
- tableSchemaCache
11006
- );
11007
- return normalizedTableSchema;
11340
+ return { type: "and", conditions: expressions };
11008
11341
  }
11009
- function isSorted(arr) {
11010
- for (let i = 1; i < arr.length; i++) {
11011
- if (arr[i - 1] >= arr[i]) {
11012
- return false;
11013
- }
11342
+ function or(...conditions) {
11343
+ const expressions = filterFalse(filterUndefined(conditions));
11344
+ if (expressions.length === 1) {
11345
+ return expressions[0];
11014
11346
  }
11015
- return true;
11016
- }
11017
- function assertNoDuplicates(arr) {
11018
- for (let i = 1; i < arr.length; i++) {
11019
- assert(arr[i - 1] !== arr[i], "Primary key must not contain duplicates");
11347
+ if (expressions.some(isAlwaysTrue)) {
11348
+ return TRUE;
11020
11349
  }
11350
+ return { type: "or", conditions: expressions };
11021
11351
  }
11022
- function normalizePrimaryKey(arr) {
11023
- if (isSorted(arr)) {
11024
- return arr;
11352
+ function not2(expression) {
11353
+ switch (expression.type) {
11354
+ case "and":
11355
+ return {
11356
+ type: "or",
11357
+ conditions: expression.conditions.map(not2)
11358
+ };
11359
+ case "or":
11360
+ return {
11361
+ type: "and",
11362
+ conditions: expression.conditions.map(not2)
11363
+ };
11364
+ case "correlatedSubquery":
11365
+ return {
11366
+ type: "correlatedSubquery",
11367
+ related: expression.related,
11368
+ op: negateOperator(expression.op)
11369
+ };
11370
+ default:
11371
+ return {
11372
+ type: "simple",
11373
+ op: negateOperator(expression.op),
11374
+ field: expression.field,
11375
+ value: expression.value
11376
+ };
11025
11377
  }
11026
- arr = [...arr].sort();
11027
- assertNoDuplicates(arr);
11028
- return arr;
11029
11378
  }
11030
- function normalizeColumns(columns, primaryKey) {
11031
- const rv = {};
11032
- for (const pk of primaryKey) {
11033
- const schemaValue = columns[pk];
11034
- assert(schemaValue, `Primary key column "${pk}" not found`);
11035
- const { type, optional } = schemaValue;
11036
- assert(!optional, `Primary key column "${pk}" cannot be optional`);
11037
- assert(
11038
- type === "string" || type === "number" || type === "boolean",
11039
- `Primary key column "${pk}" must be a string, number, or boolean. Got ${type}`
11040
- );
11041
- }
11042
- for (const [name, column] of sortedEntries(columns)) {
11043
- rv[name] = normalizeSchemaValue(column);
11379
+ function cmp(field, opOrValue, value) {
11380
+ let op;
11381
+ if (value === void 0) {
11382
+ value = opOrValue;
11383
+ op = "=";
11384
+ } else {
11385
+ op = opOrValue;
11044
11386
  }
11045
- return rv;
11046
- }
11047
- function normalizeSchemaValue(value) {
11048
11387
  return {
11049
- type: value.type,
11050
- optional: value.optional ?? false
11388
+ type: "simple",
11389
+ field,
11390
+ op,
11391
+ value
11051
11392
  };
11052
11393
  }
11053
- function normalizeRelationships(relationships, tableSchemaCache) {
11054
- const rv = {};
11055
- for (const [name, relationship] of sortedEntries(relationships)) {
11056
- rv[name] = normalizeRelationship(relationship, tableSchemaCache);
11394
+ var TRUE = {
11395
+ type: "and",
11396
+ conditions: []
11397
+ };
11398
+ var FALSE = {
11399
+ type: "or",
11400
+ conditions: []
11401
+ };
11402
+ function isAlwaysTrue(condition) {
11403
+ return condition.type === "and" && condition.conditions.length === 0;
11404
+ }
11405
+ function isAlwaysFalse(condition) {
11406
+ return condition.type === "or" && condition.conditions.length === 0;
11407
+ }
11408
+ function flatten(type, conditions) {
11409
+ const flattened2 = [];
11410
+ for (const c of conditions) {
11411
+ if (c.type === type) {
11412
+ flattened2.push(...c.conditions);
11413
+ } else {
11414
+ flattened2.push(c);
11415
+ }
11416
+ }
11417
+ return flattened2;
11418
+ }
11419
+ var negateSimpleOperatorMap = {
11420
+ ["="]: "!=",
11421
+ ["!="]: "=",
11422
+ ["<"]: ">=",
11423
+ [">"]: "<=",
11424
+ [">="]: "<",
11425
+ ["<="]: ">",
11426
+ ["IN"]: "NOT IN",
11427
+ ["NOT IN"]: "IN",
11428
+ ["LIKE"]: "NOT LIKE",
11429
+ ["NOT LIKE"]: "LIKE",
11430
+ ["ILIKE"]: "NOT ILIKE",
11431
+ ["NOT ILIKE"]: "ILIKE",
11432
+ ["IS"]: "IS NOT",
11433
+ ["IS NOT"]: "IS"
11434
+ };
11435
+ var negateOperatorMap = {
11436
+ ...negateSimpleOperatorMap,
11437
+ ["EXISTS"]: "NOT EXISTS",
11438
+ ["NOT EXISTS"]: "EXISTS"
11439
+ };
11440
+ function negateOperator(op) {
11441
+ return must(negateOperatorMap[op]);
11442
+ }
11443
+ function filterUndefined(array9) {
11444
+ return array9.filter((e) => e !== void 0);
11445
+ }
11446
+ function filterTrue(conditions) {
11447
+ return conditions.filter((c) => !isAlwaysTrue(c));
11448
+ }
11449
+ function filterFalse(conditions) {
11450
+ return conditions.filter((c) => !isAlwaysFalse(c));
11451
+ }
11452
+
11453
+ // ../zql/src/query/dnf.ts
11454
+ function dnf(condition) {
11455
+ return unwrap(dnfInner(condition));
11456
+ }
11457
+ function dnfInner(condition) {
11458
+ switch (condition.type) {
11459
+ case "simple":
11460
+ case "correlatedSubquery":
11461
+ return { type: "or", conditions: [condition] };
11462
+ case "and":
11463
+ return distributeAnd(condition.conditions.map(dnfInner));
11464
+ case "or":
11465
+ return {
11466
+ type: "or",
11467
+ conditions: flatten(
11468
+ "or",
11469
+ condition.conditions.map(dnfInner).flatMap((c) => c.conditions)
11470
+ )
11471
+ };
11472
+ default:
11473
+ unreachable(condition);
11057
11474
  }
11058
- return rv;
11059
11475
  }
11060
- function normalizeRelationship(relationship, tableSchemaCache) {
11061
- if (isFieldRelationship(relationship)) {
11062
- return normalizeFieldRelationship(relationship, tableSchemaCache);
11476
+ function distributeAnd(conditions) {
11477
+ if (conditions.length === 0) {
11478
+ return { type: "or", conditions: [TRUE] };
11063
11479
  }
11064
- return normalizeJunctionRelationship(relationship, tableSchemaCache);
11065
- }
11066
- function normalizeFieldRelationship(relationship, tableSchemaCache) {
11067
- return {
11068
- source: relationship.source,
11069
- dest: {
11070
- field: relationship.dest.field,
11071
- schema: normalizeLazyTableSchema(
11072
- relationship.dest.schema,
11073
- tableSchemaCache
11074
- )
11075
- }
11076
- };
11077
- }
11078
- function normalizeJunctionRelationship(relationship, tableSchemaCache) {
11079
- return {
11080
- source: relationship.source,
11081
- junction: {
11082
- sourceField: relationship.junction.sourceField,
11083
- destField: relationship.junction.destField,
11084
- schema: normalizeLazyTableSchema(
11085
- relationship.junction.schema,
11086
- tableSchemaCache
11087
- )
11088
- },
11089
- dest: {
11090
- field: relationship.dest.field,
11091
- schema: normalizeLazyTableSchema(
11092
- relationship.dest.schema,
11093
- tableSchemaCache
11094
- )
11480
+ return conditions.reduce((acc, orCondition) => {
11481
+ const newConditions = [];
11482
+ for (const accCondition of acc.conditions) {
11483
+ for (const orSubCondition of orCondition.conditions) {
11484
+ newConditions.push({
11485
+ type: "and",
11486
+ conditions: [accCondition, orSubCondition]
11487
+ });
11488
+ }
11095
11489
  }
11096
- };
11490
+ return {
11491
+ type: "or",
11492
+ conditions: flatten("or", newConditions)
11493
+ };
11494
+ });
11097
11495
  }
11098
- function normalizeLazyTableSchema(tableSchema, buildCache) {
11099
- const tableSchemaInstance = typeof tableSchema === "function" ? tableSchema() : tableSchema;
11100
- return normalizeTableSchemaWithCache(
11101
- tableSchemaInstance,
11102
- tableSchemaInstance.tableName,
11103
- // Don't care about name here.
11104
- buildCache
11105
- );
11496
+ function unwrap(c) {
11497
+ if (c.type === "simple" || c.type === "correlatedSubquery") {
11498
+ return c;
11499
+ }
11500
+ if (c.conditions.length === 1) {
11501
+ return unwrap(c.conditions[0]);
11502
+ }
11503
+ return { type: c.type, conditions: flatten(c.type, c.conditions.map(unwrap)) };
11106
11504
  }
11107
11505
 
11108
- // ../zql/src/zql/query/query-impl.ts
11506
+ // ../zql/src/query/query-impl.ts
11109
11507
  function newQuery(delegate, tableSchema) {
11110
11508
  return new QueryImpl(delegate, normalizeTableSchema(tableSchema));
11111
11509
  }
11112
11510
  function newQueryWithDetails(delegate, schema, ast, format) {
11113
11511
  return new QueryImpl(delegate, schema, ast, format);
11114
11512
  }
11513
+ function staticParam(anchorClass, field) {
11514
+ return {
11515
+ type: "static",
11516
+ anchor: anchorClass,
11517
+ field
11518
+ };
11519
+ }
11520
+ var subqueryFilterCount = 0;
11521
+ var SUBQ_PREFIX = "zsubq_";
11115
11522
  var AbstractQuery = class {
11116
11523
  #ast;
11117
11524
  #schema;
@@ -11133,9 +11540,6 @@ var AbstractQuery = class {
11133
11540
  }
11134
11541
  return this.#hash;
11135
11542
  }
11136
- select(..._fields) {
11137
- return this._newQuery(this.#schema, this.#ast, this.#format);
11138
- }
11139
11543
  one() {
11140
11544
  return this._newQuery(
11141
11545
  this.#schema,
@@ -11149,13 +11553,21 @@ var AbstractQuery = class {
11149
11553
  }
11150
11554
  );
11151
11555
  }
11556
+ whereExists(relationship, cb = (q) => q) {
11557
+ return this.where(({ exists }) => exists(relationship, cb));
11558
+ }
11152
11559
  related(relationship, cb = (q) => q) {
11560
+ if (relationship.startsWith(SUBQ_PREFIX)) {
11561
+ throw new Error(
11562
+ `Relationship names may not start with "${SUBQ_PREFIX}". That is a reserved prefix.`
11563
+ );
11564
+ }
11153
11565
  const related = this.#schema.relationships[relationship];
11154
11566
  assert(related, "Invalid relationship");
11155
- const related1 = related;
11156
- const related2 = related;
11157
- if (isFieldRelationship(related1)) {
11158
- const destSchema = related1.dest.schema;
11567
+ const fieldRelationship = related;
11568
+ const junctionRelationship = related;
11569
+ if (isFieldRelationship(fieldRelationship)) {
11570
+ const destSchema = fieldRelationship.dest.schema;
11159
11571
  const sq = cb(
11160
11572
  this._newQuery(
11161
11573
  destSchema,
@@ -11174,8 +11586,8 @@ var AbstractQuery = class {
11174
11586
  ...this.#ast.related ?? [],
11175
11587
  {
11176
11588
  correlation: {
11177
- parentField: related1.source,
11178
- childField: related1.dest.field,
11589
+ parentField: fieldRelationship.source,
11590
+ childField: fieldRelationship.dest.field,
11179
11591
  op: "="
11180
11592
  },
11181
11593
  subquery: addPrimaryKeysToAst(destSchema, sq.#ast)
@@ -11191,9 +11603,9 @@ var AbstractQuery = class {
11191
11603
  }
11192
11604
  );
11193
11605
  }
11194
- if (isJunctionRelationship(related2)) {
11195
- const destSchema = related2.dest.schema;
11196
- const junctionSchema = related2.junction.schema;
11606
+ if (isJunctionRelationship(junctionRelationship)) {
11607
+ const destSchema = junctionRelationship.dest.schema;
11608
+ const junctionSchema = junctionRelationship.junction.schema;
11197
11609
  const sq = cb(
11198
11610
  this._newQuery(
11199
11611
  destSchema,
@@ -11212,8 +11624,8 @@ var AbstractQuery = class {
11212
11624
  ...this.#ast.related ?? [],
11213
11625
  {
11214
11626
  correlation: {
11215
- parentField: related2.source,
11216
- childField: related2.junction.sourceField,
11627
+ parentField: junctionRelationship.source,
11628
+ childField: junctionRelationship.junction.sourceField,
11217
11629
  op: "="
11218
11630
  },
11219
11631
  subquery: {
@@ -11223,8 +11635,8 @@ var AbstractQuery = class {
11223
11635
  related: [
11224
11636
  {
11225
11637
  correlation: {
11226
- parentField: related2.junction.destField,
11227
- childField: related2.dest.field,
11638
+ parentField: junctionRelationship.junction.destField,
11639
+ childField: junctionRelationship.dest.field,
11228
11640
  op: "="
11229
11641
  },
11230
11642
  hidden: true,
@@ -11246,13 +11658,13 @@ var AbstractQuery = class {
11246
11658
  }
11247
11659
  throw new Error(`Invalid relationship ${relationship}`);
11248
11660
  }
11249
- where(field, opOrValue, value) {
11661
+ where(fieldOrExpressionFactory, opOrValue, value) {
11250
11662
  let cond;
11251
- if (opOrValue === void 0 && value === void 0) {
11252
- assert(typeof field !== "string", `Invalid condition: ${field}`);
11253
- cond = field;
11663
+ if (typeof fieldOrExpressionFactory === "function") {
11664
+ cond = fieldOrExpressionFactory(new ExpressionBuilder(this.#exists));
11254
11665
  } else {
11255
- cond = cmp(field, opOrValue, value);
11666
+ assert(opOrValue !== void 0, "Invalid condition");
11667
+ cond = cmp(fieldOrExpressionFactory, opOrValue, value);
11256
11668
  }
11257
11669
  const existingWhere = this.#ast.where;
11258
11670
  if (existingWhere) {
@@ -11262,7 +11674,7 @@ var AbstractQuery = class {
11262
11674
  this.#schema,
11263
11675
  {
11264
11676
  ...this.#ast,
11265
- where: cond
11677
+ where: dnf(cond)
11266
11678
  },
11267
11679
  this.#format
11268
11680
  );
@@ -11306,6 +11718,81 @@ var AbstractQuery = class {
11306
11718
  this.#format
11307
11719
  );
11308
11720
  }
11721
+ #exists = (relationship, cb = (q) => q) => {
11722
+ ++subqueryFilterCount;
11723
+ const related = this.#schema.relationships[relationship];
11724
+ assert(related, "Invalid relationship");
11725
+ const fieldRelationship = related;
11726
+ const junctionRelationship = related;
11727
+ if (isFieldRelationship(fieldRelationship)) {
11728
+ const destSchema = fieldRelationship.dest.schema;
11729
+ const sq = cb(
11730
+ this._newQuery(
11731
+ destSchema,
11732
+ {
11733
+ table: destSchema.tableName,
11734
+ alias: `${SUBQ_PREFIX}${subqueryFilterCount}_${relationship}`
11735
+ },
11736
+ void 0
11737
+ )
11738
+ );
11739
+ return {
11740
+ type: "correlatedSubquery",
11741
+ related: {
11742
+ correlation: {
11743
+ parentField: fieldRelationship.source,
11744
+ childField: fieldRelationship.dest.field,
11745
+ op: "="
11746
+ },
11747
+ subquery: addPrimaryKeysToAst(destSchema, sq.#ast)
11748
+ },
11749
+ op: "EXISTS"
11750
+ };
11751
+ }
11752
+ if (isJunctionRelationship(junctionRelationship)) {
11753
+ const destSchema = junctionRelationship.dest.schema;
11754
+ const junctionSchema = junctionRelationship.junction.schema;
11755
+ const queryToDest = cb(
11756
+ this._newQuery(
11757
+ destSchema,
11758
+ {
11759
+ table: destSchema.tableName,
11760
+ alias: `${SUBQ_PREFIX}${subqueryFilterCount}_${relationship}`
11761
+ },
11762
+ void 0
11763
+ )
11764
+ );
11765
+ return {
11766
+ type: "correlatedSubquery",
11767
+ related: {
11768
+ correlation: {
11769
+ parentField: junctionRelationship.source,
11770
+ childField: junctionRelationship.junction.sourceField,
11771
+ op: "="
11772
+ },
11773
+ subquery: {
11774
+ table: junctionSchema.tableName,
11775
+ alias: `${SUBQ_PREFIX}${subqueryFilterCount}_${relationship}`,
11776
+ orderBy: addPrimaryKeys(junctionSchema, void 0),
11777
+ where: {
11778
+ type: "correlatedSubquery",
11779
+ related: {
11780
+ correlation: {
11781
+ parentField: junctionRelationship.junction.destField,
11782
+ childField: junctionRelationship.dest.field,
11783
+ op: "="
11784
+ },
11785
+ subquery: addPrimaryKeysToAst(destSchema, queryToDest.#ast)
11786
+ },
11787
+ op: "EXISTS"
11788
+ }
11789
+ }
11790
+ },
11791
+ op: "EXISTS"
11792
+ };
11793
+ }
11794
+ throw new Error(`Invalid relationship ${relationship}`);
11795
+ };
11309
11796
  #completedAST;
11310
11797
  _completeAst() {
11311
11798
  if (!this.#completedAST) {
@@ -11417,7 +11904,114 @@ function arrayViewFactory(_query, input, format, onDestroy, onTransactionCommit)
11417
11904
  return v2;
11418
11905
  }
11419
11906
 
11420
- // ../zql/src/zql/query/escape-like.ts
11907
+ // ../zql/src/query/auth-query.ts
11908
+ var AuthQuery = class _AuthQuery extends AbstractQuery {
11909
+ constructor(schema, ast = { table: schema.tableName }, format) {
11910
+ super(schema, ast, format);
11911
+ }
11912
+ _newQuery(schema, ast, format) {
11913
+ return new _AuthQuery(schema, ast, format);
11914
+ }
11915
+ get ast() {
11916
+ return this._completeAst();
11917
+ }
11918
+ materialize() {
11919
+ throw new Error("AuthQuery cannot be materialized");
11920
+ }
11921
+ run() {
11922
+ throw new Error("AuthQuery cannot be run");
11923
+ }
11924
+ preload() {
11925
+ throw new Error("AuthQuery cannot be preloaded");
11926
+ }
11927
+ };
11928
+
11929
+ // ../zero-schema/src/authorization.ts
11930
+ async function defineAuthorization(schema, definer) {
11931
+ const normalizedSchema = normalizeSchema(schema);
11932
+ const queries = {};
11933
+ for (const [name, tableSchema] of Object.entries(normalizedSchema.tables)) {
11934
+ queries[name] = new AuthQuery(tableSchema);
11935
+ }
11936
+ const config = await definer(queries);
11937
+ return compileAuthorization(config);
11938
+ }
11939
+ function compileAuthorization(authz) {
11940
+ if (!authz) {
11941
+ return void 0;
11942
+ }
11943
+ const ret = {};
11944
+ for (const [tableName, tableConfig] of Object.entries(authz)) {
11945
+ ret[tableName] = {
11946
+ row: compileRowConfig(tableConfig.row),
11947
+ cell: compileCellConfig(tableConfig.cell)
11948
+ };
11949
+ }
11950
+ return ret;
11951
+ }
11952
+ function compileRowConfig(rowRules) {
11953
+ if (!rowRules) {
11954
+ return void 0;
11955
+ }
11956
+ return {
11957
+ select: compileInstanceRules(rowRules.select),
11958
+ insert: compileInstanceRules(rowRules.insert),
11959
+ update: compileInstanceRules(rowRules.update),
11960
+ delete: compileInstanceRules(rowRules.delete)
11961
+ };
11962
+ }
11963
+ function compileInstanceRules(rules) {
11964
+ if (!rules) {
11965
+ return void 0;
11966
+ }
11967
+ return rules.map(
11968
+ (rule) => [
11969
+ "allow",
11970
+ rule(
11971
+ authDataRef,
11972
+ preMutationRowRef
11973
+ ).ast
11974
+ ]
11975
+ );
11976
+ }
11977
+ function compileCellConfig(cellRules) {
11978
+ if (!cellRules) {
11979
+ return void 0;
11980
+ }
11981
+ const ret = {};
11982
+ for (const [columnName, rules] of Object.entries(cellRules)) {
11983
+ ret[columnName] = {
11984
+ select: compileInstanceRules(rules.select),
11985
+ insert: compileInstanceRules(rules.insert),
11986
+ update: compileInstanceRules(rules.update),
11987
+ delete: compileInstanceRules(rules.delete)
11988
+ };
11989
+ }
11990
+ return ret;
11991
+ }
11992
+ var authDataRef = new Proxy(
11993
+ {},
11994
+ {
11995
+ get(_target, prop, _receiver) {
11996
+ return staticParam("authData", prop);
11997
+ }
11998
+ }
11999
+ );
12000
+ var preMutationRowRef = new Proxy(
12001
+ {},
12002
+ {
12003
+ get(_target, prop, _receiver) {
12004
+ return staticParam("preMutationRow", prop);
12005
+ }
12006
+ }
12007
+ );
12008
+
12009
+ // ../zero-schema/src/schema.ts
12010
+ function createSchema(schema) {
12011
+ return schema;
12012
+ }
12013
+
12014
+ // ../zql/src/query/escape-like.ts
11421
12015
  function escapeLike(val) {
11422
12016
  return val.replace(/[%_]/g, "\\$&");
11423
12017
  }
@@ -11658,14 +12252,14 @@ var pingMessageSchema = valita_exports.tuple([valita_exports.literal("ping"), pi
11658
12252
 
11659
12253
  // ../zero-protocol/src/push.ts
11660
12254
  var CRUD_MUTATION_NAME = "_zero_crud";
11661
- var createOpSchema = valita_exports.object({
11662
- op: valita_exports.literal("create"),
12255
+ var insertOpSchema = valita_exports.object({
12256
+ op: valita_exports.literal("insert"),
11663
12257
  tableName: valita_exports.string(),
11664
12258
  primaryKey: primaryKeySchema,
11665
12259
  value: rowSchema
11666
12260
  });
11667
- var setOpSchema = valita_exports.object({
11668
- op: valita_exports.literal("set"),
12261
+ var upsertOpSchema = valita_exports.object({
12262
+ op: valita_exports.literal("upsert"),
11669
12263
  tableName: valita_exports.string(),
11670
12264
  primaryKey: primaryKeySchema,
11671
12265
  value: rowSchema
@@ -11685,8 +12279,8 @@ var deleteOpSchema = valita_exports.object({
11685
12279
  value: primaryKeyValueRecordSchema
11686
12280
  });
11687
12281
  var crudOpSchema = valita_exports.union(
11688
- createOpSchema,
11689
- setOpSchema,
12282
+ insertOpSchema,
12283
+ upsertOpSchema,
11690
12284
  updateOpSchema2,
11691
12285
  deleteOpSchema
11692
12286
  );
@@ -13372,7 +13966,7 @@ var EmptyBTree = (() => {
13372
13966
  return t2;
13373
13967
  })();
13374
13968
 
13375
- // ../zql/src/zql/ivm/lookahead-iterator.ts
13969
+ // ../zql/src/ivm/lookahead-iterator.ts
13376
13970
  var LookaheadIterator = class {
13377
13971
  #iter;
13378
13972
  #buffer;
@@ -13413,7 +14007,7 @@ var LookaheadIterator = class {
13413
14007
  }
13414
14008
  };
13415
14009
 
13416
- // ../zql/src/zql/ivm/memory-source.ts
14010
+ // ../zql/src/ivm/memory-source.ts
13417
14011
  var MemorySource = class {
13418
14012
  #tableName;
13419
14013
  #columns;
@@ -13455,8 +14049,10 @@ var MemorySource = class {
13455
14049
  };
13456
14050
  }
13457
14051
  connect(sort, optionalFilters) {
14052
+ const filteredOptionalFilters = filterOptionalFilters(optionalFilters);
14053
+ const predicates = filteredOptionalFilters.filters.map((c) => createPredicate(c));
13458
14054
  const input = {
13459
- getSchema: () => this.#getSchema(connection),
14055
+ getSchema: () => schema,
13460
14056
  fetch: (req) => this.#fetch(req, connection),
13461
14057
  cleanup: (req) => this.#cleanup(req, connection),
13462
14058
  setOutput: (output) => {
@@ -13465,11 +14061,8 @@ var MemorySource = class {
13465
14061
  destroy: () => {
13466
14062
  this.#disconnect(input);
13467
14063
  },
13468
- appliedFilters: false
14064
+ appliedFilters: filteredOptionalFilters.allApplied
13469
14065
  };
13470
- const predicates = filteredOptionalFilters(
13471
- optionalFilters
13472
- ).filters.map((c) => createPredicate(c));
13473
14066
  const connection = {
13474
14067
  input,
13475
14068
  output: void 0,
@@ -13477,6 +14070,7 @@ var MemorySource = class {
13477
14070
  compareRows: makeComparator(sort),
13478
14071
  optionalFilters: predicates
13479
14072
  };
14073
+ const schema = this.#getSchema(connection);
13480
14074
  assertOrderingIncludesPK(sort, this.#primaryKey);
13481
14075
  this.#connections.push(connection);
13482
14076
  return input;
@@ -13724,87 +14318,74 @@ function* generateWithOverlay(startAt, rows, constraint, overlay, compare) {
13724
14318
  yield* generateWithOverlayInner(rows, overlays, compare);
13725
14319
  }
13726
14320
  function computeOverlays(startAt, constraint, overlay, compare) {
13727
- let secondOverlay;
13728
- if (overlay?.change.type === "edit" && compare(overlay.change.row, overlay.change.oldRow) !== 0) {
13729
- [overlay, secondOverlay] = splitEditChange(overlay, compare);
14321
+ let overlays = {
14322
+ add: void 0,
14323
+ remove: void 0
14324
+ };
14325
+ switch (overlay?.change.type) {
14326
+ case "add":
14327
+ overlays = {
14328
+ add: overlay.change.row,
14329
+ remove: void 0
14330
+ };
14331
+ break;
14332
+ case "remove":
14333
+ overlays = {
14334
+ add: void 0,
14335
+ remove: overlay.change.row
14336
+ };
14337
+ break;
14338
+ case "edit":
14339
+ overlays = {
14340
+ add: overlay.change.row,
14341
+ remove: overlay.change.oldRow
14342
+ };
14343
+ break;
13730
14344
  }
13731
14345
  if (startAt) {
13732
- overlay = overlayForStartAt(overlay, startAt, compare);
13733
- secondOverlay = overlayForStartAt(secondOverlay, startAt, compare);
14346
+ overlays = overlaysForStartAt(overlays, startAt, compare);
13734
14347
  }
13735
14348
  if (constraint) {
13736
- overlay = overlayForConstraint(overlay, constraint);
13737
- secondOverlay = overlayForConstraint(secondOverlay, constraint);
13738
- }
13739
- if (secondOverlay !== void 0 && overlay === void 0) {
13740
- overlay = secondOverlay;
13741
- secondOverlay = void 0;
13742
- }
13743
- return [overlay, secondOverlay];
13744
- }
13745
- function overlayForStartAt(overlay, startAt, compare) {
13746
- if (!overlay) {
13747
- return void 0;
13748
- }
13749
- if (compare(overlay.change.row, startAt) < 0) {
13750
- return void 0;
13751
- }
13752
- return overlay;
13753
- }
13754
- function overlayForConstraint(overlay, constraint) {
13755
- if (!overlay) {
13756
- return void 0;
13757
- }
13758
- if (!valuesEqual(overlay.change.row[constraint.key], constraint.value)) {
13759
- return void 0;
14349
+ overlays = overlaysForConstraint(overlays, constraint);
13760
14350
  }
13761
- return overlay;
14351
+ return overlays;
13762
14352
  }
13763
- function splitEditChange(overlay, compare) {
13764
- const { oldRow, row } = overlay.change;
13765
- const removeOverlay = {
13766
- outputIndex: overlay.outputIndex,
13767
- change: { type: "remove", row: oldRow }
14353
+ function overlaysForStartAt({ add, remove }, startAt, compare) {
14354
+ const undefinedIfBeforeStartAt = (row) => row === void 0 || compare(row, startAt) < 0 ? void 0 : row;
14355
+ return {
14356
+ add: undefinedIfBeforeStartAt(add),
14357
+ remove: undefinedIfBeforeStartAt(remove)
13768
14358
  };
13769
- const addOverlay = {
13770
- outputIndex: overlay.outputIndex,
13771
- change: { type: "add", row }
14359
+ }
14360
+ function overlaysForConstraint({ add, remove }, constraint) {
14361
+ const undefinedIfDoesntMatchConstraint = (row) => row === void 0 || !valuesEqual(row[constraint.key], constraint.value) ? void 0 : row;
14362
+ return {
14363
+ add: undefinedIfDoesntMatchConstraint(add),
14364
+ remove: undefinedIfDoesntMatchConstraint(remove)
13772
14365
  };
13773
- const cmp2 = compare(oldRow, row);
13774
- assert(cmp2 !== 0, "We should not split edit change with same PK");
13775
- if (cmp2 < 0) {
13776
- return [removeOverlay, addOverlay];
13777
- }
13778
- return [addOverlay, removeOverlay];
13779
14366
  }
13780
14367
  function* generateWithOverlayInner(rowIterator, overlays, compare) {
13781
- let [overlay, secondOverlay] = overlays;
14368
+ let addOverlayYielded = false;
14369
+ let removeOverlaySkipped = false;
13782
14370
  for (const row of rowIterator) {
13783
- if (overlay) {
13784
- if (overlay.change.type === "add" || overlay.change.type === "edit") {
13785
- const cmp2 = compare(overlay.change.row, row);
13786
- if (cmp2 < 0) {
13787
- yield { row: overlay.change.row, relationships: {} };
13788
- overlay = secondOverlay;
13789
- secondOverlay = void 0;
13790
- }
14371
+ if (!addOverlayYielded && overlays.add) {
14372
+ const cmp2 = compare(overlays.add, row);
14373
+ if (cmp2 < 0) {
14374
+ addOverlayYielded = true;
14375
+ yield { row: overlays.add, relationships: {} };
13791
14376
  }
13792
- if (overlay?.change.type === "remove") {
13793
- const cmp2 = compare(overlay.change.row, row);
13794
- if (cmp2 < 0) {
13795
- overlay = secondOverlay;
13796
- secondOverlay = void 0;
13797
- } else if (cmp2 === 0) {
13798
- overlay = secondOverlay;
13799
- secondOverlay = void 0;
13800
- continue;
13801
- }
14377
+ }
14378
+ if (!removeOverlaySkipped && overlays.remove) {
14379
+ const cmp2 = compare(overlays.remove, row);
14380
+ if (cmp2 === 0) {
14381
+ removeOverlaySkipped = true;
14382
+ continue;
13802
14383
  }
13803
14384
  }
13804
14385
  yield { row, relationships: {} };
13805
14386
  }
13806
- if (overlay && overlay.change.type === "add") {
13807
- yield { row: overlay.change.row, relationships: {} };
14387
+ if (!addOverlayYielded && overlays.add) {
14388
+ yield { row: overlays.add, relationships: {} };
13808
14389
  }
13809
14390
  }
13810
14391
  var minValue = Symbol("min-value");
@@ -13839,11 +14420,7 @@ function compareBounds(a, b) {
13839
14420
  }
13840
14421
  return compareValues(a, b);
13841
14422
  }
13842
- function filteredOptionalFilters(optionalFilters) {
13843
- let ret = {
13844
- filters: [],
13845
- allApplied: false
13846
- };
14423
+ function filterOptionalFilters(optionalFilters) {
13847
14424
  if (optionalFilters) {
13848
14425
  if (optionalFilters.type === "or" && optionalFilters.conditions.length === 1) {
13849
14426
  optionalFilters = optionalFilters.conditions[0];
@@ -13852,25 +14429,26 @@ function filteredOptionalFilters(optionalFilters) {
13852
14429
  const filters = optionalFilters.conditions.filter(
13853
14430
  (c) => c.type === "simple"
13854
14431
  );
13855
- ret = {
14432
+ return {
13856
14433
  filters,
13857
14434
  allApplied: filters.length === optionalFilters.conditions.length
13858
14435
  };
13859
- } else if (optionalFilters.type === "simple") {
13860
- ret = {
14436
+ }
14437
+ if (optionalFilters.type === "simple") {
14438
+ return {
13861
14439
  filters: [optionalFilters],
13862
14440
  allApplied: true
13863
14441
  };
13864
- } else {
13865
- return { filters: [], allApplied: false };
13866
14442
  }
13867
- } else {
13868
- ret.allApplied = true;
14443
+ return { filters: [], allApplied: false };
13869
14444
  }
13870
- return ret;
14445
+ return {
14446
+ filters: [],
14447
+ allApplied: true
14448
+ };
13871
14449
  }
13872
14450
 
13873
- // ../zql/src/zql/ivm/memory-storage.ts
14451
+ // ../zql/src/ivm/memory-storage.ts
13874
14452
  var MemoryStorage = class {
13875
14453
  #data = new BTree();
13876
14454
  set(key, value) {
@@ -14050,7 +14628,7 @@ var ZeroContext = class {
14050
14628
  function makeCRUDMutate(schema, repMutate) {
14051
14629
  const { [CRUD_MUTATION_NAME]: zeroCRUD } = repMutate;
14052
14630
  let inBatch = false;
14053
- const mutate = async (body) => {
14631
+ const mutateBatch = async (body) => {
14054
14632
  if (inBatch) {
14055
14633
  throw new Error("Cannot call mutate inside a batch");
14056
14634
  }
@@ -14073,6 +14651,7 @@ function makeCRUDMutate(schema, repMutate) {
14073
14651
  throw new Error(`Cannot call mutate.${tableName}.${op} inside a batch`);
14074
14652
  }
14075
14653
  };
14654
+ const mutate = {};
14076
14655
  for (const [name, tableSchema] of Object.entries(schema.tables)) {
14077
14656
  mutate[name] = makeEntityCRUDMutate(
14078
14657
  name,
@@ -14081,24 +14660,27 @@ function makeCRUDMutate(schema, repMutate) {
14081
14660
  assertNotInBatch
14082
14661
  );
14083
14662
  }
14084
- return mutate;
14663
+ return {
14664
+ mutate,
14665
+ mutateBatch
14666
+ };
14085
14667
  }
14086
14668
  function makeEntityCRUDMutate(tableName, primaryKey, zeroCRUD, assertNotInBatch) {
14087
14669
  return {
14088
- create: (value) => {
14089
- assertNotInBatch(tableName, "create");
14670
+ insert: (value) => {
14671
+ assertNotInBatch(tableName, "insert");
14090
14672
  const op = {
14091
- op: "create",
14673
+ op: "insert",
14092
14674
  tableName,
14093
14675
  primaryKey,
14094
14676
  value
14095
14677
  };
14096
14678
  return zeroCRUD({ ops: [op] });
14097
14679
  },
14098
- set: (value) => {
14099
- assertNotInBatch(tableName, "set");
14680
+ upsert: (value) => {
14681
+ assertNotInBatch(tableName, "upsert");
14100
14682
  const op = {
14101
- op: "set",
14683
+ op: "upsert",
14102
14684
  tableName,
14103
14685
  primaryKey,
14104
14686
  value
@@ -14130,9 +14712,9 @@ function makeEntityCRUDMutate(tableName, primaryKey, zeroCRUD, assertNotInBatch)
14130
14712
  function makeBatchCRUDMutate(tableName, schema, ops) {
14131
14713
  const { primaryKey } = schema.tables[tableName];
14132
14714
  return {
14133
- create: (value) => {
14715
+ insert: (value) => {
14134
14716
  const op = {
14135
- op: "create",
14717
+ op: "insert",
14136
14718
  tableName,
14137
14719
  primaryKey,
14138
14720
  value
@@ -14140,9 +14722,9 @@ function makeBatchCRUDMutate(tableName, schema, ops) {
14140
14722
  ops.push(op);
14141
14723
  return promiseVoid;
14142
14724
  },
14143
- set: (value) => {
14725
+ upsert: (value) => {
14144
14726
  const op = {
14145
- op: "set",
14727
+ op: "upsert",
14146
14728
  tableName,
14147
14729
  primaryKey,
14148
14730
  value
@@ -14176,11 +14758,11 @@ function makeCRUDMutator(schema) {
14176
14758
  return async function zeroCRUDMutator(tx, crudArg) {
14177
14759
  for (const op of crudArg.ops) {
14178
14760
  switch (op.op) {
14179
- case "create":
14180
- await createImpl(tx, op, schema);
14761
+ case "insert":
14762
+ await insertImpl(tx, op, schema);
14181
14763
  break;
14182
- case "set":
14183
- await setImpl(tx, op, schema);
14764
+ case "upsert":
14765
+ await upsertImpl(tx, op, schema);
14184
14766
  break;
14185
14767
  case "update":
14186
14768
  await updateImpl(tx, op, schema);
@@ -14192,23 +14774,40 @@ function makeCRUDMutator(schema) {
14192
14774
  }
14193
14775
  };
14194
14776
  }
14195
- async function createImpl(tx, arg, schema) {
14777
+ function defaultOptionalFieldsToNull(schema, value) {
14778
+ let rv = value;
14779
+ for (const name in schema.columns) {
14780
+ if (rv[name] === void 0) {
14781
+ rv = { ...rv, [name]: null };
14782
+ }
14783
+ }
14784
+ return rv;
14785
+ }
14786
+ async function insertImpl(tx, arg, schema) {
14196
14787
  const key = toPrimaryKeyString(
14197
14788
  arg.tableName,
14198
14789
  schema.tables[arg.tableName].primaryKey,
14199
14790
  arg.value
14200
14791
  );
14201
14792
  if (!await tx.has(key)) {
14202
- await tx.set(key, arg.value);
14793
+ const val = defaultOptionalFieldsToNull(
14794
+ schema.tables[arg.tableName],
14795
+ arg.value
14796
+ );
14797
+ await tx.set(key, val);
14203
14798
  }
14204
14799
  }
14205
- async function setImpl(tx, arg, schema) {
14800
+ async function upsertImpl(tx, arg, schema) {
14206
14801
  const key = toPrimaryKeyString(
14207
14802
  arg.tableName,
14208
14803
  schema.tables[arg.tableName].primaryKey,
14209
14804
  arg.value
14210
14805
  );
14211
- await tx.set(key, arg.value);
14806
+ const val = defaultOptionalFieldsToNull(
14807
+ schema.tables[arg.tableName],
14808
+ arg.value
14809
+ );
14810
+ await tx.set(key, val);
14212
14811
  }
14213
14812
  async function updateImpl(tx, arg, schema) {
14214
14813
  const key = toPrimaryKeyString(
@@ -14221,7 +14820,12 @@ async function updateImpl(tx, arg, schema) {
14221
14820
  return;
14222
14821
  }
14223
14822
  const update = arg.value;
14224
- const next = { ...prev, ...update };
14823
+ const next = { ...prev };
14824
+ for (const k in update) {
14825
+ if (update[k] !== void 0) {
14826
+ next[k] = update[k];
14827
+ }
14828
+ }
14225
14829
  await tx.set(key, next);
14226
14830
  }
14227
14831
  async function deleteImpl(tx, arg, schema) {
@@ -14252,6 +14856,9 @@ function shouldEnableAnalytics(server, enableAnalytics = true) {
14252
14856
  function toWSString(url) {
14253
14857
  return "ws" + url.slice(4);
14254
14858
  }
14859
+ function appendPath(url, toAppend) {
14860
+ return url + (url.endsWith("/") ? toAppend.substring(1) : toAppend);
14861
+ }
14255
14862
 
14256
14863
  // ../zero-client/src/client/log-options.ts
14257
14864
  import {
@@ -14478,7 +15085,7 @@ function makeMessage(message, context, logLevel) {
14478
15085
  }
14479
15086
 
14480
15087
  // ../zero-client/src/client/version.ts
14481
- var version2 = "0.5.2024103100+3e74e2";
15088
+ var version2 = "0.6.2024111600+92a1ea";
14482
15089
 
14483
15090
  // ../zero-client/src/client/log-options.ts
14484
15091
  var LevelFilterLogSink = class {
@@ -14512,9 +15119,9 @@ function createLogOptions(options, createDatadogLogSink = (options2) => new Data
14512
15119
  };
14513
15120
  }
14514
15121
  const serverURL = new URL(server);
14515
- const socketHostname = serverURL.hostname;
14516
- const datadogServiceLabel = socketHostname.endsWith(ZERO_SASS_DOMAIN) ? socketHostname.substring(0, socketHostname.length - ZERO_SASS_DOMAIN.length).toLowerCase() : socketHostname;
14517
- const baseURL = new URL("/api/logs/v0/log", server);
15122
+ const { hostname } = serverURL;
15123
+ const datadogServiceLabel = hostname.endsWith(ZERO_SASS_DOMAIN) ? hostname.substring(0, hostname.length - ZERO_SASS_DOMAIN.length).toLowerCase() : hostname;
15124
+ const baseURL = new URL(appendPath(server, "/logs/v0/log"));
14518
15125
  const logLevel = consoleLogLevel === "debug" ? "debug" : "info";
14519
15126
  const logSink = new TeeLogSink2([
14520
15127
  new LevelFilterLogSink(consoleLogSink4, consoleLogLevel),
@@ -14764,30 +15371,6 @@ var State = class {
14764
15371
  }
14765
15372
  };
14766
15373
 
14767
- // ../zero-client/src/client/normalized-schema.ts
14768
- function normalizeSchema(schema) {
14769
- if (schema instanceof NormalizedSchema) {
14770
- return schema;
14771
- }
14772
- return new NormalizedSchema(schema);
14773
- }
14774
- var NormalizedSchema = class {
14775
- version;
14776
- tables;
14777
- constructor(schema) {
14778
- this.version = schema.version;
14779
- this.tables = normalizeTables(schema.tables);
14780
- }
14781
- };
14782
- function normalizeTables(tables) {
14783
- const rv = {};
14784
- const tableSchemaCache = /* @__PURE__ */ new Map();
14785
- for (const [name, table] of sortedEntries(tables)) {
14786
- rv[name] = normalizeTableSchemaWithCache(table, name, tableSchemaCache);
14787
- }
14788
- return rv;
14789
- }
14790
-
14791
15374
  // ../zero-client/src/client/query-manager.ts
14792
15375
  var QueryManager = class {
14793
15376
  #clientID;
@@ -14968,7 +15551,7 @@ function isAuthErrorKind(kind) {
14968
15551
  // ../zero-client/src/client/server-option.ts
14969
15552
  function validateServerParam(paramName, server) {
14970
15553
  const expectedProtocol = "http";
14971
- const forExample = () => ` For example: "${expectedProtocol}s://myapp-myteam.zero.ms/".`;
15554
+ const forExample = (path2 = "") => ` For example: "${expectedProtocol}s://myapp-myteam.zero.ms/${path2}".`;
14972
15555
  if (!server.startsWith(`${expectedProtocol}://`) && !server.startsWith(`${expectedProtocol}s://`)) {
14973
15556
  throw new Error(
14974
15557
  `ZeroOptions.${paramName} must use the "${expectedProtocol}" or "${expectedProtocol}s" scheme.`
@@ -14983,9 +15566,18 @@ function validateServerParam(paramName, server) {
14983
15566
  );
14984
15567
  }
14985
15568
  const urlString = url.toString();
14986
- if (url.pathname !== "/") {
15569
+ const pathComponents = url.pathname.split("/");
15570
+ if (pathComponents[0] === "") {
15571
+ pathComponents.shift();
15572
+ }
15573
+ if (pathComponents[pathComponents.length - 1] === "") {
15574
+ pathComponents.pop();
15575
+ }
15576
+ if (pathComponents.length > 1) {
14987
15577
  throw new Error(
14988
- `ZeroOptions.${paramName} must not contain a path component (other than "/").${forExample()}`
15578
+ `ZeroOptions.${paramName} may have at most one path component.${forExample(
15579
+ "zero"
15580
+ )}`
14989
15581
  );
14990
15582
  }
14991
15583
  for (const [property, invalidEndsWith] of [
@@ -15025,6 +15617,7 @@ var PokeHandler = class {
15025
15617
  // order poke errors.
15026
15618
  #pokeLock = new Lock3();
15027
15619
  #schema;
15620
+ #raf = getBrowserGlobalMethod("requestAnimationFrame") ?? rafFallback;
15028
15621
  constructor(replicachePoke, onPokeError, clientID, schema, lc) {
15029
15622
  this.#replicachePoke = replicachePoke;
15030
15623
  this.#onPokeError = onPokeError;
@@ -15082,7 +15675,7 @@ var PokeHandler = class {
15082
15675
  #startPlaybackLoop() {
15083
15676
  this.#lc.debug?.("starting playback loop");
15084
15677
  this.#pokePlaybackLoopRunning = true;
15085
- requestAnimationFrame(this.#rafCallback);
15678
+ this.#raf(this.#rafCallback);
15086
15679
  }
15087
15680
  #rafCallback = async () => {
15088
15681
  const rafLC = this.#lc.withContext("rafAt", Math.floor(performance.now()));
@@ -15091,7 +15684,7 @@ var PokeHandler = class {
15091
15684
  this.#pokePlaybackLoopRunning = false;
15092
15685
  return;
15093
15686
  }
15094
- requestAnimationFrame(this.#rafCallback);
15687
+ this.#raf(this.#rafCallback);
15095
15688
  const start = performance.now();
15096
15689
  rafLC.debug?.(
15097
15690
  "raf fired, processing pokes. Since last raf",
@@ -15280,11 +15873,14 @@ function rowsPatchOpToReplicachePatchOp(op, schema) {
15280
15873
  throw new Error("to be implemented");
15281
15874
  }
15282
15875
  }
15876
+ function rafFallback(callback) {
15877
+ setTimeout(callback, 0);
15878
+ }
15879
+
15880
+ // ../zero-client/src/client/protocol-version.ts
15881
+ var PROTOCOL_VERSION = 1;
15283
15882
 
15284
15883
  // ../zero-client/src/client/zero.ts
15285
- function createSchema(schema) {
15286
- return schema;
15287
- }
15288
15884
  var onSetConnectionStateSymbol = Symbol();
15289
15885
  var exposedToTestingSymbol = Symbol();
15290
15886
  var createLogOptionsSymbol = Symbol();
@@ -15296,7 +15892,6 @@ var DEFAULT_DISCONNECT_HIDDEN_DELAY_MS = 5e3;
15296
15892
  var CONNECT_TIMEOUT_MS = 1e4;
15297
15893
  var CHECK_CONNECTIVITY_ON_ERROR_FREQUENCY = 6;
15298
15894
  var NULL_LAST_MUTATION_ID_SENT = { clientID: "", id: -1 };
15299
- var REFLECT_VERSION = 1;
15300
15895
  function convertOnUpdateNeededReason(reason) {
15301
15896
  return { type: reason.type };
15302
15897
  }
@@ -15480,7 +16075,8 @@ var Zero = class {
15480
16075
  const server = getServer(options.server);
15481
16076
  this.#enableAnalytics = shouldEnableAnalytics(
15482
16077
  server,
15483
- options.enableAnalytics
16078
+ false
16079
+ // Reenable analytics
15484
16080
  );
15485
16081
  if (jurisdiction !== void 0 && jurisdiction !== "eu") {
15486
16082
  throw new Error('ZeroOptions.jurisdiction must be "eu" if present.');
@@ -15550,7 +16146,12 @@ var Zero = class {
15550
16146
  reason ?? ON_CLIENT_STATE_NOT_FOUND_REASON_CLIENT
15551
16147
  );
15552
16148
  };
15553
- this.mutate = makeCRUDMutate(normalizedSchema, rep.mutate);
16149
+ const { mutate, mutateBatch } = makeCRUDMutate(
16150
+ normalizedSchema,
16151
+ rep.mutate
16152
+ );
16153
+ this.mutate = mutate;
16154
+ this.mutateBatch = mutateBatch;
15554
16155
  this.#queryManager = new QueryManager(
15555
16156
  rep.clientID,
15556
16157
  (msg) => this.#sendChangeDesiredQueries(msg),
@@ -15644,30 +16245,42 @@ var Zero = class {
15644
16245
  return this.#rep.clientGroupID;
15645
16246
  }
15646
16247
  /**
15647
- * Provides facilities to write data to Zero.
16248
+ * Provides simple "CRUD" mutations for the tables in the schema.
15648
16249
  *
15649
- * `mutate` is a function as well as a "namespace" object for doing CRUD style
15650
- * mutations. When used as a function it is used to batch multiple mutations.
16250
+ * Each table has `create`, `set`, `update`, and `delete` methods.
15651
16251
  *
15652
16252
  * ```ts
15653
- * await zero.mutate.issue.create({id: '1', title: 'First issue'});
16253
+ * await zero.mutate.issue.create({id: '1', title: 'First issue', priority: 'high'});
15654
16254
  * await zero.mutate.comment.create({id: '1', text: 'First comment', issueID: '1'});
16255
+ * ```
16256
+ *
16257
+ * The `update` methods support partials. Unspecified or `undefined` fields
16258
+ * are left unchanged:
16259
+ *
16260
+ * ```ts
16261
+ * // Priority left unchanged.
16262
+ * await zero.mutate.issue.update({id: '1', title: 'Updated title'});
16263
+ * ```
16264
+ */
16265
+ mutate;
16266
+ /**
16267
+ * Provides a way to batch multiple CRUD mutations together:
15655
16268
  *
15656
- * // or as a function:
15657
- * await zero.mutate(m => {
16269
+ * ```ts
16270
+ * await zero.mutateBatch(m => {
15658
16271
  * await m.issue.create({id: '1', title: 'First issue'});
15659
16272
  * await m.comment.create({id: '1', text: 'First comment', issueID: '1'});
15660
16273
  * });
15661
16274
  * ```
15662
16275
  *
15663
- * The benefit of using the function form is that it allows you to batch
15664
- * multiple mutations together. This can be more efficient than making
15665
- * individual calls to `create`, `update`, `set`, and `delete`.
16276
+ * Batch sends all mutations in a single transaction. If one fails, all are
16277
+ * rolled back together. Batch can also be more efficient than making many
16278
+ * individual mutations.
15666
16279
  *
15667
- * The function form of `mutate` is not allowed to be called inside another
15668
- * `mutate` function. Doing so will throw an error.
16280
+ * `mutateBatch` is not allowed inside another `mutateBatch` call. Doing so
16281
+ * will throw an error.
15669
16282
  */
15670
- mutate;
16283
+ mutateBatch;
15671
16284
  /**
15672
16285
  * Whether this Zero instance has been closed. Once a Zero instance has
15673
16286
  * been closed it no longer syncs and you can no longer read or write data out
@@ -15738,11 +16351,8 @@ var Zero = class {
15738
16351
  rejectInvalidMessage();
15739
16352
  }
15740
16353
  };
15741
- #onOpen = (e) => {
15742
- const l = addWebSocketIDFromSocketToLogContext(
15743
- e.target,
15744
- this.#lc
15745
- );
16354
+ #onOpen = () => {
16355
+ const l = addWebSocketIDFromSocketToLogContext(this.#socket, this.#lc);
15746
16356
  if (this.#connectStart === void 0) {
15747
16357
  l.error?.(
15748
16358
  "Got open event but connect start time is undefined. This should not happen."
@@ -15757,10 +16367,7 @@ var Zero = class {
15757
16367
  }
15758
16368
  };
15759
16369
  #onClose = (e) => {
15760
- const l = addWebSocketIDFromSocketToLogContext(
15761
- e.target,
15762
- this.#lc
15763
- );
16370
+ const l = addWebSocketIDFromSocketToLogContext(this.#socket, this.#lc);
15764
16371
  const { code, reason, wasClean } = e;
15765
16372
  l.info?.("Got socket close event", { code, reason, wasClean });
15766
16373
  const closeKind = wasClean ? "CleanClose" : "AbruptClose";
@@ -16242,16 +16849,6 @@ var Zero = class {
16242
16849
  }
16243
16850
  if (gotError) {
16244
16851
  this.#setOnline(false);
16245
- let cfGetCheckSucceeded = false;
16246
- const cfGetCheckURL = new URL(this.#server);
16247
- cfGetCheckURL.pathname = "/api/canary/v0/get";
16248
- cfGetCheckURL.searchParams.set("id", nanoid());
16249
- const cfGetCheckController = new AbortController();
16250
- fetch(cfGetCheckURL, { signal: cfGetCheckController.signal }).then((_) => {
16251
- cfGetCheckSucceeded = true;
16252
- }).catch((_) => {
16253
- cfGetCheckSucceeded = false;
16254
- });
16255
16852
  lc.debug?.(
16256
16853
  "Sleeping",
16257
16854
  RUN_LOOP_INTERVAL_MS,
@@ -16259,13 +16856,6 @@ var Zero = class {
16259
16856
  this.#connectionState
16260
16857
  );
16261
16858
  await sleep(RUN_LOOP_INTERVAL_MS);
16262
- cfGetCheckController.abort();
16263
- if (!cfGetCheckSucceeded) {
16264
- lc.info?.(
16265
- "Canary request failed, resetting total time to connect start time."
16266
- );
16267
- this.#totalToConnectStart = void 0;
16268
- }
16269
16859
  }
16270
16860
  }
16271
16861
  }
@@ -16398,8 +16988,9 @@ var Zero = class {
16398
16988
  }
16399
16989
  };
16400
16990
  async function createSocket(rep, queryManager, socketOrigin, baseCookie, clientID, clientGroupID, schemaVersion, userID, auth, jurisdiction, lmid, wsid, debugPerf, lc, maxHeaderLength = 1024 * 8) {
16401
- const url = new URL(socketOrigin);
16402
- url.pathname = `/api/sync/v${REFLECT_VERSION}/connect`;
16991
+ const url = new URL(
16992
+ appendPath(socketOrigin, `/sync/v${PROTOCOL_VERSION}/connect`)
16993
+ );
16403
16994
  const { searchParams } = url;
16404
16995
  searchParams.set("clientID", clientID);
16405
16996
  searchParams.set("clientGroupID", clientGroupID);
@@ -16463,13 +17054,9 @@ export {
16463
17054
  dropDatabase,
16464
17055
  dropAllDatabases,
16465
17056
  createTableSchema,
16466
- cmp,
16467
- and,
16468
- or,
16469
- not,
16470
- QueryImpl,
16471
- escapeLike,
17057
+ defineAuthorization,
16472
17058
  createSchema,
17059
+ escapeLike,
16473
17060
  Zero
16474
17061
  };
16475
- //# sourceMappingURL=chunk-TBA526RR.js.map
17062
+ //# sourceMappingURL=chunk-V5NTGJ4X.js.map