@rocicorp/zero 0.2.2024101101 → 0.3.2024102500

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 (632) hide show
  1. package/out/react.js +91 -39
  2. package/out/react.js.map +2 -2
  3. package/out/replicache/src/async-iterable-to-array.js +8 -0
  4. package/out/replicache/src/async-iterable-to-array.js.map +1 -0
  5. package/out/replicache/src/bg-interval.js +38 -0
  6. package/out/replicache/src/bg-interval.js.map +1 -0
  7. package/out/replicache/src/binary-search.js +31 -0
  8. package/out/replicache/src/binary-search.js.map +1 -0
  9. package/out/replicache/src/broadcast-channel.js +29 -0
  10. package/out/replicache/src/broadcast-channel.js.map +1 -0
  11. package/out/replicache/src/btree/diff.js +6 -0
  12. package/out/replicache/src/btree/diff.js.map +1 -0
  13. package/out/replicache/src/btree/node.js +392 -0
  14. package/out/replicache/src/btree/node.js.map +1 -0
  15. package/out/replicache/src/btree/read.js +227 -0
  16. package/out/replicache/src/btree/read.js.map +1 -0
  17. package/out/replicache/src/btree/splice.js +79 -0
  18. package/out/replicache/src/btree/splice.js.map +1 -0
  19. package/out/replicache/src/btree/write.js +154 -0
  20. package/out/replicache/src/btree/write.js.map +1 -0
  21. package/out/replicache/src/call-default-fetch.js +37 -0
  22. package/out/replicache/src/call-default-fetch.js.map +1 -0
  23. package/out/replicache/src/config.js +13 -0
  24. package/out/replicache/src/config.js.map +1 -0
  25. package/out/replicache/src/connection-loop-delegates.js +30 -0
  26. package/out/replicache/src/connection-loop-delegates.js.map +1 -0
  27. package/out/replicache/src/connection-loop.js +268 -0
  28. package/out/replicache/src/connection-loop.js.map +1 -0
  29. package/out/replicache/src/cookies.js +41 -0
  30. package/out/replicache/src/cookies.js.map +1 -0
  31. package/out/replicache/src/dag/chunk.js +60 -0
  32. package/out/replicache/src/dag/chunk.js.map +1 -0
  33. package/out/replicache/src/dag/gc.js +126 -0
  34. package/out/replicache/src/dag/gc.js.map +1 -0
  35. package/out/replicache/src/dag/key-type-enum.js +6 -0
  36. package/out/replicache/src/dag/key-type-enum.js.map +1 -0
  37. package/out/replicache/src/dag/key.js +54 -0
  38. package/out/replicache/src/dag/key.js.map +1 -0
  39. package/out/replicache/src/dag/lazy-store.js +532 -0
  40. package/out/replicache/src/dag/lazy-store.js.map +1 -0
  41. package/out/replicache/src/dag/store-impl.js +175 -0
  42. package/out/replicache/src/dag/store-impl.js.map +1 -0
  43. package/out/replicache/src/dag/store.js +22 -0
  44. package/out/replicache/src/dag/store.js.map +1 -0
  45. package/out/replicache/src/dag/visitor.js +22 -0
  46. package/out/replicache/src/dag/visitor.js.map +1 -0
  47. package/out/replicache/src/db/commit.js +443 -0
  48. package/out/replicache/src/db/commit.js.map +1 -0
  49. package/out/replicache/src/db/index-operation-enum.js +4 -0
  50. package/out/replicache/src/db/index-operation-enum.js.map +1 -0
  51. package/out/replicache/src/db/index.js +170 -0
  52. package/out/replicache/src/db/index.js.map +1 -0
  53. package/out/replicache/src/db/meta-type-enum.js +7 -0
  54. package/out/replicache/src/db/meta-type-enum.js.map +1 -0
  55. package/out/replicache/src/db/read.js +59 -0
  56. package/out/replicache/src/db/read.js.map +1 -0
  57. package/out/replicache/src/db/rebase.js +56 -0
  58. package/out/replicache/src/db/rebase.js.map +1 -0
  59. package/out/replicache/src/db/scan.js +2 -0
  60. package/out/replicache/src/db/scan.js.map +1 -0
  61. package/out/replicache/src/db/write.js +260 -0
  62. package/out/replicache/src/db/write.js.map +1 -0
  63. package/out/replicache/src/error-responses.js +30 -0
  64. package/out/replicache/src/error-responses.js.map +1 -0
  65. package/out/replicache/src/filter-async-iterable.js +15 -0
  66. package/out/replicache/src/filter-async-iterable.js.map +1 -0
  67. package/out/replicache/src/format-version-enum.js +9 -0
  68. package/out/replicache/src/format-version-enum.js.map +1 -0
  69. package/out/replicache/src/format-version.js +8 -0
  70. package/out/replicache/src/format-version.js.map +1 -0
  71. package/out/replicache/src/frozen-json.js +151 -0
  72. package/out/replicache/src/frozen-json.js.map +1 -0
  73. package/out/replicache/src/get-default-puller.js +74 -0
  74. package/out/replicache/src/get-default-puller.js.map +1 -0
  75. package/out/replicache/src/get-default-pusher.js +36 -0
  76. package/out/replicache/src/get-default-pusher.js.map +1 -0
  77. package/out/replicache/src/hash.js +73 -0
  78. package/out/replicache/src/hash.js.map +1 -0
  79. package/out/replicache/src/http-request-info.js +7 -0
  80. package/out/replicache/src/http-request-info.js.map +1 -0
  81. package/out/replicache/src/impl.js +2 -0
  82. package/out/replicache/src/impl.js.map +1 -0
  83. package/out/replicache/src/index-defs.js +28 -0
  84. package/out/replicache/src/index-defs.js.map +1 -0
  85. package/out/replicache/src/invoke-kind-enum.js +4 -0
  86. package/out/replicache/src/invoke-kind-enum.js.map +1 -0
  87. package/out/replicache/src/iterable-union.js +5 -0
  88. package/out/replicache/src/iterable-union.js.map +1 -0
  89. package/out/replicache/src/kv/idb-store-with-mem-fallback.js +93 -0
  90. package/out/replicache/src/kv/idb-store-with-mem-fallback.js.map +1 -0
  91. package/out/replicache/src/kv/idb-store.js +179 -0
  92. package/out/replicache/src/kv/idb-store.js.map +1 -0
  93. package/out/replicache/src/kv/mem-store.js +61 -0
  94. package/out/replicache/src/kv/mem-store.js.map +1 -0
  95. package/out/replicache/src/kv/read-impl.js +23 -0
  96. package/out/replicache/src/kv/read-impl.js.map +1 -0
  97. package/out/replicache/src/kv/store.js +2 -0
  98. package/out/replicache/src/kv/store.js.map +1 -0
  99. package/out/replicache/src/kv/write-impl-base.js +48 -0
  100. package/out/replicache/src/kv/write-impl-base.js.map +1 -0
  101. package/out/replicache/src/kv/write-impl.js +25 -0
  102. package/out/replicache/src/kv/write-impl.js.map +1 -0
  103. package/out/replicache/src/lazy.js +10 -0
  104. package/out/replicache/src/lazy.js.map +1 -0
  105. package/out/replicache/src/log-options.js +13 -0
  106. package/out/replicache/src/log-options.js.map +1 -0
  107. package/out/replicache/src/merge-async-iterables.js +61 -0
  108. package/out/replicache/src/merge-async-iterables.js.map +1 -0
  109. package/out/replicache/src/mod.js +14 -0
  110. package/out/replicache/src/mod.js.map +1 -0
  111. package/out/replicache/src/mutation-recovery.js +439 -0
  112. package/out/replicache/src/mutation-recovery.js.map +1 -0
  113. package/out/replicache/src/new-client-channel.js +77 -0
  114. package/out/replicache/src/new-client-channel.js.map +1 -0
  115. package/out/replicache/src/on-persist-channel.js +33 -0
  116. package/out/replicache/src/on-persist-channel.js.map +1 -0
  117. package/out/replicache/src/patch-operation.js +37 -0
  118. package/out/replicache/src/patch-operation.js.map +1 -0
  119. package/out/replicache/src/pending-mutations.js +18 -0
  120. package/out/replicache/src/pending-mutations.js.map +1 -0
  121. package/out/replicache/src/persist/client-gc.js +38 -0
  122. package/out/replicache/src/persist/client-gc.js.map +1 -0
  123. package/out/replicache/src/persist/client-group-gc.js +38 -0
  124. package/out/replicache/src/persist/client-group-gc.js.map +1 -0
  125. package/out/replicache/src/persist/client-groups.js +180 -0
  126. package/out/replicache/src/persist/client-groups.js.map +1 -0
  127. package/out/replicache/src/persist/clients.js +390 -0
  128. package/out/replicache/src/persist/clients.js.map +1 -0
  129. package/out/replicache/src/persist/collect-idb-databases.js +174 -0
  130. package/out/replicache/src/persist/collect-idb-databases.js.map +1 -0
  131. package/out/replicache/src/persist/gather-mem-only-visitor.js +25 -0
  132. package/out/replicache/src/persist/gather-mem-only-visitor.js.map +1 -0
  133. package/out/replicache/src/persist/gather-not-cached-visitor.js +35 -0
  134. package/out/replicache/src/persist/gather-not-cached-visitor.js.map +1 -0
  135. package/out/replicache/src/persist/heartbeat.js +37 -0
  136. package/out/replicache/src/persist/heartbeat.js.map +1 -0
  137. package/out/replicache/src/persist/idb-databases-store-db-name.js +18 -0
  138. package/out/replicache/src/persist/idb-databases-store-db-name.js.map +1 -0
  139. package/out/replicache/src/persist/idb-databases-store.js +90 -0
  140. package/out/replicache/src/persist/idb-databases-store.js.map +1 -0
  141. package/out/replicache/src/persist/make-client-id.js +13 -0
  142. package/out/replicache/src/persist/make-client-id.js.map +1 -0
  143. package/out/replicache/src/persist/persist.js +132 -0
  144. package/out/replicache/src/persist/persist.js.map +1 -0
  145. package/out/replicache/src/persist/refresh.js +147 -0
  146. package/out/replicache/src/persist/refresh.js.map +1 -0
  147. package/out/replicache/src/process-scheduler.js +93 -0
  148. package/out/replicache/src/process-scheduler.js.map +1 -0
  149. package/out/replicache/src/puller.js +2 -0
  150. package/out/replicache/src/puller.js.map +1 -0
  151. package/out/replicache/src/pusher.js +32 -0
  152. package/out/replicache/src/pusher.js.map +1 -0
  153. package/out/replicache/src/replicache-impl.js +1007 -0
  154. package/out/replicache/src/replicache-impl.js.map +1 -0
  155. package/out/replicache/src/replicache-options.js +2 -0
  156. package/out/replicache/src/replicache-options.js.map +1 -0
  157. package/out/replicache/src/replicache.js +387 -0
  158. package/out/replicache/src/replicache.js.map +1 -0
  159. package/out/replicache/src/request-idle.js +15 -0
  160. package/out/replicache/src/request-idle.js.map +1 -0
  161. package/out/replicache/src/scan-iterator.js +202 -0
  162. package/out/replicache/src/scan-iterator.js.map +1 -0
  163. package/out/replicache/src/scan-options.js +45 -0
  164. package/out/replicache/src/scan-options.js.map +1 -0
  165. package/out/replicache/src/set-interval-with-signal.js +7 -0
  166. package/out/replicache/src/set-interval-with-signal.js.map +1 -0
  167. package/out/replicache/src/size-of-value.js +77 -0
  168. package/out/replicache/src/size-of-value.js.map +1 -0
  169. package/out/replicache/src/subscriptions.js +357 -0
  170. package/out/replicache/src/subscriptions.js.map +1 -0
  171. package/out/replicache/src/sync/diff.js +75 -0
  172. package/out/replicache/src/sync/diff.js.map +1 -0
  173. package/out/replicache/src/sync/handle-pull-response-result-type-enum.js +5 -0
  174. package/out/replicache/src/sync/handle-pull-response-result-type-enum.js.map +1 -0
  175. package/out/replicache/src/sync/ids.js +4 -0
  176. package/out/replicache/src/sync/ids.js.map +1 -0
  177. package/out/replicache/src/sync/patch.js +41 -0
  178. package/out/replicache/src/sync/patch.js.map +1 -0
  179. package/out/replicache/src/sync/pull-error.js +16 -0
  180. package/out/replicache/src/sync/pull-error.js.map +1 -0
  181. package/out/replicache/src/sync/pull.js +375 -0
  182. package/out/replicache/src/sync/pull.js.map +1 -0
  183. package/out/replicache/src/sync/push.js +141 -0
  184. package/out/replicache/src/sync/push.js.map +1 -0
  185. package/out/replicache/src/sync/request-id.js +31 -0
  186. package/out/replicache/src/sync/request-id.js.map +1 -0
  187. package/out/replicache/src/sync/sync-head-name.js +2 -0
  188. package/out/replicache/src/sync/sync-head-name.js.map +1 -0
  189. package/out/replicache/src/test-license-key.js +3 -0
  190. package/out/replicache/src/test-license-key.js.map +1 -0
  191. package/out/replicache/src/to-error.js +7 -0
  192. package/out/replicache/src/to-error.js.map +1 -0
  193. package/out/replicache/src/transaction-closed-error.js +17 -0
  194. package/out/replicache/src/transaction-closed-error.js.map +1 -0
  195. package/out/replicache/src/transactions.js +144 -0
  196. package/out/replicache/src/transactions.js.map +1 -0
  197. package/out/replicache/src/types.js +2 -0
  198. package/out/replicache/src/types.js.map +1 -0
  199. package/out/replicache/src/version.js +5 -0
  200. package/out/replicache/src/version.js.map +1 -0
  201. package/out/replicache/src/with-transactions.js +28 -0
  202. package/out/replicache/src/with-transactions.js.map +1 -0
  203. package/out/shared/src/browser-env.js +14 -0
  204. package/out/shared/src/browser-env.js.map +1 -0
  205. package/out/shared/src/document-visible.js +76 -0
  206. package/out/shared/src/document-visible.js.map +1 -0
  207. package/out/shared/src/immutable.js +2 -0
  208. package/out/shared/src/immutable.js.map +1 -0
  209. package/out/shared/src/iterables.d.ts +2 -2
  210. package/out/shared/src/iterables.d.ts.map +1 -1
  211. package/out/shared/src/iterables.js +40 -0
  212. package/out/shared/src/iterables.js.map +1 -0
  213. package/out/shared/src/navigator.js +3 -0
  214. package/out/shared/src/navigator.js.map +1 -0
  215. package/out/shared/src/random-uint64.js +8 -0
  216. package/out/shared/src/random-uint64.js.map +1 -0
  217. package/out/shared/src/random-values.d.ts +1 -0
  218. package/out/shared/src/random-values.d.ts.map +1 -1
  219. package/out/shared/src/random-values.js +22 -0
  220. package/out/shared/src/random-values.js.map +1 -0
  221. package/out/shared/src/set-utils.d.ts +1 -1
  222. package/out/shared/src/set-utils.d.ts.map +1 -1
  223. package/out/shared/src/set-utils.js +6 -4
  224. package/out/shared/src/set-utils.js.map +1 -1
  225. package/out/shared/src/sorted-entries.d.ts +2 -0
  226. package/out/shared/src/sorted-entries.d.ts.map +1 -0
  227. package/out/shared/src/sorted-entries.js +6 -0
  228. package/out/shared/src/sorted-entries.js.map +1 -0
  229. package/out/shared/src/types.js +2 -0
  230. package/out/shared/src/types.js.map +1 -0
  231. package/out/shared/src/valita.d.ts +1 -1
  232. package/out/shared/src/valita.d.ts.map +1 -1
  233. package/out/shared/src/valita.js.map +1 -1
  234. package/out/shared/src/writable.d.ts +4 -0
  235. package/out/shared/src/writable.d.ts.map +1 -0
  236. package/out/shared/src/writable.js +2 -0
  237. package/out/shared/src/writable.js.map +1 -0
  238. package/out/zero/src/config.d.ts +2 -0
  239. package/out/zero/src/config.d.ts.map +1 -0
  240. package/out/zero/src/config.js +2 -0
  241. package/out/zero/src/config.js.map +1 -0
  242. package/out/zero-cache/src/config/config-query.d.ts +18 -0
  243. package/out/zero-cache/src/config/config-query.d.ts.map +1 -0
  244. package/out/zero-cache/src/config/config-query.js +19 -0
  245. package/out/zero-cache/src/config/config-query.js.map +1 -0
  246. package/out/zero-cache/src/config/define-config.d.ts +43 -0
  247. package/out/zero-cache/src/config/define-config.d.ts.map +1 -0
  248. package/out/zero-cache/src/config/define-config.js +120 -0
  249. package/out/zero-cache/src/config/define-config.js.map +1 -0
  250. package/out/zero-cache/src/config/refs.d.ts +3 -0
  251. package/out/zero-cache/src/config/refs.d.ts.map +1 -0
  252. package/out/zero-cache/src/config/refs.js +14 -0
  253. package/out/zero-cache/src/config/refs.js.map +1 -0
  254. package/out/zero-cache/src/config/zero-config.d.ts +126 -686
  255. package/out/zero-cache/src/config/zero-config.d.ts.map +1 -1
  256. package/out/zero-cache/src/config/zero-config.js +43 -161
  257. package/out/zero-cache/src/config/zero-config.js.map +1 -1
  258. package/out/zero-cache/src/db/create.d.ts +8 -0
  259. package/out/zero-cache/src/db/create.d.ts.map +1 -0
  260. package/out/zero-cache/src/db/create.js +39 -0
  261. package/out/zero-cache/src/db/create.js.map +1 -0
  262. package/out/zero-cache/src/db/lite-tables.d.ts +3 -3
  263. package/out/zero-cache/src/db/lite-tables.d.ts.map +1 -1
  264. package/out/zero-cache/src/db/lite-tables.js +29 -20
  265. package/out/zero-cache/src/db/lite-tables.js.map +1 -1
  266. package/out/zero-cache/src/db/migration-lite.d.ts +60 -20
  267. package/out/zero-cache/src/db/migration-lite.d.ts.map +1 -1
  268. package/out/zero-cache/src/db/migration-lite.js +89 -69
  269. package/out/zero-cache/src/db/migration-lite.js.map +1 -1
  270. package/out/zero-cache/src/db/migration.d.ts +61 -20
  271. package/out/zero-cache/src/db/migration.d.ts.map +1 -1
  272. package/out/zero-cache/src/db/migration.js +92 -75
  273. package/out/zero-cache/src/db/migration.js.map +1 -1
  274. package/out/zero-cache/src/db/pg-to-lite.d.ts +11 -0
  275. package/out/zero-cache/src/db/pg-to-lite.d.ts.map +1 -0
  276. package/out/zero-cache/src/{services/change-streamer/pg/schema/lite.js → db/pg-to-lite.js} +27 -15
  277. package/out/zero-cache/src/db/pg-to-lite.js.map +1 -0
  278. package/out/zero-cache/src/db/specs.d.ts +73 -0
  279. package/out/zero-cache/src/db/specs.d.ts.map +1 -0
  280. package/out/zero-cache/src/db/specs.js +30 -0
  281. package/out/zero-cache/src/db/specs.js.map +1 -0
  282. package/out/zero-cache/src/db/statements.d.ts +1 -1
  283. package/out/zero-cache/src/db/statements.d.ts.map +1 -1
  284. package/out/zero-cache/src/server/life-cycle.d.ts.map +1 -1
  285. package/out/zero-cache/src/server/life-cycle.js +9 -5
  286. package/out/zero-cache/src/server/life-cycle.js.map +1 -1
  287. package/out/zero-cache/src/server/main.js +3 -3
  288. package/out/zero-cache/src/server/main.js.map +1 -1
  289. package/out/zero-cache/src/server/syncer.d.ts.map +1 -1
  290. package/out/zero-cache/src/server/syncer.js +2 -1
  291. package/out/zero-cache/src/server/syncer.js.map +1 -1
  292. package/out/zero-cache/src/services/change-streamer/change-streamer-http.d.ts +1 -1
  293. package/out/zero-cache/src/services/change-streamer/change-streamer-http.d.ts.map +1 -1
  294. package/out/zero-cache/src/services/change-streamer/change-streamer-http.js +1 -4
  295. package/out/zero-cache/src/services/change-streamer/change-streamer-http.js.map +1 -1
  296. package/out/zero-cache/src/services/change-streamer/change-streamer.d.ts +455 -13
  297. package/out/zero-cache/src/services/change-streamer/change-streamer.d.ts.map +1 -1
  298. package/out/zero-cache/src/services/change-streamer/change-streamer.js +16 -0
  299. package/out/zero-cache/src/services/change-streamer/change-streamer.js.map +1 -1
  300. package/out/zero-cache/src/services/change-streamer/pg/change-source.d.ts.map +1 -1
  301. package/out/zero-cache/src/services/change-streamer/pg/change-source.js +313 -88
  302. package/out/zero-cache/src/services/change-streamer/pg/change-source.js.map +1 -1
  303. package/out/zero-cache/src/services/change-streamer/pg/initial-sync.d.ts.map +1 -1
  304. package/out/zero-cache/src/services/change-streamer/pg/initial-sync.js +13 -54
  305. package/out/zero-cache/src/services/change-streamer/pg/initial-sync.js.map +1 -1
  306. package/out/zero-cache/src/services/change-streamer/pg/schema/ddl.d.ts +239 -59
  307. package/out/zero-cache/src/services/change-streamer/pg/schema/ddl.d.ts.map +1 -1
  308. package/out/zero-cache/src/services/change-streamer/pg/schema/ddl.js +291 -183
  309. package/out/zero-cache/src/services/change-streamer/pg/schema/ddl.js.map +1 -1
  310. package/out/zero-cache/src/services/change-streamer/pg/schema/init.d.ts +5 -0
  311. package/out/zero-cache/src/services/change-streamer/pg/schema/init.d.ts.map +1 -0
  312. package/out/zero-cache/src/services/change-streamer/pg/schema/init.js +18 -0
  313. package/out/zero-cache/src/services/change-streamer/pg/schema/init.js.map +1 -0
  314. package/out/zero-cache/src/services/change-streamer/pg/schema/published.d.ts +4 -4
  315. package/out/zero-cache/src/services/change-streamer/pg/schema/published.d.ts.map +1 -1
  316. package/out/zero-cache/src/services/change-streamer/pg/schema/published.js +14 -19
  317. package/out/zero-cache/src/services/change-streamer/pg/schema/published.js.map +1 -1
  318. package/out/zero-cache/src/services/change-streamer/pg/schema/shard.d.ts +17 -0
  319. package/out/zero-cache/src/services/change-streamer/pg/schema/shard.d.ts.map +1 -0
  320. package/out/zero-cache/src/services/change-streamer/pg/schema/shard.js +150 -0
  321. package/out/zero-cache/src/services/change-streamer/pg/schema/shard.js.map +1 -0
  322. package/out/zero-cache/src/services/change-streamer/pg/sync-schema.d.ts.map +1 -1
  323. package/out/zero-cache/src/services/change-streamer/pg/sync-schema.js +11 -5
  324. package/out/zero-cache/src/services/change-streamer/pg/sync-schema.js.map +1 -1
  325. package/out/zero-cache/src/services/change-streamer/schema/change.d.ts +325 -26
  326. package/out/zero-cache/src/services/change-streamer/schema/change.d.ts.map +1 -1
  327. package/out/zero-cache/src/services/change-streamer/schema/change.js +84 -1
  328. package/out/zero-cache/src/services/change-streamer/schema/change.js.map +1 -1
  329. package/out/zero-cache/src/services/change-streamer/schema/init.d.ts +2 -2
  330. package/out/zero-cache/src/services/change-streamer/schema/init.d.ts.map +1 -1
  331. package/out/zero-cache/src/services/change-streamer/schema/init.js +13 -5
  332. package/out/zero-cache/src/services/change-streamer/schema/init.js.map +1 -1
  333. package/out/zero-cache/src/services/change-streamer/schema/tables.js +6 -6
  334. package/out/zero-cache/src/services/change-streamer/storer.js +4 -4
  335. package/out/zero-cache/src/services/dispatcher/connect-params.d.ts +1 -0
  336. package/out/zero-cache/src/services/dispatcher/connect-params.d.ts.map +1 -1
  337. package/out/zero-cache/src/services/dispatcher/connect-params.js +5 -2
  338. package/out/zero-cache/src/services/dispatcher/connect-params.js.map +1 -1
  339. package/out/zero-cache/src/services/mutagen/mutagen.d.ts.map +1 -1
  340. package/out/zero-cache/src/services/mutagen/mutagen.js +21 -22
  341. package/out/zero-cache/src/services/mutagen/mutagen.js.map +1 -1
  342. package/out/zero-cache/src/services/mutagen/write-authorizer.d.ts.map +1 -1
  343. package/out/zero-cache/src/services/mutagen/write-authorizer.js +18 -9
  344. package/out/zero-cache/src/services/mutagen/write-authorizer.js.map +1 -1
  345. package/out/zero-cache/src/services/replicator/incremental-sync.d.ts.map +1 -1
  346. package/out/zero-cache/src/services/replicator/incremental-sync.js +131 -16
  347. package/out/zero-cache/src/services/replicator/incremental-sync.js.map +1 -1
  348. package/out/zero-cache/src/services/replicator/schema/change-log.d.ts +20 -3
  349. package/out/zero-cache/src/services/replicator/schema/change-log.d.ts.map +1 -1
  350. package/out/zero-cache/src/services/replicator/schema/change-log.js +46 -14
  351. package/out/zero-cache/src/services/replicator/schema/change-log.js.map +1 -1
  352. package/out/zero-cache/src/services/replicator/schema/replication-state.d.ts +1 -1
  353. package/out/zero-cache/src/services/replicator/schema/replication-state.d.ts.map +1 -1
  354. package/out/zero-cache/src/services/replicator/schema/replication-state.js +9 -9
  355. package/out/zero-cache/src/services/replicator/schema/replication-state.js.map +1 -1
  356. package/out/zero-cache/src/services/view-syncer/client-handler.d.ts +4 -3
  357. package/out/zero-cache/src/services/view-syncer/client-handler.d.ts.map +1 -1
  358. package/out/zero-cache/src/services/view-syncer/client-handler.js +27 -21
  359. package/out/zero-cache/src/services/view-syncer/client-handler.js.map +1 -1
  360. package/out/zero-cache/src/services/view-syncer/cvr-store.d.ts +6 -4
  361. package/out/zero-cache/src/services/view-syncer/cvr-store.d.ts.map +1 -1
  362. package/out/zero-cache/src/services/view-syncer/cvr-store.js +63 -18
  363. package/out/zero-cache/src/services/view-syncer/cvr-store.js.map +1 -1
  364. package/out/zero-cache/src/services/view-syncer/cvr.d.ts +11 -8
  365. package/out/zero-cache/src/services/view-syncer/cvr.d.ts.map +1 -1
  366. package/out/zero-cache/src/services/view-syncer/cvr.js +22 -13
  367. package/out/zero-cache/src/services/view-syncer/cvr.js.map +1 -1
  368. package/out/zero-cache/src/services/view-syncer/database-storage.js +1 -1
  369. package/out/zero-cache/src/services/view-syncer/database-storage.js.map +1 -1
  370. package/out/zero-cache/src/services/view-syncer/drain-coordinator.d.ts +31 -0
  371. package/out/zero-cache/src/services/view-syncer/drain-coordinator.d.ts.map +1 -0
  372. package/out/zero-cache/src/services/view-syncer/drain-coordinator.js +53 -0
  373. package/out/zero-cache/src/services/view-syncer/drain-coordinator.js.map +1 -0
  374. package/out/zero-cache/src/services/view-syncer/pipeline-driver.d.ts +13 -5
  375. package/out/zero-cache/src/services/view-syncer/pipeline-driver.d.ts.map +1 -1
  376. package/out/zero-cache/src/services/view-syncer/pipeline-driver.js +27 -0
  377. package/out/zero-cache/src/services/view-syncer/pipeline-driver.js.map +1 -1
  378. package/out/zero-cache/src/services/view-syncer/schema/cvr.d.ts +2 -1
  379. package/out/zero-cache/src/services/view-syncer/schema/cvr.d.ts.map +1 -1
  380. package/out/zero-cache/src/services/view-syncer/schema/cvr.js +5 -4
  381. package/out/zero-cache/src/services/view-syncer/schema/cvr.js.map +1 -1
  382. package/out/zero-cache/src/services/view-syncer/schema/init.d.ts +4 -0
  383. package/out/zero-cache/src/services/view-syncer/schema/init.d.ts.map +1 -0
  384. package/out/zero-cache/src/services/view-syncer/schema/init.js +16 -0
  385. package/out/zero-cache/src/services/view-syncer/schema/init.js.map +1 -0
  386. package/out/zero-cache/src/services/view-syncer/schema/types.d.ts +8 -216
  387. package/out/zero-cache/src/services/view-syncer/schema/types.d.ts.map +1 -1
  388. package/out/zero-cache/src/services/view-syncer/schema/types.js +2 -4
  389. package/out/zero-cache/src/services/view-syncer/schema/types.js.map +1 -1
  390. package/out/zero-cache/src/services/view-syncer/snapshotter.d.ts +12 -4
  391. package/out/zero-cache/src/services/view-syncer/snapshotter.d.ts.map +1 -1
  392. package/out/zero-cache/src/services/view-syncer/snapshotter.js +59 -49
  393. package/out/zero-cache/src/services/view-syncer/snapshotter.js.map +1 -1
  394. package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts +3 -4
  395. package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts.map +1 -1
  396. package/out/zero-cache/src/services/view-syncer/view-syncer.js +105 -44
  397. package/out/zero-cache/src/services/view-syncer/view-syncer.js.map +1 -1
  398. package/out/zero-cache/src/types/lite.d.ts.map +1 -1
  399. package/out/zero-cache/src/types/lite.js +8 -9
  400. package/out/zero-cache/src/types/lite.js.map +1 -1
  401. package/out/zero-cache/src/types/pg.d.ts +10 -4
  402. package/out/zero-cache/src/types/pg.d.ts.map +1 -1
  403. package/out/zero-cache/src/types/pg.js +37 -15
  404. package/out/zero-cache/src/types/pg.js.map +1 -1
  405. package/out/zero-cache/src/workers/connection.d.ts +4 -2
  406. package/out/zero-cache/src/workers/connection.d.ts.map +1 -1
  407. package/out/zero-cache/src/workers/connection.js +21 -2
  408. package/out/zero-cache/src/workers/connection.js.map +1 -1
  409. package/out/zero-cache/src/workers/syncer.d.ts +2 -1
  410. package/out/zero-cache/src/workers/syncer.d.ts.map +1 -1
  411. package/out/zero-cache/src/workers/syncer.js +20 -9
  412. package/out/zero-cache/src/workers/syncer.js.map +1 -1
  413. package/out/zero-client/src/client/context.d.ts +1 -1
  414. package/out/zero-client/src/client/context.d.ts.map +1 -1
  415. package/out/zero-client/src/client/context.js +99 -0
  416. package/out/zero-client/src/client/context.js.map +1 -0
  417. package/out/zero-client/src/client/crud.d.ts +8 -10
  418. package/out/zero-client/src/client/crud.d.ts.map +1 -1
  419. package/out/zero-client/src/client/crud.js +181 -0
  420. package/out/zero-client/src/client/crud.js.map +1 -0
  421. package/out/zero-client/src/client/enable-analytics.js +21 -0
  422. package/out/zero-client/src/client/enable-analytics.js.map +1 -0
  423. package/out/zero-client/src/client/http-string.js +14 -0
  424. package/out/zero-client/src/client/http-string.js.map +1 -0
  425. package/out/zero-client/src/client/keys.d.ts +3 -2
  426. package/out/zero-client/src/client/keys.d.ts.map +1 -1
  427. package/out/zero-client/src/client/keys.js +32 -0
  428. package/out/zero-client/src/client/keys.js.map +1 -0
  429. package/out/zero-client/src/client/log-options.js +57 -0
  430. package/out/zero-client/src/client/log-options.js.map +1 -0
  431. package/out/zero-client/src/client/metrics.js +268 -0
  432. package/out/zero-client/src/client/metrics.js.map +1 -0
  433. package/out/zero-client/src/client/normalized-schema.d.ts +17 -0
  434. package/out/zero-client/src/client/normalized-schema.d.ts.map +1 -0
  435. package/out/zero-client/src/client/normalized-schema.js +31 -0
  436. package/out/zero-client/src/client/normalized-schema.js.map +1 -0
  437. package/out/zero-client/src/client/options.js +2 -0
  438. package/out/zero-client/src/client/options.js.map +1 -0
  439. package/out/zero-client/src/client/query-manager.d.ts +18 -3
  440. package/out/zero-client/src/client/query-manager.d.ts.map +1 -1
  441. package/out/zero-client/src/client/query-manager.js +149 -0
  442. package/out/zero-client/src/client/query-manager.js.map +1 -0
  443. package/out/zero-client/src/client/reload-error-handler.js +23 -0
  444. package/out/zero-client/src/client/reload-error-handler.js.map +1 -0
  445. package/out/zero-client/src/client/replicache-types.js +2 -0
  446. package/out/zero-client/src/client/replicache-types.js.map +1 -0
  447. package/out/zero-client/src/client/server-error.js +22 -0
  448. package/out/zero-client/src/client/server-error.js.map +1 -0
  449. package/out/zero-client/src/client/server-option.js +37 -0
  450. package/out/zero-client/src/client/server-option.js.map +1 -0
  451. package/out/zero-client/src/client/version.js +5 -0
  452. package/out/zero-client/src/client/version.js.map +1 -0
  453. package/out/zero-client/src/client/zero-poke-handler.d.ts +3 -3
  454. package/out/zero-client/src/client/zero-poke-handler.d.ts.map +1 -1
  455. package/out/zero-client/src/client/zero-poke-handler.js +240 -0
  456. package/out/zero-client/src/client/zero-poke-handler.js.map +1 -0
  457. package/out/zero-client/src/client/zero.d.ts +3 -2
  458. package/out/zero-client/src/client/zero.d.ts.map +1 -1
  459. package/out/zero-client/src/client/zero.js +1212 -0
  460. package/out/zero-client/src/client/zero.js.map +1 -0
  461. package/out/zero-client/src/mod.d.ts +1 -0
  462. package/out/zero-client/src/mod.d.ts.map +1 -1
  463. package/out/zero-client/src/mod.js +5 -0
  464. package/out/zero-client/src/mod.js.map +1 -0
  465. package/out/zero-client/src/util/nanoid.js +34 -0
  466. package/out/zero-client/src/util/nanoid.js.map +1 -0
  467. package/out/zero-client/src/util/socket.js +4 -0
  468. package/out/zero-client/src/util/socket.js.map +1 -0
  469. package/out/zero-protocol/src/ast.d.ts +87 -1
  470. package/out/zero-protocol/src/ast.d.ts.map +1 -1
  471. package/out/zero-protocol/src/ast.js +53 -0
  472. package/out/zero-protocol/src/ast.js.map +1 -1
  473. package/out/zero-protocol/src/change-desired-queries.d.ts +6 -6
  474. package/out/zero-protocol/src/change-desired-queries.d.ts.map +1 -1
  475. package/out/zero-protocol/src/clients-patch.d.ts +1 -1
  476. package/out/zero-protocol/src/connect.d.ts +15 -8
  477. package/out/zero-protocol/src/connect.d.ts.map +1 -1
  478. package/out/zero-protocol/src/connect.js +21 -0
  479. package/out/zero-protocol/src/connect.js.map +1 -1
  480. package/out/zero-protocol/src/data.d.ts +36 -0
  481. package/out/zero-protocol/src/data.d.ts.map +1 -0
  482. package/out/zero-protocol/src/data.js +4 -0
  483. package/out/zero-protocol/src/data.js.map +1 -0
  484. package/out/zero-protocol/src/delete-clients.d.ts +4 -4
  485. package/out/zero-protocol/src/delete-clients.d.ts.map +1 -1
  486. package/out/zero-protocol/src/down.d.ts +18 -16
  487. package/out/zero-protocol/src/down.d.ts.map +1 -1
  488. package/out/zero-protocol/src/down.js +2 -1
  489. package/out/zero-protocol/src/down.js.map +1 -1
  490. package/out/zero-protocol/src/mod.d.ts +1 -2
  491. package/out/zero-protocol/src/mod.d.ts.map +1 -1
  492. package/out/zero-protocol/src/mod.js +2 -2
  493. package/out/zero-protocol/src/mod.js.map +1 -1
  494. package/out/zero-protocol/src/ping.d.ts +1 -1
  495. package/out/zero-protocol/src/ping.d.ts.map +1 -1
  496. package/out/zero-protocol/src/poke.d.ts +26 -26
  497. package/out/zero-protocol/src/poke.d.ts.map +1 -1
  498. package/out/zero-protocol/src/poke.js +8 -5
  499. package/out/zero-protocol/src/poke.js.map +1 -1
  500. package/out/zero-protocol/src/pong.d.ts +1 -1
  501. package/out/zero-protocol/src/pong.d.ts.map +1 -1
  502. package/out/zero-protocol/src/primary-key.d.ts +2 -3
  503. package/out/zero-protocol/src/primary-key.d.ts.map +1 -1
  504. package/out/zero-protocol/src/primary-key.js +1 -3
  505. package/out/zero-protocol/src/primary-key.js.map +1 -1
  506. package/out/zero-protocol/src/pull.d.ts +4 -4
  507. package/out/zero-protocol/src/pull.d.ts.map +1 -1
  508. package/out/zero-protocol/src/push.d.ts +105 -98
  509. package/out/zero-protocol/src/push.d.ts.map +1 -1
  510. package/out/zero-protocol/src/push.js +17 -13
  511. package/out/zero-protocol/src/push.js.map +1 -1
  512. package/out/zero-protocol/src/queries-patch.d.ts +4 -4
  513. package/out/zero-protocol/src/row-patch.d.ts +38 -0
  514. package/out/zero-protocol/src/row-patch.d.ts.map +1 -0
  515. package/out/zero-protocol/src/{entities-patch.js → row-patch.js} +10 -11
  516. package/out/zero-protocol/src/row-patch.js.map +1 -0
  517. package/out/zero-protocol/src/up.d.ts +28 -27
  518. package/out/zero-protocol/src/up.d.ts.map +1 -1
  519. package/out/zero-protocol/src/warm.d.ts +10 -0
  520. package/out/zero-protocol/src/warm.d.ts.map +1 -0
  521. package/out/zero-protocol/src/warm.js +6 -0
  522. package/out/zero-protocol/src/warm.js.map +1 -0
  523. package/out/zero-react/src/use-query.d.ts.map +1 -1
  524. package/out/zero.js +522 -217
  525. package/out/zero.js.map +4 -4
  526. package/out/zql/src/zql/builder/builder.d.ts +3 -4
  527. package/out/zql/src/zql/builder/builder.d.ts.map +1 -1
  528. package/out/zql/src/zql/builder/builder.js +1 -2
  529. package/out/zql/src/zql/builder/builder.js.map +1 -1
  530. package/out/zql/src/zql/builder/filter.d.ts +2 -2
  531. package/out/zql/src/zql/builder/filter.d.ts.map +1 -1
  532. package/out/zql/src/zql/builder/filter.js.map +1 -1
  533. package/out/zql/src/zql/ivm/array-view.d.ts +5 -12
  534. package/out/zql/src/zql/ivm/array-view.d.ts.map +1 -1
  535. package/out/zql/src/zql/ivm/array-view.js +226 -0
  536. package/out/zql/src/zql/ivm/array-view.js.map +1 -0
  537. package/out/zql/src/zql/ivm/change.d.ts +2 -1
  538. package/out/zql/src/zql/ivm/change.d.ts.map +1 -1
  539. package/out/zql/src/zql/ivm/data.d.ts +2 -33
  540. package/out/zql/src/zql/ivm/data.d.ts.map +1 -1
  541. package/out/zql/src/zql/ivm/data.js.map +1 -1
  542. package/out/zql/src/zql/ivm/filter.d.ts +2 -1
  543. package/out/zql/src/zql/ivm/filter.d.ts.map +1 -1
  544. package/out/zql/src/zql/ivm/filter.js.map +1 -1
  545. package/out/zql/src/zql/ivm/join.d.ts +1 -1
  546. package/out/zql/src/zql/ivm/join.d.ts.map +1 -1
  547. package/out/zql/src/zql/ivm/join.js +68 -24
  548. package/out/zql/src/zql/ivm/join.js.map +1 -1
  549. package/out/zql/src/zql/ivm/maybe-split-and-push-edit-change.d.ts +1 -1
  550. package/out/zql/src/zql/ivm/maybe-split-and-push-edit-change.d.ts.map +1 -1
  551. package/out/zql/src/zql/ivm/memory-source.d.ts +8 -6
  552. package/out/zql/src/zql/ivm/memory-source.d.ts.map +1 -1
  553. package/out/zql/src/zql/ivm/memory-source.js +2 -0
  554. package/out/zql/src/zql/ivm/memory-source.js.map +1 -1
  555. package/out/zql/src/zql/ivm/memory-storage.js +33 -0
  556. package/out/zql/src/zql/ivm/memory-storage.js.map +1 -0
  557. package/out/zql/src/zql/ivm/operator.d.ts +2 -1
  558. package/out/zql/src/zql/ivm/operator.d.ts.map +1 -1
  559. package/out/zql/src/zql/ivm/schema.d.ts +3 -3
  560. package/out/zql/src/zql/ivm/schema.d.ts.map +1 -1
  561. package/out/zql/src/zql/ivm/schema.js.map +1 -1
  562. package/out/zql/src/zql/ivm/skip.d.ts +2 -1
  563. package/out/zql/src/zql/ivm/skip.d.ts.map +1 -1
  564. package/out/zql/src/zql/ivm/skip.js.map +1 -1
  565. package/out/zql/src/zql/ivm/source.d.ts +2 -2
  566. package/out/zql/src/zql/ivm/source.d.ts.map +1 -1
  567. package/out/zql/src/zql/ivm/take.d.ts.map +1 -1
  568. package/out/zql/src/zql/ivm/take.js.map +1 -1
  569. package/out/zql/src/zql/query/like.d.ts +2 -0
  570. package/out/zql/src/zql/query/like.d.ts.map +1 -0
  571. package/out/zql/src/zql/query/like.js +18 -0
  572. package/out/zql/src/zql/query/like.js.map +1 -0
  573. package/out/zql/src/zql/query/normalize-table-schema.d.ts +48 -0
  574. package/out/zql/src/zql/query/normalize-table-schema.d.ts.map +1 -0
  575. package/out/zql/src/zql/query/normalize-table-schema.js +116 -0
  576. package/out/zql/src/zql/query/normalize-table-schema.js.map +1 -0
  577. package/out/zql/src/zql/query/query-impl.d.ts +6 -5
  578. package/out/zql/src/zql/query/query-impl.d.ts.map +1 -1
  579. package/out/zql/src/zql/query/query-impl.js +263 -0
  580. package/out/zql/src/zql/query/query-impl.js.map +1 -0
  581. package/out/zql/src/zql/query/query.d.ts +1 -1
  582. package/out/zql/src/zql/query/query.d.ts.map +1 -1
  583. package/out/zql/src/zql/query/query.js +3 -0
  584. package/out/zql/src/zql/query/query.js.map +1 -0
  585. package/out/zql/src/zql/query/schema.d.ts +13 -4
  586. package/out/zql/src/zql/query/schema.d.ts.map +1 -1
  587. package/out/zql/src/zql/query/schema.js +7 -0
  588. package/out/zql/src/zql/query/schema.js.map +1 -0
  589. package/out/zql/src/zql/query/typed-view.d.ts +5 -2
  590. package/out/zql/src/zql/query/typed-view.d.ts.map +1 -1
  591. package/out/zql/src/zql/query/typed-view.js +2 -0
  592. package/out/zql/src/zql/query/typed-view.js.map +1 -0
  593. package/out/zqlite/src/db.d.ts +1 -1
  594. package/out/zqlite/src/db.d.ts.map +1 -1
  595. package/out/zqlite/src/db.js +1 -1
  596. package/out/zqlite/src/db.js.map +1 -1
  597. package/out/zqlite/src/table-source.d.ts +2 -2
  598. package/out/zqlite/src/table-source.d.ts.map +1 -1
  599. package/out/zqlite/src/table-source.js.map +1 -1
  600. package/package.json +10 -8
  601. package/deps/sqlite3/sqlite3.c +0 -260574
  602. package/deps/sqlite3/sqlite3.h +0 -13572
  603. package/deps/sqlite3/sqlite3ext.h +0 -719
  604. package/out/zero-cache/src/services/change-streamer/pg/schema/create.d.ts +0 -6
  605. package/out/zero-cache/src/services/change-streamer/pg/schema/create.d.ts.map +0 -1
  606. package/out/zero-cache/src/services/change-streamer/pg/schema/create.js +0 -29
  607. package/out/zero-cache/src/services/change-streamer/pg/schema/create.js.map +0 -1
  608. package/out/zero-cache/src/services/change-streamer/pg/schema/lite.d.ts +0 -6
  609. package/out/zero-cache/src/services/change-streamer/pg/schema/lite.d.ts.map +0 -1
  610. package/out/zero-cache/src/services/change-streamer/pg/schema/lite.js.map +0 -1
  611. package/out/zero-cache/src/services/change-streamer/pg/schema/zero.d.ts +0 -11
  612. package/out/zero-cache/src/services/change-streamer/pg/schema/zero.d.ts.map +0 -1
  613. package/out/zero-cache/src/services/change-streamer/pg/schema/zero.js +0 -86
  614. package/out/zero-cache/src/services/change-streamer/pg/schema/zero.js.map +0 -1
  615. package/out/zero-cache/src/services/view-syncer/schema/pg-migrations.d.ts +0 -4
  616. package/out/zero-cache/src/services/view-syncer/schema/pg-migrations.d.ts.map +0 -1
  617. package/out/zero-cache/src/services/view-syncer/schema/pg-migrations.js +0 -12
  618. package/out/zero-cache/src/services/view-syncer/schema/pg-migrations.js.map +0 -1
  619. package/out/zero-cache/src/types/specs.d.ts +0 -29
  620. package/out/zero-cache/src/types/specs.d.ts.map +0 -1
  621. package/out/zero-cache/src/types/specs.js +0 -2
  622. package/out/zero-cache/src/types/specs.js.map +0 -1
  623. package/out/zero-client/src/client/make-id-from-primary-key.d.ts +0 -5
  624. package/out/zero-client/src/client/make-id-from-primary-key.d.ts.map +0 -1
  625. package/out/zero-protocol/src/entities-patch.d.ts +0 -66
  626. package/out/zero-protocol/src/entities-patch.d.ts.map +0 -1
  627. package/out/zero-protocol/src/entities-patch.js.map +0 -1
  628. package/out/zql/src/zql/ast/ast.d.ts +0 -84
  629. package/out/zql/src/zql/ast/ast.d.ts.map +0 -1
  630. package/out/zql/src/zql/ast/ast.js +0 -54
  631. package/out/zql/src/zql/ast/ast.js.map +0 -1
  632. package/tool/install-sqlite3.js +0 -37
package/out/zero.js CHANGED
@@ -9483,20 +9483,72 @@ var Join = class {
9483
9483
  case "child":
9484
9484
  this.#output.push(change);
9485
9485
  break;
9486
- case "edit":
9487
- if (normalizeUndefined(change.row[this.#parentKey]) === normalizeUndefined(change.oldRow[this.#parentKey])) {
9488
- this.#output.push(change);
9489
- } else {
9490
- this.#output.push({
9491
- type: "remove",
9492
- node: this.#processParentNode(change.oldRow, {}, "cleanup")
9486
+ case "edit": {
9487
+ this.#output.push({
9488
+ type: "edit",
9489
+ row: change.row,
9490
+ oldRow: change.oldRow
9491
+ });
9492
+ const oldKeyValue = normalizeUndefined(change.oldRow[this.#parentKey]);
9493
+ const newKeyValue = normalizeUndefined(change.row[this.#parentKey]);
9494
+ if (newKeyValue !== oldKeyValue) {
9495
+ const childrenToRemoveStream = this.#child.cleanup({
9496
+ constraint: {
9497
+ key: this.#childKey,
9498
+ value: oldKeyValue
9499
+ }
9493
9500
  });
9494
- this.#output.push({
9495
- type: "add",
9496
- node: this.#processParentNode(change.row, {}, "fetch")
9501
+ for (const childNode of childrenToRemoveStream) {
9502
+ this.#output.push({
9503
+ type: "child",
9504
+ // This is the new row since we already changed it in the edit above.
9505
+ row: change.row,
9506
+ child: {
9507
+ relationshipName: this.#relationshipName,
9508
+ change: {
9509
+ type: "remove",
9510
+ node: childNode
9511
+ }
9512
+ }
9513
+ });
9514
+ }
9515
+ const childrenToAddStream = this.#child.fetch({
9516
+ constraint: {
9517
+ key: this.#childKey,
9518
+ value: newKeyValue
9519
+ }
9497
9520
  });
9521
+ for (const childNode of childrenToAddStream) {
9522
+ this.#output.push({
9523
+ type: "child",
9524
+ row: change.row,
9525
+ child: {
9526
+ relationshipName: this.#relationshipName,
9527
+ change: {
9528
+ type: "add",
9529
+ node: childNode
9530
+ }
9531
+ }
9532
+ });
9533
+ }
9534
+ }
9535
+ const { primaryKey } = this.#parent.getSchema();
9536
+ const oldStorageKey = makeStorageKey(
9537
+ oldKeyValue,
9538
+ primaryKey,
9539
+ change.oldRow
9540
+ );
9541
+ const newStorageKey = makeStorageKey(
9542
+ newKeyValue,
9543
+ primaryKey,
9544
+ change.row
9545
+ );
9546
+ if (oldStorageKey !== newStorageKey) {
9547
+ this.#storage.del(oldStorageKey);
9548
+ this.#storage.set(newStorageKey, true);
9498
9549
  }
9499
9550
  break;
9551
+ }
9500
9552
  default:
9501
9553
  unreachable(change);
9502
9554
  }
@@ -9569,14 +9621,11 @@ var Join = class {
9569
9621
  }
9570
9622
  #processParentNode(parentNodeRow, parentNodeRelations, mode) {
9571
9623
  const parentKeyValue = normalizeUndefined(parentNodeRow[this.#parentKey]);
9572
- const parentPrimaryKey = [];
9573
- for (const key of this.#parent.getSchema().primaryKey) {
9574
- parentPrimaryKey.push(normalizeUndefined(parentNodeRow[key]));
9575
- }
9576
- const storageKey = createPrimaryKeySetStorageKey([
9624
+ const storageKey = makeStorageKey(
9577
9625
  parentKeyValue,
9578
- ...parentPrimaryKey
9579
- ]);
9626
+ this.#parent.getSchema().primaryKey,
9627
+ parentNodeRow
9628
+ );
9580
9629
  let method = mode;
9581
9630
  if (mode === "cleanup") {
9582
9631
  const [, second] = take(
@@ -9615,6 +9664,13 @@ function createPrimaryKeySetStorageKey(values) {
9615
9664
  function createPrimaryKeySetStorageKeyPrefix(value) {
9616
9665
  return createPrimaryKeySetStorageKey([value]);
9617
9666
  }
9667
+ function makeStorageKey(keyValue, primaryKey, row) {
9668
+ const parentPrimaryKey = [keyValue];
9669
+ for (const key of primaryKey) {
9670
+ parentPrimaryKey.push(normalizeUndefined(row[key]));
9671
+ }
9672
+ return createPrimaryKeySetStorageKey(parentPrimaryKey);
9673
+ }
9618
9674
 
9619
9675
  // ../zql/src/zql/ivm/skip.ts
9620
9676
  var Skip = class {
@@ -10155,6 +10211,10 @@ function getTakeStateKey(partitionValue) {
10155
10211
  return JSON.stringify(["take", normalizeUndefined(partitionValue)]);
10156
10212
  }
10157
10213
 
10214
+ // ../zql/src/zql/builder/error.ts
10215
+ var MissingParameterError = class extends Error {
10216
+ };
10217
+
10158
10218
  // ../zql/src/zql/builder/like.ts
10159
10219
  function getLikePredicate(pattern, flags) {
10160
10220
  const op = getLikeOp(String(pattern), flags);
@@ -10258,10 +10318,6 @@ function not(f) {
10258
10318
  return (lhs) => !f(lhs);
10259
10319
  }
10260
10320
 
10261
- // ../zql/src/zql/builder/error.ts
10262
- var MissingParameterError = class extends Error {
10263
- };
10264
-
10265
10321
  // ../zql/src/zql/builder/builder.ts
10266
10322
  function buildPipeline(ast, delegate, staticQueryParameters) {
10267
10323
  return buildPipelineInternal(
@@ -10374,7 +10430,6 @@ var ArrayView = class {
10374
10430
  // treat all changes, including the root change, generically.
10375
10431
  #root;
10376
10432
  onDestroy;
10377
- #hydrated = false;
10378
10433
  #dirty = false;
10379
10434
  constructor(input, format = { singular: false, relationships: {} }) {
10380
10435
  this.#input = input;
@@ -10383,6 +10438,7 @@ var ArrayView = class {
10383
10438
  this.#input.setOutput(this);
10384
10439
  this.#root = { "": format.singular ? void 0 : [] };
10385
10440
  assertOrderingIncludesPK(this.#schema.sort, this.#schema.primaryKey);
10441
+ this.#hydrate();
10386
10442
  }
10387
10443
  get data() {
10388
10444
  return this.#root[""];
@@ -10390,9 +10446,7 @@ var ArrayView = class {
10390
10446
  addListener(listener) {
10391
10447
  assert(!this.#listeners.has(listener), "Listener already registered");
10392
10448
  this.#listeners.add(listener);
10393
- if (this.#hydrated) {
10394
- listener(this.data);
10395
- }
10449
+ listener(this.data);
10396
10450
  return () => {
10397
10451
  this.#listeners.delete(listener);
10398
10452
  };
@@ -10406,11 +10460,7 @@ var ArrayView = class {
10406
10460
  this.#input.destroy();
10407
10461
  this.onDestroy?.();
10408
10462
  }
10409
- hydrate() {
10410
- if (this.#hydrated) {
10411
- throw new Error("Can't hydrate twice");
10412
- }
10413
- this.#hydrated = true;
10463
+ #hydrate() {
10414
10464
  this.#dirty = true;
10415
10465
  for (const node of this.#input.fetch({})) {
10416
10466
  applyChange(
@@ -10637,6 +10687,11 @@ function makeEntryPreserveRelationships(row, entry, relationships) {
10637
10687
  return result;
10638
10688
  }
10639
10689
 
10690
+ // ../shared/src/sorted-entries.ts
10691
+ function sortedEntries(object16) {
10692
+ return Object.entries(object16).sort((a, b) => stringCompare(a[0], b[0]));
10693
+ }
10694
+
10640
10695
  // ../zql/src/zql/query/schema.ts
10641
10696
  function isFieldRelationship(relationship) {
10642
10697
  return relationship.junction === void 0;
@@ -10645,9 +10700,151 @@ function isJunctionRelationship(relationship) {
10645
10700
  return !isFieldRelationship(relationship);
10646
10701
  }
10647
10702
 
10703
+ // ../zql/src/zql/query/normalize-table-schema.ts
10704
+ var NormalizedTableSchema = class {
10705
+ tableName;
10706
+ primaryKey;
10707
+ columns;
10708
+ relationships;
10709
+ constructor(tableSchema, tableSchemaCache) {
10710
+ this.tableName = tableSchema.tableName;
10711
+ const primaryKey = normalizePrimaryKey(tableSchema.primaryKey);
10712
+ this.primaryKey = primaryKey;
10713
+ this.columns = normalizeColumns(tableSchema.columns, primaryKey);
10714
+ tableSchemaCache.set(tableSchema, this);
10715
+ this.relationships = normalizeRelationships(
10716
+ tableSchema.relationships,
10717
+ tableSchemaCache
10718
+ );
10719
+ }
10720
+ };
10721
+ function normalizeTableSchema(tableSchema) {
10722
+ return normalizeTableSchemaWithCache(
10723
+ tableSchema,
10724
+ tableSchema.tableName,
10725
+ /* @__PURE__ */ new Map()
10726
+ );
10727
+ }
10728
+ function normalizeTableSchemaWithCache(tableSchema, expectedName, tableSchemaCache) {
10729
+ if (tableSchema instanceof NormalizedTableSchema) {
10730
+ return tableSchema;
10731
+ }
10732
+ assert(
10733
+ tableSchema.tableName === expectedName,
10734
+ `Table name mismatch: "${tableSchema.tableName}" !== "${expectedName}"`
10735
+ );
10736
+ let normalizedTableSchema = tableSchemaCache.get(tableSchema);
10737
+ if (normalizedTableSchema) {
10738
+ return normalizedTableSchema;
10739
+ }
10740
+ normalizedTableSchema = new NormalizedTableSchema(
10741
+ tableSchema,
10742
+ tableSchemaCache
10743
+ );
10744
+ return normalizedTableSchema;
10745
+ }
10746
+ function isSorted(arr) {
10747
+ for (let i = 1; i < arr.length; i++) {
10748
+ if (arr[i - 1] >= arr[i]) {
10749
+ return false;
10750
+ }
10751
+ }
10752
+ return true;
10753
+ }
10754
+ function assertNoDuplicates(arr) {
10755
+ for (let i = 1; i < arr.length; i++) {
10756
+ assert(arr[i - 1] !== arr[i], "Primary key must not contain duplicates");
10757
+ }
10758
+ }
10759
+ function normalizePrimaryKey(arr) {
10760
+ if (isSorted(arr)) {
10761
+ return arr;
10762
+ }
10763
+ arr = [...arr].sort();
10764
+ assertNoDuplicates(arr);
10765
+ return arr;
10766
+ }
10767
+ function normalizeColumns(columns, primaryKey) {
10768
+ const rv = {};
10769
+ for (const pk of primaryKey) {
10770
+ const schemaValue = columns[pk];
10771
+ assert(schemaValue, `Primary key column "${pk}" not found`);
10772
+ const { type, optional } = schemaValue;
10773
+ assert(!optional, `Primary key column "${pk}" cannot be optional`);
10774
+ assert(
10775
+ type === "string" || type === "number" || type === "boolean",
10776
+ `Primary key column "${pk}" must be a string, number, or boolean. Got ${type}`
10777
+ );
10778
+ }
10779
+ for (const [name, column] of sortedEntries(columns)) {
10780
+ rv[name] = normalizeSchemaValue(column);
10781
+ }
10782
+ return rv;
10783
+ }
10784
+ function normalizeSchemaValue(value) {
10785
+ return {
10786
+ type: value.type,
10787
+ optional: value.optional ?? false
10788
+ };
10789
+ }
10790
+ function normalizeRelationships(relationships, tableSchemaCache) {
10791
+ const rv = {};
10792
+ for (const [name, relationship] of sortedEntries(relationships)) {
10793
+ rv[name] = normalizeRelationship(relationship, tableSchemaCache);
10794
+ }
10795
+ return rv;
10796
+ }
10797
+ function normalizeRelationship(relationship, tableSchemaCache) {
10798
+ if (isFieldRelationship(relationship)) {
10799
+ return normalizeFieldRelationship(relationship, tableSchemaCache);
10800
+ }
10801
+ return normalizeJunctionRelationship(relationship, tableSchemaCache);
10802
+ }
10803
+ function normalizeFieldRelationship(relationship, tableSchemaCache) {
10804
+ return {
10805
+ source: relationship.source,
10806
+ dest: {
10807
+ field: relationship.dest.field,
10808
+ schema: normalizeLazyTableSchema(
10809
+ relationship.dest.schema,
10810
+ tableSchemaCache
10811
+ )
10812
+ }
10813
+ };
10814
+ }
10815
+ function normalizeJunctionRelationship(relationship, tableSchemaCache) {
10816
+ return {
10817
+ source: relationship.source,
10818
+ junction: {
10819
+ sourceField: relationship.junction.sourceField,
10820
+ destField: relationship.junction.destField,
10821
+ schema: normalizeLazyTableSchema(
10822
+ relationship.junction.schema,
10823
+ tableSchemaCache
10824
+ )
10825
+ },
10826
+ dest: {
10827
+ field: relationship.dest.field,
10828
+ schema: normalizeLazyTableSchema(
10829
+ relationship.dest.schema,
10830
+ tableSchemaCache
10831
+ )
10832
+ }
10833
+ };
10834
+ }
10835
+ function normalizeLazyTableSchema(tableSchema, buildCache) {
10836
+ const tableSchemaInstance = typeof tableSchema === "function" ? tableSchema() : tableSchema;
10837
+ return normalizeTableSchemaWithCache(
10838
+ tableSchemaInstance,
10839
+ tableSchemaInstance.tableName,
10840
+ // Don't care about name here.
10841
+ buildCache
10842
+ );
10843
+ }
10844
+
10648
10845
  // ../zql/src/zql/query/query-impl.ts
10649
10846
  function newQuery(delegate, tableSchema) {
10650
- return new QueryImpl(delegate, tableSchema);
10847
+ return new QueryImpl(delegate, normalizeTableSchema(tableSchema));
10651
10848
  }
10652
10849
  function newQueryWithDetails(delegate, schema, ast, format) {
10653
10850
  return new QueryImpl(delegate, schema, ast, format);
@@ -10688,7 +10885,7 @@ var AbstractQuery = class {
10688
10885
  const related1 = related;
10689
10886
  const related2 = related;
10690
10887
  if (isFieldRelationship(related1)) {
10691
- const destSchema = resolveSchema(related1.dest.schema);
10888
+ const destSchema = related1.dest.schema;
10692
10889
  const sq = cb(
10693
10890
  this._newQuery(
10694
10891
  destSchema,
@@ -10725,8 +10922,8 @@ var AbstractQuery = class {
10725
10922
  );
10726
10923
  }
10727
10924
  if (isJunctionRelationship(related2)) {
10728
- const destSchema = resolveSchema(related2.dest.schema);
10729
- const junctionSchema = resolveSchema(related2.junction.schema);
10925
+ const destSchema = related2.dest.schema;
10926
+ const junctionSchema = related2.junction.schema;
10730
10927
  const sq = cb(
10731
10928
  this._newQuery(
10732
10929
  destSchema,
@@ -10913,12 +11110,6 @@ var QueryImpl = class extends AbstractQuery {
10913
11110
  };
10914
11111
  }
10915
11112
  };
10916
- function resolveSchema(maybeSchema) {
10917
- if (typeof maybeSchema === "function") {
10918
- return maybeSchema();
10919
- }
10920
- return maybeSchema;
10921
- }
10922
11113
  function addPrimaryKeys(schema, orderBy) {
10923
11114
  orderBy = orderBy ?? [];
10924
11115
  const { primaryKey } = schema;
@@ -10941,11 +11132,31 @@ function addPrimaryKeysToAst(schema, ast) {
10941
11132
  };
10942
11133
  }
10943
11134
 
11135
+ // ../zql/src/zql/query/like.ts
11136
+ function like(strings, ...values) {
11137
+ strings.map(validateLiteral);
11138
+ let result = strings[0];
11139
+ for (let i = 0; i < values.length; i++) {
11140
+ result += escapeLike(String(values[i])) + strings[i + 1];
11141
+ }
11142
+ return result;
11143
+ }
11144
+ function validateLiteral(value) {
11145
+ const match = value.match(/[^%_]/);
11146
+ if (match) {
11147
+ throw new Error(`Invalid character '${match[0]}' in LIKE pattern`);
11148
+ }
11149
+ }
11150
+ function escapeLike(value) {
11151
+ return value.replace(/[%_]/g, "\\$&");
11152
+ }
11153
+
10944
11154
  // ../zero-client/src/client/zero.ts
10945
11155
  import { LogContext as LogContext3 } from "@rocicorp/logger";
10946
11156
  import { resolver as resolver8 } from "@rocicorp/resolver";
10947
11157
 
10948
11158
  // ../zero-protocol/src/ast.ts
11159
+ import { compareUTF8 as compareUTF84 } from "compare-utf8";
10949
11160
  var selectorSchema = valita_exports.string();
10950
11161
  var orderingElementSchema = readonly(
10951
11162
  valita_exports.tuple([selectorSchema, valita_exports.union(valita_exports.literal("asc"), valita_exports.literal("desc"))])
@@ -11020,6 +11231,57 @@ var astSchema = valita_exports.object({
11020
11231
  exclusive: valita_exports.boolean()
11021
11232
  }).optional()
11022
11233
  });
11234
+ function normalizeAST(ast) {
11235
+ return {
11236
+ schema: ast.schema,
11237
+ table: ast.table,
11238
+ alias: ast.alias,
11239
+ where: ast.where ? sortedWhere(ast.where) : void 0,
11240
+ related: ast.related ? sortedRelated(
11241
+ ast.related.map(
11242
+ (r) => ({
11243
+ correlation: {
11244
+ parentField: r.correlation.parentField,
11245
+ childField: r.correlation.childField,
11246
+ op: r.correlation.op
11247
+ },
11248
+ hidden: r.hidden,
11249
+ subquery: normalizeAST(r.subquery)
11250
+ })
11251
+ )
11252
+ ) : void 0,
11253
+ start: ast.start,
11254
+ limit: ast.limit,
11255
+ orderBy: ast.orderBy
11256
+ };
11257
+ }
11258
+ function sortedWhere(where) {
11259
+ return [...where].sort(cmpCondition);
11260
+ }
11261
+ function sortedRelated(related) {
11262
+ return related.sort(cmpRelated);
11263
+ }
11264
+ function cmpCondition(a, b) {
11265
+ return compareUTF8MaybeNull(a.field, b.field) || compareUTF8MaybeNull(a.op, b.op) || // Comparing the same field with the same op more than once doesn't make logical
11266
+ // sense, but is technically possible. Assume the values are of the same type and
11267
+ // sort by their String forms.
11268
+ compareUTF8MaybeNull(String(a.value), String(b.value));
11269
+ }
11270
+ function cmpRelated(a, b) {
11271
+ return compareUTF84(must(a.subquery.alias), must(b.subquery.alias));
11272
+ }
11273
+ function compareUTF8MaybeNull(a, b) {
11274
+ if (a !== null && b !== null) {
11275
+ return compareUTF84(a, b);
11276
+ }
11277
+ if (b !== null) {
11278
+ return -1;
11279
+ }
11280
+ if (a !== null) {
11281
+ return 1;
11282
+ }
11283
+ return 0;
11284
+ }
11023
11285
 
11024
11286
  // ../zero-protocol/src/queries-patch.ts
11025
11287
  var putOpSchema = valita_exports.object({
@@ -11077,6 +11339,13 @@ var initConnectionMessageSchema = valita_exports.tuple([
11077
11339
  valita_exports.literal("initConnection"),
11078
11340
  initConnectionBodySchema
11079
11341
  ]);
11342
+ function encodeSecProtocols(initConnectionMessage, authToken) {
11343
+ const protocols = [btoa(JSON.stringify(initConnectionMessage))];
11344
+ if (authToken !== void 0) {
11345
+ protocols.push(authToken);
11346
+ }
11347
+ return encodeURIComponent(protocols.join(","));
11348
+ }
11080
11349
 
11081
11350
  // ../zero-protocol/src/error.ts
11082
11351
  var errorKindSchema = valita_exports.union(
@@ -11101,12 +11370,20 @@ var errorMessageSchema = valita_exports.tuple([
11101
11370
  valita_exports.string()
11102
11371
  ]);
11103
11372
 
11104
- // ../zero-protocol/src/version.ts
11105
- var versionSchema = valita_exports.string();
11106
- var nullableVersionSchema = valita_exports.union(versionSchema, valita_exports.null());
11373
+ // ../zero-protocol/src/data.ts
11374
+ var valueSchema = valita_exports.union(
11375
+ valita_exports.null(),
11376
+ valita_exports.boolean(),
11377
+ valita_exports.number(),
11378
+ valita_exports.string(),
11379
+ valita_exports.undefined()
11380
+ );
11381
+ var rowSchema = valita_exports.record(valueSchema);
11107
11382
 
11108
11383
  // ../zero-protocol/src/primary-key.ts
11109
- var primaryKeySchema = valita_exports.array(valita_exports.string()).assert((arr) => arr.length > 0);
11384
+ var primaryKeySchema = readonly(
11385
+ valita_exports.tuple([valita_exports.string()]).concat(valita_exports.array(valita_exports.string()))
11386
+ );
11110
11387
  var primaryKeyValueSchema = valita_exports.union(
11111
11388
  valita_exports.string(),
11112
11389
  valita_exports.number(),
@@ -11116,35 +11393,38 @@ var primaryKeyValueRecordSchema = readonlyRecord(
11116
11393
  primaryKeyValueSchema
11117
11394
  );
11118
11395
 
11119
- // ../zero-protocol/src/entities-patch.ts
11396
+ // ../zero-protocol/src/row-patch.ts
11120
11397
  var putOpSchema3 = valita_exports.object({
11121
11398
  op: valita_exports.literal("put"),
11122
- entityType: valita_exports.string(),
11123
- entityID: primaryKeyValueRecordSchema,
11124
- value: jsonObjectSchema
11399
+ tableName: valita_exports.string(),
11400
+ value: rowSchema
11125
11401
  });
11126
11402
  var updateOpSchema = valita_exports.object({
11127
11403
  op: valita_exports.literal("update"),
11128
- entityType: valita_exports.string(),
11129
- entityID: primaryKeyValueRecordSchema,
11404
+ tableName: valita_exports.string(),
11405
+ id: primaryKeyValueRecordSchema,
11130
11406
  merge: jsonObjectSchema.optional(),
11131
11407
  constrain: valita_exports.array(valita_exports.string()).optional()
11132
11408
  });
11133
11409
  var delOpSchema3 = valita_exports.object({
11134
11410
  op: valita_exports.literal("del"),
11135
- entityType: valita_exports.string(),
11136
- entityID: primaryKeyValueRecordSchema
11411
+ tableName: valita_exports.string(),
11412
+ id: primaryKeyValueRecordSchema
11137
11413
  });
11138
11414
  var clearOpSchema3 = valita_exports.object({
11139
11415
  op: valita_exports.literal("clear")
11140
11416
  });
11141
- var entityPatchOpSchema = valita_exports.union(
11417
+ var rowPatchOpSchema = valita_exports.union(
11142
11418
  putOpSchema3,
11143
11419
  updateOpSchema,
11144
11420
  delOpSchema3,
11145
11421
  clearOpSchema3
11146
11422
  );
11147
- var entitiesPatchSchema = valita_exports.array(entityPatchOpSchema);
11423
+ var rowsPatchSchema = valita_exports.array(rowPatchOpSchema);
11424
+
11425
+ // ../zero-protocol/src/version.ts
11426
+ var versionSchema = valita_exports.string();
11427
+ var nullableVersionSchema = valita_exports.union(versionSchema, valita_exports.null());
11148
11428
 
11149
11429
  // ../zero-protocol/src/poke.ts
11150
11430
  var pokeStartBodySchema = valita_exports.object({
@@ -11170,13 +11450,16 @@ var pokePartBodySchema = valita_exports.object({
11170
11450
  // Patches to the desired query sets by client id.
11171
11451
  desiredQueriesPatches: valita_exports.record(queriesPatchSchema).optional(),
11172
11452
  // Patches to the set of queries for which entities are sync'd in
11173
- // entitiesPatch.
11453
+ // rowsPatch.
11174
11454
  gotQueriesPatch: queriesPatchSchema.optional(),
11175
- // Patches to the entities set.
11176
- entitiesPatch: entitiesPatchSchema.optional()
11455
+ // Patches to the rows set.
11456
+ rowsPatch: rowsPatchSchema.optional()
11177
11457
  });
11178
11458
  var pokeEndBodySchema = valita_exports.object({
11179
- pokeID: valita_exports.string()
11459
+ pokeID: valita_exports.string(),
11460
+ // If `true`, the poke with id `pokeID` should be discarded without
11461
+ // applying it.
11462
+ cancel: valita_exports.boolean().optional()
11180
11463
  });
11181
11464
  var pokeStartMessageSchema = valita_exports.tuple([
11182
11465
  valita_exports.literal("pokeStart"),
@@ -11218,9 +11501,16 @@ var pullResponseMessageSchema = valita_exports.tuple([
11218
11501
  pullResponseBodySchema
11219
11502
  ]);
11220
11503
 
11504
+ // ../zero-protocol/src/warm.ts
11505
+ var warmBodySchema = valita_exports.object({
11506
+ payload: valita_exports.string()
11507
+ });
11508
+ var warmMessageSchema = valita_exports.tuple([valita_exports.literal("warm"), warmBodySchema]);
11509
+
11221
11510
  // ../zero-protocol/src/down.ts
11222
11511
  var downstreamSchema = valita_exports.union(
11223
11512
  connectedMessageSchema,
11513
+ warmMessageSchema,
11224
11514
  errorMessageSchema,
11225
11515
  pongMessageSchema,
11226
11516
  pokeStartMessageSchema,
@@ -11237,26 +11527,29 @@ var pingMessageSchema = valita_exports.tuple([valita_exports.literal("ping"), pi
11237
11527
  var CRUD_MUTATION_NAME = "_zero_crud";
11238
11528
  var createOpSchema = valita_exports.object({
11239
11529
  op: valita_exports.literal("create"),
11240
- entityType: valita_exports.string(),
11241
- id: primaryKeyValueRecordSchema,
11242
- value: jsonObjectSchema
11530
+ tableName: valita_exports.string(),
11531
+ primaryKey: primaryKeySchema,
11532
+ value: rowSchema
11243
11533
  });
11244
11534
  var setOpSchema = valita_exports.object({
11245
11535
  op: valita_exports.literal("set"),
11246
- entityType: valita_exports.string(),
11247
- id: primaryKeyValueRecordSchema,
11248
- value: jsonObjectSchema
11536
+ tableName: valita_exports.string(),
11537
+ primaryKey: primaryKeySchema,
11538
+ value: rowSchema
11249
11539
  });
11250
11540
  var updateOpSchema2 = valita_exports.object({
11251
11541
  op: valita_exports.literal("update"),
11252
- entityType: valita_exports.string(),
11253
- id: primaryKeyValueRecordSchema,
11254
- partialValue: jsonObjectSchema
11542
+ tableName: valita_exports.string(),
11543
+ primaryKey: primaryKeySchema,
11544
+ // Partial value with at least the primary key fields
11545
+ value: rowSchema
11255
11546
  });
11256
11547
  var deleteOpSchema = valita_exports.object({
11257
11548
  op: valita_exports.literal("delete"),
11258
- entityType: valita_exports.string(),
11259
- id: primaryKeyValueRecordSchema
11549
+ tableName: valita_exports.string(),
11550
+ primaryKey: primaryKeySchema,
11551
+ // Partial value representing the primary key
11552
+ value: primaryKeyValueRecordSchema
11260
11553
  });
11261
11554
  var crudOpSchema = valita_exports.union(
11262
11555
  createOpSchema,
@@ -13478,21 +13771,12 @@ function desiredQueriesPrefixForClient(clientID) {
13478
13771
  function toGotQueriesKey(hash2) {
13479
13772
  return GOT_QUERIES_KEY_PREFIX + hash2;
13480
13773
  }
13481
- function maybeSort(arr) {
13482
- for (let i = 1; i < arr.length; i++) {
13483
- if (arr[i] < arr[i - 1]) {
13484
- return [...arr].sort();
13485
- }
13486
- }
13487
- return arr;
13488
- }
13489
- function toPrimaryKeyString(tableName, primaryKey, id) {
13774
+ function toPrimaryKeyString(tableName, primaryKey, value) {
13490
13775
  if (primaryKey.length === 1) {
13491
- return ENTITIES_KEY_PREFIX + tableName + "/" + id[primaryKey[0]];
13776
+ return ENTITIES_KEY_PREFIX + tableName + "/" + parse(value[primaryKey[0]], primaryKeyValueSchema);
13492
13777
  }
13493
- const sorted = maybeSort(primaryKey);
13494
- const arr = sorted.map((k) => id[k]);
13495
- const str = JSON.stringify(arr);
13778
+ const values = primaryKey.map((k) => parse(value[k], primaryKeyValueSchema));
13779
+ const str = JSON.stringify(values);
13496
13780
  const idSegment = h64WithReverse(str);
13497
13781
  return ENTITIES_KEY_PREFIX + tableName + "/" + idSegment;
13498
13782
  }
@@ -13583,15 +13867,6 @@ var ZeroContext = class {
13583
13867
  }
13584
13868
  };
13585
13869
 
13586
- // ../zero-client/src/client/make-id-from-primary-key.ts
13587
- function makeIDFromPrimaryKey(primaryKey, value) {
13588
- const id = {};
13589
- for (const key of primaryKey) {
13590
- id[key] = parse(value[key], primaryKeyValueSchema);
13591
- }
13592
- return id;
13593
- }
13594
-
13595
13870
  // ../zero-client/src/client/crud.ts
13596
13871
  function makeCRUDMutate(schema, repMutate) {
13597
13872
  const { [CRUD_MUTATION_NAME]: zeroCRUD } = repMutate;
@@ -13614,9 +13889,9 @@ function makeCRUDMutate(schema, repMutate) {
13614
13889
  inBatch = false;
13615
13890
  }
13616
13891
  };
13617
- const assertNotInBatch = (entityType, op) => {
13892
+ const assertNotInBatch = (tableName, op) => {
13618
13893
  if (inBatch) {
13619
- throw new Error(`Cannot call mutate.${entityType}.${op} inside a batch`);
13894
+ throw new Error(`Cannot call mutate.${tableName}.${op} inside a batch`);
13620
13895
  }
13621
13896
  };
13622
13897
  for (const [name, tableSchema] of Object.entries(schema.tables)) {
@@ -13629,44 +13904,45 @@ function makeCRUDMutate(schema, repMutate) {
13629
13904
  }
13630
13905
  return mutate;
13631
13906
  }
13632
- function makeEntityCRUDMutate(entityType, primaryKey, zeroCRUD, assertNotInBatch) {
13907
+ function makeEntityCRUDMutate(tableName, primaryKey, zeroCRUD, assertNotInBatch) {
13633
13908
  return {
13634
13909
  create: (value) => {
13635
- assertNotInBatch(entityType, "create");
13910
+ assertNotInBatch(tableName, "create");
13636
13911
  const op = {
13637
13912
  op: "create",
13638
- entityType,
13639
- id: makeIDFromPrimaryKey(primaryKey, value),
13913
+ tableName,
13914
+ primaryKey,
13640
13915
  value
13641
13916
  };
13642
13917
  return zeroCRUD({ ops: [op] });
13643
13918
  },
13644
13919
  set: (value) => {
13645
- assertNotInBatch(entityType, "set");
13920
+ assertNotInBatch(tableName, "set");
13646
13921
  const op = {
13647
13922
  op: "set",
13648
- entityType,
13649
- id: makeIDFromPrimaryKey(primaryKey, value),
13923
+ tableName,
13924
+ primaryKey,
13650
13925
  value
13651
13926
  };
13652
13927
  return zeroCRUD({ ops: [op] });
13653
13928
  },
13654
13929
  update: (value) => {
13655
- assertNotInBatch(entityType, "update");
13930
+ assertNotInBatch(tableName, "update");
13656
13931
  const op = {
13657
13932
  op: "update",
13658
- entityType,
13659
- id: makeIDFromPrimaryKey(primaryKey, value),
13660
- partialValue: value
13933
+ tableName,
13934
+ primaryKey,
13935
+ value
13661
13936
  };
13662
13937
  return zeroCRUD({ ops: [op] });
13663
13938
  },
13664
13939
  delete: (id) => {
13665
- assertNotInBatch(entityType, "delete");
13940
+ assertNotInBatch(tableName, "delete");
13666
13941
  const op = {
13667
13942
  op: "delete",
13668
- entityType,
13669
- id: makeIDFromPrimaryKey(primaryKey, id)
13943
+ tableName,
13944
+ primaryKey,
13945
+ value: id
13670
13946
  };
13671
13947
  return zeroCRUD({ ops: [op] });
13672
13948
  }
@@ -13678,8 +13954,8 @@ function makeBatchCRUDMutate(tableName, schema, ops) {
13678
13954
  create: (value) => {
13679
13955
  const op = {
13680
13956
  op: "create",
13681
- entityType: tableName,
13682
- id: makeIDFromPrimaryKey(primaryKey, value),
13957
+ tableName,
13958
+ primaryKey,
13683
13959
  value
13684
13960
  };
13685
13961
  ops.push(op);
@@ -13688,8 +13964,8 @@ function makeBatchCRUDMutate(tableName, schema, ops) {
13688
13964
  set: (value) => {
13689
13965
  const op = {
13690
13966
  op: "set",
13691
- entityType: tableName,
13692
- id: makeIDFromPrimaryKey(primaryKey, value),
13967
+ tableName,
13968
+ primaryKey,
13693
13969
  value
13694
13970
  };
13695
13971
  ops.push(op);
@@ -13698,9 +13974,9 @@ function makeBatchCRUDMutate(tableName, schema, ops) {
13698
13974
  update: (value) => {
13699
13975
  const op = {
13700
13976
  op: "update",
13701
- entityType: tableName,
13702
- id: makeIDFromPrimaryKey(primaryKey, value),
13703
- partialValue: value
13977
+ tableName,
13978
+ primaryKey,
13979
+ value
13704
13980
  };
13705
13981
  ops.push(op);
13706
13982
  return promiseVoid;
@@ -13708,8 +13984,9 @@ function makeBatchCRUDMutate(tableName, schema, ops) {
13708
13984
  delete: (id) => {
13709
13985
  const op = {
13710
13986
  op: "delete",
13711
- entityType: tableName,
13712
- id: makeIDFromPrimaryKey(primaryKey, id)
13987
+ tableName,
13988
+ primaryKey,
13989
+ value: id
13713
13990
  };
13714
13991
  ops.push(op);
13715
13992
  return promiseVoid;
@@ -13738,9 +14015,9 @@ function makeCRUDMutator(schema) {
13738
14015
  }
13739
14016
  async function createImpl(tx, arg, schema) {
13740
14017
  const key = toPrimaryKeyString(
13741
- arg.entityType,
13742
- schema.tables[arg.entityType].primaryKey,
13743
- arg.id
14018
+ arg.tableName,
14019
+ schema.tables[arg.tableName].primaryKey,
14020
+ arg.value
13744
14021
  );
13745
14022
  if (!await tx.has(key)) {
13746
14023
  await tx.set(key, arg.value);
@@ -13748,31 +14025,31 @@ async function createImpl(tx, arg, schema) {
13748
14025
  }
13749
14026
  async function setImpl(tx, arg, schema) {
13750
14027
  const key = toPrimaryKeyString(
13751
- arg.entityType,
13752
- schema.tables[arg.entityType].primaryKey,
13753
- arg.id
14028
+ arg.tableName,
14029
+ schema.tables[arg.tableName].primaryKey,
14030
+ arg.value
13754
14031
  );
13755
14032
  await tx.set(key, arg.value);
13756
14033
  }
13757
14034
  async function updateImpl(tx, arg, schema) {
13758
14035
  const key = toPrimaryKeyString(
13759
- arg.entityType,
13760
- schema.tables[arg.entityType].primaryKey,
13761
- arg.id
14036
+ arg.tableName,
14037
+ schema.tables[arg.tableName].primaryKey,
14038
+ arg.value
13762
14039
  );
13763
14040
  const prev = await tx.get(key);
13764
14041
  if (prev === void 0) {
13765
14042
  return;
13766
14043
  }
13767
- const update = arg.partialValue;
14044
+ const update = arg.value;
13768
14045
  const next = { ...prev, ...update };
13769
14046
  await tx.set(key, next);
13770
14047
  }
13771
14048
  async function deleteImpl(tx, arg, schema) {
13772
14049
  const key = toPrimaryKeyString(
13773
- arg.entityType,
13774
- schema.tables[arg.entityType].primaryKey,
13775
- arg.id
14050
+ arg.tableName,
14051
+ schema.tables[arg.tableName].primaryKey,
14052
+ arg.value
13776
14053
  );
13777
14054
  await tx.del(key);
13778
14055
  }
@@ -14308,58 +14585,28 @@ var State = class {
14308
14585
  }
14309
14586
  };
14310
14587
 
14311
- // ../zql/src/zql/ast/ast.ts
14312
- import { compareUTF8 as compareUTF84 } from "compare-utf8";
14313
- function normalizeAST(ast) {
14314
- return {
14315
- schema: ast.schema,
14316
- table: ast.table,
14317
- alias: ast.alias,
14318
- where: ast.where ? sortedWhere(ast.where) : void 0,
14319
- related: ast.related ? sortedRelated(
14320
- ast.related.map(
14321
- (r) => ({
14322
- correlation: {
14323
- parentField: r.correlation.parentField,
14324
- childField: r.correlation.childField,
14325
- op: r.correlation.op
14326
- },
14327
- hidden: r.hidden,
14328
- subquery: normalizeAST(r.subquery)
14329
- })
14330
- )
14331
- ) : void 0,
14332
- start: ast.start,
14333
- limit: ast.limit,
14334
- orderBy: ast.orderBy
14335
- };
14336
- }
14337
- function sortedWhere(where) {
14338
- return [...where].sort(cmpCondition);
14339
- }
14340
- function sortedRelated(related) {
14341
- return related.sort(cmpRelated);
14342
- }
14343
- function cmpCondition(a, b) {
14344
- return compareUTF8MaybeNull(a.field, b.field) || compareUTF8MaybeNull(a.op, b.op) || // Comparing the same field with the same op more than once doesn't make logical
14345
- // sense, but is technically possible. Assume the values are of the same type and
14346
- // sort by their String forms.
14347
- compareUTF8MaybeNull(String(a.value), String(b.value));
14348
- }
14349
- function cmpRelated(a, b) {
14350
- return compareUTF84(must(a.subquery.alias), must(b.subquery.alias));
14351
- }
14352
- function compareUTF8MaybeNull(a, b) {
14353
- if (a !== null && b !== null) {
14354
- return compareUTF84(a, b);
14588
+ // ../zero-client/src/client/normalized-schema.ts
14589
+ function normalizeSchema(schema) {
14590
+ if (schema instanceof NormalizedSchema) {
14591
+ return schema;
14355
14592
  }
14356
- if (b !== null) {
14357
- return -1;
14593
+ return new NormalizedSchema(schema);
14594
+ }
14595
+ var NormalizedSchema = class {
14596
+ version;
14597
+ tables;
14598
+ constructor(schema) {
14599
+ this.version = schema.version;
14600
+ this.tables = normalizeTables(schema.tables);
14358
14601
  }
14359
- if (a !== null) {
14360
- return 1;
14602
+ };
14603
+ function normalizeTables(tables) {
14604
+ const rv = {};
14605
+ const tableSchemaCache = /* @__PURE__ */ new Map();
14606
+ for (const [name, table] of sortedEntries(tables)) {
14607
+ rv[name] = normalizeTableSchemaWithCache(table, name, tableSchemaCache);
14361
14608
  }
14362
- return 0;
14609
+ return rv;
14363
14610
  }
14364
14611
 
14365
14612
  // ../zero-client/src/client/query-manager.ts
@@ -14399,21 +14646,49 @@ var QueryManager = class {
14399
14646
  gotCallback(got);
14400
14647
  }
14401
14648
  }
14402
- async getQueriesPatch(tx) {
14649
+ /**
14650
+ * Get the queries that need to be registered with the server.
14651
+ *
14652
+ * An optional `lastPatch` can be provided. This is the last patch that was
14653
+ * sent to the server and may not yet have been acked. If `lastPatch` is provided,
14654
+ * this method will return a patch that does not include any events sent in `lastPatch`.
14655
+ *
14656
+ * This diffing of last patch and current patch is needed since we send
14657
+ * a set of queries to the server when we first connect inside of the `sec-protocol` as
14658
+ * the `initConnectionMessage`.
14659
+ *
14660
+ * While we're waiting for the `connected` response to come back from the server,
14661
+ * the client may have registered more queries. We need to diff the `initConnectionMessage`
14662
+ * queries with the current set of queries to understand what those were.
14663
+ */
14664
+ async getQueriesPatch(tx, lastPatch) {
14403
14665
  const existingQueryHashes = /* @__PURE__ */ new Set();
14404
14666
  const prefix = desiredQueriesPrefixForClient(this.#clientID);
14405
14667
  for await (const key of tx.scan({ prefix }).keys()) {
14406
14668
  existingQueryHashes.add(key.substring(prefix.length, key.length));
14407
14669
  }
14408
- const patch = [];
14670
+ const patch = /* @__PURE__ */ new Map();
14409
14671
  for (const hash2 of existingQueryHashes) {
14410
14672
  if (!this.#queries.has(hash2)) {
14411
- patch.push({ op: "del", hash: hash2 });
14673
+ patch.set(hash2, { op: "del", hash: hash2 });
14412
14674
  }
14413
14675
  }
14414
14676
  for (const [hash2, { normalized }] of this.#queries) {
14415
14677
  if (!existingQueryHashes.has(hash2)) {
14416
- patch.push({ op: "put", hash: hash2, ast: normalized });
14678
+ patch.set(hash2, { op: "put", hash: hash2, ast: normalized });
14679
+ }
14680
+ }
14681
+ if (lastPatch) {
14682
+ for (const [hash2, { op }] of lastPatch) {
14683
+ if (op === "put" && !patch.has(hash2)) {
14684
+ patch.set(hash2, { op: "del", hash: hash2 });
14685
+ }
14686
+ }
14687
+ for (const [hash2, { op }] of patch) {
14688
+ const lastPatchOp = lastPatch.get(hash2);
14689
+ if (lastPatchOp && lastPatchOp.op === op) {
14690
+ patch.delete(hash2);
14691
+ }
14417
14692
  }
14418
14693
  }
14419
14694
  return patch;
@@ -14614,6 +14889,10 @@ var PokeHandler = class {
14614
14889
  );
14615
14890
  return;
14616
14891
  }
14892
+ if (pokeEnd.cancel) {
14893
+ this.#receivingPoke = void 0;
14894
+ return;
14895
+ }
14617
14896
  this.#pokeBuffer.push(this.#receivingPoke);
14618
14897
  this.#receivingPoke = void 0;
14619
14898
  if (!this.#pokePlaybackLoopRunning) {
@@ -14733,10 +15012,10 @@ function mergePokes(pokeBuffer, schema) {
14733
15012
  )
14734
15013
  );
14735
15014
  }
14736
- if (pokePart.entitiesPatch) {
15015
+ if (pokePart.rowsPatch) {
14737
15016
  mergedPatch.push(
14738
- ...pokePart.entitiesPatch.map(
14739
- (p) => entitiesPatchOpToReplicachePatchOp(p, schema)
15017
+ ...pokePart.rowsPatch.map(
15018
+ (p) => rowsPatchOpToReplicachePatchOp(p, schema)
14740
15019
  )
14741
15020
  );
14742
15021
  }
@@ -14787,7 +15066,7 @@ function queryPatchOpToReplicachePatchOp(op, toKey) {
14787
15066
  };
14788
15067
  }
14789
15068
  }
14790
- function entitiesPatchOpToReplicachePatchOp(op, schema) {
15069
+ function rowsPatchOpToReplicachePatchOp(op, schema) {
14791
15070
  switch (op.op) {
14792
15071
  case "clear":
14793
15072
  return op;
@@ -14795,18 +15074,18 @@ function entitiesPatchOpToReplicachePatchOp(op, schema) {
14795
15074
  return {
14796
15075
  op: "del",
14797
15076
  key: toPrimaryKeyString(
14798
- op.entityType,
14799
- schema.tables[op.entityType].primaryKey,
14800
- op.entityID
15077
+ op.tableName,
15078
+ schema.tables[op.tableName].primaryKey,
15079
+ op.id
14801
15080
  )
14802
15081
  };
14803
15082
  case "put":
14804
15083
  return {
14805
15084
  op: "put",
14806
15085
  key: toPrimaryKeyString(
14807
- op.entityType,
14808
- schema.tables[op.entityType].primaryKey,
14809
- op.entityID
15086
+ op.tableName,
15087
+ schema.tables[op.tableName].primaryKey,
15088
+ op.value
14810
15089
  ),
14811
15090
  value: op.value
14812
15091
  };
@@ -14814,9 +15093,9 @@ function entitiesPatchOpToReplicachePatchOp(op, schema) {
14814
15093
  return {
14815
15094
  op: "update",
14816
15095
  key: toPrimaryKeyString(
14817
- op.entityType,
14818
- schema.tables[op.entityType].primaryKey,
14819
- op.entityID
15096
+ op.tableName,
15097
+ schema.tables[op.tableName].primaryKey,
15098
+ op.id
14820
15099
  ),
14821
15100
  merge: op.merge,
14822
15101
  constrain: op.constrain
@@ -14880,6 +15159,13 @@ var Zero = class {
14880
15159
  #enableAnalytics;
14881
15160
  #pokeHandler;
14882
15161
  #queryManager;
15162
+ /**
15163
+ * The queries we sent when establishing a connection.
15164
+ * More queries could be registered while we're waiting for the 'connected' message
15165
+ * to come back from the server. To understand what queries we need to send
15166
+ * to the server, we diff the `initConnectionQueries` with the current set of desired queries.
15167
+ */
15168
+ #initConnectionQueries = /* @__PURE__ */ new Map();
14883
15169
  #lastMutationIDSent = NULL_LAST_MUTATION_ID_SENT;
14884
15170
  #onPong = () => void 0;
14885
15171
  #online = false;
@@ -15030,11 +15316,12 @@ var Zero = class {
15030
15316
  enableAnalytics: this.#enableAnalytics
15031
15317
  });
15032
15318
  const logOptions = this.#logOptions;
15319
+ const normalizedSchema = normalizeSchema(schema);
15033
15320
  const replicacheMutators = {
15034
- ["_zero_crud"]: makeCRUDMutator(schema)
15321
+ ["_zero_crud"]: makeCRUDMutator(normalizedSchema)
15035
15322
  };
15036
15323
  const replicacheOptions = {
15037
- schemaVersion: schema.version.toString(),
15324
+ schemaVersion: normalizedSchema.version.toString(),
15038
15325
  logLevel: logOptions.logLevel,
15039
15326
  logSinks: [logOptions.logSink],
15040
15327
  mutators: replicacheMutators,
@@ -15080,14 +15367,14 @@ var Zero = class {
15080
15367
  reason ?? ON_CLIENT_STATE_NOT_FOUND_REASON_CLIENT
15081
15368
  );
15082
15369
  };
15083
- this.mutate = makeCRUDMutate(schema, rep.mutate);
15370
+ this.mutate = makeCRUDMutate(normalizedSchema, rep.mutate);
15084
15371
  this.#queryManager = new QueryManager(
15085
15372
  rep.clientID,
15086
15373
  (msg) => this.#sendChangeDesiredQueries(msg),
15087
15374
  rep.experimentalWatch.bind(rep)
15088
15375
  );
15089
15376
  this.#zeroContext = new ZeroContext(
15090
- schema.tables,
15377
+ normalizedSchema.tables,
15091
15378
  (ast, gotCallback) => this.#queryManager.add(ast, gotCallback)
15092
15379
  );
15093
15380
  rep.experimentalWatch(
@@ -15097,7 +15384,7 @@ var Zero = class {
15097
15384
  initialValuesInFirstDiff: true
15098
15385
  }
15099
15386
  );
15100
- this.query = this.#registerQueries(schema);
15387
+ this.query = this.#registerQueries(normalizedSchema);
15101
15388
  reportReloadReason(this.#lc);
15102
15389
  this.#metrics = new MetricManager({
15103
15390
  reportIntervalMs: REPORT_INTERVAL_MS,
@@ -15111,7 +15398,7 @@ var Zero = class {
15111
15398
  (poke) => this.#rep.poke(poke),
15112
15399
  () => this.#onPokeError(),
15113
15400
  rep.clientID,
15114
- schema,
15401
+ normalizedSchema,
15115
15402
  this.#lc
15116
15403
  );
15117
15404
  this.#visibilityWatcher = getDocumentVisibilityWatcher(
@@ -15244,7 +15531,8 @@ var Zero = class {
15244
15531
  return;
15245
15532
  }
15246
15533
  this.#messageCount++;
15247
- switch (downMessage[0]) {
15534
+ const msgType = downMessage[0];
15535
+ switch (msgType) {
15248
15536
  case "connected":
15249
15537
  return this.#handleConnectedMessage(lc, downMessage);
15250
15538
  case "error":
@@ -15259,7 +15547,10 @@ var Zero = class {
15259
15547
  return this.#handlePokeEnd(lc, downMessage);
15260
15548
  case "pull":
15261
15549
  return this.#handlePullResponse(lc, downMessage);
15550
+ case "warm":
15551
+ break;
15262
15552
  default:
15553
+ msgType;
15263
15554
  rejectInvalidMessage();
15264
15555
  }
15265
15556
  };
@@ -15365,16 +15656,19 @@ var Zero = class {
15365
15656
  });
15366
15657
  this.#lastMutationIDSent = NULL_LAST_MUTATION_ID_SENT;
15367
15658
  lc.debug?.("Resolving connect resolver");
15659
+ assert(this.#socket);
15368
15660
  const queriesPatch = await this.#rep.query(
15369
- (tx) => this.#queryManager.getQueriesPatch(tx)
15661
+ (tx) => this.#queryManager.getQueriesPatch(tx, this.#initConnectionQueries)
15370
15662
  );
15371
- assert(this.#socket);
15372
- send(this.#socket, [
15373
- "initConnection",
15374
- {
15375
- desiredQueriesPatch: queriesPatch
15376
- }
15377
- ]);
15663
+ if (queriesPatch.size > 0) {
15664
+ send(this.#socket, [
15665
+ "changeDesiredQueries",
15666
+ {
15667
+ desiredQueriesPatch: [...queriesPatch.values()]
15668
+ }
15669
+ ]);
15670
+ }
15671
+ this.#initConnectionQueries = /* @__PURE__ */ new Map();
15378
15672
  this.#setConnectionState(2 /* Connected */);
15379
15673
  this.#connectResolver.resolve();
15380
15674
  }
@@ -15428,7 +15722,9 @@ var Zero = class {
15428
15722
  clearTimeout(timeoutID);
15429
15723
  };
15430
15724
  this.#closeAbortController.signal.addEventListener("abort", abortHandler);
15431
- const ws = createSocket(
15725
+ const [ws, initConnectionQueries] = await createSocket(
15726
+ this.#rep,
15727
+ this.#queryManager,
15432
15728
  toWSString(this.#server),
15433
15729
  this.#connectCookie,
15434
15730
  this.clientID,
@@ -15445,6 +15741,7 @@ var Zero = class {
15445
15741
  if (this.closed) {
15446
15742
  return;
15447
15743
  }
15744
+ this.#initConnectionQueries = initConnectionQueries;
15448
15745
  ws.addEventListener("message", this.#onMessage);
15449
15746
  ws.addEventListener("open", this.#onOpen);
15450
15747
  ws.addEventListener("close", this.#onClose);
@@ -15908,7 +16205,7 @@ var Zero = class {
15908
16205
  return rv;
15909
16206
  }
15910
16207
  };
15911
- function createSocket(socketOrigin, baseCookie, clientID, clientGroupID, schemaVersion, userID, auth, jurisdiction, lmid, wsid, debugPerf, lc) {
16208
+ async function createSocket(rep, queryManager, socketOrigin, baseCookie, clientID, clientGroupID, schemaVersion, userID, auth, jurisdiction, lmid, wsid, debugPerf, lc) {
15912
16209
  const url = new URL(socketOrigin);
15913
16210
  url.pathname = `/api/sync/v${REFLECT_VERSION}/connect`;
15914
16211
  const { searchParams } = url;
@@ -15928,11 +16225,18 @@ function createSocket(socketOrigin, baseCookie, clientID, clientGroupID, schemaV
15928
16225
  }
15929
16226
  lc.info?.("Connecting to", url.toString());
15930
16227
  const WS = mustGetBrowserGlobal("WebSocket");
15931
- return new WS(
15932
- // toString() required for RN URL polyfill.
15933
- url.toString(),
15934
- auth === "" || auth === void 0 ? void 0 : encodeURIComponent(auth)
15935
- );
16228
+ const queriesPatch = await rep.query((tx) => queryManager.getQueriesPatch(tx));
16229
+ return [
16230
+ new WS(
16231
+ // toString() required for RN URL polyfill.
16232
+ url.toString(),
16233
+ encodeSecProtocols(
16234
+ ["initConnection", { desiredQueriesPatch: [...queriesPatch.values()] }],
16235
+ auth
16236
+ )
16237
+ ),
16238
+ queriesPatch
16239
+ ];
15936
16240
  }
15937
16241
  function addWebSocketIDFromSocketToLogContext({ url }, lc) {
15938
16242
  const wsid = new URL(url).searchParams.get("wsid") ?? nanoid();
@@ -15959,6 +16263,7 @@ export {
15959
16263
  dropAllDatabases,
15960
16264
  dropDatabase,
15961
16265
  getDefaultPuller,
16266
+ like,
15962
16267
  makeIDBName
15963
16268
  };
15964
16269
  //# sourceMappingURL=zero.js.map