@rocicorp/zero 0.25.0 → 0.26.0-canary.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1588) hide show
  1. package/out/analyze-query/src/bin-analyze.js +268 -257
  2. package/out/analyze-query/src/bin-analyze.js.map +1 -1
  3. package/out/analyze-query/src/bin-transform.js +31 -23
  4. package/out/analyze-query/src/bin-transform.js.map +1 -1
  5. package/out/analyze-query/src/explain-queries.js +13 -16
  6. package/out/analyze-query/src/explain-queries.js.map +1 -1
  7. package/out/analyze-query/src/run-ast.d.ts +3 -2
  8. package/out/analyze-query/src/run-ast.d.ts.map +1 -1
  9. package/out/analyze-query/src/run-ast.js +82 -74
  10. package/out/analyze-query/src/run-ast.js.map +1 -1
  11. package/out/ast-to-zql/src/ast-to-zql.js +146 -180
  12. package/out/ast-to-zql/src/ast-to-zql.js.map +1 -1
  13. package/out/ast-to-zql/src/bin.js +51 -54
  14. package/out/ast-to-zql/src/bin.js.map +1 -1
  15. package/out/ast-to-zql/src/format.js +15 -14
  16. package/out/ast-to-zql/src/format.js.map +1 -1
  17. package/out/datadog/src/datadog-log-sink.js +223 -0
  18. package/out/datadog/src/datadog-log-sink.js.map +1 -0
  19. package/out/otel/src/enabled.js +15 -15
  20. package/out/otel/src/enabled.js.map +1 -1
  21. package/out/otel/src/log-options.d.ts +1 -1
  22. package/out/otel/src/log-options.d.ts.map +1 -1
  23. package/out/otel/src/log-options.js +35 -31
  24. package/out/otel/src/log-options.js.map +1 -1
  25. package/out/otel/src/maybe-time.js +14 -11
  26. package/out/otel/src/maybe-time.js.map +1 -1
  27. package/out/otel/src/span.js +30 -27
  28. package/out/otel/src/span.js.map +1 -1
  29. package/out/otel/src/test-log-config.js +10 -7
  30. package/out/otel/src/test-log-config.js.map +1 -1
  31. package/out/otel/src/version.js +5 -2
  32. package/out/otel/src/version.js.map +1 -1
  33. package/out/replicache/src/async-iterable-to-array.js +11 -0
  34. package/out/replicache/src/async-iterable-to-array.js.map +1 -0
  35. package/out/replicache/src/bg-interval.js +38 -0
  36. package/out/replicache/src/bg-interval.js.map +1 -0
  37. package/out/replicache/src/btree/diff.js +8 -0
  38. package/out/replicache/src/btree/diff.js.map +1 -0
  39. package/out/replicache/src/btree/node.js +400 -0
  40. package/out/replicache/src/btree/node.js.map +1 -0
  41. package/out/replicache/src/btree/read.d.ts +3 -2
  42. package/out/replicache/src/btree/read.d.ts.map +1 -1
  43. package/out/replicache/src/btree/read.js +266 -0
  44. package/out/replicache/src/btree/read.js.map +1 -0
  45. package/out/replicache/src/btree/splice.js +83 -0
  46. package/out/replicache/src/btree/splice.js.map +1 -0
  47. package/out/replicache/src/btree/write.d.ts +1 -1
  48. package/out/replicache/src/btree/write.d.ts.map +1 -1
  49. package/out/replicache/src/btree/write.js +163 -0
  50. package/out/replicache/src/btree/write.js.map +1 -0
  51. package/out/replicache/src/call-default-fetch.js +34 -0
  52. package/out/replicache/src/call-default-fetch.js.map +1 -0
  53. package/out/replicache/src/connection-loop-delegates.js +34 -0
  54. package/out/replicache/src/connection-loop-delegates.js.map +1 -0
  55. package/out/replicache/src/connection-loop.js +251 -0
  56. package/out/replicache/src/connection-loop.js.map +1 -0
  57. package/out/replicache/src/cookies.js +40 -0
  58. package/out/replicache/src/cookies.js.map +1 -0
  59. package/out/replicache/src/dag/chunk.js +59 -0
  60. package/out/replicache/src/dag/chunk.js.map +1 -0
  61. package/out/replicache/src/dag/gc.js +117 -0
  62. package/out/replicache/src/dag/gc.js.map +1 -0
  63. package/out/replicache/src/dag/key.js +20 -0
  64. package/out/replicache/src/dag/key.js.map +1 -0
  65. package/out/replicache/src/dag/lazy-store.d.ts +2 -1
  66. package/out/replicache/src/dag/lazy-store.d.ts.map +1 -1
  67. package/out/replicache/src/dag/lazy-store.js +515 -0
  68. package/out/replicache/src/dag/lazy-store.js.map +1 -0
  69. package/out/replicache/src/dag/store-impl.js +183 -0
  70. package/out/replicache/src/dag/store-impl.js.map +1 -0
  71. package/out/replicache/src/dag/store.js +27 -0
  72. package/out/replicache/src/dag/store.js.map +1 -0
  73. package/out/replicache/src/dag/visitor.js +22 -0
  74. package/out/replicache/src/dag/visitor.js.map +1 -0
  75. package/out/replicache/src/db/commit.js +358 -0
  76. package/out/replicache/src/db/commit.js.map +1 -0
  77. package/out/replicache/src/db/index-operation-enum.js +7 -0
  78. package/out/replicache/src/db/index-operation-enum.js.map +1 -0
  79. package/out/replicache/src/db/index.js +134 -0
  80. package/out/replicache/src/db/index.js.map +1 -0
  81. package/out/replicache/src/db/meta-type-enum.js +7 -0
  82. package/out/replicache/src/db/meta-type-enum.js.map +1 -0
  83. package/out/replicache/src/db/read.d.ts +3 -2
  84. package/out/replicache/src/db/read.d.ts.map +1 -1
  85. package/out/replicache/src/db/read.js +72 -0
  86. package/out/replicache/src/db/read.js.map +1 -0
  87. package/out/replicache/src/db/rebase.d.ts +2 -2
  88. package/out/replicache/src/db/rebase.d.ts.map +1 -1
  89. package/out/replicache/src/db/rebase.js +85 -0
  90. package/out/replicache/src/db/rebase.js.map +1 -0
  91. package/out/replicache/src/db/write.d.ts +2 -1
  92. package/out/replicache/src/db/write.d.ts.map +1 -1
  93. package/out/replicache/src/db/write.js +296 -0
  94. package/out/replicache/src/db/write.js.map +1 -0
  95. package/out/replicache/src/deleted-clients.js +104 -0
  96. package/out/replicache/src/deleted-clients.js.map +1 -0
  97. package/out/replicache/src/error-responses.js +34 -0
  98. package/out/replicache/src/error-responses.js.map +1 -0
  99. package/out/replicache/src/format-version-enum.js +11 -0
  100. package/out/replicache/src/format-version-enum.js.map +1 -0
  101. package/out/{chunk-EZM3XBAB.js → replicache/src/frozen-json.js} +8 -75
  102. package/out/replicache/src/frozen-json.js.map +1 -0
  103. package/out/replicache/src/get-default-puller.js +61 -0
  104. package/out/replicache/src/get-default-puller.js.map +1 -0
  105. package/out/replicache/src/get-default-pusher.js +39 -0
  106. package/out/replicache/src/get-default-pusher.js.map +1 -0
  107. package/out/replicache/src/get-kv-store-provider.js +23 -0
  108. package/out/replicache/src/get-kv-store-provider.js.map +1 -0
  109. package/out/replicache/src/hash.js +38 -0
  110. package/out/replicache/src/hash.js.map +1 -0
  111. package/out/replicache/src/http-request-info.js +10 -0
  112. package/out/replicache/src/http-request-info.js.map +1 -0
  113. package/out/replicache/src/http-status-unauthorized.js +5 -0
  114. package/out/replicache/src/http-status-unauthorized.js.map +1 -0
  115. package/out/replicache/src/index-defs.js +32 -0
  116. package/out/replicache/src/index-defs.js.map +1 -0
  117. package/out/replicache/src/invoke-kind-enum.js +7 -0
  118. package/out/replicache/src/invoke-kind-enum.js.map +1 -0
  119. package/out/{chunk-ZZXMKAAG.js → replicache/src/kv/expo-sqlite/store.js} +8 -16
  120. package/out/replicache/src/kv/expo-sqlite/store.js.map +1 -0
  121. package/out/replicache/src/kv/idb-store-with-mem-fallback.js +80 -0
  122. package/out/replicache/src/kv/idb-store-with-mem-fallback.js.map +1 -0
  123. package/out/replicache/src/kv/idb-store.js +183 -0
  124. package/out/replicache/src/kv/idb-store.js.map +1 -0
  125. package/out/replicache/src/kv/mem-store.js +51 -0
  126. package/out/replicache/src/kv/mem-store.js.map +1 -0
  127. package/out/{op-sqlite.js → replicache/src/kv/op-sqlite/store.js} +7 -18
  128. package/out/replicache/src/kv/op-sqlite/store.js.map +1 -0
  129. package/out/replicache/src/kv/op-sqlite/types.js +6 -0
  130. package/out/replicache/src/kv/op-sqlite/types.js.map +1 -0
  131. package/out/replicache/src/kv/read-impl.js +27 -0
  132. package/out/replicache/src/kv/read-impl.js.map +1 -0
  133. package/out/replicache/src/kv/sqlite-store.d.ts.map +1 -1
  134. package/out/{chunk-ECUMGQGC.js → replicache/src/kv/sqlite-store.js} +27 -21
  135. package/out/replicache/src/kv/sqlite-store.js.map +1 -0
  136. package/out/{chunk-ASRS2LFV.js → replicache/src/kv/throw-if-closed.js} +4 -6
  137. package/out/replicache/src/kv/throw-if-closed.js.map +1 -0
  138. package/out/replicache/src/kv/write-impl-base.js +57 -0
  139. package/out/replicache/src/kv/write-impl-base.js.map +1 -0
  140. package/out/replicache/src/kv/write-impl.js +30 -0
  141. package/out/replicache/src/kv/write-impl.js.map +1 -0
  142. package/out/replicache/src/lazy.js +13 -0
  143. package/out/replicache/src/lazy.js.map +1 -0
  144. package/out/replicache/src/log-options.js +9 -0
  145. package/out/replicache/src/log-options.js.map +1 -0
  146. package/out/replicache/src/make-idb-name.js +13 -0
  147. package/out/replicache/src/make-idb-name.js.map +1 -0
  148. package/out/replicache/src/new-client-channel.js +51 -0
  149. package/out/replicache/src/new-client-channel.js.map +1 -0
  150. package/out/replicache/src/on-persist-channel.js +36 -0
  151. package/out/replicache/src/on-persist-channel.js.map +1 -0
  152. package/out/replicache/src/patch-operation.js +42 -0
  153. package/out/replicache/src/patch-operation.js.map +1 -0
  154. package/out/replicache/src/pending-mutations.js +16 -0
  155. package/out/replicache/src/pending-mutations.js.map +1 -0
  156. package/out/replicache/src/persist/client-gc.js +58 -0
  157. package/out/replicache/src/persist/client-gc.js.map +1 -0
  158. package/out/replicache/src/persist/client-group-gc.js +43 -0
  159. package/out/replicache/src/persist/client-group-gc.js.map +1 -0
  160. package/out/replicache/src/persist/client-groups.js +184 -0
  161. package/out/replicache/src/persist/client-groups.js.map +1 -0
  162. package/out/replicache/src/persist/clients.d.ts +3 -2
  163. package/out/replicache/src/persist/clients.d.ts.map +1 -1
  164. package/out/replicache/src/persist/clients.js +353 -0
  165. package/out/replicache/src/persist/clients.js.map +1 -0
  166. package/out/replicache/src/persist/collect-idb-databases.js +188 -0
  167. package/out/replicache/src/persist/collect-idb-databases.js.map +1 -0
  168. package/out/replicache/src/persist/gather-mem-only-visitor.js +27 -0
  169. package/out/replicache/src/persist/gather-mem-only-visitor.js.map +1 -0
  170. package/out/replicache/src/persist/gather-not-cached-visitor.js +37 -0
  171. package/out/replicache/src/persist/gather-not-cached-visitor.js.map +1 -0
  172. package/out/replicache/src/persist/heartbeat.js +48 -0
  173. package/out/replicache/src/persist/heartbeat.js.map +1 -0
  174. package/out/replicache/src/persist/idb-databases-store-db-name.js +14 -0
  175. package/out/replicache/src/persist/idb-databases-store-db-name.js.map +1 -0
  176. package/out/replicache/src/persist/idb-databases-store.d.ts +1 -0
  177. package/out/replicache/src/persist/idb-databases-store.d.ts.map +1 -1
  178. package/out/replicache/src/persist/idb-databases-store.js +103 -0
  179. package/out/replicache/src/persist/idb-databases-store.js.map +1 -0
  180. package/out/replicache/src/persist/make-client-id.js +12 -0
  181. package/out/replicache/src/persist/make-client-id.js.map +1 -0
  182. package/out/replicache/src/persist/persist.d.ts +2 -2
  183. package/out/replicache/src/persist/persist.d.ts.map +1 -1
  184. package/out/replicache/src/persist/persist.js +183 -0
  185. package/out/replicache/src/persist/persist.js.map +1 -0
  186. package/out/replicache/src/persist/refresh.d.ts +4 -3
  187. package/out/replicache/src/persist/refresh.d.ts.map +1 -1
  188. package/out/replicache/src/persist/refresh.js +198 -0
  189. package/out/replicache/src/persist/refresh.js.map +1 -0
  190. package/out/replicache/src/process-scheduler.js +96 -0
  191. package/out/replicache/src/process-scheduler.js.map +1 -0
  192. package/out/replicache/src/pusher.js +33 -0
  193. package/out/replicache/src/pusher.js.map +1 -0
  194. package/out/replicache/src/replicache-impl.d.ts +1 -1
  195. package/out/replicache/src/replicache-impl.d.ts.map +1 -1
  196. package/out/replicache/src/replicache-impl.js +1200 -0
  197. package/out/replicache/src/replicache-impl.js.map +1 -0
  198. package/out/replicache/src/replicache-options.d.ts +3 -2
  199. package/out/replicache/src/replicache-options.d.ts.map +1 -1
  200. package/out/replicache/src/report-error.js +6 -0
  201. package/out/replicache/src/report-error.js.map +1 -0
  202. package/out/replicache/src/request-idle.js +13 -0
  203. package/out/replicache/src/request-idle.js.map +1 -0
  204. package/out/replicache/src/scan-iterator.js +146 -0
  205. package/out/replicache/src/scan-iterator.js.map +1 -0
  206. package/out/replicache/src/scan-options.js +45 -0
  207. package/out/replicache/src/scan-options.js.map +1 -0
  208. package/out/replicache/src/set-interval-with-signal.js +12 -0
  209. package/out/replicache/src/set-interval-with-signal.js.map +1 -0
  210. package/out/replicache/src/subscriptions.js +355 -0
  211. package/out/replicache/src/subscriptions.js.map +1 -0
  212. package/out/replicache/src/sync/diff.d.ts +3 -2
  213. package/out/replicache/src/sync/diff.d.ts.map +1 -1
  214. package/out/replicache/src/sync/diff.js +72 -0
  215. package/out/replicache/src/sync/diff.js.map +1 -0
  216. package/out/replicache/src/sync/handle-pull-response-result-type-enum.js +9 -0
  217. package/out/replicache/src/sync/handle-pull-response-result-type-enum.js.map +1 -0
  218. package/out/replicache/src/sync/ids.js +9 -0
  219. package/out/replicache/src/sync/ids.js.map +1 -0
  220. package/out/replicache/src/sync/patch.js +49 -0
  221. package/out/replicache/src/sync/patch.js.map +1 -0
  222. package/out/replicache/src/sync/pull-error.js +16 -0
  223. package/out/replicache/src/sync/pull-error.js.map +1 -0
  224. package/out/replicache/src/sync/pull.d.ts +3 -2
  225. package/out/replicache/src/sync/pull.d.ts.map +1 -1
  226. package/out/replicache/src/sync/pull.js +301 -0
  227. package/out/replicache/src/sync/pull.js.map +1 -0
  228. package/out/replicache/src/sync/push.js +88 -0
  229. package/out/replicache/src/sync/push.js.map +1 -0
  230. package/out/replicache/src/sync/request-id.js +20 -0
  231. package/out/replicache/src/sync/request-id.js.map +1 -0
  232. package/out/replicache/src/sync/sync-head-name.js +5 -0
  233. package/out/replicache/src/sync/sync-head-name.js.map +1 -0
  234. package/out/replicache/src/to-error.js +10 -0
  235. package/out/replicache/src/to-error.js.map +1 -0
  236. package/out/replicache/src/transaction-closed-error.js +19 -0
  237. package/out/replicache/src/transaction-closed-error.js.map +1 -0
  238. package/out/replicache/src/transactions.js +152 -0
  239. package/out/replicache/src/transactions.js.map +1 -0
  240. package/out/replicache/src/version.js +5 -0
  241. package/out/replicache/src/version.js.map +1 -0
  242. package/out/replicache/src/with-transactions.js +28 -0
  243. package/out/replicache/src/with-transactions.js.map +1 -0
  244. package/out/shared/src/abort-error.js +6 -3
  245. package/out/shared/src/abort-error.js.map +1 -1
  246. package/out/shared/src/arrays.js +45 -43
  247. package/out/shared/src/arrays.js.map +1 -1
  248. package/out/shared/src/asserts.js +64 -68
  249. package/out/shared/src/asserts.js.map +1 -1
  250. package/out/shared/src/bigint-json.js +38 -42
  251. package/out/shared/src/bigint-json.js.map +1 -1
  252. package/out/shared/src/binary-search.js +18 -29
  253. package/out/shared/src/binary-search.js.map +1 -1
  254. package/out/shared/src/broadcast-channel.js +24 -0
  255. package/out/shared/src/broadcast-channel.js.map +1 -0
  256. package/out/shared/src/browser-env.js +25 -0
  257. package/out/shared/src/browser-env.js.map +1 -0
  258. package/out/shared/src/btree-set.js +464 -507
  259. package/out/shared/src/btree-set.js.map +1 -1
  260. package/out/shared/src/cache.js +34 -38
  261. package/out/shared/src/cache.js.map +1 -1
  262. package/out/shared/src/centroid.js +24 -24
  263. package/out/shared/src/centroid.js.map +1 -1
  264. package/out/shared/src/config.js +6 -3
  265. package/out/shared/src/config.js.map +1 -1
  266. package/out/shared/src/custom-key-map.js +58 -64
  267. package/out/shared/src/custom-key-map.js.map +1 -1
  268. package/out/shared/src/custom-key-set.js +51 -57
  269. package/out/shared/src/custom-key-set.js.map +1 -1
  270. package/out/shared/src/deep-clone.js +46 -0
  271. package/out/shared/src/deep-clone.js.map +1 -0
  272. package/out/shared/src/deep-merge.d.ts +26 -4
  273. package/out/shared/src/deep-merge.d.ts.map +1 -1
  274. package/out/shared/src/deep-merge.js +28 -0
  275. package/out/shared/src/deep-merge.js.map +1 -0
  276. package/out/shared/src/document-visible.js +74 -0
  277. package/out/shared/src/document-visible.js.map +1 -0
  278. package/out/shared/src/dotenv.js +5 -7
  279. package/out/shared/src/dotenv.js.map +1 -1
  280. package/out/shared/src/error.js +57 -56
  281. package/out/shared/src/error.js.map +1 -1
  282. package/out/shared/src/has-own.js +5 -3
  283. package/out/shared/src/has-own.js.map +1 -1
  284. package/out/shared/src/hash.js +15 -14
  285. package/out/shared/src/hash.js.map +1 -1
  286. package/out/shared/src/iterables.d.ts +0 -1
  287. package/out/shared/src/iterables.d.ts.map +1 -1
  288. package/out/shared/src/iterables.js +44 -80
  289. package/out/shared/src/iterables.js.map +1 -1
  290. package/out/shared/src/json-schema.js +30 -33
  291. package/out/shared/src/json-schema.js.map +1 -1
  292. package/out/shared/src/json.js +128 -143
  293. package/out/shared/src/json.js.map +1 -1
  294. package/out/shared/src/logging-test-utils.js +12 -19
  295. package/out/shared/src/logging-test-utils.js.map +1 -1
  296. package/out/shared/src/logging.d.ts.map +1 -1
  297. package/out/shared/src/logging.js +99 -83
  298. package/out/shared/src/logging.js.map +1 -1
  299. package/out/shared/src/must.js +9 -7
  300. package/out/shared/src/must.js.map +1 -1
  301. package/out/shared/src/navigator.js +5 -0
  302. package/out/shared/src/navigator.js.map +1 -0
  303. package/out/shared/src/object-traversal.d.ts +19 -0
  304. package/out/shared/src/object-traversal.d.ts.map +1 -0
  305. package/out/shared/src/object-traversal.js +27 -0
  306. package/out/shared/src/object-traversal.js.map +1 -0
  307. package/out/shared/src/objects.js +21 -22
  308. package/out/shared/src/objects.js.map +1 -1
  309. package/out/shared/src/options-types.d.ts +113 -0
  310. package/out/shared/src/options-types.d.ts.map +1 -0
  311. package/out/shared/src/options.d.ts +4 -111
  312. package/out/shared/src/options.d.ts.map +1 -1
  313. package/out/shared/src/options.js +289 -318
  314. package/out/shared/src/options.js.map +1 -1
  315. package/out/shared/src/parse-big-int.js +12 -10
  316. package/out/shared/src/parse-big-int.js.map +1 -1
  317. package/out/shared/src/promise-race.js +20 -0
  318. package/out/shared/src/promise-race.js.map +1 -0
  319. package/out/shared/src/queue.js +119 -122
  320. package/out/shared/src/queue.js.map +1 -1
  321. package/out/shared/src/rand.js +8 -10
  322. package/out/shared/src/rand.js.map +1 -1
  323. package/out/shared/src/random-uint64.js +9 -0
  324. package/out/shared/src/random-uint64.js.map +1 -0
  325. package/out/shared/src/random-values.js +13 -0
  326. package/out/shared/src/random-values.js.map +1 -0
  327. package/out/shared/src/record-proxy.d.ts +13 -0
  328. package/out/shared/src/record-proxy.d.ts.map +1 -0
  329. package/out/shared/src/record-proxy.js +59 -0
  330. package/out/shared/src/record-proxy.js.map +1 -0
  331. package/out/shared/src/resolved-promises.js +12 -9
  332. package/out/shared/src/resolved-promises.js.map +1 -1
  333. package/out/shared/src/sentinels.js +13 -6
  334. package/out/shared/src/sentinels.js.map +1 -1
  335. package/out/shared/src/set-utils.js +63 -62
  336. package/out/shared/src/set-utils.js.map +1 -1
  337. package/out/shared/src/size-of-value.js +58 -0
  338. package/out/shared/src/size-of-value.js.map +1 -0
  339. package/out/shared/src/sleep.js +45 -53
  340. package/out/shared/src/sleep.js.map +1 -1
  341. package/out/shared/src/string-compare.js +12 -9
  342. package/out/shared/src/string-compare.js.map +1 -1
  343. package/out/shared/src/subscribable.js +34 -0
  344. package/out/shared/src/subscribable.js.map +1 -0
  345. package/out/shared/src/tdigest-schema.js +7 -7
  346. package/out/shared/src/tdigest-schema.js.map +1 -1
  347. package/out/shared/src/tdigest.js +247 -271
  348. package/out/shared/src/tdigest.js.map +1 -1
  349. package/out/shared/src/valita.js +195 -207
  350. package/out/shared/src/valita.js.map +1 -1
  351. package/out/z2s/src/compiler.d.ts +2 -2
  352. package/out/z2s/src/compiler.d.ts.map +1 -1
  353. package/out/z2s/src/compiler.js +439 -310
  354. package/out/z2s/src/compiler.js.map +1 -1
  355. package/out/z2s/src/sql.d.ts +1 -1
  356. package/out/z2s/src/sql.d.ts.map +1 -1
  357. package/out/z2s/src/sql.js +186 -218
  358. package/out/z2s/src/sql.js.map +1 -1
  359. package/out/zero/package.json.js +9 -0
  360. package/out/zero/package.json.js.map +1 -0
  361. package/out/zero/src/adapters/drizzle.d.ts +1 -1
  362. package/out/zero/src/adapters/drizzle.d.ts.map +1 -1
  363. package/out/zero/src/adapters/drizzle.js +8 -2
  364. package/out/zero/src/adapters/drizzle.js.map +1 -1
  365. package/out/zero/src/adapters/pg.js +7 -2
  366. package/out/zero/src/adapters/pg.js.map +1 -1
  367. package/out/zero/src/adapters/postgresjs.js +7 -2
  368. package/out/zero/src/adapters/postgresjs.js.map +1 -1
  369. package/out/zero/src/analyze-query.js +1 -1
  370. package/out/zero/src/analyze-query.js.map +1 -1
  371. package/out/zero/src/ast-to-zql.js +1 -1
  372. package/out/zero/src/ast-to-zql.js.map +1 -1
  373. package/out/zero/src/bindings.d.ts +2 -0
  374. package/out/zero/src/bindings.d.ts.map +1 -0
  375. package/out/zero/src/bindings.js +27 -0
  376. package/out/zero/src/bindings.js.map +1 -0
  377. package/out/zero/src/build-schema.js +3 -5
  378. package/out/zero/src/build-schema.js.map +1 -1
  379. package/out/zero/src/change-protocol/v0.js +5 -3
  380. package/out/zero/src/change-protocol/v0.js.map +1 -1
  381. package/out/zero/src/cli.js +2 -2
  382. package/out/zero/src/cli.js.map +1 -1
  383. package/out/zero/src/deploy-permissions.js +1 -1
  384. package/out/zero/src/deploy-permissions.js.map +1 -1
  385. package/out/zero/src/expo-sqlite.js +5 -0
  386. package/out/zero/src/expo-sqlite.js.map +1 -0
  387. package/out/zero/src/op-sqlite.js +5 -0
  388. package/out/zero/src/op-sqlite.js.map +1 -0
  389. package/out/zero/src/pg.js +31 -3
  390. package/out/zero/src/pg.js.map +1 -1
  391. package/out/zero/src/react-native.js +13 -0
  392. package/out/zero/src/react-native.js.map +1 -0
  393. package/out/zero/src/react.js +15 -0
  394. package/out/zero/src/react.js.map +1 -0
  395. package/out/zero/src/server.js +27 -3
  396. package/out/zero/src/server.js.map +1 -1
  397. package/out/zero/src/solid.js +15 -0
  398. package/out/zero/src/solid.js.map +1 -0
  399. package/out/zero/src/sqlite.js +7 -0
  400. package/out/zero/src/sqlite.js.map +1 -0
  401. package/out/zero/src/transform-query.js +1 -1
  402. package/out/zero/src/transform-query.js.map +1 -1
  403. package/out/zero/src/zero-cache-dev.js +138 -104
  404. package/out/zero/src/zero-cache-dev.js.map +1 -1
  405. package/out/zero/src/zero-out.js +6 -6
  406. package/out/zero/src/zero-out.js.map +1 -1
  407. package/out/zero/src/zero.js +71 -0
  408. package/out/zero/src/zero.js.map +1 -0
  409. package/out/zero/src/zqlite.js +11 -3
  410. package/out/zero/src/zqlite.js.map +1 -1
  411. package/out/zero-cache/src/auth/jwt.d.ts +3 -0
  412. package/out/zero-cache/src/auth/jwt.d.ts.map +1 -1
  413. package/out/zero-cache/src/auth/jwt.js +33 -38
  414. package/out/zero-cache/src/auth/jwt.js.map +1 -1
  415. package/out/zero-cache/src/auth/load-permissions.d.ts +1 -1
  416. package/out/zero-cache/src/auth/load-permissions.d.ts.map +1 -1
  417. package/out/zero-cache/src/auth/load-permissions.js +61 -45
  418. package/out/zero-cache/src/auth/load-permissions.js.map +1 -1
  419. package/out/zero-cache/src/auth/read-authorizer.d.ts +1 -1
  420. package/out/zero-cache/src/auth/read-authorizer.d.ts.map +1 -1
  421. package/out/zero-cache/src/auth/read-authorizer.js +79 -91
  422. package/out/zero-cache/src/auth/read-authorizer.js.map +1 -1
  423. package/out/zero-cache/src/auth/write-authorizer.d.ts +4 -3
  424. package/out/zero-cache/src/auth/write-authorizer.d.ts.map +1 -1
  425. package/out/zero-cache/src/auth/write-authorizer.js +395 -328
  426. package/out/zero-cache/src/auth/write-authorizer.js.map +1 -1
  427. package/out/zero-cache/src/config/network.js +42 -45
  428. package/out/zero-cache/src/config/network.js.map +1 -1
  429. package/out/zero-cache/src/config/normalize.js +86 -83
  430. package/out/zero-cache/src/config/normalize.js.map +1 -1
  431. package/out/zero-cache/src/config/zero-config.d.ts +63 -0
  432. package/out/zero-cache/src/config/zero-config.d.ts.map +1 -1
  433. package/out/zero-cache/src/config/zero-config.js +743 -682
  434. package/out/zero-cache/src/config/zero-config.js.map +1 -1
  435. package/out/zero-cache/src/custom/fetch.d.ts +5 -5
  436. package/out/zero-cache/src/custom/fetch.d.ts.map +1 -1
  437. package/out/zero-cache/src/custom/fetch.js +170 -162
  438. package/out/zero-cache/src/custom/fetch.js.map +1 -1
  439. package/out/zero-cache/src/custom-queries/transform-query.d.ts +10 -3
  440. package/out/zero-cache/src/custom-queries/transform-query.d.ts.map +1 -1
  441. package/out/zero-cache/src/custom-queries/transform-query.js +101 -109
  442. package/out/zero-cache/src/custom-queries/transform-query.js.map +1 -1
  443. package/out/zero-cache/src/db/create.js +32 -36
  444. package/out/zero-cache/src/db/create.js.map +1 -1
  445. package/out/zero-cache/src/db/delete-lite-db.js +9 -6
  446. package/out/zero-cache/src/db/delete-lite-db.js.map +1 -1
  447. package/out/zero-cache/src/db/lite-tables.d.ts.map +1 -1
  448. package/out/zero-cache/src/db/lite-tables.js +150 -174
  449. package/out/zero-cache/src/db/lite-tables.js.map +1 -1
  450. package/out/zero-cache/src/db/migration-lite.js +170 -165
  451. package/out/zero-cache/src/db/migration-lite.js.map +1 -1
  452. package/out/zero-cache/src/db/migration.js +157 -137
  453. package/out/zero-cache/src/db/migration.js.map +1 -1
  454. package/out/zero-cache/src/db/mode-enum.d.ts +2 -0
  455. package/out/zero-cache/src/db/mode-enum.d.ts.map +1 -1
  456. package/out/zero-cache/src/db/mode-enum.js +9 -3
  457. package/out/zero-cache/src/db/mode-enum.js.map +1 -1
  458. package/out/zero-cache/src/db/pg-copy.js +51 -90
  459. package/out/zero-cache/src/db/pg-copy.js.map +1 -1
  460. package/out/zero-cache/src/db/pg-to-lite.d.ts +10 -0
  461. package/out/zero-cache/src/db/pg-to-lite.d.ts.map +1 -1
  462. package/out/zero-cache/src/db/pg-to-lite.js +116 -97
  463. package/out/zero-cache/src/db/pg-to-lite.js.map +1 -1
  464. package/out/zero-cache/src/db/pg-type-parser.js +27 -39
  465. package/out/zero-cache/src/db/pg-type-parser.js.map +1 -1
  466. package/out/zero-cache/src/db/postgres-replica-identity-enum.js +11 -6
  467. package/out/zero-cache/src/db/postgres-replica-identity-enum.js.map +1 -1
  468. package/out/zero-cache/src/db/postgres-type-class-enum.js +17 -9
  469. package/out/zero-cache/src/db/postgres-type-class-enum.js.map +1 -1
  470. package/out/zero-cache/src/db/specs.d.ts +1 -7
  471. package/out/zero-cache/src/db/specs.d.ts.map +1 -1
  472. package/out/zero-cache/src/db/specs.js +66 -40
  473. package/out/zero-cache/src/db/specs.js.map +1 -1
  474. package/out/zero-cache/src/db/statements.d.ts +1 -1
  475. package/out/zero-cache/src/db/statements.d.ts.map +1 -1
  476. package/out/zero-cache/src/db/statements.js +59 -52
  477. package/out/zero-cache/src/db/statements.js.map +1 -1
  478. package/out/zero-cache/src/db/transaction-pool.d.ts +1 -1
  479. package/out/zero-cache/src/db/transaction-pool.d.ts.map +1 -1
  480. package/out/zero-cache/src/db/transaction-pool.js +372 -501
  481. package/out/zero-cache/src/db/transaction-pool.js.map +1 -1
  482. package/out/zero-cache/src/db/warmup.js +25 -12
  483. package/out/zero-cache/src/db/warmup.js.map +1 -1
  484. package/out/zero-cache/src/observability/events.js +71 -82
  485. package/out/zero-cache/src/observability/events.js.map +1 -1
  486. package/out/zero-cache/src/observability/metrics.js +54 -32
  487. package/out/zero-cache/src/observability/metrics.js.map +1 -1
  488. package/out/zero-cache/src/scripts/decommission.js +47 -43
  489. package/out/zero-cache/src/scripts/decommission.js.map +1 -1
  490. package/out/zero-cache/src/scripts/deploy-permissions.js +132 -119
  491. package/out/zero-cache/src/scripts/deploy-permissions.js.map +1 -1
  492. package/out/zero-cache/src/scripts/permissions.d.ts +1 -1
  493. package/out/zero-cache/src/scripts/permissions.d.ts.map +1 -1
  494. package/out/zero-cache/src/scripts/permissions.js +106 -100
  495. package/out/zero-cache/src/scripts/permissions.js.map +1 -1
  496. package/out/zero-cache/src/server/anonymous-otel-start.d.ts +10 -1
  497. package/out/zero-cache/src/server/anonymous-otel-start.d.ts.map +1 -1
  498. package/out/zero-cache/src/server/anonymous-otel-start.js +426 -366
  499. package/out/zero-cache/src/server/anonymous-otel-start.js.map +1 -1
  500. package/out/zero-cache/src/server/change-streamer.d.ts.map +1 -1
  501. package/out/zero-cache/src/server/change-streamer.js +99 -64
  502. package/out/zero-cache/src/server/change-streamer.js.map +1 -1
  503. package/out/zero-cache/src/server/inspector-delegate.js +112 -109
  504. package/out/zero-cache/src/server/inspector-delegate.js.map +1 -1
  505. package/out/zero-cache/src/server/logging.d.ts +1 -1
  506. package/out/zero-cache/src/server/logging.d.ts.map +1 -1
  507. package/out/zero-cache/src/server/logging.js +26 -19
  508. package/out/zero-cache/src/server/logging.js.map +1 -1
  509. package/out/zero-cache/src/server/main.d.ts.map +1 -1
  510. package/out/zero-cache/src/server/main.js +137 -120
  511. package/out/zero-cache/src/server/main.js.map +1 -1
  512. package/out/zero-cache/src/server/mutator.js +19 -0
  513. package/out/zero-cache/src/server/mutator.js.map +1 -0
  514. package/out/zero-cache/src/server/otel-diag-logger.d.ts +1 -1
  515. package/out/zero-cache/src/server/otel-diag-logger.d.ts.map +1 -1
  516. package/out/zero-cache/src/server/otel-diag-logger.js +48 -71
  517. package/out/zero-cache/src/server/otel-diag-logger.js.map +1 -1
  518. package/out/zero-cache/src/server/otel-log-sink.js +40 -41
  519. package/out/zero-cache/src/server/otel-log-sink.js.map +1 -1
  520. package/out/zero-cache/src/server/otel-start.d.ts +1 -1
  521. package/out/zero-cache/src/server/otel-start.d.ts.map +1 -1
  522. package/out/zero-cache/src/server/otel-start.js +53 -68
  523. package/out/zero-cache/src/server/otel-start.js.map +1 -1
  524. package/out/zero-cache/src/server/reaper.js +34 -26
  525. package/out/zero-cache/src/server/reaper.js.map +1 -1
  526. package/out/zero-cache/src/server/replicator.js +53 -31
  527. package/out/zero-cache/src/server/replicator.js.map +1 -1
  528. package/out/zero-cache/src/server/runner/main.js +6 -4
  529. package/out/zero-cache/src/server/runner/main.js.map +1 -1
  530. package/out/zero-cache/src/server/runner/run-worker.d.ts.map +1 -1
  531. package/out/zero-cache/src/server/runner/run-worker.js +46 -50
  532. package/out/zero-cache/src/server/runner/run-worker.js.map +1 -1
  533. package/out/zero-cache/src/server/runner/runtime.js +33 -32
  534. package/out/zero-cache/src/server/runner/runtime.js.map +1 -1
  535. package/out/zero-cache/src/server/runner/zero-dispatcher.d.ts.map +1 -1
  536. package/out/zero-cache/src/server/runner/zero-dispatcher.js +28 -22
  537. package/out/zero-cache/src/server/runner/zero-dispatcher.js.map +1 -1
  538. package/out/zero-cache/src/server/syncer.d.ts.map +1 -1
  539. package/out/zero-cache/src/server/syncer.js +130 -63
  540. package/out/zero-cache/src/server/syncer.js.map +1 -1
  541. package/out/zero-cache/src/server/worker-dispatcher.d.ts +1 -1
  542. package/out/zero-cache/src/server/worker-dispatcher.d.ts.map +1 -1
  543. package/out/zero-cache/src/server/worker-dispatcher.js +112 -106
  544. package/out/zero-cache/src/server/worker-dispatcher.js.map +1 -1
  545. package/out/zero-cache/src/server/worker-urls.d.ts +7 -0
  546. package/out/zero-cache/src/server/worker-urls.d.ts.map +1 -0
  547. package/out/zero-cache/src/server/worker-urls.js +21 -0
  548. package/out/zero-cache/src/server/worker-urls.js.map +1 -0
  549. package/out/zero-cache/src/services/analyze.d.ts +4 -9
  550. package/out/zero-cache/src/services/analyze.d.ts.map +1 -1
  551. package/out/zero-cache/src/services/analyze.js +118 -121
  552. package/out/zero-cache/src/services/analyze.js.map +1 -1
  553. package/out/zero-cache/src/services/change-source/column-metadata.d.ts +10 -3
  554. package/out/zero-cache/src/services/change-source/column-metadata.d.ts.map +1 -1
  555. package/out/zero-cache/src/services/change-source/column-metadata.js +154 -144
  556. package/out/zero-cache/src/services/change-source/column-metadata.js.map +1 -1
  557. package/out/zero-cache/src/services/change-source/custom/change-source.d.ts +1 -1
  558. package/out/zero-cache/src/services/change-source/custom/change-source.d.ts.map +1 -1
  559. package/out/zero-cache/src/services/change-source/custom/change-source.js +197 -171
  560. package/out/zero-cache/src/services/change-source/custom/change-source.js.map +1 -1
  561. package/out/zero-cache/src/services/change-source/custom/sync-schema.js +11 -3
  562. package/out/zero-cache/src/services/change-source/custom/sync-schema.js.map +1 -1
  563. package/out/zero-cache/src/services/change-source/pg/change-source.d.ts +1 -1
  564. package/out/zero-cache/src/services/change-source/pg/change-source.d.ts.map +1 -1
  565. package/out/zero-cache/src/services/change-source/pg/change-source.js +622 -623
  566. package/out/zero-cache/src/services/change-source/pg/change-source.js.map +1 -1
  567. package/out/zero-cache/src/services/change-source/pg/decommission.js +24 -23
  568. package/out/zero-cache/src/services/change-source/pg/decommission.js.map +1 -1
  569. package/out/zero-cache/src/services/change-source/pg/initial-sync.d.ts +1 -1
  570. package/out/zero-cache/src/services/change-source/pg/initial-sync.d.ts.map +1 -1
  571. package/out/zero-cache/src/services/change-source/pg/initial-sync.js +327 -284
  572. package/out/zero-cache/src/services/change-source/pg/initial-sync.js.map +1 -1
  573. package/out/zero-cache/src/services/change-source/pg/logical-replication/binary-reader.d.ts +2 -3
  574. package/out/zero-cache/src/services/change-source/pg/logical-replication/binary-reader.d.ts.map +1 -1
  575. package/out/zero-cache/src/services/change-source/pg/logical-replication/binary-reader.js +61 -69
  576. package/out/zero-cache/src/services/change-source/pg/logical-replication/binary-reader.js.map +1 -1
  577. package/out/zero-cache/src/services/change-source/pg/logical-replication/pgoutput-parser.js +247 -257
  578. package/out/zero-cache/src/services/change-source/pg/logical-replication/pgoutput-parser.js.map +1 -1
  579. package/out/zero-cache/src/services/change-source/pg/logical-replication/stream.js +127 -119
  580. package/out/zero-cache/src/services/change-source/pg/logical-replication/stream.js.map +1 -1
  581. package/out/zero-cache/src/services/change-source/pg/lsn.js +20 -19
  582. package/out/zero-cache/src/services/change-source/pg/lsn.js.map +1 -1
  583. package/out/zero-cache/src/services/change-source/pg/schema/ddl.d.ts +5 -5
  584. package/out/zero-cache/src/services/change-source/pg/schema/ddl.js +96 -119
  585. package/out/zero-cache/src/services/change-source/pg/schema/ddl.js.map +1 -1
  586. package/out/zero-cache/src/services/change-source/pg/schema/init.js +138 -117
  587. package/out/zero-cache/src/services/change-source/pg/schema/init.js.map +1 -1
  588. package/out/zero-cache/src/services/change-source/pg/schema/published.d.ts +2 -2
  589. package/out/zero-cache/src/services/change-source/pg/schema/published.d.ts.map +1 -1
  590. package/out/zero-cache/src/services/change-source/pg/schema/published.js +70 -76
  591. package/out/zero-cache/src/services/change-source/pg/schema/published.js.map +1 -1
  592. package/out/zero-cache/src/services/change-source/pg/schema/shard.d.ts +1 -1
  593. package/out/zero-cache/src/services/change-source/pg/schema/shard.js +199 -188
  594. package/out/zero-cache/src/services/change-source/pg/schema/shard.js.map +1 -1
  595. package/out/zero-cache/src/services/change-source/pg/schema/validation.js +53 -38
  596. package/out/zero-cache/src/services/change-source/pg/schema/validation.js.map +1 -1
  597. package/out/zero-cache/src/services/change-source/pg/sync-schema.js +11 -3
  598. package/out/zero-cache/src/services/change-source/pg/sync-schema.js.map +1 -1
  599. package/out/zero-cache/src/services/change-source/protocol/current/control.d.ts +1 -0
  600. package/out/zero-cache/src/services/change-source/protocol/current/control.d.ts.map +1 -1
  601. package/out/zero-cache/src/services/change-source/protocol/current/control.js +13 -19
  602. package/out/zero-cache/src/services/change-source/protocol/current/control.js.map +1 -1
  603. package/out/zero-cache/src/services/change-source/protocol/current/data.js +143 -116
  604. package/out/zero-cache/src/services/change-source/protocol/current/data.js.map +1 -1
  605. package/out/zero-cache/src/services/change-source/protocol/current/downstream.d.ts +2 -0
  606. package/out/zero-cache/src/services/change-source/protocol/current/downstream.d.ts.map +1 -1
  607. package/out/zero-cache/src/services/change-source/protocol/current/downstream.js +29 -19
  608. package/out/zero-cache/src/services/change-source/protocol/current/downstream.js.map +1 -1
  609. package/out/zero-cache/src/services/change-source/protocol/current/json.d.ts +8 -0
  610. package/out/zero-cache/src/services/change-source/protocol/current/json.d.ts.map +1 -0
  611. package/out/zero-cache/src/services/change-source/protocol/current/json.js +19 -0
  612. package/out/zero-cache/src/services/change-source/protocol/current/json.js.map +1 -0
  613. package/out/zero-cache/src/services/change-source/protocol/current/path.js +5 -20
  614. package/out/zero-cache/src/services/change-source/protocol/current/path.js.map +1 -1
  615. package/out/zero-cache/src/services/change-source/protocol/current/status.js +12 -13
  616. package/out/zero-cache/src/services/change-source/protocol/current/status.js.map +1 -1
  617. package/out/zero-cache/src/services/change-source/protocol/current/upstream.d.ts +1 -1
  618. package/out/zero-cache/src/services/change-source/protocol/current/upstream.d.ts.map +1 -1
  619. package/out/zero-cache/src/services/change-source/protocol/current/upstream.js +5 -4
  620. package/out/zero-cache/src/services/change-source/protocol/current/upstream.js.map +1 -1
  621. package/out/zero-cache/src/services/change-source/protocol/current.d.ts +1 -0
  622. package/out/zero-cache/src/services/change-source/protocol/current.d.ts.map +1 -1
  623. package/out/zero-cache/src/services/change-source/protocol/current.js +38 -7
  624. package/out/zero-cache/src/services/change-source/protocol/current.js.map +1 -1
  625. package/out/zero-cache/src/services/change-source/replica-schema.d.ts.map +1 -1
  626. package/out/zero-cache/src/services/change-source/replica-schema.js +67 -37
  627. package/out/zero-cache/src/services/change-source/replica-schema.js.map +1 -1
  628. package/out/zero-cache/src/services/change-streamer/backup-monitor.d.ts +1 -1
  629. package/out/zero-cache/src/services/change-streamer/backup-monitor.d.ts.map +1 -1
  630. package/out/zero-cache/src/services/change-streamer/backup-monitor.js +139 -157
  631. package/out/zero-cache/src/services/change-streamer/backup-monitor.js.map +1 -1
  632. package/out/zero-cache/src/services/change-streamer/change-streamer-http.d.ts +11 -4
  633. package/out/zero-cache/src/services/change-streamer/change-streamer-http.d.ts.map +1 -1
  634. package/out/zero-cache/src/services/change-streamer/change-streamer-http.js +208 -157
  635. package/out/zero-cache/src/services/change-streamer/change-streamer-http.js.map +1 -1
  636. package/out/zero-cache/src/services/change-streamer/change-streamer-service.d.ts +1 -1
  637. package/out/zero-cache/src/services/change-streamer/change-streamer-service.d.ts.map +1 -1
  638. package/out/zero-cache/src/services/change-streamer/change-streamer-service.js +242 -349
  639. package/out/zero-cache/src/services/change-streamer/change-streamer-service.js.map +1 -1
  640. package/out/zero-cache/src/services/change-streamer/change-streamer.d.ts +5 -1
  641. package/out/zero-cache/src/services/change-streamer/change-streamer.d.ts.map +1 -1
  642. package/out/zero-cache/src/services/change-streamer/change-streamer.js +24 -22
  643. package/out/zero-cache/src/services/change-streamer/change-streamer.js.map +1 -1
  644. package/out/zero-cache/src/services/change-streamer/error-type-enum.js +9 -4
  645. package/out/zero-cache/src/services/change-streamer/error-type-enum.js.map +1 -1
  646. package/out/zero-cache/src/services/change-streamer/forwarder.d.ts +1 -1
  647. package/out/zero-cache/src/services/change-streamer/forwarder.d.ts.map +1 -1
  648. package/out/zero-cache/src/services/change-streamer/forwarder.js +53 -57
  649. package/out/zero-cache/src/services/change-streamer/forwarder.js.map +1 -1
  650. package/out/zero-cache/src/services/change-streamer/replica-monitor.d.ts +16 -0
  651. package/out/zero-cache/src/services/change-streamer/replica-monitor.d.ts.map +1 -0
  652. package/out/zero-cache/src/services/change-streamer/replica-monitor.js +48 -0
  653. package/out/zero-cache/src/services/change-streamer/replica-monitor.js.map +1 -0
  654. package/out/zero-cache/src/services/change-streamer/schema/init.js +82 -68
  655. package/out/zero-cache/src/services/change-streamer/schema/init.js.map +1 -1
  656. package/out/zero-cache/src/services/change-streamer/schema/tables.d.ts +2 -2
  657. package/out/zero-cache/src/services/change-streamer/schema/tables.d.ts.map +1 -1
  658. package/out/zero-cache/src/services/change-streamer/schema/tables.js +93 -78
  659. package/out/zero-cache/src/services/change-streamer/schema/tables.js.map +1 -1
  660. package/out/zero-cache/src/services/change-streamer/snapshot.d.ts +58 -0
  661. package/out/zero-cache/src/services/change-streamer/snapshot.d.ts.map +1 -1
  662. package/out/zero-cache/src/services/change-streamer/snapshot.js +28 -18
  663. package/out/zero-cache/src/services/change-streamer/snapshot.js.map +1 -1
  664. package/out/zero-cache/src/services/change-streamer/storer.d.ts +3 -2
  665. package/out/zero-cache/src/services/change-streamer/storer.d.ts.map +1 -1
  666. package/out/zero-cache/src/services/change-streamer/storer.js +308 -353
  667. package/out/zero-cache/src/services/change-streamer/storer.js.map +1 -1
  668. package/out/zero-cache/src/services/change-streamer/subscriber.d.ts +3 -2
  669. package/out/zero-cache/src/services/change-streamer/subscriber.d.ts.map +1 -1
  670. package/out/zero-cache/src/services/change-streamer/subscriber.js +85 -87
  671. package/out/zero-cache/src/services/change-streamer/subscriber.js.map +1 -1
  672. package/out/zero-cache/src/services/heapz.js +21 -25
  673. package/out/zero-cache/src/services/heapz.js.map +1 -1
  674. package/out/zero-cache/src/services/http-service.d.ts +5 -5
  675. package/out/zero-cache/src/services/http-service.d.ts.map +1 -1
  676. package/out/zero-cache/src/services/http-service.js +57 -59
  677. package/out/zero-cache/src/services/http-service.js.map +1 -1
  678. package/out/zero-cache/src/services/life-cycle.d.ts +1 -1
  679. package/out/zero-cache/src/services/life-cycle.d.ts.map +1 -1
  680. package/out/zero-cache/src/services/life-cycle.js +216 -255
  681. package/out/zero-cache/src/services/life-cycle.js.map +1 -1
  682. package/out/zero-cache/src/services/limiter/sliding-window-limiter.js +76 -130
  683. package/out/zero-cache/src/services/limiter/sliding-window-limiter.js.map +1 -1
  684. package/out/zero-cache/src/services/litestream/commands.d.ts +1 -1
  685. package/out/zero-cache/src/services/litestream/commands.d.ts.map +1 -1
  686. package/out/zero-cache/src/services/litestream/commands.js +202 -154
  687. package/out/zero-cache/src/services/litestream/commands.js.map +1 -1
  688. package/out/zero-cache/src/services/mutagen/error.js +11 -6
  689. package/out/zero-cache/src/services/mutagen/error.js.map +1 -1
  690. package/out/zero-cache/src/services/mutagen/mutagen.d.ts +2 -1
  691. package/out/zero-cache/src/services/mutagen/mutagen.d.ts.map +1 -1
  692. package/out/zero-cache/src/services/mutagen/mutagen.js +271 -267
  693. package/out/zero-cache/src/services/mutagen/mutagen.js.map +1 -1
  694. package/out/zero-cache/src/services/mutagen/pusher.d.ts +202 -2
  695. package/out/zero-cache/src/services/mutagen/pusher.d.ts.map +1 -1
  696. package/out/zero-cache/src/services/mutagen/pusher.js +354 -348
  697. package/out/zero-cache/src/services/mutagen/pusher.js.map +1 -1
  698. package/out/zero-cache/src/services/replicator/change-processor.d.ts.map +1 -1
  699. package/out/zero-cache/src/services/replicator/change-processor.js +483 -497
  700. package/out/zero-cache/src/services/replicator/change-processor.js.map +1 -1
  701. package/out/zero-cache/src/services/replicator/incremental-sync.d.ts +1 -1
  702. package/out/zero-cache/src/services/replicator/incremental-sync.d.ts.map +1 -1
  703. package/out/zero-cache/src/services/replicator/incremental-sync.js +97 -97
  704. package/out/zero-cache/src/services/replicator/incremental-sync.js.map +1 -1
  705. package/out/zero-cache/src/services/replicator/notifier.js +28 -52
  706. package/out/zero-cache/src/services/replicator/notifier.js.map +1 -1
  707. package/out/zero-cache/src/services/replicator/replication-status.d.ts +2 -0
  708. package/out/zero-cache/src/services/replicator/replication-status.d.ts.map +1 -1
  709. package/out/zero-cache/src/services/replicator/replication-status.js +113 -83
  710. package/out/zero-cache/src/services/replicator/replication-status.js.map +1 -1
  711. package/out/zero-cache/src/services/replicator/replicator.d.ts +1 -1
  712. package/out/zero-cache/src/services/replicator/replicator.d.ts.map +1 -1
  713. package/out/zero-cache/src/services/replicator/replicator.js +33 -26
  714. package/out/zero-cache/src/services/replicator/replicator.js.map +1 -1
  715. package/out/zero-cache/src/services/replicator/schema/change-log.d.ts +1 -1
  716. package/out/zero-cache/src/services/replicator/schema/change-log.d.ts.map +1 -1
  717. package/out/zero-cache/src/services/replicator/schema/change-log.js +74 -86
  718. package/out/zero-cache/src/services/replicator/schema/change-log.js.map +1 -1
  719. package/out/zero-cache/src/services/replicator/schema/constants.js +5 -7
  720. package/out/zero-cache/src/services/replicator/schema/constants.js.map +1 -1
  721. package/out/zero-cache/src/services/replicator/schema/replication-state.d.ts +2 -2
  722. package/out/zero-cache/src/services/replicator/schema/replication-state.d.ts.map +1 -1
  723. package/out/zero-cache/src/services/replicator/schema/replication-state.js +70 -74
  724. package/out/zero-cache/src/services/replicator/schema/replication-state.js.map +1 -1
  725. package/out/zero-cache/src/services/run-ast.d.ts +9 -3
  726. package/out/zero-cache/src/services/run-ast.d.ts.map +1 -1
  727. package/out/zero-cache/src/services/run-ast.js +91 -78
  728. package/out/zero-cache/src/services/run-ast.js.map +1 -1
  729. package/out/zero-cache/src/services/runner.d.ts +1 -1
  730. package/out/zero-cache/src/services/runner.d.ts.map +1 -1
  731. package/out/zero-cache/src/services/runner.js +40 -40
  732. package/out/zero-cache/src/services/runner.js.map +1 -1
  733. package/out/zero-cache/src/services/running-state.d.ts +1 -1
  734. package/out/zero-cache/src/services/running-state.d.ts.map +1 -1
  735. package/out/zero-cache/src/services/running-state.js +122 -119
  736. package/out/zero-cache/src/services/running-state.js.map +1 -1
  737. package/out/zero-cache/src/services/statz.js +184 -162
  738. package/out/zero-cache/src/services/statz.js.map +1 -1
  739. package/out/zero-cache/src/services/view-syncer/active-users-gauge.d.ts +2 -1
  740. package/out/zero-cache/src/services/view-syncer/active-users-gauge.d.ts.map +1 -1
  741. package/out/zero-cache/src/services/view-syncer/active-users-gauge.js +56 -42
  742. package/out/zero-cache/src/services/view-syncer/active-users-gauge.js.map +1 -1
  743. package/out/zero-cache/src/services/view-syncer/client-handler.js +307 -298
  744. package/out/zero-cache/src/services/view-syncer/client-handler.js.map +1 -1
  745. package/out/zero-cache/src/services/view-syncer/client-schema.d.ts.map +1 -1
  746. package/out/zero-cache/src/services/view-syncer/client-schema.js +80 -82
  747. package/out/zero-cache/src/services/view-syncer/client-schema.js.map +1 -1
  748. package/out/zero-cache/src/services/view-syncer/cvr-purger.d.ts +1 -1
  749. package/out/zero-cache/src/services/view-syncer/cvr-purger.d.ts.map +1 -1
  750. package/out/zero-cache/src/services/view-syncer/cvr-purger.js +110 -96
  751. package/out/zero-cache/src/services/view-syncer/cvr-purger.js.map +1 -1
  752. package/out/zero-cache/src/services/view-syncer/cvr-store.d.ts +6 -5
  753. package/out/zero-cache/src/services/view-syncer/cvr-store.d.ts.map +1 -1
  754. package/out/zero-cache/src/services/view-syncer/cvr-store.js +676 -611
  755. package/out/zero-cache/src/services/view-syncer/cvr-store.js.map +1 -1
  756. package/out/zero-cache/src/services/view-syncer/cvr.d.ts +4 -1
  757. package/out/zero-cache/src/services/view-syncer/cvr.d.ts.map +1 -1
  758. package/out/zero-cache/src/services/view-syncer/cvr.js +643 -694
  759. package/out/zero-cache/src/services/view-syncer/cvr.js.map +1 -1
  760. package/out/zero-cache/src/services/view-syncer/drain-coordinator.js +38 -60
  761. package/out/zero-cache/src/services/view-syncer/drain-coordinator.js.map +1 -1
  762. package/out/zero-cache/src/services/view-syncer/inspect-handler.d.ts +2 -1
  763. package/out/zero-cache/src/services/view-syncer/inspect-handler.d.ts.map +1 -1
  764. package/out/zero-cache/src/services/view-syncer/inspect-handler.js +175 -85
  765. package/out/zero-cache/src/services/view-syncer/inspect-handler.js.map +1 -1
  766. package/out/zero-cache/src/services/view-syncer/pipeline-driver.d.ts +23 -22
  767. package/out/zero-cache/src/services/view-syncer/pipeline-driver.d.ts.map +1 -1
  768. package/out/zero-cache/src/services/view-syncer/pipeline-driver.js +584 -461
  769. package/out/zero-cache/src/services/view-syncer/pipeline-driver.js.map +1 -1
  770. package/out/zero-cache/src/services/view-syncer/row-record-cache.d.ts +1 -1
  771. package/out/zero-cache/src/services/view-syncer/row-record-cache.d.ts.map +1 -1
  772. package/out/zero-cache/src/services/view-syncer/row-record-cache.js +229 -277
  773. package/out/zero-cache/src/services/view-syncer/row-record-cache.js.map +1 -1
  774. package/out/zero-cache/src/services/view-syncer/schema/cvr.d.ts +1 -0
  775. package/out/zero-cache/src/services/view-syncer/schema/cvr.d.ts.map +1 -1
  776. package/out/zero-cache/src/services/view-syncer/schema/cvr.js +79 -131
  777. package/out/zero-cache/src/services/view-syncer/schema/cvr.js.map +1 -1
  778. package/out/zero-cache/src/services/view-syncer/schema/init.d.ts.map +1 -1
  779. package/out/zero-cache/src/services/view-syncer/schema/init.js +207 -131
  780. package/out/zero-cache/src/services/view-syncer/schema/init.js.map +1 -1
  781. package/out/zero-cache/src/services/view-syncer/schema/types.d.ts +4 -4
  782. package/out/zero-cache/src/services/view-syncer/schema/types.js +265 -257
  783. package/out/zero-cache/src/services/view-syncer/schema/types.js.map +1 -1
  784. package/out/zero-cache/src/services/view-syncer/snapshotter.d.ts +5 -5
  785. package/out/zero-cache/src/services/view-syncer/snapshotter.d.ts.map +1 -1
  786. package/out/zero-cache/src/services/view-syncer/snapshotter.js +309 -337
  787. package/out/zero-cache/src/services/view-syncer/snapshotter.js.map +1 -1
  788. package/out/zero-cache/src/services/view-syncer/ttl-clock.js +13 -7
  789. package/out/zero-cache/src/services/view-syncer/ttl-clock.js.map +1 -1
  790. package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts +5 -4
  791. package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts.map +1 -1
  792. package/out/zero-cache/src/services/view-syncer/view-syncer.js +1514 -1311
  793. package/out/zero-cache/src/services/view-syncer/view-syncer.js.map +1 -1
  794. package/out/zero-cache/src/types/error-with-level.d.ts.map +1 -1
  795. package/out/zero-cache/src/types/error-with-level.js +30 -21
  796. package/out/zero-cache/src/types/error-with-level.js.map +1 -1
  797. package/out/zero-cache/src/types/http.js +27 -14
  798. package/out/zero-cache/src/types/http.js.map +1 -1
  799. package/out/zero-cache/src/types/lexi-version.js +46 -31
  800. package/out/zero-cache/src/types/lexi-version.js.map +1 -1
  801. package/out/zero-cache/src/types/lite.js +118 -125
  802. package/out/zero-cache/src/types/lite.js.map +1 -1
  803. package/out/zero-cache/src/types/names.js +6 -3
  804. package/out/zero-cache/src/types/names.js.map +1 -1
  805. package/out/zero-cache/src/types/pg-data-type.js +74 -68
  806. package/out/zero-cache/src/types/pg-data-type.js.map +1 -1
  807. package/out/zero-cache/src/types/pg-types.js +17 -72
  808. package/out/zero-cache/src/types/pg-types.js.map +1 -1
  809. package/out/zero-cache/src/types/pg.d.ts +1 -1
  810. package/out/zero-cache/src/types/pg.d.ts.map +1 -1
  811. package/out/zero-cache/src/types/pg.js +213 -233
  812. package/out/zero-cache/src/types/pg.js.map +1 -1
  813. package/out/zero-cache/src/types/processes.d.ts +2 -2
  814. package/out/zero-cache/src/types/processes.d.ts.map +1 -1
  815. package/out/zero-cache/src/types/processes.js +95 -143
  816. package/out/zero-cache/src/types/processes.js.map +1 -1
  817. package/out/zero-cache/src/types/profiler.js +29 -30
  818. package/out/zero-cache/src/types/profiler.js.map +1 -1
  819. package/out/zero-cache/src/types/row-key.js +30 -68
  820. package/out/zero-cache/src/types/row-key.js.map +1 -1
  821. package/out/zero-cache/src/types/schema-versions.js +25 -19
  822. package/out/zero-cache/src/types/schema-versions.js.map +1 -1
  823. package/out/zero-cache/src/types/shards.js +50 -36
  824. package/out/zero-cache/src/types/shards.js.map +1 -1
  825. package/out/zero-cache/src/types/sql.js +9 -13
  826. package/out/zero-cache/src/types/sql.js.map +1 -1
  827. package/out/zero-cache/src/types/streams.js +245 -254
  828. package/out/zero-cache/src/types/streams.js.map +1 -1
  829. package/out/zero-cache/src/types/strings.js +14 -11
  830. package/out/zero-cache/src/types/strings.js.map +1 -1
  831. package/out/zero-cache/src/types/subscription.js +200 -259
  832. package/out/zero-cache/src/types/subscription.js.map +1 -1
  833. package/out/zero-cache/src/types/url-params.js +35 -30
  834. package/out/zero-cache/src/types/url-params.js.map +1 -1
  835. package/out/zero-cache/src/types/websocket-handoff.d.ts +5 -4
  836. package/out/zero-cache/src/types/websocket-handoff.d.ts.map +1 -1
  837. package/out/zero-cache/src/types/websocket-handoff.js +68 -76
  838. package/out/zero-cache/src/types/websocket-handoff.js.map +1 -1
  839. package/out/zero-cache/src/types/ws.js +56 -59
  840. package/out/zero-cache/src/types/ws.js.map +1 -1
  841. package/out/zero-cache/src/workers/connect-params.d.ts +1 -0
  842. package/out/zero-cache/src/workers/connect-params.d.ts.map +1 -1
  843. package/out/zero-cache/src/workers/connect-params.js +46 -40
  844. package/out/zero-cache/src/workers/connect-params.js.map +1 -1
  845. package/out/zero-cache/src/workers/connection.d.ts.map +1 -1
  846. package/out/zero-cache/src/workers/connection.js +282 -243
  847. package/out/zero-cache/src/workers/connection.js.map +1 -1
  848. package/out/zero-cache/src/workers/mutator.js +24 -0
  849. package/out/zero-cache/src/workers/mutator.js.map +1 -0
  850. package/out/zero-cache/src/workers/replicator.d.ts +1 -1
  851. package/out/zero-cache/src/workers/replicator.d.ts.map +1 -1
  852. package/out/zero-cache/src/workers/replicator.js +103 -106
  853. package/out/zero-cache/src/workers/replicator.js.map +1 -1
  854. package/out/zero-cache/src/workers/syncer-ws-message-handler.d.ts.map +1 -1
  855. package/out/zero-cache/src/workers/syncer-ws-message-handler.js +181 -147
  856. package/out/zero-cache/src/workers/syncer-ws-message-handler.js.map +1 -1
  857. package/out/zero-cache/src/workers/syncer.d.ts +3 -3
  858. package/out/zero-cache/src/workers/syncer.d.ts.map +1 -1
  859. package/out/zero-cache/src/workers/syncer.js +192 -169
  860. package/out/zero-cache/src/workers/syncer.js.map +1 -1
  861. package/out/zero-client/src/client/active-clients-manager.js +199 -0
  862. package/out/zero-client/src/client/active-clients-manager.js.map +1 -0
  863. package/out/zero-client/src/client/bindings.d.ts +13 -0
  864. package/out/zero-client/src/client/bindings.d.ts.map +1 -0
  865. package/out/zero-client/src/client/client-error-kind-enum.d.ts +12 -12
  866. package/out/zero-client/src/client/client-error-kind-enum.d.ts.map +1 -1
  867. package/out/zero-client/src/client/client-error-kind-enum.js +29 -0
  868. package/out/zero-client/src/client/client-error-kind-enum.js.map +1 -0
  869. package/out/zero-client/src/client/connection-manager.d.ts +20 -40
  870. package/out/zero-client/src/client/connection-manager.d.ts.map +1 -1
  871. package/out/zero-client/src/client/connection-manager.js +310 -0
  872. package/out/zero-client/src/client/connection-manager.js.map +1 -0
  873. package/out/zero-client/src/client/connection-status-enum.js +15 -0
  874. package/out/zero-client/src/client/connection-status-enum.js.map +1 -0
  875. package/out/zero-client/src/client/connection.d.ts +48 -5
  876. package/out/zero-client/src/client/connection.d.ts.map +1 -1
  877. package/out/zero-client/src/client/connection.js +110 -0
  878. package/out/zero-client/src/client/connection.js.map +1 -0
  879. package/out/zero-client/src/client/context.d.ts +9 -10
  880. package/out/zero-client/src/client/context.d.ts.map +1 -1
  881. package/out/zero-client/src/client/context.js +104 -0
  882. package/out/zero-client/src/client/context.js.map +1 -0
  883. package/out/zero-client/src/client/crud-impl.d.ts +11 -0
  884. package/out/zero-client/src/client/crud-impl.d.ts.map +1 -0
  885. package/out/zero-client/src/client/crud-impl.js +102 -0
  886. package/out/zero-client/src/client/crud-impl.js.map +1 -0
  887. package/out/zero-client/src/client/crud.d.ts +17 -47
  888. package/out/zero-client/src/client/crud.d.ts.map +1 -1
  889. package/out/zero-client/src/client/crud.js +143 -0
  890. package/out/zero-client/src/client/crud.js.map +1 -0
  891. package/out/zero-client/src/client/custom.d.ts +52 -25
  892. package/out/zero-client/src/client/custom.d.ts.map +1 -1
  893. package/out/zero-client/src/client/custom.js +87 -0
  894. package/out/zero-client/src/client/custom.js.map +1 -0
  895. package/out/zero-client/src/client/delete-clients-manager.d.ts +2 -2
  896. package/out/zero-client/src/client/delete-clients-manager.d.ts.map +1 -1
  897. package/out/zero-client/src/client/delete-clients-manager.js +98 -0
  898. package/out/zero-client/src/client/delete-clients-manager.js.map +1 -0
  899. package/out/zero-client/src/client/enable-analytics.js +18 -0
  900. package/out/zero-client/src/client/enable-analytics.js.map +1 -0
  901. package/out/zero-client/src/client/error.d.ts +30 -12
  902. package/out/zero-client/src/client/error.d.ts.map +1 -1
  903. package/out/zero-client/src/client/error.js +148 -0
  904. package/out/zero-client/src/client/error.js.map +1 -0
  905. package/out/zero-client/src/client/http-string.js +11 -0
  906. package/out/zero-client/src/client/http-string.js.map +1 -0
  907. package/out/zero-client/src/client/inspector/client-group.js +27 -0
  908. package/out/zero-client/src/client/inspector/client-group.js.map +1 -0
  909. package/out/zero-client/src/client/inspector/client.js +28 -0
  910. package/out/zero-client/src/client/inspector/client.js.map +1 -0
  911. package/out/zero-client/src/client/inspector/html-dialog-prompt.d.ts.map +1 -1
  912. package/out/zero-client/src/client/inspector/html-dialog-prompt.js +77 -0
  913. package/out/zero-client/src/client/inspector/html-dialog-prompt.js.map +1 -0
  914. package/out/zero-client/src/client/inspector/inspector.d.ts +8 -3
  915. package/out/zero-client/src/client/inspector/inspector.d.ts.map +1 -1
  916. package/out/zero-client/src/client/inspector/inspector.js +54 -0
  917. package/out/zero-client/src/client/inspector/inspector.js.map +1 -0
  918. package/out/zero-client/src/client/inspector/lazy-inspector.d.ts +4 -1
  919. package/out/zero-client/src/client/inspector/lazy-inspector.d.ts.map +1 -1
  920. package/out/zero-client/src/client/inspector/lazy-inspector.js +243 -0
  921. package/out/zero-client/src/client/inspector/lazy-inspector.js.map +1 -0
  922. package/out/zero-client/src/client/inspector/query.d.ts.map +1 -1
  923. package/out/zero-client/src/client/inspector/query.js +82 -0
  924. package/out/zero-client/src/client/inspector/query.js.map +1 -0
  925. package/out/zero-client/src/client/ivm-branch.d.ts +4 -4
  926. package/out/zero-client/src/client/ivm-branch.d.ts.map +1 -1
  927. package/out/zero-client/src/client/ivm-branch.js +156 -0
  928. package/out/zero-client/src/client/ivm-branch.js.map +1 -0
  929. package/out/zero-client/src/client/keys.js +45 -0
  930. package/out/zero-client/src/client/keys.js.map +1 -0
  931. package/out/zero-client/src/client/log-options.js +60 -0
  932. package/out/zero-client/src/client/log-options.js.map +1 -0
  933. package/out/zero-client/src/client/make-mutate-property.d.ts +40 -0
  934. package/out/zero-client/src/client/make-mutate-property.d.ts.map +1 -0
  935. package/out/zero-client/src/client/make-mutate-property.js +33 -0
  936. package/out/zero-client/src/client/make-mutate-property.js.map +1 -0
  937. package/out/zero-client/src/client/make-replicache-mutators.d.ts +34 -0
  938. package/out/zero-client/src/client/make-replicache-mutators.d.ts.map +1 -0
  939. package/out/zero-client/src/client/make-replicache-mutators.js +108 -0
  940. package/out/zero-client/src/client/make-replicache-mutators.js.map +1 -0
  941. package/out/zero-client/src/client/metric-name-enum.js +15 -0
  942. package/out/zero-client/src/client/metric-name-enum.js.map +1 -0
  943. package/out/zero-client/src/client/metrics.d.ts +2 -2
  944. package/out/zero-client/src/client/metrics.d.ts.map +1 -1
  945. package/out/zero-client/src/client/metrics.js +249 -0
  946. package/out/zero-client/src/client/metrics.js.map +1 -0
  947. package/out/zero-client/src/client/mutation-tracker.d.ts +12 -4
  948. package/out/zero-client/src/client/mutation-tracker.d.ts.map +1 -1
  949. package/out/zero-client/src/client/mutation-tracker.js +363 -0
  950. package/out/zero-client/src/client/mutation-tracker.js.map +1 -0
  951. package/out/zero-client/src/client/mutator-proxy.d.ts +16 -0
  952. package/out/zero-client/src/client/mutator-proxy.d.ts.map +1 -0
  953. package/out/zero-client/src/client/mutator-proxy.js +143 -0
  954. package/out/zero-client/src/client/mutator-proxy.js.map +1 -0
  955. package/out/zero-client/src/client/options.d.ts +70 -10
  956. package/out/zero-client/src/client/options.d.ts.map +1 -1
  957. package/out/zero-client/src/client/options.js +11 -0
  958. package/out/zero-client/src/client/options.js.map +1 -0
  959. package/out/zero-client/src/client/query-manager.d.ts +9 -2
  960. package/out/zero-client/src/client/query-manager.d.ts.map +1 -1
  961. package/out/zero-client/src/client/query-manager.js +377 -0
  962. package/out/zero-client/src/client/query-manager.js.map +1 -0
  963. package/out/zero-client/src/client/reload-error-handler.d.ts +4 -4
  964. package/out/zero-client/src/client/reload-error-handler.d.ts.map +1 -1
  965. package/out/zero-client/src/client/reload-error-handler.js +114 -0
  966. package/out/zero-client/src/client/reload-error-handler.js.map +1 -0
  967. package/out/zero-client/src/client/server-option.js +64 -0
  968. package/out/zero-client/src/client/server-option.js.map +1 -0
  969. package/out/zero-client/src/client/update-needed-reason-type-enum.js +9 -0
  970. package/out/zero-client/src/client/update-needed-reason-type-enum.js.map +1 -0
  971. package/out/zero-client/src/client/version.js +5 -0
  972. package/out/zero-client/src/client/version.js.map +1 -0
  973. package/out/zero-client/src/client/zero-poke-handler.d.ts +4 -4
  974. package/out/zero-client/src/client/zero-poke-handler.d.ts.map +1 -1
  975. package/out/zero-client/src/client/zero-poke-handler.js +303 -0
  976. package/out/zero-client/src/client/zero-poke-handler.js.map +1 -0
  977. package/out/zero-client/src/client/zero-rep.d.ts +3 -2
  978. package/out/zero-client/src/client/zero-rep.d.ts.map +1 -1
  979. package/out/zero-client/src/client/zero-rep.js +72 -0
  980. package/out/zero-client/src/client/zero-rep.js.map +1 -0
  981. package/out/zero-client/src/client/zero.d.ts +119 -28
  982. package/out/zero-client/src/client/zero.d.ts.map +1 -1
  983. package/out/zero-client/src/client/zero.js +1800 -0
  984. package/out/zero-client/src/client/zero.js.map +1 -0
  985. package/out/zero-client/src/mod.d.ts +23 -20
  986. package/out/zero-client/src/mod.d.ts.map +1 -1
  987. package/out/zero-client/src/types/query-result.d.ts +5 -4
  988. package/out/zero-client/src/types/query-result.d.ts.map +1 -1
  989. package/out/zero-client/src/util/nanoid.js +21 -0
  990. package/out/zero-client/src/util/nanoid.js.map +1 -0
  991. package/out/zero-client/src/util/socket.js +7 -0
  992. package/out/zero-client/src/util/socket.js.map +1 -0
  993. package/out/zero-events/src/status.d.ts +1 -1
  994. package/out/zero-events/src/status.d.ts.map +1 -1
  995. package/out/zero-protocol/src/analyze-query-result.d.ts +238 -1
  996. package/out/zero-protocol/src/analyze-query-result.d.ts.map +1 -1
  997. package/out/zero-protocol/src/analyze-query-result.js +159 -24
  998. package/out/zero-protocol/src/analyze-query-result.js.map +1 -1
  999. package/out/zero-protocol/src/application-error.d.ts +2 -8
  1000. package/out/zero-protocol/src/application-error.d.ts.map +1 -1
  1001. package/out/zero-protocol/src/application-error.js +35 -34
  1002. package/out/zero-protocol/src/application-error.js.map +1 -1
  1003. package/out/zero-protocol/src/ast.d.ts +2 -2
  1004. package/out/zero-protocol/src/ast.js +296 -277
  1005. package/out/zero-protocol/src/ast.js.map +1 -1
  1006. package/out/zero-protocol/src/change-desired-queries.d.ts +2 -2
  1007. package/out/zero-protocol/src/change-desired-queries.js +11 -7
  1008. package/out/zero-protocol/src/change-desired-queries.js.map +1 -1
  1009. package/out/zero-protocol/src/client-schema.d.ts +2 -2
  1010. package/out/zero-protocol/src/client-schema.d.ts.map +1 -1
  1011. package/out/zero-protocol/src/client-schema.js +40 -26
  1012. package/out/zero-protocol/src/client-schema.js.map +1 -1
  1013. package/out/zero-protocol/src/close-connection.js +11 -18
  1014. package/out/zero-protocol/src/close-connection.js.map +1 -1
  1015. package/out/zero-protocol/src/connect.d.ts +4 -4
  1016. package/out/zero-protocol/src/connect.d.ts.map +1 -1
  1017. package/out/zero-protocol/src/connect.js +50 -51
  1018. package/out/zero-protocol/src/connect.js.map +1 -1
  1019. package/out/zero-protocol/src/custom-queries.d.ts +4 -4
  1020. package/out/zero-protocol/src/custom-queries.js +61 -39
  1021. package/out/zero-protocol/src/custom-queries.js.map +1 -1
  1022. package/out/zero-protocol/src/data.js +9 -4
  1023. package/out/zero-protocol/src/data.js.map +1 -1
  1024. package/out/zero-protocol/src/delete-clients.js +16 -9
  1025. package/out/zero-protocol/src/delete-clients.js.map +1 -1
  1026. package/out/zero-protocol/src/down.d.ts +107 -7
  1027. package/out/zero-protocol/src/down.d.ts.map +1 -1
  1028. package/out/zero-protocol/src/down.js +20 -4
  1029. package/out/zero-protocol/src/down.js.map +1 -1
  1030. package/out/zero-protocol/src/error-kind-enum.js +41 -23
  1031. package/out/zero-protocol/src/error-kind-enum.js.map +1 -1
  1032. package/out/zero-protocol/src/error-origin-enum.js +9 -4
  1033. package/out/zero-protocol/src/error-origin-enum.js.map +1 -1
  1034. package/out/zero-protocol/src/error-reason-enum.js +17 -8
  1035. package/out/zero-protocol/src/error-reason-enum.js.map +1 -1
  1036. package/out/zero-protocol/src/error.d.ts +17 -17
  1037. package/out/zero-protocol/src/error.js +151 -89
  1038. package/out/zero-protocol/src/error.js.map +1 -1
  1039. package/out/zero-protocol/src/inspect-down.d.ts +321 -21
  1040. package/out/zero-protocol/src/inspect-down.d.ts.map +1 -1
  1041. package/out/zero-protocol/src/inspect-down.js +72 -54
  1042. package/out/zero-protocol/src/inspect-down.js.map +1 -1
  1043. package/out/zero-protocol/src/inspect-up.d.ts +10 -6
  1044. package/out/zero-protocol/src/inspect-up.d.ts.map +1 -1
  1045. package/out/zero-protocol/src/inspect-up.js +39 -26
  1046. package/out/zero-protocol/src/inspect-up.js.map +1 -1
  1047. package/out/zero-protocol/src/mutation-id.js +9 -5
  1048. package/out/zero-protocol/src/mutation-id.js.map +1 -1
  1049. package/out/zero-protocol/src/mutation-type-enum.js +7 -3
  1050. package/out/zero-protocol/src/mutation-type-enum.js.map +1 -1
  1051. package/out/zero-protocol/src/mutations-patch.js +16 -17
  1052. package/out/zero-protocol/src/mutations-patch.js.map +1 -1
  1053. package/out/zero-protocol/src/ping.js +9 -4
  1054. package/out/zero-protocol/src/ping.js.map +1 -1
  1055. package/out/zero-protocol/src/poke.js +55 -72
  1056. package/out/zero-protocol/src/poke.js.map +1 -1
  1057. package/out/zero-protocol/src/pong.js +9 -4
  1058. package/out/zero-protocol/src/pong.js.map +1 -1
  1059. package/out/zero-protocol/src/primary-key.js +19 -5
  1060. package/out/zero-protocol/src/primary-key.js.map +1 -1
  1061. package/out/zero-protocol/src/protocol-version.d.ts +2 -2
  1062. package/out/zero-protocol/src/protocol-version.d.ts.map +1 -1
  1063. package/out/zero-protocol/src/protocol-version.js +7 -58
  1064. package/out/zero-protocol/src/protocol-version.js.map +1 -1
  1065. package/out/zero-protocol/src/pull.js +26 -19
  1066. package/out/zero-protocol/src/pull.js.map +1 -1
  1067. package/out/zero-protocol/src/push.d.ts +4 -4
  1068. package/out/zero-protocol/src/push.js +179 -176
  1069. package/out/zero-protocol/src/push.js.map +1 -1
  1070. package/out/zero-protocol/src/queries-patch.d.ts +3 -3
  1071. package/out/zero-protocol/src/queries-patch.js +29 -22
  1072. package/out/zero-protocol/src/queries-patch.js.map +1 -1
  1073. package/out/zero-protocol/src/query-hash.js +18 -14
  1074. package/out/zero-protocol/src/query-hash.js.map +1 -1
  1075. package/out/zero-protocol/src/row-patch.js +29 -20
  1076. package/out/zero-protocol/src/row-patch.js.map +1 -1
  1077. package/out/zero-protocol/src/up.d.ts +6 -5
  1078. package/out/zero-protocol/src/up.d.ts.map +1 -1
  1079. package/out/zero-protocol/src/up.js +18 -4
  1080. package/out/zero-protocol/src/up.js.map +1 -1
  1081. package/out/zero-protocol/src/version.js +9 -4
  1082. package/out/zero-protocol/src/version.js.map +1 -1
  1083. package/out/zero-react/src/bindings.d.ts +2 -0
  1084. package/out/zero-react/src/bindings.d.ts.map +1 -0
  1085. package/out/zero-react/src/mod.d.ts +2 -13
  1086. package/out/zero-react/src/mod.d.ts.map +1 -1
  1087. package/out/zero-react/src/use-connection-state.d.ts +9 -0
  1088. package/out/zero-react/src/use-connection-state.d.ts.map +1 -0
  1089. package/out/zero-react/src/use-connection-state.js +14 -0
  1090. package/out/zero-react/src/use-connection-state.js.map +1 -0
  1091. package/out/zero-react/src/use-query.d.ts +5 -9
  1092. package/out/zero-react/src/use-query.d.ts.map +1 -1
  1093. package/out/zero-react/src/use-query.js +289 -0
  1094. package/out/zero-react/src/use-query.js.map +1 -0
  1095. package/out/zero-react/src/use-zero-online.d.ts +1 -1
  1096. package/out/zero-react/src/use-zero-online.js +14 -0
  1097. package/out/zero-react/src/use-zero-online.js.map +1 -0
  1098. package/out/zero-react/src/zero-provider.d.ts +19 -10
  1099. package/out/zero-react/src/zero-provider.d.ts.map +1 -1
  1100. package/out/zero-react/src/zero-provider.js +77 -0
  1101. package/out/zero-react/src/zero-provider.js.map +1 -0
  1102. package/out/zero-react/src/zero.d.ts +2 -0
  1103. package/out/zero-react/src/zero.d.ts.map +1 -0
  1104. package/out/zero-schema/src/builder/relationship-builder.js +22 -19
  1105. package/out/zero-schema/src/builder/relationship-builder.js.map +1 -1
  1106. package/out/zero-schema/src/builder/schema-builder.d.ts +1 -3
  1107. package/out/zero-schema/src/builder/schema-builder.d.ts.map +1 -1
  1108. package/out/zero-schema/src/builder/schema-builder.js +81 -71
  1109. package/out/zero-schema/src/builder/schema-builder.js.map +1 -1
  1110. package/out/zero-schema/src/builder/table-builder.js +117 -116
  1111. package/out/zero-schema/src/builder/table-builder.js.map +1 -1
  1112. package/out/zero-schema/src/compiled-permissions.d.ts +22 -2
  1113. package/out/zero-schema/src/compiled-permissions.d.ts.map +1 -1
  1114. package/out/zero-schema/src/compiled-permissions.js +24 -19
  1115. package/out/zero-schema/src/compiled-permissions.js.map +1 -1
  1116. package/out/zero-schema/src/name-mapper.js +43 -38
  1117. package/out/zero-schema/src/name-mapper.js.map +1 -1
  1118. package/out/zero-schema/src/permissions.d.ts +12 -9
  1119. package/out/zero-schema/src/permissions.d.ts.map +1 -1
  1120. package/out/zero-schema/src/permissions.js +193 -0
  1121. package/out/zero-schema/src/permissions.js.map +1 -0
  1122. package/out/zero-schema/src/schema-config.d.ts +1 -6
  1123. package/out/zero-schema/src/schema-config.d.ts.map +1 -1
  1124. package/out/zero-schema/src/schema-config.js +35 -51
  1125. package/out/zero-schema/src/schema-config.js.map +1 -1
  1126. package/out/zero-server/src/adapters/drizzle.d.ts +2 -2
  1127. package/out/zero-server/src/adapters/drizzle.d.ts.map +1 -1
  1128. package/out/zero-server/src/adapters/drizzle.js +84 -97
  1129. package/out/zero-server/src/adapters/drizzle.js.map +1 -1
  1130. package/out/zero-server/src/adapters/pg.d.ts +8 -2
  1131. package/out/zero-server/src/adapters/pg.d.ts.map +1 -1
  1132. package/out/zero-server/src/adapters/pg.js +54 -74
  1133. package/out/zero-server/src/adapters/pg.js.map +1 -1
  1134. package/out/zero-server/src/adapters/postgresjs.d.ts +7 -2
  1135. package/out/zero-server/src/adapters/postgresjs.d.ts.map +1 -1
  1136. package/out/zero-server/src/adapters/postgresjs.js +40 -54
  1137. package/out/zero-server/src/adapters/postgresjs.js.map +1 -1
  1138. package/out/zero-server/src/custom.d.ts +48 -19
  1139. package/out/zero-server/src/custom.d.ts.map +1 -1
  1140. package/out/zero-server/src/custom.js +278 -106
  1141. package/out/zero-server/src/custom.js.map +1 -1
  1142. package/out/zero-server/src/logging.js +7 -4
  1143. package/out/zero-server/src/logging.js.map +1 -1
  1144. package/out/zero-server/src/mod.d.ts +1 -1
  1145. package/out/zero-server/src/mod.d.ts.map +1 -1
  1146. package/out/zero-server/src/pg-query-executor.d.ts +11 -0
  1147. package/out/zero-server/src/pg-query-executor.d.ts.map +1 -0
  1148. package/out/zero-server/src/pg-query-executor.js +20 -0
  1149. package/out/zero-server/src/pg-query-executor.js.map +1 -0
  1150. package/out/zero-server/src/process-mutations.d.ts +13 -13
  1151. package/out/zero-server/src/process-mutations.d.ts.map +1 -1
  1152. package/out/zero-server/src/process-mutations.js +328 -272
  1153. package/out/zero-server/src/process-mutations.js.map +1 -1
  1154. package/out/zero-server/src/push-processor.d.ts +5 -3
  1155. package/out/zero-server/src/push-processor.d.ts.map +1 -1
  1156. package/out/zero-server/src/push-processor.js +50 -32
  1157. package/out/zero-server/src/push-processor.js.map +1 -1
  1158. package/out/zero-server/src/queries/process-queries.d.ts +76 -3
  1159. package/out/zero-server/src/queries/process-queries.d.ts.map +1 -1
  1160. package/out/zero-server/src/queries/process-queries.js +104 -93
  1161. package/out/zero-server/src/queries/process-queries.js.map +1 -1
  1162. package/out/zero-server/src/schema.d.ts +2 -2
  1163. package/out/zero-server/src/schema.d.ts.map +1 -1
  1164. package/out/zero-server/src/schema.js +136 -124
  1165. package/out/zero-server/src/schema.js.map +1 -1
  1166. package/out/zero-server/src/zql-database.d.ts +9 -6
  1167. package/out/zero-server/src/zql-database.d.ts.map +1 -1
  1168. package/out/zero-server/src/zql-database.js +56 -51
  1169. package/out/zero-server/src/zql-database.js.map +1 -1
  1170. package/out/zero-solid/src/bindings.d.ts +2 -0
  1171. package/out/zero-solid/src/bindings.d.ts.map +1 -0
  1172. package/out/zero-solid/src/mod.d.ts +1 -9
  1173. package/out/zero-solid/src/mod.d.ts.map +1 -1
  1174. package/out/zero-solid/src/solid-view.d.ts +3 -5
  1175. package/out/zero-solid/src/solid-view.d.ts.map +1 -1
  1176. package/out/{solid.js → zero-solid/src/solid-view.js} +47 -196
  1177. package/out/zero-solid/src/solid-view.js.map +1 -0
  1178. package/out/zero-solid/src/{use-zero-connection-state.d.ts → use-connection-state.d.ts} +3 -3
  1179. package/out/zero-solid/src/use-connection-state.d.ts.map +1 -0
  1180. package/out/zero-solid/src/use-connection-state.js +17 -0
  1181. package/out/zero-solid/src/use-connection-state.js.map +1 -0
  1182. package/out/zero-solid/src/use-query.d.ts +4 -7
  1183. package/out/zero-solid/src/use-query.d.ts.map +1 -1
  1184. package/out/zero-solid/src/use-query.js +92 -0
  1185. package/out/zero-solid/src/use-query.js.map +1 -0
  1186. package/out/zero-solid/src/use-zero-online.d.ts +1 -1
  1187. package/out/zero-solid/src/use-zero-online.d.ts.map +1 -1
  1188. package/out/zero-solid/src/use-zero-online.js +15 -0
  1189. package/out/zero-solid/src/use-zero-online.js.map +1 -0
  1190. package/out/zero-solid/src/use-zero.d.ts +22 -11
  1191. package/out/zero-solid/src/use-zero.d.ts.map +1 -1
  1192. package/out/zero-solid/src/use-zero.js +86 -0
  1193. package/out/zero-solid/src/use-zero.js.map +1 -0
  1194. package/out/zero-solid/src/zero.d.ts +2 -0
  1195. package/out/zero-solid/src/zero.d.ts.map +1 -0
  1196. package/out/zero-types/src/default-types.d.ts +38 -0
  1197. package/out/zero-types/src/default-types.d.ts.map +1 -0
  1198. package/out/zero-types/src/format.js +7 -4
  1199. package/out/zero-types/src/format.js.map +1 -1
  1200. package/out/zero-types/src/name-mapper.js +43 -40
  1201. package/out/zero-types/src/name-mapper.js.map +1 -1
  1202. package/out/zero-types/src/schema.d.ts +4 -4
  1203. package/out/zero-types/src/server-schema.d.ts.map +1 -0
  1204. package/out/zql/src/builder/builder.d.ts +10 -2
  1205. package/out/zql/src/builder/builder.d.ts.map +1 -1
  1206. package/out/zql/src/builder/builder.js +474 -427
  1207. package/out/zql/src/builder/builder.js.map +1 -1
  1208. package/out/zql/src/builder/debug-delegate.d.ts +4 -0
  1209. package/out/zql/src/builder/debug-delegate.d.ts.map +1 -1
  1210. package/out/zql/src/builder/debug-delegate.js +68 -47
  1211. package/out/zql/src/builder/debug-delegate.js.map +1 -1
  1212. package/out/zql/src/builder/filter.js +132 -138
  1213. package/out/zql/src/builder/filter.js.map +1 -1
  1214. package/out/zql/src/builder/like.js +44 -51
  1215. package/out/zql/src/builder/like.js.map +1 -1
  1216. package/out/zql/src/error.d.ts +5 -0
  1217. package/out/zql/src/error.d.ts.map +1 -1
  1218. package/out/zql/src/error.js +9 -6
  1219. package/out/zql/src/error.js.map +1 -1
  1220. package/out/zql/src/ivm/array-view.d.ts +2 -2
  1221. package/out/zql/src/ivm/array-view.d.ts.map +1 -1
  1222. package/out/zql/src/ivm/array-view.js +89 -92
  1223. package/out/zql/src/ivm/array-view.js.map +1 -1
  1224. package/out/zql/src/ivm/constraint.js +74 -127
  1225. package/out/zql/src/ivm/constraint.js.map +1 -1
  1226. package/out/zql/src/ivm/data.d.ts +7 -2
  1227. package/out/zql/src/ivm/data.d.ts.map +1 -1
  1228. package/out/zql/src/ivm/data.js +53 -87
  1229. package/out/zql/src/ivm/data.js.map +1 -1
  1230. package/out/zql/src/ivm/exists.d.ts +6 -4
  1231. package/out/zql/src/ivm/exists.d.ts.map +1 -1
  1232. package/out/zql/src/ivm/exists.js +206 -244
  1233. package/out/zql/src/ivm/exists.js.map +1 -1
  1234. package/out/zql/src/ivm/fan-in.d.ts +5 -3
  1235. package/out/zql/src/ivm/fan-in.d.ts.map +1 -1
  1236. package/out/zql/src/ivm/fan-in.js +58 -52
  1237. package/out/zql/src/ivm/fan-in.js.map +1 -1
  1238. package/out/zql/src/ivm/fan-out.d.ts +4 -2
  1239. package/out/zql/src/ivm/fan-out.d.ts.map +1 -1
  1240. package/out/zql/src/ivm/fan-out.js +56 -48
  1241. package/out/zql/src/ivm/fan-out.js.map +1 -1
  1242. package/out/zql/src/ivm/filter-operators.d.ts +13 -11
  1243. package/out/zql/src/ivm/filter-operators.d.ts.map +1 -1
  1244. package/out/zql/src/ivm/filter-operators.js +91 -88
  1245. package/out/zql/src/ivm/filter-operators.js.map +1 -1
  1246. package/out/zql/src/ivm/filter-push.d.ts +2 -1
  1247. package/out/zql/src/ivm/filter-push.d.ts.map +1 -1
  1248. package/out/zql/src/ivm/filter-push.js +27 -24
  1249. package/out/zql/src/ivm/filter-push.js.map +1 -1
  1250. package/out/zql/src/ivm/filter.d.ts +4 -2
  1251. package/out/zql/src/ivm/filter.d.ts.map +1 -1
  1252. package/out/zql/src/ivm/filter.js +36 -32
  1253. package/out/zql/src/ivm/filter.js.map +1 -1
  1254. package/out/zql/src/ivm/flipped-join.d.ts +1 -2
  1255. package/out/zql/src/ivm/flipped-join.d.ts.map +1 -1
  1256. package/out/zql/src/ivm/flipped-join.js +372 -325
  1257. package/out/zql/src/ivm/flipped-join.js.map +1 -1
  1258. package/out/zql/src/ivm/join-utils.d.ts +9 -2
  1259. package/out/zql/src/ivm/join-utils.d.ts.map +1 -1
  1260. package/out/zql/src/ivm/join-utils.js +104 -78
  1261. package/out/zql/src/ivm/join-utils.js.map +1 -1
  1262. package/out/zql/src/ivm/join.d.ts +3 -16
  1263. package/out/zql/src/ivm/join.d.ts.map +1 -1
  1264. package/out/zql/src/ivm/join.js +225 -211
  1265. package/out/zql/src/ivm/join.js.map +1 -1
  1266. package/out/zql/src/ivm/maybe-split-and-push-edit-change.d.ts +1 -1
  1267. package/out/zql/src/ivm/maybe-split-and-push-edit-change.d.ts.map +1 -1
  1268. package/out/zql/src/ivm/maybe-split-and-push-edit-change.js +26 -24
  1269. package/out/zql/src/ivm/maybe-split-and-push-edit-change.js.map +1 -1
  1270. package/out/zql/src/ivm/memory-source.d.ts +9 -8
  1271. package/out/zql/src/ivm/memory-source.d.ts.map +1 -1
  1272. package/out/zql/src/ivm/memory-source.js +484 -491
  1273. package/out/zql/src/ivm/memory-source.js.map +1 -1
  1274. package/out/zql/src/ivm/memory-storage.js +32 -31
  1275. package/out/zql/src/ivm/memory-storage.js.map +1 -1
  1276. package/out/zql/src/ivm/operator.d.ts +15 -12
  1277. package/out/zql/src/ivm/operator.d.ts.map +1 -1
  1278. package/out/zql/src/ivm/operator.js +16 -9
  1279. package/out/zql/src/ivm/operator.js.map +1 -1
  1280. package/out/zql/src/ivm/push-accumulated.d.ts +2 -2
  1281. package/out/zql/src/ivm/push-accumulated.d.ts.map +1 -1
  1282. package/out/zql/src/ivm/push-accumulated.js +236 -305
  1283. package/out/zql/src/ivm/push-accumulated.js.map +1 -1
  1284. package/out/zql/src/ivm/skip.d.ts +2 -3
  1285. package/out/zql/src/ivm/skip.d.ts.map +1 -1
  1286. package/out/zql/src/ivm/skip.js +95 -106
  1287. package/out/zql/src/ivm/skip.js.map +1 -1
  1288. package/out/zql/src/ivm/source.d.ts +18 -8
  1289. package/out/zql/src/ivm/source.d.ts.map +1 -1
  1290. package/out/zql/src/ivm/stream.d.ts +2 -0
  1291. package/out/zql/src/ivm/stream.d.ts.map +1 -1
  1292. package/out/zql/src/ivm/stream.js +12 -17
  1293. package/out/zql/src/ivm/stream.js.map +1 -1
  1294. package/out/zql/src/ivm/take.d.ts +2 -3
  1295. package/out/zql/src/ivm/take.d.ts.map +1 -1
  1296. package/out/zql/src/ivm/take.js +525 -451
  1297. package/out/zql/src/ivm/take.js.map +1 -1
  1298. package/out/zql/src/ivm/union-fan-in.d.ts +4 -4
  1299. package/out/zql/src/ivm/union-fan-in.d.ts.map +1 -1
  1300. package/out/zql/src/ivm/union-fan-in.js +213 -132
  1301. package/out/zql/src/ivm/union-fan-in.js.map +1 -1
  1302. package/out/zql/src/ivm/union-fan-out.d.ts +2 -3
  1303. package/out/zql/src/ivm/union-fan-out.d.ts.map +1 -1
  1304. package/out/zql/src/ivm/union-fan-out.js +43 -45
  1305. package/out/zql/src/ivm/union-fan-out.js.map +1 -1
  1306. package/out/zql/src/ivm/view-apply-change.d.ts.map +1 -1
  1307. package/out/zql/src/ivm/view-apply-change.js +247 -217
  1308. package/out/zql/src/ivm/view-apply-change.js.map +1 -1
  1309. package/out/zql/src/ivm/view.d.ts +3 -2
  1310. package/out/zql/src/ivm/view.d.ts.map +1 -1
  1311. package/out/zql/src/mutate/crud.d.ts +116 -0
  1312. package/out/zql/src/mutate/crud.d.ts.map +1 -0
  1313. package/out/zql/src/mutate/crud.js +41 -0
  1314. package/out/zql/src/mutate/crud.js.map +1 -0
  1315. package/out/zql/src/mutate/custom.d.ts +39 -63
  1316. package/out/zql/src/mutate/custom.d.ts.map +1 -1
  1317. package/out/zql/src/mutate/custom.js +12 -8
  1318. package/out/zql/src/mutate/custom.js.map +1 -1
  1319. package/out/zql/src/mutate/mutator-registry.d.ts +112 -0
  1320. package/out/zql/src/mutate/mutator-registry.d.ts.map +1 -0
  1321. package/out/zql/src/mutate/mutator-registry.js +88 -0
  1322. package/out/zql/src/mutate/mutator-registry.js.map +1 -0
  1323. package/out/zql/src/mutate/mutator.d.ts +94 -0
  1324. package/out/zql/src/mutate/mutator.d.ts.map +1 -0
  1325. package/out/zql/src/mutate/mutator.js +34 -0
  1326. package/out/zql/src/mutate/mutator.js.map +1 -0
  1327. package/out/zql/src/planner/planner-builder.d.ts +2 -1
  1328. package/out/zql/src/planner/planner-builder.d.ts.map +1 -1
  1329. package/out/zql/src/planner/planner-builder.js +239 -148
  1330. package/out/zql/src/planner/planner-builder.js.map +1 -1
  1331. package/out/zql/src/planner/planner-connection.d.ts +14 -15
  1332. package/out/zql/src/planner/planner-connection.d.ts.map +1 -1
  1333. package/out/zql/src/planner/planner-connection.js +205 -247
  1334. package/out/zql/src/planner/planner-connection.js.map +1 -1
  1335. package/out/zql/src/planner/planner-constraint.js +8 -11
  1336. package/out/zql/src/planner/planner-constraint.js.map +1 -1
  1337. package/out/zql/src/planner/planner-debug.d.ts +39 -44
  1338. package/out/zql/src/planner/planner-debug.d.ts.map +1 -1
  1339. package/out/zql/src/planner/planner-debug.js +227 -161
  1340. package/out/zql/src/planner/planner-debug.js.map +1 -1
  1341. package/out/zql/src/planner/planner-fan-in.d.ts.map +1 -1
  1342. package/out/zql/src/planner/planner-fan-in.js +157 -159
  1343. package/out/zql/src/planner/planner-fan-in.js.map +1 -1
  1344. package/out/zql/src/planner/planner-fan-out.d.ts.map +1 -1
  1345. package/out/zql/src/planner/planner-fan-out.js +73 -59
  1346. package/out/zql/src/planner/planner-fan-out.js.map +1 -1
  1347. package/out/zql/src/planner/planner-graph.d.ts +10 -9
  1348. package/out/zql/src/planner/planner-graph.d.ts.map +1 -1
  1349. package/out/zql/src/planner/planner-graph.js +323 -357
  1350. package/out/zql/src/planner/planner-graph.js.map +1 -1
  1351. package/out/zql/src/planner/planner-join.d.ts +7 -3
  1352. package/out/zql/src/planner/planner-join.d.ts.map +1 -1
  1353. package/out/zql/src/planner/planner-join.js +239 -322
  1354. package/out/zql/src/planner/planner-join.js.map +1 -1
  1355. package/out/zql/src/planner/planner-node.d.ts +6 -1
  1356. package/out/zql/src/planner/planner-node.d.ts.map +1 -1
  1357. package/out/zql/src/planner/planner-node.js +8 -2
  1358. package/out/zql/src/planner/planner-node.js.map +1 -1
  1359. package/out/zql/src/planner/planner-source.js +23 -12
  1360. package/out/zql/src/planner/planner-source.js.map +1 -1
  1361. package/out/zql/src/planner/planner-terminus.js +28 -27
  1362. package/out/zql/src/planner/planner-terminus.js.map +1 -1
  1363. package/out/zql/src/query/complete-ordering.d.ts +5 -0
  1364. package/out/zql/src/query/complete-ordering.d.ts.map +1 -0
  1365. package/out/zql/src/query/complete-ordering.js +71 -0
  1366. package/out/zql/src/query/complete-ordering.js.map +1 -0
  1367. package/out/zql/src/query/create-builder.d.ts +10 -0
  1368. package/out/zql/src/query/create-builder.d.ts.map +1 -0
  1369. package/out/zql/src/query/create-builder.js +32 -0
  1370. package/out/zql/src/query/create-builder.js.map +1 -0
  1371. package/out/zql/src/query/error.js +12 -8
  1372. package/out/zql/src/query/error.js.map +1 -1
  1373. package/out/zql/src/query/escape-like.js +7 -0
  1374. package/out/zql/src/query/escape-like.js.map +1 -0
  1375. package/out/zql/src/query/expression.d.ts +5 -5
  1376. package/out/zql/src/query/expression.d.ts.map +1 -1
  1377. package/out/zql/src/query/expression.js +153 -151
  1378. package/out/zql/src/query/expression.js.map +1 -1
  1379. package/out/zql/src/query/measure-push-operator.d.ts +2 -3
  1380. package/out/zql/src/query/measure-push-operator.d.ts.map +1 -1
  1381. package/out/zql/src/query/measure-push-operator.js +39 -35
  1382. package/out/zql/src/query/measure-push-operator.js.map +1 -1
  1383. package/out/zql/src/query/metrics-delegate.js +9 -5
  1384. package/out/zql/src/query/metrics-delegate.js.map +1 -1
  1385. package/out/zql/src/query/named.d.ts +21 -12
  1386. package/out/zql/src/query/named.d.ts.map +1 -1
  1387. package/out/zql/src/query/named.js +46 -64
  1388. package/out/zql/src/query/named.js.map +1 -1
  1389. package/out/zql/src/query/query-delegate-base.d.ts +120 -0
  1390. package/out/zql/src/query/query-delegate-base.d.ts.map +1 -0
  1391. package/out/zql/src/query/query-delegate-base.js +250 -0
  1392. package/out/zql/src/query/query-delegate-base.js.map +1 -0
  1393. package/out/zql/src/query/query-delegate.d.ts +27 -4
  1394. package/out/zql/src/query/query-delegate.d.ts.map +1 -1
  1395. package/out/zql/src/query/query-impl.d.ts +30 -52
  1396. package/out/zql/src/query/query-impl.d.ts.map +1 -1
  1397. package/out/zql/src/query/query-impl.js +393 -459
  1398. package/out/zql/src/query/query-impl.js.map +1 -1
  1399. package/out/zql/src/query/query-internals.d.ts +68 -0
  1400. package/out/zql/src/query/query-internals.d.ts.map +1 -0
  1401. package/out/zql/src/query/query-internals.js +11 -0
  1402. package/out/zql/src/query/query-internals.js.map +1 -0
  1403. package/out/zql/src/query/query-registry.d.ts +239 -0
  1404. package/out/zql/src/query/query-registry.d.ts.map +1 -0
  1405. package/out/zql/src/query/query-registry.js +121 -0
  1406. package/out/zql/src/query/query-registry.js.map +1 -0
  1407. package/out/zql/src/query/query.d.ts +65 -242
  1408. package/out/zql/src/query/query.d.ts.map +1 -1
  1409. package/out/zql/src/query/runnable-query-impl.d.ts +22 -0
  1410. package/out/zql/src/query/runnable-query-impl.d.ts.map +1 -0
  1411. package/out/zql/src/query/runnable-query-impl.js +60 -0
  1412. package/out/zql/src/query/runnable-query-impl.js.map +1 -0
  1413. package/out/zql/src/query/schema-query.d.ts +7 -0
  1414. package/out/zql/src/query/schema-query.d.ts.map +1 -0
  1415. package/out/zql/src/query/static-query.d.ts +3 -25
  1416. package/out/zql/src/query/static-query.d.ts.map +1 -1
  1417. package/out/zql/src/query/static-query.js +18 -32
  1418. package/out/zql/src/query/static-query.js.map +1 -1
  1419. package/out/zql/src/query/ttl.js +69 -62
  1420. package/out/zql/src/query/ttl.js.map +1 -1
  1421. package/out/zql/src/query/validate-input.d.ts +15 -0
  1422. package/out/zql/src/query/validate-input.d.ts.map +1 -0
  1423. package/out/zql/src/query/validate-input.js +24 -0
  1424. package/out/zql/src/query/validate-input.js.map +1 -0
  1425. package/out/zqlite/src/database-storage.d.ts +1 -1
  1426. package/out/zqlite/src/database-storage.d.ts.map +1 -1
  1427. package/out/zqlite/src/database-storage.js +99 -102
  1428. package/out/zqlite/src/database-storage.js.map +1 -1
  1429. package/out/zqlite/src/db.d.ts +2 -1
  1430. package/out/zqlite/src/db.d.ts.map +1 -1
  1431. package/out/zqlite/src/db.js +241 -192
  1432. package/out/zqlite/src/db.js.map +1 -1
  1433. package/out/zqlite/src/explain-queries.js +13 -16
  1434. package/out/zqlite/src/explain-queries.js.map +1 -1
  1435. package/out/zqlite/src/internal/sql-inline.d.ts +13 -0
  1436. package/out/zqlite/src/internal/sql-inline.d.ts.map +1 -0
  1437. package/out/zqlite/src/internal/sql-inline.js +45 -0
  1438. package/out/zqlite/src/internal/sql-inline.js.map +1 -0
  1439. package/out/zqlite/src/internal/sql.js +15 -10
  1440. package/out/zqlite/src/internal/sql.js.map +1 -1
  1441. package/out/zqlite/src/internal/statement-cache.js +86 -110
  1442. package/out/zqlite/src/internal/statement-cache.js.map +1 -1
  1443. package/out/zqlite/src/query-builder.js +172 -143
  1444. package/out/zqlite/src/query-builder.js.map +1 -1
  1445. package/out/zqlite/src/query-delegate.d.ts +5 -19
  1446. package/out/zqlite/src/query-delegate.d.ts.map +1 -1
  1447. package/out/zqlite/src/query-delegate.js +56 -70
  1448. package/out/zqlite/src/query-delegate.js.map +1 -1
  1449. package/out/zqlite/src/sqlite-cost-model.d.ts.map +1 -1
  1450. package/out/zqlite/src/sqlite-cost-model.js +97 -121
  1451. package/out/zqlite/src/sqlite-cost-model.js.map +1 -1
  1452. package/out/zqlite/src/sqlite-stat-fanout.d.ts +121 -0
  1453. package/out/zqlite/src/sqlite-stat-fanout.d.ts.map +1 -0
  1454. package/out/zqlite/src/sqlite-stat-fanout.js +301 -0
  1455. package/out/zqlite/src/sqlite-stat-fanout.js.map +1 -0
  1456. package/out/zqlite/src/table-source.d.ts +18 -6
  1457. package/out/zqlite/src/table-source.d.ts.map +1 -1
  1458. package/out/zqlite/src/table-source.js +443 -311
  1459. package/out/zqlite/src/table-source.js.map +1 -1
  1460. package/package.json +32 -29
  1461. package/out/chunk-424PT5DM.js +0 -23
  1462. package/out/chunk-424PT5DM.js.map +0 -7
  1463. package/out/chunk-AFADJQ2O.js +0 -1
  1464. package/out/chunk-AFADJQ2O.js.map +0 -7
  1465. package/out/chunk-ASRS2LFV.js.map +0 -7
  1466. package/out/chunk-ECUMGQGC.js.map +0 -7
  1467. package/out/chunk-EZM3XBAB.js.map +0 -7
  1468. package/out/chunk-QZSBDHTA.js +0 -18337
  1469. package/out/chunk-QZSBDHTA.js.map +0 -7
  1470. package/out/chunk-TJFNGO7E.js +0 -4126
  1471. package/out/chunk-TJFNGO7E.js.map +0 -7
  1472. package/out/chunk-VZOYWIRW.js +0 -30
  1473. package/out/chunk-VZOYWIRW.js.map +0 -7
  1474. package/out/chunk-YTVU4GOY.js +0 -372
  1475. package/out/chunk-YTVU4GOY.js.map +0 -7
  1476. package/out/chunk-ZZXMKAAG.js.map +0 -7
  1477. package/out/expo-sqlite.js +0 -11
  1478. package/out/expo-sqlite.js.map +0 -7
  1479. package/out/inspector-IU2HG74I.js +0 -43
  1480. package/out/inspector-IU2HG74I.js.map +0 -7
  1481. package/out/lazy-inspector-OXIFYSSQ.js +0 -574
  1482. package/out/lazy-inspector-OXIFYSSQ.js.map +0 -7
  1483. package/out/op-sqlite.js.map +0 -7
  1484. package/out/react-native.js +0 -25
  1485. package/out/react-native.js.map +0 -7
  1486. package/out/react.js +0 -479
  1487. package/out/react.js.map +0 -7
  1488. package/out/shared/src/enum.js +0 -2
  1489. package/out/shared/src/enum.js.map +0 -1
  1490. package/out/shared/src/expand.js +0 -2
  1491. package/out/shared/src/expand.js.map +0 -1
  1492. package/out/shared/src/immutable.js +0 -2
  1493. package/out/shared/src/immutable.js.map +0 -1
  1494. package/out/shared/src/types.js +0 -2
  1495. package/out/shared/src/types.js.map +0 -1
  1496. package/out/shared/src/writable.js +0 -2
  1497. package/out/shared/src/writable.js.map +0 -1
  1498. package/out/solid.js.map +0 -7
  1499. package/out/sqlite.js +0 -15
  1500. package/out/sqlite.js.map +0 -7
  1501. package/out/zero/package.json +0 -194
  1502. package/out/zero/src/server/change-streamer.js +0 -2
  1503. package/out/zero/src/server/change-streamer.js.map +0 -1
  1504. package/out/zero/src/server/main.js +0 -2
  1505. package/out/zero/src/server/main.js.map +0 -1
  1506. package/out/zero/src/server/reaper.js +0 -2
  1507. package/out/zero/src/server/reaper.js.map +0 -1
  1508. package/out/zero/src/server/replicator.js +0 -2
  1509. package/out/zero/src/server/replicator.js.map +0 -1
  1510. package/out/zero/src/server/runner/main.js +0 -2
  1511. package/out/zero/src/server/runner/main.js.map +0 -1
  1512. package/out/zero/src/server/syncer.js +0 -2
  1513. package/out/zero/src/server/syncer.js.map +0 -1
  1514. package/out/zero-cache/src/services/change-source/pg/logical-replication/pgoutput.types.js +0 -4
  1515. package/out/zero-cache/src/services/change-source/pg/logical-replication/pgoutput.types.js.map +0 -1
  1516. package/out/zero-cache/src/services/change-source/protocol/mod.js +0 -5
  1517. package/out/zero-cache/src/services/change-source/protocol/mod.js.map +0 -1
  1518. package/out/zero-cache/src/services/service.js +0 -2
  1519. package/out/zero-cache/src/services/service.js.map +0 -1
  1520. package/out/zero-cache/src/services/view-syncer/key-columns.d.ts +0 -32
  1521. package/out/zero-cache/src/services/view-syncer/key-columns.d.ts.map +0 -1
  1522. package/out/zero-cache/src/services/view-syncer/key-columns.js +0 -75
  1523. package/out/zero-cache/src/services/view-syncer/key-columns.js.map +0 -1
  1524. package/out/zero-cache/src/types/satisfies.js +0 -2
  1525. package/out/zero-cache/src/types/satisfies.js.map +0 -1
  1526. package/out/zero-client/src/client/on-error.d.ts +0 -15
  1527. package/out/zero-client/src/client/on-error.d.ts.map +0 -1
  1528. package/out/zero-client/src/client/zero-log-context.d.ts +0 -7
  1529. package/out/zero-client/src/client/zero-log-context.d.ts.map +0 -1
  1530. package/out/zero-events/src/index.js +0 -2
  1531. package/out/zero-events/src/index.js.map +0 -1
  1532. package/out/zero-events/src/json.js +0 -2
  1533. package/out/zero-events/src/json.js.map +0 -1
  1534. package/out/zero-events/src/status.js +0 -3
  1535. package/out/zero-events/src/status.js.map +0 -1
  1536. package/out/zero-pg/src/mod.js +0 -6
  1537. package/out/zero-pg/src/mod.js.map +0 -1
  1538. package/out/zero-protocol/src/error-kind.js +0 -3
  1539. package/out/zero-protocol/src/error-kind.js.map +0 -1
  1540. package/out/zero-protocol/src/error-origin.js +0 -3
  1541. package/out/zero-protocol/src/error-origin.js.map +0 -1
  1542. package/out/zero-protocol/src/error-reason.js +0 -3
  1543. package/out/zero-protocol/src/error-reason.js.map +0 -1
  1544. package/out/zero-react/src/components/inspector.d.ts +0 -8
  1545. package/out/zero-react/src/components/inspector.d.ts.map +0 -1
  1546. package/out/zero-react/src/components/mark-icon.d.ts +0 -3
  1547. package/out/zero-react/src/components/mark-icon.d.ts.map +0 -1
  1548. package/out/zero-react/src/components/zero-inspector.d.ts +0 -7
  1549. package/out/zero-react/src/components/zero-inspector.d.ts.map +0 -1
  1550. package/out/zero-react/src/use-zero-connection-state.d.ts +0 -9
  1551. package/out/zero-react/src/use-zero-connection-state.d.ts.map +0 -1
  1552. package/out/zero-schema/src/server-schema.d.ts.map +0 -1
  1553. package/out/zero-schema/src/server-schema.js +0 -2
  1554. package/out/zero-schema/src/server-schema.js.map +0 -1
  1555. package/out/zero-schema/src/table-schema.js +0 -7
  1556. package/out/zero-schema/src/table-schema.js.map +0 -1
  1557. package/out/zero-server/src/mod.js +0 -9
  1558. package/out/zero-server/src/mod.js.map +0 -1
  1559. package/out/zero-server/src/query.d.ts +0 -22
  1560. package/out/zero-server/src/query.d.ts.map +0 -1
  1561. package/out/zero-server/src/query.js +0 -61
  1562. package/out/zero-server/src/query.js.map +0 -1
  1563. package/out/zero-solid/src/use-zero-connection-state.d.ts.map +0 -1
  1564. package/out/zero-types/src/schema-value.js +0 -2
  1565. package/out/zero-types/src/schema-value.js.map +0 -1
  1566. package/out/zero-types/src/schema.js +0 -2
  1567. package/out/zero-types/src/schema.js.map +0 -1
  1568. package/out/zero.js +0 -81
  1569. package/out/zero.js.map +0 -7
  1570. package/out/zql/src/ivm/change.js +0 -2
  1571. package/out/zql/src/ivm/change.js.map +0 -1
  1572. package/out/zql/src/ivm/default-format.js +0 -2
  1573. package/out/zql/src/ivm/default-format.js.map +0 -1
  1574. package/out/zql/src/ivm/schema.js +0 -2
  1575. package/out/zql/src/ivm/schema.js.map +0 -1
  1576. package/out/zql/src/ivm/source.js +0 -2
  1577. package/out/zql/src/ivm/source.js.map +0 -1
  1578. package/out/zql/src/ivm/view.js +0 -2
  1579. package/out/zql/src/ivm/view.js.map +0 -1
  1580. package/out/zql/src/query/query-delegate.js +0 -2
  1581. package/out/zql/src/query/query-delegate.js.map +0 -1
  1582. package/out/zql/src/query/query.js +0 -9
  1583. package/out/zql/src/query/query.js.map +0 -1
  1584. package/out/zql/src/query/typed-view.js +0 -2
  1585. package/out/zql/src/query/typed-view.js.map +0 -1
  1586. package/out/zqlite/src/mod.js +0 -5
  1587. package/out/zqlite/src/mod.js.map +0 -1
  1588. /package/out/{zero-schema → zero-types}/src/server-schema.d.ts +0 -0
@@ -1,4126 +0,0 @@
1
- import {
2
- assert,
3
- assertArray,
4
- assertBoolean,
5
- assertDeepFrozen,
6
- assertNumber,
7
- assertObject,
8
- assertString,
9
- deepFreeze,
10
- hasOwn,
11
- isProd,
12
- throwInvalidType,
13
- unreachable
14
- } from "./chunk-EZM3XBAB.js";
15
- import {
16
- __export,
17
- __reExport
18
- } from "./chunk-424PT5DM.js";
19
-
20
- // ../replicache/src/format-version-enum.ts
21
- var DD31 = 5;
22
- var V6 = 6;
23
- var V7 = 7;
24
- var Latest = V7;
25
-
26
- // ../shared/src/valita.ts
27
- var valita_exports = {};
28
- __export(valita_exports, {
29
- assert: () => assert2,
30
- deepPartial: () => deepPartial,
31
- instanceOfAbstractType: () => instanceOfAbstractType,
32
- is: () => is,
33
- literalUnion: () => literalUnion,
34
- parse: () => parse,
35
- readonly: () => readonly,
36
- readonlyArray: () => readonlyArray,
37
- readonlyObject: () => readonlyObject,
38
- readonlyRecord: () => readonlyRecord,
39
- test: () => test,
40
- testOptional: () => testOptional
41
- });
42
- __reExport(valita_exports, valita_star);
43
- import * as v from "@badrap/valita";
44
- import * as valita_star from "@badrap/valita";
45
- function toDisplay(value) {
46
- switch (typeof value) {
47
- case "string":
48
- case "number":
49
- case "boolean":
50
- return JSON.stringify(value);
51
- case "undefined":
52
- return "undefined";
53
- case "bigint":
54
- return value.toString() + "n";
55
- default:
56
- if (value === null) {
57
- return "null";
58
- }
59
- if (Array.isArray(value)) {
60
- return "array";
61
- }
62
- return typeof value;
63
- }
64
- }
65
- function toDisplayAtPath(v2, path2) {
66
- if (!path2?.length) {
67
- return toDisplay(v2);
68
- }
69
- let cur = v2;
70
- for (const p of path2) {
71
- cur = cur[p];
72
- }
73
- return toDisplay(cur);
74
- }
75
- function displayList(word, expected, toDisplay2 = (x) => String(x)) {
76
- if (expected.length === 1) {
77
- return toDisplay2(expected[0]);
78
- }
79
- const suffix = `${toDisplay2(
80
- expected[expected.length - 2]
81
- )} ${word} ${toDisplay2(expected[expected.length - 1])}`;
82
- if (expected.length === 2) {
83
- return suffix;
84
- }
85
- return `${expected.slice(0, -2).map(toDisplay2).join(", ")}, ${suffix}`;
86
- }
87
- function getMessage(err2, v2, schema, mode) {
88
- const firstIssue = err2.issues[0];
89
- const { path: path2 } = firstIssue;
90
- const atPath = path2?.length ? ` at ${path2.join(".")}` : "";
91
- switch (firstIssue.code) {
92
- case "invalid_type":
93
- return `Expected ${displayList(
94
- "or",
95
- firstIssue.expected
96
- )}${atPath}. Got ${toDisplayAtPath(v2, path2)}`;
97
- case "missing_value": {
98
- const atPath2 = path2 && path2.length > 1 ? ` at ${path2.slice(0, -1).join(".")}` : "";
99
- if (firstIssue.path?.length) {
100
- return `Missing property ${firstIssue.path.at(-1)}${atPath2}`;
101
- }
102
- return `TODO Unknown missing property${atPath2}`;
103
- }
104
- case "invalid_literal":
105
- return `Expected literal value ${displayList(
106
- "or",
107
- firstIssue.expected,
108
- toDisplay
109
- )}${atPath} Got ${toDisplayAtPath(v2, path2)}`;
110
- case "invalid_length": {
111
- return `Expected array with length ${firstIssue.minLength === firstIssue.maxLength ? firstIssue.minLength : `between ${firstIssue.minLength} and ${firstIssue.maxLength}`}${atPath}. Got array with length ${v2.length}`;
112
- }
113
- case "unrecognized_keys":
114
- if (firstIssue.keys.length === 1) {
115
- return `Unexpected property ${firstIssue.keys[0]}${atPath}`;
116
- }
117
- return `Unexpected properties ${displayList(
118
- "and",
119
- firstIssue.keys
120
- )}${atPath}`;
121
- case "invalid_union":
122
- return schema.name === "union" ? getDeepestUnionParseError(v2, schema, mode ?? "strict") : `Invalid union value${atPath}`;
123
- case "custom_error": {
124
- const { error } = firstIssue;
125
- const message = !error ? "unknown" : typeof error === "string" ? error : error.message ?? "unknown";
126
- return `${message}${atPath}. Got ${toDisplayAtPath(v2, path2)}`;
127
- }
128
- }
129
- }
130
- function getDeepestUnionParseError(value, schema, mode) {
131
- const failures = [];
132
- for (const type of schema.options) {
133
- const r = type.try(value, { mode });
134
- if (!r.ok) {
135
- failures.push({ type, err: r });
136
- }
137
- }
138
- if (failures.length) {
139
- failures.sort(pathCmp);
140
- if (failures.length === 1 || pathCmp(failures[0], failures[1]) < 0) {
141
- return getMessage(failures[0].err, value, failures[0].type, mode);
142
- }
143
- }
144
- try {
145
- const str = JSON.stringify(value);
146
- return `Invalid union value: ${str}`;
147
- } catch {
148
- return `Invalid union value`;
149
- }
150
- }
151
- function pathCmp(a, b) {
152
- const aPath = a.err.issues[0].path;
153
- const bPath = b.err.issues[0].path;
154
- if (aPath.length !== bPath.length) {
155
- return bPath.length - aPath.length;
156
- }
157
- for (let i = 0; i < aPath.length; i++) {
158
- if (bPath[i] > aPath[i]) {
159
- return -1;
160
- }
161
- if (bPath[i] < aPath[i]) {
162
- return 1;
163
- }
164
- }
165
- return 0;
166
- }
167
- function parse(value, schema, mode) {
168
- const res = test(value, schema, mode);
169
- if (!res.ok) {
170
- throw new TypeError(res.error);
171
- }
172
- return res.value;
173
- }
174
- function is(value, schema, mode) {
175
- return test(value, schema, mode).ok;
176
- }
177
- function assert2(value, schema, mode) {
178
- parse(value, schema, mode);
179
- }
180
- function test(value, schema, mode) {
181
- const res = schema.try(value, mode ? { mode } : void 0);
182
- if (!res.ok) {
183
- return {
184
- ok: false,
185
- error: getMessage(res, value, schema, mode)
186
- };
187
- }
188
- return res;
189
- }
190
- function testOptional(value, schema, mode) {
191
- let flags = 1;
192
- if (mode === "passthrough") {
193
- flags = 0;
194
- } else if (mode === "strip") {
195
- flags = 2;
196
- }
197
- const res = schema.func(value, flags);
198
- if (res === void 0) {
199
- return { ok: true, value };
200
- } else if (res.ok) {
201
- return res;
202
- }
203
- const err2 = new v.ValitaError(res);
204
- return { ok: false, error: getMessage(err2, value, schema, mode) };
205
- }
206
- function readonly(t) {
207
- return t;
208
- }
209
- function readonlyObject(t) {
210
- return v.object(t);
211
- }
212
- function readonlyArray(t) {
213
- return v.array(t);
214
- }
215
- function readonlyRecord(t) {
216
- return v.record(t);
217
- }
218
- var AbstractType = Object.getPrototypeOf(
219
- Object.getPrototypeOf(v.string().optional())
220
- ).constructor;
221
- function instanceOfAbstractType(obj) {
222
- return obj instanceof AbstractType;
223
- }
224
- function deepPartial(s) {
225
- const shape = {};
226
- for (const [key, type] of Object.entries(s.shape)) {
227
- if (type.name === "object") {
228
- shape[key] = deepPartial(type).optional();
229
- } else {
230
- shape[key] = type.optional();
231
- }
232
- }
233
- return v.object(shape);
234
- }
235
- function literalUnion(...literals) {
236
- return v.union(...literals.map(v.literal));
237
- }
238
-
239
- // ../shared/src/json.ts
240
- function deepEqual(a, b) {
241
- if (a === b) {
242
- return true;
243
- }
244
- if (typeof a !== typeof b) {
245
- return false;
246
- }
247
- switch (typeof a) {
248
- case "boolean":
249
- case "number":
250
- case "string":
251
- return false;
252
- }
253
- a = a;
254
- if (Array.isArray(a)) {
255
- if (!Array.isArray(b)) {
256
- return false;
257
- }
258
- if (a.length !== b.length) {
259
- return false;
260
- }
261
- for (let i = 0; i < a.length; i++) {
262
- if (!deepEqual(a[i], b[i])) {
263
- return false;
264
- }
265
- }
266
- return true;
267
- }
268
- if (a === null || b === null) {
269
- return false;
270
- }
271
- if (Array.isArray(b)) {
272
- return false;
273
- }
274
- a = a;
275
- b = b;
276
- let aSize = 0;
277
- for (const key in a) {
278
- if (hasOwn(a, key)) {
279
- if (!deepEqual(a[key], b[key])) {
280
- return false;
281
- }
282
- aSize++;
283
- }
284
- }
285
- let bSize = 0;
286
- for (const key in b) {
287
- if (hasOwn(b, key)) {
288
- bSize++;
289
- }
290
- }
291
- return aSize === bSize;
292
- }
293
- function assertJSONValue(v2) {
294
- if (isProd) {
295
- return;
296
- }
297
- switch (typeof v2) {
298
- case "boolean":
299
- case "number":
300
- case "string":
301
- return;
302
- case "object":
303
- if (v2 === null) {
304
- return;
305
- }
306
- if (Array.isArray(v2)) {
307
- return assertJSONArray(v2);
308
- }
309
- return assertObjectIsJSONObject(v2);
310
- }
311
- throwInvalidType(v2, "JSON value");
312
- }
313
- function assertJSONObject(v2) {
314
- assertObject(v2);
315
- assertObjectIsJSONObject(v2);
316
- }
317
- function assertObjectIsJSONObject(v2) {
318
- for (const k in v2) {
319
- if (hasOwn(v2, k)) {
320
- const value = v2[k];
321
- if (value !== void 0) {
322
- assertJSONValue(value);
323
- }
324
- }
325
- }
326
- }
327
- function assertJSONArray(v2) {
328
- for (const item of v2) {
329
- assertJSONValue(item);
330
- }
331
- }
332
- function isJSONValue(v2, path2) {
333
- switch (typeof v2) {
334
- case "boolean":
335
- case "number":
336
- case "string":
337
- return true;
338
- case "object":
339
- if (v2 === null) {
340
- return true;
341
- }
342
- if (Array.isArray(v2)) {
343
- return isJSONArray(v2, path2);
344
- }
345
- return objectIsJSONObject(v2, path2);
346
- }
347
- return false;
348
- }
349
- function isJSONObject(v2, path2) {
350
- if (typeof v2 !== "object" || v2 === null) {
351
- return false;
352
- }
353
- return objectIsJSONObject(v2, path2);
354
- }
355
- function objectIsJSONObject(v2, path2) {
356
- for (const k in v2) {
357
- if (hasOwn(v2, k)) {
358
- path2.push(k);
359
- const value = v2[k];
360
- if (value !== void 0 && !isJSONValue(value, path2)) {
361
- return false;
362
- }
363
- path2.pop();
364
- }
365
- }
366
- return true;
367
- }
368
- function isJSONArray(v2, path2) {
369
- for (let i = 0; i < v2.length; i++) {
370
- path2.push(i);
371
- if (!isJSONValue(v2[i], path2)) {
372
- return false;
373
- }
374
- path2.pop();
375
- }
376
- return true;
377
- }
378
-
379
- // ../shared/src/size-of-value.ts
380
- var SIZE_TAG = 1;
381
- var SIZE_INT32 = 4;
382
- var SIZE_SMI = 5;
383
- var SIZE_DOUBLE = 8;
384
- function getSizeOfValue(value) {
385
- switch (typeof value) {
386
- case "string":
387
- return SIZE_TAG + SIZE_INT32 + value.length;
388
- case "number":
389
- if (isSmi(value)) {
390
- if (value <= -(2 ** 30) || value >= 2 ** 30 - 1) {
391
- return SIZE_TAG + SIZE_SMI;
392
- }
393
- return SIZE_TAG + SIZE_INT32;
394
- }
395
- return SIZE_TAG + SIZE_DOUBLE;
396
- case "boolean":
397
- return SIZE_TAG;
398
- case "object":
399
- if (value === null) {
400
- return SIZE_TAG;
401
- }
402
- if (Array.isArray(value)) {
403
- let sum = 2 * SIZE_TAG + SIZE_INT32;
404
- for (const element of value) {
405
- sum += getSizeOfValue(element);
406
- }
407
- return sum;
408
- }
409
- {
410
- const val = value;
411
- let sum = 2 * SIZE_TAG + SIZE_INT32;
412
- for (const k in val) {
413
- if (hasOwn(val, k)) {
414
- const propertyValue = val[k];
415
- if (propertyValue !== void 0) {
416
- sum += getSizeOfValue(k) + getSizeOfValue(propertyValue);
417
- }
418
- }
419
- }
420
- return sum;
421
- }
422
- }
423
- throw new Error(`Invalid value. type: ${typeof value}, value: ${value}`);
424
- }
425
- function isSmi(value) {
426
- return value === (value | 0);
427
- }
428
- var entryFixed = 2 * SIZE_TAG + SIZE_INT32 + SIZE_TAG + SIZE_INT32;
429
- function getSizeOfEntry(key, value) {
430
- return entryFixed + getSizeOfValue(key) + getSizeOfValue(value);
431
- }
432
-
433
- // ../shared/src/random-uint64.ts
434
- function randomUint64() {
435
- const high = Math.floor(Math.random() * 4294967295);
436
- const low = Math.floor(Math.random() * 4294967295);
437
- return BigInt(high) << 32n | BigInt(low);
438
- }
439
-
440
- // ../replicache/src/hash.ts
441
- var STRING_LENGTH = 22;
442
- var hashRe = /^[0-9a-v-]+$/;
443
- var emptyUUID = "0".repeat(STRING_LENGTH);
444
- var emptyHash = emptyUUID;
445
- var newRandomHash = makeNewRandomHashFunctionInternal();
446
- function toStringAndSlice(n, len) {
447
- return n.toString(32).slice(-len).padStart(len, "0");
448
- }
449
- function makeNewRandomHashFunctionInternal() {
450
- let base = "";
451
- let i = 0;
452
- return () => {
453
- if (!base) {
454
- base = toStringAndSlice(randomUint64(), 12);
455
- }
456
- const tail = toStringAndSlice(i++, 10);
457
- return base + tail;
458
- };
459
- }
460
- function isHash(value) {
461
- return typeof value === "string" && hashRe.test(value);
462
- }
463
- function assertHash(value) {
464
- assert2(value, hashSchema);
465
- }
466
- var hashSchema = valita_exports.string().assert(isHash, "Invalid hash");
467
-
468
- // ../replicache/src/btree/node.ts
469
- import { compareUTF8 } from "compare-utf8";
470
-
471
- // ../shared/src/binary-search.ts
472
- function binarySearch(high, compare) {
473
- let low = 0;
474
- while (low < high) {
475
- const mid = low + (high - low >> 1);
476
- const i = compare(mid);
477
- if (i === 0) {
478
- return mid;
479
- }
480
- if (i > 0) {
481
- low = mid + 1;
482
- } else {
483
- high = mid;
484
- }
485
- }
486
- return low;
487
- }
488
-
489
- // ../shared/src/iterables.ts
490
- function* joinIterables(...iters) {
491
- for (const iter of iters) {
492
- yield* iter;
493
- }
494
- }
495
- function* filterIter(iter, p) {
496
- let index = 0;
497
- for (const t of iter) {
498
- if (p(t, index++)) {
499
- yield t;
500
- }
501
- }
502
- }
503
- function* mapIter(iter, f) {
504
- let index = 0;
505
- for (const t of iter) {
506
- yield f(t, index++);
507
- }
508
- }
509
- function* once(stream) {
510
- const it = stream[Symbol.iterator]();
511
- const { value } = it.next();
512
- if (value !== void 0) {
513
- yield value;
514
- }
515
- it.return?.();
516
- }
517
- var IterWrapper = class _IterWrapper {
518
- iter;
519
- constructor(iter) {
520
- this.iter = iter;
521
- }
522
- [Symbol.iterator]() {
523
- return this.iter[Symbol.iterator]();
524
- }
525
- map(f) {
526
- return new _IterWrapper(mapIter(this.iter, f));
527
- }
528
- filter(p) {
529
- return new _IterWrapper(filterIter(this.iter, p));
530
- }
531
- };
532
- function wrapIterable(iter) {
533
- return new IterWrapper(iter);
534
- }
535
- function* mergeIterables(iterables, comparator, distinct = false) {
536
- const iterators = iterables.map((i) => i[Symbol.iterator]());
537
- try {
538
- const current = iterators.map((i) => i.next());
539
- let lastYielded;
540
- while (current.some((c) => !c.done)) {
541
- const min = current.reduce(
542
- (acc, c, i) => {
543
- if (c.done) {
544
- return acc;
545
- }
546
- if (acc === void 0 || comparator(c.value, acc[0]) < 0) {
547
- return [c.value, i];
548
- }
549
- return acc;
550
- },
551
- void 0
552
- );
553
- assert(min !== void 0, "min is undefined");
554
- current[min[1]] = iterators[min[1]].next();
555
- if (lastYielded !== void 0 && distinct && comparator(lastYielded, min[0]) === 0) {
556
- continue;
557
- }
558
- lastYielded = min[0];
559
- yield min[0];
560
- }
561
- } finally {
562
- for (const it of iterators) {
563
- it.return?.();
564
- }
565
- }
566
- }
567
-
568
- // ../replicache/src/btree/node.ts
569
- var NODE_LEVEL = 0;
570
- var NODE_ENTRIES = 1;
571
- function makeNodeChunkData(level, entries, formatVersion) {
572
- return deepFreeze([
573
- level,
574
- formatVersion >= V7 ? entries : entries.map((e) => e.slice(0, 2))
575
- ]);
576
- }
577
- async function findLeaf(key, hash2, source, expectedRootHash) {
578
- const node = await source.getNode(hash2);
579
- if (expectedRootHash !== source.rootHash) {
580
- return findLeaf(key, source.rootHash, source, source.rootHash);
581
- }
582
- if (isDataNodeImpl(node)) {
583
- return node;
584
- }
585
- const { entries } = node;
586
- let i = binarySearch2(key, entries);
587
- if (i === entries.length) {
588
- i--;
589
- }
590
- const entry = entries[i];
591
- return findLeaf(key, entry[1], source, expectedRootHash);
592
- }
593
- function binarySearch2(key, entries) {
594
- return binarySearch(
595
- entries.length,
596
- (i) => compareUTF8(key, entries[i][0])
597
- );
598
- }
599
- function binarySearchFound(i, entries, key) {
600
- return i !== entries.length && entries[i][0] === key;
601
- }
602
- function parseBTreeNode(v2, formatVersion, getSizeOfEntry2) {
603
- if (isProd && formatVersion >= V7) {
604
- return v2;
605
- }
606
- assertArray(v2);
607
- assertDeepFrozen(v2);
608
- assert(v2.length >= 2);
609
- const [level, entries] = v2;
610
- assertNumber(level);
611
- assertArray(entries);
612
- const f = level > 0 ? assertString : assertJSONValue;
613
- if (formatVersion >= V7) {
614
- for (const e of entries) {
615
- assertEntry(e, f);
616
- }
617
- return v2;
618
- }
619
- const newEntries = entries.map((e) => convertNonV7Entry(e, f, getSizeOfEntry2));
620
- return [level, newEntries];
621
- }
622
- function assertEntry(entry, f) {
623
- assertArray(entry);
624
- assert(entry.length >= 3);
625
- assertString(entry[0]);
626
- f(entry[1]);
627
- assertNumber(entry[2]);
628
- }
629
- function convertNonV7Entry(entry, f, getSizeOfEntry2) {
630
- assertArray(entry);
631
- assert(entry.length >= 2);
632
- assertString(entry[0]);
633
- f(entry[1]);
634
- const entrySize = getSizeOfEntry2(entry[0], entry[1]);
635
- return [entry[0], entry[1], entrySize];
636
- }
637
- var NodeImpl = class {
638
- entries;
639
- hash;
640
- isMutable;
641
- #childNodeSize = -1;
642
- constructor(entries, hash2, isMutable) {
643
- this.entries = entries;
644
- this.hash = hash2;
645
- this.isMutable = isMutable;
646
- }
647
- maxKey() {
648
- return this.entries[this.entries.length - 1][0];
649
- }
650
- getChildNodeSize(tree) {
651
- if (this.#childNodeSize !== -1) {
652
- return this.#childNodeSize;
653
- }
654
- let sum = tree.chunkHeaderSize;
655
- for (const entry of this.entries) {
656
- sum += entry[2];
657
- }
658
- return this.#childNodeSize = sum;
659
- }
660
- _updateNode(tree) {
661
- this.#childNodeSize = -1;
662
- tree.updateNode(
663
- this
664
- );
665
- }
666
- };
667
- function toChunkData(node, formatVersion) {
668
- return makeNodeChunkData(node.level, node.entries, formatVersion);
669
- }
670
- var DataNodeImpl = class extends NodeImpl {
671
- level = 0;
672
- set(key, value, entrySize, tree) {
673
- let deleteCount;
674
- const i = binarySearch2(key, this.entries);
675
- if (!binarySearchFound(i, this.entries, key)) {
676
- deleteCount = 0;
677
- } else {
678
- deleteCount = 1;
679
- }
680
- return Promise.resolve(
681
- this.#splice(tree, i, deleteCount, [key, value, entrySize])
682
- );
683
- }
684
- #splice(tree, start, deleteCount, ...items) {
685
- if (this.isMutable) {
686
- this.entries.splice(start, deleteCount, ...items);
687
- this._updateNode(tree);
688
- return this;
689
- }
690
- const entries = readonlySplice(this.entries, start, deleteCount, ...items);
691
- return tree.newDataNodeImpl(entries);
692
- }
693
- del(key, tree) {
694
- const i = binarySearch2(key, this.entries);
695
- if (!binarySearchFound(i, this.entries, key)) {
696
- return Promise.resolve(this);
697
- }
698
- return Promise.resolve(this.#splice(tree, i, 1));
699
- }
700
- async *keys(_tree) {
701
- for (const entry of this.entries) {
702
- yield entry[0];
703
- }
704
- }
705
- async *entriesIter(_tree) {
706
- for (const entry of this.entries) {
707
- yield entry;
708
- }
709
- }
710
- };
711
- function readonlySplice(array7, start, deleteCount, ...items) {
712
- const arr = array7.slice(0, start);
713
- for (let i = 0; i < items.length; i++) {
714
- arr.push(items[i]);
715
- }
716
- for (let i = start + deleteCount; i < array7.length; i++) {
717
- arr.push(array7[i]);
718
- }
719
- return arr;
720
- }
721
- var InternalNodeImpl = class _InternalNodeImpl extends NodeImpl {
722
- level;
723
- constructor(entries, hash2, level, isMutable) {
724
- super(entries, hash2, isMutable);
725
- this.level = level;
726
- }
727
- async set(key, value, entrySize, tree) {
728
- let i = binarySearch2(key, this.entries);
729
- if (i === this.entries.length) {
730
- i--;
731
- }
732
- const childHash = this.entries[i][1];
733
- const oldChildNode = await tree.getNode(childHash);
734
- const childNode = await oldChildNode.set(key, value, entrySize, tree);
735
- const childNodeSize = childNode.getChildNodeSize(tree);
736
- if (childNodeSize > tree.maxSize || childNodeSize < tree.minSize) {
737
- return this.#mergeAndPartition(tree, i, childNode);
738
- }
739
- const newEntry = createNewInternalEntryForNode(
740
- childNode,
741
- tree.getEntrySize
742
- );
743
- return this.#replaceChild(tree, i, newEntry);
744
- }
745
- /**
746
- * This merges the child node entries with previous or next sibling and then
747
- * partitions the merged entries.
748
- */
749
- async #mergeAndPartition(tree, i, childNode) {
750
- const level = this.level - 1;
751
- const thisEntries = this.entries;
752
- let values;
753
- let startIndex;
754
- let removeCount;
755
- if (i > 0) {
756
- const hash2 = thisEntries[i - 1][1];
757
- const previousSibling = await tree.getNode(hash2);
758
- values = joinIterables(
759
- previousSibling.entries,
760
- childNode.entries
761
- );
762
- startIndex = i - 1;
763
- removeCount = 2;
764
- } else if (i < thisEntries.length - 1) {
765
- const hash2 = thisEntries[i + 1][1];
766
- const nextSibling = await tree.getNode(hash2);
767
- values = joinIterables(
768
- childNode.entries,
769
- nextSibling.entries
770
- );
771
- startIndex = i;
772
- removeCount = 2;
773
- } else {
774
- values = childNode.entries;
775
- startIndex = i;
776
- removeCount = 1;
777
- }
778
- const partitions = partition(
779
- values,
780
- (value) => value[2],
781
- tree.minSize - tree.chunkHeaderSize,
782
- tree.maxSize - tree.chunkHeaderSize
783
- );
784
- const newEntries = [];
785
- for (const entries2 of partitions) {
786
- const node = tree.newNodeImpl(entries2, level);
787
- const newHashEntry = createNewInternalEntryForNode(
788
- node,
789
- tree.getEntrySize
790
- );
791
- newEntries.push(newHashEntry);
792
- }
793
- if (this.isMutable) {
794
- this.entries.splice(startIndex, removeCount, ...newEntries);
795
- this._updateNode(tree);
796
- return this;
797
- }
798
- const entries = readonlySplice(
799
- thisEntries,
800
- startIndex,
801
- removeCount,
802
- ...newEntries
803
- );
804
- return tree.newInternalNodeImpl(entries, this.level);
805
- }
806
- #replaceChild(tree, index, newEntry) {
807
- if (this.isMutable) {
808
- this.entries.splice(index, 1, newEntry);
809
- this._updateNode(tree);
810
- return this;
811
- }
812
- const entries = readonlySplice(this.entries, index, 1, newEntry);
813
- return tree.newInternalNodeImpl(entries, this.level);
814
- }
815
- async del(key, tree) {
816
- const i = binarySearch2(key, this.entries);
817
- if (i === this.entries.length) {
818
- return this;
819
- }
820
- const childHash = this.entries[i][1];
821
- const oldChildNode = await tree.getNode(childHash);
822
- const oldHash = oldChildNode.hash;
823
- const childNode = await oldChildNode.del(key, tree);
824
- if (childNode.hash === oldHash) {
825
- return this;
826
- }
827
- if (childNode.entries.length === 0) {
828
- const entries = readonlySplice(this.entries, i, 1);
829
- return tree.newInternalNodeImpl(entries, this.level);
830
- }
831
- if (i === 0 && this.entries.length === 1) {
832
- return childNode;
833
- }
834
- if (childNode.getChildNodeSize(tree) > tree.minSize) {
835
- const entry = createNewInternalEntryForNode(childNode, tree.getEntrySize);
836
- return this.#replaceChild(tree, i, entry);
837
- }
838
- return this.#mergeAndPartition(tree, i, childNode);
839
- }
840
- async *keys(tree) {
841
- for (const entry of this.entries) {
842
- const childNode = await tree.getNode(entry[1]);
843
- yield* childNode.keys(tree);
844
- }
845
- }
846
- async *entriesIter(tree) {
847
- for (const entry of this.entries) {
848
- const childNode = await tree.getNode(entry[1]);
849
- yield* childNode.entriesIter(tree);
850
- }
851
- }
852
- getChildren(start, length, tree) {
853
- const ps = [];
854
- for (let i = start; i < length && i < this.entries.length; i++) {
855
- ps.push(tree.getNode(this.entries[i][1]));
856
- }
857
- return Promise.all(ps);
858
- }
859
- async getCompositeChildren(start, length, tree) {
860
- const { level } = this;
861
- if (length === 0) {
862
- return new _InternalNodeImpl([], newRandomHash(), level - 1, true);
863
- }
864
- const output = await this.getChildren(start, start + length, tree);
865
- if (level > 1) {
866
- const entries2 = [];
867
- for (const child of output) {
868
- entries2.push(...child.entries);
869
- }
870
- return new _InternalNodeImpl(entries2, newRandomHash(), level - 1, true);
871
- }
872
- assert(level === 1);
873
- const entries = [];
874
- for (const child of output) {
875
- entries.push(...child.entries);
876
- }
877
- return new DataNodeImpl(entries, newRandomHash(), true);
878
- }
879
- };
880
- function newNodeImpl(entries, hash2, level, isMutable) {
881
- if (level === 0) {
882
- return new DataNodeImpl(
883
- entries,
884
- hash2,
885
- isMutable
886
- );
887
- }
888
- return new InternalNodeImpl(entries, hash2, level, isMutable);
889
- }
890
- function isDataNodeImpl(node) {
891
- return node.level === 0;
892
- }
893
- function partition(values, getSizeOfEntry2, min, max) {
894
- const partitions = [];
895
- const sizes = [];
896
- let sum = 0;
897
- let accum = [];
898
- for (const value of values) {
899
- const size = getSizeOfEntry2(value);
900
- if (size >= max) {
901
- if (accum.length > 0) {
902
- partitions.push(accum);
903
- sizes.push(sum);
904
- }
905
- partitions.push([value]);
906
- sizes.push(size);
907
- sum = 0;
908
- accum = [];
909
- } else if (sum + size >= min) {
910
- accum.push(value);
911
- partitions.push(accum);
912
- sizes.push(sum + size);
913
- sum = 0;
914
- accum = [];
915
- } else {
916
- sum += size;
917
- accum.push(value);
918
- }
919
- }
920
- if (sum > 0) {
921
- if (sizes.length > 0 && sum + sizes[sizes.length - 1] <= max) {
922
- partitions[partitions.length - 1].push(...accum);
923
- } else {
924
- partitions.push(accum);
925
- }
926
- }
927
- return partitions;
928
- }
929
- var emptyDataNode = makeNodeChunkData(
930
- 0,
931
- [],
932
- Latest
933
- );
934
- var emptyDataNodeImpl = new DataNodeImpl([], emptyHash, false);
935
- function createNewInternalEntryForNode(node, getSizeOfEntry2) {
936
- const key = node.maxKey();
937
- const value = node.hash;
938
- const size = getSizeOfEntry2(key, value);
939
- return [key, value, size];
940
- }
941
-
942
- // ../replicache/src/btree/splice.ts
943
- var SPLICE_UNASSIGNED = -1;
944
- var SPLICE_AT = 0;
945
- var SPLICE_REMOVED = 1;
946
- var SPLICE_ADDED = 2;
947
- var SPLICE_FROM = 3;
948
- var KEY = 0;
949
- var VALUE = 1;
950
- function* computeSplices(previous, current) {
951
- let previousIndex = 0;
952
- let currentIndex = 0;
953
- let splice;
954
- function ensureAssigned(splice2, index) {
955
- if (splice2[SPLICE_FROM] === SPLICE_UNASSIGNED) {
956
- splice2[SPLICE_FROM] = index;
957
- }
958
- }
959
- function newSplice() {
960
- return [previousIndex, 0, 0, SPLICE_UNASSIGNED];
961
- }
962
- while (previousIndex < previous.length && currentIndex < current.length) {
963
- if (previous[previousIndex][KEY] === current[currentIndex][KEY]) {
964
- if (deepEqual(
965
- // These are really Hash | InternalValue
966
- previous[previousIndex][VALUE],
967
- current[currentIndex][VALUE]
968
- )) {
969
- if (splice) {
970
- ensureAssigned(splice, 0);
971
- yield splice;
972
- splice = void 0;
973
- }
974
- } else {
975
- if (!splice) {
976
- splice = newSplice();
977
- }
978
- splice[SPLICE_ADDED]++;
979
- splice[SPLICE_REMOVED]++;
980
- ensureAssigned(splice, currentIndex);
981
- }
982
- previousIndex++;
983
- currentIndex++;
984
- } else if (previous[previousIndex][KEY] < current[currentIndex][KEY]) {
985
- if (!splice) {
986
- splice = newSplice();
987
- }
988
- splice[SPLICE_REMOVED]++;
989
- previousIndex++;
990
- } else {
991
- if (!splice) {
992
- splice = newSplice();
993
- }
994
- splice[SPLICE_ADDED]++;
995
- ensureAssigned(splice, currentIndex);
996
- currentIndex++;
997
- }
998
- }
999
- if (currentIndex < current.length) {
1000
- if (!splice) {
1001
- splice = newSplice();
1002
- }
1003
- splice[SPLICE_ADDED] += current.length - currentIndex;
1004
- ensureAssigned(splice, currentIndex);
1005
- }
1006
- if (previousIndex < previous.length) {
1007
- if (!splice) {
1008
- splice = newSplice();
1009
- }
1010
- splice[SPLICE_REMOVED] += previous.length - previousIndex;
1011
- }
1012
- if (splice) {
1013
- ensureAssigned(splice, 0);
1014
- yield splice;
1015
- }
1016
- }
1017
-
1018
- // ../replicache/src/btree/read.ts
1019
- var NODE_HEADER_SIZE = 11;
1020
- var BTreeRead = class {
1021
- _cache = /* @__PURE__ */ new Map();
1022
- _dagRead;
1023
- _formatVersion;
1024
- rootHash;
1025
- getEntrySize;
1026
- chunkHeaderSize;
1027
- constructor(dagRead, formatVersion, root = emptyHash, getEntrySize = getSizeOfEntry, chunkHeaderSize = NODE_HEADER_SIZE) {
1028
- this._dagRead = dagRead;
1029
- this._formatVersion = formatVersion;
1030
- this.rootHash = root;
1031
- this.getEntrySize = getEntrySize;
1032
- this.chunkHeaderSize = chunkHeaderSize;
1033
- }
1034
- async getNode(hash2) {
1035
- if (hash2 === emptyHash) {
1036
- return emptyDataNodeImpl;
1037
- }
1038
- const cached = this._cache.get(hash2);
1039
- if (cached) {
1040
- return cached;
1041
- }
1042
- const chunk = await this._dagRead.mustGetChunk(hash2);
1043
- const data = parseBTreeNode(
1044
- chunk.data,
1045
- this._formatVersion,
1046
- this.getEntrySize
1047
- );
1048
- const impl = newNodeImpl(
1049
- data[NODE_ENTRIES],
1050
- hash2,
1051
- data[NODE_LEVEL],
1052
- false
1053
- );
1054
- this._cache.set(hash2, impl);
1055
- return impl;
1056
- }
1057
- async get(key) {
1058
- const leaf = await findLeaf(key, this.rootHash, this, this.rootHash);
1059
- const index = binarySearch2(key, leaf.entries);
1060
- if (!binarySearchFound(index, leaf.entries, key)) {
1061
- return void 0;
1062
- }
1063
- return leaf.entries[index][1];
1064
- }
1065
- async has(key) {
1066
- const leaf = await findLeaf(key, this.rootHash, this, this.rootHash);
1067
- const index = binarySearch2(key, leaf.entries);
1068
- return binarySearchFound(index, leaf.entries, key);
1069
- }
1070
- async isEmpty() {
1071
- const { rootHash } = this;
1072
- const node = await this.getNode(this.rootHash);
1073
- if (this.rootHash !== rootHash) {
1074
- return this.isEmpty();
1075
- }
1076
- return node.entries.length === 0;
1077
- }
1078
- // We don't do any encoding of the key in the map, so we have no way of
1079
- // determining from an entry.key alone whether it is a regular key or an
1080
- // encoded IndexKey in an index map. Without encoding regular map keys the
1081
- // caller has to deal with encoding and decoding the keys for the index map.
1082
- scan(fromKey) {
1083
- return scanForHash(
1084
- this.rootHash,
1085
- () => this.rootHash,
1086
- this.rootHash,
1087
- fromKey,
1088
- async (hash2) => {
1089
- const cached = await this.getNode(hash2);
1090
- if (cached) {
1091
- return [
1092
- cached.level,
1093
- cached.isMutable ? cached.entries.slice() : cached.entries
1094
- ];
1095
- }
1096
- const chunk = await this._dagRead.mustGetChunk(hash2);
1097
- return parseBTreeNode(
1098
- chunk.data,
1099
- this._formatVersion,
1100
- this.getEntrySize
1101
- );
1102
- }
1103
- );
1104
- }
1105
- async *keys() {
1106
- const node = await this.getNode(this.rootHash);
1107
- yield* node.keys(this);
1108
- }
1109
- async *entries() {
1110
- const node = await this.getNode(this.rootHash);
1111
- yield* node.entriesIter(this);
1112
- }
1113
- [Symbol.asyncIterator]() {
1114
- return this.entries();
1115
- }
1116
- async *diff(last) {
1117
- const [currentNode, lastNode] = await Promise.all([
1118
- this.getNode(this.rootHash),
1119
- last.getNode(last.rootHash)
1120
- ]);
1121
- yield* diffNodes(lastNode, currentNode, last, this);
1122
- }
1123
- };
1124
- async function* diffNodes(last, current, lastTree, currentTree) {
1125
- if (last.level > current.level) {
1126
- const lastChild = await last.getCompositeChildren(
1127
- 0,
1128
- last.entries.length,
1129
- lastTree
1130
- );
1131
- yield* diffNodes(lastChild, current, lastTree, currentTree);
1132
- return;
1133
- }
1134
- if (current.level > last.level) {
1135
- const currentChild = await current.getCompositeChildren(
1136
- 0,
1137
- current.entries.length,
1138
- currentTree
1139
- );
1140
- yield* diffNodes(last, currentChild, lastTree, currentTree);
1141
- return;
1142
- }
1143
- if (isDataNodeImpl(last) && isDataNodeImpl(current)) {
1144
- yield* diffEntries(
1145
- last.entries,
1146
- current.entries
1147
- );
1148
- return;
1149
- }
1150
- const initialSplices = computeSplices(
1151
- last.entries,
1152
- current.entries
1153
- );
1154
- for (const splice of initialSplices) {
1155
- const [lastChild, currentChild] = await Promise.all([
1156
- last.getCompositeChildren(
1157
- splice[SPLICE_AT],
1158
- splice[SPLICE_REMOVED],
1159
- lastTree
1160
- ),
1161
- current.getCompositeChildren(
1162
- splice[SPLICE_FROM],
1163
- splice[SPLICE_ADDED],
1164
- currentTree
1165
- )
1166
- ]);
1167
- yield* diffNodes(lastChild, currentChild, lastTree, currentTree);
1168
- }
1169
- }
1170
- function* diffEntries(lastEntries, currentEntries) {
1171
- const lastLength = lastEntries.length;
1172
- const currentLength = currentEntries.length;
1173
- let i = 0;
1174
- let j = 0;
1175
- while (i < lastLength && j < currentLength) {
1176
- const lastKey = lastEntries[i][0];
1177
- const currentKey = currentEntries[j][0];
1178
- if (lastKey === currentKey) {
1179
- if (!deepEqual(lastEntries[i][1], currentEntries[j][1])) {
1180
- yield {
1181
- op: "change",
1182
- key: lastKey,
1183
- oldValue: lastEntries[i][1],
1184
- newValue: currentEntries[j][1]
1185
- };
1186
- }
1187
- i++;
1188
- j++;
1189
- } else if (lastKey < currentKey) {
1190
- yield {
1191
- op: "del",
1192
- key: lastKey,
1193
- oldValue: lastEntries[i][1]
1194
- };
1195
- i++;
1196
- } else {
1197
- yield {
1198
- op: "add",
1199
- key: currentKey,
1200
- newValue: currentEntries[j][1]
1201
- };
1202
- j++;
1203
- }
1204
- }
1205
- for (; i < lastLength; i++) {
1206
- yield {
1207
- op: "del",
1208
- key: lastEntries[i][0],
1209
- oldValue: lastEntries[i][1]
1210
- };
1211
- }
1212
- for (; j < currentLength; j++) {
1213
- yield {
1214
- op: "add",
1215
- key: currentEntries[j][0],
1216
- newValue: currentEntries[j][1]
1217
- };
1218
- }
1219
- }
1220
- async function* scanForHash(expectedRootHash, getRootHash, hash2, fromKey, readNode) {
1221
- if (hash2 === emptyHash) {
1222
- return;
1223
- }
1224
- const data = await readNode(hash2);
1225
- const entries = data[NODE_ENTRIES];
1226
- let i = 0;
1227
- if (fromKey) {
1228
- i = binarySearch2(fromKey, entries);
1229
- }
1230
- if (data[NODE_LEVEL] > 0) {
1231
- for (; i < entries.length; i++) {
1232
- yield* scanForHash(
1233
- expectedRootHash,
1234
- getRootHash,
1235
- entries[i][1],
1236
- fromKey,
1237
- readNode
1238
- );
1239
- fromKey = "";
1240
- }
1241
- } else {
1242
- for (; i < entries.length; i++) {
1243
- const rootHash = getRootHash();
1244
- if (expectedRootHash !== rootHash) {
1245
- yield* scanForHash(
1246
- rootHash,
1247
- getRootHash,
1248
- rootHash,
1249
- entries[i][0],
1250
- readNode
1251
- );
1252
- return;
1253
- }
1254
- yield entries[i];
1255
- }
1256
- }
1257
- }
1258
- async function allEntriesAsDiff(map, op) {
1259
- const diff3 = [];
1260
- const make = op === "add" ? (entry) => ({
1261
- op: "add",
1262
- key: entry[0],
1263
- newValue: entry[1]
1264
- }) : (entry) => ({
1265
- op: "del",
1266
- key: entry[0],
1267
- oldValue: entry[1]
1268
- });
1269
- for await (const entry of map.entries()) {
1270
- diff3.push(make(entry));
1271
- }
1272
- return diff3;
1273
- }
1274
-
1275
- // ../shared/src/string-compare.ts
1276
- function stringCompare(a, b) {
1277
- if (a === b) {
1278
- return 0;
1279
- }
1280
- if (a < b) {
1281
- return -1;
1282
- }
1283
- return 1;
1284
- }
1285
-
1286
- // ../replicache/src/cookies.ts
1287
- function compareCookies(a, b) {
1288
- if (a === b) {
1289
- return 0;
1290
- }
1291
- if (a === null) {
1292
- return -1;
1293
- }
1294
- if (b === null) {
1295
- return 1;
1296
- }
1297
- const cva = getCompareValue(a);
1298
- const cvb = getCompareValue(b);
1299
- if (typeof cva === "string" || typeof cvb === "string") {
1300
- return stringCompare(String(cva), String(cvb));
1301
- }
1302
- return cva - cvb;
1303
- }
1304
- function getCompareValue(cookie) {
1305
- if (typeof cookie === "string" || typeof cookie === "number") {
1306
- return cookie;
1307
- }
1308
- return cookie.order;
1309
- }
1310
- function assertCookie(v2) {
1311
- if (v2 === null || typeof v2 === "string" || typeof v2 === "number") {
1312
- return;
1313
- }
1314
- assertJSONObject(v2);
1315
- if (typeof v2.order === "string" || typeof v2.order === "number") {
1316
- return;
1317
- }
1318
- throw new Error("Invalid cookie");
1319
- }
1320
-
1321
- // ../replicache/src/dag/chunk.ts
1322
- function asRefs(sortedRefs) {
1323
- return sortedRefs;
1324
- }
1325
- function toRefs(refs) {
1326
- if (Array.isArray(refs)) {
1327
- refs.sort();
1328
- for (let i = 1; i < refs.length; i++) {
1329
- assert(refs[i - 1] !== refs[i], "Refs must not have duplicates");
1330
- }
1331
- return asRefs(refs);
1332
- }
1333
- const refsArray = [...refs];
1334
- refsArray.sort();
1335
- return asRefs(refsArray);
1336
- }
1337
- var Chunk = class {
1338
- hash;
1339
- data;
1340
- /**
1341
- * Meta is an array of refs. If there are no refs we do not write a meta
1342
- * chunk.
1343
- */
1344
- meta;
1345
- constructor(hash2, data, refs) {
1346
- assert(
1347
- !refs.includes(hash2),
1348
- "Chunk cannot reference itself"
1349
- );
1350
- assertDeepFrozen(data);
1351
- this.hash = hash2;
1352
- this.data = data;
1353
- this.meta = refs;
1354
- }
1355
- };
1356
- function assertRefs(v2) {
1357
- if (!Array.isArray(v2)) {
1358
- throw new Error("Refs must be an array");
1359
- }
1360
- if (v2.length > 0) {
1361
- assertString(v2[0]);
1362
- for (let i = 1; i < v2.length; i++) {
1363
- assertString(v2[i]);
1364
- }
1365
- }
1366
- }
1367
- function createChunk(data, refs, chunkHasher) {
1368
- const hash2 = chunkHasher();
1369
- return new Chunk(hash2, data, refs);
1370
- }
1371
-
1372
- // ../replicache/src/dag/store.ts
1373
- var ChunkNotFoundError = class extends Error {
1374
- name = "ChunkNotFoundError";
1375
- hash;
1376
- constructor(hash2) {
1377
- super(`Chunk not found ${hash2}`);
1378
- this.hash = hash2;
1379
- }
1380
- };
1381
- async function mustGetChunk(store, hash2) {
1382
- const chunk = await store.getChunk(hash2);
1383
- if (chunk) {
1384
- return chunk;
1385
- }
1386
- throw new ChunkNotFoundError(hash2);
1387
- }
1388
- async function mustGetHeadHash(name, store) {
1389
- const hash2 = await store.getHead(name);
1390
- assert(hash2, `Missing head ${name}`);
1391
- return hash2;
1392
- }
1393
-
1394
- // ../replicache/src/db/meta-type-enum.ts
1395
- var LocalDD31 = 4;
1396
- var SnapshotDD31 = 5;
1397
-
1398
- // ../replicache/src/db/commit.ts
1399
- var DEFAULT_HEAD_NAME = "main";
1400
- function commitIsLocalDD31(commit) {
1401
- return isLocalMetaDD31(commit.meta);
1402
- }
1403
- function commitIsLocal(commit) {
1404
- return commitIsLocalDD31(commit);
1405
- }
1406
- function commitIsSnapshot(commit) {
1407
- return isSnapshotMetaDD31(commit.meta);
1408
- }
1409
- var Commit = class {
1410
- chunk;
1411
- constructor(chunk) {
1412
- this.chunk = chunk;
1413
- }
1414
- get meta() {
1415
- return this.chunk.data.meta;
1416
- }
1417
- get valueHash() {
1418
- return this.chunk.data.valueHash;
1419
- }
1420
- getMutationID(clientID, dagRead) {
1421
- return getMutationID(clientID, dagRead, this.meta);
1422
- }
1423
- async getNextMutationID(clientID, dagRead) {
1424
- return await this.getMutationID(clientID, dagRead) + 1;
1425
- }
1426
- get indexes() {
1427
- return this.chunk.data.indexes;
1428
- }
1429
- };
1430
- async function getMutationID(clientID, dagRead, meta) {
1431
- switch (meta.type) {
1432
- case SnapshotDD31:
1433
- return meta.lastMutationIDs[clientID] ?? 0;
1434
- case LocalDD31: {
1435
- if (meta.clientID === clientID) {
1436
- return meta.mutationID;
1437
- }
1438
- const { basisHash } = meta;
1439
- const basisCommit = await commitFromHash(basisHash, dagRead);
1440
- return getMutationID(clientID, dagRead, basisCommit.meta);
1441
- }
1442
- default:
1443
- unreachable(meta);
1444
- }
1445
- }
1446
- async function localMutations(fromCommitHash, dagRead) {
1447
- const commits = await commitChain(fromCommitHash, dagRead);
1448
- return commits.filter((c) => commitIsLocal(c));
1449
- }
1450
- async function localMutationsDD31(fromCommitHash, dagRead) {
1451
- const commits = await commitChain(fromCommitHash, dagRead);
1452
- return commits.filter((c) => commitIsLocalDD31(c));
1453
- }
1454
- async function localMutationsGreaterThan(commit, mutationIDLimits, dagRead) {
1455
- const commits = [];
1456
- const remainingMutationIDLimits = new Map(Object.entries(mutationIDLimits));
1457
- while (!commitIsSnapshot(commit) && remainingMutationIDLimits.size > 0) {
1458
- if (commitIsLocalDD31(commit)) {
1459
- const { meta } = commit;
1460
- const mutationIDLowerLimit = remainingMutationIDLimits.get(meta.clientID);
1461
- if (mutationIDLowerLimit !== void 0) {
1462
- if (meta.mutationID <= mutationIDLowerLimit) {
1463
- remainingMutationIDLimits.delete(meta.clientID);
1464
- } else {
1465
- commits.push(commit);
1466
- }
1467
- }
1468
- }
1469
- const { basisHash } = commit.meta;
1470
- if (basisHash === null) {
1471
- throw new Error(`Commit ${commit.chunk.hash} has no basis`);
1472
- }
1473
- commit = await commitFromHash(basisHash, dagRead);
1474
- }
1475
- return commits;
1476
- }
1477
- async function baseSnapshotFromHead(name, dagRead) {
1478
- const hash2 = await dagRead.getHead(name);
1479
- assert(hash2, `Missing head ${name}`);
1480
- return baseSnapshotFromHash(hash2, dagRead);
1481
- }
1482
- async function baseSnapshotHashFromHash(hash2, dagRead) {
1483
- return (await baseSnapshotFromHash(hash2, dagRead)).chunk.hash;
1484
- }
1485
- async function baseSnapshotFromHash(hash2, dagRead) {
1486
- const commit = await commitFromHash(hash2, dagRead);
1487
- return baseSnapshotFromCommit(commit, dagRead);
1488
- }
1489
- async function baseSnapshotFromCommit(commit, dagRead) {
1490
- while (!commitIsSnapshot(commit)) {
1491
- const { meta } = commit;
1492
- if (isLocalMetaDD31(meta)) {
1493
- commit = await commitFromHash(meta.baseSnapshotHash, dagRead);
1494
- } else {
1495
- const { basisHash } = meta;
1496
- if (basisHash === null) {
1497
- throw new Error(`Commit ${commit.chunk.hash} has no basis`);
1498
- }
1499
- commit = await commitFromHash(basisHash, dagRead);
1500
- }
1501
- }
1502
- return commit;
1503
- }
1504
- function snapshotMetaParts(c, clientID) {
1505
- const m = c.meta;
1506
- const lmid = m.lastMutationIDs[clientID] ?? 0;
1507
- return [lmid, m.cookieJSON];
1508
- }
1509
- function compareCookiesForSnapshots(a, b) {
1510
- return compareCookies(a.meta.cookieJSON, b.meta.cookieJSON);
1511
- }
1512
- async function commitChain(fromCommitHash, dagRead) {
1513
- let commit = await commitFromHash(fromCommitHash, dagRead);
1514
- const commits = [];
1515
- while (!commitIsSnapshot(commit)) {
1516
- const { meta } = commit;
1517
- const { basisHash } = meta;
1518
- if (basisHash === null) {
1519
- throw new Error(`Commit ${commit.chunk.hash} has no basis`);
1520
- }
1521
- commits.push(commit);
1522
- commit = await commitFromHash(basisHash, dagRead);
1523
- }
1524
- commits.push(commit);
1525
- return commits;
1526
- }
1527
- async function commitFromHash(hash2, dagRead) {
1528
- const chunk = await dagRead.mustGetChunk(hash2);
1529
- return fromChunk(chunk);
1530
- }
1531
- async function commitFromHead(name, dagRead) {
1532
- const hash2 = await mustGetHeadHash(name, dagRead);
1533
- return commitFromHash(hash2, dagRead);
1534
- }
1535
- function assertLocalMetaDD31(v2) {
1536
- assertString(v2.clientID);
1537
- assertNumber(v2.mutationID);
1538
- assertString(v2.mutatorName);
1539
- if (!v2.mutatorName) {
1540
- throw new Error("Missing mutator name");
1541
- }
1542
- assertJSONValue(v2.mutatorArgsJSON);
1543
- if (v2.originalHash !== null) {
1544
- assertHash(v2.originalHash);
1545
- }
1546
- assertNumber(v2.timestamp);
1547
- }
1548
- function isLocalMetaDD31(meta) {
1549
- return meta.type === LocalDD31;
1550
- }
1551
- function assertSnapshotMetaDD31(v2) {
1552
- if (v2.basisHash !== null) {
1553
- assertHash(v2.basisHash);
1554
- }
1555
- assertJSONValue(v2.cookieJSON);
1556
- assertLastMutationIDs(v2.lastMutationIDs);
1557
- }
1558
- function assertLastMutationIDs(v2) {
1559
- assertObject(v2);
1560
- for (const e of Object.values(v2)) {
1561
- assertNumber(e);
1562
- }
1563
- }
1564
- function assertSnapshotCommitDD31(c) {
1565
- assertSnapshotMetaDD31(c.meta);
1566
- }
1567
- function isSnapshotMetaDD31(meta) {
1568
- return meta.type === SnapshotDD31;
1569
- }
1570
- function assertMeta(v2) {
1571
- assertObject(v2);
1572
- assertDeepFrozen(v2);
1573
- if (v2.basisHash !== null) {
1574
- assertString(v2.basisHash);
1575
- }
1576
- assertNumber(v2.type);
1577
- switch (v2.type) {
1578
- case LocalDD31:
1579
- assertLocalMetaDD31(v2);
1580
- break;
1581
- case SnapshotDD31:
1582
- assertSnapshotMetaDD31(v2);
1583
- break;
1584
- default:
1585
- throw new Error(`Invalid enum value ${v2.type}`);
1586
- }
1587
- }
1588
- function chunkIndexDefinitionEqualIgnoreName(a, b) {
1589
- return a.jsonPointer === b.jsonPointer && (a.allowEmpty ?? false) === (b.allowEmpty ?? false) && a.keyPrefix === b.keyPrefix;
1590
- }
1591
- function assertChunkIndexDefinition(v2) {
1592
- assertObject(v2);
1593
- assertDeepFrozen(v2);
1594
- assertString(v2.name);
1595
- assertString(v2.keyPrefix);
1596
- assertString(v2.jsonPointer);
1597
- if (v2.allowEmpty !== void 0) {
1598
- assertBoolean(v2.allowEmpty);
1599
- }
1600
- }
1601
- function toChunkIndexDefinition(name, indexDefinition) {
1602
- return {
1603
- name,
1604
- keyPrefix: indexDefinition.prefix ?? "",
1605
- jsonPointer: indexDefinition.jsonPointer,
1606
- allowEmpty: indexDefinition.allowEmpty ?? false
1607
- };
1608
- }
1609
- function assertIndexRecord(v2) {
1610
- assertObject(v2);
1611
- assertDeepFrozen(v2);
1612
- assertChunkIndexDefinition(v2.definition);
1613
- assertString(v2.valueHash);
1614
- }
1615
- function assertIndexRecords(v2) {
1616
- assertArray(v2);
1617
- assertDeepFrozen(v2);
1618
- for (const ir of v2) {
1619
- assertIndexRecord(ir);
1620
- }
1621
- }
1622
- function newLocalDD31(createChunk2, basisHash, baseSnapshotHash, mutationID, mutatorName, mutatorArgsJSON, originalHash, valueHash, indexes, timestamp, clientID) {
1623
- const meta = {
1624
- type: LocalDD31,
1625
- basisHash,
1626
- baseSnapshotHash,
1627
- mutationID,
1628
- mutatorName,
1629
- mutatorArgsJSON,
1630
- originalHash,
1631
- timestamp,
1632
- clientID
1633
- };
1634
- return commitFromCommitData(
1635
- createChunk2,
1636
- makeCommitData(meta, valueHash, indexes)
1637
- );
1638
- }
1639
- function newSnapshotDD31(createChunk2, basisHash, lastMutationIDs, cookieJSON, valueHash, indexes) {
1640
- return commitFromCommitData(
1641
- createChunk2,
1642
- newSnapshotCommitDataDD31(
1643
- basisHash,
1644
- lastMutationIDs,
1645
- cookieJSON,
1646
- valueHash,
1647
- indexes
1648
- )
1649
- );
1650
- }
1651
- function newSnapshotCommitDataDD31(basisHash, lastMutationIDs, cookieJSON, valueHash, indexes) {
1652
- const meta = {
1653
- type: SnapshotDD31,
1654
- basisHash,
1655
- lastMutationIDs,
1656
- cookieJSON
1657
- };
1658
- return makeCommitData(meta, valueHash, indexes);
1659
- }
1660
- function fromChunk(chunk) {
1661
- validateChunk(chunk);
1662
- return new Commit(chunk);
1663
- }
1664
- function commitFromCommitData(createChunk2, data) {
1665
- return new Commit(createChunk2(data, getRefs(data)));
1666
- }
1667
- function getRefs(data) {
1668
- const refs = /* @__PURE__ */ new Set();
1669
- refs.add(data.valueHash);
1670
- const { meta } = data;
1671
- switch (meta.type) {
1672
- case LocalDD31:
1673
- meta.basisHash && refs.add(meta.basisHash);
1674
- break;
1675
- case SnapshotDD31:
1676
- break;
1677
- default:
1678
- unreachable(meta);
1679
- }
1680
- for (const index of data.indexes) {
1681
- refs.add(index.valueHash);
1682
- }
1683
- return toRefs(refs);
1684
- }
1685
- function makeCommitData(meta, valueHash, indexes) {
1686
- return deepFreeze({
1687
- meta,
1688
- valueHash,
1689
- indexes
1690
- });
1691
- }
1692
- function assertCommitData(v2) {
1693
- if (isProd) {
1694
- return;
1695
- }
1696
- assertObject(v2);
1697
- assertDeepFrozen(v2);
1698
- assertMeta(v2.meta);
1699
- assertString(v2.valueHash);
1700
- assertIndexRecords(v2.indexes);
1701
- }
1702
- function validateChunk(chunk) {
1703
- const { data } = chunk;
1704
- assertCommitData(data);
1705
- const seen = /* @__PURE__ */ new Set();
1706
- for (const index of data.indexes) {
1707
- const { name } = index.definition;
1708
- if (seen.has(name)) {
1709
- throw new Error(`Duplicate index ${name}`);
1710
- }
1711
- seen.add(name);
1712
- }
1713
- }
1714
-
1715
- // ../replicache/src/db/index-operation-enum.ts
1716
- var Add = 0;
1717
- var Remove = 1;
1718
-
1719
- // ../replicache/src/db/index.ts
1720
- var IndexRead = class {
1721
- meta;
1722
- map;
1723
- constructor(meta, map) {
1724
- this.meta = meta;
1725
- this.map = map;
1726
- }
1727
- };
1728
- var IndexWrite = class extends IndexRead {
1729
- // Note: does not update self.meta.valueHash (doesn't need to at this point as flush
1730
- // is only called during commit.)
1731
- flush() {
1732
- return this.map.flush();
1733
- }
1734
- clear() {
1735
- return this.map.clear();
1736
- }
1737
- };
1738
- async function indexValue(lc, index, op, key, val, jsonPointer, allowEmpty) {
1739
- try {
1740
- for (const entry of getIndexKeys(key, val, jsonPointer, allowEmpty)) {
1741
- switch (op) {
1742
- case Add:
1743
- await index.put(entry, val);
1744
- break;
1745
- case Remove:
1746
- await index.del(entry);
1747
- break;
1748
- }
1749
- }
1750
- } catch (e) {
1751
- lc.info?.("Not indexing value", val, ":", e);
1752
- }
1753
- }
1754
- function getIndexKeys(primary, value, jsonPointer, allowEmpty) {
1755
- const target = evaluateJSONPointer(value, jsonPointer);
1756
- if (target === void 0) {
1757
- if (allowEmpty) {
1758
- return [];
1759
- }
1760
- throw new Error(`No value at path: ${jsonPointer}`);
1761
- }
1762
- const values = Array.isArray(target) ? target : [target];
1763
- const indexKeys = [];
1764
- for (const value2 of values) {
1765
- if (typeof value2 === "string") {
1766
- indexKeys.push(encodeIndexKey([value2, primary]));
1767
- } else {
1768
- throw new Error("Unsupported target type");
1769
- }
1770
- }
1771
- return indexKeys;
1772
- }
1773
- var KEY_VERSION_0 = "\0";
1774
- var KEY_SEPARATOR = "\0";
1775
- function encodeIndexKey(indexKey) {
1776
- const secondary = indexKey[0];
1777
- const primary = indexKey[1];
1778
- if (secondary.includes("\0")) {
1779
- throw new Error("Secondary key cannot contain null byte");
1780
- }
1781
- return KEY_VERSION_0 + secondary + KEY_SEPARATOR + primary;
1782
- }
1783
- function encodeIndexScanKey(secondary, primary) {
1784
- const k = encodeIndexKey([secondary, primary || ""]);
1785
- if (primary === void 0) {
1786
- return k.slice(0, k.length - 1);
1787
- }
1788
- return k;
1789
- }
1790
- function decodeIndexKey(encodedIndexKey) {
1791
- if (encodedIndexKey[0] !== KEY_VERSION_0) {
1792
- throw new Error("Invalid version");
1793
- }
1794
- const versionLen = KEY_VERSION_0.length;
1795
- const separatorLen = KEY_SEPARATOR.length;
1796
- const separatorOffset = encodedIndexKey.indexOf(KEY_SEPARATOR, versionLen);
1797
- if (separatorOffset === -1) {
1798
- throw new Error("Invalid formatting");
1799
- }
1800
- const secondary = encodedIndexKey.slice(versionLen, separatorOffset);
1801
- const primary = encodedIndexKey.slice(separatorOffset + separatorLen);
1802
- return [secondary, primary];
1803
- }
1804
- function evaluateJSONPointer(value, pointer) {
1805
- function parseIndex(s) {
1806
- if (s.startsWith("+") || s.startsWith("0") && s.length !== 1) {
1807
- return void 0;
1808
- }
1809
- return parseInt(s, 10);
1810
- }
1811
- if (pointer === "") {
1812
- return value;
1813
- }
1814
- if (!pointer.startsWith("/")) {
1815
- throw new Error(`Invalid JSON pointer: ${pointer}`);
1816
- }
1817
- const tokens = pointer.split("/").slice(1).map((x) => x.replace(/~1/g, "/").replace(/~0/g, "~"));
1818
- let target = value;
1819
- for (const token of tokens) {
1820
- let targetOpt;
1821
- if (Array.isArray(target)) {
1822
- const i = parseIndex(token);
1823
- if (i === void 0) {
1824
- return void 0;
1825
- }
1826
- targetOpt = target[i];
1827
- } else if (target === null) {
1828
- return void 0;
1829
- } else if (typeof target === "object") {
1830
- target = target;
1831
- targetOpt = target[token];
1832
- }
1833
- if (targetOpt === void 0) {
1834
- return void 0;
1835
- }
1836
- target = targetOpt;
1837
- }
1838
- return target;
1839
- }
1840
-
1841
- // ../replicache/src/db/read.ts
1842
- var Read = class {
1843
- #dagRead;
1844
- map;
1845
- indexes;
1846
- constructor(dagRead, map, indexes) {
1847
- this.#dagRead = dagRead;
1848
- this.map = map;
1849
- this.indexes = indexes;
1850
- }
1851
- has(key) {
1852
- return this.map.has(key);
1853
- }
1854
- get(key) {
1855
- return this.map.get(key);
1856
- }
1857
- isEmpty() {
1858
- return this.map.isEmpty();
1859
- }
1860
- getMapForIndex(indexName) {
1861
- const idx = this.indexes.get(indexName);
1862
- if (idx === void 0) {
1863
- throw new Error(`Unknown index name: ${indexName}`);
1864
- }
1865
- return idx.map;
1866
- }
1867
- get closed() {
1868
- return this.#dagRead.closed;
1869
- }
1870
- close() {
1871
- this.#dagRead.release();
1872
- }
1873
- };
1874
- function readFromDefaultHead(dagRead, formatVersion) {
1875
- return readFromHead(DEFAULT_HEAD_NAME, dagRead, formatVersion);
1876
- }
1877
- async function readFromHead(name, dagRead, formatVersion) {
1878
- const commit = await commitFromHead(name, dagRead);
1879
- return readFromCommit(commit, dagRead, formatVersion);
1880
- }
1881
- async function readFromHash(hash2, dagRead, formatVersion) {
1882
- const commit = await commitFromHash(hash2, dagRead);
1883
- return readFromCommit(commit, dagRead, formatVersion);
1884
- }
1885
- function readFromCommit(commit, dagRead, formatVersion) {
1886
- const indexes = readIndexesForRead(commit, dagRead, formatVersion);
1887
- const map = new BTreeRead(dagRead, formatVersion, commit.valueHash);
1888
- return new Read(dagRead, map, indexes);
1889
- }
1890
- function readIndexesForRead(commit, dagRead, formatVersion) {
1891
- const m = /* @__PURE__ */ new Map();
1892
- for (const index of commit.indexes) {
1893
- m.set(
1894
- index.definition.name,
1895
- new IndexRead(
1896
- index,
1897
- new BTreeRead(dagRead, formatVersion, index.valueHash)
1898
- )
1899
- );
1900
- }
1901
- return m;
1902
- }
1903
-
1904
- // ../replicache/src/with-transactions.ts
1905
- function withRead(store, fn) {
1906
- return using(store.read(), fn);
1907
- }
1908
- function withWriteNoImplicitCommit(store, fn) {
1909
- return using(store.write(), fn);
1910
- }
1911
- function withWrite(store, fn) {
1912
- return using(store.write(), async (write) => {
1913
- const result = await fn(write);
1914
- await write.commit();
1915
- return result;
1916
- });
1917
- }
1918
- async function using(x, fn) {
1919
- const write = await x;
1920
- try {
1921
- return await fn(write);
1922
- } finally {
1923
- write.release();
1924
- }
1925
- }
1926
-
1927
- // ../replicache/src/index-defs.ts
1928
- var indexDefinitionSchema = readonlyObject({
1929
- prefix: valita_exports.string().optional(),
1930
- jsonPointer: valita_exports.string(),
1931
- allowEmpty: valita_exports.boolean().optional()
1932
- });
1933
- var indexDefinitionsSchema = readonlyRecord(
1934
- indexDefinitionSchema
1935
- );
1936
- function indexDefinitionEqual(a, b) {
1937
- return a.jsonPointer === b.jsonPointer && (a.allowEmpty ?? false) === (b.allowEmpty ?? false) && (a.prefix ?? "") === (b.prefix ?? "");
1938
- }
1939
- function indexDefinitionsEqual(a, b) {
1940
- if (Object.keys(a).length !== Object.keys(b).length) {
1941
- return false;
1942
- }
1943
- for (const [aKey, aValue] of Object.entries(a)) {
1944
- const bValue = b[aKey];
1945
- if (!bValue || !indexDefinitionEqual(aValue, bValue)) {
1946
- return false;
1947
- }
1948
- }
1949
- return true;
1950
- }
1951
-
1952
- // ../replicache/src/persist/client-groups.ts
1953
- var clientGroupSchema = readonlyObject({
1954
- /**
1955
- * The hash of the commit in the perdag last persisted to this client group.
1956
- * Should only be updated by clients assigned to this client group.
1957
- */
1958
- headHash: hashSchema,
1959
- /**
1960
- * Set of mutator names common to all clients assigned to this client group.
1961
- */
1962
- mutatorNames: readonlyArray(valita_exports.string()),
1963
- /**
1964
- * Index definitions common to all clients assigned to this client group.
1965
- */
1966
- indexes: indexDefinitionsSchema,
1967
- /**
1968
- * The highest mutation ID of every client assigned to this client group.
1969
- * Should only be updated by clients assigned to this client group. Read by
1970
- * other clients to determine if there are unacknowledged pending mutations
1971
- * for them to try to recover. This is redundant with information in the
1972
- * commit graph at `headHash`, but allows other clients to determine if there
1973
- * are unacknowledged pending mutations without having to load the commit
1974
- * graph.
1975
- */
1976
- mutationIDs: readonlyRecord(valita_exports.number()),
1977
- /**
1978
- * The highest lastMutationID received from the server for every client
1979
- * assigned to this client group.
1980
- *
1981
- * Should be updated by the clients assigned to this client group whenever
1982
- * they persist to this client group. Read by other clients to determine if
1983
- * there are unacknowledged pending mutations for them to recover and
1984
- * *updated* by other clients upon successfully recovering pending mutations
1985
- * to avoid redundant pushes of pending mutations.
1986
- *
1987
- * Note: This will be the same as the `lastMutationIDs` of the base snapshot
1988
- * of the client group's commit graph when written by clients assigned to this
1989
- * client group. However, when written by another client recovering mutations
1990
- * it may be different because the other client does not update the commit
1991
- * graph.
1992
- */
1993
- lastServerAckdMutationIDs: valita_exports.record(valita_exports.number()),
1994
- /**
1995
- * If the server deletes this client group it can signal that the client group
1996
- * was deleted. If that happens we mark this client group as disabled so that
1997
- * we do not use it again when creating new clients.
1998
- */
1999
- disabled: valita_exports.boolean()
2000
- });
2001
- var CLIENT_GROUPS_HEAD_NAME = "client-groups";
2002
- function assertClientGroup(value) {
2003
- assert2(value, clientGroupSchema);
2004
- }
2005
- function chunkDataToClientGroupMap(chunkData) {
2006
- assertObject(chunkData);
2007
- const clientGroups = /* @__PURE__ */ new Map();
2008
- for (const [key, value] of Object.entries(chunkData)) {
2009
- if (value !== void 0) {
2010
- assertClientGroup(value);
2011
- clientGroups.set(key, value);
2012
- }
2013
- }
2014
- return clientGroups;
2015
- }
2016
- function clientGroupMapToChunkData(clientGroups, dagWrite) {
2017
- const chunkData = {};
2018
- for (const [clientGroupID, clientGroup] of clientGroups.entries()) {
2019
- dagWrite.assertValidHash(clientGroup.headHash);
2020
- chunkData[clientGroupID] = {
2021
- ...clientGroup,
2022
- mutatorNames: [...clientGroup.mutatorNames.values()]
2023
- };
2024
- }
2025
- return deepFreeze(chunkData);
2026
- }
2027
- async function getClientGroupsAtHash(hash2, dagRead) {
2028
- const chunk = await dagRead.getChunk(hash2);
2029
- return chunkDataToClientGroupMap(chunk?.data);
2030
- }
2031
- async function getClientGroups(dagRead) {
2032
- const hash2 = await dagRead.getHead(CLIENT_GROUPS_HEAD_NAME);
2033
- if (!hash2) {
2034
- return /* @__PURE__ */ new Map();
2035
- }
2036
- return getClientGroupsAtHash(hash2, dagRead);
2037
- }
2038
- async function setClientGroups(clientGroups, dagWrite) {
2039
- const currClientGroups = await getClientGroups(dagWrite);
2040
- for (const [clientGroupID, clientGroup] of clientGroups) {
2041
- const currClientGroup = currClientGroups.get(clientGroupID);
2042
- validateClientGroupUpdate(clientGroup, currClientGroup);
2043
- }
2044
- return setValidatedClientGroups(clientGroups, dagWrite);
2045
- }
2046
- async function setClientGroup(clientGroupID, clientGroup, dagWrite) {
2047
- const currClientGroups = await getClientGroups(dagWrite);
2048
- const currClientGroup = currClientGroups.get(clientGroupID);
2049
- validateClientGroupUpdate(clientGroup, currClientGroup);
2050
- const newClientGroups = new Map(currClientGroups);
2051
- newClientGroups.set(clientGroupID, clientGroup);
2052
- return setValidatedClientGroups(newClientGroups, dagWrite);
2053
- }
2054
- function validateClientGroupUpdate(clientGroup, currClientGroup) {
2055
- const mutatorNamesSet = new Set(clientGroup.mutatorNames);
2056
- assert(
2057
- mutatorNamesSet.size === clientGroup.mutatorNames.length,
2058
- "A client group's mutatorNames must be a set."
2059
- );
2060
- if (currClientGroup !== void 0) {
2061
- assert(
2062
- indexDefinitionsEqual(currClientGroup.indexes, clientGroup.indexes),
2063
- "A client group's index definitions must never change."
2064
- );
2065
- assert(
2066
- mutatorNamesEqual(mutatorNamesSet, currClientGroup.mutatorNames),
2067
- "A client group's mutatorNames must never change."
2068
- );
2069
- }
2070
- }
2071
- async function setValidatedClientGroups(clientGroups, dagWrite) {
2072
- const chunkData = clientGroupMapToChunkData(clientGroups, dagWrite);
2073
- const refs = /* @__PURE__ */ new Set();
2074
- for (const clientGroup of clientGroups.values()) {
2075
- refs.add(clientGroup.headHash);
2076
- }
2077
- const chunk = dagWrite.createChunk(chunkData, toRefs(refs));
2078
- await dagWrite.putChunk(chunk);
2079
- await dagWrite.setHead(CLIENT_GROUPS_HEAD_NAME, chunk.hash);
2080
- return clientGroups;
2081
- }
2082
- function mutatorNamesEqual(mutatorNamesSet, mutatorNames) {
2083
- if (mutatorNames.length !== mutatorNamesSet.size) {
2084
- return false;
2085
- }
2086
- for (const mutatorName of mutatorNames) {
2087
- if (!mutatorNamesSet.has(mutatorName)) {
2088
- return false;
2089
- }
2090
- }
2091
- return true;
2092
- }
2093
- async function getClientGroup(id, dagRead) {
2094
- const clientGroups = await getClientGroups(dagRead);
2095
- return clientGroups.get(id);
2096
- }
2097
- function clientGroupHasPendingMutations(clientGroup) {
2098
- for (const [clientID, mutationID] of Object.entries(
2099
- clientGroup.mutationIDs
2100
- )) {
2101
- const lastServerAckdMutationID = clientGroup.lastServerAckdMutationIDs[clientID];
2102
- if (lastServerAckdMutationID === void 0 && mutationID !== 0 || lastServerAckdMutationID < mutationID) {
2103
- return true;
2104
- }
2105
- }
2106
- return false;
2107
- }
2108
- async function disableClientGroup(clientGroupID, dagWrite) {
2109
- const clientGroup = await getClientGroup(clientGroupID, dagWrite);
2110
- if (!clientGroup) {
2111
- return;
2112
- }
2113
- const disabledClientGroup = {
2114
- ...clientGroup,
2115
- disabled: true
2116
- };
2117
- await setClientGroup(clientGroupID, disabledClientGroup, dagWrite);
2118
- }
2119
-
2120
- // ../replicache/src/async-iterable-to-array.ts
2121
- async function asyncIterableToArray(it) {
2122
- const arr = [];
2123
- for await (const v2 of it) {
2124
- arr.push(v2);
2125
- }
2126
- return arr;
2127
- }
2128
-
2129
- // ../replicache/src/btree/diff.ts
2130
- function diff(oldMap, newMap) {
2131
- return asyncIterableToArray(newMap.diff(oldMap));
2132
- }
2133
-
2134
- // ../replicache/src/btree/write.ts
2135
- import { Lock } from "@rocicorp/lock";
2136
- var BTreeWrite = class extends BTreeRead {
2137
- /**
2138
- * This rw lock is used to ensure we do not mutate the btree in parallel. It
2139
- * would be a problem if we didn't have the lock in cases like this:
2140
- *
2141
- * ```ts
2142
- * const p1 = tree.put('a', 0);
2143
- * const p2 = tree.put('b', 1);
2144
- * await p1;
2145
- * await p2;
2146
- * ```
2147
- *
2148
- * because both `p1` and `p2` would start from the old root hash but a put
2149
- * changes the root hash so the two concurrent puts would lead to only one of
2150
- * them actually working, and it is not deterministic which one would finish
2151
- * last.
2152
- */
2153
- #lock = new Lock();
2154
- #modified = /* @__PURE__ */ new Map();
2155
- minSize;
2156
- maxSize;
2157
- constructor(dagWrite, formatVersion, root = emptyHash, minSize = 8 * 1024, maxSize = 16 * 1024, getEntrySize = getSizeOfEntry, chunkHeaderSize) {
2158
- super(dagWrite, formatVersion, root, getEntrySize, chunkHeaderSize);
2159
- this.minSize = minSize;
2160
- this.maxSize = maxSize;
2161
- }
2162
- #addToModified(node) {
2163
- assert(node.isMutable);
2164
- this.#modified.set(node.hash, node);
2165
- this._cache.set(node.hash, node);
2166
- }
2167
- updateNode(node) {
2168
- assert(node.isMutable);
2169
- this.#modified.delete(node.hash);
2170
- node.hash = newRandomHash();
2171
- this.#addToModified(node);
2172
- }
2173
- newInternalNodeImpl(entries, level) {
2174
- const n = new InternalNodeImpl(entries, newRandomHash(), level, true);
2175
- this.#addToModified(n);
2176
- return n;
2177
- }
2178
- newDataNodeImpl(entries) {
2179
- const n = new DataNodeImpl(entries, newRandomHash(), true);
2180
- this.#addToModified(n);
2181
- return n;
2182
- }
2183
- newNodeImpl(entries, level) {
2184
- const n = newNodeImpl(entries, newRandomHash(), level, true);
2185
- this.#addToModified(n);
2186
- return n;
2187
- }
2188
- put(key, value) {
2189
- return this.#lock.withLock(async () => {
2190
- const oldRootNode = await this.getNode(this.rootHash);
2191
- const entrySize = this.getEntrySize(key, value);
2192
- const rootNode = await oldRootNode.set(key, value, entrySize, this);
2193
- if (rootNode.getChildNodeSize(this) > this.maxSize) {
2194
- const headerSize = this.chunkHeaderSize;
2195
- const partitions = partition(
2196
- rootNode.entries,
2197
- (value2) => value2[2],
2198
- this.minSize - headerSize,
2199
- this.maxSize - headerSize
2200
- );
2201
- const { level } = rootNode;
2202
- const entries = partitions.map((entries2) => {
2203
- const node = this.newNodeImpl(entries2, level);
2204
- return createNewInternalEntryForNode(node, this.getEntrySize);
2205
- });
2206
- const newRoot = this.newInternalNodeImpl(entries, level + 1);
2207
- this.rootHash = newRoot.hash;
2208
- return;
2209
- }
2210
- this.rootHash = rootNode.hash;
2211
- });
2212
- }
2213
- del(key) {
2214
- return this.#lock.withLock(async () => {
2215
- const oldRootNode = await this.getNode(this.rootHash);
2216
- const newRootNode = await oldRootNode.del(key, this);
2217
- const found = this.rootHash !== newRootNode.hash;
2218
- if (found) {
2219
- if (newRootNode.level > 0 && newRootNode.entries.length === 1) {
2220
- this.rootHash = newRootNode.entries[0][1];
2221
- } else {
2222
- this.rootHash = newRootNode.hash;
2223
- }
2224
- }
2225
- return found;
2226
- });
2227
- }
2228
- clear() {
2229
- return this.#lock.withLock(() => {
2230
- this.#modified.clear();
2231
- this.rootHash = emptyHash;
2232
- });
2233
- }
2234
- flush() {
2235
- return this.#lock.withLock(async () => {
2236
- const dagWrite = this._dagRead;
2237
- if (this.rootHash === emptyHash) {
2238
- const chunk = dagWrite.createChunk(emptyDataNode, []);
2239
- await dagWrite.putChunk(chunk);
2240
- return chunk.hash;
2241
- }
2242
- const newChunks = [];
2243
- const newRoot = gatherNewChunks(
2244
- this.rootHash,
2245
- newChunks,
2246
- dagWrite.createChunk,
2247
- this.#modified,
2248
- this._formatVersion
2249
- );
2250
- await Promise.all(newChunks.map((chunk) => dagWrite.putChunk(chunk)));
2251
- this.#modified.clear();
2252
- this.rootHash = newRoot;
2253
- return newRoot;
2254
- });
2255
- }
2256
- };
2257
- function gatherNewChunks(hash2, newChunks, createChunk2, modified, formatVersion) {
2258
- const node = modified.get(hash2);
2259
- if (node === void 0) {
2260
- return hash2;
2261
- }
2262
- if (isDataNodeImpl(node)) {
2263
- const chunk2 = createChunk2(toChunkData(node, formatVersion), []);
2264
- newChunks.push(chunk2);
2265
- return chunk2.hash;
2266
- }
2267
- const refs = [];
2268
- const { entries } = node;
2269
- for (let i = 0; i < entries.length; i++) {
2270
- const entry = entries[i];
2271
- const childHash = entry[1];
2272
- const newChildHash = gatherNewChunks(
2273
- childHash,
2274
- newChunks,
2275
- createChunk2,
2276
- modified,
2277
- formatVersion
2278
- );
2279
- if (newChildHash !== childHash) {
2280
- entries[i] = [entry[0], newChildHash, entry[2]];
2281
- }
2282
- refs.push(newChildHash);
2283
- }
2284
- const chunk = createChunk2(toChunkData(node, formatVersion), toRefs(refs));
2285
- newChunks.push(chunk);
2286
- return chunk.hash;
2287
- }
2288
-
2289
- // ../replicache/src/lazy.ts
2290
- function lazy(factory) {
2291
- let value;
2292
- return () => {
2293
- if (value === void 0) {
2294
- value = factory();
2295
- }
2296
- return value;
2297
- };
2298
- }
2299
-
2300
- // ../replicache/src/sync/diff.ts
2301
- var DiffsMap = class extends Map {
2302
- set(key, value) {
2303
- if (value.length === 0) {
2304
- return this;
2305
- }
2306
- return super.set(key, value);
2307
- }
2308
- };
2309
- async function diff2(oldHash, newHash, read, diffConfig, formatVersion) {
2310
- const [oldCommit, newCommit] = await Promise.all([
2311
- commitFromHash(oldHash, read),
2312
- commitFromHash(newHash, read)
2313
- ]);
2314
- return diffCommits(oldCommit, newCommit, read, diffConfig, formatVersion);
2315
- }
2316
- async function diffCommits(oldCommit, newCommit, read, diffConfig, formatVersion) {
2317
- const diffsMap = new DiffsMap();
2318
- if (!diffConfig.shouldComputeDiffs()) {
2319
- return diffsMap;
2320
- }
2321
- const oldMap = new BTreeRead(read, formatVersion, oldCommit.valueHash);
2322
- const newMap = new BTreeRead(read, formatVersion, newCommit.valueHash);
2323
- const valueDiff = await diff(oldMap, newMap);
2324
- diffsMap.set("", valueDiff);
2325
- await addDiffsForIndexes(
2326
- oldCommit,
2327
- newCommit,
2328
- read,
2329
- diffsMap,
2330
- diffConfig,
2331
- formatVersion
2332
- );
2333
- return diffsMap;
2334
- }
2335
- async function addDiffsForIndexes(mainCommit, syncCommit, read, diffsMap, diffConfig, formatVersion) {
2336
- const oldIndexes = readIndexesForRead(mainCommit, read, formatVersion);
2337
- const newIndexes = readIndexesForRead(syncCommit, read, formatVersion);
2338
- for (const [oldIndexName, oldIndex] of oldIndexes) {
2339
- if (!diffConfig.shouldComputeDiffsForIndex(oldIndexName)) {
2340
- continue;
2341
- }
2342
- const newIndex = newIndexes.get(oldIndexName);
2343
- if (newIndex !== void 0) {
2344
- assert(newIndex !== oldIndex);
2345
- const diffs = await diff(oldIndex.map, newIndex.map);
2346
- newIndexes.delete(oldIndexName);
2347
- diffsMap.set(oldIndexName, diffs);
2348
- } else {
2349
- const diffs = await allEntriesAsDiff(oldIndex.map, "del");
2350
- diffsMap.set(oldIndexName, diffs);
2351
- }
2352
- }
2353
- for (const [newIndexName, newIndex] of newIndexes) {
2354
- if (!diffConfig.shouldComputeDiffsForIndex(newIndexName)) {
2355
- continue;
2356
- }
2357
- const diffs = await allEntriesAsDiff(newIndex.map, "add");
2358
- diffsMap.set(newIndexName, diffs);
2359
- }
2360
- }
2361
-
2362
- // ../replicache/src/db/write.ts
2363
- var Write = class extends Read {
2364
- #dagWrite;
2365
- #basis;
2366
- #meta;
2367
- #clientID;
2368
- #formatVersion;
2369
- constructor(dagWrite, map, basis, meta, indexes, clientID, formatVersion) {
2370
- super(dagWrite, map, indexes);
2371
- this.#dagWrite = dagWrite;
2372
- this.#basis = basis;
2373
- this.#meta = meta;
2374
- this.#clientID = clientID;
2375
- this.#formatVersion = formatVersion;
2376
- if (basis === void 0) {
2377
- assert(meta.basisHash === emptyHash);
2378
- } else {
2379
- assert(meta.basisHash === basis.chunk.hash);
2380
- }
2381
- }
2382
- /**
2383
- * The value needs to be frozen since it is kept in memory and used later for
2384
- * comparison as well as returned in `get`.
2385
- */
2386
- async put(lc, key, value) {
2387
- const oldVal = lazy(() => this.map.get(key));
2388
- await updateIndexes(lc, this.indexes, key, oldVal, value);
2389
- await this.map.put(key, value);
2390
- }
2391
- getMutationID() {
2392
- return getMutationID(this.#clientID, this.#dagWrite, this.#meta);
2393
- }
2394
- async del(lc, key) {
2395
- const oldVal = lazy(() => this.map.get(key));
2396
- if (oldVal !== void 0) {
2397
- await updateIndexes(lc, this.indexes, key, oldVal, void 0);
2398
- }
2399
- return this.map.del(key);
2400
- }
2401
- async clear() {
2402
- await this.map.clear();
2403
- const ps = [];
2404
- for (const idx of this.indexes.values()) {
2405
- ps.push(idx.clear());
2406
- }
2407
- await Promise.all(ps);
2408
- }
2409
- async putCommit() {
2410
- const valueHash = await this.map.flush();
2411
- const indexRecords = [];
2412
- for (const index of this.indexes.values()) {
2413
- const valueHash2 = await index.flush();
2414
- const indexRecord = {
2415
- definition: index.meta.definition,
2416
- valueHash: valueHash2
2417
- };
2418
- indexRecords.push(indexRecord);
2419
- }
2420
- let commit;
2421
- const meta = this.#meta;
2422
- switch (meta.type) {
2423
- case LocalDD31: {
2424
- assert(this.#formatVersion >= DD31);
2425
- const {
2426
- basisHash,
2427
- mutationID,
2428
- mutatorName,
2429
- mutatorArgsJSON,
2430
- originalHash,
2431
- timestamp
2432
- } = meta;
2433
- commit = newLocalDD31(
2434
- this.#dagWrite.createChunk,
2435
- basisHash,
2436
- await baseSnapshotHashFromHash(basisHash, this.#dagWrite),
2437
- mutationID,
2438
- mutatorName,
2439
- mutatorArgsJSON,
2440
- originalHash,
2441
- valueHash,
2442
- indexRecords,
2443
- timestamp,
2444
- this.#clientID
2445
- );
2446
- break;
2447
- }
2448
- case SnapshotDD31: {
2449
- assert(this.#formatVersion > DD31);
2450
- const { basisHash, lastMutationIDs, cookieJSON } = meta;
2451
- commit = newSnapshotDD31(
2452
- this.#dagWrite.createChunk,
2453
- basisHash,
2454
- lastMutationIDs,
2455
- cookieJSON,
2456
- valueHash,
2457
- indexRecords
2458
- );
2459
- break;
2460
- }
2461
- }
2462
- await this.#dagWrite.putChunk(commit.chunk);
2463
- return commit;
2464
- }
2465
- // Return value is the hash of the new commit.
2466
- async commit(headName) {
2467
- const commit = await this.putCommit();
2468
- const commitHash = commit.chunk.hash;
2469
- await this.#dagWrite.setHead(headName, commitHash);
2470
- await this.#dagWrite.commit();
2471
- return commitHash;
2472
- }
2473
- async commitWithDiffs(headName, diffConfig) {
2474
- const commit = this.putCommit();
2475
- const diffMap = await this.#generateDiffs(diffConfig);
2476
- const commitHash = (await commit).chunk.hash;
2477
- await this.#dagWrite.setHead(headName, commitHash);
2478
- await this.#dagWrite.commit();
2479
- return [commitHash, diffMap];
2480
- }
2481
- async #generateDiffs(diffConfig) {
2482
- const diffsMap = new DiffsMap();
2483
- if (!diffConfig.shouldComputeDiffs()) {
2484
- return diffsMap;
2485
- }
2486
- let valueDiff = [];
2487
- if (this.#basis) {
2488
- const basisMap = new BTreeRead(
2489
- this.#dagWrite,
2490
- this.#formatVersion,
2491
- this.#basis.valueHash
2492
- );
2493
- valueDiff = await diff(basisMap, this.map);
2494
- }
2495
- diffsMap.set("", valueDiff);
2496
- let basisIndexes;
2497
- if (this.#basis) {
2498
- basisIndexes = readIndexesForRead(
2499
- this.#basis,
2500
- this.#dagWrite,
2501
- this.#formatVersion
2502
- );
2503
- } else {
2504
- basisIndexes = /* @__PURE__ */ new Map();
2505
- }
2506
- for (const [name, index] of this.indexes) {
2507
- if (!diffConfig.shouldComputeDiffsForIndex(name)) {
2508
- continue;
2509
- }
2510
- const basisIndex = basisIndexes.get(name);
2511
- assert(index !== basisIndex);
2512
- const indexDiffResult = await (basisIndex ? diff(basisIndex.map, index.map) : (
2513
- // No basis. All keys are new.
2514
- allEntriesAsDiff(index.map, "add")
2515
- ));
2516
- diffsMap.set(name, indexDiffResult);
2517
- }
2518
- for (const [name, basisIndex] of basisIndexes) {
2519
- if (!this.indexes.has(name) && diffConfig.shouldComputeDiffsForIndex(name)) {
2520
- const indexDiffResult = await allEntriesAsDiff(basisIndex.map, "del");
2521
- diffsMap.set(name, indexDiffResult);
2522
- }
2523
- }
2524
- return diffsMap;
2525
- }
2526
- close() {
2527
- this.#dagWrite.release();
2528
- }
2529
- };
2530
- async function newWriteLocal(basisHash, mutatorName, mutatorArgsJSON, originalHash, dagWrite, timestamp, clientID, formatVersion) {
2531
- const basis = await commitFromHash(basisHash, dagWrite);
2532
- const bTreeWrite = new BTreeWrite(dagWrite, formatVersion, basis.valueHash);
2533
- const mutationID = await basis.getNextMutationID(clientID, dagWrite);
2534
- const indexes = readIndexesForWrite(basis, dagWrite, formatVersion);
2535
- assert(formatVersion >= DD31);
2536
- return new Write(
2537
- dagWrite,
2538
- bTreeWrite,
2539
- basis,
2540
- {
2541
- type: LocalDD31,
2542
- basisHash,
2543
- baseSnapshotHash: await baseSnapshotHashFromHash(basisHash, dagWrite),
2544
- mutatorName,
2545
- mutatorArgsJSON,
2546
- mutationID,
2547
- originalHash,
2548
- timestamp,
2549
- clientID
2550
- },
2551
- indexes,
2552
- clientID,
2553
- formatVersion
2554
- );
2555
- }
2556
- async function newWriteSnapshotDD31(basisHash, lastMutationIDs, cookieJSON, dagWrite, clientID, formatVersion) {
2557
- const basis = await commitFromHash(basisHash, dagWrite);
2558
- const bTreeWrite = new BTreeWrite(dagWrite, formatVersion, basis.valueHash);
2559
- return new Write(
2560
- dagWrite,
2561
- bTreeWrite,
2562
- basis,
2563
- { basisHash, type: SnapshotDD31, lastMutationIDs, cookieJSON },
2564
- readIndexesForWrite(basis, dagWrite, formatVersion),
2565
- clientID,
2566
- formatVersion
2567
- );
2568
- }
2569
- async function updateIndexes(lc, indexes, key, oldValGetter, newVal) {
2570
- const ps = [];
2571
- for (const idx of indexes.values()) {
2572
- const { keyPrefix } = idx.meta.definition;
2573
- if (!keyPrefix || key.startsWith(keyPrefix)) {
2574
- const oldVal = await oldValGetter();
2575
- if (oldVal !== void 0) {
2576
- ps.push(
2577
- indexValue(
2578
- lc,
2579
- idx.map,
2580
- Remove,
2581
- key,
2582
- oldVal,
2583
- idx.meta.definition.jsonPointer,
2584
- idx.meta.definition.allowEmpty ?? false
2585
- )
2586
- );
2587
- }
2588
- if (newVal !== void 0) {
2589
- ps.push(
2590
- indexValue(
2591
- lc,
2592
- idx.map,
2593
- Add,
2594
- key,
2595
- newVal,
2596
- idx.meta.definition.jsonPointer,
2597
- idx.meta.definition.allowEmpty ?? false
2598
- )
2599
- );
2600
- }
2601
- }
2602
- }
2603
- await Promise.all(ps);
2604
- }
2605
- function readIndexesForWrite(commit, dagWrite, formatVersion) {
2606
- const m = /* @__PURE__ */ new Map();
2607
- for (const index of commit.indexes) {
2608
- m.set(
2609
- index.definition.name,
2610
- new IndexWrite(
2611
- index,
2612
- new BTreeWrite(dagWrite, formatVersion, index.valueHash)
2613
- )
2614
- );
2615
- }
2616
- return m;
2617
- }
2618
- async function createIndexBTree(lc, dagWrite, valueMap, prefix, jsonPointer, allowEmpty, formatVersion) {
2619
- const indexMap = new BTreeWrite(dagWrite, formatVersion);
2620
- for await (const entry of valueMap.scan(prefix)) {
2621
- const key = entry[0];
2622
- if (!key.startsWith(prefix)) {
2623
- break;
2624
- }
2625
- await indexValue(
2626
- lc,
2627
- indexMap,
2628
- Add,
2629
- key,
2630
- entry[1],
2631
- jsonPointer,
2632
- allowEmpty
2633
- );
2634
- }
2635
- return indexMap;
2636
- }
2637
-
2638
- // ../replicache/src/sync/ids.ts
2639
- var clientGroupIDSchema = valita_exports.string();
2640
- var clientIDSchema = valita_exports.string();
2641
-
2642
- // ../replicache/src/persist/make-client-id.ts
2643
- function makeClientID() {
2644
- const length = 18;
2645
- const high = randomUint64();
2646
- const low = randomUint64();
2647
- const combined = high << 64n | low;
2648
- return combined.toString(32).slice(-length).padStart(length, "0");
2649
- }
2650
-
2651
- // ../replicache/src/persist/clients.ts
2652
- var clientV5Schema = readonlyObject({
2653
- heartbeatTimestampMs: valita_exports.number(),
2654
- headHash: hashSchema,
2655
- /**
2656
- * The hash of a commit we are in the middle of refreshing into this client's
2657
- * memdag.
2658
- */
2659
- tempRefreshHash: hashSchema.nullable(),
2660
- /**
2661
- * ID of this client's perdag client group. This needs to be sent in pull
2662
- * request (to enable syncing all last mutation ids in the client group).
2663
- */
2664
- clientGroupID: clientGroupIDSchema
2665
- });
2666
- var clientV6Schema = readonlyObject({
2667
- heartbeatTimestampMs: valita_exports.number(),
2668
- /**
2669
- * A set of hashes, which contains:
2670
- * 1. The hash of the last commit this client refreshed from its client group
2671
- * (this is the commit it bootstrapped from until it completes its first
2672
- * refresh).
2673
- * 2. One or more hashes that were added to retain chunks of a commit while it
2674
- * was being refreshed into this client's memdag. (This can be one or more
2675
- * because refresh's cleanup step is a separate transaction and can fail).
2676
- * Upon refresh completing and successfully running its clean up step, this
2677
- * set will contain a single hash: the hash of the last commit this client
2678
- * refreshed.
2679
- */
2680
- refreshHashes: readonlyArray(hashSchema),
2681
- /**
2682
- * The hash of the last snapshot commit persisted by this client to this
2683
- * client's client group, or null if has never persisted a snapshot.
2684
- */
2685
- persistHash: hashSchema.nullable(),
2686
- /**
2687
- * ID of this client's perdag client group. This needs to be sent in pull
2688
- * request (to enable syncing all last mutation ids in the client group).
2689
- */
2690
- clientGroupID: clientGroupIDSchema
2691
- });
2692
- function isClientV6(client) {
2693
- return client.refreshHashes !== void 0;
2694
- }
2695
- var CLIENTS_HEAD_NAME = "clients";
2696
- var clientSchema = valita_exports.union(clientV5Schema, clientV6Schema);
2697
- function assertClient(value) {
2698
- assert2(value, clientSchema);
2699
- }
2700
- function assertClientV6(value) {
2701
- assert2(value, clientV6Schema);
2702
- }
2703
- function chunkDataToClientMap(chunkData) {
2704
- assertObject(chunkData);
2705
- const clients = /* @__PURE__ */ new Map();
2706
- for (const key in chunkData) {
2707
- if (hasOwn(chunkData, key)) {
2708
- const value = chunkData[key];
2709
- if (value !== void 0) {
2710
- assertClient(value);
2711
- clients.set(key, value);
2712
- }
2713
- }
2714
- }
2715
- return clients;
2716
- }
2717
- function clientMapToChunkData(clients, dagWrite) {
2718
- for (const client of clients.values()) {
2719
- if (isClientV6(client)) {
2720
- client.refreshHashes.forEach(dagWrite.assertValidHash);
2721
- if (client.persistHash) {
2722
- dagWrite.assertValidHash(client.persistHash);
2723
- }
2724
- } else {
2725
- dagWrite.assertValidHash(client.headHash);
2726
- if (client.tempRefreshHash) {
2727
- dagWrite.assertValidHash(client.tempRefreshHash);
2728
- }
2729
- }
2730
- }
2731
- return deepFreeze(Object.fromEntries(clients));
2732
- }
2733
- async function getClients(dagRead) {
2734
- const hash2 = await dagRead.getHead(CLIENTS_HEAD_NAME);
2735
- return getClientsAtHash(hash2, dagRead);
2736
- }
2737
- async function getClientsAtHash(hash2, dagRead) {
2738
- if (!hash2) {
2739
- return /* @__PURE__ */ new Map();
2740
- }
2741
- const chunk = await dagRead.getChunk(hash2);
2742
- return chunkDataToClientMap(chunk?.data);
2743
- }
2744
- var ClientStateNotFoundError = class extends Error {
2745
- name = "ClientStateNotFoundError";
2746
- id;
2747
- constructor(id) {
2748
- super(`Client state not found, id: ${id}`);
2749
- this.id = id;
2750
- }
2751
- };
2752
- async function assertHasClientState(id, dagRead) {
2753
- if (!await hasClientState(id, dagRead)) {
2754
- throw new ClientStateNotFoundError(id);
2755
- }
2756
- }
2757
- async function hasClientState(id, dagRead) {
2758
- return !!await getClient(id, dagRead);
2759
- }
2760
- async function getClient(id, dagRead) {
2761
- const clients = await getClients(dagRead);
2762
- return clients.get(id);
2763
- }
2764
- async function mustGetClient(id, dagRead) {
2765
- const client = await getClient(id, dagRead);
2766
- if (!client) {
2767
- throw new ClientStateNotFoundError(id);
2768
- }
2769
- return client;
2770
- }
2771
- function initClientV6(newClientID, lc, perdag, mutatorNames, indexes, formatVersion, enableClientGroupForking) {
2772
- return withWrite(perdag, async (dagWrite) => {
2773
- async function setClientsAndClientGroupAndCommit(basisHash, cookieJSON, valueHash2, indexRecords2) {
2774
- const newSnapshotData = newSnapshotCommitDataDD31(
2775
- basisHash,
2776
- {},
2777
- cookieJSON,
2778
- valueHash2,
2779
- indexRecords2
2780
- );
2781
- const chunk = dagWrite.createChunk(
2782
- newSnapshotData,
2783
- getRefs(newSnapshotData)
2784
- );
2785
- const newClientGroupID = makeClientID();
2786
- const newClient = {
2787
- heartbeatTimestampMs: Date.now(),
2788
- refreshHashes: [chunk.hash],
2789
- persistHash: null,
2790
- clientGroupID: newClientGroupID
2791
- };
2792
- const newClients = new Map(clients).set(newClientID, newClient);
2793
- const clientGroup = {
2794
- headHash: chunk.hash,
2795
- mutatorNames,
2796
- indexes,
2797
- mutationIDs: {},
2798
- lastServerAckdMutationIDs: {},
2799
- disabled: false
2800
- };
2801
- await Promise.all([
2802
- dagWrite.putChunk(chunk),
2803
- setClients(newClients, dagWrite),
2804
- setClientGroup(newClientGroupID, clientGroup, dagWrite)
2805
- ]);
2806
- return [newClient, chunk.hash, newClients, true];
2807
- }
2808
- const clients = await getClients(dagWrite);
2809
- const res = await findMatchingClient(dagWrite, mutatorNames, indexes);
2810
- if (res.type === FIND_MATCHING_CLIENT_TYPE_HEAD) {
2811
- const { clientGroupID, headHash } = res;
2812
- const newClient = {
2813
- clientGroupID,
2814
- refreshHashes: [headHash],
2815
- heartbeatTimestampMs: Date.now(),
2816
- persistHash: null
2817
- };
2818
- const newClients = new Map(clients).set(newClientID, newClient);
2819
- await setClients(newClients, dagWrite);
2820
- return [newClient, headHash, newClients, false];
2821
- }
2822
- if (!enableClientGroupForking || res.type === FIND_MATCHING_CLIENT_TYPE_NEW) {
2823
- const emptyBTreeChunk = dagWrite.createChunk(emptyDataNode, []);
2824
- await dagWrite.putChunk(emptyBTreeChunk);
2825
- const indexRecords2 = [];
2826
- for (const [name, indexDefinition] of Object.entries(indexes)) {
2827
- const chunkIndexDefinition = toChunkIndexDefinition(
2828
- name,
2829
- indexDefinition
2830
- );
2831
- indexRecords2.push({
2832
- definition: chunkIndexDefinition,
2833
- valueHash: emptyBTreeChunk.hash
2834
- });
2835
- }
2836
- return setClientsAndClientGroupAndCommit(
2837
- null,
2838
- null,
2839
- emptyBTreeChunk.hash,
2840
- indexRecords2
2841
- );
2842
- }
2843
- assert(res.type === FIND_MATCHING_CLIENT_TYPE_FORK);
2844
- const { snapshot } = res;
2845
- const indexRecords = [];
2846
- const { valueHash, indexes: oldIndexes } = snapshot;
2847
- const map = new BTreeRead(dagWrite, formatVersion, valueHash);
2848
- for (const [name, indexDefinition] of Object.entries(indexes)) {
2849
- const { prefix = "", jsonPointer, allowEmpty = false } = indexDefinition;
2850
- const chunkIndexDefinition = {
2851
- name,
2852
- keyPrefix: prefix,
2853
- jsonPointer,
2854
- allowEmpty
2855
- };
2856
- const oldIndex = findMatchingOldIndex(oldIndexes, chunkIndexDefinition);
2857
- if (oldIndex) {
2858
- indexRecords.push({
2859
- definition: chunkIndexDefinition,
2860
- valueHash: oldIndex.valueHash
2861
- });
2862
- } else {
2863
- const indexBTree = await createIndexBTree(
2864
- lc,
2865
- dagWrite,
2866
- map,
2867
- prefix,
2868
- jsonPointer,
2869
- allowEmpty,
2870
- formatVersion
2871
- );
2872
- indexRecords.push({
2873
- definition: chunkIndexDefinition,
2874
- valueHash: await indexBTree.flush()
2875
- });
2876
- }
2877
- }
2878
- return setClientsAndClientGroupAndCommit(
2879
- snapshot.meta.basisHash,
2880
- snapshot.meta.cookieJSON,
2881
- snapshot.valueHash,
2882
- indexRecords
2883
- );
2884
- });
2885
- }
2886
- function findMatchingOldIndex(oldIndexes, chunkIndexDefinition) {
2887
- return oldIndexes.find(
2888
- (index) => chunkIndexDefinitionEqualIgnoreName(index.definition, chunkIndexDefinition)
2889
- );
2890
- }
2891
- var FIND_MATCHING_CLIENT_TYPE_NEW = 0;
2892
- var FIND_MATCHING_CLIENT_TYPE_FORK = 1;
2893
- var FIND_MATCHING_CLIENT_TYPE_HEAD = 2;
2894
- async function findMatchingClient(dagRead, mutatorNames, indexes) {
2895
- let newestCookie;
2896
- let bestSnapshot;
2897
- const mutatorNamesSet = new Set(mutatorNames);
2898
- const clientGroups = await getClientGroups(dagRead);
2899
- for (const [clientGroupID, clientGroup] of clientGroups) {
2900
- if (!clientGroup.disabled && mutatorNamesEqual(mutatorNamesSet, clientGroup.mutatorNames) && indexDefinitionsEqual(indexes, clientGroup.indexes)) {
2901
- return {
2902
- type: FIND_MATCHING_CLIENT_TYPE_HEAD,
2903
- clientGroupID,
2904
- headHash: clientGroup.headHash
2905
- };
2906
- }
2907
- const clientGroupSnapshotCommit = await baseSnapshotFromHash(
2908
- clientGroup.headHash,
2909
- dagRead
2910
- );
2911
- assertSnapshotCommitDD31(clientGroupSnapshotCommit);
2912
- const { cookieJSON } = clientGroupSnapshotCommit.meta;
2913
- if (newestCookie === void 0 || compareCookies(cookieJSON, newestCookie) > 0) {
2914
- newestCookie = cookieJSON;
2915
- bestSnapshot = clientGroupSnapshotCommit;
2916
- }
2917
- }
2918
- if (bestSnapshot) {
2919
- return {
2920
- type: FIND_MATCHING_CLIENT_TYPE_FORK,
2921
- snapshot: bestSnapshot
2922
- };
2923
- }
2924
- return { type: FIND_MATCHING_CLIENT_TYPE_NEW };
2925
- }
2926
- function getRefsForClients(clients) {
2927
- const refs = /* @__PURE__ */ new Set();
2928
- for (const client of clients.values()) {
2929
- if (isClientV6(client)) {
2930
- for (const hash2 of client.refreshHashes) {
2931
- refs.add(hash2);
2932
- }
2933
- if (client.persistHash) {
2934
- refs.add(client.persistHash);
2935
- }
2936
- } else {
2937
- refs.add(client.headHash);
2938
- if (client.tempRefreshHash) {
2939
- refs.add(client.tempRefreshHash);
2940
- }
2941
- }
2942
- }
2943
- return toRefs(refs);
2944
- }
2945
- async function getClientGroupForClient(clientID, read) {
2946
- const clientGroupID = await getClientGroupIDForClient(clientID, read);
2947
- if (!clientGroupID) {
2948
- return void 0;
2949
- }
2950
- return getClientGroup(clientGroupID, read);
2951
- }
2952
- async function getClientGroupIDForClient(clientID, read) {
2953
- const client = await getClient(clientID, read);
2954
- return client?.clientGroupID;
2955
- }
2956
- async function setClient(clientID, client, dagWrite) {
2957
- const clients = await getClients(dagWrite);
2958
- const newClients = new Map(clients).set(clientID, client);
2959
- return setClients(newClients, dagWrite);
2960
- }
2961
- async function setClients(clients, dagWrite) {
2962
- const chunkData = clientMapToChunkData(clients, dagWrite);
2963
- const chunk = dagWrite.createChunk(chunkData, getRefsForClients(clients));
2964
- await dagWrite.putChunk(chunk);
2965
- await dagWrite.setHead(CLIENTS_HEAD_NAME, chunk.hash);
2966
- return chunk.hash;
2967
- }
2968
-
2969
- // ../shared/src/objects.ts
2970
- function mapValues(input, mapper) {
2971
- return mapEntries(input, (k, v2) => [k, mapper(v2)]);
2972
- }
2973
- function mapEntries(input, mapper) {
2974
- const output = {};
2975
- for (const entry of Object.entries(input)) {
2976
- const mapped = mapper(entry[0], entry[1]);
2977
- output[mapped[0]] = mapped[1];
2978
- }
2979
- return output;
2980
- }
2981
- function mapAllEntries(input, mapper) {
2982
- const output = {};
2983
- for (const mapped of mapper(Object.entries(input))) {
2984
- output[mapped[0]] = mapped[1];
2985
- }
2986
- return output;
2987
- }
2988
-
2989
- // ../shared/src/json-schema.ts
2990
- import * as valita from "@badrap/valita";
2991
- var path = [];
2992
- var jsonSchema = valita_exports.unknown().chain((v2) => {
2993
- if (isProd) {
2994
- return valita.ok(v2);
2995
- }
2996
- const rv = isJSONValue(v2, path) ? valita.ok(v2) : valita.err({
2997
- message: `Not a JSON value`,
2998
- path: path.slice()
2999
- });
3000
- path.length = 0;
3001
- return rv;
3002
- });
3003
- var jsonObjectSchema = valita_exports.unknown().chain((v2) => {
3004
- if (isProd) {
3005
- return valita.ok(v2);
3006
- }
3007
- const rv = isJSONObject(v2, path) ? valita.ok(v2) : valita.err({
3008
- message: `Not a JSON object`,
3009
- path: path.slice()
3010
- });
3011
- path.length = 0;
3012
- return rv;
3013
- });
3014
-
3015
- // ../shared/src/tdigest-schema.ts
3016
- var tdigestSchema = valita_exports.tuple([valita_exports.number()]).concat(valita_exports.array(valita_exports.number()));
3017
-
3018
- // ../zero-protocol/src/data.ts
3019
- var valueSchema = valita_exports.union(jsonSchema, valita_exports.undefined());
3020
- var rowSchema = readonlyRecord(valueSchema);
3021
-
3022
- // ../zero-protocol/src/analyze-query-result.ts
3023
- var rowCountsByQuerySchema = valita_exports.record(valita_exports.number());
3024
- var rowCountsBySourceSchema = valita_exports.record(rowCountsByQuerySchema);
3025
- var rowsByQuerySchema = valita_exports.record(valita_exports.array(rowSchema));
3026
- var rowsBySourceSchema = valita_exports.record(rowsByQuerySchema);
3027
- var analyzeQueryResultSchema = valita_exports.object({
3028
- warnings: valita_exports.array(valita_exports.string()),
3029
- syncedRows: valita_exports.record(valita_exports.array(rowSchema)).optional(),
3030
- syncedRowCount: valita_exports.number(),
3031
- start: valita_exports.number(),
3032
- /** @deprecated Use start + elapsed instead */
3033
- end: valita_exports.number(),
3034
- elapsed: valita_exports.number().optional(),
3035
- afterPermissions: valita_exports.string().optional(),
3036
- /** @deprecated Use readRowCountsByQuery */
3037
- vendedRowCounts: rowCountsBySourceSchema.optional(),
3038
- /** @deprecated Use readRows */
3039
- vendedRows: rowsBySourceSchema.optional(),
3040
- plans: valita_exports.record(valita_exports.array(valita_exports.string())).optional(),
3041
- readRows: rowsBySourceSchema.optional(),
3042
- readRowCountsByQuery: rowCountsBySourceSchema.optional(),
3043
- readRowCount: valita_exports.number().optional()
3044
- });
3045
-
3046
- // ../zero-protocol/src/ast.ts
3047
- import { compareUTF8 as compareUTF82 } from "compare-utf8";
3048
-
3049
- // ../shared/src/arrays.ts
3050
- function defined(arr) {
3051
- let i = arr.findIndex((x) => x === void 0);
3052
- if (i < 0) {
3053
- return arr;
3054
- }
3055
- const defined2 = arr.slice(0, i);
3056
- for (i++; i < arr.length; i++) {
3057
- const x = arr[i];
3058
- if (x !== void 0) {
3059
- defined2.push(x);
3060
- }
3061
- }
3062
- return defined2;
3063
- }
3064
- function areEqual(arr1, arr2) {
3065
- return arr1.length === arr2.length && arr1.every((e, i) => e === arr2[i]);
3066
- }
3067
-
3068
- // ../shared/src/must.ts
3069
- function must(v2, msg) {
3070
- if (v2 == null) {
3071
- throw new Error(msg ?? `Unexpected ${v2} value`);
3072
- }
3073
- return v2;
3074
- }
3075
-
3076
- // ../zero-protocol/src/ast.ts
3077
- var SUBQ_PREFIX = "zsubq_";
3078
- var selectorSchema = valita_exports.string();
3079
- var toStaticParam = Symbol();
3080
- var planIdSymbol = Symbol("planId");
3081
- var orderingElementSchema = readonly(
3082
- valita_exports.tuple([selectorSchema, literalUnion("asc", "desc")])
3083
- );
3084
- var orderingSchema = readonlyArray(orderingElementSchema);
3085
- var primitiveSchema = valita_exports.union(
3086
- valita_exports.string(),
3087
- valita_exports.number(),
3088
- valita_exports.boolean(),
3089
- valita_exports.null()
3090
- );
3091
- var equalityOpsSchema = literalUnion("=", "!=", "IS", "IS NOT");
3092
- var orderOpsSchema = literalUnion("<", ">", "<=", ">=");
3093
- var likeOpsSchema = literalUnion(
3094
- "LIKE",
3095
- "NOT LIKE",
3096
- "ILIKE",
3097
- "NOT ILIKE"
3098
- );
3099
- var inOpsSchema = literalUnion("IN", "NOT IN");
3100
- var simpleOperatorSchema = valita_exports.union(
3101
- equalityOpsSchema,
3102
- orderOpsSchema,
3103
- likeOpsSchema,
3104
- inOpsSchema
3105
- );
3106
- var literalReferenceSchema = readonlyObject({
3107
- type: valita_exports.literal("literal"),
3108
- value: valita_exports.union(
3109
- valita_exports.string(),
3110
- valita_exports.number(),
3111
- valita_exports.boolean(),
3112
- valita_exports.null(),
3113
- readonlyArray(valita_exports.union(valita_exports.string(), valita_exports.number(), valita_exports.boolean()))
3114
- )
3115
- });
3116
- var columnReferenceSchema = readonlyObject({
3117
- type: valita_exports.literal("column"),
3118
- name: valita_exports.string()
3119
- });
3120
- var parameterReferenceSchema = readonlyObject({
3121
- type: valita_exports.literal("static"),
3122
- // The "namespace" of the injected parameter.
3123
- // Write authorization will send the value of a row
3124
- // prior to the mutation being run (preMutationRow).
3125
- // Read and write authorization will both send the
3126
- // current authentication data (authData).
3127
- anchor: literalUnion("authData", "preMutationRow"),
3128
- field: valita_exports.union(valita_exports.string(), valita_exports.array(valita_exports.string()))
3129
- });
3130
- var conditionValueSchema = valita_exports.union(
3131
- literalReferenceSchema,
3132
- columnReferenceSchema,
3133
- parameterReferenceSchema
3134
- );
3135
- var simpleConditionSchema = readonlyObject({
3136
- type: valita_exports.literal("simple"),
3137
- op: simpleOperatorSchema,
3138
- left: conditionValueSchema,
3139
- right: valita_exports.union(parameterReferenceSchema, literalReferenceSchema)
3140
- });
3141
- var correlatedSubqueryConditionOperatorSchema = literalUnion("EXISTS", "NOT EXISTS");
3142
- var correlatedSubqueryConditionSchema = readonlyObject({
3143
- type: valita_exports.literal("correlatedSubquery"),
3144
- related: valita_exports.lazy(() => correlatedSubquerySchema),
3145
- op: correlatedSubqueryConditionOperatorSchema,
3146
- flip: valita_exports.boolean().optional()
3147
- });
3148
- var conditionSchema = valita_exports.union(
3149
- simpleConditionSchema,
3150
- valita_exports.lazy(() => conjunctionSchema),
3151
- valita_exports.lazy(() => disjunctionSchema),
3152
- correlatedSubqueryConditionSchema
3153
- );
3154
- var conjunctionSchema = readonlyObject({
3155
- type: valita_exports.literal("and"),
3156
- conditions: readonlyArray(conditionSchema)
3157
- });
3158
- var disjunctionSchema = readonlyObject({
3159
- type: valita_exports.literal("or"),
3160
- conditions: readonlyArray(conditionSchema)
3161
- });
3162
- function mustCompoundKey(field) {
3163
- assert(Array.isArray(field) && field.length >= 1);
3164
- return field;
3165
- }
3166
- var compoundKeySchema = readonly(
3167
- valita_exports.tuple([valita_exports.string()]).concat(valita_exports.array(valita_exports.string()))
3168
- );
3169
- var correlationSchema = readonlyObject({
3170
- parentField: compoundKeySchema,
3171
- childField: compoundKeySchema
3172
- });
3173
- var correlatedSubquerySchemaOmitSubquery = readonlyObject({
3174
- correlation: correlationSchema,
3175
- hidden: valita_exports.boolean().optional(),
3176
- system: literalUnion("permissions", "client", "test").optional()
3177
- });
3178
- var correlatedSubquerySchema = correlatedSubquerySchemaOmitSubquery.extend({
3179
- subquery: valita_exports.lazy(() => astSchema)
3180
- });
3181
- var astSchema = readonlyObject({
3182
- schema: valita_exports.string().optional(),
3183
- table: valita_exports.string(),
3184
- alias: valita_exports.string().optional(),
3185
- where: conditionSchema.optional(),
3186
- related: readonlyArray(correlatedSubquerySchema).optional(),
3187
- limit: valita_exports.number().optional(),
3188
- orderBy: orderingSchema.optional(),
3189
- start: valita_exports.object({
3190
- row: rowSchema,
3191
- exclusive: valita_exports.boolean()
3192
- }).optional()
3193
- });
3194
- function transformAST(ast, transform) {
3195
- const { tableName, columnName } = transform;
3196
- const colName = (c) => columnName(ast.table, c);
3197
- const key = (table, k) => {
3198
- const serverKey = k.map((col) => columnName(table, col));
3199
- return mustCompoundKey(serverKey);
3200
- };
3201
- const where = ast.where ? transform.where(ast.where) : void 0;
3202
- const transformed = {
3203
- schema: ast.schema,
3204
- table: tableName(ast.table),
3205
- alias: ast.alias,
3206
- where: where ? transformWhere(where, ast.table, transform) : void 0,
3207
- related: ast.related ? transform.related(
3208
- ast.related.map(
3209
- (r) => ({
3210
- correlation: {
3211
- parentField: key(ast.table, r.correlation.parentField),
3212
- childField: key(r.subquery.table, r.correlation.childField)
3213
- },
3214
- hidden: r.hidden,
3215
- subquery: transformAST(r.subquery, transform),
3216
- system: r.system
3217
- })
3218
- )
3219
- ) : void 0,
3220
- start: ast.start ? {
3221
- ...ast.start,
3222
- row: Object.fromEntries(
3223
- Object.entries(ast.start.row).map(([col, val]) => [
3224
- colName(col),
3225
- val
3226
- ])
3227
- )
3228
- } : void 0,
3229
- limit: ast.limit,
3230
- orderBy: ast.orderBy?.map(([col, dir]) => [colName(col), dir])
3231
- };
3232
- return transformed;
3233
- }
3234
- function transformWhere(where, table, transform) {
3235
- const { columnName } = transform;
3236
- const condValue = (c) => c.type !== "column" ? c : { ...c, name: columnName(table, c.name) };
3237
- const key = (table2, k) => {
3238
- const serverKey = k.map((col) => columnName(table2, col));
3239
- return mustCompoundKey(serverKey);
3240
- };
3241
- if (where.type === "simple") {
3242
- return { ...where, left: condValue(where.left) };
3243
- } else if (where.type === "correlatedSubquery") {
3244
- const { correlation, subquery } = where.related;
3245
- return {
3246
- ...where,
3247
- related: {
3248
- ...where.related,
3249
- correlation: {
3250
- parentField: key(table, correlation.parentField),
3251
- childField: key(subquery.table, correlation.childField)
3252
- },
3253
- subquery: transformAST(subquery, transform)
3254
- }
3255
- };
3256
- }
3257
- return {
3258
- type: where.type,
3259
- conditions: transform.conditions(
3260
- where.conditions.map((c) => transformWhere(c, table, transform))
3261
- )
3262
- };
3263
- }
3264
- var normalizeCache = /* @__PURE__ */ new WeakMap();
3265
- var NORMALIZE_TRANSFORM = {
3266
- tableName: (t) => t,
3267
- columnName: (_, c) => c,
3268
- related: sortedRelated,
3269
- where: flattened,
3270
- conditions: (c) => c.sort(cmpCondition)
3271
- };
3272
- function normalizeAST(ast) {
3273
- let normalized = normalizeCache.get(ast);
3274
- if (!normalized) {
3275
- normalized = transformAST(ast, NORMALIZE_TRANSFORM);
3276
- normalizeCache.set(ast, normalized);
3277
- }
3278
- return normalized;
3279
- }
3280
- function mapAST(ast, mapper) {
3281
- return transformAST(ast, {
3282
- tableName: (table) => mapper.tableName(table),
3283
- columnName: (table, col) => mapper.columnName(table, col),
3284
- related: (r) => r,
3285
- where: (w) => w,
3286
- conditions: (c) => c
3287
- });
3288
- }
3289
- function mapCondition(cond, table, mapper) {
3290
- return transformWhere(cond, table, {
3291
- tableName: (table2) => mapper.tableName(table2),
3292
- columnName: (table2, col) => mapper.columnName(table2, col),
3293
- related: (r) => r,
3294
- where: (w) => w,
3295
- conditions: (c) => c
3296
- });
3297
- }
3298
- function sortedRelated(related) {
3299
- return related.sort(cmpRelated);
3300
- }
3301
- function cmpCondition(a, b) {
3302
- if (a.type === "simple") {
3303
- if (b.type !== "simple") {
3304
- return -1;
3305
- }
3306
- return compareValuePosition(a.left, b.left) || compareUTF8MaybeNull(a.op, b.op) || compareValuePosition(a.right, b.right);
3307
- }
3308
- if (b.type === "simple") {
3309
- return 1;
3310
- }
3311
- if (a.type === "correlatedSubquery") {
3312
- if (b.type !== "correlatedSubquery") {
3313
- return -1;
3314
- }
3315
- return cmpRelated(a.related, b.related) || compareUTF8MaybeNull(a.op, b.op);
3316
- }
3317
- if (b.type === "correlatedSubquery") {
3318
- return -1;
3319
- }
3320
- const val = compareUTF8MaybeNull(a.type, b.type);
3321
- if (val !== 0) {
3322
- return val;
3323
- }
3324
- for (let l = 0, r = 0; l < a.conditions.length && r < b.conditions.length; l++, r++) {
3325
- const val2 = cmpCondition(a.conditions[l], b.conditions[r]);
3326
- if (val2 !== 0) {
3327
- return val2;
3328
- }
3329
- }
3330
- return a.conditions.length - b.conditions.length;
3331
- }
3332
- function compareValuePosition(a, b) {
3333
- if (a.type !== b.type) {
3334
- return compareUTF82(a.type, b.type);
3335
- }
3336
- switch (a.type) {
3337
- case "literal":
3338
- assert(b.type === "literal");
3339
- return compareUTF82(String(a.value), String(b.value));
3340
- case "column":
3341
- assert(b.type === "column");
3342
- return compareUTF82(a.name, b.name);
3343
- case "static":
3344
- throw new Error(
3345
- "Static parameters should be resolved before normalization"
3346
- );
3347
- }
3348
- }
3349
- function cmpRelated(a, b) {
3350
- return compareUTF82(must(a.subquery.alias), must(b.subquery.alias));
3351
- }
3352
- function flattened(cond) {
3353
- if (cond.type === "simple" || cond.type === "correlatedSubquery") {
3354
- return cond;
3355
- }
3356
- const conditions = defined(
3357
- cond.conditions.flatMap(
3358
- (c) => c.type === cond.type ? c.conditions.map((c2) => flattened(c2)) : flattened(c)
3359
- )
3360
- );
3361
- switch (conditions.length) {
3362
- case 0:
3363
- return void 0;
3364
- case 1:
3365
- return conditions[0];
3366
- default:
3367
- return {
3368
- type: cond.type,
3369
- conditions
3370
- };
3371
- }
3372
- }
3373
- function compareUTF8MaybeNull(a, b) {
3374
- if (a !== null && b !== null) {
3375
- return compareUTF82(a, b);
3376
- }
3377
- if (b !== null) {
3378
- return -1;
3379
- }
3380
- if (a !== null) {
3381
- return 1;
3382
- }
3383
- return 0;
3384
- }
3385
-
3386
- // ../zero-protocol/src/inspect-down.ts
3387
- var serverMetricsSchema = valita_exports.object({
3388
- "query-materialization-server": tdigestSchema,
3389
- "query-update-server": tdigestSchema
3390
- });
3391
- var inspectQueryRowSchema = valita_exports.object({
3392
- clientID: valita_exports.string(),
3393
- queryID: valita_exports.string(),
3394
- // This is the server return AST for custom queries
3395
- // TODO: Return server generated AST
3396
- ast: astSchema.nullable(),
3397
- // not null for custom queries
3398
- name: valita_exports.string().nullable(),
3399
- // not null for custom queries
3400
- args: readonlyArray(jsonSchema).nullable(),
3401
- got: valita_exports.boolean(),
3402
- deleted: valita_exports.boolean(),
3403
- ttl: valita_exports.number(),
3404
- inactivatedAt: valita_exports.number().nullable(),
3405
- rowCount: valita_exports.number(),
3406
- metrics: serverMetricsSchema.nullable().optional()
3407
- });
3408
- var inspectBaseDownSchema = valita_exports.object({
3409
- id: valita_exports.string()
3410
- });
3411
- var inspectQueriesDownSchema = inspectBaseDownSchema.extend({
3412
- op: valita_exports.literal("queries"),
3413
- value: valita_exports.array(inspectQueryRowSchema)
3414
- });
3415
- var inspectMetricsDownSchema = inspectBaseDownSchema.extend({
3416
- op: valita_exports.literal("metrics"),
3417
- value: serverMetricsSchema
3418
- });
3419
- var inspectVersionDownSchema = inspectBaseDownSchema.extend({
3420
- op: valita_exports.literal("version"),
3421
- value: valita_exports.string()
3422
- });
3423
- var inspectAuthenticatedDownSchema = inspectBaseDownSchema.extend({
3424
- op: valita_exports.literal("authenticated"),
3425
- value: valita_exports.boolean()
3426
- });
3427
- var inspectAnalyzeQueryDownSchema = inspectBaseDownSchema.extend({
3428
- op: valita_exports.literal("analyze-query"),
3429
- value: analyzeQueryResultSchema
3430
- });
3431
- var inspectErrorDownSchema = inspectBaseDownSchema.extend({
3432
- op: valita_exports.literal("error"),
3433
- value: valita_exports.string()
3434
- });
3435
- var inspectDownBodySchema = valita_exports.union(
3436
- inspectQueriesDownSchema,
3437
- inspectMetricsDownSchema,
3438
- inspectVersionDownSchema,
3439
- inspectAuthenticatedDownSchema,
3440
- inspectAnalyzeQueryDownSchema,
3441
- inspectErrorDownSchema
3442
- );
3443
- var inspectDownMessageSchema = valita_exports.tuple([
3444
- valita_exports.literal("inspect"),
3445
- inspectDownBodySchema
3446
- ]);
3447
-
3448
- // ../shared/src/random-values.ts
3449
- function getNonCryptoRandomValues(array7) {
3450
- if (array7 === null) {
3451
- throw new TypeError("array cannot be null");
3452
- }
3453
- for (let i = 0; i < array7.length; i++) {
3454
- array7[i] = Math.floor(Math.random() * 256);
3455
- }
3456
- return array7;
3457
- }
3458
-
3459
- // ../zero-client/src/util/nanoid.ts
3460
- function nanoid(size = 21) {
3461
- const randomBytes = getNonCryptoRandomValues(new Uint8Array(size));
3462
- return randomBytes.reduce((id, byte) => {
3463
- byte &= 63;
3464
- if (byte < 36) {
3465
- id += byte.toString(36);
3466
- } else if (byte < 62) {
3467
- id += (byte - 26).toString(36).toUpperCase();
3468
- } else if (byte > 62) {
3469
- id += "-";
3470
- } else {
3471
- id += "_";
3472
- }
3473
- return id;
3474
- }, "");
3475
- }
3476
-
3477
- // ../shared/src/hash.ts
3478
- import { xxHash32 } from "js-xxhash";
3479
- var h64 = (s) => hash(s, 2);
3480
- var h128 = (s) => hash(s, 4);
3481
- function hash(str, words) {
3482
- let hash2 = 0n;
3483
- for (let i = 0; i < words; i++) {
3484
- hash2 = (hash2 << 32n) + BigInt(xxHash32(str, i));
3485
- }
3486
- return hash2;
3487
- }
3488
-
3489
- // ../zero-protocol/src/primary-key.ts
3490
- var primaryKeySchema = readonly(
3491
- valita_exports.tuple([valita_exports.string()]).concat(valita_exports.array(valita_exports.string()))
3492
- );
3493
- var primaryKeyValueSchema = valita_exports.union(
3494
- valita_exports.string(),
3495
- valita_exports.number(),
3496
- valita_exports.boolean()
3497
- );
3498
- var primaryKeyValueRecordSchema = readonlyRecord(
3499
- primaryKeyValueSchema
3500
- );
3501
-
3502
- // ../zero-client/src/client/keys.ts
3503
- var DESIRED_QUERIES_KEY_PREFIX = "d/";
3504
- var GOT_QUERIES_KEY_PREFIX = "g/";
3505
- var ENTITIES_KEY_PREFIX = "e/";
3506
- var MUTATIONS_KEY_PREFIX = "m/";
3507
- function toDesiredQueriesKey(clientID, hash2) {
3508
- return DESIRED_QUERIES_KEY_PREFIX + clientID + "/" + hash2;
3509
- }
3510
- function desiredQueriesPrefixForClient(clientID) {
3511
- return DESIRED_QUERIES_KEY_PREFIX + clientID + "/";
3512
- }
3513
- function toGotQueriesKey(hash2) {
3514
- return GOT_QUERIES_KEY_PREFIX + hash2;
3515
- }
3516
- function toMutationResponseKey(mid) {
3517
- return MUTATIONS_KEY_PREFIX + mid.clientID + "/" + mid.id;
3518
- }
3519
- function toPrimaryKeyString(tableName, primaryKey, value) {
3520
- if (primaryKey.length === 1) {
3521
- return ENTITIES_KEY_PREFIX + tableName + "/" + parse(value[primaryKey[0]], primaryKeyValueSchema);
3522
- }
3523
- const values = primaryKey.map((k) => parse(value[k], primaryKeyValueSchema));
3524
- const str = JSON.stringify(values);
3525
- const idSegment = h128(str);
3526
- return ENTITIES_KEY_PREFIX + tableName + "/" + idSegment;
3527
- }
3528
- function sourceNameFromKey(key) {
3529
- const slash = key.indexOf("/", ENTITIES_KEY_PREFIX.length);
3530
- return key.slice(ENTITIES_KEY_PREFIX.length, slash);
3531
- }
3532
-
3533
- // ../zero-client/src/client/inspector/client-group.ts
3534
- var ClientGroup = class {
3535
- #delegate;
3536
- id;
3537
- constructor(delegate, clientGroupID) {
3538
- this.#delegate = delegate;
3539
- this.id = clientGroupID;
3540
- }
3541
- async clients() {
3542
- return (await this.#delegate.lazy).clientGroupClients(
3543
- this.#delegate,
3544
- this.id
3545
- );
3546
- }
3547
- async clientsWithQueries() {
3548
- return (await this.#delegate.lazy).clientGroupClientsWithQueries(
3549
- this.#delegate,
3550
- this.id
3551
- );
3552
- }
3553
- async queries() {
3554
- return (await this.#delegate.lazy).clientGroupQueries(this.#delegate);
3555
- }
3556
- };
3557
-
3558
- // ../zero-client/src/client/inspector/client.ts
3559
- var Client = class {
3560
- #delegate;
3561
- id;
3562
- clientGroup;
3563
- constructor(delegate, clientID, clientGroupID) {
3564
- this.#delegate = delegate;
3565
- this.id = clientID;
3566
- this.clientGroup = new ClientGroup(this.#delegate, clientGroupID);
3567
- }
3568
- async queries() {
3569
- return (await this.#delegate.lazy).clientQueries(this.#delegate, this.id);
3570
- }
3571
- async map() {
3572
- return (await this.#delegate.lazy).clientMap(this.#delegate, this.id);
3573
- }
3574
- async rows(tableName) {
3575
- return (await this.#delegate.lazy).clientRows(
3576
- this.#delegate,
3577
- this.id,
3578
- tableName
3579
- );
3580
- }
3581
- };
3582
-
3583
- // ../shared/src/centroid.ts
3584
- var Centroid = class {
3585
- mean;
3586
- weight;
3587
- constructor(mean, weight) {
3588
- this.mean = mean;
3589
- this.weight = weight;
3590
- }
3591
- add(r) {
3592
- if (r.weight < 0) {
3593
- throw new Error("centroid weight cannot be less than zero");
3594
- }
3595
- if (this.weight !== 0) {
3596
- this.weight += r.weight;
3597
- this.mean += r.weight * (r.mean - this.mean) / this.weight;
3598
- } else {
3599
- this.weight = r.weight;
3600
- this.mean = r.mean;
3601
- }
3602
- }
3603
- };
3604
- function sortCentroidList(centroids) {
3605
- centroids.sort((a, b) => a.mean - b.mean);
3606
- }
3607
-
3608
- // ../shared/src/tdigest.ts
3609
- var TDigest = class _TDigest {
3610
- compression;
3611
- #maxProcessed;
3612
- #maxUnprocessed;
3613
- #processed;
3614
- #unprocessed;
3615
- #cumulative;
3616
- #processedWeight;
3617
- #unprocessedWeight;
3618
- #min;
3619
- #max;
3620
- constructor(compression = 1e3) {
3621
- this.compression = compression;
3622
- this.#maxProcessed = processedSize(0, this.compression);
3623
- this.#maxUnprocessed = unprocessedSize(0, this.compression);
3624
- this.reset();
3625
- }
3626
- /**
3627
- * fromJSON creates a TDigest from a JSON-serializable representation.
3628
- * The data should be an object with compression and centroids array.
3629
- */
3630
- static fromJSON(data) {
3631
- const digest = new _TDigest(data[0]);
3632
- if (data.length % 2 !== 1) {
3633
- throw new Error("Invalid centroids array");
3634
- }
3635
- for (let i = 1; i < data.length; i += 2) {
3636
- digest.add(data[i], data[i + 1]);
3637
- }
3638
- return digest;
3639
- }
3640
- reset() {
3641
- this.#processed = [];
3642
- this.#unprocessed = [];
3643
- this.#cumulative = [];
3644
- this.#processedWeight = 0;
3645
- this.#unprocessedWeight = 0;
3646
- this.#min = Number.MAX_VALUE;
3647
- this.#max = -Number.MAX_VALUE;
3648
- }
3649
- add(mean, weight = 1) {
3650
- this.addCentroid(new Centroid(mean, weight));
3651
- }
3652
- /** AddCentroidList can quickly add multiple centroids. */
3653
- addCentroidList(centroidList) {
3654
- for (const c of centroidList) {
3655
- this.addCentroid(c);
3656
- }
3657
- }
3658
- /**
3659
- * AddCentroid adds a single centroid.
3660
- * Weights which are not a number or are <= 0 are ignored, as are NaN means.
3661
- */
3662
- addCentroid(c) {
3663
- if (Number.isNaN(c.mean) || c.weight <= 0 || Number.isNaN(c.weight) || !Number.isFinite(c.weight)) {
3664
- return;
3665
- }
3666
- this.#unprocessed.push(new Centroid(c.mean, c.weight));
3667
- this.#unprocessedWeight += c.weight;
3668
- if (this.#processed.length > this.#maxProcessed || this.#unprocessed.length > this.#maxUnprocessed) {
3669
- this.#process();
3670
- }
3671
- }
3672
- /**
3673
- * Merges the supplied digest into this digest. Functionally equivalent to
3674
- * calling t.AddCentroidList(t2.Centroids(nil)), but avoids making an extra
3675
- * copy of the CentroidList.
3676
- **/
3677
- merge(t2) {
3678
- t2.#process();
3679
- this.addCentroidList(t2.#processed);
3680
- }
3681
- #process() {
3682
- if (this.#unprocessed.length > 0 || this.#processed.length > this.#maxProcessed) {
3683
- this.#unprocessed.push(...this.#processed);
3684
- sortCentroidList(this.#unprocessed);
3685
- this.#processed.length = 0;
3686
- this.#processed.push(this.#unprocessed[0]);
3687
- this.#processedWeight += this.#unprocessedWeight;
3688
- this.#unprocessedWeight = 0;
3689
- let soFar = this.#unprocessed[0].weight;
3690
- let limit = this.#processedWeight * this.#integratedQ(1);
3691
- for (let i = 1; i < this.#unprocessed.length; i++) {
3692
- const centroid = this.#unprocessed[i];
3693
- const projected = soFar + centroid.weight;
3694
- if (projected <= limit) {
3695
- soFar = projected;
3696
- this.#processed[this.#processed.length - 1].add(centroid);
3697
- } else {
3698
- const k1 = this.#integratedLocation(soFar / this.#processedWeight);
3699
- limit = this.#processedWeight * this.#integratedQ(k1 + 1);
3700
- soFar += centroid.weight;
3701
- this.#processed.push(centroid);
3702
- }
3703
- }
3704
- this.#min = Math.min(this.#min, this.#processed[0].mean);
3705
- this.#max = Math.max(
3706
- this.#max,
3707
- this.#processed[this.#processed.length - 1].mean
3708
- );
3709
- this.#unprocessed.length = 0;
3710
- }
3711
- }
3712
- /**
3713
- * Centroids returns a copy of processed centroids.
3714
- * Useful when aggregating multiple t-digests.
3715
- *
3716
- * Centroids are appended to the passed CentroidList; if you're re-using a
3717
- * buffer, be sure to pass cl[:0].
3718
- */
3719
- centroids(cl = []) {
3720
- this.#process();
3721
- return cl.concat(this.#processed);
3722
- }
3723
- count() {
3724
- this.#process();
3725
- return this.#processedWeight;
3726
- }
3727
- /**
3728
- * toJSON returns a JSON-serializable representation of the digest.
3729
- * This processes the digest and returns an object with compression and centroid data.
3730
- */
3731
- toJSON() {
3732
- this.#process();
3733
- const data = [this.compression];
3734
- for (const centroid of this.#processed) {
3735
- data.push(centroid.mean, centroid.weight);
3736
- }
3737
- return data;
3738
- }
3739
- #updateCumulative() {
3740
- if (this.#cumulative.length > 0 && this.#cumulative[this.#cumulative.length - 1] === this.#processedWeight) {
3741
- return;
3742
- }
3743
- const n = this.#processed.length + 1;
3744
- if (this.#cumulative.length > n) {
3745
- this.#cumulative.length = n;
3746
- }
3747
- let prev = 0;
3748
- for (let i = 0; i < this.#processed.length; i++) {
3749
- const centroid = this.#processed[i];
3750
- const cur = centroid.weight;
3751
- this.#cumulative[i] = prev + cur / 2;
3752
- prev += cur;
3753
- }
3754
- this.#cumulative[this.#processed.length] = prev;
3755
- }
3756
- // Quantile returns the (approximate) quantile of
3757
- // the distribution. Accepted values for q are between 0 and 1.
3758
- // Returns NaN if Count is zero or bad inputs.
3759
- quantile(q) {
3760
- this.#process();
3761
- this.#updateCumulative();
3762
- if (q < 0 || q > 1 || this.#processed.length === 0) {
3763
- return NaN;
3764
- }
3765
- if (this.#processed.length === 1) {
3766
- return this.#processed[0].mean;
3767
- }
3768
- const index = q * this.#processedWeight;
3769
- if (index <= this.#processed[0].weight / 2) {
3770
- return this.#min + 2 * index / this.#processed[0].weight * (this.#processed[0].mean - this.#min);
3771
- }
3772
- const lower = binarySearch(
3773
- this.#cumulative.length,
3774
- (i) => -this.#cumulative[i] + index
3775
- );
3776
- if (lower + 1 !== this.#cumulative.length) {
3777
- const z12 = index - this.#cumulative[lower - 1];
3778
- const z22 = this.#cumulative[lower] - index;
3779
- return weightedAverage(
3780
- this.#processed[lower - 1].mean,
3781
- z22,
3782
- this.#processed[lower].mean,
3783
- z12
3784
- );
3785
- }
3786
- const z1 = index - this.#processedWeight - this.#processed[lower - 1].weight / 2;
3787
- const z2 = this.#processed[lower - 1].weight / 2 - z1;
3788
- return weightedAverage(
3789
- this.#processed[this.#processed.length - 1].mean,
3790
- z1,
3791
- this.#max,
3792
- z2
3793
- );
3794
- }
3795
- /**
3796
- * CDF returns the cumulative distribution function for a given value x.
3797
- */
3798
- cdf(x) {
3799
- this.#process();
3800
- this.#updateCumulative();
3801
- switch (this.#processed.length) {
3802
- case 0:
3803
- return 0;
3804
- case 1: {
3805
- const width = this.#max - this.#min;
3806
- if (x <= this.#min) {
3807
- return 0;
3808
- }
3809
- if (x >= this.#max) {
3810
- return 1;
3811
- }
3812
- if (x - this.#min <= width) {
3813
- return 0.5;
3814
- }
3815
- return (x - this.#min) / width;
3816
- }
3817
- }
3818
- if (x <= this.#min) {
3819
- return 0;
3820
- }
3821
- if (x >= this.#max) {
3822
- return 1;
3823
- }
3824
- const m0 = this.#processed[0].mean;
3825
- if (x <= m0) {
3826
- if (m0 - this.#min > 0) {
3827
- return (x - this.#min) / (m0 - this.#min) * this.#processed[0].weight / this.#processedWeight / 2;
3828
- }
3829
- return 0;
3830
- }
3831
- const mn = this.#processed[this.#processed.length - 1].mean;
3832
- if (x >= mn) {
3833
- if (this.#max - mn > 0) {
3834
- return 1 - (this.#max - x) / (this.#max - mn) * this.#processed[this.#processed.length - 1].weight / this.#processedWeight / 2;
3835
- }
3836
- return 1;
3837
- }
3838
- const upper = binarySearch(
3839
- this.#processed.length,
3840
- // Treat equals as greater than, so we can use the upper index
3841
- // This is equivalent to:
3842
- // i => this.#processed[i].mean > x ? -1 : 1,
3843
- (i) => x - this.#processed[i].mean || 1
3844
- );
3845
- const z1 = x - this.#processed[upper - 1].mean;
3846
- const z2 = this.#processed[upper].mean - x;
3847
- return weightedAverage(
3848
- this.#cumulative[upper - 1],
3849
- z2,
3850
- this.#cumulative[upper],
3851
- z1
3852
- ) / this.#processedWeight;
3853
- }
3854
- #integratedQ(k) {
3855
- return (Math.sin(
3856
- Math.min(k, this.compression) * Math.PI / this.compression - Math.PI / 2
3857
- ) + 1) / 2;
3858
- }
3859
- #integratedLocation(q) {
3860
- return this.compression * (Math.asin(2 * q - 1) + Math.PI / 2) / Math.PI;
3861
- }
3862
- };
3863
- function weightedAverage(x1, w1, x2, w2) {
3864
- if (x1 <= x2) {
3865
- return weightedAverageSorted(x1, w1, x2, w2);
3866
- }
3867
- return weightedAverageSorted(x2, w2, x1, w1);
3868
- }
3869
- function weightedAverageSorted(x1, w1, x2, w2) {
3870
- const x = (x1 * w1 + x2 * w2) / (w1 + w2);
3871
- return Math.max(x1, Math.min(x, x2));
3872
- }
3873
- function processedSize(size, compression) {
3874
- if (size === 0) {
3875
- return Math.ceil(compression) * 2;
3876
- }
3877
- return size;
3878
- }
3879
- function unprocessedSize(size, compression) {
3880
- if (size === 0) {
3881
- return Math.ceil(compression) * 8;
3882
- }
3883
- return size;
3884
- }
3885
-
3886
- // ../zero-client/src/client/inspector/inspector.ts
3887
- var Inspector = class {
3888
- #delegate;
3889
- client;
3890
- clientGroup;
3891
- constructor(rep, delegate, getSocket) {
3892
- this.#delegate = {
3893
- getQueryMetrics: delegate.getQueryMetrics.bind(delegate),
3894
- getAST: delegate.getAST.bind(delegate),
3895
- get metrics() {
3896
- return delegate.metrics;
3897
- },
3898
- rep,
3899
- getSocket,
3900
- lazy: import("./lazy-inspector-OXIFYSSQ.js")
3901
- };
3902
- this.client = new Client(this.#delegate, rep.clientID, rep.clientGroupID);
3903
- this.clientGroup = this.client.clientGroup;
3904
- }
3905
- async metrics() {
3906
- return (await this.#delegate.lazy).inspectorMetrics(this.#delegate);
3907
- }
3908
- async clients() {
3909
- return (await this.#delegate.lazy).inspectorClients(this.#delegate);
3910
- }
3911
- async clientsWithQueries() {
3912
- return (await this.#delegate.lazy).inspectorClientsWithQueries(
3913
- this.#delegate
3914
- );
3915
- }
3916
- async serverVersion() {
3917
- return (await this.#delegate.lazy).serverVersion(this.#delegate);
3918
- }
3919
- async analyzeQuery(query, options) {
3920
- return (await this.#delegate.lazy).analyzeQuery(
3921
- this.#delegate,
3922
- query,
3923
- options
3924
- );
3925
- }
3926
- };
3927
-
3928
- // ../zql/src/query/ttl.ts
3929
- var DEFAULT_TTL_MS = 1e3 * 60 * 5;
3930
- var DEFAULT_PRELOAD_TTL_MS = 0;
3931
- var MAX_TTL = "10m";
3932
- var MAX_TTL_MS = 1e3 * 60 * 10;
3933
- var multiplier = {
3934
- s: 1e3,
3935
- m: 60 * 1e3,
3936
- h: 60 * 60 * 1e3,
3937
- d: 24 * 60 * 60 * 1e3,
3938
- y: 365 * 24 * 60 * 60 * 1e3
3939
- };
3940
- function parseTTL(ttl) {
3941
- if (typeof ttl === "number") {
3942
- return Number.isNaN(ttl) ? 0 : !Number.isFinite(ttl) || ttl < 0 ? -1 : ttl;
3943
- }
3944
- if (ttl === "none") {
3945
- return 0;
3946
- }
3947
- if (ttl === "forever") {
3948
- return -1;
3949
- }
3950
- const multi = multiplier[ttl[ttl.length - 1]];
3951
- return Number(ttl.slice(0, -1)) * multi;
3952
- }
3953
- function compareTTL(a, b) {
3954
- const ap = parseTTL(a);
3955
- const bp = parseTTL(b);
3956
- if (ap === -1 && bp !== -1) {
3957
- return 1;
3958
- }
3959
- if (ap !== -1 && bp === -1) {
3960
- return -1;
3961
- }
3962
- return ap - bp;
3963
- }
3964
- function normalizeTTL(ttl) {
3965
- if (typeof ttl === "string") {
3966
- return ttl;
3967
- }
3968
- if (ttl < 0) {
3969
- return "forever";
3970
- }
3971
- if (ttl === 0) {
3972
- return "none";
3973
- }
3974
- let shortest = ttl.toString();
3975
- const lengthOfNumber = shortest.length;
3976
- for (const unit of ["y", "d", "h", "m", "s"]) {
3977
- const multi = multiplier[unit];
3978
- const value = ttl / multi;
3979
- const candidate = `${value}${unit}`;
3980
- if (candidate.length < shortest.length) {
3981
- shortest = candidate;
3982
- }
3983
- }
3984
- return shortest.length < lengthOfNumber ? shortest : ttl;
3985
- }
3986
- function clampTTL(ttl, lc) {
3987
- const parsedTTL = parseTTL(ttl);
3988
- if (parsedTTL === -1 || parsedTTL > 10 * 60 * 1e3) {
3989
- lc?.warn?.(`TTL (${ttl}) is too high, clamping to ${MAX_TTL}`);
3990
- return parseTTL(MAX_TTL);
3991
- }
3992
- return parsedTTL;
3993
- }
3994
-
3995
- export {
3996
- deepEqual,
3997
- assertJSONValue,
3998
- assertJSONObject,
3999
- stringCompare,
4000
- compareCookies,
4001
- assertCookie,
4002
- DD31,
4003
- V6,
4004
- V7,
4005
- Latest,
4006
- parse,
4007
- test,
4008
- readonly,
4009
- readonlyObject,
4010
- readonlyArray,
4011
- literalUnion,
4012
- valita_exports,
4013
- emptyHash,
4014
- newRandomHash,
4015
- assertHash,
4016
- Chunk,
4017
- assertRefs,
4018
- createChunk,
4019
- ChunkNotFoundError,
4020
- mustGetChunk,
4021
- mustGetHeadHash,
4022
- binarySearch,
4023
- joinIterables,
4024
- once,
4025
- wrapIterable,
4026
- mergeIterables,
4027
- getSizeOfValue,
4028
- BTreeRead,
4029
- DEFAULT_HEAD_NAME,
4030
- commitIsLocalDD31,
4031
- localMutations,
4032
- localMutationsDD31,
4033
- localMutationsGreaterThan,
4034
- baseSnapshotFromHead,
4035
- baseSnapshotFromHash,
4036
- baseSnapshotFromCommit,
4037
- snapshotMetaParts,
4038
- compareCookiesForSnapshots,
4039
- commitFromHash,
4040
- commitFromHead,
4041
- assertLocalMetaDD31,
4042
- isLocalMetaDD31,
4043
- assertSnapshotMetaDD31,
4044
- assertSnapshotCommitDD31,
4045
- asyncIterableToArray,
4046
- diff,
4047
- encodeIndexScanKey,
4048
- decodeIndexKey,
4049
- readFromDefaultHead,
4050
- readFromHash,
4051
- DiffsMap,
4052
- diff2,
4053
- diffCommits,
4054
- addDiffsForIndexes,
4055
- newWriteLocal,
4056
- newWriteSnapshotDD31,
4057
- clientGroupIDSchema,
4058
- clientIDSchema,
4059
- withRead,
4060
- withWriteNoImplicitCommit,
4061
- withWrite,
4062
- using,
4063
- getClientGroups,
4064
- setClientGroups,
4065
- setClientGroup,
4066
- getClientGroup,
4067
- clientGroupHasPendingMutations,
4068
- disableClientGroup,
4069
- makeClientID,
4070
- assertClientV6,
4071
- getClients,
4072
- ClientStateNotFoundError,
4073
- assertHasClientState,
4074
- hasClientState,
4075
- getClient,
4076
- mustGetClient,
4077
- initClientV6,
4078
- getClientGroupForClient,
4079
- getClientGroupIDForClient,
4080
- setClient,
4081
- setClients,
4082
- jsonSchema,
4083
- jsonObjectSchema,
4084
- areEqual,
4085
- must,
4086
- rowSchema,
4087
- SUBQ_PREFIX,
4088
- toStaticParam,
4089
- planIdSymbol,
4090
- astSchema,
4091
- normalizeAST,
4092
- mapAST,
4093
- mapCondition,
4094
- h64,
4095
- mapValues,
4096
- mapEntries,
4097
- mapAllEntries,
4098
- DEFAULT_TTL_MS,
4099
- DEFAULT_PRELOAD_TTL_MS,
4100
- compareTTL,
4101
- normalizeTTL,
4102
- clampTTL,
4103
- getNonCryptoRandomValues,
4104
- inspectQueriesDownSchema,
4105
- inspectMetricsDownSchema,
4106
- inspectVersionDownSchema,
4107
- inspectAuthenticatedDownSchema,
4108
- inspectAnalyzeQueryDownSchema,
4109
- inspectDownMessageSchema,
4110
- primaryKeySchema,
4111
- primaryKeyValueRecordSchema,
4112
- nanoid,
4113
- GOT_QUERIES_KEY_PREFIX,
4114
- ENTITIES_KEY_PREFIX,
4115
- MUTATIONS_KEY_PREFIX,
4116
- toDesiredQueriesKey,
4117
- desiredQueriesPrefixForClient,
4118
- toGotQueriesKey,
4119
- toMutationResponseKey,
4120
- toPrimaryKeyString,
4121
- sourceNameFromKey,
4122
- Client,
4123
- TDigest,
4124
- Inspector
4125
- };
4126
- //# sourceMappingURL=chunk-TJFNGO7E.js.map