@rocicorp/zero 0.26.1 → 0.26.2-canary.4

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 (1086) hide show
  1. package/out/_virtual/_@oxc-project_runtime@0.115.0/helpers/usingCtx.js +57 -0
  2. package/out/_virtual/_rolldown/runtime.js +27 -0
  3. package/out/analyze-query/src/bin-analyze.js +195 -283
  4. package/out/analyze-query/src/bin-analyze.js.map +1 -1
  5. package/out/analyze-query/src/bin-transform.js +35 -40
  6. package/out/analyze-query/src/bin-transform.js.map +1 -1
  7. package/out/analyze-query/src/explain-queries.js +11 -13
  8. package/out/analyze-query/src/explain-queries.js.map +1 -1
  9. package/out/analyze-query/src/run-ast.js +68 -103
  10. package/out/analyze-query/src/run-ast.js.map +1 -1
  11. package/out/ast-to-zql/src/ast-to-zql.js +105 -153
  12. package/out/ast-to-zql/src/ast-to-zql.js.map +1 -1
  13. package/out/ast-to-zql/src/bin.js +57 -62
  14. package/out/ast-to-zql/src/bin.js.map +1 -1
  15. package/out/ast-to-zql/src/format.js +14 -13
  16. package/out/ast-to-zql/src/format.js.map +1 -1
  17. package/out/datadog/src/datadog-log-sink.js +148 -213
  18. package/out/datadog/src/datadog-log-sink.js.map +1 -1
  19. package/out/otel/src/enabled.js +9 -11
  20. package/out/otel/src/enabled.js.map +1 -1
  21. package/out/otel/src/log-options.js +25 -35
  22. package/out/otel/src/log-options.js.map +1 -1
  23. package/out/otel/src/maybe-time.js +13 -14
  24. package/out/otel/src/maybe-time.js.map +1 -1
  25. package/out/otel/src/span.js +23 -26
  26. package/out/otel/src/span.js.map +1 -1
  27. package/out/otel/src/test-log-config.js +11 -10
  28. package/out/otel/src/test-log-config.js.map +1 -1
  29. package/out/otel/src/version.js +6 -5
  30. package/out/otel/src/version.js.map +1 -1
  31. package/out/replicache/src/async-iterable-to-array.js +8 -9
  32. package/out/replicache/src/async-iterable-to-array.js.map +1 -1
  33. package/out/replicache/src/bg-interval.js +28 -35
  34. package/out/replicache/src/bg-interval.js.map +1 -1
  35. package/out/replicache/src/btree/diff.js +6 -5
  36. package/out/replicache/src/btree/diff.js.map +1 -1
  37. package/out/replicache/src/btree/node.js +281 -372
  38. package/out/replicache/src/btree/node.js.map +1 -1
  39. package/out/replicache/src/btree/read.js +155 -256
  40. package/out/replicache/src/btree/read.js.map +1 -1
  41. package/out/replicache/src/btree/splice.js +60 -80
  42. package/out/replicache/src/btree/splice.js.map +1 -1
  43. package/out/replicache/src/btree/write.js +134 -158
  44. package/out/replicache/src/btree/write.js.map +1 -1
  45. package/out/replicache/src/call-default-fetch.js +28 -32
  46. package/out/replicache/src/call-default-fetch.js.map +1 -1
  47. package/out/replicache/src/config.js +2 -0
  48. package/out/replicache/src/connection-loop-delegates.js +31 -33
  49. package/out/replicache/src/connection-loop-delegates.js.map +1 -1
  50. package/out/replicache/src/connection-loop.js +174 -240
  51. package/out/replicache/src/connection-loop.js.map +1 -1
  52. package/out/replicache/src/cookies.js +22 -32
  53. package/out/replicache/src/cookies.js.map +1 -1
  54. package/out/replicache/src/dag/chunk.js +44 -50
  55. package/out/replicache/src/dag/chunk.js.map +1 -1
  56. package/out/replicache/src/dag/gc.js +94 -114
  57. package/out/replicache/src/dag/gc.js.map +1 -1
  58. package/out/replicache/src/dag/key.js +9 -11
  59. package/out/replicache/src/dag/key.js.map +1 -1
  60. package/out/replicache/src/dag/lazy-store.js +458 -510
  61. package/out/replicache/src/dag/lazy-store.js.map +1 -1
  62. package/out/replicache/src/dag/store-impl.js +147 -178
  63. package/out/replicache/src/dag/store-impl.js.map +1 -1
  64. package/out/replicache/src/dag/store.js +19 -22
  65. package/out/replicache/src/dag/store.js.map +1 -1
  66. package/out/replicache/src/dag/visitor.js +23 -21
  67. package/out/replicache/src/dag/visitor.js.map +1 -1
  68. package/out/replicache/src/db/commit.js +209 -283
  69. package/out/replicache/src/db/commit.js.map +1 -1
  70. package/out/replicache/src/db/index.js +79 -122
  71. package/out/replicache/src/db/index.js.map +1 -1
  72. package/out/replicache/src/db/read.js +44 -60
  73. package/out/replicache/src/db/read.js.map +1 -1
  74. package/out/replicache/src/db/rebase.js +22 -77
  75. package/out/replicache/src/db/rebase.js.map +1 -1
  76. package/out/replicache/src/db/write.js +162 -296
  77. package/out/replicache/src/db/write.js.map +1 -1
  78. package/out/replicache/src/deleted-clients.js +59 -87
  79. package/out/replicache/src/deleted-clients.js.map +1 -1
  80. package/out/replicache/src/error-responses.js +18 -26
  81. package/out/replicache/src/error-responses.js.map +1 -1
  82. package/out/replicache/src/expo-sqlite.js +2 -0
  83. package/out/replicache/src/frozen-json.js +74 -108
  84. package/out/replicache/src/frozen-json.js.map +1 -1
  85. package/out/replicache/src/get-default-puller.js +34 -46
  86. package/out/replicache/src/get-default-puller.js.map +1 -1
  87. package/out/replicache/src/get-default-pusher.js +25 -33
  88. package/out/replicache/src/get-default-pusher.js.map +1 -1
  89. package/out/replicache/src/get-kv-store-provider.js +18 -20
  90. package/out/replicache/src/get-kv-store-provider.js.map +1 -1
  91. package/out/replicache/src/hash.js +29 -29
  92. package/out/replicache/src/hash.js.map +1 -1
  93. package/out/replicache/src/http-request-info.js +9 -8
  94. package/out/replicache/src/http-request-info.js.map +1 -1
  95. package/out/replicache/src/impl.js +2 -0
  96. package/out/replicache/src/index-defs.js +17 -28
  97. package/out/replicache/src/index-defs.js.map +1 -1
  98. package/out/replicache/src/kv/expo-sqlite/store.js +52 -50
  99. package/out/replicache/src/kv/expo-sqlite/store.js.map +1 -1
  100. package/out/replicache/src/kv/idb-store-with-mem-fallback.js +71 -68
  101. package/out/replicache/src/kv/idb-store-with-mem-fallback.js.map +1 -1
  102. package/out/replicache/src/kv/idb-store.js +144 -168
  103. package/out/replicache/src/kv/idb-store.js.map +1 -1
  104. package/out/replicache/src/kv/mem-store.js +57 -45
  105. package/out/replicache/src/kv/mem-store.js.map +1 -1
  106. package/out/replicache/src/kv/op-sqlite/store.js +56 -62
  107. package/out/replicache/src/kv/op-sqlite/store.js.map +1 -1
  108. package/out/replicache/src/kv/op-sqlite/types.d.ts.map +1 -1
  109. package/out/replicache/src/kv/op-sqlite/types.js +7 -6
  110. package/out/replicache/src/kv/op-sqlite/types.js.map +1 -1
  111. package/out/replicache/src/kv/read-impl.js +26 -25
  112. package/out/replicache/src/kv/read-impl.js.map +1 -1
  113. package/out/replicache/src/kv/sqlite-store.js +194 -207
  114. package/out/replicache/src/kv/sqlite-store.js.map +1 -1
  115. package/out/replicache/src/kv/throw-if-closed.js +12 -19
  116. package/out/replicache/src/kv/throw-if-closed.js.map +1 -1
  117. package/out/replicache/src/kv/write-impl-base.js +44 -56
  118. package/out/replicache/src/kv/write-impl-base.js.map +1 -1
  119. package/out/replicache/src/kv/write-impl.js +22 -26
  120. package/out/replicache/src/kv/write-impl.js.map +1 -1
  121. package/out/replicache/src/lazy.js +10 -11
  122. package/out/replicache/src/lazy.js.map +1 -1
  123. package/out/replicache/src/log-options.js +14 -7
  124. package/out/replicache/src/log-options.js.map +1 -1
  125. package/out/replicache/src/make-idb-name.js +14 -9
  126. package/out/replicache/src/make-idb-name.js.map +1 -1
  127. package/out/replicache/src/mutation-recovery.js +12 -0
  128. package/out/replicache/src/mutation-recovery.js.map +1 -0
  129. package/out/replicache/src/new-client-channel.js +34 -42
  130. package/out/replicache/src/new-client-channel.js.map +1 -1
  131. package/out/replicache/src/on-persist-channel.js +26 -29
  132. package/out/replicache/src/on-persist-channel.js.map +1 -1
  133. package/out/replicache/src/op-sqlite.js +2 -0
  134. package/out/replicache/src/patch-operation.js +27 -36
  135. package/out/replicache/src/patch-operation.js.map +1 -1
  136. package/out/replicache/src/pending-mutations.js +14 -12
  137. package/out/replicache/src/pending-mutations.js.map +1 -1
  138. package/out/replicache/src/persist/client-gc.js +36 -51
  139. package/out/replicache/src/persist/client-gc.js.map +1 -1
  140. package/out/replicache/src/persist/client-group-gc.js +29 -36
  141. package/out/replicache/src/persist/client-group-gc.js.map +1 -1
  142. package/out/replicache/src/persist/client-groups.js +80 -154
  143. package/out/replicache/src/persist/client-groups.js.map +1 -1
  144. package/out/replicache/src/persist/clients.js +212 -307
  145. package/out/replicache/src/persist/clients.js.map +1 -1
  146. package/out/replicache/src/persist/collect-idb-databases.js +109 -171
  147. package/out/replicache/src/persist/collect-idb-databases.js.map +1 -1
  148. package/out/replicache/src/persist/gather-mem-only-visitor.js +23 -24
  149. package/out/replicache/src/persist/gather-mem-only-visitor.js.map +1 -1
  150. package/out/replicache/src/persist/gather-not-cached-visitor.js +35 -33
  151. package/out/replicache/src/persist/gather-not-cached-visitor.js.map +1 -1
  152. package/out/replicache/src/persist/heartbeat.js +31 -41
  153. package/out/replicache/src/persist/heartbeat.js.map +1 -1
  154. package/out/replicache/src/persist/idb-databases-store-db-name.js +9 -12
  155. package/out/replicache/src/persist/idb-databases-store-db-name.js.map +1 -1
  156. package/out/replicache/src/persist/idb-databases-store.js +78 -97
  157. package/out/replicache/src/persist/idb-databases-store.js.map +1 -1
  158. package/out/replicache/src/persist/make-client-id.js +13 -9
  159. package/out/replicache/src/persist/make-client-id.js.map +1 -1
  160. package/out/replicache/src/persist/persist.js +113 -174
  161. package/out/replicache/src/persist/persist.js.map +1 -1
  162. package/out/replicache/src/persist/refresh.js +94 -183
  163. package/out/replicache/src/persist/refresh.js.map +1 -1
  164. package/out/replicache/src/process-scheduler.js +122 -143
  165. package/out/replicache/src/process-scheduler.js.map +1 -1
  166. package/out/replicache/src/pusher.js +21 -26
  167. package/out/replicache/src/pusher.js.map +1 -1
  168. package/out/replicache/src/replicache-impl.js +844 -1184
  169. package/out/replicache/src/replicache-impl.js.map +1 -1
  170. package/out/replicache/src/report-error.js +9 -6
  171. package/out/replicache/src/report-error.js.map +1 -1
  172. package/out/replicache/src/request-idle.js +13 -11
  173. package/out/replicache/src/request-idle.js.map +1 -1
  174. package/out/replicache/src/scan-iterator.d.ts.map +1 -1
  175. package/out/replicache/src/scan-iterator.js +108 -135
  176. package/out/replicache/src/scan-iterator.js.map +1 -1
  177. package/out/replicache/src/scan-options.js +33 -39
  178. package/out/replicache/src/scan-options.js.map +1 -1
  179. package/out/replicache/src/set-interval-with-signal.js +11 -10
  180. package/out/replicache/src/set-interval-with-signal.js.map +1 -1
  181. package/out/replicache/src/sqlite.js +2 -0
  182. package/out/replicache/src/subscriptions.js +222 -338
  183. package/out/replicache/src/subscriptions.js.map +1 -1
  184. package/out/replicache/src/sync/diff.js +52 -65
  185. package/out/replicache/src/sync/diff.js.map +1 -1
  186. package/out/replicache/src/sync/ids.js +8 -9
  187. package/out/replicache/src/sync/ids.js.map +1 -1
  188. package/out/replicache/src/sync/patch.js +34 -45
  189. package/out/replicache/src/sync/patch.js.map +1 -1
  190. package/out/replicache/src/sync/pull-error.js +15 -15
  191. package/out/replicache/src/sync/pull-error.js.map +1 -1
  192. package/out/replicache/src/sync/pull.js +145 -283
  193. package/out/replicache/src/sync/pull.js.map +1 -1
  194. package/out/replicache/src/sync/push.js +64 -79
  195. package/out/replicache/src/sync/push.js.map +1 -1
  196. package/out/replicache/src/sync/request-id.js +23 -15
  197. package/out/replicache/src/sync/request-id.js.map +1 -1
  198. package/out/replicache/src/sync/sync-head-name.js +6 -5
  199. package/out/replicache/src/sync/sync-head-name.js.map +1 -1
  200. package/out/replicache/src/to-error.js +7 -8
  201. package/out/replicache/src/to-error.js.map +1 -1
  202. package/out/replicache/src/transaction-closed-error.js +15 -15
  203. package/out/replicache/src/transaction-closed-error.js.map +1 -1
  204. package/out/replicache/src/transactions.js +120 -140
  205. package/out/replicache/src/transactions.js.map +1 -1
  206. package/out/replicache/src/version.js +9 -5
  207. package/out/replicache/src/version.js.map +1 -1
  208. package/out/replicache/src/with-transactions.js +23 -20
  209. package/out/replicache/src/with-transactions.js.map +1 -1
  210. package/out/shared/src/abort-error.js +7 -6
  211. package/out/shared/src/abort-error.js.map +1 -1
  212. package/out/shared/src/arrays.js +35 -42
  213. package/out/shared/src/arrays.js.map +1 -1
  214. package/out/shared/src/asserts.js +21 -45
  215. package/out/shared/src/asserts.js.map +1 -1
  216. package/out/shared/src/bigint-json.js +42 -38
  217. package/out/shared/src/bigint-json.js.map +1 -1
  218. package/out/shared/src/binary-search.js +27 -18
  219. package/out/shared/src/binary-search.js.map +1 -1
  220. package/out/shared/src/broadcast-channel.js +20 -23
  221. package/out/shared/src/broadcast-channel.js.map +1 -1
  222. package/out/shared/src/browser-env.js +11 -17
  223. package/out/shared/src/browser-env.js.map +1 -1
  224. package/out/shared/src/btree-set.js +419 -481
  225. package/out/shared/src/btree-set.js.map +1 -1
  226. package/out/shared/src/cache.js +43 -36
  227. package/out/shared/src/cache.js.map +1 -1
  228. package/out/shared/src/centroid.js +24 -26
  229. package/out/shared/src/centroid.js.map +1 -1
  230. package/out/shared/src/config.js +6 -6
  231. package/out/shared/src/config.js.map +1 -1
  232. package/out/shared/src/custom-key-map.js +54 -58
  233. package/out/shared/src/custom-key-map.js.map +1 -1
  234. package/out/shared/src/custom-key-set.js +53 -51
  235. package/out/shared/src/custom-key-set.js.map +1 -1
  236. package/out/shared/src/deep-clone.js +30 -41
  237. package/out/shared/src/deep-clone.js.map +1 -1
  238. package/out/shared/src/deep-merge.js +25 -24
  239. package/out/shared/src/deep-merge.js.map +1 -1
  240. package/out/shared/src/document-visible.js +63 -70
  241. package/out/shared/src/document-visible.js.map +1 -1
  242. package/out/shared/src/dotenv.js +7 -3
  243. package/out/shared/src/dotenv.js.map +1 -1
  244. package/out/shared/src/error.js +43 -64
  245. package/out/shared/src/error.js.map +1 -1
  246. package/out/shared/src/has-own.js +6 -5
  247. package/out/shared/src/has-own.js.map +1 -1
  248. package/out/shared/src/hash.js +15 -14
  249. package/out/shared/src/hash.js.map +1 -1
  250. package/out/shared/src/iterables.js +34 -47
  251. package/out/shared/src/iterables.js.map +1 -1
  252. package/out/shared/src/json-schema.js +25 -30
  253. package/out/shared/src/json-schema.js.map +1 -1
  254. package/out/shared/src/json.js +90 -129
  255. package/out/shared/src/json.js.map +1 -1
  256. package/out/shared/src/logging-test-utils.js +9 -11
  257. package/out/shared/src/logging-test-utils.js.map +1 -1
  258. package/out/shared/src/logging.js +75 -95
  259. package/out/shared/src/logging.js.map +1 -1
  260. package/out/shared/src/must.js +7 -8
  261. package/out/shared/src/must.js.map +1 -1
  262. package/out/shared/src/navigator.js +6 -5
  263. package/out/shared/src/navigator.js.map +1 -1
  264. package/out/shared/src/object-traversal.js +23 -23
  265. package/out/shared/src/object-traversal.js.map +1 -1
  266. package/out/shared/src/objects.js +15 -18
  267. package/out/shared/src/objects.js.map +1 -1
  268. package/out/shared/src/options.js +225 -302
  269. package/out/shared/src/options.js.map +1 -1
  270. package/out/shared/src/parse-big-int.js +12 -11
  271. package/out/shared/src/parse-big-int.js.map +1 -1
  272. package/out/shared/src/promise-race.js +21 -17
  273. package/out/shared/src/promise-race.js.map +1 -1
  274. package/out/shared/src/queue.js +124 -124
  275. package/out/shared/src/queue.js.map +1 -1
  276. package/out/shared/src/rand.js +13 -7
  277. package/out/shared/src/rand.js.map +1 -1
  278. package/out/shared/src/random-uint64.js +8 -7
  279. package/out/shared/src/random-uint64.js.map +1 -1
  280. package/out/shared/src/random-values.js +8 -11
  281. package/out/shared/src/random-values.js.map +1 -1
  282. package/out/shared/src/record-proxy.js +68 -57
  283. package/out/shared/src/record-proxy.js.map +1 -1
  284. package/out/shared/src/resolved-promises.js +9 -11
  285. package/out/shared/src/resolved-promises.js.map +1 -1
  286. package/out/shared/src/sentinels.js +9 -12
  287. package/out/shared/src/sentinels.js.map +1 -1
  288. package/out/shared/src/set-utils.js +41 -63
  289. package/out/shared/src/set-utils.js.map +1 -1
  290. package/out/shared/src/size-of-value.js +55 -51
  291. package/out/shared/src/size-of-value.js.map +1 -1
  292. package/out/shared/src/sleep.js +50 -45
  293. package/out/shared/src/sleep.js.map +1 -1
  294. package/out/shared/src/string-compare.js +8 -11
  295. package/out/shared/src/string-compare.js.map +1 -1
  296. package/out/shared/src/subscribable.js +34 -33
  297. package/out/shared/src/subscribable.js.map +1 -1
  298. package/out/shared/src/tdigest-schema.js +11 -7
  299. package/out/shared/src/tdigest-schema.js.map +1 -1
  300. package/out/shared/src/tdigest.js +197 -270
  301. package/out/shared/src/tdigest.js.map +1 -1
  302. package/out/shared/src/valita.js +145 -174
  303. package/out/shared/src/valita.js.map +1 -1
  304. package/out/z2s/src/compiler.d.ts.map +1 -1
  305. package/out/z2s/src/compiler.js +238 -468
  306. package/out/z2s/src/compiler.js.map +1 -1
  307. package/out/z2s/src/sql.d.ts +0 -1
  308. package/out/z2s/src/sql.d.ts.map +1 -1
  309. package/out/z2s/src/sql.js +149 -194
  310. package/out/z2s/src/sql.js.map +1 -1
  311. package/out/zero/package.js +194 -0
  312. package/out/zero/package.js.map +1 -0
  313. package/out/zero/src/adapters/drizzle.js +1 -6
  314. package/out/zero/src/adapters/pg.js +1 -6
  315. package/out/zero/src/adapters/postgresjs.js +1 -6
  316. package/out/zero/src/adapters/prisma.js +1 -5
  317. package/out/zero/src/analyze-query.js +1 -1
  318. package/out/zero/src/ast-to-zql.js +1 -1
  319. package/out/zero/src/bindings.js +6 -21
  320. package/out/zero/src/build-schema.js +5 -1
  321. package/out/zero/src/build-schema.js.map +1 -1
  322. package/out/zero/src/change-protocol/v0.js +3 -5
  323. package/out/zero/src/cli.js +2 -2
  324. package/out/zero/src/deploy-permissions.js +1 -1
  325. package/out/zero/src/expo-sqlite.js +2 -4
  326. package/out/zero/src/op-sqlite.js +2 -4
  327. package/out/zero/src/pg.js +2 -20
  328. package/out/zero/src/react-native.js +16 -12
  329. package/out/zero/src/react-native.js.map +1 -1
  330. package/out/zero/src/react.js +3 -12
  331. package/out/zero/src/server/runner/main.js +2 -0
  332. package/out/zero/src/server.js +2 -17
  333. package/out/zero/src/solid.js +3 -12
  334. package/out/zero/src/sqlite.js +2 -6
  335. package/out/zero/src/transform-query.js +1 -1
  336. package/out/zero/src/zero-cache-dev.js +124 -151
  337. package/out/zero/src/zero-cache-dev.js.map +1 -1
  338. package/out/zero/src/zero-out.js +9 -6
  339. package/out/zero/src/zero-out.js.map +1 -1
  340. package/out/zero/src/zero.js +6 -55
  341. package/out/zero/src/zqlite.js +2 -7
  342. package/out/zero-cache/src/auth/auth.js +138 -172
  343. package/out/zero-cache/src/auth/auth.js.map +1 -1
  344. package/out/zero-cache/src/auth/jwt.js +25 -33
  345. package/out/zero-cache/src/auth/jwt.js.map +1 -1
  346. package/out/zero-cache/src/auth/load-permissions.js +54 -62
  347. package/out/zero-cache/src/auth/load-permissions.js.map +1 -1
  348. package/out/zero-cache/src/auth/read-authorizer.js +70 -80
  349. package/out/zero-cache/src/auth/read-authorizer.js.map +1 -1
  350. package/out/zero-cache/src/auth/write-authorizer.js +284 -432
  351. package/out/zero-cache/src/auth/write-authorizer.js.map +1 -1
  352. package/out/zero-cache/src/config/network.js +31 -45
  353. package/out/zero-cache/src/config/network.js.map +1 -1
  354. package/out/zero-cache/src/config/normalize.js +81 -83
  355. package/out/zero-cache/src/config/normalize.js.map +1 -1
  356. package/out/zero-cache/src/config/server-context.js +32 -29
  357. package/out/zero-cache/src/config/server-context.js.map +1 -1
  358. package/out/zero-cache/src/config/zero-config.js +753 -833
  359. package/out/zero-cache/src/config/zero-config.js.map +1 -1
  360. package/out/zero-cache/src/custom/fetch.js +183 -230
  361. package/out/zero-cache/src/custom/fetch.js.map +1 -1
  362. package/out/zero-cache/src/custom-queries/transform-query.js +93 -99
  363. package/out/zero-cache/src/custom-queries/transform-query.js.map +1 -1
  364. package/out/zero-cache/src/db/create.js +27 -29
  365. package/out/zero-cache/src/db/create.js.map +1 -1
  366. package/out/zero-cache/src/db/delete-lite-db.js +11 -7
  367. package/out/zero-cache/src/db/delete-lite-db.js.map +1 -1
  368. package/out/zero-cache/src/db/lite-tables.js +118 -158
  369. package/out/zero-cache/src/db/lite-tables.js.map +1 -1
  370. package/out/zero-cache/src/db/migration-lite.js +110 -178
  371. package/out/zero-cache/src/db/migration-lite.js.map +1 -1
  372. package/out/zero-cache/src/db/migration.js +82 -151
  373. package/out/zero-cache/src/db/migration.js.map +1 -1
  374. package/out/zero-cache/src/db/mode-enum.js +8 -9
  375. package/out/zero-cache/src/db/mode-enum.js.map +1 -1
  376. package/out/zero-cache/src/db/pg-copy.js +56 -54
  377. package/out/zero-cache/src/db/pg-copy.js.map +1 -1
  378. package/out/zero-cache/src/db/pg-to-lite.js +74 -110
  379. package/out/zero-cache/src/db/pg-to-lite.js.map +1 -1
  380. package/out/zero-cache/src/db/pg-type-parser.js +19 -36
  381. package/out/zero-cache/src/db/pg-type-parser.js.map +1 -1
  382. package/out/zero-cache/src/db/run-transaction.js +19 -20
  383. package/out/zero-cache/src/db/run-transaction.js.map +1 -1
  384. package/out/zero-cache/src/db/specs.js +42 -78
  385. package/out/zero-cache/src/db/specs.js.map +1 -1
  386. package/out/zero-cache/src/db/statements.js +52 -59
  387. package/out/zero-cache/src/db/statements.js.map +1 -1
  388. package/out/zero-cache/src/db/transaction-pool.js +376 -400
  389. package/out/zero-cache/src/db/transaction-pool.js.map +1 -1
  390. package/out/zero-cache/src/db/warmup.js +13 -24
  391. package/out/zero-cache/src/db/warmup.js.map +1 -1
  392. package/out/zero-cache/src/observability/events.js +89 -99
  393. package/out/zero-cache/src/observability/events.js.map +1 -1
  394. package/out/zero-cache/src/observability/metrics.js +30 -54
  395. package/out/zero-cache/src/observability/metrics.js.map +1 -1
  396. package/out/zero-cache/src/scripts/decommission.js +42 -47
  397. package/out/zero-cache/src/scripts/decommission.js.map +1 -1
  398. package/out/zero-cache/src/scripts/deploy-permissions.js +106 -144
  399. package/out/zero-cache/src/scripts/deploy-permissions.js.map +1 -1
  400. package/out/zero-cache/src/scripts/permissions.js +86 -107
  401. package/out/zero-cache/src/scripts/permissions.js.map +1 -1
  402. package/out/zero-cache/src/server/anonymous-otel-start.js +306 -440
  403. package/out/zero-cache/src/server/anonymous-otel-start.js.map +1 -1
  404. package/out/zero-cache/src/server/change-streamer.d.ts.map +1 -1
  405. package/out/zero-cache/src/server/change-streamer.js +57 -130
  406. package/out/zero-cache/src/server/change-streamer.js.map +1 -1
  407. package/out/zero-cache/src/server/inspector-delegate.js +89 -100
  408. package/out/zero-cache/src/server/inspector-delegate.js.map +1 -1
  409. package/out/zero-cache/src/server/logging.js +18 -26
  410. package/out/zero-cache/src/server/logging.js.map +1 -1
  411. package/out/zero-cache/src/server/main.js +85 -142
  412. package/out/zero-cache/src/server/main.js.map +1 -1
  413. package/out/zero-cache/src/server/mutator.js +16 -13
  414. package/out/zero-cache/src/server/mutator.js.map +1 -1
  415. package/out/zero-cache/src/server/otel-diag-logger.js +42 -49
  416. package/out/zero-cache/src/server/otel-diag-logger.js.map +1 -1
  417. package/out/zero-cache/src/server/otel-log-sink.js +34 -44
  418. package/out/zero-cache/src/server/otel-log-sink.js.map +1 -1
  419. package/out/zero-cache/src/server/otel-start.js +43 -51
  420. package/out/zero-cache/src/server/otel-start.js.map +1 -1
  421. package/out/zero-cache/src/server/priority-op.js +27 -25
  422. package/out/zero-cache/src/server/priority-op.js.map +1 -1
  423. package/out/zero-cache/src/server/reaper.js +32 -43
  424. package/out/zero-cache/src/server/reaper.js.map +1 -1
  425. package/out/zero-cache/src/server/replicator.d.ts.map +1 -1
  426. package/out/zero-cache/src/server/replicator.js +41 -57
  427. package/out/zero-cache/src/server/replicator.js.map +1 -1
  428. package/out/zero-cache/src/server/runner/main.js +7 -8
  429. package/out/zero-cache/src/server/runner/main.js.map +1 -1
  430. package/out/zero-cache/src/server/runner/run-worker.js +56 -52
  431. package/out/zero-cache/src/server/runner/run-worker.js.map +1 -1
  432. package/out/zero-cache/src/server/runner/runtime.js +26 -32
  433. package/out/zero-cache/src/server/runner/runtime.js.map +1 -1
  434. package/out/zero-cache/src/server/runner/zero-dispatcher.js +22 -27
  435. package/out/zero-cache/src/server/runner/zero-dispatcher.js.map +1 -1
  436. package/out/zero-cache/src/server/syncer.js +79 -148
  437. package/out/zero-cache/src/server/syncer.js.map +1 -1
  438. package/out/zero-cache/src/server/worker-dispatcher.js +84 -113
  439. package/out/zero-cache/src/server/worker-dispatcher.js.map +1 -1
  440. package/out/zero-cache/src/server/worker-urls.d.ts +2 -1
  441. package/out/zero-cache/src/server/worker-urls.d.ts.map +1 -1
  442. package/out/zero-cache/src/server/worker-urls.js +14 -18
  443. package/out/zero-cache/src/server/worker-urls.js.map +1 -1
  444. package/out/zero-cache/src/server/write-worker.js +2 -0
  445. package/out/zero-cache/src/services/analyze.js +61 -130
  446. package/out/zero-cache/src/services/analyze.js.map +1 -1
  447. package/out/zero-cache/src/services/change-source/common/backfill-manager.js +420 -419
  448. package/out/zero-cache/src/services/change-source/common/backfill-manager.js.map +1 -1
  449. package/out/zero-cache/src/services/change-source/common/change-stream-multiplexer.js +111 -114
  450. package/out/zero-cache/src/services/change-source/common/change-stream-multiplexer.js.map +1 -1
  451. package/out/zero-cache/src/services/change-source/common/replica-schema.js +80 -148
  452. package/out/zero-cache/src/services/change-source/common/replica-schema.js.map +1 -1
  453. package/out/zero-cache/src/services/change-source/custom/change-source.js +154 -216
  454. package/out/zero-cache/src/services/change-source/custom/change-source.js.map +1 -1
  455. package/out/zero-cache/src/services/change-source/pg/backfill-metadata.js +11 -14
  456. package/out/zero-cache/src/services/change-source/pg/backfill-metadata.js.map +1 -1
  457. package/out/zero-cache/src/services/change-source/pg/backfill-stream.js +168 -212
  458. package/out/zero-cache/src/services/change-source/pg/backfill-stream.js.map +1 -1
  459. package/out/zero-cache/src/services/change-source/pg/change-source.js +672 -892
  460. package/out/zero-cache/src/services/change-source/pg/change-source.js.map +1 -1
  461. package/out/zero-cache/src/services/change-source/pg/decommission.js +19 -23
  462. package/out/zero-cache/src/services/change-source/pg/decommission.js.map +1 -1
  463. package/out/zero-cache/src/services/change-source/pg/initial-sync.js +258 -411
  464. package/out/zero-cache/src/services/change-source/pg/initial-sync.js.map +1 -1
  465. package/out/zero-cache/src/services/change-source/pg/logical-replication/binary-reader.js +59 -65
  466. package/out/zero-cache/src/services/change-source/pg/logical-replication/binary-reader.js.map +1 -1
  467. package/out/zero-cache/src/services/change-source/pg/logical-replication/pgoutput-parser.js +218 -247
  468. package/out/zero-cache/src/services/change-source/pg/logical-replication/pgoutput-parser.js.map +1 -1
  469. package/out/zero-cache/src/services/change-source/pg/logical-replication/stream.js +100 -142
  470. package/out/zero-cache/src/services/change-source/pg/logical-replication/stream.js.map +1 -1
  471. package/out/zero-cache/src/services/change-source/pg/lsn.js +17 -19
  472. package/out/zero-cache/src/services/change-source/pg/lsn.js.map +1 -1
  473. package/out/zero-cache/src/services/change-source/pg/schema/ddl.js +88 -98
  474. package/out/zero-cache/src/services/change-source/pg/schema/ddl.js.map +1 -1
  475. package/out/zero-cache/src/services/change-source/pg/schema/init.js +96 -177
  476. package/out/zero-cache/src/services/change-source/pg/schema/init.js.map +1 -1
  477. package/out/zero-cache/src/services/change-source/pg/schema/published.js +69 -107
  478. package/out/zero-cache/src/services/change-source/pg/schema/published.js.map +1 -1
  479. package/out/zero-cache/src/services/change-source/pg/schema/shard.js +151 -212
  480. package/out/zero-cache/src/services/change-source/pg/schema/shard.js.map +1 -1
  481. package/out/zero-cache/src/services/change-source/pg/schema/validation.js +22 -53
  482. package/out/zero-cache/src/services/change-source/pg/schema/validation.js.map +1 -1
  483. package/out/zero-cache/src/services/change-source/protocol/current/control.js +24 -12
  484. package/out/zero-cache/src/services/change-source/protocol/current/control.js.map +1 -1
  485. package/out/zero-cache/src/services/change-source/protocol/current/data.js +180 -290
  486. package/out/zero-cache/src/services/change-source/protocol/current/data.js.map +1 -1
  487. package/out/zero-cache/src/services/change-source/protocol/current/downstream.js +21 -33
  488. package/out/zero-cache/src/services/change-source/protocol/current/downstream.js.map +1 -1
  489. package/out/zero-cache/src/services/change-source/protocol/current/json.js +7 -18
  490. package/out/zero-cache/src/services/change-source/protocol/current/json.js.map +1 -1
  491. package/out/zero-cache/src/services/change-source/protocol/current/path.js +24 -5
  492. package/out/zero-cache/src/services/change-source/protocol/current/path.js.map +1 -1
  493. package/out/zero-cache/src/services/change-source/protocol/current/status.js +25 -19
  494. package/out/zero-cache/src/services/change-source/protocol/current/status.js.map +1 -1
  495. package/out/zero-cache/src/services/change-source/protocol/current/upstream.js +24 -16
  496. package/out/zero-cache/src/services/change-source/protocol/current/upstream.js.map +1 -1
  497. package/out/zero-cache/src/services/change-source/protocol/current.js +51 -46
  498. package/out/zero-cache/src/services/change-source/protocol/current.js.map +1 -1
  499. package/out/zero-cache/src/services/change-source/protocol/mod.js +2 -0
  500. package/out/zero-cache/src/services/change-streamer/backup-monitor.js +165 -171
  501. package/out/zero-cache/src/services/change-streamer/backup-monitor.js.map +1 -1
  502. package/out/zero-cache/src/services/change-streamer/broadcast.js +163 -169
  503. package/out/zero-cache/src/services/change-streamer/broadcast.js.map +1 -1
  504. package/out/zero-cache/src/services/change-streamer/change-streamer-http.js +154 -221
  505. package/out/zero-cache/src/services/change-streamer/change-streamer-http.js.map +1 -1
  506. package/out/zero-cache/src/services/change-streamer/change-streamer-service.d.ts.map +1 -1
  507. package/out/zero-cache/src/services/change-streamer/change-streamer-service.js +340 -299
  508. package/out/zero-cache/src/services/change-streamer/change-streamer-service.js.map +1 -1
  509. package/out/zero-cache/src/services/change-streamer/change-streamer.js +17 -24
  510. package/out/zero-cache/src/services/change-streamer/change-streamer.js.map +1 -1
  511. package/out/zero-cache/src/services/change-streamer/forwarder.js +84 -103
  512. package/out/zero-cache/src/services/change-streamer/forwarder.js.map +1 -1
  513. package/out/zero-cache/src/services/change-streamer/replica-monitor.js +49 -43
  514. package/out/zero-cache/src/services/change-streamer/replica-monitor.js.map +1 -1
  515. package/out/zero-cache/src/services/change-streamer/schema/init.js +61 -89
  516. package/out/zero-cache/src/services/change-streamer/schema/init.js.map +1 -1
  517. package/out/zero-cache/src/services/change-streamer/schema/tables.d.ts +20 -1
  518. package/out/zero-cache/src/services/change-streamer/schema/tables.d.ts.map +1 -1
  519. package/out/zero-cache/src/services/change-streamer/schema/tables.js +131 -109
  520. package/out/zero-cache/src/services/change-streamer/schema/tables.js.map +1 -1
  521. package/out/zero-cache/src/services/change-streamer/snapshot.js +26 -28
  522. package/out/zero-cache/src/services/change-streamer/snapshot.js.map +1 -1
  523. package/out/zero-cache/src/services/change-streamer/storer.js +434 -513
  524. package/out/zero-cache/src/services/change-streamer/storer.js.map +1 -1
  525. package/out/zero-cache/src/services/change-streamer/subscriber.js +142 -155
  526. package/out/zero-cache/src/services/change-streamer/subscriber.js.map +1 -1
  527. package/out/zero-cache/src/services/heapz.js +18 -20
  528. package/out/zero-cache/src/services/heapz.js.map +1 -1
  529. package/out/zero-cache/src/services/http-service.js +59 -57
  530. package/out/zero-cache/src/services/http-service.js.map +1 -1
  531. package/out/zero-cache/src/services/life-cycle.js +182 -214
  532. package/out/zero-cache/src/services/life-cycle.js.map +1 -1
  533. package/out/zero-cache/src/services/limiter/sliding-window-limiter.js +102 -81
  534. package/out/zero-cache/src/services/limiter/sliding-window-limiter.js.map +1 -1
  535. package/out/zero-cache/src/services/litestream/commands.js +144 -205
  536. package/out/zero-cache/src/services/litestream/commands.js.map +1 -1
  537. package/out/zero-cache/src/services/mutagen/error.js +10 -14
  538. package/out/zero-cache/src/services/mutagen/error.js.map +1 -1
  539. package/out/zero-cache/src/services/mutagen/mutagen.js +166 -264
  540. package/out/zero-cache/src/services/mutagen/mutagen.js.map +1 -1
  541. package/out/zero-cache/src/services/mutagen/pusher.js +372 -487
  542. package/out/zero-cache/src/services/mutagen/pusher.js.map +1 -1
  543. package/out/zero-cache/src/services/replicator/change-processor.js +483 -592
  544. package/out/zero-cache/src/services/replicator/change-processor.js.map +1 -1
  545. package/out/zero-cache/src/services/replicator/incremental-sync.d.ts +4 -2
  546. package/out/zero-cache/src/services/replicator/incremental-sync.d.ts.map +1 -1
  547. package/out/zero-cache/src/services/replicator/incremental-sync.js +118 -143
  548. package/out/zero-cache/src/services/replicator/incremental-sync.js.map +1 -1
  549. package/out/zero-cache/src/services/replicator/notifier.js +52 -28
  550. package/out/zero-cache/src/services/replicator/notifier.js.map +1 -1
  551. package/out/zero-cache/src/services/replicator/replication-status.js +105 -128
  552. package/out/zero-cache/src/services/replicator/replication-status.js.map +1 -1
  553. package/out/zero-cache/src/services/replicator/replicator.d.ts +2 -1
  554. package/out/zero-cache/src/services/replicator/replicator.d.ts.map +1 -1
  555. package/out/zero-cache/src/services/replicator/replicator.js +32 -34
  556. package/out/zero-cache/src/services/replicator/replicator.js.map +1 -1
  557. package/out/zero-cache/src/services/replicator/schema/change-log.js +101 -133
  558. package/out/zero-cache/src/services/replicator/schema/change-log.js.map +1 -1
  559. package/out/zero-cache/src/services/replicator/schema/column-metadata.js +145 -174
  560. package/out/zero-cache/src/services/replicator/schema/column-metadata.js.map +1 -1
  561. package/out/zero-cache/src/services/replicator/schema/constants.js +11 -5
  562. package/out/zero-cache/src/services/replicator/schema/constants.js.map +1 -1
  563. package/out/zero-cache/src/services/replicator/schema/replication-state.js +56 -107
  564. package/out/zero-cache/src/services/replicator/schema/replication-state.js.map +1 -1
  565. package/out/zero-cache/src/services/replicator/schema/table-metadata.js +81 -66
  566. package/out/zero-cache/src/services/replicator/schema/table-metadata.js.map +1 -1
  567. package/out/zero-cache/src/services/replicator/write-worker-client.d.ts +69 -0
  568. package/out/zero-cache/src/services/replicator/write-worker-client.d.ts.map +1 -0
  569. package/out/zero-cache/src/services/replicator/write-worker-client.js +96 -0
  570. package/out/zero-cache/src/services/replicator/write-worker-client.js.map +1 -0
  571. package/out/zero-cache/src/services/replicator/write-worker.js +68 -0
  572. package/out/zero-cache/src/services/replicator/write-worker.js.map +1 -0
  573. package/out/zero-cache/src/services/run-ast.js +79 -120
  574. package/out/zero-cache/src/services/run-ast.js.map +1 -1
  575. package/out/zero-cache/src/services/runner.js +39 -41
  576. package/out/zero-cache/src/services/runner.js.map +1 -1
  577. package/out/zero-cache/src/services/running-state.js +129 -134
  578. package/out/zero-cache/src/services/running-state.js.map +1 -1
  579. package/out/zero-cache/src/services/statz.js +139 -200
  580. package/out/zero-cache/src/services/statz.js.map +1 -1
  581. package/out/zero-cache/src/services/view-syncer/active-users-gauge.js +46 -49
  582. package/out/zero-cache/src/services/view-syncer/active-users-gauge.js.map +1 -1
  583. package/out/zero-cache/src/services/view-syncer/client-handler.js +257 -299
  584. package/out/zero-cache/src/services/view-syncer/client-handler.js.map +1 -1
  585. package/out/zero-cache/src/services/view-syncer/client-schema.js +52 -82
  586. package/out/zero-cache/src/services/view-syncer/client-schema.js.map +1 -1
  587. package/out/zero-cache/src/services/view-syncer/cvr-purger.js +85 -107
  588. package/out/zero-cache/src/services/view-syncer/cvr-purger.js.map +1 -1
  589. package/out/zero-cache/src/services/view-syncer/cvr-store.js +604 -757
  590. package/out/zero-cache/src/services/view-syncer/cvr-store.js.map +1 -1
  591. package/out/zero-cache/src/services/view-syncer/cvr.js +631 -739
  592. package/out/zero-cache/src/services/view-syncer/cvr.js.map +1 -1
  593. package/out/zero-cache/src/services/view-syncer/drain-coordinator.js +60 -40
  594. package/out/zero-cache/src/services/view-syncer/drain-coordinator.js.map +1 -1
  595. package/out/zero-cache/src/services/view-syncer/inspect-handler.js +95 -178
  596. package/out/zero-cache/src/services/view-syncer/inspect-handler.js.map +1 -1
  597. package/out/zero-cache/src/services/view-syncer/pipeline-driver.d.ts.map +1 -1
  598. package/out/zero-cache/src/services/view-syncer/pipeline-driver.js +571 -722
  599. package/out/zero-cache/src/services/view-syncer/pipeline-driver.js.map +1 -1
  600. package/out/zero-cache/src/services/view-syncer/row-record-cache.d.ts.map +1 -1
  601. package/out/zero-cache/src/services/view-syncer/row-record-cache.js +246 -257
  602. package/out/zero-cache/src/services/view-syncer/row-record-cache.js.map +1 -1
  603. package/out/zero-cache/src/services/view-syncer/schema/cvr.js +59 -45
  604. package/out/zero-cache/src/services/view-syncer/schema/cvr.js.map +1 -1
  605. package/out/zero-cache/src/services/view-syncer/schema/init.js +121 -189
  606. package/out/zero-cache/src/services/view-syncer/schema/init.js.map +1 -1
  607. package/out/zero-cache/src/services/view-syncer/schema/types.js +138 -263
  608. package/out/zero-cache/src/services/view-syncer/schema/types.js.map +1 -1
  609. package/out/zero-cache/src/services/view-syncer/snapshotter.js +322 -335
  610. package/out/zero-cache/src/services/view-syncer/snapshotter.js.map +1 -1
  611. package/out/zero-cache/src/services/view-syncer/tracer.js +7 -6
  612. package/out/zero-cache/src/services/view-syncer/tracer.js.map +1 -1
  613. package/out/zero-cache/src/services/view-syncer/ttl-clock.js +9 -11
  614. package/out/zero-cache/src/services/view-syncer/ttl-clock.js.map +1 -1
  615. package/out/zero-cache/src/services/view-syncer/view-syncer.js +1067 -1603
  616. package/out/zero-cache/src/services/view-syncer/view-syncer.js.map +1 -1
  617. package/out/zero-cache/src/types/error-with-level.js +19 -25
  618. package/out/zero-cache/src/types/error-with-level.js.map +1 -1
  619. package/out/zero-cache/src/types/http.js +17 -26
  620. package/out/zero-cache/src/types/http.js.map +1 -1
  621. package/out/zero-cache/src/types/lexi-version.js +28 -42
  622. package/out/zero-cache/src/types/lexi-version.js.map +1 -1
  623. package/out/zero-cache/src/types/lite.js +101 -121
  624. package/out/zero-cache/src/types/lite.js.map +1 -1
  625. package/out/zero-cache/src/types/names.js +6 -5
  626. package/out/zero-cache/src/types/names.js.map +1 -1
  627. package/out/zero-cache/src/types/pg-data-type.d.ts +1 -0
  628. package/out/zero-cache/src/types/pg-data-type.d.ts.map +1 -1
  629. package/out/zero-cache/src/types/pg-data-type.js +58 -73
  630. package/out/zero-cache/src/types/pg-data-type.js.map +1 -1
  631. package/out/zero-cache/src/types/pg-types.js +12 -19
  632. package/out/zero-cache/src/types/pg-types.js.map +1 -1
  633. package/out/zero-cache/src/types/pg.js +144 -218
  634. package/out/zero-cache/src/types/pg.js.map +1 -1
  635. package/out/zero-cache/src/types/processes.js +95 -90
  636. package/out/zero-cache/src/types/processes.js.map +1 -1
  637. package/out/zero-cache/src/types/profiler.js +32 -27
  638. package/out/zero-cache/src/types/profiler.js.map +1 -1
  639. package/out/zero-cache/src/types/row-key.js +42 -30
  640. package/out/zero-cache/src/types/row-key.js.map +1 -1
  641. package/out/zero-cache/src/types/shards.js +36 -45
  642. package/out/zero-cache/src/types/shards.js.map +1 -1
  643. package/out/zero-cache/src/types/sql.js +20 -9
  644. package/out/zero-cache/src/types/sql.js.map +1 -1
  645. package/out/zero-cache/src/types/state-version.js +17 -23
  646. package/out/zero-cache/src/types/state-version.js.map +1 -1
  647. package/out/zero-cache/src/types/streams.js +234 -270
  648. package/out/zero-cache/src/types/streams.js.map +1 -1
  649. package/out/zero-cache/src/types/strings.js +10 -13
  650. package/out/zero-cache/src/types/strings.js.map +1 -1
  651. package/out/zero-cache/src/types/subscription.js +266 -226
  652. package/out/zero-cache/src/types/subscription.js.map +1 -1
  653. package/out/zero-cache/src/types/url-params.js +30 -39
  654. package/out/zero-cache/src/types/url-params.js.map +1 -1
  655. package/out/zero-cache/src/types/websocket-handoff.js +62 -75
  656. package/out/zero-cache/src/types/websocket-handoff.js.map +1 -1
  657. package/out/zero-cache/src/types/ws.js +43 -53
  658. package/out/zero-cache/src/types/ws.js.map +1 -1
  659. package/out/zero-cache/src/workers/connect-params.js +42 -43
  660. package/out/zero-cache/src/workers/connect-params.js.map +1 -1
  661. package/out/zero-cache/src/workers/connection.js +213 -282
  662. package/out/zero-cache/src/workers/connection.js.map +1 -1
  663. package/out/zero-cache/src/workers/mutator.js +22 -21
  664. package/out/zero-cache/src/workers/mutator.js.map +1 -1
  665. package/out/zero-cache/src/workers/replicator.d.ts +7 -0
  666. package/out/zero-cache/src/workers/replicator.d.ts.map +1 -1
  667. package/out/zero-cache/src/workers/replicator.js +92 -97
  668. package/out/zero-cache/src/workers/replicator.js.map +1 -1
  669. package/out/zero-cache/src/workers/syncer-ws-message-handler.js +121 -203
  670. package/out/zero-cache/src/workers/syncer-ws-message-handler.js.map +1 -1
  671. package/out/zero-cache/src/workers/syncer.js +147 -201
  672. package/out/zero-cache/src/workers/syncer.js.map +1 -1
  673. package/out/zero-client/src/client/active-clients-manager.js +178 -187
  674. package/out/zero-client/src/client/active-clients-manager.js.map +1 -1
  675. package/out/zero-client/src/client/bindings.js +11 -0
  676. package/out/zero-client/src/client/client-error-kind-enum.js +18 -29
  677. package/out/zero-client/src/client/client-error-kind-enum.js.map +1 -1
  678. package/out/zero-client/src/client/connection-manager.js +291 -346
  679. package/out/zero-client/src/client/connection-manager.js.map +1 -1
  680. package/out/zero-client/src/client/connection-status-enum.js +20 -15
  681. package/out/zero-client/src/client/connection-status-enum.js.map +1 -1
  682. package/out/zero-client/src/client/connection.js +92 -110
  683. package/out/zero-client/src/client/connection.js.map +1 -1
  684. package/out/zero-client/src/client/context.js +84 -100
  685. package/out/zero-client/src/client/context.js.map +1 -1
  686. package/out/zero-client/src/client/crud-impl.js +56 -88
  687. package/out/zero-client/src/client/crud-impl.js.map +1 -1
  688. package/out/zero-client/src/client/crud.js +127 -129
  689. package/out/zero-client/src/client/crud.js.map +1 -1
  690. package/out/zero-client/src/client/custom.d.ts.map +1 -1
  691. package/out/zero-client/src/client/custom.js +50 -74
  692. package/out/zero-client/src/client/custom.js.map +1 -1
  693. package/out/zero-client/src/client/delete-clients-manager.js +72 -93
  694. package/out/zero-client/src/client/delete-clients-manager.js.map +1 -1
  695. package/out/zero-client/src/client/enable-analytics.js +8 -16
  696. package/out/zero-client/src/client/enable-analytics.js.map +1 -1
  697. package/out/zero-client/src/client/error.js +118 -133
  698. package/out/zero-client/src/client/error.js.map +1 -1
  699. package/out/zero-client/src/client/http-string.js +7 -7
  700. package/out/zero-client/src/client/http-string.js.map +1 -1
  701. package/out/zero-client/src/client/inspector/client-group.js +21 -26
  702. package/out/zero-client/src/client/inspector/client-group.js.map +1 -1
  703. package/out/zero-client/src/client/inspector/client.js +23 -26
  704. package/out/zero-client/src/client/inspector/client.js.map +1 -1
  705. package/out/zero-client/src/client/inspector/html-dialog-prompt.js +72 -73
  706. package/out/zero-client/src/client/inspector/html-dialog-prompt.js.map +1 -1
  707. package/out/zero-client/src/client/inspector/inspector.js +46 -51
  708. package/out/zero-client/src/client/inspector/inspector.js.map +1 -1
  709. package/out/zero-client/src/client/inspector/lazy-inspector.js +132 -192
  710. package/out/zero-client/src/client/inspector/lazy-inspector.js.map +1 -1
  711. package/out/zero-client/src/client/inspector/query.js +72 -77
  712. package/out/zero-client/src/client/inspector/query.js.map +1 -1
  713. package/out/zero-client/src/client/ivm-branch.js +118 -145
  714. package/out/zero-client/src/client/ivm-branch.js.map +1 -1
  715. package/out/zero-client/src/client/keys.js +15 -31
  716. package/out/zero-client/src/client/keys.js.map +1 -1
  717. package/out/zero-client/src/client/log-options.js +43 -57
  718. package/out/zero-client/src/client/log-options.js.map +1 -1
  719. package/out/zero-client/src/client/make-mutate-property.js +46 -29
  720. package/out/zero-client/src/client/make-mutate-property.js.map +1 -1
  721. package/out/zero-client/src/client/make-replicache-mutators.js +80 -96
  722. package/out/zero-client/src/client/make-replicache-mutators.js.map +1 -1
  723. package/out/zero-client/src/client/metric-name-enum.js +11 -15
  724. package/out/zero-client/src/client/metric-name-enum.js.map +1 -1
  725. package/out/zero-client/src/client/metrics.js +210 -237
  726. package/out/zero-client/src/client/metrics.js.map +1 -1
  727. package/out/zero-client/src/client/mutation-tracker.js +264 -354
  728. package/out/zero-client/src/client/mutation-tracker.js.map +1 -1
  729. package/out/zero-client/src/client/mutator-proxy.js +122 -151
  730. package/out/zero-client/src/client/mutator-proxy.js.map +1 -1
  731. package/out/zero-client/src/client/options.js +7 -10
  732. package/out/zero-client/src/client/options.js.map +1 -1
  733. package/out/zero-client/src/client/query-manager.js +305 -373
  734. package/out/zero-client/src/client/query-manager.js.map +1 -1
  735. package/out/zero-client/src/client/reload-error-handler.js +80 -101
  736. package/out/zero-client/src/client/reload-error-handler.js.map +1 -1
  737. package/out/zero-client/src/client/server-option.js +30 -59
  738. package/out/zero-client/src/client/server-option.js.map +1 -1
  739. package/out/zero-client/src/client/update-needed-reason-type-enum.js +27 -9
  740. package/out/zero-client/src/client/update-needed-reason-type-enum.js.map +1 -1
  741. package/out/zero-client/src/client/version.js +9 -5
  742. package/out/zero-client/src/client/version.js.map +1 -1
  743. package/out/zero-client/src/client/zero-poke-handler.d.ts +1 -1
  744. package/out/zero-client/src/client/zero-poke-handler.d.ts.map +1 -1
  745. package/out/zero-client/src/client/zero-poke-handler.js +205 -293
  746. package/out/zero-client/src/client/zero-poke-handler.js.map +1 -1
  747. package/out/zero-client/src/client/zero-rep.js +61 -68
  748. package/out/zero-client/src/client/zero-rep.js.map +1 -1
  749. package/out/zero-client/src/client/zero.d.ts.map +1 -1
  750. package/out/zero-client/src/client/zero.js +1367 -1834
  751. package/out/zero-client/src/client/zero.js.map +1 -1
  752. package/out/zero-client/src/mod.js +21 -0
  753. package/out/zero-client/src/util/nanoid.js +13 -18
  754. package/out/zero-client/src/util/nanoid.js.map +1 -1
  755. package/out/zero-client/src/util/socket.js +6 -5
  756. package/out/zero-client/src/util/socket.js.map +1 -1
  757. package/out/zero-pg/src/mod.js +10 -0
  758. package/out/zero-protocol/src/analyze-query-result.js +108 -148
  759. package/out/zero-protocol/src/analyze-query-result.js.map +1 -1
  760. package/out/zero-protocol/src/application-error.js +36 -34
  761. package/out/zero-protocol/src/application-error.js.map +1 -1
  762. package/out/zero-protocol/src/ast.js +236 -309
  763. package/out/zero-protocol/src/ast.js.map +1 -1
  764. package/out/zero-protocol/src/change-desired-queries.js +8 -13
  765. package/out/zero-protocol/src/change-desired-queries.js.map +1 -1
  766. package/out/zero-protocol/src/client-schema.js +21 -42
  767. package/out/zero-protocol/src/client-schema.js.map +1 -1
  768. package/out/zero-protocol/src/close-connection.js +20 -12
  769. package/out/zero-protocol/src/close-connection.js.map +1 -1
  770. package/out/zero-protocol/src/connect.js +37 -52
  771. package/out/zero-protocol/src/connect.js.map +1 -1
  772. package/out/zero-protocol/src/custom-queries.js +34 -65
  773. package/out/zero-protocol/src/custom-queries.js.map +1 -1
  774. package/out/zero-protocol/src/data.js +6 -9
  775. package/out/zero-protocol/src/data.js.map +1 -1
  776. package/out/zero-protocol/src/delete-clients.js +11 -17
  777. package/out/zero-protocol/src/delete-clients.js.map +1 -1
  778. package/out/zero-protocol/src/down.js +11 -23
  779. package/out/zero-protocol/src/down.js.map +1 -1
  780. package/out/zero-protocol/src/error-kind-enum.js +24 -41
  781. package/out/zero-protocol/src/error-kind-enum.js.map +1 -1
  782. package/out/zero-protocol/src/error-origin-enum.js +8 -9
  783. package/out/zero-protocol/src/error-origin-enum.js.map +1 -1
  784. package/out/zero-protocol/src/error-reason-enum.js +12 -17
  785. package/out/zero-protocol/src/error-reason-enum.js.map +1 -1
  786. package/out/zero-protocol/src/error.js +76 -152
  787. package/out/zero-protocol/src/error.js.map +1 -1
  788. package/out/zero-protocol/src/inspect-down.js +51 -74
  789. package/out/zero-protocol/src/inspect-down.js.map +1 -1
  790. package/out/zero-protocol/src/inspect-up.js +28 -46
  791. package/out/zero-protocol/src/inspect-up.js.map +1 -1
  792. package/out/zero-protocol/src/mutation-id.js +9 -9
  793. package/out/zero-protocol/src/mutation-id.js.map +1 -1
  794. package/out/zero-protocol/src/mutation-type-enum.js +7 -7
  795. package/out/zero-protocol/src/mutation-type-enum.js.map +1 -1
  796. package/out/zero-protocol/src/mutations-patch.js +21 -16
  797. package/out/zero-protocol/src/mutations-patch.js.map +1 -1
  798. package/out/zero-protocol/src/ping.js +8 -9
  799. package/out/zero-protocol/src/ping.js.map +1 -1
  800. package/out/zero-protocol/src/poke.js +53 -59
  801. package/out/zero-protocol/src/poke.js.map +1 -1
  802. package/out/zero-protocol/src/pong.js +8 -9
  803. package/out/zero-protocol/src/pong.js.map +1 -1
  804. package/out/zero-protocol/src/primary-key.js +9 -19
  805. package/out/zero-protocol/src/primary-key.js.map +1 -1
  806. package/out/zero-protocol/src/protocol-version.js +5 -11
  807. package/out/zero-protocol/src/protocol-version.js.map +1 -1
  808. package/out/zero-protocol/src/pull.js +16 -28
  809. package/out/zero-protocol/src/pull.js.map +1 -1
  810. package/out/zero-protocol/src/push.js +162 -209
  811. package/out/zero-protocol/src/push.js.map +1 -1
  812. package/out/zero-protocol/src/queries-patch.js +22 -30
  813. package/out/zero-protocol/src/queries-patch.js.map +1 -1
  814. package/out/zero-protocol/src/query-hash.js +14 -17
  815. package/out/zero-protocol/src/query-hash.js.map +1 -1
  816. package/out/zero-protocol/src/row-patch.js +23 -30
  817. package/out/zero-protocol/src/row-patch.js.map +1 -1
  818. package/out/zero-protocol/src/up.js +11 -22
  819. package/out/zero-protocol/src/up.js.map +1 -1
  820. package/out/zero-protocol/src/update-auth.js +8 -13
  821. package/out/zero-protocol/src/update-auth.js.map +1 -1
  822. package/out/zero-protocol/src/version.js +8 -9
  823. package/out/zero-protocol/src/version.js.map +1 -1
  824. package/out/zero-react/src/bindings.js +12 -0
  825. package/out/zero-react/src/mod.js +5 -0
  826. package/out/zero-react/src/use-connection-state.js +14 -11
  827. package/out/zero-react/src/use-connection-state.js.map +1 -1
  828. package/out/zero-react/src/use-query.js +283 -281
  829. package/out/zero-react/src/use-query.js.map +1 -1
  830. package/out/zero-react/src/use-zero-online.js +17 -11
  831. package/out/zero-react/src/use-zero-online.js.map +1 -1
  832. package/out/zero-react/src/zero-provider.js +53 -69
  833. package/out/zero-react/src/zero-provider.js.map +1 -1
  834. package/out/zero-react/src/zero.js +22 -0
  835. package/out/zero-schema/src/builder/relationship-builder.js +25 -21
  836. package/out/zero-schema/src/builder/relationship-builder.js.map +1 -1
  837. package/out/zero-schema/src/builder/schema-builder.js +51 -79
  838. package/out/zero-schema/src/builder/schema-builder.js.map +1 -1
  839. package/out/zero-schema/src/builder/table-builder.js +99 -116
  840. package/out/zero-schema/src/builder/table-builder.js.map +1 -1
  841. package/out/zero-schema/src/compiled-permissions.js +21 -25
  842. package/out/zero-schema/src/compiled-permissions.js.map +1 -1
  843. package/out/zero-schema/src/name-mapper.js +31 -47
  844. package/out/zero-schema/src/name-mapper.js.map +1 -1
  845. package/out/zero-schema/src/permissions.js +94 -181
  846. package/out/zero-schema/src/permissions.js.map +1 -1
  847. package/out/zero-schema/src/schema-config.js +26 -32
  848. package/out/zero-schema/src/schema-config.js.map +1 -1
  849. package/out/zero-server/src/adapters/drizzle.d.ts.map +1 -1
  850. package/out/zero-server/src/adapters/drizzle.js +79 -76
  851. package/out/zero-server/src/adapters/drizzle.js.map +1 -1
  852. package/out/zero-server/src/adapters/pg.d.ts.map +1 -1
  853. package/out/zero-server/src/adapters/pg.js +79 -55
  854. package/out/zero-server/src/adapters/pg.js.map +1 -1
  855. package/out/zero-server/src/adapters/postgresjs.d.ts.map +1 -1
  856. package/out/zero-server/src/adapters/postgresjs.js +66 -40
  857. package/out/zero-server/src/adapters/postgresjs.js.map +1 -1
  858. package/out/zero-server/src/adapters/prisma.d.ts.map +1 -1
  859. package/out/zero-server/src/adapters/prisma.js +75 -55
  860. package/out/zero-server/src/adapters/prisma.js.map +1 -1
  861. package/out/zero-server/src/custom.d.ts.map +1 -1
  862. package/out/zero-server/src/custom.js +188 -265
  863. package/out/zero-server/src/custom.js.map +1 -1
  864. package/out/zero-server/src/logging.js +6 -5
  865. package/out/zero-server/src/logging.js.map +1 -1
  866. package/out/zero-server/src/mod.js +8 -0
  867. package/out/zero-server/src/pg-query-executor.js +14 -17
  868. package/out/zero-server/src/pg-query-executor.js.map +1 -1
  869. package/out/zero-server/src/process-mutations.js +293 -365
  870. package/out/zero-server/src/process-mutations.js.map +1 -1
  871. package/out/zero-server/src/push-processor.js +33 -49
  872. package/out/zero-server/src/push-processor.js.map +1 -1
  873. package/out/zero-server/src/queries/process-queries.js +106 -96
  874. package/out/zero-server/src/queries/process-queries.js.map +1 -1
  875. package/out/zero-server/src/schema.js +98 -144
  876. package/out/zero-server/src/schema.js.map +1 -1
  877. package/out/zero-server/src/zql-database.d.ts.map +1 -1
  878. package/out/zero-server/src/zql-database.js +54 -69
  879. package/out/zero-server/src/zql-database.js.map +1 -1
  880. package/out/zero-solid/src/bindings.js +12 -0
  881. package/out/zero-solid/src/mod.js +5 -0
  882. package/out/zero-solid/src/solid-view.js +135 -227
  883. package/out/zero-solid/src/solid-view.js.map +1 -1
  884. package/out/zero-solid/src/use-connection-state.js +18 -14
  885. package/out/zero-solid/src/use-connection-state.js.map +1 -1
  886. package/out/zero-solid/src/use-query.js +55 -100
  887. package/out/zero-solid/src/use-query.js.map +1 -1
  888. package/out/zero-solid/src/use-zero-online.js +18 -12
  889. package/out/zero-solid/src/use-zero-online.js.map +1 -1
  890. package/out/zero-solid/src/use-zero.js +65 -77
  891. package/out/zero-solid/src/use-zero.js.map +1 -1
  892. package/out/zero-solid/src/zero.js +22 -0
  893. package/out/zero-types/src/format.js +8 -7
  894. package/out/zero-types/src/format.js.map +1 -1
  895. package/out/zero-types/src/name-mapper.js +34 -47
  896. package/out/zero-types/src/name-mapper.js.map +1 -1
  897. package/out/zql/src/builder/builder.d.ts.map +1 -1
  898. package/out/zql/src/builder/builder.js +315 -476
  899. package/out/zql/src/builder/builder.js.map +1 -1
  900. package/out/zql/src/builder/debug-delegate.js +69 -74
  901. package/out/zql/src/builder/debug-delegate.js.map +1 -1
  902. package/out/zql/src/builder/filter.js +116 -140
  903. package/out/zql/src/builder/filter.js.map +1 -1
  904. package/out/zql/src/builder/like.js +41 -46
  905. package/out/zql/src/builder/like.js.map +1 -1
  906. package/out/zql/src/error.js +10 -9
  907. package/out/zql/src/error.js.map +1 -1
  908. package/out/zql/src/ivm/array-view.js +89 -91
  909. package/out/zql/src/ivm/array-view.js.map +1 -1
  910. package/out/zql/src/ivm/constraint.js +65 -74
  911. package/out/zql/src/ivm/constraint.js.map +1 -1
  912. package/out/zql/src/ivm/data.js +61 -48
  913. package/out/zql/src/ivm/data.js.map +1 -1
  914. package/out/zql/src/ivm/exists.js +164 -213
  915. package/out/zql/src/ivm/exists.js.map +1 -1
  916. package/out/zql/src/ivm/fan-in.js +62 -59
  917. package/out/zql/src/ivm/fan-in.js.map +1 -1
  918. package/out/zql/src/ivm/fan-out.js +52 -61
  919. package/out/zql/src/ivm/fan-out.js.map +1 -1
  920. package/out/zql/src/ivm/filter-operators.js +91 -96
  921. package/out/zql/src/ivm/filter-operators.js.map +1 -1
  922. package/out/zql/src/ivm/filter-push.js +22 -26
  923. package/out/zql/src/ivm/filter-push.js.map +1 -1
  924. package/out/zql/src/ivm/filter.js +41 -35
  925. package/out/zql/src/ivm/filter.js.map +1 -1
  926. package/out/zql/src/ivm/flipped-join.js +282 -391
  927. package/out/zql/src/ivm/flipped-join.js.map +1 -1
  928. package/out/zql/src/ivm/join-utils.js +85 -115
  929. package/out/zql/src/ivm/join-utils.js.map +1 -1
  930. package/out/zql/src/ivm/join.js +162 -231
  931. package/out/zql/src/ivm/join.js.map +1 -1
  932. package/out/zql/src/ivm/maybe-split-and-push-edit-change.js +21 -25
  933. package/out/zql/src/ivm/maybe-split-and-push-edit-change.js.map +1 -1
  934. package/out/zql/src/ivm/memory-source.js +364 -503
  935. package/out/zql/src/ivm/memory-source.js.map +1 -1
  936. package/out/zql/src/ivm/memory-storage.js +33 -34
  937. package/out/zql/src/ivm/memory-storage.js.map +1 -1
  938. package/out/zql/src/ivm/operator.js +13 -15
  939. package/out/zql/src/ivm/operator.js.map +1 -1
  940. package/out/zql/src/ivm/push-accumulated.js +267 -270
  941. package/out/zql/src/ivm/push-accumulated.js.map +1 -1
  942. package/out/zql/src/ivm/skip.js +91 -104
  943. package/out/zql/src/ivm/skip.js.map +1 -1
  944. package/out/zql/src/ivm/stream.js +10 -10
  945. package/out/zql/src/ivm/stream.js.map +1 -1
  946. package/out/zql/src/ivm/take.js +422 -569
  947. package/out/zql/src/ivm/take.js.map +1 -1
  948. package/out/zql/src/ivm/union-fan-in.js +157 -231
  949. package/out/zql/src/ivm/union-fan-in.js.map +1 -1
  950. package/out/zql/src/ivm/union-fan-out.js +38 -43
  951. package/out/zql/src/ivm/union-fan-out.js.map +1 -1
  952. package/out/zql/src/ivm/view-apply-change.js +166 -255
  953. package/out/zql/src/ivm/view-apply-change.js.map +1 -1
  954. package/out/zql/src/mutate/crud.js +35 -34
  955. package/out/zql/src/mutate/crud.js.map +1 -1
  956. package/out/zql/src/mutate/custom.d.ts.map +1 -1
  957. package/out/zql/src/mutate/custom.js +7 -11
  958. package/out/zql/src/mutate/custom.js.map +1 -1
  959. package/out/zql/src/mutate/mutator-registry.js +67 -71
  960. package/out/zql/src/mutate/mutator-registry.js.map +1 -1
  961. package/out/zql/src/mutate/mutator.js +26 -25
  962. package/out/zql/src/mutate/mutator.js.map +1 -1
  963. package/out/zql/src/planner/planner-builder.js +134 -239
  964. package/out/zql/src/planner/planner-builder.js.map +1 -1
  965. package/out/zql/src/planner/planner-connection.js +222 -212
  966. package/out/zql/src/planner/planner-connection.js.map +1 -1
  967. package/out/zql/src/planner/planner-constraint.js +15 -7
  968. package/out/zql/src/planner/planner-constraint.js.map +1 -1
  969. package/out/zql/src/planner/planner-debug.js +199 -224
  970. package/out/zql/src/planner/planner-debug.js.map +1 -1
  971. package/out/zql/src/planner/planner-fan-in.js +146 -162
  972. package/out/zql/src/planner/planner-fan-in.js.map +1 -1
  973. package/out/zql/src/planner/planner-fan-out.js +62 -74
  974. package/out/zql/src/planner/planner-fan-out.js.map +1 -1
  975. package/out/zql/src/planner/planner-graph.js +302 -334
  976. package/out/zql/src/planner/planner-graph.js.map +1 -1
  977. package/out/zql/src/planner/planner-join.js +255 -240
  978. package/out/zql/src/planner/planner-join.js.map +1 -1
  979. package/out/zql/src/planner/planner-node.js +10 -6
  980. package/out/zql/src/planner/planner-node.js.map +1 -1
  981. package/out/zql/src/planner/planner-source.js +15 -22
  982. package/out/zql/src/planner/planner-source.js.map +1 -1
  983. package/out/zql/src/planner/planner-terminus.js +28 -28
  984. package/out/zql/src/planner/planner-terminus.js.map +1 -1
  985. package/out/zql/src/query/complete-ordering.js +37 -61
  986. package/out/zql/src/query/complete-ordering.js.map +1 -1
  987. package/out/zql/src/query/create-builder.js +14 -22
  988. package/out/zql/src/query/create-builder.js.map +1 -1
  989. package/out/zql/src/query/error.js +10 -12
  990. package/out/zql/src/query/error.js.map +1 -1
  991. package/out/zql/src/query/escape-like.js +6 -5
  992. package/out/zql/src/query/escape-like.js.map +1 -1
  993. package/out/zql/src/query/expression.js +138 -157
  994. package/out/zql/src/query/expression.js.map +1 -1
  995. package/out/zql/src/query/measure-push-operator.js +35 -38
  996. package/out/zql/src/query/measure-push-operator.js.map +1 -1
  997. package/out/zql/src/query/metrics-delegate.js +7 -7
  998. package/out/zql/src/query/metrics-delegate.js.map +1 -1
  999. package/out/zql/src/query/named.js +52 -51
  1000. package/out/zql/src/query/named.js.map +1 -1
  1001. package/out/zql/src/query/query-delegate-base.js +190 -238
  1002. package/out/zql/src/query/query-delegate-base.js.map +1 -1
  1003. package/out/zql/src/query/query-impl.d.ts.map +1 -1
  1004. package/out/zql/src/query/query-impl.js +271 -405
  1005. package/out/zql/src/query/query-impl.js.map +1 -1
  1006. package/out/zql/src/query/query-internals.js +16 -8
  1007. package/out/zql/src/query/query-internals.js.map +1 -1
  1008. package/out/zql/src/query/query-registry.js +83 -98
  1009. package/out/zql/src/query/query-registry.js.map +1 -1
  1010. package/out/zql/src/query/query.d.ts.map +1 -1
  1011. package/out/zql/src/query/query.js +2 -0
  1012. package/out/zql/src/query/runnable-query-impl.d.ts.map +1 -1
  1013. package/out/zql/src/query/runnable-query-impl.js +30 -55
  1014. package/out/zql/src/query/runnable-query-impl.js.map +1 -1
  1015. package/out/zql/src/query/static-query.js +7 -14
  1016. package/out/zql/src/query/static-query.js.map +1 -1
  1017. package/out/zql/src/query/ttl.js +45 -67
  1018. package/out/zql/src/query/ttl.js.map +1 -1
  1019. package/out/zql/src/query/validate-input.js +23 -20
  1020. package/out/zql/src/query/validate-input.js.map +1 -1
  1021. package/out/zqlite/src/database-storage.js +99 -103
  1022. package/out/zqlite/src/database-storage.js.map +1 -1
  1023. package/out/zqlite/src/db.js +206 -249
  1024. package/out/zqlite/src/db.js.map +1 -1
  1025. package/out/zqlite/src/explain-queries.js +11 -13
  1026. package/out/zqlite/src/explain-queries.js.map +1 -1
  1027. package/out/zqlite/src/internal/sql-inline.js +54 -37
  1028. package/out/zqlite/src/internal/sql-inline.js.map +1 -1
  1029. package/out/zqlite/src/internal/sql.js +17 -15
  1030. package/out/zqlite/src/internal/sql.js.map +1 -1
  1031. package/out/zqlite/src/internal/statement-cache.js +117 -92
  1032. package/out/zqlite/src/internal/statement-cache.js.map +1 -1
  1033. package/out/zqlite/src/mod.js +5 -0
  1034. package/out/zqlite/src/query-builder.js +81 -172
  1035. package/out/zqlite/src/query-builder.js.map +1 -1
  1036. package/out/zqlite/src/query-delegate.js +45 -55
  1037. package/out/zqlite/src/query-delegate.js.map +1 -1
  1038. package/out/zqlite/src/resolve-scalar-subqueries.js +134 -124
  1039. package/out/zqlite/src/resolve-scalar-subqueries.js.map +1 -1
  1040. package/out/zqlite/src/sqlite-cost-model.js +92 -97
  1041. package/out/zqlite/src/sqlite-cost-model.js.map +1 -1
  1042. package/out/zqlite/src/sqlite-stat-fanout.js +304 -286
  1043. package/out/zqlite/src/sqlite-stat-fanout.js.map +1 -1
  1044. package/out/zqlite/src/table-source.js +281 -455
  1045. package/out/zqlite/src/table-source.js.map +1 -1
  1046. package/package.json +8 -7
  1047. package/out/replicache/src/db/index-operation-enum.js +0 -7
  1048. package/out/replicache/src/db/index-operation-enum.js.map +0 -1
  1049. package/out/replicache/src/db/meta-type-enum.js +0 -7
  1050. package/out/replicache/src/db/meta-type-enum.js.map +0 -1
  1051. package/out/replicache/src/format-version-enum.js +0 -11
  1052. package/out/replicache/src/format-version-enum.js.map +0 -1
  1053. package/out/replicache/src/http-status-unauthorized.js +0 -5
  1054. package/out/replicache/src/http-status-unauthorized.js.map +0 -1
  1055. package/out/replicache/src/invoke-kind-enum.js +0 -7
  1056. package/out/replicache/src/invoke-kind-enum.js.map +0 -1
  1057. package/out/replicache/src/sync/handle-pull-response-result-type-enum.js +0 -9
  1058. package/out/replicache/src/sync/handle-pull-response-result-type-enum.js.map +0 -1
  1059. package/out/zero/package.json.js +0 -9
  1060. package/out/zero/package.json.js.map +0 -1
  1061. package/out/zero/src/adapters/drizzle.js.map +0 -1
  1062. package/out/zero/src/adapters/pg.js.map +0 -1
  1063. package/out/zero/src/adapters/postgresjs.js.map +0 -1
  1064. package/out/zero/src/adapters/prisma.js.map +0 -1
  1065. package/out/zero/src/analyze-query.js.map +0 -1
  1066. package/out/zero/src/ast-to-zql.js.map +0 -1
  1067. package/out/zero/src/bindings.js.map +0 -1
  1068. package/out/zero/src/change-protocol/v0.js.map +0 -1
  1069. package/out/zero/src/cli.js.map +0 -1
  1070. package/out/zero/src/deploy-permissions.js.map +0 -1
  1071. package/out/zero/src/expo-sqlite.js.map +0 -1
  1072. package/out/zero/src/op-sqlite.js.map +0 -1
  1073. package/out/zero/src/pg.js.map +0 -1
  1074. package/out/zero/src/react.js.map +0 -1
  1075. package/out/zero/src/server.js.map +0 -1
  1076. package/out/zero/src/solid.js.map +0 -1
  1077. package/out/zero/src/sqlite.js.map +0 -1
  1078. package/out/zero/src/transform-query.js.map +0 -1
  1079. package/out/zero/src/zero.js.map +0 -1
  1080. package/out/zero/src/zqlite.js.map +0 -1
  1081. package/out/zero-cache/src/db/postgres-replica-identity-enum.js +0 -11
  1082. package/out/zero-cache/src/db/postgres-replica-identity-enum.js.map +0 -1
  1083. package/out/zero-cache/src/db/postgres-type-class-enum.js +0 -17
  1084. package/out/zero-cache/src/db/postgres-type-class-enum.js.map +0 -1
  1085. package/out/zero-cache/src/services/change-streamer/error-type-enum.js +0 -9
  1086. package/out/zero-cache/src/services/change-streamer/error-type-enum.js.map +0 -1
@@ -1,515 +1,463 @@
1
- import { RWLock } from "@rocicorp/lock";
2
- import { joinIterables } from "../../../shared/src/iterables.js";
3
1
  import { promiseVoid } from "../../../shared/src/resolved-promises.js";
4
- import { getSizeOfValue } from "../../../shared/src/size-of-value.js";
5
2
  import { createChunk } from "./chunk.js";
6
3
  import { computeRefCountUpdates } from "./gc.js";
7
4
  import { mustGetChunk } from "./store.js";
8
- class LazyStore {
9
- /**
10
- * This lock is used to ensure correct isolation of Reads and Writes.
11
- * Multiple Reads are allowed in parallel but only a single Write. Reads and
12
- * Writes see an isolated view of the store (corresponding to the Serializable
13
- * level of transaction isolation defined in the SQL standard).
14
- *
15
- * To ensure these semantics the read lock must be acquired when a Read is
16
- * created and held til it is closed, and a Write lock must be acquired when a
17
- * Write is created and held til it is committed or closed.
18
- *
19
- * Code must have a read or write lock to
20
- * - read `_heads`
21
- * - read `_memOnlyChunks`
22
- * - read `_sourceStore`
23
- * - read and write `_sourceChunksCache`
24
- * - read and write `_refCounts`
25
- * - read and write `_refs`
26
- * and must have a write lock to
27
- * - write `_heads`
28
- * - write `_memOnlyChunks`
29
- */
30
- #rwLock = new RWLock();
31
- #heads = /* @__PURE__ */ new Map();
32
- #sourceStore;
33
- #chunkHasher;
34
- #assertValidHash;
35
- /** The following are protected so testing subclass can access. */
36
- _memOnlyChunks = /* @__PURE__ */ new Map();
37
- _sourceChunksCache;
38
- /**
39
- * Ref counts are maintained so that chunks which are unreachable
40
- * from this stores heads can be eagerly and deterministically deleted from
41
- * `this._memOnlyChunks` and `this._sourceChunksCache`.
42
- *
43
- * These ref counts are independent from `this._sourceStore`'s ref counts.
44
- * These ref counts are based on reachability from `this._heads`.
45
- * A chunk is deleted from `this._memOnlyChunks` or
46
- * `this._sourceChunksCache` (which ever it is in) when its ref count becomes
47
- * zero.
48
- * These ref counts count the refs in `this._heads` and `this._refs`.
49
- *
50
- * Not all reachable chunk's refs are included in `this._refs`, because this
51
- * would require loading all chunks reachable in the source store in a
52
- * non-lazy manner. `this._refs` contains the refs of all currently reachable
53
- * chunks that were ever in `this._memOnlyChunks` or
54
- * `this._sourceChunksCache` (even if they have been evicted). A
55
- * chunk's ref information is lazily discovered and stored in `this._refs` and
56
- * counted in `this._refCounts`. A chunk's entries in `this._refs` and
57
- * `this._refCounts` are only deleted when a chunk is deleted due to it
58
- * becoming unreachable (it is not deleted if the chunk is evicted from the
59
- * source-store cache).
60
- *
61
- * The major implication of this lazy discovery of source store refs, is that
62
- * a reachable source store chunk may not be cached when loaded, because it is
63
- * not known to be reachable because some of the pertinent refs have not been
64
- * discovered. However, in practice chunks are read by traversing the graph
65
- * starting from a head, and all pertinent refs are discovered as part of the
66
- * traversal.
67
- *
68
- * These ref counts can be changed in two ways:
69
- * 1. A LazyRead has a cache miss and loads a chunk from the source store that
70
- * is reachable from this._heads. If this chunk's refs are not currently
71
- * counted, it will not have an entry in `this._refs`. In this case, the
72
- * chunks refs will be put in `this._refs` and `this._refCounts` will be
73
- * updated to count them.
74
- * 2. A LazyWrite commit updates a head (which can result in increasing or
75
- * decreasing ref count) or puts a reachable chunk (either a `memory-only` or
76
- * `source` chunk) that references this hash (increasing ref count). The
77
- * computation of these ref count changes is delegated to the
78
- * `computeRefCountUpdates` shared with dag.StoreImpl. In order to
79
- * delegate determining reachability to `computeRefCountUpdates` and defer
80
- * this determination until commit time, LazyWrite treats cache misses
81
- * as a 'put' of the lazily-loaded chunk.
82
- *
83
- * A chunk's hash may have an entry in `this._refCounts` without that
84
- * chunk have ever been in `this._memOnlyChunks` or `this._sourceChunksCache`.
85
- * This is the case when a head or a reachable chunk that was ever in
86
- * `this._memOnlyChunks` or `this._sourceChunksCache` references a chunk
87
- * which is not currently cached (either because it has not been read, or
88
- * because it has been evicted).
89
- */
90
- _refCounts = /* @__PURE__ */ new Map();
91
- _refs = /* @__PURE__ */ new Map();
92
- constructor(sourceStore, sourceCacheSizeLimit, chunkHasher, assertValidHash, getSizeOfChunk = getSizeOfValue) {
93
- this._sourceChunksCache = new ChunksCache(
94
- sourceCacheSizeLimit,
95
- getSizeOfChunk,
96
- this._refCounts,
97
- this._refs
98
- );
99
- this.#sourceStore = sourceStore;
100
- this.#chunkHasher = chunkHasher;
101
- this.#assertValidHash = assertValidHash;
102
- }
103
- async read(sourceRead) {
104
- const release = await this.#rwLock.read();
105
- return new LazyRead(
106
- this.#heads,
107
- this._memOnlyChunks,
108
- this._sourceChunksCache,
109
- this.#sourceStore,
110
- release,
111
- this.#assertValidHash,
112
- sourceRead
113
- );
114
- }
115
- async write() {
116
- const release = await this.#rwLock.write();
117
- return new LazyWrite(
118
- this.#heads,
119
- this._memOnlyChunks,
120
- this._sourceChunksCache,
121
- this.#sourceStore,
122
- this._refCounts,
123
- this._refs,
124
- release,
125
- this.#chunkHasher,
126
- this.#assertValidHash
127
- );
128
- }
129
- close() {
130
- return promiseVoid;
131
- }
132
- /**
133
- * Does not acquire any lock on the store.
134
- */
135
- isCached(chunkHash) {
136
- return this._sourceChunksCache.getWithoutUpdatingLRU(chunkHash) !== void 0;
137
- }
138
- withSuspendedSourceCacheEvictsAndDeletes(fn) {
139
- return this._sourceChunksCache.withSuspendedEvictsAndDeletes(fn);
140
- }
141
- }
142
- class LazyRead {
143
- _heads;
144
- _memOnlyChunks;
145
- _sourceChunksCache;
146
- _sourceStore;
147
- #sourceRead = void 0;
148
- #release;
149
- #closed = false;
150
- assertValidHash;
151
- #sourceReadOwnedByCaller;
152
- constructor(heads, memOnlyChunks, sourceChunksCache, sourceStore, release, assertValidHash, sourceRead) {
153
- this._heads = heads;
154
- this._memOnlyChunks = memOnlyChunks;
155
- this._sourceChunksCache = sourceChunksCache;
156
- this._sourceStore = sourceStore;
157
- this.#release = release;
158
- this.assertValidHash = assertValidHash;
159
- this.#sourceRead = sourceRead !== void 0 ? Promise.resolve(sourceRead) : void 0;
160
- this.#sourceReadOwnedByCaller = sourceRead !== void 0;
161
- }
162
- isMemOnlyChunkHash(hash) {
163
- return this._memOnlyChunks.has(hash);
164
- }
165
- async hasChunk(hash) {
166
- return await this.getChunk(hash) !== void 0;
167
- }
168
- async getChunk(hash) {
169
- const memOnlyChunk = this._memOnlyChunks.get(hash);
170
- if (memOnlyChunk !== void 0) {
171
- return memOnlyChunk;
172
- }
173
- let chunk = this._sourceChunksCache.get(hash);
174
- if (chunk === void 0) {
175
- chunk = await (await this._getSourceRead()).getChunk(hash);
176
- if (chunk !== void 0) {
177
- this._sourceChunksCache.put(chunk);
178
- }
179
- }
180
- return chunk;
181
- }
182
- mustGetChunk(hash) {
183
- return mustGetChunk(this, hash);
184
- }
185
- getHead(name) {
186
- return Promise.resolve(this._heads.get(name));
187
- }
188
- release() {
189
- if (!this.#closed) {
190
- this.#release();
191
- if (!this.#sourceReadOwnedByCaller) {
192
- this.#sourceRead?.then((read) => read.release()).catch((_) => {
193
- });
194
- }
195
- this.#closed = true;
196
- }
197
- }
198
- get closed() {
199
- return this.#closed;
200
- }
201
- _getSourceRead() {
202
- if (!this.#sourceRead) {
203
- this.#sourceRead = this._sourceStore.read();
204
- }
205
- return this.#sourceRead;
206
- }
207
- }
208
- class LazyWrite extends LazyRead {
209
- #refCounts;
210
- #refs;
211
- #chunkHasher;
212
- _pendingHeadChanges = /* @__PURE__ */ new Map();
213
- _pendingMemOnlyChunks = /* @__PURE__ */ new Map();
214
- _pendingCachedChunks = /* @__PURE__ */ new Map();
215
- #createdChunks = /* @__PURE__ */ new Set();
216
- constructor(heads, memOnlyChunks, sourceChunksCache, sourceStore, refCounts, refs, release, chunkHasher, assertValidHash) {
217
- super(
218
- heads,
219
- memOnlyChunks,
220
- sourceChunksCache,
221
- sourceStore,
222
- release,
223
- assertValidHash
224
- );
225
- this.#refCounts = refCounts;
226
- this.#refs = refs;
227
- this.#chunkHasher = chunkHasher;
228
- }
229
- createChunk = (data, refs) => {
230
- const chunk = createChunk(data, refs, this.#chunkHasher);
231
- this.#createdChunks.add(chunk.hash);
232
- return chunk;
233
- };
234
- putChunk(c, size) {
235
- const { hash, meta } = c;
236
- this.assertValidHash(hash);
237
- if (meta.length > 0) {
238
- for (const h of meta) {
239
- this.assertValidHash(h);
240
- }
241
- }
242
- if (this.#createdChunks.has(hash) || this.isMemOnlyChunkHash(hash)) {
243
- this._pendingMemOnlyChunks.set(hash, c);
244
- } else {
245
- this._pendingCachedChunks.set(hash, { chunk: c, size: size ?? -1 });
246
- }
247
- return promiseVoid;
248
- }
249
- async setHead(name, hash) {
250
- await this.#setHead(name, hash);
251
- }
252
- async removeHead(name) {
253
- await this.#setHead(name, void 0);
254
- }
255
- async #setHead(name, hash) {
256
- const oldHash = await this.getHead(name);
257
- const v = this._pendingHeadChanges.get(name);
258
- if (v === void 0) {
259
- this._pendingHeadChanges.set(name, { new: hash, old: oldHash });
260
- } else {
261
- v.new = hash;
262
- }
263
- }
264
- isMemOnlyChunkHash(hash) {
265
- return this._pendingMemOnlyChunks.has(hash) || super.isMemOnlyChunkHash(hash);
266
- }
267
- async getChunk(hash) {
268
- const pendingMemOnlyChunk = this._pendingMemOnlyChunks.get(hash);
269
- if (pendingMemOnlyChunk !== void 0) {
270
- return pendingMemOnlyChunk;
271
- }
272
- const memOnlyChunk = this._memOnlyChunks.get(hash);
273
- if (memOnlyChunk !== void 0) {
274
- return memOnlyChunk;
275
- }
276
- const pendingCachedChunk = this._pendingCachedChunks.get(hash);
277
- if (pendingCachedChunk !== void 0) {
278
- return pendingCachedChunk.chunk;
279
- }
280
- let chunk = this._sourceChunksCache.get(hash);
281
- if (chunk === void 0) {
282
- chunk = await (await this._getSourceRead()).getChunk(hash);
283
- if (chunk !== void 0) {
284
- this._pendingCachedChunks.set(chunk.hash, { chunk, size: -1 });
285
- }
286
- }
287
- return chunk;
288
- }
289
- getHead(name) {
290
- const headChange = this._pendingHeadChanges.get(name);
291
- if (headChange) {
292
- return Promise.resolve(headChange.new);
293
- }
294
- return super.getHead(name);
295
- }
296
- async commit() {
297
- const pendingChunks = new Set(
298
- joinIterables(
299
- this._pendingMemOnlyChunks.keys(),
300
- this._pendingCachedChunks.keys()
301
- )
302
- );
303
- const refCountUpdates = await computeRefCountUpdates(
304
- this._pendingHeadChanges.values(),
305
- pendingChunks,
306
- this
307
- );
308
- for (const [hash, count] of refCountUpdates) {
309
- if (this.isMemOnlyChunkHash(hash)) {
310
- if (count === 0) {
311
- this.#refCounts.delete(hash);
312
- this._memOnlyChunks.delete(hash);
313
- this.#refs.delete(hash);
314
- } else {
315
- this.#refCounts.set(hash, count);
316
- const chunk = this._pendingMemOnlyChunks.get(hash);
317
- if (chunk) {
318
- this.#refs.set(hash, chunk.meta);
319
- this._memOnlyChunks.set(hash, chunk);
320
- }
321
- }
322
- refCountUpdates.delete(hash);
323
- }
324
- }
325
- this._sourceChunksCache.updateForCommit(
326
- this._pendingCachedChunks,
327
- refCountUpdates
328
- );
329
- for (const [name, headChange] of this._pendingHeadChanges) {
330
- if (headChange.new) {
331
- this._heads.set(name, headChange.new);
332
- } else {
333
- this._heads.delete(name);
334
- }
335
- }
336
- this._pendingMemOnlyChunks.clear();
337
- this._pendingCachedChunks.clear();
338
- this._pendingHeadChanges.clear();
339
- this.release();
340
- }
341
- getRefCount(hash) {
342
- return this.#refCounts.get(hash);
343
- }
344
- getRefs(hash) {
345
- const pendingMemOnlyChunk = this._pendingMemOnlyChunks.get(hash);
346
- if (pendingMemOnlyChunk) {
347
- return pendingMemOnlyChunk.meta;
348
- }
349
- const memOnlyChunk = this._memOnlyChunks.get(hash);
350
- if (memOnlyChunk) {
351
- return memOnlyChunk.meta;
352
- }
353
- const pendingCachedChunk = this._pendingCachedChunks.get(hash);
354
- if (pendingCachedChunk !== void 0) {
355
- return pendingCachedChunk.chunk.meta;
356
- }
357
- return this.#refs.get(hash);
358
- }
359
- areRefsCounted(hash) {
360
- return this.#refs.has(hash);
361
- }
362
- chunksPersisted(chunkHashes) {
363
- const chunksToCache = [];
364
- for (const chunkHash of chunkHashes) {
365
- const chunk = this._memOnlyChunks.get(chunkHash);
366
- if (chunk) {
367
- this._memOnlyChunks.delete(chunkHash);
368
- chunksToCache.push(chunk);
369
- }
370
- }
371
- this._sourceChunksCache.persisted(chunksToCache);
372
- }
373
- }
374
- class ChunksCache {
375
- #cacheSizeLimit;
376
- #getSizeOfChunk;
377
- #refCounts;
378
- #refs;
379
- #size = 0;
380
- #evictsAndDeletesSuspended = false;
381
- #suspendedDeletes = [];
382
- /**
383
- * Iteration order is from least to most recently used.
384
- *
385
- * Public so that testing subclass can access.
386
- */
387
- cacheEntries = /* @__PURE__ */ new Map();
388
- constructor(cacheSizeLimit, getSizeOfChunk, refCounts, refs) {
389
- this.#cacheSizeLimit = cacheSizeLimit;
390
- this.#getSizeOfChunk = getSizeOfChunk;
391
- this.#refCounts = refCounts;
392
- this.#refs = refs;
393
- }
394
- get(hash) {
395
- const cacheEntry = this.cacheEntries.get(hash);
396
- if (cacheEntry) {
397
- this.cacheEntries.delete(hash);
398
- this.cacheEntries.set(hash, cacheEntry);
399
- }
400
- return cacheEntry?.chunk;
401
- }
402
- getWithoutUpdatingLRU(hash) {
403
- return this.cacheEntries.get(hash)?.chunk;
404
- }
405
- put(chunk) {
406
- const { hash } = chunk;
407
- const oldCacheEntry = this.cacheEntries.get(hash);
408
- if (oldCacheEntry) {
409
- this.cacheEntries.delete(hash);
410
- this.cacheEntries.set(hash, oldCacheEntry);
411
- return;
412
- }
413
- const refCount = this.#refCounts.get(hash);
414
- if (refCount === void 0 || refCount < 1) {
415
- return;
416
- }
417
- if (!this.#cacheChunk(chunk)) {
418
- return;
419
- }
420
- if (!this.#refs.has(hash)) {
421
- for (const refHash of chunk.meta) {
422
- this.#refCounts.set(refHash, (this.#refCounts.get(refHash) || 0) + 1);
423
- }
424
- this.#refs.set(hash, chunk.meta);
425
- }
426
- this.#ensureCacheSizeLimit();
427
- }
428
- #ensureCacheSizeLimit() {
429
- if (this.#evictsAndDeletesSuspended) {
430
- return;
431
- }
432
- for (const entry of this.cacheEntries.values()) {
433
- if (this.#size <= this.#cacheSizeLimit) {
434
- break;
435
- }
436
- this.#evict(entry);
437
- }
438
- }
439
- #cacheChunk(chunk, size) {
440
- const chunkSize = size ?? this.#getSizeOfChunk(chunk);
441
- if (chunkSize > this.#cacheSizeLimit) {
442
- return false;
443
- }
444
- this.#size += chunkSize;
445
- this.cacheEntries.set(chunk.hash, { chunk, size: chunkSize });
446
- return true;
447
- }
448
- #evict(cacheEntry) {
449
- const { hash } = cacheEntry.chunk;
450
- this.#size -= cacheEntry.size;
451
- this.cacheEntries.delete(hash);
452
- }
453
- #deleteEntryByHash(hash) {
454
- this.#refCounts.delete(hash);
455
- this.#refs.delete(hash);
456
- const cacheEntry = this.cacheEntries.get(hash);
457
- if (cacheEntry) {
458
- this.#size -= cacheEntry.size;
459
- this.cacheEntries.delete(hash);
460
- }
461
- }
462
- updateForCommit(chunksToPut, refCountUpdates) {
463
- for (const [hash, count] of refCountUpdates) {
464
- if (count === 0) {
465
- if (!this.#evictsAndDeletesSuspended) {
466
- this.#deleteEntryByHash(hash);
467
- } else {
468
- this.#refCounts.set(hash, 0);
469
- this.#suspendedDeletes.push(hash);
470
- }
471
- } else {
472
- this.#refCounts.set(hash, count);
473
- const chunkAndSize = chunksToPut.get(hash);
474
- if (chunkAndSize) {
475
- const { chunk, size } = chunkAndSize;
476
- const oldCacheEntry = this.cacheEntries.get(hash);
477
- if (oldCacheEntry) {
478
- this.cacheEntries.delete(hash);
479
- this.cacheEntries.set(hash, oldCacheEntry);
480
- } else {
481
- this.#cacheChunk(chunk, size !== -1 ? size : void 0);
482
- this.#refs.set(hash, chunk.meta);
483
- }
484
- }
485
- }
486
- }
487
- this.#ensureCacheSizeLimit();
488
- }
489
- persisted(chunks) {
490
- for (const chunk of chunks) {
491
- this.#cacheChunk(chunk);
492
- }
493
- this.#ensureCacheSizeLimit();
494
- }
495
- async withSuspendedEvictsAndDeletes(fn) {
496
- this.#evictsAndDeletesSuspended = true;
497
- try {
498
- return await fn();
499
- } finally {
500
- this.#evictsAndDeletesSuspended = false;
501
- for (const hash of this.#suspendedDeletes) {
502
- if (this.#refCounts.get(hash) === 0) {
503
- this.#deleteEntryByHash(hash);
504
- }
505
- }
506
- this.#ensureCacheSizeLimit();
507
- }
508
- }
509
- }
510
- export {
511
- LazyRead,
512
- LazyStore,
513
- LazyWrite
5
+ import { joinIterables } from "../../../shared/src/iterables.js";
6
+ import { getSizeOfValue } from "../../../shared/src/size-of-value.js";
7
+ import { RWLock } from "@rocicorp/lock";
8
+ //#region ../replicache/src/dag/lazy-store.ts
9
+ /**
10
+ * Dag Store which lazily loads values from a source store and then caches
11
+ * them in an LRU cache. The memory cache for chunks from the source store
12
+ * size is limited to `sourceCacheSizeLimit` bytes, and values are evicted in an
13
+ * LRU fashion. The purpose of this store is to avoid holding the entire client
14
+ * view (i.e. the source store's content) in each tab's JavaScript heap.
15
+ *
16
+ * This store's heads are independent from the heads of source store, and are
17
+ * only stored in memory.
18
+ *
19
+ * Chunks which are created via this store's {@link Write} transaction's
20
+ * {@link createChunk} method are assumed to not be persisted to the source
21
+ * store and thus are cached separately from the source store chunks. These
22
+ * memory-only chunks will not be evicted, and their sizes are not counted
23
+ * towards the source chunk cache size. A memory-only chunk will be deleted if
24
+ * it is no longer reachable from one of this store's heads.
25
+ *
26
+ * Writes only manipulate the in memory state of this store and do not alter the
27
+ * source store. Thus values must be written to the source store through a
28
+ * separate process (see {@link persist}).
29
+ *
30
+ * Intended use:
31
+ * 1. source store is the 'perdag', a slower persistent store (i.e.
32
+ * dag.StoreImpl using a kv.IDBStore)
33
+ * 2. this store's 'main' head is initialized to the hash of a chunk containing
34
+ * a commit in the source store
35
+ * 3. reads lazily read chunks from the source store and cache them
36
+ * 3. writes are initially made to this store with memory-only chunks
37
+ * 4. writes are asynchronously persisted to the source store through a separate
38
+ * process (see {@link persist}}. This process gathers memory-only chunks
39
+ * from this store and then writes them to the source store. It then informs
40
+ * this store that these chunks are no longer memory-only by calling
41
+ * {@link chunksPersisted}, which move these chunks
42
+ * to this store's LRU cache of source chunks (making them eligible for
43
+ * eviction).
44
+ *
45
+ * @param sourceStore Store to lazy load and cache values from.
46
+ * @param sourceCacheSizeLimit Size limit in bytes for cache of chunks loaded
47
+ * from `sourceStore`. This size of a value is determined using
48
+ * `getSizeOfValue`. Keys do not count towards cache size. Memory-only chunks
49
+ * do not count towards cache size.
50
+ * @param getSizeOfValue Function for measuring the size in bytes of a value.
51
+ */
52
+ var LazyStore = class {
53
+ /**
54
+ * This lock is used to ensure correct isolation of Reads and Writes.
55
+ * Multiple Reads are allowed in parallel but only a single Write. Reads and
56
+ * Writes see an isolated view of the store (corresponding to the Serializable
57
+ * level of transaction isolation defined in the SQL standard).
58
+ *
59
+ * To ensure these semantics the read lock must be acquired when a Read is
60
+ * created and held til it is closed, and a Write lock must be acquired when a
61
+ * Write is created and held til it is committed or closed.
62
+ *
63
+ * Code must have a read or write lock to
64
+ * - read `_heads`
65
+ * - read `_memOnlyChunks`
66
+ * - read `_sourceStore`
67
+ * - read and write `_sourceChunksCache`
68
+ * - read and write `_refCounts`
69
+ * - read and write `_refs`
70
+ * and must have a write lock to
71
+ * - write `_heads`
72
+ * - write `_memOnlyChunks`
73
+ */
74
+ #rwLock = new RWLock();
75
+ #heads = /* @__PURE__ */ new Map();
76
+ #sourceStore;
77
+ #chunkHasher;
78
+ #assertValidHash;
79
+ /** The following are protected so testing subclass can access. */
80
+ _memOnlyChunks = /* @__PURE__ */ new Map();
81
+ _sourceChunksCache;
82
+ /**
83
+ * Ref counts are maintained so that chunks which are unreachable
84
+ * from this stores heads can be eagerly and deterministically deleted from
85
+ * `this._memOnlyChunks` and `this._sourceChunksCache`.
86
+ *
87
+ * These ref counts are independent from `this._sourceStore`'s ref counts.
88
+ * These ref counts are based on reachability from `this._heads`.
89
+ * A chunk is deleted from `this._memOnlyChunks` or
90
+ * `this._sourceChunksCache` (which ever it is in) when its ref count becomes
91
+ * zero.
92
+ * These ref counts count the refs in `this._heads` and `this._refs`.
93
+ *
94
+ * Not all reachable chunk's refs are included in `this._refs`, because this
95
+ * would require loading all chunks reachable in the source store in a
96
+ * non-lazy manner. `this._refs` contains the refs of all currently reachable
97
+ * chunks that were ever in `this._memOnlyChunks` or
98
+ * `this._sourceChunksCache` (even if they have been evicted). A
99
+ * chunk's ref information is lazily discovered and stored in `this._refs` and
100
+ * counted in `this._refCounts`. A chunk's entries in `this._refs` and
101
+ * `this._refCounts` are only deleted when a chunk is deleted due to it
102
+ * becoming unreachable (it is not deleted if the chunk is evicted from the
103
+ * source-store cache).
104
+ *
105
+ * The major implication of this lazy discovery of source store refs, is that
106
+ * a reachable source store chunk may not be cached when loaded, because it is
107
+ * not known to be reachable because some of the pertinent refs have not been
108
+ * discovered. However, in practice chunks are read by traversing the graph
109
+ * starting from a head, and all pertinent refs are discovered as part of the
110
+ * traversal.
111
+ *
112
+ * These ref counts can be changed in two ways:
113
+ * 1. A LazyRead has a cache miss and loads a chunk from the source store that
114
+ * is reachable from this._heads. If this chunk's refs are not currently
115
+ * counted, it will not have an entry in `this._refs`. In this case, the
116
+ * chunks refs will be put in `this._refs` and `this._refCounts` will be
117
+ * updated to count them.
118
+ * 2. A LazyWrite commit updates a head (which can result in increasing or
119
+ * decreasing ref count) or puts a reachable chunk (either a `memory-only` or
120
+ * `source` chunk) that references this hash (increasing ref count). The
121
+ * computation of these ref count changes is delegated to the
122
+ * `computeRefCountUpdates` shared with dag.StoreImpl. In order to
123
+ * delegate determining reachability to `computeRefCountUpdates` and defer
124
+ * this determination until commit time, LazyWrite treats cache misses
125
+ * as a 'put' of the lazily-loaded chunk.
126
+ *
127
+ * A chunk's hash may have an entry in `this._refCounts` without that
128
+ * chunk have ever been in `this._memOnlyChunks` or `this._sourceChunksCache`.
129
+ * This is the case when a head or a reachable chunk that was ever in
130
+ * `this._memOnlyChunks` or `this._sourceChunksCache` references a chunk
131
+ * which is not currently cached (either because it has not been read, or
132
+ * because it has been evicted).
133
+ */
134
+ _refCounts = /* @__PURE__ */ new Map();
135
+ _refs = /* @__PURE__ */ new Map();
136
+ constructor(sourceStore, sourceCacheSizeLimit, chunkHasher, assertValidHash, getSizeOfChunk = getSizeOfValue) {
137
+ this._sourceChunksCache = new ChunksCache(sourceCacheSizeLimit, getSizeOfChunk, this._refCounts, this._refs);
138
+ this.#sourceStore = sourceStore;
139
+ this.#chunkHasher = chunkHasher;
140
+ this.#assertValidHash = assertValidHash;
141
+ }
142
+ async read(sourceRead) {
143
+ const release = await this.#rwLock.read();
144
+ return new LazyRead(this.#heads, this._memOnlyChunks, this._sourceChunksCache, this.#sourceStore, release, this.#assertValidHash, sourceRead);
145
+ }
146
+ async write() {
147
+ const release = await this.#rwLock.write();
148
+ return new LazyWrite(this.#heads, this._memOnlyChunks, this._sourceChunksCache, this.#sourceStore, this._refCounts, this._refs, release, this.#chunkHasher, this.#assertValidHash);
149
+ }
150
+ close() {
151
+ return promiseVoid;
152
+ }
153
+ /**
154
+ * Does not acquire any lock on the store.
155
+ */
156
+ isCached(chunkHash) {
157
+ return this._sourceChunksCache.getWithoutUpdatingLRU(chunkHash) !== void 0;
158
+ }
159
+ withSuspendedSourceCacheEvictsAndDeletes(fn) {
160
+ return this._sourceChunksCache.withSuspendedEvictsAndDeletes(fn);
161
+ }
162
+ };
163
+ var LazyRead = class {
164
+ _heads;
165
+ _memOnlyChunks;
166
+ _sourceChunksCache;
167
+ _sourceStore;
168
+ #sourceRead = void 0;
169
+ #release;
170
+ #closed = false;
171
+ assertValidHash;
172
+ #sourceReadOwnedByCaller;
173
+ constructor(heads, memOnlyChunks, sourceChunksCache, sourceStore, release, assertValidHash, sourceRead) {
174
+ this._heads = heads;
175
+ this._memOnlyChunks = memOnlyChunks;
176
+ this._sourceChunksCache = sourceChunksCache;
177
+ this._sourceStore = sourceStore;
178
+ this.#release = release;
179
+ this.assertValidHash = assertValidHash;
180
+ this.#sourceRead = sourceRead !== void 0 ? Promise.resolve(sourceRead) : void 0;
181
+ this.#sourceReadOwnedByCaller = sourceRead !== void 0;
182
+ }
183
+ isMemOnlyChunkHash(hash) {
184
+ return this._memOnlyChunks.has(hash);
185
+ }
186
+ async hasChunk(hash) {
187
+ return await this.getChunk(hash) !== void 0;
188
+ }
189
+ async getChunk(hash) {
190
+ const memOnlyChunk = this._memOnlyChunks.get(hash);
191
+ if (memOnlyChunk !== void 0) return memOnlyChunk;
192
+ let chunk = this._sourceChunksCache.get(hash);
193
+ if (chunk === void 0) {
194
+ chunk = await (await this._getSourceRead()).getChunk(hash);
195
+ if (chunk !== void 0) this._sourceChunksCache.put(chunk);
196
+ }
197
+ return chunk;
198
+ }
199
+ mustGetChunk(hash) {
200
+ return mustGetChunk(this, hash);
201
+ }
202
+ getHead(name) {
203
+ return Promise.resolve(this._heads.get(name));
204
+ }
205
+ release() {
206
+ if (!this.#closed) {
207
+ this.#release();
208
+ if (!this.#sourceReadOwnedByCaller) this.#sourceRead?.then((read) => read.release()).catch((_) => {});
209
+ this.#closed = true;
210
+ }
211
+ }
212
+ get closed() {
213
+ return this.#closed;
214
+ }
215
+ _getSourceRead() {
216
+ if (!this.#sourceRead) this.#sourceRead = this._sourceStore.read();
217
+ return this.#sourceRead;
218
+ }
219
+ };
220
+ var LazyWrite = class extends LazyRead {
221
+ #refCounts;
222
+ #refs;
223
+ #chunkHasher;
224
+ _pendingHeadChanges = /* @__PURE__ */ new Map();
225
+ _pendingMemOnlyChunks = /* @__PURE__ */ new Map();
226
+ _pendingCachedChunks = /* @__PURE__ */ new Map();
227
+ #createdChunks = /* @__PURE__ */ new Set();
228
+ constructor(heads, memOnlyChunks, sourceChunksCache, sourceStore, refCounts, refs, release, chunkHasher, assertValidHash) {
229
+ super(heads, memOnlyChunks, sourceChunksCache, sourceStore, release, assertValidHash);
230
+ this.#refCounts = refCounts;
231
+ this.#refs = refs;
232
+ this.#chunkHasher = chunkHasher;
233
+ }
234
+ createChunk = (data, refs) => {
235
+ const chunk = createChunk(data, refs, this.#chunkHasher);
236
+ this.#createdChunks.add(chunk.hash);
237
+ return chunk;
238
+ };
239
+ putChunk(c, size) {
240
+ const { hash, meta } = c;
241
+ this.assertValidHash(hash);
242
+ if (meta.length > 0) for (const h of meta) this.assertValidHash(h);
243
+ if (this.#createdChunks.has(hash) || this.isMemOnlyChunkHash(hash)) this._pendingMemOnlyChunks.set(hash, c);
244
+ else this._pendingCachedChunks.set(hash, {
245
+ chunk: c,
246
+ size: size ?? -1
247
+ });
248
+ return promiseVoid;
249
+ }
250
+ async setHead(name, hash) {
251
+ await this.#setHead(name, hash);
252
+ }
253
+ async removeHead(name) {
254
+ await this.#setHead(name, void 0);
255
+ }
256
+ async #setHead(name, hash) {
257
+ const oldHash = await this.getHead(name);
258
+ const v = this._pendingHeadChanges.get(name);
259
+ if (v === void 0) this._pendingHeadChanges.set(name, {
260
+ new: hash,
261
+ old: oldHash
262
+ });
263
+ else v.new = hash;
264
+ }
265
+ isMemOnlyChunkHash(hash) {
266
+ return this._pendingMemOnlyChunks.has(hash) || super.isMemOnlyChunkHash(hash);
267
+ }
268
+ async getChunk(hash) {
269
+ const pendingMemOnlyChunk = this._pendingMemOnlyChunks.get(hash);
270
+ if (pendingMemOnlyChunk !== void 0) return pendingMemOnlyChunk;
271
+ const memOnlyChunk = this._memOnlyChunks.get(hash);
272
+ if (memOnlyChunk !== void 0) return memOnlyChunk;
273
+ const pendingCachedChunk = this._pendingCachedChunks.get(hash);
274
+ if (pendingCachedChunk !== void 0) return pendingCachedChunk.chunk;
275
+ let chunk = this._sourceChunksCache.get(hash);
276
+ if (chunk === void 0) {
277
+ chunk = await (await this._getSourceRead()).getChunk(hash);
278
+ if (chunk !== void 0) this._pendingCachedChunks.set(chunk.hash, {
279
+ chunk,
280
+ size: -1
281
+ });
282
+ }
283
+ return chunk;
284
+ }
285
+ getHead(name) {
286
+ const headChange = this._pendingHeadChanges.get(name);
287
+ if (headChange) return Promise.resolve(headChange.new);
288
+ return super.getHead(name);
289
+ }
290
+ async commit() {
291
+ const pendingChunks = new Set(joinIterables(this._pendingMemOnlyChunks.keys(), this._pendingCachedChunks.keys()));
292
+ const refCountUpdates = await computeRefCountUpdates(this._pendingHeadChanges.values(), pendingChunks, this);
293
+ for (const [hash, count] of refCountUpdates) if (this.isMemOnlyChunkHash(hash)) {
294
+ if (count === 0) {
295
+ this.#refCounts.delete(hash);
296
+ this._memOnlyChunks.delete(hash);
297
+ this.#refs.delete(hash);
298
+ } else {
299
+ this.#refCounts.set(hash, count);
300
+ const chunk = this._pendingMemOnlyChunks.get(hash);
301
+ if (chunk) {
302
+ this.#refs.set(hash, chunk.meta);
303
+ this._memOnlyChunks.set(hash, chunk);
304
+ }
305
+ }
306
+ refCountUpdates.delete(hash);
307
+ }
308
+ this._sourceChunksCache.updateForCommit(this._pendingCachedChunks, refCountUpdates);
309
+ for (const [name, headChange] of this._pendingHeadChanges) if (headChange.new) this._heads.set(name, headChange.new);
310
+ else this._heads.delete(name);
311
+ this._pendingMemOnlyChunks.clear();
312
+ this._pendingCachedChunks.clear();
313
+ this._pendingHeadChanges.clear();
314
+ this.release();
315
+ }
316
+ getRefCount(hash) {
317
+ return this.#refCounts.get(hash);
318
+ }
319
+ getRefs(hash) {
320
+ const pendingMemOnlyChunk = this._pendingMemOnlyChunks.get(hash);
321
+ if (pendingMemOnlyChunk) return pendingMemOnlyChunk.meta;
322
+ const memOnlyChunk = this._memOnlyChunks.get(hash);
323
+ if (memOnlyChunk) return memOnlyChunk.meta;
324
+ const pendingCachedChunk = this._pendingCachedChunks.get(hash);
325
+ if (pendingCachedChunk !== void 0) return pendingCachedChunk.chunk.meta;
326
+ return this.#refs.get(hash);
327
+ }
328
+ areRefsCounted(hash) {
329
+ return this.#refs.has(hash);
330
+ }
331
+ chunksPersisted(chunkHashes) {
332
+ const chunksToCache = [];
333
+ for (const chunkHash of chunkHashes) {
334
+ const chunk = this._memOnlyChunks.get(chunkHash);
335
+ if (chunk) {
336
+ this._memOnlyChunks.delete(chunkHash);
337
+ chunksToCache.push(chunk);
338
+ }
339
+ }
340
+ this._sourceChunksCache.persisted(chunksToCache);
341
+ }
342
+ };
343
+ var ChunksCache = class {
344
+ #cacheSizeLimit;
345
+ #getSizeOfChunk;
346
+ #refCounts;
347
+ #refs;
348
+ #size = 0;
349
+ #evictsAndDeletesSuspended = false;
350
+ #suspendedDeletes = [];
351
+ /**
352
+ * Iteration order is from least to most recently used.
353
+ *
354
+ * Public so that testing subclass can access.
355
+ */
356
+ cacheEntries = /* @__PURE__ */ new Map();
357
+ constructor(cacheSizeLimit, getSizeOfChunk, refCounts, refs) {
358
+ this.#cacheSizeLimit = cacheSizeLimit;
359
+ this.#getSizeOfChunk = getSizeOfChunk;
360
+ this.#refCounts = refCounts;
361
+ this.#refs = refs;
362
+ }
363
+ get(hash) {
364
+ const cacheEntry = this.cacheEntries.get(hash);
365
+ if (cacheEntry) {
366
+ this.cacheEntries.delete(hash);
367
+ this.cacheEntries.set(hash, cacheEntry);
368
+ }
369
+ return cacheEntry?.chunk;
370
+ }
371
+ getWithoutUpdatingLRU(hash) {
372
+ return this.cacheEntries.get(hash)?.chunk;
373
+ }
374
+ put(chunk) {
375
+ const { hash } = chunk;
376
+ const oldCacheEntry = this.cacheEntries.get(hash);
377
+ if (oldCacheEntry) {
378
+ this.cacheEntries.delete(hash);
379
+ this.cacheEntries.set(hash, oldCacheEntry);
380
+ return;
381
+ }
382
+ const refCount = this.#refCounts.get(hash);
383
+ if (refCount === void 0 || refCount < 1) return;
384
+ if (!this.#cacheChunk(chunk)) return;
385
+ if (!this.#refs.has(hash)) {
386
+ for (const refHash of chunk.meta) this.#refCounts.set(refHash, (this.#refCounts.get(refHash) || 0) + 1);
387
+ this.#refs.set(hash, chunk.meta);
388
+ }
389
+ this.#ensureCacheSizeLimit();
390
+ }
391
+ #ensureCacheSizeLimit() {
392
+ if (this.#evictsAndDeletesSuspended) return;
393
+ for (const entry of this.cacheEntries.values()) {
394
+ if (this.#size <= this.#cacheSizeLimit) break;
395
+ this.#evict(entry);
396
+ }
397
+ }
398
+ #cacheChunk(chunk, size) {
399
+ const chunkSize = size ?? this.#getSizeOfChunk(chunk);
400
+ if (chunkSize > this.#cacheSizeLimit) return false;
401
+ this.#size += chunkSize;
402
+ this.cacheEntries.set(chunk.hash, {
403
+ chunk,
404
+ size: chunkSize
405
+ });
406
+ return true;
407
+ }
408
+ #evict(cacheEntry) {
409
+ const { hash } = cacheEntry.chunk;
410
+ this.#size -= cacheEntry.size;
411
+ this.cacheEntries.delete(hash);
412
+ }
413
+ #deleteEntryByHash(hash) {
414
+ this.#refCounts.delete(hash);
415
+ this.#refs.delete(hash);
416
+ const cacheEntry = this.cacheEntries.get(hash);
417
+ if (cacheEntry) {
418
+ this.#size -= cacheEntry.size;
419
+ this.cacheEntries.delete(hash);
420
+ }
421
+ }
422
+ updateForCommit(chunksToPut, refCountUpdates) {
423
+ for (const [hash, count] of refCountUpdates) if (count === 0) if (!this.#evictsAndDeletesSuspended) this.#deleteEntryByHash(hash);
424
+ else {
425
+ this.#refCounts.set(hash, 0);
426
+ this.#suspendedDeletes.push(hash);
427
+ }
428
+ else {
429
+ this.#refCounts.set(hash, count);
430
+ const chunkAndSize = chunksToPut.get(hash);
431
+ if (chunkAndSize) {
432
+ const { chunk, size } = chunkAndSize;
433
+ const oldCacheEntry = this.cacheEntries.get(hash);
434
+ if (oldCacheEntry) {
435
+ this.cacheEntries.delete(hash);
436
+ this.cacheEntries.set(hash, oldCacheEntry);
437
+ } else {
438
+ this.#cacheChunk(chunk, size !== -1 ? size : void 0);
439
+ this.#refs.set(hash, chunk.meta);
440
+ }
441
+ }
442
+ }
443
+ this.#ensureCacheSizeLimit();
444
+ }
445
+ persisted(chunks) {
446
+ for (const chunk of chunks) this.#cacheChunk(chunk);
447
+ this.#ensureCacheSizeLimit();
448
+ }
449
+ async withSuspendedEvictsAndDeletes(fn) {
450
+ this.#evictsAndDeletesSuspended = true;
451
+ try {
452
+ return await fn();
453
+ } finally {
454
+ this.#evictsAndDeletesSuspended = false;
455
+ for (const hash of this.#suspendedDeletes) if (this.#refCounts.get(hash) === 0) this.#deleteEntryByHash(hash);
456
+ this.#ensureCacheSizeLimit();
457
+ }
458
+ }
514
459
  };
515
- //# sourceMappingURL=lazy-store.js.map
460
+ //#endregion
461
+ export { LazyStore };
462
+
463
+ //# sourceMappingURL=lazy-store.js.map