@rocicorp/zero 0.26.1-canary.9 → 0.26.2-canary.1

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 (1113) 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 -280
  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.d.ts.map +1 -1
  10. package/out/analyze-query/src/run-ast.js +68 -94
  11. package/out/analyze-query/src/run-ast.js.map +1 -1
  12. package/out/ast-to-zql/src/ast-to-zql.js +105 -153
  13. package/out/ast-to-zql/src/ast-to-zql.js.map +1 -1
  14. package/out/ast-to-zql/src/bin.js +57 -62
  15. package/out/ast-to-zql/src/bin.js.map +1 -1
  16. package/out/ast-to-zql/src/format.js +14 -13
  17. package/out/ast-to-zql/src/format.js.map +1 -1
  18. package/out/datadog/src/datadog-log-sink.js +148 -213
  19. package/out/datadog/src/datadog-log-sink.js.map +1 -1
  20. package/out/otel/src/enabled.js +9 -11
  21. package/out/otel/src/enabled.js.map +1 -1
  22. package/out/otel/src/log-options.js +25 -35
  23. package/out/otel/src/log-options.js.map +1 -1
  24. package/out/otel/src/maybe-time.js +13 -14
  25. package/out/otel/src/maybe-time.js.map +1 -1
  26. package/out/otel/src/span.js +23 -26
  27. package/out/otel/src/span.js.map +1 -1
  28. package/out/otel/src/test-log-config.js +11 -10
  29. package/out/otel/src/test-log-config.js.map +1 -1
  30. package/out/otel/src/version.js +6 -5
  31. package/out/otel/src/version.js.map +1 -1
  32. package/out/replicache/src/async-iterable-to-array.js +8 -9
  33. package/out/replicache/src/async-iterable-to-array.js.map +1 -1
  34. package/out/replicache/src/bg-interval.js +28 -35
  35. package/out/replicache/src/bg-interval.js.map +1 -1
  36. package/out/replicache/src/btree/diff.js +6 -5
  37. package/out/replicache/src/btree/diff.js.map +1 -1
  38. package/out/replicache/src/btree/node.js +281 -372
  39. package/out/replicache/src/btree/node.js.map +1 -1
  40. package/out/replicache/src/btree/read.js +155 -256
  41. package/out/replicache/src/btree/read.js.map +1 -1
  42. package/out/replicache/src/btree/splice.js +60 -80
  43. package/out/replicache/src/btree/splice.js.map +1 -1
  44. package/out/replicache/src/btree/write.js +134 -158
  45. package/out/replicache/src/btree/write.js.map +1 -1
  46. package/out/replicache/src/call-default-fetch.js +28 -32
  47. package/out/replicache/src/call-default-fetch.js.map +1 -1
  48. package/out/replicache/src/config.js +2 -0
  49. package/out/replicache/src/connection-loop-delegates.js +31 -33
  50. package/out/replicache/src/connection-loop-delegates.js.map +1 -1
  51. package/out/replicache/src/connection-loop.js +174 -240
  52. package/out/replicache/src/connection-loop.js.map +1 -1
  53. package/out/replicache/src/cookies.js +22 -32
  54. package/out/replicache/src/cookies.js.map +1 -1
  55. package/out/replicache/src/dag/chunk.js +44 -50
  56. package/out/replicache/src/dag/chunk.js.map +1 -1
  57. package/out/replicache/src/dag/gc.js +94 -114
  58. package/out/replicache/src/dag/gc.js.map +1 -1
  59. package/out/replicache/src/dag/key.js +9 -11
  60. package/out/replicache/src/dag/key.js.map +1 -1
  61. package/out/replicache/src/dag/lazy-store.js +458 -510
  62. package/out/replicache/src/dag/lazy-store.js.map +1 -1
  63. package/out/replicache/src/dag/store-impl.js +147 -178
  64. package/out/replicache/src/dag/store-impl.js.map +1 -1
  65. package/out/replicache/src/dag/store.js +19 -22
  66. package/out/replicache/src/dag/store.js.map +1 -1
  67. package/out/replicache/src/dag/visitor.js +23 -21
  68. package/out/replicache/src/dag/visitor.js.map +1 -1
  69. package/out/replicache/src/db/commit.js +209 -283
  70. package/out/replicache/src/db/commit.js.map +1 -1
  71. package/out/replicache/src/db/index.js +79 -122
  72. package/out/replicache/src/db/index.js.map +1 -1
  73. package/out/replicache/src/db/read.js +44 -60
  74. package/out/replicache/src/db/read.js.map +1 -1
  75. package/out/replicache/src/db/rebase.js +22 -77
  76. package/out/replicache/src/db/rebase.js.map +1 -1
  77. package/out/replicache/src/db/write.js +162 -296
  78. package/out/replicache/src/db/write.js.map +1 -1
  79. package/out/replicache/src/deleted-clients.js +59 -87
  80. package/out/replicache/src/deleted-clients.js.map +1 -1
  81. package/out/replicache/src/error-responses.js +18 -26
  82. package/out/replicache/src/error-responses.js.map +1 -1
  83. package/out/replicache/src/expo-sqlite.js +2 -0
  84. package/out/replicache/src/frozen-json.js +74 -108
  85. package/out/replicache/src/frozen-json.js.map +1 -1
  86. package/out/replicache/src/get-default-puller.js +34 -46
  87. package/out/replicache/src/get-default-puller.js.map +1 -1
  88. package/out/replicache/src/get-default-pusher.js +25 -33
  89. package/out/replicache/src/get-default-pusher.js.map +1 -1
  90. package/out/replicache/src/get-kv-store-provider.js +18 -20
  91. package/out/replicache/src/get-kv-store-provider.js.map +1 -1
  92. package/out/replicache/src/hash.js +29 -29
  93. package/out/replicache/src/hash.js.map +1 -1
  94. package/out/replicache/src/http-request-info.js +9 -8
  95. package/out/replicache/src/http-request-info.js.map +1 -1
  96. package/out/replicache/src/impl.js +2 -0
  97. package/out/replicache/src/index-defs.js +17 -28
  98. package/out/replicache/src/index-defs.js.map +1 -1
  99. package/out/replicache/src/kv/expo-sqlite/store.js +52 -50
  100. package/out/replicache/src/kv/expo-sqlite/store.js.map +1 -1
  101. package/out/replicache/src/kv/idb-store-with-mem-fallback.js +71 -68
  102. package/out/replicache/src/kv/idb-store-with-mem-fallback.js.map +1 -1
  103. package/out/replicache/src/kv/idb-store.js +144 -168
  104. package/out/replicache/src/kv/idb-store.js.map +1 -1
  105. package/out/replicache/src/kv/mem-store.js +57 -45
  106. package/out/replicache/src/kv/mem-store.js.map +1 -1
  107. package/out/replicache/src/kv/op-sqlite/store.js +56 -62
  108. package/out/replicache/src/kv/op-sqlite/store.js.map +1 -1
  109. package/out/replicache/src/kv/op-sqlite/types.d.ts.map +1 -1
  110. package/out/replicache/src/kv/op-sqlite/types.js +7 -6
  111. package/out/replicache/src/kv/op-sqlite/types.js.map +1 -1
  112. package/out/replicache/src/kv/read-impl.js +26 -25
  113. package/out/replicache/src/kv/read-impl.js.map +1 -1
  114. package/out/replicache/src/kv/sqlite-store.js +194 -207
  115. package/out/replicache/src/kv/sqlite-store.js.map +1 -1
  116. package/out/replicache/src/kv/throw-if-closed.js +12 -19
  117. package/out/replicache/src/kv/throw-if-closed.js.map +1 -1
  118. package/out/replicache/src/kv/write-impl-base.js +44 -56
  119. package/out/replicache/src/kv/write-impl-base.js.map +1 -1
  120. package/out/replicache/src/kv/write-impl.js +22 -26
  121. package/out/replicache/src/kv/write-impl.js.map +1 -1
  122. package/out/replicache/src/lazy.js +10 -11
  123. package/out/replicache/src/lazy.js.map +1 -1
  124. package/out/replicache/src/log-options.js +14 -7
  125. package/out/replicache/src/log-options.js.map +1 -1
  126. package/out/replicache/src/make-idb-name.js +14 -9
  127. package/out/replicache/src/make-idb-name.js.map +1 -1
  128. package/out/replicache/src/mutation-recovery.js +12 -0
  129. package/out/replicache/src/mutation-recovery.js.map +1 -0
  130. package/out/replicache/src/new-client-channel.js +34 -42
  131. package/out/replicache/src/new-client-channel.js.map +1 -1
  132. package/out/replicache/src/on-persist-channel.js +26 -29
  133. package/out/replicache/src/on-persist-channel.js.map +1 -1
  134. package/out/replicache/src/op-sqlite.js +2 -0
  135. package/out/replicache/src/patch-operation.js +27 -36
  136. package/out/replicache/src/patch-operation.js.map +1 -1
  137. package/out/replicache/src/pending-mutations.js +14 -12
  138. package/out/replicache/src/pending-mutations.js.map +1 -1
  139. package/out/replicache/src/persist/client-gc.js +36 -51
  140. package/out/replicache/src/persist/client-gc.js.map +1 -1
  141. package/out/replicache/src/persist/client-group-gc.js +29 -36
  142. package/out/replicache/src/persist/client-group-gc.js.map +1 -1
  143. package/out/replicache/src/persist/client-groups.js +80 -154
  144. package/out/replicache/src/persist/client-groups.js.map +1 -1
  145. package/out/replicache/src/persist/clients.js +212 -307
  146. package/out/replicache/src/persist/clients.js.map +1 -1
  147. package/out/replicache/src/persist/collect-idb-databases.js +109 -171
  148. package/out/replicache/src/persist/collect-idb-databases.js.map +1 -1
  149. package/out/replicache/src/persist/gather-mem-only-visitor.js +23 -24
  150. package/out/replicache/src/persist/gather-mem-only-visitor.js.map +1 -1
  151. package/out/replicache/src/persist/gather-not-cached-visitor.js +35 -33
  152. package/out/replicache/src/persist/gather-not-cached-visitor.js.map +1 -1
  153. package/out/replicache/src/persist/heartbeat.js +31 -41
  154. package/out/replicache/src/persist/heartbeat.js.map +1 -1
  155. package/out/replicache/src/persist/idb-databases-store-db-name.js +9 -12
  156. package/out/replicache/src/persist/idb-databases-store-db-name.js.map +1 -1
  157. package/out/replicache/src/persist/idb-databases-store.js +78 -97
  158. package/out/replicache/src/persist/idb-databases-store.js.map +1 -1
  159. package/out/replicache/src/persist/make-client-id.js +13 -9
  160. package/out/replicache/src/persist/make-client-id.js.map +1 -1
  161. package/out/replicache/src/persist/persist.js +113 -174
  162. package/out/replicache/src/persist/persist.js.map +1 -1
  163. package/out/replicache/src/persist/refresh.js +94 -183
  164. package/out/replicache/src/persist/refresh.js.map +1 -1
  165. package/out/replicache/src/process-scheduler.js +122 -143
  166. package/out/replicache/src/process-scheduler.js.map +1 -1
  167. package/out/replicache/src/pusher.js +21 -26
  168. package/out/replicache/src/pusher.js.map +1 -1
  169. package/out/replicache/src/replicache-impl.js +844 -1184
  170. package/out/replicache/src/replicache-impl.js.map +1 -1
  171. package/out/replicache/src/report-error.js +9 -6
  172. package/out/replicache/src/report-error.js.map +1 -1
  173. package/out/replicache/src/request-idle.js +13 -11
  174. package/out/replicache/src/request-idle.js.map +1 -1
  175. package/out/replicache/src/scan-iterator.d.ts.map +1 -1
  176. package/out/replicache/src/scan-iterator.js +108 -135
  177. package/out/replicache/src/scan-iterator.js.map +1 -1
  178. package/out/replicache/src/scan-options.js +33 -39
  179. package/out/replicache/src/scan-options.js.map +1 -1
  180. package/out/replicache/src/set-interval-with-signal.js +11 -10
  181. package/out/replicache/src/set-interval-with-signal.js.map +1 -1
  182. package/out/replicache/src/sqlite.js +2 -0
  183. package/out/replicache/src/subscriptions.js +222 -338
  184. package/out/replicache/src/subscriptions.js.map +1 -1
  185. package/out/replicache/src/sync/diff.js +52 -65
  186. package/out/replicache/src/sync/diff.js.map +1 -1
  187. package/out/replicache/src/sync/ids.js +8 -9
  188. package/out/replicache/src/sync/ids.js.map +1 -1
  189. package/out/replicache/src/sync/patch.js +34 -45
  190. package/out/replicache/src/sync/patch.js.map +1 -1
  191. package/out/replicache/src/sync/pull-error.js +15 -15
  192. package/out/replicache/src/sync/pull-error.js.map +1 -1
  193. package/out/replicache/src/sync/pull.js +145 -283
  194. package/out/replicache/src/sync/pull.js.map +1 -1
  195. package/out/replicache/src/sync/push.js +64 -79
  196. package/out/replicache/src/sync/push.js.map +1 -1
  197. package/out/replicache/src/sync/request-id.js +23 -15
  198. package/out/replicache/src/sync/request-id.js.map +1 -1
  199. package/out/replicache/src/sync/sync-head-name.js +6 -5
  200. package/out/replicache/src/sync/sync-head-name.js.map +1 -1
  201. package/out/replicache/src/to-error.js +7 -8
  202. package/out/replicache/src/to-error.js.map +1 -1
  203. package/out/replicache/src/transaction-closed-error.js +15 -15
  204. package/out/replicache/src/transaction-closed-error.js.map +1 -1
  205. package/out/replicache/src/transactions.js +120 -140
  206. package/out/replicache/src/transactions.js.map +1 -1
  207. package/out/replicache/src/version.js +9 -5
  208. package/out/replicache/src/version.js.map +1 -1
  209. package/out/replicache/src/with-transactions.js +23 -20
  210. package/out/replicache/src/with-transactions.js.map +1 -1
  211. package/out/shared/src/abort-error.js +7 -6
  212. package/out/shared/src/abort-error.js.map +1 -1
  213. package/out/shared/src/arrays.js +35 -42
  214. package/out/shared/src/arrays.js.map +1 -1
  215. package/out/shared/src/asserts.js +21 -45
  216. package/out/shared/src/asserts.js.map +1 -1
  217. package/out/shared/src/bigint-json.js +42 -38
  218. package/out/shared/src/bigint-json.js.map +1 -1
  219. package/out/shared/src/binary-search.js +27 -18
  220. package/out/shared/src/binary-search.js.map +1 -1
  221. package/out/shared/src/broadcast-channel.js +20 -23
  222. package/out/shared/src/broadcast-channel.js.map +1 -1
  223. package/out/shared/src/browser-env.js +11 -17
  224. package/out/shared/src/browser-env.js.map +1 -1
  225. package/out/shared/src/btree-set.js +419 -481
  226. package/out/shared/src/btree-set.js.map +1 -1
  227. package/out/shared/src/cache.js +43 -36
  228. package/out/shared/src/cache.js.map +1 -1
  229. package/out/shared/src/centroid.js +24 -26
  230. package/out/shared/src/centroid.js.map +1 -1
  231. package/out/shared/src/config.js +6 -6
  232. package/out/shared/src/config.js.map +1 -1
  233. package/out/shared/src/custom-key-map.js +54 -58
  234. package/out/shared/src/custom-key-map.js.map +1 -1
  235. package/out/shared/src/custom-key-set.js +53 -51
  236. package/out/shared/src/custom-key-set.js.map +1 -1
  237. package/out/shared/src/deep-clone.js +30 -41
  238. package/out/shared/src/deep-clone.js.map +1 -1
  239. package/out/shared/src/deep-merge.js +25 -24
  240. package/out/shared/src/deep-merge.js.map +1 -1
  241. package/out/shared/src/document-visible.js +63 -70
  242. package/out/shared/src/document-visible.js.map +1 -1
  243. package/out/shared/src/dotenv.js +7 -3
  244. package/out/shared/src/dotenv.js.map +1 -1
  245. package/out/shared/src/error.js +43 -64
  246. package/out/shared/src/error.js.map +1 -1
  247. package/out/shared/src/has-own.js +6 -5
  248. package/out/shared/src/has-own.js.map +1 -1
  249. package/out/shared/src/hash.js +15 -14
  250. package/out/shared/src/hash.js.map +1 -1
  251. package/out/shared/src/iterables.js +34 -47
  252. package/out/shared/src/iterables.js.map +1 -1
  253. package/out/shared/src/json-schema.js +25 -30
  254. package/out/shared/src/json-schema.js.map +1 -1
  255. package/out/shared/src/json.js +90 -129
  256. package/out/shared/src/json.js.map +1 -1
  257. package/out/shared/src/logging-test-utils.js +9 -11
  258. package/out/shared/src/logging-test-utils.js.map +1 -1
  259. package/out/shared/src/logging.js +75 -95
  260. package/out/shared/src/logging.js.map +1 -1
  261. package/out/shared/src/must.js +7 -8
  262. package/out/shared/src/must.js.map +1 -1
  263. package/out/shared/src/navigator.js +6 -5
  264. package/out/shared/src/navigator.js.map +1 -1
  265. package/out/shared/src/object-traversal.js +23 -23
  266. package/out/shared/src/object-traversal.js.map +1 -1
  267. package/out/shared/src/objects.js +15 -18
  268. package/out/shared/src/objects.js.map +1 -1
  269. package/out/shared/src/options.js +225 -302
  270. package/out/shared/src/options.js.map +1 -1
  271. package/out/shared/src/parse-big-int.js +12 -11
  272. package/out/shared/src/parse-big-int.js.map +1 -1
  273. package/out/shared/src/promise-race.js +21 -17
  274. package/out/shared/src/promise-race.js.map +1 -1
  275. package/out/shared/src/queue.js +124 -124
  276. package/out/shared/src/queue.js.map +1 -1
  277. package/out/shared/src/rand.js +13 -7
  278. package/out/shared/src/rand.js.map +1 -1
  279. package/out/shared/src/random-uint64.js +8 -7
  280. package/out/shared/src/random-uint64.js.map +1 -1
  281. package/out/shared/src/random-values.js +8 -11
  282. package/out/shared/src/random-values.js.map +1 -1
  283. package/out/shared/src/record-proxy.js +68 -57
  284. package/out/shared/src/record-proxy.js.map +1 -1
  285. package/out/shared/src/resolved-promises.js +9 -11
  286. package/out/shared/src/resolved-promises.js.map +1 -1
  287. package/out/shared/src/sentinels.js +9 -12
  288. package/out/shared/src/sentinels.js.map +1 -1
  289. package/out/shared/src/set-utils.js +41 -63
  290. package/out/shared/src/set-utils.js.map +1 -1
  291. package/out/shared/src/size-of-value.js +55 -51
  292. package/out/shared/src/size-of-value.js.map +1 -1
  293. package/out/shared/src/sleep.js +50 -45
  294. package/out/shared/src/sleep.js.map +1 -1
  295. package/out/shared/src/string-compare.js +8 -11
  296. package/out/shared/src/string-compare.js.map +1 -1
  297. package/out/shared/src/subscribable.js +34 -33
  298. package/out/shared/src/subscribable.js.map +1 -1
  299. package/out/shared/src/tdigest-schema.js +11 -7
  300. package/out/shared/src/tdigest-schema.js.map +1 -1
  301. package/out/shared/src/tdigest.js +197 -270
  302. package/out/shared/src/tdigest.js.map +1 -1
  303. package/out/shared/src/valita.js +145 -174
  304. package/out/shared/src/valita.js.map +1 -1
  305. package/out/z2s/src/compiler.d.ts.map +1 -1
  306. package/out/z2s/src/compiler.js +238 -468
  307. package/out/z2s/src/compiler.js.map +1 -1
  308. package/out/z2s/src/sql.d.ts +0 -1
  309. package/out/z2s/src/sql.d.ts.map +1 -1
  310. package/out/z2s/src/sql.js +149 -194
  311. package/out/z2s/src/sql.js.map +1 -1
  312. package/out/zero/package.js +193 -0
  313. package/out/zero/package.js.map +1 -0
  314. package/out/zero/src/adapters/drizzle.js +1 -6
  315. package/out/zero/src/adapters/pg.js +1 -6
  316. package/out/zero/src/adapters/postgresjs.js +1 -6
  317. package/out/zero/src/adapters/prisma.js +1 -5
  318. package/out/zero/src/analyze-query.js +1 -1
  319. package/out/zero/src/ast-to-zql.js +1 -1
  320. package/out/zero/src/bindings.js +6 -21
  321. package/out/zero/src/build-schema.js +5 -1
  322. package/out/zero/src/build-schema.js.map +1 -1
  323. package/out/zero/src/change-protocol/v0.js +3 -5
  324. package/out/zero/src/cli.js +2 -2
  325. package/out/zero/src/deploy-permissions.js +1 -1
  326. package/out/zero/src/expo-sqlite.js +2 -4
  327. package/out/zero/src/op-sqlite.js +2 -4
  328. package/out/zero/src/pg.js +2 -20
  329. package/out/zero/src/react-native.js +16 -12
  330. package/out/zero/src/react-native.js.map +1 -1
  331. package/out/zero/src/react.js +3 -12
  332. package/out/zero/src/server/runner/main.js +2 -0
  333. package/out/zero/src/server.js +2 -17
  334. package/out/zero/src/solid.js +3 -12
  335. package/out/zero/src/sqlite.js +2 -6
  336. package/out/zero/src/transform-query.js +1 -1
  337. package/out/zero/src/zero-cache-dev.js +124 -151
  338. package/out/zero/src/zero-cache-dev.js.map +1 -1
  339. package/out/zero/src/zero-out.js +9 -6
  340. package/out/zero/src/zero-out.js.map +1 -1
  341. package/out/zero/src/zero.js +6 -55
  342. package/out/zero/src/zqlite.js +2 -7
  343. package/out/zero-cache/src/auth/auth.js +138 -172
  344. package/out/zero-cache/src/auth/auth.js.map +1 -1
  345. package/out/zero-cache/src/auth/jwt.js +25 -33
  346. package/out/zero-cache/src/auth/jwt.js.map +1 -1
  347. package/out/zero-cache/src/auth/load-permissions.js +54 -62
  348. package/out/zero-cache/src/auth/load-permissions.js.map +1 -1
  349. package/out/zero-cache/src/auth/read-authorizer.js +70 -80
  350. package/out/zero-cache/src/auth/read-authorizer.js.map +1 -1
  351. package/out/zero-cache/src/auth/write-authorizer.js +284 -432
  352. package/out/zero-cache/src/auth/write-authorizer.js.map +1 -1
  353. package/out/zero-cache/src/config/network.js +31 -45
  354. package/out/zero-cache/src/config/network.js.map +1 -1
  355. package/out/zero-cache/src/config/normalize.js +81 -83
  356. package/out/zero-cache/src/config/normalize.js.map +1 -1
  357. package/out/zero-cache/src/config/server-context.js +32 -29
  358. package/out/zero-cache/src/config/server-context.js.map +1 -1
  359. package/out/zero-cache/src/config/zero-config.d.ts +4 -0
  360. package/out/zero-cache/src/config/zero-config.d.ts.map +1 -1
  361. package/out/zero-cache/src/config/zero-config.js +753 -816
  362. package/out/zero-cache/src/config/zero-config.js.map +1 -1
  363. package/out/zero-cache/src/custom/fetch.js +183 -230
  364. package/out/zero-cache/src/custom/fetch.js.map +1 -1
  365. package/out/zero-cache/src/custom-queries/transform-query.js +93 -99
  366. package/out/zero-cache/src/custom-queries/transform-query.js.map +1 -1
  367. package/out/zero-cache/src/db/create.js +27 -29
  368. package/out/zero-cache/src/db/create.js.map +1 -1
  369. package/out/zero-cache/src/db/delete-lite-db.js +11 -7
  370. package/out/zero-cache/src/db/delete-lite-db.js.map +1 -1
  371. package/out/zero-cache/src/db/lite-tables.d.ts +2 -1
  372. package/out/zero-cache/src/db/lite-tables.d.ts.map +1 -1
  373. package/out/zero-cache/src/db/lite-tables.js +120 -156
  374. package/out/zero-cache/src/db/lite-tables.js.map +1 -1
  375. package/out/zero-cache/src/db/migration-lite.js +110 -178
  376. package/out/zero-cache/src/db/migration-lite.js.map +1 -1
  377. package/out/zero-cache/src/db/migration.js +82 -151
  378. package/out/zero-cache/src/db/migration.js.map +1 -1
  379. package/out/zero-cache/src/db/mode-enum.js +8 -9
  380. package/out/zero-cache/src/db/mode-enum.js.map +1 -1
  381. package/out/zero-cache/src/db/pg-copy.js +56 -54
  382. package/out/zero-cache/src/db/pg-copy.js.map +1 -1
  383. package/out/zero-cache/src/db/pg-to-lite.js +74 -110
  384. package/out/zero-cache/src/db/pg-to-lite.js.map +1 -1
  385. package/out/zero-cache/src/db/pg-type-parser.js +19 -36
  386. package/out/zero-cache/src/db/pg-type-parser.js.map +1 -1
  387. package/out/zero-cache/src/db/run-transaction.js +19 -20
  388. package/out/zero-cache/src/db/run-transaction.js.map +1 -1
  389. package/out/zero-cache/src/db/specs.d.ts +8 -2
  390. package/out/zero-cache/src/db/specs.d.ts.map +1 -1
  391. package/out/zero-cache/src/db/specs.js +42 -78
  392. package/out/zero-cache/src/db/specs.js.map +1 -1
  393. package/out/zero-cache/src/db/statements.js +52 -59
  394. package/out/zero-cache/src/db/statements.js.map +1 -1
  395. package/out/zero-cache/src/db/transaction-pool.js +376 -400
  396. package/out/zero-cache/src/db/transaction-pool.js.map +1 -1
  397. package/out/zero-cache/src/db/warmup.js +13 -24
  398. package/out/zero-cache/src/db/warmup.js.map +1 -1
  399. package/out/zero-cache/src/observability/events.js +89 -99
  400. package/out/zero-cache/src/observability/events.js.map +1 -1
  401. package/out/zero-cache/src/observability/metrics.js +30 -54
  402. package/out/zero-cache/src/observability/metrics.js.map +1 -1
  403. package/out/zero-cache/src/scripts/decommission.js +42 -47
  404. package/out/zero-cache/src/scripts/decommission.js.map +1 -1
  405. package/out/zero-cache/src/scripts/deploy-permissions.js +106 -144
  406. package/out/zero-cache/src/scripts/deploy-permissions.js.map +1 -1
  407. package/out/zero-cache/src/scripts/permissions.js +86 -107
  408. package/out/zero-cache/src/scripts/permissions.js.map +1 -1
  409. package/out/zero-cache/src/server/anonymous-otel-start.js +306 -440
  410. package/out/zero-cache/src/server/anonymous-otel-start.js.map +1 -1
  411. package/out/zero-cache/src/server/change-streamer.d.ts.map +1 -1
  412. package/out/zero-cache/src/server/change-streamer.js +57 -128
  413. package/out/zero-cache/src/server/change-streamer.js.map +1 -1
  414. package/out/zero-cache/src/server/inspector-delegate.js +89 -100
  415. package/out/zero-cache/src/server/inspector-delegate.js.map +1 -1
  416. package/out/zero-cache/src/server/logging.js +18 -26
  417. package/out/zero-cache/src/server/logging.js.map +1 -1
  418. package/out/zero-cache/src/server/main.js +85 -142
  419. package/out/zero-cache/src/server/main.js.map +1 -1
  420. package/out/zero-cache/src/server/mutator.js +16 -13
  421. package/out/zero-cache/src/server/mutator.js.map +1 -1
  422. package/out/zero-cache/src/server/otel-diag-logger.js +42 -49
  423. package/out/zero-cache/src/server/otel-diag-logger.js.map +1 -1
  424. package/out/zero-cache/src/server/otel-log-sink.js +34 -44
  425. package/out/zero-cache/src/server/otel-log-sink.js.map +1 -1
  426. package/out/zero-cache/src/server/otel-start.js +43 -51
  427. package/out/zero-cache/src/server/otel-start.js.map +1 -1
  428. package/out/zero-cache/src/server/priority-op.js +27 -25
  429. package/out/zero-cache/src/server/priority-op.js.map +1 -1
  430. package/out/zero-cache/src/server/reaper.js +32 -43
  431. package/out/zero-cache/src/server/reaper.js.map +1 -1
  432. package/out/zero-cache/src/server/replicator.d.ts.map +1 -1
  433. package/out/zero-cache/src/server/replicator.js +41 -57
  434. package/out/zero-cache/src/server/replicator.js.map +1 -1
  435. package/out/zero-cache/src/server/runner/main.js +7 -8
  436. package/out/zero-cache/src/server/runner/main.js.map +1 -1
  437. package/out/zero-cache/src/server/runner/run-worker.js +56 -52
  438. package/out/zero-cache/src/server/runner/run-worker.js.map +1 -1
  439. package/out/zero-cache/src/server/runner/runtime.js +26 -32
  440. package/out/zero-cache/src/server/runner/runtime.js.map +1 -1
  441. package/out/zero-cache/src/server/runner/zero-dispatcher.js +22 -27
  442. package/out/zero-cache/src/server/runner/zero-dispatcher.js.map +1 -1
  443. package/out/zero-cache/src/server/syncer.js +79 -148
  444. package/out/zero-cache/src/server/syncer.js.map +1 -1
  445. package/out/zero-cache/src/server/worker-dispatcher.js +84 -113
  446. package/out/zero-cache/src/server/worker-dispatcher.js.map +1 -1
  447. package/out/zero-cache/src/server/worker-urls.d.ts +2 -1
  448. package/out/zero-cache/src/server/worker-urls.d.ts.map +1 -1
  449. package/out/zero-cache/src/server/worker-urls.js +14 -18
  450. package/out/zero-cache/src/server/worker-urls.js.map +1 -1
  451. package/out/zero-cache/src/server/write-worker.js +2 -0
  452. package/out/zero-cache/src/services/analyze.js +61 -129
  453. package/out/zero-cache/src/services/analyze.js.map +1 -1
  454. package/out/zero-cache/src/services/change-source/common/backfill-manager.js +420 -419
  455. package/out/zero-cache/src/services/change-source/common/backfill-manager.js.map +1 -1
  456. package/out/zero-cache/src/services/change-source/common/change-stream-multiplexer.js +111 -114
  457. package/out/zero-cache/src/services/change-source/common/change-stream-multiplexer.js.map +1 -1
  458. package/out/zero-cache/src/services/change-source/common/replica-schema.d.ts +2 -0
  459. package/out/zero-cache/src/services/change-source/common/replica-schema.d.ts.map +1 -1
  460. package/out/zero-cache/src/services/change-source/common/replica-schema.js +100 -115
  461. package/out/zero-cache/src/services/change-source/common/replica-schema.js.map +1 -1
  462. package/out/zero-cache/src/services/change-source/custom/change-source.js +154 -216
  463. package/out/zero-cache/src/services/change-source/custom/change-source.js.map +1 -1
  464. package/out/zero-cache/src/services/change-source/pg/backfill-metadata.js +11 -14
  465. package/out/zero-cache/src/services/change-source/pg/backfill-metadata.js.map +1 -1
  466. package/out/zero-cache/src/services/change-source/pg/backfill-stream.d.ts.map +1 -1
  467. package/out/zero-cache/src/services/change-source/pg/backfill-stream.js +169 -209
  468. package/out/zero-cache/src/services/change-source/pg/backfill-stream.js.map +1 -1
  469. package/out/zero-cache/src/services/change-source/pg/change-source.d.ts.map +1 -1
  470. package/out/zero-cache/src/services/change-source/pg/change-source.js +676 -835
  471. package/out/zero-cache/src/services/change-source/pg/change-source.js.map +1 -1
  472. package/out/zero-cache/src/services/change-source/pg/decommission.js +19 -23
  473. package/out/zero-cache/src/services/change-source/pg/decommission.js.map +1 -1
  474. package/out/zero-cache/src/services/change-source/pg/initial-sync.js +258 -411
  475. package/out/zero-cache/src/services/change-source/pg/initial-sync.js.map +1 -1
  476. package/out/zero-cache/src/services/change-source/pg/logical-replication/binary-reader.js +59 -65
  477. package/out/zero-cache/src/services/change-source/pg/logical-replication/binary-reader.js.map +1 -1
  478. package/out/zero-cache/src/services/change-source/pg/logical-replication/pgoutput-parser.js +218 -247
  479. package/out/zero-cache/src/services/change-source/pg/logical-replication/pgoutput-parser.js.map +1 -1
  480. package/out/zero-cache/src/services/change-source/pg/logical-replication/stream.js +100 -142
  481. package/out/zero-cache/src/services/change-source/pg/logical-replication/stream.js.map +1 -1
  482. package/out/zero-cache/src/services/change-source/pg/lsn.js +17 -19
  483. package/out/zero-cache/src/services/change-source/pg/lsn.js.map +1 -1
  484. package/out/zero-cache/src/services/change-source/pg/schema/ddl.js +88 -98
  485. package/out/zero-cache/src/services/change-source/pg/schema/ddl.js.map +1 -1
  486. package/out/zero-cache/src/services/change-source/pg/schema/init.js +96 -177
  487. package/out/zero-cache/src/services/change-source/pg/schema/init.js.map +1 -1
  488. package/out/zero-cache/src/services/change-source/pg/schema/published.js +69 -107
  489. package/out/zero-cache/src/services/change-source/pg/schema/published.js.map +1 -1
  490. package/out/zero-cache/src/services/change-source/pg/schema/shard.js +151 -212
  491. package/out/zero-cache/src/services/change-source/pg/schema/shard.js.map +1 -1
  492. package/out/zero-cache/src/services/change-source/pg/schema/validation.js +22 -53
  493. package/out/zero-cache/src/services/change-source/pg/schema/validation.js.map +1 -1
  494. package/out/zero-cache/src/services/change-source/protocol/current/control.js +24 -12
  495. package/out/zero-cache/src/services/change-source/protocol/current/control.js.map +1 -1
  496. package/out/zero-cache/src/services/change-source/protocol/current/data.js +180 -290
  497. package/out/zero-cache/src/services/change-source/protocol/current/data.js.map +1 -1
  498. package/out/zero-cache/src/services/change-source/protocol/current/downstream.js +21 -33
  499. package/out/zero-cache/src/services/change-source/protocol/current/downstream.js.map +1 -1
  500. package/out/zero-cache/src/services/change-source/protocol/current/json.js +7 -18
  501. package/out/zero-cache/src/services/change-source/protocol/current/json.js.map +1 -1
  502. package/out/zero-cache/src/services/change-source/protocol/current/path.js +24 -5
  503. package/out/zero-cache/src/services/change-source/protocol/current/path.js.map +1 -1
  504. package/out/zero-cache/src/services/change-source/protocol/current/status.js +25 -19
  505. package/out/zero-cache/src/services/change-source/protocol/current/status.js.map +1 -1
  506. package/out/zero-cache/src/services/change-source/protocol/current/upstream.js +24 -16
  507. package/out/zero-cache/src/services/change-source/protocol/current/upstream.js.map +1 -1
  508. package/out/zero-cache/src/services/change-source/protocol/current.js +51 -46
  509. package/out/zero-cache/src/services/change-source/protocol/current.js.map +1 -1
  510. package/out/zero-cache/src/services/change-source/protocol/mod.js +2 -0
  511. package/out/zero-cache/src/services/change-streamer/backup-monitor.js +165 -171
  512. package/out/zero-cache/src/services/change-streamer/backup-monitor.js.map +1 -1
  513. package/out/zero-cache/src/services/change-streamer/broadcast.d.ts +100 -0
  514. package/out/zero-cache/src/services/change-streamer/broadcast.d.ts.map +1 -0
  515. package/out/zero-cache/src/services/change-streamer/broadcast.js +165 -0
  516. package/out/zero-cache/src/services/change-streamer/broadcast.js.map +1 -0
  517. package/out/zero-cache/src/services/change-streamer/change-streamer-http.js +154 -221
  518. package/out/zero-cache/src/services/change-streamer/change-streamer-http.js.map +1 -1
  519. package/out/zero-cache/src/services/change-streamer/change-streamer-service.d.ts +1 -1
  520. package/out/zero-cache/src/services/change-streamer/change-streamer-service.d.ts.map +1 -1
  521. package/out/zero-cache/src/services/change-streamer/change-streamer-service.js +341 -293
  522. package/out/zero-cache/src/services/change-streamer/change-streamer-service.js.map +1 -1
  523. package/out/zero-cache/src/services/change-streamer/change-streamer.js +17 -24
  524. package/out/zero-cache/src/services/change-streamer/change-streamer.js.map +1 -1
  525. package/out/zero-cache/src/services/change-streamer/forwarder.d.ts +17 -1
  526. package/out/zero-cache/src/services/change-streamer/forwarder.d.ts.map +1 -1
  527. package/out/zero-cache/src/services/change-streamer/forwarder.js +85 -56
  528. package/out/zero-cache/src/services/change-streamer/forwarder.js.map +1 -1
  529. package/out/zero-cache/src/services/change-streamer/replica-monitor.js +49 -43
  530. package/out/zero-cache/src/services/change-streamer/replica-monitor.js.map +1 -1
  531. package/out/zero-cache/src/services/change-streamer/schema/init.js +61 -89
  532. package/out/zero-cache/src/services/change-streamer/schema/init.js.map +1 -1
  533. package/out/zero-cache/src/services/change-streamer/schema/tables.d.ts +20 -1
  534. package/out/zero-cache/src/services/change-streamer/schema/tables.d.ts.map +1 -1
  535. package/out/zero-cache/src/services/change-streamer/schema/tables.js +131 -109
  536. package/out/zero-cache/src/services/change-streamer/schema/tables.js.map +1 -1
  537. package/out/zero-cache/src/services/change-streamer/snapshot.js +26 -28
  538. package/out/zero-cache/src/services/change-streamer/snapshot.js.map +1 -1
  539. package/out/zero-cache/src/services/change-streamer/storer.js +434 -513
  540. package/out/zero-cache/src/services/change-streamer/storer.js.map +1 -1
  541. package/out/zero-cache/src/services/change-streamer/subscriber.d.ts +18 -0
  542. package/out/zero-cache/src/services/change-streamer/subscriber.d.ts.map +1 -1
  543. package/out/zero-cache/src/services/change-streamer/subscriber.js +143 -100
  544. package/out/zero-cache/src/services/change-streamer/subscriber.js.map +1 -1
  545. package/out/zero-cache/src/services/heapz.js +18 -20
  546. package/out/zero-cache/src/services/heapz.js.map +1 -1
  547. package/out/zero-cache/src/services/http-service.js +59 -57
  548. package/out/zero-cache/src/services/http-service.js.map +1 -1
  549. package/out/zero-cache/src/services/life-cycle.js +182 -214
  550. package/out/zero-cache/src/services/life-cycle.js.map +1 -1
  551. package/out/zero-cache/src/services/limiter/sliding-window-limiter.js +102 -81
  552. package/out/zero-cache/src/services/limiter/sliding-window-limiter.js.map +1 -1
  553. package/out/zero-cache/src/services/litestream/commands.js +144 -205
  554. package/out/zero-cache/src/services/litestream/commands.js.map +1 -1
  555. package/out/zero-cache/src/services/mutagen/error.js +10 -14
  556. package/out/zero-cache/src/services/mutagen/error.js.map +1 -1
  557. package/out/zero-cache/src/services/mutagen/mutagen.js +166 -264
  558. package/out/zero-cache/src/services/mutagen/mutagen.js.map +1 -1
  559. package/out/zero-cache/src/services/mutagen/pusher.js +372 -487
  560. package/out/zero-cache/src/services/mutagen/pusher.js.map +1 -1
  561. package/out/zero-cache/src/services/replicator/change-processor.d.ts.map +1 -1
  562. package/out/zero-cache/src/services/replicator/change-processor.js +483 -595
  563. package/out/zero-cache/src/services/replicator/change-processor.js.map +1 -1
  564. package/out/zero-cache/src/services/replicator/incremental-sync.d.ts +4 -2
  565. package/out/zero-cache/src/services/replicator/incremental-sync.d.ts.map +1 -1
  566. package/out/zero-cache/src/services/replicator/incremental-sync.js +118 -143
  567. package/out/zero-cache/src/services/replicator/incremental-sync.js.map +1 -1
  568. package/out/zero-cache/src/services/replicator/notifier.js +52 -28
  569. package/out/zero-cache/src/services/replicator/notifier.js.map +1 -1
  570. package/out/zero-cache/src/services/replicator/replication-status.js +105 -128
  571. package/out/zero-cache/src/services/replicator/replication-status.js.map +1 -1
  572. package/out/zero-cache/src/services/replicator/replicator.d.ts +2 -1
  573. package/out/zero-cache/src/services/replicator/replicator.d.ts.map +1 -1
  574. package/out/zero-cache/src/services/replicator/replicator.js +32 -34
  575. package/out/zero-cache/src/services/replicator/replicator.js.map +1 -1
  576. package/out/zero-cache/src/services/replicator/schema/change-log.js +101 -133
  577. package/out/zero-cache/src/services/replicator/schema/change-log.js.map +1 -1
  578. package/out/zero-cache/src/services/replicator/schema/column-metadata.js +145 -174
  579. package/out/zero-cache/src/services/replicator/schema/column-metadata.js.map +1 -1
  580. package/out/zero-cache/src/services/replicator/schema/constants.js +11 -5
  581. package/out/zero-cache/src/services/replicator/schema/constants.js.map +1 -1
  582. package/out/zero-cache/src/services/replicator/schema/replication-state.js +56 -107
  583. package/out/zero-cache/src/services/replicator/schema/replication-state.js.map +1 -1
  584. package/out/zero-cache/src/services/replicator/schema/table-metadata.d.ts +28 -7
  585. package/out/zero-cache/src/services/replicator/schema/table-metadata.d.ts.map +1 -1
  586. package/out/zero-cache/src/services/replicator/schema/table-metadata.js +96 -50
  587. package/out/zero-cache/src/services/replicator/schema/table-metadata.js.map +1 -1
  588. package/out/zero-cache/src/services/replicator/write-worker-client.d.ts +69 -0
  589. package/out/zero-cache/src/services/replicator/write-worker-client.d.ts.map +1 -0
  590. package/out/zero-cache/src/services/replicator/write-worker-client.js +96 -0
  591. package/out/zero-cache/src/services/replicator/write-worker-client.js.map +1 -0
  592. package/out/zero-cache/src/services/replicator/write-worker.js +68 -0
  593. package/out/zero-cache/src/services/replicator/write-worker.js.map +1 -0
  594. package/out/zero-cache/src/services/run-ast.d.ts.map +1 -1
  595. package/out/zero-cache/src/services/run-ast.js +79 -118
  596. package/out/zero-cache/src/services/run-ast.js.map +1 -1
  597. package/out/zero-cache/src/services/runner.js +39 -41
  598. package/out/zero-cache/src/services/runner.js.map +1 -1
  599. package/out/zero-cache/src/services/running-state.js +129 -134
  600. package/out/zero-cache/src/services/running-state.js.map +1 -1
  601. package/out/zero-cache/src/services/statz.js +139 -200
  602. package/out/zero-cache/src/services/statz.js.map +1 -1
  603. package/out/zero-cache/src/services/view-syncer/active-users-gauge.js +46 -49
  604. package/out/zero-cache/src/services/view-syncer/active-users-gauge.js.map +1 -1
  605. package/out/zero-cache/src/services/view-syncer/client-handler.js +257 -299
  606. package/out/zero-cache/src/services/view-syncer/client-handler.js.map +1 -1
  607. package/out/zero-cache/src/services/view-syncer/client-schema.js +52 -82
  608. package/out/zero-cache/src/services/view-syncer/client-schema.js.map +1 -1
  609. package/out/zero-cache/src/services/view-syncer/cvr-purger.js +85 -107
  610. package/out/zero-cache/src/services/view-syncer/cvr-purger.js.map +1 -1
  611. package/out/zero-cache/src/services/view-syncer/cvr-store.js +604 -757
  612. package/out/zero-cache/src/services/view-syncer/cvr-store.js.map +1 -1
  613. package/out/zero-cache/src/services/view-syncer/cvr.js +631 -739
  614. package/out/zero-cache/src/services/view-syncer/cvr.js.map +1 -1
  615. package/out/zero-cache/src/services/view-syncer/drain-coordinator.js +60 -40
  616. package/out/zero-cache/src/services/view-syncer/drain-coordinator.js.map +1 -1
  617. package/out/zero-cache/src/services/view-syncer/inspect-handler.js +95 -178
  618. package/out/zero-cache/src/services/view-syncer/inspect-handler.js.map +1 -1
  619. package/out/zero-cache/src/services/view-syncer/pipeline-driver.d.ts +3 -2
  620. package/out/zero-cache/src/services/view-syncer/pipeline-driver.d.ts.map +1 -1
  621. package/out/zero-cache/src/services/view-syncer/pipeline-driver.js +574 -709
  622. package/out/zero-cache/src/services/view-syncer/pipeline-driver.js.map +1 -1
  623. package/out/zero-cache/src/services/view-syncer/row-record-cache.d.ts.map +1 -1
  624. package/out/zero-cache/src/services/view-syncer/row-record-cache.js +246 -257
  625. package/out/zero-cache/src/services/view-syncer/row-record-cache.js.map +1 -1
  626. package/out/zero-cache/src/services/view-syncer/schema/cvr.js +59 -45
  627. package/out/zero-cache/src/services/view-syncer/schema/cvr.js.map +1 -1
  628. package/out/zero-cache/src/services/view-syncer/schema/init.js +121 -189
  629. package/out/zero-cache/src/services/view-syncer/schema/init.js.map +1 -1
  630. package/out/zero-cache/src/services/view-syncer/schema/types.js +138 -263
  631. package/out/zero-cache/src/services/view-syncer/schema/types.js.map +1 -1
  632. package/out/zero-cache/src/services/view-syncer/snapshotter.d.ts +3 -3
  633. package/out/zero-cache/src/services/view-syncer/snapshotter.d.ts.map +1 -1
  634. package/out/zero-cache/src/services/view-syncer/snapshotter.js +322 -331
  635. package/out/zero-cache/src/services/view-syncer/snapshotter.js.map +1 -1
  636. package/out/zero-cache/src/services/view-syncer/tracer.js +7 -6
  637. package/out/zero-cache/src/services/view-syncer/tracer.js.map +1 -1
  638. package/out/zero-cache/src/services/view-syncer/ttl-clock.js +9 -11
  639. package/out/zero-cache/src/services/view-syncer/ttl-clock.js.map +1 -1
  640. package/out/zero-cache/src/services/view-syncer/view-syncer.js +1067 -1603
  641. package/out/zero-cache/src/services/view-syncer/view-syncer.js.map +1 -1
  642. package/out/zero-cache/src/types/error-with-level.js +19 -25
  643. package/out/zero-cache/src/types/error-with-level.js.map +1 -1
  644. package/out/zero-cache/src/types/http.js +17 -26
  645. package/out/zero-cache/src/types/http.js.map +1 -1
  646. package/out/zero-cache/src/types/lexi-version.js +28 -42
  647. package/out/zero-cache/src/types/lexi-version.js.map +1 -1
  648. package/out/zero-cache/src/types/lite.js +101 -121
  649. package/out/zero-cache/src/types/lite.js.map +1 -1
  650. package/out/zero-cache/src/types/names.js +6 -5
  651. package/out/zero-cache/src/types/names.js.map +1 -1
  652. package/out/zero-cache/src/types/pg-data-type.d.ts +1 -0
  653. package/out/zero-cache/src/types/pg-data-type.d.ts.map +1 -1
  654. package/out/zero-cache/src/types/pg-data-type.js +58 -73
  655. package/out/zero-cache/src/types/pg-data-type.js.map +1 -1
  656. package/out/zero-cache/src/types/pg-types.js +12 -19
  657. package/out/zero-cache/src/types/pg-types.js.map +1 -1
  658. package/out/zero-cache/src/types/pg.js +144 -218
  659. package/out/zero-cache/src/types/pg.js.map +1 -1
  660. package/out/zero-cache/src/types/processes.js +95 -90
  661. package/out/zero-cache/src/types/processes.js.map +1 -1
  662. package/out/zero-cache/src/types/profiler.js +32 -27
  663. package/out/zero-cache/src/types/profiler.js.map +1 -1
  664. package/out/zero-cache/src/types/row-key.js +42 -30
  665. package/out/zero-cache/src/types/row-key.js.map +1 -1
  666. package/out/zero-cache/src/types/shards.js +36 -45
  667. package/out/zero-cache/src/types/shards.js.map +1 -1
  668. package/out/zero-cache/src/types/sql.js +20 -9
  669. package/out/zero-cache/src/types/sql.js.map +1 -1
  670. package/out/zero-cache/src/types/state-version.js +17 -23
  671. package/out/zero-cache/src/types/state-version.js.map +1 -1
  672. package/out/zero-cache/src/types/streams.js +234 -270
  673. package/out/zero-cache/src/types/streams.js.map +1 -1
  674. package/out/zero-cache/src/types/strings.js +10 -13
  675. package/out/zero-cache/src/types/strings.js.map +1 -1
  676. package/out/zero-cache/src/types/subscription.d.ts +3 -1
  677. package/out/zero-cache/src/types/subscription.d.ts.map +1 -1
  678. package/out/zero-cache/src/types/subscription.js +266 -214
  679. package/out/zero-cache/src/types/subscription.js.map +1 -1
  680. package/out/zero-cache/src/types/url-params.js +30 -39
  681. package/out/zero-cache/src/types/url-params.js.map +1 -1
  682. package/out/zero-cache/src/types/websocket-handoff.js +62 -75
  683. package/out/zero-cache/src/types/websocket-handoff.js.map +1 -1
  684. package/out/zero-cache/src/types/ws.js +43 -53
  685. package/out/zero-cache/src/types/ws.js.map +1 -1
  686. package/out/zero-cache/src/workers/connect-params.js +42 -43
  687. package/out/zero-cache/src/workers/connect-params.js.map +1 -1
  688. package/out/zero-cache/src/workers/connection.js +213 -282
  689. package/out/zero-cache/src/workers/connection.js.map +1 -1
  690. package/out/zero-cache/src/workers/mutator.js +22 -21
  691. package/out/zero-cache/src/workers/mutator.js.map +1 -1
  692. package/out/zero-cache/src/workers/replicator.d.ts +7 -0
  693. package/out/zero-cache/src/workers/replicator.d.ts.map +1 -1
  694. package/out/zero-cache/src/workers/replicator.js +92 -97
  695. package/out/zero-cache/src/workers/replicator.js.map +1 -1
  696. package/out/zero-cache/src/workers/syncer-ws-message-handler.js +121 -203
  697. package/out/zero-cache/src/workers/syncer-ws-message-handler.js.map +1 -1
  698. package/out/zero-cache/src/workers/syncer.js +147 -201
  699. package/out/zero-cache/src/workers/syncer.js.map +1 -1
  700. package/out/zero-client/src/client/active-clients-manager.js +178 -187
  701. package/out/zero-client/src/client/active-clients-manager.js.map +1 -1
  702. package/out/zero-client/src/client/bindings.js +11 -0
  703. package/out/zero-client/src/client/client-error-kind-enum.js +18 -29
  704. package/out/zero-client/src/client/client-error-kind-enum.js.map +1 -1
  705. package/out/zero-client/src/client/connection-manager.js +291 -346
  706. package/out/zero-client/src/client/connection-manager.js.map +1 -1
  707. package/out/zero-client/src/client/connection-status-enum.js +20 -15
  708. package/out/zero-client/src/client/connection-status-enum.js.map +1 -1
  709. package/out/zero-client/src/client/connection.js +92 -110
  710. package/out/zero-client/src/client/connection.js.map +1 -1
  711. package/out/zero-client/src/client/context.js +84 -100
  712. package/out/zero-client/src/client/context.js.map +1 -1
  713. package/out/zero-client/src/client/crud-impl.js +56 -88
  714. package/out/zero-client/src/client/crud-impl.js.map +1 -1
  715. package/out/zero-client/src/client/crud.js +127 -129
  716. package/out/zero-client/src/client/crud.js.map +1 -1
  717. package/out/zero-client/src/client/custom.d.ts.map +1 -1
  718. package/out/zero-client/src/client/custom.js +50 -74
  719. package/out/zero-client/src/client/custom.js.map +1 -1
  720. package/out/zero-client/src/client/delete-clients-manager.js +72 -93
  721. package/out/zero-client/src/client/delete-clients-manager.js.map +1 -1
  722. package/out/zero-client/src/client/enable-analytics.js +8 -16
  723. package/out/zero-client/src/client/enable-analytics.js.map +1 -1
  724. package/out/zero-client/src/client/error.js +118 -133
  725. package/out/zero-client/src/client/error.js.map +1 -1
  726. package/out/zero-client/src/client/http-string.js +7 -7
  727. package/out/zero-client/src/client/http-string.js.map +1 -1
  728. package/out/zero-client/src/client/inspector/client-group.js +21 -26
  729. package/out/zero-client/src/client/inspector/client-group.js.map +1 -1
  730. package/out/zero-client/src/client/inspector/client.js +23 -26
  731. package/out/zero-client/src/client/inspector/client.js.map +1 -1
  732. package/out/zero-client/src/client/inspector/html-dialog-prompt.js +72 -73
  733. package/out/zero-client/src/client/inspector/html-dialog-prompt.js.map +1 -1
  734. package/out/zero-client/src/client/inspector/inspector.js +46 -51
  735. package/out/zero-client/src/client/inspector/inspector.js.map +1 -1
  736. package/out/zero-client/src/client/inspector/lazy-inspector.js +132 -192
  737. package/out/zero-client/src/client/inspector/lazy-inspector.js.map +1 -1
  738. package/out/zero-client/src/client/inspector/query.js +72 -77
  739. package/out/zero-client/src/client/inspector/query.js.map +1 -1
  740. package/out/zero-client/src/client/ivm-branch.js +118 -145
  741. package/out/zero-client/src/client/ivm-branch.js.map +1 -1
  742. package/out/zero-client/src/client/keys.js +15 -31
  743. package/out/zero-client/src/client/keys.js.map +1 -1
  744. package/out/zero-client/src/client/log-options.js +43 -57
  745. package/out/zero-client/src/client/log-options.js.map +1 -1
  746. package/out/zero-client/src/client/make-mutate-property.js +46 -29
  747. package/out/zero-client/src/client/make-mutate-property.js.map +1 -1
  748. package/out/zero-client/src/client/make-replicache-mutators.js +80 -96
  749. package/out/zero-client/src/client/make-replicache-mutators.js.map +1 -1
  750. package/out/zero-client/src/client/metric-name-enum.js +11 -15
  751. package/out/zero-client/src/client/metric-name-enum.js.map +1 -1
  752. package/out/zero-client/src/client/metrics.js +210 -237
  753. package/out/zero-client/src/client/metrics.js.map +1 -1
  754. package/out/zero-client/src/client/mutation-tracker.js +264 -354
  755. package/out/zero-client/src/client/mutation-tracker.js.map +1 -1
  756. package/out/zero-client/src/client/mutator-proxy.js +122 -151
  757. package/out/zero-client/src/client/mutator-proxy.js.map +1 -1
  758. package/out/zero-client/src/client/options.js +7 -10
  759. package/out/zero-client/src/client/options.js.map +1 -1
  760. package/out/zero-client/src/client/query-manager.js +305 -373
  761. package/out/zero-client/src/client/query-manager.js.map +1 -1
  762. package/out/zero-client/src/client/reload-error-handler.js +80 -101
  763. package/out/zero-client/src/client/reload-error-handler.js.map +1 -1
  764. package/out/zero-client/src/client/server-option.js +30 -59
  765. package/out/zero-client/src/client/server-option.js.map +1 -1
  766. package/out/zero-client/src/client/update-needed-reason-type-enum.js +27 -9
  767. package/out/zero-client/src/client/update-needed-reason-type-enum.js.map +1 -1
  768. package/out/zero-client/src/client/version.js +9 -5
  769. package/out/zero-client/src/client/version.js.map +1 -1
  770. package/out/zero-client/src/client/zero-poke-handler.d.ts +1 -1
  771. package/out/zero-client/src/client/zero-poke-handler.d.ts.map +1 -1
  772. package/out/zero-client/src/client/zero-poke-handler.js +205 -293
  773. package/out/zero-client/src/client/zero-poke-handler.js.map +1 -1
  774. package/out/zero-client/src/client/zero-rep.js +61 -68
  775. package/out/zero-client/src/client/zero-rep.js.map +1 -1
  776. package/out/zero-client/src/client/zero.d.ts.map +1 -1
  777. package/out/zero-client/src/client/zero.js +1367 -1834
  778. package/out/zero-client/src/client/zero.js.map +1 -1
  779. package/out/zero-client/src/mod.js +21 -0
  780. package/out/zero-client/src/util/nanoid.js +13 -18
  781. package/out/zero-client/src/util/nanoid.js.map +1 -1
  782. package/out/zero-client/src/util/socket.js +6 -5
  783. package/out/zero-client/src/util/socket.js.map +1 -1
  784. package/out/zero-pg/src/mod.js +10 -0
  785. package/out/zero-protocol/src/analyze-query-result.js +108 -148
  786. package/out/zero-protocol/src/analyze-query-result.js.map +1 -1
  787. package/out/zero-protocol/src/application-error.js +36 -34
  788. package/out/zero-protocol/src/application-error.js.map +1 -1
  789. package/out/zero-protocol/src/ast.js +236 -309
  790. package/out/zero-protocol/src/ast.js.map +1 -1
  791. package/out/zero-protocol/src/change-desired-queries.js +8 -13
  792. package/out/zero-protocol/src/change-desired-queries.js.map +1 -1
  793. package/out/zero-protocol/src/client-schema.js +21 -42
  794. package/out/zero-protocol/src/client-schema.js.map +1 -1
  795. package/out/zero-protocol/src/close-connection.js +20 -12
  796. package/out/zero-protocol/src/close-connection.js.map +1 -1
  797. package/out/zero-protocol/src/connect.js +37 -52
  798. package/out/zero-protocol/src/connect.js.map +1 -1
  799. package/out/zero-protocol/src/custom-queries.js +34 -65
  800. package/out/zero-protocol/src/custom-queries.js.map +1 -1
  801. package/out/zero-protocol/src/data.js +6 -9
  802. package/out/zero-protocol/src/data.js.map +1 -1
  803. package/out/zero-protocol/src/delete-clients.js +11 -17
  804. package/out/zero-protocol/src/delete-clients.js.map +1 -1
  805. package/out/zero-protocol/src/down.js +11 -23
  806. package/out/zero-protocol/src/down.js.map +1 -1
  807. package/out/zero-protocol/src/error-kind-enum.js +24 -41
  808. package/out/zero-protocol/src/error-kind-enum.js.map +1 -1
  809. package/out/zero-protocol/src/error-origin-enum.js +8 -9
  810. package/out/zero-protocol/src/error-origin-enum.js.map +1 -1
  811. package/out/zero-protocol/src/error-reason-enum.js +12 -17
  812. package/out/zero-protocol/src/error-reason-enum.js.map +1 -1
  813. package/out/zero-protocol/src/error.js +76 -152
  814. package/out/zero-protocol/src/error.js.map +1 -1
  815. package/out/zero-protocol/src/inspect-down.js +51 -74
  816. package/out/zero-protocol/src/inspect-down.js.map +1 -1
  817. package/out/zero-protocol/src/inspect-up.js +28 -46
  818. package/out/zero-protocol/src/inspect-up.js.map +1 -1
  819. package/out/zero-protocol/src/mutation-id.js +9 -9
  820. package/out/zero-protocol/src/mutation-id.js.map +1 -1
  821. package/out/zero-protocol/src/mutation-type-enum.js +7 -7
  822. package/out/zero-protocol/src/mutation-type-enum.js.map +1 -1
  823. package/out/zero-protocol/src/mutations-patch.js +21 -16
  824. package/out/zero-protocol/src/mutations-patch.js.map +1 -1
  825. package/out/zero-protocol/src/ping.js +8 -9
  826. package/out/zero-protocol/src/ping.js.map +1 -1
  827. package/out/zero-protocol/src/poke.js +53 -59
  828. package/out/zero-protocol/src/poke.js.map +1 -1
  829. package/out/zero-protocol/src/pong.js +8 -9
  830. package/out/zero-protocol/src/pong.js.map +1 -1
  831. package/out/zero-protocol/src/primary-key.js +9 -19
  832. package/out/zero-protocol/src/primary-key.js.map +1 -1
  833. package/out/zero-protocol/src/protocol-version.js +5 -11
  834. package/out/zero-protocol/src/protocol-version.js.map +1 -1
  835. package/out/zero-protocol/src/pull.js +16 -28
  836. package/out/zero-protocol/src/pull.js.map +1 -1
  837. package/out/zero-protocol/src/push.js +162 -209
  838. package/out/zero-protocol/src/push.js.map +1 -1
  839. package/out/zero-protocol/src/queries-patch.js +22 -30
  840. package/out/zero-protocol/src/queries-patch.js.map +1 -1
  841. package/out/zero-protocol/src/query-hash.js +14 -17
  842. package/out/zero-protocol/src/query-hash.js.map +1 -1
  843. package/out/zero-protocol/src/row-patch.js +23 -30
  844. package/out/zero-protocol/src/row-patch.js.map +1 -1
  845. package/out/zero-protocol/src/up.js +11 -22
  846. package/out/zero-protocol/src/up.js.map +1 -1
  847. package/out/zero-protocol/src/update-auth.js +8 -13
  848. package/out/zero-protocol/src/update-auth.js.map +1 -1
  849. package/out/zero-protocol/src/version.js +8 -9
  850. package/out/zero-protocol/src/version.js.map +1 -1
  851. package/out/zero-react/src/bindings.js +12 -0
  852. package/out/zero-react/src/mod.js +5 -0
  853. package/out/zero-react/src/use-connection-state.js +14 -11
  854. package/out/zero-react/src/use-connection-state.js.map +1 -1
  855. package/out/zero-react/src/use-query.js +283 -281
  856. package/out/zero-react/src/use-query.js.map +1 -1
  857. package/out/zero-react/src/use-zero-online.js +17 -11
  858. package/out/zero-react/src/use-zero-online.js.map +1 -1
  859. package/out/zero-react/src/zero-provider.js +53 -69
  860. package/out/zero-react/src/zero-provider.js.map +1 -1
  861. package/out/zero-react/src/zero.js +22 -0
  862. package/out/zero-schema/src/builder/relationship-builder.js +25 -21
  863. package/out/zero-schema/src/builder/relationship-builder.js.map +1 -1
  864. package/out/zero-schema/src/builder/schema-builder.js +51 -79
  865. package/out/zero-schema/src/builder/schema-builder.js.map +1 -1
  866. package/out/zero-schema/src/builder/table-builder.js +99 -116
  867. package/out/zero-schema/src/builder/table-builder.js.map +1 -1
  868. package/out/zero-schema/src/compiled-permissions.js +21 -25
  869. package/out/zero-schema/src/compiled-permissions.js.map +1 -1
  870. package/out/zero-schema/src/name-mapper.js +31 -47
  871. package/out/zero-schema/src/name-mapper.js.map +1 -1
  872. package/out/zero-schema/src/permissions.js +94 -181
  873. package/out/zero-schema/src/permissions.js.map +1 -1
  874. package/out/zero-schema/src/schema-config.js +26 -32
  875. package/out/zero-schema/src/schema-config.js.map +1 -1
  876. package/out/zero-server/src/adapters/drizzle.d.ts.map +1 -1
  877. package/out/zero-server/src/adapters/drizzle.js +79 -76
  878. package/out/zero-server/src/adapters/drizzle.js.map +1 -1
  879. package/out/zero-server/src/adapters/pg.d.ts.map +1 -1
  880. package/out/zero-server/src/adapters/pg.js +79 -55
  881. package/out/zero-server/src/adapters/pg.js.map +1 -1
  882. package/out/zero-server/src/adapters/postgresjs.d.ts.map +1 -1
  883. package/out/zero-server/src/adapters/postgresjs.js +66 -40
  884. package/out/zero-server/src/adapters/postgresjs.js.map +1 -1
  885. package/out/zero-server/src/adapters/prisma.d.ts.map +1 -1
  886. package/out/zero-server/src/adapters/prisma.js +75 -55
  887. package/out/zero-server/src/adapters/prisma.js.map +1 -1
  888. package/out/zero-server/src/custom.d.ts.map +1 -1
  889. package/out/zero-server/src/custom.js +188 -265
  890. package/out/zero-server/src/custom.js.map +1 -1
  891. package/out/zero-server/src/logging.js +6 -5
  892. package/out/zero-server/src/logging.js.map +1 -1
  893. package/out/zero-server/src/mod.js +8 -0
  894. package/out/zero-server/src/pg-query-executor.js +14 -17
  895. package/out/zero-server/src/pg-query-executor.js.map +1 -1
  896. package/out/zero-server/src/process-mutations.js +293 -365
  897. package/out/zero-server/src/process-mutations.js.map +1 -1
  898. package/out/zero-server/src/push-processor.js +33 -49
  899. package/out/zero-server/src/push-processor.js.map +1 -1
  900. package/out/zero-server/src/queries/process-queries.js +106 -96
  901. package/out/zero-server/src/queries/process-queries.js.map +1 -1
  902. package/out/zero-server/src/schema.js +98 -144
  903. package/out/zero-server/src/schema.js.map +1 -1
  904. package/out/zero-server/src/zql-database.d.ts.map +1 -1
  905. package/out/zero-server/src/zql-database.js +54 -69
  906. package/out/zero-server/src/zql-database.js.map +1 -1
  907. package/out/zero-solid/src/bindings.js +12 -0
  908. package/out/zero-solid/src/mod.js +5 -0
  909. package/out/zero-solid/src/solid-view.js +135 -227
  910. package/out/zero-solid/src/solid-view.js.map +1 -1
  911. package/out/zero-solid/src/use-connection-state.js +18 -14
  912. package/out/zero-solid/src/use-connection-state.js.map +1 -1
  913. package/out/zero-solid/src/use-query.js +55 -100
  914. package/out/zero-solid/src/use-query.js.map +1 -1
  915. package/out/zero-solid/src/use-zero-online.js +18 -12
  916. package/out/zero-solid/src/use-zero-online.js.map +1 -1
  917. package/out/zero-solid/src/use-zero.js +65 -77
  918. package/out/zero-solid/src/use-zero.js.map +1 -1
  919. package/out/zero-solid/src/zero.js +22 -0
  920. package/out/zero-types/src/format.js +8 -7
  921. package/out/zero-types/src/format.js.map +1 -1
  922. package/out/zero-types/src/name-mapper.js +34 -47
  923. package/out/zero-types/src/name-mapper.js.map +1 -1
  924. package/out/zql/src/builder/builder.d.ts.map +1 -1
  925. package/out/zql/src/builder/builder.js +315 -476
  926. package/out/zql/src/builder/builder.js.map +1 -1
  927. package/out/zql/src/builder/debug-delegate.js +69 -74
  928. package/out/zql/src/builder/debug-delegate.js.map +1 -1
  929. package/out/zql/src/builder/filter.js +116 -140
  930. package/out/zql/src/builder/filter.js.map +1 -1
  931. package/out/zql/src/builder/like.js +41 -46
  932. package/out/zql/src/builder/like.js.map +1 -1
  933. package/out/zql/src/error.js +10 -9
  934. package/out/zql/src/error.js.map +1 -1
  935. package/out/zql/src/ivm/array-view.js +89 -91
  936. package/out/zql/src/ivm/array-view.js.map +1 -1
  937. package/out/zql/src/ivm/constraint.js +65 -74
  938. package/out/zql/src/ivm/constraint.js.map +1 -1
  939. package/out/zql/src/ivm/data.js +61 -48
  940. package/out/zql/src/ivm/data.js.map +1 -1
  941. package/out/zql/src/ivm/exists.js +164 -213
  942. package/out/zql/src/ivm/exists.js.map +1 -1
  943. package/out/zql/src/ivm/fan-in.js +62 -59
  944. package/out/zql/src/ivm/fan-in.js.map +1 -1
  945. package/out/zql/src/ivm/fan-out.js +52 -61
  946. package/out/zql/src/ivm/fan-out.js.map +1 -1
  947. package/out/zql/src/ivm/filter-operators.js +91 -96
  948. package/out/zql/src/ivm/filter-operators.js.map +1 -1
  949. package/out/zql/src/ivm/filter-push.js +22 -26
  950. package/out/zql/src/ivm/filter-push.js.map +1 -1
  951. package/out/zql/src/ivm/filter.js +41 -35
  952. package/out/zql/src/ivm/filter.js.map +1 -1
  953. package/out/zql/src/ivm/flipped-join.js +282 -391
  954. package/out/zql/src/ivm/flipped-join.js.map +1 -1
  955. package/out/zql/src/ivm/join-utils.js +85 -115
  956. package/out/zql/src/ivm/join-utils.js.map +1 -1
  957. package/out/zql/src/ivm/join.js +162 -231
  958. package/out/zql/src/ivm/join.js.map +1 -1
  959. package/out/zql/src/ivm/maybe-split-and-push-edit-change.js +21 -25
  960. package/out/zql/src/ivm/maybe-split-and-push-edit-change.js.map +1 -1
  961. package/out/zql/src/ivm/memory-source.js +364 -503
  962. package/out/zql/src/ivm/memory-source.js.map +1 -1
  963. package/out/zql/src/ivm/memory-storage.js +33 -34
  964. package/out/zql/src/ivm/memory-storage.js.map +1 -1
  965. package/out/zql/src/ivm/operator.js +13 -15
  966. package/out/zql/src/ivm/operator.js.map +1 -1
  967. package/out/zql/src/ivm/push-accumulated.js +267 -270
  968. package/out/zql/src/ivm/push-accumulated.js.map +1 -1
  969. package/out/zql/src/ivm/skip.js +91 -104
  970. package/out/zql/src/ivm/skip.js.map +1 -1
  971. package/out/zql/src/ivm/stream.js +10 -10
  972. package/out/zql/src/ivm/stream.js.map +1 -1
  973. package/out/zql/src/ivm/take.js +422 -569
  974. package/out/zql/src/ivm/take.js.map +1 -1
  975. package/out/zql/src/ivm/union-fan-in.js +157 -231
  976. package/out/zql/src/ivm/union-fan-in.js.map +1 -1
  977. package/out/zql/src/ivm/union-fan-out.js +38 -43
  978. package/out/zql/src/ivm/union-fan-out.js.map +1 -1
  979. package/out/zql/src/ivm/view-apply-change.js +166 -255
  980. package/out/zql/src/ivm/view-apply-change.js.map +1 -1
  981. package/out/zql/src/mutate/crud.js +35 -34
  982. package/out/zql/src/mutate/crud.js.map +1 -1
  983. package/out/zql/src/mutate/custom.d.ts.map +1 -1
  984. package/out/zql/src/mutate/custom.js +7 -11
  985. package/out/zql/src/mutate/custom.js.map +1 -1
  986. package/out/zql/src/mutate/mutator-registry.js +67 -71
  987. package/out/zql/src/mutate/mutator-registry.js.map +1 -1
  988. package/out/zql/src/mutate/mutator.js +26 -25
  989. package/out/zql/src/mutate/mutator.js.map +1 -1
  990. package/out/zql/src/planner/planner-builder.js +134 -239
  991. package/out/zql/src/planner/planner-builder.js.map +1 -1
  992. package/out/zql/src/planner/planner-connection.js +222 -212
  993. package/out/zql/src/planner/planner-connection.js.map +1 -1
  994. package/out/zql/src/planner/planner-constraint.js +15 -7
  995. package/out/zql/src/planner/planner-constraint.js.map +1 -1
  996. package/out/zql/src/planner/planner-debug.js +199 -224
  997. package/out/zql/src/planner/planner-debug.js.map +1 -1
  998. package/out/zql/src/planner/planner-fan-in.js +146 -162
  999. package/out/zql/src/planner/planner-fan-in.js.map +1 -1
  1000. package/out/zql/src/planner/planner-fan-out.js +62 -74
  1001. package/out/zql/src/planner/planner-fan-out.js.map +1 -1
  1002. package/out/zql/src/planner/planner-graph.js +302 -334
  1003. package/out/zql/src/planner/planner-graph.js.map +1 -1
  1004. package/out/zql/src/planner/planner-join.js +255 -240
  1005. package/out/zql/src/planner/planner-join.js.map +1 -1
  1006. package/out/zql/src/planner/planner-node.js +10 -6
  1007. package/out/zql/src/planner/planner-node.js.map +1 -1
  1008. package/out/zql/src/planner/planner-source.js +15 -22
  1009. package/out/zql/src/planner/planner-source.js.map +1 -1
  1010. package/out/zql/src/planner/planner-terminus.js +28 -28
  1011. package/out/zql/src/planner/planner-terminus.js.map +1 -1
  1012. package/out/zql/src/query/complete-ordering.js +37 -61
  1013. package/out/zql/src/query/complete-ordering.js.map +1 -1
  1014. package/out/zql/src/query/create-builder.js +14 -22
  1015. package/out/zql/src/query/create-builder.js.map +1 -1
  1016. package/out/zql/src/query/error.js +10 -12
  1017. package/out/zql/src/query/error.js.map +1 -1
  1018. package/out/zql/src/query/escape-like.js +6 -5
  1019. package/out/zql/src/query/escape-like.js.map +1 -1
  1020. package/out/zql/src/query/expression.js +138 -157
  1021. package/out/zql/src/query/expression.js.map +1 -1
  1022. package/out/zql/src/query/measure-push-operator.js +35 -38
  1023. package/out/zql/src/query/measure-push-operator.js.map +1 -1
  1024. package/out/zql/src/query/metrics-delegate.js +7 -7
  1025. package/out/zql/src/query/metrics-delegate.js.map +1 -1
  1026. package/out/zql/src/query/named.js +52 -51
  1027. package/out/zql/src/query/named.js.map +1 -1
  1028. package/out/zql/src/query/query-delegate-base.js +190 -238
  1029. package/out/zql/src/query/query-delegate-base.js.map +1 -1
  1030. package/out/zql/src/query/query-impl.d.ts.map +1 -1
  1031. package/out/zql/src/query/query-impl.js +271 -405
  1032. package/out/zql/src/query/query-impl.js.map +1 -1
  1033. package/out/zql/src/query/query-internals.js +16 -8
  1034. package/out/zql/src/query/query-internals.js.map +1 -1
  1035. package/out/zql/src/query/query-registry.js +83 -98
  1036. package/out/zql/src/query/query-registry.js.map +1 -1
  1037. package/out/zql/src/query/query.d.ts.map +1 -1
  1038. package/out/zql/src/query/query.js +2 -0
  1039. package/out/zql/src/query/runnable-query-impl.d.ts.map +1 -1
  1040. package/out/zql/src/query/runnable-query-impl.js +30 -55
  1041. package/out/zql/src/query/runnable-query-impl.js.map +1 -1
  1042. package/out/zql/src/query/static-query.js +7 -14
  1043. package/out/zql/src/query/static-query.js.map +1 -1
  1044. package/out/zql/src/query/ttl.js +45 -67
  1045. package/out/zql/src/query/ttl.js.map +1 -1
  1046. package/out/zql/src/query/validate-input.js +23 -20
  1047. package/out/zql/src/query/validate-input.js.map +1 -1
  1048. package/out/zqlite/src/database-storage.js +99 -103
  1049. package/out/zqlite/src/database-storage.js.map +1 -1
  1050. package/out/zqlite/src/db.js +206 -249
  1051. package/out/zqlite/src/db.js.map +1 -1
  1052. package/out/zqlite/src/explain-queries.js +11 -13
  1053. package/out/zqlite/src/explain-queries.js.map +1 -1
  1054. package/out/zqlite/src/internal/sql-inline.js +54 -37
  1055. package/out/zqlite/src/internal/sql-inline.js.map +1 -1
  1056. package/out/zqlite/src/internal/sql.js +17 -15
  1057. package/out/zqlite/src/internal/sql.js.map +1 -1
  1058. package/out/zqlite/src/internal/statement-cache.js +117 -92
  1059. package/out/zqlite/src/internal/statement-cache.js.map +1 -1
  1060. package/out/zqlite/src/mod.js +5 -0
  1061. package/out/zqlite/src/query-builder.js +81 -172
  1062. package/out/zqlite/src/query-builder.js.map +1 -1
  1063. package/out/zqlite/src/query-delegate.js +45 -55
  1064. package/out/zqlite/src/query-delegate.js.map +1 -1
  1065. package/out/zqlite/src/resolve-scalar-subqueries.js +134 -124
  1066. package/out/zqlite/src/resolve-scalar-subqueries.js.map +1 -1
  1067. package/out/zqlite/src/sqlite-cost-model.js +92 -97
  1068. package/out/zqlite/src/sqlite-cost-model.js.map +1 -1
  1069. package/out/zqlite/src/sqlite-stat-fanout.js +304 -286
  1070. package/out/zqlite/src/sqlite-stat-fanout.js.map +1 -1
  1071. package/out/zqlite/src/table-source.js +281 -455
  1072. package/out/zqlite/src/table-source.js.map +1 -1
  1073. package/package.json +8 -7
  1074. package/out/replicache/src/db/index-operation-enum.js +0 -7
  1075. package/out/replicache/src/db/index-operation-enum.js.map +0 -1
  1076. package/out/replicache/src/db/meta-type-enum.js +0 -7
  1077. package/out/replicache/src/db/meta-type-enum.js.map +0 -1
  1078. package/out/replicache/src/format-version-enum.js +0 -11
  1079. package/out/replicache/src/format-version-enum.js.map +0 -1
  1080. package/out/replicache/src/http-status-unauthorized.js +0 -5
  1081. package/out/replicache/src/http-status-unauthorized.js.map +0 -1
  1082. package/out/replicache/src/invoke-kind-enum.js +0 -7
  1083. package/out/replicache/src/invoke-kind-enum.js.map +0 -1
  1084. package/out/replicache/src/sync/handle-pull-response-result-type-enum.js +0 -9
  1085. package/out/replicache/src/sync/handle-pull-response-result-type-enum.js.map +0 -1
  1086. package/out/zero/package.json.js +0 -9
  1087. package/out/zero/package.json.js.map +0 -1
  1088. package/out/zero/src/adapters/drizzle.js.map +0 -1
  1089. package/out/zero/src/adapters/pg.js.map +0 -1
  1090. package/out/zero/src/adapters/postgresjs.js.map +0 -1
  1091. package/out/zero/src/adapters/prisma.js.map +0 -1
  1092. package/out/zero/src/analyze-query.js.map +0 -1
  1093. package/out/zero/src/ast-to-zql.js.map +0 -1
  1094. package/out/zero/src/bindings.js.map +0 -1
  1095. package/out/zero/src/change-protocol/v0.js.map +0 -1
  1096. package/out/zero/src/cli.js.map +0 -1
  1097. package/out/zero/src/deploy-permissions.js.map +0 -1
  1098. package/out/zero/src/expo-sqlite.js.map +0 -1
  1099. package/out/zero/src/op-sqlite.js.map +0 -1
  1100. package/out/zero/src/pg.js.map +0 -1
  1101. package/out/zero/src/react.js.map +0 -1
  1102. package/out/zero/src/server.js.map +0 -1
  1103. package/out/zero/src/solid.js.map +0 -1
  1104. package/out/zero/src/sqlite.js.map +0 -1
  1105. package/out/zero/src/transform-query.js.map +0 -1
  1106. package/out/zero/src/zero.js.map +0 -1
  1107. package/out/zero/src/zqlite.js.map +0 -1
  1108. package/out/zero-cache/src/db/postgres-replica-identity-enum.js +0 -11
  1109. package/out/zero-cache/src/db/postgres-replica-identity-enum.js.map +0 -1
  1110. package/out/zero-cache/src/db/postgres-type-class-enum.js +0 -17
  1111. package/out/zero-cache/src/db/postgres-type-class-enum.js.map +0 -1
  1112. package/out/zero-cache/src/services/change-streamer/error-type-enum.js +0 -9
  1113. 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